Fix basic code issues in controlloop 69/59069/2
authorKrishnajinka <kris.jinka@samsung.com>
Mon, 6 Aug 2018 05:18:00 +0000 (14:18 +0900)
committerKrishnakumar Jinka <kris.jinka@samsung.com>
Mon, 6 Aug 2018 22:30:03 +0000 (22:30 +0000)
Found few issues while going through the code. Fixing
these issues in the controlloop package classes

Issue-ID: POLICY-1017
Change-Id: I24d0ce1257ad689c3e9d9b7a3bea07eeb65383f1
Signed-off-by: Krishnajinka <kris.jinka@samsung.com>
controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java
controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java
controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java
controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java
controlloop/common/actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/TestVFCActorServiceProvider.java
controlloop/common/actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/ActorService.java
controlloop/common/actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/spi/Actor.java
controlloop/common/actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/TestActor.java

index 5130276..1fffe04 100644 (file)
@@ -53,9 +53,9 @@ public class AppcServiceProviderTest {
 
     private static final Logger logger = LoggerFactory.getLogger(AppcServiceProviderTest.class);
 
-    private static VirtualControlLoopEvent onsetEvent;
-    private static ControlLoopOperation operation;
-    private static Policy policy;
+    private static final VirtualControlLoopEvent onsetEvent;
+    private static final ControlLoopOperation operation;
+    private static final Policy policy;
 
     static {
         /*
@@ -124,7 +124,7 @@ public class AppcServiceProviderTest {
     @Test
     public void constructModifyConfigRequestTest() {
 
-        Request appcRequest = null;
+        Request appcRequest;
         appcRequest = APPCActorServiceProvider.constructRequest(onsetEvent, operation, policy, "vnf01");
 
         /* The service provider must return a non null APPC request */
index c370f15..1d4af38 100644 (file)
@@ -299,7 +299,7 @@ public class AppcLcmActorServiceProvider implements Actor {
             return new AbstractMap.SimpleEntry<>(PolicyResult.FAILURE_EXCEPTION, message);
         }
 
-        /* Save the APPC response's message for Policy noticiation message. */
+        /* Save the APPC response's message for Policy notification message. */
         message = appcResponse.getStatus().getMessage();
 
         /* Maps the APPC response result to a Policy result. */
@@ -326,7 +326,7 @@ public class AppcLcmActorServiceProvider implements Actor {
      * This method reads and validates environmental properties coming from the policy engine. Null
      * properties cause an {@link IllegalArgumentException} runtime exception to be thrown
      * 
-     * @param string the name of the parameter to retrieve
+     * @param enginePropertyName the name of the parameter to retrieve
      * @return the property value
      */
     private static String getPeManagerEnvProperty(String enginePropertyName) {
index 48c613d..f6131b1 100644 (file)
@@ -22,6 +22,7 @@ package org.onap.policy.controlloop.actor.appclcm;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.fail;
 
 import java.time.Instant;
@@ -52,15 +53,15 @@ import org.onap.policy.simulators.Util;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 public class AppcLcmServiceProviderTest {
 
     private static final Logger logger = LoggerFactory.getLogger(AppcLcmServiceProviderTest.class);
 
-    private static VirtualControlLoopEvent onsetEvent;
-    private static ControlLoopOperation operation;
-    private static Policy policy;
-    private static LcmRequestWrapper dmaapRequest;
-    private static LcmResponseWrapper dmaapResponse;
+    private static final VirtualControlLoopEvent onsetEvent;
+    private static final ControlLoopOperation operation;
+    private static final Policy policy;
+    private static final LcmResponseWrapper dmaapResponse;
 
     static {
         /*
@@ -99,7 +100,7 @@ public class AppcLcmServiceProviderTest {
         policy.setTimeout(300);
 
         /* A sample DMAAP request wrapper. */
-        dmaapRequest = new LcmRequestWrapper();
+        LcmRequestWrapper dmaapRequest = new LcmRequestWrapper();
         dmaapRequest.setCorrelationId(onsetEvent.getRequestId().toString() + "-" + "1");
         dmaapRequest.setRpcName(policy.getRecipe().toLowerCase());
         dmaapRequest.setType("request");
@@ -224,7 +225,7 @@ public class AppcLcmServiceProviderTest {
         dmaapResponse.getBody().getStatus().setCode(100);
         dmaapResponse.getBody().getStatus().setMessage("ACCEPTED");
         result = AppcLcmActorServiceProvider.processResponse(dmaapResponse);
-        assertEquals(null, result.getKey());
+        assertNull(result.getKey());
 
         /* If APPC is successful, PolicyResult is success */
         dmaapResponse.getBody().getStatus().setCode(400);
index 49b4e98..de4e439 100644 (file)
@@ -121,7 +121,7 @@ public class SOActorServiceProvider implements Actor {
         // Perform named query request and handle response
         AaiNqResponseWrapper aaiResponseWrapper = performAaiNamedQueryRequest(onset);
         if (aaiResponseWrapper == null) {
-            // Tracing and error handling handied in the "performAaiNamedQueryRequest()" method
+            // Tracing and error handling handled in the "performAaiNamedQueryRequest()" method
             return null;
         }
 
@@ -292,8 +292,8 @@ public class SOActorServiceProvider implements Actor {
     /**
      * Constructs and sends an AAI vserver Named Query.
      * 
-     * @param onset the virtial control loop event
-     * @returns the response to the AAI Named Query
+     * @param onset the virtual control loop event
+     * @return the response to the AAI Named Query
      */
     private AaiNqResponseWrapper performAaiNamedQueryRequest(VirtualControlLoopEvent onset) {
 
@@ -353,10 +353,10 @@ public class SOActorServiceProvider implements Actor {
      * @return the base or non base index or -1 if the index was not found
      */
     private int findIndex(List<AaiNqInventoryResponseItem> inventoryResponseItems, boolean baseIndexFlag) {
-        for (AaiNqInventoryResponseItem invenoryResponseItem : inventoryResponseItems) {
-            if (invenoryResponseItem.getVfModule() != null
-                    && baseIndexFlag == invenoryResponseItem.getVfModule().getIsBaseVfModule()) {
-                return inventoryResponseItems.indexOf(invenoryResponseItem);
+        for (AaiNqInventoryResponseItem inventoryResponseItem : inventoryResponseItems) {
+            if (inventoryResponseItem.getVfModule() != null
+                    && baseIndexFlag == inventoryResponseItem.getVfModule().getIsBaseVfModule()) {
+                return inventoryResponseItems.indexOf(inventoryResponseItem);
             }
         }
 
@@ -373,9 +373,9 @@ public class SOActorServiceProvider implements Actor {
     @SuppressWarnings("unused")
     private int findNonBaseModules(List<AaiNqInventoryResponseItem> inventoryResponseItems) {
         int nonBaseModuleCount = 0;
-        for (AaiNqInventoryResponseItem invenoryResponseItem : inventoryResponseItems) {
-            if (invenoryResponseItem.getVfModule() != null
-                    && (!invenoryResponseItem.getVfModule().getIsBaseVfModule())) {
+        for (AaiNqInventoryResponseItem inventoryResponseItem : inventoryResponseItems) {
+            if (inventoryResponseItem.getVfModule() != null
+                    && (!inventoryResponseItem.getVfModule().getIsBaseVfModule())) {
                 nonBaseModuleCount++;
             }
         }
@@ -398,7 +398,7 @@ public class SOActorServiceProvider implements Actor {
      * This method reads and validates environmental properties coming from the policy engine. Null
      * properties cause an {@link IllegalArgumentException} runtime exception to be thrown
      * 
-     * @param string the name of the parameter to retrieve
+     * @param enginePropertyName the name of the parameter to retrieve
      * @return the property value
      */
     private static String getPeManagerEnvProperty(String enginePropertyName) {
index 65425b0..caf89eb 100644 (file)
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.fail;
 
+import java.util.Objects;
 import java.util.UUID;
 
 import org.junit.AfterClass;
@@ -98,7 +99,7 @@ public class TestVFCActorServiceProvider {
         VFCRequest request =
                 VFCActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse());
 
-        assertEquals(requestId, request.getRequestId());
+        assertEquals(requestId, Objects.requireNonNull(request).getRequestId());
         assertEquals("dorothy.gale.1939", request.getHealRequest().getVnfInstanceId());
         assertEquals("restartvm", request.getHealRequest().getAdditionalParams().getAction());
     }
index b0b7eb5..aeb536c 100644 (file)
@@ -35,7 +35,7 @@ public class ActorService {
     private static ActorService service;
 
     // USed to load actors
-    private ServiceLoader<Actor> loader;
+    private final ServiceLoader<Actor> loader;
 
     private ActorService() {
         loader = ServiceLoader.load(Actor.class);
index 46cc6f6..47e02a5 100644 (file)
@@ -24,12 +24,12 @@ import java.util.List;
 
 public interface Actor {
 
-    public String actor();
+    String actor();
 
-    public List<String> recipes();
+    List<String> recipes();
 
-    public List<String> recipeTargets(String recipe);
+    List<String> recipeTargets(String recipe);
 
-    public List<String> recipePayloads(String recipe);
+    List<String> recipePayloads(String recipe);
 
 }
index 0fd00e1..af04cc1 100644 (file)
@@ -33,28 +33,28 @@ public class TestActor implements Actor {
 
     @Override
     public List<String> recipes() {
-        List<String> recipieList = new ArrayList<>();
-        recipieList.add("Dorothy");
-        recipieList.add("Wizard");
+        List<String> recipeList = new ArrayList<>();
+        recipeList.add("Dorothy");
+        recipeList.add("Wizard");
 
-        return recipieList;
+        return recipeList;
     }
 
     @Override
     public List<String> recipeTargets(String recipe) {
-        List<String> recipieTargetList = new ArrayList<>();
-        recipieTargetList.add("Wicked Witch");
-        recipieTargetList.add("Wizard of Oz");
+        List<String> recipeTargetList = new ArrayList<>();
+        recipeTargetList.add("Wicked Witch");
+        recipeTargetList.add("Wizard of Oz");
 
-        return recipieTargetList;
+        return recipeTargetList;
     }
 
     @Override
     public List<String> recipePayloads(String recipe) {
-        List<String> recipiePayloadList = new ArrayList<>();
-        recipiePayloadList.add("Dorothy");
-        recipiePayloadList.add("Toto");
+        List<String> recipePayloadList = new ArrayList<>();
+        recipePayloadList.add("Dorothy");
+        recipePayloadList.add("Toto");
 
-        return recipiePayloadList;
+        return recipePayloadList;
     }
 }