diff options
Diffstat (limited to 'catalog-be/src/test/java/org')
4 files changed, 111 insertions, 200 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java index 6dd97bf62a..8b1fe5fabb 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java @@ -210,7 +210,7 @@ public class CsarUtilsTest extends BeConfDependentTest { .thenReturn(Either.right(ToscaError.GENERAL_ERROR)); try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, false, false); + Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, false); } catch (Exception e) { e.printStackTrace(); } @@ -241,7 +241,7 @@ public class CsarUtilsTest extends BeConfDependentTest { .thenReturn(Either.right(ToscaError.GENERAL_ERROR)); try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, false, false); + Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, false); } catch (Exception e) { e.printStackTrace(); } @@ -361,7 +361,7 @@ public class CsarUtilsTest extends BeConfDependentTest { .thenReturn(Either.left(toscaTemplate)); try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true, true); + Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true); } catch (Exception e) { e.printStackTrace(); } @@ -412,7 +412,7 @@ public class CsarUtilsTest extends BeConfDependentTest { .thenReturn(Either.left(toscaTemplate)); try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true, true); + Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true); } catch (Exception e) { e.printStackTrace(); } @@ -466,7 +466,7 @@ public class CsarUtilsTest extends BeConfDependentTest { .thenReturn(Either.right(CassandraOperationStatus.GENERAL_ERROR)); try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true, true); + Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true); } catch (Exception e) { e.printStackTrace(); } @@ -525,7 +525,7 @@ public class CsarUtilsTest extends BeConfDependentTest { .thenReturn(Either.left(schemaList)); try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true, true); + Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true); } catch (Exception e) { e.printStackTrace(); } @@ -587,7 +587,7 @@ public class CsarUtilsTest extends BeConfDependentTest { Mockito.any(Boolean.class))).thenReturn(new User()); try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true, true); + Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true); } catch (Exception e) { e.printStackTrace(); } @@ -697,11 +697,11 @@ public class CsarUtilsTest extends BeConfDependentTest { ToscaRepresentation tosca = new ToscaRepresentation(); tosca.setMainYaml("value"); - Mockito.when(toscaExportUtils.exportComponentInterface(Mockito.any(Component.class))) + Mockito.when(toscaExportUtils.exportComponentInterface(Mockito.any(Component.class), Mockito.any(Boolean.class))) .thenReturn(Either.left(tosca)); try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "writeComponentInterface", new Resource(), zip, fileName); + Deencapsulation.invoke(testSubject, "writeComponentInterface", new Resource(), zip, fileName, false); } catch (IOException e) { e.printStackTrace(); } @@ -871,174 +871,6 @@ public class CsarUtilsTest extends BeConfDependentTest { } @Test - public void testWriteAllFilesToCsarWhenWriteOperationsArtifactsToCsarIsRight() { - Component component = new Resource(); - Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>(); - ArtifactDefinition artifact = new ArtifactDefinition(); - artifact.setArtifactName("artifactName"); - artifact.setEsId("esId"); - artifact.setArtifactUUID("artifactUUID"); - artifact.setArtifactType("YANG"); - toscaArtifacts.put("assettoscatemplate", artifact); - - component.setToscaArtifacts(toscaArtifacts); - component.setDeploymentArtifacts(toscaArtifacts); - component.setArtifacts(toscaArtifacts); - Map<String, InterfaceDefinition> interfaces = new HashMap<>(); - InterfaceDefinition interfaceDef = new InterfaceDefinition(); - Map<String, OperationDataDefinition> operations = new HashMap<>(); - OperationDataDefinition operation = new OperationDataDefinition(); - ArtifactDataDefinition implementation = new ArtifactDataDefinition(); - implementation.setArtifactUUID("artifactUUID"); - implementation.setArtifactName("artifactName"); - operation.setImplementation(implementation); - operations.put("key", operation); - interfaceDef.setOperations(operations); - interfaces.put("key", interfaceDef); - ((Resource) component).setInterfaces(interfaces); - - ESArtifactData artifactData = new ESArtifactData(); - byte[] data = "value".getBytes(); - artifactData.setDataAsArray(data); - - ToscaTemplate toscaTemplate = new ToscaTemplate("version"); - List<Triple<String, String, Component>> dependencies = new ArrayList<>(); - toscaTemplate.setDependencies(dependencies); - - List<SdcSchemaFilesData> filesData = new ArrayList<>(); - SdcSchemaFilesData filedata = new SdcSchemaFilesData(); - filedata.setPayloadAsArray(data); - filesData.add(filedata); - - Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData), - Either.right(CassandraOperationStatus.GENERAL_ERROR)); - - Mockito.when(componentsUtils.convertFromStorageResponse(Mockito.any(StorageOperationStatus.class))) - .thenReturn(ActionStatus.GENERAL_ERROR); - - Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class))) - .thenReturn(Either.left(toscaTemplate)); - - Mockito.when( - sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(Mockito.any(String.class), Mockito.any(String.class))) - .thenReturn(Either.left(filesData)); - - testSubject.createCsar(component, false, true); - } - - @Test - public void testWriteOperationsArtifactsToCsarWhenComponentIsService() { - Component component = new Service(); - - try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "writeOperationsArtifactsToCsar", component, zip); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testWriteOperationsArtifactsToCsarWhenOperationGetImplementaionIsNull() { - Component component = new Resource(); - Map<String, InterfaceDefinition> interfaces = new HashMap<>(); - InterfaceDefinition interfaceDef = new InterfaceDefinition(); - Map<String, OperationDataDefinition> operations = new HashMap<>(); - operations.put("key", new OperationDataDefinition()); - interfaceDef.setOperations(operations); - interfaces.put("key", interfaceDef); - - ((Resource) component).setInterfaces(interfaces); - - try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "writeOperationsArtifactsToCsar", component, zip); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testWriteOperationsArtifactsToCsarWhenOperationGetArtifactNameIsNull() { - Component component = new Resource(); - - Map<String, InterfaceDefinition> interfaces = new HashMap<>(); - InterfaceDefinition interfaceDef = new InterfaceDefinition(); - Map<String, OperationDataDefinition> operations = new HashMap<>(); - OperationDataDefinition operation = new OperationDataDefinition(); - ArtifactDataDefinition implementation = new ArtifactDataDefinition(); - operation.setImplementation(implementation); - operations.put("key", operation); - interfaceDef.setOperations(operations); - interfaces.put("key", interfaceDef); - ((Resource) component).setInterfaces(interfaces); - - try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "writeOperationsArtifactsToCsar", component, zip); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testWriteOperationsArtifactsToCsarWhenGettingArtifactFromCassandra() { - Component component = new Resource(); - - Map<String, InterfaceDefinition> interfaces = new HashMap<>(); - InterfaceDefinition interfaceDef = new InterfaceDefinition(); - Map<String, OperationDataDefinition> operations = new HashMap<>(); - OperationDataDefinition operation = new OperationDataDefinition(); - ArtifactDataDefinition implementation = new ArtifactDataDefinition(); - implementation.setArtifactName("artifactName"); - implementation.setArtifactUUID("artifactUUID"); - operation.setImplementation(implementation); - operations.put("key", operation); - interfaceDef.setOperations(operations); - interfaceDef.setToscaResourceName("toscaResourceName"); - interfaces.put("key", interfaceDef); - ((Resource) component).setInterfaces(interfaces); - component.setNormalizedName("normalizedName"); - - ESArtifactData data = new ESArtifactData(); - data.setDataAsArray("data".getBytes()); - - Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(data)); - - try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "writeOperationsArtifactsToCsar", component, zip); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testWriteOperationsArtifactsToCsarWhenNullPointerExceptionIsCaught() { - Component component = new Resource(); - - Map<String, InterfaceDefinition> interfaces = new HashMap<>(); - InterfaceDefinition interfaceDef = new InterfaceDefinition(); - Map<String, OperationDataDefinition> operations = new HashMap<>(); - OperationDataDefinition operation = new OperationDataDefinition(); - ArtifactDataDefinition implementation = new ArtifactDataDefinition(); - implementation.setArtifactName("artifactName"); - implementation.setArtifactUUID("artifactUUID"); - operation.setImplementation(implementation); - operations.put("key", operation); - interfaceDef.setOperations(operations); - interfaceDef.setToscaResourceName("toscaResourceName"); - interfaces.put("key", interfaceDef); - ((Resource) component).setInterfaces(interfaces); - component.setNormalizedName("normalizedName"); - - Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))) - .thenReturn(Either.left(new ESArtifactData())); - - try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "writeOperationsArtifactsToCsar", component, zip); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test public void testWriteArtifactDefinition() { Component component = new Service(); List<ArtifactDefinition> artifactDefinitionList = new ArrayList<>(); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java index 49599777c3..2fabe43733 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java @@ -162,14 +162,14 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { Mockito.when(dataTypeCache.getAll()).thenReturn(Either.right(TitanOperationStatus.NOT_FOUND)); // default test when convertInterfaceNodeType is right - result = testSubject.exportComponentInterface(component); + result = testSubject.exportComponentInterface(component, false); Mockito.when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); Mockito.when(capabiltyRequirementConvertor.convertRequirements(Mockito.any(Map.class),Mockito.any(Resource.class), Mockito.any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); // default test when convertInterfaceNodeType is left - result = testSubject.exportComponentInterface(component); + result = testSubject.exportComponentInterface(component, false); } @@ -397,7 +397,8 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { Mockito.any(ToscaNodeType.class))).thenReturn(Either.left(new ToscaNodeType())); // default test - result = Deencapsulation.invoke(testSubject, "convertInterfaceNodeType",new HashMap<>(), component, toscaNode, nodeTypes); + result = Deencapsulation.invoke(testSubject, "convertInterfaceNodeType",new HashMap<>(), component, toscaNode + , nodeTypes, false); } @Ignore("need to fix change in injected class.") @Test diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java index 7a88d0a9d3..ac53a6d930 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java @@ -114,7 +114,7 @@ public class InterfacesOperationsToscaUtilTest { component.setInterfaces(new HashMap<>()); component.getInterfaces().put(interfaceType, addedInterface); ToscaNodeType nodeType = new ToscaNodeType(); - InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType); + InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType, false); ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null); ToscaTemplate template = new ToscaTemplate(NODE_TYPE_NAME); @@ -146,7 +146,7 @@ public class InterfacesOperationsToscaUtilTest { component.setInterfaces(new HashMap<>()); component.getInterfaces().put(interfaceType, addedInterface); ToscaNodeType nodeType = new ToscaNodeType(); - InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType); + InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType, true); ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null); ToscaTemplate template = new ToscaTemplate("testService"); @@ -177,7 +177,7 @@ public class InterfacesOperationsToscaUtilTest { component.setInterfaces(new HashMap<>()); component.getInterfaces().put(interfaceType, addedInterface); ToscaNodeType nodeType = new ToscaNodeType(); - InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType); + InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType, false); ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null); ToscaTemplate template = new ToscaTemplate("test"); 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 66983d7d3a..99988224c8 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 @@ -15,19 +15,30 @@ */ package org.openecomp.sdc.be.tosca.utils; +import static org.junit.Assert.assertEquals; +import static org.openecomp.sdc.be.tosca.utils.OperationArtifactUtil.BPMN_ARTIFACT_PATH; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.lang.WordUtils; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.openecomp.sdc.be.DummyConfigurationManager; +import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; +import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.ComponentMetadataDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Resource; - -import java.io.File; -import java.util.HashMap; - -import static org.junit.Assert.assertEquals; +import org.openecomp.sdc.be.tosca.CsarUtils; +import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; +import org.openecomp.sdc.common.api.ArtifactTypeEnum; public class OperationArtifactUtilTest { @@ -38,25 +49,92 @@ public class OperationArtifactUtilTest { @Test public void testCorrectPathForOperationArtifacts() { - Component component = new Resource(); - component.setNormalizedName("normalizedComponentName"); - final InterfaceDefinition addedInterface = new InterfaceDefinition(); + 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, op, false); + String expectedArtifactPath = CsarUtils.ARTIFACTS + File.separator + + WordUtils.capitalizeFully(ArtifactGroupTypeEnum.DEPLOYMENT.name()) + File.separator + + ArtifactTypeEnum.WORKFLOW.name() + File.separator + BPMN_ARTIFACT_PATH + File.separator + + "createBPMN.bpmn"; + + + assertEquals(expectedArtifactPath,actualArtifactPath); + } + + @Test + public void testCorrectPathForOperationArtifactsInService() { + ResourceMetadataDataDefinition componentMetadataDataDefinition = new ResourceMetadataDataDefinition(); + componentMetadataDataDefinition.setToscaResourceName("org.openecomp.resource.vf.TestResource"); + final ComponentMetadataDefinition componentMetadataDefinition = + new ComponentMetadataDefinition(componentMetadataDataDefinition); + Component component = new Resource(componentMetadataDefinition); + component.setVersion("1.0"); final OperationDataDefinition op = new OperationDataDefinition(); final ArtifactDataDefinition implementation = new ArtifactDataDefinition(); implementation.setArtifactName("createBPMN.bpmn"); op.setImplementation(implementation); + final String actualArtifactPath = OperationArtifactUtil.createOperationArtifactPath(component, op, true); + String expectedArtifactPath = CsarUtils.ARTIFACTS + File.separator + + "org.openecomp.resource.vf.TestResource_v1.0" + File.separator + + WordUtils.capitalizeFully(ArtifactGroupTypeEnum.DEPLOYMENT.name()) + File.separator + + ArtifactTypeEnum.WORKFLOW.name() + + File.separator + BPMN_ARTIFACT_PATH + File.separator + "createBPMN.bpmn"; + + + assertEquals(expectedArtifactPath,actualArtifactPath); + } + + @Test + public void testGetDistinctInterfaceOperationArtifactsByName() { + Component component = new Resource(); + component.setNormalizedName("normalizedComponentName"); + final InterfaceDefinition addedInterface = new InterfaceDefinition(); + OperationDataDefinition op1 = createInterfaceOperation("createBPMN.bpmn"); + OperationDataDefinition op2 = createInterfaceOperation("createBPMN.bpmn"); addedInterface.setOperations(new HashMap<>()); - addedInterface.getOperations().put("create", op); + addedInterface.getOperations().put("create", op1); + addedInterface.getOperations().put("update", op2); final String interfaceType = "normalizedComponentName-interface"; - ((Resource) component).setInterfaces(new HashMap<>()); - ((Resource) component).getInterfaces().put(interfaceType, addedInterface); - final String actualArtifactPath = OperationArtifactUtil.createOperationArtifactPath(component.getNormalizedName(), interfaceType, op); - String expectedArtifactPath ="Artifacts"+ File.separator+"normalizedComponentName"+File.separator - +"normalizedComponentName-interface"+File.separator+"Deployment" - +File.separator+"Workflows"+File.separator+"BPMN" - +File.separator+"createBPMN.bpmn"; + component.setInterfaces(new HashMap<>()); + component.getInterfaces().put(interfaceType, addedInterface); + Map<String, ArtifactDefinition> distinctInterfaceOperationArtifactsByName = + OperationArtifactUtil.getDistinctInterfaceOperationArtifactsByName(component); + Assert.assertEquals(1, distinctInterfaceOperationArtifactsByName.size()); + } - assertEquals(expectedArtifactPath,actualArtifactPath); + @Test + public void testGetDistinctInterfaceOperationArtifactsByNameAllDistinct() { + Component component = new Resource(); + component.setNormalizedName("normalizedComponentName"); + final InterfaceDefinition addedInterface = new InterfaceDefinition(); + OperationDataDefinition op1 = createInterfaceOperation("createBPMN.bpmn"); + OperationDataDefinition op2 = createInterfaceOperation("updateBPMN.bpmn"); + addedInterface.setOperations(new HashMap<>()); + addedInterface.getOperations().put("create", op1); + addedInterface.getOperations().put("update", op2); + final String interfaceType = "normalizedComponentName-interface"; + component.setInterfaces(new HashMap<>()); + component.getInterfaces().put(interfaceType, addedInterface); + + Map<String, ArtifactDefinition> distinctInterfaceOperationArtifactsByName = + OperationArtifactUtil.getDistinctInterfaceOperationArtifactsByName(component); + Assert.assertEquals(2, distinctInterfaceOperationArtifactsByName.size()); + } + + private OperationDataDefinition createInterfaceOperation(String artifactName) { + final OperationDataDefinition op = new OperationDataDefinition(); + final ArtifactDataDefinition implementation = new ArtifactDataDefinition(); + implementation.setUniqueId(UUID.randomUUID().toString()); + implementation.setArtifactName(artifactName); + op.setImplementation(implementation); + return op; } }
\ No newline at end of file |