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 {
35 private static final String REQ_ID = "reqID";
38 public void testConstructor() {
39 SoResponse response = new SoResponse();
40 SoResponseWrapper obj = new SoResponseWrapper(response, REQ_ID);
42 assertEquals(response, obj.getSoResponse());
43 assertEquals(REQ_ID, obj.getRequestId());
47 public void testSetGet() {
48 SoResponse response = new SoResponse();
49 SoResponseWrapper obj = new SoResponseWrapper(response, REQ_ID);
51 SoResponse response2 = new SoResponse();
52 response2.setHttpResponseCode(2008);
53 obj.setSoResponse(response2);
54 assertEquals(response2, obj.getSoResponse());
56 obj.setRequestId("id2");
57 assertEquals("id2", obj.getRequestId());
61 public void testSoResponseWrapperMethods() {
62 String requestId = UUID.randomUUID().toString();
63 SoResponse response = new SoResponse();
65 SoResponseWrapper responseWrapper = new SoResponseWrapper(response, requestId);
66 assertNotNull(responseWrapper);
67 assertNotEquals(0, responseWrapper.hashCode());
69 assertEquals(response, responseWrapper.getSoResponse());
71 assertNotEquals(0, responseWrapper.hashCode());
73 assertEquals("SOResponseWrapper [SOResponse=org.onap.policy.", responseWrapper.toString().substring(0, 46));
75 SoResponseWrapper identicalResponseWrapper = new SoResponseWrapper(response, requestId);
77 assertEquals(responseWrapper, responseWrapper);
78 assertEquals(responseWrapper, identicalResponseWrapper);
79 assertNotEquals(null, responseWrapper);
80 assertNotEquals("Hello", responseWrapper);
81 assertFalse(responseWrapper.equals(null));
82 assertFalse(responseWrapper.equals("AString"));
84 assertEquals(new SoResponseWrapper(null, null), new SoResponseWrapper(null, null));
85 assertNotEquals(new SoResponseWrapper(null, null), identicalResponseWrapper);
87 assertNotEquals(0, new SoResponseWrapper(null, null).hashCode());
89 identicalResponseWrapper.setSoResponse(new SoResponse());
90 assertNotEquals(responseWrapper, identicalResponseWrapper);
91 identicalResponseWrapper.setSoResponse(response);
92 assertEquals(responseWrapper, identicalResponseWrapper);
94 identicalResponseWrapper.setRequestId(UUID.randomUUID().toString());
95 assertNotEquals(responseWrapper, identicalResponseWrapper);
96 identicalResponseWrapper.setRequestId(requestId);
97 assertEquals(responseWrapper, identicalResponseWrapper);
99 responseWrapper.setRequestId(null);
100 assertNotEquals(responseWrapper, identicalResponseWrapper);
101 identicalResponseWrapper.setRequestId(null);
102 assertEquals(responseWrapper, identicalResponseWrapper);
103 responseWrapper.setRequestId(requestId);
104 assertNotEquals(responseWrapper, identicalResponseWrapper);
105 identicalResponseWrapper.setRequestId(requestId);
106 assertEquals(responseWrapper, identicalResponseWrapper);