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;
30 import org.junit.Test;
32 public class SoResponseWrapperTest {
34 private static final String REQ_ID = "reqID";
37 public void testConstructor() {
38 SoResponse response = new SoResponse();
39 SoResponseWrapper obj = new SoResponseWrapper(response, REQ_ID);
41 assertEquals(response, obj.getSoResponse());
42 assertEquals(REQ_ID, obj.getRequestId());
46 public void testSetGet() {
47 SoResponse response = new SoResponse();
48 SoResponseWrapper obj = new SoResponseWrapper(response, REQ_ID);
50 SoResponse response2 = new SoResponse();
51 response2.setHttpResponseCode(2008);
52 obj.setSoResponse(response2);
53 assertEquals(response2, obj.getSoResponse());
55 obj.setRequestId("id2");
56 assertEquals("id2", obj.getRequestId());
60 public void testSoResponseWrapperMethods() {
61 String requestId = UUID.randomUUID().toString();
62 SoResponse response = new SoResponse();
64 SoResponseWrapper responseWrapper = new SoResponseWrapper(response, requestId);
65 assertNotNull(responseWrapper);
66 assertNotEquals(0, responseWrapper.hashCode());
68 assertEquals(response, responseWrapper.getSoResponse());
70 assertNotEquals(0, responseWrapper.hashCode());
72 assertEquals("SOResponseWrapper [SOResponse=org.onap.policy.", responseWrapper.toString().substring(0, 46));
74 SoResponseWrapper identicalResponseWrapper = new SoResponseWrapper(response, requestId);
76 assertEquals(responseWrapper, responseWrapper);
77 assertEquals(responseWrapper, identicalResponseWrapper);
78 assertNotEquals(null, responseWrapper);
79 assertNotEquals("Hello", responseWrapper);
80 assertFalse(responseWrapper.equals(null));
81 assertFalse(responseWrapper.equals("AString"));
83 assertEquals(new SoResponseWrapper(null, null), new SoResponseWrapper(null, null));
84 assertNotEquals(new SoResponseWrapper(null, null), identicalResponseWrapper);
86 assertNotEquals(0, new SoResponseWrapper(null, null).hashCode());
88 identicalResponseWrapper.setSoResponse(new SoResponse());
89 assertNotEquals(responseWrapper, identicalResponseWrapper);
90 identicalResponseWrapper.setSoResponse(response);
91 assertEquals(responseWrapper, identicalResponseWrapper);
93 identicalResponseWrapper.setRequestId(UUID.randomUUID().toString());
94 assertNotEquals(responseWrapper, identicalResponseWrapper);
95 identicalResponseWrapper.setRequestId(requestId);
96 assertEquals(responseWrapper, identicalResponseWrapper);
98 responseWrapper.setRequestId(null);
99 assertNotEquals(responseWrapper, identicalResponseWrapper);
100 identicalResponseWrapper.setRequestId(null);
101 assertEquals(responseWrapper, identicalResponseWrapper);
102 responseWrapper.setRequestId(requestId);
103 assertNotEquals(responseWrapper, identicalResponseWrapper);
104 identicalResponseWrapper.setRequestId(requestId);
105 assertEquals(responseWrapper, identicalResponseWrapper);