2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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.assertFalse;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
30 import java.util.HashMap;
32 import org.junit.Test;
34 public class ResponseTest {
37 public void testResonse() {
38 Response response = new Response();
39 assertNotNull(response);
40 assertNotNull(new Response(new Request()));
41 assertNotEquals(0, response.hashCode());
43 CommonHeader commonHeader = new CommonHeader();
45 Request request = new Request();
46 request.setCommonHeader(commonHeader);
47 assertNotNull(new Response(request));
49 response.setCommonHeader(commonHeader);
50 assertEquals(commonHeader, response.getCommonHeader());
52 ResponseStatus status = new ResponseStatus();
53 response.setStatus(status);
54 assertEquals(status, response.getStatus());
56 Map<String, Object> payload = new HashMap<>();
57 payload.put("North", "Good Witch");
58 payload.put("West", "Bad Witch");
60 response.setPayload(payload);
61 assertEquals(payload, response.getPayload());
63 assertNotEquals(0, response.hashCode());
65 assertEquals("Response [CommonHeader=CommonHeader [TimeStamp=", response.toString().substring(0, 47));
67 Response copiedResponse = new Response();
68 copiedResponse.setCommonHeader(response.getCommonHeader());
69 copiedResponse.setStatus(response.getStatus());
70 copiedResponse.setPayload(response.getPayload());
72 assertTrue(response.equals(response));
73 assertTrue(response.equals(copiedResponse));
74 assertFalse(response.equals(null));
75 assertFalse(response.equals("Hello"));
77 response.setCommonHeader(null);
78 assertFalse(response.equals(copiedResponse));
79 copiedResponse.setCommonHeader(null);
80 assertTrue(response.equals(copiedResponse));
81 response.setCommonHeader(commonHeader);
82 assertFalse(response.equals(copiedResponse));
83 copiedResponse.setCommonHeader(commonHeader);
84 assertTrue(response.equals(copiedResponse));
86 response.setStatus(null);
87 assertFalse(response.equals(copiedResponse));
88 copiedResponse.setStatus(null);
89 assertTrue(response.equals(copiedResponse));
90 response.setStatus(status);
91 assertFalse(response.equals(copiedResponse));
92 copiedResponse.setStatus(status);
93 assertTrue(response.equals(copiedResponse));
95 response.setPayload(new HashMap<String, Object>());
96 assertFalse(response.equals(copiedResponse));
97 copiedResponse.setPayload(new HashMap<String, Object>());
98 assertTrue(response.equals(copiedResponse));
99 response.setPayload(payload);
100 assertFalse(response.equals(copiedResponse));
101 copiedResponse.setPayload(payload);
102 assertTrue(response.equals(copiedResponse));