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