From c54c3683ac17c53a322ffc88deb05e56e9039d74 Mon Sep 17 00:00:00 2001 From: AvinashS Date: Fri, 22 Sep 2017 12:57:19 +0000 Subject: Fix double value validation Fix double values in Meta file validation fix Change-Id: Ie4b7ae34566b060871c14b683d8d12386a53d395 IssueId: VNFSDK-96 Signed-off-by: AvinashS --- .../org/onap/validation/csar/CsarValidator.java | 21 +++++++++++++-------- .../csarvalidationtest/CsarValidatorTest.java | 5 +---- 2 files changed, 14 insertions(+), 12 deletions(-) (limited to 'csarvalidation/src') 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 8263e6b..e542b65 100644 --- a/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java +++ b/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java @@ -53,6 +53,8 @@ public class CsarValidator { LOG.debug("CSAR extracted sucessfully."); } } catch (Exception e1) { + + //deleteDirectory(); LOG.error("CSAR %s is not a valid CSAR/ZIP file! ", e1); } @@ -165,7 +167,7 @@ public class CsarValidator { return true; } } - } catch (IOException e) { + } catch (IOException | NullPointerException e) { LOG.error("Could not read file %s ! " + e.getMessage(), cfile); } return false; @@ -185,10 +187,10 @@ public class CsarValidator { "vnfmType"); boolean tResult = checkEntryFor(CommonConstants.MAINSERV_TEMPLATE, tListMetadata, key); - if (tResult && mfResult) { - return true; - } else { + if (!tResult || !mfResult) { return false; + } else { + return true; } } @@ -212,20 +214,23 @@ public class CsarValidator { } Yaml yaml = new Yaml(); - Map values = null; + Map values; try { values = (Map) yaml.load(new FileInputStream(new File(tFileWithPath))); } catch (FileNotFoundException e) { return false; } - Map subValues = (Map) values.get(key); + Map subValues = (Map) values.get(key); //1. Check for empty values in map and if number of mandatory attributes presence - List lResultNonNull = subValues.values().stream() + List lResultNonNull = subValues.values().stream() .filter(Objects::nonNull) + .map(Object::toString) .collect(Collectors.toList()); - if (subValues.size() != attributes.size() && + + + if (subValues.size() != attributes.size() && lResultNonNull.size() != attributes.size()) { return false; } 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 be764a1..7eccb7a 100644 --- a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java +++ b/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java @@ -35,13 +35,11 @@ public class CsarValidatorTest { String dir2 = System.getProperty("file.separator") + csarFile.substring(1); String packageId = UUID.randomUUID().toString(); - private String csarFile2 = classLoader.getResource("sample.csar").getFile(); + private String csarFile2 = classLoader.getResource("sample2.csar").getFile(); String sample2 = System.getProperty("file.separator") + csarFile2.substring(1); String packageId2 = UUID.randomUUID().toString(); - - @Test public void testAll() { CsarValidator csarValidator = new CsarValidator(packageId, dir2); @@ -49,7 +47,6 @@ public class CsarValidatorTest { CsarValidator csarValidator2 = new CsarValidator(packageId2, sample2); testValidateCsar(csarValidator2); - } @Test -- cgit 1.2.3-korg