Changes for Checkstyle 8.32
[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-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.so;
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
29 import java.util.UUID;
30 import org.junit.Test;
31
32 public class SoResponseWrapperTest {
33
34     private static final String REQ_ID = "reqID";
35
36     @Test
37     public void testConstructor() {
38         SoResponse response = new SoResponse();
39         SoResponseWrapper obj = new SoResponseWrapper(response, REQ_ID);
40
41         assertEquals(response, obj.getSoResponse());
42         assertEquals(REQ_ID, obj.getRequestId());
43     }
44
45     @Test
46     public void testSetGet() {
47         SoResponse response = new SoResponse();
48         SoResponseWrapper obj = new SoResponseWrapper(response, REQ_ID);
49
50         SoResponse response2 = new SoResponse();
51         response2.setHttpResponseCode(2008);
52         obj.setSoResponse(response2);
53         assertEquals(response2, obj.getSoResponse());
54
55         obj.setRequestId("id2");
56         assertEquals("id2", obj.getRequestId());
57     }
58
59     @Test
60     public void testSoResponseWrapperMethods() {
61         String requestId = UUID.randomUUID().toString();
62         SoResponse response = new SoResponse();
63
64         SoResponseWrapper responseWrapper = new SoResponseWrapper(response, requestId);
65         assertNotNull(responseWrapper);
66         assertNotEquals(0, responseWrapper.hashCode());
67
68         assertEquals(response, responseWrapper.getSoResponse());
69
70         assertNotEquals(0, responseWrapper.hashCode());
71
72         assertEquals("SOResponseWrapper [SOResponse=org.onap.policy.", responseWrapper.toString().substring(0,  46));
73
74         SoResponseWrapper identicalResponseWrapper = new SoResponseWrapper(response, requestId);
75
76         assertEquals(responseWrapper,  responseWrapper);
77         assertEquals(responseWrapper,  identicalResponseWrapper);
78         assertNotEquals(null, responseWrapper);
79         assertNotEquals("Hello", responseWrapper);
80         assertFalse(responseWrapper.equals(null));
81         assertFalse(responseWrapper.equals("AString"));
82
83         assertEquals(new SoResponseWrapper(null, null), new SoResponseWrapper(null, null));
84         assertNotEquals(new SoResponseWrapper(null, null), identicalResponseWrapper);
85
86         assertNotEquals(0, new SoResponseWrapper(null, null).hashCode());
87
88         identicalResponseWrapper.setSoResponse(new SoResponse());
89         assertNotEquals(responseWrapper,  identicalResponseWrapper);
90         identicalResponseWrapper.setSoResponse(response);
91         assertEquals(responseWrapper,  identicalResponseWrapper);
92
93         identicalResponseWrapper.setRequestId(UUID.randomUUID().toString());
94         assertNotEquals(responseWrapper,  identicalResponseWrapper);
95         identicalResponseWrapper.setRequestId(requestId);
96         assertEquals(responseWrapper,  identicalResponseWrapper);
97
98         responseWrapper.setRequestId(null);
99         assertNotEquals(responseWrapper,  identicalResponseWrapper);
100         identicalResponseWrapper.setRequestId(null);
101         assertEquals(responseWrapper,  identicalResponseWrapper);
102         responseWrapper.setRequestId(requestId);
103         assertNotEquals(responseWrapper,  identicalResponseWrapper);
104         identicalResponseWrapper.setRequestId(requestId);
105         assertEquals(responseWrapper,  identicalResponseWrapper);
106     }
107 }