summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-07-14 21:06:58 +0100
committerMichael Morris <michael.morris@est.tech>2022-07-15 13:16:16 +0000
commitee8876059c520d97bf068734b25a02365d7fe1ea (patch)
tree46176fc6a016818c6d17dd0ac20054ec884e7802 /catalog-be/src/test/java/org
parente4055451d3fbfe1fba35dcf546907ad432f6b4fc (diff)
Support Outputs during Import Service
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: I4d58576b70ef738d6fa7545cd268ec030b43f95c Issue-ID: SDC-4051
Diffstat (limited to 'catalog-be/src/test/java/org')
-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
5 files changed, 308 insertions, 182 deletions
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);