2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2021 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.assertj.core.api.Assertions.assertThat;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
29 import java.util.HashMap;
31 import org.junit.Test;
33 public class ResponseTest {
36 public void testResonse() {
37 Response response = new Response();
38 assertNotNull(response);
39 assertNotNull(new Response(new Request()));
40 assertNotEquals(0, response.hashCode());
42 CommonHeader commonHeader = new CommonHeader();
44 Request request = new Request();
45 request.setCommonHeader(commonHeader);
46 assertNotNull(new Response(request));
48 response.setCommonHeader(commonHeader);
49 assertEquals(commonHeader, response.getCommonHeader());
51 ResponseStatus status = new ResponseStatus();
52 response.setStatus(status);
53 assertEquals(status, response.getStatus());
55 Map<String, Object> payload = new HashMap<>();
56 payload.put("North", "Good Witch");
57 payload.put("West", "Bad Witch");
59 response.setPayload(payload);
60 assertEquals(payload, response.getPayload());
62 assertNotEquals(0, response.hashCode());
64 assertThat(response.toString()).startsWith("Response(commonHeader=CommonHeader(timeStamp=");
66 Response copiedResponse = new Response();
67 copiedResponse.setCommonHeader(response.getCommonHeader());
68 copiedResponse.setStatus(response.getStatus());
69 copiedResponse.setPayload(response.getPayload());
71 assertEquals(response, (Object) response);
72 assertEquals(response, copiedResponse);
73 assertNotEquals(response, null);
74 assertNotEquals(response, (Object) "Hello");
76 response.setCommonHeader(null);
77 assertNotEquals(response, copiedResponse);
78 copiedResponse.setCommonHeader(null);
79 assertEquals(response, copiedResponse);
80 response.setCommonHeader(commonHeader);
81 assertNotEquals(response, copiedResponse);
82 copiedResponse.setCommonHeader(commonHeader);
83 assertEquals(response, copiedResponse);
85 response.setStatus(null);
86 assertNotEquals(response, copiedResponse);
87 copiedResponse.setStatus(null);
88 assertEquals(response, copiedResponse);
89 response.setStatus(status);
90 assertNotEquals(response, copiedResponse);
91 copiedResponse.setStatus(status);
92 assertEquals(response, copiedResponse);
94 response.setPayload(new HashMap<String, Object>());
95 assertNotEquals(response, copiedResponse);
96 copiedResponse.setPayload(new HashMap<String, Object>());
97 assertEquals(response, copiedResponse);
98 response.setPayload(payload);
99 assertNotEquals(response, copiedResponse);
100 copiedResponse.setPayload(payload);
101 assertEquals(response, copiedResponse);