aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2023-10-19 09:18:55 +0100
committerJvD_Ericsson <jeff.van.dam@est.tech>2023-10-26 13:13:15 +0100
commit5d7ca5c1e86d7633a1954ae89334df18d264f82b (patch)
tree67637eb436ceac8c98d27ad9a4b154e0c65e8470 /catalog-be/src/test/java
parent6b58f89d940d56bfda38b5f86ef5a86ee29f80cf (diff)
Improve test coverage
- Added some tests to - ToscaExportHandlerTest.java - ToscaExportHandlerTest.java - Removed unused code Issue-ID: SDC-4654 Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech> Change-Id: Iee23e3a148005e960eb9c986b7b0605e4f7c8337
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java1481
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java74
2 files changed, 807 insertions, 748 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 b749ef68fd..2fc1e82827 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
@@ -20,8 +20,6 @@
package org.openecomp.sdc.be.tosca;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -90,7 +88,6 @@ import org.openecomp.sdc.be.tosca.ComponentCache.CacheEntry;
import org.openecomp.sdc.be.tosca.CsarUtils.NonMetaArtifactInfo;
import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
-import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.api.ConfigurationSource;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
@@ -99,809 +96,797 @@ import org.openecomp.sdc.exception.ResponseFormat;
class CsarUtilsTest extends BaseConfDependent {
- @InjectMocks
- private CsarUtils testSubject;
-
+ private final List<String> nodesFromPackage = Arrays.asList("tosca.nodes.Root", "tosca.nodes.Container.Application");
+ private final byte[] contentData;
@InjectMocks
- private CommonCsarGenerator commonCsarGenerator;
-
- @Mock
- private ArtifactCassandraDao artifactCassandraDao;
-
- @Mock
- private ComponentsUtils componentsUtils;
-
- @Mock
- private ToscaExportHandler toscaExportUtils;
+ private CsarUtils testSubject;
+ @InjectMocks
+ private CommonCsarGenerator commonCsarGenerator;
+ @Mock
+ private ArtifactCassandraDao artifactCassandraDao;
+ @Mock
+ private ComponentsUtils componentsUtils;
+ @Mock
+ private ToscaExportHandler toscaExportUtils;
+ @Mock
+ private SdcSchemaFilesCassandraDao sdcSchemaFilesCassandraDao;
+ @Mock
+ private ToscaOperationFacade toscaOperationFacade;
+ @Mock
+ private ArtifactsBusinessLogic artifactsBusinessLogic;
- @Mock
- private SdcSchemaFilesCassandraDao sdcSchemaFilesCassandraDao;
+ public CsarUtilsTest() throws IOException {
+ contentData = getFileResource("yamlValidation/resource-serviceTemplate.yml");
+ }
- @Mock
- private ToscaOperationFacade toscaOperationFacade;
+ @BeforeAll
+ public static void setupBeforeClass() {
+ componentName = "catalog-be";
+ confPath = "src/test/resources/config";
+ setUp();
+ }
- @Mock
- private ArtifactsBusinessLogic artifactsBusinessLogic;
+ private static void initConfigurationManager() {
+ final String confPath = new File(Objects
+ .requireNonNull(
+ CsarUtilsTest.class.getClassLoader().getResource("config/catalog-be/configuration.yaml"))
+ .getFile()).getParent();
+ final ConfigurationSource confSource =
+ new FSConfigurationSource(ExternalConfiguration.getChangeListener(), confPath);
+ new ConfigurationManager(confSource);
+ }
- private final List<String> nodesFromPackage = Arrays.asList("tosca.nodes.Root", "tosca.nodes.Container.Application");
+ @BeforeEach
+ public void setUpMock() {
+ ExternalConfiguration.setAppName("catalog-be");
+ MockitoAnnotations.openMocks(this);
+ initConfigurationManager();
+ }
- private final byte[] contentData;
+ @Test
+ void testCreateCsar() throws IOException {
+ Component component = new Resource();
+ Map<String, ArtifactDefinition> artifactDefinitionHashMap = new HashMap<>();
+ ArtifactDefinition artifact = new ArtifactDefinition();
+ artifact.setArtifactName("artifactName");
+ artifact.setEsId("esId");
+ artifactDefinitionHashMap.put("assettoscatemplate", artifact);
- public CsarUtilsTest() throws IOException {
- contentData = getFileResource("yamlValidation/resource-serviceTemplate.yml");
- }
-
- @BeforeAll
- public static void setupBeforeClass() {
- componentName = "catalog-be";
- confPath = "src/test/resources/config";
- setUp();
- }
-
- @BeforeEach
- public void setUpMock() {
- ExternalConfiguration.setAppName("catalog-be");
- MockitoAnnotations.openMocks(this);
- initConfigurationManager();
- }
-
- private static void initConfigurationManager() {
- final String confPath = new File(Objects
- .requireNonNull(
- CsarUtilsTest.class.getClassLoader().getResource("config/catalog-be/configuration.yaml"))
- .getFile()).getParent();
- final ConfigurationSource confSource =
- new FSConfigurationSource(ExternalConfiguration.getChangeListener(), confPath);
- new ConfigurationManager(confSource);
- }
-
- private NonMetaArtifactInfo createNonMetaArtifactInfoTestSubject() {
- return new CsarUtils.NonMetaArtifactInfo("mock", "mock", ArtifactTypeEnum.AAI_SERVICE_MODEL.getType(),
- ArtifactGroupTypeEnum.DEPLOYMENT, new byte[0], "mock", true);
- }
-
- @Test
- void testCreateCsar() throws IOException {
- Component component = new Resource();
- Map<String, ArtifactDefinition> artifactDefinitionHashMap = new HashMap<>();
- ArtifactDefinition artifact = new ArtifactDefinition();
- artifact.setArtifactName("artifactName");
- artifact.setEsId("esId");
- artifactDefinitionHashMap.put("assettoscatemplate", artifact);
-
- component.setToscaArtifacts(artifactDefinitionHashMap);
- component.setArtifacts(artifactDefinitionHashMap);
- component.setDeploymentArtifacts(artifactDefinitionHashMap);
+ component.setToscaArtifacts(artifactDefinitionHashMap);
+ 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(artifactCassandraDao.getArtifact(Mockito.any(String.class)))
+ .thenReturn(Either.right(CassandraOperationStatus.GENERAL_ERROR));
- Mockito.when(componentsUtils.convertFromStorageResponse(Mockito.any(StorageOperationStatus.class)))
- .thenReturn(ActionStatus.GENERAL_ERROR);
+ Mockito.when(componentsUtils.convertFromStorageResponse(Mockito.any(StorageOperationStatus.class)))
+ .thenReturn(ActionStatus.GENERAL_ERROR);
assertNotNull(commonCsarGenerator.generateCsarZip(component, false, zip,
- false, true,
+ false, true,
"Definitions/", true, false).right());
- }
-
- @Test
- void testCreateCsarWithGenerateCsarZipResponseIsLeft() throws IOException {
- 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);
- DAOArtifactData artifactData = new DAOArtifactData();
- byte[] data = "value".getBytes();
- ByteBuffer bufferData = ByteBuffer.wrap(data);
- artifactData.setData(bufferData);
-
- 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);
+ }
+
+ @Test
+ void testCreateCsarWithGenerateCsarZipResponseIsLeft() throws IOException {
+ 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);
+ DAOArtifactData artifactData = new DAOArtifactData();
+ byte[] data = "value".getBytes();
+ ByteBuffer bufferData = ByteBuffer.wrap(data);
+ artifactData.setData(bufferData);
+
+ 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);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(out);
- Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
+ Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
- Mockito.when(componentsUtils.convertFromStorageResponse(Mockito.any(StorageOperationStatus.class)))
- .thenReturn(ActionStatus.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(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));
+ Mockito.when(
+ sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(Mockito.any(String.class), Mockito.any(String.class)))
+ .thenReturn(Either.left(filesData));
assertNotNull(commonCsarGenerator.generateCsarZip(component, false, zip,
false, true,
"Definitions/", true, false).right());
- }
+ }
- @Test
- void testPopulateZipWhenGetDependenciesIsRight() {
- Component component = new Service();
- boolean getFromCS = false;
+ @Test
+ void testPopulateZipWhenGetDependenciesIsRight() {
+ Component component = new Service();
+ boolean getFromCS = false;
- 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);
+ 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);
- component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- DAOArtifactData artifactData = new DAOArtifactData();
- byte[] data = "value".getBytes();
- ByteBuffer bufferData = ByteBuffer.wrap(data);
- artifactData.setData(bufferData);
+ component.setToscaArtifacts(toscaArtifacts);
+ component.setDeploymentArtifacts(toscaArtifacts);
+ component.setArtifacts(toscaArtifacts);
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ DAOArtifactData artifactData = new DAOArtifactData();
+ byte[] data = "value".getBytes();
+ ByteBuffer bufferData = ByteBuffer.wrap(data);
+ artifactData.setData(bufferData);
- ToscaRepresentation tosca = ToscaRepresentation.make("value".getBytes());
+ ToscaRepresentation tosca = ToscaRepresentation.make("value".getBytes());
- Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
+ Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
- Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class))).thenReturn(Either.left(tosca));
+ Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class))).thenReturn(Either.left(tosca));
- Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class)))
- .thenReturn(Either.right(ToscaError.GENERAL_ERROR));
+ 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(commonCsarGenerator, "generateCsarZip", component, getFromCS, zip, true, true, "Definitions/", true, false);
} catch (Exception e) {
e.printStackTrace();
}
- }
-
- @Test
- void testPopulateZipWhenExportComponentIsRight() {
- Component component = new Resource();
- boolean getFromCS = false;
-
- 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);
- component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- DAOArtifactData artifactData = new DAOArtifactData();
- byte[] data = "value".getBytes();
- ByteBuffer bufferData = ByteBuffer.wrap(data);
- artifactData.setData(bufferData);
-
- Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class)))
- .thenReturn(Either.right(ToscaError.GENERAL_ERROR));
+ }
+
+ @Test
+ void testPopulateZipWhenExportComponentIsRight() {
+ Component component = new Resource();
+ boolean getFromCS = false;
+
+ 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);
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ DAOArtifactData artifactData = new DAOArtifactData();
+ byte[] data = "value".getBytes();
+ ByteBuffer bufferData = ByteBuffer.wrap(data);
+ artifactData.setData(bufferData);
+
+ 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(commonCsarGenerator, "generateCsarZip", component, getFromCS, zip, true, true, "Definitions/", true, false);
} catch (Exception e) {
e.printStackTrace();
}
- }
-
- @Test
- void testPopulateZipWhenComponentIsServiceAndCollectComponentCsarDefinitionIsRight() {
- Component component = new Service();
- boolean getFromCS = false;
-
- Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
- ArtifactDefinition artifact = new ArtifactDefinition();
- artifact.setArtifactName("artifactName");
- artifact.setEsId("esId");
- artifact.setArtifactUUID("artifactUUID");
- artifact.setArtifactType("YANG");
- artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
- artifact.setDescription("description");
- artifact.setArtifactLabel("artifactLabel");
- toscaArtifacts.put("assettoscatemplate", artifact);
-
- component.setToscaArtifacts(toscaArtifacts);
- component.setDeploymentArtifacts(toscaArtifacts);
- component.setArtifacts(toscaArtifacts);
- component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- component.setVersion("1.0");
- component.setLastUpdaterUserId("userId");
- component.setUniqueId("uid");
- DAOArtifactData artifactData = new DAOArtifactData();
- ByteBuffer bufferData = ByteBuffer.wrap(contentData);
- artifactData.setData(bufferData);
-
- List<SdcSchemaFilesData> filesData = new ArrayList<>();
- SdcSchemaFilesData filedata = new SdcSchemaFilesData();
- filedata.setPayloadAsArray(contentData);
- filesData.add(filedata);
-
- ToscaTemplate toscaTemplate = new ToscaTemplate("version");
- List<Triple<String, String, Component>> dependencies = new ArrayList<>();
- Triple<String, String, Component> triple = Triple.of("fileName", "cassandraId", component);
- dependencies.add(triple);
- toscaTemplate.setDependencies(dependencies);
-
- ToscaRepresentation tosca = ToscaRepresentation.make("value".getBytes());
-
- Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
-
- Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class))).thenReturn(Either.left(tosca));
-
- 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));
-
- Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class)))
- .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
-
- Mockito.when(artifactsBusinessLogic.validateUserExists(Mockito.any(User.class))).thenReturn(new User());
-
-
- Mockito.when(artifactsBusinessLogic.validateAndHandleArtifact(Mockito.any(String.class),
- Mockito.any(ComponentTypeEnum.class), Mockito.any(ArtifactOperationInfo.class), Mockito.isNull(),
- Mockito.any(ArtifactDefinition.class), Mockito.any(String.class), Mockito.any(String.class),
- Mockito.isNull(), Mockito.isNull(), Mockito.any(User.class), Mockito.any(Component.class),
- Mockito.any(Boolean.class), Mockito.any(Boolean.class), Mockito.any(Boolean.class)))
- .thenReturn(Either.left(Mockito.any(ArtifactDefinition.class)));
-
- 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
- void testPopulateZipWhenGetEntryDataIsRight() {
- Component component = new Service();
- boolean getFromCS = true;
-
- Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
- ArtifactDefinition artifact = new ArtifactDefinition();
- artifact.setArtifactName("artifactName");
- artifact.setEsId("esId");
- artifact.setArtifactUUID("artifactUUID");
- artifact.setArtifactType("YANG");
- artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
- artifact.setDescription("description");
- artifact.setArtifactLabel("artifactLabel");
- toscaArtifacts.put("assettoscatemplate", artifact);
-
- component.setToscaArtifacts(toscaArtifacts);
- component.setDeploymentArtifacts(toscaArtifacts);
- component.setArtifacts(toscaArtifacts);
- component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- component.setVersion("1.0");
- component.setLastUpdaterUserId("userId");
- component.setUniqueId("uid");
- DAOArtifactData artifactData = new DAOArtifactData();
- byte[] data = "value".getBytes();
- ByteBuffer bufferData = ByteBuffer.wrap(data);
- artifactData.setData(bufferData);
-
- ToscaTemplate toscaTemplate = new ToscaTemplate("version");
- List<Triple<String, String, Component>> dependencies = new ArrayList<>();
- Triple<String, String, Component> triple = Triple.of("fileName", "", component);
- dependencies.add(triple);
- toscaTemplate.setDependencies(dependencies);
-
- Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
-
- Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class)))
- .thenReturn(Either.right(ToscaError.GENERAL_ERROR));
-
- Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class)))
- .thenReturn(Either.left(toscaTemplate));
+ }
+
+ @Test
+ void testPopulateZipWhenComponentIsServiceAndCollectComponentCsarDefinitionIsRight() {
+ Component component = new Service();
+ boolean getFromCS = false;
+
+ Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
+ ArtifactDefinition artifact = new ArtifactDefinition();
+ artifact.setArtifactName("artifactName");
+ artifact.setEsId("esId");
+ artifact.setArtifactUUID("artifactUUID");
+ artifact.setArtifactType("YANG");
+ artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
+ artifact.setDescription("description");
+ artifact.setArtifactLabel("artifactLabel");
+ toscaArtifacts.put("assettoscatemplate", artifact);
+
+ component.setToscaArtifacts(toscaArtifacts);
+ component.setDeploymentArtifacts(toscaArtifacts);
+ component.setArtifacts(toscaArtifacts);
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ component.setVersion("1.0");
+ component.setLastUpdaterUserId("userId");
+ component.setUniqueId("uid");
+ DAOArtifactData artifactData = new DAOArtifactData();
+ ByteBuffer bufferData = ByteBuffer.wrap(contentData);
+ artifactData.setData(bufferData);
+
+ List<SdcSchemaFilesData> filesData = new ArrayList<>();
+ SdcSchemaFilesData filedata = new SdcSchemaFilesData();
+ filedata.setPayloadAsArray(contentData);
+ filesData.add(filedata);
+
+ ToscaTemplate toscaTemplate = new ToscaTemplate("version");
+ List<Triple<String, String, Component>> dependencies = new ArrayList<>();
+ Triple<String, String, Component> triple = Triple.of("fileName", "cassandraId", component);
+ dependencies.add(triple);
+ toscaTemplate.setDependencies(dependencies);
+
+ ToscaRepresentation tosca = ToscaRepresentation.make("value".getBytes());
+
+ Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
+
+ Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class))).thenReturn(Either.left(tosca));
+
+ 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));
+
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class)))
+ .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+
+ Mockito.when(artifactsBusinessLogic.validateUserExists(Mockito.any(User.class))).thenReturn(new User());
+
+
+ Mockito.when(artifactsBusinessLogic.validateAndHandleArtifact(Mockito.any(String.class),
+ Mockito.any(ComponentTypeEnum.class), Mockito.any(ArtifactOperationInfo.class), Mockito.isNull(),
+ Mockito.any(ArtifactDefinition.class), Mockito.any(String.class), Mockito.any(String.class),
+ Mockito.isNull(), Mockito.isNull(), Mockito.any(User.class), Mockito.any(Component.class),
+ Mockito.any(Boolean.class), Mockito.any(Boolean.class), Mockito.any(Boolean.class)))
+ .thenReturn(Either.left(Mockito.any(ArtifactDefinition.class)));
+
+ 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
+ void testPopulateZipWhenGetEntryDataIsRight() {
+ Component component = new Service();
+ boolean getFromCS = true;
+
+ Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
+ ArtifactDefinition artifact = new ArtifactDefinition();
+ artifact.setArtifactName("artifactName");
+ artifact.setEsId("esId");
+ artifact.setArtifactUUID("artifactUUID");
+ artifact.setArtifactType("YANG");
+ artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
+ artifact.setDescription("description");
+ artifact.setArtifactLabel("artifactLabel");
+ toscaArtifacts.put("assettoscatemplate", artifact);
+
+ component.setToscaArtifacts(toscaArtifacts);
+ component.setDeploymentArtifacts(toscaArtifacts);
+ component.setArtifacts(toscaArtifacts);
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ component.setVersion("1.0");
+ component.setLastUpdaterUserId("userId");
+ component.setUniqueId("uid");
+ DAOArtifactData artifactData = new DAOArtifactData();
+ byte[] data = "value".getBytes();
+ ByteBuffer bufferData = ByteBuffer.wrap(data);
+ artifactData.setData(bufferData);
+
+ ToscaTemplate toscaTemplate = new ToscaTemplate("version");
+ List<Triple<String, String, Component>> dependencies = new ArrayList<>();
+ Triple<String, String, Component> triple = Triple.of("fileName", "", component);
+ dependencies.add(triple);
+ toscaTemplate.setDependencies(dependencies);
+
+ Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
+
+ Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class)))
+ .thenReturn(Either.right(ToscaError.GENERAL_ERROR));
+
+ Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class)))
+ .thenReturn(Either.left(toscaTemplate));
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
- void testPopulateZipWhenGetEntryDataOfInnerComponentIsRight() {
- Component component = new Service();
- boolean getFromCS = false;
-
- Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
- ArtifactDefinition artifact = new ArtifactDefinition();
- artifact.setArtifactName("artifactName");
- artifact.setEsId("esId");
- artifact.setArtifactUUID("artifactUUID");
- artifact.setArtifactType("YANG");
- artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
- artifact.setDescription("description");
- artifact.setArtifactLabel("artifactLabel");
- toscaArtifacts.put("assettoscatemplate", artifact);
-
- component.setToscaArtifacts(toscaArtifacts);
- component.setDeploymentArtifacts(toscaArtifacts);
- component.setArtifacts(toscaArtifacts);
- component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- component.setVersion("1.0");
- component.setLastUpdaterUserId("userId");
- component.setUniqueId("uid");
- DAOArtifactData artifactData = new DAOArtifactData();
- ByteBuffer bufferData = ByteBuffer.wrap(contentData);
- artifactData.setData(bufferData);
-
- ToscaTemplate toscaTemplate = new ToscaTemplate("version");
- List<Triple<String, String, Component>> dependencies = new ArrayList<>();
- Triple<String, String, Component> triple = Triple.of("fileName", "", component);
- dependencies.add(triple);
- toscaTemplate.setDependencies(dependencies);
-
- ToscaRepresentation tosca = ToscaRepresentation.make(contentData);
-
- Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
-
- Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class))).thenReturn(Either.left(tosca),
- Either.left(tosca), Either.right(ToscaError.GENERAL_ERROR));
-
- Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class)))
- .thenReturn(Either.left(toscaTemplate));
+ }
+
+ @Test
+ void testPopulateZipWhenGetEntryDataOfInnerComponentIsRight() {
+ Component component = new Service();
+ boolean getFromCS = false;
+
+ Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
+ ArtifactDefinition artifact = new ArtifactDefinition();
+ artifact.setArtifactName("artifactName");
+ artifact.setEsId("esId");
+ artifact.setArtifactUUID("artifactUUID");
+ artifact.setArtifactType("YANG");
+ artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
+ artifact.setDescription("description");
+ artifact.setArtifactLabel("artifactLabel");
+ toscaArtifacts.put("assettoscatemplate", artifact);
+
+ component.setToscaArtifacts(toscaArtifacts);
+ component.setDeploymentArtifacts(toscaArtifacts);
+ component.setArtifacts(toscaArtifacts);
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ component.setVersion("1.0");
+ component.setLastUpdaterUserId("userId");
+ component.setUniqueId("uid");
+ DAOArtifactData artifactData = new DAOArtifactData();
+ ByteBuffer bufferData = ByteBuffer.wrap(contentData);
+ artifactData.setData(bufferData);
+
+ ToscaTemplate toscaTemplate = new ToscaTemplate("version");
+ List<Triple<String, String, Component>> dependencies = new ArrayList<>();
+ Triple<String, String, Component> triple = Triple.of("fileName", "", component);
+ dependencies.add(triple);
+ toscaTemplate.setDependencies(dependencies);
+
+ ToscaRepresentation tosca = ToscaRepresentation.make(contentData);
+
+ Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
+
+ Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class))).thenReturn(Either.left(tosca),
+ Either.left(tosca), Either.right(ToscaError.GENERAL_ERROR));
+
+ Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class)))
+ .thenReturn(Either.left(toscaTemplate));
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
- void testPopulateZipWhenLatestSchemaFilesFromCassandraIsRight() {
- Component component = new Service();
- boolean getFromCS = false;
-
- Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
- ArtifactDefinition artifact = new ArtifactDefinition();
- artifact.setArtifactName("artifactName");
- artifact.setEsId("esId");
- artifact.setArtifactUUID("artifactUUID");
- artifact.setArtifactType("YANG");
- artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
- artifact.setDescription("description");
- artifact.setArtifactLabel("artifactLabel");
- toscaArtifacts.put("assettoscatemplate", artifact);
-
- component.setToscaArtifacts(toscaArtifacts);
- component.setDeploymentArtifacts(toscaArtifacts);
- component.setArtifacts(toscaArtifacts);
- component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- component.setVersion("1.0");
- component.setLastUpdaterUserId("userId");
- component.setUniqueId("uid");
- DAOArtifactData artifactData = new DAOArtifactData();
- ByteBuffer bufferData = ByteBuffer.wrap(contentData);
- artifactData.setData(bufferData);
-
- ToscaTemplate toscaTemplate = new ToscaTemplate("version");
- List<Triple<String, String, Component>> dependencies = new ArrayList<>();
- Triple<String, String, Component> triple = Triple.of("fileName", "", component);
- dependencies.add(triple);
- toscaTemplate.setDependencies(dependencies);
-
- ToscaRepresentation tosca = ToscaRepresentation.make(contentData);
-
- Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
-
- Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class))).thenReturn(Either.left(tosca));
-
- 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.right(CassandraOperationStatus.GENERAL_ERROR));
-
- try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
- Deencapsulation.invoke(commonCsarGenerator, "generateCsarZip", component, getFromCS, zip, true, "toscaMetaFileName", true, "Definitions/", true, false);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Test
- void testAddInnerComponentsToCache() {
- ComponentCache componentCache = ComponentCache.overwritable(overwriteIfSameVersions());
- Component childComponent = new Resource();
- Component componentRI = new Service();
- List<ComponentInstance> componentInstances = new ArrayList<>();
- ComponentInstance instance = new ComponentInstance();
- instance.setComponentUid("resourceUid");
- componentInstances.add(instance);
- childComponent.setComponentInstances(componentInstances);
-
- Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
- ArtifactDefinition artifact = new ArtifactDefinition();
- artifact.setArtifactName("artifactName");
- artifact.setEsId("esId");
- artifact.setArtifactUUID("artifactUUID");
- artifact.setArtifactType("YANG");
- artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
- artifact.setDescription("description");
- artifact.setArtifactLabel("artifactLabel");
- toscaArtifacts.put("assettoscatemplate", artifact);
-
- componentRI.setToscaArtifacts(toscaArtifacts);
-
- Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class)))
- .thenReturn(Either.left(componentRI));
-
- 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());
- }
-
- @Test
- void testAddInnerComponentsToCacheWhenGetToscaElementIsRight() {
- Map<String, ImmutableTriple<String, String, Component>> componentCache = new HashMap<>();
- Component childComponent = new Resource();
-
- List<ComponentInstance> componentInstances = new ArrayList<>();
- ComponentInstance instance = new ComponentInstance();
- instance.setComponentUid("abc");
- componentInstances.add(instance);
- childComponent.setComponentInstances(componentInstances);
-
- Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
- ArtifactDefinition artifact = new ArtifactDefinition();
- artifact.setArtifactName("artifactName");
- artifact.setEsId("esId");
- artifact.setArtifactUUID("artifactUUID");
- artifact.setArtifactType("YANG");
- artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
- artifact.setDescription("description");
- artifact.setArtifactLabel("artifactLabel");
- toscaArtifacts.put("assettoscatemplate", artifact);
-
- Component componentRI = new Service();
-
- componentRI.setToscaArtifacts(toscaArtifacts);
-
- Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class)))
- .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
-
-
- assertTrue(componentCache.isEmpty());
- }
-
- @Test
- void testWriteComponentInterface() throws IOException {
- String fileName = "name.hello";
- ToscaRepresentation tosca = ToscaRepresentation.make("value".getBytes());
-
- 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)) {
- List<Triple<String, String, Component>> output = Deencapsulation.invoke(commonCsarGenerator, "writeComponentInterface", new Resource(),
+ }
+
+ @Test
+ void testPopulateZipWhenLatestSchemaFilesFromCassandraIsRight() {
+ Component component = new Service();
+ boolean getFromCS = false;
+
+ Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
+ ArtifactDefinition artifact = new ArtifactDefinition();
+ artifact.setArtifactName("artifactName");
+ artifact.setEsId("esId");
+ artifact.setArtifactUUID("artifactUUID");
+ artifact.setArtifactType("YANG");
+ artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
+ artifact.setDescription("description");
+ artifact.setArtifactLabel("artifactLabel");
+ toscaArtifacts.put("assettoscatemplate", artifact);
+
+ component.setToscaArtifacts(toscaArtifacts);
+ component.setDeploymentArtifacts(toscaArtifacts);
+ component.setArtifacts(toscaArtifacts);
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ component.setVersion("1.0");
+ component.setLastUpdaterUserId("userId");
+ component.setUniqueId("uid");
+ DAOArtifactData artifactData = new DAOArtifactData();
+ ByteBuffer bufferData = ByteBuffer.wrap(contentData);
+ artifactData.setData(bufferData);
+
+ ToscaTemplate toscaTemplate = new ToscaTemplate("version");
+ List<Triple<String, String, Component>> dependencies = new ArrayList<>();
+ Triple<String, String, Component> triple = Triple.of("fileName", "", component);
+ dependencies.add(triple);
+ toscaTemplate.setDependencies(dependencies);
+
+ ToscaRepresentation tosca = ToscaRepresentation.make(contentData);
+
+ Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
+
+ Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class))).thenReturn(Either.left(tosca));
+
+ 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.right(CassandraOperationStatus.GENERAL_ERROR));
+
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
+ Deencapsulation.invoke(commonCsarGenerator, "generateCsarZip", component, getFromCS, zip, true, "toscaMetaFileName", true, "Definitions/",
+ true, false);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ void testAddInnerComponentsToCache() {
+ ComponentCache componentCache = ComponentCache.overwritable(overwriteIfSameVersions());
+ Component childComponent = new Resource();
+ Component componentRI = new Service();
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ ComponentInstance instance = new ComponentInstance();
+ instance.setComponentUid("resourceUid");
+ componentInstances.add(instance);
+ childComponent.setComponentInstances(componentInstances);
+
+ Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
+ ArtifactDefinition artifact = new ArtifactDefinition();
+ artifact.setArtifactName("artifactName");
+ artifact.setEsId("esId");
+ artifact.setArtifactUUID("artifactUUID");
+ artifact.setArtifactType("YANG");
+ artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
+ artifact.setDescription("description");
+ artifact.setArtifactLabel("artifactLabel");
+ toscaArtifacts.put("assettoscatemplate", artifact);
+
+ componentRI.setToscaArtifacts(toscaArtifacts);
+
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class)))
+ .thenReturn(Either.left(componentRI));
+
+ 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());
+ }
+
+ @Test
+ void testAddInnerComponentsToCacheWhenGetToscaElementIsRight() {
+ Map<String, ImmutableTriple<String, String, Component>> componentCache = new HashMap<>();
+ Component childComponent = new Resource();
+
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ ComponentInstance instance = new ComponentInstance();
+ instance.setComponentUid("abc");
+ componentInstances.add(instance);
+ childComponent.setComponentInstances(componentInstances);
+
+ Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
+ ArtifactDefinition artifact = new ArtifactDefinition();
+ artifact.setArtifactName("artifactName");
+ artifact.setEsId("esId");
+ artifact.setArtifactUUID("artifactUUID");
+ artifact.setArtifactType("YANG");
+ artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
+ artifact.setDescription("description");
+ artifact.setArtifactLabel("artifactLabel");
+ toscaArtifacts.put("assettoscatemplate", artifact);
+
+ Component componentRI = new Service();
+
+ componentRI.setToscaArtifacts(toscaArtifacts);
+
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class)))
+ .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+
+
+ assertTrue(componentCache.isEmpty());
+ }
+
+ @Test
+ void testWriteComponentInterface() throws IOException {
+ String fileName = "name.hello";
+ ToscaRepresentation tosca = ToscaRepresentation.make("value".getBytes());
+
+ 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)) {
+ List<Triple<String, String, Component>> output = Deencapsulation.invoke(commonCsarGenerator, "writeComponentInterface", new Resource(),
zip, fileName, "Definitions/");
- assertNotNull(output);
- }
- }
-
- @Test
- void testGetEntryData() {
- String cassandraId = "id";
- Component childComponent = new Resource();
-
- Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class)))
- .thenReturn(Either.right(CassandraOperationStatus.GENERAL_ERROR));
-
- Either<byte[], ActionStatus> output = Deencapsulation.invoke(commonCsarGenerator, "getEntryData", cassandraId, childComponent);
-
- assertNotNull(output);
- assertTrue(output.isRight());
- }
-
- @Test
- void testGetLatestSchemaFilesFromCassandraWhenListOfSchemasIsEmpty() {
- List<SdcSchemaFilesData> filesData = new ArrayList<>();
-
- Mockito.when(
- sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(Mockito.any(String.class), Mockito.any(String.class)))
- .thenReturn(Either.left(filesData));
-
- Either<byte[], ResponseFormat> output = Deencapsulation.invoke(commonCsarGenerator, "getLatestSchemaFilesFromCassandra");
-
- assertNotNull(output);
- assertTrue(output.isRight());
- }
-
- @Test
- void testExtractVfcsArtifactsFromCsar() {
- String key = "Artifacts/org.openecomp.resource.some/Deployment/to/resource";
- byte[] data = "value".getBytes();
-
- Map<String, byte[]> csar = new HashMap<>();
- csar.put(key, data);
-
- Map<String, List<ArtifactDefinition>> output = CsarUtils.extractVfcsArtifactsFromCsar(csar);
-
- assertNotNull(output);
- assertTrue(output.containsKey("org.openecomp.resource.some"));
- assertEquals(1, output.get("org.openecomp.resource.some").size());
- }
-
- @Test
- void testAddExtractedVfcArtifactWhenArtifactsContainsExtractedArtifactKey() {
- ImmutablePair<String, ArtifactDefinition> extractedVfcArtifact = new ImmutablePair<String, ArtifactDefinition>(
- "key", new ArtifactDefinition());
- Map<String, List<ArtifactDefinition>> artifacts = new HashMap<>();
- artifacts.put("key", new ArrayList<>());
-
- Deencapsulation.invoke(testSubject, "addExtractedVfcArtifact", extractedVfcArtifact, artifacts);
-
- assertEquals(1, artifacts.get("key").size());
- }
-
- @Test
- void testAddExtractedVfcArtifactWhenArtifactsDoesntContainsExtractedArtifactKey() {
- ImmutablePair<String, ArtifactDefinition> extractedVfcArtifact = new ImmutablePair<String, ArtifactDefinition>(
- "key", new ArtifactDefinition());
- Map<String, List<ArtifactDefinition>> artifacts = new HashMap<>();
- artifacts.put("key1", new ArrayList<>());
-
- Deencapsulation.invoke(testSubject, "addExtractedVfcArtifact", extractedVfcArtifact, artifacts);
-
- assertEquals(0, artifacts.get("key1").size());
- assertEquals(1, artifacts.get("key").size());
- assertEquals(2, artifacts.size());
- }
-
- @Test
- void testExtractVfcArtifact() {
- String path = "path/to/informational/artificat";
- Map<String, byte[]> map = new HashMap<>();
- map.put(path, "value".getBytes());
- Entry<String, byte[]> entry = map.entrySet().iterator().next();
-
- Optional<ImmutablePair<String, ArtifactDefinition>> output =
- Deencapsulation.invoke(testSubject, "extractVfcArtifact", entry, new HashMap<>());
-
- if(output.isPresent()) {
- assertEquals("to", output.get().left);
- } else {
- fail("`output` is empty!");
- }
- }
-
- @Test
- void testDetectArtifactGroupTypeWithExceptionBeingCaught() {
- Either<ArtifactGroupTypeEnum, Boolean> output = Deencapsulation.invoke(testSubject, "detectArtifactGroupType", "type", Map.class);
-
- assertNotNull(output);
- assertTrue(output.isRight());
- assertFalse(output.right().value());
- }
-
- @Test
- void testDetectArtifactGroupTypeWWhenCollectedWarningMessagesContainesKey() {
- Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
-
- collectedWarningMessages.put("Warning - unrecognized artifact group type {} was received.", new HashSet<>());
- Either<ArtifactGroupTypeEnum, Boolean> output = Deencapsulation.invoke(testSubject, "detectArtifactGroupType", "type", collectedWarningMessages);
-
- assertNotNull(output);
- assertTrue(output.isRight());
- assertFalse(output.right().value());
- }
-
- @Test
- void testValidateNonMetaArtifactWithExceptionCaught() {
- CsarUtils.validateNonMetaArtifact("", new byte[0], new HashMap<>());
- }
-
- @Test
- void testCollectComponentCsarDefinitionWhenComponentIsServiceAndGetToscaElementIsLeft() {
- Component component = new Service();
- component.setUniqueId("uniqueId");
- List<ComponentInstance> resourceInstances = new ArrayList<>();
- ComponentInstance instance = new ComponentInstance();
- instance.setComponentUid("resourceUid");
- instance.setOriginType(OriginTypeEnum.SERVICE);
- resourceInstances.add(instance);
- component.setComponentInstances(resourceInstances);
-
- 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);
-
- Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class))).thenReturn(Either.left(component),
- Either.right(StorageOperationStatus.BAD_REQUEST));
-
- Either<Object, ResponseFormat> output = Deencapsulation.invoke(testSubject, "collectComponentCsarDefinition", component);
-
- assertNotNull(output);
- assertTrue(output.isRight());
- }
-
- @Test
- void testCollectComponentTypeArtifactsWhenFetchedComponentHasComponentInstances() {
- Component component = new Service();
- Component fetchedComponent = new Resource();
- component.setUniqueId("uniqueId");
- List<ComponentInstance> resourceInstances = new ArrayList<>();
- ComponentInstance instance = new ComponentInstance();
- instance.setComponentUid("resourceUid");
- instance.setOriginType(OriginTypeEnum.SERVICE);
- resourceInstances.add(instance);
- component.setComponentInstances(resourceInstances);
- fetchedComponent.setComponentInstances(resourceInstances);
-
- 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);
-
- fetchedComponent.setToscaArtifacts(toscaArtifacts);
- fetchedComponent.setDeploymentArtifacts(toscaArtifacts);
- fetchedComponent.setArtifacts(toscaArtifacts);
-
- Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class))).thenReturn(Either.left(component),
- Either.left(fetchedComponent), Either.right(StorageOperationStatus.BAD_REQUEST));
-
- Either<Object, ResponseFormat> output = Deencapsulation.invoke(testSubject, "collectComponentCsarDefinition", component);
-
- assertNotNull(output);
- assertTrue(output.isRight());
- }
-
- @Test
- void testCollectComponentTypeArtifactsWhenFetchedComponentDontHaveComponentInstances() {
- Component component = new Service();
- Component fetchedComponent = new Resource();
- component.setUniqueId("uniqueId");
- List<ComponentInstance> resourceInstances = new ArrayList<>();
- ComponentInstance instance = new ComponentInstance();
- instance.setComponentUid("resourceUid");
- instance.setOriginType(OriginTypeEnum.SERVICE);
-
- Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
- ArtifactDefinition artifact = new ArtifactDefinition();
- artifact.setArtifactName("artifactName");
- artifact.setEsId("esId");
- artifact.setArtifactUUID("artifactUUID");
- artifact.setArtifactType("PLAN");
- toscaArtifacts.put("assettoscatemplate", artifact);
-
- instance.setDeploymentArtifacts(toscaArtifacts);
-
- resourceInstances.add(instance);
- component.setComponentInstances(resourceInstances);
-
- component.setToscaArtifacts(toscaArtifacts);
- component.setDeploymentArtifacts(toscaArtifacts);
- component.setArtifacts(toscaArtifacts);
-
- fetchedComponent.setToscaArtifacts(toscaArtifacts);
- fetchedComponent.setDeploymentArtifacts(toscaArtifacts);
- fetchedComponent.setArtifacts(toscaArtifacts);
-
- Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class))).thenReturn(Either.left(component),
- Either.left(fetchedComponent));
-
- Either<Object, ResponseFormat> output = Deencapsulation.invoke(testSubject, "collectComponentCsarDefinition", component);
-
- assertNotNull(output);
- assertTrue(output.isLeft());
- }
-
- @Test
- void testValidateNonMetaArtifactHappyScenario() {
- String artifactPath = "Artifacts/Deployment/YANG_XML/myYang.xml";
- byte[] payloadData = "some payload data".getBytes();
- Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
- Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath,
- payloadData, collectedWarningMessages);
- assertTrue(eitherNonMetaArtifact.isLeft());
- assertTrue(collectedWarningMessages.isEmpty());
-
- artifactPath = "Artifacts/Informational/OTHER/someArtifact.xml";
- eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
- assertTrue(eitherNonMetaArtifact.isLeft());
- assertTrue(collectedWarningMessages.isEmpty());
- }
-
- @Test
- void testValidateNonMetaArtifactScenarioWithWarnnings() {
- String artifactPath = "Artifacts/Deployment/Buga/myYang.xml";
- byte[] payloadData = "some payload data".getBytes();
- Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
- Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath,
- payloadData, collectedWarningMessages);
- assertTrue(eitherNonMetaArtifact.isLeft());
-
- artifactPath = "Artifacts/Informational/Buga2/someArtifact.xml";
- eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
- assertTrue(eitherNonMetaArtifact.isLeft());
-
- assertEquals(1, collectedWarningMessages.size());
- assertEquals(2, collectedWarningMessages.values().iterator().next().size());
- }
-
- @Test
- void testValidateNonMetaArtifactUnhappyScenario() {
- String artifactPath = "Artifacts/Buga/YANG_XML/myYang.xml";
- byte[] payloadData = "some payload data".getBytes();
- Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
- Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath,
- payloadData, collectedWarningMessages);
- assertTrue(eitherNonMetaArtifact.isRight());
- assertFalse(collectedWarningMessages.isEmpty());
- }
-
- @Test
- void testAddSchemaFilesFromCassandraAddingDuplicatedEntry() throws IOException {
- final String rootPath = System.getProperty("user.dir");
- 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(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());
- }
- }
-
- @Test
- void testFindNonRootNodesFromPackage() {
- final Resource resource = new Resource();
- resource.setDerivedList(nodesFromPackage);
- final Component component = resource;
- final List<Triple<String, String, Component>> dependencies = new ArrayList<>();
- 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(commonCsarGenerator,
- "findNonRootNodesFromPackage", dependencies);
- assertTrue(CollectionUtils.isNotEmpty(result));
- assertEquals(expectedResult, result);
- }
+ assertNotNull(output);
+ }
+ }
+
+ @Test
+ void testGetEntryData() {
+ String cassandraId = "id";
+ Component childComponent = new Resource();
+
+ Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class)))
+ .thenReturn(Either.right(CassandraOperationStatus.GENERAL_ERROR));
+
+ Either<byte[], ActionStatus> output = Deencapsulation.invoke(commonCsarGenerator, "getEntryData", cassandraId, childComponent);
+
+ assertNotNull(output);
+ assertTrue(output.isRight());
+ }
+
+ @Test
+ void testGetLatestSchemaFilesFromCassandraWhenListOfSchemasIsEmpty() {
+ List<SdcSchemaFilesData> filesData = new ArrayList<>();
+
+ Mockito.when(
+ sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(Mockito.any(String.class), Mockito.any(String.class)))
+ .thenReturn(Either.left(filesData));
+
+ Either<byte[], ResponseFormat> output = Deencapsulation.invoke(commonCsarGenerator, "getLatestSchemaFilesFromCassandra");
+
+ assertNotNull(output);
+ assertTrue(output.isRight());
+ }
+
+ @Test
+ void testExtractVfcsArtifactsFromCsar() {
+ String key = "Artifacts/org.openecomp.resource.some/Deployment/to/resource";
+ byte[] data = "value".getBytes();
+
+ Map<String, byte[]> csar = new HashMap<>();
+ csar.put(key, data);
+
+ Map<String, List<ArtifactDefinition>> output = CsarUtils.extractVfcsArtifactsFromCsar(csar);
+
+ assertNotNull(output);
+ assertTrue(output.containsKey("org.openecomp.resource.some"));
+ assertEquals(1, output.get("org.openecomp.resource.some").size());
+ }
+
+ @Test
+ void testAddExtractedVfcArtifactWhenArtifactsContainsExtractedArtifactKey() {
+ ImmutablePair<String, ArtifactDefinition> extractedVfcArtifact = new ImmutablePair<String, ArtifactDefinition>(
+ "key", new ArtifactDefinition());
+ Map<String, List<ArtifactDefinition>> artifacts = new HashMap<>();
+ artifacts.put("key", new ArrayList<>());
+
+ Deencapsulation.invoke(testSubject, "addExtractedVfcArtifact", extractedVfcArtifact, artifacts);
+
+ assertEquals(1, artifacts.get("key").size());
+ }
+
+ @Test
+ void testAddExtractedVfcArtifactWhenArtifactsDoesntContainsExtractedArtifactKey() {
+ ImmutablePair<String, ArtifactDefinition> extractedVfcArtifact = new ImmutablePair<String, ArtifactDefinition>(
+ "key", new ArtifactDefinition());
+ Map<String, List<ArtifactDefinition>> artifacts = new HashMap<>();
+ artifacts.put("key1", new ArrayList<>());
+
+ Deencapsulation.invoke(testSubject, "addExtractedVfcArtifact", extractedVfcArtifact, artifacts);
+
+ assertEquals(0, artifacts.get("key1").size());
+ assertEquals(1, artifacts.get("key").size());
+ assertEquals(2, artifacts.size());
+ }
+
+ @Test
+ void testExtractVfcArtifact() {
+ String path = "path/to/informational/artificat";
+ Map<String, byte[]> map = new HashMap<>();
+ map.put(path, "value".getBytes());
+ Entry<String, byte[]> entry = map.entrySet().iterator().next();
+
+ Optional<ImmutablePair<String, ArtifactDefinition>> output =
+ Deencapsulation.invoke(testSubject, "extractVfcArtifact", entry, new HashMap<>());
+
+ if (output.isPresent()) {
+ assertEquals("to", output.get().left);
+ } else {
+ fail("`output` is empty!");
+ }
+ }
+
+ @Test
+ void testDetectArtifactGroupTypeWithExceptionBeingCaught() {
+ Either<ArtifactGroupTypeEnum, Boolean> output = Deencapsulation.invoke(testSubject, "detectArtifactGroupType", "type", Map.class);
+
+ assertNotNull(output);
+ assertTrue(output.isRight());
+ assertFalse(output.right().value());
+ }
+
+ @Test
+ void testDetectArtifactGroupTypeWWhenCollectedWarningMessagesContainesKey() {
+ Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
+
+ collectedWarningMessages.put("Warning - unrecognized artifact group type {} was received.", new HashSet<>());
+ Either<ArtifactGroupTypeEnum, Boolean> output =
+ Deencapsulation.invoke(testSubject, "detectArtifactGroupType", "type", collectedWarningMessages);
+
+ assertNotNull(output);
+ assertTrue(output.isRight());
+ assertFalse(output.right().value());
+ }
+
+ @Test
+ void testValidateNonMetaArtifactWithExceptionCaught() {
+ CsarUtils.validateNonMetaArtifact("", new byte[0], new HashMap<>());
+ }
+
+ @Test
+ void testCollectComponentCsarDefinitionWhenComponentIsServiceAndGetToscaElementIsLeft() {
+ Component component = new Service();
+ component.setUniqueId("uniqueId");
+ List<ComponentInstance> resourceInstances = new ArrayList<>();
+ ComponentInstance instance = new ComponentInstance();
+ instance.setComponentUid("resourceUid");
+ instance.setOriginType(OriginTypeEnum.SERVICE);
+ resourceInstances.add(instance);
+ component.setComponentInstances(resourceInstances);
+
+ 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);
+
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class))).thenReturn(Either.left(component),
+ Either.right(StorageOperationStatus.BAD_REQUEST));
+
+ Either<Object, ResponseFormat> output = Deencapsulation.invoke(testSubject, "collectComponentCsarDefinition", component);
+
+ assertNotNull(output);
+ assertTrue(output.isRight());
+ }
+
+ @Test
+ void testCollectComponentTypeArtifactsWhenFetchedComponentHasComponentInstances() {
+ Component component = new Service();
+ Component fetchedComponent = new Resource();
+ component.setUniqueId("uniqueId");
+ List<ComponentInstance> resourceInstances = new ArrayList<>();
+ ComponentInstance instance = new ComponentInstance();
+ instance.setComponentUid("resourceUid");
+ instance.setOriginType(OriginTypeEnum.SERVICE);
+ resourceInstances.add(instance);
+ component.setComponentInstances(resourceInstances);
+ fetchedComponent.setComponentInstances(resourceInstances);
+
+ 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);
+
+ fetchedComponent.setToscaArtifacts(toscaArtifacts);
+ fetchedComponent.setDeploymentArtifacts(toscaArtifacts);
+ fetchedComponent.setArtifacts(toscaArtifacts);
+
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class))).thenReturn(Either.left(component),
+ Either.left(fetchedComponent), Either.right(StorageOperationStatus.BAD_REQUEST));
+
+ Either<Object, ResponseFormat> output = Deencapsulation.invoke(testSubject, "collectComponentCsarDefinition", component);
+
+ assertNotNull(output);
+ assertTrue(output.isRight());
+ }
+
+ @Test
+ void testCollectComponentTypeArtifactsWhenFetchedComponentDontHaveComponentInstances() {
+ Component component = new Service();
+ Component fetchedComponent = new Resource();
+ component.setUniqueId("uniqueId");
+ List<ComponentInstance> resourceInstances = new ArrayList<>();
+ ComponentInstance instance = new ComponentInstance();
+ instance.setComponentUid("resourceUid");
+ instance.setOriginType(OriginTypeEnum.SERVICE);
+
+ Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
+ ArtifactDefinition artifact = new ArtifactDefinition();
+ artifact.setArtifactName("artifactName");
+ artifact.setEsId("esId");
+ artifact.setArtifactUUID("artifactUUID");
+ artifact.setArtifactType("PLAN");
+ toscaArtifacts.put("assettoscatemplate", artifact);
+
+ instance.setDeploymentArtifacts(toscaArtifacts);
+
+ resourceInstances.add(instance);
+ component.setComponentInstances(resourceInstances);
+
+ component.setToscaArtifacts(toscaArtifacts);
+ component.setDeploymentArtifacts(toscaArtifacts);
+ component.setArtifacts(toscaArtifacts);
+
+ fetchedComponent.setToscaArtifacts(toscaArtifacts);
+ fetchedComponent.setDeploymentArtifacts(toscaArtifacts);
+ fetchedComponent.setArtifacts(toscaArtifacts);
+
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class))).thenReturn(Either.left(component),
+ Either.left(fetchedComponent));
+
+ Either<Object, ResponseFormat> output = Deencapsulation.invoke(testSubject, "collectComponentCsarDefinition", component);
+
+ assertNotNull(output);
+ assertTrue(output.isLeft());
+ }
+
+ @Test
+ void testValidateNonMetaArtifactHappyScenario() {
+ String artifactPath = "Artifacts/Deployment/YANG_XML/myYang.xml";
+ byte[] payloadData = "some payload data".getBytes();
+ Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
+ Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath,
+ payloadData, collectedWarningMessages);
+ assertTrue(eitherNonMetaArtifact.isLeft());
+ assertTrue(collectedWarningMessages.isEmpty());
+
+ artifactPath = "Artifacts/Informational/OTHER/someArtifact.xml";
+ eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
+ assertTrue(eitherNonMetaArtifact.isLeft());
+ assertTrue(collectedWarningMessages.isEmpty());
+ }
+
+ @Test
+ void testValidateNonMetaArtifactScenarioWithWarnnings() {
+ String artifactPath = "Artifacts/Deployment/Buga/myYang.xml";
+ byte[] payloadData = "some payload data".getBytes();
+ Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
+ Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath,
+ payloadData, collectedWarningMessages);
+ assertTrue(eitherNonMetaArtifact.isLeft());
+
+ artifactPath = "Artifacts/Informational/Buga2/someArtifact.xml";
+ eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
+ assertTrue(eitherNonMetaArtifact.isLeft());
+
+ assertEquals(1, collectedWarningMessages.size());
+ assertEquals(2, collectedWarningMessages.values().iterator().next().size());
+ }
+
+ @Test
+ void testValidateNonMetaArtifactUnhappyScenario() {
+ String artifactPath = "Artifacts/Buga/YANG_XML/myYang.xml";
+ byte[] payloadData = "some payload data".getBytes();
+ Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
+ Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath,
+ payloadData, collectedWarningMessages);
+ assertTrue(eitherNonMetaArtifact.isRight());
+ assertFalse(collectedWarningMessages.isEmpty());
+ }
+
+ @Test
+ void testAddSchemaFilesFromCassandraAddingDuplicatedEntry() throws IOException {
+ final String rootPath = System.getProperty("user.dir");
+ 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(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());
+ }
+ }
+
+ @Test
+ void testFindNonRootNodesFromPackage() {
+ final Resource resource = new Resource();
+ resource.setDerivedList(nodesFromPackage);
+ final Component component = resource;
+ final List<Triple<String, String, Component>> dependencies = new ArrayList<>();
+ 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(commonCsarGenerator,
+ "findNonRootNodesFromPackage", dependencies);
+ assertTrue(CollectionUtils.isNotEmpty(result));
+ assertEquals(expectedResult, result);
+ }
private byte[] getFileResource(final String filePath) throws IOException {
try (final InputStream inputStream = getFileResourceAsInputStream(filePath)) {
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 0b3796261a..dc60cc81d5 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
@@ -69,6 +69,9 @@ import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterCapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
@@ -104,6 +107,7 @@ import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.be.tosca.exception.ToscaConversionException;
import org.openecomp.sdc.be.tosca.model.ToscaCapability;
import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate;
@@ -164,6 +168,9 @@ class ToscaExportHandlerTest extends BaseConfDependent {
private InterfacesOperationsConverter interfacesOperationsConverter;
@Mock
+ ModelOperation modelOperation;
+
+ @Mock
private PolicyExportParser policyExportParser;
@Mock
@@ -303,8 +310,15 @@ class ToscaExportHandlerTest extends BaseConfDependent {
void testExportDataType() {
DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
dataTypeDefinition.setUniqueId("uniqueId");
+ PropertyDefinition propData = new PropertyDataDefinitionBuilder()
+ .setName("property")
+ .setType("type")
+ .build();
+ List<PropertyDefinition> propDataList = Arrays.asList(propData);
+ dataTypeDefinition.setProperties(propDataList);
Either<ToscaRepresentation, ToscaError> result;
when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>()));
+ when(propertyConvertor.convertProperty(any(), any(), any() )).thenReturn(new ToscaProperty());
result = testSubject.exportDataType(dataTypeDefinition);
assertNotNull(result);
}
@@ -476,6 +490,44 @@ class ToscaExportHandlerTest extends BaseConfDependent {
}
@Test
+ void testConvertToscaTemplateWithSubstitutionFilter() throws ToscaConversionException {
+ Component component = getNewResource();
+ ToscaTemplate toscaNode = new ToscaTemplate("");
+ component.setComponentInstances(new ArrayList<>());
+
+ SubstitutionFilterPropertyDataDefinition filterProp = new SubstitutionFilterPropertyDataDefinition();
+ ListDataDefinition<SubstitutionFilterPropertyDataDefinition> filterProperties = new ListDataDefinition<>();
+ filterProperties.add(filterProp);
+ SubstitutionFilterDataDefinition subFilter = new SubstitutionFilterDataDefinition();
+ subFilter.setProperties(filterProperties);
+ component.setSubstitutionFilter(subFilter);
+
+ Map<String, String[]> substitutionMappingMap = new HashMap<>();
+ String[] array = {"value1", "value2"};
+ substitutionMappingMap.put("key", array);
+
+ when(capabilityRequirementConverter.convertSubstitutionMappingCapabilities(anyMap(),
+ any(Component.class))).thenReturn(Either.left(substitutionMappingMap));
+
+ when(capabilityRequirementConverter.convertSubstitutionMappingRequirements(any(Component.class), anyMap()))
+ .thenReturn(Either.left(Collections.emptyMap()));
+
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(new HashMap<>()));
+
+ when(inputConverter.convertInputs(anyList(), anyMap())).thenReturn(new HashMap<>());
+
+ when(groupExportParser.getGroups(component)).thenReturn(null);
+
+ final Map<String, ToscaProperty> map = new HashMap<>();
+ map.put("mock", new ToscaProperty());
+ doReturn(map).when(outputConverter).convert(any(), any());
+
+ // test component contains group
+ final var result = Deencapsulation.invoke(testSubject, "convertToscaTemplate", component, toscaNode, false);
+ assertNotNull(result);
+ }
+
+ @Test
void testConvertToscaTemplateWhenComponentIsService() throws Exception {
Component component = getNewService();
ToscaTemplate toscaNode = new ToscaTemplate("");
@@ -717,6 +769,16 @@ class ToscaExportHandlerTest extends BaseConfDependent {
instance.setUniqueId("uuid");
instance.setDescription("desc");
instance.setSourceModelUid("sourceModelUid");
+ instance.setMinOccurrences("0");
+ instance.setMaxOccurrences("10");
+ instance.setInstanceCount("{get_input:int}");
+
+ RequirementNodeFilterCapabilityDataDefinition filterCap = new RequirementNodeFilterCapabilityDataDefinition();
+ ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> instanceFilterCapabilities = new ListDataDefinition<>();
+ instanceFilterCapabilities.add(filterCap);
+ CINodeFilterDataDefinition nodeFilter = new CINodeFilterDataDefinition();
+ nodeFilter.setCapabilities(instanceFilterCapabilities);
+ instance.setNodeFilter(nodeFilter);
componentInstances.add(instance);
@@ -784,6 +846,18 @@ class ToscaExportHandlerTest extends BaseConfDependent {
}
@Test
+ void test () {
+ Component component = getNewService();
+ component.setModel("test");
+
+ when(modelOperation.findAllModelImports("test", true)).thenReturn(new ArrayList<>());
+
+ final Either<ToscaRepresentation, ToscaError> toscaRepresentationToscaErrorEither = testSubject.exportComponent(component, false);
+ assertNotNull(toscaRepresentationToscaErrorEither);
+ assertTrue(toscaRepresentationToscaErrorEither.isRight());
+ }
+
+ @Test
void testConvertWithBooleanNodeFilterWhenComponentIsService() {
final Component component = getNewService();
final List<ComponentInstance> componentInstances = new ArrayList<>();