Change code in appc dispatcher for new LCMs in R6
[appc.git] / appc-dispatcher / appc-dispatcher-common / domain-model-lib / src / test / java / org / onap / appc / domainmodel / lcm / TestRequestContext.java
1 /*
2 * ============LICENSE_START=======================================================
3 * ONAP : APPC
4 * ================================================================================
5 * Copyright 2018 TechMahindra
6 *=================================================================================
7 * Modifications Copyright 2018 IBM.
8 *=================================================================================
9 * Modifications Copyright 2019 AT&T Intellectual Property
10 *=================================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 *     http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 * ============LICENSE_END=========================================================
23 */
24 package org.onap.appc.domainmodel.lcm;
25
26 import static org.junit.Assert.*;
27
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31
32 import java.util.HashMap;
33 import java.util.Map;
34
35 public class TestRequestContext {
36     private RequestContext requestContext;
37     private Map<String, String> testadditionalContext;
38
39     @Before
40     public void setUp() {
41         requestContext = new RequestContext();
42     }
43
44     @Test
45     public void testGetActionLevel_ValidEnumConstant() {
46         requestContext.setActionLevel(ActionLevel.VM);
47         Assert.assertNotNull(requestContext.getActionLevel());
48         Assert.assertEquals(requestContext.getActionLevel(), ActionLevel.VM);
49     }
50
51     @Test
52     public void testgetAdditionalContext() {
53         testadditionalContext = new HashMap<String, String>();
54         testadditionalContext.put("A", "a");
55         requestContext.setAdditionalContext(testadditionalContext);
56         Assert.assertNotNull(requestContext.getAdditionalContext());
57         Assert.assertTrue(requestContext.getAdditionalContext().containsKey("A"));
58         Assert.assertTrue(requestContext.getAdditionalContext().containsValue("a"));
59     }
60
61     @Test
62     public void testAddKeyValueToAdditionalContext() {
63         String key = "key1";
64         String value = "value1";
65         requestContext.addKeyValueToAdditionalContext(key, value);
66         Map<String, String> additionalContext = requestContext.getAdditionalContext();
67         Assert.assertEquals("value1", additionalContext.get("key1"));
68     }
69
70     @Test
71     public void testGetPayload() {
72         requestContext.setPayload("ABC:2000");
73         Assert.assertNotNull(requestContext.getPayload());
74         Assert.assertEquals(requestContext.getPayload(), "ABC:2000");
75     }
76
77     @Test
78     public void testToString_ReturnNonEmptyString() {
79         assertNotEquals(requestContext.toString(), "");
80         assertNotEquals(requestContext.toString(), null);
81     }
82
83     @Test
84     public void testToString_ContainsString() {
85         assertTrue(requestContext.toString().contains("RequestContext{commonHeader"));
86     }
87
88     @Test
89     public void testGetSetCommonHeader() {
90         CommonHeader commonHeader = new CommonHeader();
91         requestContext.setCommonHeader(commonHeader);
92         assertEquals(commonHeader, requestContext.getCommonHeader());
93     }
94
95     @Test
96     public void testGetSetActionIdentifiers() {
97         ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
98         requestContext.setActionIdentifiers(actionIdentifiers);
99         assertEquals(actionIdentifiers, requestContext.getActionIdentifiers());
100     }
101
102     @Test
103     public void testGetSetAction() {
104         VNFOperation action = VNFOperation.ActionStatus;
105         requestContext.setAction(action);
106         assertEquals(action, requestContext.getAction());
107     }
108
109 }