diff options
author | AvinashS <avinash.s@huawei.com> | 2017-10-13 15:12:29 +0530 |
---|---|---|
committer | AvinashS <avinash.s@huawei.com> | 2017-10-13 15:12:29 +0530 |
commit | 0cd1abfbaf9ab74d294be36d863d6813f0243489 (patch) | |
tree | ab43a581c3b24ba1fef8d5d1f1ea0c184b0a407b | |
parent | 20b01aa1fb3d83ccaf7c0918cd722da4b26c038f (diff) |
Code cleanup
Change-Id: I02bac5f387273965a622723654895a27202f1182
IssueId: VNFSDK-108
Signed-off-by: AvinashS <avinash.s@huawei.com>
6 files changed, 130 insertions, 123 deletions
diff --git a/csarvalidation/src/main/java/org/onap/validation/csar/CsarUtil.java b/csarvalidation/src/main/java/org/onap/validation/csar/CsarUtil.java index f915168..850ccdd 100644 --- a/csarvalidation/src/main/java/org/onap/validation/csar/CsarUtil.java +++ b/csarvalidation/src/main/java/org/onap/validation/csar/CsarUtil.java @@ -23,17 +23,12 @@ import java.io.File; import java.io.FileOutputStream; import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.ArrayList; import java.util.HashMap; import java.util.Enumeration; -import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -145,7 +140,11 @@ public class CsarUtil { } } - + /** + * + * @param filePath + * @return HashMap<String, String> + */ public static HashMap<String, String> csarExtract(String filePath) { try { diff --git a/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java b/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java index 57870be..24969e7 100644 --- a/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java +++ b/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java @@ -21,7 +21,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.Paths; import static java.nio.charset.StandardCharsets.*; import java.util.*; @@ -42,11 +41,16 @@ public class CsarValidator { // Map of packageId and CSAR files private static HashMap<String, HashMap<String, String>> csar = new HashMap<String, HashMap<String, String>>(); private static String MAINSERV_TEMPLATE; - - public CsarValidator(String packageId, String csarWithPath) { - - try { - FileInputStream is = new FileInputStream(csarWithPath); + /** + * + * @param packageId + * @param csarWithPath + * @throws IOException + */ + public CsarValidator(String packageId, String csarWithPath) throws IOException { + + try(FileInputStream is = new FileInputStream(csarWithPath)) { + } catch (FileNotFoundException e2) { LOG.error("CSAR %s is not found! " +ErrorCodes.RESOURCE_MISSING); throw new ValidationException(ErrorCodes.RESOURCE_MISSING); @@ -63,15 +67,11 @@ public class CsarValidator { //deleteDirectory(); LOG.error("CSAR %s is not a valid CSAR/ZIP file! ", e1); } - - - try { - // vsl = new ValidatorSchemaLoader(); - } catch (Exception e) { - e.printStackTrace(); - } } - + /** + * + * @return true if all validations are successful + */ public static boolean validateCsar() { boolean vsm = validateCsarMeta(); @@ -87,7 +87,12 @@ public class CsarValidator { //In future return the status handler object instead. return false; } - + + /** + * + * @param csarWithPath + * @return true if csar integrity validation is successful + */ public static boolean validateCsarIntegrity(String csarWithPath) { try { @@ -106,7 +111,10 @@ public class CsarValidator { return false; } } - + /** + * + * @return true if csar meta data validation is successful + */ public static boolean validateCsarMeta() { String cfile = csarFiles.get(CommonConstants.CSAR_META); @@ -153,7 +161,10 @@ public class CsarValidator { return false; } - + /** + * + * @return true csar tosca meta validation is successful + */ public static boolean validateToscaMeta() { String cfile = csarFiles.get(CommonConstants.TOSCA_META); @@ -192,7 +203,10 @@ public class CsarValidator { } return false; } - + /** + * + * @return true csar validation is successful + */ public static boolean validateMainService() { String key = "metadata"; @@ -201,7 +215,8 @@ public class CsarValidator { List<String> mListMetadata = Arrays.asList("vnf_product_name", "vnf_provider_id", "vnf_package_version", "vnf_release_data_time"); - boolean mfResult = CheckEntryFor(CommonConstants.MAINSERV_MANIFEST, mListMetadata, key); + @SuppressWarnings("unused") + boolean mfResult = CheckEntryFor(CommonConstants.MAINSERV_MANIFEST, mListMetadata, key); String mrfFile = MAINSERV_TEMPLATE; if(!Paths.get(mrfFile).isAbsolute()){ mrfFile = csarFiles.get(FilenameUtils.getName(mrfFile)); @@ -224,8 +239,10 @@ public class CsarValidator { return null; } - private static boolean CheckEntryFor(String cFile, List<String> attributes, String key) { - String tFileWithPath; + @SuppressWarnings("unchecked") + private static boolean CheckEntryFor(String cFile, List<String> attributes, String key) { + @SuppressWarnings("unused") + String tFileWithPath; if (! Paths.get(cFile).isAbsolute()) { cFile = csarFiles.get(FilenameUtils.getName(cFile)); @@ -270,7 +287,6 @@ public class CsarValidator { .filter(attributes::contains) .collect(Collectors.toList()); - // System.out.println(result); if (lResult.size() == 0) { return false; } diff --git a/csarvalidation/src/main/java/org/onap/validation/csar/FileUtil.java b/csarvalidation/src/main/java/org/onap/validation/csar/FileUtil.java index c1b10fa..16faf2d 100644 --- a/csarvalidation/src/main/java/org/onap/validation/csar/FileUtil.java +++ b/csarvalidation/src/main/java/org/onap/validation/csar/FileUtil.java @@ -23,18 +23,11 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.io.Resources; - -import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.zip.ZipEntry; import java.util.zip.ZipFile; diff --git a/csarvalidation/src/main/java/org/onap/validation/csar/ValidationException.java b/csarvalidation/src/main/java/org/onap/validation/csar/ValidationException.java index 804b632..5a3230b 100644 --- a/csarvalidation/src/main/java/org/onap/validation/csar/ValidationException.java +++ b/csarvalidation/src/main/java/org/onap/validation/csar/ValidationException.java @@ -15,8 +15,6 @@ */ package org.onap.validation.csar; -import java.io.PrintStream; -import java.io.PrintWriter; import java.util.Map; import java.util.TreeMap; 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 782e521..826decb 100644 --- a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java +++ b/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java @@ -1,23 +1,23 @@ /** * Copyright 2017 Huawei Technologies Co., Ltd. - * <p> + * * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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 org.junit.Test; -import org.onap.validation.csar.CsarValidator; -import org.onap.validation.csar.FileUtil; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.io.File; import java.io.FileInputStream; @@ -30,9 +30,9 @@ 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; +import org.junit.Test; +import org.onap.validation.csar.CsarValidator; +import org.onap.validation.csar.FileUtil; public class CsarValidatorTest { @@ -59,30 +59,30 @@ public class CsarValidatorTest { private String csarFile5 = classLoader.getResource("sample2.csar").getFile(); String sample5 = System.getProperty("file.separator") + csarFile5.substring(1); String packageId5 = UUID.randomUUID().toString(); + @Test public void testAll() throws IOException, InterruptedException { CsarValidator csarValidator = new CsarValidator(packageId, sample1); - CsarValidator csarValidator2 = new CsarValidator(packageId2, sample2); - CsarValidator csarValidator3 = new CsarValidator(packageId3, sample3); - CsarValidator csarValidator4 = new CsarValidator(packageId4, sample4); - CsarValidator csarValidator5 = new CsarValidator(packageId5, sample5); testValidateCsar(csarValidator); + CsarValidator csarValidator2 = new CsarValidator(packageId2, sample2); testValidateCsar(csarValidator2); + CsarValidator csarValidator3 = new CsarValidator(packageId3, sample3); testValidateCsar(csarValidator3); + CsarValidator csarValidator4 = new CsarValidator(packageId4, sample4); testValidateCsar(csarValidator4); + CsarValidator csarValidator5 = new CsarValidator(packageId5, sample5); testValidateCsar(csarValidator5); String sample1Dir = sample1.replace(".csar", ""); - String sample2Dir = sample2.replace(".csar", ""); - String sample3Dir = sample3.replace(".csar", ""); - String sample4Dir = sample4.replace(".csar", ""); - String sample5Dir = sample5.replace(".csar", ""); - boolean result = FileUtil.deleteDirectory(sample1Dir); - boolean result1 = FileUtil.deleteDirectory(sample2Dir); - boolean result2 = FileUtil.deleteDirectory(sample3Dir); - boolean result3 = FileUtil.deleteDirectory(sample4Dir); - boolean result4 = FileUtil.deleteDirectory(sample5Dir); - System.out.println(result4); - assertEquals(true, result == true && result1 ==true && result2 == true && result3 == true && result4 == true); + String sample2Dir = sample2.replace(".csar", ""); + String sample3Dir = sample3.replace(".csar", ""); + String sample4Dir = sample4.replace(".csar", ""); + String sample5Dir = sample5.replace(".csar", ""); + boolean result = FileUtil.deleteDirectory(sample1Dir); + boolean result1 = FileUtil.deleteDirectory(sample2Dir); + boolean result2 = FileUtil.deleteDirectory(sample3Dir); + boolean result3 = FileUtil.deleteDirectory(sample4Dir); + boolean result4 = FileUtil.deleteDirectory(sample5Dir); + assertEquals(true, result == true && result1 == true && result2 == true && result3 == true && result4 == true); } @Test @@ -113,79 +113,82 @@ public class CsarValidatorTest { testValidateMainService(csarValidator5); //Rel1 specific test case String sample1Dir = sample1.replace(".csar", ""); - String sample2Dir = sample2.replace(".csar", ""); - String sample3Dir = sample3.replace(".csar", ""); - String sample4Dir = sample4.replace(".csar", ""); - String sample5Dir = sample5.replace(".csar", ""); - boolean result = FileUtil.deleteDirectory(sample1Dir); - boolean result1 = FileUtil.deleteDirectory(sample2Dir); - boolean result2 = FileUtil.deleteDirectory(sample3Dir); - boolean result3 = FileUtil.deleteDirectory(sample4Dir); - boolean result4 = FileUtil.deleteDirectory(sample5Dir); - assertEquals(true, result == true && result1 ==true && result2 == true && result3 == true && result4 == true); + String sample2Dir = sample2.replace(".csar", ""); + String sample3Dir = sample3.replace(".csar", ""); + String sample4Dir = sample4.replace(".csar", ""); + String sample5Dir = sample5.replace(".csar", ""); + boolean result = FileUtil.deleteDirectory(sample1Dir); + boolean result1 = FileUtil.deleteDirectory(sample2Dir); + boolean result2 = FileUtil.deleteDirectory(sample3Dir); + boolean result3 = FileUtil.deleteDirectory(sample4Dir); + boolean result4 = FileUtil.deleteDirectory(sample5Dir); + assertEquals(true, result == true && result1 == true && result2 == true && result3 == true && result4 == true); + } + + @Test + public void testCloseInputStream() { + InputStream dir = null; + FileUtil.closeInputStream(dir); + assertTrue(true); + } + + @Test(expected = IllegalArgumentException.class) + public void testReadJsonDatafFromFile() { + FileUtil.readJsonDatafFromFile(sample1, null); + } + + @Test + public void testCloseZipFile() throws ZipException, IOException { + File file = new File(sample1); + ZipFile dir1 = new ZipFile(file); + FileUtil.closeZipFile(dir1); + assertTrue(true); } + + @Test + public void testCloseFileStream() throws FileNotFoundException { + FileInputStream dir3 = new FileInputStream(sample1); + FileUtil.closeFileStream(dir3 ); + } + @Test - public void testCloseInputStream() { - InputStream dir = null; - FileUtil.closeInputStream(dir); - assertTrue(true); - } - - @Test(expected = IllegalArgumentException.class) - public void testReadJsonDatafFromFile() { - FileUtil.readJsonDatafFromFile(sample1, null); - } - - @Test - public void testCloseZipFile() throws ZipException, IOException { - File file = new File(sample1); - ZipFile dir1 = new ZipFile(file); - FileUtil.closeZipFile(dir1); - assertTrue(true); - } - @Test - public void testCloseFileStream() throws FileNotFoundException { - FileInputStream dir3 = new FileInputStream(sample1); - FileUtil.closeFileStream(dir3 ); - } - @Test - public void testCloseOutptutStream() { - OutputStream dir4 = new OutputStream() { - - @Override - public void write(int b) throws IOException { - - } - }; - FileUtil.closeOutputStream(dir4); - } + public void testCloseOutptutStream() { + OutputStream dir4 = new OutputStream() { + + @Override + public void write(int number) throws IOException { + + } + }; + FileUtil.closeOutputStream(dir4); + } private void testValidateCsarMeta(CsarValidator cv) { - boolean result = cv.validateCsarMeta(); + boolean result = CsarValidator.validateCsarMeta(); assertEquals(true, result == true); } private void testValidateCsarIntegrity(CsarValidator cv) { - boolean result = cv.validateCsarIntegrity(sample1); + boolean result = CsarValidator.validateCsarIntegrity(sample1); assertEquals(true, result == true); - } + } private void testValidateToscaMeta(CsarValidator cv) { - boolean result = cv.validateToscaMeta(); + boolean result = CsarValidator.validateToscaMeta(); assertEquals(true, result == true); } private void testValidateMainService(CsarValidator cv) { - boolean result = cv.validateMainService(); + boolean result = CsarValidator.validateMainService(); assertEquals(true, result == true); } private void testValidateCsar(CsarValidator cv) { - boolean result = cv.validateCsar(); + boolean result = CsarValidator.validateCsar(); assertEquals(true, result == true); } } diff --git a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/ValidationExceptionTest.java b/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/ValidationExceptionTest.java index 61ea3ee..8ab498e 100644 --- a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/ValidationExceptionTest.java +++ b/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/ValidationExceptionTest.java @@ -1,51 +1,49 @@ /** * Copyright 2017 Huawei Technologies Co., Ltd. - * + * <p> * 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 - * + * <p> * http://www.apache.org/licenses/LICENSE-2.0 - * + * <p> * 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 static org.junit.Assert.assertTrue; 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(); + ValidationException validationException = new ValidationException(); @Test public void testWrappedInfoThrowableErrorCodes() { Throwable ex = new IOException(); - ValidationException result = validationException.wrappedInfo(ex, ErrorCodes.FILE_IO); + ValidationException.wrappedInfo(ex, ErrorCodes.FILE_IO); assertTrue(true); } @Test public void testWrappedInfoThrowableErrorCodes1() { Throwable ex = new ValidationException(); - ValidationException result = validationException.wrappedInfo(ex, ErrorCodes.FILE_IO); + ValidationException.wrappedInfo(ex, ErrorCodes.FILE_IO); assertTrue(true); } @Test public void testWrappedInfoThrowableErrorCodes2() { Throwable ex = new ValidationException(); - ValidationException result = validationException.wrappedInfo(ex, null); + ValidationException.wrappedInfo(ex, null); assertTrue(true); } } |