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