summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org
diff options
context:
space:
mode:
authorshiria <shiri.amichai@amdocs.com>2019-03-17 09:41:10 +0200
committerAvi Gaffa <avi.gaffa@amdocs.com>2019-03-17 09:38:46 +0000
commit532b6da80ebd6977aa27300ab3cbe7b21d88609a (patch)
treed9f61c8f68450815b05da841d5892a28cc4a7e03 /openecomp-be/lib/openecomp-tosca-lib/src/test/java/org
parent1b6adf74f6a436978a8afd8c68a453bde9956589 (diff)
Load TOSCA package into Tosca model object
Change-Id: I24360bcd988df48359eb6092f6a80e989e35f026 Issue-ID: SDC-2192 Signed-off-by: shiria <shiri.amichai@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/test/java/org')
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java165
1 files changed, 164 insertions, 1 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java
index 2814f0143b..4962f243ca 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java
@@ -30,7 +30,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-
+import org.apache.commons.io.IOUtils;
+import org.hamcrest.core.StringContains;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -61,6 +62,7 @@ import org.onap.sdc.tosca.datatypes.model.Status;
import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping;
import org.onap.sdc.tosca.datatypes.model.TopologyTemplate;
import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
+import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.SdcRuntimeException;
import org.openecomp.sdc.tosca.TestUtil;
@@ -1104,5 +1106,166 @@ public class ToscaAnalyzerServiceImplTest {
public void testGetFlatEntityThrowsExceptionIncorrectSwitchProvided() {
toscaAnalyzerService.getFlatEntity(ToscaElementTypes.RELATIONSHIP_TYPE, null, null, null);
}
+
+ @Test
+ public void getFullPathFromRelativePathBackwards(){
+ ToscaAnalyzerServiceImpl toscaAnalyzerServiceImpl = new ToscaAnalyzerServiceImpl();
+ String importFile = "../ImportedServiceTemplate";
+ ServiceTemplate mainServiceTemplate = new ServiceTemplate();
+ ServiceTemplate importedServiceTemplate = new ServiceTemplate();
+ ToscaServiceModel toscaServiceModel = new ToscaServiceModel();
+ toscaServiceModel.addServiceTemplate("Definitions/service/MainServiceTemplate", mainServiceTemplate);
+ toscaServiceModel.addServiceTemplate("Definitions/ImportedServiceTemplate", importedServiceTemplate);
+
+ String fileNameForImport = toscaAnalyzerServiceImpl
+ .fetchFullFileNameForImport(importFile, null, mainServiceTemplate, toscaServiceModel);
+ assertEquals("Definitions/ImportedServiceTemplate", fileNameForImport);
+ }
+
+ @Test
+ public void getFullPathFromRelativePathForwards(){
+ ToscaAnalyzerServiceImpl toscaAnalyzerServiceImpl = new ToscaAnalyzerServiceImpl();
+ String importFile = "services/ImportedServiceTemplate";
+ ServiceTemplate mainServiceTemplate = new ServiceTemplate();
+ ServiceTemplate importedServiceTemplate = new ServiceTemplate();
+ ToscaServiceModel toscaServiceModel = new ToscaServiceModel();
+ toscaServiceModel.addServiceTemplate("Definitions/MainServiceTemplate", mainServiceTemplate);
+ toscaServiceModel.addServiceTemplate("Definitions/services/ImportedServiceTemplate", importedServiceTemplate);
+
+ String fileNameForImport = toscaAnalyzerServiceImpl
+ .fetchFullFileNameForImport(importFile, null, mainServiceTemplate, toscaServiceModel);
+ assertEquals("Definitions/services/ImportedServiceTemplate", fileNameForImport);
+ }
+
+ @Test
+ public void getFullPathFromRelativePathMix(){
+ ToscaAnalyzerServiceImpl toscaAnalyzerServiceImpl = new ToscaAnalyzerServiceImpl();
+ String importFile = "../types/global/ImportedServiceTemplate";
+ ServiceTemplate mainServiceTemplate = new ServiceTemplate();
+ ServiceTemplate importedServiceTemplate = new ServiceTemplate();
+ ToscaServiceModel toscaServiceModel = new ToscaServiceModel();
+ toscaServiceModel.addServiceTemplate("Definitions/services/MainServiceTemplate", mainServiceTemplate);
+ toscaServiceModel.addServiceTemplate("Definitions/types/global/ImportedServiceTemplate", importedServiceTemplate);
+
+ String fileNameForImport = toscaAnalyzerServiceImpl
+ .fetchFullFileNameForImport(importFile, null, mainServiceTemplate, toscaServiceModel);
+ assertEquals("Definitions/types/global/ImportedServiceTemplate", fileNameForImport);
+ }
+
+ @Test
+ public void testConvertToscaImport() throws Exception {
+ String inputResourceName = "/mock/analyzerService/importConvertTest.yml";
+ byte[] uploadedFileData = IOUtils.toByteArray(this.getClass().getResource(inputResourceName));
+
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ ToscaAnalyzerServiceImpl toscaAnalyzerServiceImpl = new ToscaAnalyzerServiceImpl();
+ String convertServiceTemplateImport =
+ toscaAnalyzerServiceImpl.convertServiceTemplateImport(toscaExtensionYamlUtil, uploadedFileData);
+
+ Assert.assertNotNull(convertServiceTemplateImport);
+ ServiceTemplate serviceTemplate =
+ new YamlUtil().yamlToObject(convertServiceTemplateImport, ServiceTemplate.class);
+ Assert.assertNotNull(serviceTemplate.getImports().get(0).get("data"));
+ Assert.assertNotNull(serviceTemplate.getImports().get(1).get("artifacts"));
+ Assert.assertNotNull(serviceTemplate.getImports().get(2).get("capabilities"));
+ Assert.assertNotNull(serviceTemplate.getImports().get(3).get("api_interfaces"));
+ Assert.assertNotNull(serviceTemplate.getImports().get(4).get("api_util_relationships"));
+ Assert.assertNotNull(serviceTemplate.getImports().get(5).get("common"));
+ Assert.assertNotNull(serviceTemplate.getImports().get(6).get("api_util"));
+ Assert.assertNotNull(serviceTemplate.getImports().get(7).get("relationshipsExt"));
+ }
+
+ @Test
+ public void loadValidToscaYamlFileTest() throws Exception {
+ String inputResourceName = "/mock/analyzerService/ServiceTemplateInterfaceInheritanceTest.yaml";
+ byte[] uploadedFileData = IOUtils.toByteArray(this.getClass().getResource(inputResourceName));
+
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ ToscaAnalyzerServiceImpl toscaAnalyzerServiceImpl = new ToscaAnalyzerServiceImpl();
+ ToscaServiceModel toscaServiceModel = new ToscaServiceModel();
+ String fileFullName = "Definition/service.yaml";
+ toscaAnalyzerServiceImpl
+ .loadToscaYamlFile(toscaServiceModel, toscaExtensionYamlUtil, uploadedFileData, fileFullName);
+ Assert.assertNotNull(toscaServiceModel.getServiceTemplate(fileFullName));
+ }
+
+ @Test
+ public void loadInvalidToscaYamlFileTest() throws Exception {
+ thrown.expect(CoreException.class);
+ thrown.expectMessage(StringContains.containsString(
+ "Tosca file 'Definition/service.yaml' is not following TOSCA spec, can't be parsed. Related error - "));
+ String inputResourceName = "/mock/analyzerService/invalidToscaFileTest.yml";
+ byte[] uploadedFileData = IOUtils.toByteArray(this.getClass().getResource(inputResourceName));
+
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ ToscaAnalyzerServiceImpl toscaAnalyzerServiceImpl = new ToscaAnalyzerServiceImpl();
+ ToscaServiceModel toscaServiceModel = new ToscaServiceModel();
+ String fileFullName = "Definition/service.yaml";
+ toscaAnalyzerServiceImpl
+ .loadToscaYamlFile(toscaServiceModel, toscaExtensionYamlUtil, uploadedFileData, fileFullName);
+ }
+
+ @Test
+ public void loadValidToscaMetadataFileTest() throws Exception {
+ String inputResourceName = "/mock/analyzerService/validTosca.meta";
+ byte[] uploadedFileData = IOUtils.toByteArray(this.getClass().getResource(inputResourceName));
+
+ ToscaAnalyzerServiceImpl toscaAnalyzerServiceImpl = new ToscaAnalyzerServiceImpl();
+ ToscaServiceModel toscaServiceModel = new ToscaServiceModel();
+ toscaAnalyzerServiceImpl
+ .loadToscaMetaFile(toscaServiceModel, uploadedFileData);
+ Assert.assertEquals("Definitions/service-Service2-template.yml",
+ toscaServiceModel.getEntryDefinitionServiceTemplate());
+ }
+
+ @Test
+ public void loadInvalidToscaMetadataFileTest() throws Exception {
+ thrown.expect(CoreException.class);
+ thrown.expectMessage("Missing data - TOSCA.meta file must include 'Entry-Definitions' data.");
+ String inputResourceName = "/mock/analyzerService/invalidTosca.meta";
+ byte[] uploadedFileData = IOUtils.toByteArray(this.getClass().getResource(inputResourceName));
+
+ ToscaAnalyzerServiceImpl toscaAnalyzerServiceImpl = new ToscaAnalyzerServiceImpl();
+ ToscaServiceModel toscaServiceModel = new ToscaServiceModel();
+ toscaAnalyzerServiceImpl
+ .loadToscaMetaFile(toscaServiceModel, uploadedFileData);
+ }
+
+ @Test
+ public void loadToscaCsarPackageWithMetadataTest() throws Exception {
+ String inputResourceName = "/mock/analyzerService/toscaPackageWithMetadata.csar";
+ byte[] uploadedFileData = IOUtils.toByteArray(this.getClass().getResource(inputResourceName));
+ //InputStream toscaPackage = new ByteArrayInputStream(uploadedFileData);
+ ToscaAnalyzerServiceImpl toscaAnalyzerServiceImpl = new ToscaAnalyzerServiceImpl();
+ ToscaServiceModel toscaServiceModel = toscaAnalyzerServiceImpl.loadToscaCsarPackage(uploadedFileData);
+ assertNotNull(toscaServiceModel);
+ assertEquals("Definitions/service.yaml", toscaServiceModel.getEntryDefinitionServiceTemplate());
+ assertEquals(10, toscaServiceModel.getServiceTemplates().size());
+ assertEquals(1, toscaServiceModel.getArtifactFiles().getFiles().size());
+ }
+
+ @Test
+ public void loadToscaCsarPackageWithoutMetadataTest() throws Exception {
+ String inputResourceName = "/mock/analyzerService/toscaPackageWithoutMetadata.csar";
+ byte[] uploadedFileData = IOUtils.toByteArray(this.getClass().getResource(inputResourceName));
+ //InputStream toscaPackage = new ByteArrayInputStream(uploadedFileData);
+ ToscaAnalyzerServiceImpl toscaAnalyzerServiceImpl = new ToscaAnalyzerServiceImpl();
+ ToscaServiceModel toscaServiceModel = toscaAnalyzerServiceImpl.loadToscaCsarPackage(uploadedFileData);
+ assertNotNull(toscaServiceModel);
+ assertEquals("service.yaml", toscaServiceModel.getEntryDefinitionServiceTemplate());
+ assertEquals(10, toscaServiceModel.getServiceTemplates().size());
+ assertEquals(1, toscaServiceModel.getArtifactFiles().getFiles().size());
+ }
+
+ @Test
+ public void loadInvalidToscaCsarPackageWithoutEntryDefTest() throws Exception {
+ thrown.expect(CoreException.class);
+ thrown.expectMessage("TOSCA Entry Definition was not found");
+ String inputResourceName = "/mock/analyzerService/toscaPackageInvalidEntryDef.csar";
+ byte[] uploadedFileData = IOUtils.toByteArray(this.getClass().getResource(inputResourceName));
+ //InputStream toscaPackage = new ByteArrayInputStream(uploadedFileData);
+ ToscaAnalyzerServiceImpl toscaAnalyzerServiceImpl = new ToscaAnalyzerServiceImpl();
+ toscaAnalyzerServiceImpl.loadToscaCsarPackage(uploadedFileData);
+ }
}