From 28e1a54e6074f50dcc06f7ea4eb3943ad873b448 Mon Sep 17 00:00:00 2001 From: vasraz Date: Fri, 1 Sep 2023 14:31:28 +0100 Subject: Create plugin point for csar generation Issue-ID: SDC-4578 Signed-off-by: franciscovila Change-Id: I3bb280ce4e442780598464216145abc130765539 Signed-off-by: Vasyl Razinkov --- .../org/openecomp/sdc/be/tosca/CsarUtilsTest.java | 164 ++++++--------------- .../sdc/be/tosca/ToscaExportHandlerTest.java | 12 +- 2 files changed, 54 insertions(+), 122 deletions(-) (limited to 'catalog-be/src/test') 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 373e9b1c89..b749ef68fd 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 @@ -100,7 +100,10 @@ import org.openecomp.sdc.exception.ResponseFormat; class CsarUtilsTest extends BaseConfDependent { @InjectMocks - CsarUtils testSubject; + private CsarUtils testSubject; + + @InjectMocks + private CommonCsarGenerator commonCsarGenerator; @Mock private ArtifactCassandraDao artifactCassandraDao; @@ -124,7 +127,7 @@ class CsarUtilsTest extends BaseConfDependent { private final byte[] contentData; - public CsarUtilsTest() throws IOException { + public CsarUtilsTest() throws IOException { contentData = getFileResource("yamlValidation/resource-serviceTemplate.yml"); } @@ -158,7 +161,7 @@ class CsarUtilsTest extends BaseConfDependent { } @Test - void testCreateCsar() { + void testCreateCsar() throws IOException { Component component = new Resource(); Map artifactDefinitionHashMap = new HashMap<>(); ArtifactDefinition artifact = new ArtifactDefinition(); @@ -170,17 +173,22 @@ class CsarUtilsTest extends BaseConfDependent { component.setArtifacts(artifactDefinitionHashMap); component.setDeploymentArtifacts(artifactDefinitionHashMap); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ZipOutputStream zip = new ZipOutputStream(out); + Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))) .thenReturn(Either.right(CassandraOperationStatus.GENERAL_ERROR)); Mockito.when(componentsUtils.convertFromStorageResponse(Mockito.any(StorageOperationStatus.class))) .thenReturn(ActionStatus.GENERAL_ERROR); - testSubject.createCsar(component, true, true); + assertNotNull(commonCsarGenerator.generateCsarZip(component, false, zip, + false, true, + "Definitions/", true, false).right()); } @Test - void testCreateCsarWithGenerateCsarZipResponseIsLeft() { + void testCreateCsarWithGenerateCsarZipResponseIsLeft() throws IOException { Component component = new Resource(); Map toscaArtifacts = new HashMap<>(); ArtifactDefinition artifact = new ArtifactDefinition(); @@ -207,6 +215,9 @@ class CsarUtilsTest extends BaseConfDependent { filedata.setPayloadAsArray(data); filesData.add(filedata); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ZipOutputStream zip = new ZipOutputStream(out); + Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData)); Mockito.when(componentsUtils.convertFromStorageResponse(Mockito.any(StorageOperationStatus.class))) @@ -219,7 +230,9 @@ class CsarUtilsTest extends BaseConfDependent { sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(Mockito.any(String.class), Mockito.any(String.class))) .thenReturn(Either.left(filesData)); - testSubject.createCsar(component, false, true); + assertNotNull(commonCsarGenerator.generateCsarZip(component, false, zip, + false, true, + "Definitions/", true, false).right()); } @Test @@ -253,11 +266,11 @@ class CsarUtilsTest extends BaseConfDependent { Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class))) .thenReturn(Either.right(ToscaError.GENERAL_ERROR)); - try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, false); - } catch (Exception e) { - e.printStackTrace(); - } + try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { + Deencapsulation.invoke(commonCsarGenerator, "generateCsarZip", component, getFromCS, zip, true, true, "Definitions/", true, false); + } catch (Exception e) { + e.printStackTrace(); + } } @Test @@ -285,11 +298,11 @@ class CsarUtilsTest extends BaseConfDependent { Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class))) .thenReturn(Either.right(ToscaError.GENERAL_ERROR)); - try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, false); - } catch (Exception e) { - e.printStackTrace(); - } + try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { + Deencapsulation.invoke(commonCsarGenerator, "generateCsarZip", component, getFromCS, zip, true, true, "Definitions/", true, false); + } catch (Exception e) { + e.printStackTrace(); + } } @Test @@ -357,7 +370,7 @@ class CsarUtilsTest extends BaseConfDependent { .thenReturn(Either.left(Mockito.any(ArtifactDefinition.class))); try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true); + Deencapsulation.invoke(commonCsarGenerator, "generateCsarZip", component, getFromCS, zip, true, true, "/Definitions", true, false); } catch (Exception e) { e.printStackTrace(); } @@ -405,11 +418,11 @@ class CsarUtilsTest extends BaseConfDependent { Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class))) .thenReturn(Either.left(toscaTemplate)); - try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true); - } catch (Exception e) { - e.printStackTrace(); - } + try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { + Deencapsulation.invoke(commonCsarGenerator, "generateCsarZip", component, getFromCS, zip, true, true, "Definitions/", true, false); + } catch (Exception e) { + e.printStackTrace(); + } } @Test @@ -455,11 +468,11 @@ class CsarUtilsTest extends BaseConfDependent { Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class))) .thenReturn(Either.left(toscaTemplate)); - try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true); - } catch (Exception e) { - e.printStackTrace(); - } + try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { + Deencapsulation.invoke(commonCsarGenerator, "generateCsarZip", component, getFromCS, zip, true, true, "Definitions/", true, false); + } catch (Exception e) { + e.printStackTrace(); + } } @Test @@ -509,7 +522,7 @@ class CsarUtilsTest extends BaseConfDependent { .thenReturn(Either.right(CassandraOperationStatus.GENERAL_ERROR)); try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) { - Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true); + Deencapsulation.invoke(commonCsarGenerator, "generateCsarZip", component, getFromCS, zip, true, "toscaMetaFileName", true, "Definitions/", true, false); } catch (Exception e) { e.printStackTrace(); } @@ -542,7 +555,7 @@ class CsarUtilsTest extends BaseConfDependent { Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class))) .thenReturn(Either.left(componentRI)); - Deencapsulation.invoke(testSubject, "addInnerComponentsToCache", componentCache, childComponent); + Deencapsulation.invoke(commonCsarGenerator, "addInnerComponentsToCache", componentCache, childComponent); io.vavr.collection.List expected = io.vavr.collection.List.of(entry("esId","artifactName",componentRI)); assertEquals(expected, componentCache.all().toList()); @@ -591,7 +604,8 @@ class CsarUtilsTest extends BaseConfDependent { try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out)) { - List> output = Deencapsulation.invoke(testSubject, "writeComponentInterface", new Resource(), zip, fileName); + List> output = Deencapsulation.invoke(commonCsarGenerator, "writeComponentInterface", new Resource(), + zip, fileName, "Definitions/"); assertNotNull(output); } } @@ -604,7 +618,7 @@ class CsarUtilsTest extends BaseConfDependent { Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))) .thenReturn(Either.right(CassandraOperationStatus.GENERAL_ERROR)); - Either output = Deencapsulation.invoke(testSubject, "getEntryData", cassandraId, childComponent); + Either output = Deencapsulation.invoke(commonCsarGenerator, "getEntryData", cassandraId, childComponent); assertNotNull(output); assertTrue(output.isRight()); @@ -618,7 +632,7 @@ class CsarUtilsTest extends BaseConfDependent { sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(Mockito.any(String.class), Mockito.any(String.class))) .thenReturn(Either.left(filesData)); - Either output = Deencapsulation.invoke(testSubject, "getLatestSchemaFilesFromCassandra"); + Either output = Deencapsulation.invoke(commonCsarGenerator, "getLatestSchemaFilesFromCassandra"); assertNotNull(output); assertTrue(output.isRight()); @@ -703,88 +717,6 @@ class CsarUtilsTest extends BaseConfDependent { assertFalse(output.right().value()); } - @Test - void testNonMetaArtifactInfoCtor() { - createNonMetaArtifactInfoTestSubject(); - } - - @Test - void testNonMetaArtifactInfoGetPath() { - NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject(); - - testSubject.getPath(); - } - - @Test - void testNonMetaArtifactInfoGetArtifactName() { - NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject(); - - testSubject.getArtifactName(); - } - - @Test - void testNonMetaArtifactInfoGetArtifactType() { - final NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject(); - assertThat("The artifact type should be as expected", - testSubject.getArtifactType(), is(ArtifactTypeEnum.AAI_SERVICE_MODEL.getType())); - } - - @Test - void testNonMetaArtifactInfoGetDisplayName() { - NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject(); - - testSubject.getDisplayName(); - } - - @Test - void testNonMetaArtifactInfoGetArtifactGroupType() { - NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject(); - - testSubject.getArtifactGroupType(); - } - - @Test - void testNonMetaArtifactInfoGetArtifactLabel() { - NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject(); - - testSubject.getArtifactLabel(); - } - - @Test - void testNonMetaArtifactInfoGetIsFromCsar() { - NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject(); - - testSubject.isFromCsar(); - } - - @Test - void testNonMetaArtifactInfoGetPayloadData() { - NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject(); - - testSubject.getPayloadData(); - } - - @Test - void testNonMetaArtifactInfoGetArtifaactChecksum() { - NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject(); - - testSubject.getArtifactChecksum(); - } - - @Test - void testNonMetaArtifactInfoGetArtifactUniqueId() { - NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject(); - - testSubject.getArtifactUniqueId(); - } - - @Test - void testNonMetaArtifactInfosetArtifactUniqueId() { - NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject(); - - testSubject.setArtifactUniqueId("artifactUniqueId"); - } - @Test void testValidateNonMetaArtifactWithExceptionCaught() { CsarUtils.validateNonMetaArtifact("", new byte[0], new HashMap<>()); @@ -950,7 +882,7 @@ class CsarUtilsTest extends BaseConfDependent { final Path path = Paths.get(rootPath + "/src/test/resources/sdc.zip"); final byte[] data = Files.readAllBytes(path); try (final ByteArrayOutputStream out = new ByteArrayOutputStream(); final ZipOutputStream zip = new ZipOutputStream(out)) { - Deencapsulation.invoke(testSubject, "addSchemaFilesFromCassandra", zip, data, nodesFromPackage); + Deencapsulation.invoke(commonCsarGenerator, "addSchemaFilesFromCassandra", zip, data, nodesFromPackage, "Definitions/"); final IOException actualException = assertThrows(IOException.class, () -> zip.putNextEntry(new ZipEntry("Definitions/nodes.yml"))); assertEquals("duplicate entry: Definitions/nodes.yml", actualException.getMessage()); } @@ -965,7 +897,7 @@ class CsarUtilsTest extends BaseConfDependent { final Triple triple = Triple.of("fileName", "cassandraId", component); dependencies.add(triple); final List expectedResult = Arrays.asList("tosca.nodes.Container.Application"); - final List result = Deencapsulation.invoke(testSubject, + final List result = Deencapsulation.invoke(commonCsarGenerator, "findNonRootNodesFromPackage", dependencies); assertTrue(CollectionUtils.isNotEmpty(result)); assertEquals(expectedResult, result); 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 4f267138d7..0b3796261a 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 @@ -386,7 +386,7 @@ class ToscaExportHandlerTest extends BaseConfDependent { when(toscaOperationFacade.getToscaFullElement("name")).thenReturn(Either.left(resource)); Either>, ToscaError> result; - result = Deencapsulation.invoke(testSubject, "fillImports", resource, toscaTemplate); + result = Deencapsulation.invoke(testSubject, "fillImports", resource, toscaTemplate, false); verify(toscaOperationFacade, times(1)).getToscaFullElement("name"); assertTrue(result.isLeft()); @@ -421,7 +421,7 @@ class ToscaExportHandlerTest extends BaseConfDependent { doReturn(map).when(outputConverter).convert(any(), any()); // default test - result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode); + result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode, false); assertNotNull(result); } @@ -471,7 +471,7 @@ class ToscaExportHandlerTest extends BaseConfDependent { doReturn(map).when(outputConverter).convert(any(), any()); // test component contains group - final var result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode); + final var result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode, false); assertNotNull(result); } @@ -510,7 +510,7 @@ class ToscaExportHandlerTest extends BaseConfDependent { doReturn(map).when(outputConverter).convert(any(), any()); // test component contains group - result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode); + result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode, false); assertNotNull(result); } @@ -561,7 +561,7 @@ class ToscaExportHandlerTest extends BaseConfDependent { when(toscaOperationFacade.getByToscaResourceNameAndVersion("org.typeA", "1.0", null)).thenReturn(Either.left(baseType)); // default test - result = Deencapsulation.invoke(testSubject, "fillImports", component, toscaTemplate); + result = Deencapsulation.invoke(testSubject, "fillImports", component, toscaTemplate, false); assertNotNull(result); } @@ -588,7 +588,7 @@ class ToscaExportHandlerTest extends BaseConfDependent { when(toscaOperationFacade.getToscaFullElement("modelName")).thenReturn(Either.left(new Service())); // default test - Deencapsulation.invoke(testSubject, "createDependency", componentCache, imports, dependecies, ci); + Deencapsulation.invoke(testSubject, "createDependency", componentCache, imports, dependecies, ci, false); assertFalse(componentCache.isEmpty()); } -- cgit 1.2.3-korg