summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2020-02-12 14:59:19 +0000
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-03-24 14:19:28 +0000
commite224d76e1558a31818badc60af59dc02e0fb268a (patch)
treee928a5d2b46dd2519c70fe95be7f165246740914 /catalog-be/src/test/java/org
parent97930ffc459281aa11c8e3fb1ffacafdc3d161be (diff)
Import of VFC will maintain interface implementations
Issue-ID: SDC-2772 Signed-off-by: MichaelMorris <michael.morris@est.tech> Change-Id: Id387ebd67ff0b136d532df70fe8b2b8760edc433
Diffstat (limited to 'catalog-be/src/test/java/org')
-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
3 files changed, 122 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() {