2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.appc;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotEquals;
26 import static org.junit.Assert.assertNotNull;
28 import java.util.HashMap;
30 import org.junit.Test;
32 public class ResponseTest {
35 public void testResonse() {
36 Response response = new Response();
37 assertNotNull(response);
38 assertNotNull(new Response(new Request()));
39 assertNotEquals(0, response.hashCode());
41 CommonHeader commonHeader = new CommonHeader();
43 Request request = new Request();
44 request.setCommonHeader(commonHeader);
45 assertNotNull(new Response(request));
47 response.setCommonHeader(commonHeader);
48 assertEquals(commonHeader, response.getCommonHeader());
50 ResponseStatus status = new ResponseStatus();
51 response.setStatus(status);
52 assertEquals(status, response.getStatus());
54 Map<String, Object> payload = new HashMap<>();
55 payload.put("North", "Good Witch");
56 payload.put("West", "Bad Witch");
58 response.setPayload(payload);
59 assertEquals(payload, response.getPayload());
61 assertNotEquals(0, response.hashCode());
63 assertEquals("Response [CommonHeader=CommonHeader [TimeStamp=", response.toString().substring(0, 47));
65 Response copiedResponse = new Response();
66 copiedResponse.setCommonHeader(response.getCommonHeader());
67 copiedResponse.setStatus(response.getStatus());
68 copiedResponse.setPayload(response.getPayload());
71 * Disabling sonar to test equals().
73 assertEquals(response, response); // NOSONAR
74 assertEquals(response, copiedResponse);
75 assertNotEquals(response, null);
76 assertNotEquals(response, "Hello"); // NOSONAR
78 response.setCommonHeader(null);
79 assertNotEquals(response, copiedResponse);
80 copiedResponse.setCommonHeader(null);
81 assertEquals(response, copiedResponse);
82 response.setCommonHeader(commonHeader);
83 assertNotEquals(response, copiedResponse);
84 copiedResponse.setCommonHeader(commonHeader);
85 assertEquals(response, copiedResponse);
87 response.setStatus(null);
88 assertNotEquals(response, copiedResponse);
89 copiedResponse.setStatus(null);
90 assertEquals(response, copiedResponse);
91 response.setStatus(status);
92 assertNotEquals(response, copiedResponse);
93 copiedResponse.setStatus(status);
94 assertEquals(response, copiedResponse);
96 response.setPayload(new HashMap<String, Object>());
97 assertNotEquals(response, copiedResponse);
98 copiedResponse.setPayload(new HashMap<String, Object>());
99 assertEquals(response, copiedResponse);
100 response.setPayload(payload);
101 assertNotEquals(response, copiedResponse);
102 copiedResponse.setPayload(payload);
103 assertEquals(response, copiedResponse);