Merge "Fix sonar issues in models: sdc to vfc"
authorJorge Hernandez <jorge.hernandez-herrero@att.com>
Mon, 17 Jun 2019 21:13:40 +0000 (21:13 +0000)
committerGerrit Code Review <gerrit@onap.org>
Mon, 17 Jun 2019 21:13:40 +0000 (21:13 +0000)
24 files changed:
models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceInstanceTest.java
models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceTest.java
models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceInstanceTest.java
models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceTest.java
models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java
models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/util/Serialization.java
models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java
models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java
models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciCommonHeader.java
models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequest.java
models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java
models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java
models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java
models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java
models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java
models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/SdnrTest.java
models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java
models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoDummyServer.java
models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java
models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestInfoTest.java
models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java
models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java
models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/DemoTest.java
models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java

index 9409635..8ae0084 100644 (file)
@@ -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());
index 60510a1..6949a36 100644 (file)
@@ -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());
index ca2cb3d..c06974c 100644 (file)
@@ -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());
     }
index 3bf6a53..1923862 100644 (file)
@@ -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());
     }
index 3679625..7612eeb 100644 (file)
@@ -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
                 );
index cfaa46f..090b4f9 100644 (file)
@@ -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() {
+
+    }
 }
index 1c18d9c..41f07c3 100644 (file)
@@ -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);
 
     }
 }
index 2a1cc69..c069f1c 100644 (file)
@@ -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);
 
 
index f575a73..8552bb2 100644 (file)
@@ -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.
      *
index 73ee4c6..d76dd88 100644 (file)
@@ -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) {
index f0cc246..84178e0 100644 (file)
@@ -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);
index 023dd18..0009c2a 100644 (file)
@@ -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);
index 27f4c23..6e990ea 100644 (file)
@@ -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));
     }
index f8f5820..08ac56b 100644 (file)
@@ -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));
     }
 }
index 151d334..f05f50e 100644 (file)
@@ -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));
     }
 }
index 8317482..4cbda52 100644 (file)
@@ -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);
index 888afe2..6e2494b 100644 (file)
@@ -68,6 +68,7 @@ public final class SoManager {
     private String user;
     private String password;
 
+    @FunctionalInterface
     public interface SoCallback {
         public void onSoResponseWrapper(SoResponseWrapper wrapper);
     }
index e9c3383..d7e7a11 100644 (file)
@@ -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())
index 03ac06d..aa3562a 100644 (file)
@@ -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
index 2302696..dd7db84 100644 (file)
@@ -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
index deedc79..fdc5996 100644 (file)
@@ -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);
index 850f375..406e35d 100644 (file)
@@ -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);
             }
index 4d060a7..1c530c7 100644 (file)
 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);
 
     }
 }
index 15534db..7874d25 100644 (file)
@@ -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();