diff options
Diffstat (limited to 'vid-app-common/src/test/java')
7 files changed, 93 insertions, 7 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 b916347d2..8d60b8477 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 @@ -320,7 +320,7 @@ public class ResourceCommandTest { static VfModule createVfModule(Action action) { return new VfModule(mock(ModelInfo.class), null, null, action.toString(), null, null, null, null, null, - false, false, null, null, null, null, null, null, null, null); + false, false, null, null, null, null, null, null, null, null, null); } static Network createNetwork(Action action) { diff --git a/vid-app-common/src/test/java/org/onap/vid/job/command/VnfCommandTest.kt b/vid-app-common/src/test/java/org/onap/vid/job/command/VnfCommandTest.kt index 977966271..ab5440658 100644 --- a/vid-app-common/src/test/java/org/onap/vid/job/command/VnfCommandTest.kt +++ b/vid-app-common/src/test/java/org/onap/vid/job/command/VnfCommandTest.kt @@ -26,16 +26,20 @@ import org.hamcrest.core.AllOf.allOf import org.mockito.Answers import org.mockito.InjectMocks import org.mockito.Mock +import org.mockito.Mockito.mock import org.onap.vid.job.JobAdapter import org.onap.vid.job.JobsBrokerService import org.onap.vid.job.command.ResourceCommandTest.FakeResourceCreator import org.onap.vid.job.impl.JobSharedData import org.onap.vid.model.Action +import org.onap.vid.model.serviceInstantiation.VfModule +import org.onap.vid.model.serviceInstantiation.VfModule.PauseInstantiation.afterCompletion import org.onap.vid.mso.RestMsoImplementation import org.onap.vid.properties.Features import org.onap.vid.services.AsyncInstantiationBusinessLogic import org.onap.vid.testUtils.TestUtils import org.onap.vid.testUtils.TestUtils.initMockitoMocks +import org.testng.AssertJUnit import org.testng.annotations.BeforeMethod import org.testng.annotations.DataProvider import org.testng.annotations.Test @@ -102,4 +106,28 @@ class VnfCommandTest { ) } + @DataProvider + fun shoudlPause(): Array<Array<out Any?>> { + return arrayOf( + arrayOf("action create, pause in module and flag active", Action.Create, true, true, true), + arrayOf("action create, pause in module and flag not active", Action.Create, true, false, false), + arrayOf("action not create, pause in module and flag active", Action.None, true, true, false), + arrayOf("action create, no pause in module and flag active", Action.Create, false, true, false), + arrayOf("action create, no pause in module and flag not active", Action.Create, false, false, false)) + } + + @Test(dataProvider = "shoudlPause") + fun `shouldPauseAfterInstantiation -- given different flag and pause conditions`(desc: String, vfModuleAction: Action, isPause: Boolean, flag: Boolean, + expectedResult: Boolean) { + val vfModule = mock(VfModule::class.java); + + _when(featureManager.isActive(Features.FLAG_2006_PAUSE_VFMODULE_INSTANTIATION_CREATION)).thenReturn(flag) + _when(vfModule.action).thenReturn(vfModuleAction) + + if (isPause) { + _when(vfModule.pauseInstantiation).thenReturn(afterCompletion) + } + + AssertJUnit.assertEquals(desc, expectedResult, vnfCommand.shoudlPauseAfterInstantiation(vfModule)) + } } 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 dfacf57a3..061b62af2 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 @@ -1030,6 +1030,40 @@ public class AsyncInstantiationIntegrationTest extends AsyncInstantiationBaseTes getStatusCounter); } + @DataProvider + public static Object[][] pauseInstantiation(Method test) { + return new Object[][]{ + {true, 2}, + {false, 3} + }; + } + + @Test (dataProvider = "pauseInstantiation") + public void viewEdit_existingVnfCreate3VfModulesPauseAfterTheSecond(boolean flag, int expectedNumberOfInvocation) { + 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); + + when(commandUtils.isVfModuleBaseModule(eq("6b528779-44a3-4472-bdff-9cd15ec93450"), + argThat(it -> it.getModelCustomizationName().equals("2017488PasqualeVpe..PASQUALE_base_vPE_BV..module-0")))).thenReturn(true); + + UUID jobUUID = asyncInstantiationBL.pushBulkJob( + readJsonResourceFileAsObject("/payload_jsons/vfModuleCreate2AndPauseRequest.json", ServiceInstantiation.class), "userId") + .get(0); + + String createPath= "/serviceInstantiation/v7/serviceInstances/f8791436-8d55-4fde-b4d5-72dd2cf13cfb/vnfs/VNF_INSTANCE_ID/vfModules"; + + when(restMso.restCall(eq(HttpMethod.POST), eq(RequestReferencesContainer.class), any(), eq(createPath), any())).thenReturn(createVfModuleResponse); + when(restMso.GetForObject(endsWith(createVfModuleResponse.get().getRequestReferences().getRequestId()), eq(AsyncRequestStatus.class))).thenReturn(createStatusResponse); + + + processJobsCountTimesAndAssertStatus(jobUUID, 40, expectedJobStatus); + + verify(restMso, times(expectedNumberOfInvocation)).restCall(eq(HttpMethod.POST), any(), any(), eq(createPath), any()); + } + //this test is going along with AsyncInstantiationALaCarteApiTest.delete1Create1NetworkFromService API test //The API test has only the happy flow scenario, while this test also test additional MSO responses (mostly non happy) @Test(dataProvider="createAndDeleteIntegrationTestDataProvider") diff --git a/vid-app-common/src/test/java/org/onap/vid/model/serviceInstantiation/InstantiationModelSerializationTest.java b/vid-app-common/src/test/java/org/onap/vid/model/serviceInstantiation/InstantiationModelSerializationTest.java index 6a5b102a0..26e8f8285 100644 --- a/vid-app-common/src/test/java/org/onap/vid/model/serviceInstantiation/InstantiationModelSerializationTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/model/serviceInstantiation/InstantiationModelSerializationTest.java @@ -32,6 +32,7 @@ import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.samePropertyValuesAs; import static org.onap.vid.model.Action.Create; +import static org.onap.vid.model.serviceInstantiation.VfModule.PauseInstantiation.afterCompletion; import static org.onap.vid.testUtils.TestUtils.setStringsInStringFields; import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER; @@ -154,6 +155,7 @@ public class InstantiationModelSerializationTest { true, true, 1, + afterCompletion, "originalName"); verifySerializationAndDeserialization(vfModule); @@ -167,7 +169,7 @@ public class InstantiationModelSerializationTest { VfModule vfModule = new VfModule(newModelInfo(), null, null, null, null, null, null, null, null, false, /* HERE ====> */ USE_PRELOAD, - null, null, null, null, null, null, null, null); + null, null, null, null, null, null, null, null , null); assertThat(vfModule, jsonPartEquals("sdncPreLoad", USE_PRELOAD)); assertThat(vfModule, jsonNodeAbsent("usePreload")); @@ -182,7 +184,7 @@ public class InstantiationModelSerializationTest { /* HERE ====> */ VOLUME_GROUP_INSTANCE_NAME, null, null, null, null, null, null, false, null, null, null, null, null, - null, null, null, null); + null, null, null, null, null); assertThat(vfModule, jsonPartEquals("volumeGroupName", VOLUME_GROUP_INSTANCE_NAME)); assertThat(vfModule, jsonNodeAbsent("volumeGroupInstanceName")); diff --git a/vid-app-common/src/test/java/org/onap/vid/model/serviceInstantiation/VfModuleTest.java b/vid-app-common/src/test/java/org/onap/vid/model/serviceInstantiation/VfModuleTest.java index 89b0acadb..9ed43ff70 100644 --- a/vid-app-common/src/test/java/org/onap/vid/model/serviceInstantiation/VfModuleTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/model/serviceInstantiation/VfModuleTest.java @@ -55,7 +55,7 @@ public class VfModuleTest { null, null, null, null, null, null, null, null, true, true, null, null, true, null, true, - true, null, null); + true, null, null, null); return setStringsInStringFields(vfModule); } diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java index f61131770..738af18cf 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java @@ -266,12 +266,12 @@ public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests return new VfModule(vfModuleInfo, instanceName, volumeGroupInstanceName, Action.Create.name(), "mdt1", null, "88a6ca3ee0394ade9403f075db23167e", instanceParams, supplementaryParams, false, usePreload, null, UUID.randomUUID().toString(), null, null, - null, null, null, "originalName"); + null, null, null, null, "originalName"); } return new VfModule(vfModuleInfo, instanceName, volumeGroupInstanceName, Action.Create.name(), null, null, null, instanceParams, supplementaryParams, false, false, null, UUID.randomUUID().toString(), null, - null, null, null, null, "originalName"); + null, null, null, null, null, "originalName"); } protected ModelInfo createVfModuleModelInfo(String modelName, String modelVersion, String modelVersionId, String modelInvariantId, String modelCustomizationId, String modelCustomizationName) { @@ -281,7 +281,8 @@ public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests protected VfModule createVfModuleForReplace(ModelInfo vfModuleModelInfo, String instanceName, String lcpCloudRegionId, String tenantId, Boolean retainAssignments, Boolean retainVolumeGroups, List<UserParamNameAndValue> supplementaryParams) { return new VfModule( vfModuleModelInfo, instanceName, null, Action.Upgrade.name(), lcpCloudRegionId, null, tenantId, - null, supplementaryParams, true, null, null, UUID.randomUUID().toString(), null, null, retainAssignments, retainVolumeGroups, null, "originalName"); + null, supplementaryParams, true, null, null, UUID.randomUUID().toString(), null, + null, retainAssignments, retainVolumeGroups, null, null, "originalName"); } protected ModelInfo createVnfModelInfo(boolean isAlacarte) { diff --git a/vid-app-common/src/test/java/org/onap/vid/utils/KotlinUtilsTest.kt b/vid-app-common/src/test/java/org/onap/vid/utils/KotlinUtilsTest.kt new file mode 100644 index 000000000..ac729e490 --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/utils/KotlinUtilsTest.kt @@ -0,0 +1,21 @@ +package org.onap.vid.utils + +import org.testng.AssertJUnit.assertEquals +import org.testng.annotations.DataProvider +import org.testng.annotations.Test + +internal class KotlinUtilsTest { + @DataProvider + fun listsAndPerdicates(): Array<Array<Any>>? { + return arrayOf( + arrayOf("stop on second item", listOf("a", "b", "c", "d"), "b", listOf("a", "b")), + arrayOf("return all of the list", listOf("a", "b", "c", "d"), "z", listOf("a", "b", "c", "d")), + arrayOf("only first item returns", listOf("a", "b", "c", "d"), "a", listOf("a")), + arrayOf("returns an empty list", emptyList<String>(), "z", emptyList<String>())) + } + + @Test(dataProvider = "listsAndPerdicates") + fun testTakeUntilIncludingReturendValue(desc: String, list: List<String>, predicate: String, expectedResultList: List<String>) { + assertEquals(desc, expectedResultList, list.takeUntilIncluding { it == predicate }) + } +} |