Merge "Add debugging of REST call"
[policy/drools-applications.git] / controlloop / common / 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  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.so;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotEquals;
26 import static org.junit.Assert.assertNotNull;
27
28 import java.util.UUID;
29
30 import org.junit.Test;
31
32 public class SoResponseWrapperTest {
33
34     @Test
35     public void testConstructor() {
36         SoResponse response = new SoResponse();
37         SoResponseWrapper obj = new SoResponseWrapper(response, "reqID");
38
39         assertEquals(response, obj.getSoResponse());
40         assertEquals("reqID", obj.getRequestId());
41     }
42
43     @Test
44     public void testSetGet() {
45         SoResponse response = new SoResponse();
46         SoResponseWrapper obj = new SoResponseWrapper(response, "reqID");
47
48         SoResponse response2 = new SoResponse();
49         response2.setHttpResponseCode(2008);
50         obj.setSoResponse(response2);
51         assertEquals(response2, obj.getSoResponse());
52
53         obj.setRequestId("id2");
54         assertEquals("id2", obj.getRequestId());
55     }
56
57     @Test
58     public void testSoResponseWrapperMethods() {
59         String requestId = UUID.randomUUID().toString();
60         SoResponse response = new SoResponse();
61
62         SoResponseWrapper responseWrapper = new SoResponseWrapper(response, requestId);
63         assertNotNull(responseWrapper);
64         assertNotEquals(0, responseWrapper.hashCode());
65
66         assertEquals(response, responseWrapper.getSoResponse());
67
68         assertNotEquals(0, responseWrapper.hashCode());
69
70         assertEquals("SOResponseWrapper [SOResponse=org.onap.policy.", responseWrapper.toString().substring(0,  46));
71
72         SoResponseWrapper identicalResponseWrapper = new SoResponseWrapper(response, requestId);
73
74         assertEquals(responseWrapper,  responseWrapper);
75         assertEquals(responseWrapper,  identicalResponseWrapper);
76         assertNotEquals(null, responseWrapper);
77         assertNotEquals("Hello", responseWrapper);
78         assertFalse(responseWrapper.equals(null));
79         assertFalse(responseWrapper.equals("AString"));
80         
81         assertEquals(new SoResponseWrapper(null, null), new SoResponseWrapper(null, null));
82         assertNotEquals(new SoResponseWrapper(null, null), identicalResponseWrapper);
83         
84         assertNotEquals(0, new SoResponseWrapper(null, null).hashCode());
85
86         identicalResponseWrapper.setSoResponse(new SoResponse());
87         assertNotEquals(responseWrapper,  identicalResponseWrapper);
88         identicalResponseWrapper.setSoResponse(response);
89         assertEquals(responseWrapper,  identicalResponseWrapper);
90         
91         identicalResponseWrapper.setRequestId(UUID.randomUUID().toString());
92         assertNotEquals(responseWrapper,  identicalResponseWrapper);
93         identicalResponseWrapper.setRequestId(requestId);
94         assertEquals(responseWrapper,  identicalResponseWrapper);
95         
96         responseWrapper.setRequestId(null);
97         assertNotEquals(responseWrapper,  identicalResponseWrapper);
98         identicalResponseWrapper.setRequestId(null);
99         assertEquals(responseWrapper,  identicalResponseWrapper);
100         responseWrapper.setRequestId(requestId);
101         assertNotEquals(responseWrapper,  identicalResponseWrapper);
102         identicalResponseWrapper.setRequestId(requestId);
103         assertEquals(responseWrapper,  identicalResponseWrapper);
104     }
105 }