summaryrefslogtreecommitdiffstats
path: root/csarvalidation/src/test
diff options
context:
space:
mode:
authorAvinashS <avinash.s@huawei.com>2017-10-11 11:48:18 +0530
committerAvinashS <avinash.s@huawei.com>2017-10-11 11:48:18 +0530
commit524c870ae13b75bcd7c895738d9580073a13551d (patch)
tree40c29d89b973c60a1cd61734cc16d01aa820afd8 /csarvalidation/src/test
parentf745139f2baa56bce2d0b0ce05810a1061ff3268 (diff)
Enhance UT.
Add UT for delete directory/file Change-Id: I1294b94ab69844dd719c6d9b4b5066581e07ea91 IssueId: VNFSDK-108 Signed-off-by: AvinashS <avinash.s@huawei.com>
Diffstat (limited to 'csarvalidation/src/test')
-rw-r--r--csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java79
-rw-r--r--csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/ValidationExceptionTest.java48
2 files changed, 121 insertions, 6 deletions
diff --git a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java b/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java
index 7eccb7a..9e0500d 100644
--- a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java
+++ b/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java
@@ -17,10 +17,19 @@ package org.onap.validation.csarvalidationtest;
import org.junit.Test;
import org.onap.validation.csar.CsarValidator;
-
+import org.onap.validation.csar.FileUtil;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -38,15 +47,25 @@ public class CsarValidatorTest {
private String csarFile2 = classLoader.getResource("sample2.csar").getFile();
String sample2 = System.getProperty("file.separator") + csarFile2.substring(1);
String packageId2 = UUID.randomUUID().toString();
-
-
+/*
+ private String csarFile3 = classLoader.getResource("sample4.csar").getFile();
+ String sample3 = System.getProperty("file.separator") + csarFile3.substring(1);
+ String packageId3 = UUID.randomUUID().toString(); */
@Test
public void testAll() {
CsarValidator csarValidator = new CsarValidator(packageId, dir2);
testValidateCsar(csarValidator);
CsarValidator csarValidator2 = new CsarValidator(packageId2, sample2);
+ // CsarValidator csarValidator3 = new CsarValidator(packageId3, sample3);
testValidateCsar(csarValidator2);
+ String dir3 = dir2.replace(".csar", "");
+ String dir4 = sample2.replace(".csar", "");
+ // String dir5 = sample3.replace(".csar", "");
+ boolean result = FileUtil.deleteDirectory(dir3);
+ boolean result1 = FileUtil.deleteDirectory(dir4);
+ //boolean result2 = FileUtil.deleteDirectory(dir5);
+ assertEquals(true, result == true && result1 ==true);
}
@Test
@@ -59,10 +78,58 @@ public class CsarValidatorTest {
CsarValidator csarValidator2 = new CsarValidator(packageId2, sample2);
testValidateCsarIntegrity(csarValidator2);
testValidateToscaMeta(csarValidator2);
- testValidateMainService(csarValidator2); //Rel1 specific test case
+ testValidateMainService(csarValidator2);
+ //Rel1 specific test case
+ String dir3 = dir2.replace(".csar", "");
+ String dir4 = sample2.replace(".csar", "");
+ boolean result = FileUtil.deleteDirectory(dir3);
+ boolean result1 = FileUtil.deleteDirectory(dir4);
+ assertEquals(true, result == true && result1 ==true);
}
-
-
+ @Test
+ public void testCloseInputStream() {
+ InputStream dir = null;
+ FileUtil.closeInputStream(dir);
+ assertTrue(true);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testReadJsonDatafFromFile() {
+ FileUtil.readJsonDatafFromFile(dir2, null);
+ }
+
+ @Test
+ public void testCloseZipFile() throws ZipException, IOException {
+ File file = new File(dir2);
+ ZipFile dir1 = new ZipFile(file);
+ FileUtil.closeZipFile(dir1);
+ assertTrue(true);
+ }
+ @Test
+ public void testCloseFileStream() throws FileNotFoundException {
+ FileInputStream dir3 = new FileInputStream(dir2);
+ FileUtil.closeFileStream(dir3 );
+ }
+ @Test
+ public void testCloseOutptutStream() {
+ OutputStream dir4 = new OutputStream() {
+
+ @Override
+ public void write(int b) throws IOException {
+
+ }
+ };
+ FileUtil.closeOutputStream(dir4);
+ }
+
+ /* @Test
+ public void testDeleteDirectory() throws IOException {
+ String dir4 = dir2.replace(".csar", "");
+ String dir3 = sample2.replace(".csar", "");
+ boolean result = FileUtil.deleteDirectory(dir3);
+ boolean result1 = FileUtil.deleteDirectory(dir3);
+ assertEquals(true, result == true && result1 ==true);
+ }*/
private void testValidateCsarMeta(CsarValidator cv) {
boolean result = cv.validateCsarMeta();
diff --git a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/ValidationExceptionTest.java b/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/ValidationExceptionTest.java
new file mode 100644
index 0000000..dfbd32d
--- /dev/null
+++ b/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/ValidationExceptionTest.java
@@ -0,0 +1,48 @@
+/**
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.validation.csarvalidationtest;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.onap.validation.csar.ErrorCodes;
+import org.onap.validation.csar.ValidationException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class ValidationExceptionTest {
+ ValidationException validationException = new ValidationException();
+ @Test
+ public void testWrappedInfoThrowableErrorCodes() {
+ Throwable ex = new IOException();
+ ValidationException result = validationException.wrappedInfo(ex , ErrorCodes.FILE_IO);
+ assertTrue(true);
+ }
+ @Test
+ public void testWrappedInfoThrowableErrorCodes1() {
+ Throwable ex = new ValidationException();
+ ValidationException result = validationException.wrappedInfo(ex , ErrorCodes.FILE_IO);
+ assertTrue(true);
+ }
+ @Test
+ public void testWrappedInfoThrowableErrorCodes2() {
+ Throwable ex = new ValidationException();
+ ValidationException result = validationException.wrappedInfo(ex , null);
+ assertTrue(true);
+ }
+}