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);
76 * Disabling sonar because we are purposely checking various branches of the
79 assertEquals(responseWrapper, responseWrapper); // NOSONAR
80 assertEquals(responseWrapper, identicalResponseWrapper);
81 assertNotEquals(null, responseWrapper);
82 assertNotEquals("Hello", responseWrapper); // NOSONAR
83 assertNotEquals(responseWrapper, null);
84 assertNotEquals(responseWrapper, "AString"); // NOSONAR
86 assertEquals(new SoResponseWrapper(null, null), new SoResponseWrapper(null, null));
87 assertNotEquals(new SoResponseWrapper(null, null), identicalResponseWrapper);
89 assertNotEquals(0, new SoResponseWrapper(null, null).hashCode());
91 identicalResponseWrapper.setSoResponse(new SoResponse());
92 assertNotEquals(responseWrapper, identicalResponseWrapper);
93 identicalResponseWrapper.setSoResponse(response);
94 assertEquals(responseWrapper, identicalResponseWrapper);
96 identicalResponseWrapper.setRequestId(UUID.randomUUID().toString());
97 assertNotEquals(responseWrapper, identicalResponseWrapper);
98 identicalResponseWrapper.setRequestId(requestId);
99 assertEquals(responseWrapper, identicalResponseWrapper);
101 responseWrapper.setRequestId(null);
102 assertNotEquals(responseWrapper, identicalResponseWrapper);
103 identicalResponseWrapper.setRequestId(null);
104 assertEquals(responseWrapper, identicalResponseWrapper);
105 responseWrapper.setRequestId(requestId);
106 assertNotEquals(responseWrapper, identicalResponseWrapper);
107 identicalResponseWrapper.setRequestId(requestId);
108 assertEquals(responseWrapper, identicalResponseWrapper);