2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
 
   6  * ================================================================================
 
   7  * Licensed under the Apache License, Version 2.0 (the "License");
 
   8  * you may not use this file except in compliance with the License.
 
   9  * You may obtain a copy of the License at
 
  11  *      http://www.apache.org/licenses/LICENSE-2.0
 
  13  * Unless required by applicable law or agreed to in writing, software
 
  14  * distributed under the License is distributed on an "AS IS" BASIS,
 
  15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  16  * See the License for the specific language governing permissions and
 
  17  * limitations under the License.
 
  18  * ============LICENSE_END=========================================================
 
  21 package org.onap.policy.controlloop.actorserviceprovider.controlloop;
 
  23 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
  24 import static org.junit.Assert.assertEquals;
 
  25 import static org.junit.Assert.assertFalse;
 
  26 import static org.junit.Assert.assertNotNull;
 
  27 import static org.junit.Assert.assertSame;
 
  30 import java.util.UUID;
 
  31 import org.junit.Before;
 
  32 import org.junit.Test;
 
  33 import org.onap.policy.controlloop.VirtualControlLoopEvent;
 
  35 public class ControlLoopEventContextTest {
 
  36     private static final UUID REQ_ID = UUID.randomUUID();
 
  38     private Map<String, String> enrichment;
 
  39     private VirtualControlLoopEvent event;
 
  40     private ControlLoopEventContext context;
 
  43      * Initializes data, including {@link #context}.
 
  47         enrichment = Map.of("abc", "one", "def", "two");
 
  49         event = new VirtualControlLoopEvent();
 
  50         event.setRequestId(REQ_ID);
 
  51         event.setAai(enrichment);
 
  53         context = new ControlLoopEventContext(event);
 
  57     public void testControlLoopEventContext() {
 
  58         assertSame(event, context.getEvent());
 
  59         assertSame(REQ_ID, context.getRequestId());
 
  60         assertEquals(enrichment, context.getEnrichment());
 
  63         assertThatThrownBy(() -> new ControlLoopEventContext(null));
 
  65         // no request id, no enrichment data
 
  66         event.setRequestId(null);
 
  68         context = new ControlLoopEventContext(event);
 
  69         assertSame(event, context.getEvent());
 
  70         assertNotNull(context.getRequestId());
 
  71         assertEquals(Map.of(), context.getEnrichment());
 
  75     public void testContains_testGetProperty_testSetProperty() {
 
  76         context.setProperty("abc", "a string");
 
  77         context.setProperty("def", 100);
 
  79         assertFalse(context.contains("ghi"));
 
  81         String strValue = context.getProperty("abc");
 
  82         assertEquals("a string", strValue);
 
  84         int intValue = context.getProperty("def");
 
  85         assertEquals(100, intValue);