summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorojasdubey <ojas.dubey@amdocs.com>2018-10-17 15:10:48 +0530
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-10-21 07:25:04 +0000
commit5cc93c4c9e4750a4630afa6f4509438ca4925f51 (patch)
treecdd1c6b89b3a2e39a52be6e391e03fb5723c773a
parentc4e49e8e97cff5a051415448650d80ecd3207c10 (diff)
Bugfix - VF workflow artifacts in service csar
1. Added implementation for packing VF workflow artifacts to service csar 2. Updated the paths of workflow artifacts in VF csar as agreed 3. Updated the implementation to pack the artifact only once based on the artifact name Change-Id: I7ab22153e5a4877e6b727e0eb28831ac4e60894f Issue-ID: SDC-1845 Signed-off-by: ojasdubey <ojas.dubey@amdocs.com>
-rw-r--r--catalog-be/sdc-backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java102
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java15
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java86
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java186
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java7
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java6
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java112
11 files changed, 238 insertions, 298 deletions
diff --git a/catalog-be/sdc-backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb b/catalog-be/sdc-backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb
index c7710c503e..4c0207c2c6 100644
--- a/catalog-be/sdc-backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb
+++ b/catalog-be/sdc-backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb
@@ -319,6 +319,9 @@ serviceDeploymentArtifacts:
PLAN:
acceptedTypes:
- xml
+ WORKFLOW:
+ acceptedTypes:
+
resourceDeploymentArtifacts:
HEAT:
@@ -444,6 +447,9 @@ resourceDeploymentArtifacts:
validForResourceTypes:
- VF
- VFC
+ WORKFLOW:
+ acceptedTypes:
+ validForResourceTypes: *allResourceTypes
resourceInstanceDeploymentArtifacts:
HEAT_ENV:
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
index 4ef2e06205..ebdbcea535 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
@@ -3145,9 +3145,11 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
Operation operation = optionalOperation.get();
ArtifactDefinition implementationArtifact = operation.getImplementationArtifact();
- implementationArtifact.setArtifactName(operation.getName() + "_" + artifactInfo.getArtifactName());
+ implementationArtifact.setArtifactName(artifactInfo.getArtifactName());
implementationArtifact.setDescription(artifactInfo.getDescription());
implementationArtifact.setArtifactType(artifactInfo.getArtifactType());
+ implementationArtifact.setArtifactLabel(artifactInfo.getUniqueId());
+ implementationArtifact.setEsId(artifactInfo.getEsId());
operation.setImplementation(implementationArtifact);
gotInterface.setOperationsMap(operationsMap);
Either<InterfaceDefinition, StorageOperationStatus> interfaceDefinitionStorageOperationStatusEither =
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
index 6f822fd7e3..26e256fb00 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
@@ -259,8 +259,8 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
String artifactUUID = UUID.randomUUID().toString();
artifactDefinition.setArtifactUUID(artifactUUID);
artifactDefinition.setUniqueId(artifactUUID);
- artifactDefinition.setArtifactType(ArtifactTypeEnum.PLAN.getType());
- artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.LIFE_CYCLE);
+ artifactDefinition.setArtifactType(ArtifactTypeEnum.WORKFLOW.getType());
+ artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
operation.setUniqueId(UUID.randomUUID().toString());
operation.setImplementation(artifactDefinition);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
index 066b657068..bea65cf187 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
@@ -23,6 +23,7 @@ package org.openecomp.sdc.be.tosca;
import fj.data.Either;
import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.commons.lang.WordUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -35,7 +36,6 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
import org.openecomp.sdc.be.dao.cassandra.SdcSchemaFilesCassandraDao;
-import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.*;
@@ -94,8 +94,6 @@ public class CsarUtils {
public static final String RESOURCES_PATH = "Resources/";
public static final String INFORMATIONAL_ARTIFACTS = "Informational/";
public static final String DEPLOYMENT_ARTIFACTS = "Deployment/";
- public static final String WORKFLOW_ARTIFACT_DIR = "Workflows" + File.separator + "BPMN" + File.separator;
- public static final String DEPLOYMENT_ARTIFACTS_DIR = "Deployment" + File.separator;
public static final String DEFINITIONS_PATH = "Definitions/";
private static final String CSAR_META_VERSION = "1.0";
@@ -249,7 +247,7 @@ public class CsarUtils {
// US798487 - Abstraction of complex types
if (!ModelConverter.isAtomicComponent(component)) {
log.debug("Component {} is complex - generating abstract type for it..", component.getName());
- writeComponentInterface(component, zip, fileName);
+ writeComponentInterface(component, zip, fileName, false);
}
if (dependencies == null) {
@@ -308,7 +306,7 @@ public class CsarUtils {
// add component interface to zip
if (!ModelConverter.isAtomicComponent(innerComponent)) {
- writeComponentInterface(innerComponent, zip, icFileName);
+ writeComponentInterface(innerComponent, zip, icFileName, true);
}
}
}
@@ -433,10 +431,10 @@ public class CsarUtils {
}
private Either<ZipOutputStream, ResponseFormat> writeComponentInterface(Component component, ZipOutputStream zip,
- String fileName) {
+ String fileName, boolean isAssociatedResourceComponent) {
try {
Either<ToscaRepresentation, ToscaError> componentInterface = toscaExportUtils
- .exportComponentInterface(component);
+ .exportComponentInterface(component, isAssociatedResourceComponent);
ToscaRepresentation componentInterfaceYaml = componentInterface.left().value();
String mainYaml = componentInterfaceYaml.getMainYaml();
String interfaceFileName = DEFINITIONS_PATH + ToscaExportHandler.getInterfaceFilename(fileName);
@@ -858,74 +856,9 @@ public class CsarUtils {
return Either.right(writeComponentArtifactsToSpecifiedPath.right().value());
}
}
- writeComponentArtifactsToSpecifiedPath = writeOperationsArtifactsToCsar(mainComponent, zipstream);
-
- if (writeComponentArtifactsToSpecifiedPath.isRight()) {
- return Either.right(writeComponentArtifactsToSpecifiedPath.right().value());
- }
return Either.left(zipstream);
}
- private Either<ZipOutputStream, ResponseFormat> writeOperationsArtifactsToCsar(Component component,
- ZipOutputStream zipstream) {
- if (component instanceof Service) {
- return Either.left(zipstream);
- }
- if (Objects.isNull(((Resource) component).getInterfaces())) {
- log.debug("Component Name {}- no interfaces found", component.getNormalizedName());
- return Either.left(zipstream);
- }
- final Map<String, InterfaceDefinition> interfaces = ((Resource) component).getInterfaces();
-
- for (Map.Entry<String, InterfaceDefinition> interfaceEntry : interfaces.entrySet()) {
- for (OperationDataDefinition operation : interfaceEntry.getValue().getOperations().values()) {
- try {
- if (Objects.isNull(operation.getImplementation())) {
- log.debug(
- "Component Name {}, Interface Id {}, Operation Name {} - no Operation Implementation found",
- component.getNormalizedName(), interfaceEntry.getValue().getUniqueId(),
- operation.getName());
- continue;
- }
- if (Objects.isNull(operation.getImplementation().getArtifactName())) {
- log.debug("Component Name {}, Interface Id {}, Operation Name {} - no artifact found",
- component.getNormalizedName(), interfaceEntry.getValue().getUniqueId(),
- operation.getName());
- continue;
- }
-
- final String artifactUUID = operation.getImplementation().getArtifactUUID();
-
- final Either<byte[], ActionStatus> artifactFromCassandra = getFromCassandra(artifactUUID);
- final String artifactName = operation.getImplementation().getArtifactName();
- if (artifactFromCassandra.isRight()) {
- log.error("ArtifactName {}, unique ID {}", artifactName, artifactUUID);
- log.error("Failed to get {} payload from DB reason: {}", artifactName,
- artifactFromCassandra.right().value());
- return Either.right(componentsUtils.getResponseFormat(
- ActionStatus.ARTIFACT_PAYLOAD_NOT_FOUND_DURING_CSAR_CREATION, "Resource",
- component.getUniqueId(), artifactName, artifactUUID));
- }
-
- final byte[] payloadData = artifactFromCassandra.left().value();
- zipstream.putNextEntry(new ZipEntry(
- OperationArtifactUtil.createOperationArtifactPath(component.getNormalizedName(),
- interfaceEntry.getValue().getToscaResourceName(), operation)));
- zipstream.write(payloadData);
-
- } catch (IOException | NullPointerException e) {
- log.error("Component Name {}, Interface Name {}, Operation Name {}", component.getNormalizedName(),
- interfaceEntry.getKey(), operation.getName());
- log.error("Error while writing the operation's artifacts to the CSAR " + "{}", e);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.ERROR_DURING_CSAR_CREATION,
- "Resource", component.getUniqueId()));
- }
- }
- }
- return Either.left(zipstream);
-
- }
-
private Either<ZipOutputStream, ResponseFormat> writeComponentArtifactsToSpecifiedPath(Component mainComponent,
ComponentArtifacts componentArtifacts, ZipOutputStream zipstream, String currentPath,
boolean isInCertificationRequest) throws IOException {
@@ -958,14 +891,17 @@ public class CsarUtils {
Set<ArtifactGroupTypeEnum> groupTypeEnumKeySet = artifactsInfo.keySet();
for (ArtifactGroupTypeEnum artifactGroupTypeEnum : groupTypeEnumKeySet) {
- String groupTypeFolder = path + WordUtils.capitalizeFully(artifactGroupTypeEnum.getType()) + "/";
+ String groupTypeFolder = path + WordUtils.capitalizeFully(artifactGroupTypeEnum.getType()) + File.separator;
Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactTypesMap = artifactsInfo.get(artifactGroupTypeEnum);
Set<ArtifactTypeEnum> artifactTypeEnumKeySet = artifactTypesMap.keySet();
for (ArtifactTypeEnum artifactTypeEnum : artifactTypeEnumKeySet) {
List<ArtifactDefinition> artifactDefinitionList = artifactTypesMap.get(artifactTypeEnum);
- String artifactTypeFolder = groupTypeFolder + artifactTypeEnum.toString() + "/";
+ String artifactTypeFolder = groupTypeFolder + artifactTypeEnum.toString() + File.separator;
+ if (artifactTypeEnum == ArtifactTypeEnum.WORKFLOW) {
+ artifactTypeFolder += OperationArtifactUtil.BPMN_ARTIFACT_PATH + File.separator;
+ }
Either<ZipOutputStream, ResponseFormat> writeArtifactDefinition = writeArtifactDefinition(mainComponent,
zip, artifactDefinitionList, artifactTypeFolder, isInCertificationRequest);
@@ -1046,7 +982,15 @@ public class CsarUtils {
public void addArtifactsToGroup(ArtifactGroupTypeEnum artifactGroup,
Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactsDefinition) {
- artifactsInfoField.put(artifactGroup, artifactsDefinition);
+ if (artifactsInfoField.get(artifactGroup) == null) {
+ artifactsInfoField.put(artifactGroup, artifactsDefinition);
+ } else {
+ Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactTypeEnumListMap =
+ artifactsInfoField.get(artifactGroup);
+ artifactTypeEnumListMap.putAll(artifactsDefinition);
+ artifactsInfoField.put(artifactGroup, artifactTypeEnumListMap);
+ }
+
}
public boolean isEmpty() {
@@ -1356,6 +1300,10 @@ public class CsarUtils {
Map<String, ArtifactDefinition> deploymentArtifacts = component.getDeploymentArtifacts();
Map<ArtifactTypeEnum, List<ArtifactDefinition>> deploymentArtifactsByType = collectGroupArtifacts(
deploymentArtifacts);
+ Map<String, ArtifactDefinition> interfaceOperationArtifacts =
+ OperationArtifactUtil.getDistinctInterfaceOperationArtifactsByName(component);
+ Map<ArtifactTypeEnum, List<ArtifactDefinition>> interfaceOperationArtifactsByType = collectGroupArtifacts(
+ interfaceOperationArtifacts);
ArtifactsInfo artifactsInfo = new ArtifactsInfo();
if (!informationalArtifactsByType.isEmpty()) {
artifactsInfo.addArtifactsToGroup(ArtifactGroupTypeEnum.INFORMATIONAL, informationalArtifactsByType);
@@ -1363,6 +1311,10 @@ public class CsarUtils {
if (!deploymentArtifactsByType.isEmpty()) {
artifactsInfo.addArtifactsToGroup(ArtifactGroupTypeEnum.DEPLOYMENT, deploymentArtifactsByType);
}
+ //Add component interface operation artifacts
+ if(MapUtils.isNotEmpty(interfaceOperationArtifacts)) {
+ artifactsInfo.addArtifactsToGroup(ArtifactGroupTypeEnum.DEPLOYMENT, interfaceOperationArtifactsByType);
+ }
return artifactsInfo;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
index 41b29e3517..69c4cec42b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -151,7 +151,8 @@ public class ToscaExportHandler {
return Either.left(toscaRepresentation);
}
- public Either<ToscaRepresentation, ToscaError> exportComponentInterface(Component component) {
+ public Either<ToscaRepresentation, ToscaError> exportComponentInterface(Component component,
+ boolean isAssociatedResourceComponent) {
if (null == DEFAULT_IMPORTS) {
log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION);
return Either.right(ToscaError.GENERAL_ERROR);
@@ -160,8 +161,8 @@ public class ToscaExportHandler {
ToscaTemplate toscaTemplate = new ToscaTemplate(TOSCA_VERSION);
toscaTemplate.setImports(new ArrayList<>(DEFAULT_IMPORTS));
Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
- Either<ToscaTemplate, ToscaError> toscaTemplateRes = convertInterfaceNodeType(new HashMap<>(), component, toscaTemplate,
- nodeTypes);
+ Either<ToscaTemplate, ToscaError> toscaTemplateRes = convertInterfaceNodeType(new HashMap<>(), component,
+ toscaTemplate, nodeTypes, isAssociatedResourceComponent);
if (toscaTemplateRes.isRight()) {
return Either.right(toscaTemplateRes.right().value());
}
@@ -546,8 +547,10 @@ public class ToscaExportHandler {
return convertReqCapAndTypeName(componentsCache, component, toscaNode, nodeTypes, toscaNodeType, dataTypes);
}
- private Either<ToscaTemplate, ToscaError> convertInterfaceNodeType(Map<String, Component> componentsCache, Component component, ToscaTemplate toscaNode,
- Map<String, ToscaNodeType> nodeTypes) {
+ private Either<ToscaTemplate, ToscaError> convertInterfaceNodeType(Map<String, Component> componentsCache,
+ Component component, ToscaTemplate toscaNode,
+ Map<String, ToscaNodeType> nodeTypes,
+ boolean isAssociatedResourceComponent) {
log.debug("start convert node type for {}", component.getUniqueId());
ToscaNodeType toscaNodeType = createNodeType(component);
toscaNode.setInterface_types(addInterfaceTypeElement(component));
@@ -561,7 +564,7 @@ public class ToscaExportHandler {
List<InputDefinition> inputDef = component.getInputs();
Map<String, ToscaProperty> inputs = new HashMap<>();
- addInterfaceDefinitionElement(component, toscaNodeType);
+ addInterfaceDefinitionElement(component, toscaNodeType, isAssociatedResourceComponent);
if (inputDef != null) {
inputDef.forEach(i -> {
ToscaProperty property = propertyConvertor.convertProperty(dataTypes, i, false);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java
index 70fd2575f0..c3628df17b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java
@@ -95,7 +95,8 @@ public class InterfacesOperationsToscaUtil {
* @param component to work on
* @param nodeType to which the interfaces element will be added
*/
- public static void addInterfaceDefinitionElement(Component component, ToscaNodeType nodeType) {
+ public static void addInterfaceDefinitionElement(Component component, ToscaNodeType nodeType,
+ boolean isAssociatedResourceComponent) {
if (component instanceof Product) {
return;
}
@@ -116,9 +117,8 @@ public class InterfacesOperationsToscaUtil {
ToscaLifecycleOperationDefinition toscaOperation = new ToscaLifecycleOperationDefinition();
if (isArtifactPresent(operationEntry)) {
operationArtifactPath = OperationArtifactUtil
- .createOperationArtifactPath(component.getNormalizedName(),
- interfaceDefinition.getToscaResourceName(),
- operationEntry.getValue());
+ .createOperationArtifactPath(component, operationEntry.getValue(),
+ isAssociatedResourceComponent);
toscaOperation.setImplementation(operationArtifactPath);
}
toscaOperation.setDescription(operationEntry.getValue().getDescription());
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java
index 5d0b4466c6..b70ae90f7c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java
@@ -16,28 +16,94 @@
package org.openecomp.sdc.be.tosca.utils;
+import java.io.File;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang.WordUtils;
+import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.tosca.CsarUtils;
-
-import java.io.File;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
public class OperationArtifactUtil {
+ public static final String BPMN_ARTIFACT_PATH = "BPMN";
+
+ private OperationArtifactUtil() {
+ //Hiding implicit public constructor
+ }
/**
* This method assumes that operation.getImplementation() is not NULL ( it should be verified by the caller method)
*
- * @param componentName component's normalized name
- * @param interfaceType the specific interface type
* @param operation the specific operation name
* @return the full path including file name for operation's artifacts
*/
+ static String createOperationArtifactPath(Component component, OperationDataDefinition operation,
+ boolean isAssociatedResourceComponent) {
+ if (!(component instanceof Resource)) {
+ return null;
+ }
+ if (isAssociatedResourceComponent) {
+ ResourceMetadataDataDefinition resourceMetadataDataDefinition = (ResourceMetadataDataDefinition)
+ component.getComponentMetadataDefinition().getMetadataDataDefinition();
+ return createOperationArtifactPathInService(resourceMetadataDataDefinition.getToscaResourceName() +
+ "_v" + component.getVersion(), operation);
+ }
+ return createOperationArtifactPathInResource(operation);
+ }
+
+
+ private static String createOperationArtifactPathInResource(OperationDataDefinition operation) {
+ return CsarUtils.ARTIFACTS + File.separator + WordUtils.capitalizeFully(ArtifactGroupTypeEnum.DEPLOYMENT.name())
+ + File.separator + ArtifactTypeEnum.WORKFLOW.name() + File.separator + BPMN_ARTIFACT_PATH
+ + File.separator + operation.getImplementation().getArtifactName();
+ }
+
+ private static String createOperationArtifactPathInService(String toscaComponentName,
+ OperationDataDefinition operation) {
+ return CsarUtils.ARTIFACTS + File.separator + toscaComponentName + File.separator +
+ WordUtils.capitalizeFully(ArtifactGroupTypeEnum.DEPLOYMENT.name()) + File.separator +
+ ArtifactTypeEnum.WORKFLOW.name() + File.separator + BPMN_ARTIFACT_PATH + File.separator +
+ operation.getImplementation().getArtifactName();
+ }
+
+ public static Map<String, ArtifactDefinition> getDistinctInterfaceOperationArtifactsByName(Component originComponent) {
+ Map<String, ArtifactDefinition> distinctInterfaceArtifactsByName = new HashMap<>();
+ Map<String, InterfaceDefinition> interfaces = originComponent.getInterfaces();
+ if (MapUtils.isEmpty(interfaces)) {
+ return distinctInterfaceArtifactsByName;
+ }
+ Map<String, ArtifactDefinition> interfaceArtifacts = interfaces.values().stream()
+ .flatMap(interfaceDefinition -> interfaceDefinition.getOperationsMap().values().stream())
+ .map(Operation::getImplementationArtifact)
+ .collect(Collectors.toMap(ArtifactDataDefinition::getUniqueId,
+ artifactDefinition -> artifactDefinition));
+ if (MapUtils.isNotEmpty(interfaceArtifacts)) {
+ Set<String> artifactNameSet = new HashSet<>();
+ for (Map.Entry<String, ArtifactDefinition> interfaceArtifactEntry : interfaceArtifacts.entrySet()) {
+ String artifactName = interfaceArtifactEntry.getValue().getArtifactName();
+ if (artifactNameSet.contains(artifactName)) {
+ continue;
+ }
+ distinctInterfaceArtifactsByName.put(interfaceArtifactEntry.getKey(),
+ interfaceArtifactEntry.getValue());
+ artifactNameSet.add(artifactName);
+ }
- public static String createOperationArtifactPath(String componentName, String interfaceType,
- OperationDataDefinition operation) {
- return CsarUtils.ARTIFACTS + File.separator + componentName + File.separator + interfaceType + File.separator
- + CsarUtils.DEPLOYMENT_ARTIFACTS_DIR + CsarUtils.WORKFLOW_ARTIFACT_DIR + operation
- .getImplementation()
- .getArtifactName();
+ }
+ return distinctInterfaceArtifactsByName;
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java
index 6dd97bf62a..8b1fe5fabb 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java
@@ -210,7 +210,7 @@ public class CsarUtilsTest extends BeConfDependentTest {
.thenReturn(Either.right(ToscaError.GENERAL_ERROR));
try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
- Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, false, false);
+ Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, false);
} catch (Exception e) {
e.printStackTrace();
}
@@ -241,7 +241,7 @@ public class CsarUtilsTest extends BeConfDependentTest {
.thenReturn(Either.right(ToscaError.GENERAL_ERROR));
try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
- Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, false, false);
+ Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, false);
} catch (Exception e) {
e.printStackTrace();
}
@@ -361,7 +361,7 @@ public class CsarUtilsTest extends BeConfDependentTest {
.thenReturn(Either.left(toscaTemplate));
try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
- Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true, true);
+ Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true);
} catch (Exception e) {
e.printStackTrace();
}
@@ -412,7 +412,7 @@ public class CsarUtilsTest extends BeConfDependentTest {
.thenReturn(Either.left(toscaTemplate));
try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
- Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true, true);
+ Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true);
} catch (Exception e) {
e.printStackTrace();
}
@@ -466,7 +466,7 @@ public class CsarUtilsTest extends BeConfDependentTest {
.thenReturn(Either.right(CassandraOperationStatus.GENERAL_ERROR));
try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
- Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true, true);
+ Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true);
} catch (Exception e) {
e.printStackTrace();
}
@@ -525,7 +525,7 @@ public class CsarUtilsTest extends BeConfDependentTest {
.thenReturn(Either.left(schemaList));
try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
- Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true, true);
+ Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true);
} catch (Exception e) {
e.printStackTrace();
}
@@ -587,7 +587,7 @@ public class CsarUtilsTest extends BeConfDependentTest {
Mockito.any(Boolean.class))).thenReturn(new User());
try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
- Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true, true);
+ Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true);
} catch (Exception e) {
e.printStackTrace();
}
@@ -697,11 +697,11 @@ public class CsarUtilsTest extends BeConfDependentTest {
ToscaRepresentation tosca = new ToscaRepresentation();
tosca.setMainYaml("value");
- Mockito.when(toscaExportUtils.exportComponentInterface(Mockito.any(Component.class)))
+ Mockito.when(toscaExportUtils.exportComponentInterface(Mockito.any(Component.class), Mockito.any(Boolean.class)))
.thenReturn(Either.left(tosca));
try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
- Deencapsulation.invoke(testSubject, "writeComponentInterface", new Resource(), zip, fileName);
+ Deencapsulation.invoke(testSubject, "writeComponentInterface", new Resource(), zip, fileName, false);
} catch (IOException e) {
e.printStackTrace();
}
@@ -871,174 +871,6 @@ public class CsarUtilsTest extends BeConfDependentTest {
}
@Test
- public void testWriteAllFilesToCsarWhenWriteOperationsArtifactsToCsarIsRight() {
- Component component = new Resource();
- Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
- ArtifactDefinition artifact = new ArtifactDefinition();
- artifact.setArtifactName("artifactName");
- artifact.setEsId("esId");
- artifact.setArtifactUUID("artifactUUID");
- artifact.setArtifactType("YANG");
- toscaArtifacts.put("assettoscatemplate", artifact);
-
- component.setToscaArtifacts(toscaArtifacts);
- component.setDeploymentArtifacts(toscaArtifacts);
- component.setArtifacts(toscaArtifacts);
- Map<String, InterfaceDefinition> interfaces = new HashMap<>();
- InterfaceDefinition interfaceDef = new InterfaceDefinition();
- Map<String, OperationDataDefinition> operations = new HashMap<>();
- OperationDataDefinition operation = new OperationDataDefinition();
- ArtifactDataDefinition implementation = new ArtifactDataDefinition();
- implementation.setArtifactUUID("artifactUUID");
- implementation.setArtifactName("artifactName");
- operation.setImplementation(implementation);
- operations.put("key", operation);
- interfaceDef.setOperations(operations);
- interfaces.put("key", interfaceDef);
- ((Resource) component).setInterfaces(interfaces);
-
- ESArtifactData artifactData = new ESArtifactData();
- byte[] data = "value".getBytes();
- artifactData.setDataAsArray(data);
-
- ToscaTemplate toscaTemplate = new ToscaTemplate("version");
- List<Triple<String, String, Component>> dependencies = new ArrayList<>();
- toscaTemplate.setDependencies(dependencies);
-
- List<SdcSchemaFilesData> filesData = new ArrayList<>();
- SdcSchemaFilesData filedata = new SdcSchemaFilesData();
- filedata.setPayloadAsArray(data);
- filesData.add(filedata);
-
- Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData),
- Either.right(CassandraOperationStatus.GENERAL_ERROR));
-
- Mockito.when(componentsUtils.convertFromStorageResponse(Mockito.any(StorageOperationStatus.class)))
- .thenReturn(ActionStatus.GENERAL_ERROR);
-
- Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class)))
- .thenReturn(Either.left(toscaTemplate));
-
- Mockito.when(
- sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(Mockito.any(String.class), Mockito.any(String.class)))
- .thenReturn(Either.left(filesData));
-
- testSubject.createCsar(component, false, true);
- }
-
- @Test
- public void testWriteOperationsArtifactsToCsarWhenComponentIsService() {
- Component component = new Service();
-
- try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
- Deencapsulation.invoke(testSubject, "writeOperationsArtifactsToCsar", component, zip);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void testWriteOperationsArtifactsToCsarWhenOperationGetImplementaionIsNull() {
- Component component = new Resource();
- Map<String, InterfaceDefinition> interfaces = new HashMap<>();
- InterfaceDefinition interfaceDef = new InterfaceDefinition();
- Map<String, OperationDataDefinition> operations = new HashMap<>();
- operations.put("key", new OperationDataDefinition());
- interfaceDef.setOperations(operations);
- interfaces.put("key", interfaceDef);
-
- ((Resource) component).setInterfaces(interfaces);
-
- try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
- Deencapsulation.invoke(testSubject, "writeOperationsArtifactsToCsar", component, zip);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void testWriteOperationsArtifactsToCsarWhenOperationGetArtifactNameIsNull() {
- Component component = new Resource();
-
- Map<String, InterfaceDefinition> interfaces = new HashMap<>();
- InterfaceDefinition interfaceDef = new InterfaceDefinition();
- Map<String, OperationDataDefinition> operations = new HashMap<>();
- OperationDataDefinition operation = new OperationDataDefinition();
- ArtifactDataDefinition implementation = new ArtifactDataDefinition();
- operation.setImplementation(implementation);
- operations.put("key", operation);
- interfaceDef.setOperations(operations);
- interfaces.put("key", interfaceDef);
- ((Resource) component).setInterfaces(interfaces);
-
- try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
- Deencapsulation.invoke(testSubject, "writeOperationsArtifactsToCsar", component, zip);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void testWriteOperationsArtifactsToCsarWhenGettingArtifactFromCassandra() {
- Component component = new Resource();
-
- Map<String, InterfaceDefinition> interfaces = new HashMap<>();
- InterfaceDefinition interfaceDef = new InterfaceDefinition();
- Map<String, OperationDataDefinition> operations = new HashMap<>();
- OperationDataDefinition operation = new OperationDataDefinition();
- ArtifactDataDefinition implementation = new ArtifactDataDefinition();
- implementation.setArtifactName("artifactName");
- implementation.setArtifactUUID("artifactUUID");
- operation.setImplementation(implementation);
- operations.put("key", operation);
- interfaceDef.setOperations(operations);
- interfaceDef.setToscaResourceName("toscaResourceName");
- interfaces.put("key", interfaceDef);
- ((Resource) component).setInterfaces(interfaces);
- component.setNormalizedName("normalizedName");
-
- ESArtifactData data = new ESArtifactData();
- data.setDataAsArray("data".getBytes());
-
- Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(data));
-
- try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
- Deencapsulation.invoke(testSubject, "writeOperationsArtifactsToCsar", component, zip);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void testWriteOperationsArtifactsToCsarWhenNullPointerExceptionIsCaught() {
- Component component = new Resource();
-
- Map<String, InterfaceDefinition> interfaces = new HashMap<>();
- InterfaceDefinition interfaceDef = new InterfaceDefinition();
- Map<String, OperationDataDefinition> operations = new HashMap<>();
- OperationDataDefinition operation = new OperationDataDefinition();
- ArtifactDataDefinition implementation = new ArtifactDataDefinition();
- implementation.setArtifactName("artifactName");
- implementation.setArtifactUUID("artifactUUID");
- operation.setImplementation(implementation);
- operations.put("key", operation);
- interfaceDef.setOperations(operations);
- interfaceDef.setToscaResourceName("toscaResourceName");
- interfaces.put("key", interfaceDef);
- ((Resource) component).setInterfaces(interfaces);
- component.setNormalizedName("normalizedName");
-
- Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class)))
- .thenReturn(Either.left(new ESArtifactData()));
-
- try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
- Deencapsulation.invoke(testSubject, "writeOperationsArtifactsToCsar", component, zip);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Test
public void testWriteArtifactDefinition() {
Component component = new Service();
List<ArtifactDefinition> artifactDefinitionList = new ArrayList<>();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
index 49599777c3..2fabe43733 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
@@ -162,14 +162,14 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
Mockito.when(dataTypeCache.getAll()).thenReturn(Either.right(TitanOperationStatus.NOT_FOUND));
// default test when convertInterfaceNodeType is right
- result = testSubject.exportComponentInterface(component);
+ result = testSubject.exportComponentInterface(component, false);
Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
Mockito.when(capabiltyRequirementConvertor.convertRequirements(Mockito.any(Map.class),Mockito.any(Resource.class),
Mockito.any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
// default test when convertInterfaceNodeType is left
- result = testSubject.exportComponentInterface(component);
+ result = testSubject.exportComponentInterface(component, false);
}
@@ -397,7 +397,8 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
Mockito.any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType()));
// default test
- result = Deencapsulation.invoke(testSubject, "convertInterfaceNodeType",new HashMap<>(), component, toscaNode, nodeTypes);
+ result = Deencapsulation.invoke(testSubject, "convertInterfaceNodeType",new HashMap<>(), component, toscaNode
+ , nodeTypes, false);
}
@Ignore("need to fix change in injected class.")
@Test
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java
index 7a88d0a9d3..ac53a6d930 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java
@@ -114,7 +114,7 @@ public class InterfacesOperationsToscaUtilTest {
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
ToscaNodeType nodeType = new ToscaNodeType();
- InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType);
+ InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType, false);
ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null);
ToscaTemplate template = new ToscaTemplate(NODE_TYPE_NAME);
@@ -146,7 +146,7 @@ public class InterfacesOperationsToscaUtilTest {
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
ToscaNodeType nodeType = new ToscaNodeType();
- InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType);
+ InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType, true);
ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null);
ToscaTemplate template = new ToscaTemplate("testService");
@@ -177,7 +177,7 @@ public class InterfacesOperationsToscaUtilTest {
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
ToscaNodeType nodeType = new ToscaNodeType();
- InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType);
+ InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType, false);
ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null);
ToscaTemplate template = new ToscaTemplate("test");
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java
index 66983d7d3a..99988224c8 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java
@@ -15,19 +15,30 @@
*/
package org.openecomp.sdc.be.tosca.utils;
+import static org.junit.Assert.assertEquals;
+import static org.openecomp.sdc.be.tosca.utils.OperationArtifactUtil.BPMN_ARTIFACT_PATH;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.commons.lang.WordUtils;
+import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openecomp.sdc.be.DummyConfigurationManager;
+import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentMetadataDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Resource;
-
-import java.io.File;
-import java.util.HashMap;
-
-import static org.junit.Assert.assertEquals;
+import org.openecomp.sdc.be.tosca.CsarUtils;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
public class OperationArtifactUtilTest {
@@ -38,25 +49,92 @@ public class OperationArtifactUtilTest {
@Test
public void testCorrectPathForOperationArtifacts() {
- Component component = new Resource();
- component.setNormalizedName("normalizedComponentName");
- final InterfaceDefinition addedInterface = new InterfaceDefinition();
+ ResourceMetadataDataDefinition componentMetadataDataDefinition = new ResourceMetadataDataDefinition();
+ componentMetadataDataDefinition.setToscaResourceName("org.openecomp.resource.vf.TestResource");
+ final ComponentMetadataDefinition componentMetadataDefinition =
+ new ComponentMetadataDefinition(componentMetadataDataDefinition);
+ Component component = new Resource(componentMetadataDefinition);
+ final OperationDataDefinition op = new OperationDataDefinition();
+ final ArtifactDataDefinition implementation = new ArtifactDataDefinition();
+ implementation.setArtifactName("createBPMN.bpmn");
+ op.setImplementation(implementation);
+ final String actualArtifactPath = OperationArtifactUtil.createOperationArtifactPath(component, op, false);
+ String expectedArtifactPath = CsarUtils.ARTIFACTS + File.separator +
+ WordUtils.capitalizeFully(ArtifactGroupTypeEnum.DEPLOYMENT.name()) + File.separator +
+ ArtifactTypeEnum.WORKFLOW.name() + File.separator + BPMN_ARTIFACT_PATH + File.separator +
+ "createBPMN.bpmn";
+
+
+ assertEquals(expectedArtifactPath,actualArtifactPath);
+ }
+
+ @Test
+ public void testCorrectPathForOperationArtifactsInService() {
+ ResourceMetadataDataDefinition componentMetadataDataDefinition = new ResourceMetadataDataDefinition();
+ componentMetadataDataDefinition.setToscaResourceName("org.openecomp.resource.vf.TestResource");
+ final ComponentMetadataDefinition componentMetadataDefinition =
+ new ComponentMetadataDefinition(componentMetadataDataDefinition);
+ Component component = new Resource(componentMetadataDefinition);
+ component.setVersion("1.0");
final OperationDataDefinition op = new OperationDataDefinition();
final ArtifactDataDefinition implementation = new ArtifactDataDefinition();
implementation.setArtifactName("createBPMN.bpmn");
op.setImplementation(implementation);
+ final String actualArtifactPath = OperationArtifactUtil.createOperationArtifactPath(component, op, true);
+ String expectedArtifactPath = CsarUtils.ARTIFACTS + File.separator +
+ "org.openecomp.resource.vf.TestResource_v1.0" + File.separator +
+ WordUtils.capitalizeFully(ArtifactGroupTypeEnum.DEPLOYMENT.name()) + File.separator +
+ ArtifactTypeEnum.WORKFLOW.name() +
+ File.separator + BPMN_ARTIFACT_PATH + File.separator + "createBPMN.bpmn";
+
+
+ assertEquals(expectedArtifactPath,actualArtifactPath);
+ }
+
+ @Test
+ public void testGetDistinctInterfaceOperationArtifactsByName() {
+ Component component = new Resource();
+ component.setNormalizedName("normalizedComponentName");
+ final InterfaceDefinition addedInterface = new InterfaceDefinition();
+ OperationDataDefinition op1 = createInterfaceOperation("createBPMN.bpmn");
+ OperationDataDefinition op2 = createInterfaceOperation("createBPMN.bpmn");
addedInterface.setOperations(new HashMap<>());
- addedInterface.getOperations().put("create", op);
+ addedInterface.getOperations().put("create", op1);
+ addedInterface.getOperations().put("update", op2);
final String interfaceType = "normalizedComponentName-interface";
- ((Resource) component).setInterfaces(new HashMap<>());
- ((Resource) component).getInterfaces().put(interfaceType, addedInterface);
- final String actualArtifactPath = OperationArtifactUtil.createOperationArtifactPath(component.getNormalizedName(), interfaceType, op);
- String expectedArtifactPath ="Artifacts"+ File.separator+"normalizedComponentName"+File.separator
- +"normalizedComponentName-interface"+File.separator+"Deployment"
- +File.separator+"Workflows"+File.separator+"BPMN"
- +File.separator+"createBPMN.bpmn";
+ component.setInterfaces(new HashMap<>());
+ component.getInterfaces().put(interfaceType, addedInterface);
+ Map<String, ArtifactDefinition> distinctInterfaceOperationArtifactsByName =
+ OperationArtifactUtil.getDistinctInterfaceOperationArtifactsByName(component);
+ Assert.assertEquals(1, distinctInterfaceOperationArtifactsByName.size());
+ }
- assertEquals(expectedArtifactPath,actualArtifactPath);
+ @Test
+ public void testGetDistinctInterfaceOperationArtifactsByNameAllDistinct() {
+ Component component = new Resource();
+ component.setNormalizedName("normalizedComponentName");
+ final InterfaceDefinition addedInterface = new InterfaceDefinition();
+ OperationDataDefinition op1 = createInterfaceOperation("createBPMN.bpmn");
+ OperationDataDefinition op2 = createInterfaceOperation("updateBPMN.bpmn");
+ addedInterface.setOperations(new HashMap<>());
+ addedInterface.getOperations().put("create", op1);
+ addedInterface.getOperations().put("update", op2);
+ final String interfaceType = "normalizedComponentName-interface";
+ component.setInterfaces(new HashMap<>());
+ component.getInterfaces().put(interfaceType, addedInterface);
+
+ Map<String, ArtifactDefinition> distinctInterfaceOperationArtifactsByName =
+ OperationArtifactUtil.getDistinctInterfaceOperationArtifactsByName(component);
+ Assert.assertEquals(2, distinctInterfaceOperationArtifactsByName.size());
+ }
+
+ private OperationDataDefinition createInterfaceOperation(String artifactName) {
+ final OperationDataDefinition op = new OperationDataDefinition();
+ final ArtifactDataDefinition implementation = new ArtifactDataDefinition();
+ implementation.setUniqueId(UUID.randomUUID().toString());
+ implementation.setArtifactName(artifactName);
+ op.setImplementation(implementation);
+ return op;
}
} \ No newline at end of file