ffa80b490fb92d7bf8a1d18beeb24db3bba401c6
[appc.git] /
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.assertNotEquals;
25 import static org.junit.Assert.assertTrue;
26
27 import java.util.HashMap;
28 import java.util.Map;
29
30 import org.junit.Assert;
31 import org.junit.Before;
32 import org.junit.Test;
33
34 public class TestResponseContext {
35     private ResponseContext responseContext;
36     private Map<String, String> testadditionalContext;
37
38     @Before
39     public void setUp() {
40         responseContext = new ResponseContext();
41     }
42
43     @Test
44     public void testgetAdditionalContext() {    
45         testadditionalContext=new HashMap<String, String>();
46         testadditionalContext.put("A", "a");
47         responseContext.setAdditionalContext(testadditionalContext);
48         Assert.assertNotNull(responseContext.getAdditionalContext());
49         Assert.assertTrue(responseContext.getAdditionalContext().containsKey("A"));
50         Assert.assertTrue(responseContext.getAdditionalContext().containsValue("a"));
51     }
52
53     @Test
54     public void testGetPayload() {
55         responseContext.setPayload("ABC:2000");
56         Assert.assertNotNull(responseContext.getPayload());
57         Assert.assertEquals(responseContext.getPayload(), "ABC:2000");
58     }
59
60     @Test
61     public void testToString_ReturnNonEmptyString() {
62         assertNotEquals(responseContext.toString(), "");
63         assertNotEquals(responseContext.toString(), null);
64     }
65
66     @Test
67     public void testToString_ContainsString() {
68         assertTrue(responseContext.toString().contains("ResponseContext{commonHeader"));
69     }
70     
71     @Test
72     public void testAddKeyValueToAdditionalContext() {
73         String key="key1";
74         String value="value1";
75         responseContext.addKeyValueToAdditionalContext(key, value);
76         Map<String, String> additionalContext= responseContext.getAdditionalContext();
77         Assert.assertEquals("value1", additionalContext.get("key1"));
78     }
79     
80     @Test
81     public void testGetPayloadObject() {
82         responseContext.setPayloadObject("ABC:2000");
83         Assert.assertEquals("ABC:2000", responseContext.getPayloadObject());
84     }
85
86 }