aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandlerTest.java34
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java3
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java81
-rw-r--r--catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml19
-rw-r--r--catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-tosca1.3.yaml19
-rw-r--r--catalog-be/src/test/resources/interfaceDefinition/interfaceDefinitionInvalidMilestone-tosca1.3.yaml17
6 files changed, 153 insertions, 20 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandlerTest.java
index bbbbcfc260..800fbc2082 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandlerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandlerTest.java
@@ -26,9 +26,10 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.lenient;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DEFAULT;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DESCRIPTION;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.REQUIRED;
@@ -56,27 +57,36 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.yaml.snakeyaml.Yaml;
@ExtendWith(MockitoExtension.class)
class InterfaceDefinitionHandlerTest {
- @Mock
- private InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
- private InterfaceDefinitionHandler interfaceDefinitionHandler;
- private InterfaceDefinition interfaceLifecyleStandard;
private static final Path TEST_RESOURCE_PATH = Paths.get("src/test/resources/interfaceDefinition");
private static final String CREATE_OPERATION = "create";
private static final String DELETE_OPERATION = "delete";
private static final String START_OPERATION = "start";
private static final String STOP_OPERATION = "stop";
private static final String INTERFACE_TYPE = "tosca.interfaces.node.lifecycle.Standard";
+ static ConfigurationSource
+ configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be");
+ static ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
+ @Mock
+ private InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
+ private InterfaceDefinitionHandler interfaceDefinitionHandler;
+ private InterfaceDefinition interfaceLifecyleStandard;
@BeforeEach
void setUp() {
@@ -95,7 +105,7 @@ class InterfaceDefinitionHandlerTest {
operations.put(DELETE_OPERATION, new OperationDataDefinition());
interfaceLifecyleStandard.setOperations(operations);
interfaceTypes.put(INTERFACE_TYPE, interfaceLifecyleStandard);
- when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(StringUtils.EMPTY)).thenReturn(Either.left(interfaceTypes));
+ lenient().when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(StringUtils.EMPTY)).thenReturn(Either.left(interfaceTypes));
}
@Test
@@ -108,10 +118,20 @@ class InterfaceDefinitionHandlerTest {
@Test
void testCreateWithOperationSuccess() throws FileNotFoundException {
final Map<String, Object> load = loadYaml(Paths.get("interfaceDefinition-tosca1.3.yaml"));
- final InterfaceDefinition actualInterfaceDefinition = interfaceDefinitionHandler.create( load, StringUtils.EMPTY);
+ final InterfaceDefinition actualInterfaceDefinition = interfaceDefinitionHandler.create(load, StringUtils.EMPTY);
assertInterfaceDefinition(actualInterfaceDefinition);
}
+ @Test
+ void testCreateWithOperationFailMilestones() throws FileNotFoundException {
+ final Map<String, Object> load = loadYaml(Paths.get("interfaceDefinitionInvalidMilestone-tosca1.3.yaml"));
+ final ByActionStatusComponentException actualException =
+ assertThrows(ByActionStatusComponentException.class, () -> interfaceDefinitionHandler.create(load, StringUtils.EMPTY));
+ assertEquals(ActionStatus.INVALID_OPERATION_MILESTONE, actualException.getActionStatus());
+ assertEquals(1, actualException.getParams().length);
+ assertEquals("on_failure", actualException.getParams()[0]);
+ }
+
private void assertInterfaceDefinition(final InterfaceDefinition actualInterfaceDefinition) {
interfaceLifecyleStandard.getOperations().keySet().forEach(operation ->
assertTrue(actualInterfaceDefinition.hasOperation(operation)));
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java
index 407956db0e..587b902f4c 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java
@@ -57,6 +57,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.InterfaceInstanceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MilestoneDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum;
@@ -1052,7 +1053,7 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
new ComponentInstanceInterface("interfaceId", new InterfaceInstanceDataDefinition());
Map<String, Operation> operationsMap = Maps.newHashMap();
operationsMap.put(operationId, new Operation(new ArtifactDataDefinition(), "1",
- new ListDataDefinition<>(), new ListDataDefinition<>()));
+ new ListDataDefinition<>(), new ListDataDefinition<>(), new HashMap<>()));
componentInstanceInterface.setOperationsMap(operationsMap);
Map<String, List<ComponentInstanceInterface>> componentInstancesInterfacesMap = Maps.newHashMap();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
index 5ba29cbbef..dfe4107b86 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
@@ -42,16 +42,20 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openecomp.sdc.be.DummyConfigurationManager;
+import org.openecomp.sdc.be.datatypes.elements.ActivityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MilestoneDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType;
+import org.openecomp.sdc.be.datatypes.enums.ActivityTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.datatypes.enums.MilestoneTypeEnum;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
@@ -98,7 +102,7 @@ class InterfacesOperationsConverterTest {
component.getComponentMetadataDefinition().getMetadataDataDefinition().setSystemName("NodeTypeName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType("Local");
- addOperationsToInterface(component, addedInterface, 5, 3, true, false, false);
+ addOperationsToInterface(component, addedInterface, 5, 3, true, false, false, false);
final String interfaceType = "normalizedComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
@@ -121,7 +125,7 @@ class InterfacesOperationsConverterTest {
component.getComponentMetadataDefinition().getMetadataDataDefinition().setSystemName("NodeTypeName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType("Local");
- addOperationsToInterface(component, addedInterface, 5, 3, true, false, false);
+ addOperationsToInterface(component, addedInterface, 5, 3, true, false, false, false);
final String interfaceType = "normalizedServiceComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
@@ -142,7 +146,7 @@ class InterfacesOperationsConverterTest {
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType("com.some.resource.or.other.resourceName");
- addOperationsToInterface(component, addedInterface, 3, 2, true, false, false);
+ addOperationsToInterface(component, addedInterface, 3, 2, true, false, false, false);
final String interfaceType = "normalizedComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
@@ -165,7 +169,7 @@ class InterfacesOperationsConverterTest {
component.setNormalizedName("normalizedServiceComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType("com.some.service.or.other.serviceName");
- addOperationsToInterface(component, addedInterface, 3, 2, true, false, false);
+ addOperationsToInterface(component, addedInterface, 3, 2, true, false, false, false);
final String interfaceType = "normalizedServiceComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
@@ -189,7 +193,7 @@ class InterfacesOperationsConverterTest {
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
addedInterface.setType("com.some.resource.or.other.resourceName");
- addOperationsToInterface(component, addedInterface, 3, 2, true, false, false);
+ addOperationsToInterface(component, addedInterface, 3, 2, true, false, false, false);
final String interfaceType = "normalizedComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
@@ -210,7 +214,7 @@ class InterfacesOperationsConverterTest {
component.setNormalizedName("normalizedComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType("com.some.resource.or.other.resourceNameNoInputs");
- addOperationsToInterface(component, addedInterface, 3, 3, false, false, false);
+ addOperationsToInterface(component, addedInterface, 3, 3, false, false, false, false);
final String interfaceType = "normalizedComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
@@ -234,7 +238,7 @@ class InterfacesOperationsConverterTest {
component.setNormalizedName("normalizedComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType(addedInterfaceType);
- addOperationsToInterface(component, addedInterface, 2, 2, true, true, false);
+ addOperationsToInterface(component, addedInterface, 2, 2, true, true, false, false);
addedInterface.getOperationsMap().values().stream()
.filter(operationInputDefinition -> operationInputDefinition.getName().equalsIgnoreCase(
"name_for_op_0"))
@@ -268,7 +272,7 @@ class InterfacesOperationsConverterTest {
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType(addedInterfaceType);
addedInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
- addOperationsToInterface(component, addedInterface, 2, 2, true, true, false);
+ addOperationsToInterface(component, addedInterface, 2, 2, true, true, false, false);
addedInterface.getOperationsMap().values().stream()
.filter(operationInputDefinition -> operationInputDefinition.getName().equalsIgnoreCase(
"name_for_op_0"))
@@ -281,7 +285,7 @@ class InterfacesOperationsConverterTest {
InterfaceDefinition secondInterface = new InterfaceDefinition();
secondInterface.setType(secondInterfaceType);
secondInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
- addOperationsToInterface(component, secondInterface, 2, 2, true, true, false);
+ addOperationsToInterface(component, secondInterface, 2, 2, true, true, false, false);
secondInterface.getOperationsMap().values().stream()
.filter(operationInputDefinition -> operationInputDefinition.getName().equalsIgnoreCase(
"name_for_op_0"))
@@ -396,8 +400,8 @@ class InterfacesOperationsConverterTest {
assertTrue(expectedListOfStringPropValue.contains("value3"));
}
- private void addOperationsToInterface(Component component, InterfaceDefinition addedInterface, int numOfOps,
- int numOfInputsPerOp, boolean hasInputs, boolean hasOutputs, boolean addAComplexType) {
+ private void addOperationsToInterface(Component component, InterfaceDefinition addedInterface, int numOfOps, int numOfInputsPerOp,
+ boolean hasInputs, boolean hasOutputs, boolean addAComplexType, boolean hasMilestones) {
addedInterface.setOperations(new HashMap<>());
for (int i = 0; i < numOfOps; i++) {
@@ -407,6 +411,9 @@ class InterfacesOperationsConverterTest {
final ArtifactDataDefinition implementation = new ArtifactDataDefinition();
implementation.setArtifactName(i + "_createBPMN.bpmn");
operation.setImplementation(implementation);
+ if (hasMilestones) {
+ operation.setMilestones(createMilestones());
+ }
if (hasInputs) {
operation.setInputs(createInputs(component, numOfInputsPerOp, addAComplexType));
}
@@ -418,6 +425,19 @@ class InterfacesOperationsConverterTest {
}
}
+ private Map<String, MilestoneDataDefinition> createMilestones() {
+ Map<String, MilestoneDataDefinition> toscaMilestones = new HashMap<>();
+ ActivityDataDefinition activity = new ActivityDataDefinition();
+ activity.setType(ActivityTypeEnum.DELEGATE.getValue());
+ activity.setWorkflow("workflow1");
+ ListDataDefinition<ActivityDataDefinition> activities = new ListDataDefinition<>();
+ activities.add(activity);
+ MilestoneDataDefinition milestone = new MilestoneDataDefinition();
+ milestone.setActivities(activities);
+ toscaMilestones.put(MilestoneTypeEnum.ON_ENTRY.getValue(), milestone);
+ return toscaMilestones;
+ }
+
private InputDataDefinition createInput(final String type, final String description, final Boolean isRequired,
final String defaultValue) {
final PropertyDataDefinition propertyDataDefinition = new PropertyDataDefinition();
@@ -555,7 +575,7 @@ class InterfacesOperationsConverterTest {
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
addedInterface.setType("com.some.resource.or.other.resourceName");
- addOperationsToInterface(component, addedInterface, 3, 2, true, false, true);
+ addOperationsToInterface(component, addedInterface, 3, 2, true, false, true, false);
final String interfaceType = "normalizedComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
@@ -585,6 +605,43 @@ class InterfacesOperationsConverterTest {
assertEquals("SELF", complexInputStringProp.get("propertySource"));
}
+ @Test
+ void testGetInterfaceAsMapWithMilestones() {
+ Component component = new Resource();
+ component.setNormalizedName("normalizedComponentName");
+ InterfaceDefinition addedInterface = new InterfaceDefinition();
+ addedInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
+ addedInterface.setType("com.some.resource.or.other.resourceName");
+ addOperationsToInterface(component, addedInterface, 2, 0, false, false, false, true);
+ final String interfaceType = "normalizedComponentName-interface";
+ component.setInterfaces(new HashMap<>());
+ component.getInterfaces().put(interfaceType, addedInterface);
+ final var interfacesMap = interfacesOperationsConverter.getInterfacesMap(component, null, component.getInterfaces(), dataTypes, false);
+ assertNotNull(interfacesMap);
+ assertEquals(1, interfacesMap.size());
+ assertTrue(interfacesMap.containsKey("resourceName"));
+ Object resourceName = interfacesMap.get("resourceName");
+ assertNotNull(resourceName);
+ assertTrue(resourceName instanceof Map);
+ assertEquals(3, ((Map) resourceName).size());
+ Map<String, Object> resource = (Map<String, Object>) resourceName;
+ assertTrue(resource.containsKey("name_for_op_0"));
+ Map<String, Object> operation0 = (Map<String, Object>) resource.get("name_for_op_0");
+ assertTrue(operation0.containsKey("milestones"));
+ Map<String, Object> operation0Milestones = (Map<String, Object>) operation0.get("milestones");
+ assertTrue(operation0Milestones.containsKey(MilestoneTypeEnum.ON_ENTRY.getValue()));
+ Map<String, Object> milestone = (Map<String, Object>) operation0Milestones.get(MilestoneTypeEnum.ON_ENTRY.getValue());
+ assertTrue(milestone.containsKey("activities"));
+ List<Map<String, Object>> activities = (List<Map<String, Object>>) milestone.get("activities");
+ assertEquals(1, activities.size());
+ Map<String, Object> activity = activities.get(0);
+ assertEquals(1, activities.size());
+ assertTrue(activity.containsKey("delegate"));
+ Map<String, String> activityVariables = (Map<String, String>) activity.get("delegate");
+ assertTrue(activityVariables.containsKey("workflow"));
+ assertEquals("workflow1", activityVariables.get("workflow"));
+ }
+
private void addComplexTypeToDataTypes() {
PropertyDefinition intProp = new PropertyDefinition();
intProp.setType("integer");
diff --git a/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml
index 49de865f63..8f350edd54 100644
--- a/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml
+++ b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml
@@ -46,6 +46,25 @@ start:
service_restoration_sla: service_restoration_sla_value
battery_backup: true
partner_priorty_assist: false
+ milestones:
+ on_failure:
+ activities:
+ - type: delegate
+ workflow: workflow1
+ - type: delegate
+ workflow: workflow2
+ on_success:
+ activities:
+ - type: delegate
+ workflow: workflow1
+ - type: delegate
+ workflow: workflow2
+ on_timeout:
+ activities:
+ - type: delegate
+ workflow: workflow1
+ - type: delegate
+ workflow: workflow2
stop:
implementation: "camunda/executeAction"
inputs:
diff --git a/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-tosca1.3.yaml b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-tosca1.3.yaml
index 164280ddda..8adcdcf4cf 100644
--- a/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-tosca1.3.yaml
+++ b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-tosca1.3.yaml
@@ -41,6 +41,25 @@ operations:
service_restoration_sla: service_restoration_sla_value
battery_backup: true
partner_priorty_assist: false
+ milestones:
+ on_failure:
+ activities:
+ - type: delegate
+ workflow: workflow1
+ - type: delegate
+ workflow: workflow2
+ on_success:
+ activities:
+ - type: delegate
+ workflow: workflow1
+ - type: delegate
+ workflow: workflow2
+ on_timeout:
+ activities:
+ - type: delegate
+ workflow: workflow1
+ - type: delegate
+ workflow: workflow2
stop:
implementation: "camunda/executeAction"
inputs:
diff --git a/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinitionInvalidMilestone-tosca1.3.yaml b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinitionInvalidMilestone-tosca1.3.yaml
new file mode 100644
index 0000000000..4e3c556cb8
--- /dev/null
+++ b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinitionInvalidMilestone-tosca1.3.yaml
@@ -0,0 +1,17 @@
+inputs:
+ stringInput:
+ type: string
+ description: stringInput description
+ required: true
+ default: defaultValue
+ status: aStatus
+ actionInput:
+ type: org.openecomp.resource.datatypes.Action
+type: tosca.interfaces.node.lifecycle.Standard
+operations:
+ start:
+ implementation: "camunda/executeAction"
+ milestones:
+ on_failure:
+ on_success:
+ on_timeout: \ No newline at end of file