Fix some sonars in policy-models
[policy/models.git] / models-interactions / model-impl / sdnr / src / test / java / org / onap / policy / sdnr / PciResponseTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * sdnr
4  * ================================================================================
5  * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Nordix Foundation.
7  * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.sdnr;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNotEquals;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertNull;
30
31 import org.junit.Test;
32
33 public class PciResponseTest {
34
35     Status status = new Status(0, "");
36
37     String responsePayload = "";
38     String requestPayload = "";
39
40
41     @Test
42     public void testHashCode() {
43         PciResponse response = new PciResponse();
44         assertNotEquals(0, response.hashCode());
45         response.setCommonHeader(new PciCommonHeader());
46         assertNotEquals(0, response.hashCode());
47         response.setPayload(responsePayload);
48         assertNotEquals(0, response.hashCode());
49         response.setStatus(null);
50         assertNotEquals(0, response.hashCode());
51     }
52
53     @Test
54     public void testPciResponse() {
55         PciResponse response = new PciResponse();
56         assertNull(response.getCommonHeader());
57         assertNull(response.getPayload());
58         assertNotNull(response.getStatus());
59     }
60
61     @Test
62     public void testToString() {
63         PciResponse response = new PciResponse();
64         assertFalse(response.toString().isEmpty());
65     }
66
67     @Test
68     public void testEqualsObject() {
69         PciResponse response = new PciResponse();
70         assertEquals(response, response);
71         assertNotEquals(response, null);
72         assertNotEquals(response, new Object());
73
74         PciResponse response2 = new PciResponse();
75         assertEquals(response, response2);
76
77         response.setCommonHeader(new PciCommonHeader());
78         assertNotEquals(response, response2);
79         response2.setCommonHeader(response.getCommonHeader());
80         assertEquals(response, response2);
81
82         response.setPayload(responsePayload);
83         assertNotEquals(response, response2);
84         response2.setPayload(response.getPayload());
85         assertEquals(response, response2);
86
87         response.setCommonHeader(null);
88         assertNotEquals(response, response2);
89         response2.setCommonHeader(null);
90         assertEquals(response, response2);
91
92         response.setPayload(null);
93         assertNotEquals(response, response2);
94         response2.setPayload(response.getPayload());
95         assertEquals(response, response2);
96
97         response.setStatus(null);
98         assertNotEquals(response, response2);
99         response2.setStatus(response.getStatus());
100         assertEquals(response, response2);
101
102         Status stat = new Status();
103         stat.setCode(5);
104         response.setStatus(stat);
105         response2.setStatus(new Status());
106         assertNotEquals(response, response2);
107     }
108
109     @Test
110     public void testResponseRequest() {
111         PciRequest request = new PciRequest();
112         request.setCommonHeader(new PciCommonHeader());
113         request.setPayload(requestPayload);
114
115         PciResponse response = new PciResponse(request);
116
117         assertEquals(response.getCommonHeader(), request.getCommonHeader());
118     }
119
120 }