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/ResourceImportManagerTest.java95
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ImportUtilsTest.java10
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java17
-rw-r--r--catalog-be/src/test/resources/customTypes/custom-types-node-type-with-interface-impl-unknown-operation.yml26
-rw-r--r--catalog-be/src/test/resources/customTypes/custom-types-node-type-with-interface-impl.yml26
-rw-r--r--catalog-be/src/test/resources/customTypes/custom-types-node-type-with-unknown-interface-impl.yml26
6 files changed, 200 insertions, 0 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
index 88eff3372a..58d93fbfb8 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
@@ -32,6 +32,7 @@ import org.mockito.stubbing.Answer;
import org.openecomp.sdc.be.auditing.impl.AuditingManager;
import org.openecomp.sdc.be.components.impl.ImportUtils;
import org.openecomp.sdc.be.components.impl.ImportUtilsTest;
+import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
@@ -40,8 +41,10 @@ import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.RequirementDefinition;
@@ -68,6 +71,7 @@ import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
@@ -79,6 +83,8 @@ public class ResourceImportManagerTest {
static AuditingManager auditingManager = Mockito.mock(AuditingManager.class);
static ResponseFormatManager responseFormatManager = Mockito.mock(ResponseFormatManager.class);
static ResourceBusinessLogic resourceBusinessLogic = Mockito.mock(ResourceBusinessLogic.class);
+ static InterfaceOperationBusinessLogic interfaceOperationBusinessLogic = Mockito.mock(InterfaceOperationBusinessLogic.class);
+
static UserBusinessLogic userAdmin = Mockito.mock(UserBusinessLogic.class);
static ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
@@ -92,6 +98,7 @@ public class ResourceImportManagerTest {
when(toscaOperationFacade.getLatestByToscaResourceName(Mockito.anyString())).thenReturn(Either.left(null));
importManager.setResponseFormatManager(responseFormatManager);
importManager.setResourceBusinessLogic(resourceBusinessLogic);
+ importManager.setInterfaceOperationBusinessLogic(interfaceOperationBusinessLogic);
importManager.setToscaOperationFacade(toscaOperationFacade);
String appConfigDir = "src/test/resources/config/catalog-be";
@@ -195,6 +202,78 @@ public class ResourceImportManagerTest {
testSetRequirments(createResource.left);
}
+
+ @Test
+ public void testResourceCreationWithInterfaceImplementation() throws IOException {
+ UploadResourceInfo resourceMD = createDummyResourceMD();
+ User user = new User();
+ user.setUserId(resourceMD.getContactId());
+ when(userAdmin.getUser(Mockito.anyString(), Mockito.anyBoolean())).thenReturn(user);
+
+ setResourceBusinessLogicMock();
+
+ String jsonContent = ImportUtilsTest.loadCustomTypeFileNameToJsonString("custom-types-node-type-with-interface-impl.yml");
+
+ Map<String, InterfaceDefinition> interfaceTypes = new HashMap<>();
+ final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setType("tosca.interfaces.node.lifecycle.Standard");
+ Map<String, OperationDataDefinition> operations = new HashMap<>();
+ operations.put("configure", new OperationDataDefinition());
+ interfaceDefinition.setOperations(operations );
+ interfaceTypes.put("tosca.interfaces.node.lifecycle.standard", interfaceDefinition);
+ when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(interfaceTypes));
+
+ ImmutablePair<Resource, ActionStatus> createResource = importManager.importNormativeResource(jsonContent, resourceMD, user, true, true);
+ testSetInterfaceImplementation(createResource.left);
+ }
+
+ @Test
+ public void testResourceCreationWithInterfaceImplementation_UnknownInterface() throws IOException {
+ UploadResourceInfo resourceMD = createDummyResourceMD();
+ User user = new User();
+ user.setUserId(resourceMD.getContactId());
+ when(userAdmin.getUser(Mockito.anyString(), Mockito.anyBoolean())).thenReturn(user);
+
+ setResourceBusinessLogicMock();
+
+ String jsonContent = ImportUtilsTest.loadCustomTypeFileNameToJsonString("custom-types-node-type-with-unknown-interface-impl.yml");
+
+ Map<String, InterfaceDefinition> interfaceTypes = new HashMap<>();
+ final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setType("tosca.interfaces.node.lifecycle.Standard");
+ Map<String, OperationDataDefinition> operations = new HashMap<>();
+ operations.put("configure", new OperationDataDefinition());
+ interfaceDefinition.setOperations(operations );
+ interfaceTypes.put("tosca.interfaces.node.lifecycle.standard", interfaceDefinition);
+ when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(interfaceTypes));
+
+ ImmutablePair<Resource, ActionStatus> createResource = importManager.importNormativeResource(jsonContent, resourceMD, user, true, true);
+ assertNull(createResource.left.getInterfaces());
+ }
+
+ @Test
+ public void testResourceCreationWitInterfaceImplementation_UnknownOperation() throws IOException {
+ UploadResourceInfo resourceMD = createDummyResourceMD();
+ User user = new User();
+ user.setUserId(resourceMD.getContactId());
+ when(userAdmin.getUser(Mockito.anyString(), Mockito.anyBoolean())).thenReturn(user);
+
+ setResourceBusinessLogicMock();
+
+ String jsonContent = ImportUtilsTest.loadCustomTypeFileNameToJsonString("custom-types-node-type-with-interface-impl-unknown-operation.yml");
+
+ Map<String, InterfaceDefinition> interfaceTypes = new HashMap<>();
+ final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setType("tosca.interfaces.node.lifecycle.Standard");
+ Map<String, OperationDataDefinition> operations = new HashMap<>();
+ operations.put("configure", new OperationDataDefinition());
+ interfaceDefinition.setOperations(operations );
+ interfaceTypes.put("tosca.interfaces.node.lifecycle.standard", interfaceDefinition);
+ when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(interfaceTypes));
+
+ ImmutablePair<Resource, ActionStatus> createResource = importManager.importNormativeResource(jsonContent, resourceMD, user, true, true);
+ assertNull(createResource.left.getInterfaces());
+ }
private void setResourceBusinessLogicMock() {
when(resourceBusinessLogic.getUserAdmin()).thenReturn(userAdmin);
@@ -318,6 +397,22 @@ public class ResourceImportManagerTest {
assertEquals("binding", requirement.getName());
}
+
+ private void testSetInterfaceImplementation(Resource resource) {
+ Map<String, InterfaceDefinition> interfaces = resource.getInterfaces();
+ assertEquals(1, interfaces.size());
+ assertTrue(interfaces.containsKey("Standard"));
+
+ InterfaceDefinition interfaceDefinition = interfaces.get("Standard");
+ assertEquals("tosca.interfaces.node.lifecycle.Standard", interfaceDefinition.getType());
+ assertEquals("tosca.interfaces.node.lifecycle.standard", interfaceDefinition.getUniqueId());
+ Map<String, OperationDataDefinition> operations = interfaceDefinition.getOperations();
+ assertEquals(1, operations.size());
+
+ OperationDataDefinition operation = operations.get("configure");
+ assertEquals("\"camunda/vnfConfigure\"", operation.getImplementation().getArtifactName());
+
+ }
private void testSetDerivedFrom(Resource resource) {
assertEquals(1, resource.getDerivedFrom().size());
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 681e9cda95..e47cdc999e 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
@@ -540,11 +540,21 @@ 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);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java
index dafe0fc280..23288582ca 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java
@@ -90,6 +90,23 @@ public class OperationArtifactUtilTest {
assertEquals(expectedArtifactPath,actualArtifactPath);
}
+
+ @Test
+ public void testCorrectPathForLiteralInterfaceImplementationValue() {
+ ResourceMetadataDataDefinition componentMetadataDataDefinition = new ResourceMetadataDataDefinition();
+ componentMetadataDataDefinition.setToscaResourceName("org.openecomp.resource.vf.TestResource");
+ final ComponentMetadataDefinition componentMetadataDefinition =
+ new ComponentMetadataDefinition(componentMetadataDataDefinition);
+ Component component = new Resource(componentMetadataDefinition);
+ final OperationDataDefinition op = new OperationDataDefinition();
+ final ArtifactDataDefinition implementation = new ArtifactDataDefinition();
+ implementation.setArtifactName("\"createBPMN.bpmn\"");
+ op.setImplementation(implementation);
+ final String actualArtifactPath = OperationArtifactUtil.createOperationArtifactPath(component, null, op, false);
+ String expectedArtifactPath = "createBPMN.bpmn";
+
+ assertEquals(expectedArtifactPath,actualArtifactPath);
+ }
@Test
public void testGetDistinctInterfaceOperationArtifactsByName() {
diff --git a/catalog-be/src/test/resources/customTypes/custom-types-node-type-with-interface-impl-unknown-operation.yml b/catalog-be/src/test/resources/customTypes/custom-types-node-type-with-interface-impl-unknown-operation.yml
new file mode 100644
index 0000000000..af49b43989
--- /dev/null
+++ b/catalog-be/src/test/resources/customTypes/custom-types-node-type-with-interface-impl-unknown-operation.yml
@@ -0,0 +1,26 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ org.openecomp.resources.customNodeType:
+ derived_from: tosca.nodes.Root
+ description: A node type derived from tosca.nodes.Root with an interface implementation
+ attributes:
+ tosca_id:
+ type: string
+ tosca_name:
+ type: string
+ state:
+ type: string
+ capabilities:
+ feature:
+ type: tosca.capabilities.Node
+ requirements:
+ - dependency :
+ capability: tosca.capabilities.Node
+ node: tosca.nodes.Root
+ relationship: tosca.relationships.DependsOn
+ occurrences: [ 0, UNBOUNDED ]
+ interfaces:
+ Standard:
+ type: tosca.interfaces.node.lifecycle.Standard
+ unknownoperation:
+ implementation: 'camunda/vnfConfigure' \ No newline at end of file
diff --git a/catalog-be/src/test/resources/customTypes/custom-types-node-type-with-interface-impl.yml b/catalog-be/src/test/resources/customTypes/custom-types-node-type-with-interface-impl.yml
new file mode 100644
index 0000000000..2fc8e3d8de
--- /dev/null
+++ b/catalog-be/src/test/resources/customTypes/custom-types-node-type-with-interface-impl.yml
@@ -0,0 +1,26 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ org.openecomp.resources.customNodeType:
+ derived_from: tosca.nodes.Root
+ description: A node type derived from tosca.nodes.Root with an interface implementation
+ attributes:
+ tosca_id:
+ type: string
+ tosca_name:
+ type: string
+ state:
+ type: string
+ capabilities:
+ feature:
+ type: tosca.capabilities.Node
+ requirements:
+ - dependency :
+ capability: tosca.capabilities.Node
+ node: tosca.nodes.Root
+ relationship: tosca.relationships.DependsOn
+ occurrences: [ 0, UNBOUNDED ]
+ interfaces:
+ Standard:
+ type: tosca.interfaces.node.lifecycle.Standard
+ configure:
+ implementation: 'camunda/vnfConfigure' \ No newline at end of file
diff --git a/catalog-be/src/test/resources/customTypes/custom-types-node-type-with-unknown-interface-impl.yml b/catalog-be/src/test/resources/customTypes/custom-types-node-type-with-unknown-interface-impl.yml
new file mode 100644
index 0000000000..680b1d7ca8
--- /dev/null
+++ b/catalog-be/src/test/resources/customTypes/custom-types-node-type-with-unknown-interface-impl.yml
@@ -0,0 +1,26 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ org.openecomp.resources.customNodeType:
+ derived_from: tosca.nodes.Root
+ description: A node type derived from tosca.nodes.Root with an interface implementation
+ attributes:
+ tosca_id:
+ type: string
+ tosca_name:
+ type: string
+ state:
+ type: string
+ capabilities:
+ feature:
+ type: tosca.capabilities.Node
+ requirements:
+ - dependency :
+ capability: tosca.capabilities.Node
+ node: tosca.nodes.Root
+ relationship: tosca.relationships.DependsOn
+ occurrences: [ 0, UNBOUNDED ]
+ interfaces:
+ Standard:
+ type: tosca.interfaces.node.lifecycle.Unknown
+ configure:
+ implementation: 'camunda/vnfConfigure' \ No newline at end of file