Implant vid-app-common org.onap.vid.job (main and test)
[vid.git] / vid-app-common / src / test / java / org / onap / vid / job / impl / JobAdapterTest.java
index f6785c3..4e11b7e 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,10 +26,15 @@ import org.onap.vid.job.Job;
 import org.onap.vid.job.JobAdapter;
 import org.onap.vid.job.JobType;
 import org.onap.vid.job.command.JobCommandFactoryTest;
+import org.onap.vid.properties.Features;
+import org.onap.vid.testUtils.TestUtils;
 import org.testng.annotations.Test;
+import org.togglz.core.manager.FeatureManager;
 
 import java.util.UUID;
 
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotEquals;
 import static org.testng.AssertJUnit.assertNotNull;
@@ -38,12 +43,14 @@ public class JobAdapterTest {
 
     @Test
     public void testCreateServiceInstantiationJob() {
-        JobAdapter jobAdapter = new JobAdapterImpl();
+        FeatureManager featureManager = mock(FeatureManager.class);
+        JobAdapter jobAdapter = new JobAdapterImpl(featureManager);
 
         JobType jobType = JobType.NoOp;
         JobAdapter.AsyncJobRequest request = new JobCommandFactoryTest.MockedRequest(42,"nothing");
         UUID templateId = UUID.randomUUID();
         String userId = "ou012t";
+        String testApi = "VNF_API";
         String optimisticUniqueServiceInstanceName = "optimisticUniqueServiceInstanceName";
         int indexInBulk = RandomUtils.nextInt();
         Job job = jobAdapter.createServiceInstantiationJob(
@@ -51,6 +58,7 @@ public class JobAdapterTest {
                 request,
                 templateId,
                 userId,
+                testApi,
                 optimisticUniqueServiceInstanceName,
                 indexInBulk
                 );
@@ -59,6 +67,7 @@ public class JobAdapterTest {
         assertEquals(job.getSharedData().getRequest(), request);
         assertEquals(job.getSharedData().getRequestType(), request.getClass());
         assertEquals(job.getSharedData().getUserId(), userId);
+        assertEquals(job.getSharedData().getTestApi(), testApi);
         assertEquals(job.getSharedData().getJobUuid(), job.getUuid());
         assertEquals(job.getSharedData().getRootJobId(), job.getUuid());
         assertNotNull(job.getUuid());
@@ -68,13 +77,16 @@ public class JobAdapterTest {
         assertEquals(job.getStatus(), Job.JobStatus.PENDING);
     }
 
-    @Test
-    public void testCreateChildJob() {
-
-        JobAdapter jobAdapter = new JobAdapterImpl();
+    @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class)
+    public void testCreateChildJob(boolean isFlagExpCreateResourcesInParallel) {
+        FeatureManager featureManager = mock(FeatureManager.class);
+        when(featureManager.isActive(Features.FLAG_EXP_CREATE_RESOURCES_IN_PARALLEL)).thenReturn(isFlagExpCreateResourcesInParallel);
+        Job.JobStatus expectedJobStatus = isFlagExpCreateResourcesInParallel ? Job.JobStatus.CREATING : Job.JobStatus.PENDING_RESOURCE;
+        JobAdapter jobAdapter = new JobAdapterImpl(featureManager);
 
         UUID templateId = UUID.randomUUID();
         String userId = "ou012t";
+        String testApi = "VNF_API";
         String optimisticUniqueServiceInstanceName = "optimisticUniqueServiceInstanceName";
         int indexInBulk = RandomUtils.nextInt();
         Job grandJob = jobAdapter.createServiceInstantiationJob(
@@ -82,39 +94,44 @@ public class JobAdapterTest {
                 new JobCommandFactoryTest.MockedRequest(99, "anything"),
                 templateId,
                 userId,
+                testApi,
                 optimisticUniqueServiceInstanceName,
                 indexInBulk
         );
 
-        Job.JobStatus jobStatus = Job.JobStatus.PAUSE;
         JobType jobType = JobType.NoOp;
         JobAdapter.AsyncJobRequest request = new JobCommandFactoryTest.MockedRequest(42,"nothing");
-        Job parentJob = jobAdapter.createChildJob(jobType, jobStatus, request, grandJob.getSharedData(), ImmutableMap.of());
+        Job parentJob = jobAdapter.createChildJob(jobType, request, grandJob.getSharedData(), ImmutableMap.of(), 1);
 
         assertEquals(parentJob.getType(), jobType);
         assertEquals(parentJob.getSharedData().getRequest(), request);
         assertEquals(parentJob.getSharedData().getRequestType(), request.getClass());
         assertEquals(parentJob.getSharedData().getUserId(), userId);
+        assertEquals(parentJob.getSharedData().getTestApi(), testApi);
         assertEquals(parentJob.getSharedData().getJobUuid(), parentJob.getUuid());
         assertNotNull(parentJob.getUuid());
         assertNotEquals(parentJob.getUuid(), grandJob.getUuid());
-        assertEquals(parentJob.getStatus(), jobStatus);
+        assertEquals(parentJob.getStatus(), expectedJobStatus);
+        assertEquals(parentJob.getTemplateId(), grandJob.getUuid());
+        assertEquals(parentJob.getIndexInBulk().intValue(), 1);
         assertEquals(parentJob.getSharedData().getRootJobId(), grandJob.getUuid());
 
-        Job.JobStatus jobStatus2 = Job.JobStatus.IN_PROGRESS;
         JobType jobType2 = JobType.AggregateState;
         JobAdapter.AsyncJobRequest request2 = new JobCommandFactoryTest.MockedRequest(66,"abc");
-        Job job = jobAdapter.createChildJob(jobType2, jobStatus2, request2, parentJob.getSharedData(), ImmutableMap.of());
+        Job job = jobAdapter.createChildJob(jobType2, request2, parentJob.getSharedData(), ImmutableMap.of(), 0);
 
         assertEquals(job.getType(), jobType2);
         assertEquals(job.getSharedData().getRequest(), request2);
         assertEquals(job.getSharedData().getRequestType(), request2.getClass());
         assertEquals(job.getSharedData().getUserId(), userId);
+        assertEquals(job.getSharedData().getTestApi(), testApi);
         assertEquals(job.getSharedData().getJobUuid(), job.getUuid());
         assertNotNull(job.getUuid());
         assertNotEquals(job.getUuid(), parentJob.getUuid());
-        assertEquals(job.getStatus(), jobStatus2);
+        assertEquals(job.getStatus(), expectedJobStatus);
         assertEquals(job.getSharedData().getRootJobId(), grandJob.getUuid());
+        assertEquals(job.getTemplateId(), parentJob.getUuid());
+        assertEquals(job.getIndexInBulk().intValue(), 0);
 
     }
 }