aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-lib/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/test')
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java165
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/importConvertTest.yml14
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/invalidTosca.meta6
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/invalidToscaFileTest.yml8
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscaPackageInvalidEntryDef.csarbin0 -> 13114 bytes
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscaPackageWithMetadata.csarbin0 -> 13070 bytes
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscaPackageWithoutMetadata.csarbin0 -> 12828 bytes
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/validTosca.meta7
8 files changed, 199 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);
+ }
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/importConvertTest.yml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/importConvertTest.yml
new file mode 100644
index 0000000000..08ddc3c206
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/importConvertTest.yml
@@ -0,0 +1,14 @@
+tosca_definitions_version: tosca_simple_yaml_1_1
+imports:
+- data.yml
+- artifacts.yml
+- capabilities.yml
+- ../../api/interfaces.yml
+- api/util/relationships.yml
+- common:
+ file: api/common.yaml
+- file: api/util.yaml
+- relationshipsExt.yml
+node_types:
+ tosca.nodes.Root:
+ description: The TOSCA Node Type all other TOSCA base Node Types derive from \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/invalidTosca.meta b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/invalidTosca.meta
new file mode 100644
index 0000000000..c9be3f4d2e
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/invalidTosca.meta
@@ -0,0 +1,6 @@
+TOSCA-Meta-File-Version: 1.0
+CSAR-Version: 1.1
+Created-By: Carlos Santana
+
+Name: csar.meta
+Content-Type: text/plain \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/invalidToscaFileTest.yml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/invalidToscaFileTest.yml
new file mode 100644
index 0000000000..f572a3a196
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/invalidToscaFileTest.yml
@@ -0,0 +1,8 @@
+tosca_definitions_version: tosca_simple_yaml_1_1
+imports:
+- data.yml
+- artifacts.yml
+node_types:
+ tosca.nodes.Root:
+ description: The TOSCA Node Type all other TOSCA base Node Types derive from
+ invalidFiled: invalid filed \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscaPackageInvalidEntryDef.csar b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscaPackageInvalidEntryDef.csar
new file mode 100644
index 0000000000..02c2caf555
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscaPackageInvalidEntryDef.csar
Binary files differ
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscaPackageWithMetadata.csar b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscaPackageWithMetadata.csar
new file mode 100644
index 0000000000..e844509c20
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscaPackageWithMetadata.csar
Binary files differ
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscaPackageWithoutMetadata.csar b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscaPackageWithoutMetadata.csar
new file mode 100644
index 0000000000..0256cc9797
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/toscaPackageWithoutMetadata.csar
Binary files differ
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/validTosca.meta b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/validTosca.meta
new file mode 100644
index 0000000000..8eba903cd8
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/validTosca.meta
@@ -0,0 +1,7 @@
+TOSCA-Meta-File-Version: 1.0
+CSAR-Version: 1.1
+Created-By: Carlos Santana
+Entry-Definitions: Definitions/service-Service2-template.yml
+
+Name: csar.meta
+Content-Type: text/plain \ No newline at end of file