diff options
author | Plummer, Brittany <brittany.plummer@att.com> | 2019-05-31 15:56:32 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2019-05-31 15:56:44 -0400 |
commit | a8e40692a53109fde1eb6e977947db907a611287 (patch) | |
tree | bb070e9203b971784212f18560ccf6d206dd8033 /mso-api-handlers/mso-api-handler-infra/src | |
parent | 89b396152a7f5ca62175d13342c1b3a1a9067ccb (diff) |
apih resume request handling more generic
getInstanceName throws exception if requestScope doesn't match modelType
Updated to combine separate return statements
Replaced if statements for modelType and added tests
Replace if statements for modelType in ResumeOrchestrationRequest and
added tests
Added coverage for setId in ModelType
Updated to use ModelType setters/getters
model type can now get and set generically
Added modelInfo to RequestBody for resume request
Added getModelType call and unit tests
Moved getModelType from ServiceInstances
Moved getModelType and added unit tests
Added tests for getIsBaseVfModule
Added more tests for isBaseVfModule
Began adding tests for getIsBaseVfModule
Updated currentActiveRequest creation and isBaseVfModule
Updated recipe lookup and setting of aLaCarte to be more general
Updated concurrency control to include other resources
Change-Id: I12ad011d0a021c3ee066e16b4c8a4526d040cbe3
Issue-ID: SO-1963
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src')
6 files changed, 648 insertions, 152 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java index 2a0718aeba..4e910e5382 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java @@ -59,7 +59,9 @@ import org.onap.so.apihandlerinfra.exceptions.ContactCamundaException; import org.onap.so.apihandlerinfra.exceptions.DuplicateRequestException; import org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException; import org.onap.so.apihandlerinfra.exceptions.ValidateException; +import org.onap.so.apihandlerinfra.exceptions.VfModuleNotFoundException; import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; +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.db.request.client.RequestsDbClient; @@ -67,6 +69,7 @@ import org.onap.so.exceptions.ValidationException; import org.onap.so.logger.ErrorCode; import org.onap.so.logger.LogConstants; import org.onap.so.logger.MessageEnum; +import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.ModelType; import org.onap.so.serviceinstancebeans.RelatedInstance; import org.onap.so.serviceinstancebeans.RelatedInstanceList; @@ -638,11 +641,70 @@ public class RequestHandlerUtils { request.setRequestBody(infraActiveRequest.getRequestBody()); request.setAicCloudRegion(infraActiveRequest.getAicCloudRegion()); request.setRequestScope(infraActiveRequest.getRequestScope()); - request.setServiceInstanceId(infraActiveRequest.getServiceInstanceId()); - request.setServiceInstanceName(infraActiveRequest.getServiceInstanceName()); request.setRequestAction(infraActiveRequest.getRequestAction()); + setInstanceIdAndName(infraActiveRequest, request); } return request; } + protected void setInstanceIdAndName(InfraActiveRequests infraActiveRequest, + InfraActiveRequests currentActiveRequest) { + String requestScope = infraActiveRequest.getRequestScope(); + try { + ModelType type = ModelType.valueOf(requestScope); + type.setName(currentActiveRequest, type.getName(infraActiveRequest)); + type.setId(currentActiveRequest, type.getId(infraActiveRequest)); + } catch (IllegalArgumentException e) { + logger.error( + "requestScope \"{}\" does not match a ModelType enum. Unable to set instanceId and instanceName from the original request.", + requestScope); + } + } + + protected Boolean getIsBaseVfModule(ModelInfo modelInfo, Actions action, String vnfType, + String sdcServiceModelVersion, InfraActiveRequests currentActiveReq) throws ApiException { + // Get VF Module-specific base module indicator + VfModule vfm = null; + String modelVersionId = modelInfo.getModelVersionId(); + Boolean isBaseVfModule = false; + + if (modelVersionId != null) { + vfm = catalogDbClient.getVfModuleByModelUUID(modelVersionId); + } else if (modelInfo.getModelInvariantId() != null && modelInfo.getModelVersion() != null) { + vfm = catalogDbClient.getVfModuleByModelInvariantUUIDAndModelVersion(modelInfo.getModelInvariantId(), + modelInfo.getModelVersion()); + } + + if (vfm != null) { + if (vfm.getIsBase()) { + isBaseVfModule = true; + } + } else if (action == Action.createInstance || action == Action.updateInstance) { + String serviceVersionText = ""; + if (sdcServiceModelVersion != null && !sdcServiceModelVersion.isEmpty()) { + serviceVersionText = " with version " + sdcServiceModelVersion; + } + String errorMessage = "VnfType " + vnfType + " and VF Module Model Name " + modelInfo.getModelName() + + serviceVersionText + " not found in MSO Catalog DB"; + ErrorLoggerInfo errorLoggerInfo = + new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, ErrorCode.DataError) + .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); + VfModuleNotFoundException vfModuleException = new VfModuleNotFoundException.Builder(errorMessage, + HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build(); + updateStatus(currentActiveReq, Status.FAILED, vfModuleException.getMessage()); + throw vfModuleException; + } + return isBaseVfModule; + } + + protected ModelType getModelType(Actions action, ModelInfo modelInfo) { + if (action == Action.applyUpdatedConfig || action == Action.inPlaceSoftwareUpdate) { + return ModelType.vnf; + } else if (action == Action.addMembers || action == Action.removeMembers) { + return ModelType.instanceGroup; + } else { + return modelInfo.getModelType(); + } + } + } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequest.java index abf3729215..32d2c50978 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ResumeOrchestrationRequest.java @@ -47,6 +47,8 @@ import org.onap.so.logger.HttpHeadersConstants; import org.onap.so.logger.LogConstants; import org.onap.so.logger.MdcConstants; import org.onap.so.logger.MessageEnum; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.ModelType; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,6 +76,8 @@ public class ResumeOrchestrationRequest { @Autowired private RequestsDbClient requestsDbClient; + @Autowired + private MsoRequest msoRequest; @POST @Path("/{version:[vV][7]}/requests/{requestId}/resume") @@ -128,24 +132,26 @@ public class ResumeOrchestrationRequest { String requestBody = infraActiveRequest.getRequestBody(); Action action = Action.valueOf(infraActiveRequest.getRequestAction()); String requestId = currentActiveRequest.getRequestId(); - String serviceInstanceName = infraActiveRequest.getServiceInstanceName(); String requestScope = infraActiveRequest.getRequestScope(); - String serviceInstanceId = infraActiveRequest.getServiceInstanceId(); + String instanceName = getInstanceName(infraActiveRequest, requestScope, currentActiveRequest); + HashMap<String, String> instanceIdMap = setInstanceIdMap(infraActiveRequest, requestScope); - checkForInProgressRequest(currentActiveRequest, serviceInstanceId, requestScope, serviceInstanceName, action); + checkForInProgressRequest(currentActiveRequest, instanceIdMap, requestScope, instanceName, action); ServiceInstancesRequest sir = null; sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestBody, action, requestId, requestUri); Boolean aLaCarte = sir.getRequestDetails().getRequestParameters().getALaCarte(); - if (aLaCarte == null) { - aLaCarte = false; - } String pnfCorrelationId = serviceInstances.getPnfCorrelationId(sir); - RecipeLookupResult recipeLookupResult = serviceRecipeLookup(currentActiveRequest, sir, action, aLaCarte); + RecipeLookupResult recipeLookupResult = serviceInstances.getServiceInstanceOrchestrationURI(sir, action, + msoRequest.getAlacarteFlag(sir), currentActiveRequest); requestDbSave(currentActiveRequest); + if (aLaCarte == null) { + aLaCarte = setALaCarteFlagIfNull(requestScope, action); + } + RequestClientParameter requestClientParameter = setRequestClientParameter(recipeLookupResult, version, infraActiveRequest, currentActiveRequest, pnfCorrelationId, aLaCarte, sir); @@ -153,40 +159,60 @@ public class ResumeOrchestrationRequest { recipeLookupResult.getOrchestrationURI(), requestScope); } - protected void checkForInProgressRequest(InfraActiveRequests currentActiveRequest, String serviceInstanceId, - String requestScope, String serviceInstanceName, Action action) throws ApiException { - boolean inProgress = false; - HashMap<String, String> instanceIdMap = new HashMap<>(); - instanceIdMap.put("serviceInstanceId", serviceInstanceId); - InfraActiveRequests requestInProgress = requestHandlerUtils.duplicateCheck(action, instanceIdMap, - serviceInstanceName, requestScope, currentActiveRequest); - if (requestInProgress != null) { - inProgress = requestHandlerUtils.camundaHistoryCheck(requestInProgress, currentActiveRequest); + protected Boolean setALaCarteFlagIfNull(String requestScope, Action action) { + Boolean aLaCarteFlag; + if (!requestScope.equalsIgnoreCase(ModelType.service.name()) && action != Action.recreateInstance) { + aLaCarteFlag = true; + } else { + aLaCarteFlag = false; } - if (inProgress) { - requestHandlerUtils.buildErrorOnDuplicateRecord(currentActiveRequest, action, instanceIdMap, - serviceInstanceName, requestScope, requestInProgress); + return aLaCarteFlag; + } + + protected HashMap<String, String> setInstanceIdMap(InfraActiveRequests infraActiveRequest, String requestScope) { + HashMap<String, String> instanceIdMap = new HashMap<>(); + ModelType type; + try { + type = ModelType.valueOf(requestScope); + instanceIdMap.put(type.name() + "InstanceId", type.getId(infraActiveRequest)); + } catch (IllegalArgumentException e) { + logger.error("requestScope \"{}\" does not match a ModelType enum.", requestScope); } + return instanceIdMap; } - protected RecipeLookupResult serviceRecipeLookup(InfraActiveRequests currentActiveRequest, - ServiceInstancesRequest sir, Action action, Boolean aLaCarte) - throws ValidateException, RequestDbFailureException { - RecipeLookupResult recipeLookupResult = null; + protected String getInstanceName(InfraActiveRequests infraActiveRequest, String requestScope, + InfraActiveRequests currentActiveRequest) throws ValidateException, RequestDbFailureException { + ModelType type; + String instanceName = ""; try { - recipeLookupResult = serviceInstances.getServiceURI(sir, action, aLaCarte); - } catch (IOException e) { - logger.error("IOException while performing service recipe lookup", e); - ErrorLoggerInfo errorLoggerInfo = - new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError) - .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); - ValidateException validateException = - new ValidateException.Builder(e.getMessage(), HttpStatus.SC_BAD_REQUEST, - ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build(); + type = ModelType.valueOf(requestScope); + instanceName = type.getName(infraActiveRequest); + } catch (IllegalArgumentException e) { + logger.error("requestScope \"{}\" does not match a ModelType enum.", requestScope); + ValidateException validateException = new ValidateException.Builder( + "requestScope: \"" + requestScope + "\" from request: " + infraActiveRequest.getRequestId() + + " does not match a ModelType enum.", + HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).build(); requestHandlerUtils.updateStatus(currentActiveRequest, Status.FAILED, validateException.getMessage()); throw validateException; } - return recipeLookupResult; + return instanceName; + } + + protected void checkForInProgressRequest(InfraActiveRequests currentActiveRequest, + HashMap<String, String> instanceIdMap, String requestScope, String instanceName, Action action) + throws ApiException { + boolean inProgress = false; + InfraActiveRequests requestInProgress = requestHandlerUtils.duplicateCheck(action, instanceIdMap, instanceName, + requestScope, currentActiveRequest); + if (requestInProgress != null) { + inProgress = requestHandlerUtils.camundaHistoryCheck(requestInProgress, currentActiveRequest); + } + if (inProgress) { + requestHandlerUtils.buildErrorOnDuplicateRecord(currentActiveRequest, action, instanceIdMap, instanceName, + requestScope, requestInProgress); + } } protected void requestDbSave(InfraActiveRequests currentActiveRequest) throws RequestDbFailureException { @@ -204,23 +230,37 @@ public class ResumeOrchestrationRequest { protected RequestClientParameter setRequestClientParameter(RecipeLookupResult recipeLookupResult, String version, InfraActiveRequests infraActiveRequest, InfraActiveRequests currentActiveRequest, String pnfCorrelationId, - Boolean aLaCarte, ServiceInstancesRequest sir) throws ValidateException { + Boolean aLaCarte, ServiceInstancesRequest sir) throws ApiException { RequestClientParameter requestClientParameter = null; + Action action = Action.valueOf(infraActiveRequest.getRequestAction()); + ModelInfo modelInfo = sir.getRequestDetails().getModelInfo(); + + Boolean isBaseVfModule = false; + if (requestHandlerUtils.getModelType(action, modelInfo).equals(ModelType.vfModule)) { + isBaseVfModule = requestHandlerUtils.getIsBaseVfModule(modelInfo, action, infraActiveRequest.getVnfType(), + msoRequest.getSDCServiceModelVersion(sir), currentActiveRequest); + } + try { - requestClientParameter = new RequestClientParameter.Builder() - .setRequestId(currentActiveRequest.getRequestId()) - .setRecipeTimeout(recipeLookupResult.getRecipeTimeout()) - .setRequestAction(infraActiveRequest.getRequestAction()) - .setServiceInstanceId(infraActiveRequest.getServiceInstanceId()) - .setPnfCorrelationId(pnfCorrelationId).setVnfId(infraActiveRequest.getVnfId()) - .setVfModuleId(infraActiveRequest.getVfModuleId()) - .setVolumeGroupId(infraActiveRequest.getVolumeGroupId()) - .setNetworkId(infraActiveRequest.getNetworkId()).setServiceType(infraActiveRequest.getServiceType()) - .setVnfType(infraActiveRequest.getVnfType()).setNetworkType(infraActiveRequest.getNetworkType()) - .setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(infraActiveRequest.getRequestBody(), sir, - aLaCarte, Action.valueOf(infraActiveRequest.getRequestAction()))) - .setApiVersion(version).setALaCarte(aLaCarte).setRequestUri(currentActiveRequest.getRequestUrl()) - .setInstanceGroupId(infraActiveRequest.getInstanceGroupId()).build(); + requestClientParameter = + new RequestClientParameter.Builder().setRequestId(currentActiveRequest.getRequestId()) + .setBaseVfModule(isBaseVfModule).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()) + .setRequestAction(infraActiveRequest.getRequestAction()) + .setServiceInstanceId(infraActiveRequest.getServiceInstanceId()) + .setPnfCorrelationId(pnfCorrelationId).setVnfId(infraActiveRequest.getVnfId()) + .setVfModuleId(infraActiveRequest.getVfModuleId()) + .setVolumeGroupId(infraActiveRequest.getVolumeGroupId()) + .setNetworkId(infraActiveRequest.getNetworkId()) + .setServiceType(infraActiveRequest.getServiceType()) + .setVnfType(infraActiveRequest.getVnfType()) + .setVfModuleType(msoRequest.getVfModuleType(sir, infraActiveRequest.getRequestScope(), + action, Integer.parseInt(version))) + .setNetworkType(infraActiveRequest.getNetworkType()) + .setRequestDetails(requestHandlerUtils + .mapJSONtoMSOStyle(infraActiveRequest.getRequestBody(), sir, aLaCarte, action)) + .setApiVersion(version).setALaCarte(aLaCarte) + .setRequestUri(currentActiveRequest.getRequestUrl()) + .setInstanceGroupId(infraActiveRequest.getInstanceGroupId()).build(); } catch (IOException e) { logger.error("IOException while generating requestClientParameter to send to BPMN", e); ErrorLoggerInfo errorLoggerInfo = diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java index 45319de5e8..68fa6e4f56 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java @@ -814,64 +814,20 @@ public class ServiceInstances { referencesResponse.setRequestId(requestId); serviceResponse.setRequestReferences(referencesResponse); - Boolean isBaseVfModule = false; - RecipeLookupResult recipeLookupResult = getServiceInstanceOrchestrationURI(sir, action, alaCarteFlag, currentActiveReq); String serviceInstanceType = requestHandlerUtils.getServiceType(requestScope, sir, alaCarteFlag); - ModelType modelType; - ModelInfo modelInfo = sir.getRequestDetails().getModelInfo(); - if (action == Action.applyUpdatedConfig || action == Action.inPlaceSoftwareUpdate) { - modelType = ModelType.vnf; - } else if (action == Action.addMembers || action == Action.removeMembers) { - modelType = ModelType.instanceGroup; - } else { - modelType = modelInfo.getModelType(); - } - - if (modelType.equals(ModelType.vfModule)) { - - - // Get VF Module-specific base module indicator - VfModule vfm = null; - - String modelVersionId = modelInfo.getModelVersionId(); - if (modelVersionId != null) { - vfm = catalogDbClient.getVfModuleByModelUUID(modelVersionId); - } else if (modelInfo.getModelInvariantId() != null && modelInfo.getModelVersion() != null) { - vfm = catalogDbClient.getVfModuleByModelInvariantUUIDAndModelVersion(modelInfo.getModelInvariantId(), - modelInfo.getModelVersion()); - } - - if (vfm != null) { - if (vfm.getIsBase()) { - isBaseVfModule = true; - } - } else if (action == Action.createInstance || action == Action.updateInstance) { - // There is no entry for this vfModuleType with this version, if specified, in VF_MODULE table in - // Catalog DB. - // This request cannot proceed - - String serviceVersionText = ""; - if (sdcServiceModelVersion != null && !sdcServiceModelVersion.isEmpty()) { - serviceVersionText = " with version " + sdcServiceModelVersion; - } + ModelInfo modelInfo = sir.getRequestDetails().getModelInfo(); + ModelType modelType = requestHandlerUtils.getModelType(action, modelInfo); - String errorMessage = "VnfType " + vnfType + " and VF Module Model Name " + modelInfo.getModelName() - + serviceVersionText + " not found in MSO Catalog DB"; - ErrorLoggerInfo errorLoggerInfo = - new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, ErrorCode.DataError) - .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); - VfModuleNotFoundException vfModuleException = new VfModuleNotFoundException.Builder(errorMessage, - HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build(); - requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, vfModuleException.getMessage()); + Boolean isBaseVfModule = false; - throw vfModuleException; - } + if (modelType.equals(ModelType.vfModule)) { + isBaseVfModule = requestHandlerUtils.getIsBaseVfModule(modelInfo, action, vnfType, sdcServiceModelVersion, + currentActiveReq); } - serviceInstanceId = requestHandlerUtils.setServiceInstanceId(requestScope, sir); String vnfId = ""; String vfModuleId = ""; @@ -1030,7 +986,7 @@ public class ServiceInstances { .orElse(""); } - private RecipeLookupResult getServiceInstanceOrchestrationURI(ServiceInstancesRequest sir, Actions action, + protected RecipeLookupResult getServiceInstanceOrchestrationURI(ServiceInstancesRequest sir, Actions action, boolean alaCarteFlag, InfraActiveRequests currentActiveReq) throws ApiException { RecipeLookupResult recipeLookupResult = null; // if the aLaCarte flag is set to TRUE, the API-H should choose the VID_DEFAULT recipe for the requested action 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); + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ResumeOrchestrationRequest/RequestBody.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ResumeOrchestrationRequest/RequestBody.json index 5cd31427a0..7e8ed4dee1 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ResumeOrchestrationRequest/RequestBody.json +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ResumeOrchestrationRequest/RequestBody.json @@ -8,6 +8,12 @@ }, "requestParameters":{ "aLaCarte":"false" - } + }, + "modelInfo":{ + "modelInvariantId": "f7ce78bb-423b-11e7-93f8-0050569a7965", + "modelVersion": "1.0", + "modelType":"service", + "modelName":"serviceModel" + } } }
\ No newline at end of file |