class CsarUtilsTest extends BaseConfDependent {
@InjectMocks
- CsarUtils testSubject;
+ private CsarUtils testSubject;
+
+ @InjectMocks
+ private CommonCsarGenerator commonCsarGenerator;
@Mock
private ArtifactCassandraDao artifactCassandraDao;
private final byte[] contentData;
- public CsarUtilsTest() throws IOException {
+ public CsarUtilsTest() throws IOException {
contentData = getFileResource("yamlValidation/resource-serviceTemplate.yml");
}
}
@Test
- void testCreateCsar() {
+ void testCreateCsar() throws IOException {
Component component = new Resource();
Map<String, ArtifactDefinition> artifactDefinitionHashMap = new HashMap<>();
ArtifactDefinition artifact = new ArtifactDefinition();
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<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
ArtifactDefinition artifact = new ArtifactDefinition();
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)))
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
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
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
.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();
}
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
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
.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();
}
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<CacheEntry> expected = io.vavr.collection.List.of(entry("esId","artifactName",componentRI));
assertEquals(expected, componentCache.all().toList());
try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out)) {
- List<Triple<String, String, Component>> output = Deencapsulation.invoke(testSubject, "writeComponentInterface", new Resource(), zip, fileName);
+ List<Triple<String, String, Component>> output = Deencapsulation.invoke(commonCsarGenerator, "writeComponentInterface", new Resource(),
+ zip, fileName, "Definitions/");
assertNotNull(output);
}
}
Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class)))
.thenReturn(Either.right(CassandraOperationStatus.GENERAL_ERROR));
- Either<byte[], ActionStatus> output = Deencapsulation.invoke(testSubject, "getEntryData", cassandraId, childComponent);
+ Either<byte[], ActionStatus> output = Deencapsulation.invoke(commonCsarGenerator, "getEntryData", cassandraId, childComponent);
assertNotNull(output);
assertTrue(output.isRight());
sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(Mockito.any(String.class), Mockito.any(String.class)))
.thenReturn(Either.left(filesData));
- Either<byte[], ResponseFormat> output = Deencapsulation.invoke(testSubject, "getLatestSchemaFilesFromCassandra");
+ Either<byte[], ResponseFormat> output = Deencapsulation.invoke(commonCsarGenerator, "getLatestSchemaFilesFromCassandra");
assertNotNull(output);
assertTrue(output.isRight());
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<>());
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());
}
final Triple<String, String, Component> triple = Triple.of("fileName", "cassandraId", component);
dependencies.add(triple);
final List<String> expectedResult = Arrays.asList("tosca.nodes.Container.Application");
- final List<String> result = Deencapsulation.invoke(testSubject,
+ final List<String> result = Deencapsulation.invoke(commonCsarGenerator,
"findNonRootNodesFromPackage", dependencies);
assertTrue(CollectionUtils.isNotEmpty(result));
assertEquals(expectedResult, result);