Changes for Checkstyle 8.32
[policy/models.git] / models-interactions / model-impl / appc / src / test / java / org / onap / policy / appc / ResponseTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * appc
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.policy.appc;
23
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;
29
30 import java.util.HashMap;
31 import java.util.Map;
32 import org.junit.Test;
33
34 public class ResponseTest {
35
36     @Test
37     public void testResonse() {
38         Response response = new Response();
39         assertNotNull(response);
40         assertNotNull(new Response(new Request()));
41         assertNotEquals(0, response.hashCode());
42
43         CommonHeader commonHeader = new CommonHeader();
44
45         Request request = new Request();
46         request.setCommonHeader(commonHeader);
47         assertNotNull(new Response(request));
48
49         response.setCommonHeader(commonHeader);
50         assertEquals(commonHeader, response.getCommonHeader());
51
52         ResponseStatus status = new ResponseStatus();
53         response.setStatus(status);
54         assertEquals(status, response.getStatus());
55
56         Map<String, Object> payload = new HashMap<>();
57         payload.put("North", "Good Witch");
58         payload.put("West", "Bad Witch");
59
60         response.setPayload(payload);
61         assertEquals(payload, response.getPayload());
62
63         assertNotEquals(0, response.hashCode());
64
65         assertEquals("Response [CommonHeader=CommonHeader [TimeStamp=", response.toString().substring(0, 47));
66
67         Response copiedResponse = new Response();
68         copiedResponse.setCommonHeader(response.getCommonHeader());
69         copiedResponse.setStatus(response.getStatus());
70         copiedResponse.setPayload(response.getPayload());
71
72         assertTrue(response.equals(response));
73         assertTrue(response.equals(copiedResponse));
74         assertFalse(response.equals(null));
75         assertFalse(response.equals("Hello"));
76
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));
85
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));
94
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));
103     }
104 }