From b485c37b36ddb3ab5e8085c009b26e97c8e62d74 Mon Sep 17 00:00:00 2001 From: JulienBe Date: Wed, 28 Oct 2020 11:50:25 -0400 Subject: Upgrade Vulnerable Direct Dependencies [snakeyaml] Change-Id: I84417ab3d4f18634be519b837a34d1f1e774ceff Signed-off-by: amohamad Issue-ID: SDC-3051 Updated MVN dependencies in the respective pom.xml files Updated the signature of some methods to match new version 1.26 Modified test cases to match the new wording of exceptions Still working on troublshooting other failing test cases Change-Id: Ifc796574e6d8d4e4fc707db04944d83427b5dbe6 Signed-off-by: amohamad Signed-off-by: JulienBe --- .../SOL004MetaDirectoryValidatorTest.java | 66 +++++++++------------- 1 file changed, 27 insertions(+), 39 deletions(-) (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src') diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java index 2053373dce..33a558ea75 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java @@ -24,10 +24,10 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validati import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.anEmptyMap; -import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -63,10 +63,8 @@ import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.va import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.commons.collections.CollectionUtils; @@ -963,27 +961,12 @@ public class SOL004MetaDirectoryValidatorTest { final List expectedErrorList = new ArrayList<>(); expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR - , Messages.INVALID_YAML_FORMAT_1.formatMessage(nonManoPmEventsSource, "while scanning a simple key\n" - + " in 'reader', line 2, column 1:\n" - + " key {}\n" - + " ^\n" - + "could not find expected ':'\n" - + " in 'reader', line 2, column 7:\n" - + " {}\n" - + " ^\n")) + , Messages.INVALID_YAML_FORMAT_1.formatMessage(nonManoPmEventsSource, "while scanning a simple key in 'reader', line 2, column 1: key {} ^could not find expected ':' in 'reader', line 2, column 7: key {} ^")) ); - expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR, "while scanning a simple key\n" + - " in 'reader', line 2, column 1:\n" + - " key {}\n" + - " ^\n" + - "could not find expected ':'\n" + - " in 'reader', line 2, column 7:\n" + - " {}\n" + - " ^\n") + expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR, "while scanning a simple key in 'reader', line 2, column 1: key {} ^could not find expected ':' in 'reader', line 2, column 7: key {} ^") ); - final Map> actualErrorMap = sol004MetaDirectoryValidator - .validateContent(handler); + final Map> actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler); assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList); } @@ -1253,22 +1236,6 @@ public class SOL004MetaDirectoryValidatorTest { assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList); } - protected void assertExpectedErrors(List actualErrorList, final List expectedErrorList) { - if (actualErrorList == null) { - actualErrorList = new ArrayList<>(); - } - - printErrorMessages(actualErrorList); - - assertThat("The actual error list should have the same size as the expected error list " + actualErrorList.toString() - , actualErrorList, hasSize(expectedErrorList.size()) - ); - - assertThat("The actual error and expected error lists should be the same" - , actualErrorList, containsInAnyOrder(expectedErrorList.toArray(new ErrorMessage[0])) - ); - } - protected void assertExpectedErrors(final String testCase, final Map> errors, final int expectedErrors){ final List errorMessages = errors.get(SdcCommon.UPLOAD_FILE); printErrorMessages(errorMessages); @@ -1287,4 +1254,25 @@ public class SOL004MetaDirectoryValidatorTest { } } + private void assertExpectedErrors(List actualErrorList, final List expectedErrorList) { + if (actualErrorList == null) { + actualErrorList = new ArrayList<>(); + } + + printErrorMessages(actualErrorList); + + assertThat("The actual error list should have the same size as the expected error list" + , actualErrorList, hasSize(expectedErrorList.size()) + ); + + actualErrorList.forEach(error -> { + Predicate matching = e -> e.getLevel() == error.getLevel() && sanitize(e.getMessage()).equalsIgnoreCase(sanitize(error.getMessage())); + assertTrue("The actual error and expected error lists should be the same", expectedErrorList.stream().anyMatch(matching)); + }); + } + + private static String sanitize(String s) { + return s.trim().replaceAll("\n", "").replaceAll("\r", "").replaceAll("\\s{2,}", " ").trim(); + } + } -- cgit 1.2.3-korg