diff options
author | Dmitry Puzikov <d.puzikov2@partner.samsung.com> | 2020-04-03 17:40:28 +0200 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2020-04-07 09:52:41 +0000 |
commit | 2ea2a56aed979ea94cf65f7fefdae09d1f95506b (patch) | |
tree | 6f25055d1d7232d38e863332484a92509f24517f /openecomp-be | |
parent | e052e9b0cc7d30f2fb4bada0a3e75e2c4d0e2f73 (diff) |
More tests added
Change-Id: I4b6ec51eb13d3553b308f794fb22b7761993f0ab
Issue-ID: SDC-2869
Signed-off-by: Dmitry Puzikov <d.puzikov2@partner.samsung.com>
Diffstat (limited to 'openecomp-be')
-rw-r--r-- | openecomp-be/lib/openecomp-common-lib/src/test/java/org/openecomp/sdc/common/utils/CommonUtilTest.java | 87 | ||||
-rw-r--r-- | openecomp-be/lib/openecomp-common-lib/src/test/resources/valid.csar | bin | 0 -> 330 bytes | |||
-rw-r--r-- | openecomp-be/lib/openecomp-common-lib/src/test/resources/valid.zip | bin | 0 -> 330 bytes | |||
-rw-r--r-- | openecomp-be/lib/openecomp-common-lib/src/test/resources/valid_zip_with_dir.zip | bin | 0 -> 474 bytes | |||
-rw-r--r-- | openecomp-be/lib/openecomp-common-lib/src/test/resources/valid_zip_with_not_yaml_file.zip | bin | 0 -> 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 Binary files differnew file mode 100644 index 0000000000..b74c27b3ef --- /dev/null +++ b/openecomp-be/lib/openecomp-common-lib/src/test/resources/valid.csar 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 Binary files differnew file mode 100644 index 0000000000..b74c27b3ef --- /dev/null +++ b/openecomp-be/lib/openecomp-common-lib/src/test/resources/valid.zip 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 Binary files differnew file mode 100644 index 0000000000..4fcc17d3ce --- /dev/null +++ b/openecomp-be/lib/openecomp-common-lib/src/test/resources/valid_zip_with_dir.zip 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 Binary files differnew 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 |