2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018-2020 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.assertNotEquals;
26 import static org.junit.Assert.assertNotNull;
28 import java.util.UUID;
29 import org.junit.Test;
31 public class SoResponseWrapperTest {
33 private static final String REQ_ID = "reqID";
36 public void testConstructor() {
37 SoResponse response = new SoResponse();
38 SoResponseWrapper obj = new SoResponseWrapper(response, REQ_ID);
40 assertEquals(response, obj.getSoResponse());
41 assertEquals(REQ_ID, obj.getRequestId());
45 public void testSetGet() {
46 SoResponse response = new SoResponse();
47 SoResponseWrapper obj = new SoResponseWrapper(response, REQ_ID);
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, (Object) responseWrapper);
76 assertEquals(responseWrapper, identicalResponseWrapper);
77 assertNotEquals(responseWrapper, null);
78 assertNotEquals(responseWrapper, (Object) "AString");
80 assertEquals(new SoResponseWrapper(null, null), new SoResponseWrapper(null, null));
81 assertNotEquals(new SoResponseWrapper(null, null), identicalResponseWrapper);
83 assertNotEquals(0, new SoResponseWrapper(null, null).hashCode());
85 identicalResponseWrapper.setSoResponse(new SoResponse());
86 assertNotEquals(responseWrapper, identicalResponseWrapper);
87 identicalResponseWrapper.setSoResponse(response);
88 assertEquals(responseWrapper, identicalResponseWrapper);
90 identicalResponseWrapper.setRequestId(UUID.randomUUID().toString());
91 assertNotEquals(responseWrapper, identicalResponseWrapper);
92 identicalResponseWrapper.setRequestId(requestId);
93 assertEquals(responseWrapper, identicalResponseWrapper);
95 responseWrapper.setRequestId(null);
96 assertNotEquals(responseWrapper, identicalResponseWrapper);
97 identicalResponseWrapper.setRequestId(null);
98 assertEquals(responseWrapper, identicalResponseWrapper);
99 responseWrapper.setRequestId(requestId);
100 assertNotEquals(responseWrapper, identicalResponseWrapper);
101 identicalResponseWrapper.setRequestId(requestId);
102 assertEquals(responseWrapper, identicalResponseWrapper);