diff options
Diffstat (limited to 'controlloop/common/model-impl/so/src/test')
-rw-r--r-- | controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSOManager.java | 252 | ||||
-rwxr-xr-x | controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoPolicyExceptionHolder.java (renamed from controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoPolicyException.java) | 6 | ||||
-rwxr-xr-x | controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoRequestDetails.java | 106 | ||||
-rwxr-xr-x | controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoRequestError.java | 4 | ||||
-rwxr-xr-x | controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoResponseWrapper.java | 55 | ||||
-rwxr-xr-x | controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoServiceExceptionHolder.java (renamed from controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoServiceException.java) | 6 |
6 files changed, 421 insertions, 8 deletions
diff --git a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSOManager.java b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSOManager.java new file mode 100644 index 000000000..a2beb57b5 --- /dev/null +++ b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSOManager.java @@ -0,0 +1,252 @@ +/*- + * ============LICENSE_START======================================================= + * TestSOManager + * ================================================================================ + * Copyright (C) 2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.so; + +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.startsWith; +import static org.mockito.Mockito.*; + +import java.util.UUID; +import java.util.concurrent.Future; + +import org.drools.core.WorkingMemory; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.rest.RESTManager; +import org.onap.policy.rest.RESTManager.Pair; +import org.onap.policy.so.util.Serialization; + +public class TestSOManager { + private static WorkingMemory mockedWorkingMemory; + + private RESTManager mockedRESTManager; + + private Pair<Integer, String> httpResponsePutOK; + private Pair<Integer, String> httpResponseGetOK; + private Pair<Integer, String> httpResponsePostOK; + private Pair<Integer, String> httpResponseErr; + + private SORequest request; + private SOResponse response; + + @BeforeClass + public static void beforeTestSOManager() { + mockedWorkingMemory = mock(WorkingMemory.class); + } + + @Before + public void setupMockedRest() { + mockedRESTManager = mock(RESTManager.class); + + httpResponsePutOK = mockedRESTManager.new Pair<>(202, Serialization.gsonPretty.toJson(response)); + httpResponseGetOK = mockedRESTManager.new Pair<>(200, Serialization.gsonPretty.toJson(response)); + httpResponsePostOK = mockedRESTManager.new Pair<>(202, Serialization.gsonPretty.toJson(response)); + httpResponseErr = mockedRESTManager.new Pair<>(200, "{"); + } + + @Before + public void createRequestAndResponse() { + request = new SORequest(); + SORequestStatus requestStatus = new SORequestStatus(); + requestStatus.setRequestState("COMPLETE"); + request.setRequestStatus(requestStatus); + request.setRequestId(UUID.randomUUID()); + + response = new SOResponse(); + + SORequestReferences requestReferences = new SORequestReferences(); + String requestId = UUID.randomUUID().toString(); + requestReferences.setRequestId(requestId); + response.setRequestReferences(requestReferences); + + response.setRequest(request); + } + + @Test + public void testSOInitiation() { + assertNotNull(new SOManager()); + } + + @Test + public void testCreateModuleInstance() throws InterruptedException { + SOManager manager = new SOManager(); + manager.setRestManager(mockedRESTManager); + + assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "OK", request)); + + when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Null"), anyMap(), anyString(), anyString())) + .thenReturn(null); + assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "Null", request)); + + when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Not202"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponseErr); + assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "Not202", request)); + + when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetNull"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponsePutOK); + when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetNull"), anyMap())) + .thenReturn(null); + assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetNull", request)); + + when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetOK"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponsePutOK); + when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetOK"), anyMap())) + .thenReturn(httpResponseGetOK); + request.getRequestStatus().setRequestState("COMPLETE"); + SOResponse response = manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetOK", request); + assertNotNull(response); + assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState()); + + response.getRequest().getRequestStatus().setRequestState("FAILED"); + Pair<Integer, String> httpResponseGetOKRequestFailed = mockedRESTManager.new Pair<>(200, Serialization.gsonPretty.toJson(response)); + when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetOKReqFailed"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponsePutOK); + when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetOKReqFailed"), anyMap())) + .thenReturn(httpResponseGetOKRequestFailed); + response = manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetOKReqFailed", request); + assertNotNull(response); + assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState()); + + when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetBadJSON"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponsePutOK); + when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetBadJSON"), anyMap())) + .thenReturn(httpResponseErr); + assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetBadJSON", request)); + + response.getRequest().getRequestStatus().setRequestState("IN-PROGRESS"); + Pair<Integer, String> httpResponseGetOKRequestTimeout = mockedRESTManager.new Pair<>(200, Serialization.gsonPretty.toJson(response)); + when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetOKReqTimeout"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponsePutOK); + when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetOKReqTimeout"), anyMap())) + .thenReturn(httpResponseGetOKRequestTimeout); + + manager.setRestGetTimeout(10); + response = manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetOKReqTimeout", request); + assertNotNull(response); + assertEquals("IN-PROGRESS", response.getRequest().getRequestStatus().getRequestState()); + } + + @Test + public void testAsyncSORestCall() throws InterruptedException { + PolicyEngine.manager.getEnvironment().put("so.url", "http://somewhere.over.the.rainbow.null"); + PolicyEngine.manager.getEnvironment().put("so.username", "Dorothy"); + PolicyEngine.manager.getEnvironment().put("so.password", "OK"); + + SOManager manager = new SOManager(); + manager.setRestManager(mockedRESTManager); + + String serviceInstanceId = UUID.randomUUID().toString(); + String vnfInstanceId = UUID.randomUUID().toString(); + + when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow.null"), eq("policy"), eq("policy"), anyMap(), anyString(), anyString())) + .thenReturn(null); + + Future<?> asyncRestCallFuture = manager.asyncSORestCall(request.getRequestId().toString(), mockedWorkingMemory, serviceInstanceId, vnfInstanceId, request); + try { + assertNull(asyncRestCallFuture.get()); + } + catch (Exception e) { + fail("test should not throw an exception"); + } + + PolicyEngine.manager.getEnvironment().put("so.url", "http://somewhere.over.the.rainbow.err"); + when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow.err"), eq("policy"), eq("policy"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponseErr); + + asyncRestCallFuture = manager.asyncSORestCall(request.getRequestId().toString(), mockedWorkingMemory, serviceInstanceId, vnfInstanceId, request); + try { + assertNull(asyncRestCallFuture.get()); + } + catch (Exception e) { + System.err.println(e); + fail("test should not throw an exception"); + } + + PolicyEngine.manager.getEnvironment().put("so.url", "http://somewhere.over.the.rainbow.ok"); + when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow.ok"), eq("policy"), eq("policy"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponsePostOK); + + asyncRestCallFuture = manager.asyncSORestCall(request.getRequestId().toString(), mockedWorkingMemory, serviceInstanceId, vnfInstanceId, request); + try { + assertNull(asyncRestCallFuture.get()); + } + catch (Exception e) { + System.err.println(e); + fail("test should not throw an exception"); + } +/* + when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Null"), anyMap(), anyString(), anyString())) + .thenReturn(null); + assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "Null", request)); + + when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Not202"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponseErr); + assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "Not202", request)); + + when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetNull"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponsePutOK); + when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetNull"), anyMap())) + .thenReturn(null); + assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetNull", request)); + + when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetOK"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponsePutOK); + when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetOK"), anyMap())) + .thenReturn(httpResponseGetOK); + request.getRequestStatus().setRequestState("COMPLETE"); + SOResponse response = manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetOK", request); + assertNotNull(response); + assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState()); + + response.getRequest().getRequestStatus().setRequestState("FAILED"); + Pair<Integer, String> httpResponseGetOKRequestFailed = mockedRESTManager.new Pair<>(200, Serialization.gsonPretty.toJson(response)); + when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetOKReqFailed"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponsePutOK); + when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetOKReqFailed"), anyMap())) + .thenReturn(httpResponseGetOKRequestFailed); + response = manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetOKReqFailed", request); + assertNotNull(response); + assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState()); + + when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetBadJSON"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponsePutOK); + when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetBadJSON"), anyMap())) + .thenReturn(httpResponseErr); + assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetBadJSON", request)); + + response.getRequest().getRequestStatus().setRequestState("IN-PROGRESS"); + Pair<Integer, String> httpResponseGetOKRequestTimeout = mockedRESTManager.new Pair<>(200, Serialization.gsonPretty.toJson(response)); + when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetOKReqTimeout"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponsePutOK); + when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetOKReqTimeout"), anyMap())) + .thenReturn(httpResponseGetOKRequestTimeout); + + manager.setRestGetTimeout(10); + response = manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetOKReqTimeout", request); + assertNotNull(response); + assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState()); + */ + } +} diff --git a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoPolicyException.java b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoPolicyExceptionHolder.java index b2ba7f4d0..978ec8a59 100755 --- a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoPolicyException.java +++ b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoPolicyExceptionHolder.java @@ -25,11 +25,11 @@ import static org.junit.Assert.assertTrue; import org.junit.Test;
-public class TestSoPolicyException {
+public class TestSoPolicyExceptionHolder {
@Test
public void testConstructor() {
- SOPolicyException obj = new SOPolicyException();
+ SOPolicyExceptionHolder obj = new SOPolicyExceptionHolder();
assertTrue(obj.getMessageId() == null);
assertTrue(obj.getText() == null);
@@ -37,7 +37,7 @@ public class TestSoPolicyException { @Test
public void testSetGet() {
- SOPolicyException obj = new SOPolicyException();
+ SOPolicyExceptionHolder obj = new SOPolicyExceptionHolder();
obj.setMessageId("messageId");
assertEquals("messageId", obj.getMessageId());
diff --git a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoRequestDetails.java b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoRequestDetails.java index 5c3c1a411..42dfe0805 100755 --- a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoRequestDetails.java +++ b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoRequestDetails.java @@ -21,8 +21,14 @@ package org.onap.policy.so;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.util.ArrayList;
+import java.util.List;
+
import org.junit.Test;
public class TestSoRequestDetails {
@@ -65,4 +71,104 @@ public class TestSoRequestDetails { obj.setSubscriberInfo(subscriberInfo);
assertEquals(subscriberInfo, obj.getSubscriberInfo());
}
+
+ @Test
+ public void testSOMRequestDetailsMethods() {
+ SORequestDetails details = new SORequestDetails();
+ assertNotNull(details);
+ assertNotEquals(0, details.hashCode());
+
+ SOCloudConfiguration cloudConfiguration = new SOCloudConfiguration();
+ details.setCloudConfiguration(cloudConfiguration);
+ assertEquals(cloudConfiguration, details.getCloudConfiguration());
+ assertNotEquals(0, details.hashCode());
+
+ SOModelInfo modelInfo = new SOModelInfo();
+ details.setModelInfo(modelInfo);
+ assertEquals(modelInfo, details.getModelInfo());
+ assertNotEquals(0, details.hashCode());
+
+ List<SORelatedInstanceListElement> relatedInstanceList = new ArrayList<>();
+ details.setRelatedInstanceList(relatedInstanceList);
+ assertEquals(relatedInstanceList, details.getRelatedInstanceList());
+ assertNotEquals(0, details.hashCode());
+
+ SORequestInfo requestInfo = new SORequestInfo();
+ details.setRequestInfo(requestInfo);
+ assertEquals(requestInfo, details.getRequestInfo());
+ assertNotEquals(0, details.hashCode());
+
+ SORequestParameters requestParameters = new SORequestParameters();
+ details.setRequestParameters(requestParameters);
+ assertEquals(requestParameters, details.getRequestParameters());
+ assertNotEquals(0, details.hashCode());
+
+ SOSubscriberInfo subscriberInfo = new SOSubscriberInfo();
+ details.setSubscriberInfo(subscriberInfo);
+ assertEquals(subscriberInfo, details.getSubscriberInfo());
+ assertNotEquals(0, details.hashCode());
+
+ assertEquals("SORequestDetails [modelInfo=org.onap.policy.so", details.toString().substring(0, 46));
+
+ SORequestDetails copiedDetails = new SORequestDetails(details);
+
+ assertTrue(details.equals(details));
+ assertTrue(details.equals(copiedDetails));
+ assertFalse(details.equals(null));
+ assertFalse(details.equals("Hello"));
+
+ details.setCloudConfiguration(null);
+ assertFalse(details.equals(copiedDetails));
+ copiedDetails.setCloudConfiguration(null);
+ assertTrue(details.equals(copiedDetails));
+ details.setCloudConfiguration(cloudConfiguration);
+ assertFalse(details.equals(copiedDetails));
+ copiedDetails.setCloudConfiguration(cloudConfiguration);
+ assertTrue(details.equals(copiedDetails));
+
+ details.setModelInfo(null);
+ assertFalse(details.equals(copiedDetails));
+ copiedDetails.setModelInfo(null);
+ assertTrue(details.equals(copiedDetails));
+ details.setModelInfo(modelInfo);
+ assertFalse(details.equals(copiedDetails));
+ copiedDetails.setModelInfo(modelInfo);
+ assertTrue(details.equals(copiedDetails));
+
+ details.setRequestInfo(null);
+ assertFalse(details.equals(copiedDetails));
+ copiedDetails.setRequestInfo(null);
+ assertTrue(details.equals(copiedDetails));
+ details.setRequestInfo(requestInfo);
+ assertFalse(details.equals(copiedDetails));
+ copiedDetails.setRequestInfo(requestInfo);
+ assertTrue(details.equals(copiedDetails));
+
+ details.setRequestParameters(null);
+ assertFalse(details.equals(copiedDetails));
+ copiedDetails.setRequestParameters(null);
+ assertTrue(details.equals(copiedDetails));
+ details.setRequestParameters(requestParameters);
+ assertFalse(details.equals(copiedDetails));
+ copiedDetails.setRequestParameters(requestParameters);
+ assertTrue(details.equals(copiedDetails));
+
+ details.setSubscriberInfo(null);
+ assertFalse(details.equals(copiedDetails));
+ copiedDetails.setSubscriberInfo(null);
+ assertTrue(details.equals(copiedDetails));
+ details.setSubscriberInfo(subscriberInfo);
+ assertFalse(details.equals(copiedDetails));
+ copiedDetails.setSubscriberInfo(subscriberInfo);
+ assertTrue(details.equals(copiedDetails));
+
+ details.setRelatedInstanceList(null);
+ assertFalse(details.equals(copiedDetails));
+ copiedDetails.setRelatedInstanceList(null);
+ assertTrue(details.equals(copiedDetails));
+ details.setRelatedInstanceList(relatedInstanceList);
+ assertFalse(details.equals(copiedDetails));
+ copiedDetails.setRelatedInstanceList(relatedInstanceList);
+ assertTrue(details.equals(copiedDetails));
+ }
}
diff --git a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoRequestError.java b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoRequestError.java index 31f3b6c54..1108daf3d 100755 --- a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoRequestError.java +++ b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoRequestError.java @@ -39,11 +39,11 @@ public class TestSoRequestError { public void testSetGet() {
SORequestError obj = new SORequestError();
- SOPolicyException policyException = new SOPolicyException();
+ SOPolicyExceptionHolder policyException = new SOPolicyExceptionHolder();
obj.setPolicyException(policyException);
assertEquals(policyException, obj.getPolicyException());
- SOServiceException serviceException = new SOServiceException();
+ SOServiceExceptionHolder serviceException = new SOServiceExceptionHolder();
obj.setServiceException(serviceException);
assertEquals(serviceException, obj.getServiceException());
}
diff --git a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoResponseWrapper.java b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoResponseWrapper.java index 93549a21d..7b4830125 100755 --- a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoResponseWrapper.java +++ b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoResponseWrapper.java @@ -21,6 +21,11 @@ package org.onap.policy.so;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.UUID;
import org.junit.Test;
@@ -48,4 +53,54 @@ public class TestSoResponseWrapper { obj.setRequestID("id2");
assertEquals("id2", obj.getRequestID());
}
+
+ @SuppressWarnings("unlikely-arg-type")
+ @Test
+ public void testSOResponseWrapperMethods() {
+ String requestID = UUID.randomUUID().toString();
+ SOResponse response = new SOResponse();
+
+ SOResponseWrapper responseWrapper = new SOResponseWrapper(response, requestID);
+ assertNotNull(responseWrapper);
+ assertNotEquals(0, responseWrapper.hashCode());
+
+ assertEquals(response, responseWrapper.getSoResponse());
+
+ assertNotEquals(0, responseWrapper.hashCode());
+
+ assertEquals("SOResponseWrapper [SOResponse=org.onap.policy.", responseWrapper.toString().substring(0, 46));
+
+ SOResponseWrapper identicalResponseWrapper = new SOResponseWrapper(response, requestID);
+
+ assertEquals(responseWrapper, responseWrapper);
+ assertEquals(responseWrapper, identicalResponseWrapper);
+ assertNotEquals(null, responseWrapper);
+ assertNotEquals("Hello", responseWrapper);
+ assertFalse(responseWrapper.equals(null));
+ assertFalse(responseWrapper.equals("AString"));
+
+ assertEquals(new SOResponseWrapper(null, null), new SOResponseWrapper(null, null));
+ assertNotEquals(new SOResponseWrapper(null, null), identicalResponseWrapper);
+
+ assertNotEquals(0, new SOResponseWrapper(null, null).hashCode());
+
+ identicalResponseWrapper.setSoResponse(new SOResponse());
+ assertNotEquals(responseWrapper, identicalResponseWrapper);
+ identicalResponseWrapper.setSoResponse(response);
+ assertEquals(responseWrapper, identicalResponseWrapper);
+
+ identicalResponseWrapper.setRequestID(UUID.randomUUID().toString());
+ assertNotEquals(responseWrapper, identicalResponseWrapper);
+ identicalResponseWrapper.setRequestID(requestID);
+ assertEquals(responseWrapper, identicalResponseWrapper);
+
+ responseWrapper.setRequestID(null);
+ assertNotEquals(responseWrapper, identicalResponseWrapper);
+ identicalResponseWrapper.setRequestID(null);
+ assertEquals(responseWrapper, identicalResponseWrapper);
+ responseWrapper.setRequestID(requestID);
+ assertNotEquals(responseWrapper, identicalResponseWrapper);
+ identicalResponseWrapper.setRequestID(requestID);
+ assertEquals(responseWrapper, identicalResponseWrapper);
+ }
}
diff --git a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoServiceException.java b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoServiceExceptionHolder.java index cae8d1955..877ea7146 100755 --- a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoServiceException.java +++ b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoServiceExceptionHolder.java @@ -25,11 +25,11 @@ import static org.junit.Assert.assertTrue; import org.junit.Test;
-public class TestSoServiceException {
+public class TestSoServiceExceptionHolder {
@Test
public void testConstructor() {
- SOServiceException obj = new SOServiceException();
+ SOServiceExceptionHolder obj = new SOServiceExceptionHolder();
assertTrue(obj.getMessageId() == null);
assertTrue(obj.getText() == null);
@@ -39,7 +39,7 @@ public class TestSoServiceException { @Test
public void testSetGet() {
- SOServiceException obj = new SOServiceException();
+ SOServiceExceptionHolder obj = new SOServiceExceptionHolder();
obj.setMessageId("messageId");
assertEquals("messageId", obj.getMessageId());
|