2 * ============LICENSE_START=======================================================
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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
24 package org.onap.appc.listener.LCM.model;
26 import static junit.framework.TestCase.assertNotNull;
27 import static org.junit.Assert.assertEquals;
28 import static org.onap.appc.listener.TestUtil.buildCommonHeader;
30 import java.util.HashMap;
32 import org.json.JSONObject;
33 import org.junit.Before;
34 import org.junit.Test;
36 public class OutputBodyTest {
38 private OutputBody outputBody;
42 outputBody = new OutputBody();
46 public void should_set_properties() {
48 CommonHeader testCommonHeader = buildCommonHeader();
49 ResponseStatus testResponseStatus = new ResponseStatus(200, "OK");
51 outputBody.setHeader(testCommonHeader);
52 outputBody.setStatus(testResponseStatus);
53 outputBody.setLocked("test-locked");
54 outputBody.setPayload("{\"payload\": \"value\"");
56 assertEquals(testCommonHeader, outputBody.getHeader());
57 assertEquals(testResponseStatus, outputBody.getStatus());
58 assertEquals("test-locked", outputBody.getLocked());
59 assertEquals("{\"payload\": \"value\"", outputBody.getPayload());
64 public void should_inherit_input_body_header_when_initialized_from_constructor() {
66 InputBody testInputBody = new InputBody();
67 CommonHeader testCommonHeader = buildCommonHeader();
68 testInputBody.setCommonHeader(testCommonHeader);
70 outputBody = new OutputBody(testInputBody);
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());
81 public void toResponse_should_convert_to_json_object() {
82 CommonHeader testCommonHeader = buildCommonHeader();
83 ResponseStatus testResponseStatus = new ResponseStatus(200, "OK");
85 outputBody.setHeader(testCommonHeader);
86 outputBody.setStatus(testResponseStatus);
87 outputBody.setLocked("test-locked");
88 outputBody.setPayload("{\"payload\": \"value\"");
90 JSONObject response = outputBody.toResponse();
91 assertNotNull(response);
93 assertEquals("test-locked", response.get("locked"));
94 assertEquals("{\"payload\": \"value\"", response.get("payload"));