aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-06-14 19:20:55 -0400
committerJim Hahn <jrh3@att.com>2019-06-17 12:31:32 -0400
commitba6267f5bd58dd7a3a0d6363e7ac4c27705e9f40 (patch)
tree658afb8b0500180302e837b0f90e0372c82b7062 /models-interactions
parentf59ec395bf1e41df894f884e70ff3185280668c0 (diff)
Fix sonar issues in models: sdc to vfc
sdc sdnc snr so vfc Still haven't done the "rest" project yet, as still awaiting removal of www.examples.org. Change-Id: Icc4948799e2423bd4568232ee5629b88b7ecb996 Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions')
-rw-r--r--models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceInstanceTest.java22
-rw-r--r--models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceTest.java9
-rw-r--r--models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceInstanceTest.java22
-rw-r--r--models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceTest.java9
-rw-r--r--models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java3
-rw-r--r--models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/util/Serialization.java8
-rw-r--r--models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java20
-rw-r--r--models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java93
-rw-r--r--models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciCommonHeader.java3
-rw-r--r--models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequest.java5
-rw-r--r--models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java20
-rw-r--r--models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java11
-rw-r--r--models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java7
-rw-r--r--models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java11
-rw-r--r--models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java47
-rw-r--r--models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/SdnrTest.java9
-rw-r--r--models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java1
-rw-r--r--models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoDummyServer.java18
-rw-r--r--models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java326
-rw-r--r--models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestInfoTest.java24
-rw-r--r--models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java8
-rw-r--r--models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java9
-rw-r--r--models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/DemoTest.java14
-rw-r--r--models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java84
24 files changed, 366 insertions, 417 deletions
diff --git a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceInstanceTest.java b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceInstanceTest.java
index 940963565..8ae0084f6 100644
--- a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceInstanceTest.java
+++ b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceInstanceTest.java
@@ -30,6 +30,10 @@ import org.junit.Test;
public class ResourceInstanceTest {
+ private static final String RESOURCE = "resource";
+ private static final String INSTANCE = "instance";
+ private static final String VERSION_000 = "0.0.0";
+
@Test
public void testConstructors() {
ResourceInstance ri = new ResourceInstance();
@@ -111,11 +115,11 @@ public class ResourceInstanceTest {
assertTrue(ri1.equals(ri2));
assertTrue(ri2.equals(ri1));
- ri1.setResourceInstanceName("instance");
- ri1.setResourceName("resource");
+ ri1.setResourceInstanceName(INSTANCE);
+ ri1.setResourceName(RESOURCE);
ri1.setResourceInvariantUUID(UUID.randomUUID());
ri1.setResourceInvariantUUID(UUID.randomUUID());
- ri1.setResourceVersion("0.0.0");
+ ri1.setResourceVersion(VERSION_000);
ri1.setResourceType(ResourceType.VL);
ri2 = new ResourceInstance(ri1);
assertTrue(ri1.equals(ri2));
@@ -128,11 +132,11 @@ public class ResourceInstanceTest {
ResourceInstance ri2 = new ResourceInstance(ri1);
assertEquals(ri1.toString(), ri2.toString());
- ri1.setResourceInstanceName("instance");
- ri1.setResourceName("resource");
+ ri1.setResourceInstanceName(INSTANCE);
+ ri1.setResourceName(RESOURCE);
ri1.setResourceInvariantUUID(UUID.randomUUID());
ri1.setResourceInvariantUUID(UUID.randomUUID());
- ri1.setResourceVersion("0.0.0");
+ ri1.setResourceVersion(VERSION_000);
ri1.setResourceType(ResourceType.VL);
ri2 = new ResourceInstance(ri1);
assertEquals(ri1.toString(), ri2.toString());
@@ -144,11 +148,11 @@ public class ResourceInstanceTest {
ResourceInstance ri2 = new ResourceInstance(ri1);
assertEquals(ri1.hashCode(), ri2.hashCode());
- ri1.setResourceInstanceName("instance");
- ri1.setResourceName("resource");
+ ri1.setResourceInstanceName(INSTANCE);
+ ri1.setResourceName(RESOURCE);
ri1.setResourceInvariantUUID(UUID.randomUUID());
ri1.setResourceInvariantUUID(UUID.randomUUID());
- ri1.setResourceVersion("0.0.0");
+ ri1.setResourceVersion(VERSION_000);
ri1.setResourceType(ResourceType.VL);
ri2 = new ResourceInstance(ri1);
assertEquals(ri1.hashCode(), ri2.hashCode());
diff --git a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceTest.java b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceTest.java
index 60510a1d1..6949a36f8 100644
--- a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceTest.java
+++ b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceTest.java
@@ -30,6 +30,9 @@ import org.junit.Test;
public class ResourceTest {
+ private static final String EQUALS_TEST = "equalsTest";
+ private static final String VERSION_111 = "1.1.1";
+
@Test
public void testConstructors() {
Resource res = new Resource();
@@ -120,7 +123,7 @@ public class ResourceTest {
assertTrue(r1.equals(r2));
assertTrue(r2.equals(r1));
- r1 = new Resource(UUID.randomUUID(), UUID.randomUUID(), "equalsTest", "1.1.1",
+ r1 = new Resource(UUID.randomUUID(), UUID.randomUUID(), EQUALS_TEST, VERSION_111,
ResourceType.VFC);
r2 = new Resource(r1);
assertTrue(r1.equals(r2));
@@ -133,7 +136,7 @@ public class ResourceTest {
Resource r2 = new Resource(r1);
assertEquals(r1.toString(), r2.toString());
- r1 = new Resource(UUID.randomUUID(), UUID.randomUUID(), "equalsTest", "1.1.1",
+ r1 = new Resource(UUID.randomUUID(), UUID.randomUUID(), EQUALS_TEST, VERSION_111,
ResourceType.VFC);
r2 = new Resource(r1);
assertEquals(r1.toString(), r2.toString());
@@ -145,7 +148,7 @@ public class ResourceTest {
Resource r2 = new Resource(r1);
assertEquals(r1.hashCode(), r2.hashCode());
- r1 = new Resource(UUID.randomUUID(), UUID.randomUUID(), "equalsTest", "1.1.1",
+ r1 = new Resource(UUID.randomUUID(), UUID.randomUUID(), EQUALS_TEST, VERSION_111,
ResourceType.VFC);
r2 = new Resource(r1);
assertEquals(r1.hashCode(), r2.hashCode());
diff --git a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceInstanceTest.java b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceInstanceTest.java
index ca2cb3d0e..c06974cd5 100644
--- a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceInstanceTest.java
+++ b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceInstanceTest.java
@@ -30,6 +30,10 @@ import org.junit.Test;
public class ServiceInstanceTest {
+ private static final String SERVICE = "service";
+ private static final String INSTANCE = "instance";
+ private static final String VERSION_333 = "3.3.3";
+
@Test
public void testConstructors() {
ServiceInstance si = new ServiceInstance();
@@ -123,13 +127,13 @@ public class ServiceInstanceTest {
assertTrue(si1.equals(si2));
assertTrue(si2.equals(si1));
- si1.setServiceInstanceName("instance");
- si1.setServiceName("service");
+ si1.setServiceInstanceName(INSTANCE);
+ si1.setServiceName(SERVICE);
si1.setServiceInstanceUUID(UUID.randomUUID());
si1.setServiceUUID(UUID.randomUUID());
si1.setPersonaModelUUID(UUID.randomUUID());
si1.setWidgetModelUUID(UUID.randomUUID());
- si1.setWidgetModelVersion("3.3.3");
+ si1.setWidgetModelVersion(VERSION_333);
si2 = new ServiceInstance(si1);
assertTrue(si1.equals(si2));
assertTrue(si2.equals(si1));
@@ -141,13 +145,13 @@ public class ServiceInstanceTest {
ServiceInstance si2 = new ServiceInstance(si1);
assertEquals(si1.toString(), si2.toString());
- si1.setServiceInstanceName("instance");
- si1.setServiceName("service");
+ si1.setServiceInstanceName(INSTANCE);
+ si1.setServiceName(SERVICE);
si1.setServiceInstanceUUID(UUID.randomUUID());
si1.setServiceUUID(UUID.randomUUID());
si1.setPersonaModelUUID(UUID.randomUUID());
si1.setWidgetModelUUID(UUID.randomUUID());
- si1.setWidgetModelVersion("3.3.3");
+ si1.setWidgetModelVersion(VERSION_333);
si2 = new ServiceInstance(si1);
assertEquals(si1.toString(), si2.toString());
}
@@ -158,13 +162,13 @@ public class ServiceInstanceTest {
ServiceInstance si2 = new ServiceInstance(si1);
assertEquals(si1.hashCode(), si2.hashCode());
- si1.setServiceInstanceName("instance");
- si1.setServiceName("service");
+ si1.setServiceInstanceName(INSTANCE);
+ si1.setServiceName(SERVICE);
si1.setServiceInstanceUUID(UUID.randomUUID());
si1.setServiceUUID(UUID.randomUUID());
si1.setPersonaModelUUID(UUID.randomUUID());
si1.setWidgetModelUUID(UUID.randomUUID());
- si1.setWidgetModelVersion("3.3.3");
+ si1.setWidgetModelVersion(VERSION_333);
si2 = new ServiceInstance(si1);
assertEquals(si1.hashCode(), si2.hashCode());
}
diff --git a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceTest.java b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceTest.java
index 3bf6a537e..19238622d 100644
--- a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceTest.java
+++ b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceTest.java
@@ -30,6 +30,9 @@ import org.junit.Test;
public class ServiceTest {
+ private static final String EQUALS_TEST = "equalsTest";
+ private static final String VERSION_111 = "1.1.1";
+
@Test
public void testConstructors() {
Service svc = new Service();
@@ -108,7 +111,7 @@ public class ServiceTest {
assertTrue(s1.equals(s2));
assertTrue(s2.equals(s1));
- s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), "equalsTest", "1.1.1");
+ s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), EQUALS_TEST, VERSION_111);
s2 = new Service(s1);
assertTrue(s1.equals(s2));
assertTrue(s2.equals(s1));
@@ -120,7 +123,7 @@ public class ServiceTest {
Service s2 = new Service(s1);
assertEquals(s1.toString(), s2.toString());
- s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), "equalsTest", "1.1.1");
+ s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), EQUALS_TEST, VERSION_111);
s2 = new Service(s1);
assertEquals(s1.toString(), s2.toString());
}
@@ -131,7 +134,7 @@ public class ServiceTest {
Service s2 = new Service(s1);
assertEquals(s1.hashCode(), s2.hashCode());
- s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), "equalsTest", "1.1.1");
+ s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), EQUALS_TEST, VERSION_111);
s2 = new Service(s1);
assertEquals(s1.hashCode(), s2.hashCode());
}
diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java
index 3679625ec..7612eeb3f 100644
--- a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java
+++ b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java
@@ -49,6 +49,7 @@ public final class SdncManager implements Runnable {
// The REST manager used for processing REST calls for this Sdnc manager
private RestManager restManager;
+ @FunctionalInterface
public interface SdncCallback {
public void onCallback(SdncResponse response);
}
@@ -133,7 +134,7 @@ public final class SdncManager implements Runnable {
logger.info(body);
response.setRequestId(sdncRequest.getRequestId().toString());
- if (!response.getResponseOutput().getResponseCode().equals("200")) {
+ if (!"200".equals(response.getResponseOutput().getResponseCode())) {
logger.info(
"Sdnc Heal Restcall failed with http error code {} {}", httpDetails.first, httpDetails.second
);
diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/util/Serialization.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/util/Serialization.java
index cfaa46fd0..090b4f9b6 100644
--- a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/util/Serialization.java
+++ b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/util/Serialization.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Huawei. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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.
@@ -23,11 +24,12 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public final class Serialization {
- private Serialization() {
- }
-
+
public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping()
.setPrettyPrinting()
.create();
+ private Serialization() {
+
+ }
}
diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java
index 1c18d9c8f..41f07c3c7 100644
--- a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java
+++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Huawei. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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.
@@ -21,8 +22,11 @@ package org.onap.policy.sdnc;
import org.junit.Test;
import org.onap.policy.sdnc.util.Serialization;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class DemoTest {
+ private static final Logger logger = LoggerFactory.getLogger(DemoTest.class);
@Test
public void test() {
@@ -37,34 +41,34 @@ public class DemoTest {
request.getHealRequest().setRequestInfo(new SdncHealRequestInfo());
request.getHealRequest().getRequestInfo().setRequestAction("request-action");
-
+
request.getHealRequest().setServiceInfo(new SdncHealServiceInfo());
request.getHealRequest().getServiceInfo().setServiceInstanceId("service-instance-01");
-
+
request.getHealRequest().setNetworkInfo(new SdncHealNetworkInfo());
request.getHealRequest().getNetworkInfo().setNetworkId("network-5555");
-
+
String body = Serialization.gsonPretty.toJson(request);
- System.out.println(body);
+ logger.info("{}", body);
SdncResponse response = new SdncResponse();
body = Serialization.gsonPretty.toJson(response);
- System.out.println(body);
+ logger.info("{}", body);
response.setRequestId("request-01");
response.setResponseOutput(new SdncResponseOutput());
response.getResponseOutput().setSvcRequestId("service-req-01");
response.getResponseOutput().setResponseCode("200");
response.getResponseOutput().setAckFinalIndicator("final-indicator-00");
-
+
body = Serialization.gsonPretty.toJson(response);
- System.out.println(body);
+ logger.info("{}", body);
response = Serialization.gsonPretty.fromJson(body, SdncResponse.class);
body = Serialization.gsonPretty.toJson(response);
- System.out.println(body);
+ logger.info("{}", body);
}
}
diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java
index 2a1cc6984..c069f1c3b 100644
--- a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java
+++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java
@@ -23,8 +23,7 @@
package org.onap.policy.sdnc;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.endsWith;
@@ -35,7 +34,6 @@ import static org.mockito.Mockito.when;
import java.util.UUID;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.rest.RestManager;
import org.onap.policy.rest.RestManager.Pair;
@@ -43,6 +41,10 @@ import org.onap.policy.sdnc.SdncManager.SdncCallback;
import org.onap.policy.sdnc.util.Serialization;
public class SdncManagerTest implements SdncCallback {
+ private static final String SOMEWHERE_OVER_THE_RAINBOW = "http://somewhere.over.the.rainbow";
+
+ private static final String DOROTHY = "Dorothy";
+
private RestManager mockedRestManager;
private Pair<Integer, String> httpResponsePutOk;
@@ -53,10 +55,6 @@ public class SdncManagerTest implements SdncCallback {
private SdncRequest request;
private SdncResponse response;
- @BeforeClass
- public static void beforeTestSdncManager() {
- }
-
/**
* Set up the mocked REST manager.
*/
@@ -90,7 +88,7 @@ public class SdncManagerTest implements SdncCallback {
request = new SdncRequest();
request.setRequestId(requestId);
request.setHealRequest(healRequest);
- request.setNsInstanceId("Dorothy");
+ request.setNsInstanceId(DOROTHY);
SdncResponseOutput responseDescriptor = new SdncResponseOutput();
responseDescriptor.setSvcRequestId("1234");
@@ -103,53 +101,30 @@ public class SdncManagerTest implements SdncCallback {
}
@Test
- public void testSdncInitiation() throws InterruptedException {
- try {
- new SdncManager(null, null, null, null, null);
- fail("test should throw an exception here");
- }
- catch (IllegalArgumentException e) {
- assertEquals(
- "the parameters \"callback\" and \"request\" on the SdncManager constructor may not be null",
- e.getMessage()
- );
- }
-
- try {
- new SdncManager(this, null, null, null, null);
- fail("test should throw an exception here");
- }
- catch (IllegalArgumentException e) {
- assertEquals(
- "the parameters \"callback\" and \"request\" on the SdncManager constructor may not be null",
- e.getMessage()
- );
- }
-
- try {
- new SdncManager(this, request, null, null, null);
- fail("test should throw an exception here");
- }
- catch (IllegalArgumentException e) {
- assertEquals(
- "the \"url\" parameter on the SdncManager constructor may not be null",
- e.getMessage()
- );
- }
-
- new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Toto");
+ public void testSdncInitiation() {
+
+ assertThatIllegalArgumentException().isThrownBy(() -> new SdncManager(null, null, null, null, null))
+ .withMessage("the parameters \"callback\" and \"request\" on the SdncManager constructor may not be null");
+
+ assertThatIllegalArgumentException().isThrownBy(() -> new SdncManager(this, null, null, null, null))
+ .withMessage("the parameters \"callback\" and \"request\" on the SdncManager constructor may not be null");
+
+ assertThatIllegalArgumentException().isThrownBy(() -> new SdncManager(this, request, null, null, null))
+ .withMessage("the \"url\" parameter on the SdncManager constructor may not be null");
+
+ new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "Toto");
}
@Test
public void testSdncExecutionException() throws InterruptedException {
- SdncManager manager = new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Exception");
+ SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "Exception");
manager.setRestManager(mockedRestManager);
Thread managerThread = new Thread(manager);
managerThread.start();
- when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Exception"), anyMap(), anyString(), anyString()))
- .thenThrow(new RuntimeException("OzException"));
+ when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("Exception"), anyMap(),
+ anyString(), anyString())).thenThrow(new RuntimeException("OzException"));
managerThread.join(100);
@@ -157,14 +132,14 @@ public class SdncManagerTest implements SdncCallback {
@Test
public void testSdncExecutionNull() throws InterruptedException {
- SdncManager manager = new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Null");
+ SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "Null");
manager.setRestManager(mockedRestManager);
Thread managerThread = new Thread(manager);
managerThread.start();
- when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Null"), anyMap(), anyString(), anyString()))
- .thenReturn(null);
+ when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("Null"), anyMap(),
+ anyString(), anyString())).thenReturn(null);
managerThread.join(100);
}
@@ -172,44 +147,44 @@ public class SdncManagerTest implements SdncCallback {
@Test
public void testSdncExecutionError0() throws InterruptedException {
- SdncManager manager = new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Error0");
+ SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "Error0");
manager.setRestManager(mockedRestManager);
Thread managerThread = new Thread(manager);
managerThread.start();
- when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Error0"), anyMap(), anyString(), anyString()))
- .thenReturn(httpResponseErr);
+ when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("Error0"), anyMap(),
+ anyString(), anyString())).thenReturn(httpResponseErr);
managerThread.join(100);
}
@Test
public void testSdncExecutionBadResponse() throws InterruptedException {
- SdncManager manager = new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "BadResponse");
+ SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "BadResponse");
manager.setRestManager(mockedRestManager);
Thread managerThread = new Thread(manager);
managerThread.start();
- when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString()))
- .thenReturn(httpResponseBadResponse);
+ when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("OK"), anyMap(),
+ anyString(), anyString())).thenReturn(httpResponseBadResponse);
managerThread.join(100);
}
@Test
public void testSdncExecutionOk() throws InterruptedException {
- SdncManager manager = new SdncManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "OOK");
+ SdncManager manager = new SdncManager(this, request, SOMEWHERE_OVER_THE_RAINBOW, DOROTHY, "OOK");
manager.setRestManager(mockedRestManager);
Thread managerThread = new Thread(manager);
managerThread.start();
- when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString()))
- .thenReturn(httpResponsePutOk);
+ when(mockedRestManager.post(startsWith(SOMEWHERE_OVER_THE_RAINBOW), eq(DOROTHY), eq("OK"), anyMap(),
+ anyString(), anyString())).thenReturn(httpResponsePutOk);
- when(mockedRestManager.get(endsWith("1234"), eq("Dorothy"), eq("OK"), anyMap()))
+ when(mockedRestManager.get(endsWith("1234"), eq(DOROTHY), eq("OK"), anyMap()))
.thenReturn(httpResponseGetOk);
diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciCommonHeader.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciCommonHeader.java
index f575a73c3..8552bb23c 100644
--- a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciCommonHeader.java
+++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciCommonHeader.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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.
@@ -148,6 +149,7 @@ public class PciCommonHeader implements Serializable {
public void setSubRequestId(String subRequestId) {
this.subRequestId = subRequestId;
}
+
/**
* Set the request track.
*
@@ -157,6 +159,7 @@ public class PciCommonHeader implements Serializable {
public void setRequestTrack(Map<String, String> requestTrack) {
this.requestTrack = requestTrack;
}
+
/**
* Get the request track.
*
diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequest.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequest.java
index 73ee4c65d..d76dd88b5 100644
--- a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequest.java
+++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequest.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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.
@@ -82,8 +83,8 @@ public class PciRequest implements Serializable {
/**
* Set the payload.
*
- * @param action
- * the action to set
+ * @param payload
+ * the payload to set
*/
public void setPayload(String payload) {
diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java
index f0cc246b9..84178e062 100644
--- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java
+++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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.
@@ -36,6 +37,9 @@ import org.junit.Test;
public class PciCommonHeaderTest {
+ private static final String KANSAS = "Kansas";
+ private static final String CAN_I_GO_HOME = "Can I go home?";
+
@Test
public void testPciCommonHeader() {
PciCommonHeader commonHeader = new PciCommonHeader();
@@ -43,8 +47,8 @@ public class PciCommonHeaderTest {
assertNotNull(new PciCommonHeader(commonHeader));
assertNotEquals(0, commonHeader.hashCode());
- commonHeader.setApiVer("Kansas");
- assertEquals("Kansas", commonHeader.getApiVer());
+ commonHeader.setApiVer(KANSAS);
+ assertEquals(KANSAS, commonHeader.getApiVer());
Map<String, String> flagMap = new HashMap<>();
commonHeader.setFlags(flagMap);
@@ -58,8 +62,8 @@ public class PciCommonHeaderTest {
commonHeader.setRequestId(requestId);
assertEquals(requestId, commonHeader.getRequestId());
- commonHeader.setSubRequestId("Can I go home?");
- assertEquals("Can I go home?", commonHeader.getSubRequestId());
+ commonHeader.setSubRequestId(CAN_I_GO_HOME);
+ assertEquals(CAN_I_GO_HOME, commonHeader.getSubRequestId());
Instant timestamp = Instant.now();
commonHeader.setTimeStamp(timestamp);
@@ -91,9 +95,9 @@ public class PciCommonHeaderTest {
assertFalse(commonHeader.equals(copiedPciCommonHeader));
copiedPciCommonHeader.setApiVer(null);
assertTrue(commonHeader.equals(copiedPciCommonHeader));
- commonHeader.setApiVer("Kansas");
+ commonHeader.setApiVer(KANSAS);
assertFalse(commonHeader.equals(copiedPciCommonHeader));
- copiedPciCommonHeader.setApiVer("Kansas");
+ copiedPciCommonHeader.setApiVer(KANSAS);
assertTrue(commonHeader.equals(copiedPciCommonHeader));
commonHeader.setFlags(null);
@@ -128,9 +132,9 @@ public class PciCommonHeaderTest {
assertFalse(commonHeader.equals(copiedPciCommonHeader));
copiedPciCommonHeader.setSubRequestId(null);
assertTrue(commonHeader.equals(copiedPciCommonHeader));
- commonHeader.setSubRequestId("Can I go home?");
+ commonHeader.setSubRequestId(CAN_I_GO_HOME);
assertFalse(commonHeader.equals(copiedPciCommonHeader));
- copiedPciCommonHeader.setSubRequestId("Can I go home?");
+ copiedPciCommonHeader.setSubRequestId(CAN_I_GO_HOME);
assertTrue(commonHeader.equals(copiedPciCommonHeader));
commonHeader.setTimeStamp(null);
diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java
index 023dd18ca..0009c2a5c 100644
--- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java
+++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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.
@@ -31,6 +32,8 @@ import org.junit.Test;
public class PciRequestTest {
+ private static final String MODIFY = "Modify";
+
@Test
public void testPciRequest() {
PciRequest request = new PciRequest();
@@ -46,8 +49,8 @@ public class PciRequestTest {
request.setPayload(requestPayload);
assertEquals(requestPayload, request.getPayload());
- request.setAction("Modify");
- assertEquals("Modify", request.getAction());
+ request.setAction(MODIFY);
+ assertEquals(MODIFY, request.getAction());
assertNotEquals(0, request.hashCode());
@@ -76,9 +79,9 @@ public class PciRequestTest {
assertFalse(request.equals(copiedPciRequest));
copiedPciRequest.setAction(null);
assertTrue(request.equals(copiedPciRequest));
- request.setAction("Modify");
+ request.setAction(MODIFY);
assertFalse(request.equals(copiedPciRequest));
- copiedPciRequest.setAction("Modify");
+ copiedPciRequest.setAction(MODIFY);
assertTrue(request.equals(copiedPciRequest));
request.setPayload(null);
diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java
index 27f4c23cf..6e990ea12 100644
--- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java
+++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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.
@@ -97,9 +98,9 @@ public class PciResponseTest {
response2.setStatus(response.getStatus());
assertTrue(response.equals(response2));
- Status status = new Status();
- status.setCode(5);
- response.setStatus(status);
+ Status stat = new Status();
+ stat.setCode(5);
+ response.setStatus(stat);
response2.setStatus(new Status());
assertFalse(response.equals(response2));
}
diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java
index f8f5820dc..08ac56b85 100644
--- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java
+++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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.
@@ -31,6 +32,8 @@ import org.junit.Test;
public class PciStatusTest {
+ private static final String THE_WONDERFUL_LAND_OF_OZ = "The wonderful land of Oz";
+
@Test
public void testResponseStatus() {
Status status = new Status();
@@ -40,8 +43,8 @@ public class PciStatusTest {
status.setCode(1234);
assertEquals(1234, status.getCode());
- status.setValue("The wonderful land of Oz");
- assertEquals("The wonderful land of Oz", status.getValue());
+ status.setValue(THE_WONDERFUL_LAND_OF_OZ);
+ assertEquals(THE_WONDERFUL_LAND_OF_OZ, status.getValue());
assertEquals("Status [code = 1234, value = The wonderfu", status.toString().substring(0, 41));
@@ -67,9 +70,9 @@ public class PciStatusTest {
assertFalse(status.equals(copiedStatus));
copiedStatus.setValue(null);
assertTrue(status.equals(copiedStatus));
- status.setValue("The wonderful land of Oz");
+ status.setValue(THE_WONDERFUL_LAND_OF_OZ);
assertFalse(status.equals(copiedStatus));
- copiedStatus.setValue("The wonderful land of Oz");
+ copiedStatus.setValue(THE_WONDERFUL_LAND_OF_OZ);
assertTrue(status.equals(copiedStatus));
}
}
diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java
index 151d3343a..f05f50e67 100644
--- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java
+++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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.
@@ -31,26 +32,32 @@ import org.junit.Test;
public class PciWrapperTest {
+ private static final String YELLOW_BRICK_ROAD = "YellowBrickRoad";
+ private static final String TORNADO = "Tornado";
+ private static final String THE_EMERALD_CITY = "The Emerald City";
+ private static final String MUNCHKIN = "Munchkin";
+ private static final String VERSION_19 = "19.3.9";
+
@Test
public void testPciWrapper() {
PciWrapper wrapper = new PciWrapper();
assertNotNull(wrapper);
assertNotEquals(0, wrapper.hashCode());
- wrapper.setVersion("19.3.9");
- assertEquals("19.3.9", wrapper.getVersion());
+ wrapper.setVersion(VERSION_19);
+ assertEquals(VERSION_19, wrapper.getVersion());
- wrapper.setCambriaPartition("The Emerald City");
- assertEquals("The Emerald City", wrapper.getCambriaPartition());
+ wrapper.setCambriaPartition(THE_EMERALD_CITY);
+ assertEquals(THE_EMERALD_CITY, wrapper.getCambriaPartition());
- wrapper.setRpcName("Tornado");
- assertEquals("Tornado", wrapper.getRpcName());
+ wrapper.setRpcName(TORNADO);
+ assertEquals(TORNADO, wrapper.getRpcName());
- wrapper.setCorrelationId("YellowBrickRoad");
- assertEquals("YellowBrickRoad", wrapper.getCorrelationId());
+ wrapper.setCorrelationId(YELLOW_BRICK_ROAD);
+ assertEquals(YELLOW_BRICK_ROAD, wrapper.getCorrelationId());
- wrapper.setType("Munchkin");
- assertEquals("Munchkin", wrapper.getType());
+ wrapper.setType(MUNCHKIN);
+ assertEquals(MUNCHKIN, wrapper.getType());
assertNotEquals(0, wrapper.hashCode());
@@ -72,45 +79,45 @@ public class PciWrapperTest {
assertFalse(wrapper.equals(copiedPciWrapper));
copiedPciWrapper.setVersion(null);
assertTrue(wrapper.equals(copiedPciWrapper));
- wrapper.setVersion("19.3.9");
+ wrapper.setVersion(VERSION_19);
assertFalse(wrapper.equals(copiedPciWrapper));
- copiedPciWrapper.setVersion("19.3.9");
+ copiedPciWrapper.setVersion(VERSION_19);
assertTrue(wrapper.equals(copiedPciWrapper));
wrapper.setCambriaPartition(null);
assertFalse(wrapper.equals(copiedPciWrapper));
copiedPciWrapper.setCambriaPartition(null);
assertTrue(wrapper.equals(copiedPciWrapper));
- wrapper.setCambriaPartition("The Emerald City");
+ wrapper.setCambriaPartition(THE_EMERALD_CITY);
assertFalse(wrapper.equals(copiedPciWrapper));
- copiedPciWrapper.setCambriaPartition("The Emerald City");
+ copiedPciWrapper.setCambriaPartition(THE_EMERALD_CITY);
assertTrue(wrapper.equals(copiedPciWrapper));
wrapper.setRpcName(null);
assertFalse(wrapper.equals(copiedPciWrapper));
copiedPciWrapper.setRpcName(null);
assertTrue(wrapper.equals(copiedPciWrapper));
- wrapper.setRpcName("Tornado");
+ wrapper.setRpcName(TORNADO);
assertFalse(wrapper.equals(copiedPciWrapper));
- copiedPciWrapper.setRpcName("Tornado");
+ copiedPciWrapper.setRpcName(TORNADO);
assertTrue(wrapper.equals(copiedPciWrapper));
wrapper.setCorrelationId(null);
assertFalse(wrapper.equals(copiedPciWrapper));
copiedPciWrapper.setCorrelationId(null);
assertTrue(wrapper.equals(copiedPciWrapper));
- wrapper.setCorrelationId("YellowBrickRoad");
+ wrapper.setCorrelationId(YELLOW_BRICK_ROAD);
assertFalse(wrapper.equals(copiedPciWrapper));
- copiedPciWrapper.setCorrelationId("YellowBrickRoad");
+ copiedPciWrapper.setCorrelationId(YELLOW_BRICK_ROAD);
assertTrue(wrapper.equals(copiedPciWrapper));
wrapper.setType(null);
assertFalse(wrapper.equals(copiedPciWrapper));
copiedPciWrapper.setType(null);
assertTrue(wrapper.equals(copiedPciWrapper));
- wrapper.setType("Munchkin");
+ wrapper.setType(MUNCHKIN);
assertFalse(wrapper.equals(copiedPciWrapper));
- copiedPciWrapper.setType("Munchkin");
+ copiedPciWrapper.setType(MUNCHKIN);
assertTrue(wrapper.equals(copiedPciWrapper));
}
}
diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/SdnrTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/SdnrTest.java
index 8317482cc..4cbda52ec 100644
--- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/SdnrTest.java
+++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/SdnrTest.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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.
@@ -35,6 +36,8 @@ import org.slf4j.LoggerFactory;
public class SdnrTest {
+ private static final String CORRELATION_ID = "664be3d2-6c12-4f4b-a3e7-c349acced200";
+
private static final Logger logger = LoggerFactory.getLogger(SdnrTest.class);
private static PciRequestWrapper dmaapRequest;
@@ -45,12 +48,12 @@ public class SdnrTest {
* Construct an SDNR Request to be Serialized
*/
dmaapRequest = new PciRequestWrapper();
- dmaapRequest.setCorrelationId("664be3d2-6c12-4f4b-a3e7-c349acced200" + "-" + "1");
+ dmaapRequest.setCorrelationId(CORRELATION_ID + "-" + "1");
dmaapRequest.setRpcName("restart");
dmaapRequest.setType("request");
dmaapResponse = new PciResponseWrapper();
- dmaapResponse.setCorrelationId("664be3d2-6c12-4f4b-a3e7-c349acced200" + "-" + "1");
+ dmaapResponse.setCorrelationId(CORRELATION_ID + "-" + "1");
dmaapResponse.setRpcName("restart");
dmaapResponse.setType("response");
@@ -59,7 +62,7 @@ public class SdnrTest {
sdnrRequest.setAction("ModifyConfig");
PciCommonHeader commonHeader = new PciCommonHeader();
- commonHeader.setRequestId(UUID.fromString("664be3d2-6c12-4f4b-a3e7-c349acced200"));
+ commonHeader.setRequestId(UUID.fromString(CORRELATION_ID));
commonHeader.setSubRequestId("1");
sdnrRequest.setCommonHeader(commonHeader);
diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java
index 888afe2ae..6e2494b72 100644
--- a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java
+++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java
@@ -68,6 +68,7 @@ public final class SoManager {
private String user;
private String password;
+ @FunctionalInterface
public interface SoCallback {
public void onSoResponseWrapper(SoResponseWrapper wrapper);
}
diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoDummyServer.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoDummyServer.java
index e9c338356..d7e7a1166 100644
--- a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoDummyServer.java
+++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoDummyServer.java
@@ -36,6 +36,7 @@ import javax.ws.rs.core.Response;
@Path("/SO")
public class SoDummyServer {
+ private static final String ONGOING = "ONGOING";
private static int postMessagesReceived = 0;
private static int putMessagesReceived = 0;
private static int statMessagesReceived = 0;
@@ -113,9 +114,9 @@ public class SoDummyServer {
SoResponse response = ongoingRequestMap.get(nsInstanceId);
- int iterationsLeft = Integer.valueOf(response.getRequest().getRequestScope());
+ int iterationsLeft = Integer.parseInt(response.getRequest().getRequestScope());
if (--iterationsLeft > 0) {
- response.getRequest().setRequestScope(new Integer(iterationsLeft).toString());
+ response.getRequest().setRequestScope(Integer.toString(iterationsLeft));
String responseString = new Gson().toJson(response, SoResponse.class);
return Response.status(response.getHttpResponseCode()).entity(responseString).build();
}
@@ -158,12 +159,7 @@ public class SoDummyServer {
return Response.status(400).build();
}
- SoRequest request = null;
- try {
- request = new Gson().fromJson(jsonString, SoRequest.class);
- } catch (Exception e) {
- return Response.status(400).build();
- }
+ SoRequest request = new Gson().fromJson(jsonString, SoRequest.class);
if (request == null) {
return Response.status(400).build();
@@ -206,7 +202,7 @@ public class SoDummyServer {
if ("ReturnOnging202".equals(request.getRequestType())) {
ongoingRequestMap.put(request.getRequestId().toString(), response);
- response.getRequest().getRequestStatus().setRequestState("ONGOING");
+ response.getRequest().getRequestStatus().setRequestState(ONGOING);
response.setHttpResponseCode(202);
String responseString = new Gson().toJson(response, SoResponse.class);
return Response.status(response.getHttpResponseCode())
@@ -217,7 +213,7 @@ public class SoDummyServer {
if ("ReturnOnging200".equals(request.getRequestType())) {
ongoingRequestMap.put(request.getRequestId().toString(), response);
- response.getRequest().getRequestStatus().setRequestState("ONGOING");
+ response.getRequest().getRequestStatus().setRequestState(ONGOING);
response.setHttpResponseCode(200);
String responseString = new Gson().toJson(response, SoResponse.class);
return Response.status(response.getHttpResponseCode())
@@ -228,7 +224,7 @@ public class SoDummyServer {
if ("ReturnBadAfterWait".equals(request.getRequestType())) {
ongoingRequestMap.put(request.getRequestId().toString(), response);
- response.getRequest().getRequestStatus().setRequestState("ONGOING");
+ response.getRequest().getRequestStatus().setRequestState(ONGOING);
response.setHttpResponseCode(200);
String responseString = new Gson().toJson(response, SoResponse.class);
return Response.status(response.getHttpResponseCode())
diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java
index 03ac06dd5..aa3562ae5 100644
--- a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java
+++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java
@@ -28,13 +28,11 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.IOException;
import java.net.URI;
import java.util.UUID;
import java.util.concurrent.Future;
-import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
@@ -49,6 +47,19 @@ import org.junit.Test;
import org.onap.policy.so.SoManager.SoCallback;
public class SoManagerTest implements SoCallback {
+ private static final String LOCALHOST_99999999 = "http:/localhost:99999999";
+ private static final String CITIZEN = "citizen";
+ private static final String RETURN_ONGING202 = "ReturnOnging202";
+ private static final String RETURN_ONGING200 = "ReturnOnging200";
+ private static final String RETURN_FAILED = "ReturnFailed";
+ private static final String RETURN_COMPLETED = "ReturnCompleted";
+ private static final String RETURN_BAD_JSON = "ReturnBadJson";
+ private static final String RETURN_BAD_AFTER_WAIT = "ReturnBadAfterWait";
+ private static final String ONGOING = "ONGOING";
+ private static final String FAILED = "FAILED";
+ private static final String COMPLETE = "COMPLETE";
+ private static final String DATE1 = "2018-03-23 16:31";
+ private static final String SERVICE_INSTANTIATION_V7 = "/serviceInstantiation/v7";
private static final String BASE_URI = "http://localhost:46553/TestSOManager";
private static final String BASE_SO_URI = BASE_URI + "/SO";
private static HttpServer server;
@@ -68,99 +79,100 @@ public class SoManagerTest implements SoCallback {
}
@AfterClass
- public static void tearDown() throws Exception {
+ public static void tearDown() {
server.shutdown();
}
@Test
- public void testGrizzlyServer() throws ClientProtocolException, IOException {
- CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpGet httpGet = new HttpGet("http://localhost:46553/TestSOManager/SO/Stats");
- CloseableHttpResponse response = httpclient.execute(httpGet);
-
- String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8");
- assertTrue(returnBody.matches("^\\{\"GET\": [0-9]*,\"STAT\": [0-9]*,\"POST\": [0-9]*,\"PUT\": [0-9]*,"
- + "\"DELETE\": [0-9]*\\}$"));
+ public void testGrizzlyServer() throws IOException {
+ try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
+ HttpGet httpGet = new HttpGet("http://localhost:46553/TestSOManager/SO/Stats");
+ CloseableHttpResponse response = httpclient.execute(httpGet);
+
+ String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8");
+ assertTrue(returnBody.matches("^\\{\"GET\": [0-9]*,\"STAT\": [0-9]*,\"POST\": [0-9]*,\"PUT\": [0-9]*,"
+ + "\"DELETE\": [0-9]*\\}$"));
+ }
}
@Test
- public void testServiceInstantiation() throws IOException {
+ public void testServiceInstantiation() {
SoManager manager = new SoManager(null, null, null);
assertNotNull(manager);
manager.setRestGetTimeout(100);
- SoResponse response = manager.createModuleInstance("http:/localhost:99999999", BASE_SO_URI, "sean",
- "citizen", null);
+ SoResponse response = manager.createModuleInstance(LOCALHOST_99999999, BASE_SO_URI, "sean",
+ CITIZEN, null);
assertNull(response);
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", null);
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, null);
assertNull(response);
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", new SoRequest());
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, new SoRequest());
assertNull(response);
SoRequest request = new SoRequest();
request.setRequestId(UUID.randomUUID());
request.setRequestScope("Test");
- request.setRequestType("ReturnBadJson");
- request.setStartTime("2018-03-23 16:31");
+ request.setRequestType(RETURN_BAD_JSON);
+ request.setStartTime(DATE1);
request.setRequestStatus(new SoRequestStatus());
- request.getRequestStatus().setRequestState("ONGOING");
+ request.getRequestStatus().setRequestState(ONGOING);
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", request);
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, request);
assertNull(response);
- request.setRequestType("ReturnCompleted");
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", request);
+ request.setRequestType(RETURN_COMPLETED);
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, request);
assertNotNull(response);
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
- request.setRequestType("ReturnFailed");
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", request);
+ request.setRequestType(RETURN_FAILED);
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, request);
assertNotNull(response);
- assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState());
+ assertEquals(FAILED, response.getRequest().getRequestStatus().getRequestState());
// Use scope to set the number of iterations we'll wait for
- request.setRequestType("ReturnOnging200");
- request.setRequestScope(new Integer(10).toString());
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", request);
+ request.setRequestType(RETURN_ONGING200);
+ request.setRequestScope("10");
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, request);
assertNotNull(response);
assertNotNull(response.getRequest());
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
- request.setRequestType("ReturnOnging202");
- request.setRequestScope(new Integer(20).toString());
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", request);
+ request.setRequestType(RETURN_ONGING202);
+ request.setRequestScope("20");
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, request);
assertNotNull(response);
assertNotNull(response.getRequest());
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
// Test timeout after 20 attempts for a response
- request.setRequestType("ReturnOnging202");
- request.setRequestScope(new Integer(21).toString());
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", request);
+ request.setRequestType(RETURN_ONGING202);
+ request.setRequestScope("21");
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, request);
assertNull(response);
// Test bad response after 3 attempts for a response
- request.setRequestType("ReturnBadAfterWait");
- request.setRequestScope(new Integer(3).toString());
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", request);
+ request.setRequestType(RETURN_BAD_AFTER_WAIT);
+ request.setRequestScope("3");
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, request);
assertNull(response);
}
@Test
- public void testVfModuleCreation() throws IOException {
- SoManager manager = new SoManager("http:/localhost:99999999", "sean", "citizen");
+ public void testVfModuleCreation() throws Exception {
+ SoManager manager = new SoManager(LOCALHOST_99999999, "sean", CITIZEN);
assertNotNull(manager);
manager.setRestGetTimeout(100);
@@ -168,117 +180,81 @@ public class SoManagerTest implements SoCallback {
soRequest.setOperationType(SoOperationType.SCALE_OUT);
Future<SoResponse> asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this,
UUID.randomUUID().toString(), UUID.randomUUID().toString(), soRequest);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ SoResponse response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
- manager = new SoManager(BASE_SO_URI, "sean", "citizen");
+ manager = new SoManager(BASE_SO_URI, "sean", CITIZEN);
manager.setRestGetTimeout(100);
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), soRequest);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
SoRequest request = new SoRequest();
request.setRequestId(UUID.randomUUID());
request.setRequestScope("Test");
- request.setRequestType("ReturnBadJson");
- request.setStartTime("2018-03-23 16:31");
+ request.setRequestType(RETURN_BAD_JSON);
+ request.setStartTime(DATE1);
request.setRequestStatus(new SoRequestStatus());
- request.getRequestStatus().setRequestState("ONGOING");
+ request.getRequestStatus().setRequestState(ONGOING);
request.setOperationType(SoOperationType.SCALE_OUT);
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
- request.setRequestType("ReturnCompleted");
+ request.setRequestType(RETURN_COMPLETED);
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
- request.setRequestType("ReturnFailed");
+ request.setRequestType(RETURN_FAILED);
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(FAILED, response.getRequest().getRequestStatus().getRequestState());
// Use scope to set the number of iterations we'll wait for
- request.setRequestType("ReturnOnging200");
- request.setRequestScope(new Integer(10).toString());
+ request.setRequestType(RETURN_ONGING200);
+ request.setRequestScope("10");
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertNotNull(response.getRequest());
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertNotNull(response.getRequest());
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
- request.setRequestType("ReturnOnging202");
- request.setRequestScope(new Integer(20).toString());
+ request.setRequestType(RETURN_ONGING202);
+ request.setRequestScope("20");
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertNotNull(response.getRequest());
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertNotNull(response.getRequest());
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
// Test timeout after 20 attempts for a response
- request.setRequestType("ReturnOnging202");
- request.setRequestScope(new Integer(21).toString());
+ request.setRequestType(RETURN_ONGING202);
+ request.setRequestScope("21");
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
// Test bad response after 3 attempts for a response
- request.setRequestType("ReturnBadAfterWait");
- request.setRequestScope(new Integer(3).toString());
+ request.setRequestType(RETURN_BAD_AFTER_WAIT);
+ request.setRequestScope("3");
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
}
@Test
- public void testVfModuleDeletion() {
- SoManager manager = new SoManager("http:/localhost:99999999", "sean", "citizen");
+ public void testVfModuleDeletion() throws Exception {
+ SoManager manager = new SoManager(LOCALHOST_99999999, "sean", CITIZEN);
assertNotNull(manager);
manager.setRestGetTimeout(100);
@@ -286,113 +262,77 @@ public class SoManagerTest implements SoCallback {
soRequest.setOperationType(SoOperationType.DELETE_VF_MODULE);
Future<SoResponse> asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this,
UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), soRequest);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ SoResponse response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
- manager = new SoManager(BASE_SO_URI, "sean", "citizen");
+ manager = new SoManager(BASE_SO_URI, "sean", CITIZEN);
manager.setRestGetTimeout(100);
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), UUID.randomUUID().toString(), soRequest);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
SoRequest request = new SoRequest();
request.setRequestId(UUID.randomUUID());
request.setRequestScope("Test");
- request.setRequestType("ReturnBadJson");
- request.setStartTime("2018-03-23 16:31");
+ request.setRequestType(RETURN_BAD_JSON);
+ request.setStartTime(DATE1);
request.setRequestStatus(new SoRequestStatus());
- request.getRequestStatus().setRequestState("ONGOING");
+ request.getRequestStatus().setRequestState(ONGOING);
request.setOperationType(SoOperationType.DELETE_VF_MODULE);
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
- request.setRequestType("ReturnCompleted");
+ request.setRequestType(RETURN_COMPLETED);
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
- request.setRequestType("ReturnFailed");
+ request.setRequestType(RETURN_FAILED);
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(FAILED, response.getRequest().getRequestStatus().getRequestState());
// Use scope to set the number of iterations we'll wait for
- request.setRequestType("ReturnOnging200");
- request.setRequestScope(new Integer(10).toString());
+ request.setRequestType(RETURN_ONGING200);
+ request.setRequestScope("10");
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertNotNull(response.getRequest());
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertNotNull(response.getRequest());
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
- request.setRequestType("ReturnOnging202");
- request.setRequestScope(new Integer(20).toString());
+ request.setRequestType(RETURN_ONGING202);
+ request.setRequestScope("20");
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertNotNull(response.getRequest());
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertNotNull(response.getRequest());
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
// Test timeout after 20 attempts for a response
- request.setRequestType("ReturnOnging202");
- request.setRequestScope(new Integer(21).toString());
+ request.setRequestType(RETURN_ONGING202);
+ request.setRequestScope("21");
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
// Test bad response after 3 attempts for a response
- request.setRequestType("ReturnBadAfterWait");
- request.setRequestScope(new Integer(3).toString());
+ request.setRequestType(RETURN_BAD_AFTER_WAIT);
+ request.setRequestScope("3");
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
}
@Override
diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestInfoTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestInfoTest.java
index 2302696ee..dd7db84f3 100644
--- a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestInfoTest.java
+++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestInfoTest.java
@@ -3,7 +3,6 @@
* so
* ================================================================================
* Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,7 +22,8 @@
package org.onap.policy.so;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import org.junit.Test;
@@ -33,16 +33,16 @@ public class SoRequestInfoTest {
public void testConstructor() {
SoRequestInfo obj = new SoRequestInfo();
- assertTrue(obj.getBillingAccountNumber() == null);
- assertTrue(obj.getCallbackUrl() == null);
- assertTrue(obj.getCorrelator() == null);
- assertTrue(obj.getInstanceName() == null);
- assertTrue(obj.getOrderNumber() == null);
- assertTrue(obj.getOrderVersion() == null);
- assertTrue(obj.getProductFamilyId() == null);
- assertTrue(obj.getRequestorId() == null);
- assertTrue(obj.getSource() == null);
- assertTrue(obj.isSuppressRollback() == false);
+ assertNull(obj.getBillingAccountNumber());
+ assertNull(obj.getCallbackUrl());
+ assertNull(obj.getCorrelator());
+ assertNull(obj.getInstanceName());
+ assertNull(obj.getOrderNumber());
+ assertNull(obj.getOrderVersion());
+ assertNull(obj.getProductFamilyId());
+ assertNull(obj.getRequestorId());
+ assertNull(obj.getSource());
+ assertFalse(obj.isSuppressRollback());
}
@Test
diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java
index deedc79c5..fdc59965a 100644
--- a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java
+++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java
@@ -32,19 +32,21 @@ import org.junit.Test;
public class SoResponseWrapperTest {
+ private static final String REQ_ID = "reqID";
+
@Test
public void testConstructor() {
SoResponse response = new SoResponse();
- SoResponseWrapper obj = new SoResponseWrapper(response, "reqID");
+ SoResponseWrapper obj = new SoResponseWrapper(response, REQ_ID);
assertEquals(response, obj.getSoResponse());
- assertEquals("reqID", obj.getRequestId());
+ assertEquals(REQ_ID, obj.getRequestId());
}
@Test
public void testSetGet() {
SoResponse response = new SoResponse();
- SoResponseWrapper obj = new SoResponseWrapper(response, "reqID");
+ SoResponseWrapper obj = new SoResponseWrapper(response, REQ_ID);
SoResponse response2 = new SoResponse();
response2.setHttpResponseCode(2008);
diff --git a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java
index 850f37552..406e35d33 100644
--- a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java
+++ b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java
@@ -47,6 +47,7 @@ public final class VfcManager implements Runnable {
// The REST manager used for processing REST calls for this VFC manager
private RestManager restManager;
+ @FunctionalInterface
public interface VfcCallback {
void onResponse(VfcResponse responseError);
}
@@ -155,9 +156,11 @@ public final class VfcManager implements Runnable {
}
Thread.sleep(20000);
}
- if ((attemptsLeft <= 0) && (responseGet != null) && (responseGet.getResponseDescriptor() != null)
- && (responseGet.getResponseDescriptor().getStatus() != null)
- && (!responseGet.getResponseDescriptor().getStatus().isEmpty())) {
+ boolean isTimeout = (attemptsLeft <= 0) && (responseGet != null)
+ && (responseGet.getResponseDescriptor() != null);
+ isTimeout = isTimeout && (responseGet.getResponseDescriptor().getStatus() != null)
+ && (!responseGet.getResponseDescriptor().getStatus().isEmpty());
+ if (isTimeout) {
logger.debug("VFC timeout. Status: ({})", responseGet.getResponseDescriptor().getStatus());
this.callback.onResponse(responseGet);
}
diff --git a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/DemoTest.java b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/DemoTest.java
index 4d060a713..1c530c797 100644
--- a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/DemoTest.java
+++ b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/DemoTest.java
@@ -21,11 +21,13 @@
package org.onap.policy.vfc;
import java.util.LinkedList;
-
import org.junit.Test;
import org.onap.policy.vfc.util.Serialization;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class DemoTest {
+ private static final Logger logger = LoggerFactory.getLogger(DemoTest.class);
@Test
public void test() {
@@ -44,13 +46,13 @@ public class DemoTest {
request.getHealRequest().getAdditionalParams().getActionInfo().setVmname("xgw-smp11");
String body = Serialization.gsonPretty.toJson(request);
- System.out.println(body);
+ logger.info("{}", body);
VfcResponse response = new VfcResponse();
response.setJobId("1");
body = Serialization.gsonPretty.toJson(response);
- System.out.println(body);
+ logger.info("{}", body);
response.setResponseDescriptor(new VfcResponseDescriptor());
response.getResponseDescriptor().setProgress("40");
@@ -59,7 +61,7 @@ public class DemoTest {
response.getResponseDescriptor().setErrorCode(null);
response.getResponseDescriptor().setResponseId("42");
body = Serialization.gsonPretty.toJson(response);
- System.out.println(body);
+ logger.info("{}", body);
VfcResponseDescriptor responseDescriptor = new VfcResponseDescriptor();
responseDescriptor.setProgress("20");
@@ -72,11 +74,11 @@ public class DemoTest {
response.getResponseDescriptor().getResponseHistoryList().add(responseDescriptor);
body = Serialization.gsonPretty.toJson(response);
- System.out.println(body);
+ logger.info("{}", body);
response = Serialization.gsonPretty.fromJson(body, VfcResponse.class);
body = Serialization.gsonPretty.toJson(response);
- System.out.println(body);
+ logger.info("{}", body);
}
}
diff --git a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java
index 15534dbbb..7874d2514 100644
--- a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java
+++ b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java
@@ -22,8 +22,7 @@
package org.onap.policy.vfc;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.endsWith;
@@ -35,7 +34,6 @@ import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
-
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.rest.RestManager;
@@ -45,6 +43,10 @@ import org.onap.policy.vfc.util.Serialization;
public class VfcManagerTest implements VfcCallback {
+ private static final String SOME_URL = "http://somewhere.over.the.rainbow";
+
+ private static final String DOROTHY = "Dorothy";
+
private RestManager mockedRestManager;
private Pair<Integer, String> httpResponsePutOk;
@@ -89,7 +91,7 @@ public class VfcManagerTest implements VfcCallback {
final UUID requestId = UUID.randomUUID();
request = new VfcRequest();
request.setHealRequest(healRequest);
- request.setNsInstanceId("Dorothy");
+ request.setNsInstanceId(DOROTHY);
request.setRequestId(requestId);
List<VfcResponseDescriptor> responseHistoryList = new ArrayList<>();;
@@ -110,49 +112,31 @@ public class VfcManagerTest implements VfcCallback {
@Test
public void testVfcInitiation() {
- try {
- new VfcManager(null, null, null, null, null);
- fail("test should throw an exception here");
- }
- catch (IllegalArgumentException e) {
- assertEquals("the parameters \"cb\" and \"request\" on the VfcManager constructor may not be null",
- e.getMessage());
- }
-
- try {
- new VfcManager(this, null, null, null, null);
- fail("test should throw an exception here");
- }
- catch (IllegalArgumentException e) {
- assertEquals("the parameters \"cb\" and \"request\" on the VfcManager constructor may not be null",
- e.getMessage());
- }
-
- try {
- new VfcManager(this, request, null, null, null);
- fail("test should throw an exception here");
- }
- catch (IllegalArgumentException e) {
- assertEquals("the \"url\" parameter on the VfcManager constructor may not be null",
- e.getMessage());
- }
-
- new VfcManager(this, request, "http://somewhere.over.the.rainbow", null, null);
-
- new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Toto");
+ assertThatIllegalArgumentException().isThrownBy(() -> new VfcManager(null, null, null, null, null)).withMessage(
+ "the parameters \"cb\" and \"request\" on the VfcManager constructor may not be null");
+
+ assertThatIllegalArgumentException().isThrownBy(() -> new VfcManager(this, null, null, null, null)).withMessage(
+ "the parameters \"cb\" and \"request\" on the VfcManager constructor may not be null");
+
+ assertThatIllegalArgumentException().isThrownBy(() -> new VfcManager(this, request, null, null, null))
+ .withMessage("the \"url\" parameter on the VfcManager constructor may not be null");
+
+ new VfcManager(this, request, SOME_URL, null, null);
+
+ new VfcManager(this, request, SOME_URL, DOROTHY, "Toto");
}
@Test
public void testVfcExecutionException() throws InterruptedException {
- VfcManager manager = new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Exception");
+ VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "Exception");
manager.setRestManager(mockedRestManager);
Thread managerThread = new Thread(manager);
managerThread.start();
when(mockedRestManager.post(
- startsWith("http://somewhere.over.the.rainbow"),
- eq("Dorothy"),
+ startsWith(SOME_URL),
+ eq(DOROTHY),
eq("Exception"),
anyMap(),
anyString(),
@@ -164,14 +148,14 @@ public class VfcManagerTest implements VfcCallback {
@Test
public void testVfcExecutionNull() throws InterruptedException {
- VfcManager manager = new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Null");
+ VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "Null");
manager.setRestManager(mockedRestManager);
Thread managerThread = new Thread(manager);
managerThread.start();
- when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"),
- eq("Dorothy"), eq("Null"), anyMap(), anyString(), anyString()))
+ when(mockedRestManager.post(startsWith(SOME_URL),
+ eq(DOROTHY), eq("Null"), anyMap(), anyString(), anyString()))
.thenReturn(null);
managerThread.join();
@@ -179,14 +163,14 @@ public class VfcManagerTest implements VfcCallback {
@Test
public void testVfcExecutionError0() throws InterruptedException {
- VfcManager manager = new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Error0");
+ VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "Error0");
manager.setRestManager(mockedRestManager);
Thread managerThread = new Thread(manager);
managerThread.start();
- when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"),
- eq("Dorothy"), eq("Error0"), anyMap(), anyString(), anyString()))
+ when(mockedRestManager.post(startsWith(SOME_URL),
+ eq(DOROTHY), eq("Error0"), anyMap(), anyString(), anyString()))
.thenReturn(httpResponseErr);
managerThread.join();
@@ -194,14 +178,14 @@ public class VfcManagerTest implements VfcCallback {
@Test
public void testVfcExecutionBadResponse() throws InterruptedException {
- VfcManager manager = new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "BadResponse");
+ VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "BadResponse");
manager.setRestManager(mockedRestManager);
Thread managerThread = new Thread(manager);
managerThread.start();
- when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"),
- eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString()))
+ when(mockedRestManager.post(startsWith(SOME_URL),
+ eq(DOROTHY), eq("OK"), anyMap(), anyString(), anyString()))
.thenReturn(httpResponseBadResponse);
managerThread.join();
@@ -209,17 +193,17 @@ public class VfcManagerTest implements VfcCallback {
@Test
public void testVfcExecutionOk() throws InterruptedException {
- VfcManager manager = new VfcManager(this, request, "http://somewhere.over.the.rainbow", "Dorothy", "Ok");
+ VfcManager manager = new VfcManager(this, request, SOME_URL, DOROTHY, "Ok");
manager.setRestManager(mockedRestManager);
Thread managerThread = new Thread(manager);
managerThread.start();
- when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"),
- eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString()))
+ when(mockedRestManager.post(startsWith(SOME_URL),
+ eq(DOROTHY), eq("OK"), anyMap(), anyString(), anyString()))
.thenReturn(httpResponsePutOk);
- when(mockedRestManager.get(endsWith("1234"), eq("Dorothy"), eq("OK"), anyMap()))
+ when(mockedRestManager.get(endsWith("1234"), eq(DOROTHY), eq("OK"), anyMap()))
.thenReturn(httpResponseGetOk);
managerThread.join();