From b6ff67fa1d21765f2f52f3643946c96b2f13aa07 Mon Sep 17 00:00:00 2001 From: Pawel Date: Thu, 12 Nov 2020 12:15:55 +0100 Subject: Extract pm-dicrionary validation Issue-ID: VNFSDK-713 Signed-off-by: Pawel Change-Id: Iee5a23a3a6c9215927aa2c453faab62d30453444 --- Changelog.md | 4 + csarvalidation/pom.xml | 5 + .../onap/validation/yaml/YamlFileValidator.java | 72 ------- .../java/org/onap/validation/yaml/YamlLoader.java | 61 ------ .../org/onap/validation/yaml/YamlValidator.java | 40 ---- .../yaml/error/SchemaValidationError.java | 36 ---- .../yaml/error/YamlDocumentValidationError.java | 42 ---- .../yaml/exception/YamlProcessingException.java | 33 --- .../onap/validation/yaml/model/YamlDocument.java | 56 ----- .../validation/yaml/model/YamlDocumentFactory.java | 52 ----- .../yaml/model/YamlParameterListFactory.java | 42 ---- .../validation/yaml/model/YamlParametersList.java | 34 --- .../yaml/process/YamlValidationProcess.java | 111 ---------- .../yaml/process/YamlValidationStep.java | 45 ---- .../onap/validation/yaml/schema/YamlSchema.java | 37 ---- .../validation/yaml/schema/YamlSchemaFactory.java | 59 ----- .../yaml/schema/node/YamlSchemaBranchNode.java | 80 ------- .../yaml/schema/node/YamlSchemaLeafNode.java | 50 ----- .../yaml/schema/node/YamlSchemaNode.java | 66 ------ .../yaml/schema/node/YamlSchemaNodeFactory.java | 84 -------- .../validation/yaml/YamlFileValidatorTest.java | 117 ---------- .../org/onap/validation/yaml/YamlLoaderTest.java | 99 --------- .../org/onap/validation/yaml/YamlLoadingUtils.java | 94 -------- .../onap/validation/yaml/YamlValidatorTest.java | 123 ----------- .../yaml/model/YamlDocumentFactoryTest.java | 154 ------------- .../yaml/model/YamlParameterListFactoryTest.java | 81 ------- .../yaml/process/YamlValidationProcessTest.java | 101 --------- .../yaml/schema/YamlSchemaFactoryTest.java | 122 ----------- .../schema/node/YamlSchemaNodeFactoryTest.java | 153 ------------- .../yaml_schema/Multi_Document_Invalid.yaml | 86 -------- .../test/resources/yaml_schema/PM_Dictionary.yaml | 228 -------------------- .../yaml_schema/PM_Dictionary_JSON_Style.yaml | 239 --------------------- .../yaml_schema/Simple_Invalid_Mapping_Value.yaml | 149 ------------- .../Simple_Invalid_Schema_Construction.yaml | 39 ---- .../Simple_Invalid_Schema_LazyLoading.yaml | 39 ---- .../Simple_Unknown_Escape_Character.yaml | 149 ------------- .../resources/yaml_schema/Simple_Valid_Schema.yaml | 39 ---- .../Simple_Valid_Schema_Multi_Root.yaml | 23 -- pmdictionaryvalidation/pom.xml | 71 ++++++ .../onap/validation/yaml/YamlFileValidator.java | 72 +++++++ .../java/org/onap/validation/yaml/YamlLoader.java | 61 ++++++ .../org/onap/validation/yaml/YamlValidator.java | 40 ++++ .../yaml/error/SchemaValidationError.java | 36 ++++ .../yaml/error/YamlDocumentValidationError.java | 42 ++++ .../yaml/exception/YamlProcessingException.java | 33 +++ .../onap/validation/yaml/model/YamlDocument.java | 56 +++++ .../validation/yaml/model/YamlDocumentFactory.java | 52 +++++ .../yaml/model/YamlParameterListFactory.java | 42 ++++ .../validation/yaml/model/YamlParametersList.java | 34 +++ .../yaml/process/YamlValidationProcess.java | 111 ++++++++++ .../yaml/process/YamlValidationStep.java | 45 ++++ .../onap/validation/yaml/schema/YamlSchema.java | 37 ++++ .../validation/yaml/schema/YamlSchemaFactory.java | 59 +++++ .../yaml/schema/node/YamlSchemaBranchNode.java | 80 +++++++ .../yaml/schema/node/YamlSchemaLeafNode.java | 50 +++++ .../yaml/schema/node/YamlSchemaNode.java | 66 ++++++ .../yaml/schema/node/YamlSchemaNodeFactory.java | 84 ++++++++ .../src/main/resources/log4j2.properties | 48 +++++ .../validation/yaml/YamlFileValidatorTest.java | 110 ++++++++++ .../org/onap/validation/yaml/YamlLoaderTest.java | 96 +++++++++ .../org/onap/validation/yaml/YamlLoadingUtils.java | 94 ++++++++ .../onap/validation/yaml/YamlValidatorTest.java | 118 ++++++++++ .../yaml/model/YamlDocumentFactoryTest.java | 134 ++++++++++++ .../yaml/model/YamlParameterListFactoryTest.java | 83 +++++++ .../yaml/process/YamlValidationProcessTest.java | 97 +++++++++ .../yaml/schema/YamlSchemaFactoryTest.java | 118 ++++++++++ .../schema/node/YamlSchemaNodeFactoryTest.java | 146 +++++++++++++ .../yaml_schema/Multi_Document_Invalid.yaml | 86 ++++++++ .../test/resources/yaml_schema/PM_Dictionary.yaml | 228 ++++++++++++++++++++ .../yaml_schema/PM_Dictionary_JSON_Style.yaml | 239 +++++++++++++++++++++ .../yaml_schema/Simple_Invalid_Mapping_Value.yaml | 149 +++++++++++++ .../Simple_Invalid_Schema_Construction.yaml | 39 ++++ .../Simple_Invalid_Schema_LazyLoading.yaml | 39 ++++ .../Simple_Unknown_Escape_Character.yaml | 149 +++++++++++++ .../resources/yaml_schema/Simple_Valid_Schema.yaml | 39 ++++ .../Simple_Valid_Schema_Multi_Root.yaml | 23 ++ pom.xml | 1 + 77 files changed, 3116 insertions(+), 3035 deletions(-) delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/YamlFileValidator.java delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java delete mode 100644 csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java delete mode 100644 csarvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java delete mode 100644 csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java delete mode 100644 csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java delete mode 100644 csarvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java delete mode 100644 csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java delete mode 100644 csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java delete mode 100644 csarvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java delete mode 100644 csarvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java delete mode 100644 csarvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java delete mode 100644 csarvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml delete mode 100644 csarvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml delete mode 100644 csarvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml delete mode 100644 csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml delete mode 100644 csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml delete mode 100644 csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml delete mode 100644 csarvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml delete mode 100644 csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml delete mode 100644 csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml create mode 100644 pmdictionaryvalidation/pom.xml create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlFileValidator.java create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java create mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java create mode 100644 pmdictionaryvalidation/src/main/resources/log4j2.properties create mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java create mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java create mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java create mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java create mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java create mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java create mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java create mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java create mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java create mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml create mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml create mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml create mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml create mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml create mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml create mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml create mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml create mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml diff --git a/Changelog.md b/Changelog.md index 8bf5b52..d0f5b78 100644 --- a/Changelog.md +++ b/Changelog.md @@ -104,3 +104,7 @@ All notable changes to this project will be documented in this file. - https://jira.onap.org/browse/VNFSDK-660 ## [1.2.15] + +## Move +- Extract pm-dictionary validation to separate module + - https://jira.onap.org/browse/VNFSDK-713 diff --git a/csarvalidation/pom.xml b/csarvalidation/pom.xml index 729c82d..3444935 100644 --- a/csarvalidation/pom.xml +++ b/csarvalidation/pom.xml @@ -105,6 +105,11 @@ + + org.onap.vnfsdk.validation + validation-pmdictionary + ${project.version} + commons-codec commons-codec diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlFileValidator.java b/csarvalidation/src/main/java/org/onap/validation/yaml/YamlFileValidator.java deleted file mode 100644 index 2de4f48..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlFileValidator.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml; - -import org.onap.validation.yaml.error.SchemaValidationError; -import org.onap.validation.yaml.error.YamlDocumentValidationError; -import org.onap.validation.yaml.exception.YamlProcessingException; -import org.onap.validation.yaml.model.YamlDocument; -import org.onap.validation.yaml.schema.YamlSchema; -import org.onap.validation.yaml.schema.YamlSchemaFactory; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -public class YamlFileValidator { - - private static final int FIRST_DOCUMENT_INDEX = 1; - - public List validateYamlFileWithSchema(String pathToFile) - throws YamlProcessingException { - - List documents = new YamlLoader().loadMultiDocumentYamlFile(pathToFile); - if(!documents.isEmpty()) { - return validateDocuments(documents); - } else { - throw new YamlProcessingException("PM_Dictionary YAML file is empty"); - } - } - - private List validateDocuments(List documents) - throws YamlProcessingException { - - List yamlFileValidationErrors = new ArrayList<>(); - YamlSchema schema = extractSchema(documents); - YamlValidator validator = new YamlValidator(schema); - - for (int index = FIRST_DOCUMENT_INDEX; index < documents.size(); index++) { - List validationErrors = validator.validate(documents.get(index)); - yamlFileValidationErrors.addAll(transformErrors(index,validationErrors)); - } - - return yamlFileValidationErrors; - } - - private List transformErrors(int index, List validationErrors) { - return validationErrors - .stream() - .map(error->new YamlDocumentValidationError(index, error.getPath(), error.getMessage())) - .collect(Collectors.toList()); - } - - private YamlSchema extractSchema(List documents) throws YamlProcessingException { - return new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0)); - } - -} diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java b/csarvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java deleted file mode 100644 index 1a5eef9..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml; - -import org.onap.validation.yaml.exception.YamlProcessingException; -import org.onap.validation.yaml.model.YamlDocument; -import org.onap.validation.yaml.model.YamlDocumentFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.yaml.snakeyaml.Yaml; - -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - -class YamlLoader { - - private static final Logger LOGGER = LoggerFactory.getLogger(YamlLoader.class); - - List loadMultiDocumentYamlFile(URL path) - throws YamlDocumentFactory.YamlDocumentParsingException { - List documentsFromFile = new ArrayList<>(); - try (InputStream yamlStream = path.openStream()) { - for (Object yamlDocument : new Yaml().loadAll(yamlStream)) { - documentsFromFile.add( - new YamlDocumentFactory().createYamlDocument(yamlDocument) - ); - } - } catch (IOException e) { - LOGGER.error("Failed to load multi document YAML file",e); - } - return documentsFromFile; - } - - List loadMultiDocumentYamlFile(String path) - throws YamlProcessingException { - try { - return loadMultiDocumentYamlFile(new URL("file://" + path)); - } catch (MalformedURLException e) { - throw new YamlProcessingException("Fail to read file under given path.", e); - } - } -} diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java b/csarvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java deleted file mode 100644 index 9430df4..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml; - -import org.onap.validation.yaml.exception.YamlProcessingException; -import org.onap.validation.yaml.error.SchemaValidationError; -import org.onap.validation.yaml.model.YamlDocument; -import org.onap.validation.yaml.process.YamlValidationProcess; -import org.onap.validation.yaml.schema.YamlSchema; - -import java.util.List; - -public class YamlValidator { - - private final YamlSchema schema; - - YamlValidator(YamlSchema schema) { - this.schema = schema; - } - - public List validate(YamlDocument document) throws YamlProcessingException { - return new YamlValidationProcess(schema,document).validate(); - } - -} diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java b/csarvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java deleted file mode 100644 index 6ffe6d4..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.error; - -public class SchemaValidationError { - private final String path; - private final String message; - - public String getPath() { - return path; - } - - public String getMessage() { - return message; - } - - public SchemaValidationError(String path, String message) { - this.path = path; - this.message = message; - } -} diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java b/csarvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java deleted file mode 100644 index f04708f..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.error; - -public class YamlDocumentValidationError { - private final int yamlDocumentNumber; - private final String path; - private final String message; - - public YamlDocumentValidationError(int yamlDocumentNumber, String path, String message) { - this.yamlDocumentNumber = yamlDocumentNumber; - this.path = path; - this.message = message; - } - - public int getYamlDocumentNumber() { - return yamlDocumentNumber; - } - - public String getPath() { - return path; - } - - public String getMessage() { - return message; - } -} diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java b/csarvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java deleted file mode 100644 index 99c2437..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.exception; - -public class YamlProcessingException extends Exception { - - public YamlProcessingException(String message, Throwable throwable) { - super(message, throwable); - } - - public YamlProcessingException(String message) { - super(message); - } - - public YamlProcessingException(Throwable throwable) { - super(throwable); - } -} diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java b/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java deleted file mode 100644 index 557b6fd..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.model; - -import java.util.Map; - -public class YamlDocument { - - private final Map yaml; - - YamlDocument(Map yaml) { - this.yaml = yaml; - } - - public Map getYaml() { - return yaml; - } - - public boolean containsKey(String key) { - return yaml.containsKey(key); - } - - public String getValue(String key) { - return yaml.get(key).toString(); - } - - public YamlParametersList getListOfValues(String key) { - return new YamlParameterListFactory().createYamlParameterList( - yaml.get(key) - ); - } - - public YamlDocument getSubStructure(String name) - throws YamlDocumentFactory.YamlDocumentParsingException { - return new YamlDocumentFactory().createYamlDocument( - yaml.get(name) - ); - } -} - - diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java b/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java deleted file mode 100644 index b56422c..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.model; - -import org.onap.validation.yaml.exception.YamlProcessingException; - -import java.util.HashMap; -import java.util.Map; - -public class YamlDocumentFactory { - - public YamlDocument createYamlDocument(Object yaml) throws YamlDocumentParsingException { - try { - Map parsedYaml = transformMap((Map) yaml); - return new YamlDocument(parsedYaml); - } catch (ClassCastException e) { - throw new YamlDocumentParsingException( - String.format("Fail to parse given objects: %s as yaml document.", yaml), e - ); - } - } - - private Map transformMap(Map yaml) { - Map parsedYaml = new HashMap<>(); - for (Map.Entry entry: yaml.entrySet()) { - parsedYaml.put(entry.getKey().toString(), entry.getValue()); - } - return parsedYaml; - } - - public static class YamlDocumentParsingException extends YamlProcessingException { - YamlDocumentParsingException(String message, Throwable throwable) { - super(message, throwable); - } - } - -} diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java b/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java deleted file mode 100644 index 5f41c5c..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.model; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class YamlParameterListFactory { - - public YamlParametersList createEmptyYamlParameterList() { - return new YamlParametersList(Collections.emptyList()); - } - - public YamlParametersList createYamlParameterList(Object yaml) { - List parametersList = new ArrayList<>(); - if( yaml instanceof List) { - for (Object element : (List) yaml) { - parametersList.add(element.toString()); - } - } else { - parametersList.add(yaml.toString()); - } - return new YamlParametersList(parametersList); - } - -} diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java b/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java deleted file mode 100644 index 2b93c74..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.model; - -import java.util.List; - -public class YamlParametersList { - - private final List parameters; - - YamlParametersList(List parameters) { - this.parameters = parameters; - } - - public List getParameters() { - return parameters; - } - -} diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java b/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java deleted file mode 100644 index 273014b..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.process; - -import org.onap.validation.yaml.exception.YamlProcessingException; -import org.onap.validation.yaml.error.SchemaValidationError; -import org.onap.validation.yaml.model.YamlDocument; -import org.onap.validation.yaml.schema.YamlSchema; -import org.onap.validation.yaml.schema.node.YamlSchemaNode; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Queue; - -public class YamlValidationProcess { - - private final Queue validationSteps; - private final List errors; - private final YamlSchema schema; - private final YamlDocument document; - - public YamlValidationProcess(YamlSchema schema, YamlDocument document) { - this.schema = schema; - this.document = document; - errors = new ArrayList<>(); - validationSteps = new LinkedList<>(); - } - - public List validate() throws YamlProcessingException { - validationSteps.add(new YamlValidationStep(schema.getRootNodes(), document)); - while (!validationSteps.isEmpty()) { - YamlValidationStep nextValidationNode = validationSteps.poll(); - validateStep(nextValidationNode); - } - return errors; - } - - private void validateStep(YamlValidationStep validationNode) - throws YamlProcessingException { - for (YamlSchemaNode schemaNode : validationNode.getSchemaNodes()) { - validateNode(validationNode.getDocument(), schemaNode); - } - } - - private void validateNode(YamlDocument document, YamlSchemaNode schemaNode) - throws YamlProcessingException { - - if (document.containsKey(schemaNode.getName())) { - if (schemaNode.isContainingSubStructure()) { - addNextLevelNodeToValidationNodesQueue(document, schemaNode); - } else if (!isValueOfNodeInAcceptedValuesList(document, schemaNode)) { - addIncorrectValueError(document, schemaNode); - } - } else if (schemaNode.isRequired()) { - addRequiredKeyNotFoundError(schemaNode); - } - } - - private boolean isValueOfNodeInAcceptedValuesList(YamlDocument document, YamlSchemaNode node) { - return node.getAcceptedValues().isEmpty() || - node.getAcceptedValues().containsAll( - document.getListOfValues(node.getName()).getParameters() - ); - } - - private void addNextLevelNodeToValidationNodesQueue(YamlDocument document, YamlSchemaNode node) - throws YamlProcessingException { - validationSteps.add( - new YamlValidationStep( - node.getNextNodes(), - document.getSubStructure(node.getName()) - ) - ); - } - - private void addRequiredKeyNotFoundError(YamlSchemaNode node) { - errors.add( - new SchemaValidationError( - node.getPath(), - String.format("Key not found: %s", node.getName()) - ) - ); - } - - private void addIncorrectValueError(YamlDocument document, YamlSchemaNode node) { - errors.add( - new SchemaValidationError( - node.getPath() + node.getName(), - String.format( - "Value(s) is/are not in array of accepted values.%n value(s): %s%n accepted value(s): %s", - document.getValue(node.getName()), node.getAcceptedValues()) - ) - ); - } -} diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java b/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java deleted file mode 100644 index eb5ab8e..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.process; - -import org.onap.validation.yaml.model.YamlDocument; -import org.onap.validation.yaml.schema.node.YamlSchemaNode; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -class YamlValidationStep { - - private final List schemaNodes; - private final YamlDocument document; - - YamlValidationStep(List nodes, YamlDocument yaml) { - this.schemaNodes = new ArrayList<>(nodes); - this.document = yaml; - } - - List getSchemaNodes() { - return Collections.unmodifiableList(schemaNodes); - } - - YamlDocument getDocument() { - return document; - } - -} diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java b/csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java deleted file mode 100644 index 69bb6cd..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.schema; - -import org.onap.validation.yaml.schema.node.YamlSchemaNode; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class YamlSchema { - - private final List rootNodes; - - public List getRootNodes() { - return Collections.unmodifiableList(rootNodes); - } - - YamlSchema(List rootNodes) { - this.rootNodes = new ArrayList<>(rootNodes); - } -} diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java b/csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java deleted file mode 100644 index df7d673..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - - -package org.onap.validation.yaml.schema; - -import org.onap.validation.yaml.exception.YamlProcessingException; -import org.onap.validation.yaml.model.YamlDocument; -import org.onap.validation.yaml.model.YamlDocumentFactory; -import org.onap.validation.yaml.schema.node.YamlSchemaNode; -import org.onap.validation.yaml.schema.node.YamlSchemaNodeFactory; - -import java.util.ArrayList; -import java.util.List; - -public class YamlSchemaFactory { - - - private static final String ROOT_PATH = "/"; - - public YamlSchema createTreeStructuredYamlSchema(YamlDocument schema) - throws YamlProcessingException { - - return new YamlSchema(getRootNodes(schema)); - } - - private List getRootNodes(YamlDocument yamlDocument) - throws YamlProcessingException { - - List nextNodes = new ArrayList<>(); - for(String nodeName: yamlDocument.getYaml().keySet()) { - nextNodes.add( - new YamlSchemaNodeFactory().createNode( - nodeName, - ROOT_PATH, - new YamlDocumentFactory().createYamlDocument( - yamlDocument.getYaml().get(nodeName) - ) - ) - ); - } - return nextNodes; - } - -} diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java b/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java deleted file mode 100644 index 0f5b480..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.schema.node; - -import org.onap.validation.yaml.exception.YamlProcessingException; -import org.onap.validation.yaml.model.YamlDocument; -import org.onap.validation.yaml.model.YamlDocumentFactory; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -public class YamlSchemaBranchNode extends YamlSchemaNode { - - private final YamlDocument nextNodesInLazyForm; - private Optional> nextNodes; - - YamlSchemaBranchNode(String name, String path, boolean required, String comment, - YamlDocument nextNodesInLazyForm) { - super(name, path, required, comment); - this.nextNodesInLazyForm = nextNodesInLazyForm; - this.nextNodes = Optional.empty(); - } - - @Override - public boolean isContainingSubStructure() { - return true; - } - - @Override - public List getAcceptedValues() { - return Collections.emptyList(); - } - - @Override - public synchronized List getNextNodes() throws YamlSchemaProcessingException { - try { - return nextNodes.orElseGet(this::loadNextNodes); - } catch (YamlSchemaLazyLoadingException lazyLoadingException) { - throw new YamlSchemaProcessingException(lazyLoadingException); - } - } - - private List loadNextNodes() { - try { - List loadedNextNodes = new ArrayList<>(); - for (String key : nextNodesInLazyForm.getYaml().keySet()) { - YamlDocument substructure = new YamlDocumentFactory() - .createYamlDocument(nextNodesInLazyForm.getYaml().get(key)); - loadedNextNodes.add(new YamlSchemaNodeFactory().createNode(key, getPath() + getName() + "/", substructure)); - } - nextNodes = Optional.of(loadedNextNodes); - return loadedNextNodes; - } catch (YamlProcessingException e) { - throw new YamlSchemaLazyLoadingException("Lazy loading failed, due to yaml parsing exception.",e); - } - } - - static class YamlSchemaLazyLoadingException extends RuntimeException { - YamlSchemaLazyLoadingException(String message, Throwable throwable) { - super(message, throwable); - } - } -} diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java b/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java deleted file mode 100644 index c98f41e..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.schema.node; - -import org.onap.validation.yaml.model.YamlParametersList; - -import java.util.Collections; -import java.util.List; - -public class YamlSchemaLeafNode extends YamlSchemaNode { - - private final YamlParametersList acceptedValues; - - YamlSchemaLeafNode(String name, String path, boolean required, String comment, - YamlParametersList acceptedValues) { - super(name, path, required, comment); - this.acceptedValues = acceptedValues; - } - - @Override - public List getAcceptedValues() { - return acceptedValues.getParameters(); - } - - @Override - public List getNextNodes() { - return Collections.emptyList(); - } - - @Override - public boolean isContainingSubStructure() { - return false; - } - -} diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java b/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java deleted file mode 100644 index 28913a2..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.schema.node; - -import org.onap.validation.yaml.exception.YamlProcessingException; - -import java.util.List; - -public abstract class YamlSchemaNode { - - private final String path; - private final String name; - private final boolean required; - private final String comment; - - - public String getName() { - return name; - } - - public String getPath() { - return path; - } - - public boolean isRequired() { - return required; - } - - public abstract List getAcceptedValues(); - - public abstract List getNextNodes() throws YamlSchemaProcessingException; - - public abstract boolean isContainingSubStructure(); - - public String getComment() { - return comment; - } - - YamlSchemaNode(String name, String path, boolean required, String comment) { - this.name = name; - this.path = path; - this.required = required; - this.comment = comment; - } - - static class YamlSchemaProcessingException extends YamlProcessingException { - YamlSchemaProcessingException(Throwable throwable) { - super(throwable); - } - } -} diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java b/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java deleted file mode 100644 index 79a8f14..0000000 --- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.schema.node; - -import org.onap.validation.yaml.exception.YamlProcessingException; -import org.onap.validation.yaml.model.YamlDocument; -import org.onap.validation.yaml.model.YamlDocumentFactory; -import org.onap.validation.yaml.model.YamlParameterListFactory; -import org.onap.validation.yaml.model.YamlParametersList; - -import static org.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException; - -public class YamlSchemaNodeFactory { - - public static final String EMPTY_COMMENT = "no comment available"; - static final String STRUCTURE_KEY = "structure"; - static final String COMMENT_KEY = "comment"; - static final String VALUE_KET = "value"; - static final String PRESENCE_KEY = "presence"; - static final String PRESENCE_REQUIRED_KEY = "required"; - - public YamlSchemaNode createNode(String nodeName, String path, YamlDocument yamlDocument) - throws YamlProcessingException { - - YamlSchemaNode yamlSchemaNode; - if(isYamlContainingKey(yamlDocument, STRUCTURE_KEY)) { - yamlSchemaNode = new YamlSchemaBranchNode( - nodeName, path, getIsPresenceRequired(yamlDocument), getComment(yamlDocument), - getNextNodes(yamlDocument) - ); - } else { - yamlSchemaNode = new YamlSchemaLeafNode( - nodeName, path, getIsPresenceRequired(yamlDocument), getComment(yamlDocument), - getAcceptedValues(yamlDocument) - ); - } - return yamlSchemaNode; - } - - private YamlDocument getNextNodes(YamlDocument yamlDocument) - throws YamlDocumentParsingException { - return new YamlDocumentFactory().createYamlDocument(yamlDocument.getYaml().get(STRUCTURE_KEY)); - } - - private String getComment(YamlDocument yamlDocument) { - - return isYamlContainingKey(yamlDocument, COMMENT_KEY) - ? yamlDocument.getYaml().get(COMMENT_KEY).toString() - : EMPTY_COMMENT; - } - - private YamlParametersList getAcceptedValues(YamlDocument yamlDocument) { - - return isYamlContainingKey(yamlDocument, VALUE_KET) - ? new YamlParameterListFactory().createYamlParameterList(yamlDocument.getYaml().get(VALUE_KET)) - : new YamlParameterListFactory().createEmptyYamlParameterList(); - } - - private boolean getIsPresenceRequired(YamlDocument yamlDocument) { - - return isYamlContainingKey(yamlDocument, PRESENCE_KEY) - && yamlDocument.getYaml().get(PRESENCE_KEY).equals(PRESENCE_REQUIRED_KEY); - } - - private boolean isYamlContainingKey(YamlDocument yamlDocument, String structureKey) { - return yamlDocument.getYaml().containsKey(structureKey); - } - -} diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java deleted file mode 100644 index f89cc68..0000000 --- a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml; - -import org.assertj.core.util.Lists; -import org.junit.Test; -import org.onap.validation.yaml.error.YamlDocumentValidationError; -import org.onap.validation.yaml.exception.YamlProcessingException; -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; - -public class YamlFileValidatorTest { - - @Test - public void shouldReturnCorrectErrorsWhenGivenPathToValidPmDictionaryFile() throws YamlProcessingException { - // given - String path = getFullPathForGivenResources(YamlLoadingUtils.PATH_TO_VALID_YAML); - - // when - List validationErrors = - new YamlFileValidator().validateYamlFileWithSchema(path); - - // then - assertValidationReturnedExpectedErrors(validationErrors); - - } - - @Test - public void shouldReturnCorrecErrorsWhenGivenPathToValidJsonStylePmDictionaryFile() throws YamlProcessingException { - // given - String path = getFullPathForGivenResources(YamlLoadingUtils.PATH_TO_VALID_JSON_STYLE_YAML); - - // when - List validationErrors = - new YamlFileValidator().validateYamlFileWithSchema(path); - - // then - assertValidationReturnedExpectedErrors(validationErrors); - } - - - private void assertValidationReturnedExpectedErrors(List validationErrors) { - assertThat(validationErrors).isNotNull(); - assertThat(validationErrors).hasSize(4); - assertThat(validationErrors).usingRecursiveFieldByFieldElementComparator().containsAll( - Lists.list( - new YamlDocumentValidationError(1, - "/pmMetaData/pmFields/measResultType", - "Value(s) is/are not in array of accepted values.\n" + - " value(s): integer\n" + - " accepted value(s): [float, uint32, uint64]"), - new YamlDocumentValidationError(1, - "/pmMetaData/pmFields/", - "Key not found: measChangeType"), - new YamlDocumentValidationError(2, - "/pmMetaData/pmFields/", - "Key not found: measChangeType"), - new YamlDocumentValidationError(3, - "/pmMetaData/pmFields/measAdditionalFields/vendorField1", - "Value(s) is/are not in array of accepted values.\n" + - " value(s): [Z, A]\n" + - " accepted value(s): [X, Y, Z]") - ) - ); - } - @Test - public void shouldThrowErrorWhenGivenPathToInvalidPmDictionaryFile() { - // given - String path = getFullPathForGivenResources(YamlLoadingUtils.PATH_TO_MULTI_DOCUMENT_INVALID_YAML); - // when then - assertThatThrownBy(() -> - new YamlFileValidator().validateYamlFileWithSchema(path) - ).isInstanceOf(ParserException.class) - .hasMessageContaining( - "expected the node content, but found ''" - ); - } - - @Test - public void shouldThrowErrorWhenGivenInvalidPath() { - // given - String path ="invalid/path/to/pm_dictionary"; - - // when then - assertThatThrownBy(() -> - new YamlFileValidator().validateYamlFileWithSchema(path) - ).isInstanceOf(YamlProcessingException.class) - .hasMessageContaining( - "PM_Dictionary YAML file is empty" - ); - } - - private String getFullPathForGivenResources(String pathToValidYaml) { - return this.getClass().getClassLoader().getResource( - pathToValidYaml - ).getPath(); - } -} diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java deleted file mode 100644 index 4c68d60..0000000 --- a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml; - -import org.junit.Test; -import org.onap.validation.yaml.exception.YamlProcessingException; -import org.onap.validation.yaml.model.YamlDocument; -import org.onap.validation.yaml.model.YamlDocumentFactory; -import org.yaml.snakeyaml.parser.ParserException; -import org.yaml.snakeyaml.scanner.ScannerException; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - - -public class YamlLoaderTest { - - private static final int EXPECTED_NUMBER_OF_DOCUMENTS = 5; - private static final String LETTER_S_WITH_ASCII_CODE = "s(115)"; - - @Test - public void shouldLoadAllDocumentsFromYamlFile() throws YamlDocumentFactory.YamlDocumentParsingException { - // when - List documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile(); - - // then - assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS); - } - - @Test - public void shouldLoadAllDocumentsFromJsonStyleYamlFile() throws YamlDocumentFactory.YamlDocumentParsingException { - // when - List documents = YamlLoadingUtils.loadValidJsonStyleMultiDocumentYamlFile(); - - // then - assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS); - } - - @Test - public void shouldLoadAllDocumentsFromYamlFileUsingPathInString() throws YamlProcessingException { - // when - List documents = YamlLoadingUtils.loadValidMultiDocumentYamlFileUsingStringPath(); - - // then - assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS); - } - - @Test - public void shouldThrowExceptionWhenLoadingDocumentsFromInvalidYamlFile() { - // when then - assertThatThrownBy(YamlLoadingUtils::tryToLoadMultiDocumentInvalidYamlFile - ).isInstanceOf(ParserException.class) - .hasMessageContaining("expected the node content, but found ''"); - } - - @Test - public void shouldThrowExceptionWhenLoadingDocumentsFromInvalidYamlFileUsingPathInString() { - // when then - assertThatThrownBy(YamlLoadingUtils::tryToLoadMultiDocumentInvalidYamlFileUsingStringPath - ).isInstanceOf(ParserException.class) - .hasMessageContaining("expected the node content, but found ''"); - } - - - @Test - public void shouldThrowExceptionWhenLoadingInvalidYamlFileWithIncorrectKeyMapping() { - // when then - assertThatThrownBy(YamlLoadingUtils::tryToLoadInvalidYamlFileWithIncorrectKeyMapping - ).isInstanceOf(ScannerException.class) - .hasMessageContaining("mapping values are not allowed here"); - } - - - @Test - public void shouldThrowExceptionWhenLoadingInvalidYamlFileWithUnknownEscapeCharacter() { - // when then - assertThatThrownBy(YamlLoadingUtils::tryToLoadInvalidYamlFileWithUnknownEscapeCharacter - ).isInstanceOf(ScannerException.class) - .hasMessageContaining("found unknown escape character " + LETTER_S_WITH_ASCII_CODE); - } - -} diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java b/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java deleted file mode 100644 index 8d03910..0000000 --- a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml; - -import org.onap.validation.yaml.exception.YamlProcessingException; -import org.onap.validation.yaml.model.YamlDocument; - -import java.net.URL; -import java.util.List; - -import static org.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException; - -public final class YamlLoadingUtils { - - private YamlLoadingUtils() {} - - public static final int VALID_YAML_DOCUMENT_INDEX = 4; - public static final int YAML_DOCUMENT_WITH_WRONG_VALUE_IN_ARRAY_INDEX = 3; - public static final int YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX = 2; - public static final int YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX = 1; - - static final String PATH_TO_VALID_YAML = "yaml_schema/PM_Dictionary.yaml"; - static final String PATH_TO_VALID_JSON_STYLE_YAML = "yaml_schema/PM_Dictionary_JSON_Style.yaml"; - private static final String PATH_TO_SIMPLE_VALID_SCHEMA = "yaml_schema/Simple_Valid_Schema.yaml"; - private static final String PATH_TO_SIMPLE_VALID_SCHEMA_MULTI_ROOT = "yaml_schema/Simple_Valid_Schema_Multi_Root.yaml"; - private static final String PATH_TO_SIMPLE_INVALID_SCHEMA = "yaml_schema/Simple_Invalid_Schema_Construction.yaml"; - private static final String PATH_TO_SIMPLE_INVALID_SCHEMA_FOR_LAZY_LOADING = "yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml"; - static final String PATH_TO_MULTI_DOCUMENT_INVALID_YAML = "yaml_schema/Multi_Document_Invalid.yaml"; - private static final String PATH_TO_INVALID_YAML_WITH_INCORRECT_KEY_MAPPING = "yaml_schema/Simple_Invalid_Mapping_Value.yaml"; - private static final String PATH_TO_INVALID_YAML_WITH_UNKNOWN_ESCAPE_CHARACTER = "yaml_schema/Simple_Unknown_Escape_Character.yaml"; - - public static List loadValidMultiDocumentYamlFile() throws YamlDocumentParsingException { - return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_VALID_YAML)); - } - - public static List loadValidJsonStyleMultiDocumentYamlFile() throws YamlDocumentParsingException { - return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_VALID_JSON_STYLE_YAML)); - } - - public static List loadValidMultiDocumentYamlFileUsingStringPath() throws YamlProcessingException { - return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_VALID_YAML).getPath()); - } - - public static YamlDocument loadSimpleValidYamlSchemaFile() throws YamlDocumentParsingException { - return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_VALID_SCHEMA)).get(0); - } - - public static YamlDocument loadSimpleInvalidYamlSchemaFile() throws YamlDocumentParsingException { - return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_INVALID_SCHEMA)).get(0); - } - - public static YamlDocument loadSimpleInvalidYamlSchemaForLazyLoadingFile() throws YamlDocumentParsingException { - return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_INVALID_SCHEMA_FOR_LAZY_LOADING)).get(0); - } - - public static YamlDocument loadSimpleValidYamlSchemaWithMultiRootFile() throws YamlDocumentParsingException { - return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_VALID_SCHEMA_MULTI_ROOT)).get(0); - } - - public static List tryToLoadMultiDocumentInvalidYamlFile() throws YamlDocumentParsingException { - return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_MULTI_DOCUMENT_INVALID_YAML)); - } - - public static List tryToLoadMultiDocumentInvalidYamlFileUsingStringPath() throws YamlProcessingException { - return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_MULTI_DOCUMENT_INVALID_YAML).getPath()); - } - - public static List tryToLoadInvalidYamlFileWithIncorrectKeyMapping() throws YamlDocumentParsingException { - return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_INVALID_YAML_WITH_INCORRECT_KEY_MAPPING)); - } - - public static List tryToLoadInvalidYamlFileWithUnknownEscapeCharacter() throws YamlDocumentParsingException { - return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_INVALID_YAML_WITH_UNKNOWN_ESCAPE_CHARACTER)); - } - - private static URL getUrlForGivenPath(String path) { - return YamlLoadingUtils.class.getClassLoader().getResource(path); - } -} diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java deleted file mode 100644 index efe9d69..0000000 --- a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml; - -import org.assertj.core.util.Lists; -import org.junit.Test; -import org.onap.validation.yaml.exception.YamlProcessingException; -import org.onap.validation.yaml.error.SchemaValidationError; -import org.onap.validation.yaml.model.YamlDocument; -import org.onap.validation.yaml.schema.YamlSchemaFactory; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.onap.validation.yaml.YamlLoadingUtils.VALID_YAML_DOCUMENT_INDEX; -import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_MISSING_FIELD_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_WRONG_VALUE_IN_ARRAY_INDEX; - -public class YamlValidatorTest { - - - @Test - public void shouldCreateValidatorUsingSchemaLoadedFromYamlFileAndValidatedJsonStyleDocumentsFromThatFile() - throws YamlProcessingException { - - // given - List documents = YamlLoadingUtils.loadValidJsonStyleMultiDocumentYamlFile(); - YamlValidator validator = new YamlValidator(new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0))); - Map> validationErrors = new HashMap<>(); - - // when - for (int documentIndex = 1 ; documentIndex < documents.size() ; documentIndex++) { - validationErrors.put(documentIndex, validator.validate(documents.get(documentIndex))); - } - - // then - assertValidatorReturnedCorrectErrors(validationErrors); - } - - @Test - public void shouldCreateValidatorUsingSchemaLoadedFromYamlFileAndValidatedDocumentsFromThatFile() - throws YamlProcessingException { - - // given - List documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile(); - YamlValidator validator = new YamlValidator(new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0))); - Map> validationErrors = new HashMap<>(); - - // when - for (int documentIndex = 1 ; documentIndex < documents.size() ; documentIndex++) { - validationErrors.put(documentIndex, validator.validate(documents.get(documentIndex))); - } - - // then - assertValidatorReturnedCorrectErrors(validationErrors); - } - - private void assertValidatorReturnedCorrectErrors(Map> validationErrors) { - - SchemaValidationError expectedValidationValueError = - new SchemaValidationError( - "/pmMetaData/pmFields/measResultType", - "Value(s) is/are not in array of accepted values.\n" - + " value(s): integer\n" - + " accepted value(s): [float, uint32, uint64]" - ); - SchemaValidationError expectedValidationKeyError = - new SchemaValidationError( - "/pmMetaData/pmFields/", - "Key not found: measChangeType" - ); - SchemaValidationError expectedValidationValuesInArrayError = - new SchemaValidationError( - "/pmMetaData/pmFields/measAdditionalFields/vendorField1", - "Value(s) is/are not in array of accepted values.\n" - + " value(s): [Z, A]\n" - + " accepted value(s): [X, Y, Z]" - ); - - assertThat(validationErrors.size()).isEqualTo(4); - assertThat(validationErrors).containsKeys(1,2,3); - assertThat(validationErrors.get(YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX)).hasSize(2); - assertThat(validationErrors.get(YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX)) - .usingFieldByFieldElementComparator() - .containsAll( - Lists.list( - expectedValidationValueError, - expectedValidationKeyError - )); - assertThat(validationErrors.get(YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX)).hasSize(1); - assertThat(validationErrors.get(YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX)) - .usingFieldByFieldElementComparator() - .contains( - expectedValidationKeyError - ); - assertThat(validationErrors.get(YAML_DOCUMENT_WITH_WRONG_VALUE_IN_ARRAY_INDEX)).hasSize(1); - assertThat(validationErrors.get(YAML_DOCUMENT_WITH_WRONG_VALUE_IN_ARRAY_INDEX)) - .usingFieldByFieldElementComparator() - .contains( - expectedValidationValuesInArrayError - ); - assertThat(validationErrors.get(VALID_YAML_DOCUMENT_INDEX)).hasSize(0); - } - -} diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java deleted file mode 100644 index 7879d4e..0000000 --- a/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.model; - -import org.assertj.core.util.Lists; -import org.junit.Test; - -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -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.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException; - -public class YamlDocumentFactoryTest { - - @Test - public void shouldTurnMapOfUnknownKeyTypeToMapWithStringKeysAndBeAbleToReturnStringifyValues() - throws YamlDocumentParsingException { - // given - Map inputMap = new HashMap<>(); - List testList = Lists.list("element1", "element11"); - Map testEmptyMap = Collections.emptyMap(); - - inputMap.put("test", testList); - inputMap.put(345, "element2"); - inputMap.put("test2", "element3"); - inputMap.put(2.67, testEmptyMap); - - // 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("{}"); - } - - @Test - public void shouldTurnMapOfUnknownKeyTypeToMapWithStringKeysAndBeAbleToExtractSubStructure() - throws YamlDocumentParsingException { - // given - Map inputMap = new HashMap<>(); - Map subStructureMap = new HashMap<>(); - - inputMap.put("test", "element1"); - inputMap.put("structure", subStructureMap); - - subStructureMap.put("subTest1", "subElement1"); - subStructureMap.put("subTest2", "subElement2"); - - // 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"); - } - - @Test - public void shouldTurnMapOfUnknownKeyTypeToMapWithStringKeysAndBeAbleToExtractParametersList() - throws YamlDocumentParsingException { - // given - Map inputMap = new HashMap<>(); - List parametersList = new LinkedList<>(); - - inputMap.put("test", "element1"); - inputMap.put("parameters", parametersList); - - parametersList.add("parameter1"); - parametersList.add("parameter2"); - - // 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"); - } - - @Test - public void shouldThrowExceptionIfGetSubStructureIsCalledOnList() - throws YamlDocumentParsingException { - // given - Map inputMap = new HashMap<>(); - List testList = Lists.list("element1", "element2"); - - inputMap.put("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) - ); - } - - @Test - public void shouldThrowExceptionIfGetSubStructureIsCalledOnString() - throws YamlDocumentParsingException { - // given - Map inputMap = new HashMap<>(); - - inputMap.put("test", "testElement"); - - 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.", "testElement") - ); - } -} diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java deleted file mode 100644 index 34e61c5..0000000 --- a/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.model; - -import org.assertj.core.util.Lists; -import org.junit.Test; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -public class YamlParameterListFactoryTest { - - @Test - public void shouldCreateEmptyParametersList() { - // when - YamlParametersList parametersList = new YamlParameterListFactory().createEmptyYamlParameterList(); - - // then - assertThat(parametersList).isNotNull(); - assertThat(parametersList.getParameters()).isEmpty(); - } - - @Test - public void shouldCreateParametersListContainingStringsFromListContainingSimpleTypes() { - // given - List testList = Lists.list("test1",3,23.45,'a',"test2"); - - // when - YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testList); - - // then - assertThat(parametersList).isNotNull(); - assertThat(parametersList.getParameters()).hasSize(5); - assertThat(parametersList.getParameters()).contains("test1","test2","3","23.45","a"); - } - - @Test - public void shouldCreateParametersListContainingStringsFromListContainingVariousTypes() { - // given - List testList = Lists.list("test1",3,Lists.list(2,3,4),"test2"); - - // when - YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testList); - - // then - assertThat(parametersList).isNotNull(); - assertThat(parametersList.getParameters()).hasSize(4); - assertThat(parametersList.getParameters()).contains("test1","test2","3","[2, 3, 4]"); - } - - @Test - public void shouldCreateListWithOneStringWhenGivenObjectIsNotList() { - // given - Object testObject = "test"; - - // when - YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testObject); - - // then - assertThat(parametersList).isNotNull(); - assertThat(parametersList.getParameters()).hasSize(1); - assertThat(parametersList.getParameters()).contains("test"); - } - -} diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java deleted file mode 100644 index 12fe9ec..0000000 --- a/csarvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.process; - -import org.junit.Test; -import org.onap.validation.yaml.YamlLoadingUtils; -import org.onap.validation.yaml.exception.YamlProcessingException; -import org.onap.validation.yaml.error.SchemaValidationError; -import org.onap.validation.yaml.model.YamlDocument; -import org.onap.validation.yaml.schema.YamlSchema; -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.onap.validation.yaml.YamlLoadingUtils.VALID_YAML_DOCUMENT_INDEX; -import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX; -import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX; - - -public class YamlValidationProcessTest { - - @Test - public void shouldReturnNoErrorWhenProcessingValidPmDictionaryYaml() - throws YamlProcessingException { - // given - List documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile(); - YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0)); - YamlDocument document = documents.get(VALID_YAML_DOCUMENT_INDEX); - - // when - List errors = new YamlValidationProcess(schema,document).validate(); - - // then - assertThat(errors).isEmpty(); - } - - @Test - public void shouldReturnOneErrorWhenProcessingPmDictionaryYamlWithMissingField() - throws YamlProcessingException { - // given - List documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile(); - YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0)); - YamlDocument document = documents.get(YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX); - - // when - List errors = new YamlValidationProcess(schema,document).validate(); - - // then - assertThat(errors).hasSize(1); - } - - @Test - public void shouldReturnTwoErrorsWhenProcessingPmDictionaryYamlWithMissingFieldAndIncorrectValue() - throws YamlProcessingException { - // given - List 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 - List errors = new YamlValidationProcess(schema,document).validate(); - - // then - assertThat(errors).hasSize(2); - } - - @Test - public void shouldThrowExceptionWhenProcessingPmDictionaryIsNotValidYaml() - throws YamlProcessingException { - // given - List 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() - ).isInstanceOf(YamlProcessingException.class) - .hasMessageContaining( - String.format("Lazy loading failed, due to yaml parsing exception.") - ); - } -} diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java deleted file mode 100644 index 4c05d71..0000000 --- a/csarvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.schema; - -import org.junit.Test; -import org.onap.validation.yaml.YamlLoadingUtils; -import org.onap.validation.yaml.exception.YamlProcessingException; -import org.onap.validation.yaml.model.YamlDocument; -import org.onap.validation.yaml.schema.node.YamlSchemaNode; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException; -import static org.onap.validation.yaml.schema.node.YamlSchemaNodeFactory.EMPTY_COMMENT; -import static org.onap.validation.yaml.schema.node.YamlSchemaNodeFactoryTest.assertThatBranchNodeIsValid; -import static org.onap.validation.yaml.schema.node.YamlSchemaNodeFactoryTest.assertThatLeafNodeIsValid; - - -public class YamlSchemaFactoryTest { - - @Test - public void shouldCreateYamlSchemaFromYamlDocumentWithMultipleRoots() - throws YamlProcessingException { - - // given - YamlDocument documents = YamlLoadingUtils.loadSimpleValidYamlSchemaWithMultiRootFile(); - - // when - YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents); - - // 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"); - } - - - @Test - public void shouldCreateYamlSchemaFromYamlDocument() - throws YamlProcessingException { - - // given - YamlDocument documents = YamlLoadingUtils.loadSimpleValidYamlSchemaFile(); - - // when - YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents); - - // then - assertThat(schema).isNotNull(); - assertThat(schema.getRootNodes()).hasSize(1); - YamlSchemaNode pmMetaData = schema.getRootNodes().get(0); - assertThatBranchNodeIsValid(pmMetaData, "pmMetaData","/", true, EMPTY_COMMENT, - 2); - - YamlSchemaNode pmHeader = pmMetaData.getNextNodes().get(1); - assertThatBranchNodeIsValid(pmHeader, "pmHeader","/pmMetaData/", true, EMPTY_COMMENT, - 1); - - YamlSchemaNode nfType = pmHeader.getNextNodes().get(0); - assertThatLeafNodeIsValid(nfType, "nfType", "/pmMetaData/pmHeader/", true, "nfType comment"); - - YamlSchemaNode pmFields = pmMetaData.getNextNodes().get(0); - assertThatBranchNodeIsValid(pmFields, "pmFields", "/pmMetaData/", true, EMPTY_COMMENT, - 2); - - YamlSchemaNode measChangeType = pmFields.getNextNodes().get(1); - assertThatLeafNodeIsValid(measChangeType, "measChangeType", "/pmMetaData/pmFields/", - true, "measChangeType comment", - "added", "modified", "deleted"); - - YamlSchemaNode measAdditionalFields = pmFields.getNextNodes().get(0); - assertThatBranchNodeIsValid(measAdditionalFields, "measAdditionalFields", "/pmMetaData/pmFields/", - true, "measAdditionalFields comment", - 2); - - YamlSchemaNode vendorField1 = measAdditionalFields.getNextNodes().get(0); - assertThatLeafNodeIsValid(vendorField1, "vendorField1", "/pmMetaData/pmFields/measAdditionalFields/", - true, "vendorField1 comment", - "X", "Y", "Z"); - YamlSchemaNode vendorField2 = measAdditionalFields.getNextNodes().get(1); - assertThatLeafNodeIsValid(vendorField2, "vendorField2", "/pmMetaData/pmFields/measAdditionalFields/", - false, "vendorField2 comment", - "A", "B"); - } - - @Test - public void shouldThrowYamlParsingExceptionWhenLoadedSchemaIsInvalid() - throws YamlDocumentParsingException { - - // given - YamlDocument documents = YamlLoadingUtils.loadSimpleInvalidYamlSchemaFile(); - - // when/then - assertThatThrownBy(() -> - new YamlSchemaFactory().createTreeStructuredYamlSchema(documents) - ).isInstanceOf(YamlDocumentParsingException.class) - .hasMessageContaining( - String.format( - "Fail to parse given objects: %s as yaml document", - documents.getSubStructure("pmMetaData").getYaml().get("structure") - ) - ); - } - -} diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java deleted file mode 100644 index d35e3b2..0000000 --- a/csarvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright 2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.onap.validation.yaml.schema.node; - -import org.assertj.core.util.Lists; -import org.junit.Test; -import org.onap.validation.yaml.YamlLoadingUtils; -import org.onap.validation.yaml.exception.YamlProcessingException; -import org.onap.validation.yaml.model.YamlDocument; -import org.onap.validation.yaml.model.YamlDocumentFactory; - -import java.util.HashMap; -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.onap.validation.yaml.schema.node.YamlSchemaNodeFactory.EMPTY_COMMENT; - -public class YamlSchemaNodeFactoryTest { - - private static final String ROOT_PATH = "/"; - - @Test - public void shouldThrowExceptionDuringLazyLoadingWhenLoadedSchemaHaveInvalidSubStructure() - throws YamlProcessingException { - // given - String nodeName = "pmMetaData"; - - YamlDocument document = YamlLoadingUtils.loadSimpleInvalidYamlSchemaForLazyLoadingFile(); - YamlSchemaNode node = new YamlSchemaNodeFactory() - .createNode(nodeName, ROOT_PATH, document.getSubStructure(nodeName)); - - // when/then - assertThatThrownBy(node::getNextNodes - ).isInstanceOf(YamlSchemaNode.YamlSchemaProcessingException.class) - .hasMessageContaining( - "Lazy loading failed, due to yaml parsing exception." - ); - } - - @Test - public void shouldCreateLeafNodeIfGivenYamlDocumentHaveNoSubStructure() - throws YamlProcessingException { - // given - String nodeName = "leaf_test"; - String comment = "test leaf node"; - List acceptedValues = Lists.list("val1", "val2"); - Map 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 - YamlSchemaNode yamlSchemaNode = new YamlSchemaNodeFactory().createNode(nodeName, ROOT_PATH, document); - - // then - assertThatLeafNodeIsValid( - yamlSchemaNode, nodeName, ROOT_PATH, true, comment, - acceptedValues.toArray(new String[acceptedValues.size()]) - ); - } - - @Test - public void shouldCreateBranchNodeIfGivenYamlDocumentHaveSubStructure() - throws YamlProcessingException { - // given - String nodeName = "branch_test"; - String comment = "test branch node"; - - Map subStructure = new HashMap<>(); - String subNode1Name = "branch_test_node1"; - String subNode2Name = "branch_test_node2"; - subStructure.put(subNode1Name, new HashMap<>()); - subStructure.put(subNode2Name, new HashMap<>()); - - Map nodeInYamlFormat = new HashMap<>(); - nodeInYamlFormat.put(YamlSchemaNodeFactory.PRESENCE_KEY, YamlSchemaNodeFactory.PRESENCE_REQUIRED_KEY); - nodeInYamlFormat.put(YamlSchemaNodeFactory.COMMENT_KEY, comment); - nodeInYamlFormat.put(YamlSchemaNodeFactory.STRUCTURE_KEY, subStructure); - YamlDocument document = new YamlDocumentFactory().createYamlDocument( - nodeInYamlFormat - ); - - // when - YamlSchemaNode yamlSchemaNode = new YamlSchemaNodeFactory().createNode(nodeName, ROOT_PATH, document); - - // then - assertThatBranchNodeIsValid( - yamlSchemaNode, nodeName, ROOT_PATH, true, comment, 2); - - List subNodes = yamlSchemaNode.getNextNodes(); - assertThat(subNodes).hasSize(2); - assertThatLeafNodeIsValid( - subNodes.get(1), subNode1Name, ROOT_PATH + nodeName + "/", false, EMPTY_COMMENT); - assertThatLeafNodeIsValid( - subNodes.get(0), subNode2Name, ROOT_PATH + nodeName + "/", false, EMPTY_COMMENT); - } - - public static void assertThatBranchNodeIsValid( - YamlSchemaNode yamlSchemaNode, String name, String path, boolean isRequired, String comment, - int numberOfSubNodes - ) throws YamlSchemaNode.YamlSchemaProcessingException { - assertThatNodeIsValid(yamlSchemaNode, name, path, isRequired, comment); - - assertThat(yamlSchemaNode.getClass()).isEqualTo(YamlSchemaBranchNode.class); - assertThat(yamlSchemaNode.isContainingSubStructure()).isTrue(); - assertThat(yamlSchemaNode.getNextNodes()).hasSize(numberOfSubNodes); - assertThat(yamlSchemaNode.getAcceptedValues()).isEmpty(); - } - - public static void assertThatLeafNodeIsValid( - YamlSchemaNode yamlSchemaNode, String name, String path, boolean isRequired, String comment, - String... acceptedValues - ) throws YamlSchemaNode.YamlSchemaProcessingException { - assertThatNodeIsValid(yamlSchemaNode, name, path, isRequired, comment); - - assertThat(yamlSchemaNode.getClass()).isEqualTo(YamlSchemaLeafNode.class); - assertThat(yamlSchemaNode.isContainingSubStructure()).isFalse(); - assertThat(yamlSchemaNode.getAcceptedValues()).containsExactly(acceptedValues); - assertThat(yamlSchemaNode.getNextNodes()).isEmpty(); - } - - private static void assertThatNodeIsValid(YamlSchemaNode yamlSchemaNode, String name, String path, boolean isRequired, String comment) { - assertThat(yamlSchemaNode).isNotNull(); - assertThat(yamlSchemaNode.getName()).isEqualTo(name); - assertThat(yamlSchemaNode.getPath()).isEqualTo(path); - if (comment.isEmpty()) { - assertThat(yamlSchemaNode.getComment()).isNotEmpty(); - } else { - assertThat(yamlSchemaNode.getComment()).isEqualTo(comment); - } - assertThat(yamlSchemaNode.isRequired()).isEqualTo(isRequired); - } -} diff --git a/csarvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml b/csarvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml deleted file mode 100644 index aab34fa..0000000 --- a/csarvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml +++ /dev/null @@ -1,86 +0,0 @@ -... -# PM Dictionary perf3gpp measurements for the gnb-Nokia NF (bracket style yaml) ---- -pmMetaData: { - pmHeader: { - nfType: gnb-Nokia, - pmDefSchemaVsn: 2.0, - pmDefVsn: 5G19_1906_002 - }, - pmFields: { - iMeasInfoId: 2204, - iMeasType: 1, - - measCollectionMethod: CC, - measCondition: "This measurement is updated when X2AP: SgNB Modification Required message is sent to MeNB - with the SCG Change Indication set as PSCellChange.", - measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change attempts.", - measFamily: NINFC, - measInfoId: "NR Intra Frequency PSCell Change", - measLastChange: 5G18A_1807_003, - measObjClass: NGCELL, - measResultRange: 0-4096, - measResultType: integer, - measResultUnits: number, - measType: VS.NINFC.IntraFrPscelChAttempt, - measAdditionalFields: { - vendorField1: X, - vendorField2: B - } - } -} ---- -pmMetaData: { - pmHeader: { - nfType: gnb-Nokia, - pmDefSchemaVsn: 2.0, - pmDefVsn: 5G19_1906_002 - }, - pmFields: { - iMeasInfoId: 2204, - iMeasType: 2, - measCollectionMethod: CC, - measCondition: "This measurement is updated when the TDCoverall timer has elapsed before gNB receives the X2AP: SgNB Modification Confirm message.", - measDescription: "This measurement the number of intra gNB intra frequency PSCell change failures due to TDCoverall timer expiry.", - measFamily: NINFC, - measInfoId: "NR Intra Frequency PSCell Change", - measLastChange: 5G18A_1807_003, - measObjClass: NGCELL, - measResultRange: 0-4096, - measResultType: float, - measResultUnits: number, - measType: VS.NINFC.IntraFrPscelChFailTdcExp, - measAdditionalFields: { - vendorField1: Y - } - } -} -... ---- -pmMetaData: { - pmHeader: { - nfType: gnb-Nokia, - pmDefSchemaVsn: 2.0, - pmDefVsn: 5G19_1906_002 - }, - pmFields: { - iMeasInfoId: 2206, - iMeasType: 1, - measCondition: "This measurement is updated when MeNB replies to X2AP: SgNB Modification Required message with the X2AP: SgNB Modification Refuse message.", - measCollectionMethod: CC, - measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change failures due to MeNB refusal.", - measFamily: NINFC, - measInfoId: "NR Intra Frequency PSCell Change", - measLastChange: 5G19_1906_002, - measObjClass: NGCELL, - measResultRange: 0-4096, - measResultType: float, - measChangeType: added, - measResultUnits: number, - measType: VS.NINFC.IntraFrPscelChFailMenbRef, - measAdditionalFields: { - vendorField1: Z, - vendorField2: A - } - } -... diff --git a/csarvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml b/csarvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml deleted file mode 100644 index 12a4af9..0000000 --- a/csarvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml +++ /dev/null @@ -1,228 +0,0 @@ ---- -# PM Dictionary schema specifying and describing the meta information -# used to define perf3gpp measurements in the PM Dictionary -pmMetaData: { presence: required, structure: { - pmHeader: { - presence: required, - structure: { - nfType: { - presence: required, - comment: "NF type; should match the nfName-vendor string used in - the fileReady or perf3gpp eventName" - }, - pmDefSchemaVsn: { - presence: required, - value: 2.0, - comment: "PM Dictionary Schema Version from the VES Event - Registration specification" - }, - pmDefVsn: { - presence: required, - comment: "vendor-defined PM Dictionary version" - } - } - }, - pmFields: { - presence: required, - structure: { - iMeasInfoId: { - presence: required, - comment: "vendor-defined integer measurement group identifier" - }, - iMeasType: { - presence: required, - comment: "vendor-defined integer identifier for the measType; - must be combined with measInfoId to identify a - specific measurement." - }, - measChangeType: { - presence: required, - value: [added, modified, deleted], - comment: "indicates the type of change that occurred during - measLastChange" - }, - measCollectionMethod: { - presence: required, - value: [CC, SI, DER, Gauge, Average], - comment: "the measurement collection method; CC, SI, DER and - Gauge are as defined in 3GPP; average contains the - average value of the measurement during the - granularity period" - }, - measCondition: { - presence: required, - comment: "description of the condition causing the measurement" - }, - measDescription: { - presence: required, - comment: "description of the measurement information - and purpose" - }, - measFamily: { - presence: required, - comment: "abbreviation for a family of measurements, in - 3GPP format, or vendor defined" - }, - measInfoId: { - presence: required, - comment: "name for a group of related measurements in - 3GPP format or vendor defined" - }, - measLastChange: { - presence: required, - comment: "version of the PM Dictionary the last time this - measurement was added, modified or deleted" - }, - measObjClass: { - presence: required, - value: [NGBTS, NGCELL, IPNO, IPSEC, ETHIF], - comment: "measurement object class" - }, - measResultRange: { - presence: optional, - comment: "range of the measurement result; only necessary when - the range is smaller than the full range of the - data type" - }, - measResultType: { - presence: required, - value: [float, uint32, uint64], - comment: "data type of the measurement result" - }, - measResultUnits: { - presence: required, - value: [seconds, minutes, nanoseconds, microseconds, dB, - number, kilobytes, bytes, ethernetFrames, - packets, users], - comment: "units of measure for the measurement result" - }, - measType: { - presence: required, - comment: "measurement name in 3GPP or vendor-specific format; - vendor specific names are preceded with VS" - }, - measAdditionalFields: { - presence: required, - comment: "vendor-specific PM Dictionary fields", - structure: { - vendorField1: { - presence: required, - value: [X, Y, Z], - comment: "vendor field 1 description" - }, - vendorField2: { - presence: optional, - value: [A, B], - comment: "vendor field 2 description." - } - } - } - } - } -}} -... -# PM Dictionary perf3gpp measurements for the gnb-Nokia NF (bracket style yaml) ---- -pmMetaData: - pmHeader: - nfType: gnb-Nokia - pmDefSchemaVsn: 2.0 - pmDefVsn: 5G19_1906_002 - pmFields: - iMeasInfoId: 2204 - iMeasType: 1 - measCollectionMethod: CC - measCondition: "This measurement is updated when X2AP: SgNB Modification Required message is sent to MeNB - with the SCG Change Indication set as PSCellChange." - measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change attempts." - measFamily: NINFC - measInfoId: "NR Intra Frequency PSCell Change" - measLastChange: 5G18A_1807_003 - measObjClass: NGCELL - measResultRange: 0-4096 - measResultType: integer - measResultUnits: number - measType: VS.NINFC.IntraFrPscelChAttempt - measAdditionalFields: - vendorField1: X - vendorField2: B -... ---- -pmMetaData: - pmHeader: - nfType: gnb-Nokia - pmDefSchemaVsn: 2.0 - pmDefVsn: 5G19_1906_002 - pmFields: - iMeasInfoId: 2204 - iMeasType: 2 - measCollectionMethod: CC - measCondition: "This measurement is updated when the TDCoverall timer has elapsed before gNB receives the X2AP: SgNB Modification Confirm message." - measDescription: "This measurement the number of intra gNB intra frequency PSCell change failures due to TDCoverall timer expiry." - measFamily: NINFC - measInfoId: "NR Intra Frequency PSCell Change" - measLastChange: 5G18A_1807_003 - measObjClass: NGCELL - measResultRange: 0-4096 - measResultType: float - measResultUnits: number - measType: VS.NINFC.IntraFrPscelChFailTdcExp - measAdditionalFields: - vendorField1: - - Y - - X -... ---- -pmMetaData: - pmHeader: - nfType: gnb-Nokia - pmDefSchemaVsn: 2.0 - pmDefVsn: 5G19_1906_002 - pmFields: - iMeasInfoId: 2206 - iMeasType: 1 - measCondition: "This measurement is updated when MeNB replies to X2AP: SgNB Modification Required message with the X2AP: SgNB Modification Refuse message." - measCollectionMethod: CC - measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change failures due to MeNB refusal." - measFamily: NINFC - measInfoId: "NR Intra Frequency PSCell Change" - measLastChange: 5G19_1906_002 - measObjClass: NGCELL - measResultRange: 0-4096 - measResultType: float - measChangeType: added - measResultUnits: number - measType: VS.NINFC.IntraFrPscelChFailMenbRef - measAdditionalFields: - vendorField1: - - Z - - A - vendorField2: A -... ---- -pmMetaData: - pmHeader: - nfType: gnb-Nokia - pmDefSchemaVsn: 2.0 - pmDefVsn: 5G19_1906_002 - pmFields: - iMeasInfoId: 2206 - iMeasType: 1 - measCondition: "This measurement is updated when MeNB replies to X2AP: SgNB Modification Required message with the X2AP: SgNB Modification Refuse message." - measCollectionMethod: CC - measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change failures due to MeNB refusal." - measFamily: NINFC - measInfoId: "NR Intra Frequency PSCell Change" - measLastChange: 5G19_1906_002 - measObjClass: NGCELL - measResultRange: 0-4096 - measResultType: float - measChangeType: added - measResultUnits: number - measType: VS.NINFC.IntraFrPscelChFailMenbRef - measAdditionalFields: - vendorField1: - - X - - Y - vendorField2: A -... diff --git a/csarvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml b/csarvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml deleted file mode 100644 index f4cbddf..0000000 --- a/csarvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml +++ /dev/null @@ -1,239 +0,0 @@ ---- -# PM Dictionary schema specifying and describing the meta information -# used to define perf3gpp measurements in the PM Dictionary -pmMetaData: { presence: required, structure: { - pmHeader: { - presence: required, - structure: { - nfType: { - presence: required, - comment: "NF type; should match the nfName-vendor string used in - the fileReady or perf3gpp eventName" - }, - pmDefSchemaVsn: { - presence: required, - value: 2.0, - comment: "PM Dictionary Schema Version from the VES Event - Registration specification" - }, - pmDefVsn: { - presence: required, - comment: "vendor-defined PM Dictionary version" - } - } - }, - pmFields: { - presence: required, - structure: { - iMeasInfoId: { - presence: required, - comment: "vendor-defined integer measurement group identifier" - }, - iMeasType: { - presence: required, - comment: "vendor-defined integer identifier for the measType; - must be combined with measInfoId to identify a - specific measurement." - }, - measChangeType: { - presence: required, - value: [added, modified, deleted], - comment: "indicates the type of change that occurred during - measLastChange" - }, - measCollectionMethod: { - presence: required, - value: [CC, SI, DER, Gauge, Average], - comment: "the measurement collection method; CC, SI, DER and - Gauge are as defined in 3GPP; average contains the - average value of the measurement during the - granularity period" - }, - measCondition: { - presence: required, - comment: "description of the condition causing the measurement" - }, - measDescription: { - presence: required, - comment: "description of the measurement information - and purpose" - }, - measFamily: { - presence: required, - comment: "abbreviation for a family of measurements, in - 3GPP format, or vendor defined" - }, - measInfoId: { - presence: required, - comment: "name for a group of related measurements in - 3GPP format or vendor defined" - }, - measLastChange: { - presence: required, - comment: "version of the PM Dictionary the last time this - measurement was added, modified or deleted" - }, - measObjClass: { - presence: required, - value: [NGBTS, NGCELL, IPNO, IPSEC, ETHIF], - comment: "measurement object class" - }, - measResultRange: { - presence: optional, - comment: "range of the measurement result; only necessary when - the range is smaller than the full range of the - data type" - }, - measResultType: { - presence: required, - value: [float, uint32, uint64], - comment: "data type of the measurement result" - }, - measResultUnits: { - presence: required, - value: [seconds, minutes, nanoseconds, microseconds, dB, - number, kilobytes, bytes, ethernetFrames, - packets, users], - comment: "units of measure for the measurement result" - }, - measType: { - presence: required, - comment: "measurement name in 3GPP or vendor-specific format; - vendor specific names are preceded with VS" - }, - measAdditionalFields: { - presence: required, - comment: "vendor-specific PM Dictionary fields", - structure: { - vendorField1: { - presence: required, - value: [X, Y, Z], - comment: "vendor field 1 description" - }, - vendorField2: { - presence: optional, - value: [A, B], - comment: "vendor field 2 description." - } - } - } - } - } -}} -... -# PM Dictionary perf3gpp measurements for the gnb-Nokia NF (bracket style yaml) ---- -pmMetaData: { - pmHeader: { - nfType: gnb-Nokia, - pmDefSchemaVsn: 2.0, - pmDefVsn: 5G19_1906_002 - }, - pmFields: { - iMeasInfoId: 2204, - iMeasType: 1, - - measCollectionMethod: CC, - measCondition: "This measurement is updated when X2AP: SgNB Modification Required message is sent to MeNB - with the SCG Change Indication set as PSCellChange.", - measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change attempts.", - measFamily: NINFC, - measInfoId: "NR Intra Frequency PSCell Change", - measLastChange: 5G18A_1807_003, - measObjClass: NGCELL, - measResultRange: 0-4096, - measResultType: integer, - measResultUnits: number, - measType: VS.NINFC.IntraFrPscelChAttempt, - measAdditionalFields: { - vendorField1: X, - vendorField2: B - } - } -} -... ---- -pmMetaData: { - pmHeader: { - nfType: gnb-Nokia, - pmDefSchemaVsn: 2.0, - pmDefVsn: 5G19_1906_002 - }, - pmFields: { - iMeasInfoId: 2204, - iMeasType: 2, - measCollectionMethod: CC, - measCondition: "This measurement is updated when the TDCoverall timer has elapsed before gNB receives the X2AP: SgNB Modification Confirm message.", - measDescription: "This measurement the number of intra gNB intra frequency PSCell change failures due to TDCoverall timer expiry.", - measFamily: NINFC, - measInfoId: "NR Intra Frequency PSCell Change", - measLastChange: 5G18A_1807_003, - measObjClass: NGCELL, - measResultRange: 0-4096, - measResultType: float, - measResultUnits: number, - measType: VS.NINFC.IntraFrPscelChFailTdcExp, - measAdditionalFields: { - vendorField1: [Y,Z] - } - } -} -... ---- -pmMetaData: { - pmHeader: { - nfType: gnb-Nokia, - pmDefSchemaVsn: 2.0, - pmDefVsn: 5G19_1906_002 - }, - pmFields: { - iMeasInfoId: 2206, - iMeasType: 1, - measCondition: "This measurement is updated when MeNB replies to X2AP: SgNB Modification Required message with the X2AP: SgNB Modification Refuse message.", - measCollectionMethod: CC, - measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change failures due to MeNB refusal.", - measFamily: NINFC, - measInfoId: "NR Intra Frequency PSCell Change", - measLastChange: 5G19_1906_002, - measObjClass: NGCELL, - measResultRange: 0-4096, - measResultType: float, - measChangeType: added, - measResultUnits: number, - measType: VS.NINFC.IntraFrPscelChFailMenbRef, - measAdditionalFields: { - vendorField1: [Z,A], - vendorField2: A - } - } -} -... ---- -pmMetaData: { - pmHeader: { - nfType: gnb-Nokia, - pmDefSchemaVsn: 2.0, - pmDefVsn: 5G19_1906_002 - }, - pmFields: { - iMeasInfoId: 2206, - iMeasType: 1, - measCondition: "This measurement is updated when MeNB replies to X2AP: SgNB Modification Required message with the X2AP: SgNB Modification Refuse message.", - measCollectionMethod: CC, - measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change failures due to MeNB refusal.", - measFamily: NINFC, - measInfoId: "NR Intra Frequency PSCell Change", - measLastChange: 5G19_1906_002, - measObjClass: NGCELL, - measResultRange: 0-4096, - measResultType: float, - measChangeType: added, - measResultUnits: number, - measType: VS.NINFC.IntraFrPscelChFailMenbRef, - measAdditionalFields: { - vendorField1: [X,Y], - vendorField2: A - } - } -} -... diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml b/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml deleted file mode 100644 index 25c72cd..0000000 --- a/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml +++ /dev/null @@ -1,149 +0,0 @@ ---- -# PM Dictionary schema specifying and describing the meta information -# used to define perf3gpp measurements in the PM Dictionary -pmMetaData: { presence: required, structure: { - pmHeader: { - presence: required, - structure: { - nfType: { - presence: required, - comment: "NF type; should match the nfName-vendor string used in - the fileReady or perf3gpp eventName" - }, - pmDefSchemaVsn: { - presence: required, - value: 2.0, - comment: "PM Dictionary Schema Version from the VES Event - Registration specification" - }, - pmDefVsn: { - presence: required, - comment: "vendor-defined PM Dictionary version" - } - } - }, - pmFields: { - presence: required, - structure: { - iMeasInfoId: { - presence: required, - comment: "vendor-defined integer measurement group identifier" - }, - iMeasType: { - presence: required, - comment: "vendor-defined integer identifier for the measType; - must be combined with measInfoId to identify a - specific measurement." - }, - measChangeType: { - presence: required, - value: [added, modified, deleted], - comment: "indicates the type of change that occurred during - measLastChange" - }, - measCollectionMethod: { - presence: required, - value: [CC, SI, DER, Gauge, Average], - comment: "the measurement collection method; CC, SI, DER and - Gauge are as defined in 3GPP; average contains the - average value of the measurement during the - granularity period" - }, - measCondition: { - presence: required, - comment: "description of the condition causing the measurement" - }, - measDescription: { - presence: required, - comment: "description of the measurement information - and purpose" - }, - measFamily: { - presence: required, - comment: "abbreviation for a family of measurements, in - 3GPP format, or vendor defined" - }, - measInfoId: { - presence: required, - comment: "name for a group of related measurements in - 3GPP format or vendor defined" - }, - measLastChange: { - presence: required, - comment: "version of the PM Dictionary the last time this - measurement was added, modified or deleted" - }, - measObjClass: { - presence: required, - value: [NGBTS, NGCELL, IPNO, IPSEC, ETHIF], - comment: "measurement object class" - }, - measResultRange: { - presence: optional, - comment: "range of the measurement result; only necessary when - the range is smaller than the full range of the - data type" - }, - measResultType: { - presence: required, - value: [float, uint32, uint64], - comment: "data type of the measurement result" - }, - measResultUnits: { - presence: required, - value: [seconds, minutes, nanoseconds, microseconds, dB, - number, kilobytes, bytes, ethernetFrames, - packets, users], - comment: "units of measure for the measurement result" - }, - measType: { - presence: required, - comment: "measurement name in 3GPP or vendor-specific format; - vendor specific names are preceded with VS" - }, - measAdditionalFields: { - presence: required, - comment: "vendor-specific PM Dictionary fields", - structure: { - vendorField1: { - presence: required, - value: [X, Y, Z], - comment: "vendor field 1 description" - }, - vendorField2: { - presence: optional, - value: [A, B], - comment: "vendor field 2 description." - } - } - } - } - } -}} -... -# PM Dictionary perf3gpp measurements for the gnb-Nokia NF (bracket style yaml) ---- -pmMetaData: - pmHeader: - nfType: gnb-Nokia - pmDefSchemaVsn: 2.0 - pmDefVsn: 5G19_1906_002 - pmFields: - iMeasInfoId: 2204 - iMeasType: 1 - measCollectionMethod: CC - measCondition: This measurement is updated when X2AP: SgNB Modification Required message is sent to MeNB - with the SCG Change Indication set as PSCellChange. - measDescription: This counter indicates the number of intra gNB intra frequency PSCell change attempts. - measFamily: NINFC - measInfoId: "NR Intra Frequency PSCell Change" - measLastChange: 5G18A_1807_003 - measObjClass: NGCELL - measResultRange: 0-4096 - measResultType: integer - measResultUnits: number - measType: VS.NINFC.IntraFrPscelChAttempt - measAdditionalFields: - vendorField1: X - vendorField2: B -... diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml b/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml deleted file mode 100644 index c5e7b7c..0000000 --- a/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml +++ /dev/null @@ -1,39 +0,0 @@ ---- -pmMetaData: { presence: required, structure: [ - -pmHeader: { - presence: required, - structure: { - nfType: { - presence: required, - comment: "nfType comment" - } - } - }, - -pmFields: { - presence: required, - structure: { - measChangeType: { - presence: required, - value: [added, modified, deleted], - comment: "measChangeType comment" - }, - measAdditionalFields: { - presence: required, - comment: "measAdditionalFields comment", - structure: { - vendorField1: { - presence: required, - value: [X, Y, Z], - comment: "vendorField1 comment" - }, - vendorField2: { - presence: optional, - value: [A, B], - comment: "vendorField2 comment" - } - } - } - } - } -]} -... diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml b/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml deleted file mode 100644 index 7f9f946..0000000 --- a/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml +++ /dev/null @@ -1,39 +0,0 @@ ---- -pmMetaData: { presence: required, structure: { - pmHeader: { - presence: required, - structure: { - nfType: { - presence: required, - comment: "nfType comment" - } - } - }, - pmFields: { - presence: required, - structure: [ - -measChangeType: { - presence: required, - value: [added, modified, deleted], - comment: "measChangeType comment" - }, - -measAdditionalFields: { - presence: required, - comment: "measAdditionalFields comment", - structure: { - vendorField1: { - presence: required, - value: [X, Y, Z], - comment: "vendorField1 comment" - }, - vendorField2: { - presence: optional, - value: [A, B], - comment: "vendorField2 comment" - } - } - } - ] - } -}} -... diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml b/csarvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml deleted file mode 100644 index 2cac9e6..0000000 --- a/csarvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml +++ /dev/null @@ -1,149 +0,0 @@ ---- -# PM Dictionary schema specifying and describing the meta information -# used to define perf3gpp measurements in the PM Dictionary -pmMetaData: { presence: required, structure: { - pmHeader: { - presence: required, - structure: { - nfType: { - presence: required, - comment: "NF type; should match the nfName-vendor string used in - the fileReady or perf3gpp eventName" - }, - pmDefSchemaVsn: { - presence: required, - value: 2.0, - comment: "PM Dictionary Schema Version from the VES Event - Registration specification" - }, - pmDefVsn: { - presence: required, - comment: "vendor-defined PM Dictionary version" - } - } - }, - pmFields: { - presence: required, - structure: { - iMeasInfoId: { - presence: required, - comment: "vendor-defined integer measurement group identifier" - }, - iMeasType: { - presence: required, - comment: "vendor-defined integer identifier for the measType; - must be combined with measInfoId to identify a - specific measurement." - }, - measChangeType: { - presence: required, - value: [added, modified, deleted], - comment: "indicates the type of change that occurred during - measLastChange" - }, - measCollectionMethod: { - presence: required, - value: [CC, SI, DER, Gauge, Average], - comment: "the measurement collection method; CC, SI, DER and - Gauge are as defined in 3GPP; average contains the - average value of the measurement during the - granularity period" - }, - measCondition: { - presence: required, - comment: "description of the condition causing the measurement" - }, - measDescription: { - presence: required, - comment: "description of the measurement information - and purpose" - }, - measFamily: { - presence: required, - comment: "abbreviation for a family of measurements, in - 3GPP format, or vendor defined" - }, - measInfoId: { - presence: required, - comment: "name for a group of related measurements in - 3GPP format or vendor defined" - }, - measLastChange: { - presence: required, - comment: "version of the PM Dictionary the last time this - measurement was added, modified or deleted" - }, - measObjClass: { - presence: required, - value: [NGBTS, NGCELL, IPNO, IPSEC, ETHIF], - comment: "measurement object class" - }, - measResultRange: { - presence: optional, - comment: "range of the measurement result; only necessary when - the range is smaller than the full range of the - data type" - }, - measResultType: { - presence: required, - value: [float, uint32, uint64], - comment: "data type of the measurement result" - }, - measResultUnits: { - presence: required, - value: [seconds, minutes, nanoseconds, microseconds, dB, - number, kilobytes, bytes, ethernetFrames, - packets, users], - comment: "units of measure for the measurement result" - }, - measType: { - presence: required, - comment: "measurement name in 3GPP or vendor-specific format; - vendor specific names are preceded with VS" - }, - measAdditionalFields: { - presence: required, - comment: "vendor-specific PM Dictionary fields", - structure: { - vendorField1: { - presence: required, - value: [X, Y, Z], - comment: "vendor field 1 description" - }, - vendorField2: { - presence: optional, - value: [A, B], - comment: "vendor field 2 description." - } - } - } - } - } -}} -... -# PM Dictionary perf3gpp measurements for the gnb-Nokia NF (bracket style yaml) ---- -pmMetaData: - pmHeader: - nfType: gnb-Nokia - pmDefSchemaVsn: 2.0 - pmDefVsn: 5G19_1906_002 - pmFields: - iMeasInfoId: 2204 - iMeasType: 1 - measCollectionMethod: CC - measCondition: "This measurement is updated when X2AP: SgNB Modification Required message is \sent\ to MeNB - with the SCG Change Indication set as PSCellChange." - measDescription: This counter indicates the number of intra gNB intra frequency PSCell change attempts. - measFamily: NINFC - measInfoId: "NR Intra Frequency PSCell Change" - measLastChange: 5G18A_1807_003 - measObjClass: NGCELL - measResultRange: 0-4096 - measResultType: integer - measResultUnits: number - measType: VS.NINFC.IntraFrPscelChAttempt - measAdditionalFields: - vendorField1: X - vendorField2: B -... diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml b/csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml deleted file mode 100644 index a125b13..0000000 --- a/csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml +++ /dev/null @@ -1,39 +0,0 @@ ---- -pmMetaData: { presence: required, structure: { - pmHeader: { - presence: required, - structure: { - nfType: { - presence: required, - comment: "nfType comment" - } - } - }, - pmFields: { - presence: required, - structure: { - measChangeType: { - presence: required, - value: [added, modified, deleted], - comment: "measChangeType comment" - }, - measAdditionalFields: { - presence: required, - comment: "measAdditionalFields comment", - structure: { - vendorField1: { - presence: required, - value: [X, Y, Z], - comment: "vendorField1 comment" - }, - vendorField2: { - presence: optional, - value: [A, B], - comment: "vendorField2 comment" - } - } - } - } - } -}} -... diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml b/csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml deleted file mode 100644 index d73ca4f..0000000 --- a/csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml +++ /dev/null @@ -1,23 +0,0 @@ ---- -root1: { presence: required, structure: { - field1: { - presence: required, - value: [X, Y, Z], - comment: "field 1 description" - } -}} -root2: { presence: required, structure: { - field2: { - presence: required, - value: [X, Y, Z], - comment: "field 1 description" - } -}} -root3: { presence: required, structure: { - field3: { - presence: required, - value: [X, Y, Z], - comment: "field 1 description" - } -}} -... diff --git a/pmdictionaryvalidation/pom.xml b/pmdictionaryvalidation/pom.xml new file mode 100644 index 0000000..3822057 --- /dev/null +++ b/pmdictionaryvalidation/pom.xml @@ -0,0 +1,71 @@ + + + + org.onap.vnfsdk.validation + validation + 1.2.15-SNAPSHOT + + 4.0.0 + + validation-pmdictionary + jar + pmdictionaryvalidation/validation + + + + google-collections + Google collections repository + https://mvnrepository.com/artifact/com.google.collections/google-collections + + + onap + ONAP repository + https://nexus.onap.org/content/repositories/public/ + + + + 2.13.3 + 1.26 + 5.7.0 + 3.18.1 + + + + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j-slf4j-impl.version} + + + org.slf4j + slf4j-ext + + + + + org.yaml + snakeyaml + ${snakeyaml.version} + + + + org.junit.jupiter + junit-jupiter + ${junit.version} + test + + + org.junit.vintage + junit-vintage-engine + ${junit.version} + test + + + org.assertj + assertj-core + ${assertj-core.version} + test + + + diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlFileValidator.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlFileValidator.java new file mode 100644 index 0000000..2de4f48 --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlFileValidator.java @@ -0,0 +1,72 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml; + +import org.onap.validation.yaml.error.SchemaValidationError; +import org.onap.validation.yaml.error.YamlDocumentValidationError; +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.schema.YamlSchema; +import org.onap.validation.yaml.schema.YamlSchemaFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class YamlFileValidator { + + private static final int FIRST_DOCUMENT_INDEX = 1; + + public List validateYamlFileWithSchema(String pathToFile) + throws YamlProcessingException { + + List documents = new YamlLoader().loadMultiDocumentYamlFile(pathToFile); + if(!documents.isEmpty()) { + return validateDocuments(documents); + } else { + throw new YamlProcessingException("PM_Dictionary YAML file is empty"); + } + } + + private List validateDocuments(List documents) + throws YamlProcessingException { + + List yamlFileValidationErrors = new ArrayList<>(); + YamlSchema schema = extractSchema(documents); + YamlValidator validator = new YamlValidator(schema); + + for (int index = FIRST_DOCUMENT_INDEX; index < documents.size(); index++) { + List validationErrors = validator.validate(documents.get(index)); + yamlFileValidationErrors.addAll(transformErrors(index,validationErrors)); + } + + return yamlFileValidationErrors; + } + + private List transformErrors(int index, List validationErrors) { + return validationErrors + .stream() + .map(error->new YamlDocumentValidationError(index, error.getPath(), error.getMessage())) + .collect(Collectors.toList()); + } + + private YamlSchema extractSchema(List documents) throws YamlProcessingException { + return new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0)); + } + +} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java new file mode 100644 index 0000000..1a5eef9 --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java @@ -0,0 +1,61 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml; + +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.model.YamlDocumentFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +class YamlLoader { + + private static final Logger LOGGER = LoggerFactory.getLogger(YamlLoader.class); + + List loadMultiDocumentYamlFile(URL path) + throws YamlDocumentFactory.YamlDocumentParsingException { + List documentsFromFile = new ArrayList<>(); + try (InputStream yamlStream = path.openStream()) { + for (Object yamlDocument : new Yaml().loadAll(yamlStream)) { + documentsFromFile.add( + new YamlDocumentFactory().createYamlDocument(yamlDocument) + ); + } + } catch (IOException e) { + LOGGER.error("Failed to load multi document YAML file",e); + } + return documentsFromFile; + } + + List loadMultiDocumentYamlFile(String path) + throws YamlProcessingException { + try { + return loadMultiDocumentYamlFile(new URL("file://" + path)); + } catch (MalformedURLException e) { + throw new YamlProcessingException("Fail to read file under given path.", e); + } + } +} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java new file mode 100644 index 0000000..30ba646 --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java @@ -0,0 +1,40 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml; + +import org.onap.validation.yaml.error.SchemaValidationError; +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.process.YamlValidationProcess; +import org.onap.validation.yaml.schema.YamlSchema; + +import java.util.List; + +public class YamlValidator { + + private final YamlSchema schema; + + YamlValidator(YamlSchema schema) { + this.schema = schema; + } + + public List validate(YamlDocument document) throws YamlProcessingException { + return new YamlValidationProcess(schema,document).validate(); + } + +} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java new file mode 100644 index 0000000..6ffe6d4 --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java @@ -0,0 +1,36 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.error; + +public class SchemaValidationError { + private final String path; + private final String message; + + public String getPath() { + return path; + } + + public String getMessage() { + return message; + } + + public SchemaValidationError(String path, String message) { + this.path = path; + this.message = message; + } +} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java new file mode 100644 index 0000000..f04708f --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java @@ -0,0 +1,42 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.error; + +public class YamlDocumentValidationError { + private final int yamlDocumentNumber; + private final String path; + private final String message; + + public YamlDocumentValidationError(int yamlDocumentNumber, String path, String message) { + this.yamlDocumentNumber = yamlDocumentNumber; + this.path = path; + this.message = message; + } + + public int getYamlDocumentNumber() { + return yamlDocumentNumber; + } + + public String getPath() { + return path; + } + + public String getMessage() { + return message; + } +} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java new file mode 100644 index 0000000..99c2437 --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java @@ -0,0 +1,33 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.exception; + +public class YamlProcessingException extends Exception { + + public YamlProcessingException(String message, Throwable throwable) { + super(message, throwable); + } + + public YamlProcessingException(String message) { + super(message); + } + + public YamlProcessingException(Throwable throwable) { + super(throwable); + } +} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java new file mode 100644 index 0000000..557b6fd --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java @@ -0,0 +1,56 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.model; + +import java.util.Map; + +public class YamlDocument { + + private final Map yaml; + + YamlDocument(Map yaml) { + this.yaml = yaml; + } + + public Map getYaml() { + return yaml; + } + + public boolean containsKey(String key) { + return yaml.containsKey(key); + } + + public String getValue(String key) { + return yaml.get(key).toString(); + } + + public YamlParametersList getListOfValues(String key) { + return new YamlParameterListFactory().createYamlParameterList( + yaml.get(key) + ); + } + + public YamlDocument getSubStructure(String name) + throws YamlDocumentFactory.YamlDocumentParsingException { + return new YamlDocumentFactory().createYamlDocument( + yaml.get(name) + ); + } +} + + diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java new file mode 100644 index 0000000..b56422c --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java @@ -0,0 +1,52 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.model; + +import org.onap.validation.yaml.exception.YamlProcessingException; + +import java.util.HashMap; +import java.util.Map; + +public class YamlDocumentFactory { + + public YamlDocument createYamlDocument(Object yaml) throws YamlDocumentParsingException { + try { + Map parsedYaml = transformMap((Map) yaml); + return new YamlDocument(parsedYaml); + } catch (ClassCastException e) { + throw new YamlDocumentParsingException( + String.format("Fail to parse given objects: %s as yaml document.", yaml), e + ); + } + } + + private Map transformMap(Map yaml) { + Map parsedYaml = new HashMap<>(); + for (Map.Entry entry: yaml.entrySet()) { + parsedYaml.put(entry.getKey().toString(), entry.getValue()); + } + return parsedYaml; + } + + public static class YamlDocumentParsingException extends YamlProcessingException { + YamlDocumentParsingException(String message, Throwable throwable) { + super(message, throwable); + } + } + +} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java new file mode 100644 index 0000000..5f41c5c --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java @@ -0,0 +1,42 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.model; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class YamlParameterListFactory { + + public YamlParametersList createEmptyYamlParameterList() { + return new YamlParametersList(Collections.emptyList()); + } + + public YamlParametersList createYamlParameterList(Object yaml) { + List parametersList = new ArrayList<>(); + if( yaml instanceof List) { + for (Object element : (List) yaml) { + parametersList.add(element.toString()); + } + } else { + parametersList.add(yaml.toString()); + } + return new YamlParametersList(parametersList); + } + +} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java new file mode 100644 index 0000000..2b93c74 --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java @@ -0,0 +1,34 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.model; + +import java.util.List; + +public class YamlParametersList { + + private final List parameters; + + YamlParametersList(List parameters) { + this.parameters = parameters; + } + + public List getParameters() { + return parameters; + } + +} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java new file mode 100644 index 0000000..ebd37ce --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java @@ -0,0 +1,111 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.process; + +import org.onap.validation.yaml.error.SchemaValidationError; +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.schema.YamlSchema; +import org.onap.validation.yaml.schema.node.YamlSchemaNode; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +public class YamlValidationProcess { + + private final Queue validationSteps; + private final List errors; + private final YamlSchema schema; + private final YamlDocument document; + + public YamlValidationProcess(YamlSchema schema, YamlDocument document) { + this.schema = schema; + this.document = document; + errors = new ArrayList<>(); + validationSteps = new LinkedList<>(); + } + + public List validate() throws YamlProcessingException { + validationSteps.add(new YamlValidationStep(schema.getRootNodes(), document)); + while (!validationSteps.isEmpty()) { + YamlValidationStep nextValidationNode = validationSteps.poll(); + validateStep(nextValidationNode); + } + return errors; + } + + private void validateStep(YamlValidationStep validationNode) + throws YamlProcessingException { + for (YamlSchemaNode schemaNode : validationNode.getSchemaNodes()) { + validateNode(validationNode.getDocument(), schemaNode); + } + } + + private void validateNode(YamlDocument document, YamlSchemaNode schemaNode) + throws YamlProcessingException { + + if (document.containsKey(schemaNode.getName())) { + if (schemaNode.isContainingSubStructure()) { + addNextLevelNodeToValidationNodesQueue(document, schemaNode); + } else if (!isValueOfNodeInAcceptedValuesList(document, schemaNode)) { + addIncorrectValueError(document, schemaNode); + } + } else if (schemaNode.isRequired()) { + addRequiredKeyNotFoundError(schemaNode); + } + } + + private boolean isValueOfNodeInAcceptedValuesList(YamlDocument document, YamlSchemaNode node) { + return node.getAcceptedValues().isEmpty() || + node.getAcceptedValues().containsAll( + document.getListOfValues(node.getName()).getParameters() + ); + } + + private void addNextLevelNodeToValidationNodesQueue(YamlDocument document, YamlSchemaNode node) + throws YamlProcessingException { + validationSteps.add( + new YamlValidationStep( + node.getNextNodes(), + document.getSubStructure(node.getName()) + ) + ); + } + + private void addRequiredKeyNotFoundError(YamlSchemaNode node) { + errors.add( + new SchemaValidationError( + node.getPath(), + String.format("Key not found: %s", node.getName()) + ) + ); + } + + private void addIncorrectValueError(YamlDocument document, YamlSchemaNode node) { + errors.add( + new SchemaValidationError( + node.getPath() + node.getName(), + String.format( + "Value(s) is/are not in array of accepted values.%n value(s): %s%n accepted value(s): %s", + document.getValue(node.getName()), node.getAcceptedValues()) + ) + ); + } +} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java new file mode 100644 index 0000000..eb5ab8e --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java @@ -0,0 +1,45 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.process; + +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.schema.node.YamlSchemaNode; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +class YamlValidationStep { + + private final List schemaNodes; + private final YamlDocument document; + + YamlValidationStep(List nodes, YamlDocument yaml) { + this.schemaNodes = new ArrayList<>(nodes); + this.document = yaml; + } + + List getSchemaNodes() { + return Collections.unmodifiableList(schemaNodes); + } + + YamlDocument getDocument() { + return document; + } + +} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java new file mode 100644 index 0000000..69bb6cd --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java @@ -0,0 +1,37 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.schema; + +import org.onap.validation.yaml.schema.node.YamlSchemaNode; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class YamlSchema { + + private final List rootNodes; + + public List getRootNodes() { + return Collections.unmodifiableList(rootNodes); + } + + YamlSchema(List rootNodes) { + this.rootNodes = new ArrayList<>(rootNodes); + } +} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java new file mode 100644 index 0000000..df7d673 --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java @@ -0,0 +1,59 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +package org.onap.validation.yaml.schema; + +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.model.YamlDocumentFactory; +import org.onap.validation.yaml.schema.node.YamlSchemaNode; +import org.onap.validation.yaml.schema.node.YamlSchemaNodeFactory; + +import java.util.ArrayList; +import java.util.List; + +public class YamlSchemaFactory { + + + private static final String ROOT_PATH = "/"; + + public YamlSchema createTreeStructuredYamlSchema(YamlDocument schema) + throws YamlProcessingException { + + return new YamlSchema(getRootNodes(schema)); + } + + private List getRootNodes(YamlDocument yamlDocument) + throws YamlProcessingException { + + List nextNodes = new ArrayList<>(); + for(String nodeName: yamlDocument.getYaml().keySet()) { + nextNodes.add( + new YamlSchemaNodeFactory().createNode( + nodeName, + ROOT_PATH, + new YamlDocumentFactory().createYamlDocument( + yamlDocument.getYaml().get(nodeName) + ) + ) + ); + } + return nextNodes; + } + +} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java new file mode 100644 index 0000000..0f5b480 --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java @@ -0,0 +1,80 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.schema.node; + +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.model.YamlDocumentFactory; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +public class YamlSchemaBranchNode extends YamlSchemaNode { + + private final YamlDocument nextNodesInLazyForm; + private Optional> nextNodes; + + YamlSchemaBranchNode(String name, String path, boolean required, String comment, + YamlDocument nextNodesInLazyForm) { + super(name, path, required, comment); + this.nextNodesInLazyForm = nextNodesInLazyForm; + this.nextNodes = Optional.empty(); + } + + @Override + public boolean isContainingSubStructure() { + return true; + } + + @Override + public List getAcceptedValues() { + return Collections.emptyList(); + } + + @Override + public synchronized List getNextNodes() throws YamlSchemaProcessingException { + try { + return nextNodes.orElseGet(this::loadNextNodes); + } catch (YamlSchemaLazyLoadingException lazyLoadingException) { + throw new YamlSchemaProcessingException(lazyLoadingException); + } + } + + private List loadNextNodes() { + try { + List loadedNextNodes = new ArrayList<>(); + for (String key : nextNodesInLazyForm.getYaml().keySet()) { + YamlDocument substructure = new YamlDocumentFactory() + .createYamlDocument(nextNodesInLazyForm.getYaml().get(key)); + loadedNextNodes.add(new YamlSchemaNodeFactory().createNode(key, getPath() + getName() + "/", substructure)); + } + nextNodes = Optional.of(loadedNextNodes); + return loadedNextNodes; + } catch (YamlProcessingException e) { + throw new YamlSchemaLazyLoadingException("Lazy loading failed, due to yaml parsing exception.",e); + } + } + + static class YamlSchemaLazyLoadingException extends RuntimeException { + YamlSchemaLazyLoadingException(String message, Throwable throwable) { + super(message, throwable); + } + } +} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java new file mode 100644 index 0000000..c98f41e --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java @@ -0,0 +1,50 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.schema.node; + +import org.onap.validation.yaml.model.YamlParametersList; + +import java.util.Collections; +import java.util.List; + +public class YamlSchemaLeafNode extends YamlSchemaNode { + + private final YamlParametersList acceptedValues; + + YamlSchemaLeafNode(String name, String path, boolean required, String comment, + YamlParametersList acceptedValues) { + super(name, path, required, comment); + this.acceptedValues = acceptedValues; + } + + @Override + public List getAcceptedValues() { + return acceptedValues.getParameters(); + } + + @Override + public List getNextNodes() { + return Collections.emptyList(); + } + + @Override + public boolean isContainingSubStructure() { + return false; + } + +} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java new file mode 100644 index 0000000..28913a2 --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java @@ -0,0 +1,66 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.schema.node; + +import org.onap.validation.yaml.exception.YamlProcessingException; + +import java.util.List; + +public abstract class YamlSchemaNode { + + private final String path; + private final String name; + private final boolean required; + private final String comment; + + + public String getName() { + return name; + } + + public String getPath() { + return path; + } + + public boolean isRequired() { + return required; + } + + public abstract List getAcceptedValues(); + + public abstract List getNextNodes() throws YamlSchemaProcessingException; + + public abstract boolean isContainingSubStructure(); + + public String getComment() { + return comment; + } + + YamlSchemaNode(String name, String path, boolean required, String comment) { + this.name = name; + this.path = path; + this.required = required; + this.comment = comment; + } + + static class YamlSchemaProcessingException extends YamlProcessingException { + YamlSchemaProcessingException(Throwable throwable) { + super(throwable); + } + } +} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java new file mode 100644 index 0000000..79a8f14 --- /dev/null +++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java @@ -0,0 +1,84 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.schema.node; + +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.model.YamlDocumentFactory; +import org.onap.validation.yaml.model.YamlParameterListFactory; +import org.onap.validation.yaml.model.YamlParametersList; + +import static org.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException; + +public class YamlSchemaNodeFactory { + + public static final String EMPTY_COMMENT = "no comment available"; + static final String STRUCTURE_KEY = "structure"; + static final String COMMENT_KEY = "comment"; + static final String VALUE_KET = "value"; + static final String PRESENCE_KEY = "presence"; + static final String PRESENCE_REQUIRED_KEY = "required"; + + public YamlSchemaNode createNode(String nodeName, String path, YamlDocument yamlDocument) + throws YamlProcessingException { + + YamlSchemaNode yamlSchemaNode; + if(isYamlContainingKey(yamlDocument, STRUCTURE_KEY)) { + yamlSchemaNode = new YamlSchemaBranchNode( + nodeName, path, getIsPresenceRequired(yamlDocument), getComment(yamlDocument), + getNextNodes(yamlDocument) + ); + } else { + yamlSchemaNode = new YamlSchemaLeafNode( + nodeName, path, getIsPresenceRequired(yamlDocument), getComment(yamlDocument), + getAcceptedValues(yamlDocument) + ); + } + return yamlSchemaNode; + } + + private YamlDocument getNextNodes(YamlDocument yamlDocument) + throws YamlDocumentParsingException { + return new YamlDocumentFactory().createYamlDocument(yamlDocument.getYaml().get(STRUCTURE_KEY)); + } + + private String getComment(YamlDocument yamlDocument) { + + return isYamlContainingKey(yamlDocument, COMMENT_KEY) + ? yamlDocument.getYaml().get(COMMENT_KEY).toString() + : EMPTY_COMMENT; + } + + private YamlParametersList getAcceptedValues(YamlDocument yamlDocument) { + + return isYamlContainingKey(yamlDocument, VALUE_KET) + ? new YamlParameterListFactory().createYamlParameterList(yamlDocument.getYaml().get(VALUE_KET)) + : new YamlParameterListFactory().createEmptyYamlParameterList(); + } + + private boolean getIsPresenceRequired(YamlDocument yamlDocument) { + + return isYamlContainingKey(yamlDocument, PRESENCE_KEY) + && yamlDocument.getYaml().get(PRESENCE_KEY).equals(PRESENCE_REQUIRED_KEY); + } + + private boolean isYamlContainingKey(YamlDocument yamlDocument, String structureKey) { + return yamlDocument.getYaml().containsKey(structureKey); + } + +} diff --git a/pmdictionaryvalidation/src/main/resources/log4j2.properties b/pmdictionaryvalidation/src/main/resources/log4j2.properties new file mode 100644 index 0000000..f3202ee --- /dev/null +++ b/pmdictionaryvalidation/src/main/resources/log4j2.properties @@ -0,0 +1,48 @@ +# Copyright Nokia 2020,2020 Huawei Technologies Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# By default, log4j2 will look for a configuration file named log4j2.xml on the classpath. +# reference: https://logging.apache.org/log4j/2.x/faq.html#troubleshooting + +rootLogger.level=ERROR +rootLogger.appenderRefs=file +rootLogger.appenderRef.file.ref=RollingFile + +logger.onap.name = org.onap +logger.onap.level=ERROR +logger.onap.additivity=false +logger.onap.appenderRef.stdout.ref=STDOUT + +appenders=stdout, file + +# Direct log messages to stdout +appender.stdout.type=Console +appender.stdout.name=STDOUT +appender.stdout.target=SYSTEM_OUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n + +# Redirect log messages to a log file, support file rolling. +appender.file.type = RollingFile +appender.file.name = RollingFile +appender.file.fileName=./pmdictionary-validate.log +appender.file.filePattern=./pmdictionary-validate.%d{yyyy-MM-dd-HH:mm:ss}.log +appender.file.append=true +appender.file.policies.type=Policies +appender.file.policies.size.type=SizeBasedTriggeringPolicy +appender.file.policies.size.size=5MB +appender.file.strategy.type=DefaultRolloverStrategy +appender.file.strategy.max=10 +appender.file.layout.type=PatternLayout +appender.file.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java new file mode 100644 index 0000000..089348d --- /dev/null +++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java @@ -0,0 +1,110 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +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; +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; + +class YamlFileValidatorTest { + + @Test + void shouldReturnCorrectErrorsWhenGivenPathToValidPmDictionaryFile() throws YamlProcessingException { + // given + String path = getFullPathForGivenResources(YamlLoadingUtils.PATH_TO_VALID_YAML); + + // when + List validationErrors = new YamlFileValidator().validateYamlFileWithSchema(path); + + // then + assertValidationReturnedExpectedErrors(validationErrors); + + } + + @Test + void shouldReturnCorrecErrorsWhenGivenPathToValidJsonStylePmDictionaryFile() throws YamlProcessingException { + // given + String path = getFullPathForGivenResources(YamlLoadingUtils.PATH_TO_VALID_JSON_STYLE_YAML); + + // when + List validationErrors = new YamlFileValidator().validateYamlFileWithSchema(path); + + // then + assertValidationReturnedExpectedErrors(validationErrors); + } + + + private void assertValidationReturnedExpectedErrors(List validationErrors) { + assertThat(validationErrors) + .isNotNull() + .hasSize(4) + .usingRecursiveFieldByFieldElementComparator() + .containsAll( + Lists.list( + new YamlDocumentValidationError(1, + "/pmMetaData/pmFields/measResultType", + "Value(s) is/are not in array of accepted values.\n" + + " value(s): integer\n" + + " accepted value(s): [float, uint32, uint64]"), + new YamlDocumentValidationError(1, + "/pmMetaData/pmFields/", + "Key not found: measChangeType"), + new YamlDocumentValidationError(2, + "/pmMetaData/pmFields/", + "Key not found: measChangeType"), + new YamlDocumentValidationError(3, + "/pmMetaData/pmFields/measAdditionalFields/vendorField1", + "Value(s) is/are not in array of accepted values.\n" + + " value(s): [Z, A]\n" + + " accepted value(s): [X, Y, Z]") + ) + ); + } + + @Test + void shouldThrowErrorWhenGivenPathToInvalidPmDictionaryFile() { + // given + String path = getFullPathForGivenResources(YamlLoadingUtils.PATH_TO_MULTI_DOCUMENT_INVALID_YAML); + // when then + assertThatThrownBy(() -> new YamlFileValidator().validateYamlFileWithSchema(path)) + .isInstanceOf(ParserException.class) + .hasMessageContaining("expected the node content, but found ''"); + } + + @Test + void shouldThrowErrorWhenGivenInvalidPath() { + // given + String path = "invalid/path/to/pm_dictionary"; + + // when then + assertThatThrownBy(() -> new YamlFileValidator().validateYamlFileWithSchema(path)) + .isInstanceOf(YamlProcessingException.class) + .hasMessageContaining("PM_Dictionary YAML file is empty"); + } + + private String getFullPathForGivenResources(String pathToValidYaml) { + return this.getClass().getClassLoader().getResource(pathToValidYaml).getPath(); + } +} diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java new file mode 100644 index 0000000..36297ca --- /dev/null +++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java @@ -0,0 +1,96 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml; + +import org.junit.jupiter.api.Test; +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.model.YamlDocumentFactory; +import org.yaml.snakeyaml.parser.ParserException; +import org.yaml.snakeyaml.scanner.ScannerException; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + + +class YamlLoaderTest { + + private static final int EXPECTED_NUMBER_OF_DOCUMENTS = 5; + private static final String LETTER_S_WITH_ASCII_CODE = "s(115)"; + + @Test + void shouldLoadAllDocumentsFromYamlFile() throws YamlDocumentFactory.YamlDocumentParsingException { + // when + List documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile(); + + // then + assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS); + } + + @Test + void shouldLoadAllDocumentsFromJsonStyleYamlFile() throws YamlDocumentFactory.YamlDocumentParsingException { + // when + List documents = YamlLoadingUtils.loadValidJsonStyleMultiDocumentYamlFile(); + + // then + assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS); + } + + @Test + void shouldLoadAllDocumentsFromYamlFileUsingPathInString() throws YamlProcessingException { + // when + List documents = YamlLoadingUtils.loadValidMultiDocumentYamlFileUsingStringPath(); + + // then + assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS); + } + + @Test + void shouldThrowExceptionWhenLoadingDocumentsFromInvalidYamlFile() { + // when then + assertThatThrownBy(YamlLoadingUtils::tryToLoadMultiDocumentInvalidYamlFile) + .isInstanceOf(ParserException.class) + .hasMessageContaining("expected the node content, but found ''"); + } + + @Test + void shouldThrowExceptionWhenLoadingDocumentsFromInvalidYamlFileUsingPathInString() { + // when then + assertThatThrownBy(YamlLoadingUtils::tryToLoadMultiDocumentInvalidYamlFileUsingStringPath) + .isInstanceOf(ParserException.class) + .hasMessageContaining("expected the node content, but found ''"); + } + + @Test + void shouldThrowExceptionWhenLoadingInvalidYamlFileWithIncorrectKeyMapping() { + // when then + assertThatThrownBy(YamlLoadingUtils::tryToLoadInvalidYamlFileWithIncorrectKeyMapping) + .isInstanceOf(ScannerException.class) + .hasMessageContaining("mapping values are not allowed here"); + } + + @Test + void shouldThrowExceptionWhenLoadingInvalidYamlFileWithUnknownEscapeCharacter() { + // 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/YamlLoadingUtils.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java new file mode 100644 index 0000000..b65029f --- /dev/null +++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java @@ -0,0 +1,94 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml; + +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.model.YamlDocument; + +import java.net.URL; +import java.util.List; + +import static org.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException; + +public final class YamlLoadingUtils { + + private YamlLoadingUtils() { } + + public static final int VALID_YAML_DOCUMENT_INDEX = 4; + public static final int YAML_DOCUMENT_WITH_WRONG_VALUE_IN_ARRAY_INDEX = 3; + public static final int YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX = 2; + public static final int YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX = 1; + + static final String PATH_TO_VALID_YAML = "yaml_schema/PM_Dictionary.yaml"; + static final String PATH_TO_VALID_JSON_STYLE_YAML = "yaml_schema/PM_Dictionary_JSON_Style.yaml"; + private static final String PATH_TO_SIMPLE_VALID_SCHEMA = "yaml_schema/Simple_Valid_Schema.yaml"; + private static final String PATH_TO_SIMPLE_VALID_SCHEMA_MULTI_ROOT = "yaml_schema/Simple_Valid_Schema_Multi_Root.yaml"; + private static final String PATH_TO_SIMPLE_INVALID_SCHEMA = "yaml_schema/Simple_Invalid_Schema_Construction.yaml"; + private static final String PATH_TO_SIMPLE_INVALID_SCHEMA_FOR_LAZY_LOADING = "yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml"; + static final String PATH_TO_MULTI_DOCUMENT_INVALID_YAML = "yaml_schema/Multi_Document_Invalid.yaml"; + private static final String PATH_TO_INVALID_YAML_WITH_INCORRECT_KEY_MAPPING = "yaml_schema/Simple_Invalid_Mapping_Value.yaml"; + private static final String PATH_TO_INVALID_YAML_WITH_UNKNOWN_ESCAPE_CHARACTER = "yaml_schema/Simple_Unknown_Escape_Character.yaml"; + + public static List loadValidMultiDocumentYamlFile() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_VALID_YAML)); + } + + public static List loadValidJsonStyleMultiDocumentYamlFile() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_VALID_JSON_STYLE_YAML)); + } + + public static List loadValidMultiDocumentYamlFileUsingStringPath() throws YamlProcessingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_VALID_YAML).getPath()); + } + + public static YamlDocument loadSimpleValidYamlSchemaFile() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_VALID_SCHEMA)).get(0); + } + + public static YamlDocument loadSimpleInvalidYamlSchemaFile() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_INVALID_SCHEMA)).get(0); + } + + public static YamlDocument loadSimpleInvalidYamlSchemaForLazyLoadingFile() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_INVALID_SCHEMA_FOR_LAZY_LOADING)).get(0); + } + + public static YamlDocument loadSimpleValidYamlSchemaWithMultiRootFile() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_VALID_SCHEMA_MULTI_ROOT)).get(0); + } + + public static List tryToLoadMultiDocumentInvalidYamlFile() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_MULTI_DOCUMENT_INVALID_YAML)); + } + + public static List tryToLoadMultiDocumentInvalidYamlFileUsingStringPath() throws YamlProcessingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_MULTI_DOCUMENT_INVALID_YAML).getPath()); + } + + public static List tryToLoadInvalidYamlFileWithIncorrectKeyMapping() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_INVALID_YAML_WITH_INCORRECT_KEY_MAPPING)); + } + + public static List tryToLoadInvalidYamlFileWithUnknownEscapeCharacter() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_INVALID_YAML_WITH_UNKNOWN_ESCAPE_CHARACTER)); + } + + private static URL getUrlForGivenPath(String path) { + return YamlLoadingUtils.class.getClassLoader().getResource(path); + } +} diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java new file mode 100644 index 0000000..3f64540 --- /dev/null +++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java @@ -0,0 +1,118 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +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; +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.schema.YamlSchemaFactory; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +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; +import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_WRONG_VALUE_IN_ARRAY_INDEX; + +class YamlValidatorTest { + + @Test + void shouldCreateValidatorUsingSchemaLoadedFromYamlFileAndValidatedJsonStyleDocumentsFromThatFile() + throws YamlProcessingException { + + // given + List documents = YamlLoadingUtils.loadValidJsonStyleMultiDocumentYamlFile(); + YamlValidator validator = new YamlValidator(new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0))); + Map> validationErrors = new HashMap<>(); + + // when + for (int documentIndex = 1; documentIndex < documents.size(); documentIndex++) { + validationErrors.put(documentIndex, validator.validate(documents.get(documentIndex))); + } + + // then + assertValidatorReturnedCorrectErrors(validationErrors); + } + + @Test + void shouldCreateValidatorUsingSchemaLoadedFromYamlFileAndValidatedDocumentsFromThatFile() + throws YamlProcessingException { + + // given + List documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile(); + YamlValidator validator = new YamlValidator(new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0))); + Map> validationErrors = new HashMap<>(); + + // when + for (int documentIndex = 1; documentIndex < documents.size(); documentIndex++) { + validationErrors.put(documentIndex, validator.validate(documents.get(documentIndex))); + } + + // then + assertValidatorReturnedCorrectErrors(validationErrors); + } + + private void assertValidatorReturnedCorrectErrors(Map> validationErrors) { + + SchemaValidationError expectedValidationValueError = + new SchemaValidationError( + "/pmMetaData/pmFields/measResultType", + "Value(s) is/are not in array of accepted values.\n" + + " value(s): integer\n" + + " accepted value(s): [float, uint32, uint64]" + ); + SchemaValidationError expectedValidationKeyError = + new SchemaValidationError( + "/pmMetaData/pmFields/", + "Key not found: measChangeType" + ); + SchemaValidationError expectedValidationValuesInArrayError = + new SchemaValidationError( + "/pmMetaData/pmFields/measAdditionalFields/vendorField1", + "Value(s) is/are not in array of accepted values.\n" + + " value(s): [Z, A]\n" + + " accepted value(s): [X, Y, Z]" + ); + + assertThat(validationErrors) + .hasSize(4) + .containsKeys(1, 2, 3); + assertThat(validationErrors.get(YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX)) + .hasSize(2) + .usingFieldByFieldElementComparator() + .containsAll(Lists.list( + expectedValidationValueError, + expectedValidationKeyError + )); + assertThat(validationErrors.get(YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX)) + .hasSize(1) + .usingFieldByFieldElementComparator() + .contains(expectedValidationKeyError); + assertThat(validationErrors.get(YAML_DOCUMENT_WITH_WRONG_VALUE_IN_ARRAY_INDEX)) + .hasSize(1) + .usingFieldByFieldElementComparator() + .contains(expectedValidationValuesInArrayError); + assertThat(validationErrors.get(VALID_YAML_DOCUMENT_INDEX)).hasSize(0); + } + +} 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 new file mode 100644 index 0000000..0bd0579 --- /dev/null +++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java @@ -0,0 +1,134 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.model; + +import org.junit.jupiter.api.Test; + +import java.util.Collections; +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.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException; + +class YamlDocumentFactoryTest { + + @Test + void shouldTurnMapOfUnknownKeyTypeToMapWithStringKeysAndBeAbleToReturnStringifyValues() + throws YamlDocumentParsingException { + // given + List testList = List.of("element1", "element11"); + Map testEmptyMap = Collections.emptyMap(); + Map inputMap = Map.of( + "test", testList, + 345, "element2", + "test2", "element3", + 2.67, testEmptyMap); + + // 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("{}"); + } + + @Test + void shouldTurnMapOfUnknownKeyTypeToMapWithStringKeysAndBeAbleToExtractSubStructure() + throws YamlDocumentParsingException { + // given + Map subStructureMap = Map.of( + "subTest1", "subElement1", + "subTest2", "subElement2"); + Map inputMap = Map.of( + "test", "element1", + "structure", subStructureMap); + + // 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"); + } + + @Test + void shouldTurnMapOfUnknownKeyTypeToMapWithStringKeysAndBeAbleToExtractParametersList() + throws YamlDocumentParsingException { + // given + List parametersList = List.of("parameter1", "parameter2"); + Map inputMap = Map.of( + "test", "element1", + "parameters", parametersList); + + // 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"); + } + + @Test + void shouldThrowExceptionIfGetSubStructureIsCalledOnList() + throws YamlDocumentParsingException { + // given + List testList = List.of("element1", "element2"); + Map 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)); + } + + @Test + void shouldThrowExceptionIfGetSubStructureIsCalledOnString() + throws YamlDocumentParsingException { + // given + Map inputMap = Collections.singletonMap("test", "testElement"); + + 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.", "testElement")); + } +} 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 new file mode 100644 index 0000000..ed15532 --- /dev/null +++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java @@ -0,0 +1,83 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.model; + +import org.assertj.core.util.Lists; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class YamlParameterListFactoryTest { + + @Test + void shouldCreateEmptyParametersList() { + // when + YamlParametersList parametersList = new YamlParameterListFactory().createEmptyYamlParameterList(); + + // then + assertThat(parametersList).isNotNull(); + assertThat(parametersList.getParameters()).isEmpty(); + } + + @Test + void shouldCreateParametersListContainingStringsFromListContainingSimpleTypes() { + // given + List elements = List.of("test1", 3, 23.45, 'a', "test2"); + + // when + YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList( elements); + + // then + assertThat(parametersList).isNotNull(); + assertThat(parametersList.getParameters()) + .hasSize(5) + .contains("test1", "test2", "3", "23.45", "a"); + } + + @Test + void shouldCreateParametersListContainingStringsFromListContainingVariousTypes() { + // given + List testList = List.of("test1", 3, Lists.list(2, 3, 4), "test2"); + + // when + YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testList); + + // then + assertThat(parametersList).isNotNull(); + assertThat(parametersList.getParameters()) + .hasSize(4) + .contains("test1", "test2", "3", "[2, 3, 4]"); + } + + @Test + void shouldCreateListWithOneStringWhenGivenObjectIsNotList() { + // given + Object testObject = "test"; + + // when + YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testObject); + + // then + assertThat(parametersList).isNotNull(); + assertThat(parametersList.getParameters()) + .hasSize(1) + .contains("test"); + } +} 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 new file mode 100644 index 0000000..4c602e0 --- /dev/null +++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java @@ -0,0 +1,97 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.process; + +import org.junit.jupiter.api.Test; +import org.onap.validation.yaml.YamlLoadingUtils; +import org.onap.validation.yaml.error.SchemaValidationError; +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.schema.YamlSchema; +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.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; + +class YamlValidationProcessTest { + + @Test + void shouldReturnNoErrorWhenProcessingValidPmDictionaryYaml() + throws YamlProcessingException { + // given + List documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile(); + YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0)); + YamlDocument document = documents.get(VALID_YAML_DOCUMENT_INDEX); + + // when + List errors = new YamlValidationProcess(schema, document).validate(); + + // then + assertThat(errors).isEmpty(); + } + + @Test + void shouldReturnOneErrorWhenProcessingPmDictionaryYamlWithMissingField() + throws YamlProcessingException { + // given + List documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile(); + YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0)); + YamlDocument document = documents.get(YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX); + + // when + List errors = new YamlValidationProcess(schema, document).validate(); + + // then + assertThat(errors).hasSize(1); + } + + @Test + void shouldReturnTwoErrorsWhenProcessingPmDictionaryYamlWithMissingFieldAndIncorrectValue() + throws YamlProcessingException { + // given + List 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 + List errors = new YamlValidationProcess(schema, document).validate(); + + // then + assertThat(errors).hasSize(2); + } + + @Test + void shouldThrowExceptionWhenProcessingPmDictionaryIsNotValidYaml() + throws YamlProcessingException { + // given + List 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()) + .isInstanceOf(YamlProcessingException.class) + .hasMessageContaining(String.format("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 new file mode 100644 index 0000000..5768851 --- /dev/null +++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java @@ -0,0 +1,118 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.validation.yaml.schema; + +import org.junit.jupiter.api.Test; +import org.onap.validation.yaml.YamlLoadingUtils; +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.schema.node.YamlSchemaNode; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException; +import static org.onap.validation.yaml.schema.node.YamlSchemaNodeFactory.EMPTY_COMMENT; +import static org.onap.validation.yaml.schema.node.YamlSchemaNodeFactoryTest.assertThatBranchNodeIsValid; +import static org.onap.validation.yaml.schema.node.YamlSchemaNodeFactoryTest.assertThatLeafNodeIsValid; + + +class YamlSchemaFactoryTest { + + @Test + void shouldCreateYamlSchemaFromYamlDocumentWithMultipleRoots() + throws YamlProcessingException { + + // given + YamlDocument documents = YamlLoadingUtils.loadSimpleValidYamlSchemaWithMultiRootFile(); + + // when + YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents); + + // 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"); + } + + + @Test + void shouldCreateYamlSchemaFromYamlDocument() + throws YamlProcessingException { + + // given + YamlDocument documents = YamlLoadingUtils.loadSimpleValidYamlSchemaFile(); + + // when + YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents); + + // then + assertThat(schema).isNotNull(); + assertThat(schema.getRootNodes()).hasSize(1); + YamlSchemaNode pmMetaData = schema.getRootNodes().get(0); + assertThatBranchNodeIsValid(pmMetaData, "pmMetaData", "/", true, EMPTY_COMMENT, + 2); + + YamlSchemaNode pmHeader = pmMetaData.getNextNodes().get(1); + assertThatBranchNodeIsValid(pmHeader, "pmHeader", "/pmMetaData/", true, EMPTY_COMMENT, + 1); + + YamlSchemaNode nfType = pmHeader.getNextNodes().get(0); + assertThatLeafNodeIsValid(nfType, "nfType", "/pmMetaData/pmHeader/", true, "nfType comment"); + + YamlSchemaNode pmFields = pmMetaData.getNextNodes().get(0); + assertThatBranchNodeIsValid(pmFields, "pmFields", "/pmMetaData/", true, EMPTY_COMMENT, + 2); + + YamlSchemaNode measChangeType = pmFields.getNextNodes().get(1); + assertThatLeafNodeIsValid(measChangeType, "measChangeType", "/pmMetaData/pmFields/", + true, "measChangeType comment", + "added", "modified", "deleted"); + + YamlSchemaNode measAdditionalFields = pmFields.getNextNodes().get(0); + assertThatBranchNodeIsValid(measAdditionalFields, "measAdditionalFields", "/pmMetaData/pmFields/", + true, "measAdditionalFields comment", + 2); + + YamlSchemaNode vendorField1 = measAdditionalFields.getNextNodes().get(0); + assertThatLeafNodeIsValid(vendorField1, "vendorField1", "/pmMetaData/pmFields/measAdditionalFields/", + true, "vendorField1 comment", + "X", "Y", "Z"); + YamlSchemaNode vendorField2 = measAdditionalFields.getNextNodes().get(1); + assertThatLeafNodeIsValid(vendorField2, "vendorField2", "/pmMetaData/pmFields/measAdditionalFields/", + false, "vendorField2 comment", + "A", "B"); + } + + @Test + void shouldThrowYamlParsingExceptionWhenLoadedSchemaIsInvalid() + throws YamlDocumentParsingException { + + // given + YamlDocument documents = YamlLoadingUtils.loadSimpleInvalidYamlSchemaFile(); + + // when/then + assertThatThrownBy(() -> new YamlSchemaFactory().createTreeStructuredYamlSchema(documents)) + .isInstanceOf(YamlDocumentParsingException.class) + .hasMessageContaining(String.format( + "Fail to parse given objects: %s as yaml document", + documents.getSubStructure("pmMetaData").getYaml().get("structure")) + ); + } +} 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 new file mode 100644 index 0000000..ed43a1d --- /dev/null +++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java @@ -0,0 +1,146 @@ +/* + * Copyright 2020 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +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; +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.model.YamlDocumentFactory; + +import java.util.HashMap; +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.onap.validation.yaml.schema.node.YamlSchemaNodeFactory.EMPTY_COMMENT; + +public class YamlSchemaNodeFactoryTest { + + private static final String ROOT_PATH = "/"; + + @Test + void shouldThrowExceptionDuringLazyLoadingWhenLoadedSchemaHaveInvalidSubStructure() + throws YamlProcessingException { + // given + String nodeName = "pmMetaData"; + + YamlDocument document = YamlLoadingUtils.loadSimpleInvalidYamlSchemaForLazyLoadingFile(); + YamlSchemaNode node = new YamlSchemaNodeFactory() + .createNode(nodeName, ROOT_PATH, document.getSubStructure(nodeName)); + + // when/then + assertThatThrownBy(node::getNextNodes) + .isInstanceOf(YamlSchemaNode.YamlSchemaProcessingException.class) + .hasMessageContaining("Lazy loading failed, due to yaml parsing exception."); + } + + @Test + void shouldCreateLeafNodeIfGivenYamlDocumentHaveNoSubStructure() + throws YamlProcessingException { + // given + String nodeName = "leaf_test"; + String comment = "test leaf node"; + List acceptedValues = Lists.list("val1", "val2"); + Map 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 + YamlSchemaNode yamlSchemaNode = new YamlSchemaNodeFactory().createNode(nodeName, ROOT_PATH, document); + + // then + assertThatLeafNodeIsValid( + yamlSchemaNode, nodeName, ROOT_PATH, true, comment, + acceptedValues.toArray(new String[acceptedValues.size()]) + ); + } + + @Test + void shouldCreateBranchNodeIfGivenYamlDocumentHaveSubStructure() + throws YamlProcessingException { + // given + String nodeName = "branch_test"; + String comment = "test branch node"; + + Map subStructure = new HashMap<>(); + String subNode1Name = "branch_test_node1"; + String subNode2Name = "branch_test_node2"; + subStructure.put(subNode1Name, new HashMap<>()); + subStructure.put(subNode2Name, new HashMap<>()); + + Map nodeInYamlFormat = new HashMap<>(); + nodeInYamlFormat.put(YamlSchemaNodeFactory.PRESENCE_KEY, YamlSchemaNodeFactory.PRESENCE_REQUIRED_KEY); + nodeInYamlFormat.put(YamlSchemaNodeFactory.COMMENT_KEY, comment); + nodeInYamlFormat.put(YamlSchemaNodeFactory.STRUCTURE_KEY, subStructure); + YamlDocument document = new YamlDocumentFactory().createYamlDocument(nodeInYamlFormat); + + // when + YamlSchemaNode yamlSchemaNode = new YamlSchemaNodeFactory().createNode(nodeName, ROOT_PATH, document); + + // then + assertThatBranchNodeIsValid(yamlSchemaNode, nodeName, ROOT_PATH, true, comment, 2); + + List subNodes = yamlSchemaNode.getNextNodes(); + assertThat(subNodes).hasSize(2); + assertThatLeafNodeIsValid( + subNodes.get(1), subNode1Name, ROOT_PATH + nodeName + "/", false, EMPTY_COMMENT); + assertThatLeafNodeIsValid( + subNodes.get(0), subNode2Name, ROOT_PATH + nodeName + "/", false, EMPTY_COMMENT); + } + + public static void assertThatBranchNodeIsValid( + YamlSchemaNode yamlSchemaNode, String name, String path, boolean isRequired, String comment, + int numberOfSubNodes + ) throws YamlSchemaNode.YamlSchemaProcessingException { + assertThatNodeIsValid(yamlSchemaNode, name, path, isRequired, comment); + + assertThat(yamlSchemaNode.getClass()).isEqualTo(YamlSchemaBranchNode.class); + assertThat(yamlSchemaNode.isContainingSubStructure()).isTrue(); + assertThat(yamlSchemaNode.getNextNodes()).hasSize(numberOfSubNodes); + assertThat(yamlSchemaNode.getAcceptedValues()).isEmpty(); + } + + public static void assertThatLeafNodeIsValid( + YamlSchemaNode yamlSchemaNode, String name, String path, boolean isRequired, String comment, + String... acceptedValues + ) throws YamlSchemaNode.YamlSchemaProcessingException { + assertThatNodeIsValid(yamlSchemaNode, name, path, isRequired, comment); + + assertThat(yamlSchemaNode.getClass()).isEqualTo(YamlSchemaLeafNode.class); + assertThat(yamlSchemaNode.isContainingSubStructure()).isFalse(); + assertThat(yamlSchemaNode.getAcceptedValues()).containsExactly(acceptedValues); + assertThat(yamlSchemaNode.getNextNodes()).isEmpty(); + } + + private static void assertThatNodeIsValid(YamlSchemaNode yamlSchemaNode, String name, String path, boolean isRequired, String comment) { + assertThat(yamlSchemaNode).isNotNull(); + assertThat(yamlSchemaNode.getName()).isEqualTo(name); + assertThat(yamlSchemaNode.getPath()).isEqualTo(path); + if (comment.isEmpty()) { + assertThat(yamlSchemaNode.getComment()).isNotEmpty(); + } else { + assertThat(yamlSchemaNode.getComment()).isEqualTo(comment); + } + assertThat(yamlSchemaNode.isRequired()).isEqualTo(isRequired); + } +} diff --git a/pmdictionaryvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml new file mode 100644 index 0000000..aab34fa --- /dev/null +++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml @@ -0,0 +1,86 @@ +... +# PM Dictionary perf3gpp measurements for the gnb-Nokia NF (bracket style yaml) +--- +pmMetaData: { + pmHeader: { + nfType: gnb-Nokia, + pmDefSchemaVsn: 2.0, + pmDefVsn: 5G19_1906_002 + }, + pmFields: { + iMeasInfoId: 2204, + iMeasType: 1, + + measCollectionMethod: CC, + measCondition: "This measurement is updated when X2AP: SgNB Modification Required message is sent to MeNB + with the SCG Change Indication set as PSCellChange.", + measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change attempts.", + measFamily: NINFC, + measInfoId: "NR Intra Frequency PSCell Change", + measLastChange: 5G18A_1807_003, + measObjClass: NGCELL, + measResultRange: 0-4096, + measResultType: integer, + measResultUnits: number, + measType: VS.NINFC.IntraFrPscelChAttempt, + measAdditionalFields: { + vendorField1: X, + vendorField2: B + } + } +} +--- +pmMetaData: { + pmHeader: { + nfType: gnb-Nokia, + pmDefSchemaVsn: 2.0, + pmDefVsn: 5G19_1906_002 + }, + pmFields: { + iMeasInfoId: 2204, + iMeasType: 2, + measCollectionMethod: CC, + measCondition: "This measurement is updated when the TDCoverall timer has elapsed before gNB receives the X2AP: SgNB Modification Confirm message.", + measDescription: "This measurement the number of intra gNB intra frequency PSCell change failures due to TDCoverall timer expiry.", + measFamily: NINFC, + measInfoId: "NR Intra Frequency PSCell Change", + measLastChange: 5G18A_1807_003, + measObjClass: NGCELL, + measResultRange: 0-4096, + measResultType: float, + measResultUnits: number, + measType: VS.NINFC.IntraFrPscelChFailTdcExp, + measAdditionalFields: { + vendorField1: Y + } + } +} +... +--- +pmMetaData: { + pmHeader: { + nfType: gnb-Nokia, + pmDefSchemaVsn: 2.0, + pmDefVsn: 5G19_1906_002 + }, + pmFields: { + iMeasInfoId: 2206, + iMeasType: 1, + measCondition: "This measurement is updated when MeNB replies to X2AP: SgNB Modification Required message with the X2AP: SgNB Modification Refuse message.", + measCollectionMethod: CC, + measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change failures due to MeNB refusal.", + measFamily: NINFC, + measInfoId: "NR Intra Frequency PSCell Change", + measLastChange: 5G19_1906_002, + measObjClass: NGCELL, + measResultRange: 0-4096, + measResultType: float, + measChangeType: added, + measResultUnits: number, + measType: VS.NINFC.IntraFrPscelChFailMenbRef, + measAdditionalFields: { + vendorField1: Z, + vendorField2: A + } + } +... diff --git a/pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml new file mode 100644 index 0000000..12a4af9 --- /dev/null +++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml @@ -0,0 +1,228 @@ +--- +# PM Dictionary schema specifying and describing the meta information +# used to define perf3gpp measurements in the PM Dictionary +pmMetaData: { presence: required, structure: { + pmHeader: { + presence: required, + structure: { + nfType: { + presence: required, + comment: "NF type; should match the nfName-vendor string used in + the fileReady or perf3gpp eventName" + }, + pmDefSchemaVsn: { + presence: required, + value: 2.0, + comment: "PM Dictionary Schema Version from the VES Event + Registration specification" + }, + pmDefVsn: { + presence: required, + comment: "vendor-defined PM Dictionary version" + } + } + }, + pmFields: { + presence: required, + structure: { + iMeasInfoId: { + presence: required, + comment: "vendor-defined integer measurement group identifier" + }, + iMeasType: { + presence: required, + comment: "vendor-defined integer identifier for the measType; + must be combined with measInfoId to identify a + specific measurement." + }, + measChangeType: { + presence: required, + value: [added, modified, deleted], + comment: "indicates the type of change that occurred during + measLastChange" + }, + measCollectionMethod: { + presence: required, + value: [CC, SI, DER, Gauge, Average], + comment: "the measurement collection method; CC, SI, DER and + Gauge are as defined in 3GPP; average contains the + average value of the measurement during the + granularity period" + }, + measCondition: { + presence: required, + comment: "description of the condition causing the measurement" + }, + measDescription: { + presence: required, + comment: "description of the measurement information + and purpose" + }, + measFamily: { + presence: required, + comment: "abbreviation for a family of measurements, in + 3GPP format, or vendor defined" + }, + measInfoId: { + presence: required, + comment: "name for a group of related measurements in + 3GPP format or vendor defined" + }, + measLastChange: { + presence: required, + comment: "version of the PM Dictionary the last time this + measurement was added, modified or deleted" + }, + measObjClass: { + presence: required, + value: [NGBTS, NGCELL, IPNO, IPSEC, ETHIF], + comment: "measurement object class" + }, + measResultRange: { + presence: optional, + comment: "range of the measurement result; only necessary when + the range is smaller than the full range of the + data type" + }, + measResultType: { + presence: required, + value: [float, uint32, uint64], + comment: "data type of the measurement result" + }, + measResultUnits: { + presence: required, + value: [seconds, minutes, nanoseconds, microseconds, dB, + number, kilobytes, bytes, ethernetFrames, + packets, users], + comment: "units of measure for the measurement result" + }, + measType: { + presence: required, + comment: "measurement name in 3GPP or vendor-specific format; + vendor specific names are preceded with VS" + }, + measAdditionalFields: { + presence: required, + comment: "vendor-specific PM Dictionary fields", + structure: { + vendorField1: { + presence: required, + value: [X, Y, Z], + comment: "vendor field 1 description" + }, + vendorField2: { + presence: optional, + value: [A, B], + comment: "vendor field 2 description." + } + } + } + } + } +}} +... +# PM Dictionary perf3gpp measurements for the gnb-Nokia NF (bracket style yaml) +--- +pmMetaData: + pmHeader: + nfType: gnb-Nokia + pmDefSchemaVsn: 2.0 + pmDefVsn: 5G19_1906_002 + pmFields: + iMeasInfoId: 2204 + iMeasType: 1 + measCollectionMethod: CC + measCondition: "This measurement is updated when X2AP: SgNB Modification Required message is sent to MeNB + with the SCG Change Indication set as PSCellChange." + measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change attempts." + measFamily: NINFC + measInfoId: "NR Intra Frequency PSCell Change" + measLastChange: 5G18A_1807_003 + measObjClass: NGCELL + measResultRange: 0-4096 + measResultType: integer + measResultUnits: number + measType: VS.NINFC.IntraFrPscelChAttempt + measAdditionalFields: + vendorField1: X + vendorField2: B +... +--- +pmMetaData: + pmHeader: + nfType: gnb-Nokia + pmDefSchemaVsn: 2.0 + pmDefVsn: 5G19_1906_002 + pmFields: + iMeasInfoId: 2204 + iMeasType: 2 + measCollectionMethod: CC + measCondition: "This measurement is updated when the TDCoverall timer has elapsed before gNB receives the X2AP: SgNB Modification Confirm message." + measDescription: "This measurement the number of intra gNB intra frequency PSCell change failures due to TDCoverall timer expiry." + measFamily: NINFC + measInfoId: "NR Intra Frequency PSCell Change" + measLastChange: 5G18A_1807_003 + measObjClass: NGCELL + measResultRange: 0-4096 + measResultType: float + measResultUnits: number + measType: VS.NINFC.IntraFrPscelChFailTdcExp + measAdditionalFields: + vendorField1: + - Y + - X +... +--- +pmMetaData: + pmHeader: + nfType: gnb-Nokia + pmDefSchemaVsn: 2.0 + pmDefVsn: 5G19_1906_002 + pmFields: + iMeasInfoId: 2206 + iMeasType: 1 + measCondition: "This measurement is updated when MeNB replies to X2AP: SgNB Modification Required message with the X2AP: SgNB Modification Refuse message." + measCollectionMethod: CC + measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change failures due to MeNB refusal." + measFamily: NINFC + measInfoId: "NR Intra Frequency PSCell Change" + measLastChange: 5G19_1906_002 + measObjClass: NGCELL + measResultRange: 0-4096 + measResultType: float + measChangeType: added + measResultUnits: number + measType: VS.NINFC.IntraFrPscelChFailMenbRef + measAdditionalFields: + vendorField1: + - Z + - A + vendorField2: A +... +--- +pmMetaData: + pmHeader: + nfType: gnb-Nokia + pmDefSchemaVsn: 2.0 + pmDefVsn: 5G19_1906_002 + pmFields: + iMeasInfoId: 2206 + iMeasType: 1 + measCondition: "This measurement is updated when MeNB replies to X2AP: SgNB Modification Required message with the X2AP: SgNB Modification Refuse message." + measCollectionMethod: CC + measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change failures due to MeNB refusal." + measFamily: NINFC + measInfoId: "NR Intra Frequency PSCell Change" + measLastChange: 5G19_1906_002 + measObjClass: NGCELL + measResultRange: 0-4096 + measResultType: float + measChangeType: added + measResultUnits: number + measType: VS.NINFC.IntraFrPscelChFailMenbRef + measAdditionalFields: + vendorField1: + - X + - Y + vendorField2: A +... diff --git a/pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml new file mode 100644 index 0000000..f4cbddf --- /dev/null +++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml @@ -0,0 +1,239 @@ +--- +# PM Dictionary schema specifying and describing the meta information +# used to define perf3gpp measurements in the PM Dictionary +pmMetaData: { presence: required, structure: { + pmHeader: { + presence: required, + structure: { + nfType: { + presence: required, + comment: "NF type; should match the nfName-vendor string used in + the fileReady or perf3gpp eventName" + }, + pmDefSchemaVsn: { + presence: required, + value: 2.0, + comment: "PM Dictionary Schema Version from the VES Event + Registration specification" + }, + pmDefVsn: { + presence: required, + comment: "vendor-defined PM Dictionary version" + } + } + }, + pmFields: { + presence: required, + structure: { + iMeasInfoId: { + presence: required, + comment: "vendor-defined integer measurement group identifier" + }, + iMeasType: { + presence: required, + comment: "vendor-defined integer identifier for the measType; + must be combined with measInfoId to identify a + specific measurement." + }, + measChangeType: { + presence: required, + value: [added, modified, deleted], + comment: "indicates the type of change that occurred during + measLastChange" + }, + measCollectionMethod: { + presence: required, + value: [CC, SI, DER, Gauge, Average], + comment: "the measurement collection method; CC, SI, DER and + Gauge are as defined in 3GPP; average contains the + average value of the measurement during the + granularity period" + }, + measCondition: { + presence: required, + comment: "description of the condition causing the measurement" + }, + measDescription: { + presence: required, + comment: "description of the measurement information + and purpose" + }, + measFamily: { + presence: required, + comment: "abbreviation for a family of measurements, in + 3GPP format, or vendor defined" + }, + measInfoId: { + presence: required, + comment: "name for a group of related measurements in + 3GPP format or vendor defined" + }, + measLastChange: { + presence: required, + comment: "version of the PM Dictionary the last time this + measurement was added, modified or deleted" + }, + measObjClass: { + presence: required, + value: [NGBTS, NGCELL, IPNO, IPSEC, ETHIF], + comment: "measurement object class" + }, + measResultRange: { + presence: optional, + comment: "range of the measurement result; only necessary when + the range is smaller than the full range of the + data type" + }, + measResultType: { + presence: required, + value: [float, uint32, uint64], + comment: "data type of the measurement result" + }, + measResultUnits: { + presence: required, + value: [seconds, minutes, nanoseconds, microseconds, dB, + number, kilobytes, bytes, ethernetFrames, + packets, users], + comment: "units of measure for the measurement result" + }, + measType: { + presence: required, + comment: "measurement name in 3GPP or vendor-specific format; + vendor specific names are preceded with VS" + }, + measAdditionalFields: { + presence: required, + comment: "vendor-specific PM Dictionary fields", + structure: { + vendorField1: { + presence: required, + value: [X, Y, Z], + comment: "vendor field 1 description" + }, + vendorField2: { + presence: optional, + value: [A, B], + comment: "vendor field 2 description." + } + } + } + } + } +}} +... +# PM Dictionary perf3gpp measurements for the gnb-Nokia NF (bracket style yaml) +--- +pmMetaData: { + pmHeader: { + nfType: gnb-Nokia, + pmDefSchemaVsn: 2.0, + pmDefVsn: 5G19_1906_002 + }, + pmFields: { + iMeasInfoId: 2204, + iMeasType: 1, + + measCollectionMethod: CC, + measCondition: "This measurement is updated when X2AP: SgNB Modification Required message is sent to MeNB + with the SCG Change Indication set as PSCellChange.", + measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change attempts.", + measFamily: NINFC, + measInfoId: "NR Intra Frequency PSCell Change", + measLastChange: 5G18A_1807_003, + measObjClass: NGCELL, + measResultRange: 0-4096, + measResultType: integer, + measResultUnits: number, + measType: VS.NINFC.IntraFrPscelChAttempt, + measAdditionalFields: { + vendorField1: X, + vendorField2: B + } + } +} +... +--- +pmMetaData: { + pmHeader: { + nfType: gnb-Nokia, + pmDefSchemaVsn: 2.0, + pmDefVsn: 5G19_1906_002 + }, + pmFields: { + iMeasInfoId: 2204, + iMeasType: 2, + measCollectionMethod: CC, + measCondition: "This measurement is updated when the TDCoverall timer has elapsed before gNB receives the X2AP: SgNB Modification Confirm message.", + measDescription: "This measurement the number of intra gNB intra frequency PSCell change failures due to TDCoverall timer expiry.", + measFamily: NINFC, + measInfoId: "NR Intra Frequency PSCell Change", + measLastChange: 5G18A_1807_003, + measObjClass: NGCELL, + measResultRange: 0-4096, + measResultType: float, + measResultUnits: number, + measType: VS.NINFC.IntraFrPscelChFailTdcExp, + measAdditionalFields: { + vendorField1: [Y,Z] + } + } +} +... +--- +pmMetaData: { + pmHeader: { + nfType: gnb-Nokia, + pmDefSchemaVsn: 2.0, + pmDefVsn: 5G19_1906_002 + }, + pmFields: { + iMeasInfoId: 2206, + iMeasType: 1, + measCondition: "This measurement is updated when MeNB replies to X2AP: SgNB Modification Required message with the X2AP: SgNB Modification Refuse message.", + measCollectionMethod: CC, + measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change failures due to MeNB refusal.", + measFamily: NINFC, + measInfoId: "NR Intra Frequency PSCell Change", + measLastChange: 5G19_1906_002, + measObjClass: NGCELL, + measResultRange: 0-4096, + measResultType: float, + measChangeType: added, + measResultUnits: number, + measType: VS.NINFC.IntraFrPscelChFailMenbRef, + measAdditionalFields: { + vendorField1: [Z,A], + vendorField2: A + } + } +} +... +--- +pmMetaData: { + pmHeader: { + nfType: gnb-Nokia, + pmDefSchemaVsn: 2.0, + pmDefVsn: 5G19_1906_002 + }, + pmFields: { + iMeasInfoId: 2206, + iMeasType: 1, + measCondition: "This measurement is updated when MeNB replies to X2AP: SgNB Modification Required message with the X2AP: SgNB Modification Refuse message.", + measCollectionMethod: CC, + measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change failures due to MeNB refusal.", + measFamily: NINFC, + measInfoId: "NR Intra Frequency PSCell Change", + measLastChange: 5G19_1906_002, + measObjClass: NGCELL, + measResultRange: 0-4096, + measResultType: float, + measChangeType: added, + measResultUnits: number, + measType: VS.NINFC.IntraFrPscelChFailMenbRef, + measAdditionalFields: { + vendorField1: [X,Y], + vendorField2: A + } + } +} +... diff --git a/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml new file mode 100644 index 0000000..25c72cd --- /dev/null +++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml @@ -0,0 +1,149 @@ +--- +# PM Dictionary schema specifying and describing the meta information +# used to define perf3gpp measurements in the PM Dictionary +pmMetaData: { presence: required, structure: { + pmHeader: { + presence: required, + structure: { + nfType: { + presence: required, + comment: "NF type; should match the nfName-vendor string used in + the fileReady or perf3gpp eventName" + }, + pmDefSchemaVsn: { + presence: required, + value: 2.0, + comment: "PM Dictionary Schema Version from the VES Event + Registration specification" + }, + pmDefVsn: { + presence: required, + comment: "vendor-defined PM Dictionary version" + } + } + }, + pmFields: { + presence: required, + structure: { + iMeasInfoId: { + presence: required, + comment: "vendor-defined integer measurement group identifier" + }, + iMeasType: { + presence: required, + comment: "vendor-defined integer identifier for the measType; + must be combined with measInfoId to identify a + specific measurement." + }, + measChangeType: { + presence: required, + value: [added, modified, deleted], + comment: "indicates the type of change that occurred during + measLastChange" + }, + measCollectionMethod: { + presence: required, + value: [CC, SI, DER, Gauge, Average], + comment: "the measurement collection method; CC, SI, DER and + Gauge are as defined in 3GPP; average contains the + average value of the measurement during the + granularity period" + }, + measCondition: { + presence: required, + comment: "description of the condition causing the measurement" + }, + measDescription: { + presence: required, + comment: "description of the measurement information + and purpose" + }, + measFamily: { + presence: required, + comment: "abbreviation for a family of measurements, in + 3GPP format, or vendor defined" + }, + measInfoId: { + presence: required, + comment: "name for a group of related measurements in + 3GPP format or vendor defined" + }, + measLastChange: { + presence: required, + comment: "version of the PM Dictionary the last time this + measurement was added, modified or deleted" + }, + measObjClass: { + presence: required, + value: [NGBTS, NGCELL, IPNO, IPSEC, ETHIF], + comment: "measurement object class" + }, + measResultRange: { + presence: optional, + comment: "range of the measurement result; only necessary when + the range is smaller than the full range of the + data type" + }, + measResultType: { + presence: required, + value: [float, uint32, uint64], + comment: "data type of the measurement result" + }, + measResultUnits: { + presence: required, + value: [seconds, minutes, nanoseconds, microseconds, dB, + number, kilobytes, bytes, ethernetFrames, + packets, users], + comment: "units of measure for the measurement result" + }, + measType: { + presence: required, + comment: "measurement name in 3GPP or vendor-specific format; + vendor specific names are preceded with VS" + }, + measAdditionalFields: { + presence: required, + comment: "vendor-specific PM Dictionary fields", + structure: { + vendorField1: { + presence: required, + value: [X, Y, Z], + comment: "vendor field 1 description" + }, + vendorField2: { + presence: optional, + value: [A, B], + comment: "vendor field 2 description." + } + } + } + } + } +}} +... +# PM Dictionary perf3gpp measurements for the gnb-Nokia NF (bracket style yaml) +--- +pmMetaData: + pmHeader: + nfType: gnb-Nokia + pmDefSchemaVsn: 2.0 + pmDefVsn: 5G19_1906_002 + pmFields: + iMeasInfoId: 2204 + iMeasType: 1 + measCollectionMethod: CC + measCondition: This measurement is updated when X2AP: SgNB Modification Required message is sent to MeNB + with the SCG Change Indication set as PSCellChange. + measDescription: This counter indicates the number of intra gNB intra frequency PSCell change attempts. + measFamily: NINFC + measInfoId: "NR Intra Frequency PSCell Change" + measLastChange: 5G18A_1807_003 + measObjClass: NGCELL + measResultRange: 0-4096 + measResultType: integer + measResultUnits: number + measType: VS.NINFC.IntraFrPscelChAttempt + measAdditionalFields: + vendorField1: X + vendorField2: B +... diff --git a/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml new file mode 100644 index 0000000..c5e7b7c --- /dev/null +++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml @@ -0,0 +1,39 @@ +--- +pmMetaData: { presence: required, structure: [ + -pmHeader: { + presence: required, + structure: { + nfType: { + presence: required, + comment: "nfType comment" + } + } + }, + -pmFields: { + presence: required, + structure: { + measChangeType: { + presence: required, + value: [added, modified, deleted], + comment: "measChangeType comment" + }, + measAdditionalFields: { + presence: required, + comment: "measAdditionalFields comment", + structure: { + vendorField1: { + presence: required, + value: [X, Y, Z], + comment: "vendorField1 comment" + }, + vendorField2: { + presence: optional, + value: [A, B], + comment: "vendorField2 comment" + } + } + } + } + } +]} +... diff --git a/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml new file mode 100644 index 0000000..7f9f946 --- /dev/null +++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml @@ -0,0 +1,39 @@ +--- +pmMetaData: { presence: required, structure: { + pmHeader: { + presence: required, + structure: { + nfType: { + presence: required, + comment: "nfType comment" + } + } + }, + pmFields: { + presence: required, + structure: [ + -measChangeType: { + presence: required, + value: [added, modified, deleted], + comment: "measChangeType comment" + }, + -measAdditionalFields: { + presence: required, + comment: "measAdditionalFields comment", + structure: { + vendorField1: { + presence: required, + value: [X, Y, Z], + comment: "vendorField1 comment" + }, + vendorField2: { + presence: optional, + value: [A, B], + comment: "vendorField2 comment" + } + } + } + ] + } +}} +... diff --git a/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml new file mode 100644 index 0000000..2cac9e6 --- /dev/null +++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml @@ -0,0 +1,149 @@ +--- +# PM Dictionary schema specifying and describing the meta information +# used to define perf3gpp measurements in the PM Dictionary +pmMetaData: { presence: required, structure: { + pmHeader: { + presence: required, + structure: { + nfType: { + presence: required, + comment: "NF type; should match the nfName-vendor string used in + the fileReady or perf3gpp eventName" + }, + pmDefSchemaVsn: { + presence: required, + value: 2.0, + comment: "PM Dictionary Schema Version from the VES Event + Registration specification" + }, + pmDefVsn: { + presence: required, + comment: "vendor-defined PM Dictionary version" + } + } + }, + pmFields: { + presence: required, + structure: { + iMeasInfoId: { + presence: required, + comment: "vendor-defined integer measurement group identifier" + }, + iMeasType: { + presence: required, + comment: "vendor-defined integer identifier for the measType; + must be combined with measInfoId to identify a + specific measurement." + }, + measChangeType: { + presence: required, + value: [added, modified, deleted], + comment: "indicates the type of change that occurred during + measLastChange" + }, + measCollectionMethod: { + presence: required, + value: [CC, SI, DER, Gauge, Average], + comment: "the measurement collection method; CC, SI, DER and + Gauge are as defined in 3GPP; average contains the + average value of the measurement during the + granularity period" + }, + measCondition: { + presence: required, + comment: "description of the condition causing the measurement" + }, + measDescription: { + presence: required, + comment: "description of the measurement information + and purpose" + }, + measFamily: { + presence: required, + comment: "abbreviation for a family of measurements, in + 3GPP format, or vendor defined" + }, + measInfoId: { + presence: required, + comment: "name for a group of related measurements in + 3GPP format or vendor defined" + }, + measLastChange: { + presence: required, + comment: "version of the PM Dictionary the last time this + measurement was added, modified or deleted" + }, + measObjClass: { + presence: required, + value: [NGBTS, NGCELL, IPNO, IPSEC, ETHIF], + comment: "measurement object class" + }, + measResultRange: { + presence: optional, + comment: "range of the measurement result; only necessary when + the range is smaller than the full range of the + data type" + }, + measResultType: { + presence: required, + value: [float, uint32, uint64], + comment: "data type of the measurement result" + }, + measResultUnits: { + presence: required, + value: [seconds, minutes, nanoseconds, microseconds, dB, + number, kilobytes, bytes, ethernetFrames, + packets, users], + comment: "units of measure for the measurement result" + }, + measType: { + presence: required, + comment: "measurement name in 3GPP or vendor-specific format; + vendor specific names are preceded with VS" + }, + measAdditionalFields: { + presence: required, + comment: "vendor-specific PM Dictionary fields", + structure: { + vendorField1: { + presence: required, + value: [X, Y, Z], + comment: "vendor field 1 description" + }, + vendorField2: { + presence: optional, + value: [A, B], + comment: "vendor field 2 description." + } + } + } + } + } +}} +... +# PM Dictionary perf3gpp measurements for the gnb-Nokia NF (bracket style yaml) +--- +pmMetaData: + pmHeader: + nfType: gnb-Nokia + pmDefSchemaVsn: 2.0 + pmDefVsn: 5G19_1906_002 + pmFields: + iMeasInfoId: 2204 + iMeasType: 1 + measCollectionMethod: CC + measCondition: "This measurement is updated when X2AP: SgNB Modification Required message is \sent\ to MeNB + with the SCG Change Indication set as PSCellChange." + measDescription: This counter indicates the number of intra gNB intra frequency PSCell change attempts. + measFamily: NINFC + measInfoId: "NR Intra Frequency PSCell Change" + measLastChange: 5G18A_1807_003 + measObjClass: NGCELL + measResultRange: 0-4096 + measResultType: integer + measResultUnits: number + measType: VS.NINFC.IntraFrPscelChAttempt + measAdditionalFields: + vendorField1: X + vendorField2: B +... diff --git a/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml new file mode 100644 index 0000000..a125b13 --- /dev/null +++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml @@ -0,0 +1,39 @@ +--- +pmMetaData: { presence: required, structure: { + pmHeader: { + presence: required, + structure: { + nfType: { + presence: required, + comment: "nfType comment" + } + } + }, + pmFields: { + presence: required, + structure: { + measChangeType: { + presence: required, + value: [added, modified, deleted], + comment: "measChangeType comment" + }, + measAdditionalFields: { + presence: required, + comment: "measAdditionalFields comment", + structure: { + vendorField1: { + presence: required, + value: [X, Y, Z], + comment: "vendorField1 comment" + }, + vendorField2: { + presence: optional, + value: [A, B], + comment: "vendorField2 comment" + } + } + } + } + } +}} +... diff --git a/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml new file mode 100644 index 0000000..d73ca4f --- /dev/null +++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml @@ -0,0 +1,23 @@ +--- +root1: { presence: required, structure: { + field1: { + presence: required, + value: [X, Y, Z], + comment: "field 1 description" + } +}} +root2: { presence: required, structure: { + field2: { + presence: required, + value: [X, Y, Z], + comment: "field 1 description" + } +}} +root3: { presence: required, structure: { + field3: { + presence: required, + value: [X, Y, Z], + comment: "field 1 description" + } +}} +... diff --git a/pom.xml b/pom.xml index c150b7f..9228351 100644 --- a/pom.xml +++ b/pom.xml @@ -34,6 +34,7 @@ csarvalidation deployment + pmdictionaryvalidation -- cgit 1.2.3-korg