aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2020-10-14 20:56:11 +0100
committerS�bastien Determe <sebastien.determe@intl.att.com>2020-12-07 14:51:59 +0000
commit95ad93091d5fa6e377e76f312d495151bddc9da8 (patch)
tree9923a98bd90b99cb960cf1f7ead2a57402aca1a8 /catalog-be
parenta9467feb90c33ad5b6b2ed80581c4adf75114046 (diff)
Support interface input during import VFC
Change-Id: I097ce258a7dadbedf1aff6ce53dd1286da074552 Issue-ID: SDC-3372 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml12
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java51
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java255
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java194
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java85
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaInterfaceDefinition.java27
-rw-r--r--catalog-be/src/main/resources/config/error-configuration.yaml12
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java64
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ImportUtilsTest.java8
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandlerTest.java174
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java (renamed from catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsConverterTest.java)240
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaInterfaceDefinitionTest.java72
-rw-r--r--catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml12
-rw-r--r--catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml24
-rw-r--r--catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-tosca1.3.yaml25
15 files changed, 836 insertions, 419 deletions
diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
index d2a79909d6..4aa93cb268 100644
--- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
+++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
@@ -2060,6 +2060,18 @@ errors:
message: "Error: Failed to delete interface operation.",
messageId: "SVC4702"
}
+ #SVC4732
+ INTERFACE_UNKNOWN: {
+ code: 400,
+ message: "Error: The interface '%1' does not exists in the database.",
+ messageId: "SVC4732"
+ }
+ #SVC4733
+ INTERFACE_OPERATION_NOT_DEFINED: {
+ code: 400,
+ message: "Error: The operation '%1' does not exists in the interface '%2'.",
+ messageId: "SVC4733"
+ }
#-----------SVC4692---------------------------
RESOURCE_LIFECYCLE_STATE_NOT_VALID: {
code: 400,
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
index 4127faa820..614b261b4a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
@@ -47,6 +47,7 @@ import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentEx
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.Annotation;
+import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
@@ -348,24 +349,24 @@ public final class ImportUtils {
}
}
- private static List<PropertyConstraint> getPropertyConstraints(Map<String, Object> propertyValue,
- String propertyType) {
- List<Object> propertyFieldConstraints = findCurrentLevelConstraintsElement(propertyValue);
- if (CollectionUtils.isNotEmpty(propertyFieldConstraints)) {
- List<PropertyConstraint> constraintList = new ArrayList<>();
- Type constraintType = new TypeToken<PropertyConstraint>() {
- }.getType();
- Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser())
- .create();
+ private static List<PropertyConstraint> getPropertyConstraints(final Map<String, Object> propertyValue,
+ final String propertyType) {
+ final List<Object> propertyFieldConstraints = findCurrentLevelConstraintsElement(propertyValue);
+ if (CollectionUtils.isEmpty(propertyFieldConstraints)) {
+ return Collections.emptyList();
+ }
+ final List<PropertyConstraint> constraintList = new ArrayList<>();
+ final Type constraintType = new TypeToken<PropertyConstraint>() {
+ }.getType();
+ final Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser())
+ .create();
- for (Object constraintJson : propertyFieldConstraints) {
- PropertyConstraint propertyConstraint = validateAndGetPropertyConstraint(propertyType, constraintType,
- gson, constraintJson);
- constraintList.add(propertyConstraint);
- }
- return constraintList;
+ for (final Object constraintJson : propertyFieldConstraints) {
+ final PropertyConstraint propertyConstraint = validateAndGetPropertyConstraint(propertyType, constraintType,
+ gson, constraintJson);
+ constraintList.add(propertyConstraint);
}
- return null;
+ return constraintList;
}
private static List<Object> findCurrentLevelConstraintsElement(Map<String, Object> toscaJson) {
@@ -485,10 +486,13 @@ public final class ImportUtils {
return result;
}
- public static InputDefinition createModuleInput(Map<String, Object> inputValue,
- AnnotationTypeOperations annotationTypeOperations) {
+ public static InputDefinition createModuleInput(final Map<String, Object> inputValue,
+ final AnnotationTypeOperations annotationTypeOperations) {
+ return parseAnnotationsAndAddItToInput(createModuleInput(inputValue), inputValue, annotationTypeOperations);
+ }
- InputDefinition inputDef = new InputDefinition();
+ public static InputDefinition createModuleInput(final Map<String, Object> inputValue) {
+ final InputDefinition inputDef = new InputDefinition();
setField(inputValue, TypeUtils.ToscaTagNamesEnum.TYPE, inputDef::setType);
setFieldBoolean(inputValue, ToscaTagNamesEnum.REQUIRED, req -> inputDef.setRequired(Boolean.parseBoolean(req)));
setField(inputValue, TypeUtils.ToscaTagNamesEnum.DESCRIPTION, inputDef::setDescription);
@@ -504,9 +508,7 @@ public final class ImportUtils {
setScheme(inputValue, inputDef);
setPropertyConstraints(inputValue, inputDef);
-
- return parseAnnotationsAndAddItToInput(inputDef, inputValue, annotationTypeOperations);
-
+ return inputDef;
}
public static InputDefinition parseAnnotationsAndAddItToInput(InputDefinition inputDef,
@@ -608,6 +610,11 @@ public final class ImportUtils {
}
+ public static Either<Map<String, InputDefinition>, ResultStatusEnum> getInputs(final Map<String, Object> toscaJson) {
+ return getElements(toscaJson, TypeUtils.ToscaTagNamesEnum.INPUTS, ImportUtils::createInputs,
+ ImportUtils::createModuleInput);
+ }
+
public static <T> Either<Map<String, T>, ResultStatusEnum> getElements(Map<String, Object> toscaJson,
TypeUtils.ToscaTagNamesEnum elementTagName,
Function<String, T> elementGenByName,
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java
new file mode 100644
index 0000000000..aeb4376c15
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java
@@ -0,0 +1,255 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import static org.openecomp.sdc.be.components.impl.ImportUtils.Constants.QUOTE;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DEFAULT;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DESCRIPTION;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.IMPLEMENTATION;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.INPUTS;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NOTIFICATIONS;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.OPERATIONS;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.REQUIRED;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.STATUS;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.TYPE;
+
+import fj.data.Either;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import org.apache.commons.collections.MapUtils;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.tosca.utils.OperationArtifactUtil;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * Handles interface definition TOSCA conversions
+ */
+@Component("interfaceDefinitionHandler")
+public class InterfaceDefinitionHandler {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(InterfaceDefinitionHandler.class);
+
+ private final InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
+
+ public InterfaceDefinitionHandler(final InterfaceOperationBusinessLogic interfaceOperationBusinessLogic) {
+ this.interfaceOperationBusinessLogic = interfaceOperationBusinessLogic;
+ }
+
+ /**
+ * Creates an interface definition based on a TOSCA map representing an interface definition.
+ *
+ * @param interfaceDefinitionToscaMap the TOSCA interface definition structure
+ * @return an interface definition representation
+ */
+ public InterfaceDefinition create(final Map<String, Object> interfaceDefinitionToscaMap) {
+
+ final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+
+ if (interfaceDefinitionToscaMap.containsKey(TYPE.getElementName())) {
+ final Object typeObj = interfaceDefinitionToscaMap.get(TYPE.getElementName());
+ if (!(typeObj instanceof String)) {
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_YAML);
+ }
+ final String type = (String) typeObj;
+ interfaceDefinition.setType(type);
+ interfaceDefinition.setUniqueId(type.toLowerCase());
+ }
+
+ final Map<String, InputDefinition> inputDefinitionMap = handleInputs(interfaceDefinitionToscaMap);
+ if (!inputDefinitionMap.isEmpty()) {
+ final Map<String, InputDataDefinition> collect = inputDefinitionMap.entrySet().stream().
+ collect(Collectors.toMap(Entry::getKey, value -> new InputDataDefinition(value.getValue())));
+ interfaceDefinition.setInputs(collect);
+ }
+ final Map<String, OperationDataDefinition> operationMap;
+ if (interfaceDefinitionToscaMap.containsKey(OPERATIONS.getElementName()) || interfaceDefinitionToscaMap
+ .containsKey(NOTIFICATIONS.getElementName())) {
+ operationMap = handleOperations(interfaceDefinitionToscaMap);
+ //TODO handle notifications
+ } else {
+ operationMap = handleLegacyOperations(interfaceDefinitionToscaMap);
+ }
+ if (!operationMap.isEmpty()) {
+ validateOperations(interfaceDefinition.getType(), operationMap);
+ interfaceDefinition.setOperations(operationMap);
+ }
+
+ return interfaceDefinition;
+ }
+
+ private void validateOperations(final String interfaceType,
+ final Map<String, OperationDataDefinition> operationMap) {
+ if (MapUtils.isEmpty(operationMap)) {
+ return;
+ }
+ Either<Map<String, InterfaceDefinition>, ResponseFormat> interfaceDefinitionMapEither =
+ interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes();
+ if (interfaceDefinitionMapEither.isRight() || MapUtils.isEmpty(interfaceDefinitionMapEither.left().value())) {
+ throw new ByActionStatusComponentException(ActionStatus.INTERFACE_UNKNOWN, interfaceType);
+ }
+
+ final Map<String, InterfaceDefinition> interfaceDefinitionMap = interfaceDefinitionMapEither.left().value();
+ final Optional<InterfaceDefinition> interfaceDefinitionOptional = interfaceDefinitionMap.entrySet().stream()
+ .filter(interfaceDefinitionEntry -> interfaceDefinitionEntry.getKey().equalsIgnoreCase(interfaceType))
+ .map(Entry::getValue).findFirst();
+ if (interfaceDefinitionOptional.isEmpty()) {
+ throw new ByActionStatusComponentException(ActionStatus.INTERFACE_UNKNOWN, interfaceType);
+ }
+ final InterfaceDefinition interfaceDefinition = interfaceDefinitionOptional.get();
+ operationMap.keySet().forEach(operation1 -> {
+ if (!interfaceDefinition.hasOperation(operation1)) {
+ throw new ByActionStatusComponentException(ActionStatus.INTERFACE_OPERATION_NOT_DEFINED,
+ operation1, interfaceType);
+ }
+ });
+ }
+
+ private Map<String, OperationDataDefinition> handleOperations(
+ final Map<String, Object> interfaceDefinitionToscaMap) {
+ if (!interfaceDefinitionToscaMap.containsKey(OPERATIONS.getElementName())) {
+ return Collections.emptyMap();
+ }
+ final Map<String, Object> operationMap =
+ (Map<String, Object>) interfaceDefinitionToscaMap.get(OPERATIONS.getElementName());
+ return operationMap.entrySet().stream()
+ .map(interfaceEntry -> createOperation(interfaceEntry.getKey(),
+ (Map<String, Object>) interfaceEntry.getValue()))
+ .collect(
+ Collectors.toMap(OperationDataDefinition::getName, operationDataDefinition -> operationDataDefinition));
+ }
+
+ private Map<String, OperationDataDefinition> handleLegacyOperations(
+ final Map<String, Object> interfaceDefinitionToscaMap) {
+ final List<String> notALegacyOperationEntry = Arrays
+ .asList(OPERATIONS.getElementName(),
+ TYPE.getElementName(),
+ INPUTS.getElementName(),
+ NOTIFICATIONS.getElementName());
+ return interfaceDefinitionToscaMap.entrySet().stream()
+ .filter(interfaceEntry -> !notALegacyOperationEntry.contains(interfaceEntry.getKey()))
+ .map(interfaceEntry -> createOperation(interfaceEntry.getKey(),
+ (Map<String, Object>) interfaceEntry.getValue()))
+ .collect(
+ Collectors.toMap(OperationDataDefinition::getName, operationDataDefinition -> operationDataDefinition));
+ }
+
+
+ private OperationDataDefinition createOperation(final String operationName,
+ final Map<String, Object> operationDefinitionMap) {
+ final OperationDataDefinition operation = new OperationDataDefinition();
+ operation.setName(operationName);
+
+ handleOperationImplementation(operationDefinitionMap).ifPresent(operation::setImplementation);
+ if (operationDefinitionMap.containsKey(INPUTS.getElementName())) {
+ final Map<String, Object> interfaceInputs =
+ (Map<String, Object>) operationDefinitionMap.get(INPUTS.getElementName());
+ operation.setInputs(handleInterfaceOperationInputs(interfaceInputs));
+ }
+
+ return operation;
+ }
+
+ private ListDataDefinition<OperationInputDefinition> handleInterfaceOperationInputs(
+ final Map<String, Object> interfaceInputs) {
+ final ListDataDefinition<OperationInputDefinition> inputs = new ListDataDefinition<>();
+ for (final Entry<String, Object> interfaceInput : interfaceInputs.entrySet()) {
+ final OperationInputDefinition operationInput = new OperationInputDefinition();
+ operationInput.setName(interfaceInput.getKey());
+ if (interfaceInput.getValue() instanceof Map) {
+ final LinkedHashMap<String, Object> inputPropertyValue =
+ (LinkedHashMap<String, Object>) interfaceInput.getValue();
+ LOGGER.info("createModuleInterface: i interfaceInput.getKey() {}, {} , {} ",
+ interfaceInput.getKey(), inputPropertyValue.keySet(), inputPropertyValue.values());
+ if (inputPropertyValue.get(TYPE.getElementName()) != null) {
+ operationInput.setType(inputPropertyValue.get(TYPE.getElementName()).toString());
+ }
+ if (inputPropertyValue.get(DESCRIPTION.getElementName()) != null) {
+ operationInput.setDescription(inputPropertyValue.get(DESCRIPTION.getElementName()).toString());
+ }
+ if (inputPropertyValue.get(REQUIRED.getElementName()) != null) {
+ operationInput.setRequired(
+ Boolean.getBoolean(inputPropertyValue.get(REQUIRED.getElementName()).toString()));
+ }
+ if (inputPropertyValue.get(DEFAULT.getElementName()) != null) {
+ operationInput.setToscaDefaultValue(inputPropertyValue.get(DEFAULT.getElementName()).toString());
+ }
+ if (inputPropertyValue.get(STATUS.getElementName()) != null) {
+ operationInput.setStatus(inputPropertyValue.get(STATUS.getElementName()).toString());
+ }
+
+ } else if (interfaceInput.getValue() instanceof String) {
+ final String value = (String) interfaceInput.getValue();
+ operationInput.setDefaultValue(value);
+ operationInput.setToscaDefaultValue(value);
+ operationInput.setValue(value);
+ }
+ inputs.add(operationInput);
+ }
+ return inputs;
+ }
+
+ private Optional<ArtifactDataDefinition> handleOperationImplementation(
+ final Map<String, Object> operationDefinitionMap) {
+ if (!operationDefinitionMap.containsKey(IMPLEMENTATION.getElementName())) {
+ return Optional.empty();
+ }
+ final ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition();
+ final String artifactName = (String) operationDefinitionMap.get(IMPLEMENTATION.getElementName());
+ if (OperationArtifactUtil.artifactNameIsALiteralValue(artifactName)) {
+ artifactDataDefinition.setArtifactName(artifactName);
+ } else {
+ artifactDataDefinition.setArtifactName(QUOTE + artifactName + QUOTE);
+ }
+ return Optional.of(artifactDataDefinition);
+ }
+
+ private Map<String, InputDefinition> handleInputs(final Map<String, Object> interfaceDefinitionToscaMap) {
+ if (!interfaceDefinitionToscaMap.containsKey(INPUTS.getElementName())) {
+ return Collections.emptyMap();
+ }
+
+ final Either<Map<String, InputDefinition>, ResultStatusEnum> inputMapEither =
+ ImportUtils.getInputs(interfaceDefinitionToscaMap);
+ if (inputMapEither.isRight()) {
+ return Collections.emptyMap();
+ }
+
+ return inputMapEither.left().value();
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
index 7ff916df32..b96e4e58e2 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
@@ -22,7 +22,6 @@
package org.openecomp.sdc.be.components.impl;
-import static org.openecomp.sdc.be.components.impl.ImportUtils.Constants.QUOTE;
import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementOperation.createDataType;
import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementOperation.createDataTypeDefinitionWithName;
import static org.openecomp.sdc.be.utils.TypeUtils.setField;
@@ -34,7 +33,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -62,11 +60,7 @@ import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
-import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -94,7 +88,6 @@ import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
-import org.openecomp.sdc.be.tosca.utils.OperationArtifactUtil;
import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
import org.openecomp.sdc.common.log.wrappers.Logger;
@@ -112,13 +105,7 @@ public class ResourceImportManager {
private static final Logger log = Logger.getLogger(ResourceImportManager.class);
static final Pattern PROPERTY_NAME_PATTERN_IGNORE_LENGTH = Pattern.compile("[\\w\\-\\_\\d\\:]+");
- private static final String IMPLEMENTATION = "implementation";
- private static final String INPUTS = "inputs";
- private static final String TYPE = "type";
- private static final String DESCRIPTION = "description";
- private static final String REQUIRED = "required";
- private static final String DEFAULT = "default";
- private static final String STATUS = "status";
+ private final InterfaceDefinitionHandler interfaceDefinitionHandler;
private ServletContext servletContext;
@@ -134,7 +121,6 @@ public class ResourceImportManager {
@Autowired
private ServiceBusinessLogic serviceBusinessLogic;
- private InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
private IGraphLockOperation graphLockOperation;
private ToscaOperationFacade toscaOperationFacade;
@@ -145,9 +131,11 @@ public class ResourceImportManager {
private ResponseFormatManager responseFormatManager;
@Autowired
- public ResourceImportManager(ComponentsUtils componentsUtils, CapabilityTypeOperation capabilityTypeOperation) {
+ public ResourceImportManager(ComponentsUtils componentsUtils, CapabilityTypeOperation capabilityTypeOperation,
+ final InterfaceDefinitionHandler interfaceDefinitionHandler) {
this.componentsUtils = componentsUtils;
this.capabilityTypeOperation = capabilityTypeOperation;
+ this.interfaceDefinitionHandler = interfaceDefinitionHandler;
}
@Autowired
@@ -380,11 +368,9 @@ public class ResourceImportManager {
if (toscaInterfaces.isLeft()) {
Map<String, Object> jsonInterfaces = toscaInterfaces.left().value();
Map<String, InterfaceDefinition> moduleInterfaces = new HashMap<>();
- Iterator<Entry<String, Object>> interfacesNameValue = jsonInterfaces.entrySet().iterator();
- while (interfacesNameValue.hasNext()) {
- Entry<String, Object> interfaceNameValue = interfacesNameValue.next();
- Either<InterfaceDefinition, ResultStatusEnum> eitherInterface = createModuleInterface(interfaceNameValue
- .getValue(), resource);
+ for (final Entry<String, Object> interfaceNameValue : jsonInterfaces.entrySet()) {
+ final Either<InterfaceDefinition, ResultStatusEnum> eitherInterface =
+ createModuleInterface(interfaceNameValue.getValue());
if (eitherInterface.isRight()) {
log.info("error when creating interface:{}, for resource:{}", interfaceNameValue.getKey(),
resource.getName());
@@ -393,165 +379,32 @@ public class ResourceImportManager {
}
}
- if (moduleInterfaces.size() > 0) {
+ if (!moduleInterfaces.isEmpty()) {
resource.setInterfaces(moduleInterfaces);
}
}
}
- private Either<InterfaceDefinition, ResultStatusEnum> createModuleInterface(Object interfaceJson,
- Resource resource) {
- final InterfaceDefinition interf = new InterfaceDefinition();
- Either<InterfaceDefinition, ResultStatusEnum> result = Either.left(interf);
-
+ private Either<InterfaceDefinition, ResultStatusEnum> createModuleInterface(final Object interfaceJson) {
try {
if (interfaceJson instanceof String) {
- final String requirementJsonString = (String) interfaceJson;
- interf.setType(requirementJsonString);
- } else if (interfaceJson instanceof Map && ResourceTypeEnum.VFC.equals(resource.getResourceType())) {
- final Map<String, Object> requirementJsonMap = (Map<String, Object>) interfaceJson;
- final Map<String, OperationDataDefinition> operations = new HashMap<>();
-
- for (final Entry<String, Object> entry : requirementJsonMap.entrySet()) {
- if (entryIsInterfaceType(entry)) {
- final String type = (String) requirementJsonMap
- .get(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName());
- interf.setType(type);
- interf.setUniqueId(type.toLowerCase());
- } else if (entryContainsImplementationForAKnownOperation(entry, interf.getType())) {
-
- final OperationDataDefinition operation = new OperationDataDefinition();
- operation.setName(entry.getKey());
-
- final Map<?, ?> entryValue = (Map<?, ?>) entry.getValue();
- if (entryValue.containsKey(IMPLEMENTATION)) {
- operation.setImplementation(handleOperationImplementation(entry));
- }
- if (entryValue.containsKey(INPUTS)) {
- final Map<String, Object> interfaceInputs = (Map<String, Object>) entryValue
- .get(ToscaTagNamesEnum.INPUTS.getElementName());
- operation.setInputs(handleInterfaceInput(interfaceInputs));
- }
- operations.put(entry.getKey(), operation);
- }
- }
- if (!operations.isEmpty()) {
- interf.setOperations(operations);
- }
- } else {
- result = Either.right(ResultStatusEnum.GENERAL_ERROR);
- }
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeSystemError("Import Resource- create interface");
- log.debug("error when creating interface, message:{}", e.getMessage(), e);
- result = Either.right(ResultStatusEnum.GENERAL_ERROR);
- }
-
- return result;
- }
-
- private ArtifactDataDefinition handleOperationImplementation(final Entry<String, Object> entry) {
- final ArtifactDataDefinition implementation = new ArtifactDataDefinition();
- final String artifactName = ((Map<String, String>) entry.getValue()).get(IMPLEMENTATION);
- if (OperationArtifactUtil.artifactNameIsALiteralValue(artifactName)) {
- implementation.setArtifactName(artifactName);
- } else {
- implementation.setArtifactName(QUOTE + artifactName + QUOTE);
- }
- return implementation;
- }
-
- private ListDataDefinition<OperationInputDefinition> handleInterfaceInput(
- final Map<String, Object> interfaceInputs) {
- final ListDataDefinition<OperationInputDefinition> inputs = new ListDataDefinition<>();
- for (final Entry<String, Object> interfaceInput : interfaceInputs.entrySet()) {
- final OperationInputDefinition operationInput = new OperationInputDefinition();
- operationInput.setName(interfaceInput.getKey());
- if (interfaceInput.getValue() instanceof Map) {
- final LinkedHashMap<String, Object> inputPropertyValue =
- (LinkedHashMap<String, Object>) interfaceInput.getValue();
- log.info("createModuleInterface: i interfaceInput.getKey() {}, {} , {} ",
- interfaceInput.getKey(), inputPropertyValue.keySet(),
- inputPropertyValue.values());
- if (inputPropertyValue.get(TYPE) != null) {
- operationInput.setType(inputPropertyValue.get(TYPE).toString());
- }
- if (inputPropertyValue.get(DESCRIPTION) != null) {
- operationInput.setDescription(inputPropertyValue.get(DESCRIPTION).toString());
- }
- if (inputPropertyValue.get(REQUIRED) != null) {
- operationInput.setRequired(
- Boolean.getBoolean(inputPropertyValue.get(REQUIRED).toString()));
- }
- if (inputPropertyValue.get(DEFAULT) != null) {
- operationInput.setToscaDefaultValue(inputPropertyValue.get(DEFAULT).toString());
- }
- if (inputPropertyValue.get(STATUS) != null) {
- operationInput.setStatus(inputPropertyValue.get(STATUS).toString());
- }
-
- } else if (interfaceInput.getValue() instanceof String) {
- final String value = (String) interfaceInput.getValue();
- operationInput.setDefaultValue(value);
- operationInput.setToscaDefaultValue(value);
- operationInput.setValue(value);
+ final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setType((String) interfaceJson);
+ return Either.left(interfaceDefinition);
}
- inputs.getListToscaDataDefinition().add(operationInput);
- inputs.add(operationInput);
- }
- return inputs;
- }
- private boolean entryIsInterfaceType(final Entry<String, Object> entry) {
- if(entry.getKey().equals(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName())) {
- if (entry.getValue() instanceof String) {
- return true;
+ if (interfaceJson instanceof Map) {
+ final Map<String, Object> interfaceJsonMap = (Map<String, Object>) interfaceJson;
+ final InterfaceDefinition interfaceDefinition = interfaceDefinitionHandler.create(interfaceJsonMap);
+ return Either.left(interfaceDefinition);
}
- throw new ByActionStatusComponentException(ActionStatus.INVALID_YAML);
- }
- return false;
- }
-
- private boolean entryContainsImplementationForAKnownOperation(final Entry<String, Object> entry,
- final String interfaceType) {
- if (entry.getValue() instanceof Map && ((Map<?, ?>)entry.getValue()).containsKey(IMPLEMENTATION)) {
- if (isAKnownOperation(interfaceType, entry.getKey())){
- return true;
- }
- throw new ByActionStatusComponentException(ActionStatus.INTERFACE_OPERATION_NOT_FOUND);
- }
- return false;
- }
-
- private boolean isAKnownOperation(String interfaceType, String operation) {
- Either<Map<String, InterfaceDefinition>, ResponseFormat> interfaceLifecycleTypes = interfaceOperationBusinessLogic
- .getAllInterfaceLifecycleTypes();
- if (interfaceLifecycleTypes.isRight() || interfaceLifecycleTypes.left().value() == null) {
- return false;
- }
- for (Entry<String, InterfaceDefinition> interfaceLifecycleType : interfaceLifecycleTypes.left().value()
- .entrySet()) {
- if (interfaceTypeAndOperationMatches(interfaceLifecycleType, interfaceType, operation)) {
- return true;
- }
- }
- return false;
- }
-
- private boolean interfaceTypeAndOperationMatches(Entry<String, InterfaceDefinition> interfaceLifecycleType,
- String interfaceType, String operation) {
- if (interfaceLifecycleType.getKey().equalsIgnoreCase(interfaceType)
- && interfaceLifecycleType.getValue().getOperations() != null) {
- for (String interfaceLifecycleTypeOperation : interfaceLifecycleType.getValue().getOperations().keySet()) {
- if (interfaceLifecycleTypeOperation != null && interfaceLifecycleTypeOperation
- .equalsIgnoreCase(operation)) {
- return true;
- }
- }
+ return Either.right(ResultStatusEnum.GENERAL_ERROR);
+ } catch (final Exception e) {
+ BeEcompErrorManager.getInstance().logBeSystemError("Import Resource- create interface");
+ log.debug("error when creating interface, message:{}", e.getMessage(), e);
+ return Either.right(ResultStatusEnum.GENERAL_ERROR);
}
- return false;
}
private void setRequirements(Map<String, Object> toscaJson, Resource resource,
@@ -1165,11 +1018,6 @@ public class ResourceImportManager {
this.resourceBusinessLogic = resourceBusinessLogic;
}
- @Autowired
- public void setInterfaceOperationBusinessLogic(InterfaceOperationBusinessLogic interfaceOperationBusinessLogic) {
- this.interfaceOperationBusinessLogic = interfaceOperationBusinessLogic;
- }
-
public IGraphLockOperation getGraphLockOperation() {
return graphLockOperation;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java
index 9e9d834691..1f1dcfed8c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java
@@ -16,10 +16,21 @@
package org.openecomp.sdc.be.tosca;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DEFAULT;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.INPUTS;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.OPERATIONS;
+
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
import org.apache.commons.collections.MapUtils;
+import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
import org.openecomp.sdc.be.model.Component;
@@ -27,30 +38,27 @@ import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Product;
-import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.tosca.PropertyConvertor.PropertyType;
+import org.openecomp.sdc.be.tosca.model.ToscaInput;
import org.openecomp.sdc.be.tosca.model.ToscaInterfaceDefinition;
import org.openecomp.sdc.be.tosca.model.ToscaInterfaceNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaLifecycleOperationDefinition;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
import org.openecomp.sdc.be.tosca.utils.OperationArtifactUtil;
+import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
+import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
@Service
public class InterfacesOperationsConverter {
private static final String DERIVED_FROM_STANDARD_INTERFACE = "tosca.interfaces.node.lifecycle.Standard";
private static final String DERIVED_FROM_BASE_DEFAULT = "org.openecomp.interfaces.node.lifecycle.";
- private static final String OPERATIONS_KEY = "operations";
- private static final String DEFAULT = "default";
private static final String DEFAULT_HAS_UNDERSCORE = "_default";
private static final String DOT = ".";
private static final String DEFAULTP = "defaultp";
@@ -58,10 +66,10 @@ public class InterfacesOperationsConverter {
public static final String SELF = "SELF";
private static final String LOCAL_INTERFACE_TYPE = "Local";
- private PropertyConvertor propertyConvertor;
+ private final PropertyConvertor propertyConvertor;
@Autowired
- public InterfacesOperationsConverter(PropertyConvertor propertyConvertor) {
+ public InterfacesOperationsConverter(final PropertyConvertor propertyConvertor) {
this.propertyConvertor = propertyConvertor;
}
@@ -96,7 +104,7 @@ public class InterfacesOperationsConverter {
}
toscaInterfaceType.setOperations(toscaOperations);
Map<String, Object> interfacesAsMap = getObjectAsMap(toscaInterfaceType);
- Map<String, Object> operationsMap = (Map<String, Object>) interfacesAsMap.remove(OPERATIONS_KEY);
+ Map<String, Object> operationsMap = (Map<String, Object>) interfacesAsMap.remove(OPERATIONS.getElementName());
interfacesAsMap.putAll(operationsMap);
toscaInterfaceTypes.put(getInterfaceType(component, LOCAL_INTERFACE_TYPE), interfacesAsMap);
@@ -134,12 +142,12 @@ public class InterfacesOperationsConverter {
return getInterfacesMap(component, null, component.getInterfaces(), dataTypes, isAssociatedComponent, false);
}
- public Map<String, Object> getInterfacesMap(Component component,
- ComponentInstance componentInstance,
- Map<String, InterfaceDefinition> interfaces,
- Map<String, DataTypeDefinition> dataTypes,
- boolean isAssociatedComponent,
- boolean isServiceProxyInterface) {
+ public Map<String, Object> getInterfacesMap(final Component component,
+ final ComponentInstance componentInstance,
+ final Map<String, InterfaceDefinition> interfaces,
+ final Map<String, DataTypeDefinition> dataTypes,
+ final boolean isAssociatedComponent,
+ final boolean isServiceProxyInterface) {
if(MapUtils.isEmpty(interfaces)) {
return null;
}
@@ -155,7 +163,7 @@ public class InterfacesOperationsConverter {
}
toscaInterfaceDefinition.setType(interfaceType);
final Map<String, OperationDataDefinition> operations = interfaceDefinition.getOperations();
- Map<String, Object> toscaOperations = new HashMap<>();
+ Map<String, Object> toscaOperationMap = new HashMap<>();
String operationArtifactPath;
for (Map.Entry<String, OperationDataDefinition> operationEntry : operations.entrySet()) {
@@ -169,12 +177,20 @@ public class InterfacesOperationsConverter {
toscaOperation.setDescription(operationEntry.getValue().getDescription());
fillToscaOperationInputs(operationEntry.getValue(), dataTypes, toscaOperation, isServiceProxyInterface);
- toscaOperations.put(operationEntry.getValue().getName(), toscaOperation);
+ toscaOperationMap.put(operationEntry.getValue().getName(), toscaOperation);
+ }
+ toscaInterfaceDefinition.setOperations(toscaOperationMap);
+
+ final Map<String, Object> interfaceInputMap = createInterfaceInputMap(interfaceDefinition, dataTypes);
+ if (!interfaceInputMap.isEmpty()) {
+ toscaInterfaceDefinition.setInputs(interfaceInputMap);
}
- toscaInterfaceDefinition.setOperations(toscaOperations);
Map<String, Object> interfaceDefAsMap = getObjectAsMap(toscaInterfaceDefinition);
- Map<String, Object> operationsMap = (Map<String, Object>) interfaceDefAsMap.remove(OPERATIONS_KEY);
+ if (interfaceDefAsMap.containsKey(INPUTS.getElementName())) {
+ handleDefaults((Map<String, Object>) interfaceDefAsMap.get(INPUTS.getElementName()));
+ }
+ Map<String, Object> operationsMap = (Map<String, Object>) interfaceDefAsMap.remove(OPERATIONS.getElementName());
if (isServiceProxyInterface) {
//Remove input type and copy default value directly into the proxy node template from the node type
handleServiceProxyOperationInputValue(operationsMap, interfaceType);
@@ -188,6 +204,22 @@ public class InterfacesOperationsConverter {
return toscaInterfaceDefinitions;
}
+ private Map<String, Object> createInterfaceInputMap(final InterfaceDefinition interfaceDefinition,
+ final Map<String, DataTypeDefinition> allDataTypeMap) {
+ final Map<String, InputDataDefinition> inputMap = interfaceDefinition.getInputs();
+ if (MapUtils.isEmpty(inputMap)) {
+ return Collections.emptyMap();
+ }
+ final Map<String, Object> toscaInterfaceInputMap = new HashMap<>();
+ for (final Entry<String, InputDataDefinition> inputEntry : inputMap.entrySet()) {
+ final InputDataDefinition inputDataDefinition = inputEntry.getValue();
+ final ToscaProperty toscaProperty = propertyConvertor
+ .convertProperty(allDataTypeMap, new PropertyDefinition(inputDataDefinition), PropertyType.INPUT);
+ toscaInterfaceInputMap.put(inputEntry.getKey(), new ToscaInput(toscaProperty));
+ }
+ return toscaInterfaceInputMap;
+ }
+
private static void handleServiceProxyOperationInputValue(Map<String, Object> operationsMap, String parentKey) {
for (Map.Entry<String, Object> operationEntry : operationsMap.entrySet()) {
final Object value = operationEntry.getValue();
@@ -223,7 +255,7 @@ public class InterfacesOperationsConverter {
* ToscaExportHandler so, any string Map key named "defaultp" will have its named changed to "default"
* @param operationsMap the map to update
*/
- private static void handleDefaults(Map<String, Object> operationsMap) {
+ private void handleDefaults(Map<String, Object> operationsMap) {
for (Map.Entry<String, Object> operationEntry : operationsMap.entrySet()) {
final Object value = operationEntry.getValue();
if (value instanceof Map) {
@@ -232,7 +264,7 @@ public class InterfacesOperationsConverter {
final String key = operationEntry.getKey();
if (key.equals(DEFAULTP)) {
Object removed = operationsMap.remove(key);
- operationsMap.put(DEFAULT, removed);
+ operationsMap.put(ToscaTagNamesEnum.DEFAULT.getElementName(), removed);
}
}
}
@@ -314,10 +346,9 @@ public class InterfacesOperationsConverter {
Map<String, Object> objectAsMap =
obj instanceof Map ? (Map<String, Object>) obj : objectMapper.convertValue(obj, Map.class);
- if (objectAsMap.containsKey(DEFAULT)) {
- Object defaultValue = objectAsMap.get(DEFAULT);
- objectAsMap.remove(DEFAULT);
- objectAsMap.put(DEFAULT_HAS_UNDERSCORE, defaultValue);
+ final String defaultEntry = DEFAULT.getElementName();
+ if (objectAsMap.containsKey(defaultEntry)) {
+ objectAsMap.put(DEFAULT_HAS_UNDERSCORE, objectAsMap.remove(defaultEntry));
}
return objectAsMap;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaInterfaceDefinition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaInterfaceDefinition.java
index 1d444e697a..2f4a3d8ac1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaInterfaceDefinition.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaInterfaceDefinition.java
@@ -16,35 +16,20 @@
package org.openecomp.sdc.be.tosca.model;
import java.util.Map;
+import lombok.Getter;
+import lombok.Setter;
/**
* @author KATYR
* @since March 26, 2018
*/
-
+@Setter
+@Getter
public class ToscaInterfaceDefinition {
private String type;
- private Map<String, Object> operations; // ToscaLifecycleOperationDefinition <-> Object
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public Map<String, Object> getOperations() {
- return operations;
- }
-
-// public void setOperations(Map<String, Object> operations) {
-// this.operations = operations;
-// }
+ private Map<String, Object> operations;
+ private Map<String, Object> inputs;
- public void setOperations(Map<String,Object> toscaOperations) {
- this.operations = toscaOperations;
- }
}
diff --git a/catalog-be/src/main/resources/config/error-configuration.yaml b/catalog-be/src/main/resources/config/error-configuration.yaml
index 14b4ece4b0..96bfa245e3 100644
--- a/catalog-be/src/main/resources/config/error-configuration.yaml
+++ b/catalog-be/src/main/resources/config/error-configuration.yaml
@@ -2060,6 +2060,18 @@ errors:
message: "Error: Failed to delete interface operation.",
messageId: "SVC4702"
}
+ #SVC4732
+ INTERFACE_UNKNOWN: {
+ code: 400,
+ message: "Error: The interface '%1' does not exists in the database.",
+ messageId: "SVC4732"
+ }
+ #SVC4733
+ INTERFACE_OPERATION_NOT_DEFINED: {
+ code: 400,
+ message: "Error: The operation '%1' does not exists in the interface '%2'.",
+ messageId: "SVC4733"
+ }
#-----------SVC4692---------------------------
RESOURCE_LIFECYCLE_STATE_NOT_VALID: {
code: 400,
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
index b497253118..336b8ec940 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
@@ -22,7 +22,20 @@
package org.openecomp.sdc.be.components;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -32,6 +45,7 @@ import org.mockito.stubbing.Answer;
import org.openecomp.sdc.be.auditing.impl.AuditingManager;
import org.openecomp.sdc.be.components.impl.ImportUtils;
import org.openecomp.sdc.be.components.impl.ImportUtilsTest;
+import org.openecomp.sdc.be.components.impl.InterfaceDefinitionHandler;
import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
@@ -63,27 +77,15 @@ import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.exception.PolicyException;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
public class ResourceImportManagerTest {
- private static ConfigurationManager configurationManager;
static ResourceImportManager importManager;
static AuditingManager auditingManager = Mockito.mock(AuditingManager.class);
static ResponseFormatManager responseFormatManager = Mockito.mock(ResponseFormatManager.class);
static ResourceBusinessLogic resourceBusinessLogic = Mockito.mock(ResourceBusinessLogic.class);
static InterfaceOperationBusinessLogic interfaceOperationBusinessLogic = Mockito.mock(InterfaceOperationBusinessLogic.class);
+ static InterfaceDefinitionHandler interfaceDefinitionHandler =
+ new InterfaceDefinitionHandler(interfaceOperationBusinessLogic);
static UserBusinessLogic userAdmin = Mockito.mock(UserBusinessLogic.class);
static ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
@@ -93,17 +95,16 @@ public class ResourceImportManagerTest {
@BeforeClass
public static void beforeClass() {
- importManager = new ResourceImportManager(componentsUtils, capabilityTypeOperation);
+ importManager = new ResourceImportManager(componentsUtils, capabilityTypeOperation, interfaceDefinitionHandler);
importManager.setAuditingManager(auditingManager);
when(toscaOperationFacade.getLatestByToscaResourceName(Mockito.anyString())).thenReturn(Either.left(null));
importManager.setResponseFormatManager(responseFormatManager);
importManager.setResourceBusinessLogic(resourceBusinessLogic);
- importManager.setInterfaceOperationBusinessLogic(interfaceOperationBusinessLogic);
importManager.setToscaOperationFacade(toscaOperationFacade);
String appConfigDir = "src/test/resources/config/catalog-be";
ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
- configurationManager = new ConfigurationManager(configurationSource);
+ final ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
Configuration configuration = new Configuration();
configuration.setJanusGraphInMemoryGraph(true);
@@ -223,8 +224,9 @@ public class ResourceImportManagerTest {
interfaceTypes.put("tosca.interfaces.node.lifecycle.standard", interfaceDefinition);
when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(interfaceTypes));
- ImmutablePair<Resource, ActionStatus> createResource = importManager.importNormativeResource(jsonContent, resourceMD, user, true, true);
- testSetInterfaceImplementation(createResource.left);
+ final ImmutablePair<Resource, ActionStatus> createResource = importManager
+ .importNormativeResource(jsonContent, resourceMD, user, true, true);
+ assertSetInterfaceImplementation(createResource.left);
}
@Test
@@ -342,12 +344,12 @@ public class ResourceImportManagerTest {
assertTrue(properties.containsKey("volume_id"));
propertyDefinition = properties.get("volume_id");
assertEquals("string", propertyDefinition.getType());
- assertTrue(!propertyDefinition.isRequired());
+ assertFalse(propertyDefinition.isRequired());
assertTrue(properties.containsKey("snapshot_id"));
propertyDefinition = properties.get("snapshot_id");
assertEquals("string", propertyDefinition.getType());
- assertTrue(!propertyDefinition.isRequired());
+ assertFalse(propertyDefinition.isRequired());
}
@@ -398,20 +400,19 @@ public class ResourceImportManagerTest {
}
- private void testSetInterfaceImplementation(Resource resource) {
- Map<String, InterfaceDefinition> interfaces = resource.getInterfaces();
+ private void assertSetInterfaceImplementation(final Resource resource) {
+ final Map<String, InterfaceDefinition> interfaces = resource.getInterfaces();
assertEquals(1, interfaces.size());
assertTrue(interfaces.containsKey("Standard"));
-
- InterfaceDefinition interfaceDefinition = interfaces.get("Standard");
+
+ final InterfaceDefinition interfaceDefinition = interfaces.get("Standard");
assertEquals("tosca.interfaces.node.lifecycle.Standard", interfaceDefinition.getType());
assertEquals("tosca.interfaces.node.lifecycle.standard", interfaceDefinition.getUniqueId());
- Map<String, OperationDataDefinition> operations = interfaceDefinition.getOperations();
+ final Map<String, OperationDataDefinition> operations = interfaceDefinition.getOperations();
assertEquals(1, operations.size());
- OperationDataDefinition operation = operations.get("configure");
+ final OperationDataDefinition operation = operations.get("configure");
assertEquals("'camunda/vnfConfigure'", operation.getImplementation().getArtifactName());
-
}
private void testSetDerivedFrom(Resource resource) {
@@ -421,19 +422,12 @@ public class ResourceImportManagerTest {
}
private void testSetMetaDataFromJson(Resource resource, UploadResourceInfo resourceMD) {
-
- // assertTrue( resource.getCategory().equals(resourceMD.getCategory())
- // );
assertEquals(resource.getDescription(), resourceMD.getDescription());
assertEquals(resource.getIcon(), resourceMD.getResourceIconPath());
assertEquals(resource.getName(), resourceMD.getName());
assertEquals(resource.getResourceVendorModelNumber(), resourceMD.getResourceVendorModelNumber());
assertEquals(resource.getContactId(), resourceMD.getContactId());
assertEquals(resource.getCreatorUserId(), resourceMD.getContactId());
-
- // assertTrue( resource.isAbstract() ==
- // Constants.ABSTRACT_CATEGORY.equals(resourceMD.getCategory()));
-
assertEquals(resourceMD.getTags().size(), resource.getTags().size());
for (String tag : resource.getTags()) {
assertTrue(resourceMD.getTags().contains(tag));
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ImportUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ImportUtilsTest.java
index 87875d8f20..9cd095b5b5 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ImportUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ImportUtilsTest.java
@@ -324,7 +324,7 @@ public class ImportUtilsTest {
PropertyDefinition property = properties.get("service_type");
assertTrue(property.getConstraints()!= null && property.getConstraints().size() == 1);
assertTrue(property.getConstraints().get(0) instanceof ValidValuesConstraint);
- assertTrue(((ValidValuesConstraint) property.getConstraints().get(0)).getValidValues() != null);
+ assertNotNull(((ValidValuesConstraint) property.getConstraints().get(0)).getValidValues());
List<String> validValues = ((ValidValuesConstraint) property.getConstraints().get(0)).getValidValues();
assertTrue(validValues.containsAll(Lists.newArrayList("firewall", "analyzer", "source-nat", "loadbalancer")));
@@ -334,7 +334,7 @@ public class ImportUtilsTest {
PropertyDefinition innerProperty = new PropertyDefinition(property.getSchema().getProperty());
List<PropertyConstraint> innerConstraints = innerProperty.getConstraints();
assertTrue(innerConstraints.get(0) instanceof ValidValuesConstraint);
- assertTrue(((ValidValuesConstraint) innerConstraints.get(0)).getValidValues() != null);
+ assertNotNull(((ValidValuesConstraint) innerConstraints.get(0)).getValidValues());
validValues = ((ValidValuesConstraint) innerConstraints.get(0)).getValidValues();
assertTrue(validValues.containsAll(Lists.newArrayList("management", "left", "right", "other")));
}
@@ -352,6 +352,10 @@ public class ImportUtilsTest {
Map<String, Map<String, Object>> expectedProperties = getElements(toscaJson, TypeUtils.ToscaTagNamesEnum.INPUTS);
compareProperties(expectedProperties, actualInputs.left().value());
+ actualInputs = ImportUtils.getInputs(toscaJson);
+ assertTrue(actualInputs.isLeft());
+ expectedProperties = getElements(toscaJson, TypeUtils.ToscaTagNamesEnum.INPUTS);
+ compareProperties(expectedProperties, actualInputs.left().value());
}
private void compareAttributes(Map<String, Map<String, Object>> expected, Map<String, AttributeDataDefinition> actual) {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandlerTest.java
new file mode 100644
index 0000000000..f819eceb43
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandlerTest.java
@@ -0,0 +1,174 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.aMapWithSize;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.Mockito.when;
+
+import fj.data.Either;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.commons.collections.MapUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.yaml.snakeyaml.Yaml;
+
+@ExtendWith(MockitoExtension.class)
+class InterfaceDefinitionHandlerTest {
+
+ @Mock
+ private InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
+ private InterfaceDefinitionHandler interfaceDefinitionHandler;
+ private InterfaceDefinition interfaceLifecyleStandard;
+ private static final Path TEST_RESOURCE_PATH = Paths.get("src/test/resources/interfaceDefinition");
+ private static final String CREATE_OPERATION = "create";
+ private static final String DELETE_OPERATION = "delete";
+ private static final String START_OPERATION = "start";
+ private static final String STOP_OPERATION = "stop";
+ private static final String INTERFACE_TYPE = "tosca.interfaces.node.lifecycle.Standard";
+
+ @BeforeEach
+ void setUp() {
+ interfaceDefinitionHandler = new InterfaceDefinitionHandler(interfaceOperationBusinessLogic);
+ mockAllInterfacesLifecycle();
+ }
+
+ private void mockAllInterfacesLifecycle() {
+ final Map<String, InterfaceDefinition> interfaceTypes = new HashMap<>();
+ interfaceLifecyleStandard = new InterfaceDefinition();
+ interfaceLifecyleStandard.setType(INTERFACE_TYPE);
+ final Map<String, OperationDataDefinition> operations = new HashMap<>();
+ operations.put(CREATE_OPERATION, new OperationDataDefinition());
+ operations.put(START_OPERATION, new OperationDataDefinition());
+ operations.put(STOP_OPERATION, new OperationDataDefinition());
+ operations.put(DELETE_OPERATION, new OperationDataDefinition());
+ interfaceLifecyleStandard.setOperations(operations);
+ interfaceTypes.put(INTERFACE_TYPE, interfaceLifecyleStandard);
+ when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(interfaceTypes));
+ }
+
+ @Test
+ void testCreateWithLegacyOperationDeclarationSuccess() throws FileNotFoundException {
+ final Map<String, Object> load = loadYaml(Paths.get("interfaceDefinition-legacy.yaml"));
+ final InterfaceDefinition actualInterfaceDefinition = interfaceDefinitionHandler.create(load);
+ assertInterfaceDefinition(actualInterfaceDefinition);
+ }
+
+ @Test
+ void testCreateWithOperationSuccess() throws FileNotFoundException {
+ final Map<String, Object> load = loadYaml(Paths.get("interfaceDefinition-tosca1.3.yaml"));
+ final InterfaceDefinition actualInterfaceDefinition = interfaceDefinitionHandler.create(load);
+ assertInterfaceDefinition(actualInterfaceDefinition);
+ }
+
+ private void assertInterfaceDefinition(final InterfaceDefinition actualInterfaceDefinition) {
+ interfaceLifecyleStandard.getOperations().keySet().forEach(operation ->
+ assertTrue(actualInterfaceDefinition.hasOperation(operation)));
+ assertThat("Interface type should be as expected", actualInterfaceDefinition.getType(),
+ equalTo(actualInterfaceDefinition.getType()));
+ assertThat("Interface should contain 2 inputs", actualInterfaceDefinition.getInputs(), aMapWithSize(2));
+ assertThat("Interface inputs should be as expected", actualInterfaceDefinition.getInputs().keySet(),
+ containsInAnyOrder("stringInput", "actionInput"));
+
+ final InputDataDefinition stringInput = actualInterfaceDefinition.getInputs().get("stringInput");
+ assertInput("string", "stringInput description", true, "defaultValue", "aStatus", stringInput);
+ final InputDataDefinition actionInput = actualInterfaceDefinition.getInputs().get("actionInput");
+ assertInput("org.openecomp.resource.datatypes.Action", null, false, null, null, actionInput);
+
+ final OperationDataDefinition createOperation = actualInterfaceDefinition.getOperations().get(CREATE_OPERATION);
+ assertOperation("'camunda/serviceSelect'", createOperation);
+
+ final OperationDataDefinition deleteOperation = actualInterfaceDefinition.getOperations().get(DELETE_OPERATION);
+ assertOperation("'camunda/serviceDeselect'", deleteOperation);
+
+ final Map<String, String> expectedInputMap = new HashMap<>();
+ expectedInputMap.put("action", "org.openecomp.resource.datatypes.Action");
+ final OperationDataDefinition startOperation = actualInterfaceDefinition.getOperations().get(START_OPERATION);
+ assertOperation("'camunda/executeAction'", expectedInputMap, startOperation);
+ final OperationDataDefinition stopOperation = actualInterfaceDefinition.getOperations().get(STOP_OPERATION);
+ assertOperation("'camunda/executeAction'", expectedInputMap, stopOperation);
+ }
+
+ private void assertOperation(final String implementation, final OperationDataDefinition actualOperation) {
+ assertOperation(implementation, Collections.emptyMap(), actualOperation);
+ }
+
+ private void assertOperation(final String implementation, final Map<String, String> inputNameTypeMap,
+ final OperationDataDefinition actualOperation) {
+ final ArtifactDataDefinition artifactDefinition = actualOperation.getImplementation();
+ assertThat("Implementation should be as expected", artifactDefinition.getArtifactName(), equalTo(implementation));
+ final ListDataDefinition<OperationInputDefinition> inputListDataDef = actualOperation.getInputs();
+ if (inputListDataDef == null) {
+ if (MapUtils.isNotEmpty(inputNameTypeMap)) {
+ final String expectedInputNames = String.join(",", inputNameTypeMap.keySet());
+ fail(String.format("No inputs were found, but some inputs are expected: %s", expectedInputNames));
+ }
+ return;
+ }
+
+ final String msgFormat = "Operation should have %s";
+ final List<OperationInputDefinition> inputList = inputListDataDef.getListToscaDataDefinition();
+ assertThat(String.format(msgFormat, "the expected quantity of inputs"), inputList, hasSize(inputNameTypeMap.size()));
+
+ final List<String> inputNames = inputList.stream()
+ .map(OperationInputDefinition::getName).collect(Collectors.toList());
+
+ assertThat(String.format(msgFormat, "the expected inputs"), inputNames,
+ hasItems(inputNameTypeMap.keySet().toArray(new String[0])));
+ }
+
+ private void assertInput(final String type, final String description, final Boolean required,
+ final String defaultValue, final String status, final InputDataDefinition actualInput) {
+ assertThat("Input type should be as expected", type, equalTo(actualInput.getType()));
+ assertThat("Input description should be as expected", description, equalTo(actualInput.getDescription()));
+ assertThat("Input required should be as expected", required, equalTo(required != null && required));
+ assertThat("Input default should be as expected", defaultValue, equalTo(actualInput.getDefaultValue()));
+ assertThat("Input status should be as expected", status, equalTo(actualInput.getStatus()));
+ }
+
+ private Map<String, Object> loadYaml(final Path filePathFromResource) throws FileNotFoundException {
+ final Path filePath = Paths.get(TEST_RESOURCE_PATH.toString(), filePathFromResource.toString());
+ final FileInputStream fileInputStream = new FileInputStream(filePath.toString());
+ return (Map<String, Object>) new Yaml().load(fileInputStream);
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
index 93a45ad20f..0281317b89 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsConverterTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
@@ -1,24 +1,42 @@
/*
- * Copyright © 2016-2018 European Support Limited
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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
*
- * 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.
*
- * 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.
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
*/
-package org.openecomp.sdc.be.tosca.utils;
-
-import static org.mockito.Mockito.mock;
+package org.openecomp.sdc.be.tosca;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.openecomp.sdc.be.tosca.InterfacesOperationsConverter.SELF;
import static org.openecomp.sdc.be.tosca.InterfacesOperationsConverter.addInterfaceTypeElement;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DEFAULT;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DESCRIPTION;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.INPUTS;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.INTERFACES;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE_TYPES;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.REQUIRED;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.TYPE;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -28,23 +46,23 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Objects;
import java.util.function.Function;
+import java.util.stream.Collectors;
import org.apache.commons.collections4.MapUtils;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.be.DummyConfigurationManager;
-import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
@@ -52,44 +70,40 @@ import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.ServiceMetadataDefinition;
-import org.openecomp.sdc.be.tosca.InterfacesOperationsConverter;
-import org.openecomp.sdc.be.tosca.PropertyConvertor;
-import org.openecomp.sdc.be.tosca.ToscaExportHandler;
-import org.openecomp.sdc.be.tosca.ToscaRepresentation;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
import org.openecomp.sdc.common.util.YamlToObjectConverter;
import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
+import org.yaml.snakeyaml.Yaml;
-@RunWith(MockitoJUnitRunner.class)
-public class InterfacesOperationsConverterTest {
+class InterfacesOperationsConverterTest {
private static final String MAPPED_PROPERTY_NAME = "mapped_property";
private static final String INPUT_NAME_PREFIX = "input_";
private static final String OUTPUT_NAME_PREFIX = "output_";
private static final String NODE_TYPE_NAME = "test";
- private String[] inputTypes = {"string", "integer", "float", "boolean"};
+ private final String[] inputTypes = {"string", "integer", "float", "boolean"};
private static ObjectMapper mapper;
- private Configuration.EnvironmentContext environmentContext = mock(Configuration.EnvironmentContext.class);
- DummyConfigurationManager dummyConfigurationManager = new DummyConfigurationManager();
private static final Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
private InterfacesOperationsConverter interfacesOperationsConverter;
- @BeforeClass
+ @BeforeAll
public static void setUp() {
+ //initialize the static configuration manager
+ new DummyConfigurationManager();
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
- @Before
+ @BeforeEach
public void setUpBeforeTest() {
interfacesOperationsConverter =
new InterfacesOperationsConverter(new PropertyConvertor());
}
@Test
- public void addInterfaceTypeElementToResource() {
+ void addInterfaceTypeElementToResource() {
Component component = new Resource();
component.setNormalizedName("normalizedComponentName");
component.setComponentMetadataDefinition(new ServiceMetadataDefinition());
@@ -110,14 +124,14 @@ public class InterfacesOperationsConverterTest {
template.setInterface_types(interfaceTypeElement);
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
- Assert.assertTrue(all(
+ assertTrue(all(
containsAll("NodeTypeName"),
containsNone("operations")
).apply(new String(toscaRepresentation.getMainYaml())));
}
@Test
- public void addInterfaceTypeElementToService() {
+ void addInterfaceTypeElementToService() {
Component component = new Service();
component.setNormalizedName("normalizedServiceComponentName");
component.setComponentMetadataDefinition(new ServiceMetadataDefinition());
@@ -138,14 +152,14 @@ public class InterfacesOperationsConverterTest {
template.setInterface_types(interfaceTypeElement);
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
- Assert.assertTrue(all(
+ assertTrue(all(
containsAll("NodeTypeName"),
containsNone("operations")
).apply(new String(toscaRepresentation.getMainYaml())));
}
@Test
- public void addInterfaceDefinitionElementToResource() {
+ void addInterfaceDefinitionElementToResource() {
Component component = new Resource();
component.setNormalizedName("normalizedComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
@@ -167,7 +181,7 @@ public class InterfacesOperationsConverterTest {
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
String mainYaml = new String(toscaRepresentation.getMainYaml());
- Assert.assertTrue(all(
+ assertTrue(all(
containsAll("resourceName:", "inputs:", "has description", MAPPED_PROPERTY_NAME, "com.some.resource.or.other.resourceName"),
containsNone("operations", "defaultp")
).apply(mainYaml));
@@ -176,7 +190,7 @@ public class InterfacesOperationsConverterTest {
}
@Test
- public void addInterfaceDefinitionElementToService() {
+ void addInterfaceDefinitionElementToService() {
Component component = new Service();
component.setNormalizedName("normalizedServiceComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
@@ -196,7 +210,7 @@ public class InterfacesOperationsConverterTest {
template.setNode_types(nodeTypes);
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
String mainYaml = new String(toscaRepresentation.getMainYaml());
- Assert.assertTrue(all(
+ assertTrue(all(
containsAll("serviceName", "inputs:", "has description", MAPPED_PROPERTY_NAME, "com.some.service.or.other.serviceName"),
containsNone("operations", "defaultp")
).apply(mainYaml));
@@ -205,7 +219,7 @@ public class InterfacesOperationsConverterTest {
@Test
- public void testGetInterfaceAsMapServiceProxy() {
+ void testGetInterfaceAsMapServiceProxy() {
Component component = new Resource();
component.setNormalizedName("normalizedComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
@@ -227,7 +241,7 @@ public class InterfacesOperationsConverterTest {
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
String mainYaml = new String(toscaRepresentation.getMainYaml());
- Assert.assertTrue(all(
+ assertTrue(all(
containsAll("resourceName:", "inputs:", "has description", MAPPED_PROPERTY_NAME, "com.some.resource.or.other.resourceName"),
containsNone("operations", "defaultp")
).apply(mainYaml));
@@ -235,7 +249,7 @@ public class InterfacesOperationsConverterTest {
}
@Test
- public void addInterfaceDefinitionElement_noInputs() {
+ void addInterfaceDefinitionElement_noInputs() {
Component component = new Resource();
component.setNormalizedName("normalizedComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
@@ -255,14 +269,14 @@ public class InterfacesOperationsConverterTest {
template.setNode_types(nodeTypes);
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
- Assert.assertTrue(all(
+ assertTrue(all(
containsAll("resourceNameNoInputs", "has description", "com.some.resource.or.other.resourceName"),
containsNone("operations", INPUT_NAME_PREFIX, "defaultp")
).apply(new String(toscaRepresentation.getMainYaml())));
}
@Test
- public void addInterfaceDefinitionElementInputMappedToOtherOperationOutput() {
+ void addInterfaceDefinitionElementInputMappedToOtherOperationOutput() {
String addedInterfaceType = "com.some.resource.or.other.resourceNameInputMappedToOutput";
Component component = new Resource();
component.setNormalizedName("normalizedComponentName");
@@ -289,7 +303,7 @@ public class InterfacesOperationsConverterTest {
template.setNode_types(nodeTypes);
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
String mainYaml = new String(toscaRepresentation.getMainYaml());
- Assert.assertTrue(all(
+ assertTrue(all(
containsAll("resourceNameInputMappedToOutput:", "inputs:"),
containsNone("operations")
).apply(mainYaml));
@@ -297,7 +311,7 @@ public class InterfacesOperationsConverterTest {
}
@Test
- public void addInterfaceDefinitionElementInputMappedToOtherOperationOutputFromOtherInterface() {
+ void addInterfaceDefinitionElementInputMappedToOtherOperationOutputFromOtherInterface() {
String addedInterfaceType = "com.some.resource.or.other.resourceNameInputMappedToOutput";
Component component = new Resource();
component.setNormalizedName("normalizedComponentName");
@@ -339,13 +353,83 @@ public class InterfacesOperationsConverterTest {
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
String mainYaml = new String(toscaRepresentation.getMainYaml());
- Assert.assertTrue(all(
+ assertTrue(all(
containsAll("resourceNameInputMappedToOutput:", "inputs:"),
containsNone("operations")
).apply(mainYaml));
validateOperationInputs(mainYaml, 2, "name_for_op_1");
}
+ @Test
+ void interfaceWithInputsToscaExportTest() {
+ final Component component = new Service();
+ final InterfaceDefinition aInterfaceWithInput = new InterfaceDefinition();
+ final String interfaceName = "myInterfaceName";
+ final String interfaceType = "my.type." + interfaceName;
+ aInterfaceWithInput.setType(interfaceType);
+ final String input1Name = "input1";
+ final InputDataDefinition input1 = createInput("string", "input1 description", false, "input1 value");
+ final String input2Name = "input2";
+ final InputDataDefinition input2 = createInput("string", "input2 description", true, "input2 value");
+ final Map<String, InputDataDefinition> inputMap = new HashMap<>();
+ inputMap.put(input1Name, input1);
+ inputMap.put(input2Name, input2);
+ aInterfaceWithInput.setInputs(inputMap);
+ component.setInterfaces(new HashMap<>());
+ component.getInterfaces().put(interfaceName, aInterfaceWithInput);
+ final ToscaNodeType nodeType = new ToscaNodeType();
+ interfacesOperationsConverter.addInterfaceDefinitionElement(component, nodeType, dataTypes, false);
+ final ToscaExportHandler handler = new ToscaExportHandler(null, null, null, null, null, null, null, null,
+ interfacesOperationsConverter);
+ final ToscaTemplate template = new ToscaTemplate("testService");
+ final Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
+ nodeTypes.put(NODE_TYPE_NAME, nodeType);
+ template.setNode_types(nodeTypes);
+ final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
+ final String toscaTemplateYaml = new String(toscaRepresentation.getMainYaml());
+ assertThat(toscaTemplateYaml, allOf(containsString(INPUTS.getElementName() + ":"), containsString(input1Name), containsString(interfaceName)));
+ validateInterfaceInputs(toscaTemplateYaml, interfaceName, inputMap);
+ }
+
+ private void validateInterfaceInputs(final String yaml, final String interfaceName, final Map<String, InputDataDefinition> expectedInputMap) {
+ String fixedMainYaml = yaml;
+ final String nullString = "null";
+ if (fixedMainYaml.startsWith(nullString)) {
+ fixedMainYaml = yaml.substring(nullString.length());
+ }
+ if (fixedMainYaml.endsWith(nullString)) {
+ fixedMainYaml = fixedMainYaml.substring(0, fixedMainYaml.length() - nullString.length());
+ }
+ final Map<String, Object> yamlMap = (Map<String, Object>) new Yaml().load(fixedMainYaml);
+ final Map<String, Object> nodeTypesMap = (Map<String, Object>) yamlMap.get(NODE_TYPES.getElementName());
+ final Map<String, Object> node = (Map<String, Object>) nodeTypesMap.get(NODE_TYPE_NAME);
+ final Map<String, Object> interfacesMap = (Map<String, Object>) node.get(INTERFACES.getElementName());
+ final Map<String, Object> interface1 = (Map<String, Object>) interfacesMap.get(interfaceName);
+ final Map<String, Object> actualInputsMap = (Map<String, Object>) interface1.get(INPUTS.getElementName());
+ assertThat(actualInputsMap.keySet(), containsInAnyOrder(expectedInputMap.keySet().toArray()));
+ expectedInputMap.forEach((inputName, inputDataDefinition) -> {
+ final Map<String, Object> actualInput = (Map<String, Object>) actualInputsMap.get(inputName);
+ compareInputYaml(inputName, actualInput, inputDataDefinition);
+ });
+ }
+
+ private void compareInputYaml(final String inputName, final Map<String, Object> actualInput,
+ final InputDataDefinition expectedInput) {
+ final String msgFormat = "%s should be equal in input %s";
+ String field = TYPE.getElementName();
+ assertThat(String.format(msgFormat, field, inputName),
+ actualInput.get(field), equalTo(expectedInput.getType()));
+ field = DESCRIPTION.getElementName();
+ assertThat(String.format(msgFormat, field, inputName),
+ actualInput.get(field), equalTo(expectedInput.getDescription()));
+ field = REQUIRED.getElementName();
+ assertThat(String.format(msgFormat, field, inputName),
+ actualInput.get(field), equalTo(expectedInput.getRequired()));
+ field = DEFAULT.getElementName();
+ assertThat(String.format(msgFormat, field, inputName),
+ actualInput.get(field), equalTo(expectedInput.getDefaultValue()));
+ }
+
@FunctionalInterface
interface MainYamlAssertion extends Function<String, Boolean> {}
@@ -383,6 +467,24 @@ public class InterfacesOperationsConverterTest {
}
}
+ private InputDataDefinition createInput(final String type, final String description, final Boolean isRequired,
+ final String defaultValue) {
+ final PropertyDataDefinition propertyDataDefinition = new PropertyDataDefinition();
+ if (type != null) {
+ propertyDataDefinition.setType(type);
+ }
+ if (description != null) {
+ propertyDataDefinition.setDescription(description);
+ }
+ if (defaultValue != null) {
+ propertyDataDefinition.setDefaultValue(defaultValue);
+ }
+ if (isRequired != null) {
+ propertyDataDefinition.setRequired(isRequired);
+ }
+ return new InputDataDefinition(propertyDataDefinition);
+ }
+
private ListDataDefinition<OperationInputDefinition> createInputs(Component component, int numOfInputs) {
ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
for (int i = 0; i < numOfInputs; i++) {
@@ -458,7 +560,11 @@ public class InterfacesOperationsConverterTest {
Map<String, Object> interfaces = toscaNodeType.getInterfaces();
for (Map.Entry<String, Object> interfaceEntry : interfaces.entrySet()) {
Map<String, Object> interfaceDefinition = mapper.convertValue(interfaceEntry.getValue(), Map.class);
- for (Map.Entry<String, Object> operationEntry : interfaceDefinition.entrySet()) {
+ final Map<String, Object> operationsMap = interfaceDefinition.entrySet().stream()
+ .filter(entry -> !INPUTS.getElementName().equals(entry.getKey()) &&
+ !TYPE.getElementName().equals(entry.getKey()))
+ .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
+ for (Map.Entry<String, Object> operationEntry : operationsMap.entrySet()) {
Object operationVal = operationEntry.getValue();
if (operationVal instanceof Map) {
//Since the inputs are mapped to output operations from only first interface so using that name
@@ -475,9 +581,9 @@ public class InterfacesOperationsConverterTest {
for (Map.Entry<String, Object> inputEntry : inputs.entrySet()) {
String[] inputNameSplit = inputEntry.getKey().split("_");
Map<String, Object> inputValueObject = (Map<String, Object>) inputEntry.getValue();
- Assert.assertEquals(inputNameSplit[1], inputValueObject.get("type"));
+ assertEquals(inputNameSplit[1], inputValueObject.get("type"));
Boolean expectedIsRequired = Integer.parseInt(inputNameSplit[2]) % 2 == 0;
- Assert.assertEquals(expectedIsRequired, inputValueObject.get("required"));
+ assertEquals(expectedIsRequired, inputValueObject.get("required"));
validateOperationInputDefinitionDefaultValue(interfaceType, operationName, inputNameSplit[1],
Integer.parseInt(inputNameSplit[2]), inputValueObject);
}
@@ -491,19 +597,19 @@ public class InterfacesOperationsConverterTest {
if(mappedInputValue.containsKey(ToscaFunctions.GET_PROPERTY.getFunctionName())) {
String mappedPropertyValue = MAPPED_PROPERTY_NAME + index;
List<String> mappedPropertyDefaultValue = (List<String>) mappedInputValue.get(ToscaFunctions.GET_PROPERTY.getFunctionName());
- Assert.assertEquals(2, mappedPropertyDefaultValue.size());
- Assert.assertTrue(mappedPropertyDefaultValue.contains(SELF));
- Assert.assertTrue(mappedPropertyDefaultValue.contains(mappedPropertyValue));
+ assertEquals(2, mappedPropertyDefaultValue.size());
+ assertTrue(mappedPropertyDefaultValue.contains(SELF));
+ assertTrue(mappedPropertyDefaultValue.contains(mappedPropertyValue));
} else if(mappedInputValue.containsKey(ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName())) {
List<String> mappedPropertyDefaultValue = (List<String>) mappedInputValue.get(ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName());
- Assert.assertEquals(4, mappedPropertyDefaultValue.size());
+ assertEquals(4, mappedPropertyDefaultValue.size());
String mappedPropertyValue = OUTPUT_NAME_PREFIX + inputType + "_" + index;
- Assert.assertTrue(mappedPropertyDefaultValue.contains(SELF));
- Assert.assertTrue(mappedPropertyDefaultValue.contains(interfaceType));
- Assert.assertTrue(mappedPropertyDefaultValue.contains(operationName));
- Assert.assertTrue(mappedPropertyDefaultValue.contains(mappedPropertyValue));
+ assertTrue(mappedPropertyDefaultValue.contains(SELF));
+ assertTrue(mappedPropertyDefaultValue.contains(interfaceType));
+ assertTrue(mappedPropertyDefaultValue.contains(operationName));
+ assertTrue(mappedPropertyDefaultValue.contains(mappedPropertyValue));
} else {
- Assert.fail("Invalid Tosca function in default value. Allowed values: "+ ToscaFunctions.GET_PROPERTY.getFunctionName() +
+ fail("Invalid Tosca function in default value. Allowed values: "+ ToscaFunctions.GET_PROPERTY.getFunctionName() +
"/"+ ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName());
}
}
@@ -522,9 +628,9 @@ public class InterfacesOperationsConverterTest {
Map<String, Object> operationInputs = (Map<String, Object>) operation.get("inputs");
for (Object inputValue : operationInputs.values()) {
Map<String, Object> inputValueAsMap = (Map<String, Object>) inputValue;
- Assert.assertFalse(inputValueAsMap.keySet().contains("type"));
- Assert.assertFalse(inputValueAsMap.keySet().contains("required"));
- Assert.assertFalse(inputValueAsMap.keySet().contains("default"));
+ assertFalse(inputValueAsMap.keySet().contains("type"));
+ assertFalse(inputValueAsMap.keySet().contains("required"));
+ assertFalse(inputValueAsMap.keySet().contains("default"));
}
}
}
@@ -532,7 +638,7 @@ public class InterfacesOperationsConverterTest {
}
@Test
- public void testAddInterfaceTypeElementGetCorrectLocalInterfaceName() {
+ void testAddInterfaceTypeElementGetCorrectLocalInterfaceName() {
Service service = new Service();
service.setComponentMetadataDefinition(new ServiceMetadataDefinition());
service.getComponentMetadataDefinition().getMetadataDataDefinition().setName("LocalInterface");
@@ -542,12 +648,12 @@ public class InterfacesOperationsConverterTest {
Map<String, Object> resultMap = InterfacesOperationsConverter.addInterfaceTypeElement(service,
Collections.singletonList("org.openecomp.interfaces.node.lifecycle.Standard"));
- Assert.assertTrue(MapUtils.isNotEmpty(resultMap)
+ assertTrue(MapUtils.isNotEmpty(resultMap)
&& resultMap.containsKey("org.openecomp.interfaces.node.lifecycle.LocalInterface"));
}
@Test
- public void testAddInterfaceTypeElementNoTypeChangeIfNotLocal() {
+ void testAddInterfaceTypeElementNoTypeChangeIfNotLocal() {
Service service = new Service();
service.setComponentMetadataDefinition(new ServiceMetadataDefinition());
service.getComponentMetadataDefinition().getMetadataDataDefinition().setName("LocalInterface");
@@ -557,7 +663,7 @@ public class InterfacesOperationsConverterTest {
Map<String, Object> resultMap = interfacesOperationsConverter.getInterfacesMap(service, null,
service.getInterfaces(), null, false, false);
- Assert.assertTrue(MapUtils.isNotEmpty(resultMap)
+ assertTrue(MapUtils.isNotEmpty(resultMap)
&& resultMap.containsKey("NotLocal"));
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaInterfaceDefinitionTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaInterfaceDefinitionTest.java
deleted file mode 100644
index b922d0d60d..0000000000
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaInterfaceDefinitionTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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.openecomp.sdc.be.tosca.model;
-
-import org.junit.Test;
-
-import java.util.Map;
-
-public class ToscaInterfaceDefinitionTest {
-
- private ToscaInterfaceDefinition createTestSubject() {
- return new ToscaInterfaceDefinition();
- }
-
- @Test
- public void testGetType() throws Exception {
- ToscaInterfaceDefinition testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getType();
- }
-
- @Test
- public void testSetType() throws Exception {
- ToscaInterfaceDefinition testSubject;
- String type = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setType(type);
- }
-
- @Test
- public void testGetOperations() throws Exception {
- ToscaInterfaceDefinition testSubject;
- Map<String, Object> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getOperations();
- }
-
- @Test
- public void testSetOperations() throws Exception {
- ToscaInterfaceDefinition testSubject;
- Map<String, Object> toscaOperations = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setOperations(toscaOperations);
- }
-}
diff --git a/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml
index a28f31b1b0..50906d2624 100644
--- a/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml
+++ b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml
@@ -2038,6 +2038,18 @@ errors:
message: "Error: Failed to delete interface operation.",
messageId: "SVC4702"
}
+ #SVC4732
+ INTERFACE_UNKNOWN: {
+ code: 400,
+ message: "Error: The interface '%1' does not exists in the database.",
+ messageId: "SVC4732"
+ }
+ #SVC4733
+ INTERFACE_OPERATION_NOT_DEFINED: {
+ code: 400,
+ message: "Error: The operation '%1' does not exists in the interface '%2'.",
+ messageId: "SVC4733"
+ }
#-----------SVC4692---------------------------
RESOURCE_LIFECYCLE_STATE_NOT_VALID: {
code: 400,
diff --git a/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml
new file mode 100644
index 0000000000..d12664be9d
--- /dev/null
+++ b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml
@@ -0,0 +1,24 @@
+inputs:
+ stringInput:
+ type: string
+ description: stringInput description
+ required: true
+ default: defaultValue
+ status: aStatus
+ actionInput:
+ type: org.openecomp.resource.datatypes.Action
+type: tosca.interfaces.node.lifecycle.Standard
+create:
+ implementation: "camunda/serviceSelect"
+start:
+ implementation: "camunda/executeAction"
+ inputs:
+ action:
+ type: org.openecomp.resource.datatypes.Action
+stop:
+ implementation: "camunda/executeAction"
+ inputs:
+ action:
+ type: org.openecomp.resource.datatypes.Action
+delete:
+ implementation: "camunda/serviceDeselect" \ No newline at end of file
diff --git a/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-tosca1.3.yaml b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-tosca1.3.yaml
new file mode 100644
index 0000000000..13dfb9a1fb
--- /dev/null
+++ b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-tosca1.3.yaml
@@ -0,0 +1,25 @@
+inputs:
+ stringInput:
+ type: string
+ description: stringInput description
+ required: true
+ default: defaultValue
+ status: aStatus
+ actionInput:
+ type: org.openecomp.resource.datatypes.Action
+type: tosca.interfaces.node.lifecycle.Standard
+operations:
+ create:
+ implementation: "camunda/serviceSelect"
+ start:
+ implementation: "camunda/executeAction"
+ inputs:
+ action:
+ type: org.openecomp.resource.datatypes.Action
+ stop:
+ implementation: "camunda/executeAction"
+ inputs:
+ action:
+ type: org.openecomp.resource.datatypes.Action
+ delete:
+ implementation: "camunda/serviceDeselect" \ No newline at end of file