summaryrefslogtreecommitdiffstats
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/ToscaFileOutputServiceCsarImplTest.java276
1 files changed, 148 insertions, 128 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImplTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImplTest.java
index 10aabe6741..92374f57fe 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImplTest.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImplTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,153 +20,173 @@
package org.openecomp.sdc.tosca.services.impl;
-import org.junit.Assert;
-import org.junit.Test;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.openecomp.core.utilities.file.FileContentHandler;
-import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-import org.openecomp.sdc.tosca.services.ToscaConstants;
-import org.openecomp.sdc.tosca.services.ToscaUtil;
-
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
-public class ToscaFileOutputServiceCsarImplTest {
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.MockitoAnnotations;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.tosca.services.ToscaUtil;
- @Test
- public void testCreationMetaFile() {
- ToscaFileOutputServiceCsarImpl toscaFileOutputServiceCSARImpl =
- new ToscaFileOutputServiceCsarImpl();
- String createdMeta = toscaFileOutputServiceCSARImpl.createMetaFile("entryFile.yaml");
- String expectedMeta =
- "TOSCA-Meta-File-Version: 1.0\n" +
- "CSAR-Version: 1.1\n" +
- "Created-By: ASDC Onboarding portal\n" +
- "Entry-Definitions: Definitions" + File.separator + "entryFile.yaml";
- Assert.assertEquals(createdMeta.replaceAll("\\s+", ""), expectedMeta.replaceAll("\\s+", ""));
- }
-
- @Test
- public void testCSARFileCreationWithExternalArtifacts() throws IOException {
- ToscaFileOutputServiceCsarImpl toscaFileOutputServiceCSARImpl =
- new ToscaFileOutputServiceCsarImpl();
- ServiceTemplate mainServiceTemplate = new ServiceTemplate();
- Map<String, String> metadata1 = new HashMap<>();
- metadata1.put("Template_author", "OPENECOMP");
- metadata1.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME,"ST1");
- metadata1.put("Template_version", "1.0.0");
- mainServiceTemplate.setMetadata(metadata1);
- mainServiceTemplate.setTosca_definitions_version("tosca_simple_yaml_1_0_0");
- mainServiceTemplate.setDescription("testing desc tosca service template");
-
- ServiceTemplate additionalServiceTemplate = new ServiceTemplate();
- Map<String, String> metadata2 = new HashMap<>();
- metadata2.put("Template_author", "OPENECOMP");
- metadata2.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, "ST2");
- metadata2.put("Template_version", "1.0.0");
- additionalServiceTemplate.setTosca_definitions_version("tosca_simple_yaml_1_0_0");
- additionalServiceTemplate.setDescription("testing desc tosca service template");
- additionalServiceTemplate.setMetadata(metadata2);
-
- Map<String, ServiceTemplate> definitionsInput = new HashMap<>();
- definitionsInput
- .put(ToscaUtil.getServiceTemplateFileName(mainServiceTemplate), mainServiceTemplate);
- definitionsInput.put(ToscaUtil.getServiceTemplateFileName(additionalServiceTemplate),
- additionalServiceTemplate);
-
-
- Map<String, byte[]> dummyHeatArtifacts = new HashMap<>();
- String file1Content = "this is file number 1";
- String file2Content = "this is file number 2";
- String file1 = "file1.xml";
- dummyHeatArtifacts.put(file1, file1Content.getBytes());
- String file2 = "file2.yml";
- dummyHeatArtifacts.put(file2, file2Content.getBytes());
-
-
- FileContentHandler heatFiles = new FileContentHandler();
- heatFiles.putAll(dummyHeatArtifacts);
- Map<String, byte[]> licenseArtifacts = new HashMap<>();
-
- FileContentHandler licenseArtifactsFiles = new FileContentHandler();
-
- licenseArtifacts.put(
- ToscaFileOutputServiceCsarImpl.EXTERNAL_ARTIFACTS_FOLDER_NAME + File.separator +
- "license-file-1.xml", file1Content.getBytes());
- licenseArtifacts.put(
- ToscaFileOutputServiceCsarImpl.EXTERNAL_ARTIFACTS_FOLDER_NAME + File.separator +
- "license-file-2.xml", file1Content.getBytes());
-
- licenseArtifactsFiles.putAll(licenseArtifacts);
-
- byte[] csarFile = toscaFileOutputServiceCSARImpl.createOutputFile(
- new ToscaServiceModel(heatFiles, definitionsInput,
- ToscaUtil.getServiceTemplateFileName(mainServiceTemplate)), licenseArtifactsFiles);
-
- File file = File.createTempFile("resultFile", "zip");
- try (FileOutputStream fos = new FileOutputStream(file)) {
- fos.write(csarFile);
- }
+public class ToscaFileOutputServiceCsarImplTest {
- try (ZipFile zipFile = new ZipFile(file)) {
+ @InjectMocks
+ private ToscaFileOutputServiceCsarImpl toscaFileOutputServiceCsarImpl;
- Enumeration<? extends ZipEntry> entries = zipFile.entries();
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+ }
- int count = 0;
- while (entries.hasMoreElements()) {
- count++;
- entries.nextElement();
- }
+ @Test
+ public void testCreationMetaFile() {
+ String createdMeta = toscaFileOutputServiceCsarImpl.createMetaFile("entryFile.yaml");
+ String expectedMeta =
+ "TOSCA-Meta-File-Version: 1.0\n" +
+ "CSAR-Version: 1.1\n" +
+ "Created-By: ASDC Onboarding portal\n" +
+ "Entry-Definitions: Definitions" + File.separator + "entryFile.yaml";
+ Assert.assertEquals(createdMeta.replaceAll("\\s+", ""), expectedMeta.replaceAll("\\s+", ""));
}
- Files.delete(Paths.get(file.getAbsolutePath()));
- }
-
- @Test
- public void testCSARFileCreation_noArtifacts() throws IOException {
- ToscaFileOutputServiceCsarImpl toscaFileOutputServiceCSARImpl =
- new ToscaFileOutputServiceCsarImpl();
- ServiceTemplate serviceTemplate = new ServiceTemplate();
- Map<String, String> metadata = new HashMap<>();
- metadata.put("Template_author", "OPENECOMP");
- metadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, "Test");
- metadata.put("Template_version", "1.0.0");
- serviceTemplate.setTosca_definitions_version("tosca_simple_yaml_1_0_0");
- serviceTemplate.setDescription("testing desc tosca service template");
- serviceTemplate.setMetadata(metadata);
- Map<String, ServiceTemplate> definitionsInput = new HashMap<>();
- String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
- definitionsInput.put(serviceTemplateFileName, serviceTemplate);
- byte[] csarFile = toscaFileOutputServiceCSARImpl
- .createOutputFile(new ToscaServiceModel(null, definitionsInput, serviceTemplateFileName),
- null);
-
-
- File file = File.createTempFile("resultFile", "zip");
- try (FileOutputStream fos = new FileOutputStream(file)) {
- fos.write(csarFile);
+ @Test
+ public void testCSARFileCreationWithExternalArtifacts() throws IOException {
+ ToscaFileOutputServiceCsarImpl toscaFileOutputServiceCSARImpl =
+ new ToscaFileOutputServiceCsarImpl();
+ ServiceTemplate mainServiceTemplate = new ServiceTemplate();
+ Map<String, String> metadata1 = new HashMap<>();
+ metadata1.put("Template_author", "OPENECOMP");
+ metadata1.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, "ST1");
+ metadata1.put("Template_version", "1.0.0");
+ mainServiceTemplate.setMetadata(metadata1);
+ mainServiceTemplate.setTosca_definitions_version("tosca_simple_yaml_1_0_0");
+ mainServiceTemplate.setDescription("testing desc tosca service template");
+
+ ServiceTemplate additionalServiceTemplate = new ServiceTemplate();
+ Map<String, String> metadata2 = new HashMap<>();
+ metadata2.put("Template_author", "OPENECOMP");
+ metadata2.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, "ST2");
+ metadata2.put("Template_version", "1.0.0");
+ additionalServiceTemplate.setTosca_definitions_version("tosca_simple_yaml_1_0_0");
+ additionalServiceTemplate.setDescription("testing desc tosca service template");
+ additionalServiceTemplate.setMetadata(metadata2);
+
+ Map<String, ServiceTemplate> definitionsInput = new HashMap<>();
+ definitionsInput
+ .put(ToscaUtil.getServiceTemplateFileName(mainServiceTemplate), mainServiceTemplate);
+ definitionsInput.put(ToscaUtil.getServiceTemplateFileName(additionalServiceTemplate),
+ additionalServiceTemplate);
+
+
+ Map<String, byte[]> dummyHeatArtifacts = new HashMap<>();
+ String file1Content = "this is file number 1";
+ String file2Content = "this is file number 2";
+ String file1 = "file1.xml";
+ dummyHeatArtifacts.put(file1, file1Content.getBytes());
+ String file2 = "file2.yml";
+ dummyHeatArtifacts.put(file2, file2Content.getBytes());
+
+
+ FileContentHandler heatFiles = new FileContentHandler();
+ heatFiles.putAll(dummyHeatArtifacts);
+ Map<String, byte[]> licenseArtifacts = new HashMap<>();
+
+ FileContentHandler licenseArtifactsFiles = new FileContentHandler();
+
+ licenseArtifacts.put(
+ ToscaFileOutputServiceCsarImpl.EXTERNAL_ARTIFACTS_FOLDER_NAME + File.separator +
+ "license-file-1.xml", file1Content.getBytes());
+ licenseArtifacts.put(
+ ToscaFileOutputServiceCsarImpl.EXTERNAL_ARTIFACTS_FOLDER_NAME + File.separator +
+ "license-file-2.xml", file1Content.getBytes());
+
+ licenseArtifactsFiles.putAll(licenseArtifacts);
+
+ byte[] csarFile = toscaFileOutputServiceCSARImpl.createOutputFile(
+ new ToscaServiceModel(heatFiles, definitionsInput,
+ ToscaUtil.getServiceTemplateFileName(mainServiceTemplate)), licenseArtifactsFiles);
+
+ File file = File.createTempFile("resultFile", "zip");
+ try (FileOutputStream fos = new FileOutputStream(file)) {
+ fos.write(csarFile);
+ }
+
+ try (ZipFile zipFile = new ZipFile(file)) {
+
+ Enumeration<? extends ZipEntry> entries = zipFile.entries();
+
+ while (entries.hasMoreElements()) {
+ entries.nextElement();
+ }
+ }
+
+ Files.delete(Paths.get(file.getAbsolutePath()));
}
- try (ZipFile zipFile = new ZipFile(file)) {
+ @Test
+ public void testCSARFileCreation_noArtifacts() throws IOException {
+ ServiceTemplate serviceTemplate = new ServiceTemplate();
+ Map<String, String> metadata = new HashMap<>();
+ metadata.put("Template_author", "OPENECOMP");
+ metadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, "Test");
+ metadata.put("Template_version", "1.0.0");
+ serviceTemplate.setTosca_definitions_version("tosca_simple_yaml_1_0_0");
+ serviceTemplate.setDescription("testing desc tosca service template");
+ serviceTemplate.setMetadata(metadata);
+ Map<String, ServiceTemplate> definitionsInput = new HashMap<>();
+ String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
+ definitionsInput.put(serviceTemplateFileName, serviceTemplate);
+ byte[] csarFile = toscaFileOutputServiceCsarImpl
+ .createOutputFile(new ToscaServiceModel(null, definitionsInput, serviceTemplateFileName),
+ null);
+
+
+ File file = File.createTempFile("resultFile", "zip");
+ try (FileOutputStream fos = new FileOutputStream(file)) {
+ fos.write(csarFile);
+ }
+
+ try (ZipFile zipFile = new ZipFile(file)) {
+
+ Enumeration<? extends ZipEntry> entries = zipFile.entries();
+
+ int count = 0;
+ while (entries.hasMoreElements()) {
+ count++;
+ entries.nextElement();
+ }
+ Assert.assertEquals(2, count);
+ }
+
+ Files.delete(Paths.get(file.getAbsolutePath()));
+ }
- Enumeration<? extends ZipEntry> entries = zipFile.entries();
+ @Test(expected = CoreException.class)
+ public void testCreateOutputFileEntryDefinitionServiceTemplateIsNull() {
+ ToscaServiceModel toscaServiceModel = new ToscaServiceModel();
+ toscaServiceModel.setServiceTemplates(Collections.emptyMap());
- int count = 0;
- while (entries.hasMoreElements()) {
- count++;
- entries.nextElement();
- }
- Assert.assertEquals(2, count);
+ toscaFileOutputServiceCsarImpl.createOutputFile(toscaServiceModel, null);
}
- Files.delete(Paths.get(file.getAbsolutePath()));
- }
+ @Test
+ public void testGetArtifactsFolderName() {
+ Assert.assertEquals("Artifacts", toscaFileOutputServiceCsarImpl.getArtifactsFolderName());
+ }
}