diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks')
7 files changed, 1369 insertions, 1309 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/AaiResourceIdValidator.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/AaiResourceIdValidator.java new file mode 100644 index 0000000000..6d90070b96 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/AaiResourceIdValidator.java @@ -0,0 +1,220 @@ +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +import java.util.Map; +import java.util.Optional; +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.GenericVnfs; +import org.onap.aai.domain.yang.L3Network; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.aai.domain.yang.ServiceInstances; +import org.onap.aai.domain.yang.VolumeGroup; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; +import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; +import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException; +import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException; +import org.onap.so.serviceinstancebeans.RequestDetails; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component +public class AaiResourceIdValidator { + + private static final Logger LOGGER = LoggerFactory.getLogger(AaiResourceIdValidator.class); + + private static final String SERVICE_INSTANCE = "serviceInstance"; + private static final String NAME_EXISTS_WITH_DIFF_VERSION_ID = "(%s) and different version id (%s)"; + private static final String WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI = + "WorkflowAction was unable to verify if the instance name already exist in AAI."; + private static final String NAME_EXISTS_MULTIPLE = + "(%s) and multiple combination of model-version-id + service-type + global-customer-id"; + private static final String NAME_EXISTS_WITH_DIFF_COMBINATION = + "(%s) and global-customer-id (%s), service-type (%s), model-version-id (%s)"; + private static final String NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID = + "(%s), same parent and different customization id (%s)"; + private static final String NAME_EXISTS_WITH_DIFF_PARENT = "(%s) id (%s) and different parent relationship"; + + + private final BBInputSetupUtils bbInputSetupUtils; + + public AaiResourceIdValidator(BBInputSetupUtils bbInputSetupUtils) { + this.bbInputSetupUtils = bbInputSetupUtils; + } + + protected String validateResourceIdInAAI(String generatedResourceId, WorkflowType type, String instanceName, + RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws Exception { + try { + if ("SERVICE".equalsIgnoreCase(type.toString())) { + return validateServiceResourceIdInAAI(generatedResourceId, instanceName, reqDetails); + } else if ("NETWORK".equalsIgnoreCase(type.toString())) { + return validateNetworkResourceIdInAAI(generatedResourceId, instanceName, reqDetails, + workflowResourceIds); + } else if ("VNF".equalsIgnoreCase(type.toString())) { + return validateVnfResourceIdInAAI(generatedResourceId, instanceName, reqDetails, workflowResourceIds); + } else if ("VFMODULE".equalsIgnoreCase(type.toString())) { + return validateVfModuleResourceIdInAAI(generatedResourceId, instanceName, reqDetails, + workflowResourceIds); + } else if ("VOLUMEGROUP".equalsIgnoreCase(type.toString())) { + return validateVolumeGroupResourceIdInAAI(generatedResourceId, instanceName, reqDetails, + workflowResourceIds); + } else if ("CONFIGURATION".equalsIgnoreCase(type.toString())) { + return validateConfigurationResourceIdInAAI(generatedResourceId, instanceName, reqDetails, + workflowResourceIds); + } + return generatedResourceId; + } catch (DuplicateNameException dne) { + throw dne; + } catch (Exception ex) { + LOGGER.error(WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI, ex); + throw new IllegalStateException( + WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI); + } + } + + protected String validateServiceResourceIdInAAI(String generatedResourceId, String instanceName, + RequestDetails reqDetails) throws DuplicateNameException { + String globalCustomerId = reqDetails.getSubscriberInfo().getGlobalSubscriberId(); + String serviceType = reqDetails.getRequestParameters().getSubscriptionServiceType(); + if (instanceName != null) { + Optional<ServiceInstance> serviceInstanceAAI = + bbInputSetupUtils.getAAIServiceInstanceByName(globalCustomerId, serviceType, instanceName); + if (serviceInstanceAAI.isPresent()) { + if (serviceInstanceAAI.get().getModelVersionId() + .equalsIgnoreCase(reqDetails.getModelInfo().getModelVersionId())) { + return serviceInstanceAAI.get().getServiceInstanceId(); + } else { + throw new DuplicateNameException(SERVICE_INSTANCE, String.format(NAME_EXISTS_WITH_DIFF_VERSION_ID, + instanceName, reqDetails.getModelInfo().getModelVersionId())); + } + } else { + ServiceInstances aaiServiceInstances = + bbInputSetupUtils.getAAIServiceInstancesGloballyByName(instanceName); + if (aaiServiceInstances != null) { + if (aaiServiceInstances.getServiceInstance() != null + && !aaiServiceInstances.getServiceInstance().isEmpty()) { + if (aaiServiceInstances.getServiceInstance().size() > 1) { + throw new DuplicateNameException(SERVICE_INSTANCE, + String.format(NAME_EXISTS_MULTIPLE, instanceName)); + } else { + ServiceInstance si = aaiServiceInstances.getServiceInstance().stream().findFirst().get(); + Map<String, String> keys = + bbInputSetupUtils.getURIKeysFromServiceInstance(si.getServiceInstanceId()); + + throw new DuplicateNameException(SERVICE_INSTANCE, String.format( + NAME_EXISTS_WITH_DIFF_COMBINATION, instanceName, + keys.get(AAIFluentTypeBuilder.Types.CUSTOMER.getUriParams().globalCustomerId), + keys.get( + AAIFluentTypeBuilder.Types.SERVICE_SUBSCRIPTION.getUriParams().serviceType), + si.getModelVersionId())); + } + } + } + } + } + return generatedResourceId; + } + + protected String validateNetworkResourceIdInAAI(String generatedResourceId, String instanceName, + RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) + throws DuplicateNameException, MultipleObjectsFoundException { + Optional<L3Network> network = bbInputSetupUtils + .getRelatedNetworkByNameFromServiceInstance(workflowResourceIds.getServiceInstanceId(), instanceName); + if (network.isPresent()) { + if (network.get().getModelCustomizationId() + .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) { + return network.get().getNetworkId(); + } else { + throw new DuplicateNameException("l3Network", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID, + instanceName, network.get().getModelCustomizationId())); + } + } + if (bbInputSetupUtils.existsAAINetworksGloballyByName(instanceName)) { + throw new DuplicateNameException("l3Network", String.format(NAME_EXISTS_WITH_DIFF_PARENT, instanceName, + workflowResourceIds.getServiceInstanceId())); + } + return generatedResourceId; + } + + protected String validateVnfResourceIdInAAI(String generatedResourceId, String instanceName, + RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException { + Optional<GenericVnf> vnf = bbInputSetupUtils + .getRelatedVnfByNameFromServiceInstance(workflowResourceIds.getServiceInstanceId(), instanceName); + if (vnf.isPresent()) { + if (vnf.get().getModelCustomizationId() + .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) { + return vnf.get().getVnfId(); + } else { + throw new DuplicateNameException("generic-vnf", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID, + instanceName, vnf.get().getModelCustomizationId())); + } + } + GenericVnfs vnfs = bbInputSetupUtils.getAAIVnfsGloballyByName(instanceName); + if (vnfs != null) { + throw new DuplicateNameException("generic-vnf", + String.format(NAME_EXISTS_WITH_DIFF_PARENT, instanceName, vnfs.getGenericVnf().get(0).getVnfId())); + } + return generatedResourceId; + } + + protected String validateVfModuleResourceIdInAAI(String generatedResourceId, String instanceName, + RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException { + GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(workflowResourceIds.getVnfId()); + if (vnf != null && vnf.getVfModules() != null) { + for (org.onap.aai.domain.yang.VfModule vfModule : vnf.getVfModules().getVfModule()) { + if (vfModule.getVfModuleName().equalsIgnoreCase(instanceName)) { + if (vfModule.getModelCustomizationId() + .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) { + return vfModule.getVfModuleId(); + } else { + throw new DuplicateNameException("vfModule", + String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID, instanceName, + reqDetails.getModelInfo().getModelCustomizationId())); + } + } + } + } + if (bbInputSetupUtils.existsAAIVfModuleGloballyByName(instanceName)) { + throw new DuplicateNameException("vfModule", instanceName); + } + return generatedResourceId; + } + + protected String validateVolumeGroupResourceIdInAAI(String generatedResourceId, String instanceName, + RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException { + Optional<VolumeGroup> volumeGroup = + bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf(workflowResourceIds.getVnfId(), instanceName); + if (volumeGroup.isPresent()) { + if (volumeGroup.get().getVfModuleModelCustomizationId() + .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) { + return volumeGroup.get().getVolumeGroupId(); + } else { + throw new DuplicateNameException("volumeGroup", volumeGroup.get().getVolumeGroupName()); + } + } + if (bbInputSetupUtils.existsAAIVolumeGroupGloballyByName(instanceName)) { + throw new DuplicateNameException("volumeGroup", instanceName); + } + return generatedResourceId; + } + + protected String validateConfigurationResourceIdInAAI(String generatedResourceId, String instanceName, + RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException { + Optional<org.onap.aai.domain.yang.Configuration> configuration = + bbInputSetupUtils.getRelatedConfigurationByNameFromServiceInstance( + workflowResourceIds.getServiceInstanceId(), instanceName); + if (configuration.isPresent()) { + if (configuration.get().getModelCustomizationId() + .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) { + return configuration.get().getConfigurationId(); + } else { + throw new DuplicateNameException("configuration", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID, + instanceName, configuration.get().getConfigurationId())); + } + } + if (bbInputSetupUtils.existsAAIConfigurationGloballyByName(instanceName)) { + throw new DuplicateNameException("configuration", instanceName); + } + return generatedResourceId; + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversal.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversal.java new file mode 100644 index 0000000000..3556cc024c --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversal.java @@ -0,0 +1,232 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ + * Modifications Copyright (c) 2020 Tech Mahindra + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.db.catalog.beans.CollectionResourceCustomization; +import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization; +import org.onap.so.db.catalog.beans.CvnfcCustomization; +import org.onap.so.db.catalog.beans.VfModuleCustomization; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.serviceinstancebeans.Networks; +import org.onap.so.serviceinstancebeans.Pnfs; +import org.onap.so.serviceinstancebeans.Service; +import org.onap.so.serviceinstancebeans.VfModules; +import org.onap.so.serviceinstancebeans.Vnfs; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CREATE_INSTANCE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.FABRIC_CONFIGURATION; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.USER_PARAM_SERVICE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE; + +@Component +public class UserParamsServiceTraversal { + + private static final Logger logger = LoggerFactory.getLogger(UserParamsServiceTraversal.class); + + private final CatalogDbClient catalogDbClient; + private final ExceptionBuilder exceptionBuilder; + + UserParamsServiceTraversal(CatalogDbClient catalogDbClient, ExceptionBuilder exceptionBuilder) { + this.catalogDbClient = catalogDbClient; + this.exceptionBuilder = exceptionBuilder; + } + + protected List<Resource> getResourceListFromUserParams(DelegateExecution execution, + List<Map<String, Object>> userParams, String serviceModelVersionId, String requestAction) + throws IOException { + List<Resource> resourceList = new ArrayList<>(); + boolean foundVfModuleOrVG = false; + String vnfCustomizationUUID = ""; + String vfModuleCustomizationUUID = ""; + if (userParams != null) { + for (Map<String, Object> params : userParams) { + if (params.containsKey(USER_PARAM_SERVICE)) { + ObjectMapper obj = new ObjectMapper(); + String input = obj.writeValueAsString(params.get(USER_PARAM_SERVICE)); + Service validate = obj.readValue(input, Service.class); + resourceList.add( + new Resource(WorkflowType.SERVICE, validate.getModelInfo().getModelVersionId(), false)); + if (validate.getResources().getVnfs() != null) { + for (Vnfs vnf : validate.getResources().getVnfs()) { + resourceList.add(new Resource(WorkflowType.VNF, + vnf.getModelInfo().getModelCustomizationId(), false)); + if (vnf.getModelInfo() != null && vnf.getModelInfo().getModelCustomizationUuid() != null) { + vnfCustomizationUUID = vnf.getModelInfo().getModelCustomizationUuid(); + } + if (vnf.getVfModules() != null) { + for (VfModules vfModule : vnf.getVfModules()) { + VfModuleCustomization vfModuleCustomization = + catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID( + vfModule.getModelInfo().getModelCustomizationUuid()); + if (vfModuleCustomization != null) { + + if (vfModuleCustomization.getVfModule() != null + && vfModuleCustomization.getVfModule().getVolumeHeatTemplate() != null + && vfModuleCustomization.getVolumeHeatEnv() != null) { + resourceList.add(new Resource(WorkflowType.VOLUMEGROUP, + vfModuleCustomization.getModelCustomizationUUID(), false)); + foundVfModuleOrVG = true; + } + + if ((vfModuleCustomization.getVfModule() != null) + && ((vfModuleCustomization.getVfModule().getModuleHeatTemplate() != null + && vfModuleCustomization.getHeatEnvironment() != null)) + || (vfModuleCustomization.getVfModule().getModelName() != null + && vfModuleCustomization.getVfModule().getModelName() + .contains("helm"))) { + foundVfModuleOrVG = true; + Resource resource = new Resource(WorkflowType.VFMODULE, + vfModuleCustomization.getModelCustomizationUUID(), false); + resource.setBaseVfModule( + vfModuleCustomization.getVfModule().getIsBase() != null + && vfModuleCustomization.getVfModule().getIsBase()); + resourceList.add(resource); + if (vfModule.getModelInfo() != null + && vfModule.getModelInfo().getModelCustomizationUuid() != null) { + vfModuleCustomizationUUID = + vfModule.getModelInfo().getModelCustomizationUuid(); + } + if (!vnfCustomizationUUID.isEmpty() + && !vfModuleCustomizationUUID.isEmpty()) { + List<CvnfcConfigurationCustomization> configs = + traverseCatalogDbForConfiguration( + validate.getModelInfo().getModelVersionId(), + vnfCustomizationUUID, vfModuleCustomizationUUID); + for (CvnfcConfigurationCustomization config : configs) { + Resource configResource = new Resource(WorkflowType.CONFIGURATION, + config.getConfigurationResource().getModelUUID(), false); + resource.setVnfCustomizationId( + vnf.getModelInfo().getModelCustomizationId()); + resource.setVfModuleCustomizationId( + vfModule.getModelInfo().getModelCustomizationId()); + resourceList.add(configResource); + } + } + } + if (!foundVfModuleOrVG) { + buildAndThrowException(execution, + "Could not determine if vfModule was a vfModule or volume group. Heat template and Heat env are null"); + } + } + } + } + } + } + if (validate.getResources().getPnfs() != null) { + for (Pnfs pnf : validate.getResources().getPnfs()) { + resourceList.add(new Resource(WorkflowType.PNF, + pnf.getModelInfo().getModelCustomizationId(), false)); + } + } + if (validate.getResources().getNetworks() != null) { + for (Networks network : validate.getResources().getNetworks()) { + resourceList.add(new Resource(WorkflowType.NETWORK, + network.getModelInfo().getModelCustomizationId(), false)); + } + if (requestAction.equals(CREATE_INSTANCE)) { + String networkColCustId = + queryCatalogDbForNetworkCollection(execution, serviceModelVersionId); + if (networkColCustId != null) { + resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, networkColCustId, false)); + } + } + } + break; + } + } + } + return resourceList; + } + + + private List<CvnfcConfigurationCustomization> traverseCatalogDbForConfiguration(String serviceModelUUID, + String vnfCustomizationUUID, String vfModuleCustomizationUUID) { + List<CvnfcConfigurationCustomization> configurations = new ArrayList<>(); + try { + List<CvnfcCustomization> cvnfcCustomizations = catalogDbClient.getCvnfcCustomization(serviceModelUUID, + vnfCustomizationUUID, vfModuleCustomizationUUID); + for (CvnfcCustomization cvnfc : cvnfcCustomizations) { + for (CvnfcConfigurationCustomization customization : cvnfc.getCvnfcConfigurationCustomization()) { + if (customization.getConfigurationResource().getToscaNodeType().contains(FABRIC_CONFIGURATION)) { + configurations.add(customization); + } + } + } + logger.debug("found {} fabric configuration(s)", configurations.size()); + return configurations; + } catch (Exception ex) { + logger.error("Error in finding configurations", ex); + return configurations; + } + } + + private String queryCatalogDbForNetworkCollection(DelegateExecution execution, String serviceModelVersionId) { + org.onap.so.db.catalog.beans.Service service = catalogDbClient.getServiceByID(serviceModelVersionId); + if (service != null) { + CollectionResourceCustomization networkCollection = this.findCatalogNetworkCollection(execution, service); + if (networkCollection != null) { + return networkCollection.getModelCustomizationUUID(); + } + } + return null; + } + + private CollectionResourceCustomization findCatalogNetworkCollection(DelegateExecution execution, + org.onap.so.db.catalog.beans.Service service) { + CollectionResourceCustomization networkCollection = null; + int count = 0; + for (CollectionResourceCustomization collectionCustom : service.getCollectionResourceCustomizations()) { + if (catalogDbClient.getNetworkCollectionResourceCustomizationByID( + collectionCustom.getModelCustomizationUUID()) != null) { + networkCollection = collectionCustom; + count++; + } + } + if (count == 0) { + return null; + } else if (count > 1) { + buildAndThrowException(execution, + "Found multiple Network Collections in the Service model, only one per Service is supported."); + } + return networkCollection; + } + + private void buildAndThrowException(DelegateExecution execution, String msg) { + logger.error(msg); + execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index 5d95f973bf..662cad542c 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -26,27 +26,13 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.lang3.SerializationUtils; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.javatuples.Pair; -import org.onap.aai.domain.yang.GenericVnf; -import org.onap.aai.domain.yang.GenericVnfs; -import org.onap.aai.domain.yang.L3Network; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.aai.domain.yang.ServiceInstances; import org.onap.aai.domain.yang.Vnfc; import org.onap.aai.domain.yang.VolumeGroup; import org.onap.aai.domain.yang.VpnBinding; @@ -68,16 +54,12 @@ import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; -import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException; -import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.orchestration.AAIConfigurationResources; import org.onap.so.client.orchestration.AAIEntityNotFoundException; import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization; import org.onap.so.db.catalog.beans.CollectionResourceCustomization; import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization; -import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization; -import org.onap.so.db.catalog.beans.CvnfcCustomization; import org.onap.so.db.catalog.beans.InstanceGroup; import org.onap.so.db.catalog.beans.VfModuleCustomization; import org.onap.so.db.catalog.beans.macro.NorthBoundRequest; @@ -86,33 +68,37 @@ import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.serviceinstancebeans.CloudConfiguration; import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.ModelType; -import org.onap.so.serviceinstancebeans.Networks; -import org.onap.so.serviceinstancebeans.Pnfs; import org.onap.so.serviceinstancebeans.RelatedInstance; import org.onap.so.serviceinstancebeans.RelatedInstanceList; import org.onap.so.serviceinstancebeans.RequestDetails; -import org.onap.so.serviceinstancebeans.Service; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; -import org.onap.so.serviceinstancebeans.VfModules; -import org.onap.so.serviceinstancebeans.Vnfs; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CREATE_INSTANCE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.FABRIC_CONFIGURATION; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.USER_PARAM_SERVICE; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE; @Component public class WorkflowAction { - private static final String WORKFLOW_ACTION_ERROR_MESSAGE = "WorkflowActionErrorMessage"; private static final String SERVICE_INSTANCES = "serviceInstances"; - private static final String SERVICE_INSTANCE = "serviceInstance"; private static final String VF_MODULES = "vfModules"; - private static final String WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI = - "WorkflowAction was unable to verify if the instance name already exist in AAI."; private static final String VNF_TYPE = "vnfType"; private static final String SERVICE = "Service"; private static final String VNF = "Vnf"; @@ -123,26 +109,15 @@ public class WorkflowAction { private static final String NETWORKCOLLECTION = "NetworkCollection"; private static final String CONFIGURATION = "Configuration"; private static final String ASSIGNINSTANCE = "assignInstance"; - private static final String CREATEINSTANCE = "createInstance"; private static final String REPLACEINSTANCE = "replaceInstance"; private static final String REPLACEINSTANCERETAINASSIGNMENTS = "replaceInstanceRetainAssignments"; - private static final String USERPARAMSERVICE = "service"; private static final String SUPPORTEDTYPES = "vnfs|vfModules|networks|networkCollections|volumeGroups|serviceInstances|instanceGroups"; private static final String HOMINGSOLUTION = "Homing_Solution"; - private static final String FABRIC_CONFIGURATION = "FabricConfiguration"; private static final String SERVICE_TYPE_TRANSPORT = "TRANSPORT"; private static final String SERVICE_TYPE_BONDING = "BONDING"; private static final String CLOUD_OWNER = "DEFAULT"; private static final Logger logger = LoggerFactory.getLogger(WorkflowAction.class); - private static final String NAME_EXISTS_WITH_DIFF_VERSION_ID = "(%s) and different version id (%s)"; - private static final String NAME_EXISTS_MULTIPLE = - "(%s) and multiple combination of model-version-id + service-type + global-customer-id"; - private static final String NAME_EXISTS_WITH_DIFF_COMBINATION = - "(%s) and global-customer-id (%s), service-type (%s), model-version-id (%s)"; - private static final String NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID = - "(%s), same parent and different customization id (%s)"; - private static final String NAME_EXISTS_WITH_DIFF_PARENT = "(%s) id (%s) and different parent relationship"; private static final String CREATENETWORKBB = "CreateNetworkBB"; private static final String ACTIVATENETWORKBB = "ActivateNetworkBB"; private static final String VOLUMEGROUP_DELETE_PATTERN = "(Un|De)(.*)Volume(.*)"; @@ -167,6 +142,10 @@ public class WorkflowAction { private VrfValidation vrfValidation; @Autowired private Environment environment; + @Autowired + private UserParamsServiceTraversal userParamsServiceTraversal; + @Autowired + private AaiResourceIdValidator aaiResourceIdValidator; public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) { this.bbInputSetupUtils = bbInputSetupUtils; @@ -238,7 +217,7 @@ public class WorkflowAction { requestDetails, requestAction, resourceId, flowsToExecute, vnfType, orchFlows, apiVersion, resourceKey, replaceInfo); } else { - if (isConfiguration(orchFlows) && !requestAction.equalsIgnoreCase(CREATEINSTANCE)) { + if (isConfiguration(orchFlows) && !requestAction.equalsIgnoreCase(CREATE_INSTANCE)) { addConfigBuildingBlocksToFlowsToExecuteList(execution, sIRequest, requestId, workflowResourceIds, requestDetails, requestAction, resourceId, flowsToExecute, vnfType, apiVersion, resourceKey, replaceInfo, orchFlows); @@ -255,36 +234,41 @@ public class WorkflowAction { } } } else { - boolean foundRelated = false; boolean containsService = false; List<Resource> resourceList = new ArrayList<>(); List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>(); + List<Map<String, Object>> userParams = + sIRequest.getRequestDetails().getRequestParameters().getUserParams(); if (resourceType == WorkflowType.SERVICE && requestAction.equalsIgnoreCase(ASSIGNINSTANCE)) { // SERVICE-MACRO-ASSIGN will always get user params with a // service. - if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) { + + if (userParams != null) { containsService = isContainsService(sIRequest); if (containsService) { - traverseUserParamsService(execution, resourceList, sIRequest, requestAction); + resourceList = userParamsServiceTraversal.getResourceListFromUserParams(execution, + userParams, serviceInstanceId, requestAction); } } else { buildAndThrowException(execution, "Service-Macro-Assign request details must contain user params with a service"); } - } else if (resourceType == WorkflowType.SERVICE && requestAction.equalsIgnoreCase(CREATEINSTANCE)) { + } else if (resourceType == WorkflowType.SERVICE + && requestAction.equalsIgnoreCase(CREATE_INSTANCE)) { // SERVICE-MACRO-CREATE will get user params with a service, // a service with a network, a service with a - // networkcollection, OR an empty service. + // network collection, OR an empty service. // If user params is just a service or null and macro // queries the SI and finds a VNF, macro fails. - if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) { + if (userParams != null) { containsService = isContainsService(sIRequest); } if (containsService) { - foundRelated = traverseUserParamsService(execution, resourceList, sIRequest, requestAction); + resourceList = userParamsServiceTraversal.getResourceListFromUserParams(execution, + userParams, serviceInstanceId, requestAction); } - if (!foundRelated) { + if (!foundRelated(resourceList)) { traverseCatalogDbService(execution, sIRequest, resourceList, aaiResourceIds); } } else if (resourceType == WorkflowType.SERVICE @@ -333,15 +317,15 @@ public class WorkflowAction { logger.info("Sorting for Vlan Tagging"); flowsToExecute = sortExecutionPathByObjectForVlanTagging(flowsToExecute, requestAction); } - // By default, enable homing at VNF level for CREATEINSTANCE and ASSIGNINSTANCE + // By default, enable homing at VNF level for CREATE_INSTANCE and ASSIGNINSTANCE if (resourceType == WorkflowType.SERVICE - && (requestAction.equals(CREATEINSTANCE) || requestAction.equals(ASSIGNINSTANCE)) + && (requestAction.equals(CREATE_INSTANCE) || requestAction.equals(ASSIGNINSTANCE)) && resourceList.stream().anyMatch(x -> WorkflowType.VNF.equals(x.getResourceType()))) { execution.setVariable(HOMING, true); execution.setVariable("calledHoming", false); } if (resourceType == WorkflowType.SERVICE && (requestAction.equalsIgnoreCase(ASSIGNINSTANCE) - || requestAction.equalsIgnoreCase(CREATEINSTANCE))) { + || requestAction.equalsIgnoreCase(CREATE_INSTANCE))) { generateResourceIds(flowsToExecute, resourceList, serviceInstanceId); } else { updateResourceIdsFromAAITraversal(flowsToExecute, resourceList, aaiResourceIds, @@ -351,9 +335,8 @@ public class WorkflowAction { } // If the user set "Homing_Solution" to "none", disable homing, else if "Homing_Solution" is specified, // enable it. - if (sIRequest.getRequestDetails().getRequestParameters() != null - && sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) { - List<Map<String, Object>> userParams = getListOfUserParams(sIRequest); + List<Map<String, Object>> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams(); + if (sIRequest.getRequestDetails().getRequestParameters() != null && userParams != null) { for (Map<String, Object> params : userParams) { if (params.containsKey(HOMINGSOLUTION)) { execution.setVariable(HOMING, !"none".equals(params.get(HOMINGSOLUTION))); @@ -400,14 +383,12 @@ public class WorkflowAction { private boolean isContainsService(ServiceInstancesRequest sIRequest) { boolean containsService; - List<Map<String, Object>> userParams = getListOfUserParams(sIRequest); - containsService = userParams.stream().anyMatch(param -> param.containsKey(USERPARAMSERVICE)); + List<Map<String, Object>> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams(); + containsService = userParams.stream().anyMatch(param -> param.containsKey(USER_PARAM_SERVICE)); return containsService; } - private List<Map<String, Object>> getListOfUserParams(ServiceInstancesRequest sIRequest) { - return sIRequest.getRequestDetails().getRequestParameters().getUserParams(); - } + private List<ExecuteBuildingBlock> loadExecuteBuildingBlocks(DelegateExecution execution, String requestId, String errorMessage) { @@ -625,6 +606,18 @@ public class WorkflowAction { return flowsToExecuteConfigs; } + protected void buildAndThrowException(DelegateExecution execution, String msg) { + logger.error(msg); + execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg); + } + + protected void buildAndThrowException(DelegateExecution execution, String msg, Exception ex) { + logger.error(msg, ex); + execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg + ex.getMessage()); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg + ex.getMessage()); + } + protected List<OrchestrationFlow> getVfModuleReplaceBuildingBlocks(ConfigBuildingBlocksDataObject dataObj) throws Exception { @@ -1214,150 +1207,6 @@ public class WorkflowAction { } } - protected boolean traverseUserParamsService(DelegateExecution execution, List<Resource> resourceList, - ServiceInstancesRequest sIRequest, String requestAction) throws IOException { - boolean foundRelated = false; - boolean foundVfModuleOrVG = false; - String vnfCustomizationUUID = ""; - String vfModuleCustomizationUUID = ""; - if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) { - List<Map<String, Object>> userParams = getListOfUserParams(sIRequest); - for (Map<String, Object> params : userParams) { - if (params.containsKey(USERPARAMSERVICE)) { - ObjectMapper obj = new ObjectMapper(); - String input = obj.writeValueAsString(params.get(USERPARAMSERVICE)); - Service validate = obj.readValue(input, Service.class); - resourceList.add( - new Resource(WorkflowType.SERVICE, validate.getModelInfo().getModelVersionId(), false)); - if (validate.getResources().getVnfs() != null) { - for (Vnfs vnf : validate.getResources().getVnfs()) { - resourceList.add(new Resource(WorkflowType.VNF, - vnf.getModelInfo().getModelCustomizationId(), false)); - foundRelated = true; - if (vnf.getModelInfo() != null && vnf.getModelInfo().getModelCustomizationUuid() != null) { - vnfCustomizationUUID = vnf.getModelInfo().getModelCustomizationUuid(); - } - if (vnf.getVfModules() != null) { - for (VfModules vfModule : vnf.getVfModules()) { - VfModuleCustomization vfModuleCustomization = - catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID( - vfModule.getModelInfo().getModelCustomizationUuid()); - if (vfModuleCustomization != null) { - - if (vfModuleCustomization.getVfModule() != null - && vfModuleCustomization.getVfModule().getVolumeHeatTemplate() != null - && vfModuleCustomization.getVolumeHeatEnv() != null) { - resourceList.add(new Resource(WorkflowType.VOLUMEGROUP, - vfModuleCustomization.getModelCustomizationUUID(), false)); - foundVfModuleOrVG = true; - } - - if ((vfModuleCustomization.getVfModule() != null) - && ((vfModuleCustomization.getVfModule().getModuleHeatTemplate() != null - && vfModuleCustomization.getHeatEnvironment() != null)) - || (vfModuleCustomization.getVfModule().getModelName() != null - && vfModuleCustomization.getVfModule().getModelName() - .contains("helm"))) { - foundVfModuleOrVG = true; - Resource resource = new Resource(WorkflowType.VFMODULE, - vfModuleCustomization.getModelCustomizationUUID(), false); - resource.setBaseVfModule( - vfModuleCustomization.getVfModule().getIsBase() != null - && vfModuleCustomization.getVfModule().getIsBase()); - resourceList.add(resource); - if (vfModule.getModelInfo() != null - && vfModule.getModelInfo().getModelCustomizationUuid() != null) { - vfModuleCustomizationUUID = - vfModule.getModelInfo().getModelCustomizationUuid(); - } - if (!vnfCustomizationUUID.isEmpty() - && !vfModuleCustomizationUUID.isEmpty()) { - List<CvnfcConfigurationCustomization> configs = - traverseCatalogDbForConfiguration( - validate.getModelInfo().getModelVersionId(), - vnfCustomizationUUID, vfModuleCustomizationUUID); - for (CvnfcConfigurationCustomization config : configs) { - Resource configResource = new Resource(WorkflowType.CONFIGURATION, - config.getConfigurationResource().getModelUUID(), false); - resource.setVnfCustomizationId( - vnf.getModelInfo().getModelCustomizationId()); - resource.setVfModuleCustomizationId( - vfModule.getModelInfo().getModelCustomizationId()); - resourceList.add(configResource); - } - } - } - if (!foundVfModuleOrVG) { - buildAndThrowException(execution, - "Could not determine if vfModule was a vfModule or volume group. Heat template and Heat env are null"); - } - } - } - } - } - } - if (validate.getResources().getPnfs() != null) { - for (Pnfs pnf : validate.getResources().getPnfs()) { - resourceList.add(new Resource(WorkflowType.PNF, - pnf.getModelInfo().getModelCustomizationId(), false)); - foundRelated = true; - } - } - if (validate.getResources().getNetworks() != null) { - for (Networks network : validate.getResources().getNetworks()) { - resourceList.add(new Resource(WorkflowType.NETWORK, - network.getModelInfo().getModelCustomizationId(), false)); - foundRelated = true; - } - if (requestAction.equals(CREATEINSTANCE)) { - String networkColCustId = queryCatalogDBforNetworkCollection(execution, sIRequest); - if (networkColCustId != null) { - resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, networkColCustId, false)); - foundRelated = true; - } - } - } - break; - } - } - } - return foundRelated; - } - - protected List<CvnfcConfigurationCustomization> traverseCatalogDbForConfiguration(String serviceModelUUID, - String vnfCustomizationUUID, String vfModuleCustomizationUUID) { - List<CvnfcConfigurationCustomization> configurations = new ArrayList<>(); - try { - List<CvnfcCustomization> cvnfcCustomizations = catalogDbClient.getCvnfcCustomization(serviceModelUUID, - vnfCustomizationUUID, vfModuleCustomizationUUID); - for (CvnfcCustomization cvnfc : cvnfcCustomizations) { - for (CvnfcConfigurationCustomization customization : cvnfc.getCvnfcConfigurationCustomization()) { - if (customization.getConfigurationResource().getToscaNodeType().contains(FABRIC_CONFIGURATION)) { - configurations.add(customization); - } - } - } - logger.debug("found {} fabric configuration(s)", configurations.size()); - return configurations; - } catch (Exception ex) { - logger.error("Error in finding configurations", ex); - return configurations; - } - } - - protected String queryCatalogDBforNetworkCollection(DelegateExecution execution, - ServiceInstancesRequest sIRequest) { - org.onap.so.db.catalog.beans.Service service = - catalogDbClient.getServiceByID(sIRequest.getRequestDetails().getModelInfo().getModelVersionId()); - if (service != null) { - CollectionResourceCustomization networkCollection = this.findCatalogNetworkCollection(execution, service); - if (networkCollection != null) { - return networkCollection.getModelCustomizationUUID(); - } - } - return null; - } - protected WorkflowResourceIds populateResourceIdsFromApiHandler(DelegateExecution execution) { return WorkflowResourceIdsUtils.getWorkflowResourceIdsFromExecution(execution); } @@ -1397,36 +1246,6 @@ public class WorkflowAction { } } - protected String validateResourceIdInAAI(String generatedResourceId, WorkflowType type, String instanceName, - RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws Exception { - try { - if ("SERVICE".equalsIgnoreCase(type.toString())) { - return validateServiceResourceIdInAAI(generatedResourceId, instanceName, reqDetails); - } else if ("NETWORK".equalsIgnoreCase(type.toString())) { - return validateNetworkResourceIdInAAI(generatedResourceId, instanceName, reqDetails, - workflowResourceIds); - } else if ("VNF".equalsIgnoreCase(type.toString())) { - return validateVnfResourceIdInAAI(generatedResourceId, instanceName, reqDetails, workflowResourceIds); - } else if ("VFMODULE".equalsIgnoreCase(type.toString())) { - return validateVfModuleResourceIdInAAI(generatedResourceId, instanceName, reqDetails, - workflowResourceIds); - } else if ("VOLUMEGROUP".equalsIgnoreCase(type.toString())) { - return validateVolumeGroupResourceIdInAAI(generatedResourceId, instanceName, reqDetails, - workflowResourceIds); - } else if ("CONFIGURATION".equalsIgnoreCase(type.toString())) { - return validateConfigurationResourceIdInAAI(generatedResourceId, instanceName, reqDetails, - workflowResourceIds); - } - return generatedResourceId; - } catch (DuplicateNameException dne) { - throw dne; - } catch (Exception ex) { - logger.error(WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI, ex); - throw new IllegalStateException( - WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI); - } - } - protected String convertTypeFromPlural(String type) { if (!type.matches(SUPPORTEDTYPES)) { return type; @@ -1442,7 +1261,7 @@ public class WorkflowAction { protected List<ExecuteBuildingBlock> sortExecutionPathByObjectForVlanTagging(List<ExecuteBuildingBlock> orchFlows, String requestAction) { List<ExecuteBuildingBlock> sortedOrchFlows = new ArrayList<>(); - if (requestAction.equals(CREATEINSTANCE)) { + if (requestAction.equals(CREATE_INSTANCE)) { for (ExecuteBuildingBlock ebb : orchFlows) { if (ebb.getBuildingBlock().getBpmnFlowName().equals("AssignNetworkBB")) { String key = ebb.getBuildingBlock().getKey(); @@ -1555,7 +1374,7 @@ public class WorkflowAction { } else if (orchFlow.getFlowName().contains(VFMODULE) || (orchFlow.getFlowName().contains(CONTROLLER) && (VFMODULE).equalsIgnoreCase(orchFlow.getBpmnScope()))) { List<Resource> vfModuleResourcesSorted; - if (requestAction.equals(CREATEINSTANCE) || requestAction.equals(ASSIGNINSTANCE) + if (requestAction.equals(CREATE_INSTANCE) || requestAction.equals(ASSIGNINSTANCE) || requestAction.equals("activateInstance")) { vfModuleResourcesSorted = sortVfModulesByBaseFirst(resourceList.stream() .filter(x -> WorkflowType.VFMODULE == x.getResourceType()).collect(Collectors.toList())); @@ -1686,18 +1505,6 @@ public class WorkflowAction { return listToExecute; } - protected void buildAndThrowException(DelegateExecution execution, String msg, Exception ex) { - logger.error(msg, ex); - execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg + ex.getMessage()); - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg + ex.getMessage()); - } - - protected void buildAndThrowException(DelegateExecution execution, String msg) { - logger.error(msg); - execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg); - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg); - } - public void handleRuntimeException(DelegateExecution execution) { StringBuilder wfeExpMsg = new StringBuilder("Runtime error "); String runtimeErrorMessage; @@ -1724,155 +1531,20 @@ public class WorkflowAction { protected boolean isRequestMacroServiceResume(boolean aLaCarte, WorkflowType resourceType, String requestAction, String serviceInstanceId) { return (!aLaCarte && resourceType == WorkflowType.SERVICE - && (requestAction.equalsIgnoreCase(ASSIGNINSTANCE) || requestAction.equalsIgnoreCase(CREATEINSTANCE)) + && (requestAction.equalsIgnoreCase(ASSIGNINSTANCE) || requestAction.equalsIgnoreCase(CREATE_INSTANCE)) && (serviceInstanceId != null && serviceInstanceId.trim().length() > 1) && (bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId) != null)); } - protected String validateServiceResourceIdInAAI(String generatedResourceId, String instanceName, - RequestDetails reqDetails) throws DuplicateNameException { - String globalCustomerId = reqDetails.getSubscriberInfo().getGlobalSubscriberId(); - String serviceType = reqDetails.getRequestParameters().getSubscriptionServiceType(); - if (instanceName != null) { - Optional<ServiceInstance> serviceInstanceAAI = - bbInputSetupUtils.getAAIServiceInstanceByName(globalCustomerId, serviceType, instanceName); - if (serviceInstanceAAI.isPresent()) { - if (serviceInstanceAAI.get().getModelVersionId() - .equalsIgnoreCase(reqDetails.getModelInfo().getModelVersionId())) { - return serviceInstanceAAI.get().getServiceInstanceId(); - } else { - throw new DuplicateNameException(SERVICE_INSTANCE, String.format(NAME_EXISTS_WITH_DIFF_VERSION_ID, - instanceName, reqDetails.getModelInfo().getModelVersionId())); - } - } else { - ServiceInstances aaiServiceInstances = - bbInputSetupUtils.getAAIServiceInstancesGloballyByName(instanceName); - if (aaiServiceInstances != null) { - if (aaiServiceInstances.getServiceInstance() != null - && !aaiServiceInstances.getServiceInstance().isEmpty()) { - if (aaiServiceInstances.getServiceInstance().size() > 1) { - throw new DuplicateNameException(SERVICE_INSTANCE, - String.format(NAME_EXISTS_MULTIPLE, instanceName)); - } else { - ServiceInstance si = aaiServiceInstances.getServiceInstance().stream().findFirst().get(); - Map<String, String> keys = - bbInputSetupUtils.getURIKeysFromServiceInstance(si.getServiceInstanceId()); - - throw new DuplicateNameException(SERVICE_INSTANCE, String.format( - NAME_EXISTS_WITH_DIFF_COMBINATION, instanceName, - keys.get(AAIFluentTypeBuilder.Types.CUSTOMER.getUriParams().globalCustomerId), - keys.get( - AAIFluentTypeBuilder.Types.SERVICE_SUBSCRIPTION.getUriParams().serviceType), - si.getModelVersionId())); - } - } - } - } - } - return generatedResourceId; - } - - protected String validateNetworkResourceIdInAAI(String generatedResourceId, String instanceName, - RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) - throws DuplicateNameException, MultipleObjectsFoundException { - Optional<L3Network> network = bbInputSetupUtils - .getRelatedNetworkByNameFromServiceInstance(workflowResourceIds.getServiceInstanceId(), instanceName); - if (network.isPresent()) { - if (network.get().getModelCustomizationId() - .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) { - return network.get().getNetworkId(); - } else { - throw new DuplicateNameException("l3Network", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID, - instanceName, network.get().getModelCustomizationId())); - } - } - if (bbInputSetupUtils.existsAAINetworksGloballyByName(instanceName)) { - throw new DuplicateNameException("l3Network", String.format(NAME_EXISTS_WITH_DIFF_PARENT, instanceName, - workflowResourceIds.getServiceInstanceId())); - } - return generatedResourceId; - } - - protected String validateVnfResourceIdInAAI(String generatedResourceId, String instanceName, - RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException { - Optional<GenericVnf> vnf = bbInputSetupUtils - .getRelatedVnfByNameFromServiceInstance(workflowResourceIds.getServiceInstanceId(), instanceName); - if (vnf.isPresent()) { - if (vnf.get().getModelCustomizationId() - .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) { - return vnf.get().getVnfId(); - } else { - throw new DuplicateNameException("generic-vnf", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID, - instanceName, vnf.get().getModelCustomizationId())); - } - } - GenericVnfs vnfs = bbInputSetupUtils.getAAIVnfsGloballyByName(instanceName); - if (vnfs != null) { - throw new DuplicateNameException("generic-vnf", - String.format(NAME_EXISTS_WITH_DIFF_PARENT, instanceName, vnfs.getGenericVnf().get(0).getVnfId())); - } - return generatedResourceId; - } - - protected String validateVfModuleResourceIdInAAI(String generatedResourceId, String instanceName, - RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException { - GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(workflowResourceIds.getVnfId()); - if (vnf != null && vnf.getVfModules() != null) { - for (org.onap.aai.domain.yang.VfModule vfModule : vnf.getVfModules().getVfModule()) { - if (vfModule.getVfModuleName().equalsIgnoreCase(instanceName)) { - if (vfModule.getModelCustomizationId() - .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) { - return vfModule.getVfModuleId(); - } else { - throw new DuplicateNameException("vfModule", - String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID, instanceName, - reqDetails.getModelInfo().getModelCustomizationId())); - } - } - } - } - if (bbInputSetupUtils.existsAAIVfModuleGloballyByName(instanceName)) { - throw new DuplicateNameException("vfModule", instanceName); - } - return generatedResourceId; - } - - protected String validateVolumeGroupResourceIdInAAI(String generatedResourceId, String instanceName, - RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException { - Optional<VolumeGroup> volumeGroup = - bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf(workflowResourceIds.getVnfId(), instanceName); - if (volumeGroup.isPresent()) { - if (volumeGroup.get().getVfModuleModelCustomizationId() - .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) { - return volumeGroup.get().getVolumeGroupId(); - } else { - throw new DuplicateNameException("volumeGroup", volumeGroup.get().getVolumeGroupName()); - } - } - if (bbInputSetupUtils.existsAAIVolumeGroupGloballyByName(instanceName)) { - throw new DuplicateNameException("volumeGroup", instanceName); - } - return generatedResourceId; + protected boolean foundRelated(List<Resource> resourceList) { + return (containsWorkflowType(resourceList, WorkflowType.VNF) + || containsWorkflowType(resourceList, WorkflowType.PNF) + || containsWorkflowType(resourceList, WorkflowType.NETWORK) + || containsWorkflowType(resourceList, WorkflowType.NETWORKCOLLECTION)); } - protected String validateConfigurationResourceIdInAAI(String generatedResourceId, String instanceName, - RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException { - Optional<org.onap.aai.domain.yang.Configuration> configuration = - bbInputSetupUtils.getRelatedConfigurationByNameFromServiceInstance( - workflowResourceIds.getServiceInstanceId(), instanceName); - if (configuration.isPresent()) { - if (configuration.get().getModelCustomizationId() - .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) { - return configuration.get().getConfigurationId(); - } else { - throw new DuplicateNameException("configuration", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID, - instanceName, configuration.get().getConfigurationId())); - } - } - if (bbInputSetupUtils.existsAAIConfigurationGloballyByName(instanceName)) { - throw new DuplicateNameException("configuration", instanceName); - } - return generatedResourceId; + protected boolean containsWorkflowType(List<Resource> resourceList, WorkflowType workflowType) { + return resourceList.stream().anyMatch(resource -> resource.getResourceType().equals(workflowType)); } private void fillExecutionDefault(DelegateExecution execution) { @@ -1904,7 +1576,7 @@ public class WorkflowAction { WorkflowResourceIds workflowResourceIds) throws Exception { if (resource.isGenerated() && requestAction.equalsIgnoreCase("createInstance") && requestDetails.getRequestInfo().getInstanceName() != null) { - return validateResourceIdInAAI(resource.getResourceId(), resource.getResourceType(), + return aaiResourceIdValidator.validateResourceIdInAAI(resource.getResourceId(), resource.getResourceType(), requestDetails.getRequestInfo().getInstanceName(), requestDetails, workflowResourceIds); } else { return resource.getResourceId(); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java new file mode 100644 index 0000000000..bffa2592c1 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ + * Modifications Copyright (c) 2020 Tech Mahindra + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +public final class WorkflowActionConstants { + + static final String USER_PARAM_SERVICE = "service"; + static final String CREATE_INSTANCE = "createInstance"; + static final String FABRIC_CONFIGURATION = "FabricConfiguration"; + static final String WORKFLOW_ACTION_ERROR_MESSAGE = "WorkflowActionErrorMessage"; +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java index e8ce828652..ab83acaec2 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java @@ -24,7 +24,6 @@ package org.onap.so.bpmn; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.common.InjectionHelper; import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetworkBBUtils; @@ -33,8 +32,6 @@ import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.aaiclient.client.aai.AAIResourcesClient; -import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; -import org.onap.aaiclient.client.aai.entities.Relationships; import org.onap.so.client.aai.mapper.AAIObjectMapper; import org.onap.so.client.adapter.network.mapper.NetworkAdapterObjectMapper; import org.onap.so.client.appc.ApplicationControllerAction; @@ -162,5 +159,4 @@ public abstract class BaseTaskTest extends TestDataSetup { @Mock protected NamingRequestObject namingRequestObject; - } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/AaiResourceIdValidatorTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/AaiResourceIdValidatorTest.java new file mode 100644 index 0000000000..ead6c0b4cf --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/AaiResourceIdValidatorTest.java @@ -0,0 +1,765 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +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.junit.MockitoJUnitRunner; +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.GenericVnfs; +import org.onap.aai.domain.yang.L3Network; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.aai.domain.yang.ServiceInstances; +import org.onap.aai.domain.yang.VfModule; +import org.onap.aai.domain.yang.VfModules; +import org.onap.aai.domain.yang.VolumeGroup; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; +import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; +import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.RequestDetails; +import org.onap.so.serviceinstancebeans.RequestParameters; +import org.onap.so.serviceinstancebeans.SubscriberInfo; + +@RunWith(MockitoJUnitRunner.class) +public class AaiResourceIdValidatorTest { + + @Mock + private BBInputSetupUtils bbInputSetupUtilsMock; + + @InjectMocks + private AaiResourceIdValidator testedObject; + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test + public void validateResourceIdInAAIVnfTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setServiceInstanceId("siId123"); + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("id123"); + vnf.setModelCustomizationId("1234567"); + Optional<GenericVnf> opVnf = Optional.of(vnf); + GenericVnf vnf2 = new GenericVnf(); + vnf2.setVnfId("id123"); + vnf2.setModelCustomizationId("222"); + Optional<GenericVnf> opVnf2 = Optional.of(vnf2); + when(bbInputSetupUtilsMock.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName123")).thenReturn(opVnf); + when(bbInputSetupUtilsMock.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName222")).thenReturn(opVnf2); + String id = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "vnfName123", reqDetails, + workflowResourceIds); + assertEquals("id123", id); + String id2 = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "nameTest", reqDetails, + workflowResourceIds); + assertEquals("generatedId123", id2); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "generic-vnf with name (vnfName222), same parent and different customization id (222) already exists. The name must be unique.")); + testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "vnfName222", reqDetails, + workflowResourceIds); + } + + @Test + public void validateResourceIdInAAIVnfNotGloballyUniqueTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + GenericVnfs genericVnfs = new GenericVnfs(); + GenericVnf vnf3 = new GenericVnf(); + vnf3.setVnfId("id123"); + + genericVnfs.getGenericVnf().add(vnf3); + when(bbInputSetupUtilsMock.getAAIVnfsGloballyByName("vnfName333")).thenReturn(genericVnfs); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "generic-vnf with name (vnfName333) id (id123) and different parent relationship already exists. The name must be unique.")); + testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "vnfName333", reqDetails, + new WorkflowResourceIds()); + } + + @Test + public void validateResourceIdInAAINetworkTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setServiceInstanceId("siId123"); + L3Network network = new L3Network(); + network.setNetworkId("id123"); + network.setModelCustomizationId("1234567"); + Optional<L3Network> opNetwork = Optional.of(network); + L3Network network2 = new L3Network(); + network2.setNetworkId("id123"); + network2.setModelCustomizationId("222"); + Optional<L3Network> opNetwork2 = Optional.of(network2); + + when(bbInputSetupUtilsMock.getRelatedNetworkByNameFromServiceInstance("siId123", "name123")) + .thenReturn(opNetwork); + when(bbInputSetupUtilsMock.getRelatedNetworkByNameFromServiceInstance("siId123", "networkName222")) + .thenReturn(opNetwork2); + String id = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "name123", reqDetails, + workflowResourceIds); + assertEquals("id123", id); + String id2 = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "111111", reqDetails, + workflowResourceIds); + assertEquals("generatedId123", id2); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "l3Network with name (networkName222), same parent and different customization id (222) already exists. The name must be unique.")); + testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "networkName222", reqDetails, + workflowResourceIds); + } + + @Test + public void validateNetworkResourceNameExistsInAAITest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setServiceInstanceId("siId123"); + + when(bbInputSetupUtilsMock.existsAAINetworksGloballyByName("networkName333")).thenReturn(true); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "l3Network with name (networkName333) id (siId123) and different parent relationship already exists. The name must be unique.")); + testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "networkName333", reqDetails, + workflowResourceIds); + } + + @Test + public void validateResourceIdInAAIVfModuleTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setVnfId("id123"); + + GenericVnf vnf = new GenericVnf(); + VfModules vfModules = new VfModules(); + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("id123"); + vfModule.setVfModuleName("name123"); + vfModule.setModelCustomizationId("1234567"); + vfModules.getVfModule().add(vfModule); + vnf.setVfModules(vfModules); + + when(bbInputSetupUtilsMock.getAAIGenericVnf("id123")).thenReturn(vnf); + String id = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "name123", reqDetails, + workflowResourceIds); + assertEquals("id123", id); + + GenericVnf vnf1 = new GenericVnf(); + VfModules vfModules2 = new VfModules(); + VfModule vfModule2 = new VfModule(); + vfModule2.setVfModuleName("vFModName222"); + vfModule2.setModelCustomizationId("222"); + vfModules2.getVfModule().add(vfModule2); + vnf1.setVfModules(vfModules2); + workflowResourceIds.setVnfId("id111"); + when(bbInputSetupUtilsMock.getAAIGenericVnf("id111")).thenReturn(vnf1); + String id2 = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "111111", reqDetails, + workflowResourceIds); + assertEquals("generatedId123", id2); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "vfModule with name (vFModName222), same parent and different customization id (1234567) already exists. The name must be unique.")); + testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "vFModName222", reqDetails, + workflowResourceIds); + } + + @Test + public void validateResourceIdInAAIVfModuleNotGloballyUniqueTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + + when(bbInputSetupUtilsMock.existsAAIVfModuleGloballyByName("vFModName333")).thenReturn(true); + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage( + containsString("vfModule with name vFModName333 already exists. The name must be unique.")); + testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "vFModName333", reqDetails, + new WorkflowResourceIds()); + } + + @Test + public void validateResourceIdInAAIVolumeGroupTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setVnfId("id123"); + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setVolumeGroupId("id123"); + volumeGroup.setVolumeGroupName("name123"); + volumeGroup.setVfModuleModelCustomizationId("1234567"); + Optional<VolumeGroup> opVolumeGroup = Optional.of(volumeGroup); + + when(bbInputSetupUtilsMock.getRelatedVolumeGroupByNameFromVnf("id123", "name123")).thenReturn(opVolumeGroup); + String id = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "name123", + reqDetails, workflowResourceIds); + assertEquals("id123", id); + + String id2 = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "111111", + reqDetails, workflowResourceIds); + assertEquals("generatedId123", id2); + } + + + @Test + public void validateSourceIdInAAIVolumeGroupNotGloballyUniqueTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + when(bbInputSetupUtilsMock.existsAAIVolumeGroupGloballyByName("testVolumeGroup")).thenReturn(true); + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage( + containsString("volumeGroup with name testVolumeGroup already exists. The name must be unique.")); + testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "testVolumeGroup", reqDetails, + new WorkflowResourceIds()); + } + + @Test + public void validateResourceIdInAAIConfigurationTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setServiceInstanceId("siId123"); + + org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration(); + configuration.setConfigurationId("id123"); + configuration.setModelCustomizationId("1234567"); + Optional<org.onap.aai.domain.yang.Configuration> opConfiguration = Optional.of(configuration); + + org.onap.aai.domain.yang.Configuration configuration2 = new org.onap.aai.domain.yang.Configuration(); + configuration2.setConfigurationId("id123"); + configuration2.setModelCustomizationId("222"); + Optional<org.onap.aai.domain.yang.Configuration> opConfiguration2 = Optional.of(configuration2); + + when(bbInputSetupUtilsMock.getRelatedConfigurationByNameFromServiceInstance("siId123", "name123")) + .thenReturn(opConfiguration); + String id = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.CONFIGURATION, "name123", + reqDetails, workflowResourceIds); + assertEquals("id123", id); + + String id2 = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.CONFIGURATION, "111111", + reqDetails, workflowResourceIds); + assertEquals("generatedId123", id2); + + when(bbInputSetupUtilsMock.getRelatedConfigurationByNameFromServiceInstance("siId123", "name222")) + .thenReturn(opConfiguration2); + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "configuration with name (name222), same parent and different customization id (id123) already exists. The name must be unique.")); + testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.CONFIGURATION, "name222", reqDetails, + workflowResourceIds); + } + + @Test + public void validateResourceIdInAAIConfigurationNotGloballyUniqueTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + when(bbInputSetupUtilsMock.existsAAIConfigurationGloballyByName("testConfig")).thenReturn(true); + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage( + containsString("configuration with name testConfig already exists. The name must be unique.")); + testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.CONFIGURATION, "testConfig", reqDetails, + new WorkflowResourceIds()); + } + + @Test + public void validateResourceIdInAAISITest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + reqDetails.getModelInfo().setModelVersionId("1234567"); + + ServiceInstance si = new ServiceInstance(); + si.setServiceInstanceId("siId123"); + si.setModelVersionId("1234567"); + ServiceInstances serviceInstances = new ServiceInstances(); + serviceInstances.getServiceInstance().add(si); + Optional<ServiceInstance> siOp = Optional.of(si); + ServiceInstance si2 = new ServiceInstance(); + si2.setServiceInstanceId("siId222"); + si2.setModelVersionId("22222"); + si2.setServiceInstanceName("siName222"); + Optional<ServiceInstance> siOp2 = Optional.of(si2); + ServiceInstances serviceInstances2 = new ServiceInstances(); + serviceInstances2.getServiceInstance().add(si2); + + when(bbInputSetupUtilsMock.getAAIServiceInstanceByName("id123", "subServiceType123", "siName123")) + .thenReturn(siOp); + when(bbInputSetupUtilsMock.getAAIServiceInstanceByName("id123", "subServiceType123", "siName222")) + .thenReturn(siOp2); + String id = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName123", + reqDetails, new WorkflowResourceIds()); + assertEquals("siId123", id); + String id2 = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "111111", reqDetails, + new WorkflowResourceIds()); + assertEquals("generatedId123", id2); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "serviceInstance with name (siName222) and different version id (1234567) already exists. The name must be unique.")); + testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName222", reqDetails, + new WorkflowResourceIds()); + } + + @Test + public void validateResourceIdInAAIMultipleSITest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + reqDetails.getModelInfo().setModelVersionId("1234567"); + ServiceInstance si = new ServiceInstance(); + ServiceInstances serviceInstances = new ServiceInstances(); + serviceInstances.getServiceInstance().add(si); + ServiceInstance si2 = new ServiceInstance(); + serviceInstances.getServiceInstance().add(si2); + when(bbInputSetupUtilsMock.getAAIServiceInstancesGloballyByName("siName123")).thenReturn(serviceInstances); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "serviceInstance with name (siName123) and multiple combination of model-version-id + service-type + global-customer-id already exists. The name must be unique.")); + testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName123", reqDetails, + new WorkflowResourceIds()); + } + + @Test + public void validateResourceIdInAAISIExistsTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + reqDetails.getModelInfo().setModelVersionId("1234567"); + + ServiceInstance si = new ServiceInstance(); + si.setServiceInstanceId("siId123"); + si.setModelVersionId("1234567"); + ServiceInstances serviceInstances = new ServiceInstances(); + serviceInstances.getServiceInstance().add(si); + + Map<String, String> uriKeys = new HashMap<>(); + uriKeys.put(AAIFluentTypeBuilder.Types.CUSTOMER.getUriParams().globalCustomerId, "globalCustomerId"); + uriKeys.put(AAIFluentTypeBuilder.Types.SERVICE_SUBSCRIPTION.getUriParams().serviceType, "serviceType"); + + when(bbInputSetupUtilsMock.getAAIServiceInstancesGloballyByName("siName123")).thenReturn(serviceInstances); + when(bbInputSetupUtilsMock.getURIKeysFromServiceInstance("siId123")).thenReturn(uriKeys); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "serviceInstance with name (siName123) and global-customer-id (globalCustomerId), service-type (serviceType), model-version-id (1234567) already exists. The name must be unique.")); + testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName123", reqDetails, + new WorkflowResourceIds()); + } + + @Test + public void validateServiceResourceIdInAAINoDupTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + String id = testedObject.validateServiceResourceIdInAAI("generatedId123", "siName123", reqDetails); + assertEquals("generatedId123", id); + } + + @Test + public void validateServiceResourceIdInAAISameModelVersionId() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + reqDetails.getModelInfo().setModelVersionId("1234567"); + + ServiceInstance si = new ServiceInstance(); + si.setServiceInstanceId("siId123"); + si.setModelVersionId("1234567"); + Optional<ServiceInstance> siOp = Optional.of(si); + + when(bbInputSetupUtilsMock.getAAIServiceInstanceByName("id123", "subServiceType123", "siName123")) + .thenReturn(siOp); + String id = testedObject.validateServiceResourceIdInAAI("generatedId123", "siName123", reqDetails); + assertEquals("siId123", id); + } + + @Test + public void validateServiceResourceIdInAAIDifferentModelVersionId() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + reqDetails.getModelInfo().setModelVersionId("1234567"); + + ServiceInstance si = new ServiceInstance(); + si.setModelVersionId("9999999"); + ServiceInstances serviceInstances = new ServiceInstances(); + serviceInstances.getServiceInstance().add(si); + Optional<ServiceInstance> siOp = Optional.of(si); + + when(bbInputSetupUtilsMock.getAAIServiceInstanceByName("id123", "subServiceType123", "siName123")) + .thenReturn(siOp); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "serviceInstance with name (siName123) and different version id (1234567) already exists. The name must be unique.")); + + String id = testedObject.validateServiceResourceIdInAAI("generatedId123", "siName123", reqDetails); + assertEquals("siId123", id); + } + + @Test + public void validateServiceResourceIdInAAIDuplicateNameTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + ServiceInstance si = new ServiceInstance(); + si.setModelVersionId("1234567"); + ServiceInstances serviceInstances = new ServiceInstances(); + serviceInstances.getServiceInstance().add(si); + + when(bbInputSetupUtilsMock.getAAIServiceInstancesGloballyByName("siName")).thenReturn(serviceInstances); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "serviceInstance with name (siName) and global-customer-id (null), service-type (null), model-version-id (1234567) already exists. The name must be unique.")); + + testedObject.validateServiceResourceIdInAAI("generatedId123", "siName", reqDetails); + } + + @Test + public void validateServiceResourceIdInAAIDuplicateNameMultipleTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + ServiceInstances serviceInstances = new ServiceInstances(); + serviceInstances.getServiceInstance().add(new ServiceInstance()); + serviceInstances.getServiceInstance().add(new ServiceInstance()); + + when(bbInputSetupUtilsMock.getAAIServiceInstancesGloballyByName("siName")).thenReturn(serviceInstances); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "serviceInstance with name (siName) and multiple combination of model-version-id + service-type + global-customer-id already exists. The name must be unique.")); + + testedObject.validateServiceResourceIdInAAI("generatedId123", "siName", reqDetails); + } + + @Test + public void validateNetworkResourceIdInAAITest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + String id = testedObject.validateNetworkResourceIdInAAI("generatedId123", "name123", reqDetails, + new WorkflowResourceIds()); + assertEquals("generatedId123", id); + } + + @Test + public void validateNetworkResourceIdInAAISameModelCustIdTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setServiceInstanceId("siId123"); + L3Network network = new L3Network(); + network.setNetworkId("id123"); + network.setModelCustomizationId("1234567"); + Optional<L3Network> opNetwork = Optional.of(network); + + when(bbInputSetupUtilsMock.getRelatedNetworkByNameFromServiceInstance("siId123", "name123")) + .thenReturn(opNetwork); + + String id = testedObject.validateNetworkResourceIdInAAI("generatedId123", "name123", reqDetails, + workflowResourceIds); + assertEquals("id123", id); + } + + @Test + public void validateNetworkResourceIdInAAIDuplicateNameTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setServiceInstanceId("siId123"); + L3Network network = new L3Network(); + network.setModelCustomizationId("9999999"); + Optional<L3Network> opNetwork = Optional.of(network); + + when(bbInputSetupUtilsMock.getRelatedNetworkByNameFromServiceInstance("siId123", "name123")) + .thenReturn(opNetwork); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "l3Network with name (name123), same parent and different customization id (9999999) already exists. The name must be unique.")); + + testedObject.validateNetworkResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds); + } + + @Test + public void validateNetworkResourceIdInAAINotGloballyUniqueTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setServiceInstanceId("siId123"); + + when(bbInputSetupUtilsMock.existsAAINetworksGloballyByName("name123")).thenReturn(true); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "l3Network with name (name123) id (siId123) and different parent relationship already exists. The name must be unique.")); + + testedObject.validateNetworkResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds); + } + + @Test + public void validateVnfResourceIdInAAITest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + String id = testedObject.validateVnfResourceIdInAAI("generatedId123", "vnfName123", reqDetails, + new WorkflowResourceIds()); + assertEquals("generatedId123", id); + } + + @Test + public void validateVnfResourceIdInAAISameModelCustomizationIdTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setServiceInstanceId("siId123"); + + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("id123"); + vnf.setModelCustomizationId("1234567"); + Optional<GenericVnf> opVnf = Optional.of(vnf); + + when(bbInputSetupUtilsMock.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName123")).thenReturn(opVnf); + String id = testedObject.validateVnfResourceIdInAAI("generatedId123", "vnfName123", reqDetails, + workflowResourceIds); + assertEquals("id123", id); + } + + @Test + public void validateVnfResourceIdInAAIDiffModelCustomizationIdTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setServiceInstanceId("siId123"); + GenericVnf vnf = new GenericVnf(); + vnf.setModelCustomizationId("9999999"); + Optional<GenericVnf> opVnf = Optional.of(vnf); + + when(bbInputSetupUtilsMock.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName123")).thenReturn(opVnf); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "generic-vnf with name (vnfName123), same parent and different customization id (9999999) already exists. The name must be unique.")); + + testedObject.validateVnfResourceIdInAAI("generatedId123", "vnfName123", reqDetails, workflowResourceIds); + } + + @Test + public void validateVnfResourceIdInAAINotGloballyUniqueTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("id123"); + GenericVnfs genericVnfs = new GenericVnfs(); + genericVnfs.getGenericVnf().add(vnf); + + when(bbInputSetupUtilsMock.getAAIVnfsGloballyByName("vnfName123")).thenReturn(genericVnfs); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "generic-vnf with name (vnfName123) id (id123) and different parent relationship already exists. The name must be unique.")); + + testedObject.validateVnfResourceIdInAAI("generatedId123", "vnfName123", reqDetails, new WorkflowResourceIds()); + } + + @Test + public void validateVfModuleResourceIdTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + String id = testedObject.validateVfModuleResourceIdInAAI("generatedId123", "name123", reqDetails, + new WorkflowResourceIds()); + assertEquals("generatedId123", id); + } + + @Test + public void validateVfModuleResourceIdSameModelCustIdTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setVnfId("vnfId123"); + VfModules vfModules = new VfModules(); + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("id123"); + vfModule.setVfModuleName("name123"); + vfModule.setModelCustomizationId("1234567"); + vfModules.getVfModule().add(vfModule); + GenericVnf vnf = new GenericVnf(); + vnf.setVfModules(vfModules); + + when(bbInputSetupUtilsMock.getAAIGenericVnf("vnfId123")).thenReturn(vnf); + + String id = testedObject.validateVfModuleResourceIdInAAI("generatedId123", "name123", reqDetails, + workflowResourceIds); + assertEquals("id123", id); + } + + @Test + public void validateVfModuleResourceIdDifferentModelCustIdTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setVnfId("vnfId123"); + VfModules vfModules = new VfModules(); + VfModule vfModule = new VfModule(); + vfModule.setVfModuleName("name123"); + vfModule.setModelCustomizationId("9999999"); + vfModules.getVfModule().add(vfModule); + GenericVnf vnf = new GenericVnf(); + vnf.setVfModules(vfModules); + + when(bbInputSetupUtilsMock.getAAIGenericVnf("vnfId123")).thenReturn(vnf); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "vfModule with name (name123), same parent and different customization id (1234567) already exists. The name must be unique.")); + + testedObject.validateVfModuleResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds); + } + + @Test + public void validateVfModuleResourceIdNotGloballyUniqueTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + when(bbInputSetupUtilsMock.existsAAIVfModuleGloballyByName("name123")).thenReturn(true); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException + .expectMessage(containsString("vfModule with name name123 already exists. The name must be unique.")); + + testedObject.validateVfModuleResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds); + } + + @Test + public void validateVolumeGroupResourceIdInAAITest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + String id = testedObject.validateVolumeGroupResourceIdInAAI("generatedId123", "name123", reqDetails, + new WorkflowResourceIds()); + assertEquals("generatedId123", id); + } + + @Test + public void validateVolumeGroupResourceIdInAAISameModelCustIdTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setVnfId("vnfId123"); + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setVolumeGroupId("id123"); + volumeGroup.setVfModuleModelCustomizationId("1234567"); + Optional<VolumeGroup> opVolumeGroup = Optional.of(volumeGroup); + + when(bbInputSetupUtilsMock.getRelatedVolumeGroupByNameFromVnf("vnfId123", "name123")).thenReturn(opVolumeGroup); + String id = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "name123", + reqDetails, workflowResourceIds); + + assertEquals("id123", id); + } + + @Test + public void validateVolumeGroupResourceIdInAAIDifferentModelCustIdTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setVnfId("vnfId123"); + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setVolumeGroupName("name123"); + volumeGroup.setVfModuleModelCustomizationId("9999999"); + Optional<VolumeGroup> opVolumeGroup = Optional.of(volumeGroup); + + when(bbInputSetupUtilsMock.getRelatedVolumeGroupByNameFromVnf("vnfId123", "name123")).thenReturn(opVolumeGroup); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage( + containsString("volumeGroup with name name123 already exists. The name must be unique.")); + + testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "name123", reqDetails, + workflowResourceIds); + } + + @Test + public void validateVolumeGroupResourceIdInAAINotGloballyUniqueTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + when(bbInputSetupUtilsMock.existsAAIVolumeGroupGloballyByName("name123")).thenReturn(true); + + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage( + containsString("volumeGroup with name name123 already exists. The name must be unique.")); + + testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "name123", reqDetails, + workflowResourceIds); + } + + @Test + public void validateConfigurationResourceIdInAAITest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + String id = testedObject.validateConfigurationResourceIdInAAI("generatedId123", "name123", reqDetails, + new WorkflowResourceIds()); + assertEquals("generatedId123", id); + } + + @Test + public void validateConfigurationResourceIdInAAISameModelCustIdTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setServiceInstanceId("siId123"); + org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration(); + configuration.setConfigurationId("id123"); + configuration.setModelCustomizationId("1234567"); + Optional<org.onap.aai.domain.yang.Configuration> opConfiguration = Optional.of(configuration); + + when(bbInputSetupUtilsMock.getRelatedConfigurationByNameFromServiceInstance("siId123", "name123")) + .thenReturn(opConfiguration); + + String id = testedObject.validateConfigurationResourceIdInAAI("generatedId123", "name123", reqDetails, + workflowResourceIds); + assertEquals("id123", id); + } + + @Test + public void validateConfigurationResourceIdInAAIDifferentModelCustIdTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setServiceInstanceId("siId123"); + org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration(); + configuration.setConfigurationId("id123"); + configuration.setModelCustomizationId("9999999"); + Optional<org.onap.aai.domain.yang.Configuration> opConfiguration = Optional.of(configuration); + + when(bbInputSetupUtilsMock.getRelatedConfigurationByNameFromServiceInstance("siId123", "name123")) + .thenReturn(opConfiguration); + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage(containsString( + "configuration with name (name123), same parent and different customization id (id123) already exists. The name must be unique.")); + + testedObject.validateConfigurationResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds); + } + + @Test + public void validateConfigurationResourceIdInAAINotGloballyUniqueTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + + when(bbInputSetupUtilsMock.existsAAIConfigurationGloballyByName("name123")).thenReturn(true); + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage( + containsString("configuration with name name123 already exists. The name must be unique.")); + + testedObject.validateConfigurationResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds); + } + + private RequestDetails setupRequestDetails() { + RequestDetails reqDetails = new RequestDetails(); + SubscriberInfo subInfo = new SubscriberInfo(); + subInfo.setGlobalSubscriberId("id123"); + reqDetails.setSubscriberInfo(subInfo); + RequestParameters reqParams = new RequestParameters(); + reqParams.setSubscriptionServiceType("subServiceType123"); + reqDetails.setRequestParameters(reqParams); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelCustomizationId("1234567"); + reqDetails.setModelInfo(modelInfo); + return reqDetails; + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index 7f22c5138e..5f9356d066 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -35,6 +35,7 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyObject; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -50,9 +51,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.UUID; import org.camunda.bpm.engine.delegate.BpmnError; @@ -67,15 +66,10 @@ import org.junit.rules.ExpectedException; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; -import org.onap.aai.domain.yang.GenericVnf; -import org.onap.aai.domain.yang.GenericVnfs; -import org.onap.aai.domain.yang.L3Network; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipList; import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.aai.domain.yang.ServiceInstances; import org.onap.aai.domain.yang.VfModule; -import org.onap.aai.domain.yang.VfModules; import org.onap.aai.domain.yang.VolumeGroup; import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; import org.onap.aaiclient.client.aai.entities.Relationships; @@ -107,11 +101,8 @@ import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.VfModuleCustomization; import org.onap.so.db.catalog.beans.macro.NorthBoundRequest; import org.onap.so.db.catalog.beans.macro.OrchestrationFlow; -import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.RequestDetails; -import org.onap.so.serviceinstancebeans.RequestParameters; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; -import org.onap.so.serviceinstancebeans.SubscriberInfo; import org.springframework.core.env.Environment; public class WorkflowActionTest extends BaseTaskTest { @@ -127,8 +118,13 @@ public class WorkflowActionTest extends BaseTaskTest { @Mock protected Environment environment; + @Mock + protected UserParamsServiceTraversal userParamsServiceTraversal; + @Mock + private AaiResourceIdValidator aaiResourceIdValidator; @InjectMocks protected WorkflowAction workflowAction; + private DelegateExecution execution; @InjectMocks @@ -237,7 +233,7 @@ public class WorkflowActionTest extends BaseTaskTest { doThrow(new DuplicateNameException( "serviceInstance with name (instanceName) and different version id (3c40d244-808e-42ca-b09a-256d83d19d0a) already exists. The name must be unique.")) - .when(SPY_workflowAction).validateResourceIdInAAI(anyString(), eq(WorkflowType.SERVICE), + .when(aaiResourceIdValidator).validateResourceIdInAAI(anyString(), eq(WorkflowType.SERVICE), eq("test"), any(RequestDetails.class), any(WorkflowResourceIds.class)); SPY_workflowAction.selectExecutionList(execution); @@ -286,6 +282,8 @@ public class WorkflowActionTest extends BaseTaskTest { VfModuleCustomization vfModuleCustomization3 = vfModuleCustomization2; vfModuleCustomization3.setModelCustomizationUUID("72d9d1cd-f46d-447a-abdb-451d6fb05fa8"); + when(userParamsServiceTraversal.getResourceListFromUserParams(any(), anyList(), anyString(), anyString())) + .thenReturn(prepareListWithResources()); when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, false, "my-custom-cloud-owner")).thenReturn(northBoundRequest); when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f")) @@ -334,6 +332,8 @@ public class WorkflowActionTest extends BaseTaskTest { VfModuleCustomization vfModuleCustomization3 = vfModuleCustomization2; vfModuleCustomization3.setModelCustomizationUUID("72d9d1cd-f46d-447a-abdb-451d6fb05fa8"); + when(userParamsServiceTraversal.getResourceListFromUserParams(any(), anyList(), anyString(), anyString())) + .thenReturn(prepareListWithResources()); when(environment.getProperty("org.onap.so.cloud-owner")).thenReturn("att-aic"); when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, false, "att-aic")).thenReturn(northBoundRequest); @@ -606,6 +606,8 @@ public class WorkflowActionTest extends BaseTaskTest { VfModuleCustomization vfModuleCustomization3 = vfModuleCustomization2; vfModuleCustomization3.setModelCustomizationUUID("72d9d1cd-f46d-447a-abdb-451d6fb05fa8"); + when(userParamsServiceTraversal.getResourceListFromUserParams(any(), anyList(), anyString(), anyString())) + .thenReturn(prepareListWithResources()); when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, false, "my-custom-cloud-owner")).thenReturn(northBoundRequest); when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f")) @@ -622,6 +624,7 @@ public class WorkflowActionTest extends BaseTaskTest { "ActivateVolumeGroupBB", "CreateVfModuleBB", "CreateVfModuleBB", "CreateVfModuleBB", "ActivateVfModuleBB", "ActivateVfModuleBB", "ActivateVfModuleBB", "ActivateVnfBB", "ActivateServiceInstanceBB"); + assertEquals(3, ebbs.get(0).getWorkflowResourceIds().getServiceInstanceId().length()); int randomUUIDLength = UUID.randomUUID().toString().length(); assertEquals(randomUUIDLength, ebbs.get(1).getWorkflowResourceIds().getVnfId().length()); @@ -2010,906 +2013,6 @@ public class WorkflowActionTest extends BaseTaskTest { assertNull(x.getVolumeGroupId()); } - private RequestDetails setupRequestDetails(String globalSubscriberId, String subscriptionServiceType, - String modelCustomizationId) { - RequestDetails reqDetails = new RequestDetails(); - SubscriberInfo subInfo = new SubscriberInfo(); - subInfo.setGlobalSubscriberId(globalSubscriberId); - reqDetails.setSubscriberInfo(subInfo); - RequestParameters reqParams = new RequestParameters(); - reqParams.setSubscriptionServiceType(subscriptionServiceType); - reqDetails.setRequestParameters(reqParams); - ModelInfo modelInfo = new ModelInfo(); - modelInfo.setModelCustomizationId(modelCustomizationId); - reqDetails.setModelInfo(modelInfo); - return reqDetails; - } - - @Test - public void validateResourceIdInAAIVnfTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - // Vnf - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("id123"); - vnf.setVnfName("vnfName123"); - vnf.setModelCustomizationId("1234567"); - Optional<GenericVnf> opVnf = Optional.of(vnf); - GenericVnf vnf2 = new GenericVnf(); - vnf2.setVnfId("id123"); - vnf2.setVnfName("vnfName222"); - vnf2.setModelCustomizationId("222"); - Optional<GenericVnf> opVnf2 = Optional.of(vnf2); - when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName123")).thenReturn(opVnf); - when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName222")).thenReturn(opVnf2); - when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123", "111111")).thenReturn(Optional.empty()); - String id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "vnfName123", reqDetails, - workflowResourceIds); - assertEquals("id123", id); - String id2 = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "111111", reqDetails, - workflowResourceIds); - assertEquals("generatedId123", id2); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "generic-vnf with name (vnfName222), same parent and different customization id (222) already exists. The name must be unique.")); - workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "vnfName222", reqDetails, - workflowResourceIds); - } - - @Test - public void validateResourceIdInAAIVnfNotGloballyUniqueTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - // Vnf - GenericVnfs genericVnfs = new GenericVnfs(); - GenericVnf vnf3 = new GenericVnf(); - vnf3.setVnfId("id123"); - vnf3.setVnfName("vnfName333"); - genericVnfs.getGenericVnf().add(vnf3); - when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName333")).thenReturn(Optional.empty()); - when(bbSetupUtils.getAAIVnfsGloballyByName("vnfName333")).thenReturn(genericVnfs); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "generic-vnf with name (vnfName333) id (id123) and different parent relationship already exists. The name must be unique.")); - workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "vnfName333", reqDetails, - workflowResourceIds); - } - - @Test - public void validateResourceIdInAAINetworkTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - // Network - L3Network network = new L3Network(); - network.setNetworkId("id123"); - network.setNetworkName("name123"); - network.setModelCustomizationId("1234567"); - workflowResourceIds.setServiceInstanceId("siId123"); - Optional<L3Network> opNetwork = Optional.of(network); - L3Network network2 = new L3Network(); - network2.setNetworkId("id123"); - network2.setNetworkName("networkName222"); - network2.setModelCustomizationId("222"); - Optional<L3Network> opNetwork2 = Optional.of(network2); - when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("siId123", "name123")).thenReturn(opNetwork); - when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("siId123", "networkName222")) - .thenReturn(opNetwork2); - when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("siId123", "111111")).thenReturn(Optional.empty()); - String id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "name123", - reqDetails, workflowResourceIds); - assertEquals("id123", id); - String id2 = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "111111", - reqDetails, workflowResourceIds); - assertEquals("generatedId123", id2); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "l3Network with name (networkName222), same parent and different customization id (222) already exists. The name must be unique.")); - workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "networkName222", reqDetails, - workflowResourceIds); - } - - @Test - public void validateNetworkResourceNameExistsInAAITest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - // Network - L3Network network = new L3Network(); - network.setNetworkId("id123"); - network.setNetworkName("name123"); - network.setModelCustomizationId("1234567"); - workflowResourceIds.setServiceInstanceId("siId123"); - - when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("networkName333", "111111")) - .thenReturn(Optional.empty()); - when(bbSetupUtils.existsAAINetworksGloballyByName("networkName333")).thenReturn(true); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "l3Network with name (networkName333) id (siId123) and different parent relationship already exists. The name must be unique.")); - workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "networkName333", reqDetails, - workflowResourceIds); - } - - @Test - public void validateResourceIdInAAIVfModuleTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("id123"); - vnf.setVnfName("vnfName123"); - vnf.setModelCustomizationId("222"); - - // VfModule - VfModules vfModules = new VfModules(); - VfModule vfModule = new VfModule(); - vfModule.setVfModuleId("id123"); - vfModule.setVfModuleName("name123"); - vfModule.setModelCustomizationId("1234567"); - vfModules.getVfModule().add(vfModule); - vnf.setVfModules(vfModules); - workflowResourceIds.setVnfId("id123"); - when(bbSetupUtils.getAAIGenericVnf("id123")).thenReturn(vnf); - String id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "name123", - reqDetails, workflowResourceIds); - assertEquals("id123", id); - - GenericVnf vnf1 = new GenericVnf(); - VfModules vfModules2 = new VfModules(); - VfModule vfModule2 = new VfModule(); - vfModule2.setVfModuleId("id123"); - vfModule2.setVfModuleName("vFModName222"); - vfModule2.setModelCustomizationId("222"); - vfModules2.getVfModule().add(vfModule2); - vnf1.setVfModules(vfModules2); - workflowResourceIds.setVnfId("id111"); - when(bbSetupUtils.getAAIGenericVnf("id111")).thenReturn(vnf1); - String id2 = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "111111", - reqDetails, workflowResourceIds); - assertEquals("generatedId123", id2); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "vfModule with name (vFModName222), same parent and different customization id (1234567) already exists. The name must be unique.")); - workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "vFModName222", reqDetails, - workflowResourceIds); - } - - @Test - public void validateResourceIdInAAIVfModuleNotGloballyUniqueTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setVnfId("id111"); - - GenericVnf vnf1 = new GenericVnf(); - workflowResourceIds.setVnfId("id111"); - when(bbSetupUtils.getAAIGenericVnf("id111")).thenReturn(vnf1); - - when(bbSetupUtils.existsAAIVfModuleGloballyByName("vFModName333")).thenReturn(true); - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage( - containsString("vfModule with name vFModName333 already exists. The name must be unique.")); - workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "vFModName333", reqDetails, - workflowResourceIds); - } - - @Test - public void validateResourceIdInAAIVolumeGroupTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("id123"); - vnf.setVnfName("vnfName123"); - vnf.setModelCustomizationId("1234567"); - - GenericVnf vnf2 = new GenericVnf(); - vnf2.setVnfId("id123"); - vnf2.setVnfName("vnfName123"); - vnf2.setModelCustomizationId("222"); - - // VolumeGroup - VolumeGroup volumeGroup = new VolumeGroup(); - volumeGroup.setVolumeGroupId("id123"); - volumeGroup.setVolumeGroupName("name123"); - volumeGroup.setVfModuleModelCustomizationId("1234567"); - workflowResourceIds.setVnfId("id123"); - Optional<VolumeGroup> opVolumeGroup = Optional.of(volumeGroup); - - workflowResourceIds.setVnfId("id123"); - - when(bbSetupUtils.getAAIGenericVnf("id123")).thenReturn(vnf); - when(bbSetupUtils.getRelatedVolumeGroupByNameFromVnf("id123", "name123")).thenReturn(opVolumeGroup); - String id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "name123", - reqDetails, workflowResourceIds); - assertEquals("id123", id); - - when(bbSetupUtils.getAAIGenericVnf("id123")).thenReturn(vnf2); - when(bbSetupUtils.getRelatedVolumeGroupByNameFromVfModule("id123", "id123", "111111")) - .thenReturn(opVolumeGroup); - - when(bbSetupUtils.getRelatedVolumeGroupByNameFromVnf("id123", "111111")).thenReturn(Optional.empty()); - String id2 = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "111111", - reqDetails, workflowResourceIds); - assertEquals("generatedId123", id2); - } - - @Test - public void validatesourceIdInAAIVolumeGroupNotGloballyUniqueTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setVnfId("id123"); - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("id123"); - when(bbSetupUtils.getAAIGenericVnf("id123")).thenReturn(vnf); - when(bbSetupUtils.getRelatedVolumeGroupByNameFromVnf("id123", "testVolumeGroup")).thenReturn(Optional.empty()); - - when(bbSetupUtils.existsAAIVolumeGroupGloballyByName("testVolumeGroup")).thenReturn(true); - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage( - containsString("volumeGroup with name testVolumeGroup already exists. The name must be unique.")); - workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "testVolumeGroup", - reqDetails, workflowResourceIds); - } - - @Test - public void validateResourceIdInAAIConfigurationTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - // Configuration - org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration(); - configuration.setConfigurationId("id123"); - configuration.setConfigurationName("name123"); - configuration.setModelCustomizationId("1234567"); - Optional<org.onap.aai.domain.yang.Configuration> opConfiguration = Optional.of(configuration); - - org.onap.aai.domain.yang.Configuration configuration2 = new org.onap.aai.domain.yang.Configuration(); - configuration2.setConfigurationId("id123"); - configuration2.setConfigurationName("name123"); - configuration2.setModelCustomizationId("222"); - Optional<org.onap.aai.domain.yang.Configuration> opConfiguration2 = Optional.of(configuration2); - - workflowResourceIds.setVnfId("id123"); - - when(bbSetupUtils.getRelatedConfigurationByNameFromServiceInstance("siId123", "name123")) - .thenReturn(opConfiguration); - String id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.CONFIGURATION, "name123", - reqDetails, workflowResourceIds); - assertEquals("id123", id); - - when(bbSetupUtils.getRelatedConfigurationByNameFromServiceInstance("siId123", "111111")) - .thenReturn(Optional.empty()); - String id2 = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.CONFIGURATION, "111111", - reqDetails, workflowResourceIds); - assertEquals("generatedId123", id2); - - when(bbSetupUtils.getRelatedConfigurationByNameFromServiceInstance("siId123", "name222")) - .thenReturn(opConfiguration2); - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "configuration with name (name222), same parent and different customization id (id123) already exists. The name must be unique.")); - workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.CONFIGURATION, "name222", reqDetails, - workflowResourceIds); - } - - @Test - public void validateResourceIdInAAIConfigurationNotGloballyUniqueTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - when(bbSetupUtils.getRelatedConfigurationByNameFromServiceInstance("siId123", "testConfig")) - .thenReturn(Optional.empty()); - when(bbSetupUtils.existsAAIConfigurationGloballyByName("testConfig")).thenReturn(true); - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage( - containsString("configuration with name testConfig already exists. The name must be unique.")); - workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.CONFIGURATION, "testConfig", reqDetails, - workflowResourceIds); - } - - @Test - public void validateResourceIdInAAISITest() throws Exception { - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - reqDetails.getModelInfo().setModelVersionId("1234567"); - - ServiceInstance si = new ServiceInstance(); - si.setServiceInstanceId("siId123"); - si.setModelVersionId("1234567"); - ServiceInstances serviceInstances = new ServiceInstances(); - serviceInstances.getServiceInstance().add(si); - Optional<ServiceInstance> siOp = Optional.of(si); - ServiceInstance si2 = new ServiceInstance(); - si2.setServiceInstanceId("siId222"); - si2.setModelVersionId("22222"); - si2.setServiceInstanceName("siName222"); - Optional<ServiceInstance> siOp2 = Optional.of(si2); - ServiceInstances serviceInstances2 = new ServiceInstances(); - serviceInstances2.getServiceInstance().add(si2); - - when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siName123")).thenReturn(siOp); - when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siName222")).thenReturn(siOp2); - when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "111111")) - .thenReturn(Optional.empty()); - - when(bbSetupUtils.getAAIServiceInstancesGloballyByName("siName123")).thenReturn(serviceInstances); - String id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName123", - reqDetails, workflowResourceIds); - assertEquals("siId123", id); - String id2 = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "111111", - reqDetails, workflowResourceIds); - assertEquals("generatedId123", id2); - - when(bbSetupUtils.getAAIServiceInstancesGloballyByName("siName222")).thenReturn(serviceInstances2); - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "serviceInstance with name (siName222) and different version id (1234567) already exists. The name must be unique.")); - workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName222", reqDetails, - workflowResourceIds); - } - - @Test - public void validateResourceIdInAAIMultipleSITest() throws Exception { - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - reqDetails.getModelInfo().setModelVersionId("1234567"); - - ServiceInstance si = new ServiceInstance(); - si.setServiceInstanceId("siId123"); - si.setModelVersionId("1234567"); - ServiceInstances serviceInstances = new ServiceInstances(); - serviceInstances.getServiceInstance().add(si); - - ServiceInstance si2 = new ServiceInstance(); - si2.setServiceInstanceId("siId222"); - si2.setModelVersionId("22222"); - si2.setServiceInstanceName("siName222"); - serviceInstances.getServiceInstance().add(si2); - - when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siId123")) - .thenReturn(Optional.empty()); - - when(bbSetupUtils.getAAIServiceInstancesGloballyByName("siName123")).thenReturn(serviceInstances); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "serviceInstance with name (siName123) and multiple combination of model-version-id + service-type + global-customer-id already exists. The name must be unique.")); - workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName123", reqDetails, - workflowResourceIds); - } - - @Test - public void validateResourceIdInAAISIExistsTest() throws Exception { - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - reqDetails.getModelInfo().setModelVersionId("1234567"); - - ServiceInstance si = new ServiceInstance(); - si.setServiceInstanceId("siId123"); - si.setModelVersionId("1234567"); - ServiceInstances serviceInstances = new ServiceInstances(); - serviceInstances.getServiceInstance().add(si); - - when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siId123")) - .thenReturn(Optional.empty()); - - when(bbSetupUtils.getAAIServiceInstancesGloballyByName("siName123")).thenReturn(serviceInstances); - - Map<String, String> uriKeys = new HashMap<>(); - uriKeys.put(AAIFluentTypeBuilder.Types.CUSTOMER.getUriParams().globalCustomerId, "globalCustomerId"); - uriKeys.put(AAIFluentTypeBuilder.Types.SERVICE_SUBSCRIPTION.getUriParams().serviceType, "serviceType"); - - when(bbSetupUtils.getURIKeysFromServiceInstance("siId123")).thenReturn(uriKeys); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "serviceInstance with name (siName123) and global-customer-id (globalCustomerId), service-type (serviceType), model-version-id (1234567) already exists. The name must be unique.")); - workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName123", reqDetails, - workflowResourceIds); - } - - @Test - public void validateServiceResourceIdInAAINoDupTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - reqDetails.getModelInfo().setModelVersionId("1234567"); - when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siName123")) - .thenReturn(Optional.empty()); - when(bbSetupUtils.getAAIServiceInstancesGloballyByName("siName123")).thenReturn(null); - String id = workflowAction.validateServiceResourceIdInAAI("generatedId123", "siName123", reqDetails); - assertEquals("generatedId123", id); - } - - @Test - public void validateServiceResourceIdInAAISameModelVersionId() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - reqDetails.getModelInfo().setModelVersionId("1234567"); - - ServiceInstance si = new ServiceInstance(); - si.setServiceInstanceId("siId123"); - si.setModelVersionId("1234567"); - Optional<ServiceInstance> siOp = Optional.of(si); - - when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siName123")).thenReturn(siOp); - String id = workflowAction.validateServiceResourceIdInAAI("generatedId123", "siName123", reqDetails); - assertEquals("siId123", id); - } - - @Test - public void validateServiceResourceIdInAAIDifferentModelVersionId() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - reqDetails.getModelInfo().setModelVersionId("1234567"); - - ServiceInstance si = new ServiceInstance(); - si.setServiceInstanceId("siId123"); - si.setModelVersionId("9999999"); - ServiceInstances serviceInstances = new ServiceInstances(); - serviceInstances.getServiceInstance().add(si); - Optional<ServiceInstance> siOp = Optional.of(si); - - when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siName123")).thenReturn(siOp); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "serviceInstance with name (siName123) and different version id (1234567) already exists. The name must be unique.")); - - String id = workflowAction.validateServiceResourceIdInAAI("generatedId123", "siName123", reqDetails); - assertEquals("siId123", id); - } - - @Test - public void validateServiceResourceIdInAAIDuplicateNameTest() throws Exception { - - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - reqDetails.getModelInfo().setModelVersionId("1234567"); - - ServiceInstance si = new ServiceInstance(); - si.setServiceInstanceId("siId123"); - si.setModelVersionId("1234567"); - - ServiceInstances serviceInstances = new ServiceInstances(); - serviceInstances.getServiceInstance().add(si); - - when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siName")) - .thenReturn(Optional.empty()); - when(bbSetupUtils.getAAIServiceInstancesGloballyByName("siName")).thenReturn(serviceInstances); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "serviceInstance with name (siName) and global-customer-id (null), service-type (null), model-version-id (1234567) already exists. The name must be unique.")); - - workflowAction.validateServiceResourceIdInAAI("generatedId123", "siName", reqDetails); - } - - @Test - public void validateServiceResourceIdInAAIDuplicateNameMultipleTest() throws Exception { - - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - reqDetails.getModelInfo().setModelVersionId("1234567"); - - ServiceInstance si = new ServiceInstance(); - si.setServiceInstanceId("siId123"); - si.setModelVersionId("1234567"); - - ServiceInstance si2 = new ServiceInstance(); - si2.setServiceInstanceId("siId222"); - si2.setModelVersionId("22222"); - si2.setServiceInstanceName("siName222"); - - ServiceInstances serviceInstances = new ServiceInstances(); - serviceInstances.getServiceInstance().add(si); - serviceInstances.getServiceInstance().add(si2); - - when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siName")) - .thenReturn(Optional.empty()); - when(bbSetupUtils.getAAIServiceInstancesGloballyByName("siName")).thenReturn(serviceInstances); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "serviceInstance with name (siName) and multiple combination of model-version-id + service-type + global-customer-id already exists. The name must be unique.")); - - workflowAction.validateServiceResourceIdInAAI("generatedId123", "siName", reqDetails); - } - - @Test - public void validateNetworkResourceIdInAAITest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("siId123", "name123")) - .thenReturn(Optional.empty()); - when(bbSetupUtils.existsAAINetworksGloballyByName("name123")).thenReturn(false); - - String id = workflowAction.validateNetworkResourceIdInAAI("generatedId123", "name123", reqDetails, - workflowResourceIds); - assertEquals("generatedId123", id); - } - - @Test - public void validateNetworkResourceIdInAAISameModelCustIdTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - L3Network network = new L3Network(); - network.setNetworkId("id123"); - network.setNetworkName("name123"); - network.setModelCustomizationId("1234567"); - Optional<L3Network> opNetwork = Optional.of(network); - - when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("siId123", "name123")).thenReturn(opNetwork); - - String id = workflowAction.validateNetworkResourceIdInAAI("generatedId123", "name123", reqDetails, - workflowResourceIds); - assertEquals("id123", id); - } - - @Test - public void validateNetworkResourceIdInAAIDuplicateNameTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - L3Network network = new L3Network(); - network.setNetworkId("id123"); - network.setNetworkName("name123"); - network.setModelCustomizationId("9999999"); - Optional<L3Network> opNetwork = Optional.of(network); - - when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("siId123", "name123")).thenReturn(opNetwork); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "l3Network with name (name123), same parent and different customization id (9999999) already exists. The name must be unique.")); - - workflowAction.validateNetworkResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds); - } - - @Test - public void validateNetworkResourceIdInAAINotGloballyUniqueTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("siId123", "name123")) - .thenReturn(Optional.empty()); - when(bbSetupUtils.existsAAINetworksGloballyByName("name123")).thenReturn(true); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "l3Network with name (name123) id (siId123) and different parent relationship already exists. The name must be unique.")); - - workflowAction.validateNetworkResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds); - } - - @Test - public void validateVnfResourceIdInAAITest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName123")).thenReturn(Optional.empty()); - String id = workflowAction.validateVnfResourceIdInAAI("generatedId123", "vnfName123", reqDetails, - workflowResourceIds); - assertEquals("generatedId123", id); - } - - @Test - public void validateVnfResourceIdInAAISameModelCustomizationIdTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("id123"); - vnf.setVnfName("vnfName123"); - vnf.setModelCustomizationId("1234567"); - Optional<GenericVnf> opVnf = Optional.of(vnf); - - when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName123")).thenReturn(opVnf); - String id = workflowAction.validateVnfResourceIdInAAI("generatedId123", "vnfName123", reqDetails, - workflowResourceIds); - assertEquals("id123", id); - } - - @Test - public void validateVnfResourceIdInAAIDiffModelCustomizationIdTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("id123"); - vnf.setVnfName("vnfName123"); - vnf.setModelCustomizationId("9999999"); - Optional<GenericVnf> opVnf = Optional.of(vnf); - - when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName123")).thenReturn(opVnf); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "generic-vnf with name (vnfName123), same parent and different customization id (9999999) already exists. The name must be unique.")); - - workflowAction.validateVnfResourceIdInAAI("generatedId123", "vnfName123", reqDetails, workflowResourceIds); - } - - @Test - public void validateVnfResourceIdInAAINotGloballyUniqueTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("id123"); - vnf.setVnfName("vnfName123"); - GenericVnfs genericVnfs = new GenericVnfs(); - genericVnfs.getGenericVnf().add(vnf); - - when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName123")).thenReturn(Optional.empty()); - when(bbSetupUtils.getAAIVnfsGloballyByName("vnfName123")).thenReturn(genericVnfs); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "generic-vnf with name (vnfName123) id (id123) and different parent relationship already exists. The name must be unique.")); - - workflowAction.validateVnfResourceIdInAAI("generatedId123", "vnfName123", reqDetails, workflowResourceIds); - } - - @Test - public void validateVfModuleResourceIdTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setVnfId("vnfId123"); - - when(bbSetupUtils.getAAIGenericVnf("id123")).thenReturn(null); - when(bbSetupUtils.existsAAIVfModuleGloballyByName("name123")).thenReturn(false); - - String id = workflowAction.validateVfModuleResourceIdInAAI("generatedId123", "name123", reqDetails, - workflowResourceIds); - assertEquals("generatedId123", id); - } - - @Test - public void validateVfModuleResourceIdSameModelCustIdTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setVnfId("vnfId123"); - - VfModules vfModules = new VfModules(); - VfModule vfModule = new VfModule(); - vfModule.setVfModuleId("id123"); - vfModule.setVfModuleName("name123"); - vfModule.setModelCustomizationId("1234567"); - vfModules.getVfModule().add(vfModule); - - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("id123"); - vnf.setVnfName("vnfName123"); - vnf.setVfModules(vfModules); - - when(bbSetupUtils.getAAIGenericVnf("vnfId123")).thenReturn(vnf); - - String id = workflowAction.validateVfModuleResourceIdInAAI("generatedId123", "name123", reqDetails, - workflowResourceIds); - assertEquals("id123", id); - } - - @Test - public void validateVfModuleResourceIdDifferentModelCustIdTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setVnfId("vnfId123"); - - VfModules vfModules = new VfModules(); - VfModule vfModule = new VfModule(); - vfModule.setVfModuleId("id123"); - vfModule.setVfModuleName("name123"); - vfModule.setModelCustomizationId("9999999"); - vfModules.getVfModule().add(vfModule); - - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("id123"); - vnf.setVnfName("vnfName123"); - vnf.setVfModules(vfModules); - - when(bbSetupUtils.getAAIGenericVnf("vnfId123")).thenReturn(vnf); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "vfModule with name (name123), same parent and different customization id (1234567) already exists. The name must be unique.")); - - workflowAction.validateVfModuleResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds); - - } - - @Test - public void validateVfModuleResourceIdNotGloballyUniqueTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setVnfId("vnfId123"); - - when(bbSetupUtils.getAAIGenericVnf("id123")).thenReturn(null); - when(bbSetupUtils.existsAAIVfModuleGloballyByName("name123")).thenReturn(true); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException - .expectMessage(containsString("vfModule with name name123 already exists. The name must be unique.")); - - workflowAction.validateVfModuleResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds); - } - - @Test - public void validateVolumeGroupResourceIdInAAITest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setVnfId("vnfId123"); - - when(bbSetupUtils.getRelatedVolumeGroupByNameFromVnf("id123", "name123")).thenReturn(Optional.empty()); - when(bbSetupUtils.existsAAIVolumeGroupGloballyByName("name123")).thenReturn(false); - - String id = workflowAction.validateVolumeGroupResourceIdInAAI("generatedId123", "name123", reqDetails, - workflowResourceIds); - assertEquals("generatedId123", id); - } - - @Test - public void validateVolumeGroupResourceIdInAAISameModelCustIdTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - workflowResourceIds.setVnfId("vnfId123"); - - VolumeGroup volumeGroup = new VolumeGroup(); - volumeGroup.setVolumeGroupId("id123"); - volumeGroup.setVolumeGroupName("name123"); - volumeGroup.setVfModuleModelCustomizationId("1234567"); - - Optional<VolumeGroup> opVolumeGroup = Optional.of(volumeGroup); - - when(bbSetupUtils.getRelatedVolumeGroupByNameFromVnf("vnfId123", "name123")).thenReturn(opVolumeGroup); - String id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "name123", - reqDetails, workflowResourceIds); - - assertEquals("id123", id); - } - - @Test - public void validateVolumeGroupResourceIdInAAIDifferentModelCustIdTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - workflowResourceIds.setVnfId("vnfId123"); - - VolumeGroup volumeGroup = new VolumeGroup(); - volumeGroup.setVolumeGroupId("id123"); - volumeGroup.setVolumeGroupName("name123"); - volumeGroup.setVfModuleModelCustomizationId("9999999"); - - Optional<VolumeGroup> opVolumeGroup = Optional.of(volumeGroup); - - when(bbSetupUtils.getRelatedVolumeGroupByNameFromVnf("vnfId123", "name123")).thenReturn(opVolumeGroup); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage( - containsString("volumeGroup with name name123 already exists. The name must be unique.")); - - workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "name123", reqDetails, - workflowResourceIds); - } - - @Test - public void validateVolumeGroupResourceIdInAAINotGloballyUniqueTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setVnfId("vnfId123"); - - when(bbSetupUtils.getRelatedVolumeGroupByNameFromVnf("vnfId123", "name123")).thenReturn(Optional.empty()); - when(bbSetupUtils.existsAAIVolumeGroupGloballyByName("name123")).thenReturn(true); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage( - containsString("volumeGroup with name name123 already exists. The name must be unique.")); - - workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "name123", reqDetails, - workflowResourceIds); - } - - @Test - public void validateConfigurationResourceIdInAAITest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - when(bbSetupUtils.getRelatedConfigurationByNameFromServiceInstance("siId123", "name123")) - .thenReturn(Optional.empty()); - when(bbSetupUtils.existsAAIConfigurationGloballyByName("name123")).thenReturn(false); - - String id = workflowAction.validateConfigurationResourceIdInAAI("generatedId123", "name123", reqDetails, - workflowResourceIds); - assertEquals("generatedId123", id); - } - - @Test - public void validateConfigurationResourceIdInAAISameModelCustIdTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration(); - configuration.setConfigurationId("id123"); - configuration.setConfigurationName("name123"); - configuration.setModelCustomizationId("1234567"); - Optional<org.onap.aai.domain.yang.Configuration> opConfiguration = Optional.of(configuration); - - when(bbSetupUtils.getRelatedConfigurationByNameFromServiceInstance("siId123", "name123")) - .thenReturn(opConfiguration); - when(bbSetupUtils.existsAAIConfigurationGloballyByName("name123")).thenReturn(false); - - String id = workflowAction.validateConfigurationResourceIdInAAI("generatedId123", "name123", reqDetails, - workflowResourceIds); - assertEquals("id123", id); - } - - @Test - public void validateConfigurationResourceIdInAAIDifferentModelCustIdTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration(); - configuration.setConfigurationId("id123"); - configuration.setConfigurationName("name123"); - configuration.setModelCustomizationId("9999999"); - Optional<org.onap.aai.domain.yang.Configuration> opConfiguration = Optional.of(configuration); - - when(bbSetupUtils.getRelatedConfigurationByNameFromServiceInstance("siId123", "name123")) - .thenReturn(opConfiguration); - when(bbSetupUtils.existsAAIConfigurationGloballyByName("name123")).thenReturn(false); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage(containsString( - "configuration with name (name123), same parent and different customization id (id123) already exists. The name must be unique.")); - - workflowAction.validateConfigurationResourceIdInAAI("generatedId123", "name123", reqDetails, - workflowResourceIds); - } - - @Test - public void validateConfigurationResourceIdInAAINotGloballyUniqueTest() throws Exception { - RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("siId123"); - - when(bbSetupUtils.getRelatedConfigurationByNameFromServiceInstance("siId123", "name123")) - .thenReturn(Optional.empty()); - when(bbSetupUtils.existsAAIConfigurationGloballyByName("name123")).thenReturn(true); - - this.expectedException.expect(DuplicateNameException.class); - this.expectedException.expectMessage( - containsString("configuration with name name123 already exists. The name must be unique.")); - - workflowAction.validateConfigurationResourceIdInAAI("generatedId123", "name123", reqDetails, - workflowResourceIds); - } - @Test public void handleRuntimeExceptionTest() { execution.setVariable("BPMN_javaExpMsg", "test runtime error message"); @@ -3100,6 +2203,32 @@ public class WorkflowActionTest extends BaseTaskTest { } } + @Test + public void foundRelatedTest() { + List<Resource> resourceList = new ArrayList<>(); + resourceList.add(new Resource(WorkflowType.PNF, "model customization id", false)); + resourceList.add(new Resource(WorkflowType.VNF, "model customization id", false)); + resourceList.add(new Resource(WorkflowType.NETWORK, "model customization id", false)); + resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, "model customization id", false)); + + assertEquals(workflowAction.foundRelated(resourceList), true); + } + + @Test + public void containsWorkflowTypeTest() { + List<Resource> resourceList = new ArrayList<>(); + resourceList.add(new Resource(WorkflowType.PNF, "resource id", false)); + resourceList.add(new Resource(WorkflowType.VNF, "model customization id", false)); + resourceList.add(new Resource(WorkflowType.NETWORK, "model customization id", false)); + resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, "model customization id", false)); + + assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.PNF), true); + assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.VNF), true); + assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.NETWORK), true); + assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.NETWORKCOLLECTION), true); + assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.CONFIGURATION), false); + } + private List<Pair<WorkflowType, String>> getExpectedResourceIds() { List<Pair<WorkflowType, String>> resourceIds = new ArrayList<>(); resourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VNF, "testVnfId1")); @@ -3141,4 +2270,15 @@ public class WorkflowActionTest extends BaseTaskTest { private String readBpmnRequestFromFile(String fileName) throws IOException { return new String(Files.readAllBytes(Paths.get("src/test/resources/__files/" + fileName))); } + + private List<Resource> prepareListWithResources() { + List<Resource> resourceList = new ArrayList<>(); + resourceList.add(new Resource(WorkflowType.SERVICE, "3c40d244-808e-42ca-b09a-256d83d19d0a", false)); + resourceList.add(new Resource(WorkflowType.VNF, "ab153b6e-c364-44c0-bef6-1f2982117f04", false)); + resourceList.add(new Resource(WorkflowType.VOLUMEGROUP, "a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f", false)); + resourceList.add(new Resource(WorkflowType.VFMODULE, "72d9d1cd-f46d-447a-abdb-451d6fb05fa8", false)); + resourceList.add(new Resource(WorkflowType.VFMODULE, "3c40d244-808e-42ca-b09a-256d83d19d0a", false)); + resourceList.add(new Resource(WorkflowType.VFMODULE, "72d9d1cd-f46d-447a-abdb-451d6fb05fa8", false)); + return resourceList; + } } |