diff options
author | AvinashS <avinash.s@huawei.com> | 2017-09-18 12:55:57 +0000 |
---|---|---|
committer | AvinashS <avinash.s@huawei.com> | 2017-09-18 12:55:57 +0000 |
commit | 56c184e1622436654d9f12b1098a8020a6323a3a (patch) | |
tree | 67f89f9d4ca05e958c496be103bf91a6e6b4a270 /csarvalidation/src | |
parent | d77a91e05fe1f2da7059e8cc1a5d41a804691e13 (diff) |
Instantiate validation with path
To populate csar files during object
creation.
Change-Id: I66b5cf8b46f98990240e9cc470eff6a8874f3de0
IssueId: VNFSDK-90
Signed-off-by: AvinashS <avinash.s@huawei.com>
Diffstat (limited to 'csarvalidation/src')
-rw-r--r-- | csarvalidation/src/main/java/org/onap/validation/csar/CsarParser.java | 37 | ||||
-rw-r--r-- | csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarParserTest.java | 7 |
2 files changed, 32 insertions, 12 deletions
diff --git a/csarvalidation/src/main/java/org/onap/validation/csar/CsarParser.java b/csarvalidation/src/main/java/org/onap/validation/csar/CsarParser.java index 410562c..76a7b11 100644 --- a/csarvalidation/src/main/java/org/onap/validation/csar/CsarParser.java +++ b/csarvalidation/src/main/java/org/onap/validation/csar/CsarParser.java @@ -41,6 +41,23 @@ public class CsarParser { private static HashMap<String, HashMap<String, String>> csar = new HashMap<String, HashMap<String, String>>(); private static final CsarUtil cUtil = new CsarUtil(); + + public CsarParser(String csarWithPath) { + + try { + FileInputStream is = new FileInputStream(csarWithPath); + } catch (FileNotFoundException e2) { + LOG.error("CSAR %s is not found! ", e2); + } + try { + boolean ret = csarExtract(csarWithPath); + if(ret == true) { + LOG.debug("CSAR extracted sucessfully."); + } + } catch (Exception e1) { + LOG.error("CSAR %s is not a valid CSAR/ZIP file! ", e1); + } + } /* * pubic static boolean validateCsar(String filePath) { * @@ -74,13 +91,15 @@ public class CsarParser { } } - public static boolean csarExtract(String filePath) { + private static boolean csarExtract(String filePath) { try { String tempfolder = CsarUtil.getUnzipDir(filePath); csarFiles = CsarUtil.unzip(filePath, tempfolder); + } catch (IOException e1) { LOG.error("CSAR extraction error ! " + e1.getMessage()); + return false; } return true; @@ -118,22 +137,24 @@ public class CsarParser { return false; } } - - } - reader.close(); + } + reader.close(); + return true; } } catch (IOException e2) { - e2.printStackTrace(); - return false; + LOG.error("Exception cought while validateCsarMeta ! " + e2.getMessage()); + //e2.printStackTrace(); + } finally { if (reader != null) { try { reader.close(); + } catch (IOException e1) { LOG.error("close reader failed ! " + e1.getMessage()); } } - return true; + } } @@ -145,7 +166,7 @@ public class CsarParser { String cfile = csarFiles.get(CommonConstants.TOSCA_META); try { - if (!cfile.isEmpty() && cfile.contains("/" + CommonConstants.TOSCA_METADATA + "/" + CommonConstants.TOSCA_META)) { + if (!cfile.isEmpty() && cfile.contains( System.getProperty("file.separator")+ CommonConstants.TOSCA_METADATA + System.getProperty("file.separator") + CommonConstants.TOSCA_META)) { String value = checkEntryFor("Entry-Definitions:", cfile); if (value == null) { diff --git a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarParserTest.java b/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarParserTest.java index 4c692e7..ce9ba5b 100644 --- a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarParserTest.java +++ b/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarParserTest.java @@ -25,7 +25,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class CsarParserTest { - CsarParser csarParser = new CsarParser(); + String regex = "^\\/[a-zA-Z]\\:\\/"; ClassLoader classLoader = getClass().getClassLoader(); Pattern pattern = Pattern.compile(regex); @@ -33,10 +33,10 @@ public class CsarParserTest { Matcher matcher = pattern.matcher(configFile); String dir2 = "/"+configFile.substring(1); + CsarParser csarParser = new CsarParser(dir2); + @Test public void testValidateCsarMeta() { - boolean result1 = csarParser.csarExtract(dir2); - // assertEquals(true, result = true); boolean result = CsarParser.validateCsarMeta(); assertEquals(true, result == true); System.out.println("inside testValidateCsarMeta : " + result); @@ -51,7 +51,6 @@ public class CsarParserTest { @Test public void testValidateToscaMeta() { - boolean result1 = csarParser.csarExtract(dir2); boolean result = csarParser.validateToscaMeta(); assertEquals(true, result == true); System.out.println("inside testValidateToscaMeta : " + result); |