Honor user-cookie to select a temporal feature set
[vid.git] / vid-app-common / src / test / java / org / onap / vid / services / AsyncInstantiationBusinessLogicTest.java
index 93208aa..0749aaf 100644 (file)
@@ -23,8 +23,10 @@ package org.onap.vid.services;
 import static net.javacrumbs.jsonunit.JsonAssert.assertJsonEquals;
 import static net.javacrumbs.jsonunit.JsonAssert.whenIgnoringPaths;
 import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
+import static net.javacrumbs.jsonunit.JsonMatchers.jsonPartEquals;
 import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.allOf;
 import static org.hamcrest.Matchers.containsInAnyOrder;
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.hasItem;
@@ -59,12 +61,14 @@ import static org.onap.vid.job.Job.JobStatus.PAUSE;
 import static org.onap.vid.job.Job.JobStatus.PENDING;
 import static org.onap.vid.job.Job.JobStatus.STOPPED;
 import static org.onap.vid.testUtils.TestUtils.generateRandomAlphaNumeric;
+import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -150,8 +154,6 @@ import org.testng.annotations.Test;
 @ContextConfiguration(classes = {DataSourceConfig.class, SystemProperties.class, MockedAaiClientAndFeatureManagerConfig.class})
 public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseTest {
 
-
-
     @Mock
     private JobAdapter jobAdapterMock;
 
@@ -491,21 +493,33 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
         return prepareServiceInstantiation(PROJECT_NAME, isUserProvidedNaming, bulkSize);
     }
 
-    @Test
-    public void getSummarizedMap(){
+    @DataProvider
+    public static Object[][] dataProviderSummarizedMap() {
+        return new Object[][]{
+            {"/payload_jsons/templateSummarize4vnfs6vfmodules.json", ImmutableMap.of("vnf", 4L, "vfModule", 6L, "volumeGroup", 1L, "network", 2L)},
+            {"/payload_jsons/templateSummarize3Vnfs8Vfmodule2VolumeGroups.json", ImmutableMap.of("vnf", 3L, "vfModule", 8L, "volumeGroup", 2L)},
+            {"/payload_jsons/templateSummarize3Networks.json", ImmutableMap.of("network", 3L)},
+
+        };
+    }
+
+    @Test(dataProvider = "dataProviderSummarizedMap")
+    public void summarizedChildrenMap_givenServiceInstantiation_yieldCorrectMap(String pathInResource, Map<String, Long> expectedMap){
         ServiceInstantiation serviceInstantiation = TestUtils.readJsonResourceFileAsObject(
-            "/payload_jsons/templateSummarize4vnfs6vfmodules.json", ServiceInstantiation.class);
-        Map<String, Long> childrenMap =  asyncInstantiationBL.getSummarizedChildrenMap(serviceInstantiation);
-        Map<String, Long> expectedMap = ImmutableMap.of(
-            "vnf", 4L,
-            "vfModule", 6L,
-            "volumeGroup", 1L,
-            "network", 2L
-        );
+            pathInResource, ServiceInstantiation.class);
+        Map<String, Long> childrenMap =  asyncInstantiationBL.summarizedChildrenMap(serviceInstantiation);
         assertEquals(childrenMap,expectedMap);
-
     }
 
+    @Test
+    public void requestSummaryOrNull_givenActionWhichIsNotCreate_yieldNullRegardlessOfPayload(){
+        ServiceInstantiation serviceInstantiation = mock(ServiceInstantiation.class);
+
+        when(serviceInstantiation.getAction()).thenReturn(Action.Upgrade);
+        when(featureManager.isActive(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE)).thenReturn(true);
+
+        assertThat(asyncInstantiationBL.requestSummaryOrNull(serviceInstantiation), is(nullValue()));
+    }
 
     @Test
     public void whenPushBulkJob_thenJobRequestIsSaveInJobRequestDb() {
@@ -751,7 +765,7 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
                 UUID.randomUUID(),
                 UUID.randomUUID(),
                 new Date(),
-                "myName", ServiceInfo.ServiceAction.INSTANTIATE);
+                "myName", ServiceInfo.ServiceAction.INSTANTIATE, null);
         assertEquals(SERVICE_MODEL_VERSION_ID, serviceInfo.getServiceModelId());
 
     }
@@ -1379,7 +1393,36 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
     {
         String path = asyncInstantiationBL.getVfModuleReplacePath("myService", "myVNF", "myVFModule");
         assertThat(path, equalTo("/serviceInstantiation/v7/serviceInstances/myService/vnfs/myVNF/vfModules/myVFModule/replace"));
+    }
 
+    @Test
+    public void whenCallClearStatusFromRequest_isFailedAndStatusAreRemoved() throws JsonProcessingException {
+        ServiceInstantiation serviceInstantiation = JACKSON_OBJECT_MAPPER.readValue(
+               "{"
+                + "    \"modelInfo\": {"
+                + "        \"modelType\": \"service\""
+                + "    },"
+                + "    \"isFailed\": true,"
+                + "    \"statusMessage\": \"some status\","
+                + "    \"vnfs\": {"
+                + "        \"vProbe_NC_VNF\": {"
+                + "            \"modelInfo\": {"
+                + "                \"modelType\": \"vnf\""
+                + "            },"
+                + "            \"isFailed\": true,"
+                + "            \"statusMessage\": \"other status\""
+                + "        }"
+                + "    }"
+                + "}",
+            ServiceInstantiation.class);
+        asyncInstantiationBL.clearStatusFromRequest(serviceInstantiation);
+        assertThat(serviceInstantiation, allOf(
+            jsonPartEquals("isFailed", false),
+            jsonPartEquals("statusMessage", null),
+            jsonPartEquals("vnfs.vProbe_NC_VNF.isFailed", false),
+            jsonPartEquals("vnfs.vProbe_NC_VNF.statusMessage", null)
+        ));
     }
 
+
 }