aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap
diff options
context:
space:
mode:
authorEinat Vinouze <einat.vinouze@intl.att.com>2020-05-20 12:00:29 +0300
committerEinat Vinouze <einat.vinouze@intl.att.com>2020-05-21 08:32:30 +0300
commitcb024eb027cb9e0776359a9ee06b1caec4592256 (patch)
tree0c264aa8b5461d88ab3eb40e2bd35989588145a6 /vid-app-common/src/test/java/org/onap
parent19016e3c0951ff994956e93b1c24e412a7ed542e (diff)
Set JobStatus as COMPLETED_AND_PAUSED when needed so we can present it on instantiationStatus
Issue-ID: VID-821 Signed-off-by: Einat Vinouze <einat.vinouze@intl.att.com> Change-Id: I19328ce643ea984a97dc04183626dea133be517d Signed-off-by: Einat Vinouze <einat.vinouze@intl.att.com>
Diffstat (limited to 'vid-app-common/src/test/java/org/onap')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/job/command/ResourceCommandTest.java110
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/job/command/WatchChildrenJobsBLTest.java28
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/job/impl/AsyncInstantiationIntegrationTest.java9
3 files changed, 82 insertions, 65 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/job/command/ResourceCommandTest.java b/vid-app-common/src/test/java/org/onap/vid/job/command/ResourceCommandTest.java
index 9d466f4b3..85faaab28 100644
--- a/vid-app-common/src/test/java/org/onap/vid/job/command/ResourceCommandTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/job/command/ResourceCommandTest.java
@@ -28,6 +28,14 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.onap.vid.job.Job.JobStatus.COMPLETED;
+import static org.onap.vid.job.Job.JobStatus.COMPLETED_WITH_ERRORS;
+import static org.onap.vid.job.Job.JobStatus.COMPLETED_WITH_NO_ACTION;
+import static org.onap.vid.job.Job.JobStatus.FAILED;
+import static org.onap.vid.job.Job.JobStatus.IN_PROGRESS;
+import static org.onap.vid.job.Job.JobStatus.PAUSE;
+import static org.onap.vid.job.Job.JobStatus.RESOURCE_IN_PROGRESS;
+import static org.onap.vid.job.Job.JobStatus.STOPPED;
import static org.onap.vid.job.command.ResourceCommandKt.ACTION_PHASE;
import static org.onap.vid.job.command.ResourceCommandKt.INTERNAL_STATE;
import static org.onap.vid.job.command.ResourceCommandTest.FakeResourceCreator.createGroup;
@@ -212,14 +220,14 @@ public class ResourceCommandTest {
@DataProvider
public static Object[][] nextStateDeletePhaseProvider() {
return new Object[][]{
- {InternalState.CREATING_CHILDREN, Job.JobStatus.COMPLETED, InternalState.WATCHING},
- {InternalState.WATCHING, Job.JobStatus.COMPLETED, InternalState.DELETE_MYSELF},
- {InternalState.WATCHING, Job.JobStatus.IN_PROGRESS, InternalState.WATCHING},
- {InternalState.WATCHING, Job.JobStatus.RESOURCE_IN_PROGRESS, InternalState.WATCHING},
- {InternalState.DELETE_MYSELF, Job.JobStatus.COMPLETED, InternalState.IN_PROGRESS},
- {InternalState.IN_PROGRESS, Job.JobStatus.COMPLETED, InternalState.TERMINAL},
- {InternalState.IN_PROGRESS, Job.JobStatus.IN_PROGRESS, InternalState.IN_PROGRESS},
- {InternalState.IN_PROGRESS, Job.JobStatus.RESOURCE_IN_PROGRESS, InternalState.IN_PROGRESS},
+ {InternalState.CREATING_CHILDREN, COMPLETED, InternalState.WATCHING},
+ {InternalState.WATCHING, COMPLETED, InternalState.DELETE_MYSELF},
+ {InternalState.WATCHING, IN_PROGRESS, InternalState.WATCHING},
+ {InternalState.WATCHING, RESOURCE_IN_PROGRESS, InternalState.WATCHING},
+ {InternalState.DELETE_MYSELF, COMPLETED, InternalState.IN_PROGRESS},
+ {InternalState.IN_PROGRESS, COMPLETED, InternalState.TERMINAL},
+ {InternalState.IN_PROGRESS, IN_PROGRESS, InternalState.IN_PROGRESS},
+ {InternalState.IN_PROGRESS, RESOURCE_IN_PROGRESS, InternalState.IN_PROGRESS},
};
}
@@ -228,28 +236,28 @@ public class ResourceCommandTest {
InternalState internalState, Job.JobStatus jobStatus, InternalState expectedState) {
//there is no meaning to the constructor inputs here
- MockCommandTestingStateMachine underTest = new MockCommandTestingStateMachine(InternalState.TERMINAL, Delete, Job.JobStatus.FAILED, true);
+ MockCommandTestingStateMachine underTest = new MockCommandTestingStateMachine(InternalState.TERMINAL, Delete, FAILED, true);
assertEquals(expectedState, underTest.calcNextStateDeletePhase(jobStatus, internalState));
}
@Test
public void whenNoNeedToDeleteMyself_internalStateMovesFromWatchingToTerminal() {
- MockCommandTestingStateMachine underTest = new MockCommandTestingStateMachine(InternalState.WATCHING, Delete, Job.JobStatus.COMPLETED, false);
- assertEquals(InternalState.TERMINAL, underTest.calcNextStateDeletePhase(Job.JobStatus.COMPLETED, InternalState.WATCHING));
+ MockCommandTestingStateMachine underTest = new MockCommandTestingStateMachine(InternalState.WATCHING, Delete, COMPLETED, false);
+ assertEquals(InternalState.TERMINAL, underTest.calcNextStateDeletePhase(COMPLETED, InternalState.WATCHING));
}
@DataProvider
public static Object[][] testShallStopJobDataProvider() {
return new Object[][]{
- {Job.JobStatus.IN_PROGRESS, None, false, false},
- {Job.JobStatus.COMPLETED_WITH_NO_ACTION, None, false, false},
- {Job.JobStatus.COMPLETED, None, false, false},
- {Job.JobStatus.FAILED, None, false, true},
- {Job.JobStatus.COMPLETED_WITH_ERRORS, None, false, true},
- {Job.JobStatus.COMPLETED_WITH_ERRORS, None, true, false},
- {Job.JobStatus.FAILED, None, true, false},
- {Job.JobStatus.FAILED, Delete, true, true},
- {Job.JobStatus.FAILED, Create, true, true},
+ {IN_PROGRESS, None, false, false},
+ {COMPLETED_WITH_NO_ACTION, None, false, false},
+ {COMPLETED, None, false, false},
+ {FAILED, None, false, true},
+ {COMPLETED_WITH_ERRORS, None, false, true},
+ {COMPLETED_WITH_ERRORS, None, true, false},
+ {FAILED, None, true, false},
+ {FAILED, Delete, true, true},
+ {FAILED, Create, true, true},
};
}
@@ -257,7 +265,7 @@ public class ResourceCommandTest {
@Test(dataProvider = "testShallStopJobDataProvider")
public void testShallStopJob(Job.JobStatus jobStatus, Action action, boolean isService, boolean expectedResult) {
//in this test, there is no meaning to constructor parameters besides isService
- MockCommandTestingStateMachine underTest = new MockCommandTestingStateMachine(InternalState.WATCHING, Delete, Job.JobStatus.COMPLETED, false, isService, true);
+ MockCommandTestingStateMachine underTest = new MockCommandTestingStateMachine(InternalState.WATCHING, Delete, COMPLETED, false, isService, true);
BaseResource mockedRequest = mock(BaseResource.class);
when(underTest.getSharedData().getRequest()).thenReturn(mockedRequest);
@@ -355,27 +363,27 @@ public class ResourceCommandTest {
@Test(dataProvider = "testIsDescendantHasActionDataProvider")
public void testIsDescendantHasAction(String desc, Action action, boolean expectedResult, BaseResource request) {
//in this test, there is no meaning to constructor parameters
- MockCommand underTest = new MockCommand(InternalState.WATCHING, Delete, Job.JobStatus.COMPLETED);
+ MockCommand underTest = new MockCommand(InternalState.WATCHING, Delete, COMPLETED);
assertEquals(expectedResult, underTest.isDescendantHasAction(request, action));
}
@DataProvider
public static Object[][] testCallDataProvider() {
return new Object[][]{
- {"initial state with successful creating children" ,InternalState.INITIAL, Job.JobStatus.COMPLETED, InternalState.WATCHING, Job.JobStatus.RESOURCE_IN_PROGRESS},
- {"initial state with failed creating children", InternalState.INITIAL, Job.JobStatus.FAILED, null, Job.JobStatus.FAILED},
- {"watching state with children still in progress" ,InternalState.WATCHING, Job.JobStatus.RESOURCE_IN_PROGRESS, InternalState.WATCHING, Job.JobStatus.RESOURCE_IN_PROGRESS},
- {"watching state with children that completed with errors" ,InternalState.WATCHING, Job.JobStatus.COMPLETED_WITH_ERRORS, null, Job.JobStatus.COMPLETED_WITH_ERRORS},
- {"watching state with children that completed with no action" ,InternalState.WATCHING, Job.JobStatus.COMPLETED_WITH_NO_ACTION, InternalState.DELETE_MYSELF, Job.JobStatus.RESOURCE_IN_PROGRESS},
- {"watching state with children that has completed" ,InternalState.WATCHING, Job.JobStatus.COMPLETED, InternalState.DELETE_MYSELF, Job.JobStatus.RESOURCE_IN_PROGRESS},
- {"mso call state that failed" ,InternalState.DELETE_MYSELF, Job.JobStatus.FAILED, null, Job.JobStatus.FAILED},
+ {"initial state with successful creating children" ,InternalState.INITIAL, COMPLETED, InternalState.WATCHING, RESOURCE_IN_PROGRESS},
+ {"initial state with failed creating children", InternalState.INITIAL, FAILED, null, FAILED},
+ {"watching state with children still in progress" ,InternalState.WATCHING, RESOURCE_IN_PROGRESS, InternalState.WATCHING, RESOURCE_IN_PROGRESS},
+ {"watching state with children that completed with errors" ,InternalState.WATCHING, COMPLETED_WITH_ERRORS, null, COMPLETED_WITH_ERRORS},
+ {"watching state with children that completed with no action" ,InternalState.WATCHING, COMPLETED_WITH_NO_ACTION, InternalState.DELETE_MYSELF, RESOURCE_IN_PROGRESS},
+ {"watching state with children that has completed" ,InternalState.WATCHING, COMPLETED, InternalState.DELETE_MYSELF, RESOURCE_IN_PROGRESS},
+ {"mso call state that failed" ,InternalState.DELETE_MYSELF, FAILED, null, FAILED},
//TODO handle AAI get unique name state {"mso call state that still in progress" ,InternalState.DELETE_MYSELF, Job.JobStatus.FAILED, null, Job.JobStatus.FAILED, false},
- {"mso call state that success" ,InternalState.DELETE_MYSELF, Job.JobStatus.COMPLETED, InternalState.IN_PROGRESS, Job.JobStatus.RESOURCE_IN_PROGRESS},
- {"in progress return in progress" ,InternalState.IN_PROGRESS, Job.JobStatus.IN_PROGRESS, InternalState.IN_PROGRESS, Job.JobStatus.RESOURCE_IN_PROGRESS},
- {"in progress return in pause" ,InternalState.IN_PROGRESS, Job.JobStatus.PAUSE, InternalState.IN_PROGRESS, Job.JobStatus.RESOURCE_IN_PROGRESS},
- {"in progress return in pause" ,InternalState.IN_PROGRESS, Job.JobStatus.STOPPED, null, Job.JobStatus.STOPPED},
- {"in progress return in pause" ,InternalState.IN_PROGRESS, Job.JobStatus.FAILED, null, Job.JobStatus.FAILED},
- {"in progress return in pause" ,InternalState.IN_PROGRESS, Job.JobStatus.COMPLETED, null, Job.JobStatus.COMPLETED},
+ {"mso call state that success" ,InternalState.DELETE_MYSELF, COMPLETED, InternalState.IN_PROGRESS, RESOURCE_IN_PROGRESS},
+ {"in progress return in progress" ,InternalState.IN_PROGRESS, IN_PROGRESS, InternalState.IN_PROGRESS, RESOURCE_IN_PROGRESS},
+ {"in progress return in pause" ,InternalState.IN_PROGRESS, PAUSE, InternalState.IN_PROGRESS, RESOURCE_IN_PROGRESS},
+ {"in progress return in pause" ,InternalState.IN_PROGRESS, STOPPED, null, STOPPED},
+ {"in progress return in pause" ,InternalState.IN_PROGRESS, FAILED, null, FAILED},
+ {"in progress return in pause" ,InternalState.IN_PROGRESS, COMPLETED, null, COMPLETED},
};
}
@@ -409,18 +417,24 @@ public class ResourceCommandTest {
@Test(dataProvider = "InProgressDataProvider")
public void whenGetResultFromMso_InProgressReturnThem(Job.JobStatus mockedJobStatus) {
- Job.JobStatus expectedJobStatus = (mockedJobStatus== Job.JobStatus.PAUSE) ? Job.JobStatus.IN_PROGRESS : mockedJobStatus;
+ Job.JobStatus expectedJobStatus = (mockedJobStatus== PAUSE) ? IN_PROGRESS : mockedJobStatus;
MockCommand underTest = new MockCommand(InternalState.IN_PROGRESS, Delete, mockedJobStatus);
when(underTest.getInProgressStatusService().call(any(), any(), any())).thenReturn(mockedJobStatus);
+
+ // we need to mock the request for pause after completion only when the status is completed
+ if(mockedJobStatus == COMPLETED){
+ BaseResource mockedBaseResource = mock(BaseResource.class);
+ when(underTest.getSharedData().getRequest()).thenReturn(mockedBaseResource);
+ }
assertEquals(expectedJobStatus, underTest.inProgress());
}
@DataProvider
public static Object[][] InProgressExceptionsDataProvider() {
return new Object[][]{
- {new ProcessingException(""), Job.JobStatus.IN_PROGRESS},
- {new InProgressStatusService.BadResponseFromMso(null), Job.JobStatus.IN_PROGRESS},
- {new GenericUncheckedException(""),Job.JobStatus.STOPPED }
+ {new ProcessingException(""), IN_PROGRESS},
+ {new InProgressStatusService.BadResponseFromMso(null), IN_PROGRESS},
+ {new GenericUncheckedException(""), STOPPED }
};
}
@@ -441,7 +455,7 @@ public class ResourceCommandTest {
@Test(dataProvider = "testIsNeedToDeleteMySelfDataProvider")
public void testIsNeedToDeleteMySelf(Action action) {
boolean expectedResult = (action== Delete);
- MockCommand underTest = new MockCommand(InternalState.DELETE_MYSELF, Delete, Job.JobStatus.IN_PROGRESS);
+ MockCommand underTest = new MockCommand(InternalState.DELETE_MYSELF, Delete, IN_PROGRESS);
BaseResource mockedBaseResource = mock(BaseResource.class);
when(underTest.getSharedData().getRequest()).thenReturn(mockedBaseResource);
when(mockedBaseResource.getAction()).thenReturn(action);
@@ -451,15 +465,15 @@ public class ResourceCommandTest {
@DataProvider
public static Object[][] testWatchingDataProvider() {
return new Object[][]{
- {"all children final, no failed child ", Job.JobStatus.COMPLETED, Job.JobStatus.COMPLETED},
- {"all children final, there is failed child ", Job.JobStatus.COMPLETED_WITH_ERRORS, Job.JobStatus.COMPLETED_WITH_ERRORS},
- {"not all children final", Job.JobStatus.IN_PROGRESS, Job.JobStatus.IN_PROGRESS},
+ {"all children final, no failed child ", COMPLETED, COMPLETED},
+ {"all children final, there is failed child ", COMPLETED_WITH_ERRORS, COMPLETED_WITH_ERRORS},
+ {"not all children final", IN_PROGRESS, IN_PROGRESS},
};
}
@Test(dataProvider = "testWatchingDataProvider")
public void testWatching(String desc, Job.JobStatus childrenJobsStatus, Job.JobStatus expectedJobStatus) {
- MockCommand underTest = new MockCommand(InternalState.WATCHING, Delete, Job.JobStatus.IN_PROGRESS);
+ MockCommand underTest = new MockCommand(InternalState.WATCHING, Delete, IN_PROGRESS);
when(underTest.getWatchChildrenJobsBL().retrieveChildrenJobsStatus(any())).thenReturn(childrenJobsStatus);
assertEquals(expectedJobStatus, underTest.watchChildren());
}
@@ -502,7 +516,7 @@ public class ResourceCommandTest {
private final RuntimeException exceptionToThrow;
public MockCommandThrowExceptionOnCreateChildren(RuntimeException exceptionToThrow) {
- super(InternalState.CREATING_CHILDREN, Delete, Job.JobStatus.COMPLETED, true);
+ super(InternalState.CREATING_CHILDREN, Delete, COMPLETED, true);
this.exceptionToThrow = exceptionToThrow;
doAnswer(returnsFirstArg()).when(this.getWatchChildrenJobsBL()).cumulateJobStatus(any(), any());
}
@@ -517,8 +531,8 @@ public class ResourceCommandTest {
@DataProvider
public static Object[][] exceptionAndStateProvider() {
return new Object[][]{
- {new TryAgainException(new Exception()), Job.JobStatus.RESOURCE_IN_PROGRESS},
- {new AbortingException(new Exception()), Job.JobStatus.FAILED},
+ {new TryAgainException(new Exception()), RESOURCE_IN_PROGRESS},
+ {new AbortingException(new Exception()), FAILED},
};
}
@@ -548,7 +562,7 @@ public class ResourceCommandTest {
BaseResource mockedRequest3 = mock(BaseResource.class);
when(mockedRequest3.getPosition()).thenReturn(thirdPosition);
- MockCommand underTest = new MockCommand(InternalState.CREATING_CHILDREN, Create, Job.JobStatus.IN_PROGRESS);
+ MockCommand underTest = new MockCommand(InternalState.CREATING_CHILDREN, Create, IN_PROGRESS);
List<Pair<BaseResource, Integer>> sortedList = underTest.setPositionWhereIsMissing(ImmutableList.of(mockedRequest1, mockedRequest2, mockedRequest3));
assertEquals(sortedList.get(0).getSecond(),expectedPositions.get(0));
diff --git a/vid-app-common/src/test/java/org/onap/vid/job/command/WatchChildrenJobsBLTest.java b/vid-app-common/src/test/java/org/onap/vid/job/command/WatchChildrenJobsBLTest.java
index a9a961db8..fad32bba6 100644
--- a/vid-app-common/src/test/java/org/onap/vid/job/command/WatchChildrenJobsBLTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/job/command/WatchChildrenJobsBLTest.java
@@ -20,27 +20,28 @@
package org.onap.vid.job.command;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+import static org.testng.AssertJUnit.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+import java.util.stream.Collectors;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.onap.portalsdk.core.service.DataAccessService;
import org.onap.vid.job.Job.JobStatus;
import org.onap.vid.job.impl.JobDaoImpl;
import org.onap.vid.utils.DaoUtils;
-import org.onap.portalsdk.core.service.DataAccessService;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.UUID;
-import java.util.stream.Collectors;
-
-import static org.mockito.ArgumentMatchers.*;
-import static org.mockito.Mockito.when;
-import static org.testng.AssertJUnit.assertEquals;
-
public class WatchChildrenJobsBLTest {
@Mock
private DataAccessService dataAccessService;
@@ -90,8 +91,9 @@ public class WatchChildrenJobsBLTest {
{Arrays.asList(JobStatus.COMPLETED_WITH_ERRORS, JobStatus.COMPLETED_WITH_ERRORS), JobStatus.COMPLETED_WITH_ERRORS},
{Arrays.asList(JobStatus.COMPLETED_WITH_ERRORS, JobStatus.COMPLETED_WITH_NO_ACTION), JobStatus.COMPLETED_WITH_ERRORS},
{Arrays.asList(JobStatus.COMPLETED_WITH_NO_ACTION, JobStatus.COMPLETED_WITH_NO_ACTION), JobStatus.COMPLETED_WITH_NO_ACTION},
-
-
+ {Arrays.asList(JobStatus.COMPLETED_AND_PAUSED, JobStatus.RESOURCE_IN_PROGRESS), JobStatus.IN_PROGRESS},
+ {Arrays.asList(JobStatus.COMPLETED_AND_PAUSED, JobStatus.COMPLETED), JobStatus.COMPLETED_AND_PAUSED},
+ {Arrays.asList(JobStatus.COMPLETED_AND_PAUSED, JobStatus.IN_PROGRESS), JobStatus.IN_PROGRESS},
};
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/job/impl/AsyncInstantiationIntegrationTest.java b/vid-app-common/src/test/java/org/onap/vid/job/impl/AsyncInstantiationIntegrationTest.java
index 061b62af2..ce94a7096 100644
--- a/vid-app-common/src/test/java/org/onap/vid/job/impl/AsyncInstantiationIntegrationTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/job/impl/AsyncInstantiationIntegrationTest.java
@@ -47,6 +47,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.onap.vid.job.Job.JobStatus.COMPLETED;
+import static org.onap.vid.job.Job.JobStatus.COMPLETED_AND_PAUSED;
import static org.onap.vid.job.Job.JobStatus.COMPLETED_WITH_ERRORS;
import static org.onap.vid.job.Job.JobStatus.COMPLETED_WITH_NO_ACTION;
import static org.onap.vid.job.Job.JobStatus.FAILED;
@@ -1033,16 +1034,16 @@ public class AsyncInstantiationIntegrationTest extends AsyncInstantiationBaseTes
@DataProvider
public static Object[][] pauseInstantiation(Method test) {
return new Object[][]{
- {true, 2},
- {false, 3}
+ {true, 2, COMPLETED_AND_PAUSED},
+ {false, 3, COMPLETED}
};
}
@Test (dataProvider = "pauseInstantiation")
- public void viewEdit_existingVnfCreate3VfModulesPauseAfterTheSecond(boolean flag, int expectedNumberOfInvocation) {
+ public void viewEdit_existingVnfCreate3VfModulesPauseAfterTheSecond(boolean flag, int expectedNumberOfInvocation,
+ JobStatus expectedJobStatus) {
RestObject<RequestReferencesContainer> createVfModuleResponse = createResponseRandomIds(202);
RestObject<AsyncRequestStatus> createStatusResponse = asyncRequestStatusResponseAsRestObject(COMPLETE_STR);
- JobStatus expectedJobStatus = COMPLETED;
when(featureManager.isActive(Features.FLAG_2006_PAUSE_VFMODULE_INSTANTIATION_CREATION)).thenReturn(flag);