Merge "Add data type and policy type reference checking"
[policy/models.git] / models-interactions / model-actors / actorServiceProvider / src / test / java / org / onap / policy / controlloop / actorserviceprovider / controlloop / ControlLoopEventContextTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.controlloop.actorserviceprovider.controlloop;
22
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;
28
29 import java.util.Map;
30 import java.util.UUID;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.policy.controlloop.VirtualControlLoopEvent;
34
35 public class ControlLoopEventContextTest {
36     private static final UUID REQ_ID = UUID.randomUUID();
37
38     private Map<String, String> enrichment;
39     private VirtualControlLoopEvent event;
40     private ControlLoopEventContext context;
41
42     /**
43      * Initializes data, including {@link #context}.
44      */
45     @Before
46     public void setUp() {
47         enrichment = Map.of("abc", "one", "def", "two");
48
49         event = new VirtualControlLoopEvent();
50         event.setRequestId(REQ_ID);
51         event.setAai(enrichment);
52
53         context = new ControlLoopEventContext(event);
54     }
55
56     @Test
57     public void testControlLoopEventContext() {
58         assertSame(event, context.getEvent());
59         assertSame(REQ_ID, context.getRequestId());
60         assertEquals(enrichment, context.getEnrichment());
61
62         // null event
63         assertThatThrownBy(() -> new ControlLoopEventContext(null));
64
65         // no request id, no enrichment data
66         event.setRequestId(null);
67         event.setAai(null);
68         context = new ControlLoopEventContext(event);
69         assertSame(event, context.getEvent());
70         assertNotNull(context.getRequestId());
71         assertEquals(Map.of(), context.getEnrichment());
72     }
73
74     @Test
75     public void testContains_testGetProperty_testSetProperty() {
76         context.setProperty("abc", "a string");
77         context.setProperty("def", 100);
78
79         assertFalse(context.contains("ghi"));
80
81         String strValue = context.getProperty("abc");
82         assertEquals("a string", strValue);
83
84         int intValue = context.getProperty("def");
85         assertEquals(100, intValue);
86     }
87 }