2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.so;
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;
29 import java.util.UUID;
31 import org.junit.Test;
33 public class SoResponseWrapperTest {
36 public void testConstructor() {
37 SoResponse response = new SoResponse();
38 SoResponseWrapper obj = new SoResponseWrapper(response, "reqID");
40 assertEquals(response, obj.getSoResponse());
41 assertEquals("reqID", obj.getRequestId());
45 public void testSetGet() {
46 SoResponse response = new SoResponse();
47 SoResponseWrapper obj = new SoResponseWrapper(response, "reqID");
49 SoResponse response2 = new SoResponse();
50 response2.setHttpResponseCode(2008);
51 obj.setSoResponse(response2);
52 assertEquals(response2, obj.getSoResponse());
54 obj.setRequestId("id2");
55 assertEquals("id2", obj.getRequestId());
59 public void testSoResponseWrapperMethods() {
60 String requestId = UUID.randomUUID().toString();
61 SoResponse response = new SoResponse();
63 SoResponseWrapper responseWrapper = new SoResponseWrapper(response, requestId);
64 assertNotNull(responseWrapper);
65 assertNotEquals(0, responseWrapper.hashCode());
67 assertEquals(response, responseWrapper.getSoResponse());
69 assertNotEquals(0, responseWrapper.hashCode());
71 assertEquals("SOResponseWrapper [SOResponse=org.onap.policy.", responseWrapper.toString().substring(0, 46));
73 SoResponseWrapper identicalResponseWrapper = new SoResponseWrapper(response, requestId);
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"));
82 assertEquals(new SoResponseWrapper(null, null), new SoResponseWrapper(null, null));
83 assertNotEquals(new SoResponseWrapper(null, null), identicalResponseWrapper);
85 assertNotEquals(0, new SoResponseWrapper(null, null).hashCode());
87 identicalResponseWrapper.setSoResponse(new SoResponse());
88 assertNotEquals(responseWrapper, identicalResponseWrapper);
89 identicalResponseWrapper.setSoResponse(response);
90 assertEquals(responseWrapper, identicalResponseWrapper);
92 identicalResponseWrapper.setRequestId(UUID.randomUUID().toString());
93 assertNotEquals(responseWrapper, identicalResponseWrapper);
94 identicalResponseWrapper.setRequestId(requestId);
95 assertEquals(responseWrapper, identicalResponseWrapper);
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);