summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-impl/vfc/src/test
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/model-impl/vfc/src/test
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/model-impl/vfc/src/test')
-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
2 files changed, 42 insertions, 56 deletions
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();