LCM package test classes refactor
[appc.git] / appc-event-listener / appc-event-listener-bundle / src / test / java / org / onap / appc / listener / LCM / model / OutputBodyTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2018 Nokia Solutions and Networks
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  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24 package org.onap.appc.listener.LCM.model;
25
26 import static junit.framework.TestCase.assertNotNull;
27 import static org.junit.Assert.assertEquals;
28 import static org.onap.appc.listener.TestUtil.buildCommonHeader;
29
30 import java.util.HashMap;
31 import java.util.Map;
32 import org.json.JSONObject;
33 import org.junit.Before;
34 import org.junit.Test;
35
36 public class OutputBodyTest {
37
38     private OutputBody outputBody;
39
40     @Before
41     public void setup() {
42         outputBody = new OutputBody();
43     }
44
45     @Test
46     public void should_set_properties() {
47
48         CommonHeader testCommonHeader = buildCommonHeader();
49         ResponseStatus testResponseStatus = new ResponseStatus(200, "OK");
50
51         outputBody.setHeader(testCommonHeader);
52         outputBody.setStatus(testResponseStatus);
53         outputBody.setLocked("test-locked");
54         outputBody.setPayload("{\"payload\": \"value\"");
55
56         assertEquals(testCommonHeader, outputBody.getHeader());
57         assertEquals(testResponseStatus, outputBody.getStatus());
58         assertEquals("test-locked", outputBody.getLocked());
59         assertEquals("{\"payload\": \"value\"", outputBody.getPayload());
60     }
61
62
63     @Test
64     public void should_inherit_input_body_header_when_initialized_from_constructor() {
65
66         InputBody testInputBody = new InputBody();
67         CommonHeader testCommonHeader = buildCommonHeader();
68         testInputBody.setCommonHeader(testCommonHeader);
69
70         outputBody = new OutputBody(testInputBody);
71
72         assertNotNull(outputBody.getHeader());
73         assertEquals(testCommonHeader.getFlags(), outputBody.getHeader().getFlags());
74         assertEquals(testCommonHeader.getSubRequestId(), outputBody.getHeader().getSubRequestId());
75         assertEquals(testCommonHeader.getRequestID(), outputBody.getHeader().getRequestID());
76         assertEquals(testCommonHeader.getOriginatorId(), outputBody.getHeader().getOriginatorId());
77         assertEquals(testCommonHeader.getApiVer(), outputBody.getHeader().getApiVer());
78     }
79
80     @Test
81     public void toResponse_should_convert_to_json_object() {
82         CommonHeader testCommonHeader = buildCommonHeader();
83         ResponseStatus testResponseStatus = new ResponseStatus(200, "OK");
84
85         outputBody.setHeader(testCommonHeader);
86         outputBody.setStatus(testResponseStatus);
87         outputBody.setLocked("test-locked");
88         outputBody.setPayload("{\"payload\": \"value\"");
89
90         JSONObject response = outputBody.toResponse();
91         assertNotNull(response);
92
93         assertEquals("test-locked", response.get("locked"));
94         assertEquals("{\"payload\": \"value\"", response.get("payload"));
95     }
96 }