Skip preprocessor step in Actors
[policy/models.git] / models-interactions / model-actors / actor.so / src / test / java / org / onap / policy / controlloop / actor / so / VfModuleCreateTest.java
index 8c084b8..012f8de 100644 (file)
 
 package org.onap.policy.controlloop.actor.so;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ForkJoinPool;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.commons.lang3.tuple.Pair;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
 import org.onap.aai.domain.yang.CloudRegion;
@@ -45,11 +50,16 @@ import org.onap.aai.domain.yang.ModelVer;
 import org.onap.aai.domain.yang.ServiceInstance;
 import org.onap.aai.domain.yang.Tenant;
 import org.onap.policy.aai.AaiCqResponse;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams;
 import org.onap.policy.controlloop.policy.PolicyResult;
 import org.onap.policy.so.SoRequest;
+import org.onap.policy.so.SoResponse;
 
 public class VfModuleCreateTest extends BasicSoOperation {
     private static final String MODEL_NAME2 = "my-model-name-B";
@@ -63,6 +73,15 @@ public class VfModuleCreateTest extends BasicSoOperation {
         super(DEFAULT_ACTOR, VfModuleCreate.NAME);
     }
 
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        initBeforeClass();
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() {
+        destroyAfterClass();
+    }
 
     @Before
     public void setUp() throws Exception {
@@ -70,6 +89,25 @@ public class VfModuleCreateTest extends BasicSoOperation {
         oper = new VfModuleCreate(params, config);
     }
 
+    /**
+     * Tests "success" case with simulator.
+     */
+    @Test
+    public void testSuccess() throws Exception {
+        HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT)
+                        .path("serviceInstantiation/v7/serviceInstances").pollPath("orchestrationRequests/v5/")
+                        .maxPolls(2).build();
+        config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+        params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+
+        oper = new VfModuleCreate(params, config);
+
+        outcome = oper.start().get();
+        assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+        assertTrue(outcome.getResponse() instanceof SoResponse);
+    }
+
     @Test
     public void testConstructor() {
         assertEquals(DEFAULT_ACTOR, oper.getActorName());
@@ -81,6 +119,19 @@ public class VfModuleCreateTest extends BasicSoOperation {
                         .withMessageContaining("Target information");
     }
 
+    @Test
+    public void testGetPropertyNames() {
+        // @formatter:off
+        assertThat(oper.getPropertyNames()).isEqualTo(
+                        List.of(
+                            OperationProperties.AAI_MODEL_SERVICE,
+                            OperationProperties.AAI_MODEL_VNF,
+                            OperationProperties.AAI_MODEL_CLOUD_REGION,
+                            OperationProperties.AAI_MODEL_TENANT,
+                            OperationProperties.DATA_VF_COUNT));
+        // @formatter:on
+    }
+
     @Test
     public void testStartPreprocessorAsync() throws Exception {
         // insert CQ data so it's there for the check
@@ -101,6 +152,15 @@ public class VfModuleCreateTest extends BasicSoOperation {
         assertTrue(guardStarted.get());
     }
 
+    /**
+     * Tests startPreprocessorAsync(), when preprocessing is disabled.
+     */
+    @Test
+    public void testStartPreprocessorAsyncDisabled() {
+        params = params.toBuilder().preprocessed(true).build();
+        assertNull(new VfModuleCreate(params, config).startPreprocessorAsync());
+    }
+
     @Test
     public void testStartGuardAsync() throws Exception {
         // remove CQ data so it's forced to query
@@ -132,15 +192,7 @@ public class VfModuleCreateTest extends BasicSoOperation {
         Map<String, Object> payload = captor.getValue().getPayload();
         assertNotNull(payload);
 
-        @SuppressWarnings("unchecked")
-        Map<String, Object> resource = (Map<String, Object>) payload.get("resource");
-        assertNotNull(resource);
-
-        @SuppressWarnings("unchecked")
-        Map<String, Object> guard = (Map<String, Object>) resource.get("guard");
-        assertNotNull(guard);
-
-        Integer newCount = (Integer) guard.get(VfModuleCreate.PAYLOAD_KEY_VF_COUNT);
+        Integer newCount = (Integer) payload.get(VfModuleCreate.PAYLOAD_KEY_VF_COUNT);
         assertNotNull(newCount);
         assertEquals(origCount + 1, newCount.intValue());
     }
@@ -157,7 +209,7 @@ public class VfModuleCreateTest extends BasicSoOperation {
 
         oper = new VfModuleCreate(params, config) {
             @Override
-            public long getWaitMsGet() {
+            protected long getPollWaitMs() {
                 return 1;
             }
         };
@@ -167,14 +219,18 @@ public class VfModuleCreateTest extends BasicSoOperation {
         outcome = future2.get(5, TimeUnit.SECONDS);
         assertEquals(PolicyResult.SUCCESS, outcome.getResult());
 
+        SoResponse resp = outcome.getResponse();
+        assertNotNull(resp);
+        assertEquals(REQ_ID.toString(), resp.getRequestReferences().getRequestId());
+
         assertEquals(origCount + 1, oper.getVfCount());
     }
 
     /**
-     * Tests startOperationAsync() when "get" operations are required.
+     * Tests startOperationAsync() when polling is required.
      */
     @Test
-    public void testStartOperationAsyncWithGets() throws Exception {
+    public void testStartOperationAsyncWithPolling() throws Exception {
         when(rawResponse.getStatus()).thenReturn(500, 500, 500, 500, 200, 200);
 
         when(client.post(any(), any(), any(), any())).thenAnswer(provideResponse(rawResponse));
@@ -185,7 +241,7 @@ public class VfModuleCreateTest extends BasicSoOperation {
 
         oper = new VfModuleCreate(params, config) {
             @Override
-            public long getWaitMsGet() {
+            public long getPollWaitMs() {
                 return 1;
             }
         };