Fix sonar issues in models: sdc to vfc
[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 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.assertFalse;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertTrue;
29
30 import org.junit.Test;
31
32 public class PciResponseTest {
33
34     Status status = new Status(0, "");
35
36     String responsePayload = "";
37     String requestPayload = "";
38
39
40     @Test
41     public void testHashCode() {
42         PciResponse response = new PciResponse();
43         assertTrue(response.hashCode() != 0);
44         response.setCommonHeader(new PciCommonHeader());
45         assertTrue(response.hashCode() != 0);
46         response.setPayload(responsePayload);
47         assertTrue(response.hashCode() != 0);
48         response.setStatus(null);
49         assertTrue(response.hashCode() != 0);
50     }
51
52     @Test
53     public void testPciResponse() {
54         PciResponse response = new PciResponse();
55         assertNull(response.getCommonHeader());
56         assertNull(response.getPayload());
57         assertNotNull(response.getStatus());
58     }
59
60     @Test
61     public void testToString() {
62         PciResponse response = new PciResponse();
63         assertFalse(response.toString().isEmpty());
64     }
65
66     @Test
67     public void testEqualsObject() {
68         PciResponse response = new PciResponse();
69         assertTrue(response.equals(response));
70         assertFalse(response.equals(null));
71         assertFalse(response.equals(new Object()));
72
73         PciResponse response2 = new PciResponse();
74         assertTrue(response.equals(response2));
75
76         response.setCommonHeader(new PciCommonHeader());
77         assertFalse(response.equals(response2));
78         response2.setCommonHeader(response.getCommonHeader());
79         assertTrue(response.equals(response2));
80
81         response.setPayload(responsePayload);
82         assertFalse(response.equals(response2));
83         response2.setPayload(response.getPayload());
84         assertTrue(response.equals(response2));
85
86         response.setCommonHeader(null);
87         assertFalse(response.equals(response2));
88         response2.setCommonHeader(null);
89         assertTrue(response.equals(response2));
90
91         response.setPayload(null);
92         assertFalse(response.equals(response2));
93         response2.setPayload(response.getPayload());
94         assertTrue(response.equals(response2));
95
96         response.setStatus(null);
97         assertFalse(response.equals(response2));
98         response2.setStatus(response.getStatus());
99         assertTrue(response.equals(response2));
100
101         Status stat = new Status();
102         stat.setCode(5);
103         response.setStatus(stat);
104         response2.setStatus(new Status());
105         assertFalse(response.equals(response2));
106     }
107
108     @Test
109     public void testResponseRequest() {
110         PciRequest request = new PciRequest();
111         request.setCommonHeader(new PciCommonHeader());
112         request.setPayload(requestPayload);
113
114         PciResponse response = new PciResponse(request);
115
116         assertTrue(response.getCommonHeader().equals(request.getCommonHeader()));
117     }
118
119 }