Fix some sonars in policy-models
[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-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
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.assertNotEquals;
26 import static org.junit.Assert.assertNotNull;
27
28 import java.util.HashMap;
29 import java.util.Map;
30 import org.junit.Test;
31
32 public class ResponseTest {
33
34     @Test
35     public void testResonse() {
36         Response response = new Response();
37         assertNotNull(response);
38         assertNotNull(new Response(new Request()));
39         assertNotEquals(0, response.hashCode());
40
41         CommonHeader commonHeader = new CommonHeader();
42
43         Request request = new Request();
44         request.setCommonHeader(commonHeader);
45         assertNotNull(new Response(request));
46
47         response.setCommonHeader(commonHeader);
48         assertEquals(commonHeader, response.getCommonHeader());
49
50         ResponseStatus status = new ResponseStatus();
51         response.setStatus(status);
52         assertEquals(status, response.getStatus());
53
54         Map<String, Object> payload = new HashMap<>();
55         payload.put("North", "Good Witch");
56         payload.put("West", "Bad Witch");
57
58         response.setPayload(payload);
59         assertEquals(payload, response.getPayload());
60
61         assertNotEquals(0, response.hashCode());
62
63         assertEquals("Response [CommonHeader=CommonHeader [TimeStamp=", response.toString().substring(0, 47));
64
65         Response copiedResponse = new Response();
66         copiedResponse.setCommonHeader(response.getCommonHeader());
67         copiedResponse.setStatus(response.getStatus());
68         copiedResponse.setPayload(response.getPayload());
69
70         /*
71          * Disabling sonar to test equals().
72          */
73         assertEquals(response, response);           // NOSONAR
74         assertEquals(response, copiedResponse);
75         assertNotEquals(response, null);
76         assertNotEquals(response, "Hello");         // NOSONAR
77
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);
86
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);
95
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);
104     }
105 }