migrate model-impl from drools-applications
[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     @Test
36     public void testConstructor() {
37         SoResponse response = new SoResponse();
38         SoResponseWrapper obj = new SoResponseWrapper(response, "reqID");
39
40         assertEquals(response, obj.getSoResponse());
41         assertEquals("reqID", obj.getRequestId());
42     }
43
44     @Test
45     public void testSetGet() {
46         SoResponse response = new SoResponse();
47         SoResponseWrapper obj = new SoResponseWrapper(response, "reqID");
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         assertEquals(responseWrapper,  responseWrapper);
76         assertEquals(responseWrapper,  identicalResponseWrapper);
77         assertNotEquals(null, responseWrapper);
78         assertNotEquals("Hello", responseWrapper);
79         assertFalse(responseWrapper.equals(null));
80         assertFalse(responseWrapper.equals("AString"));
81
82         assertEquals(new SoResponseWrapper(null, null), new SoResponseWrapper(null, null));
83         assertNotEquals(new SoResponseWrapper(null, null), identicalResponseWrapper);
84
85         assertNotEquals(0, new SoResponseWrapper(null, null).hashCode());
86
87         identicalResponseWrapper.setSoResponse(new SoResponse());
88         assertNotEquals(responseWrapper,  identicalResponseWrapper);
89         identicalResponseWrapper.setSoResponse(response);
90         assertEquals(responseWrapper,  identicalResponseWrapper);
91
92         identicalResponseWrapper.setRequestId(UUID.randomUUID().toString());
93         assertNotEquals(responseWrapper,  identicalResponseWrapper);
94         identicalResponseWrapper.setRequestId(requestId);
95         assertEquals(responseWrapper,  identicalResponseWrapper);
96
97         responseWrapper.setRequestId(null);
98         assertNotEquals(responseWrapper,  identicalResponseWrapper);
99         identicalResponseWrapper.setRequestId(null);
100         assertEquals(responseWrapper,  identicalResponseWrapper);
101         responseWrapper.setRequestId(requestId);
102         assertNotEquals(responseWrapper,  identicalResponseWrapper);
103         identicalResponseWrapper.setRequestId(requestId);
104         assertEquals(responseWrapper,  identicalResponseWrapper);
105     }
106 }