aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Puzikov <d.puzikov2@partner.samsung.com>2020-04-03 17:40:28 +0200
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-04-07 09:52:41 +0000
commit2ea2a56aed979ea94cf65f7fefdae09d1f95506b (patch)
tree6f25055d1d7232d38e863332484a92509f24517f
parente052e9b0cc7d30f2fb4bada0a3e75e2c4d0e2f73 (diff)
More tests added
Change-Id: I4b6ec51eb13d3553b308f794fb22b7761993f0ab Issue-ID: SDC-2869 Signed-off-by: Dmitry Puzikov <d.puzikov2@partner.samsung.com>
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/test/java/org/openecomp/sdc/common/utils/CommonUtilTest.java87
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/test/resources/valid.csarbin0 -> 330 bytes
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/test/resources/valid.zipbin0 -> 330 bytes
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/test/resources/valid_zip_with_dir.zipbin0 -> 474 bytes
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/test/resources/valid_zip_with_not_yaml_file.zipbin0 -> 490 bytes
5 files changed, 87 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-common-lib/src/test/java/org/openecomp/sdc/common/utils/CommonUtilTest.java b/openecomp-be/lib/openecomp-common-lib/src/test/java/org/openecomp/sdc/common/utils/CommonUtilTest.java
index 119616a9be..e08238aa1f 100644
--- a/openecomp-be/lib/openecomp-common-lib/src/test/java/org/openecomp/sdc/common/utils/CommonUtilTest.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/test/java/org/openecomp/sdc/common/utils/CommonUtilTest.java
@@ -16,15 +16,30 @@
package org.openecomp.sdc.common.utils;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.fail;
import static org.onap.sdc.tosca.services.CommonUtil.DEFAULT;
import static org.onap.sdc.tosca.services.CommonUtil.UNDERSCORE_DEFAULT;
import static org.testng.Assert.assertTrue;
+import com.google.common.io.Files;
+import java.io.File;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.zip.exception.ZipException;
import org.testng.annotations.Test;
public class CommonUtilTest {
+ private static final String VALID_ZIP_FILE_PATH = "src/test/resources/valid.zip";
+ private static final String VALID_CSAR_FILE_PATH = "src/test/resources/valid.csar";
+ private static final String VALID_ZIP_WITH_NOT_YAML_FILE_PATH = "src/test/resources/valid_zip_with_not_yaml_file.zip";
+ private static final String VALID_ZIP_WITH_DIR_FILE_PATH = "src/test/resources/valid_zip_with_dir.zip";
@Test
public void testGetObjectAsMap() {
@@ -33,4 +48,76 @@ public class CommonUtilTest {
assertTrue(CommonUtil.getObjectAsMap(obj).containsKey(UNDERSCORE_DEFAULT));
}
+ @Test
+ public void testValidateAndUploadFileContentZip() throws IOException {
+ byte[] file = getFileAsBytes(VALID_ZIP_FILE_PATH);
+
+ FileContentHandler fch = CommonUtil.validateAndUploadFileContent(OnboardingTypesEnum.ZIP, file);
+
+ assertThat(fch, notNullValue(FileContentHandler.class));
+ assertThat(fch.containsFile("file.one.yaml"), is(true));
+ assertThat(fch.containsFile("file.two.yaml"), is(true));
+ }
+
+ @Test
+ public void testValidateAndUploadFileContentCsar() throws IOException {
+ byte[] file = getFileAsBytes(VALID_CSAR_FILE_PATH);
+
+ FileContentHandler fch = CommonUtil.validateAndUploadFileContent(OnboardingTypesEnum.CSAR, file);
+
+ assertThat(fch, notNullValue(FileContentHandler.class));
+ assertThat(fch.containsFile("file.one.yaml"), is(true));
+ assertThat(fch.containsFile("file.two.yaml"), is(true));
+ }
+
+ @Test(expectedExceptions={CoreException.class})
+ public void testValidateNoFolders() throws IOException {
+ byte[] file = getFileAsBytes(VALID_ZIP_WITH_DIR_FILE_PATH);
+
+ FileContentHandler fch = CommonUtil.validateAndUploadFileContent(OnboardingTypesEnum.ZIP, file);
+
+ fail("Should throw CoreException");
+ }
+
+ @Test
+ public void testGetZipContent() throws ZipException {
+ byte[] file = getFileAsBytes(VALID_ZIP_WITH_DIR_FILE_PATH);
+
+ FileContentHandler fch = CommonUtil.getZipContent(file);
+
+ assertThat(fch, notNullValue(FileContentHandler.class));
+ assertThat(fch.getFileList().size(), is(2));
+ assertThat(fch.getFolderList().size(), is(1));
+ }
+
+ @Test
+ public void testValidateAllFilesYaml() throws ZipException {
+ byte[] file = getFileAsBytes(VALID_ZIP_WITH_DIR_FILE_PATH);
+ FileContentHandler fch = CommonUtil.getZipContent(file);
+
+ boolean result = CommonUtil.validateAllFilesYml(fch);
+
+ assertThat(result, is(true));
+ }
+
+ @Test
+ public void testValidateNotAllFilesYaml() throws ZipException {
+ byte[] file = getFileAsBytes(VALID_ZIP_WITH_NOT_YAML_FILE_PATH);
+ FileContentHandler fch = CommonUtil.getZipContent(file);
+
+ boolean result = CommonUtil.validateAllFilesYml(fch);
+
+ assertThat(result, is(false));
+ }
+
+ private byte[] getFileAsBytes(String fileName) {
+ byte[] data = null;
+ try {
+ File file = new File(fileName);
+ data = Files.toByteArray(file);
+ } catch (IOException e) {
+ fail("Couldn't read test file");
+ }
+ return data;
+ }
}
diff --git a/openecomp-be/lib/openecomp-common-lib/src/test/resources/valid.csar b/openecomp-be/lib/openecomp-common-lib/src/test/resources/valid.csar
new file mode 100644
index 0000000000..b74c27b3ef
--- /dev/null
+++ b/openecomp-be/lib/openecomp-common-lib/src/test/resources/valid.csar
Binary files differ
diff --git a/openecomp-be/lib/openecomp-common-lib/src/test/resources/valid.zip b/openecomp-be/lib/openecomp-common-lib/src/test/resources/valid.zip
new file mode 100644
index 0000000000..b74c27b3ef
--- /dev/null
+++ b/openecomp-be/lib/openecomp-common-lib/src/test/resources/valid.zip
Binary files differ
diff --git a/openecomp-be/lib/openecomp-common-lib/src/test/resources/valid_zip_with_dir.zip b/openecomp-be/lib/openecomp-common-lib/src/test/resources/valid_zip_with_dir.zip
new file mode 100644
index 0000000000..4fcc17d3ce
--- /dev/null
+++ b/openecomp-be/lib/openecomp-common-lib/src/test/resources/valid_zip_with_dir.zip
Binary files differ
diff --git a/openecomp-be/lib/openecomp-common-lib/src/test/resources/valid_zip_with_not_yaml_file.zip b/openecomp-be/lib/openecomp-common-lib/src/test/resources/valid_zip_with_not_yaml_file.zip
new file mode 100644
index 0000000000..aded0bfba6
--- /dev/null
+++ b/openecomp-be/lib/openecomp-common-lib/src/test/resources/valid_zip_with_not_yaml_file.zip
Binary files differ