aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/test/java')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsUnitTest.java284
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequestTest.java248
2 files changed, 482 insertions, 50 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsUnitTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsUnitTest.java
index b9d9974701..e92417728c 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsUnitTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsUnitTest.java
@@ -21,33 +21,69 @@
package org.onap.so.apihandlerinfra;
import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.Timestamp;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.apihandlerinfra.exceptions.ApiException;
+import org.onap.so.apihandlerinfra.exceptions.VfModuleNotFoundException;
+import org.onap.so.db.catalog.beans.VfModule;
+import org.onap.so.db.catalog.client.CatalogDbClient;
import org.onap.so.db.request.beans.InfraActiveRequests;
+import org.onap.so.serviceinstancebeans.ModelInfo;
+import org.onap.so.serviceinstancebeans.ModelType;
@RunWith(MockitoJUnitRunner.class)
public class RequestHandlerUtilsUnitTest {
+ @Mock
+ private CatalogDbClient catDbClient;
+
+ @InjectMocks
@Spy
private RequestHandlerUtils requestHandler;
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
private static final String CURRENT_REQUEST_ID = "eca3a1b1-43ab-457e-ab1c-367263d148b4";
private static final String RESUMED_REQUEST_ID = "59c7247f-839f-4923-90c3-05faa3ab354d";
private static final String SERVICE_INSTANCE_ID = "00032ab7-na18-42e5-965d-8ea592502018";
+ private static final String SERVICE_INSTANCE_NAME = "serviceInstanceName";
+ private static final String VNF_ID = "00032ab7-na18-42e5-965d-8ea592502017";
+ private static final String VFMODULE_ID = "00032ab7-na18-42e5-965d-8ea592502016";
+ private static final String NETWORK_ID = "00032ab7-na18-42e5-965d-8ea592502015";
+ private static final String VOLUME_GROUP_ID = "00032ab7-na18-42e5-965d-8ea592502014";
+ private static final String VNF_NAME = "vnfName";
+ private static final String VFMODULE_NAME = "vfModuleName";
+ private static final String NETWORK_NAME = "networkName";
+ private static final String VOLUME_GROUP_NAME = "volumeGroupName";
+ private static final String MODEL_VERSION_ID = "883f4a7a-b5a5-44e0-8738-361c6413d24c";
+ private static final String MODEL_VERSION = "1.0";
+ private static final String MODEL_INVARIANT_ID = "d358b828-e7f8-4833-ac96-2782bed1a9a9";
+ private static final String MODEL_NAME = "modelName";
private final Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis());
private String requestUri =
"http:localhost:6746/onap/so/infra/orchestrationRequests/v7/00032ab7-na18-42e5-965d-8ea592502019/resume";
private InfraActiveRequests infraActiveRequest = new InfraActiveRequests();
private InfraActiveRequests currentActiveRequest = new InfraActiveRequests();
private InfraActiveRequests currentActiveRequestIARNull = new InfraActiveRequests();
+ private Action action = Action.createInstance;
+ private String vnfType = "vnfType";
+ private String sdcServiceModelVersion = "7";
public String getRequestBody(String request) throws IOException {
request = "src/test/resources/ResumeOrchestrationRequest" + request;
@@ -67,7 +103,7 @@ public class RequestHandlerUtilsUnitTest {
infraActiveRequest.setAicCloudRegion("cloudRegion");
infraActiveRequest.setRequestScope("service");
infraActiveRequest.setServiceInstanceId(SERVICE_INSTANCE_ID);
- infraActiveRequest.setServiceInstanceName("serviceInstanceName");
+ infraActiveRequest.setServiceInstanceName(SERVICE_INSTANCE_NAME);
infraActiveRequest.setRequestStatus(Status.IN_PROGRESS.toString());
infraActiveRequest.setRequestAction(Action.createInstance.toString());
infraActiveRequest.setServiceType("serviceType");
@@ -81,8 +117,6 @@ public class RequestHandlerUtilsUnitTest {
currentActiveRequest.setRequestBody(getRequestBody("/RequestBody.json"));
currentActiveRequest.setAicCloudRegion("cloudRegion");
currentActiveRequest.setRequestScope("service");
- currentActiveRequest.setServiceInstanceId(SERVICE_INSTANCE_ID);
- currentActiveRequest.setServiceInstanceName("serviceInstanceName");
currentActiveRequest.setRequestStatus(Status.IN_PROGRESS.toString());
currentActiveRequest.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER);
currentActiveRequest.setRequestAction(Action.createInstance.toString());
@@ -107,6 +141,7 @@ public class RequestHandlerUtilsUnitTest {
@Test
public void createNewRecordCopyFromInfraActiveRequestTest() {
+ doNothing().when(requestHandler).setInstanceIdAndName(infraActiveRequest, currentActiveRequest);
InfraActiveRequests result = requestHandler.createNewRecordCopyFromInfraActiveRequest(infraActiveRequest,
CURRENT_REQUEST_ID, startTimeStamp, "VID", requestUri, "xxxxxx", RESUMED_REQUEST_ID);
assertThat(currentActiveRequest, sameBeanAs(result));
@@ -118,4 +153,247 @@ public class RequestHandlerUtilsUnitTest {
startTimeStamp, "VID", requestUri, "xxxxxx", RESUMED_REQUEST_ID);
assertThat(currentActiveRequestIARNull, sameBeanAs(result));
}
+
+ @Test
+ public void setInstanceIdAndNameServiceTest() {
+ InfraActiveRequests serviceRequest = new InfraActiveRequests();
+
+ InfraActiveRequests expected = new InfraActiveRequests();
+ expected.setServiceInstanceId(SERVICE_INSTANCE_ID);
+ expected.setServiceInstanceName(SERVICE_INSTANCE_NAME);
+
+ requestHandler.setInstanceIdAndName(infraActiveRequest, serviceRequest);
+ assertThat(serviceRequest, sameBeanAs(expected));
+ }
+
+ @Test
+ public void setInstanceIdAndNameRequestScopeNotValidTest() {
+ InfraActiveRequests originalServiceRequest = new InfraActiveRequests();
+ originalServiceRequest.setRequestScope("test");
+ InfraActiveRequests serviceRequest = new InfraActiveRequests();
+
+ InfraActiveRequests expected = new InfraActiveRequests();
+
+ requestHandler.setInstanceIdAndName(originalServiceRequest, serviceRequest);
+ assertThat(serviceRequest, sameBeanAs(expected));
+ }
+
+ @Test
+ public void setInstanceIdAndNameVnfTest() {
+ InfraActiveRequests vnfRequestOriginal = new InfraActiveRequests();
+ vnfRequestOriginal.setRequestScope("vnf");
+ vnfRequestOriginal.setVnfId(VNF_ID);
+ vnfRequestOriginal.setVnfName(VNF_NAME);
+ InfraActiveRequests vnfRequest = new InfraActiveRequests();
+
+ InfraActiveRequests expected = new InfraActiveRequests();
+ expected.setVnfId(VNF_ID);
+ expected.setVnfName(VNF_NAME);
+
+ requestHandler.setInstanceIdAndName(vnfRequestOriginal, vnfRequest);
+ assertThat(vnfRequest, sameBeanAs(expected));
+ }
+
+ @Test
+ public void setInstanceIdAndNameVfModuleTest() {
+ InfraActiveRequests vfModuleRequestOriginal = new InfraActiveRequests();
+ vfModuleRequestOriginal.setRequestScope("vfModule");
+ vfModuleRequestOriginal.setVfModuleId(VFMODULE_ID);
+ vfModuleRequestOriginal.setVfModuleName(VFMODULE_NAME);
+ InfraActiveRequests vfModuleRequest = new InfraActiveRequests();
+
+ InfraActiveRequests expected = new InfraActiveRequests();
+ expected.setVfModuleId(VFMODULE_ID);
+ expected.setVfModuleName(VFMODULE_NAME);
+
+ requestHandler.setInstanceIdAndName(vfModuleRequestOriginal, vfModuleRequest);
+ assertThat(vfModuleRequest, sameBeanAs(expected));
+ }
+
+ @Test
+ public void setInstanceIdAndNameNetworkTest() {
+ InfraActiveRequests networkRequestOriginal = new InfraActiveRequests();
+ networkRequestOriginal.setRequestScope("network");
+ networkRequestOriginal.setNetworkId(NETWORK_ID);
+ networkRequestOriginal.setNetworkName(NETWORK_NAME);
+ InfraActiveRequests networkRequest = new InfraActiveRequests();
+
+ InfraActiveRequests expected = new InfraActiveRequests();
+ expected.setNetworkId(NETWORK_ID);
+ expected.setNetworkName(NETWORK_NAME);
+
+ requestHandler.setInstanceIdAndName(networkRequestOriginal, networkRequest);
+ assertThat(networkRequest, sameBeanAs(expected));
+ }
+
+ @Test
+ public void setInstanceIdAndNameVolumeGroupTest() {
+ InfraActiveRequests volumeGroupRequestOriginal = new InfraActiveRequests();
+ volumeGroupRequestOriginal.setRequestScope("volumeGroup");
+ volumeGroupRequestOriginal.setVolumeGroupId(VOLUME_GROUP_ID);
+ volumeGroupRequestOriginal.setVolumeGroupName(VOLUME_GROUP_NAME);
+ InfraActiveRequests volumeGroupRequest = new InfraActiveRequests();
+
+ InfraActiveRequests expected = new InfraActiveRequests();
+ expected.setVolumeGroupId(VOLUME_GROUP_ID);
+ expected.setVolumeGroupName(VOLUME_GROUP_NAME);
+
+ requestHandler.setInstanceIdAndName(volumeGroupRequestOriginal, volumeGroupRequest);
+ assertThat(volumeGroupRequest, sameBeanAs(expected));
+ }
+
+ @Test
+ public void getIsBaseVfModuleTrueTest() throws ApiException {
+ VfModule vfModule = new VfModule();
+ vfModule.setIsBase(true);
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelVersionId(MODEL_VERSION_ID);
+
+ doReturn(vfModule).when(catDbClient).getVfModuleByModelUUID(MODEL_VERSION_ID);
+ Boolean expected = true;
+
+ Boolean result = requestHandler.getIsBaseVfModule(modelInfo, action, vnfType, sdcServiceModelVersion,
+ currentActiveRequest);
+ assertEquals(result, expected);
+ }
+
+ @Test
+ public void getIsBaseVfModuleFalseTest() throws ApiException {
+ VfModule vfModule = new VfModule();
+ vfModule.setIsBase(false);
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelVersionId(MODEL_VERSION_ID);
+
+ doReturn(vfModule).when(catDbClient).getVfModuleByModelUUID(MODEL_VERSION_ID);
+ Boolean expected = false;
+
+ Boolean result = requestHandler.getIsBaseVfModule(modelInfo, action, vnfType, sdcServiceModelVersion,
+ currentActiveRequest);
+ assertEquals(result, expected);
+ }
+
+ @Test
+ public void getIsBaseVfModuleNullTest() throws ApiException {
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelVersionId(MODEL_VERSION_ID);
+ modelInfo.setModelName(MODEL_NAME);
+ String errorMessage =
+ "VnfType vnfType and VF Module Model Name modelName with version 7 not found in MSO Catalog DB";
+
+ doNothing().when(requestHandler).updateStatus(currentActiveRequest, Status.FAILED, errorMessage);
+ doReturn(null).when(catDbClient).getVfModuleByModelUUID(MODEL_VERSION_ID);
+
+ thrown.expect(VfModuleNotFoundException.class);
+ thrown.expectMessage(errorMessage);
+ requestHandler.getIsBaseVfModule(modelInfo, action, vnfType, sdcServiceModelVersion, currentActiveRequest);
+ }
+
+ @Test
+ public void getIsBaseVfModuleModelVersionIdNullTest() throws ApiException {
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelInvariantId(MODEL_INVARIANT_ID);
+ modelInfo.setModelVersion(MODEL_VERSION);
+ modelInfo.setModelName(MODEL_NAME);
+ Boolean expected = false;
+
+ doReturn(null).when(catDbClient).getVfModuleByModelInvariantUUIDAndModelVersion(MODEL_INVARIANT_ID,
+ MODEL_VERSION);
+
+ Boolean result = requestHandler.getIsBaseVfModule(modelInfo, Action.deleteInstance, vnfType,
+ sdcServiceModelVersion, currentActiveRequest);
+ assertEquals(result, expected);
+ }
+
+ @Test
+ public void getIsBaseVfModuleModelInfoNotSetTest() throws ApiException {
+ ModelInfo modelInfo = new ModelInfo();
+ Boolean expected = false;
+
+ Boolean result = requestHandler.getIsBaseVfModule(modelInfo, Action.deleteInstance, vnfType,
+ sdcServiceModelVersion, currentActiveRequest);
+ assertEquals(result, expected);
+ }
+
+ @Test
+ public void getIsBaseVfModuleModelVersionNullTest() throws ApiException {
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelInvariantId(MODEL_INVARIANT_ID);
+ modelInfo.setModelName(MODEL_NAME);
+ Boolean expected = false;
+
+ Boolean result = requestHandler.getIsBaseVfModule(modelInfo, Action.deleteInstance, vnfType,
+ sdcServiceModelVersion, currentActiveRequest);
+ assertEquals(result, expected);
+ }
+
+ @Test
+ public void getIsBaseVfModuleModelVersionNullUpdateTest() throws ApiException {
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelInvariantId(MODEL_INVARIANT_ID);
+ modelInfo.setModelName(MODEL_NAME);
+ String errorMessage = "VnfType vnfType and VF Module Model Name modelName not found in MSO Catalog DB";
+
+ doNothing().when(requestHandler).updateStatus(currentActiveRequest, Status.FAILED, errorMessage);
+
+ thrown.expect(VfModuleNotFoundException.class);
+ thrown.expectMessage(errorMessage);
+ requestHandler.getIsBaseVfModule(modelInfo, Action.updateInstance, vnfType, null, currentActiveRequest);
+ }
+
+ @Test
+ public void getIsBaseVfModulesdcModelVersionEmptyTest() throws ApiException {
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelInvariantId(MODEL_INVARIANT_ID);
+ modelInfo.setModelName(MODEL_NAME);
+ String errorMessage = "VnfType vnfType and VF Module Model Name modelName not found in MSO Catalog DB";
+
+ doNothing().when(requestHandler).updateStatus(currentActiveRequest, Status.FAILED, errorMessage);
+
+ thrown.expect(VfModuleNotFoundException.class);
+ thrown.expectMessage(errorMessage);
+ requestHandler.getIsBaseVfModule(modelInfo, Action.updateInstance, vnfType, "", currentActiveRequest);
+ }
+
+ @Test
+ public void getModelTypeApplyUpdatedConfigTest() {
+ ModelType modelTypeExpected = ModelType.vnf;
+
+ ModelType modelTypeResult = requestHandler.getModelType(Action.applyUpdatedConfig, null);
+ assertEquals(modelTypeResult, modelTypeExpected);
+ }
+
+ @Test
+ public void getModelTypeInPlaceSoftwareUpdateTest() {
+ ModelType modelTypeExpected = ModelType.vnf;
+
+ ModelType modelTypeResult = requestHandler.getModelType(Action.inPlaceSoftwareUpdate, null);
+ assertEquals(modelTypeResult, modelTypeExpected);
+ }
+
+ @Test
+ public void getModelTypeAddMembersTest() {
+ ModelType modelTypeExpected = ModelType.instanceGroup;
+
+ ModelType modelTypeResult = requestHandler.getModelType(Action.addMembers, null);
+ assertEquals(modelTypeResult, modelTypeExpected);
+ }
+
+ @Test
+ public void getModelTypeRemoveMembersTest() {
+ ModelType modelTypeExpected = ModelType.instanceGroup;
+
+ ModelType modelTypeResult = requestHandler.getModelType(Action.removeMembers, null);
+ assertEquals(modelTypeResult, modelTypeExpected);
+ }
+
+ @Test
+ public void getModelTypeTest() {
+ ModelType modelTypeExpected = ModelType.service;
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelType(ModelType.service);
+
+ ModelType modelTypeResult = requestHandler.getModelType(Action.createInstance, modelInfo);
+ assertEquals(modelTypeResult, modelTypeExpected);
+ }
+
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequestTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequestTest.java
index 7e49fff50d..398966b0b3 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequestTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequestTest.java
@@ -30,6 +30,7 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
@@ -53,9 +54,11 @@ import org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException;
import org.onap.so.apihandlerinfra.exceptions.ValidateException;
import org.onap.so.db.request.beans.InfraActiveRequests;
import org.onap.so.db.request.client.RequestsDbClient;
+import org.onap.so.serviceinstancebeans.ModelInfo;
import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
import org.springframework.web.client.HttpClientErrorException;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.onap.so.serviceinstancebeans.ModelType;
@RunWith(MockitoJUnitRunner.class)
public class ResumeOrchestrationRequestTest {
@@ -81,8 +84,20 @@ public class ResumeOrchestrationRequestTest {
private static final String CURRENT_REQUEST_ID = "eca3a1b1-43ab-457e-ab1c-367263d148b4";
private static final String REQUEST_ID = "00032ab7-na18-42e5-965d-8ea592502019";
private static final String SERVICE_INSTANCE_ID = "00032ab7-na18-42e5-965d-8ea592502018";
+ private static final String VNF_ID = "00032ab7-na18-42e5-965d-8ea592502017";
+ private static final String VFMODULE_ID = "00032ab7-na18-42e5-965d-8ea592502016";
+ private static final String NETWORK_ID = "00032ab7-na18-42e5-965d-8ea592502015";
+ private static final String VOLUME_GROUP_ID = "00032ab7-na18-42e5-965d-8ea592502014";
private static final String SERVICE_INSTANCE_NAME = "serviceInstanceName";
- private static final String REQUEST_SCOPE = "service";
+ private static final String VNF_NAME = "vnfName";
+ private static final String VFMODULE_NAME = "vfModuleName";
+ private static final String NETWORK_NAME = "networkName";
+ private static final String VOLUME_GROUP_NAME = "volumeGroupName";
+ private static final String SERVICE = "service";
+ private static final String VNF = "vnf";
+ private static final String VFMODULE = "vfModule";
+ private static final String NETWORK = "network";
+ private static final String VOLUME_GROUP = "volumeGroup";
private final Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis());
private final Action action = Action.createInstance;
private final Boolean aLaCarte = false;
@@ -91,15 +106,18 @@ public class ResumeOrchestrationRequestTest {
"http:localhost:6746/onap/so/infra/orchestrationRequests/v7/00032ab7-na18-42e5-965d-8ea592502019/resume";
private final RecipeLookupResult lookupResult = new RecipeLookupResult("/mso/async/services/WorkflowActionBB", 80);
private RequestClientParameter requestClientParameter = null;
+ private RequestClientParameter requestClientParameterVfModule = null;
private ObjectMapper mapper = new ObjectMapper();
private InfraActiveRequests infraActiveRequest = new InfraActiveRequests();
private InfraActiveRequests currentActiveRequest = new InfraActiveRequests();
+ private InfraActiveRequests infraActiveRequestVfModule = new InfraActiveRequests();
private ServiceInstancesRequest sir = new ServiceInstancesRequest();
private ServiceInstancesRequest sirNullALaCarte = new ServiceInstancesRequest();
private String requestBody = null;
private String requestBodyNullALaCarte = null;
private ContainerRequestContext requestContext = null;
private HashMap<String, String> instanceIdMap = new HashMap<>();
+ ModelInfo modelInfo;
@Before
@@ -110,13 +128,16 @@ public class ResumeOrchestrationRequestTest {
// Setup InfraActiveRequests
setInfraActiveRequest();
setCurrentActiveRequest();
+ setInfraActiveRequestVfModule();
requestBody = infraActiveRequest.getRequestBody();
sir = mapper.readValue(requestBody, ServiceInstancesRequest.class);
requestBodyNullALaCarte = getRequestBody("/ALaCarteNull.json");
- sirNullALaCarte = sir = mapper.readValue(requestBodyNullALaCarte, ServiceInstancesRequest.class);
+ sirNullALaCarte = mapper.readValue(requestBodyNullALaCarte, ServiceInstancesRequest.class);
setRequestClientParameter();
+ setRequestClientParameterVfModule();
instanceIdMap.put("serviceInstanceId", SERVICE_INSTANCE_ID);
+ modelInfo = sir.getRequestDetails().getModelInfo();
}
public String getRequestBody(String request) throws IOException {
@@ -128,12 +149,21 @@ public class ResumeOrchestrationRequestTest {
infraActiveRequest.setTenantId("tenant-id");
infraActiveRequest.setRequestBody(getRequestBody("/RequestBody.json"));
infraActiveRequest.setAicCloudRegion("cloudRegion");
- infraActiveRequest.setRequestScope(REQUEST_SCOPE);
+ infraActiveRequest.setRequestScope(SERVICE);
infraActiveRequest.setServiceInstanceId(SERVICE_INSTANCE_ID);
infraActiveRequest.setServiceInstanceName(SERVICE_INSTANCE_NAME);
infraActiveRequest.setRequestStatus(Status.IN_PROGRESS.toString());
infraActiveRequest.setRequestAction(Action.createInstance.toString());
infraActiveRequest.setServiceType("serviceType");
+ infraActiveRequest.setVnfId(VNF_ID);
+ infraActiveRequest.setVfModuleId(VFMODULE_ID);
+ infraActiveRequest.setNetworkId(NETWORK_ID);
+ infraActiveRequest.setVolumeGroupId(VOLUME_GROUP_ID);
+ infraActiveRequest.setVnfName(VNF_NAME);
+ infraActiveRequest.setVfModuleName(VFMODULE_NAME);
+ infraActiveRequest.setNetworkName(NETWORK_NAME);
+ infraActiveRequest.setVolumeGroupName(VOLUME_GROUP_NAME);
+ infraActiveRequest.setRequestId(REQUEST_ID);
}
private void setCurrentActiveRequest() throws IOException {
@@ -143,7 +173,7 @@ public class ResumeOrchestrationRequestTest {
currentActiveRequest.setTenantId("tenant-id");
currentActiveRequest.setRequestBody(getRequestBody("/RequestBody.json"));
currentActiveRequest.setAicCloudRegion("cloudRegion");
- currentActiveRequest.setRequestScope(REQUEST_SCOPE);
+ currentActiveRequest.setRequestScope(SERVICE);
currentActiveRequest.setServiceInstanceId(SERVICE_INSTANCE_ID);
currentActiveRequest.setServiceInstanceName(SERVICE_INSTANCE_NAME);
currentActiveRequest.setRequestStatus(Status.IN_PROGRESS.toString());
@@ -154,13 +184,33 @@ public class ResumeOrchestrationRequestTest {
currentActiveRequest.setProgress(new Long(5));
}
+ private void setInfraActiveRequestVfModule() throws IOException {
+ infraActiveRequestVfModule.setRequestBody(getRequestBody("/RequestBody.json"));
+ infraActiveRequestVfModule.setRequestScope(VFMODULE);
+ infraActiveRequestVfModule.setRequestStatus(Status.IN_PROGRESS.toString());
+ infraActiveRequestVfModule.setRequestAction(Action.createInstance.toString());
+ infraActiveRequestVfModule.setVnfId(VNF_ID);
+ infraActiveRequestVfModule.setVfModuleId(VFMODULE_ID);
+ infraActiveRequestVfModule.setVnfName(VNF_NAME);
+ infraActiveRequestVfModule.setVfModuleName(VFMODULE_NAME);
+ }
+
private void setRequestClientParameter() {
- requestClientParameter = new RequestClientParameter.Builder().setRequestId(CURRENT_REQUEST_ID)
- .setRecipeTimeout(80).setRequestAction(Action.createInstance.toString())
- .setServiceInstanceId(SERVICE_INSTANCE_ID).setPnfCorrelationId("pnfCorrelationId").setVnfId(null)
- .setVfModuleId(null).setVolumeGroupId(null).setNetworkId(null).setServiceType("serviceType")
- .setVnfType(null).setNetworkType(null).setRequestDetails(requestBody).setApiVersion(version)
- .setALaCarte(aLaCarte).setRequestUri(requestUri).setInstanceGroupId(null).build();
+ requestClientParameter =
+ new RequestClientParameter.Builder().setRequestId(CURRENT_REQUEST_ID).setRecipeTimeout(80)
+ .setRequestAction(Action.createInstance.toString()).setServiceInstanceId(SERVICE_INSTANCE_ID)
+ .setPnfCorrelationId("pnfCorrelationId").setVnfId(VNF_ID).setVfModuleId(VFMODULE_ID)
+ .setVolumeGroupId(VOLUME_GROUP_ID).setNetworkId(NETWORK_ID).setServiceType("serviceType")
+ .setVnfType(null).setNetworkType(null).setRequestDetails(requestBody).setApiVersion(version)
+ .setALaCarte(aLaCarte).setRequestUri(requestUri).setInstanceGroupId(null).build();
+ }
+
+ private void setRequestClientParameterVfModule() {
+ requestClientParameterVfModule =
+ new RequestClientParameter.Builder().setRequestId(CURRENT_REQUEST_ID).setRecipeTimeout(80)
+ .setRequestAction(Action.createInstance.toString()).setPnfCorrelationId("pnfCorrelationId")
+ .setVnfId(VNF_ID).setVfModuleId(VFMODULE_ID).setRequestDetails(requestBody)
+ .setApiVersion(version).setALaCarte(aLaCarte).setRequestUri(requestUri).build();
}
@Test
@@ -201,16 +251,20 @@ public class ResumeOrchestrationRequestTest {
@Test
public void resumeRequestTest() throws ApiException, IOException {
Response response = null;
+ doReturn(instanceIdMap).when(resumeReq).setInstanceIdMap(infraActiveRequest, ModelType.service.toString());
+ doReturn(SERVICE_INSTANCE_NAME).when(resumeReq).getInstanceName(infraActiveRequest,
+ ModelType.service.toString(), currentActiveRequest);
when(requestHandler.convertJsonToServiceInstanceRequest(anyString(), any(Actions.class), anyString(),
anyString())).thenReturn(sir);
when(serviceInstances.getPnfCorrelationId(any(ServiceInstancesRequest.class))).thenReturn("pnfCorrelationId");
- doReturn(lookupResult).when(resumeReq).serviceRecipeLookup(currentActiveRequest, sir, action, aLaCarte);
+ doReturn(lookupResult).when(serviceInstances).getServiceInstanceOrchestrationURI(sir, action, aLaCarte,
+ currentActiveRequest);
doReturn(requestClientParameter).when(resumeReq).setRequestClientParameter(lookupResult, version,
infraActiveRequest, currentActiveRequest, "pnfCorrelationId", aLaCarte, sir);
doNothing().when(resumeReq).requestDbSave(currentActiveRequest);
when(requestHandler.postBPELRequest(any(InfraActiveRequests.class), any(RequestClientParameter.class),
anyString(), anyString())).thenReturn(response);
- doNothing().when(resumeReq).checkForInProgressRequest(currentActiveRequest, SERVICE_INSTANCE_ID, REQUEST_SCOPE,
+ doNothing().when(resumeReq).checkForInProgressRequest(currentActiveRequest, instanceIdMap, SERVICE,
SERVICE_INSTANCE_NAME, action);
resumeReq.resumeRequest(infraActiveRequest, currentActiveRequest, version,
@@ -220,15 +274,8 @@ public class ResumeOrchestrationRequestTest {
}
@Test
- public void serviceRecipeLookupTest() throws ApiException, IOException {
- when(serviceInstances.getServiceURI(any(ServiceInstancesRequest.class), any(Action.class), anyBoolean()))
- .thenReturn(lookupResult);
- RecipeLookupResult result = resumeReq.serviceRecipeLookup(currentActiveRequest, sir, action, aLaCarte);
- assertThat(result, sameBeanAs(lookupResult));
- }
-
- @Test
public void setRequestClientParameterTest() throws ApiException, IOException {
+ doReturn(ModelType.service).when(requestHandler).getModelType(action, modelInfo);
when(requestHandler.mapJSONtoMSOStyle(anyString(), any(ServiceInstancesRequest.class), anyBoolean(),
any(Action.class))).thenReturn(requestBody);
RequestClientParameter result = resumeReq.setRequestClientParameter(lookupResult, version, infraActiveRequest,
@@ -237,6 +284,16 @@ public class ResumeOrchestrationRequestTest {
}
@Test
+ public void setRequestClientParameterVfModuleTest() throws ApiException, IOException {
+ when(requestHandler.mapJSONtoMSOStyle(anyString(), any(ServiceInstancesRequest.class), anyBoolean(),
+ any(Action.class))).thenReturn(requestBody);
+ doReturn(ModelType.vfModule).when(requestHandler).getModelType(action, modelInfo);
+ RequestClientParameter result = resumeReq.setRequestClientParameter(lookupResult, version,
+ infraActiveRequestVfModule, currentActiveRequest, "pnfCorrelationId", aLaCarte, sir);
+ assertThat(requestClientParameterVfModule, sameBeanAs(result));
+ }
+
+ @Test
public void requestDbSaveTest() throws RequestDbFailureException {
doNothing().when(requestDbClient).save(currentActiveRequest);
resumeReq.requestDbSave(currentActiveRequest);
@@ -246,17 +303,22 @@ public class ResumeOrchestrationRequestTest {
@Test
public void resumeRequestTestALaCarteNull() throws ApiException, IOException {
Response response = null;
-
+ doReturn(instanceIdMap).when(resumeReq).setInstanceIdMap(infraActiveRequest, ModelType.service.toString());
+ doReturn(SERVICE_INSTANCE_NAME).when(resumeReq).getInstanceName(infraActiveRequest,
+ ModelType.service.toString(), currentActiveRequest);
when(requestHandler.convertJsonToServiceInstanceRequest(anyString(), any(Actions.class), anyString(),
anyString())).thenReturn(sirNullALaCarte);
when(serviceInstances.getPnfCorrelationId(any(ServiceInstancesRequest.class))).thenReturn("pnfCorrelationId");
- doReturn(lookupResult).when(resumeReq).serviceRecipeLookup(currentActiveRequest, sir, action, aLaCarte);
+ doReturn(false).when(msoRequest).getAlacarteFlag(sirNullALaCarte);
+ doReturn(lookupResult).when(serviceInstances).getServiceInstanceOrchestrationURI(sirNullALaCarte, action, false,
+ currentActiveRequest);
doReturn(requestClientParameter).when(resumeReq).setRequestClientParameter(lookupResult, version,
- infraActiveRequest, currentActiveRequest, "pnfCorrelationId", aLaCarte, sir);
+ infraActiveRequest, currentActiveRequest, "pnfCorrelationId", aLaCarte, sirNullALaCarte);
+ doReturn(false).when(resumeReq).setALaCarteFlagIfNull(SERVICE, action);
doNothing().when(resumeReq).requestDbSave(currentActiveRequest);
when(requestHandler.postBPELRequest(any(InfraActiveRequests.class), any(RequestClientParameter.class),
anyString(), anyString())).thenReturn(response);
- doNothing().when(resumeReq).checkForInProgressRequest(currentActiveRequest, SERVICE_INSTANCE_ID, REQUEST_SCOPE,
+ doNothing().when(resumeReq).checkForInProgressRequest(currentActiveRequest, instanceIdMap, SERVICE,
SERVICE_INSTANCE_NAME, action);
resumeReq.resumeRequest(infraActiveRequest, currentActiveRequest, version,
@@ -266,18 +328,8 @@ public class ResumeOrchestrationRequestTest {
}
@Test
- public void serviceRecipeLookupErrorTest() throws IOException, ApiException {
- when(serviceInstances.getServiceURI(sir, action, aLaCarte))
- .thenThrow(new IOException("Error occurred on recipe lookup"));
- doNothing().when(requestHandler).updateStatus(any(InfraActiveRequests.class), any(Status.class), anyString());
-
- thrown.expect(ValidateException.class);
- thrown.expectMessage("Error occurred on recipe lookup");
- resumeReq.serviceRecipeLookup(currentActiveRequest, sir, action, aLaCarte);
- }
-
- @Test
public void setRequestClientParameterErrorTest() throws ApiException, IOException {
+ doReturn(ModelType.service).when(requestHandler).getModelType(action, modelInfo);
when(requestHandler.mapJSONtoMSOStyle(anyString(), any(ServiceInstancesRequest.class), anyBoolean(),
any(Action.class))).thenThrow(new IOException("IOException"));
@@ -290,39 +342,141 @@ public class ResumeOrchestrationRequestTest {
@Test
public void checkForInProgressRequest() throws ApiException {
doReturn(infraActiveRequest).when(requestHandler).duplicateCheck(action, instanceIdMap, SERVICE_INSTANCE_NAME,
- REQUEST_SCOPE, currentActiveRequest);
+ SERVICE, currentActiveRequest);
doReturn(true).when(requestHandler).camundaHistoryCheck(infraActiveRequest, currentActiveRequest);
doThrow(DuplicateRequestException.class).when(requestHandler).buildErrorOnDuplicateRecord(currentActiveRequest,
- action, instanceIdMap, SERVICE_INSTANCE_NAME, REQUEST_SCOPE, infraActiveRequest);
+ action, instanceIdMap, SERVICE_INSTANCE_NAME, SERVICE, infraActiveRequest);
thrown.expect(DuplicateRequestException.class);
- resumeReq.checkForInProgressRequest(currentActiveRequest, SERVICE_INSTANCE_ID, REQUEST_SCOPE,
- SERVICE_INSTANCE_NAME, action);
+ resumeReq.checkForInProgressRequest(currentActiveRequest, instanceIdMap, SERVICE, SERVICE_INSTANCE_NAME,
+ action);
}
@Test
public void checkForInProgressRequestNoInProgressRequests() throws ApiException {
- doReturn(null).when(requestHandler).duplicateCheck(action, instanceIdMap, SERVICE_INSTANCE_NAME, REQUEST_SCOPE,
+ doReturn(null).when(requestHandler).duplicateCheck(action, instanceIdMap, SERVICE_INSTANCE_NAME, SERVICE,
currentActiveRequest);
- resumeReq.checkForInProgressRequest(currentActiveRequest, SERVICE_INSTANCE_ID, REQUEST_SCOPE,
- SERVICE_INSTANCE_NAME, action);
- verify(requestHandler).duplicateCheck(action, instanceIdMap, SERVICE_INSTANCE_NAME, REQUEST_SCOPE,
+ resumeReq.checkForInProgressRequest(currentActiveRequest, instanceIdMap, SERVICE, SERVICE_INSTANCE_NAME,
+ action);
+ verify(requestHandler).duplicateCheck(action, instanceIdMap, SERVICE_INSTANCE_NAME, SERVICE,
currentActiveRequest);
}
@Test
public void checkForInProgressRequestCamundaHistoryCheckReturnsNoInProgress() throws ApiException {
doReturn(infraActiveRequest).when(requestHandler).duplicateCheck(action, instanceIdMap, SERVICE_INSTANCE_NAME,
- REQUEST_SCOPE, currentActiveRequest);
+ SERVICE, currentActiveRequest);
doReturn(false).when(requestHandler).camundaHistoryCheck(infraActiveRequest, currentActiveRequest);
- resumeReq.checkForInProgressRequest(currentActiveRequest, SERVICE_INSTANCE_ID, REQUEST_SCOPE,
- SERVICE_INSTANCE_NAME, action);
- verify(requestHandler).duplicateCheck(action, instanceIdMap, SERVICE_INSTANCE_NAME, REQUEST_SCOPE,
+ resumeReq.checkForInProgressRequest(currentActiveRequest, instanceIdMap, SERVICE, SERVICE_INSTANCE_NAME,
+ action);
+ verify(requestHandler).duplicateCheck(action, instanceIdMap, SERVICE_INSTANCE_NAME, SERVICE,
currentActiveRequest);
verify(requestHandler).camundaHistoryCheck(infraActiveRequest, currentActiveRequest);
}
+ @Test
+ public void setInstanceIdMapServiceTest() {
+ HashMap<String, String> expected = new HashMap<>();
+ expected.put("serviceInstanceId", SERVICE_INSTANCE_ID);
+ HashMap<String, String> result = resumeReq.setInstanceIdMap(infraActiveRequest, SERVICE);
+ assertEquals(result, expected);
+ }
+
+ @Test
+ public void setInstanceIdMapRequestScopeNotValidTest() {
+ HashMap<String, String> expected = new HashMap<>();
+ HashMap<String, String> result = resumeReq.setInstanceIdMap(infraActiveRequest, "test");
+ assertEquals(result, expected);
+ }
+
+ @Test
+ public void setInstanceIdMapVnfTest() {
+ HashMap<String, String> expected = new HashMap<>();
+ expected.put("vnfInstanceId", VNF_ID);
+ HashMap<String, String> result = resumeReq.setInstanceIdMap(infraActiveRequest, VNF);
+ assertEquals(result, expected);
+ }
+
+ @Test
+ public void setInstanceIdMapVfModuleTest() {
+ HashMap<String, String> expected = new HashMap<>();
+ expected.put("vfModuleInstanceId", VFMODULE_ID);
+ HashMap<String, String> result = resumeReq.setInstanceIdMap(infraActiveRequest, VFMODULE);
+ assertEquals(result, expected);
+ }
+
+ @Test
+ public void setInstanceIdMapNetworkTest() {
+ HashMap<String, String> expected = new HashMap<>();
+ expected.put("networkInstanceId", NETWORK_ID);
+ HashMap<String, String> result = resumeReq.setInstanceIdMap(infraActiveRequest, NETWORK);
+ assertEquals(result, expected);
+ }
+
+ @Test
+ public void setInstanceIdMapVolumeGroupTest() {
+ HashMap<String, String> expected = new HashMap<>();
+ expected.put("volumeGroupInstanceId", VOLUME_GROUP_ID);
+ HashMap<String, String> result = resumeReq.setInstanceIdMap(infraActiveRequest, VOLUME_GROUP);
+ assertEquals(result, expected);
+ }
+
+ @Test
+ public void setInstanceNameServiceTest() throws ValidateException, RequestDbFailureException {
+ String result = resumeReq.getInstanceName(infraActiveRequest, SERVICE, currentActiveRequest);
+ assertEquals(result, SERVICE_INSTANCE_NAME);
+ }
+
+ @Test
+ public void setInstanceNameRequestScopeNotValidTest() throws ValidateException, RequestDbFailureException {
+ thrown.expect(ValidateException.class);
+ thrown.expectMessage(
+ "requestScope: \"test\" from request: 00032ab7-na18-42e5-965d-8ea592502019 does not match a ModelType enum.");
+
+ resumeReq.getInstanceName(infraActiveRequest, "test", currentActiveRequest);
+ }
+
+ @Test
+ public void setInstanceNameVnfTest() throws ValidateException, RequestDbFailureException {
+ String result = resumeReq.getInstanceName(infraActiveRequest, VNF, currentActiveRequest);
+ assertEquals(result, VNF_NAME);
+ }
+ @Test
+ public void setInstanceNameVfModuleTest() throws ValidateException, RequestDbFailureException {
+ String result = resumeReq.getInstanceName(infraActiveRequest, VFMODULE, currentActiveRequest);
+ assertEquals(result, VFMODULE_NAME);
+ }
+
+ @Test
+ public void setInstanceNameNetworkTest() throws ValidateException, RequestDbFailureException {
+ String result = resumeReq.getInstanceName(infraActiveRequest, NETWORK, currentActiveRequest);
+ assertEquals(result, NETWORK_NAME);
+ }
+
+ @Test
+ public void setInstanceNameVolumeGroupTest() throws ValidateException, RequestDbFailureException {
+ String result = resumeReq.getInstanceName(infraActiveRequest, VOLUME_GROUP, currentActiveRequest);
+ assertEquals(result, VOLUME_GROUP_NAME);
+ }
+
+ @Test
+ public void setALaCarteFlagIfNullTest() {
+ Boolean aLaCarteFlag = resumeReq.setALaCarteFlagIfNull(SERVICE, action);
+ assertEquals(aLaCarteFlag, false);
+ }
+
+ @Test
+ public void setALaCarteFlagIfNullVnfTest() {
+ Boolean aLaCarteFlag = resumeReq.setALaCarteFlagIfNull(VNF, action);
+ assertEquals(aLaCarteFlag, true);
+ }
+
+ @Test
+ public void setALaCarteFlagIfNullRecreateTest() {
+ Boolean aLaCarteFlag = resumeReq.setALaCarteFlagIfNull(VNF, Action.recreateInstance);
+ assertEquals(aLaCarteFlag, false);
+ }
}