import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
when(restMso.GetForObject(endsWith(VNF_REQUEST_ID), eq(AsyncRequestStatus.class))).
thenReturn(asyncRequestStatusResponseAsRestObject(COMPLETE_STR));
- try {
- reset(commandUtils);
- when(commandUtils.isVfModuleBaseModule(SERVICE_MODEL_VERSION_ID, VF_MODULE_0_MODEL_VERSION_ID)).thenReturn(true);
- when(commandUtils.isVfModuleBaseModule(SERVICE_MODEL_VERSION_ID, VF_MODULE_1_MODEL_VERSION_ID)).thenReturn(false);
- } catch (AsdcCatalogException e) {
-
- }
+ reset(commandUtils);
+ when(commandUtils.isVfModuleBaseModule(eq(SERVICE_MODEL_VERSION_ID),
+ argThat(it -> it.getModelCustomizationId().equals(VF_MODULE_0_MODEL_CUSTOMIZATION_NAME)))).thenReturn(true);
+ when(commandUtils.isVfModuleBaseModule(eq(SERVICE_MODEL_VERSION_ID),
+ argThat(it -> it.getModelCustomizationId().equals(VF_MODULE_1_MODEL_CUSTOMIZATION_NAME)))).thenReturn(false);
/*---------- vf Module without volume group name (base) -----------*/
RestObject<AsyncRequestStatus> createStatusResponse,
RestObject<AsyncRequestStatus> deleteStatusResponse,
JobStatus expectedJobStatus,
- int getStatusCounter) throws IOException, AsdcCatalogException {
+ int getStatusCounter) {
- when(commandUtils.isVfModuleBaseModule("6b528779-44a3-4472-bdff-9cd15ec93450", "f8360508-3f17-4414-a2ed-6bc71161e8db")).thenReturn(true);
- when(commandUtils.isVfModuleBaseModule("6b528779-44a3-4472-bdff-9cd15ec93450", "25284168-24bb-4698-8cb4-3f509146eca5")).thenReturn(false);
+ when(commandUtils.isVfModuleBaseModule(eq("6b528779-44a3-4472-bdff-9cd15ec93450"),
+ argThat(it -> it.getModelCustomizationName().equals("2017488PasqualeVpe..PASQUALE_base_vPE_BV..module-0")))).thenReturn(true);
+ when(commandUtils.isVfModuleBaseModule(eq("6b528779-44a3-4472-bdff-9cd15ec93450"),
+ argThat(it -> it.getModelCustomizationName().equals("2017488PasqualeVpe..PASQUALE_vRE_BV..module-1")))).thenReturn(false);
createAndDeleteIntegrationTest("/payload_jsons/vfModuleDelete1Create1None1Request.json",
"/serviceInstantiation/v7/serviceInstances/f8791436-8d55-4fde-b4d5-72dd2cf13cfb/vnfs/VNF_INSTANCE_ID/vfModules",
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")
assertThat(requestCaptor.getValue(), jsonEquals(expectedPayloadToMso).when(IGNORING_ARRAY_ORDER));
}
+ @Test
+ public void viewEdit_oneNetworkExistsAddAnotherNetwork() {
+ String currentServiceInstanceId = "ce2821fc-3b28-4759-9613-1e514d7563c0";
+ String addNetworkRequestId = randomUuid();
+ String userId = "az2016";
+
+
+ String expectedMsoAddNetworkPath =
+ "/serviceInstantiation/v7/serviceInstances/" + currentServiceInstanceId + "/networks";
+
+ when(restMso.restCall(eq(HttpMethod.POST),eq(RequestReferencesContainer.class),any(), eq(expectedMsoAddNetworkPath), any()))
+ .thenReturn(createResponse(202, currentServiceInstanceId, addNetworkRequestId));
+
+ when(restMso.GetForObject(eq("/orchestrationRequests/v7/" + addNetworkRequestId),eq(AsyncRequestStatus.class)))
+ .thenReturn(asyncRequestStatusResponseAsRestObject(COMPLETE_STR));
+
+ List<UUID> uuids= asyncInstantiationBL.pushBulkJob(addNetworkBulkPayload(), userId);
+ assertThat(uuids, hasSize(1));
+ processJobsCountTimesAndAssertStatus(uuids.get(0), 200, COMPLETED);
+
+ verify(restMso, times(1)).restCall(eq(HttpMethod.POST), any(), any(), eq(expectedMsoAddNetworkPath),any());
+ verify(restMso, times(1)).GetForObject(any(),any());
+ }
+
+ @Test
+ public void whenDeletingVfModule_thenExpectedDeleteRequestSent()
+ {
+ String currentServiceInstanceId = "6196ab1f-2349-4b32-9b6c-cffeb0ccc79c";
+ String currentVnfInstanceId = "d520268f-7489-4662-be59-f81495b3a069";
+ String currentVfModuleInstanceId = "b0732bed-3ddf-43cc-b193-7f18db84e476";
+
+ assertTestPayloadFitsExpectedIds(deleteVfModuleBulkPayload(), currentServiceInstanceId, currentVnfInstanceId, currentVfModuleInstanceId);
+
+ String deleteRequestId = randomUuid();
+ String userId = "az2016";
+
+
+ String expectedMsoDeletePath = "/serviceInstantiation/v7/serviceInstances/"
+ + currentServiceInstanceId + "/vnfs/" + currentVnfInstanceId + "/vfModules/" + currentVfModuleInstanceId;
+
+ when(restMso.restCall(eq(HttpMethod.DELETE), eq(RequestReferencesContainer.class), any(), eq(expectedMsoDeletePath), eq(Optional.of(userId))))
+ .thenReturn(createResponse(202, currentVfModuleInstanceId, deleteRequestId));
+
+ when(restMso.GetForObject(eq("/orchestrationRequests/v7/" + deleteRequestId), eq(AsyncRequestStatus.class)))
+ .thenReturn(asyncRequestStatusResponseAsRestObject(IN_PROGRESS_STR),
+ asyncRequestStatusResponseAsRestObject(IN_PROGRESS_STR),
+ asyncRequestStatusResponseAsRestObject(COMPLETE_STR));
+
+ enableAddCloudOwnerOnMsoRequest();
+
+
+ UUID jobUUID = asyncInstantiationBL.pushBulkJob(deleteVfModuleBulkPayload(), userId).get(0);
+ processJobsCountTimesAndAssertStatus(jobUUID, 20, COMPLETED);
+
+
+ ArgumentCaptor<RequestDetailsWrapper> requestCaptor = ArgumentCaptor.forClass(RequestDetailsWrapper.class);
+ verify(restMso, times(1)).restCall(
+ eq(HttpMethod.DELETE),
+ eq(RequestReferencesContainer.class),
+ requestCaptor.capture(),
+ eq(expectedMsoDeletePath),
+ eq(Optional.of(userId))
+ );
+
+ assertThat(requestCaptor.getValue(), jsonEquals(getDeleteVfModulePayloadToMso()));
+ }
+
+
+ private ServiceInstantiation deleteVfModuleBulkPayload() {
+ return readJsonResourceFileAsObject("/payload_jsons/vfmodule/delete_1_vfmodule_expected_bulk.json", ServiceInstantiation.class);
+ }
+
+ private ServiceInstantiation addNetworkBulkPayload() {
+ return readJsonResourceFileAsObject("/payload_jsons/Network/one_network_exists_add_another_network_expected_bulk.json", ServiceInstantiation.class);
+ }
+
+ private String getDeleteVfModulePayloadToMso() {
+ return "{ " +
+ " \"requestDetails\": { " +
+ " \"requestInfo\": { " +
+ " \"source\": \"VID\", " +
+ " \"requestorId\": \"az2016\" " +
+ " }, " +
+ " \"modelInfo\": { " +
+ " \"modelType\": \"vfModule\", " +
+ " \"modelName\": \"XbiTestModuleReplace..base_ocg..module-0\", " +
+ " \"modelVersionId\": \"04b21d26-9780-4956-8329-b22b049329f4\", " +
+ " \"modelVersion\": \"1.0\", " +
+ " \"modelInvariantId\": \"d887658e-2a89-4baf-83e2-b189601a1a7c\", " +
+ " \"modelCustomizationName\": \"XbiTestModuleReplace..base_ocg..module-0\", " +
+ " \"modelCustomizationId\": \"3f1f0fcb-8a88-4612-a794-3912613ed9e8\" " +
+ " }, " +
+ " \"cloudConfiguration\": { " +
+ " \"lcpCloudRegionId\": \"olson5a\", " +
+ " \"cloudOwner\": \"irma-aic\", " +
+ " \"tenantId\": \"7ff7b1a4fe954f71ab79d3160ec3eb08\" " +
+ " } " +
+ " } " +
+ "}";
+ }
+
private void assertTestPayloadFitsExpectedIds(ServiceInstantiation upgradeVfModulePayload, String serviceInstanceId,
String vnfInstanceId, String vfModuleInstanceId) {
/*
assertNull(templateOfRetry.getStatusMessage());
}
+ @Test
+ public void oneVnfExistsAddAnotherVnf(){
+ final String VNF_REQUEST_ID = UUID.randomUUID().toString();
+ final String VNF_INSTANCE_ID = UUID.randomUUID().toString();
+
+ ServiceInstantiation serviceInstantiation = readJsonResourceFileAsObject("/payload_jsons/vnf/one_vnf_exists_add_another_vnf_expected_bulk.json",
+ ServiceInstantiation.class);
+ List<UUID> uuids = asyncInstantiationBL.pushBulkJob(serviceInstantiation, USER_ID);
+ assertThat(uuids, hasSize(1));
+
+ //mock mso to answer 200 of create vnf instance request
+ when(restMso.restCall(eq(HttpMethod.POST), eq(RequestReferencesContainer.class), any(), endsWith("e6cc1c4f-05f7-49bc-8e86-ac2eb92baaaa/vnfs"), any())).thenReturn(
+ createResponse(200, VNF_INSTANCE_ID, VNF_REQUEST_ID));
+
+ //mock mso to answer msoVnfStatus (COMPLETE) for vnf creation status,
+ when(restMso.GetForObject(endsWith(VNF_REQUEST_ID), eq(AsyncRequestStatus.class))).
+ thenReturn(asyncRequestStatusResponseAsRestObject(COMPLETE_STR));
+
+ processJobsCountTimesAndAssertStatus(uuids.get(0), 200, COMPLETED);
+ verify(restMso, times(1)).restCall(eq(HttpMethod.POST), any(), any(), endsWith("e6cc1c4f-05f7-49bc-8e86-ac2eb92baaaa/vnfs"), any());
+ verify(restMso, times(1)).GetForObject(any(), any());
+ }
+
}