Fix some sonars in policy-models
[policy/models.git] / models-interactions / model-impl / so / src / test / java / org / onap / policy / so / SoResponseWrapperTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * so
4  * ================================================================================
5  * Copyright (C) 2018-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.so;
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.UUID;
29 import org.junit.Test;
30
31 public class SoResponseWrapperTest {
32
33     private static final String REQ_ID = "reqID";
34
35     @Test
36     public void testConstructor() {
37         SoResponse response = new SoResponse();
38         SoResponseWrapper obj = new SoResponseWrapper(response, REQ_ID);
39
40         assertEquals(response, obj.getSoResponse());
41         assertEquals(REQ_ID, obj.getRequestId());
42     }
43
44     @Test
45     public void testSetGet() {
46         SoResponse response = new SoResponse();
47         SoResponseWrapper obj = new SoResponseWrapper(response, REQ_ID);
48
49         SoResponse response2 = new SoResponse();
50         response2.setHttpResponseCode(2008);
51         obj.setSoResponse(response2);
52         assertEquals(response2, obj.getSoResponse());
53
54         obj.setRequestId("id2");
55         assertEquals("id2", obj.getRequestId());
56     }
57
58     @Test
59     public void testSoResponseWrapperMethods() {
60         String requestId = UUID.randomUUID().toString();
61         SoResponse response = new SoResponse();
62
63         SoResponseWrapper responseWrapper = new SoResponseWrapper(response, requestId);
64         assertNotNull(responseWrapper);
65         assertNotEquals(0, responseWrapper.hashCode());
66
67         assertEquals(response, responseWrapper.getSoResponse());
68
69         assertNotEquals(0, responseWrapper.hashCode());
70
71         assertEquals("SOResponseWrapper [SOResponse=org.onap.policy.", responseWrapper.toString().substring(0,  46));
72
73         SoResponseWrapper identicalResponseWrapper = new SoResponseWrapper(response, requestId);
74
75         /*
76          * Disabling sonar because we are purposely checking various branches of the
77          * equals() method.
78          */
79         assertEquals(responseWrapper,  responseWrapper);        // NOSONAR
80         assertEquals(responseWrapper,  identicalResponseWrapper);
81         assertNotEquals(null, responseWrapper);
82         assertNotEquals("Hello", responseWrapper);              // NOSONAR
83         assertNotEquals(responseWrapper, null);
84         assertNotEquals(responseWrapper, "AString");            // NOSONAR
85
86         assertEquals(new SoResponseWrapper(null, null), new SoResponseWrapper(null, null));
87         assertNotEquals(new SoResponseWrapper(null, null), identicalResponseWrapper);
88
89         assertNotEquals(0, new SoResponseWrapper(null, null).hashCode());
90
91         identicalResponseWrapper.setSoResponse(new SoResponse());
92         assertNotEquals(responseWrapper,  identicalResponseWrapper);
93         identicalResponseWrapper.setSoResponse(response);
94         assertEquals(responseWrapper,  identicalResponseWrapper);
95
96         identicalResponseWrapper.setRequestId(UUID.randomUUID().toString());
97         assertNotEquals(responseWrapper,  identicalResponseWrapper);
98         identicalResponseWrapper.setRequestId(requestId);
99         assertEquals(responseWrapper,  identicalResponseWrapper);
100
101         responseWrapper.setRequestId(null);
102         assertNotEquals(responseWrapper,  identicalResponseWrapper);
103         identicalResponseWrapper.setRequestId(null);
104         assertEquals(responseWrapper,  identicalResponseWrapper);
105         responseWrapper.setRequestId(requestId);
106         assertNotEquals(responseWrapper,  identicalResponseWrapper);
107         identicalResponseWrapper.setRequestId(requestId);
108         assertEquals(responseWrapper,  identicalResponseWrapper);
109     }
110 }