summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPawel <pawel.kasperkiewicz@nokia.com>2020-11-13 13:40:43 +0100
committerPawel <pawel.kasperkiewicz@nokia.com>2020-11-25 11:26:39 +0100
commit513f2ef448b14f3880981c1bc95ab395b29de4e9 (patch)
tree8b4e04f283be7dd649bbebe467f4e8a0c1e068ff
parentb6ff67fa1d21765f2f52f3643946c96b2f13aa07 (diff)
Tests refactor
Issue-ID: VNFSDK-713 Signed-off-by: Pawel <pawel.kasperkiewicz@nokia.com> Change-Id: I86bfb5af43c6ccab74c46ba4bdcf13a3be27962c
-rw-r--r--pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java39
-rw-r--r--pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java20
-rw-r--r--pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java19
-rw-r--r--pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java86
-rw-r--r--pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java52
-rw-r--r--pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java31
-rw-r--r--pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java27
-rw-r--r--pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java28
8 files changed, 151 insertions, 151 deletions
diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java
index 089348d..5eb5dd5 100644
--- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java
+++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java
@@ -17,7 +17,6 @@
package org.onap.validation.yaml;
-import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Test;
import org.onap.validation.yaml.error.YamlDocumentValidationError;
import org.onap.validation.yaml.exception.YamlProcessingException;
@@ -26,32 +25,31 @@ import org.yaml.snakeyaml.parser.ParserException;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.catchThrowable;
class YamlFileValidatorTest {
@Test
void shouldReturnCorrectErrorsWhenGivenPathToValidPmDictionaryFile() throws YamlProcessingException {
- // given
+ //given
String path = getFullPathForGivenResources(YamlLoadingUtils.PATH_TO_VALID_YAML);
- // when
+ //when
List<YamlDocumentValidationError> validationErrors = new YamlFileValidator().validateYamlFileWithSchema(path);
- // then
+ //then
assertValidationReturnedExpectedErrors(validationErrors);
-
}
@Test
- void shouldReturnCorrecErrorsWhenGivenPathToValidJsonStylePmDictionaryFile() throws YamlProcessingException {
- // given
+ void shouldReturnCorrectErrorsWhenGivenPathToValidJsonStylePmDictionaryFile() throws YamlProcessingException {
+ //given
String path = getFullPathForGivenResources(YamlLoadingUtils.PATH_TO_VALID_JSON_STYLE_YAML);
- // when
+ //when
List<YamlDocumentValidationError> validationErrors = new YamlFileValidator().validateYamlFileWithSchema(path);
- // then
+ //then
assertValidationReturnedExpectedErrors(validationErrors);
}
@@ -62,7 +60,7 @@ class YamlFileValidatorTest {
.hasSize(4)
.usingRecursiveFieldByFieldElementComparator()
.containsAll(
- Lists.list(
+ List.of(
new YamlDocumentValidationError(1,
"/pmMetaData/pmFields/measResultType",
"Value(s) is/are not in array of accepted values.\n" +
@@ -85,21 +83,28 @@ class YamlFileValidatorTest {
@Test
void shouldThrowErrorWhenGivenPathToInvalidPmDictionaryFile() {
- // given
+ //given
String path = getFullPathForGivenResources(YamlLoadingUtils.PATH_TO_MULTI_DOCUMENT_INVALID_YAML);
- // when then
- assertThatThrownBy(() -> new YamlFileValidator().validateYamlFileWithSchema(path))
+
+ //when
+ Throwable ex = catchThrowable(() -> new YamlFileValidator().validateYamlFileWithSchema(path));
+
+ //then
+ assertThat(ex)
.isInstanceOf(ParserException.class)
.hasMessageContaining("expected the node content, but found '<document end>'");
}
@Test
void shouldThrowErrorWhenGivenInvalidPath() {
- // given
+ //given
String path = "invalid/path/to/pm_dictionary";
- // when then
- assertThatThrownBy(() -> new YamlFileValidator().validateYamlFileWithSchema(path))
+ //when
+ Throwable ex = catchThrowable(() -> new YamlFileValidator().validateYamlFileWithSchema(path));
+
+ //then
+ assertThat(ex)
.isInstanceOf(YamlProcessingException.class)
.hasMessageContaining("PM_Dictionary YAML file is empty");
}
diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java
index 36297ca..46cc5de 100644
--- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java
+++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java
@@ -37,34 +37,34 @@ class YamlLoaderTest {
@Test
void shouldLoadAllDocumentsFromYamlFile() throws YamlDocumentFactory.YamlDocumentParsingException {
- // when
+ //when
List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile();
- // then
+ //then
assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS);
}
@Test
void shouldLoadAllDocumentsFromJsonStyleYamlFile() throws YamlDocumentFactory.YamlDocumentParsingException {
- // when
+ //when
List<YamlDocument> documents = YamlLoadingUtils.loadValidJsonStyleMultiDocumentYamlFile();
- // then
+ //then
assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS);
}
@Test
void shouldLoadAllDocumentsFromYamlFileUsingPathInString() throws YamlProcessingException {
- // when
+ //when
List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFileUsingStringPath();
- // then
+ //then
assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS);
}
@Test
void shouldThrowExceptionWhenLoadingDocumentsFromInvalidYamlFile() {
- // when then
+ //when /then
assertThatThrownBy(YamlLoadingUtils::tryToLoadMultiDocumentInvalidYamlFile)
.isInstanceOf(ParserException.class)
.hasMessageContaining("expected the node content, but found '<document end>'");
@@ -72,7 +72,7 @@ class YamlLoaderTest {
@Test
void shouldThrowExceptionWhenLoadingDocumentsFromInvalidYamlFileUsingPathInString() {
- // when then
+ //when /then
assertThatThrownBy(YamlLoadingUtils::tryToLoadMultiDocumentInvalidYamlFileUsingStringPath)
.isInstanceOf(ParserException.class)
.hasMessageContaining("expected the node content, but found '<document end>'");
@@ -80,7 +80,7 @@ class YamlLoaderTest {
@Test
void shouldThrowExceptionWhenLoadingInvalidYamlFileWithIncorrectKeyMapping() {
- // when then
+ //when /then
assertThatThrownBy(YamlLoadingUtils::tryToLoadInvalidYamlFileWithIncorrectKeyMapping)
.isInstanceOf(ScannerException.class)
.hasMessageContaining("mapping values are not allowed here");
@@ -88,7 +88,7 @@ class YamlLoaderTest {
@Test
void shouldThrowExceptionWhenLoadingInvalidYamlFileWithUnknownEscapeCharacter() {
- // when then
+ //when /then
assertThatThrownBy(YamlLoadingUtils::tryToLoadInvalidYamlFileWithUnknownEscapeCharacter)
.isInstanceOf(ScannerException.class)
.hasMessageContaining("found unknown escape character " + LETTER_S_WITH_ASCII_CODE);
diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java
index 3f64540..9d289c0 100644
--- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java
+++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java
@@ -17,7 +17,6 @@
package org.onap.validation.yaml;
-import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Test;
import org.onap.validation.yaml.error.SchemaValidationError;
import org.onap.validation.yaml.exception.YamlProcessingException;
@@ -39,36 +38,34 @@ class YamlValidatorTest {
@Test
void shouldCreateValidatorUsingSchemaLoadedFromYamlFileAndValidatedJsonStyleDocumentsFromThatFile()
throws YamlProcessingException {
-
- // given
+ //given
List<YamlDocument> documents = YamlLoadingUtils.loadValidJsonStyleMultiDocumentYamlFile();
YamlValidator validator = new YamlValidator(new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0)));
Map<Integer, List<SchemaValidationError>> validationErrors = new HashMap<>();
- // when
+ //when
for (int documentIndex = 1; documentIndex < documents.size(); documentIndex++) {
validationErrors.put(documentIndex, validator.validate(documents.get(documentIndex)));
}
- // then
+ //then
assertValidatorReturnedCorrectErrors(validationErrors);
}
@Test
void shouldCreateValidatorUsingSchemaLoadedFromYamlFileAndValidatedDocumentsFromThatFile()
throws YamlProcessingException {
-
- // given
+ //given
List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile();
YamlValidator validator = new YamlValidator(new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0)));
Map<Integer, List<SchemaValidationError>> validationErrors = new HashMap<>();
- // when
+ //when
for (int documentIndex = 1; documentIndex < documents.size(); documentIndex++) {
validationErrors.put(documentIndex, validator.validate(documents.get(documentIndex)));
}
- // then
+ //then
assertValidatorReturnedCorrectErrors(validationErrors);
}
@@ -100,7 +97,7 @@ class YamlValidatorTest {
assertThat(validationErrors.get(YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX))
.hasSize(2)
.usingFieldByFieldElementComparator()
- .containsAll(Lists.list(
+ .containsAll(List.of(
expectedValidationValueError,
expectedValidationKeyError
));
@@ -112,7 +109,7 @@ class YamlValidatorTest {
.hasSize(1)
.usingFieldByFieldElementComparator()
.contains(expectedValidationValuesInArrayError);
- assertThat(validationErrors.get(VALID_YAML_DOCUMENT_INDEX)).hasSize(0);
+ assertThat(validationErrors.get(VALID_YAML_DOCUMENT_INDEX)).isEmpty();
}
}
diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java
index 0bd0579..70219b3 100644
--- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java
+++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java
@@ -22,9 +22,10 @@ import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.ThrowableAssert.catchThrowable;
import static org.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException;
class YamlDocumentFactoryTest {
@@ -32,7 +33,7 @@ class YamlDocumentFactoryTest {
@Test
void shouldTurnMapOfUnknownKeyTypeToMapWithStringKeysAndBeAbleToReturnStringifyValues()
throws YamlDocumentParsingException {
- // given
+ //given
List<String> testList = List.of("element1", "element11");
Map<Object, Object> testEmptyMap = Collections.emptyMap();
Map<Object, Object> inputMap = Map.of(
@@ -41,27 +42,17 @@ class YamlDocumentFactoryTest {
"test2", "element3",
2.67, testEmptyMap);
- // when
+ //when
YamlDocument document = new YamlDocumentFactory().createYamlDocument(inputMap);
- // then
- assertThat(document).isNotNull();
- assertThat(document.getYaml()).containsKeys("test", "345", "test2", "2.67");
-
- assertThat(document.getYaml()).containsEntry("test", testList);
- assertThat(document.getValue("test")).isEqualTo("[element1, element11]");
-
- assertThat(document.getValue("345")).isEqualTo("element2");
- assertThat(document.getValue("test2")).isEqualTo("element3");
-
- assertThat(document.getYaml()).containsEntry("2.67", testEmptyMap);
- assertThat(document.getValue("2.67")).isEqualTo("{}");
+ //then
+ assertYamlDocument(document, inputMap);
}
@Test
void shouldTurnMapOfUnknownKeyTypeToMapWithStringKeysAndBeAbleToExtractSubStructure()
throws YamlDocumentParsingException {
- // given
+ //given
Map<Object, Object> subStructureMap = Map.of(
"subTest1", "subElement1",
"subTest2", "subElement2");
@@ -69,66 +60,71 @@ class YamlDocumentFactoryTest {
"test", "element1",
"structure", subStructureMap);
- // when
+ //when
YamlDocument document = new YamlDocumentFactory().createYamlDocument(inputMap);
- // then
- assertThat(document).isNotNull();
- assertThat(document.getYaml()).containsKeys("test", "structure");
- assertThat(document.getValue("test")).isEqualTo("element1");
-
- assertThat(document.getSubStructure("structure")).isNotNull();
- assertThat(document.getSubStructure("structure").getValue("subTest1")).isEqualTo("subElement1");
- assertThat(document.getSubStructure("structure").getValue("subTest2")).isEqualTo("subElement2");
+ //then
+ assertYamlDocument(document, inputMap);
}
@Test
void shouldTurnMapOfUnknownKeyTypeToMapWithStringKeysAndBeAbleToExtractParametersList()
throws YamlDocumentParsingException {
- // given
+ //given
List<String> parametersList = List.of("parameter1", "parameter2");
Map<Object, Object> inputMap = Map.of(
"test", "element1",
"parameters", parametersList);
- // when
+ //when
YamlDocument document = new YamlDocumentFactory().createYamlDocument(inputMap);
- // then
- assertThat(document).isNotNull();
- assertThat(document.getYaml()).containsKeys("test", "parameters");
- assertThat(document.getValue("test")).isEqualTo("element1");
-
- assertThat(document.getListOfValues("parameters")).isNotNull();
- assertThat(document.getListOfValues("parameters").getParameters()).contains("parameter1", "parameter2");
+ //then
+ assertYamlDocument(document, inputMap);
}
@Test
void shouldThrowExceptionIfGetSubStructureIsCalledOnList()
throws YamlDocumentParsingException {
- // given
+ //given
List<String> testList = List.of("element1", "element2");
Map<Object, Object> inputMap = Collections.singletonMap("test", testList);
-
YamlDocument document = new YamlDocumentFactory().createYamlDocument(inputMap);
- // when then
- assertThatThrownBy(() -> document.getSubStructure("test"))
- .isInstanceOf(YamlDocumentParsingException.class)
- .hasMessageContaining(String.format("Fail to parse given objects: %s as yaml document", testList));
+ //when
+ Throwable ex = catchThrowable(() -> document.getSubStructure("test"));
+
+ //then
+ assertYamlDocumentParsingException(ex, testList);
}
@Test
void shouldThrowExceptionIfGetSubStructureIsCalledOnString()
throws YamlDocumentParsingException {
- // given
+ //given
Map<Object, Object> inputMap = Collections.singletonMap("test", "testElement");
-
YamlDocument document = new YamlDocumentFactory().createYamlDocument(inputMap);
- // when then
- assertThatThrownBy(() -> document.getSubStructure("test"))
+ //when
+ Throwable ex = catchThrowable(() -> document.getSubStructure("test"));
+
+ //then
+ assertYamlDocumentParsingException(ex, "testElement");
+ }
+
+ private void assertYamlDocument(YamlDocument document, Map<Object, Object> inputMap) {
+ assertThat(document).isNotNull();
+ assertThat(document.getYaml()).containsExactlyEntriesOf(mapKeyToString(inputMap));
+ }
+
+ private Map<String, Object> mapKeyToString(Map<Object, Object> inputMap) {
+ return inputMap.entrySet().stream()
+ .collect(Collectors.toMap(w -> w.getKey().toString(), Map.Entry::getValue));
+ }
+
+ private void assertYamlDocumentParsingException(Throwable ex, Object unparsed) {
+ assertThat(ex)
.isInstanceOf(YamlDocumentParsingException.class)
- .hasMessageContaining(String.format("Fail to parse given objects: %s as yaml document.", "testElement"));
+ .hasMessageContaining(String.format("Fail to parse given objects: %s as yaml document.", unparsed));
}
}
diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java
index ed15532..70d0235 100644
--- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java
+++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java
@@ -17,9 +17,9 @@
package org.onap.validation.yaml.model;
-import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Test;
+import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@@ -28,56 +28,58 @@ class YamlParameterListFactoryTest {
@Test
void shouldCreateEmptyParametersList() {
- // when
+ //when
YamlParametersList parametersList = new YamlParameterListFactory().createEmptyYamlParameterList();
- // then
+ //then
assertThat(parametersList).isNotNull();
assertThat(parametersList.getParameters()).isEmpty();
}
@Test
void shouldCreateParametersListContainingStringsFromListContainingSimpleTypes() {
- // given
- List<Object> elements = List.of("test1", 3, 23.45, 'a', "test2");
+ //given
+ List<Object> testList = List.of("test1", 3, 23.45, 'a', "test2");
- // when
- YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList( elements);
+ //when
+ YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testList);
- // then
- assertThat(parametersList).isNotNull();
- assertThat(parametersList.getParameters())
- .hasSize(5)
- .contains("test1", "test2", "3", "23.45", "a");
+ //then
+ assertYamlParametersList(parametersList, testList);
}
@Test
void shouldCreateParametersListContainingStringsFromListContainingVariousTypes() {
- // given
- List<Object> testList = List.of("test1", 3, Lists.list(2, 3, 4), "test2");
+ //given
+ List<Object> testList = List.of("test1", 3, List.of(2, 3, 4), "test2");
- // when
+ //when
YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testList);
- // then
- assertThat(parametersList).isNotNull();
- assertThat(parametersList.getParameters())
- .hasSize(4)
- .contains("test1", "test2", "3", "[2, 3, 4]");
+ //then
+ assertYamlParametersList(parametersList, testList);
}
@Test
void shouldCreateListWithOneStringWhenGivenObjectIsNotList() {
- // given
+ //given
Object testObject = "test";
- // when
+ //when
YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testObject);
- // then
+ //then
+ assertYamlParametersList(parametersList, Collections.singletonList(testObject));
+ }
+
+ private void assertYamlParametersList(YamlParametersList parametersList, List<Object> testList) {
assertThat(parametersList).isNotNull();
assertThat(parametersList.getParameters())
- .hasSize(1)
- .contains("test");
+ .containsExactly(mapToStrings(testList));
}
+
+ private String[] mapToStrings(List<Object> elements) {
+ return elements.stream().map(Object::toString).toArray(String[]::new);
+ }
+
}
diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java
index 4c602e0..79cc105 100644
--- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java
+++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java
@@ -28,7 +28,7 @@ import org.onap.validation.yaml.schema.YamlSchemaFactory;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.onap.validation.yaml.YamlLoadingUtils.VALID_YAML_DOCUMENT_INDEX;
import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX;
import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX;
@@ -38,60 +38,63 @@ class YamlValidationProcessTest {
@Test
void shouldReturnNoErrorWhenProcessingValidPmDictionaryYaml()
throws YamlProcessingException {
- // given
+ //given
List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile();
YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0));
YamlDocument document = documents.get(VALID_YAML_DOCUMENT_INDEX);
- // when
+ //when
List<SchemaValidationError> errors = new YamlValidationProcess(schema, document).validate();
- // then
+ //then
assertThat(errors).isEmpty();
}
@Test
void shouldReturnOneErrorWhenProcessingPmDictionaryYamlWithMissingField()
throws YamlProcessingException {
- // given
+ //given
List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile();
YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0));
YamlDocument document = documents.get(YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX);
- // when
+ //when
List<SchemaValidationError> errors = new YamlValidationProcess(schema, document).validate();
- // then
+ //then
assertThat(errors).hasSize(1);
}
@Test
void shouldReturnTwoErrorsWhenProcessingPmDictionaryYamlWithMissingFieldAndIncorrectValue()
throws YamlProcessingException {
- // given
+ //given
List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile();
YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0));
YamlDocument document = documents.get(YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX);
- // when
+ //when
List<SchemaValidationError> errors = new YamlValidationProcess(schema, document).validate();
- // then
+ //then
assertThat(errors).hasSize(2);
}
@Test
void shouldThrowExceptionWhenProcessingPmDictionaryIsNotValidYaml()
throws YamlProcessingException {
- // given
+ //given
List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile();
YamlDocument schemaInYaml = YamlLoadingUtils.loadSimpleInvalidYamlSchemaForLazyLoadingFile();
YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(schemaInYaml);
YamlDocument document = documents.get(VALID_YAML_DOCUMENT_INDEX);
- // when then
- assertThatThrownBy(() -> new YamlValidationProcess(schema, document).validate())
+ //when
+ Throwable ex = catchThrowable(() -> new YamlValidationProcess(schema, document).validate());
+
+ //then
+ assertThat(ex)
.isInstanceOf(YamlProcessingException.class)
- .hasMessageContaining(String.format("Lazy loading failed, due to yaml parsing exception."));
+ .hasMessageContaining("Lazy loading failed, due to yaml parsing exception.");
}
}
diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java
index 5768851..6757556 100644
--- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java
+++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java
@@ -17,6 +17,7 @@
package org.onap.validation.yaml.schema;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.onap.validation.yaml.YamlLoadingUtils;
import org.onap.validation.yaml.exception.YamlProcessingException;
@@ -36,33 +37,30 @@ class YamlSchemaFactoryTest {
@Test
void shouldCreateYamlSchemaFromYamlDocumentWithMultipleRoots()
throws YamlProcessingException {
-
- // given
+ //given
YamlDocument documents = YamlLoadingUtils.loadSimpleValidYamlSchemaWithMultiRootFile();
- // when
+ //when
YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents);
- // then
+ //then
assertThat(schema).isNotNull();
- assertThat(schema.getRootNodes()).hasSize(3);
- assertThat(schema.getRootNodes().get(0).getName()).isEqualTo("root1");
- assertThat(schema.getRootNodes().get(1).getName()).isEqualTo("root2");
- assertThat(schema.getRootNodes().get(2).getName()).isEqualTo("root3");
+ assertThat(schema.getRootNodes())
+ .extracting(YamlSchemaNode::getName)
+ .containsExactly("root1", "root2", "root3");
}
@Test
void shouldCreateYamlSchemaFromYamlDocument()
throws YamlProcessingException {
-
- // given
+ //given
YamlDocument documents = YamlLoadingUtils.loadSimpleValidYamlSchemaFile();
- // when
+ //when
YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents);
- // then
+ //then
assertThat(schema).isNotNull();
assertThat(schema.getRootNodes()).hasSize(1);
YamlSchemaNode pmMetaData = schema.getRootNodes().get(0);
@@ -103,11 +101,10 @@ class YamlSchemaFactoryTest {
@Test
void shouldThrowYamlParsingExceptionWhenLoadedSchemaIsInvalid()
throws YamlDocumentParsingException {
-
- // given
+ //given
YamlDocument documents = YamlLoadingUtils.loadSimpleInvalidYamlSchemaFile();
- // when/then
+ //when /then
assertThatThrownBy(() -> new YamlSchemaFactory().createTreeStructuredYamlSchema(documents))
.isInstanceOf(YamlDocumentParsingException.class)
.hasMessageContaining(String.format(
diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java
index ed43a1d..0bdd9d0 100644
--- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java
+++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java
@@ -17,7 +17,6 @@
package org.onap.validation.yaml.schema.node;
-import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Test;
import org.onap.validation.yaml.YamlLoadingUtils;
import org.onap.validation.yaml.exception.YamlProcessingException;
@@ -29,7 +28,7 @@ import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.onap.validation.yaml.schema.node.YamlSchemaNodeFactory.EMPTY_COMMENT;
public class YamlSchemaNodeFactoryTest {
@@ -39,15 +38,17 @@ public class YamlSchemaNodeFactoryTest {
@Test
void shouldThrowExceptionDuringLazyLoadingWhenLoadedSchemaHaveInvalidSubStructure()
throws YamlProcessingException {
- // given
+ //given
String nodeName = "pmMetaData";
-
YamlDocument document = YamlLoadingUtils.loadSimpleInvalidYamlSchemaForLazyLoadingFile();
YamlSchemaNode node = new YamlSchemaNodeFactory()
.createNode(nodeName, ROOT_PATH, document.getSubStructure(nodeName));
- // when/then
- assertThatThrownBy(node::getNextNodes)
+ //when
+ Throwable ex = catchThrowable(node::getNextNodes);
+
+ //then
+ assertThat(ex)
.isInstanceOf(YamlSchemaNode.YamlSchemaProcessingException.class)
.hasMessageContaining("Lazy loading failed, due to yaml parsing exception.");
}
@@ -55,20 +56,20 @@ public class YamlSchemaNodeFactoryTest {
@Test
void shouldCreateLeafNodeIfGivenYamlDocumentHaveNoSubStructure()
throws YamlProcessingException {
- // given
+ //given
String nodeName = "leaf_test";
String comment = "test leaf node";
- List<String> acceptedValues = Lists.list("val1", "val2");
+ List<String> acceptedValues = List.of("val1", "val2");
Map<Object, Object> nodeInYamlFormat = new HashMap<>();
nodeInYamlFormat.put(YamlSchemaNodeFactory.PRESENCE_KEY, YamlSchemaNodeFactory.PRESENCE_REQUIRED_KEY);
nodeInYamlFormat.put(YamlSchemaNodeFactory.COMMENT_KEY, comment);
nodeInYamlFormat.put(YamlSchemaNodeFactory.VALUE_KET, acceptedValues);
YamlDocument document = new YamlDocumentFactory().createYamlDocument(nodeInYamlFormat);
- // when
+ //when
YamlSchemaNode yamlSchemaNode = new YamlSchemaNodeFactory().createNode(nodeName, ROOT_PATH, document);
- // then
+ //then
assertThatLeafNodeIsValid(
yamlSchemaNode, nodeName, ROOT_PATH, true, comment,
acceptedValues.toArray(new String[acceptedValues.size()])
@@ -78,7 +79,7 @@ public class YamlSchemaNodeFactoryTest {
@Test
void shouldCreateBranchNodeIfGivenYamlDocumentHaveSubStructure()
throws YamlProcessingException {
- // given
+ //given
String nodeName = "branch_test";
String comment = "test branch node";
@@ -94,12 +95,11 @@ public class YamlSchemaNodeFactoryTest {
nodeInYamlFormat.put(YamlSchemaNodeFactory.STRUCTURE_KEY, subStructure);
YamlDocument document = new YamlDocumentFactory().createYamlDocument(nodeInYamlFormat);
- // when
+ //when
YamlSchemaNode yamlSchemaNode = new YamlSchemaNodeFactory().createNode(nodeName, ROOT_PATH, document);
- // then
+ //then
assertThatBranchNodeIsValid(yamlSchemaNode, nodeName, ROOT_PATH, true, comment, 2);
-
List<YamlSchemaNode> subNodes = yamlSchemaNode.getNextNodes();
assertThat(subNodes).hasSize(2);
assertThatLeafNodeIsValid(