2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
23 package org.onap.appc.listener.LCM.model;
25 import static junit.framework.TestCase.assertNotNull;
26 import static org.junit.Assert.assertEquals;
27 import static org.onap.appc.listener.TestUtil.buildCommonHeader;
29 import java.util.HashMap;
31 import org.json.JSONObject;
32 import org.junit.Before;
33 import org.junit.Test;
35 public class OutputBodyTest {
37 private OutputBody outputBody;
41 outputBody = new OutputBody();
45 public void should_set_properties() {
47 CommonHeader testCommonHeader = buildCommonHeader();
48 ResponseStatus testResponseStatus = new ResponseStatus(200, "OK");
50 outputBody.setHeader(testCommonHeader);
51 outputBody.setStatus(testResponseStatus);
52 outputBody.setLocked("test-locked");
53 outputBody.setPayload("{\"payload\": \"value\"");
55 assertEquals(testCommonHeader, outputBody.getHeader());
56 assertEquals(testResponseStatus, outputBody.getStatus());
57 assertEquals("test-locked", outputBody.getLocked());
58 assertEquals("{\"payload\": \"value\"", outputBody.getPayload());
63 public void should_inherit_input_body_header_when_initialized_from_constructor() {
65 InputBody testInputBody = new InputBody();
66 CommonHeader testCommonHeader = buildCommonHeader();
67 testInputBody.setCommonHeader(testCommonHeader);
69 outputBody = new OutputBody(testInputBody);
71 assertNotNull(outputBody.getHeader());
72 assertEquals(testCommonHeader.getFlags(), outputBody.getHeader().getFlags());
73 assertEquals(testCommonHeader.getSubRequestId(), outputBody.getHeader().getSubRequestId());
74 assertEquals(testCommonHeader.getRequestID(), outputBody.getHeader().getRequestID());
75 assertEquals(testCommonHeader.getOriginatorId(), outputBody.getHeader().getOriginatorId());
76 assertEquals(testCommonHeader.getApiVer(), outputBody.getHeader().getApiVer());
80 public void toResponse_should_convert_to_json_object() {
81 CommonHeader testCommonHeader = buildCommonHeader();
82 ResponseStatus testResponseStatus = new ResponseStatus(200, "OK");
84 outputBody.setHeader(testCommonHeader);
85 outputBody.setStatus(testResponseStatus);
86 outputBody.setLocked("test-locked");
87 outputBody.setPayload("{\"payload\": \"value\"");
89 JSONObject response = outputBody.toResponse();
90 assertNotNull(response);
92 assertEquals("test-locked", response.get("locked"));
93 assertEquals("{\"payload\": \"value\"", response.get("payload"));