aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java9
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java17
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java70
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java43
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java102
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java18
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java38
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java14
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java14
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ImportUtilsTest.java178
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java121
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java49
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java63
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java79
-rw-r--r--catalog-be/src/test/resources/normativeTypes/importToscaInputsOutputs.yml (renamed from catalog-be/src/test/resources/normativeTypes/importToscaInputs.yml)404
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/OutputDefinition.java8
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java15
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java58
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperationTest.java137
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java308
-rw-r--r--catalog-ui/src/app/models/attributes-outputs/output-be-model.ts8
-rw-r--r--catalog-ui/src/app/models/attributes-outputs/output-fe-model.ts14
-rw-r--r--common-app-api/pom.xml6
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/AttributeDataDefinition.java2
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java4
-rw-r--r--pom.xml4
27 files changed, 1095 insertions, 689 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java
index 79bfcc6df7..394d6b314b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/attribute/DefaultAttributeDeclarator.java
@@ -25,7 +25,6 @@ import com.google.gson.Gson;
import fj.data.Either;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -182,7 +181,7 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie
outputDefinition.setOutputPath(attributesName);
outputDefinition.setInstanceUniqueId(propertiesOwner.getUniqueId());
outputDefinition.setAttributeId(attributeOutput.getUniqueId());
- outputDefinition.setAttributes(Arrays.asList(attributeOutput));
+ outputDefinition.setAttribute(attributeOutput);
if (attribute instanceof IComponentInstanceConnectedElement) {
((IComponentInstanceConnectedElement) attribute).setComponentInstanceId(propertiesOwner.getUniqueId());
((IComponentInstanceConnectedElement) attribute).setComponentInstanceName(propertiesOwner.getName());
@@ -201,7 +200,7 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie
attributeDataDefinition.setValue(jsonObject.toJSONString());
} else {
jsonObject
- .put(GET_ATTRIBUTE, Arrays.asList(output.getAttributes().get(0).getComponentInstanceName(), attributeDataDefinition.getName()));
+ .put(GET_ATTRIBUTE, Arrays.asList(output.getAttribute().getComponentInstanceName(), attributeDataDefinition.getName()));
output.setValue(jsonObject.toJSONString());
}
} else {
@@ -209,7 +208,7 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie
if (objValue instanceof Map || objValue instanceof List) {
if (!complexProperty) {
jsonObject.put(GET_ATTRIBUTE,
- Arrays.asList(output.getAttributes().get(0).getComponentInstanceName(), attributeDataDefinition.getName()));
+ Arrays.asList(output.getAttribute().getComponentInstanceName(), attributeDataDefinition.getName()));
output.setValue(jsonObject.toJSONString());
} else {
final Map<String, Object> mappedToscaTemplate = (Map<String, Object>) objValue;
@@ -218,7 +217,7 @@ public abstract class DefaultAttributeDeclarator<PROPERTYOWNER extends Propertie
}
} else {
jsonObject
- .put(GET_ATTRIBUTE, Arrays.asList(output.getAttributes().get(0).getComponentInstanceName(), attributeDataDefinition.getName()));
+ .put(GET_ATTRIBUTE, Arrays.asList(output.getAttribute().getComponentInstanceName(), attributeDataDefinition.getName()));
output.setValue(jsonObject.toJSONString());
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
index 31281db0c7..ed753fdd18 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
@@ -42,6 +42,7 @@ import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.MEMBERS;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE_TEMPLATES;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE_TYPE;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.OUTPUTS;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.POLICIES;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.PROPERTIES;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.REQUIREMENTS;
@@ -93,6 +94,7 @@ import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.GroupTypeDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.NodeTypeInfo;
+import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PolicyTypeDefinition;
@@ -135,13 +137,16 @@ public class YamlTemplateParsingHandler {
Map<String, NodeTypeInfo> nodeTypesInfo, String nodeName,
Component component, String interfaceTemplateYaml) {
log.debug("#parseResourceInfoFromYAML - Going to parse yaml {} ", fileName);
- Map<String, Object> mappedToscaTemplate = getMappedToscaTemplate(fileName, resourceYml, nodeTypesInfo, nodeName);
- ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo();
- Map<String, Object> mappedTopologyTemplate = (Map<String, Object>) findToscaElement(mappedToscaTemplate, TOPOLOGY_TEMPLATE,
+ final Map<String, Object> mappedToscaTemplate = getMappedToscaTemplate(fileName, resourceYml, nodeTypesInfo, nodeName);
+ final ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo();
+ final Map<String, Object> mappedTopologyTemplate = (Map<String, Object>) findToscaElement(mappedToscaTemplate, TOPOLOGY_TEMPLATE,
ToscaElementTypeEnum.ALL).left().on(err -> failIfNotTopologyTemplate(fileName));
- Map<String, Object> mappedTopologyTemplateInputs = mappedTopologyTemplate.entrySet().stream()
+ final Map<String, Object> mappedTopologyTemplateInputs = mappedTopologyTemplate.entrySet().stream()
.filter(entry -> entry.getKey().equals(INPUTS.getElementName())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+ final Map<String, Object> mappedTopologyTemplateOutputs = mappedTopologyTemplate.entrySet().stream()
+ .filter(entry -> entry.getKey().equals(OUTPUTS.getElementName())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
parsedToscaYamlInfo.setInputs(getInputs(mappedTopologyTemplateInputs));
+ parsedToscaYamlInfo.setOutputs(getOutputs(mappedTopologyTemplateOutputs));
parsedToscaYamlInfo.setInstances(getInstances(mappedToscaTemplate, createdNodesToscaResourceNames));
parsedToscaYamlInfo.setGroups(getGroups(mappedToscaTemplate, component.getModel()));
parsedToscaYamlInfo.setPolicies(getPolicies(mappedToscaTemplate, component.getModel()));
@@ -190,6 +195,10 @@ public class YamlTemplateParsingHandler {
return inputs;
}
+ private Map<String, OutputDefinition> getOutputs(Map<String, Object> toscaJson) {
+ return ImportUtils.getOutputs(toscaJson).left().on(err -> new HashMap<>());
+ }
+
private Map<String, PropertyDefinition> getProperties(Map<String, Object> toscaJson) {
return ImportUtils.getProperties(toscaJson).left().on(err -> new HashMap<>());
}
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 7719187cda..b4f6ee3950 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
@@ -41,7 +41,7 @@ import java.util.Map.Entry;
import java.util.function.Consumer;
import java.util.function.Function;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.StringEscapeUtils;
+import org.apache.commons.text.StringEscapeUtils;
import org.onap.sdc.tosca.datatypes.model.EntrySchema;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
@@ -56,6 +56,7 @@ import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.HeatParameterDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.heat.HeatParameterType;
@@ -92,8 +93,8 @@ public final class ImportUtils {
}
@Autowired
- public static void setComponentsUtils(ComponentsUtils componentsUtils) {
- componentsUtils = componentsUtils;
+ public static void setComponentsUtils(ComponentsUtils cu) {
+ componentsUtils = cu;
}
private static void buildMap(Map<String, Object> output, Map<String, Object> map) {
@@ -257,8 +258,8 @@ public final class ImportUtils {
* @param toscaTagName
* @return
*/
- public static Either<String, ResultStatusEnum> findFirstToscaBooleanElement(Map<String, Object> toscaJson,
- TypeUtils.ToscaTagNamesEnum toscaTagName) {
+ private static Either<String, ResultStatusEnum> findFirstToscaBooleanElement(Map<String, Object> toscaJson,
+ TypeUtils.ToscaTagNamesEnum toscaTagName) {
Either<String, ResultStatusEnum> returnedElement = Either.right(ResultStatusEnum.ELEMENT_NOT_FOUND);
Either<Object, ResultStatusEnum> findFirstToscaElements = findToscaElement(toscaJson, toscaTagName, ToscaElementTypeEnum.BOOLEAN);
if (findFirstToscaElements.isLeft()) {
@@ -310,7 +311,7 @@ public final class ImportUtils {
} catch (ClassCastException | JsonParseException e) {
throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_CONSTRAINTS_FORMAT, constraintJson.toString());
}
- if (propertyConstraint != null && propertyConstraint instanceof ValidValuesConstraint) {
+ if (propertyConstraint instanceof ValidValuesConstraint) {
try {
((ValidValuesConstraint) propertyConstraint).validateType(propertyType);
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
@@ -323,7 +324,7 @@ public final class ImportUtils {
return propertyConstraint;
}
- public static PropertyDefinition createModuleProperty(Map<String, Object> propertyValue) {
+ static PropertyDefinition createModuleProperty(Map<String, Object> propertyValue) {
PropertyDefinition propertyDef = new PropertyDefinition();
setField(propertyValue, TypeUtils.ToscaTagNamesEnum.TYPE, propertyDef::setType);
setFieldBoolean(propertyValue, ToscaTagNamesEnum.REQUIRED, req -> propertyDef.setRequired(Boolean.parseBoolean(req)));
@@ -340,12 +341,11 @@ public final class ImportUtils {
private static void setJsonStringField(Map<String, Object> propertyValue, ToscaTagNamesEnum elementName, String type, Consumer<String> setter) {
Either<Object, ResultStatusEnum> eitherValue = findToscaElement(propertyValue, elementName, ToscaElementTypeEnum.ALL);
if (eitherValue.isLeft()) {
- String propertyJsonStringValue = getPropertyJsonStringValue(eitherValue.left().value(), type);
- setter.accept(propertyJsonStringValue);
+ setter.accept(getPropertyJsonStringValue(eitherValue.left().value(), type));
}
}
- public static Annotation createModuleAnnotation(Map<String, Object> annotationMap, AnnotationTypeOperations annotationTypeOperations) {
+ private static Annotation createModuleAnnotation(Map<String, Object> annotationMap, AnnotationTypeOperations annotationTypeOperations) {
String parsedAnnotationType = findFirstToscaStringElement(annotationMap, TypeUtils.ToscaTagNamesEnum.TYPE).left().value();
AnnotationTypeDefinition annotationTypeObject = annotationTypeOperations.getLatestType(parsedAnnotationType);
if (annotationTypeObject != null) {
@@ -387,11 +387,11 @@ public final class ImportUtils {
return result;
}
- public static InputDefinition createModuleInput(final Map<String, Object> inputValue, final AnnotationTypeOperations annotationTypeOperations) {
+ private static InputDefinition createModuleInput(final Map<String, Object> inputValue, final AnnotationTypeOperations annotationTypeOperations) {
return parseAnnotationsAndAddItToInput(createModuleInput(inputValue), inputValue, annotationTypeOperations);
}
- public static InputDefinition createModuleInput(final Map<String, Object> inputValue) {
+ private 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)));
@@ -408,8 +408,17 @@ public final class ImportUtils {
return inputDef;
}
- public static InputDefinition parseAnnotationsAndAddItToInput(InputDefinition inputDef, Map<String, Object> inputValue,
- AnnotationTypeOperations annotationTypeOperations) {
+ private static OutputDefinition createModuleOutput(final Map<String, Object> outputValue) {
+ final OutputDefinition outputDef = new OutputDefinition();
+ setField(outputValue, TypeUtils.ToscaTagNamesEnum.TYPE, outputDef::setType);
+ setField(outputValue, TypeUtils.ToscaTagNamesEnum.DESCRIPTION, outputDef::setDescription);
+ setJsonStringField(outputValue, TypeUtils.ToscaTagNamesEnum.VALUE, outputDef.getType(), outputDef::setValue);
+ setField(outputValue, TypeUtils.ToscaTagNamesEnum.STATUS, outputDef::setStatus);
+ return outputDef;
+ }
+
+ private static InputDefinition parseAnnotationsAndAddItToInput(InputDefinition inputDef, Map<String, Object> inputValue,
+ AnnotationTypeOperations annotationTypeOperations) {
Function<String, Annotation> elementGenByName = ImportUtils::createAnnotation;
Function<Map<String, Object>, Annotation> func = annotation -> createModuleAnnotation(annotation, annotationTypeOperations);
return getElements(inputValue, TypeUtils.ToscaTagNamesEnum.ANNOTATIONS, elementGenByName, func).left()
@@ -425,7 +434,7 @@ public final class ImportUtils {
return inputDef;
}
- public static AttributeDefinition createModuleAttribute(Map<String, Object> attributeMap) {
+ static AttributeDefinition createModuleAttribute(Map<String, Object> attributeMap) {
AttributeDefinition attributeDef = new AttributeDefinition();
setField(attributeMap, TypeUtils.ToscaTagNamesEnum.TYPE, attributeDef::setType);
setField(attributeMap, TypeUtils.ToscaTagNamesEnum.DESCRIPTION, attributeDef::setDescription);
@@ -486,7 +495,7 @@ public final class ImportUtils {
}
}
- public static void setFieldBoolean(Map<String, Object> toscaJson, TypeUtils.ToscaTagNamesEnum tagName, Consumer<String> setter) {
+ private static void setFieldBoolean(Map<String, Object> toscaJson, TypeUtils.ToscaTagNamesEnum tagName, Consumer<String> setter) {
Either<String, ResultStatusEnum> fieldStringValue = findFirstToscaBooleanElement(toscaJson, tagName);
if (fieldStringValue.isLeft()) {
setter.accept(fieldStringValue.left().value());
@@ -520,13 +529,19 @@ public final class ImportUtils {
return getElements(toscaJson, TypeUtils.ToscaTagNamesEnum.INPUTS, elementGenByName, func);
}
+ public static Either<Map<String, OutputDefinition>, ResultStatusEnum> getOutputs(Map<String, Object> toscaJson) {
+ final Function<String, OutputDefinition> elementGenByName = ImportUtils::createOutputs;
+ final Function<Map<String, Object>, OutputDefinition> func = ImportUtils::createModuleOutput;
+ return getElements(toscaJson, TypeUtils.ToscaTagNamesEnum.OUTPUTS, elementGenByName, func);
+ }
+
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,
- Function<Map<String, Object>, T> func) {
+ private static <T> Either<Map<String, T>, ResultStatusEnum> getElements(Map<String, Object> toscaJson, TypeUtils.ToscaTagNamesEnum elementTagName,
+ Function<String, T> elementGenByName,
+ Function<Map<String, Object>, T> func) {
Either<Map<String, T>, ResultStatusEnum> eitherResult = Either.right(ResultStatusEnum.ELEMENT_NOT_FOUND);
Either<Map<String, Object>, ResultStatusEnum> toscaAttributes = findFirstToscaMapElement(toscaJson, elementTagName);
if (toscaAttributes.isLeft()) {
@@ -571,13 +586,19 @@ public final class ImportUtils {
return input;
}
+ private static OutputDefinition createOutputs(final String name) {
+ final OutputDefinition output = new OutputDefinition();
+ output.setName(name);
+ return output;
+ }
+
private static Annotation createAnnotation(String name) {
Annotation annotation = new Annotation();
annotation.setName(name);
return annotation;
}
- public static Either<List<HeatParameterDefinition>, ResultStatusEnum> getHeatParameters(Map<String, Object> heatData, String artifactType) {
+ static Either<List<HeatParameterDefinition>, ResultStatusEnum> getHeatParameters(Map<String, Object> heatData, String artifactType) {
Either<List<HeatParameterDefinition>, ResultStatusEnum> eitherResult = Either.right(ResultStatusEnum.ELEMENT_NOT_FOUND);
Either<Map<String, Object>, ResultStatusEnum> toscaProperties = findFirstToscaMapElement(heatData, TypeUtils.ToscaTagNamesEnum.PARAMETERS);
if (toscaProperties.isLeft()) {
@@ -657,13 +678,16 @@ public final class ImportUtils {
}
public static String getPropertyJsonStringValue(Object value, String type) {
- Gson gson = new Gson();
if (type == null) {
return null;
}
ToscaPropertyType validType = ToscaPropertyType.isValidType(type);
- if (validType == null || validType == ToscaPropertyType.JSON || validType == ToscaPropertyType.MAP || validType == ToscaPropertyType.LIST) {
- return gson.toJson(value);
+ if (validType == null
+ || validType == ToscaPropertyType.JSON
+ || validType == ToscaPropertyType.MAP
+ || validType == ToscaPropertyType.LIST
+ || value instanceof Map) {
+ return (new Gson()).toJson(value);
}
return value.toString();
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
index 18993e8f65..bca901ee8b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
@@ -127,14 +127,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
ComponentParametersView filters = new ComponentParametersView();
filters.disableAll();
filters.setIgnoreInputs(false);
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
+ Either<Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
.getToscaElement(componentId, filters);
if (getComponentEither.isRight()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, componentId, actionStatus);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
}
- org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
+ Component component = getComponentEither.left().value();
List<InputDefinition> inputs = component.getInputs();
return Either.left(inputs);
}
@@ -147,14 +147,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
filters.setIgnoreInputs(false);
filters.setIgnoreComponentInstances(false);
filters.setIgnoreComponentInstancesInputs(false);
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
+ Either<Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
.getToscaElement(componentId, filters);
if (getComponentEither.isRight()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, componentId, actionStatus);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
}
- org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
+ Component component = getComponentEither.left().value();
if (!ComponentValidations.validateComponentInstanceExist(component, componentInstanceId)) {
ActionStatus actionStatus = ActionStatus.COMPONENT_INSTANCE_NOT_FOUND;
log.debug("Failed to found component instance inputs {}, error: {}", componentInstanceId, actionStatus);
@@ -182,12 +182,12 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
String instanceId, String inputId) {
validateUserExists(userId);
String parentId = componentId;
- org.openecomp.sdc.be.model.Component component;
+ Component component;
ComponentParametersView filters = new ComponentParametersView();
filters.disableAll();
filters.setIgnoreComponentInstances(false);
if (!instanceId.equals(inputId)) {
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
+ Either<Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
.getToscaElement(parentId, filters);
if (getComponentEither.isRight()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
@@ -204,7 +204,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
filters.setIgnoreComponentInstancesProperties(false);
filters.setIgnoreComponentInstancesInputs(false);
filters.setIgnoreProperties(false);
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
+ Either<Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
.getToscaElement(parentId, filters);
if (getComponentEither.isRight()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
@@ -266,7 +266,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
List<InputDefinition> inputs, String userId, boolean shouldLockComp) {
List<InputDefinition> returnInputs = new ArrayList<>();
Either<List<InputDefinition>, ResponseFormat> result = null;
- org.openecomp.sdc.be.model.Component component = null;
+ Component component = null;
try {
validateUserExists(userId);
ComponentParametersView componentParametersView = new ComponentParametersView();
@@ -353,14 +353,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
public Either<List<ComponentInstanceInput>, ResponseFormat> getInputsForComponentInput(String userId, String componentId, String inputId) {
validateUserExists(userId);
- org.openecomp.sdc.be.model.Component component = null;
+ Component component = null;
ComponentParametersView filters = new ComponentParametersView();
filters.disableAll();
filters.setIgnoreComponentInstances(false);
filters.setIgnoreInputs(false);
filters.setIgnoreComponentInstancesInputs(false);
filters.setIgnoreProperties(false);
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
+ Either<Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
.getToscaElement(componentId, filters);
if (getComponentEither.isRight()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
@@ -388,7 +388,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
boolean shouldLockComp,
boolean inTransaction) {
Either<List<InputDefinition>, ResponseFormat> result = null;
- org.openecomp.sdc.be.model.Component component = null;
+ Component component = null;
try {
validateUserExists(userId);
component = getAndValidateComponentForCreate(userId, componentId, componentType, shouldLockComp);
@@ -431,7 +431,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
ComponentInstListInput componentListInput, boolean shouldLockComp,
boolean inTransaction) {
Either<List<InputDefinition>, ResponseFormat> result = null;
- org.openecomp.sdc.be.model.Component component = null;
+ Component component = null;
log.trace("#createListInput: enter");
try {
/* check if user exists */
@@ -513,11 +513,11 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
return componentParametersView;
}
- private org.openecomp.sdc.be.model.Component getAndValidateComponentForCreate(
+ private Component getAndValidateComponentForCreate(
String userId, String componentId, ComponentTypeEnum componentType, boolean shouldLockComp
) {
ComponentParametersView componentParametersView = getBaseComponentParametersView();
- org.openecomp.sdc.be.model.Component component = validateComponentExists(componentId, componentType, componentParametersView);
+ Component component = validateComponentExists(componentId, componentType, componentParametersView);
if (shouldLockComp) {
// lock the component
lockComponent(component, CREATE_INPUT);
@@ -566,7 +566,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
}
public Either<List<InputDefinition>, ResponseFormat> createInputsInGraph(Map<String, InputDefinition> inputs,
- org.openecomp.sdc.be.model.Component component) {
+ Component component) {
List<InputDefinition> resourceProperties = component.getInputs();
@@ -604,7 +604,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
private Either<List<InputDefinition>, ResponseFormat> createListInputsInGraph(Map<String, InputDefinition> inputs,
Map<String, DataTypeDefinition> privateDataTypes,
- org.openecomp.sdc.be.model.Component component) {
+ Component component) {
log.trace("#createListInputsInGraph: enter");
@@ -652,12 +652,12 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
componentParametersView.setIgnoreInterfaces(false);
componentParametersView.setIgnoreDataType(false);
componentParametersView.setIgnoreProperties(false);
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentEither = toscaOperationFacade
+ Either<Component, StorageOperationStatus> componentEither = toscaOperationFacade
.getToscaElement(componentId, componentParametersView);
if (componentEither.isRight()) {
throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(componentEither.right().value()));
}
- org.openecomp.sdc.be.model.Component component = componentEither.left().value();
+ Component component = componentEither.left().value();
// Validate inputId is child of the component
Optional<InputDefinition> optionalInput = component.getInputs().stream().
// filter by ID
@@ -700,10 +700,9 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
}
private Either<InputDefinition, ResponseFormat> deleteListInput(String componentId, String inputId,
- org.openecomp.sdc.be.model.Component component, InputDefinition inputForDelete,
+ Component component, InputDefinition inputForDelete,
StorageOperationStatus status) {
// the input is created by 'Declare List'.
-
// need to 1. undeclare properties, 2. delete input, 3. delete private data type
StorageOperationStatus storageOperationStatus = propertyDeclarationOrchestrator.unDeclarePropertiesAsListInputs(component, inputForDelete);
if (storageOperationStatus != StorageOperationStatus.OK) {
@@ -762,14 +761,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
filters.setIgnoreComponentInstancesInputs(false);
filters.setIgnoreComponentInstancesProperties(false);
filters.setIgnoreProperties(false);
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
+ Either<Component, StorageOperationStatus> getComponentEither = toscaOperationFacade
.getToscaElement(componentId, filters);
if (getComponentEither.isRight()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
log.debug(FAILED_TO_FOUND_COMPONENT_ERROR, componentId, actionStatus);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
}
- org.openecomp.sdc.be.model.Component component = getComponentEither.left().value();
+ Component component = getComponentEither.left().value();
Optional<InputDefinition> op = component.getInputs().stream().filter(in -> in.getUniqueId().equals(inputId)).findFirst();
if (!op.isPresent()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentEither.right().value());
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java
index 2d6a619cc7..a5f819d9b0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogic.java
@@ -20,10 +20,12 @@
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import org.apache.commons.collections4.CollectionUtils;
import org.openecomp.sdc.be.components.attribute.AttributeDeclarationOrchestrator;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
@@ -32,8 +34,12 @@ import org.openecomp.sdc.be.components.validation.ComponentValidations;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.utils.MapUtil;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstOutputsMap;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceAttribOutput;
+import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
import org.openecomp.sdc.be.model.ComponentInstanceOutput;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.OutputDefinition;
@@ -51,6 +57,7 @@ import org.openecomp.sdc.common.log.enums.StatusCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
@org.springframework.stereotype.Component("outputsBusinessLogic")
public class OutputsBusinessLogic extends BaseBusinessLogic {
@@ -58,8 +65,8 @@ public class OutputsBusinessLogic extends BaseBusinessLogic {
private static final String CREATE_OUTPUT = "CreateOutput";
private static final Logger log = Logger.getLogger(OutputsBusinessLogic.class);
private static final String FAILED_TO_FOUND_COMPONENT_ERROR = "Failed to found component {}, error: {}";
- private static final String GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_GROUP = "Going to execute rollback on create group.";
- private static final String GOING_TO_EXECUTE_COMMIT_ON_CREATE_GROUP = "Going to execute commit on create group.";
+ private static final String GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_OUTPUTS = "Going to execute rollback on create outputs.";
+ private static final String GOING_TO_EXECUTE_COMMIT_ON_CREATE_OUTPUTS = "Going to execute commit on create outputs.";
private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(OutputsBusinessLogic.class);
private static final String FAILED_TO_FOUND_COMPONENT_INSTANCE_OUTPUTS_COMPONENT_INSTANCE_ID = "Failed to found component instance outputs componentInstanceId: {}";
private static final String FAILED_TO_FOUND_COMPONENT_INSTANCE_OUTPUTS_ERROR = "Failed to found component instance outputs {}, error: {}";
@@ -94,7 +101,7 @@ public class OutputsBusinessLogic extends BaseBusinessLogic {
if (!ComponentValidations.validateComponentInstanceExist(component, componentInstanceId)) {
final ActionStatus actionStatus = ActionStatus.COMPONENT_INSTANCE_NOT_FOUND;
log.debug(FAILED_TO_FOUND_COMPONENT_INSTANCE_OUTPUTS_ERROR, componentInstanceId, actionStatus);
- loggerSupportability.log(LoggerSupportabilityActions.CREATE_INPUTS, component.getComponentMetadataForSupportLog(), StatusCode.ERROR,
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_OUTPUTS, component.getComponentMetadataForSupportLog(), StatusCode.ERROR,
FAILED_TO_FOUND_COMPONENT_INSTANCE_OUTPUTS_COMPONENT_INSTANCE_ID, componentInstanceId);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
}
@@ -110,11 +117,11 @@ public class OutputsBusinessLogic extends BaseBusinessLogic {
return createMultipleOutputs(userId, componentId, componentTypeEnum, componentInstOutputsMap, true, false);
}
- public Either<List<OutputDefinition>, ResponseFormat> createMultipleOutputs(final String userId, final String componentId,
- final ComponentTypeEnum componentType,
- final ComponentInstOutputsMap componentInstOutputsMapUi,
- final boolean shouldLockComp, final boolean inTransaction) {
- Either<List<OutputDefinition>, ResponseFormat> result = null;
+ private Either<List<OutputDefinition>, ResponseFormat> createMultipleOutputs(final String userId, final String componentId,
+ final ComponentTypeEnum componentType,
+ final ComponentInstOutputsMap componentInstOutputsMapUi,
+ final boolean shouldLockComp, final boolean inTransaction) {
+ Either<List<OutputDefinition>, ResponseFormat> result = Either.right(new ResponseFormat(HttpStatus.BAD_REQUEST.value()));
org.openecomp.sdc.be.model.Component component = null;
try {
validateUserExists(userId);
@@ -129,11 +136,11 @@ public class OutputsBusinessLogic extends BaseBusinessLogic {
return result;
} finally {
if (!inTransaction) {
- if (result == null || result.isRight()) {
- log.debug(GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_GROUP);
+ if (result.isRight()) {
+ log.debug(GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_OUTPUTS);
janusGraphDao.rollback();
} else {
- log.debug(GOING_TO_EXECUTE_COMMIT_ON_CREATE_GROUP);
+ log.debug(GOING_TO_EXECUTE_COMMIT_ON_CREATE_OUTPUTS);
janusGraphDao.commit();
}
}
@@ -144,11 +151,11 @@ public class OutputsBusinessLogic extends BaseBusinessLogic {
}
}
- private org.openecomp.sdc.be.model.Component getAndValidateComponentForCreate(final String userId, final String componentId,
- final ComponentTypeEnum componentType,
- final boolean shouldLockComp) {
+ private Component getAndValidateComponentForCreate(final String userId, final String componentId,
+ final ComponentTypeEnum componentType,
+ final boolean shouldLockComp) {
final ComponentParametersView componentParametersView = getBaseComponentParametersView();
- final org.openecomp.sdc.be.model.Component component = validateComponentExists(componentId, componentType, componentParametersView);
+ final Component component = validateComponentExists(componentId, componentType, componentParametersView);
if (shouldLockComp) {
// lock the component
lockComponent(component, CREATE_OUTPUT);
@@ -161,7 +168,11 @@ public class OutputsBusinessLogic extends BaseBusinessLogic {
final List<OutputDefinition> outputsToCreate) {
final Map<String, OutputDefinition> outputsToPersist = MapUtil.toMap(outputsToCreate, OutputDefinition::getName);
assignOwnerIdToOutputs(userId, outputsToPersist);
- return toscaOperationFacade.addOutputsToComponent(outputsToPersist, cmptId).left().map(persistedOutputs -> outputsToCreate);
+ final var statusEither = toscaOperationFacade.addOutputsToComponent(outputsToPersist, cmptId);
+ if (statusEither.isRight()) {
+ return statusEither;
+ }
+ return statusEither.left().map(persistedOutputs -> outputsToCreate);
}
private void assignOwnerIdToOutputs(final String userId, final Map<String, OutputDefinition> outputsToCreate) {
@@ -189,7 +200,6 @@ public class OutputsBusinessLogic extends BaseBusinessLogic {
* @return
*/
public OutputDefinition deleteOutput(final String componentId, final String userId, final String outputId) {
- Either<OutputDefinition, ResponseFormat> deleteEither = null;
if (log.isDebugEnabled()) {
log.debug("Going to delete output id: {}", outputId);
}
@@ -236,4 +246,62 @@ public class OutputsBusinessLogic extends BaseBusinessLogic {
unlockComponent(failed, component);
}
}
+
+ public Either<List<OutputDefinition>, ResponseFormat> createOutputsInGraph(final Map<String, OutputDefinition> outputs,
+ final Component component,
+ final String userId) {
+
+ final List<OutputDefinition> result = new ArrayList<>();
+ for (final Map.Entry<String, OutputDefinition> outputDefinition : outputs.entrySet()) {
+ final var outputDefinitionValue = outputDefinition.getValue();
+ outputDefinitionValue.setName(outputDefinition.getKey());
+
+ final String value = outputDefinitionValue.getValue();
+ if (value != null) {
+ final List<String> getAttribute = (List<String>) ImportUtils.loadYamlAsStrictMap(value)
+ .get(ToscaGetFunctionType.GET_ATTRIBUTE.getFunctionName());
+ if (getAttribute.size() == 2) {
+ final var optionalComponentInstance = component.getComponentInstanceByName(getAttribute.get(0));
+ if (optionalComponentInstance.isPresent()) {
+ final var createdOutputs
+ = createOutputs(component.getUniqueId(), userId, getAttribute.get(1), optionalComponentInstance.get());
+ if (createdOutputs.isRight()) {
+ return Either.right((createdOutputs.right().value()));
+ }
+ result.addAll(createdOutputs.left().value());
+ } else {
+ // From SELF
+ outputDefinitionValue.setInstanceUniqueId(component.getUniqueId());
+ }
+ }
+ }
+ }
+ return Either.left(result);
+
+ }
+
+ private Either<List<OutputDefinition>, ResponseFormat> createOutputs(final String componentUniqueId, final String userId,
+ final String attributeName,
+ final ComponentInstance componentInstance) {
+ // From Instance
+ final List<OutputDefinition> result = new ArrayList<>();
+ final var componentInstanceAttributes = componentInstance.getAttributes();
+ if (CollectionUtils.isNotEmpty(componentInstanceAttributes)) {
+ final var componentInstanceAttributeOptional = componentInstanceAttributes.stream()
+ .filter(ad -> ad.getName().equals(attributeName)).map(ComponentInstanceAttribute::new).findFirst();
+ if (componentInstanceAttributeOptional.isPresent()) {
+ final var componentInstOutputsMap = new ComponentInstOutputsMap();
+ componentInstOutputsMap.setComponentInstanceAttributes(Collections.singletonMap(componentInstance.getUniqueId(),
+ Collections.singletonList(new ComponentInstanceAttribOutput(componentInstanceAttributeOptional.get()))));
+ final var createdOutputs = createMultipleOutputs(userId, componentUniqueId, ComponentTypeEnum.SERVICE,
+ componentInstOutputsMap, true, false);
+ if (createdOutputs.isRight()) {
+ return Either.right((createdOutputs.right().value()));
+ }
+ result.addAll(createdOutputs.left().value());
+ }
+ }
+ return Either.left(result);
+ }
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
index 34460f46d5..3c21ae16a7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
@@ -97,6 +97,7 @@ import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.NodeTypeInfo;
import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
@@ -252,7 +253,7 @@ public class ServiceImportBusinessLogic {
throw new ComponentException(findNodeTypesArtifactsToHandleRes.right().value());
}
return createServiceFromYaml(service, csarInfo.getMainTemplateContent(), csarInfo.getMainTemplateName(), nodeTypesInfo, csarInfo,
- findNodeTypesArtifactsToHandleRes.left().value(), true, false, null);
+ findNodeTypesArtifactsToHandleRes.left().value(), true, false, null, user.getUserId());
} catch (Exception e) {
log.debug("Exception occured when createServiceFromCsar,error is:{}", e.getMessage(), e);
throw new ComponentException(ActionStatus.GENERAL_ERROR);
@@ -262,7 +263,8 @@ public class ServiceImportBusinessLogic {
protected Service createServiceFromYaml(Service service, String topologyTemplateYaml, String yamlName, Map<String, NodeTypeInfo> nodeTypesInfo,
CsarInfo csarInfo,
Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
- boolean shouldLock, boolean inTransaction, String nodeName) throws BusinessLogicException {
+ boolean shouldLock, boolean inTransaction, String nodeName, final String userId)
+ throws BusinessLogicException {
List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
Service createdService;
CreateServiceFromYamlParameter csfyp = new CreateServiceFromYamlParameter();
@@ -277,7 +279,7 @@ public class ServiceImportBusinessLogic {
csfyp.setNodeTypesInfo(nodeTypesInfo);
csfyp.setCsarInfo(csarInfo);
csfyp.setNodeName(nodeName);
- createdService = createServiceAndRIsFromYaml(service, false, nodeTypesArtifactsToCreate, shouldLock, inTransaction, csfyp);
+ createdService = createServiceAndRIsFromYaml(service, false, nodeTypesArtifactsToCreate, shouldLock, inTransaction, csfyp, userId);
log.debug("#createResourceFromYaml - The resource {} has been created ", service.getName());
} catch (ComponentException | BusinessLogicException e) {
log.debug("Create Service from yaml failed", e);
@@ -291,7 +293,8 @@ public class ServiceImportBusinessLogic {
protected Service createServiceAndRIsFromYaml(Service service, boolean isNormative,
Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
- boolean shouldLock, boolean inTransaction, CreateServiceFromYamlParameter csfyp)
+ boolean shouldLock, boolean inTransaction, CreateServiceFromYamlParameter csfyp,
+ final String userId)
throws BusinessLogicException {
List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
String yamlName = csfyp.getYamlName();
@@ -325,7 +328,7 @@ public class ServiceImportBusinessLogic {
log.trace("************* Going to add inputs from yaml {}", yamlName);
Map<String, InputDefinition> inputs = parsedToscaYamlInfo.getInputs();
service = serviceImportParseLogic.createInputsOnService(service, inputs);
- log.trace("************* Finish to add inputs from yaml {}", yamlName);
+ log.trace("************* Finished to add inputs from yaml {}", yamlName);
ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> substitutionFilterProperties = parsedToscaYamlInfo.getSubstitutionFilterProperties();
service = serviceImportParseLogic.createSubstitutionFilterOnService(service, substitutionFilterProperties);
log.trace("************* Added Substitution filter from interface yaml {}", yamlName);
@@ -334,6 +337,11 @@ public class ServiceImportBusinessLogic {
service = createRIAndRelationsFromYaml(yamlName, service, uploadComponentInstanceInfoMap, topologyTemplateYaml,
nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, nodeName);
log.trace("************* Finished to create nodes, RI and Relation from yaml {}", yamlName);
+ log.trace("************* Going to add outputs from yaml {}", yamlName);
+ Map<String, OutputDefinition> outputs = parsedToscaYamlInfo.getOutputs();
+ service = serviceImportParseLogic.createOutputsOnService(service, outputs, userId);
+ log.trace("************* Finished to add outputs from yaml {}", yamlName);
+
Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes
= groupBusinessLogic.validateUpdateVfGroupNames(parsedToscaYamlInfo.getGroups(), service.getSystemName());
if (validateUpdateVfGroupNamesRes.isRight()) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
index 7a5b90976f..507f4ad32c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
@@ -77,6 +77,7 @@ import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.NodeTypeInfo;
import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.RelationshipImpl;
import org.openecomp.sdc.be.model.RelationshipInfo;
@@ -112,7 +113,6 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.GeneralUtility;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
-import org.springframework.beans.factory.annotation.Autowired;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
@@ -131,27 +131,18 @@ public class ServiceImportParseLogic {
private static final String CREATE_RESOURCE_VALIDATE_CAPABILITY_TYPES = "Create Resource - validateCapabilityTypesCreate";
private static final String CATEGORY_IS_EMPTY = "Resource category is empty";
private static final Logger log = Logger.getLogger(ServiceImportParseLogic.class);
- @Autowired
private final ServiceBusinessLogic serviceBusinessLogic;
- @Autowired
private final ComponentsUtils componentsUtils;
- @Autowired
private final ToscaOperationFacade toscaOperationFacade;
- @Autowired
private final LifecycleBusinessLogic lifecycleBusinessLogic;
- @Autowired
private final InputsBusinessLogic inputsBusinessLogic;
- @Autowired
private final ResourceImportManager resourceImportManager;
- @Autowired
private final ComponentSubstitutionFilterBusinessLogic substitutionFilterBusinessLogic;
- @Autowired
private final IInterfaceLifecycleOperation interfaceTypeOperation;
- @Autowired
private final ICapabilityTypeOperation capabilityTypeOperation;
- @Autowired
private final ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic;
private final GroupBusinessLogic groupBusinessLogic;
+ private final OutputsBusinessLogic outputsBusinessLogic;
public ServiceImportParseLogic(final ServiceBusinessLogic serviceBusinessLogic, final ComponentsUtils componentsUtils,
final ToscaOperationFacade toscaOperationFacade, final LifecycleBusinessLogic lifecycleBusinessLogic,
@@ -159,7 +150,7 @@ public class ServiceImportParseLogic {
final ComponentSubstitutionFilterBusinessLogic substitutionFilterBusinessLogic,
final IInterfaceLifecycleOperation interfaceTypeOperation, final ICapabilityTypeOperation capabilityTypeOperation,
final ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic,
- final GroupBusinessLogic groupBusinessLogic) {
+ final GroupBusinessLogic groupBusinessLogic, final OutputsBusinessLogic outputsBusinessLogic) {
this.serviceBusinessLogic = serviceBusinessLogic;
this.componentsUtils = componentsUtils;
this.toscaOperationFacade = toscaOperationFacade;
@@ -171,6 +162,7 @@ public class ServiceImportParseLogic {
this.capabilityTypeOperation = capabilityTypeOperation;
this.componentNodeFilterBusinessLogic = componentNodeFilterBusinessLogic;
this.groupBusinessLogic = groupBusinessLogic;
+ this.outputsBusinessLogic = outputsBusinessLogic;
}
public Either<Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandle(
@@ -1039,8 +1031,6 @@ public class ServiceImportParseLogic {
reqDef.setLeftOccurrences(String.valueOf(left));
validRegDef = reqDef;
break;
- } else {
- continue;
}
} else {
validRegDef = reqDef;
@@ -1066,8 +1056,6 @@ public class ServiceImportParseLogic {
reqDef.setLeftOccurrences(String.valueOf(left));
validRegDef = reqDef;
break;
- } else {
- continue;
}
} else {
validRegDef = reqDef;
@@ -1371,6 +1359,24 @@ public class ServiceImportParseLogic {
return updatedResource.left().value();
}
+ public Service createOutputsOnService(final Service service, final Map<String, OutputDefinition> outputs, final String userId) {
+ if (MapUtils.isNotEmpty(outputs) || isNotEmpty(service.getOutputs())) {
+ final Either<List<OutputDefinition>, ResponseFormat> createOutputs = outputsBusinessLogic.createOutputsInGraph(outputs, service, userId);
+ if (createOutputs.isRight()) {
+ throw new ComponentException(createOutputs.right().value());
+ }
+ } else {
+ return service;
+ }
+ final Either<Service, StorageOperationStatus> updatedResource = toscaOperationFacade.getToscaElement(service.getUniqueId());
+ if (updatedResource.isRight()) {
+ throw new ComponentException(
+ componentsUtils.getResponseFormatByComponent(componentsUtils.convertFromStorageResponse(updatedResource.right().value()), service,
+ ComponentTypeEnum.SERVICE));
+ }
+ return updatedResource.left().value();
+ }
+
public Service createSubstitutionFilterOnService(Service service,
ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> substitutionFilterProperties)
throws BusinessLogicException {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java
index 7c300b310d..1b1111a86e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java
@@ -1061,16 +1061,16 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
}
}
- protected void handleImportService(Wrapper<Response> responseWrapper, User user, UploadServiceInfo serviceInfoObject, String yamlAsString,
- ServiceAuthorityTypeEnum authority, boolean createNewVersion, String serviceUniqueId) throws ZipException {
+ protected void handleImportService(Wrapper<Response> responseWrapper, User user, UploadServiceInfo serviceInfoObject, String serviceUniqueId)
+ throws ZipException {
Response response = null;
- Object representation = null;
ImmutablePair<Service, ActionStatus> importedServiceStatus = null;
if (CsarValidationUtils.isCsarPayloadName(serviceInfoObject.getPayloadName())) {
log.debug("import service from csar");
importedServiceStatus = importServiceFromUICsar(serviceInfoObject, user, serviceUniqueId);
}
if (importedServiceStatus != null) {
+ Object representation = null;
try {
representation = RepresentationUtils.toRepresentation(importedServiceStatus.left);
} catch (IOException e) {
@@ -1083,18 +1083,14 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
private ImmutablePair<Service, ActionStatus> importServiceFromUICsar(UploadServiceInfo serviceInfoObject, User user, String serviceUniqueId)
throws ZipException {
- Service newService;
- ImmutablePair<Service, ActionStatus> result = null;
- ActionStatus actionStatus;
Service service = new Service();
String payloadName = serviceInfoObject.getPayloadName();
fillServiceFromServiceInfoObject(service, serviceInfoObject);
Map<String, byte[]> csarUIPayloadRes = getCsarFromPayload(serviceInfoObject);
getAndValidateCsarYaml(csarUIPayloadRes, service, user, payloadName);
- newService = serviceImportManager.getServiceImportBusinessLogic()
+ final Service newService = serviceImportManager.getServiceImportBusinessLogic()
.createService(service, AuditingActionEnum.CREATE_SERVICE, user, csarUIPayloadRes, payloadName);
- actionStatus = ActionStatus.CREATED;
- return new ImmutablePair<>(newService, actionStatus);
+ return new ImmutablePair<>(newService, ActionStatus.CREATED);
}
private void fillServiceFromServiceInfoObject(Service service, UploadServiceInfo serviceInfoObject) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java
index c26f3ca522..f49bfdc637 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java
@@ -672,18 +672,17 @@ public class ServiceServlet extends AbstractValidationsServlet {
}
private Wrapper<Response> performUIImport(String data, final HttpServletRequest request, String userId,
- String ServiceUniqueId) throws FileNotFoundException, ZipException {
+ String serviceUniqueId) throws FileNotFoundException, ZipException {
Wrapper<Response> responseWrapper = new Wrapper<>();
Wrapper<User> userWrapper = new Wrapper<>();
Wrapper<UploadServiceInfo> uploadServiceInfoWrapper = new Wrapper<>();
Wrapper<String> yamlStringWrapper = new Wrapper<>();
- ServiceAuthorityTypeEnum ServiceAuthorityEnum = ServiceAuthorityTypeEnum.USER_TYPE_UI;
- commonServiceGeneralValidations(responseWrapper, userWrapper, uploadServiceInfoWrapper, ServiceAuthorityEnum, userId, data);
+ ServiceAuthorityTypeEnum serviceAuthorityTypeEnum = ServiceAuthorityTypeEnum.USER_TYPE_UI;
+ commonServiceGeneralValidations(responseWrapper, userWrapper, uploadServiceInfoWrapper, serviceAuthorityTypeEnum, userId, data);
specificServiceAuthorityValidations(responseWrapper, uploadServiceInfoWrapper, yamlStringWrapper, userWrapper.getInnerElement(), request,
- data, ServiceAuthorityEnum);
+ data, serviceAuthorityTypeEnum);
if (responseWrapper.isEmpty()) {
- handleImportService(responseWrapper, userWrapper.getInnerElement(), uploadServiceInfoWrapper.getInnerElement(),
- yamlStringWrapper.getInnerElement(), ServiceAuthorityEnum, true, ServiceUniqueId);
+ handleImportService(responseWrapper, userWrapper.getInnerElement(), uploadServiceInfoWrapper.getInnerElement(), serviceUniqueId);
}
return responseWrapper;
}
@@ -775,8 +774,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
uploadServiceInfoWrapper.getInnerElement().setProjectCode(oldService.getProjectCode());
if (responseWrapper.isEmpty()) {
log.debug("importReplaceService:start handleImportService");
- handleImportService(responseWrapper, userWrapper.getInnerElement(), uploadServiceInfoWrapper.getInnerElement(),
- yamlStringWrapper.getInnerElement(), serviceAuthorityEnum, true, null);
+ handleImportService(responseWrapper, userWrapper.getInnerElement(), uploadServiceInfoWrapper.getInnerElement(), null);
}
return responseWrapper.getInnerElement();
} catch (IOException | ZipException e) {
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 9cd095b5b5..b7559e3836 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
@@ -7,9 +7,9 @@
* 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.
@@ -20,10 +20,10 @@
package org.openecomp.sdc.be.components.impl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.common.collect.Lists;
import fj.data.Either;
@@ -36,7 +36,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaElementTypeEnum;
@@ -46,6 +46,7 @@ import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.HeatParameterDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations;
@@ -56,10 +57,32 @@ import org.yaml.snakeyaml.Yaml;
public class ImportUtilsTest {
+ public static String loadFileNameToJsonString(String fileName) throws IOException {
+ String sourceDir = "src/test/resources/normativeTypes";
+ return loadFileNameToJsonString(sourceDir, fileName);
+ }
+
+ public static String loadCustomTypeFileNameToJsonString(String fileName) throws IOException {
+ String sourceDir = "src/test/resources/customTypes";
+ return loadFileNameToJsonString(sourceDir, fileName);
+ }
+
+ private static String loadFileNameToJsonString(String sourceDir, String fileName) throws IOException {
+ java.nio.file.Path filePath = FileSystems.getDefault().getPath(sourceDir, fileName);
+ byte[] fileContent = Files.readAllBytes(filePath);
+ return new String(fileContent);
+ }
+
+ private static Object loadJsonFromFile(String fileName) throws IOException {
+ String content = loadFileNameToJsonString(fileName);
+ return new Yaml().load(content);
+ }
@Test
- public void testStringTypeFindToscaElements() throws IOException {
- Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements((Map<String, Object>) loadJsonFromFile("normative-types-string-list-test.yml"), "stringTestTag", ToscaElementTypeEnum.STRING, new ArrayList<>());
+ void testStringTypeFindToscaElements() throws IOException {
+ Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements(
+ (Map<String, Object>) loadJsonFromFile("normative-types-string-list-test.yml"), "stringTestTag", ToscaElementTypeEnum.STRING,
+ new ArrayList<>());
assertTrue(toscaElements.isLeft());
List<Object> list = toscaElements.left().value();
assertEquals(4, list.size());
@@ -73,8 +96,9 @@ public class ImportUtilsTest {
}
@Test
- public void testBooleanTypeFindToscaElements() throws IOException {
- Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements((Map<String, Object>) loadJsonFromFile("normative-types-all-map-test.yml"), "required", ToscaElementTypeEnum.BOOLEAN, new ArrayList<>());
+ void testBooleanTypeFindToscaElements() throws IOException {
+ Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements(
+ (Map<String, Object>) loadJsonFromFile("normative-types-all-map-test.yml"), "required", ToscaElementTypeEnum.BOOLEAN, new ArrayList<>());
assertTrue(toscaElements.isLeft());
List<Object> list = toscaElements.left().value();
assertEquals(3, list.size());
@@ -93,8 +117,10 @@ public class ImportUtilsTest {
}
@Test
- public void testListTypeFindToscaElements() throws IOException {
- Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements((Map<String, Object>) loadJsonFromFile("normative-types-string-list-test.yml"), "listTestTag", ToscaElementTypeEnum.LIST, new ArrayList<>());
+ void testListTypeFindToscaElements() throws IOException {
+ Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements(
+ (Map<String, Object>) loadJsonFromFile("normative-types-string-list-test.yml"), "listTestTag", ToscaElementTypeEnum.LIST,
+ new ArrayList<>());
assertTrue(toscaElements.isLeft());
List<Object> list = toscaElements.left().value();
assertEquals(3, list.size());
@@ -106,9 +132,7 @@ public class ImportUtilsTest {
verifyListElement1(element);
} else if (count == 2) {
verifyListElement2(element);
- }
-
- else if (count == 3) {
+ } else if (count == 3) {
verifyListElement3(element);
}
count++;
@@ -116,8 +140,9 @@ public class ImportUtilsTest {
}
@Test
- public void testAllTypeFindToscaElements() throws IOException {
- Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements((Map<String, Object>) loadJsonFromFile("normative-types-all-map-test.yml"), "allTestTag", ToscaElementTypeEnum.ALL, new ArrayList<>());
+ void testAllTypeFindToscaElements() throws IOException {
+ Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements(
+ (Map<String, Object>) loadJsonFromFile("normative-types-all-map-test.yml"), "allTestTag", ToscaElementTypeEnum.ALL, new ArrayList<>());
assertTrue(toscaElements.isLeft());
List<Object> list = toscaElements.left().value();
assertEquals(5, list.size());
@@ -139,14 +164,10 @@ public class ImportUtilsTest {
assertEquals("required", elementEntry.getKey());
assertTrue(elementEntry.getValue() instanceof Boolean);
assertTrue((Boolean) elementEntry.getValue());
- }
-
- else if (count == 3) {
+ } else if (count == 3) {
assertTrue(element instanceof String);
assertEquals("1 MB", element);
- }
-
- else if (count == 4) {
+ } else if (count == 4) {
assertTrue(element instanceof List);
List<Object> listElement = (List<Object>) element;
assertEquals(2, listElement.size());
@@ -173,8 +194,9 @@ public class ImportUtilsTest {
}
@Test
- public void testMapTypeFindToscaElements() throws IOException {
- Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements((Map<String, Object>) loadJsonFromFile("normative-types-all-map-test.yml"), "mapTestTag", ToscaElementTypeEnum.MAP, new ArrayList<>());
+ void testMapTypeFindToscaElements() throws IOException {
+ Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements(
+ (Map<String, Object>) loadJsonFromFile("normative-types-all-map-test.yml"), "mapTestTag", ToscaElementTypeEnum.MAP, new ArrayList<>());
assertTrue(toscaElements.isLeft());
List<Object> list = toscaElements.left().value();
assertEquals(2, list.size());
@@ -214,14 +236,14 @@ public class ImportUtilsTest {
}
@Test
- public void testCreateFullHeatParameterModuleWithString() {
+ void testCreateFullHeatParameterModuleWithString() {
testCreateFullHeatParameterModule("string", "default value");
}
@Test
- public void testCreateFullHeatParameterModuleWithNumber() {
+ void testCreateFullHeatParameterModuleWithNumber() {
testCreateFullHeatParameterModule("number", "777");
testCreateFullHeatParameterModule("number", "777.23");
@@ -229,7 +251,7 @@ public class ImportUtilsTest {
}
@Test
- public void testCreateFullHeatParameterModuleWithBoolean() {
+ void testCreateFullHeatParameterModuleWithBoolean() {
testCreateFullHeatParameterModule("boolean", "true");
testCreateFullHeatParameterModule("boolean", "on");
@@ -238,34 +260,14 @@ public class ImportUtilsTest {
}
@Test
- public void testCreateFullHeatParameterModuleWithList() {
+ void testCreateFullHeatParameterModuleWithList() {
testCreateFullHeatParameterModule("comma_delimited_list", "[one, two]");
}
- // @Test
- // public void testCreateFullHeatParameterModuleWithInvalidType(){
- //
- // String name = "fullParameter";
- // String description = "description_text";
- //
- // Map<String, Object> parametersMap = new HashMap<String, Object>();
- // Map<String, Object> firstParam = createParameterMap("aaa", "aaa",
- // name, description);
- // parametersMap.put(ToscaTagNamesEnum.PARAMETERS.getElementName(),
- // firstParam);
- //
- // Either<List<HeatParameterDefinition>,ResultStatusEnum> heatParameters =
- // ImportUtils.getHeatParameters(parametersMap);
- // assertTrue(heatParameters.isRight());
- // assertEquals(ResultStatusEnum.INVALID_PROPERTY_TYPE,
- // heatParameters.right().value());
- //
- // }
-
@Test
- public void testCreateFullHeatParameterModuleWithMissingType() {
+ void testCreateFullHeatParameterModuleWithMissingType() {
String name = "fullParameter";
String description = "description_text";
@@ -274,14 +276,15 @@ public class ImportUtilsTest {
Map<String, Object> firstParam = createParameterMap(null, "aaa", name, description);
parametersMap.put(TypeUtils.ToscaTagNamesEnum.PARAMETERS.getElementName(), firstParam);
- Either<List<HeatParameterDefinition>, ResultStatusEnum> heatParameters = ImportUtils.getHeatParameters(parametersMap, ArtifactTypeEnum.HEAT.getType());
+ Either<List<HeatParameterDefinition>, ResultStatusEnum> heatParameters = ImportUtils.getHeatParameters(parametersMap,
+ ArtifactTypeEnum.HEAT.getType());
assertTrue(heatParameters.isRight());
assertEquals(ResultStatusEnum.INVALID_PROPERTY_TYPE, heatParameters.right().value());
}
@Test
- public void testCreateFullHeatParameterModuleWithMissingFields() {
+ void testCreateFullHeatParameterModuleWithMissingFields() {
String name = "fullParameter";
@@ -292,7 +295,8 @@ public class ImportUtilsTest {
Map<String, Object> firstParam = createParameterMap(type, defValue, name, null);
parametersMap.put(TypeUtils.ToscaTagNamesEnum.PARAMETERS.getElementName(), firstParam);
- Either<List<HeatParameterDefinition>, ResultStatusEnum> heatParameters = ImportUtils.getHeatParameters(parametersMap, ArtifactTypeEnum.HEAT.getType());
+ Either<List<HeatParameterDefinition>, ResultStatusEnum> heatParameters = ImportUtils.getHeatParameters(parametersMap,
+ ArtifactTypeEnum.HEAT.getType());
assertTrue(heatParameters.isLeft());
List<HeatParameterDefinition> parameterDefList = heatParameters.left().value();
assertFalse(parameterDefList.isEmpty());
@@ -303,7 +307,7 @@ public class ImportUtilsTest {
}
@Test
- public void testGetPropertiesFromYml() throws IOException {
+ void testGetPropertiesFromYml() throws IOException {
Map<String, Object> toscaJson = (Map<String, Object>) loadJsonFromFile("importToscaProperties.yml");
Either<Map<String, PropertyDefinition>, ResultStatusEnum> actualProperties = ImportUtils.getProperties(toscaJson);
@@ -314,7 +318,7 @@ public class ImportUtilsTest {
}
@Test
- public void testGetPropertiesWithConstraintsFromYml() throws IOException {
+ void testGetPropertiesWithConstraintsFromYml() throws IOException {
Map<String, Object> toscaJson = (Map<String, Object>) loadJsonFromFile("propertyConstraintsTest.yml");
Either<Map<String, PropertyDefinition>, ResultStatusEnum> actualProperties = ImportUtils.getProperties(toscaJson);
@@ -322,7 +326,7 @@ public class ImportUtilsTest {
Map<String, PropertyDefinition> properties = actualProperties.left().value();
assertTrue(properties.containsKey("service_type"));
PropertyDefinition property = properties.get("service_type");
- assertTrue(property.getConstraints()!= null && property.getConstraints().size() == 1);
+ assertTrue(property.getConstraints() != null && property.getConstraints().size() == 1);
assertTrue(property.getConstraints().get(0) instanceof ValidValuesConstraint);
assertNotNull(((ValidValuesConstraint) property.getConstraints().get(0)).getValidValues());
List<String> validValues = ((ValidValuesConstraint) property.getConstraints().get(0)).getValidValues();
@@ -330,7 +334,7 @@ public class ImportUtilsTest {
assertTrue(properties.containsKey("service_interface_type_list"));
property = properties.get("service_interface_type_list");
- assertTrue(property.getSchema()!= null && property.getSchema().getProperty() != null);
+ assertTrue(property.getSchema() != null && property.getSchema().getProperty() != null);
PropertyDefinition innerProperty = new PropertyDefinition(property.getSchema().getProperty());
List<PropertyConstraint> innerConstraints = innerProperty.getConstraints();
assertTrue(innerConstraints.get(0) instanceof ValidValuesConstraint);
@@ -340,14 +344,14 @@ public class ImportUtilsTest {
}
@Test
- public void testGetInputsFromYml() throws IOException {
+ void testGetInputsFromYml() throws IOException {
- Map<String, Object> toscaJson = (Map<String, Object>) loadJsonFromFile("importToscaInputs.yml");
+ Map<String, Object> toscaJson = (Map<String, Object>) loadJsonFromFile("importToscaInputsOutputs.yml");
- AnnotationTypeOperations annotationTypeOperations= Mockito.mock(AnnotationTypeOperations.class);
+ AnnotationTypeOperations annotationTypeOperations = Mockito.mock(AnnotationTypeOperations.class);
Mockito.when(annotationTypeOperations.getLatestType(Mockito.anyString())).thenReturn(null);
- Either<Map<String, InputDefinition>, ResultStatusEnum> actualInputs = ImportUtils.getInputs(toscaJson,annotationTypeOperations);
+ Either<Map<String, InputDefinition>, ResultStatusEnum> actualInputs = ImportUtils.getInputs(toscaJson, annotationTypeOperations);
assertTrue(actualInputs.isLeft());
Map<String, Map<String, Object>> expectedProperties = getElements(toscaJson, TypeUtils.ToscaTagNamesEnum.INPUTS);
compareProperties(expectedProperties, actualInputs.left().value());
@@ -358,7 +362,18 @@ public class ImportUtilsTest {
compareProperties(expectedProperties, actualInputs.left().value());
}
- private void compareAttributes(Map<String, Map<String, Object>> expected, Map<String, AttributeDataDefinition> actual) {
+ @Test
+ void testGetOutputsFromYml() throws IOException {
+
+ Map<String, Object> toscaJson = (Map<String, Object>) loadJsonFromFile("importToscaInputsOutputs.yml");
+
+ Either<Map<String, OutputDefinition>, ResultStatusEnum> actualOutputs = ImportUtils.getOutputs(toscaJson);
+ assertTrue(actualOutputs.isLeft());
+ Map<String, Map<String, Object>> expectedProperties = getElements(toscaJson, TypeUtils.ToscaTagNamesEnum.OUTPUTS);
+ compareAttributes(expectedProperties, actualOutputs.left().value());
+ }
+
+ private void compareAttributes(Map<String, Map<String, Object>> expected, Map<String, OutputDefinition> actual) {
Map<String, Object> singleExpectedAttribute;
AttributeDataDefinition actualAttribute, expectedAttributeModel;
@@ -373,11 +388,11 @@ public class ImportUtilsTest {
expectedAttributeModel = ImportUtils.createModuleAttribute(singleExpectedAttribute);
expectedAttributeModel.setName(expectedAttribute.getKey().toString());
- assertEquals(((AttributeDefinition)expectedAttributeModel).getDefaultValue(), ((AttributeDefinition)actualAttribute).getDefaultValue());
- assertEquals(((AttributeDefinition)expectedAttributeModel).getDescription(), ((AttributeDefinition)actualAttribute).getDescription());
- assertEquals(((AttributeDefinition)expectedAttributeModel).getName(), ((AttributeDefinition)actualAttribute).getName());
- assertEquals(((AttributeDefinition)expectedAttributeModel).getStatus(), ((AttributeDefinition)actualAttribute).getStatus());
- assertEquals(((AttributeDefinition)expectedAttributeModel).getType(), ((AttributeDefinition)actualAttribute).getType());
+ assertEquals(((AttributeDefinition) expectedAttributeModel).getDefaultValue(), ((AttributeDefinition) actualAttribute).getDefaultValue());
+ assertEquals(((AttributeDefinition) expectedAttributeModel).getDescription(), ((AttributeDefinition) actualAttribute).getDescription());
+ assertEquals(((AttributeDefinition) expectedAttributeModel).getName(), ((AttributeDefinition) actualAttribute).getName());
+ assertEquals(((AttributeDefinition) expectedAttributeModel).getStatus(), ((AttributeDefinition) actualAttribute).getStatus());
+ assertEquals(((AttributeDefinition) expectedAttributeModel).getType(), ((AttributeDefinition) actualAttribute).getType());
compareSchemas(expectedAttributeModel.getSchema(), actualAttribute.getSchema());
@@ -385,7 +400,7 @@ public class ImportUtilsTest {
}
- private void compareProperties(Map<String, Map<String, Object>> expected, Map<String, ? extends PropertyDefinition > actual) {
+ private void compareProperties(Map<String, Map<String, Object>> expected, Map<String, ? extends PropertyDefinition> actual) {
Map<String, Object> singleExpectedProperty;
PropertyDefinition actualProperty, expectedPropertyModel;
@@ -444,7 +459,8 @@ public class ImportUtilsTest {
Map<String, Object> firstParam = createParameterMap(type, defaultVal, name, description);
parametersMap.put(TypeUtils.ToscaTagNamesEnum.PARAMETERS.getElementName(), firstParam);
- Either<List<HeatParameterDefinition>, ResultStatusEnum> heatParameters = ImportUtils.getHeatParameters(parametersMap, ArtifactTypeEnum.HEAT.getType());
+ Either<List<HeatParameterDefinition>, ResultStatusEnum> heatParameters = ImportUtils.getHeatParameters(parametersMap,
+ ArtifactTypeEnum.HEAT.getType());
assertTrue(heatParameters.isLeft());
List<HeatParameterDefinition> parameterDefList = heatParameters.left().value();
assertFalse(parameterDefList.isEmpty());
@@ -532,26 +548,4 @@ public class ImportUtilsTest {
assertEquals("stringVal2", innerEntry.getValue());
}
- public static String loadFileNameToJsonString(String fileName) throws IOException {
- String sourceDir = "src/test/resources/normativeTypes";
- return loadFileNameToJsonString(sourceDir, fileName);
- }
-
- public static String loadCustomTypeFileNameToJsonString(String fileName) throws IOException {
- String sourceDir = "src/test/resources/customTypes";
- return loadFileNameToJsonString(sourceDir, fileName);
- }
-
- private static String loadFileNameToJsonString(String sourceDir, String fileName) throws IOException {
- java.nio.file.Path filePath = FileSystems.getDefault().getPath(sourceDir, fileName);
- byte[] fileContent = Files.readAllBytes(filePath);
- return new String(fileContent);
- }
-
-
- private static Object loadJsonFromFile(String fileName) throws IOException {
- String content = loadFileNameToJsonString(fileName);
- return new Yaml().load(content);
- }
-
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java
index 9c7e3848c6..cfdd774f67 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/OutputsBusinessLogicTest.java
@@ -20,10 +20,13 @@
package org.openecomp.sdc.be.components.impl;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -31,11 +34,13 @@ import static org.mockito.Mockito.when;
import fj.data.Either;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+import javax.ws.rs.core.Response.Status;
import org.apache.commons.collections.CollectionUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -48,18 +53,19 @@ import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.ComponentInstOutputsMap;
import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.ComponentInstanceOutput;
import org.openecomp.sdc.be.model.ComponentInstanceAttribOutput;
+import org.openecomp.sdc.be.model.ComponentInstanceOutput;
import org.openecomp.sdc.be.model.ComponentParametersView;
-import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
@@ -92,31 +98,24 @@ class OutputsBusinessLogicTest {
@Mock
private ComponentsUtils componentsUtilsMock;
-
@Mock
private UserBusinessLogic userAdminMock;
-
@Mock
private ToscaOperationFacade toscaOperationFacadeMock;
-
@Mock
private UserValidations userValidations;
-
@Mock
private IGraphLockOperation graphLockOperation;
-
@Mock
private AttributeDeclarationOrchestrator attributeDeclarationOrchestrator;
-
@Mock
private ApplicationDataTypeCache applicationDataTypeCache;
-
@Mock
private AttributeOperation attributeOperation;
-
@Mock
private JanusGraphDao janusGraphDao;
-
+ @Mock
+ private ResponseFormatManager responseFormatManager;
@InjectMocks
private OutputsBusinessLogic testInstance;
@@ -126,7 +125,7 @@ class OutputsBusinessLogicTest {
private List<ComponentInstanceOutput> outputsList;
@BeforeEach
- public void setUp() {
+ void setUp() {
MockitoAnnotations.openMocks(this);
service = new Service();
service.setUniqueId(COMPONENT_ID);
@@ -145,6 +144,10 @@ class OutputsBusinessLogicTest {
// add a ComponentInstance
final ComponentInstance componentInstance = new ComponentInstance();
componentInstance.setUniqueId(COMPONENT_INSTANCE_ID);
+ componentInstance.setName(COMPONENT_INSTANCE_ID);
+ final AttributeDefinition attributeDefinition = new AttributeDefinition();
+ attributeDefinition.setName("attribName");
+ componentInstance.setAttributes(Collections.singletonList(attributeDefinition));
service.setComponentInstances(Collections.singletonList(componentInstance));
instanceOutputMap = new HashMap<>();
@@ -235,10 +238,8 @@ class OutputsBusinessLogicTest {
}
private void initMockitoStubbings(List<OutputDefinition> declaredPropertiesToOutputs) {
- when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(
- Either.left(service));
- when(attributeDeclarationOrchestrator.declareAttributesToOutputs(any(), any())).thenReturn(Either.left(
- declaredPropertiesToOutputs));
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(Either.left(service));
+ when(attributeDeclarationOrchestrator.declareAttributesToOutputs(any(), any())).thenReturn(Either.left(declaredPropertiesToOutputs));
when(toscaOperationFacadeMock.addOutputsToComponent(any(), any())).thenReturn(Either.left(declaredPropertiesToOutputs));
when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
when(graphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
@@ -299,8 +300,7 @@ class OutputsBusinessLogicTest {
service.setOutputs(Collections.singletonList(listOutput));
final String NONEXIST_OUTPUT_NAME = "myOutput";
- when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
- .thenReturn(Either.left(service));
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(Either.left(service));
try {
testInstance.deleteOutput(COMPONENT_ID, USER_ID, NONEXIST_OUTPUT_NAME);
@@ -319,8 +319,7 @@ class OutputsBusinessLogicTest {
listOutput.setUniqueId(outputId);
service.setOutputs(Collections.singletonList(listOutput));
- when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
- .thenReturn(Either.left(service));
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(Either.left(service));
when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.NOT_FOUND);
when(componentsUtilsMock.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, ComponentTypeEnum.SERVICE))
.thenReturn(ActionStatus.SERVICE_NOT_FOUND);
@@ -343,8 +342,7 @@ class OutputsBusinessLogicTest {
listOutput.setUniqueId(outputId);
service.setOutputs(Collections.singletonList(listOutput));
- when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
- .thenReturn(Either.left(service));
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(Either.left(service));
when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
when(toscaOperationFacadeMock.deleteOutputOfResource(service, listOutput.getName())).thenReturn(StorageOperationStatus.BAD_REQUEST);
when(componentsUtilsMock.convertFromStorageResponse(StorageOperationStatus.BAD_REQUEST)).thenReturn(ActionStatus.INVALID_CONTENT);
@@ -368,8 +366,7 @@ class OutputsBusinessLogicTest {
listOutput.setUniqueId(outputId);
service.setOutputs(Collections.singletonList(listOutput));
- when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
- .thenReturn(Either.left(service));
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(Either.left(service));
when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
when(toscaOperationFacadeMock.deleteOutputOfResource(service, listOutput.getName())).thenReturn(StorageOperationStatus.OK);
when(attributeDeclarationOrchestrator.unDeclareAttributesAsOutputs(service, listOutput)).thenReturn(StorageOperationStatus.BAD_REQUEST);
@@ -392,8 +389,7 @@ class OutputsBusinessLogicTest {
listOutput.setUniqueId(outputId);
service.setOutputs(Collections.singletonList(listOutput));
- when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
- .thenReturn(Either.left(service));
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(Either.left(service));
when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
when(toscaOperationFacadeMock.deleteOutputOfResource(service, listOutput.getName())).thenReturn(StorageOperationStatus.OK);
when(attributeDeclarationOrchestrator.unDeclareAttributesAsOutputs(service, listOutput)).thenReturn(StorageOperationStatus.OK);
@@ -402,4 +398,69 @@ class OutputsBusinessLogicTest {
verify(attributeDeclarationOrchestrator, times(1)).unDeclareAttributesAsOutputs(service, listOutput);
}
+ @Test
+ void testCreateOutputsInGraph_OK() {
+ final Map<String, OutputDefinition> outputs = new HashMap<>();
+ final var out_1 = new OutputDefinition();
+ out_1.setName("out-1");
+ out_1.setValue("{ get_attribute: [ instanceId, attribName ] }");
+ final var out_2 = new OutputDefinition();
+ out_2.setName("out-2");
+ out_2.setValue("{ get_attribute: [ SELF, oneMoreAttribute ] }");
+ outputs.put(out_1.getName(), out_1);
+ outputs.put(out_2.getName(), out_2);
+
+ final List<OutputDefinition> serviceOutputs = new ArrayList<>();
+ final var out_3 = new OutputDefinition();
+ out_3.setName("out-3");
+ serviceOutputs.add(out_3);
+ service.setOutputs(serviceOutputs);
+
+ final List<OutputDefinition> list = Arrays.asList(out_1, out_2, out_3);
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(Either.left(service));
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
+ when(attributeDeclarationOrchestrator.declareAttributesToOutputs(eq(service), any(ComponentInstOutputsMap.class)))
+ .thenReturn(Either.left(list));
+ when(toscaOperationFacadeMock.addOutputsToComponent(anyMap(), anyString())).thenReturn(Either.left(list));
+
+ final var result = testInstance.createOutputsInGraph(outputs, service, USER_ID);
+ assertTrue(result.isLeft());
+ assertEquals(3, result.left().value().size());
+ assertEquals(list, result.left().value());
+ }
+
+ @Test
+ void testCreateOutputsInGraph_NegativeCreateAndAssociateOutputsStatus() {
+ final Map<String, OutputDefinition> outputs = new HashMap<>();
+ final var out_1 = new OutputDefinition();
+ out_1.setName("out-1");
+ out_1.setValue("{ get_attribute: [ instanceId, attribName ] }");
+ final var out_2 = new OutputDefinition();
+ out_2.setName("out-2");
+ out_2.setValue("{ get_attribute: [ SELF, oneMoreAttribute ] }");
+ outputs.put(out_1.getName(), out_1);
+ outputs.put(out_2.getName(), out_2);
+
+ final List<OutputDefinition> serviceOutputs = new ArrayList<>();
+ final var out_3 = new OutputDefinition();
+ out_3.setName("out-3");
+ serviceOutputs.add(out_3);
+ service.setOutputs(serviceOutputs);
+
+ final var list = Arrays.asList(out_1, out_2, out_3);
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(Either.left(service));
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
+ when(attributeDeclarationOrchestrator.declareAttributesToOutputs(eq(service), any(ComponentInstOutputsMap.class)))
+ .thenReturn(Either.left(list));
+ when(toscaOperationFacadeMock.addOutputsToComponent(anyMap(), eq(COMPONENT_ID)))
+ .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ when(componentsUtilsMock.convertFromStorageResponse(StorageOperationStatus.GENERAL_ERROR)).thenReturn(ActionStatus.GENERAL_ERROR);
+ when(componentsUtilsMock.getResponseFormat(StorageOperationStatus.GENERAL_ERROR))
+ .thenReturn(new ResponseFormat(Status.INTERNAL_SERVER_ERROR.getStatusCode()));
+
+ final var result = testInstance.createOutputsInGraph(outputs, service, USER_ID);
+ assertNotNull(result);
+ assertTrue(result.isRight());
+ assertEquals(500, result.right().value().getStatus());
+ }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
index 1d6a3ff673..dcc0289822 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.anyMap;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.openecomp.sdc.be.components.impl.ServiceImportBusinessLogic.CREATE_RESOURCE;
@@ -50,7 +51,6 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
-import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.csar.CsarInfo;
import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo;
@@ -108,18 +108,15 @@ import org.openecomp.sdc.exception.ResponseFormat;
class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTestSetup {
- @InjectMocks
- private ServiceImportBusinessLogic sIBL;
-
- @Mock
- private ArtifactDefinition artifactDefinition;
- @Mock
- private ServletUtils servletUtils;
- @Mock
- private ResourceImportManager resourceImportManager;
+ private static final String DEFAULT_ICON = "defaulticon";
- private AbstractValidationsServlet servlet = new ArtifactExternalServlet(userBusinessLogic,
+ private final ArtifactDefinition artifactDefinition = mock(ArtifactDefinition.class);
+ private final ResourceImportManager resourceImportManager = mock(ResourceImportManager.class);
+ private final ServletUtils servletUtils = mock(ServletUtils.class);
+ private final AbstractValidationsServlet servlet = new ArtifactExternalServlet(userBusinessLogic,
componentInstanceBusinessLogic, componentsUtils, servletUtils, resourceImportManager, artifactsBusinessLogic);
+ @InjectMocks
+ private ServiceImportBusinessLogic sIBL;
public static String loadFileNameToJsonString(String fileName) throws IOException {
String sourceDir = "src/test/resources/normativeTypes";
@@ -185,6 +182,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(serviceImportParseLogic.getServiceWithGroups(anyString())).thenReturn(newService);
when(mockJanusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
when(graphLockOperation.unlockComponentByName(anyString(), anyString(), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
+ when(serviceImportParseLogic.createOutputsOnService(any(Service.class), any(), anyString())).thenReturn(newService);
Service result = sIBL.createService(oldService, AuditingActionEnum.CREATE_RESOURCE, user, payload, payloadName);
assertNotNull(result);
@@ -259,7 +257,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceFromYaml(oldService,
topologyTemplateYaml, yamlName, nodeTypesInfo, csarInfo,
- nodeTypesArtifactsToCreate, false, true, nodeName));
+ nodeTypesArtifactsToCreate, false, true, nodeName, user.getUserId()));
}
@Test
@@ -278,7 +276,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
csfyp.setParsedToscaYamlInfo(parsedToscaYamlInfo);
when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(resource));
Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceAndRIsFromYaml(oldService,
- false, nodeTypesArtifactsToCreate, false, true, csfyp));
+ false, nodeTypesArtifactsToCreate, false, true, csfyp, user.getUserId()));
}
@Test
@@ -297,7 +295,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
csfyp.setParsedToscaYamlInfo(parsedToscaYamlInfo);
when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(resource));
Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceAndRIsFromYaml(oldService,
- false, nodeTypesArtifactsToCreate, false, true, csfyp));
+ false, nodeTypesArtifactsToCreate, false, true, csfyp, user.getUserId()));
}
@Test
@@ -749,21 +747,26 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
void testCreateGroupsOnResourceNull() {
Service service = createServiceObject(true);
Map<String, GroupDefinition> groups = new HashMap<>();
- Assertions.assertNotNull(sIBL.createGroupsOnResource(service, groups));
+ Assertions.assertNotNull(
+ sIBL.createGroupsOnResource(service, groups));
}
@Test
void testUpdateGroupsMembersUsingResource() {
Service service = createServiceObject(true);
Map<String, GroupDefinition> groups = getGroups();
- Assertions.assertNotNull(sIBL.updateGroupsMembersUsingResource(groups, service));
+
+ Assertions.assertNotNull(
+ sIBL.updateGroupsMembersUsingResource(groups, service));
}
@Test
void testUpdateGroupsMembersUsingResource_left() {
Service service = createServiceObject(true);
Map<String, GroupDefinition> groups = getGroups();
- Assertions.assertNotNull(sIBL.updateGroupsMembersUsingResource(groups, service));
+
+ Assertions.assertNotNull(
+ sIBL.updateGroupsMembersUsingResource(groups, service));
}
@Test
@@ -1881,7 +1884,9 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
groupDefinition.setUniqueId("groupDefinitionUniqueId");
groupDefinition.setName("groupDefinition");
groupDefinitionList.add(groupDefinition);
- Assertions.assertNotNull(sIBL.createGroupsOnResource(resource, groups));
+
+ Assertions.assertNotNull(
+ sIBL.createGroupsOnResource(resource, groups));
}
@Test
@@ -1897,14 +1902,18 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
void testUpdateGroupsMembersUsingResource2() {
Resource resource = createParseResourceObject(true);
Map<String, GroupDefinition> groups = getGroups();
- Assertions.assertNotNull(sIBL.updateGroupsMembersUsingResource(groups, resource));
+
+ Assertions.assertNotNull(
+ sIBL.updateGroupsMembersUsingResource(groups, resource));
}
@Test
void testUpdateGroupsMembersUsingResource_left2() {
Resource resource = createParseResourceObject(true);
Map<String, GroupDefinition> groups = getGroups();
- Assertions.assertNotNull(sIBL.updateGroupsMembersUsingResource(groups, resource));
+
+ Assertions.assertNotNull(
+ sIBL.updateGroupsMembersUsingResource(groups, resource));
}
@Test
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java
index 8ff8163128..beaa695fe4 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java
@@ -20,6 +20,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import fj.data.Either;
@@ -43,15 +44,8 @@ import org.openecomp.sdc.ElementOperationMock;
import org.openecomp.sdc.be.components.csar.CsarArtifactsAndGroupsBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarInfo;
-import org.openecomp.sdc.be.components.distribution.engine.DistributionEngine;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
-import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.utils.CreateServiceFromYamlParameter;
-import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
-import org.openecomp.sdc.be.components.merge.resource.ResourceDataMergeBusinessLogic;
-import org.openecomp.sdc.be.components.path.ForwardingPathValidator;
-import org.openecomp.sdc.be.components.validation.NodeFilterValidator;
-import org.openecomp.sdc.be.components.validation.ServiceDistributionValidation;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.components.validation.component.ComponentContactIdValidator;
import org.openecomp.sdc.be.components.validation.component.ComponentDescriptionValidator;
@@ -71,9 +65,7 @@ import org.openecomp.sdc.be.components.validation.service.ServiceRoleValidator;
import org.openecomp.sdc.be.components.validation.service.ServiceTypeValidator;
import org.openecomp.sdc.be.components.validation.service.ServiceValidator;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
-import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -85,6 +77,7 @@ import org.openecomp.sdc.be.externalapi.servlet.representation.ReplaceVNFInfo;
import org.openecomp.sdc.be.externalapi.servlet.representation.ResourceInstanceMetadata;
import org.openecomp.sdc.be.facade.operations.CatalogOperation;
import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.CapabilityDefinition;
@@ -105,7 +98,6 @@ import org.openecomp.sdc.be.model.UploadReqInfo;
import org.openecomp.sdc.be.model.UploadServiceInfo;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
-import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeFilterOperation;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -133,36 +125,29 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
private static final String RESOURCE_TOSCA_NAME = "My-Resource_Tosca_Name";
private static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
private static final String RESOURCE_SUBCATEGORY = "Router";
- protected final ServletContext servletContext = Mockito.mock(ServletContext.class);
- protected final ComponentValidator componentValidator = Mockito.mock(ComponentValidator.class);
- final DistributionEngine distributionEngine = Mockito.mock(DistributionEngine.class);
- final ServiceDistributionValidation serviceDistributionValidation = Mockito.mock(ServiceDistributionValidation.class);
- final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
- final ForwardingPathValidator forwardingPathValidator = Mockito.mock(ForwardingPathValidator.class);
- final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
- final NodeFilterOperation serviceFilterOperation = Mockito.mock(NodeFilterOperation.class);
- final NodeFilterValidator serviceFilterValidator = Mockito.mock(NodeFilterValidator.class);
- // final ServiceBusinessLogic serviceBusinessLogic = Mockito.mock(ServiceBusinessLogic.class);
- final CsarBusinessLogic csarBusinessLogic = Mockito.mock(CsarBusinessLogic.class);
- final LifecycleBusinessLogic lifecycleBusinessLogic = Mockito.mock(LifecycleBusinessLogic.class);
- final CompositionBusinessLogic compositionBusinessLogic = Mockito.mock(CompositionBusinessLogic.class);
- final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic = Mockito.mock(ResourceDataMergeBusinessLogic.class);
- final ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic = Mockito.mock(ComponentNodeFilterBusinessLogic.class);
- protected UserBusinessLogic userBusinessLogic = Mockito.mock(UserBusinessLogic.class);
- protected WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
- protected WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
+
+ private final ArtifactDefinition artifactDefinition = mock(ArtifactDefinition.class);
+ private final ResourceImportManager resourceImportManager = mock(ResourceImportManager.class);
+ private final ServletUtils servletUtils = mock(ServletUtils.class);
+
+ protected final ServletContext servletContext = mock(ServletContext.class);
+ protected final ComponentValidator componentValidator = mock(ComponentValidator.class);
+ final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = mock(ComponentInstanceBusinessLogic.class);
+ final CsarBusinessLogic csarBusinessLogic = mock(CsarBusinessLogic.class);
+ final CompositionBusinessLogic compositionBusinessLogic = mock(CompositionBusinessLogic.class);
+ protected UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class);
+ protected WebAppContextWrapper webAppContextWrapper = mock(WebAppContextWrapper.class);
+ protected WebApplicationContext webAppContext = mock(WebApplicationContext.class);
protected ResponseFormatManager responseManager = null;
- protected ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
- protected AuditCassandraDao auditingDao = Mockito.mock(AuditCassandraDao.class);
- protected ArtifactsBusinessLogic artifactsBusinessLogic = Mockito.mock(ArtifactsBusinessLogic.class);
- protected GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
- protected JanusGraphDao mockJanusGraphDao = Mockito.mock(JanusGraphDao.class);
- protected ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
- protected CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic = Mockito.mock(CsarArtifactsAndGroupsBusinessLogic.class);
- protected GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
- protected UserValidations userValidations = Mockito.mock(UserValidations.class);
- protected CatalogOperation catalogOperation = Mockito.mock(CatalogOperation.class);
- protected ServiceImportParseLogic serviceImportParseLogic = Mockito.mock(ServiceImportParseLogic.class);
+ protected ComponentsUtils componentsUtils = mock(ComponentsUtils.class);
+ protected ArtifactsBusinessLogic artifactsBusinessLogic = mock(ArtifactsBusinessLogic.class);
+ protected GraphLockOperation graphLockOperation = mock(GraphLockOperation.class);
+ protected JanusGraphDao mockJanusGraphDao = mock(JanusGraphDao.class);
+ protected ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class);
+ protected CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic = mock(CsarArtifactsAndGroupsBusinessLogic.class);
+ protected UserValidations userValidations = mock(UserValidations.class);
+ protected CatalogOperation catalogOperation = mock(CatalogOperation.class);
+ protected ServiceImportParseLogic serviceImportParseLogic = mock(ServiceImportParseLogic.class);
protected ServiceTypeValidator serviceTypeValidator = new ServiceTypeValidator(componentsUtils);
protected ServiceRoleValidator serviceRoleValidator = new ServiceRoleValidator(componentsUtils);
protected ServiceFunctionValidator serviceFunctionValidator = new ServiceFunctionValidator(componentsUtils);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java
index 0306ce082e..c564f59398 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java
@@ -17,8 +17,11 @@
package org.openecomp.sdc.be.components.impl;
import static org.assertj.core.api.Java6Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
@@ -43,6 +46,7 @@ import java.util.Map.Entry;
import java.util.NoSuchElementException;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.glassfish.grizzly.http.util.HttpStatus;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -77,6 +81,7 @@ import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.NodeTypeInfo;
+import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
import org.openecomp.sdc.be.model.RequirementDefinition;
@@ -118,6 +123,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
private final IElementOperation elementDao = mock(IElementOperation.class);
private final IInterfaceLifecycleOperation interfaceTypeOperation = mock(IInterfaceLifecycleOperation.class);
private final InputsBusinessLogic inputsBusinessLogic = mock(InputsBusinessLogic.class);
+ private final OutputsBusinessLogic outputsBusinessLogic = mock(OutputsBusinessLogic.class);
private final LifecycleBusinessLogic lifecycleBusinessLogic = mock(LifecycleBusinessLogic.class);
private final ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic = mock(ComponentNodeFilterBusinessLogic.class);
@@ -128,7 +134,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
private ServiceImportParseLogic createTestSubject() {
return new ServiceImportParseLogic(serviceBusinessLogic, componentsUtils, toscaOperationFacade, lifecycleBusinessLogic, inputsBusinessLogic,
null, null, interfaceTypeOperation, capabilityTypeOperation, componentNodeFilterBusinessLogic,
- groupBusinessLogic);
+ groupBusinessLogic, outputsBusinessLogic);
}
@BeforeEach
@@ -1130,6 +1136,77 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
}
@Test
+ void testCreateOutputsOnService_OK() {
+ Service service = createServiceObject(true);
+ List<OutputDefinition> resourceOutputs = new ArrayList<>();
+ OutputDefinition outputDefinition = new OutputDefinition();
+ resourceOutputs.add(outputDefinition);
+ outputDefinition.setName("outputDefinitionName");
+ service.setOutputs(resourceOutputs);
+ Map<String, OutputDefinition> outputs = new HashMap<>();
+ outputs.put("outputsMap", outputDefinition);
+
+ when(outputsBusinessLogic.createOutputsInGraph(outputs, service, user.getUserId())).thenReturn(Either.left(resourceOutputs));
+ when(toscaOperationFacade.getToscaElement(service.getUniqueId())).thenReturn(Either.left(service));
+ Service outputsOnService = testSubject.createOutputsOnService(service, outputs, user.getUserId());
+ assertNotNull(outputsOnService);
+ assertSame(service, outputsOnService);
+ }
+
+ @Test
+ void testCreateOutputsOnService_Fail_whenOutputsIsEmpty() {
+ Service service = createServiceObject(true);
+ Map<String, OutputDefinition> outputs = new HashMap<>();
+ Service outputsOnService = testSubject.createOutputsOnService(service, outputs, user.getUserId());
+ assertNotNull(outputsOnService);
+ assertSame(service, outputsOnService);
+ }
+
+ @Test
+ void testCreateOutputsOnService_Fail_createOutputsInGraph() {
+ Service service = createServiceObject(true);
+ List<OutputDefinition> resourceOutputs = new ArrayList<>();
+ OutputDefinition outputDefinition = new OutputDefinition();
+ resourceOutputs.add(outputDefinition);
+ outputDefinition.setName("outputDefinitionName");
+ service.setOutputs(resourceOutputs);
+ Map<String, OutputDefinition> outputs = new HashMap<>();
+ outputs.put("outputsMap", outputDefinition);
+
+ when(outputsBusinessLogic.createOutputsInGraph(outputs, service, user.getUserId()))
+ .thenReturn(Either.right(new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode())));
+
+ final var componentException = assertThrows(ComponentException.class, () -> {
+ testSubject.createOutputsOnService(service, outputs, user.getUserId());
+ });
+ assertNotNull(componentException);
+ assertEquals(ActionStatus.OK, componentException.getActionStatus());
+ assertEquals(400, componentException.getResponseFormat().getStatus());
+ }
+
+ @Test
+ void testCreateOutputsOnService_Fail_getToscaElement() {
+ Service service = createServiceObject(true);
+ List<OutputDefinition> resourceOutputs = new ArrayList<>();
+ OutputDefinition outputDefinition = new OutputDefinition();
+ resourceOutputs.add(outputDefinition);
+ outputDefinition.setName("outputDefinitionName");
+ service.setOutputs(resourceOutputs);
+ Map<String, OutputDefinition> outputs = new HashMap<>();
+ outputs.put("outputsMap", outputDefinition);
+
+ when(outputsBusinessLogic.createOutputsInGraph(outputs, service, user.getUserId())).thenReturn(Either.left(resourceOutputs));
+ when(toscaOperationFacade.getToscaElement(service.getUniqueId())).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+
+ final var componentException = assertThrows(ComponentException.class, () -> {
+ testSubject.createOutputsOnService(service, outputs, user.getUserId());
+ });
+ assertNotNull(componentException);
+ assertEquals(ActionStatus.OK, componentException.getActionStatus());
+ assertEquals(400, componentException.getResponseFormat().getStatus());
+ }
+
+ @Test
void testAssociateCINodeFilterToComponent() {
String yamlName = "yamlName.yml";
Service service = createServiceObject(true);
diff --git a/catalog-be/src/test/resources/normativeTypes/importToscaInputs.yml b/catalog-be/src/test/resources/normativeTypes/importToscaInputsOutputs.yml
index 9fac2fb2c7..83deccb333 100644
--- a/catalog-be/src/test/resources/normativeTypes/importToscaInputs.yml
+++ b/catalog-be/src/test/resources/normativeTypes/importToscaInputsOutputs.yml
@@ -11,28 +11,28 @@ metadata:
resourceVendorRelease: 1.0.0.wd03
resourceVendorModelNumber: '666'
imports:
-- nodes:
- file: nodes.yml
-- datatypes:
- file: data.yml
-- capabilities:
- file: capabilities.yml
-- relationships:
- file: relationships.yml
-- groups:
- file: groups.yml
-- policies:
- file: policies.yml
-- annotations:
- file: annotations.yml
-- resource-ciResVFOnboarded-base_vfw-aa8dcbff-nodes.vpgCvfc-interface:
- file: resource-CiresvfonboardedBaseVfwAa8dcbffNodesVpgcvfc-template-interface.yml
-- resource-CiresvfonboardedBaseVfwAa8dcbff.compute.nodes.heat.vpg:
- file: resource-Ciresvfonboardedbasevfwaa8dcbffComputeNodesHeatVpg-template.yml
-- resource-NeutronPort:
- file: resource-Neutronport-template.yml
-- resource-extNeutronCP:
- file: resource-Extneutroncp-template.yml
+ - nodes:
+ file: nodes.yml
+ - datatypes:
+ file: data.yml
+ - capabilities:
+ file: capabilities.yml
+ - relationships:
+ file: relationships.yml
+ - groups:
+ file: groups.yml
+ - policies:
+ file: policies.yml
+ - annotations:
+ file: annotations.yml
+ - resource-ciResVFOnboarded-base_vfw-aa8dcbff-nodes.vpgCvfc-interface:
+ file: resource-CiresvfonboardedBaseVfwAa8dcbffNodesVpgcvfc-template-interface.yml
+ - resource-CiresvfonboardedBaseVfwAa8dcbff.compute.nodes.heat.vpg:
+ file: resource-Ciresvfonboardedbasevfwaa8dcbffComputeNodesHeatVpg-template.yml
+ - resource-NeutronPort:
+ file: resource-Neutronport-template.yml
+ - resource-extNeutronCP:
+ file: resource-Extneutroncp-template.yml
topology_template:
inputs:
port_vpg_private_1_port_network:
@@ -201,6 +201,25 @@ topology_template:
port_vpg_private_0_port_order:
type: integer
required: false
+ outputs:
+ vpg_state:
+ value:
+ get_attribute:
+ - vpg
+ - state
+ type: string
+ vpg_vpg_private_0_port_tosca_name:
+ value:
+ get_attribute:
+ - vpg_vpg_private_0_port_tosca
+ - tosca_name
+ type: string
+ vpg_vpg_private_1_port_tosca_id:
+ value:
+ get_attribute:
+ - vpg_vpg_private_1_port
+ - tosca_id
+ type: string
node_templates:
vpg_vpg_private_0_port:
type: org.openecomp.resource.cp.nodes.heat.network.neutron.Port
@@ -225,8 +244,8 @@ topology_template:
get_input: port_vpg_private_0_port_related_networks
network:
get_input:
- - port_vpg_private_0_port_network
- - index_value
+ - port_vpg_private_0_port_network
+ - index_value
replacement_policy: AUTO
ip_requirements:
get_input: port_vpg_private_0_port_ip_requirements
@@ -234,8 +253,8 @@ topology_template:
get_input: port_vpg_private_0_port_network_role
fixed_ips:
get_input:
- - port_vpg_private_0_port_fixed_ips
- - index_value
+ - port_vpg_private_0_port_fixed_ips
+ - index_value
subinterface_indicator: false
mac_requirements:
get_input: port_vpg_private_0_port_mac_requirements
@@ -249,9 +268,9 @@ topology_template:
order:
get_input: port_vpg_private_0_port_order
requirements:
- - binding:
- capability: binding
- node: vpg
+ - binding:
+ capability: binding
+ node: vpg
capabilities:
network.outgoing.bytes.rate_vpg_vpg_private_0_port:
properties:
@@ -301,6 +320,9 @@ topology_template:
description: Number of incoming packets
type: Cumulative
category: network
+ attributes:
+ tosca_name:
+ type: string
vpg_vpg_private_1_port:
type: org.openecomp.resource.cp.v2.extNeutronCP
metadata:
@@ -324,8 +346,8 @@ topology_template:
get_input: port_vpg_private_1_port_related_networks
network:
get_input:
- - port_vpg_private_1_port_network
- - index_value
+ - port_vpg_private_1_port_network
+ - index_value
replacement_policy: AUTO
ip_requirements:
get_input: port_vpg_private_1_port_ip_requirements
@@ -333,8 +355,8 @@ topology_template:
get_input: port_vpg_private_1_port_network_role
fixed_ips:
get_input:
- - port_vpg_private_1_port_fixed_ips
- - index_value
+ - port_vpg_private_1_port_fixed_ips
+ - index_value
subinterface_indicator: false
mac_requirements:
get_input: port_vpg_private_1_port_mac_requirements
@@ -348,9 +370,9 @@ topology_template:
order:
get_input: port_vpg_private_1_port_order
requirements:
- - binding:
- capability: binding
- node: vpg
+ - binding:
+ capability: binding
+ node: vpg
capabilities:
network.incoming.bytes.rate_vpg_vpg_private_1_port:
properties:
@@ -406,6 +428,9 @@ topology_template:
description: Number of incoming bytes
type: Cumulative
category: network
+ attributes:
+ tosca_id:
+ type: string
vpg:
type: org.openecomp.resource.vfc.CiresvfonboardedBaseVfwAa8dcbff.abstract.compute.nodes.heat.vpg
metadata:
@@ -426,26 +451,26 @@ topology_template:
get_input: vm_flavor_name
key_name:
get_input:
- - compute_vpg_key_name
- - index_value
+ - compute_vpg_key_name
+ - index_value
image:
get_input: vm_image_name
image_update_policy: REBUILD
metadata:
get_input:
- - compute_vpg_metadata
- - index_value
+ - compute_vpg_metadata
+ - index_value
software_config_transport: POLL_SERVER_CFN
contrail_service_instance_ind: false
user_data_format:
get_input:
- - compute_vpg_user_data_format
- - index_value
+ - compute_vpg_user_data_format
+ - index_value
user_data_update_policy: REPLACE
name:
get_input:
- - compute_vpg_name
- - index_value
+ - compute_vpg_name
+ - index_value
flavor_update_policy: RESIZE
capabilities:
disk.read.bytes_vpg:
@@ -665,223 +690,226 @@ topology_template:
description: Average disk latency
type: Gauge
category: disk
+ attributes:
+ state:
+ type: string
substitution_mappings:
node_type: org.openecomp.resource.vfc.CiresvfonboardedBaseVfwAa8dcbffcvfc.abstract.nodes.vpg
capabilities:
network.incoming.bytes.rate_vpg_vpg_private_1_port:
- - vpg_vpg_private_1_port
- - network.incoming.bytes.rate
+ - vpg_vpg_private_1_port
+ - network.incoming.bytes.rate
disk.read.bytes_vpg:
- - vpg
- - disk.read.bytes
+ - vpg
+ - disk.read.bytes
binding_vpg_vpg_private_1_port:
- - vpg_vpg_private_1_port
- - binding
+ - vpg_vpg_private_1_port
+ - binding
network.outgoing.bytes.rate_vpg_vpg_private_0_port:
- - vpg_vpg_private_0_port
- - network.outgoing.bytes.rate
+ - vpg_vpg_private_0_port
+ - network.outgoing.bytes.rate
forwarder_vpg_vpg_private_0_port:
- - vpg_vpg_private_0_port
- - forwarder
+ - vpg_vpg_private_0_port
+ - forwarder
disk.allocation_vpg:
- - vpg
- - disk.allocation
+ - vpg
+ - disk.allocation
network.incoming.bytes_vpg_vpg_private_1_port:
- - vpg_vpg_private_1_port
- - network.incoming.bytes
+ - vpg_vpg_private_1_port
+ - network.incoming.bytes
attachment_vpg_vpg_private_0_port:
- - vpg_vpg_private_0_port
- - attachment
+ - vpg_vpg_private_0_port
+ - attachment
endpoint_vpg:
- - vpg
- - endpoint
+ - vpg
+ - endpoint
cpu_vpg:
- - vpg
- - cpu
+ - vpg
+ - cpu
disk.device.read.bytes.rate_vpg:
- - vpg
- - disk.device.read.bytes.rate
+ - vpg
+ - disk.device.read.bytes.rate
network.outgoing.bytes.rate_vpg_vpg_private_1_port:
- - vpg_vpg_private_1_port
- - network.outgoing.bytes.rate
+ - vpg_vpg_private_1_port
+ - network.outgoing.bytes.rate
feature_vpg_vpg_private_1_port:
- - vpg_vpg_private_1_port
- - feature
+ - vpg_vpg_private_1_port
+ - feature
disk.device.write.bytes.rate_vpg:
- - vpg
- - disk.device.write.bytes.rate
+ - vpg
+ - disk.device.write.bytes.rate
attachment_vpg_vpg_private_1_port:
- - vpg_vpg_private_1_port
- - attachment
+ - vpg_vpg_private_1_port
+ - attachment
disk.iops_vpg:
- - vpg
- - disk.iops
+ - vpg
+ - disk.iops
disk.usage_vpg:
- - vpg
- - disk.usage
+ - vpg
+ - disk.usage
disk.device.usage_vpg:
- - vpg
- - disk.device.usage
+ - vpg
+ - disk.device.usage
disk.device.read.bytes_vpg:
- - vpg
- - disk.device.read.bytes
+ - vpg
+ - disk.device.read.bytes
disk.device.write.bytes_vpg:
- - vpg
- - disk.device.write.bytes
+ - vpg
+ - disk.device.write.bytes
disk.write.requests_vpg:
- - vpg
- - disk.write.requests
+ - vpg
+ - disk.write.requests
feature_vpg:
- - vpg
- - feature
+ - vpg
+ - feature
disk.capacity_vpg:
- - vpg
- - disk.capacity
+ - vpg
+ - disk.capacity
disk.device.latency_vpg:
- - vpg
- - disk.device.latency
+ - vpg
+ - disk.device.latency
disk.device.write.requests.rate_vpg:
- - vpg
- - disk.device.write.requests.rate
+ - vpg
+ - disk.device.write.requests.rate
feature_vpg_vpg_private_0_port:
- - vpg_vpg_private_0_port
- - feature
+ - vpg_vpg_private_0_port
+ - feature
forwarder_vpg_vpg_private_1_port:
- - vpg_vpg_private_1_port
- - forwarder
+ - vpg_vpg_private_1_port
+ - forwarder
network.outgoing.packets.rate_vpg_vpg_private_1_port:
- - vpg_vpg_private_1_port
- - network.outgoing.packets.rate
+ - vpg_vpg_private_1_port
+ - network.outgoing.packets.rate
network.incoming.packets.rate_vpg_vpg_private_1_port:
- - vpg_vpg_private_1_port
- - network.incoming.packets.rate
+ - vpg_vpg_private_1_port
+ - network.incoming.packets.rate
binding_vpg:
- - vpg
- - binding
+ - vpg
+ - binding
disk.device.allocation_vpg:
- - vpg
- - disk.device.allocation
+ - vpg
+ - disk.device.allocation
network.incoming.bytes_vpg_vpg_private_0_port:
- - vpg_vpg_private_0_port
- - network.incoming.bytes
+ - vpg_vpg_private_0_port
+ - network.incoming.bytes
disk.ephemeral.size_vpg:
- - vpg
- - disk.ephemeral.size
+ - vpg
+ - disk.ephemeral.size
network.outgoing.bytes_vpg_vpg_private_1_port:
- - vpg_vpg_private_1_port
- - network.outgoing.bytes
+ - vpg_vpg_private_1_port
+ - network.outgoing.bytes
network.incoming.packets_vpg_vpg_private_1_port:
- - vpg_vpg_private_1_port
- - network.incoming.packets
+ - vpg_vpg_private_1_port
+ - network.incoming.packets
disk.write.requests.rate_vpg:
- - vpg
- - disk.write.requests.rate
+ - vpg
+ - disk.write.requests.rate
disk.write.bytes.rate_vpg:
- - vpg
- - disk.write.bytes.rate
+ - vpg
+ - disk.write.bytes.rate
disk.device.iops_vpg:
- - vpg
- - disk.device.iops
+ - vpg
+ - disk.device.iops
host_vpg:
- - vpg
- - host
+ - vpg
+ - host
network.outpoing.packets_vpg_vpg_private_0_port:
- - vpg_vpg_private_0_port
- - network.outpoing.packets
+ - vpg_vpg_private_0_port
+ - network.outpoing.packets
instance_vpg:
- - vpg
- - instance
+ - vpg
+ - instance
disk.device.capacity_vpg:
- - vpg
- - disk.device.capacity
+ - vpg
+ - disk.device.capacity
disk.device.read.requests_vpg:
- - vpg
- - disk.device.read.requests
+ - vpg
+ - disk.device.read.requests
cpu_util_vpg:
- - vpg
- - cpu_util
+ - vpg
+ - cpu_util
memory.usage_vpg:
- - vpg
- - memory.usage
+ - vpg
+ - memory.usage
disk.device.read.requests.rate_vpg:
- - vpg
- - disk.device.read.requests.rate
+ - vpg
+ - disk.device.read.requests.rate
disk.read.requests_vpg:
- - vpg
- - disk.read.requests
+ - vpg
+ - disk.read.requests
cpu.delta_vpg:
- - vpg
- - cpu.delta
+ - vpg
+ - cpu.delta
network.incoming.packets.rate_vpg_vpg_private_0_port:
- - vpg_vpg_private_0_port
- - network.incoming.packets.rate
+ - vpg_vpg_private_0_port
+ - network.incoming.packets.rate
network.incoming.bytes.rate_vpg_vpg_private_0_port:
- - vpg_vpg_private_0_port
- - network.incoming.bytes.rate
+ - vpg_vpg_private_0_port
+ - network.incoming.bytes.rate
disk.write.bytes_vpg:
- - vpg
- - disk.write.bytes
+ - vpg
+ - disk.write.bytes
network.outgoing.packets.rate_vpg_vpg_private_0_port:
- - vpg_vpg_private_0_port
- - network.outgoing.packets.rate
+ - vpg_vpg_private_0_port
+ - network.outgoing.packets.rate
scalable_vpg:
- - vpg
- - scalable
+ - vpg
+ - scalable
vcpus_vpg:
- - vpg
- - vcpus
+ - vpg
+ - vcpus
port_mirroring_vpg_vpg_private_1_port:
- - vpg_vpg_private_1_port
- - port_mirroring
+ - vpg_vpg_private_1_port
+ - port_mirroring
disk.root.size_vpg:
- - vpg
- - disk.root.size
+ - vpg
+ - disk.root.size
disk.device.write.requests_vpg:
- - vpg
- - disk.device.write.requests
+ - vpg
+ - disk.device.write.requests
network.outgoing.bytes_vpg_vpg_private_0_port:
- - vpg_vpg_private_0_port
- - network.outgoing.bytes
+ - vpg_vpg_private_0_port
+ - network.outgoing.bytes
memory_vpg:
- - vpg
- - memory
+ - vpg
+ - memory
network.outpoing.packets_vpg_vpg_private_1_port:
- - vpg_vpg_private_1_port
- - network.outpoing.packets
+ - vpg_vpg_private_1_port
+ - network.outpoing.packets
os_vpg:
- - vpg
- - os
+ - vpg
+ - os
binding_vpg_vpg_private_0_port:
- - vpg_vpg_private_0_port
- - binding
+ - vpg_vpg_private_0_port
+ - binding
disk.read.bytes.rate_vpg:
- - vpg
- - disk.read.bytes.rate
+ - vpg
+ - disk.read.bytes.rate
memory.resident_vpg:
- - vpg
- - memory.resident
+ - vpg
+ - memory.resident
disk.latency_vpg:
- - vpg
- - disk.latency
+ - vpg
+ - disk.latency
network.incoming.packets_vpg_vpg_private_0_port:
- - vpg_vpg_private_0_port
- - network.incoming.packets
+ - vpg_vpg_private_0_port
+ - network.incoming.packets
requirements:
link_vpg_vpg_private_0_port:
- - vpg_vpg_private_0_port
- - link
+ - vpg_vpg_private_0_port
+ - link
dependency_vpg:
- - vpg
- - dependency
+ - vpg
+ - dependency
dependency_vpg_vpg_private_0_port:
- - vpg_vpg_private_0_port
- - dependency
+ - vpg_vpg_private_0_port
+ - dependency
local_storage_vpg:
- - vpg
- - local_storage
+ - vpg
+ - local_storage
dependency_vpg_vpg_private_1_port:
- - vpg_vpg_private_1_port
- - dependency
+ - vpg_vpg_private_1_port
+ - dependency
link_vpg_vpg_private_1_port:
- - vpg_vpg_private_1_port
- - link
+ - vpg_vpg_private_1_port
+ - link
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/OutputDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/OutputDefinition.java
index 3d2125471d..ae0c2c0632 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/OutputDefinition.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/OutputDefinition.java
@@ -18,7 +18,6 @@
*/
package org.openecomp.sdc.be.model;
-import java.util.List;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@@ -29,17 +28,18 @@ import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
@NoArgsConstructor
public class OutputDefinition extends AttributeDefinition {
- private List<ComponentInstanceAttribute> attributes;
+ private ComponentInstanceAttribute attribute;
public OutputDefinition(final AttributeDataDefinition attributeDataDefinition) {
super(attributeDataDefinition);
}
- public OutputDefinition(AttributeDefinition propertyDefinition) {
- super(propertyDefinition);
+ public OutputDefinition(AttributeDefinition attributeDefinition) {
+ super(attributeDefinition);
}
public OutputDefinition(final OutputDefinition outputDefinition) {
super(outputDefinition);
+ this.attribute = outputDefinition.getAttribute();
}
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java
index 9ea74ea565..6af88e1215 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java
@@ -32,6 +32,7 @@ import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterProp
public class ParsedToscaYamlInfo {
Map<String, InputDefinition> inputs;
+ Map<String, OutputDefinition> outputs;
Map<String, UploadComponentInstanceInfo> instances;
Map<String, GroupDefinition> groups;
Map<String, PolicyDefinition> policies;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java
index 7742cbfe0e..dcd801168a 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java
@@ -583,6 +583,21 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
return StorageOperationStatus.OK;
}
+ public StorageOperationStatus associateOutputsToComponent(final GraphVertex nodeTypeVertex,
+ final Map<String, ? extends AttributeDataDefinition> outputs,
+ final String id) {
+ if (MapUtils.isNotEmpty(outputs)) {
+ outputs.values().stream().filter(e -> e.getUniqueId() == null)
+ .forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
+ final Either<GraphVertex, StorageOperationStatus> associateElementToData
+ = associateElementToData(nodeTypeVertex, VertexTypeEnum.OUTPUTS, EdgeLabelEnum.OUTPUTS, outputs);
+ if (associateElementToData.isRight()) {
+ return associateElementToData.right().value();
+ }
+ }
+ return StorageOperationStatus.OK;
+ }
+
private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
fillCommonMetadata(nodeTypeVertex, topologyTemplate);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
index cf1b23ec88..7c34da89f0 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
@@ -148,6 +148,8 @@ public class ToscaOperationFacade {
private static final String VF = "VF";
private static final String NOT_SUPPORTED_COMPONENT_TYPE = "Not supported component type {}";
private static final String COMPONENT_CREATED_SUCCESSFULLY = "Component created successfully!!!";
+ private static final String INPUTS_ASSOCIATED_TO_COMPONENT_SUCCESSFULLY = "Inputs associated to component successfully!";
+ private static final String OUTPUTS_ASSOCIATED_TO_COMPONENT_SUCCESSFULLY = "Outputs associated to component successfully!";
private static final String COULDNT_FETCH_COMPONENT_WITH_AND_UNIQUE_ID_ERROR = "Couldn't fetch component with and unique id {}, error: {}";
private static final Logger log = Logger.getLogger(ToscaOperationFacade.class.getName());
@Autowired
@@ -1362,7 +1364,7 @@ public class ToscaOperationFacade {
.collect(Collectors.toMap(Map.Entry::getKey, e -> new PropertyDataDefinition(e.getValue())));
StorageOperationStatus status = topologyTemplateOperation.associateInputsToComponent(vertex, inputsMap, componentId);
if (StorageOperationStatus.OK == status) {
- log.debug(COMPONENT_CREATED_SUCCESSFULLY);
+ log.debug(INPUTS_ASSOCIATED_TO_COMPONENT_SUCCESSFULLY);
List<InputDefinition> inputsResList = null;
if (inputsMap != null && !inputsMap.isEmpty()) {
inputsResList = inputsMap.values().stream().map(InputDefinition::new).collect(Collectors.toList());
@@ -1372,6 +1374,28 @@ public class ToscaOperationFacade {
return Either.right(status);
}
+ public Either<List<OutputDefinition>, StorageOperationStatus> createAndAssociateOutputs(final Map<String, OutputDefinition> outputs,
+ final String componentId) {
+ final Either<GraphVertex, JanusGraphOperationStatus> getVertexEither = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ log.debug(COULDNT_FETCH_COMPONENT_WITH_AND_UNIQUE_ID_ERROR, componentId, getVertexEither.right().value());
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getVertexEither.right().value()));
+ }
+ final GraphVertex vertex = getVertexEither.left().value();
+ final Map<String, OutputDefinition> outputsMap = outputs.entrySet().stream()
+ .collect(Collectors.toMap(Map.Entry::getKey, e -> new OutputDefinition(e.getValue())));
+ final StorageOperationStatus status = topologyTemplateOperation.associateOutputsToComponent(vertex, outputsMap, componentId);
+ if (StorageOperationStatus.OK == status) {
+ log.debug(OUTPUTS_ASSOCIATED_TO_COMPONENT_SUCCESSFULLY);
+ List<OutputDefinition> outputsResList = null;
+ if (MapUtils.isNotEmpty(outputsMap)) {
+ outputsResList = outputsMap.values().stream().map(OutputDefinition::new).collect(Collectors.toList());
+ }
+ return Either.left(outputsResList);
+ }
+ return Either.right(status);
+ }
+
public Either<List<InputDefinition>, StorageOperationStatus> addInputsToComponent(Map<String, InputDefinition> inputs, String componentId) {
Either<GraphVertex, JanusGraphOperationStatus> getVertexEither = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
if (getVertexEither.isRight()) {
@@ -1526,7 +1550,7 @@ public class ToscaOperationFacade {
GraphVertex vertex = getVertexEither.left().value();
List<AttributeDataDefinition> outputsAsDataDef = outputs.stream().map(AttributeDataDefinition::new).collect(Collectors.toList());
StorageOperationStatus status = topologyTemplateOperation
- .updateToscaDataOfToscaElement(vertex, EdgeLabelEnum.OUTPUTS, VertexTypeEnum.OUTPUTS, outputsAsDataDef, JsonPresentationFields.NAME);
+ .updateToscaDataOfToscaElement(vertex, EdgeLabelEnum.OUTPUTS, VertexTypeEnum.OUTPUTS, outputsAsDataDef, JsonPresentationFields.NAME);
if (StorageOperationStatus.OK == status) {
log.debug(COMPONENT_CREATED_SUCCESSFULLY);
List<OutputDefinition> outputsResList = null;
@@ -1671,33 +1695,33 @@ public class ToscaOperationFacade {
}
public Either<Map<String, List<ComponentInstanceOutput>>, StorageOperationStatus> addComponentInstanceOutputsToComponent(
- Component containerComponent, Map<String, List<ComponentInstanceOutput>> instProperties) {
- requireNonNull(instProperties);
+ Component containerComponent, Map<String, List<ComponentInstanceOutput>> instOutputs) {
+ requireNonNull(instOutputs);
StorageOperationStatus status;
- for (final Entry<String, List<ComponentInstanceOutput>> entry : instProperties.entrySet()) {
- final List<ComponentInstanceOutput> props = entry.getValue();
+ for (final Entry<String, List<ComponentInstanceOutput>> entry : instOutputs.entrySet()) {
+ final List<ComponentInstanceOutput> outputs = entry.getValue();
final String componentInstanceId = entry.getKey();
- if (!isEmpty(props)) {
- for (final ComponentInstanceOutput property : props) {
- final List<ComponentInstanceOutput> componentInstancesInputs = containerComponent.getComponentInstancesOutputs()
+ if (!isEmpty(outputs)) {
+ for (final ComponentInstanceOutput output : outputs) {
+ final List<ComponentInstanceOutput> componentInstanceOutputs = containerComponent.getComponentInstancesOutputs()
.get(componentInstanceId);
- final Optional<ComponentInstanceOutput> instanceProperty = componentInstancesInputs.stream()
- .filter(p -> p.getName().equals(property.getName())).findAny();
- if (instanceProperty.isPresent()) {
- status = updateComponentInstanceOutput(containerComponent, componentInstanceId, property);
+ final Optional<ComponentInstanceOutput> componentInstanceOutput = componentInstanceOutputs.stream()
+ .filter(p -> p.getName().equals(output.getName())).findAny();
+ if (componentInstanceOutput.isPresent()) {
+ status = updateComponentInstanceOutput(containerComponent, componentInstanceId, output);
} else {
- status = addComponentInstanceOutput(containerComponent, componentInstanceId, property);
+ status = addComponentInstanceOutput(containerComponent, componentInstanceId, output);
}
if (status != StorageOperationStatus.OK) {
- log.debug("Failed to update instance input {} for instance {} error {} ", property, componentInstanceId, status);
+ log.debug("Failed to update instance output {} for instance {} error {} ", output, componentInstanceId, status);
return Either.right(status);
} else {
- log.trace("instance input {} for instance {} updated", property, componentInstanceId);
+ log.trace("instance output {} for instance {} updated", output, componentInstanceId);
}
}
}
}
- return Either.left(instProperties);
+ return Either.left(instOutputs);
}
public Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> addComponentInstancePropertiesToComponent(
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperationTest.java
index 82560b0576..f14089e902 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperationTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -20,49 +20,54 @@
package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
-import org.janusgraph.core.JanusGraphVertex;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.janusgraph.core.JanusGraphVertex;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.DistributionStatusEnum;
+import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
-import org.openecomp.sdc.be.model.ComponentParametersView;
-import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
-
-import java.util.*;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-@RunWith(MockitoJUnitRunner.class)
-//error scenarios
-public class TopologyTemplateOperationTest {
+@ExtendWith(MockitoExtension.class)
+class TopologyTemplateOperationTest {
private static final String CONTAINER_ID = "containerId";
@InjectMocks
@@ -71,57 +76,63 @@ public class TopologyTemplateOperationTest {
private JanusGraphDao janusGraphDao;
@Test
- public void overrideToscaDataOfToscaElement_failedToFetchContainerVertex() {
+ void overrideToscaDataOfToscaElement_failedToFetchContainerVertex() {
when(janusGraphDao.getVertexById(CONTAINER_ID, JsonParseFlagEnum.NoParse)).thenReturn(Either.right(
JanusGraphOperationStatus.INVALID_ID));
- StorageOperationStatus storageOperationStatus = topologyTemplateOperation.overrideToscaDataOfToscaElement(CONTAINER_ID, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, Collections.emptyMap());
+ StorageOperationStatus storageOperationStatus = topologyTemplateOperation.overrideToscaDataOfToscaElement(CONTAINER_ID,
+ EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, Collections.emptyMap());
assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.INVALID_ID);
}
@Test
- public void overrideToscaDataOfToscaElement_failedToFetchDataVertex() {
+ void overrideToscaDataOfToscaElement_failedToFetchDataVertex() {
GraphVertex containerVertex = new GraphVertex();
when(janusGraphDao.getVertexById(CONTAINER_ID, JsonParseFlagEnum.NoParse)).thenReturn(Either.left(containerVertex));
- when(janusGraphDao.getChildVertex(containerVertex, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, JsonParseFlagEnum.ParseJson)).thenReturn(Either.right(
- JanusGraphOperationStatus.NOT_FOUND));
- StorageOperationStatus storageOperationStatus = topologyTemplateOperation.overrideToscaDataOfToscaElement(CONTAINER_ID, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, Collections.emptyMap());
+ when(janusGraphDao.getChildVertex(containerVertex, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, JsonParseFlagEnum.ParseJson)).thenReturn(
+ Either.right(
+ JanusGraphOperationStatus.NOT_FOUND));
+ StorageOperationStatus storageOperationStatus = topologyTemplateOperation.overrideToscaDataOfToscaElement(CONTAINER_ID,
+ EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, Collections.emptyMap());
assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.NOT_FOUND);
}
@Test
- public void updateToscaDataDeepElements_failedToFetchContainerVertex() {
+ void updateToscaDataDeepElements_failedToFetchContainerVertex() {
when(janusGraphDao.getVertexById(CONTAINER_ID, JsonParseFlagEnum.NoParse)).thenReturn(Either.right(
JanusGraphOperationStatus.INVALID_ID));
- StorageOperationStatus storageOperationStatus = topologyTemplateOperation.updateToscaDataDeepElementsBlockToToscaElement(CONTAINER_ID, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, new MapCapabilityProperty(), "");
+ StorageOperationStatus storageOperationStatus = topologyTemplateOperation.updateToscaDataDeepElementsBlockToToscaElement(CONTAINER_ID,
+ EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, new MapCapabilityProperty(), "");
assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.INVALID_ID);
}
@Test
- public void updateToscaDataDeepElements_failedToFetchDataVertex() {
+ void updateToscaDataDeepElements_failedToFetchDataVertex() {
GraphVertex containerVertex = new GraphVertex();
when(janusGraphDao.getVertexById(CONTAINER_ID, JsonParseFlagEnum.NoParse)).thenReturn(Either.left(containerVertex));
- when(janusGraphDao.getChildVertex(containerVertex, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, JsonParseFlagEnum.ParseJson)).thenReturn(Either.right(
- JanusGraphOperationStatus.NOT_FOUND));
- StorageOperationStatus storageOperationStatus = topologyTemplateOperation.updateToscaDataDeepElementsBlockToToscaElement(CONTAINER_ID, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, new MapCapabilityProperty(), "");
+ when(janusGraphDao.getChildVertex(containerVertex, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, JsonParseFlagEnum.ParseJson)).thenReturn(
+ Either.right(
+ JanusGraphOperationStatus.NOT_FOUND));
+ StorageOperationStatus storageOperationStatus = topologyTemplateOperation.updateToscaDataDeepElementsBlockToToscaElement(CONTAINER_ID,
+ EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, new MapCapabilityProperty(), "");
assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.NOT_FOUND);
}
@Test
- public void addPolicyToToscaElementSuccessTest(){
+ void addPolicyToToscaElementSuccessTest() {
JanusGraphOperationStatus status = JanusGraphOperationStatus.OK;
StorageOperationStatus result = addPolicyToToscaElementWithStatus(status);
assertThat(result).isEqualTo(StorageOperationStatus.OK);
}
@Test
- public void addPolicyToToscaElementFailureTest(){
+ void addPolicyToToscaElementFailureTest() {
JanusGraphOperationStatus status = JanusGraphOperationStatus.ALREADY_EXIST;
StorageOperationStatus result = addPolicyToToscaElementWithStatus(status);
assertThat(result).isEqualTo(StorageOperationStatus.ENTITY_ALREADY_EXISTS);
}
@Test
- public void testAssociateOrAddCalcCapReqToComponent() {
+ void testAssociateOrAddCalcCapReqToComponent() {
StorageOperationStatus result;
GraphVertex graphVertex = new GraphVertex();
Map<String, MapListRequirementDataDefinition> calcRequirements = new HashMap<>();
@@ -133,7 +144,7 @@ public class TopologyTemplateOperationTest {
}
@Test
- public void testSetDataTypesFromGraph() {
+ void testSetDataTypesFromGraph() {
GraphVertex containerVertex = new GraphVertex();
ComponentParametersView filter = new ComponentParametersView(true);
filter.setIgnoreComponentInstancesInterfaces(true);
@@ -151,7 +162,7 @@ public class TopologyTemplateOperationTest {
}
@Test
- public void testSetOutputsFromGraph() {
+ void testSetOutputsFromGraph() {
final GraphVertex containerVertex = new GraphVertex();
final ComponentParametersView filter = new ComponentParametersView(true);
filter.setIgnoreOutputs(false);
@@ -170,7 +181,7 @@ public class TopologyTemplateOperationTest {
}
@Test
- public void testUpdateDistributionStatus() {
+ void testUpdateDistributionStatus() {
Either<GraphVertex, StorageOperationStatus> result;
String uniqueId = "uniqueId";
User user = new User();
@@ -192,7 +203,8 @@ public class TopologyTemplateOperationTest {
when(graphVertex.getVertex()).thenReturn(janusGraphVertex);
when(janusGraphVertex.edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name())).thenReturn(edgeIterator);
when(janusGraphDao
- .getVertexByPropertyAndLabel(GraphPropertyEnum.USERID, userId, VertexTypeEnum.USER, JsonParseFlagEnum.NoParse)).thenReturn(Either.left(graphVertex));
+ .getVertexByPropertyAndLabel(GraphPropertyEnum.USERID, userId, VertexTypeEnum.USER, JsonParseFlagEnum.NoParse)).thenReturn(
+ Either.left(graphVertex));
when(janusGraphDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.left(graphVertex));
when(janusGraphDao.createEdge(graphVertex, graphVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null)).thenReturn(
JanusGraphOperationStatus.OK);
@@ -201,6 +213,44 @@ public class TopologyTemplateOperationTest {
assertThat(result.isLeft()).isTrue();
}
+ @Test
+ void testAssociateOutputsToComponent_OK() {
+ GraphVertex containerVertex = new GraphVertex();
+ String componentName = "componentName";
+ String componentId = UniqueIdBuilder.buildResourceUniqueId();
+ containerVertex.setVertex(Mockito.mock(JanusGraphVertex.class));
+ containerVertex.setJsonMetadataField(JsonPresentationFields.NAME, componentName);
+ containerVertex.setUniqueId(componentId);
+ containerVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
+ final Map<String, AttributeDataDefinition> outputs = new HashMap<>();
+ outputs.put("out-1", new OutputDefinition());
+
+ when(janusGraphDao.createVertex(any(GraphVertex.class))).thenReturn(Either.left(containerVertex));
+ when(janusGraphDao.createEdge(any(Vertex.class), any(Vertex.class), eq(EdgeLabelEnum.OUTPUTS), anyMap()))
+ .thenReturn(JanusGraphOperationStatus.OK);
+
+ final StorageOperationStatus result = topologyTemplateOperation.associateOutputsToComponent(containerVertex, outputs, CONTAINER_ID);
+ assertEquals(StorageOperationStatus.OK, result);
+ }
+
+ @Test
+ void testAssociateOutputsToComponent_Fail_createVertex() {
+ GraphVertex containerVertex = new GraphVertex();
+ String componentName = "componentName";
+ String componentId = UniqueIdBuilder.buildResourceUniqueId();
+ containerVertex.setVertex(Mockito.mock(JanusGraphVertex.class));
+ containerVertex.setJsonMetadataField(JsonPresentationFields.NAME, componentName);
+ containerVertex.setUniqueId(componentId);
+ containerVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
+ final Map<String, AttributeDataDefinition> outputs = new HashMap<>();
+ outputs.put("out-1", new OutputDefinition());
+
+ when(janusGraphDao.createVertex(any(GraphVertex.class))).thenReturn(Either.right(JanusGraphOperationStatus.NOT_CREATED));
+
+ final StorageOperationStatus result = topologyTemplateOperation.associateOutputsToComponent(containerVertex, outputs, CONTAINER_ID);
+ assertEquals(StorageOperationStatus.SCHEMA_ERROR, result);
+ }
+
@SuppressWarnings("unchecked")
private StorageOperationStatus addPolicyToToscaElementWithStatus(JanusGraphOperationStatus status) {
GraphVertex componentV = new GraphVertex();
@@ -220,7 +270,8 @@ public class TopologyTemplateOperationTest {
when(janusGraphDao.getChildVertex(componentV, EdgeLabelEnum.POLICIES, JsonParseFlagEnum.ParseJson)).thenReturn(toscaDataVertexRes);
Either<GraphVertex, JanusGraphOperationStatus> createVertex = Either.left(dataV);
when(janusGraphDao.createVertex(any(GraphVertex.class))).thenReturn(createVertex);
- when(janusGraphDao.createEdge(any(JanusGraphVertex.class), any(JanusGraphVertex.class), any(EdgeLabelEnum.class), any(HashMap.class))).thenReturn(status);
+ when(janusGraphDao.createEdge(any(JanusGraphVertex.class), any(JanusGraphVertex.class), any(EdgeLabelEnum.class),
+ any(HashMap.class))).thenReturn(status);
return topologyTemplateOperation.addPolicyToToscaElement(componentV, policy, counter);
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java
index d7b6c60539..8aa4353266 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java
@@ -1,42 +1,28 @@
/*
-
* Copyright (c) 2018 AT&T Intellectual Property.
-
*
-
* 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.
-
*/
package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
import static org.assertj.core.api.Assertions.assertThat;
-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.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyMap;
@@ -61,22 +47,22 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.config.ComponentType;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.api.exception.JanusGraphException;
+import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
-import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
@@ -100,6 +86,7 @@ import org.openecomp.sdc.be.model.ComponentInstanceOutput;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.OutputDefinition;
import org.openecomp.sdc.be.model.PolicyDefinition;
@@ -117,8 +104,8 @@ import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-@RunWith(MockitoJUnitRunner.class)
-public class ToscaOperationFacadeTest {
+@ExtendWith(MockitoExtension.class)
+class ToscaOperationFacadeTest {
private static final String COMPONENT_ID = "componentId";
private static final String PROPERTY1_NAME = "prop1";
@@ -148,15 +135,15 @@ public class ToscaOperationFacadeTest {
@Mock
private IGraphLockOperation graphLockOperationMock;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
testInstance = new ToscaOperationFacade();
MockitoAnnotations.openMocks(this);
}
@SuppressWarnings("unchecked")
@Test
- public void fetchMetaDataByResourceType() throws Exception {
+ void fetchMetaDataByResourceType() throws Exception {
ArgumentCaptor<Map> criteriaCapture = ArgumentCaptor.forClass(Map.class);
ArgumentCaptor<Map> criteriaNotCapture = ArgumentCaptor.forClass(Map.class);
ComponentParametersView dataFilter = new ComponentParametersView();
@@ -195,7 +182,7 @@ public class ToscaOperationFacadeTest {
@SuppressWarnings("unchecked")
@Test
- public void fetchMetaDataByResourceType_failedToGetData() throws Exception {
+ void fetchMetaDataByResourceType_failedToGetData() throws Exception {
when(janusGraphDaoMock.getByCriteria(eq(null), anyMap(), anyMap(), eq(JsonParseFlagEnum.ParseMetadata))).thenReturn(Either.right(
JanusGraphOperationStatus.GENERAL_ERROR));
Either<List<Component>, StorageOperationStatus> fetchedComponents = testInstance
@@ -205,41 +192,41 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void associatePolicyToComponentSuccessTest() {
+ void associatePolicyToComponentSuccessTest() {
Either<PolicyDefinition, StorageOperationStatus> result = associatePolicyToComponentWithStatus(StorageOperationStatus.OK);
assertTrue(result.isLeft());
}
@Test
- public void associatePolicyToComponentFailureTest() {
+ void associatePolicyToComponentFailureTest() {
Either<PolicyDefinition, StorageOperationStatus> result = associatePolicyToComponentWithStatus(StorageOperationStatus.BAD_REQUEST);
assertTrue(result.isRight() && result.right().value() == StorageOperationStatus.BAD_REQUEST);
}
@Test
- public void updatePolicyOfComponentSuccessTest() {
+ void updatePolicyOfComponentSuccessTest() {
Either<PolicyDefinition, StorageOperationStatus> result = updatePolicyOfComponentWithStatus(StorageOperationStatus.OK);
assertTrue(result.isLeft());
}
@Test
- public void updatePolicyOfComponentFailureTest() {
+ void updatePolicyOfComponentFailureTest() {
Either<PolicyDefinition, StorageOperationStatus> result = updatePolicyOfComponentWithStatus(StorageOperationStatus.NOT_FOUND);
assertTrue(result.isRight() && result.right().value() == StorageOperationStatus.NOT_FOUND);
}
@Test
- public void removePolicyFromComponentSuccessTest() {
+ void removePolicyFromComponentSuccessTest() {
removePolicyFromComponentWithStatus(StorageOperationStatus.OK);
}
@Test
- public void removePolicyFromComponentFailureTest() {
+ void removePolicyFromComponentFailureTest() {
removePolicyFromComponentWithStatus(StorageOperationStatus.NOT_FOUND);
}
@Test
- public void testFindLastCertifiedToscaElementByUUID() {
+ void testFindLastCertifiedToscaElementByUUID() {
Either<Component, StorageOperationStatus> result;
Component component = new Resource();
List<GraphVertex> list = new ArrayList<>();
@@ -259,7 +246,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testLatestComponentByToscaResourceName() {
+ void testLatestComponentByToscaResourceName() {
Either<Component, StorageOperationStatus> result;
TopologyTemplate toscaElement = new TopologyTemplate();
toscaElement.setComponentType(ComponentTypeEnum.SERVICE);
@@ -286,7 +273,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testValidateCsarUuidUniqueness() {
+ void testValidateCsarUuidUniqueness() {
StorageOperationStatus result;
String csarUUID = "csarUUID";
Map<GraphPropertyEnum, Object> properties = new EnumMap<>(GraphPropertyEnum.class);
@@ -298,7 +285,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testValidateCsarUuidUnique_true() {
+ void testValidateCsarUuidUnique_true() {
StorageOperationStatus result;
String csarUUID = "csarUUID";
Map<GraphPropertyEnum, Object> properties = new EnumMap<>(GraphPropertyEnum.class);
@@ -310,7 +297,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testGetLatestCertiNodeTypeByToscaResourceName() {
+ void testGetLatestCertiNodeTypeByToscaResourceName() {
Either<Resource, StorageOperationStatus> result;
String toscaResourceName = "resourceName";
String uniqueId = "uniqueId";
@@ -334,7 +321,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testValidateCompExists() {
+ void testValidateCompExists() {
Either<Boolean, StorageOperationStatus> result;
String componentId = "componentId";
GraphVertex graphVertex = getTopologyTemplateVertex();
@@ -344,7 +331,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testValidateCompExists_NotFound() {
+ void testValidateCompExists_NotFound() {
Either<Boolean, StorageOperationStatus> result;
String componentId = "componentId";
when(janusGraphDaoMock.getVertexById(componentId, JsonParseFlagEnum.NoParse)).thenReturn(Either.right(
@@ -354,7 +341,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testValidateToscaResourceNameExists() {
+ void testValidateToscaResourceNameExists() {
Either<Boolean, StorageOperationStatus> result;
String templateName = "templateName";
Map<GraphPropertyEnum, Object> properties = new EnumMap<>(GraphPropertyEnum.class);
@@ -368,7 +355,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testValidateToscaResourceNameExists_false() {
+ void testValidateToscaResourceNameExists_false() {
Either<Boolean, StorageOperationStatus> result;
String templateName = "templateName";
Map<GraphPropertyEnum, Object> properties = new EnumMap<>(GraphPropertyEnum.class);
@@ -383,7 +370,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testOverrideComponent() {
+ void testOverrideComponent() {
Either<Resource, StorageOperationStatus> result;
Resource resource = new Resource();
String id = "id";
@@ -406,7 +393,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testGetToscaElement() {
+ void testGetToscaElement() {
Either<Component, StorageOperationStatus> result;
String id = "id";
GraphVertex graphVertex = getTopologyTemplateVertex();
@@ -419,7 +406,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testDeleteService_ServiceInUse() {
+ void testDeleteService_ServiceInUse() {
String invariantUUID = "12345";
String serviceUid = "1";
GraphVertex service1 = getTopologyTemplateVertex();
@@ -442,16 +429,16 @@ public class ToscaOperationFacadeTest {
inUseBy.add(usingService);
when(janusGraphDaoMock.findAllVertexByInvariantUuid(invariantUUID, Collections.emptyMap())).
- thenReturn(allResourcesToDelete);
+ thenReturn(allResourcesToDelete);
when(janusGraphDaoMock.getParentVertices(any(GraphVertex.class), any(), eq(JsonParseFlagEnum.ParseAll))).
- thenReturn(Either.left(inUseBy)).thenReturn(Either.left(inUseBy));
+ thenReturn(Either.left(inUseBy)).thenReturn(Either.left(inUseBy));
final OperationException actualException = assertThrows(OperationException.class, () -> testInstance.deleteService(invariantUUID, true));
- assertEquals(actualException.getActionStatus(), ActionStatus.COMPONENT_IN_USE_BY_ANOTHER_COMPONENT);
- assertEquals(actualException.getParams()[0], ComponentType.SERVICE + " " + service2Name);
+ assertEquals(ActionStatus.COMPONENT_IN_USE_BY_ANOTHER_COMPONENT, actualException.getActionStatus());
+ assertEquals(actualException.getParams()[0], ComponentType.SERVICE + " " + service2Name);
}
@Test
- public void testDeleteService_WithOneVersion() {
+ void testDeleteService_WithOneVersion() {
String invariantUUID = "12345";
String serviceUid = "1";
Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
@@ -466,17 +453,17 @@ public class ToscaOperationFacadeTest {
affectedComponentIds.add(service1.getUniqueId());
when(janusGraphDaoMock.findAllVertexByInvariantUuid(invariantUUID, Collections.emptyMap())).
- thenReturn(allResourcesToDelete);
+ thenReturn(allResourcesToDelete);
when(janusGraphDaoMock.getParentVertices(eq(service1), any(), eq(JsonParseFlagEnum.ParseAll))).
- thenReturn(Either.right(JanusGraphOperationStatus.OK));
+ thenReturn(Either.right(JanusGraphOperationStatus.OK));
when(graphLockOperationMock.lockComponent(service1.getUniqueId(), NodeTypeEnum.Service)).
- thenReturn(StorageOperationStatus.OK);
+ thenReturn(StorageOperationStatus.OK);
when(topologyTemplateOperationMock.deleteToscaElement(service1)).thenReturn(Either.left(toscaElement));
assertEquals(affectedComponentIds, testInstance.deleteService(invariantUUID, true));
}
@Test
- public void testDeleteService_WithTwoVersions() {
+ void testDeleteService_WithTwoVersions() {
String invariantUUID = "12345";
String serviceUid = "1";
String service2Uid = "2";
@@ -498,20 +485,20 @@ public class ToscaOperationFacadeTest {
propertiesToMatch.put(GraphPropertyEnum.INVARIANT_UUID, invariantUUID);
when(janusGraphDaoMock.findAllVertexByInvariantUuid(invariantUUID, Collections.emptyMap())).
- thenReturn(allResourcesToDelete);
+ thenReturn(allResourcesToDelete);
when(janusGraphDaoMock.getParentVertices(any(GraphVertex.class), any(), eq(JsonParseFlagEnum.ParseAll))).
- thenReturn(Either.right(JanusGraphOperationStatus.OK));
+ thenReturn(Either.right(JanusGraphOperationStatus.OK));
when(graphLockOperationMock.lockComponent(service.getUniqueId(), NodeTypeEnum.Service)).
thenReturn(StorageOperationStatus.OK);
when(graphLockOperationMock.lockComponent(serviceV2.getUniqueId(), NodeTypeEnum.Service)).
- thenReturn(StorageOperationStatus.OK);
+ thenReturn(StorageOperationStatus.OK);
when(topologyTemplateOperationMock.deleteToscaElement(service)).thenReturn(Either.left(toscaElement));
when(topologyTemplateOperationMock.deleteToscaElement(serviceV2)).thenReturn(Either.left(toscaElement));
assertEquals(affectedComponentIds, testInstance.deleteService(invariantUUID, true));
}
@Test
- public void testDeleteService_FailDelete() {
+ void testDeleteService_FailDelete() {
String invariantUUID = "12345";
String serviceUid = "1";
GraphVertex service = getTopologyTemplateVertex();
@@ -522,32 +509,32 @@ public class ToscaOperationFacadeTest {
allResourcesToDelete.add(service);
when(janusGraphDaoMock.findAllVertexByInvariantUuid(invariantUUID, Collections.emptyMap())).
- thenReturn(allResourcesToDelete);
+ thenReturn(allResourcesToDelete);
when(janusGraphDaoMock.getParentVertices(eq(service), any(), eq(JsonParseFlagEnum.ParseAll))).
- thenReturn(Either.right(JanusGraphOperationStatus.OK));
+ thenReturn(Either.right(JanusGraphOperationStatus.OK));
when(graphLockOperationMock.lockComponent(service.getUniqueId(), NodeTypeEnum.Service)).
- thenReturn(StorageOperationStatus.OK);
+ thenReturn(StorageOperationStatus.OK);
when(topologyTemplateOperationMock.deleteToscaElement(service))
- .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
StorageException actualException = assertThrows(StorageException.class, () -> testInstance.deleteService(invariantUUID, false));
assertEquals(StorageOperationStatus.NOT_FOUND, actualException.getStorageOperationStatus());
assertEquals(0, actualException.getParams().length);
}
@Test
- public void testDeleteService_NotFound() {
+ void testDeleteService_NotFound() {
String invariantUUID = "12345";
when(janusGraphDaoMock.findAllVertexByInvariantUuid(invariantUUID, Collections.emptyMap())).
- thenReturn(Collections.emptyList());
+ thenReturn(Collections.emptyList());
assertEquals(0, testInstance.deleteService(invariantUUID, true).size());
}
@Test
- public void testDeleteService_GeneralErrorInJanusGraphDao() {
+ void testDeleteService_GeneralErrorInJanusGraphDao() {
String invariantUUID = "12345";
JanusGraphException janusException = new JanusGraphException(JanusGraphOperationStatus.GENERAL_ERROR, "General error");
when(janusGraphDaoMock.findAllVertexByInvariantUuid(invariantUUID, Collections.emptyMap())).
- thenThrow(janusException);
+ thenThrow(janusException);
StorageException actualException = assertThrows(StorageException.class, () -> testInstance.deleteService(invariantUUID, false));
assertEquals(StorageOperationStatus.GENERAL_ERROR, actualException.getStorageOperationStatus());
@@ -555,7 +542,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testMarkComponentToDelete() {
+ void testMarkComponentToDelete() {
StorageOperationStatus result;
Component component = new Resource();
String id = "id";
@@ -568,7 +555,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testDelToscaComponent() {
+ void testDelToscaComponent() {
Either<Component, StorageOperationStatus> result;
String componentId = "compId";
GraphVertex graphVertex = getTopologyTemplateVertex();
@@ -580,7 +567,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testGetLatestByToscaResourceName() {
+ void testGetLatestByToscaResourceName() {
Either<Component, StorageOperationStatus> result;
String toscaResourceName = "name";
String model = "testModel";
@@ -610,7 +597,7 @@ public class ToscaOperationFacadeTest {
@Test
- public void testGetLatestResourceByToscaResourceName() {
+ void testGetLatestResourceByToscaResourceName() {
Either<Resource, StorageOperationStatus> result;
String toscaResourceName = "org.openecomp.resource.vf";
ToscaElement toscaElement = getToscaElementForTest();
@@ -642,7 +629,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testGetFollowed() {
+ void testGetFollowed() {
Either<Set<Component>, StorageOperationStatus> result;
String userId = "id";
Set<LifecycleStateEnum> lifecycleStates = new HashSet<>();
@@ -662,7 +649,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testGetBySystemName() {
+ void testGetBySystemName() {
Either<List<Component>, StorageOperationStatus> result;
String sysName = "sysName";
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
@@ -688,7 +675,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testGetCompByNameAndVersion() {
+ void testGetCompByNameAndVersion() {
Either<Component, StorageOperationStatus> result;
ComponentTypeEnum componentType = ComponentTypeEnum.RESOURCE;
String name = "name";
@@ -719,13 +706,13 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void addDataTypesToComponentSuccessTest() {
+ void addDataTypesToComponentSuccessTest() {
Either<List<DataTypeDefinition>, StorageOperationStatus> result = addDataTypesToComponentWithStatus(StorageOperationStatus.OK);
assertTrue(result.isLeft());
}
@Test
- public void addDataTypesToComponentFailureTest_BadRequest() {
+ void addDataTypesToComponentFailureTest_BadRequest() {
Either<List<DataTypeDefinition>, StorageOperationStatus> result = addDataTypesToComponentWithStatus(StorageOperationStatus.BAD_REQUEST);
assertTrue(result.isRight() && result.right().value() == StorageOperationStatus.BAD_REQUEST);
}
@@ -786,7 +773,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testDataTypesToComponentFailureTest_NotFound() {
+ void testDataTypesToComponentFailureTest_NotFound() {
Either<List<DataTypeDefinition>, StorageOperationStatus> result;
String componentId = "componentId";
GraphVertex vertex = getNodeTypeVertex();
@@ -798,7 +785,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testDeleteDataTypeOfComponent() {
+ void testDeleteDataTypeOfComponent() {
Component component = new Resource();
String id = "id";
component.setUniqueId(id);
@@ -816,7 +803,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testAddComponentInstancePropertiesToComponent() {
+ void testAddComponentInstancePropertiesToComponent() {
// set up component object
Component component = new Resource();
component.setUniqueId(COMPONENT_ID);
@@ -846,7 +833,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testAddComponentInstanceToTopologyTemplate_ServiceProxy() {
+ void testAddComponentInstanceToTopologyTemplate_ServiceProxy() {
Component containerComponent = new Service();
Component originalComponent = new Service();
ComponentInstance componentInstance = new ComponentInstance();
@@ -888,7 +875,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testAddComponentInstanceToTopologyTemplate_ServiceSubstitution() {
+ void testAddComponentInstanceToTopologyTemplate_ServiceSubstitution() {
Component containerComponent = new Service();
Component originalComponent = new Service();
ComponentInstance componentInstance = new ComponentInstance();
@@ -928,7 +915,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testUpdateComponentInstanceRequirement() {
+ void testUpdateComponentInstanceRequirement() {
String containerComponentId = "containerComponentId";
String componentInstanceUniqueId = "componentInstanceUniqueId";
RequirementDataDefinition requirementDataDefinition = Mockito.mock(RequirementDataDefinition.class);
@@ -944,13 +931,13 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void associateCapabilitiesToServiceFailureTest() {
+ void associateCapabilitiesToServiceFailureTest() {
StorageOperationStatus result = associateCapabilitiesToServiceWithStatus(StorageOperationStatus.BAD_REQUEST);
assertSame(StorageOperationStatus.BAD_REQUEST, result);
}
@Test
- public void associateCapabilitiesToServiceSuccessTest() {
+ void associateCapabilitiesToServiceSuccessTest() {
StorageOperationStatus result = associateCapabilitiesToServiceWithStatus(StorageOperationStatus.OK);
assertSame(StorageOperationStatus.OK, result);
}
@@ -977,23 +964,22 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void associateRequirementsToServiceFailureTest() {
+ void associateRequirementsToServiceFailureTest() {
StorageOperationStatus result = associateRequirementsToServiceWithStatus(StorageOperationStatus.BAD_REQUEST);
assertSame(StorageOperationStatus.BAD_REQUEST, result);
}
@Test
- public void associateRequirementsToServiceSuccessTest() {
+ void associateRequirementsToServiceSuccessTest() {
StorageOperationStatus result = associateRequirementsToServiceWithStatus(StorageOperationStatus.OK);
assertSame(StorageOperationStatus.OK, result);
}
@Test
- public void test_addOutputsToComponent() {
+ void test_addOutputsToComponent() {
final GraphVertex graphVertex = getTopologyTemplateVertex();
- final String componentId = "componentId";
- doReturn(Either.left(graphVertex)).when(janusGraphDaoMock).getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ doReturn(Either.left(graphVertex)).when(janusGraphDaoMock).getVertexById(COMPONENT_ID, JsonParseFlagEnum.NoParse);
doReturn(StorageOperationStatus.OK).when(topologyTemplateOperationMock)
.addToscaDataToToscaElement(
any(GraphVertex.class), eq(EdgeLabelEnum.OUTPUTS), eq(VertexTypeEnum.OUTPUTS), anyMap(), eq(JsonPresentationFields.NAME));
@@ -1001,18 +987,18 @@ public class ToscaOperationFacadeTest {
final Map<String, OutputDefinition> outputs = new HashMap<>();
final OutputDefinition outputDefinition = new OutputDefinition();
outputs.put("mock", outputDefinition);
- final Either<List<OutputDefinition>, StorageOperationStatus> result = testInstance.addOutputsToComponent(outputs, componentId);
+ final Either<List<OutputDefinition>, StorageOperationStatus> result = testInstance.addOutputsToComponent(outputs, COMPONENT_ID);
assertNotNull(result);
assertTrue(result.isLeft());
assertFalse(result.left().value().isEmpty());
assertThat(result.left().value().get(0)).isInstanceOf(OutputDefinition.class);
- verify(janusGraphDaoMock, times(1)).getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ verify(janusGraphDaoMock, times(1)).getVertexById(COMPONENT_ID, JsonParseFlagEnum.NoParse);
verify(topologyTemplateOperationMock, times(1)).addToscaDataToToscaElement(
any(GraphVertex.class), eq(EdgeLabelEnum.OUTPUTS), eq(VertexTypeEnum.OUTPUTS), anyMap(), eq(JsonPresentationFields.NAME));
}
@Test
- public void test_addComponentInstanceOutputsToComponent_updateComponentInstanceOutput() {
+ void test_addComponentInstanceOutputsToComponent_updateComponentInstanceOutput() {
final Component component = new Resource();
component.setUniqueId(COMPONENT_ID);
final Map<String, List<ComponentInstanceOutput>> map = new HashMap<>();
@@ -1040,7 +1026,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void test_addComponentInstanceOutputsToComponent_addComponentInstanceOutput() {
+ void test_addComponentInstanceOutputsToComponent_addComponentInstanceOutput() {
final Component component = new Resource();
component.setUniqueId(COMPONENT_ID);
Map<String, List<ComponentInstanceOutput>> map = new HashMap<>();
@@ -1069,7 +1055,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void test_addComponentInstanceAttributesToComponent() {
+ void test_addComponentInstanceAttributesToComponent() {
final Component component = new Resource();
component.setUniqueId(COMPONENT_ID);
Map<String, List<ComponentInstanceAttribute>> map = new HashMap<>();
@@ -1096,7 +1082,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void test_updateAttributeOfComponent_success() {
+ void test_updateAttributeOfComponent_success() {
final GraphVertex graphVertex = getTopologyTemplateVertex();
final String componentId = "componentId";
final Component component = new Resource();
@@ -1121,7 +1107,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void test_updateAttributeOfComponent_isNotPresent() {
+ void test_updateAttributeOfComponent_isNotPresent() {
final GraphVertex graphVertex = getTopologyTemplateVertex();
final String componentId = "componentId";
final Component component = new Resource();
@@ -1149,7 +1135,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void test_updateComponentInstanceAttributes() {
+ void test_updateComponentInstanceAttributes() {
final GraphVertex graphVertex = getTopologyTemplateVertex();
final String componentId = "componentId";
final Component component = new Resource();
@@ -1169,7 +1155,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void test_updateComponentInstanceOutputs() {
+ void test_updateComponentInstanceOutputs() {
final GraphVertex graphVertex = getTopologyTemplateVertex();
final String componentId = "componentId";
final Component component = new Resource();
@@ -1189,7 +1175,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void test_deleteOutputOfResource() {
+ void test_deleteOutputOfResource() {
final Component component = new Resource();
component.setUniqueId(COMPONENT_ID);
@@ -1204,7 +1190,7 @@ public class ToscaOperationFacadeTest {
}
@Test
- public void testDeleteResource_ResourceInUse() {
+ void testDeleteResource_ResourceInUse() {
GraphVertex graphVertex = getTopologyTemplateVertex();
String invariantUuid = "1";
graphVertex.setUniqueId(invariantUuid);
@@ -1216,7 +1202,7 @@ public class ToscaOperationFacadeTest {
usingComponent.setMetadataJson(metadataJson);
List<GraphVertex> inUseBy = new ArrayList<>();
inUseBy.add(usingComponent);
- Map<String,Object> metadata = new HashMap<>();
+ Map<String, Object> metadata = new HashMap<>();
metadata.put("ex1", new Object());
graphVertex.setMetadataJson(metadata);
ToscaElement toscaElement = getToscaElementForTest();
@@ -1225,19 +1211,20 @@ public class ToscaOperationFacadeTest {
allResourcesToDelete.add(graphVertex);
when(janusGraphDaoMock.findAllVertexByInvariantUuid(invariantUuid, Collections.emptyMap())).
- thenReturn(allResourcesToDelete);
+ thenReturn(allResourcesToDelete);
when(janusGraphDaoMock.getParentVertices(any(GraphVertex.class), any(), eq(JsonParseFlagEnum.ParseAll))).thenReturn(Either.left(inUseBy));
- final OperationException actualException = assertThrows(OperationException.class, () -> testInstance.deleteComponent(invariantUuid, NodeTypeEnum.Resource, true));
- assertEquals(actualException.getActionStatus(), ActionStatus.COMPONENT_IN_USE_BY_ANOTHER_COMPONENT);
+ final OperationException actualException = assertThrows(OperationException.class,
+ () -> testInstance.deleteComponent(invariantUuid, NodeTypeEnum.Resource, true));
+ assertEquals(ActionStatus.COMPONENT_IN_USE_BY_ANOTHER_COMPONENT, actualException.getActionStatus());
}
@Test
- public void testDeleteResource_WithTwoVersions() {
+ void testDeleteResource_WithTwoVersions() {
GraphVertex graphVertex = getTopologyTemplateVertex();
String invariantUuid = "1";
graphVertex.setUniqueId(invariantUuid);
- Map<String,Object> metadata1 = new HashMap<>();
+ Map<String, Object> metadata1 = new HashMap<>();
metadata1.put("ex1", new Object());
graphVertex.setMetadataJson(metadata1);
ToscaElement toscaElement1 = getToscaElementForTest();
@@ -1246,7 +1233,7 @@ public class ToscaOperationFacadeTest {
toscaElement2.setUniqueId("2");
GraphVertex graphVertex2 = getTopologyTemplateVertex();
graphVertex2.setUniqueId("2");
- Map<String,Object> metadata2 = new HashMap<>();
+ Map<String, Object> metadata2 = new HashMap<>();
metadata2.put("ex2", new Object());
graphVertex.setMetadataJson(metadata2);
List<GraphVertex> parentVertices = new ArrayList<>();
@@ -1256,43 +1243,43 @@ public class ToscaOperationFacadeTest {
affectedComponentIds.add(graphVertex2.getUniqueId());
when(graphLockOperationMock.lockComponent(graphVertex.getUniqueId(), NodeTypeEnum.Resource)).
- thenReturn(StorageOperationStatus.OK);
+ thenReturn(StorageOperationStatus.OK);
when(graphLockOperationMock.lockComponent(graphVertex2.getUniqueId(), NodeTypeEnum.Resource)).
- thenReturn(StorageOperationStatus.OK);
+ thenReturn(StorageOperationStatus.OK);
when(topologyTemplateOperationMock.deleteToscaElement(graphVertex)).thenReturn(Either.left(toscaElement1));
when(topologyTemplateOperationMock.deleteToscaElement(graphVertex2)).thenReturn(Either.left(toscaElement2));
List<GraphVertex> allResourcesToDelete = new ArrayList<>();
allResourcesToDelete.add(graphVertex);
allResourcesToDelete.add(graphVertex2);
when(janusGraphDaoMock.findAllVertexByInvariantUuid(invariantUuid, Collections.emptyMap())).
- thenReturn(allResourcesToDelete);
+ thenReturn(allResourcesToDelete);
when(janusGraphDaoMock.getParentVertices(any(GraphVertex.class), any(), any())).thenReturn(Either.right(JanusGraphOperationStatus.OK));
assertEquals(affectedComponentIds, testInstance.deleteComponent(invariantUuid, NodeTypeEnum.Resource, false));
}
@Test
- public void testDeleteResource_WithOneVersion() {
+ void testDeleteResource_WithOneVersion() {
GraphVertex graphVertex = getTopologyTemplateVertex();
graphVertex.setUniqueId("1");
- Map<String,Object> metadata = new HashMap<>();
+ Map<String, Object> metadata = new HashMap<>();
metadata.put("ex1", new Object());
graphVertex.setMetadataJson(metadata);
ToscaElement toscaElement = getToscaElementForTest();
List<String> affectedComponentIds = new ArrayList<>();
affectedComponentIds.add(graphVertex.getUniqueId());
when(graphLockOperationMock.lockComponent(graphVertex.getUniqueId(), NodeTypeEnum.Resource)).
- thenReturn(StorageOperationStatus.OK);
+ thenReturn(StorageOperationStatus.OK);
when(topologyTemplateOperationMock.deleteToscaElement(graphVertex)).thenReturn(Either.left(toscaElement));
List<GraphVertex> allResourcesToDelete = new ArrayList<>();
allResourcesToDelete.add(graphVertex);
when(janusGraphDaoMock.findAllVertexByInvariantUuid(graphVertex.getUniqueId(), Collections.emptyMap())).
- thenReturn(allResourcesToDelete);
+ thenReturn(allResourcesToDelete);
when(janusGraphDaoMock.getParentVertices(any(GraphVertex.class), any(), any())).thenReturn(Either.right(JanusGraphOperationStatus.OK));
assertEquals(affectedComponentIds, testInstance.deleteComponent("1", NodeTypeEnum.Resource, true));
}
@Test
- public void testDeleteResource_FailDelete() {
+ void testDeleteResource_FailDelete() {
Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
metadataProperties.put(GraphPropertyEnum.NAME, "graphVertex");
GraphVertex graphVertex = getTopologyTemplateVertex();
@@ -1307,25 +1294,91 @@ public class ToscaOperationFacadeTest {
allResourcesToDelete.add(graphVertex);
when(janusGraphDaoMock.findAllVertexByInvariantUuid(graphVertex.getUniqueId(), Collections.emptyMap())).
- thenReturn(allResourcesToDelete);
+ thenReturn(allResourcesToDelete);
when(graphLockOperationMock.lockComponent(graphVertex.getUniqueId(), NodeTypeEnum.Resource)).
- thenReturn(StorageOperationStatus.OK);
+ thenReturn(StorageOperationStatus.OK);
when(topologyTemplateOperationMock.deleteToscaElement(graphVertex))
- .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
when(janusGraphDaoMock.getParentVertices(any(GraphVertex.class), any(), any())).thenReturn(Either.right(JanusGraphOperationStatus.OK));
- StorageException actualException = assertThrows(StorageException.class, () -> testInstance.deleteComponent(invariantUUID, NodeTypeEnum.Resource, false));
+ StorageException actualException = assertThrows(StorageException.class,
+ () -> testInstance.deleteComponent(invariantUUID, NodeTypeEnum.Resource, false));
assertEquals(StorageOperationStatus.NOT_FOUND, actualException.getStorageOperationStatus());
assertEquals(0, actualException.getParams().length);
}
@Test
- public void testDeleteResource_NotFound() {
+ void testDeleteResource_NotFound() {
String invariantUUID = "12345";
- when(janusGraphDaoMock.findAllVertexByInvariantUuid(invariantUUID, Collections.emptyMap())).
- thenReturn(Collections.emptyList());
+ when(janusGraphDaoMock.findAllVertexByInvariantUuid(invariantUUID, Collections.emptyMap())).thenReturn(Collections.emptyList());
assertEquals(0, testInstance.deleteComponent(invariantUUID, NodeTypeEnum.Resource, true).size());
}
+ @Test
+ void testCreateAndAssociateInputs_OK() {
+ GraphVertex vertex = getTopologyTemplateVertex();
+ when(janusGraphDaoMock.getVertexById(COMPONENT_ID, JsonParseFlagEnum.NoParse)).thenReturn(Either.left(vertex));
+ when(topologyTemplateOperationMock.associateInputsToComponent(eq(vertex), anyMap(), anyString())).thenReturn(StorageOperationStatus.OK);
+ Map<String, InputDefinition> inputs = new HashMap<>();
+ inputs.put("1", new InputDefinition());
+ inputs.put("2", new InputDefinition());
+ final var result = testInstance.createAndAssociateInputs(inputs, COMPONENT_ID);
+ assertTrue(result.isLeft());
+ assertNotNull(result.left());
+ assertEquals(2, result.left().value().size());
+ }
+
+ @Test
+ void testCreateAndAssociateInputs_NegativeAssociateInputsToComponentStatus() {
+ GraphVertex vertex = getTopologyTemplateVertex();
+ when(janusGraphDaoMock.getVertexById(COMPONENT_ID, JsonParseFlagEnum.NoParse)).thenReturn(Either.left(vertex));
+ when(topologyTemplateOperationMock.associateInputsToComponent(eq(vertex), anyMap(), anyString()))
+ .thenReturn(StorageOperationStatus.NOT_FOUND);
+ final var result = testInstance.createAndAssociateInputs(new HashMap<>(), COMPONENT_ID);
+ assertTrue(result.isRight());
+ assertEquals(StorageOperationStatus.NOT_FOUND, result.right().value());
+ }
+
+ @Test
+ void testCreateAndAssociateInputs_componentNotFound() {
+ when(janusGraphDaoMock.getVertexById(COMPONENT_ID, JsonParseFlagEnum.NoParse)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ final var result = testInstance.createAndAssociateInputs(new HashMap<>(), COMPONENT_ID);
+ assertTrue(result.isRight());
+ assertEquals(StorageOperationStatus.NOT_FOUND, result.right().value());
+ }
+
+ @Test
+ void testCreateAndAssociateOutputs_OK() {
+ GraphVertex vertex = getTopologyTemplateVertex();
+ when(janusGraphDaoMock.getVertexById(COMPONENT_ID, JsonParseFlagEnum.NoParse)).thenReturn(Either.left(vertex));
+ when(topologyTemplateOperationMock.associateOutputsToComponent(eq(vertex), anyMap(), anyString())).thenReturn(StorageOperationStatus.OK);
+ Map<String, OutputDefinition> outputs = new HashMap<>();
+ outputs.put("1", new OutputDefinition());
+ outputs.put("2", new OutputDefinition());
+ final var result = testInstance.createAndAssociateOutputs(outputs, COMPONENT_ID);
+ assertTrue(result.isLeft());
+ assertNotNull(result.left());
+ assertEquals(2, result.left().value().size());
+ }
+
+ @Test
+ void testCreateAndAssociateOutputs_NegativeAssociateOutputsToComponentStatus() {
+ GraphVertex vertex = getTopologyTemplateVertex();
+ when(janusGraphDaoMock.getVertexById(COMPONENT_ID, JsonParseFlagEnum.NoParse)).thenReturn(Either.left(vertex));
+ when(topologyTemplateOperationMock.associateOutputsToComponent(eq(vertex), anyMap(), anyString()))
+ .thenReturn(StorageOperationStatus.NOT_FOUND);
+ final var result = testInstance.createAndAssociateOutputs(new HashMap<>(), COMPONENT_ID);
+ assertTrue(result.isRight());
+ assertEquals(StorageOperationStatus.NOT_FOUND, result.right().value());
+ }
+
+ @Test
+ void testCreateAndAssociateOutputs_componentNotFound() {
+ when(janusGraphDaoMock.getVertexById(COMPONENT_ID, JsonParseFlagEnum.NoParse)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ final var result = testInstance.createAndAssociateOutputs(new HashMap<>(), COMPONENT_ID);
+ assertTrue(result.isRight());
+ assertEquals(StorageOperationStatus.NOT_FOUND, result.right().value());
+ }
+
private StorageOperationStatus associateRequirementsToServiceWithStatus(StorageOperationStatus status) {
Map<String, ListRequirementDataDefinition> requirementsMap = new HashedMap();
String componentId = "componentid";
@@ -1359,7 +1412,9 @@ public class ToscaOperationFacadeTest {
}
Either<GraphVertex, JanusGraphOperationStatus> getVertexEither = Either.left(vertex);
when(janusGraphDaoMock.getVertexById(componentId, JsonParseFlagEnum.ParseMetadata)).thenReturn(getVertexEither);
- when(topologyTemplateOperationMock.addPolicyToToscaElement(eq(vertex), any(PolicyDefinition.class), anyInt())).thenReturn(status);
+ if (status == StorageOperationStatus.OK) {
+ when(topologyTemplateOperationMock.addPolicyToToscaElement(eq(vertex), any(PolicyDefinition.class), anyInt())).thenReturn(status);
+ }
return testInstance.associatePolicyToComponent(componentId, policy, counter);
}
@@ -1406,4 +1461,5 @@ public class ToscaOperationFacadeTest {
graphVertex.setLabel(VertexTypeEnum.NODE_TYPE);
return graphVertex;
}
+
}
diff --git a/catalog-ui/src/app/models/attributes-outputs/output-be-model.ts b/catalog-ui/src/app/models/attributes-outputs/output-be-model.ts
index c5f0bfabd3..e90a8a9f4e 100644
--- a/catalog-ui/src/app/models/attributes-outputs/output-be-model.ts
+++ b/catalog-ui/src/app/models/attributes-outputs/output-be-model.ts
@@ -18,23 +18,21 @@
* ============LICENSE_END=========================================================
*/
-import {AttributeBEModel} from "./attribute-be-model";
+import { AttributeBEModel } from './attribute-be-model';
export class OutputBEModel extends AttributeBEModel {
outputPath: string;
- outputs: Array<OutputComponentInstanceModel>;
instanceUniqueId: string;
ownerId: string;
attributeId: string;
- attributes: Array<OutputComponentInstanceModel>;
+ attribute: OutputComponentInstanceModel;
constructor(output?: OutputBEModel) {
super(output);
this.instanceUniqueId = output.instanceUniqueId;
this.attributeId = output.attributeId;
- this.attributes = output.attributes;
- this.outputs = output.outputs;
+ this.attribute = output.attribute;
this.ownerId = output.ownerId;
this.outputPath = output.outputPath;
}
diff --git a/catalog-ui/src/app/models/attributes-outputs/output-fe-model.ts b/catalog-ui/src/app/models/attributes-outputs/output-fe-model.ts
index 8806562d06..d66846bf4a 100644
--- a/catalog-ui/src/app/models/attributes-outputs/output-fe-model.ts
+++ b/catalog-ui/src/app/models/attributes-outputs/output-fe-model.ts
@@ -18,11 +18,11 @@
* ============LICENSE_END=========================================================
*/
-import * as _ from "lodash";
-import {PROPERTY_DATA} from "../../utils/constants";
-import {OutputBEModel} from "./output-be-model";
-import {AttributeFEModel} from "./attribute-fe-model";
-import {DerivedAttributeType} from "./attribute-be-model";
+import * as _ from 'lodash';
+import { PROPERTY_DATA } from '../../utils/constants';
+import { DerivedAttributeType } from './attribute-be-model';
+import { AttributeFEModel } from './attribute-fe-model';
+import { OutputBEModel } from './output-be-model';
export class OutputFEModel extends OutputBEModel {
isSimpleType: boolean;
@@ -38,7 +38,7 @@ export class OutputFEModel extends OutputBEModel {
super(output);
if (output) {
this.isSimpleType = PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1;
- let relatedAttribute = output.attributes && output.attributes[0] || output.outputs && output.outputs[0];
+ const relatedAttribute = output.attribute;
if (relatedAttribute) {
this.relatedAttributeValue = relatedAttribute.value;
this.relatedAttributeName = relatedAttribute.name;
@@ -71,6 +71,6 @@ export class OutputFEModel extends OutputBEModel {
}
hasChanged(): boolean {
- return this.hasDefaultValueChanged() ;
+ return this.hasDefaultValueChanged();
}
}
diff --git a/common-app-api/pom.xml b/common-app-api/pom.xml
index 7905404f82..10b08266fe 100644
--- a/common-app-api/pom.xml
+++ b/common-app-api/pom.xml
@@ -324,9 +324,9 @@
</dependency>
<dependency>
- <artifactId>commons-collections</artifactId>
- <groupId>commons-collections</groupId>
- <version>3.2.2</version>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-collections4</artifactId>
+ <version>${commons.collections.version}</version>
</dependency>
<dependency>
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/AttributeDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/AttributeDataDefinition.java
index 7e99418221..77e219b1b3 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/AttributeDataDefinition.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/AttributeDataDefinition.java
@@ -34,7 +34,7 @@ import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
@NoArgsConstructor
public class AttributeDataDefinition extends ToscaDataDefinition {
- private transient List<GetOutputValueDataDefinition> getOutputValues;
+ private List<GetOutputValueDataDefinition> getOutputValues;
private String outputId;
private String value;
private String outputPath;
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java b/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java
index 4a41039213..92a9e3a144 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java
@@ -64,8 +64,8 @@ public class TypeUtils {
// Heat env Validation
PARAMETERS("parameters"),
// Import Validations
- TOSCA_VERSION("tosca_definitions_version"), TOPOLOGY_TEMPLATE("topology_template"), OCCURRENCES("occurrences"), NODE_TEMPLATES(
- "node_templates"), GROUPS("groups"), INPUTS("inputs"),
+ TOSCA_VERSION("tosca_definitions_version"), TOPOLOGY_TEMPLATE("topology_template"), OCCURRENCES("occurrences"), NODE_TEMPLATES("node_templates"),
+ GROUPS("groups"), INPUTS("inputs"), OUTPUTS("outputs"),
SUBSTITUTION_MAPPINGS("substitution_mappings"), NODE_TYPE("node_type"), DIRECTIVES("directives"),
// Attributes
ATTRIBUTES("attributes"), LABEL("label"), HIDDEN("hidden"), IMMUTABLE("immutable"), ANNOTATIONS("annotations"),
diff --git a/pom.xml b/pom.xml
index fcd64aead5..c3683ca443 100644
--- a/pom.xml
+++ b/pom.xml
@@ -47,7 +47,7 @@ Modifications copyright (c) 2018-2019 Nokia
<lang3.version>3.10</lang3.version>
<guava.version>30.1-jre</guava.version>
<janusgraph.version>0.3.3</janusgraph.version>
- <spring.version>5.3.18</spring.version>
+ <spring.version>5.3.20</spring.version>
<spring.boot.version>2.2.13.RELEASE</spring.boot.version>
<!-- update to 2.36 bring error-->
@@ -76,7 +76,7 @@ Modifications copyright (c) 2018-2019 Nokia
<hibernate.validator.version>6.1.6.Final</hibernate.validator.version>
<org.json.version>20220320</org.json.version>
- <commons.collections.version>4.1</commons.collections.version>
+ <commons.collections.version>4.3</commons.collections.version>
<ws.rs.version>2.1.1</ws.rs.version>
<javax.validation.version>2.0.1.Final</javax.validation.version>
<javax.servlet.version>${servlet-api.version}</javax.servlet.version>