2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.so;
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;
28 import java.util.UUID;
30 import org.junit.Test;
32 public class SoResponseWrapperTest {
35 public void testConstructor() {
36 SoResponse response = new SoResponse();
37 SoResponseWrapper obj = new SoResponseWrapper(response, "reqID");
39 assertEquals(response, obj.getSoResponse());
40 assertEquals("reqID", obj.getRequestId());
44 public void testSetGet() {
45 SoResponse response = new SoResponse();
46 SoResponseWrapper obj = new SoResponseWrapper(response, "reqID");
48 SoResponse response2 = new SoResponse();
49 response2.setHttpResponseCode(2008);
50 obj.setSoResponse(response2);
51 assertEquals(response2, obj.getSoResponse());
53 obj.setRequestId("id2");
54 assertEquals("id2", obj.getRequestId());
58 public void testSoResponseWrapperMethods() {
59 String requestId = UUID.randomUUID().toString();
60 SoResponse response = new SoResponse();
62 SoResponseWrapper responseWrapper = new SoResponseWrapper(response, requestId);
63 assertNotNull(responseWrapper);
64 assertNotEquals(0, responseWrapper.hashCode());
66 assertEquals(response, responseWrapper.getSoResponse());
68 assertNotEquals(0, responseWrapper.hashCode());
70 assertEquals("SOResponseWrapper [SOResponse=org.onap.policy.", responseWrapper.toString().substring(0, 46));
72 SoResponseWrapper identicalResponseWrapper = new SoResponseWrapper(response, requestId);
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"));
81 assertEquals(new SoResponseWrapper(null, null), new SoResponseWrapper(null, null));
82 assertNotEquals(new SoResponseWrapper(null, null), identicalResponseWrapper);
84 assertNotEquals(0, new SoResponseWrapper(null, null).hashCode());
86 identicalResponseWrapper.setSoResponse(new SoResponse());
87 assertNotEquals(responseWrapper, identicalResponseWrapper);
88 identicalResponseWrapper.setSoResponse(response);
89 assertEquals(responseWrapper, identicalResponseWrapper);
91 identicalResponseWrapper.setRequestId(UUID.randomUUID().toString());
92 assertNotEquals(responseWrapper, identicalResponseWrapper);
93 identicalResponseWrapper.setRequestId(requestId);
94 assertEquals(responseWrapper, identicalResponseWrapper);
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);