From b2c0528da052b5c73e3fc1f7f98d22578acd91f0 Mon Sep 17 00:00:00 2001 From: xuegao Date: Fri, 19 Mar 2021 14:04:17 +0100 Subject: Improve test coverage Add unit tests to improve test coverage. Issue-ID: SDC-3428 Change-Id: I29a8f1d49f1dfd6bca79f3d873d1e1ff7adc4fb2 Signed-off-by: xuegao --- .../types/GlobalValidationContextTest.java | 43 +++++++++++++++------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src') diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/test/java/org/openecomp/core/validation/types/GlobalValidationContextTest.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/test/java/org/openecomp/core/validation/types/GlobalValidationContextTest.java index 8f17f0f357..3541465736 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/test/java/org/openecomp/core/validation/types/GlobalValidationContextTest.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/test/java/org/openecomp/core/validation/types/GlobalValidationContextTest.java @@ -18,12 +18,13 @@ package org.openecomp.core.validation.types; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; -import org.junit.Assert; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import org.openecomp.core.validation.ErrorMessageCode; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.datatypes.error.ErrorMessage; +import java.io.InputStream; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -31,6 +32,10 @@ import java.util.List; import java.util.Map; import java.util.function.BiPredicate; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class GlobalValidationContextTest { private static String filename = "testName"; private static String yaml1 = "one.yaml"; @@ -45,7 +50,7 @@ public class GlobalValidationContextTest { ErrorMessageCode error = new ErrorMessageCode("Error"); globalValidationContext.setMessageCode(error); - Assert.assertEquals(error, globalValidationContext.getMessageCode()); + assertEquals(error, globalValidationContext.getMessageCode()); } @Test @@ -54,8 +59,8 @@ public class GlobalValidationContextTest { globalValidationContext.addFileContext(filename, content.getBytes()); Map fileContextMap = globalValidationContext.getFileContextMap(); - Assert.assertTrue(MapUtils.isNotEmpty(fileContextMap)); - Assert.assertTrue(fileContextMap.containsKey(filename)); + assertTrue(MapUtils.isNotEmpty(fileContextMap)); + assertTrue(fileContextMap.containsKey(filename)); } @Test @@ -81,6 +86,18 @@ public class GlobalValidationContextTest { testIfFileHasErrorMessage(messageContainers, 1); } + @Test + public void testGetFileContent() { + GlobalValidationContext globalValidationContext = new GlobalValidationContext(); + + assertTrue(globalValidationContext.getFileContent(yaml1).isEmpty()); + + byte[] bytes = content.getBytes(); + globalValidationContext.addFileContext(yaml1, bytes); + + assertTrue(globalValidationContext.getFileContent(yaml1).get() instanceof InputStream); + } + @Test public void testGetFiles() { GlobalValidationContext globalValidationContext = new GlobalValidationContext(); @@ -94,7 +111,7 @@ public class GlobalValidationContextTest { testGetFilesByFileType((fileName, globalContext) -> fileName.endsWith(".txt"), 1, Collections.singletonList(text1), globalValidationContext); - + assertEquals(3, globalValidationContext.getFiles().size()); } private void testGetFilesByFileType(BiPredicate func, @@ -102,23 +119,23 @@ public class GlobalValidationContextTest { List expectedFileNames, GlobalValidationContext globalValidationContext) { Collection files = globalValidationContext.files(func); - Assert.assertTrue(CollectionUtils.isNotEmpty(files)); - Assert.assertEquals(files.size(), expectedFilesNumberToFind); - expectedFileNames.forEach(filename -> Assert.assertTrue(files.contains(filename))); + assertTrue(CollectionUtils.isNotEmpty(files)); + assertEquals(files.size(), expectedFilesNumberToFind); + expectedFileNames.forEach(filename -> assertTrue(files.contains(filename))); } private void testIfFileHasMessageContainer(Map messageContainers) { - Assert.assertNotNull(messageContainers); - Assert.assertTrue(messageContainers.containsKey(filename)); + assertNotNull(messageContainers); + assertTrue(messageContainers.containsKey(filename)); } private void testIfFileHasErrorMessage(Map messageContainers, int expectedErrorsNumber) { MessageContainer messageContainer = messageContainers.get(filename); - Assert.assertEquals(messageContainer.getErrorMessageList().size(), expectedErrorsNumber); + assertEquals(messageContainer.getErrorMessageList().size(), expectedErrorsNumber); ErrorMessage errorMessage = new ErrorMessage(ErrorLevel.ERROR, ErrorLevel.ERROR.toString() + ": " + message); - Assert.assertTrue(messageContainer.getErrorMessageList().contains(errorMessage)); + assertTrue(messageContainer.getErrorMessageList().contains(errorMessage)); } } -- cgit 1.2.3-korg