From 0fce7537299e6af0d2b1fdb1d5c01654ce9573c0 Mon Sep 17 00:00:00 2001 From: Bartosz Gardziejewski Date: Thu, 6 May 2021 10:14:57 +0200 Subject: Rename PM_Dictionary_Validator to Dictionary_Validator Signed-off-by: Bartosz Gardziejewski Change-Id: Icb65e6f832804aa4a958e530422d35e079ffe3c1 Issue-ID: VNFSDK-769 --- csarvalidation/pom.xml | 2 +- .../VTPValidateCSARR816745IntegrationTest.java | 2 +- .../functional/PnfValidationFunctionalTest.java | 2 +- dictionaryvalidation/README.md | 26 +++ dictionaryvalidation/pom.xml | 151 +++++++++++++ .../main/java/org/onap/validation/cli/Main.java | 48 +++++ .../command/validate/OutputFilePathGenerator.java | 41 ++++ .../cli/command/validate/ResponseModel.java | 51 +++++ .../cli/command/validate/ResponseStorage.java | 30 +++ .../cli/command/validate/ToJsonConverter.java | 28 +++ .../command/validate/ToResponseModelConverter.java | 31 +++ .../validate/ValidateDictionaryYamlCommand.java | 92 ++++++++ .../java/org/onap/validation/cli/core/Cli.java | 85 ++++++++ .../java/org/onap/validation/cli/core/Command.java | 29 +++ .../onap/validation/cli/core/CommandException.java | 27 +++ .../onap/validation/cli/core/CommandResponse.java | 48 +++++ .../java/org/onap/validation/cli/core/Console.java | 41 ++++ .../onap/validation/rule/DictionaryValidate.java | 120 +++++++++++ .../rule/DictionaryValidateResponse.java | 57 +++++ .../onap/validation/yaml/YamlContentValidator.java | 83 +++++++ .../java/org/onap/validation/yaml/YamlLoader.java | 82 +++++++ .../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 | 78 +++++++ .../yaml/schema/node/YamlSchemaLeafNode.java | 50 +++++ .../yaml/schema/node/YamlSchemaNode.java | 66 ++++++ .../yaml/schema/node/YamlSchemaNodeFactory.java | 84 ++++++++ .../java/org/onap/validation/yaml/util/Args.java | 36 ++++ .../services/org.onap.cli.fw.cmd.OnapCommand | 15 ++ .../src/main/resources/log4j2.properties | 56 +++++ .../open-cli-schema/dictionary-validate.yaml | 63 ++++++ .../DictionaryValidateRuleFunctionalTest.java | 178 +++++++++++++++ .../org/onap/functional/util/OnapCliWrapper.java | 42 ++++ .../onap/functional/util/ValidationUtility.java | 49 +++++ .../java/org/onap/validation/cli/MainCITest.java | 144 +++++++++++++ .../validate/OutputFilePathGeneratorTest.java | 43 ++++ .../cli/command/validate/ToJsonConverterTest.java | 70 ++++++ .../command/validate/ValidateYamlCommandTest.java | 96 +++++++++ .../java/org/onap/validation/cli/core/CliTest.java | 101 +++++++++ .../validation/yaml/YamlContentValidatorTest.java | 164 ++++++++++++++ .../org/onap/validation/yaml/YamlLoaderTest.java | 148 +++++++++++++ .../org/onap/validation/yaml/YamlLoadingUtils.java | 104 +++++++++ .../onap/validation/yaml/YamlValidatorTest.java | 115 ++++++++++ .../yaml/model/YamlDocumentFactoryTest.java | 130 +++++++++++ .../yaml/model/YamlParameterListFactoryTest.java | 85 ++++++++ .../yaml/process/YamlValidationProcessTest.java | 100 +++++++++ .../yaml/schema/YamlSchemaFactoryTest.java | 115 ++++++++++ .../schema/node/YamlSchemaNodeFactoryTest.java | 147 +++++++++++++ .../org/onap/validation/yaml/util/ArgsTest.java | 39 ++++ .../src/test/resources/Not_Yaml_File.txt | 1 + .../yaml_schema/Custom_Invalid_Dictionary.yaml | 56 +++++ .../yaml_schema/Custom_Valid_Dictionary.yaml | 58 +++++ .../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/README.md | 26 --- pmdictionaryvalidation/pom.xml | 151 ------------- .../main/java/org/onap/validation/cli/Main.java | 48 ----- .../command/validate/OutputFilePathGenerator.java | 41 ---- .../cli/command/validate/ResponseModel.java | 51 ----- .../cli/command/validate/ResponseStorage.java | 30 --- .../cli/command/validate/ToJsonConverter.java | 28 --- .../command/validate/ToResponseModelConverter.java | 31 --- .../validate/ValidatePmDictionaryYamlCommand.java | 92 -------- .../java/org/onap/validation/cli/core/Cli.java | 85 -------- .../java/org/onap/validation/cli/core/Command.java | 29 --- .../onap/validation/cli/core/CommandException.java | 27 --- .../onap/validation/cli/core/CommandResponse.java | 48 ----- .../java/org/onap/validation/cli/core/Console.java | 41 ---- .../onap/validation/rule/PMDictionaryValidate.java | 120 ----------- .../rule/PMDictionaryValidateResponse.java | 57 ----- .../onap/validation/yaml/YamlContentValidator.java | 83 ------- .../java/org/onap/validation/yaml/YamlLoader.java | 82 ------- .../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 | 78 ------- .../yaml/schema/node/YamlSchemaLeafNode.java | 50 ----- .../yaml/schema/node/YamlSchemaNode.java | 66 ------ .../yaml/schema/node/YamlSchemaNodeFactory.java | 84 -------- .../java/org/onap/validation/yaml/util/Args.java | 36 ---- .../services/org.onap.cli.fw.cmd.OnapCommand | 15 -- .../src/main/resources/log4j2.properties | 56 ----- .../open-cli-schema/pm-dictionary-validate.yaml | 63 ------ .../PmDictionaryValidateRuleFunctionalTest.java | 133 ------------ .../org/onap/functional/util/OnapCliWrapper.java | 42 ---- .../onap/functional/util/ValidationUtility.java | 49 ----- .../java/org/onap/validation/cli/MainCITest.java | 144 ------------- .../validate/OutputFilePathGeneratorTest.java | 43 ---- .../cli/command/validate/ToJsonConverterTest.java | 70 ------ .../command/validate/ValidateYamlCommandTest.java | 96 --------- .../java/org/onap/validation/cli/core/CliTest.java | 101 --------- .../validation/yaml/YamlContentValidatorTest.java | 164 -------------- .../org/onap/validation/yaml/YamlLoaderTest.java | 148 ------------- .../org/onap/validation/yaml/YamlLoadingUtils.java | 104 --------- .../onap/validation/yaml/YamlValidatorTest.java | 115 ---------- .../yaml/model/YamlDocumentFactoryTest.java | 130 ----------- .../yaml/model/YamlParameterListFactoryTest.java | 85 -------- .../yaml/process/YamlValidationProcessTest.java | 100 --------- .../yaml/schema/YamlSchemaFactoryTest.java | 115 ---------- .../schema/node/YamlSchemaNodeFactoryTest.java | 147 ------------- .../org/onap/validation/yaml/util/ArgsTest.java | 39 ---- .../src/test/resources/Not_Yaml_File.txt | 1 - .../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 | 2 +- 138 files changed, 5085 insertions(+), 4926 deletions(-) create mode 100644 dictionaryvalidation/README.md create mode 100644 dictionaryvalidation/pom.xml create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/cli/Main.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/OutputFilePathGenerator.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ResponseModel.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ResponseStorage.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ToJsonConverter.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ToResponseModelConverter.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ValidateDictionaryYamlCommand.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/cli/core/Cli.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/cli/core/Command.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/cli/core/CommandException.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/cli/core/CommandResponse.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/cli/core/Console.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/rule/DictionaryValidate.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/rule/DictionaryValidateResponse.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlContentValidator.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java create mode 100644 dictionaryvalidation/src/main/java/org/onap/validation/yaml/util/Args.java create mode 100644 dictionaryvalidation/src/main/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand create mode 100644 dictionaryvalidation/src/main/resources/log4j2.properties create mode 100644 dictionaryvalidation/src/main/resources/open-cli-schema/dictionary-validate.yaml create mode 100644 dictionaryvalidation/src/test/java/org/onap/functional/DictionaryValidateRuleFunctionalTest.java create mode 100644 dictionaryvalidation/src/test/java/org/onap/functional/util/OnapCliWrapper.java create mode 100644 dictionaryvalidation/src/test/java/org/onap/functional/util/ValidationUtility.java create mode 100644 dictionaryvalidation/src/test/java/org/onap/validation/cli/MainCITest.java create mode 100644 dictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/OutputFilePathGeneratorTest.java create mode 100644 dictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/ToJsonConverterTest.java create mode 100644 dictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/ValidateYamlCommandTest.java create mode 100644 dictionaryvalidation/src/test/java/org/onap/validation/cli/core/CliTest.java create mode 100644 dictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlContentValidatorTest.java create mode 100644 dictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java create mode 100644 dictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java create mode 100644 dictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java create mode 100644 dictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java create mode 100644 dictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java create mode 100644 dictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java create mode 100644 dictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java create mode 100644 dictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java create mode 100644 dictionaryvalidation/src/test/java/org/onap/validation/yaml/util/ArgsTest.java create mode 100644 dictionaryvalidation/src/test/resources/Not_Yaml_File.txt create mode 100644 dictionaryvalidation/src/test/resources/yaml_schema/Custom_Invalid_Dictionary.yaml create mode 100644 dictionaryvalidation/src/test/resources/yaml_schema/Custom_Valid_Dictionary.yaml create mode 100644 dictionaryvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml create mode 100644 dictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml create mode 100644 dictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml create mode 100644 dictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml create mode 100644 dictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml create mode 100644 dictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml create mode 100644 dictionaryvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml create mode 100644 dictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml create mode 100644 dictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml delete mode 100644 pmdictionaryvalidation/README.md delete mode 100644 pmdictionaryvalidation/pom.xml delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/cli/Main.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/OutputFilePathGenerator.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ResponseModel.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ResponseStorage.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ToJsonConverter.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ToResponseModelConverter.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ValidatePmDictionaryYamlCommand.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/Cli.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/Command.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/CommandException.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/CommandResponse.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/Console.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/rule/PMDictionaryValidate.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/rule/PMDictionaryValidateResponse.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlContentValidator.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java delete mode 100644 pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/util/Args.java delete mode 100644 pmdictionaryvalidation/src/main/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand delete mode 100644 pmdictionaryvalidation/src/main/resources/log4j2.properties delete mode 100644 pmdictionaryvalidation/src/main/resources/open-cli-schema/pm-dictionary-validate.yaml delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/functional/PmDictionaryValidateRuleFunctionalTest.java delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/functional/util/OnapCliWrapper.java delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/functional/util/ValidationUtility.java delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/cli/MainCITest.java delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/OutputFilePathGeneratorTest.java delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/ToJsonConverterTest.java delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/ValidateYamlCommandTest.java delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/cli/core/CliTest.java delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlContentValidatorTest.java delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java delete mode 100644 pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/util/ArgsTest.java delete mode 100644 pmdictionaryvalidation/src/test/resources/Not_Yaml_File.txt delete mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml delete mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml delete mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml delete mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml delete mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml delete mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml delete mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml delete mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml delete mode 100644 pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml diff --git a/csarvalidation/pom.xml b/csarvalidation/pom.xml index 3ccc8eb..2f2fdda 100644 --- a/csarvalidation/pom.xml +++ b/csarvalidation/pom.xml @@ -105,7 +105,7 @@ org.onap.vnfsdk.validation - validation-pmdictionary + validation-dictionary ${project.version} diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745IntegrationTest.java index 17e9de3..39f7836 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745IntegrationTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745IntegrationTest.java @@ -139,7 +139,7 @@ public class VTPValidateCSARR816745IntegrationTest { // then List errors = testCase.getErrors(); assertThat(errors.size()).isEqualTo(1); - assertThat(convertToMessagesList(errors)).contains("Fail to load PM_Dictionary With error: PM_Dictionary YAML file is empty"); + assertThat(convertToMessagesList(errors)).contains("Fail to load PM_Dictionary With error: Dictionary YAML file is empty"); } @Test diff --git a/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java b/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java index 3e3877e..008b6d1 100644 --- a/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java +++ b/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java @@ -318,7 +318,7 @@ public class PnfValidationFunctionalTest { List expectedPnfDictionaryErrors = List.of( createExpectedError(PM_DICTIONARY_YAML_RULE, "0x2000", - "Fail to load PM_Dictionary With error: PM_Dictionary YAML file is empty", + "Fail to load PM_Dictionary With error: Dictionary YAML file is empty", "Artifacts/Deployment/Measurements/PM_Dictionary.yml" ) ); diff --git a/dictionaryvalidation/README.md b/dictionaryvalidation/README.md new file mode 100644 index 0000000..4e1a6f5 --- /dev/null +++ b/dictionaryvalidation/README.md @@ -0,0 +1,26 @@ +Dictionary Validation +======================= +This module can be used as a library to validate dictionary against the schema (schema is the first document in the file). + +How to use Dictionary validation library +------------------------------------------ +VNF-SDK validation library (dictionaryvalidation) should be used to validate the Dictionary file. + Below dependency should be added to the required modules in your project. + + + org.onap.vnfsdk.validation + validation-dictionary + version + + +How to validate Dictionary +-------------------------- +1.Validate Dictionary from a path to the file. + + new YamlContentValidator().validate(pathToFile) + +2.Validate Dictionary file from the byte array. + + new YamlContentValidator().validate(fileContentAsByteArray) + +Above methods return list of YamlDocumentValidationError(empty list for no errors) or throw YamlProcessingException/YAMLException when something goes wrong. diff --git a/dictionaryvalidation/pom.xml b/dictionaryvalidation/pom.xml new file mode 100644 index 0000000..07bf873 --- /dev/null +++ b/dictionaryvalidation/pom.xml @@ -0,0 +1,151 @@ + + + + org.onap.vnfsdk.validation + validation + 1.2.20-SNAPSHOT + + 4.0.0 + + validation-dictionary + jar + dictionaryvalidation/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/ + + + + 5.7.0 + 3.18.1 + 3.2.4 + 3.5.0 + 2.23.0 + 2.8.6 + + + + org.onap.cli + cli-framework + ${cli-framework.version} + + + commons-codec + commons-codec + + + + + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j-slf4j-impl.version} + + + org.slf4j + slf4j-ext + + + + + org.yaml + snakeyaml + ${snakeyaml.version} + + + com.google.code.gson + gson + ${gson.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 + + + org.mockito + mockito-core + ${mockito-core.version} + test + + + org.mockito + mockito-junit-jupiter + ${mockito-junit-jupiter.version} + test + + + org.onap.cli + cli-main + ${cli-main.version} + test + + + + ${project.artifactId}-${project.version} + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven-shade-plugin.version} + + + + package + + shade + + + true + standalone + true + + + *:* + + META-INF/DEPENDENCIES + META-INF/LICENSE + META-INF/NOTICE + + + + + + + org.onap.validation.cli.Main + + true + + + + + + + + + + diff --git a/dictionaryvalidation/src/main/java/org/onap/validation/cli/Main.java b/dictionaryvalidation/src/main/java/org/onap/validation/cli/Main.java new file mode 100644 index 0000000..ddeecbf --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/cli/Main.java @@ -0,0 +1,48 @@ +/* + * 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.cli; + +import org.onap.validation.cli.command.validate.ResponseStorage; +import org.onap.validation.cli.command.validate.ToJsonConverter; +import org.onap.validation.cli.command.validate.ValidateDictionaryYamlCommand; +import org.onap.validation.cli.core.Cli; +import org.onap.validation.cli.core.Console; +import org.onap.validation.yaml.util.Args; + +import java.util.List; + +public class Main { + + public static void main(String[] args) { + final Console console = new Console(); + final ResponseStorage storage = new ResponseStorage(); + + System.exit( + run(args, console, storage) + ); + } + + static int run(String[] args, Console console, ResponseStorage responseStorage) { + + Cli cli = new Cli<>(console, responseStorage); + + return cli.run( + new Args(List.of(args)), + new ValidateDictionaryYamlCommand(new ToJsonConverter()) + ); + } +} diff --git a/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/OutputFilePathGenerator.java b/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/OutputFilePathGenerator.java new file mode 100644 index 0000000..2ed7285 --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/OutputFilePathGenerator.java @@ -0,0 +1,41 @@ +/* + *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.cli.command.validate; + +import java.nio.file.Path; + +public class OutputFilePathGenerator { + + public static final int FILE_NAME_ABBREVIATION_INDEX = 0; + public static final String BY_PERIOD_REGEX = "\\."; + public static final String POST_FIX = "-validation-results.json"; + + public Path responsePathFor(Path filePath) { + final Path parent = filePath.getParent(); + final String fileNameAbbreviation = getFileNameAbbreviation(filePath); + return Path.of(parent.toString(), createFileName(fileNameAbbreviation)); + } + + private String createFileName(String fileNameAbbreviation) { + return fileNameAbbreviation + POST_FIX; + } + + private String getFileNameAbbreviation(Path filePath) { + final Path fileName = filePath.getFileName(); + return fileName.toString().split(BY_PERIOD_REGEX)[FILE_NAME_ABBREVIATION_INDEX]; + } +} diff --git a/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ResponseModel.java b/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ResponseModel.java new file mode 100644 index 0000000..033031d --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ResponseModel.java @@ -0,0 +1,51 @@ +/* + *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.cli.command.validate; + +import org.onap.validation.yaml.error.YamlDocumentValidationError; + +import java.util.Collections; +import java.util.List; + +public class ResponseModel { + + private final String file; + private final ResponseStatus status; + private final List errors; + + public ResponseModel(String file, ResponseStatus status, List errors) { + this.file = file; + this.status = status; + this.errors = errors; + } + + public String getFile() { + return file; + } + + public List getErrors() { + return Collections.unmodifiableList(errors); + } + + public ResponseStatus getStatus() { + return status; + } + + public enum ResponseStatus { + PASS, FAILED + } +} diff --git a/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ResponseStorage.java b/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ResponseStorage.java new file mode 100644 index 0000000..3daed16 --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ResponseStorage.java @@ -0,0 +1,30 @@ +/* + *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.cli.command.validate; + +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Path; + +public class ResponseStorage{ + + public void store(Path filePath, T response) throws IOException { + try (PrintWriter out = new PrintWriter(filePath.toFile())) { + out.println(response); + } + } +} diff --git a/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ToJsonConverter.java b/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ToJsonConverter.java new file mode 100644 index 0000000..168daf8 --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ToJsonConverter.java @@ -0,0 +1,28 @@ +/* + *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.cli.command.validate; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + + +public class ToJsonConverter { + public String convert(ResponseModel responseModel) { + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + return gson.toJson(responseModel); + } +} diff --git a/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ToResponseModelConverter.java b/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ToResponseModelConverter.java new file mode 100644 index 0000000..674068f --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ToResponseModelConverter.java @@ -0,0 +1,31 @@ +/* + *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.cli.command.validate; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public final class ToResponseModelConverter { + + private ToResponseModelConverter() { + } + + public static ResponseModel toModel(String json) { + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + return gson.fromJson(json, ResponseModel.class); + } +} diff --git a/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ValidateDictionaryYamlCommand.java b/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ValidateDictionaryYamlCommand.java new file mode 100644 index 0000000..68b0b7a --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ValidateDictionaryYamlCommand.java @@ -0,0 +1,92 @@ +/* + *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.cli.command.validate; + +import org.onap.validation.cli.core.Command; +import org.onap.validation.cli.core.CommandException; +import org.onap.validation.cli.core.CommandResponse; +import org.onap.validation.yaml.YamlContentValidator; +import org.onap.validation.yaml.error.YamlDocumentValidationError; +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.util.Args; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +public class ValidateDictionaryYamlCommand implements Command { + + public static final int PATH_TO_FILE_INDEX = 0; + private final YamlContentValidator yamlContentValidator = new YamlContentValidator(); + + private final ToJsonConverter toJsonConverter; + private final OutputFilePathGenerator filePathGenerator = new OutputFilePathGenerator(); + + public ValidateDictionaryYamlCommand(ToJsonConverter toJsonConverter) { + this.toJsonConverter = toJsonConverter; + } + + @Override + public CommandResponse execute(Args args) throws CommandException { + final String pathToFile = resolvePathToFile(args); + + try { + return validate(pathToFile); + } catch (YamlProcessingException e) { + throw new CommandException("Provided yaml file has invalid structure!", e); + } + } + + @Override + public String getName() { + return "Validate Dictionary yaml"; + } + + @Override + public Path getOutputFilePath(Args args) throws CommandException { + final String pathToFile = resolvePathToFile(args); + return this.filePathGenerator.responsePathFor(Path.of(pathToFile)); + } + + private CommandResponse validate(String pathToFile) throws YamlProcessingException { + final List errors = yamlContentValidator.validate(pathToFile); + return new CommandResponse<>( + toJsonConverter.convert(new ResponseModel(pathToFile, resolveResponseStatus(errors), errors)) + ,resolveCommandStatus(errors) + ); + } + + private ResponseModel.ResponseStatus resolveResponseStatus(List errors) { + return errors.isEmpty() ? ResponseModel.ResponseStatus.PASS : ResponseModel.ResponseStatus.FAILED; + } + + private CommandResponse.CommandStatus resolveCommandStatus(List errors) { + return errors.isEmpty() ? CommandResponse.CommandStatus.PASS : CommandResponse.CommandStatus.FAILED; + } + + private String resolvePathToFile(Args args) throws CommandException { + try { + final String pathToFile = args.getArg(PATH_TO_FILE_INDEX); + if (!Files.exists(Path.of(pathToFile))) { + throw new CommandException(String.format("File '%s' does not exist!", pathToFile)); + } + return pathToFile; + } catch (IllegalArgumentException ex) { + throw new CommandException("Command argument is missing: provide a path to file", ex); + } + } +} diff --git a/dictionaryvalidation/src/main/java/org/onap/validation/cli/core/Cli.java b/dictionaryvalidation/src/main/java/org/onap/validation/cli/core/Cli.java new file mode 100644 index 0000000..bf2abad --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/cli/core/Cli.java @@ -0,0 +1,85 @@ +/* + *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.cli.core; + +import org.onap.validation.cli.command.validate.ResponseStorage; +import org.onap.validation.cli.core.CommandResponse.CommandStatus; +import org.onap.validation.yaml.util.Args; + +import java.nio.file.Path; + +public class Cli { + + public static final int INTERNAL_ERROR_STATUS_CODE = 2; + public static final int FAILED_STATUS_CODE = 1; + public static final int PASS_STATUS_CODE = 0; + + public static final String APPLICATION_INTERNAL_ERROR_MSG = "\n# Application fails with internal error."; + public static final String APPLICATION_EXIT_SUCCESSFULLY_MSG = "\n# Application exits successfully."; + + private final Console console; + private final ResponseStorage responseStorage; + + public Cli(Console console, ResponseStorage responseStorage) { + this.console = console; + this.responseStorage = responseStorage; + } + + public int run(Args args, Command command) { + try { + final CommandResponse commandResponse = processCommand(args, command); + + logResultInfo(commandResponse.getResult()); + storeResult(args, command, commandResponse.getResult()); + + this.console.info(APPLICATION_EXIT_SUCCESSFULLY_MSG); + + return resolveCliStatusCodeFor(commandResponse); + } catch (Exception e) { + logException(e); + return INTERNAL_ERROR_STATUS_CODE; + } + } + + private int resolveCliStatusCodeFor(CommandResponse commandResponse) { + return commandResponse.getCommandStatus() == CommandStatus.PASS ? PASS_STATUS_CODE : FAILED_STATUS_CODE; + } + + private void logException(Exception e) { + this.console.error("# Command error: "); + this.console.error(e); + this.console.error(APPLICATION_INTERNAL_ERROR_MSG); + } + + private void storeResult(Args args, Command command, T result) throws CommandException, java.io.IOException { + final Path pathToFileWithResponse = command.getOutputFilePath(args); + this.responseStorage.store(pathToFileWithResponse, result); + this.console.info(String.format("%n# Result was stored in a file: '%s'", pathToFileWithResponse)); + } + + private void logResultInfo(T result) { + this.console.info("\n# Operation result:\n"); + this.console.info(result.toString()); + } + + private CommandResponse processCommand(Args args, Command command) throws CommandException { + this.console.info(String.format("# Executing a '%s' operation ...", command.getName())); + final CommandResponse commandResponse = command.execute(args); + this.console.info("# ... Done."); + return commandResponse; + } +} diff --git a/dictionaryvalidation/src/main/java/org/onap/validation/cli/core/Command.java b/dictionaryvalidation/src/main/java/org/onap/validation/cli/core/Command.java new file mode 100644 index 0000000..1da724f --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/cli/core/Command.java @@ -0,0 +1,29 @@ +/* + *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.cli.core; + +import org.onap.validation.yaml.util.Args; + +import java.nio.file.Path; + +public interface Command { + CommandResponse execute(Args args) throws CommandException; + + String getName(); + + Path getOutputFilePath(Args args) throws CommandException; +} diff --git a/dictionaryvalidation/src/main/java/org/onap/validation/cli/core/CommandException.java b/dictionaryvalidation/src/main/java/org/onap/validation/cli/core/CommandException.java new file mode 100644 index 0000000..2c72ff8 --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/cli/core/CommandException.java @@ -0,0 +1,27 @@ +/* + *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.cli.core; + +public class CommandException extends Exception { + public CommandException(String msg) { + super(msg); + } + + public CommandException(String msg, Exception ex) { + super(msg, ex); + } +} diff --git a/dictionaryvalidation/src/main/java/org/onap/validation/cli/core/CommandResponse.java b/dictionaryvalidation/src/main/java/org/onap/validation/cli/core/CommandResponse.java new file mode 100644 index 0000000..73db4ab --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/cli/core/CommandResponse.java @@ -0,0 +1,48 @@ +/* + *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.cli.core; + +public class CommandResponse { + + private final T result; + private final CommandStatus commandStatus; + + public CommandResponse(T result, CommandStatus commandStatus) { + this.result = result; + this.commandStatus = commandStatus; + } + + public T getResult() { + return result; + } + + public CommandStatus getCommandStatus() { + return commandStatus; + } + + public enum CommandStatus { + PASS, FAILED + } + + @Override + public String toString() { + return "CommandResponse{" + + "result=" + result + + ", commandStatus=" + commandStatus + + '}'; + } +} diff --git a/dictionaryvalidation/src/main/java/org/onap/validation/cli/core/Console.java b/dictionaryvalidation/src/main/java/org/onap/validation/cli/core/Console.java new file mode 100644 index 0000000..4c20437 --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/cli/core/Console.java @@ -0,0 +1,41 @@ +/* + *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.cli.core; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Console { + + public static final Logger logger = LoggerFactory.getLogger(Console.class); + + public void info(String msg) { + System.out.println(msg); + logger.info(msg); + } + + public void error(Exception ex) { + System.err.println(ex.getMessage() + ", more information in log file."); + logger.error("Internal error", ex); + } + + public void error(String msg) { + System.err.println(msg); + logger.error(msg); + } + +} diff --git a/dictionaryvalidation/src/main/java/org/onap/validation/rule/DictionaryValidate.java b/dictionaryvalidation/src/main/java/org/onap/validation/rule/DictionaryValidate.java new file mode 100644 index 0000000..c3b96b4 --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/rule/DictionaryValidate.java @@ -0,0 +1,120 @@ +/* + * Copyright 2019 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.rule; + +import com.google.gson.Gson; +import org.onap.cli.fw.cmd.OnapCommand; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.output.OnapCommandResultType; +import org.onap.cli.fw.schema.OnapCommandSchema; +import org.onap.validation.cli.command.validate.ResponseModel; +import org.onap.validation.cli.command.validate.ResponseModel.ResponseStatus; +import org.onap.validation.cli.command.validate.ToJsonConverter; +import org.onap.validation.cli.command.validate.ToResponseModelConverter; +import org.onap.validation.cli.command.validate.ValidateDictionaryYamlCommand; +import org.onap.validation.cli.core.CommandException; +import org.onap.validation.cli.core.CommandResponse; +import org.onap.validation.yaml.util.Args; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; +import java.util.List; + +/** + * Validates CSAR + */ +@OnapCommandSchema(schema = "dictionary-validate.yaml") +public class DictionaryValidate extends OnapCommand { + + private static final String VALIDATION_PASS = "PASS"; + private static final String VALIDATION_FAILED = "FAILED"; + public static final String PARAM_IN_YAML = "yaml"; + public static final String PARAM_OUT_FILE = "file"; + public static final String PARAM_OUT_DATE = "date"; + public static final String PARAM_OUT_CRITERIA = "criteria"; + public static final String PARAM_OUT_ERRORS = "errors"; + private final Gson gson = new Gson(); + + private static final Logger logger = LoggerFactory.getLogger(DictionaryValidate.class); + + @Override + protected void run() throws OnapCommandException { + + final Date timestamp = new Date(); + final String yamlPath = (String) getParametersMap().get(PARAM_IN_YAML).getValue(); + + try { + final ResponseModel responseModel = executeValidation(yamlPath); + handleResponse(responseModel, timestamp); + } catch (CommandException e) { + handleError(timestamp, yamlPath, e); + } + } + + private void handleResponse(ResponseModel responseModel, Date timestamp) { + setOclipResponse(responseModel.getFile(), + timestamp, + getCriteria(responseModel), + transformToJson(responseModel.getErrors()) + ); + } + + private void handleError(Date validationTimestamp, String path, CommandException e) { + setOclipResponse(path, + validationTimestamp, + VALIDATION_FAILED, + transformToJson(e.getMessage()) + ); + logger.error("Internal application error", e); + } + + private String getCriteria(ResponseModel responseModel) { + return responseModel.getStatus().equals(ResponseStatus.PASS) ? VALIDATION_PASS : VALIDATION_FAILED; + } + + private String transformToJson(T data) { + return gson.toJson(data); + } + + private void setOclipResponse(String pathToFile, Date timestamp, String criteria, String errors) { + final DictionaryValidateResponse dictionaryValidateResponse = new DictionaryValidateResponse( + pathToFile, + timestamp.toString(), + criteria, + errors + ); + setOclipResponse(dictionaryValidateResponse); + } + + private void setOclipResponse(DictionaryValidateResponse dictionaryValidateResponse) { + this.getResult().getRecordsMap().get(PARAM_OUT_FILE).getValues().add(dictionaryValidateResponse.getFile()); + this.getResult().getRecordsMap().get(PARAM_OUT_DATE).getValues().add(dictionaryValidateResponse.getDate()); + this.getResult().getRecordsMap().get(PARAM_OUT_CRITERIA).getValues().add(dictionaryValidateResponse.getCriteria()); + this.getResult().getRecordsMap().get(PARAM_OUT_ERRORS).getValues().add(dictionaryValidateResponse.getErrors()); + this.getResult().setOutput(transformToJson(dictionaryValidateResponse)); + this.getResult().setType(OnapCommandResultType.TEXT); + } + + private ResponseModel executeValidation(String path) throws CommandException { + final ValidateDictionaryYamlCommand validation = new ValidateDictionaryYamlCommand(new ToJsonConverter()); + final CommandResponse commandResponse = validation.execute(new Args(List.of(path))); + final String result = commandResponse.getResult(); + + return ToResponseModelConverter.toModel(result); + } +} diff --git a/dictionaryvalidation/src/main/java/org/onap/validation/rule/DictionaryValidateResponse.java b/dictionaryvalidation/src/main/java/org/onap/validation/rule/DictionaryValidateResponse.java new file mode 100644 index 0000000..684cf7b --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/rule/DictionaryValidateResponse.java @@ -0,0 +1,57 @@ +/* + * Copyright 2019 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.rule; + +public class DictionaryValidateResponse { + + public static final String PLATFORM_VTP_1_0 = "Dictionary Test Platform (VTP) 1.0"; + public static final String ONAP_DISCUSS_LISTS_ONAP_ORG = "ONAP VTP Team onap-discuss@lists.onap.org"; + private final String file; + private final String date; + private final String criteria; + private final String errors; + + public DictionaryValidateResponse(String file, String date, String criteria, String errors) { + this.file = file; + this.date = date; + this.criteria = criteria; + this.errors = errors; + } + + public String getFile() { + return file; + } + + public String getDate() { + return date; + } + + public String getContact() { + return ONAP_DISCUSS_LISTS_ONAP_ORG; + } + + public String getPlatform() { + return PLATFORM_VTP_1_0; + } + + public String getCriteria() { + return criteria; + } + + public String getErrors() { + return errors; + } +} diff --git a/dictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlContentValidator.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlContentValidator.java new file mode 100644 index 0000000..4501113 --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlContentValidator.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; + +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.model.YamlDocumentFactory; +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 YamlContentValidator { + + private static final int FIRST_DOCUMENT_INDEX = 1; + private static final YamlLoader YAML_LOADER = new YamlLoader(new YamlDocumentFactory()); + + public List validate(String pathToFile) + throws YamlProcessingException { + List documents = YAML_LOADER.loadMultiDocumentYamlFile(pathToFile); + return getYamlDocumentValidationErrors(documents); + } + + public List validate(byte[] yamlWithSchema) + throws YamlProcessingException { + List documents = YAML_LOADER.loadMultiDocumentYaml(yamlWithSchema); + return getYamlDocumentValidationErrors(documents); + } + + private List getYamlDocumentValidationErrors(List documents) throws YamlProcessingException { + if (documents.isEmpty()) { + throw new YamlProcessingException("Dictionary YAML file is empty"); + } else { + return validateDocuments(documents); + } + } + + 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/dictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java new file mode 100644 index 0000000..c23da0a --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java @@ -0,0 +1,82 @@ +/* + * 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.ByteArrayInputStream; +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); + private final YamlDocumentFactory documentFactory; + + YamlLoader(YamlDocumentFactory documentFactory) { + this.documentFactory = documentFactory; + } + + List loadMultiDocumentYaml(byte[] yamlWithSchema) + throws YamlDocumentFactory.YamlDocumentParsingException { + List documents = new ArrayList<>(); + try (InputStream yamlStream = new ByteArrayInputStream(yamlWithSchema)) { + documents.addAll(loadMultiDocumentYaml(yamlStream)); + } catch (IOException e) { + LOGGER.error("Failed to load multi document YAML", e); + } + return documents; + } + + List loadMultiDocumentYamlFile(URL path) + throws YamlDocumentFactory.YamlDocumentParsingException { + List documents = new ArrayList<>(); + try (InputStream yamlStream = path.openStream()) { + documents.addAll(loadMultiDocumentYaml(yamlStream)); + } catch (IOException e) { + LOGGER.error("Failed to load multi document YAML file", e); + } + return documents; + } + + 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); + } + } + + private List loadMultiDocumentYaml(InputStream yamlStream) throws YamlDocumentFactory.YamlDocumentParsingException { + List documents = new ArrayList<>(); + for (Object yamlDocument : new Yaml().loadAll(yamlStream)) { + documents.add(documentFactory.createYamlDocument(yamlDocument)); + } + return documents; + } +} diff --git a/dictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java new file mode 100644 index 0000000..30ba646 --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java new file mode 100644 index 0000000..6ffe6d4 --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java new file mode 100644 index 0000000..f04708f --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java new file mode 100644 index 0000000..99c2437 --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java new file mode 100644 index 0000000..557b6fd --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java new file mode 100644 index 0000000..b56422c --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java new file mode 100644 index 0000000..5f41c5c --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java new file mode 100644 index 0000000..2b93c74 --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java new file mode 100644 index 0000000..ebd37ce --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java new file mode 100644 index 0000000..eb5ab8e --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java new file mode 100644 index 0000000..69bb6cd --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java new file mode 100644 index 0000000..df7d673 --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java new file mode 100644 index 0000000..a3e9636 --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java @@ -0,0 +1,78 @@ +/* + * 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; + +public class YamlSchemaBranchNode extends YamlSchemaNode { + + private final YamlDocument nextNodesInLazyForm; + private List nextNodes = Collections.emptyList(); + + YamlSchemaBranchNode(String name, String path, boolean required, String comment, + YamlDocument nextNodesInLazyForm) { + super(name, path, required, comment); + this.nextNodesInLazyForm = nextNodesInLazyForm; + } + + @Override + public boolean isContainingSubStructure() { + return true; + } + + @Override + public List getAcceptedValues() { + return Collections.emptyList(); + } + + @Override + public synchronized List getNextNodes() throws YamlSchemaProcessingException { + try { + return nextNodes.isEmpty() ? this.loadNextNodes() : nextNodes; + } 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 = 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/dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java new file mode 100644 index 0000000..c98f41e --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java new file mode 100644 index 0000000..28913a2 --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java new file mode 100644 index 0000000..79a8f14 --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/main/java/org/onap/validation/yaml/util/Args.java b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/util/Args.java new file mode 100644 index 0000000..9ae44c8 --- /dev/null +++ b/dictionaryvalidation/src/main/java/org/onap/validation/yaml/util/Args.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.util; + +import java.util.ArrayList; +import java.util.List; + +public class Args { + + private final List data; + + public Args(List data) { + this.data = new ArrayList<>(data); + } + + public String getArg(int index) { + if (this.data.size() <= index) { + throw new IllegalArgumentException(String.format("Argument with index %d is not available!", index)); + } + return this.data.get(index); + } +} diff --git a/dictionaryvalidation/src/main/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand b/dictionaryvalidation/src/main/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand new file mode 100644 index 0000000..9d1b8a2 --- /dev/null +++ b/dictionaryvalidation/src/main/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand @@ -0,0 +1,15 @@ +# 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. + +org.onap.validation.rule.DictionaryValidate diff --git a/dictionaryvalidation/src/main/resources/log4j2.properties b/dictionaryvalidation/src/main/resources/log4j2.properties new file mode 100644 index 0000000..8ef4de1 --- /dev/null +++ b/dictionaryvalidation/src/main/resources/log4j2.properties @@ -0,0 +1,56 @@ +# Copyright Nokia 2020 +# +# 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 + + +status = error +dest = err +name = PropertiesConfig + +property.filename = ./dictionary-validate.log + +filter.threshold.type = ThresholdFilter +filter.threshold.level = debug + +appender.console.type = Console +appender.console.name = STDOUT +appender.console.layout.type = PatternLayout +appender.console.layout.pattern = %m%n +appender.console.filter.threshold.type = ThresholdFilter +appender.console.filter.threshold.level = error + +appender.rolling.type = RollingFile +appender.rolling.name = RollingFile +appender.rolling.fileName = ${filename} +appender.rolling.filePattern = ./dictionary-validate.%d{yyyy-MM-dd-HH:mm:ss}.log +appender.rolling.layout.type = PatternLayout +appender.rolling.layout.pattern = %d %p %C{1.} [%t] %m%n +appender.rolling.policies.type = Policies +appender.rolling.policies.time.type = TimeBasedTriggeringPolicy +appender.rolling.policies.time.interval = 2 +appender.rolling.policies.time.modulate = true +appender.rolling.policies.size.type = SizeBasedTriggeringPolicy +appender.rolling.policies.size.size=5MB +appender.rolling.strategy.type = DefaultRolloverStrategy +appender.rolling.strategy.max = 5 + +logger.rolling.name = org.onap.validation +logger.rolling.level = debug +logger.rolling.additivity = false +logger.rolling.appenderRef.rolling.ref = RollingFile + +rootLogger.level = info +rootLogger.appenderRef.stdout.ref = STDOUT diff --git a/dictionaryvalidation/src/main/resources/open-cli-schema/dictionary-validate.yaml b/dictionaryvalidation/src/main/resources/open-cli-schema/dictionary-validate.yaml new file mode 100644 index 0000000..1f5801d --- /dev/null +++ b/dictionaryvalidation/src/main/resources/open-cli-schema/dictionary-validate.yaml @@ -0,0 +1,63 @@ +# 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. + +open_cli_schema_version: 1.0 + +name: dictionary-validate + +description: Validate Dictionary Yaml file + +info: + product: onap-honolulu + version: 1.0 + service: vnf-compliance + author: ONAP VTP Team onap-discuss@lists.onap.org + +parameters: + - name: yaml + description: Yaml file path + long_option: yaml + short_option: b + type: binary + is_optional: false + +results: + direction: portrait + attributes: + - name: file + description: Dictionary Yaml file + scope: short + type: string + - name: date + description: Validation date + scope: short + type: string + - name: platform + description: Platform used to test the reqs + scope: short + type: string + default_value: Dictionary Test Platform (VTP) 1.0 + - name: contact + description: Owner for this test case + scope: short + type: string + default_value: ONAP VTP Team onap-discuss@lists.onap.org + - name: criteria + description: Overall test reqs passed? PASS or FAILED + scope: short + type: string + - name: errors + description: All test cases errors + scope: short + type: json diff --git a/dictionaryvalidation/src/test/java/org/onap/functional/DictionaryValidateRuleFunctionalTest.java b/dictionaryvalidation/src/test/java/org/onap/functional/DictionaryValidateRuleFunctionalTest.java new file mode 100644 index 0000000..2d2c542 --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/functional/DictionaryValidateRuleFunctionalTest.java @@ -0,0 +1,178 @@ +/* + * 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.functional; + +import org.junit.Test; +import org.onap.functional.util.OnapCliWrapper; +import org.onap.validation.rule.DictionaryValidate; +import org.onap.validation.rule.DictionaryValidateResponse; + +import java.net.URISyntaxException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.onap.functional.util.ValidationUtility.OPERATION_STATUS_FAILED; +import static org.onap.functional.util.ValidationUtility.OPERATION_STATUS_PASS; +import static org.onap.functional.util.ValidationUtility.getCliCommandValidationResult; +import static org.onap.functional.util.ValidationUtility.verifyThatOperationFinishedWithError; +import static org.onap.functional.util.ValidationUtility.verifyThatOperationFinishedWithoutAnyError; + + +public class DictionaryValidateRuleFunctionalTest { + + + private static final String YAML_SCHEMA_SIMPLE_VALID_SCHEMA_YAML = "yaml_schema/Simple_Valid_Schema.yaml"; + private static final String YAML_CUSTOM_SCHEMA_SIMPLE_VALID_SCHEMA_YAML = "yaml_schema/Custom_Valid_Dictionary.yaml"; + private static final String YAML_CUSTOM_SCHEMA_SIMPLE_INVALID_SCHEMA_YAML = "yaml_schema/Custom_Invalid_Dictionary.yaml"; + private static final String NO_ERRORS = "[]"; + private static final String YAML_SCHEMA_PM_DICTIONARY_YAML = "yaml_schema/PM_Dictionary.yaml"; + private static final String PATH_TO_NON_EXITING_FILE_YAML = "path/to/nonExitingFile.yaml"; + private static final String NOT_YAML_FILE_TXT = "Not_Yaml_File.txt"; + + @Test + public void shouldSuccessfullyValidatePMDictionaryYamlFile() throws URISyntaxException { + // given + OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo(YAML_SCHEMA_SIMPLE_VALID_SCHEMA_YAML)); + + // when + cli.handle(); + + // then + final DictionaryValidateResponse result = getCliCommandValidationResult(cli, DictionaryValidateResponse.class); + + assertThat(result.getFile()).contains(YAML_SCHEMA_SIMPLE_VALID_SCHEMA_YAML); + assertThat(result.getPlatform()).contains(DictionaryValidateResponse.PLATFORM_VTP_1_0); + assertThat(result.getContact()).contains(DictionaryValidateResponse.ONAP_DISCUSS_LISTS_ONAP_ORG); + assertThat(result.getCriteria()).isEqualTo(OPERATION_STATUS_PASS); + assertThat(result.getErrors()).isEqualTo(NO_ERRORS); + verifyThatOperationFinishedWithoutAnyError(cli); + } + + @Test + public void shouldSuccessfullyValidateCustomDictionaryYamlFile() throws URISyntaxException { + // given + OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo(YAML_CUSTOM_SCHEMA_SIMPLE_VALID_SCHEMA_YAML)); + + // when + cli.handle(); + + // then + final DictionaryValidateResponse result = getCliCommandValidationResult(cli, DictionaryValidateResponse.class); + + assertThat(result.getFile()).contains(YAML_CUSTOM_SCHEMA_SIMPLE_VALID_SCHEMA_YAML); + assertThat(result.getPlatform()).contains(DictionaryValidateResponse.PLATFORM_VTP_1_0); + assertThat(result.getContact()).contains(DictionaryValidateResponse.ONAP_DISCUSS_LISTS_ONAP_ORG); + assertThat(result.getCriteria()).isEqualTo(OPERATION_STATUS_PASS); + verifyThatOperationFinishedWithoutAnyError(cli); + } + + @Test + public void shouldFailWhileValidatingCustomDictionaryYamlFileWithEerror() throws URISyntaxException { + // given + OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo(YAML_CUSTOM_SCHEMA_SIMPLE_INVALID_SCHEMA_YAML)); + + // when + cli.handle(); + + // then + final DictionaryValidateResponse result = getCliCommandValidationResult(cli, DictionaryValidateResponse.class); + + assertThat(result.getFile()).contains(YAML_CUSTOM_SCHEMA_SIMPLE_INVALID_SCHEMA_YAML); + assertThat(result.getPlatform()).contains(DictionaryValidateResponse.PLATFORM_VTP_1_0); + assertThat(result.getContact()).contains(DictionaryValidateResponse.ONAP_DISCUSS_LISTS_ONAP_ORG); + assertThat(result.getCriteria()).isEqualTo(OPERATION_STATUS_FAILED); + final String errors = result.getErrors(); + assertThat(errors).contains( + "Value(s) is/are not in array of accepted values.", + "accepted value(s): [X, Y, Z]", + "accepted value(s): [3, 30, 33]", + "Key not found: field2" + ); + verifyThatOperationFinishedWithoutAnyError(cli); + } + + @Test + public void shouldFailsWhenPMDictionaryYamlFileHasSomeErrors() throws URISyntaxException { + // given + OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo(YAML_SCHEMA_PM_DICTIONARY_YAML)); + + // when + cli.handle(); + + // then + final DictionaryValidateResponse result = getCliCommandValidationResult(cli, DictionaryValidateResponse.class); + + assertThat(result.getFile()).contains(YAML_SCHEMA_PM_DICTIONARY_YAML); + assertThat(result.getPlatform()).contains(DictionaryValidateResponse.PLATFORM_VTP_1_0); + assertThat(result.getContact()).contains(DictionaryValidateResponse.ONAP_DISCUSS_LISTS_ONAP_ORG); + assertThat(result.getCriteria()).isEqualTo(OPERATION_STATUS_FAILED); + final String errors = result.getErrors(); + assertThat(errors).contains( + "Value(s) is/are not in array of accepted values.", + "accepted value(s): [float, uint32, uint64]", + "Key not found: measChangeType", + "accepted value(s): [X, Y, Z]" + ); + verifyThatOperationFinishedWithoutAnyError(cli); + } + + @Test + public void shouldReportAnErrorWhenYamlFileDoesNotExist() { + // given + OnapCliWrapper cli = new OnapCliWrapper(new String[]{PATH_TO_NON_EXITING_FILE_YAML}); + + // when + cli.handle(); + + verifyThatOperationFinishedWithError(cli); + } + + + @Test + public void shouldReportThatValidationFailedWithInternalError() throws URISyntaxException { + // given + OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo(NOT_YAML_FILE_TXT)); + + // when + cli.handle(); + + // then + final DictionaryValidateResponse result = getCliCommandValidationResult(cli, DictionaryValidateResponse.class); + + assertThat(result.getFile()).contains(NOT_YAML_FILE_TXT); + assertThat(result.getPlatform()).contains(DictionaryValidateResponse.PLATFORM_VTP_1_0); + assertThat(result.getContact()).contains(DictionaryValidateResponse.ONAP_DISCUSS_LISTS_ONAP_ORG); + assertThat(result.getCriteria()).isEqualTo(OPERATION_STATUS_FAILED); + assertThat(result.getErrors()).contains("Provided yaml file has invalid structure!"); + verifyThatOperationFinishedWithoutAnyError(cli); + } + + + private String[] createPnfValidationRequestInfo(String yamlPath) throws URISyntaxException { + return new String[]{ + "--product", "onap-honolulu", + "dictionary-validate", + "--format", "json", + "--yaml", absoluteFilePath(yamlPath) + }; + } + + + public static String absoluteFilePath(String relativeFilePath) throws URISyntaxException { + return DictionaryValidate.class.getClassLoader().getResource(relativeFilePath) + .toURI().getPath(); + } +} diff --git a/dictionaryvalidation/src/test/java/org/onap/functional/util/OnapCliWrapper.java b/dictionaryvalidation/src/test/java/org/onap/functional/util/OnapCliWrapper.java new file mode 100644 index 0000000..347a7bb --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/functional/util/OnapCliWrapper.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.functional.util; + + +import org.onap.cli.fw.cmd.OnapCommand; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.output.OnapCommandResult; +import org.onap.cli.main.OnapCli; + +public class OnapCliWrapper extends OnapCli { + + private OnapCommandResult commandResult; + + public OnapCliWrapper(String[] args) { + super(args); + } + + @Override + public void handleTracking(OnapCommand cmd) throws OnapCommandException { + super.handleTracking(cmd); + this.commandResult = cmd.getResult(); + } + + public OnapCommandResult getCommandResult() { + return this.commandResult; + } +} diff --git a/dictionaryvalidation/src/test/java/org/onap/functional/util/ValidationUtility.java b/dictionaryvalidation/src/test/java/org/onap/functional/util/ValidationUtility.java new file mode 100644 index 0000000..3a497f4 --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/functional/util/ValidationUtility.java @@ -0,0 +1,49 @@ +/* + * 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.functional.util; + +import com.google.gson.Gson; +import org.onap.cli.fw.output.OnapCommandResult; + + +import static org.assertj.core.api.Assertions.assertThat; + + +public final class ValidationUtility { + + private static final int NO_ERROR_CODE = 0; + public static final int ERROR_CODE = 1; + + private ValidationUtility(){} + + public static final String OPERATION_STATUS_PASS = "PASS"; + public static final String OPERATION_STATUS_FAILED = "FAILED"; + + public static T getCliCommandValidationResult(OnapCliWrapper cli, Class clazz) { + final OnapCommandResult onapCommandResult = cli.getCommandResult(); + final String json = onapCommandResult.getOutput().toString(); + return new Gson().fromJson(json, clazz); + } + + public static void verifyThatOperationFinishedWithoutAnyError(OnapCliWrapper cli) { + assertThat(cli.getExitCode()).isEqualTo(NO_ERROR_CODE); + } + + public static void verifyThatOperationFinishedWithError(OnapCliWrapper cli) { + assertThat(cli.getExitCode()).isEqualTo(ERROR_CODE); + } +} diff --git a/dictionaryvalidation/src/test/java/org/onap/validation/cli/MainCITest.java b/dictionaryvalidation/src/test/java/org/onap/validation/cli/MainCITest.java new file mode 100644 index 0000000..307d388 --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/validation/cli/MainCITest.java @@ -0,0 +1,144 @@ +/* + *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.cli; + + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.validation.cli.command.validate.OutputFilePathGenerator; +import org.onap.validation.cli.command.validate.ResponseModel; +import org.onap.validation.cli.command.validate.ResponseStorage; +import org.onap.validation.cli.core.Cli; +import org.onap.validation.cli.core.CommandException; +import org.onap.validation.cli.core.Console; +import org.onap.validation.cli.command.validate.ToResponseModelConverter; +import org.onap.validation.yaml.YamlLoadingUtils; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +@ExtendWith(MockitoExtension.class) +class MainCITest { + + public static final int JSON_RESPONSE_INDEX = 3; + public static final int OPERATION_INFO_MSG_INDEX = 5; + public static final int NO_ERROR = 0; + @Mock + private Console console; + @Mock + private ResponseStorage responseStorage; + private final OutputFilePathGenerator filePathGenerator = new OutputFilePathGenerator(); + + @Test + void shouldReportThatPathToFileWasNotProvided() { + // when + final int statusCode = Main.run(new String[0], console, responseStorage); + + // then + assertThat(statusCode).isEqualTo(Cli.INTERNAL_ERROR_STATUS_CODE); + final ArgumentCaptor exceptionCaptor = ArgumentCaptor.forClass(CommandException.class); + verify(console).error(exceptionCaptor.capture()); + verify(console).error(Cli.APPLICATION_INTERNAL_ERROR_MSG); + assertThat(exceptionCaptor.getValue().getMessage()).isEqualTo("Command argument is missing: provide a path to file"); + + } + + @Test + void shouldReportThatFileDoseNotExist() throws IOException { + // when + final String pathToYaml = "/path/to/nonExisting.yaml"; + final int statusCode = Main.run(new String[]{pathToYaml}, console, new ResponseStorage()); + + // then + assertThat(statusCode).isEqualTo(Cli.INTERNAL_ERROR_STATUS_CODE); + final ArgumentCaptor exceptionCaptor = ArgumentCaptor.forClass(CommandException.class); + verify(console).error(exceptionCaptor.capture()); + verify(console).error(Cli.APPLICATION_INTERNAL_ERROR_MSG); + assertThat(exceptionCaptor.getValue().getMessage()).isEqualTo("File '/path/to/nonExisting.yaml' does not exist!"); + verify(responseStorage, never()).store(eq(Path.of(pathToYaml)), anyString()); + } + + @Test + void shouldReportThatFileIsBroken() throws IOException { + // when + final String pathToFile = YamlLoadingUtils.getUrlForGivenPath("Not_Yaml_File.txt").getPath(); + final int statusCode = Main.run(new String[]{pathToFile}, console, new ResponseStorage()); + + // then + assertThat(statusCode).isEqualTo(Cli.INTERNAL_ERROR_STATUS_CODE); + final ArgumentCaptor exceptionCaptor = ArgumentCaptor.forClass(CommandException.class); + verify(console).error(exceptionCaptor.capture()); + verify(console).error(Cli.APPLICATION_INTERNAL_ERROR_MSG); + assertThat(exceptionCaptor.getValue().getMessage()).isEqualTo("Provided yaml file has invalid structure!"); + verify(responseStorage, never()).store(eq(Path.of(pathToFile)), anyString()); + } + + @Test + void shouldValidateProperYamlFile() throws IOException { + // when + final String path = YamlLoadingUtils.getUrlForGivenPath(YamlLoadingUtils.PATH_TO_SIMPLE_VALID_SCHEMA).getPath(); + final int statusCode = Main.run(new String[]{path}, console, responseStorage); + + // then + assertThat(statusCode).isEqualTo(Cli.PASS_STATUS_CODE); + assertThatResponseWasLoggedAtConsole( + path, + ResponseModel.ResponseStatus.PASS, + NO_ERROR + ); + } + + @Test + void shouldValidateYamlWithErrors() throws IOException { + // when + final String path = YamlLoadingUtils.getUrlForGivenPath(YamlLoadingUtils.PATH_TO_YAML_WITH_WRONG_VALUES).getPath(); + final int statusCode = Main.run(new String[]{path}, console, responseStorage); + + // then + assertThat(statusCode).isEqualTo(Cli.FAILED_STATUS_CODE); + assertThatResponseWasLoggedAtConsole( + path, + ResponseModel.ResponseStatus.FAILED, + 4 + ); + } + + private void assertThatResponseWasLoggedAtConsole(String pathToFile, ResponseModel.ResponseStatus responseStatus, int expectedErrors) throws IOException { + ArgumentCaptor consoleInfoCaptor = ArgumentCaptor.forClass(String.class); + verify(console, times(6)).info(consoleInfoCaptor.capture()); + final List allValues = consoleInfoCaptor.getAllValues(); + final String json = allValues.get(JSON_RESPONSE_INDEX); + final ResponseModel responseModel = ToResponseModelConverter.toModel(json); + assertThat(responseModel.getFile()).isEqualTo(pathToFile); + assertThat(responseModel.getStatus()).isEqualTo(responseStatus); + assertThat(responseModel.getErrors()).hasSize(expectedErrors); + assertThat(consoleInfoCaptor.getAllValues().get(OPERATION_INFO_MSG_INDEX)).isEqualTo(Cli.APPLICATION_EXIT_SUCCESSFULLY_MSG); + verify(responseStorage).store(eq(filePathGenerator.responsePathFor(Path.of(pathToFile))), eq(json)); + } + +} diff --git a/dictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/OutputFilePathGeneratorTest.java b/dictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/OutputFilePathGeneratorTest.java new file mode 100644 index 0000000..b4d68b4 --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/OutputFilePathGeneratorTest.java @@ -0,0 +1,43 @@ +/* + *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.cli.command.validate; + +import org.junit.jupiter.api.Test; + +import java.nio.file.Path; + +import static org.assertj.core.api.Assertions.assertThat; + + +class OutputFilePathGeneratorTest { + + private final OutputFilePathGenerator filePathGenerator = new OutputFilePathGenerator(); + + @Test + void shouldReturnPathToFileWithResponse() { + // given + final Path pathToYaml = Path.of("/some/path/PMDictionary.yaml"); + final Path expected = Path.of("/some/path/PMDictionary-validation-results.json"); + + // when + final Path actual = filePathGenerator.responsePathFor(pathToYaml); + + // then + assertThat(actual).isEqualTo(expected); + } + +} diff --git a/dictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/ToJsonConverterTest.java b/dictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/ToJsonConverterTest.java new file mode 100644 index 0000000..06a15bb --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/ToJsonConverterTest.java @@ -0,0 +1,70 @@ +/* + *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.cli.command.validate; + +import org.junit.jupiter.api.Test; +import org.onap.validation.yaml.error.YamlDocumentValidationError; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.onap.validation.cli.command.validate.ToResponseModelConverter.toModel; + + +class ToJsonConverterTest { + + private static final String PATH_TO_TEST_YAML = "/path/to/test.yaml"; + private final ToJsonConverter toJsonConverter = new ToJsonConverter(); + + @Test + void shouldConvertEmptyArray() { + // given + final ResponseModel responseModel = new ResponseModel(PATH_TO_TEST_YAML, + ResponseModel.ResponseStatus.PASS, + List.of()); + + // when + String json = toJsonConverter.convert(responseModel); + + // then + ResponseModel actual = toModel(json); + assertThat(actual.getFile()).isEqualTo(PATH_TO_TEST_YAML); + assertThat(actual.getStatus()).isEqualTo(ResponseModel.ResponseStatus.PASS); + assertThat(actual.getErrors()).isEmpty(); + } + + + @Test + void shouldConvertListOfErrors() { + // given + final ResponseModel responseModel = new ResponseModel(PATH_TO_TEST_YAML, + ResponseModel.ResponseStatus.FAILED, + List.of( + new YamlDocumentValidationError(1, PATH_TO_TEST_YAML, "error1"), + new YamlDocumentValidationError(2, PATH_TO_TEST_YAML, "error2"))); + + // when + String json = toJsonConverter.convert(responseModel); + + // then + + ResponseModel actual = toModel(json); + assertThat(actual.getFile()).isEqualTo(PATH_TO_TEST_YAML); + assertThat(actual.getStatus()).isEqualTo(ResponseModel.ResponseStatus.FAILED); + assertThat(actual.getErrors()).hasSize(2); + } +} diff --git a/dictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/ValidateYamlCommandTest.java b/dictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/ValidateYamlCommandTest.java new file mode 100644 index 0000000..9d651ad --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/ValidateYamlCommandTest.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.cli.command.validate; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.validation.cli.core.CommandException; +import org.onap.validation.cli.core.CommandResponse; +import org.onap.validation.yaml.YamlLoadingUtils; +import org.onap.validation.yaml.util.Args; + +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.cli.command.validate.ToResponseModelConverter.toModel; + +@ExtendWith(MockitoExtension.class) +class ValidateYamlCommandTest { + + private final ToJsonConverter toJsonConverter = new ToJsonConverter(); + private ValidateDictionaryYamlCommand validateYamlCommand; + + @BeforeEach + void setUp() { + this.validateYamlCommand = new ValidateDictionaryYamlCommand(toJsonConverter); + } + + @Test + void shouldReportAnErrorWhenFileDoesNotExist() { + // given + Args args = new Args(List.of("/invalid/filePath/toValidate.yaml")); + + // when + assertThatThrownBy(() -> validateYamlCommand.execute(args)).hasMessage("File '/invalid/filePath/toValidate.yaml' does not exist!"); + } + + @Test + void shouldReportAnErrorWhenPathToFileWasNotPass() { + // given + Args args = new Args(List.of()); + + // when + assertThatThrownBy(() -> validateYamlCommand.execute(args)).hasMessage("Command argument is missing: provide a path to file"); + } + + @Test + void shouldValidateFileWithoutAnyError() throws CommandException { + // given + final String path = YamlLoadingUtils.getUrlForGivenPath(YamlLoadingUtils.PATH_TO_SIMPLE_VALID_SCHEMA).getPath(); + Args args = new Args(List.of(path)); + + // when + final CommandResponse commandResponse = validateYamlCommand.execute(args); + + // then + assertThat(commandResponse.getCommandStatus()).isEqualTo(CommandResponse.CommandStatus.PASS); + ResponseModel actual = toModel(commandResponse.getResult()); + assertThat(actual.getFile()).isEqualTo(path); + assertThat(actual.getStatus()).isEqualTo(ResponseModel.ResponseStatus.PASS); + assertThat(actual.getErrors()).isEmpty(); + } + + @Test + void shouldReportThatFileHasSomeErrors() throws CommandException { + // given + final String path = YamlLoadingUtils.getUrlForGivenPath(YamlLoadingUtils.PATH_TO_YAML_WITH_WRONG_VALUES).getPath(); + Args args = new Args(List.of(path)); + + // when + final CommandResponse commandResponse = validateYamlCommand.execute(args); + + // then + assertThat(commandResponse.getCommandStatus()).isEqualTo(CommandResponse.CommandStatus.FAILED); + ResponseModel actual = toModel(commandResponse.getResult()); + assertThat(actual.getFile()).isEqualTo(path); + assertThat(actual.getStatus()).isEqualTo(ResponseModel.ResponseStatus.FAILED); + assertThat(actual.getErrors()).hasSize(4); + } +} diff --git a/dictionaryvalidation/src/test/java/org/onap/validation/cli/core/CliTest.java b/dictionaryvalidation/src/test/java/org/onap/validation/cli/core/CliTest.java new file mode 100644 index 0000000..c8ad629 --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/validation/cli/core/CliTest.java @@ -0,0 +1,101 @@ +/* + *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.cli.core; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.validation.cli.command.validate.ResponseStorage; +import org.onap.validation.yaml.util.Args; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +@ExtendWith(MockitoExtension.class) +class CliTest { + @Mock + private Console console; + + @Mock + private ResponseStorage responseStorage; + + @Mock + private Command validationCommand; + + private Cli cli; + + @BeforeEach + void setUp() { + cli = new Cli<>(console, responseStorage); + } + + @Test + void shouldExecuteCommandWithoutAnyError() throws CommandException { + + // given + Args args = new Args(List.of()); + when(validationCommand.execute(args)).thenReturn( + new CommandResponse<>("{ 'errors': [] }", CommandResponse.CommandStatus.PASS) + ); + + // when + final int exitCode = cli.run(args, validationCommand); + + // then + assertThat(exitCode).isEqualTo(Cli.PASS_STATUS_CODE); + verify(console).info("{ 'errors': [] }"); + } + + @Test + void shouldHandleErrorReportedByCommand() throws CommandException { + + // given + Args args = new Args(List.of()); + final CommandException commandException = new CommandException("It should be reported"); + Mockito.doThrow(commandException).when(validationCommand).execute(args); + + // when + final int exitCode = cli.run(args, validationCommand); + + // then + assertThat(exitCode).isEqualTo(Cli.INTERNAL_ERROR_STATUS_CODE); + verify(console).error(commandException); + } + + @Test + void shouldHandleRuntimeException() throws CommandException { + + // given + Args args = new Args(List.of()); + final RuntimeException commandException = new RuntimeException(); + Mockito.doThrow(commandException).when(validationCommand).execute(args); + + // when + final int exitCode = cli.run(args, validationCommand); + + // then + assertThat(exitCode).isEqualTo(Cli.INTERNAL_ERROR_STATUS_CODE); + verify(console).error(commandException); + } +} diff --git a/dictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlContentValidatorTest.java b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlContentValidatorTest.java new file mode 100644 index 0000000..ff4e55b --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlContentValidatorTest.java @@ -0,0 +1,164 @@ +/* + * 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.Nested; +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.io.IOException; +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.PATH_TO_MULTI_DOCUMENT_INVALID_YAML; +import static org.onap.validation.yaml.YamlLoadingUtils.PATH_TO_VALID_JSON_STYLE_YAML; +import static org.onap.validation.yaml.YamlLoadingUtils.PATH_TO_YAML_WITH_WRONG_VALUES; +import static org.onap.validation.yaml.YamlLoadingUtils.readFile; + +class YamlContentValidatorTest { + + final YamlContentValidator yamlContentValidator = new YamlContentValidator(); + + @Nested + class FromStringPathValidator { + @Test + void shouldReturnCorrectErrorsWhenGivenPathToValidPmDictionaryFile() throws YamlProcessingException { + // given + String path = getFullPathForGivenResources(PATH_TO_YAML_WITH_WRONG_VALUES); + + // when + List validationErrors = new YamlContentValidator().validate(path); + + // then + assertValidationReturnedExpectedErrors(validationErrors); + } + + @Test + void shouldReturnCorrectErrorsWhenGivenPathToValidJsonStylePmDictionaryFile() throws YamlProcessingException { + // given + String path = getFullPathForGivenResources(PATH_TO_VALID_JSON_STYLE_YAML); + + // when + List validationErrors = new YamlContentValidator().validate(path); + + // then + assertValidationReturnedExpectedErrors(validationErrors); + } + + @Test + void shouldThrowErrorWhenGivenPathToInvalidPmDictionaryFile() { + // given + String path = getFullPathForGivenResources(PATH_TO_MULTI_DOCUMENT_INVALID_YAML); + + //when then + assertThatThrownBy(() -> yamlContentValidator.validate(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(() -> yamlContentValidator.validate(path)) + .isInstanceOf(YamlProcessingException.class) + .hasMessageContaining("Dictionary YAML file is empty"); + } + } + + @Nested + class FromByteArrayValidator { + @Test + void shouldReturnCorrectErrorsWhenGivenPmDictionaryFileWithErrors() throws YamlProcessingException, IOException { + // given + byte[] yaml = readFile(PATH_TO_YAML_WITH_WRONG_VALUES); + + // when + List validationErrors = new YamlContentValidator().validate(yaml); + + // then + assertValidationReturnedExpectedErrors(validationErrors); + } + + @Test + void shouldReturnCorrectErrorsWhenGivenValidJsonStylePmDictionary() throws YamlProcessingException, IOException { + // given + byte[] yaml = readFile(PATH_TO_VALID_JSON_STYLE_YAML); + + // when + List validationErrors = new YamlContentValidator().validate(yaml); + + // then + assertValidationReturnedExpectedErrors(validationErrors); + } + + @Test + void shouldThrowErrorWhenGivenInvalidPmDictionary() throws IOException { + // given + byte[] yaml = readFile(PATH_TO_MULTI_DOCUMENT_INVALID_YAML); + + //when then + assertThatThrownBy(() -> new YamlContentValidator().validate(yaml)) + .isInstanceOf(ParserException.class) + .hasMessageContaining("expected the node content, but found ''"); + } + + @Test + void shouldThrowErrorWhenGivenEmptyPmDictionary() { + //when then + assertThatThrownBy(() -> new YamlContentValidator().validate(new byte[0])) + .isInstanceOf(YamlProcessingException.class) + .hasMessageContaining("Dictionary YAML file is empty"); + } + } + + private void assertValidationReturnedExpectedErrors(List validationErrors) { + assertThat(validationErrors) + .isNotNull() + .hasSize(4) + .usingRecursiveFieldByFieldElementComparator() + .containsAll( + List.of( + 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]") + ) + ); + } + + private String getFullPathForGivenResources(String pathToValidYaml) { + return this.getClass().getClassLoader().getResource(pathToValidYaml).getPath(); + } +} diff --git a/dictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java new file mode 100644 index 0000000..3e1f601 --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java @@ -0,0 +1,148 @@ +/* + * 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.Nested; +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.io.IOException; +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)"; + + @Nested + class FromUrlLoader { + @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 shouldThrowExceptionWhenLoadingDocumentsFromInvalidYamlFile() { + // when then + assertThatThrownBy(YamlLoadingUtils::tryToLoadMultiDocumentInvalidYamlFile) + .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); + } + } + + @Nested + class FromStringPathLoader { + @Test + void shouldLoadAllDocumentsFromYamlFileUsingPathInString() throws YamlProcessingException { + // when + List documents = YamlLoadingUtils.loadValidMultiDocumentYamlFileUsingStringPath(); + + // then + assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS); + } + + @Test + void shouldThrowExceptionWhenLoadingDocumentsFromInvalidYamlFileUsingPathInString() { + // when then + assertThatThrownBy(YamlLoadingUtils::tryToLoadMultiDocumentInvalidYamlFileUsingStringPath) + .isInstanceOf(ParserException.class) + .hasMessageContaining("expected the node content, but found ''"); + } + } + + @Nested + class FromByteArrayLoader { + private final YamlLoader YAML_LOADER = new YamlLoader(new YamlDocumentFactory()); + + @Test + void shouldLoadAllDocumentsFromYamlFile() throws YamlDocumentFactory.YamlDocumentParsingException, IOException { + // when + List documents = YAML_LOADER.loadMultiDocumentYaml(YamlLoadingUtils.readFile(YamlLoadingUtils.PATH_TO_YAML_WITH_WRONG_VALUES)); + + // then + assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS); + } + + @Test + void shouldLoadAllDocumentsFromJsonStyleYamlFile() throws YamlDocumentFactory.YamlDocumentParsingException, IOException { + // when + List documents = YAML_LOADER.loadMultiDocumentYaml(YamlLoadingUtils.readFile(YamlLoadingUtils.PATH_TO_VALID_JSON_STYLE_YAML)); + + // then + assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS); + } + + @Test + void shouldThrowExceptionWhenLoadingDocumentsFromInvalidYamlFile() { + // when then + assertThatThrownBy(() -> YAML_LOADER.loadMultiDocumentYaml(YamlLoadingUtils.readFile(YamlLoadingUtils.PATH_TO_MULTI_DOCUMENT_INVALID_YAML))) + .isInstanceOf(ParserException.class) + .hasMessageContaining("expected the node content, but found ''"); + } + + @Test + void shouldThrowExceptionWhenLoadingInvalidYamlFileWithIncorrectKeyMapping() { + // when then + assertThatThrownBy(() -> YAML_LOADER.loadMultiDocumentYaml(YamlLoadingUtils.readFile(YamlLoadingUtils.PATH_TO_INVALID_YAML_WITH_INCORRECT_KEY_MAPPING))) + .isInstanceOf(ScannerException.class) + .hasMessageContaining("mapping values are not allowed here"); + } + + @Test + void shouldThrowExceptionWhenLoadingInvalidYamlFileWithUnknownEscapeCharacter() { + // when then + assertThatThrownBy(() -> YAML_LOADER.loadMultiDocumentYaml(YamlLoadingUtils.readFile(YamlLoadingUtils.PATH_TO_INVALID_YAML_WITH_UNKNOWN_ESCAPE_CHARACTER))) + .isInstanceOf(ScannerException.class) + .hasMessageContaining("found unknown escape character " + LETTER_S_WITH_ASCII_CODE); + } + } +} diff --git a/dictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java new file mode 100644 index 0000000..dc1ce3b --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java @@ -0,0 +1,104 @@ +/* + *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 java.io.IOException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +import static org.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException; + +public final class YamlLoadingUtils { + + public static final YamlLoader YAML_LOADER = new YamlLoader(new YamlDocumentFactory()); + + 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; + public static final String PATH_TO_YAML_WITH_WRONG_VALUES = "yaml_schema/PM_Dictionary.yaml"; + public static final String PATH_TO_VALID_JSON_STYLE_YAML = "yaml_schema/PM_Dictionary_JSON_Style.yaml"; + public static final String PATH_TO_SIMPLE_VALID_SCHEMA = "yaml_schema/Simple_Valid_Schema.yaml"; + public static final String PATH_TO_SIMPLE_VALID_SCHEMA_MULTI_ROOT = "yaml_schema/Simple_Valid_Schema_Multi_Root.yaml"; + public static final String PATH_TO_SIMPLE_INVALID_SCHEMA = "yaml_schema/Simple_Invalid_Schema_Construction.yaml"; + public static final String PATH_TO_SIMPLE_INVALID_SCHEMA_FOR_LAZY_LOADING = "yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml"; + public static final String PATH_TO_MULTI_DOCUMENT_INVALID_YAML = "yaml_schema/Multi_Document_Invalid.yaml"; + public static final String PATH_TO_INVALID_YAML_WITH_INCORRECT_KEY_MAPPING = "yaml_schema/Simple_Invalid_Mapping_Value.yaml"; + public 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 YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_YAML_WITH_WRONG_VALUES)); + } + + public static List loadValidJsonStyleMultiDocumentYamlFile() throws YamlDocumentParsingException { + return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_VALID_JSON_STYLE_YAML)); + } + + public static List loadValidMultiDocumentYamlFileUsingStringPath() throws YamlProcessingException { + return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_YAML_WITH_WRONG_VALUES).getPath()); + } + + public static YamlDocument loadSimpleValidYamlSchemaFile() throws YamlDocumentParsingException { + return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_VALID_SCHEMA)).get(0); + } + + public static YamlDocument loadSimpleInvalidYamlSchemaFile() throws YamlDocumentParsingException { + return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_INVALID_SCHEMA)).get(0); + } + + public static YamlDocument loadSimpleInvalidYamlSchemaForLazyLoadingFile() throws YamlDocumentParsingException { + return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_INVALID_SCHEMA_FOR_LAZY_LOADING)).get(0); + } + + public static YamlDocument loadSimpleValidYamlSchemaWithMultiRootFile() throws YamlDocumentParsingException { + return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_VALID_SCHEMA_MULTI_ROOT)).get(0); + } + + public static List tryToLoadMultiDocumentInvalidYamlFile() throws YamlDocumentParsingException { + return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_MULTI_DOCUMENT_INVALID_YAML)); + } + + public static List tryToLoadMultiDocumentInvalidYamlFileUsingStringPath() throws YamlProcessingException { + return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_MULTI_DOCUMENT_INVALID_YAML).getPath()); + } + + public static List tryToLoadInvalidYamlFileWithIncorrectKeyMapping() throws YamlDocumentParsingException { + return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_INVALID_YAML_WITH_INCORRECT_KEY_MAPPING)); + } + + public static List tryToLoadInvalidYamlFileWithUnknownEscapeCharacter() throws YamlDocumentParsingException { + return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_INVALID_YAML_WITH_UNKNOWN_ESCAPE_CHARACTER)); + } + + public static byte[] readFile(String path) throws IOException { + String file = getUrlForGivenPath(path).getFile(); + return Files.readAllBytes(Path.of(file)); + } + + public static URL getUrlForGivenPath(String path) { + return YamlLoadingUtils.class.getClassLoader().getResource(path); + } +} diff --git a/dictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java new file mode 100644 index 0000000..3d993f8 --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java @@ -0,0 +1,115 @@ +/* + * 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.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(List.of( + 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)).isEmpty(); + } + +} diff --git a/dictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java new file mode 100644 index 0000000..d7d1153 --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java @@ -0,0 +1,130 @@ +/* + * 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 java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.ThrowableAssert.catchThrowable; +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 + assertYamlDocument(document, inputMap); + } + + @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 + assertYamlDocument(document, inputMap); + } + + @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 + assertYamlDocument(document, inputMap); + } + + @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 + Throwable ex = catchThrowable(() -> document.getSubStructure("test")); + + // then + assertYamlDocumentParsingException(ex, testList); + } + + @Test + void shouldThrowExceptionIfGetSubStructureIsCalledOnString() + throws YamlDocumentParsingException { + // given + Map inputMap = Collections.singletonMap("test", "testElement"); + YamlDocument document = new YamlDocumentFactory().createYamlDocument(inputMap); + + // when + Throwable ex = catchThrowable(() -> document.getSubStructure("test")); + + // then + assertYamlDocumentParsingException(ex, "testElement"); + } + + private void assertYamlDocument(YamlDocument document, Map inputMap) { + assertThat(document).isNotNull(); + assertThat(document.getYaml()).containsExactlyEntriesOf(mapKeyToString(inputMap)); + } + + private Map mapKeyToString(Map inputMap) { + return inputMap.entrySet().stream() + .collect(Collectors.toMap(w -> w.getKey().toString(), Map.Entry::getValue)); + } + + private void assertYamlDocumentParsingException(Throwable ex, Object unparsed) { + assertThat(ex) + .isInstanceOf(YamlDocumentParsingException.class) + .hasMessageContaining(String.format("Fail to parse given objects: %s as yaml document.", unparsed)); + } +} diff --git a/dictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java new file mode 100644 index 0000000..ab6f882 --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java @@ -0,0 +1,85 @@ +/* + * 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 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 testList = List.of("test1", 3, 23.45, 'a', "test2"); + + // when + YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testList); + + // then + assertYamlParametersList(parametersList, testList); + } + + @Test + void shouldCreateParametersListContainingStringsFromListContainingVariousTypes() { + // given + List testList = List.of("test1", 3, List.of(2, 3, 4), "test2"); + + // when + YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testList); + + // then + assertYamlParametersList(parametersList, testList); + } + + @Test + void shouldCreateListWithOneStringWhenGivenObjectIsNotList() { + // given + Object testObject = "test"; + + // when + YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testObject); + + // then + assertYamlParametersList(parametersList, Collections.singletonList(testObject)); + } + + private void assertYamlParametersList(YamlParametersList parametersList, List testList) { + assertThat(parametersList).isNotNull(); + assertThat(parametersList.getParameters()) + .containsExactly(mapToStrings(testList)); + } + + private String[] mapToStrings(List elements) { + return elements.stream().map(Object::toString).toArray(String[]::new); + } + +} diff --git a/dictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java new file mode 100644 index 0000000..5c9d8e5 --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java @@ -0,0 +1,100 @@ +/* + * 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.catchThrowable; +import static org.onap.validation.yaml.YamlLoadingUtils.VALID_YAML_DOCUMENT_INDEX; +import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX; +import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX; + +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 + Throwable ex = catchThrowable(() -> new YamlValidationProcess(schema, document).validate()); + + // then + assertThat(ex) + .isInstanceOf(YamlProcessingException.class) + .hasMessageContaining("Lazy loading failed, due to yaml parsing exception."); + } +} diff --git a/dictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java new file mode 100644 index 0000000..efc304c --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java @@ -0,0 +1,115 @@ +/* + * 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.Disabled; +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()) + .extracting(YamlSchemaNode::getName) + .containsExactly("root1", "root2", "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/dictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java new file mode 100644 index 0000000..646b8a2 --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java @@ -0,0 +1,147 @@ +/* + * 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.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.catchThrowable; +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 + Throwable ex = catchThrowable(node::getNextNodes); + + // then + assertThat(ex) + .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 = List.of("val1", "val2"); + Map nodeInYamlFormat = Map.of( + YamlSchemaNodeFactory.PRESENCE_KEY, YamlSchemaNodeFactory.PRESENCE_REQUIRED_KEY, + YamlSchemaNodeFactory.COMMENT_KEY, comment, + 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[0]) + ); + } + + @Test + void shouldCreateBranchNodeIfGivenYamlDocumentHaveSubStructure() + throws YamlProcessingException { + // given + String nodeName = "branch_test"; + String comment = "test branch node"; + + String subNode1Name = "branch_test_node1"; + String subNode2Name = "branch_test_node2"; + + Map subStructure = Map.of( + subNode1Name, new HashMap<>(), + subNode2Name, new HashMap<>()); + + Map nodeInYamlFormat = Map.of( + YamlSchemaNodeFactory.PRESENCE_KEY, YamlSchemaNodeFactory.PRESENCE_REQUIRED_KEY, + YamlSchemaNodeFactory.COMMENT_KEY, comment, + 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/dictionaryvalidation/src/test/java/org/onap/validation/yaml/util/ArgsTest.java b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/util/ArgsTest.java new file mode 100644 index 0000000..0090683 --- /dev/null +++ b/dictionaryvalidation/src/test/java/org/onap/validation/yaml/util/ArgsTest.java @@ -0,0 +1,39 @@ +/* + *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.util; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; + +class ArgsTest { + + @Test + void shouldThrowAnExceptionWhenArgIsNotAvailable() { + Args args = new Args(List.of()); + Assertions.assertThatThrownBy(() -> args.getArg(0)).hasMessage("Argument with index 0 is not available!"); + } + + @Test + void shouldReturnArgumentForGivenIndex() { + Args args = new Args(List.of("one","two", "three")); + Assertions.assertThat(args.getArg(0)).isEqualTo("one"); + Assertions.assertThat(args.getArg(1)).isEqualTo("two"); + Assertions.assertThat(args.getArg(2)).isEqualTo("three"); + } +} diff --git a/dictionaryvalidation/src/test/resources/Not_Yaml_File.txt b/dictionaryvalidation/src/test/resources/Not_Yaml_File.txt new file mode 100644 index 0000000..be6ee44 --- /dev/null +++ b/dictionaryvalidation/src/test/resources/Not_Yaml_File.txt @@ -0,0 +1 @@ +Not a Yaml file! diff --git a/dictionaryvalidation/src/test/resources/yaml_schema/Custom_Invalid_Dictionary.yaml b/dictionaryvalidation/src/test/resources/yaml_schema/Custom_Invalid_Dictionary.yaml new file mode 100644 index 0000000..d5d12d6 --- /dev/null +++ b/dictionaryvalidation/src/test/resources/yaml_schema/Custom_Invalid_Dictionary.yaml @@ -0,0 +1,56 @@ +--- +rootElement: { presence: required, structure: { + field1: { + presence: required, + comment: "field 1 description", + structure: { + field11:{ + presence: required, + comment: "field 11 description" + }, + field12: { + presence: required, + comment: "field 12 description" + }, + field13: { + presence: optional, + value: [ X, Y, Z ], + comment: "field 13 description" + } + } + }, + field2: { + presence: required, + comment: "field 2 description" + }, + field3: { + presence: required, + value: [ 3, 30, 33 ], + comment: "field 2 description" + } +}} +... +--- +rootElement: + field1: + field11: test11 + field12: test12 + field13: A + field2: test2 + field3: 3 +... +--- +rootElement: + field1: + field11: test11 + field12: test12 + field2: test2 + field3: 300 +... +--- +rootElement: + field1: + field11: test11 + field12: test12 + field3: 3 +... diff --git a/dictionaryvalidation/src/test/resources/yaml_schema/Custom_Valid_Dictionary.yaml b/dictionaryvalidation/src/test/resources/yaml_schema/Custom_Valid_Dictionary.yaml new file mode 100644 index 0000000..4193b0d --- /dev/null +++ b/dictionaryvalidation/src/test/resources/yaml_schema/Custom_Valid_Dictionary.yaml @@ -0,0 +1,58 @@ +--- +rootElement1: { presence: required, structure: { + field11: { + presence: required, + value: [X, Y, Z], + comment: "field 11 description" + }, + field12: { + presence: required, + comment: "field 12 description" + } +}} +rootElement2: { presence: required, structure: { + field21: { + presence: required, + value: [22, 222, 2222], + comment: "field 21 description" + }, + field22: { + presence: optional, + value: [ A,B,C ], + comment: "field 22 description" + } +}} +rootElement3: { presence: optional, structure: { + field3: { + presence: required, + comment: "field 3 description" + } +}} +... +--- +rootElement1: + field11: X + field12: test +rootElement2: + field21: 22 + field22: B +... +--- +rootElement1: + field11: X + field12: test12 +rootElement2: + field21: 22 +rootElement3: + field3: test3 +... +--- +rootElement1: + field11: Y + field12: testing12 +rootElement2: + field21: 222 + field22: A +rootElement3: + field3: testing3 +... diff --git a/dictionaryvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml b/dictionaryvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml new file mode 100644 index 0000000..aab34fa --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml b/dictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml new file mode 100644 index 0000000..12a4af9 --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml b/dictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml new file mode 100644 index 0000000..f4cbddf --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml b/dictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml new file mode 100644 index 0000000..25c72cd --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml b/dictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml new file mode 100644 index 0000000..c5e7b7c --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml b/dictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml new file mode 100644 index 0000000..7f9f946 --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml b/dictionaryvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml new file mode 100644 index 0000000..2cac9e6 --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml b/dictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml new file mode 100644 index 0000000..a125b13 --- /dev/null +++ b/dictionaryvalidation/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/dictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml b/dictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml new file mode 100644 index 0000000..d73ca4f --- /dev/null +++ b/dictionaryvalidation/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/pmdictionaryvalidation/README.md b/pmdictionaryvalidation/README.md deleted file mode 100644 index 2bc91a5..0000000 --- a/pmdictionaryvalidation/README.md +++ /dev/null @@ -1,26 +0,0 @@ -PMDictionary Validation -======================= -This module can be used as a library to validate pmdictionary against the schema (schema is the first document in the file). - -How to use PMDictionary validation library ------------------------------------------- -VNF-SDK validation library (pmdictionaryvalidation) should be used to validate the PM_Dictionary file. - Below dependency should be added to the required modules in your project. - - - org.onap.vnfsdk.validation - validation-pmdictionary - version - - -How to validate PMDictionary --------------------------- -1.Validate PMDictionary from a path to the file. - - new YamlContentValidator().validate(pathToFile) - -2.Validate PMDictionary file from the byte array. - - new YamlContentValidator().validate(fileContentAsByteArray) - -Above methods return list of YamlDocumentValidationError(empty list for no errors) or throw YamlProcessingException/YAMLException when something goes wrong. diff --git a/pmdictionaryvalidation/pom.xml b/pmdictionaryvalidation/pom.xml deleted file mode 100644 index 8046fb4..0000000 --- a/pmdictionaryvalidation/pom.xml +++ /dev/null @@ -1,151 +0,0 @@ - - - - org.onap.vnfsdk.validation - validation - 1.2.20-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/ - - - - 5.7.0 - 3.18.1 - 3.2.4 - 3.5.0 - 2.23.0 - 2.8.6 - - - - org.onap.cli - cli-framework - ${cli-framework.version} - - - commons-codec - commons-codec - - - - - org.apache.logging.log4j - log4j-slf4j-impl - ${log4j-slf4j-impl.version} - - - org.slf4j - slf4j-ext - - - - - org.yaml - snakeyaml - ${snakeyaml.version} - - - com.google.code.gson - gson - ${gson.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 - - - org.mockito - mockito-core - ${mockito-core.version} - test - - - org.mockito - mockito-junit-jupiter - ${mockito-junit-jupiter.version} - test - - - org.onap.cli - cli-main - ${cli-main.version} - test - - - - ${project.artifactId}-${project.version} - - - - org.apache.maven.plugins - maven-shade-plugin - ${maven-shade-plugin.version} - - - - package - - shade - - - true - standalone - true - - - *:* - - META-INF/DEPENDENCIES - META-INF/LICENSE - META-INF/NOTICE - - - - - - - org.onap.validation.cli.Main - - true - - - - - - - - - - diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/Main.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/Main.java deleted file mode 100644 index 5ab2e69..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/Main.java +++ /dev/null @@ -1,48 +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.cli; - -import org.onap.validation.cli.command.validate.ResponseStorage; -import org.onap.validation.cli.command.validate.ToJsonConverter; -import org.onap.validation.cli.command.validate.ValidatePmDictionaryYamlCommand; -import org.onap.validation.cli.core.Cli; -import org.onap.validation.cli.core.Console; -import org.onap.validation.yaml.util.Args; - -import java.util.List; - -public class Main { - - public static void main(String[] args) { - final Console console = new Console(); - final ResponseStorage storage = new ResponseStorage(); - - System.exit( - run(args, console, storage) - ); - } - - static int run(String[] args, Console console, ResponseStorage responseStorage) { - - Cli cli = new Cli<>(console, responseStorage); - - return cli.run( - new Args(List.of(args)), - new ValidatePmDictionaryYamlCommand(new ToJsonConverter()) - ); - } -} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/OutputFilePathGenerator.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/OutputFilePathGenerator.java deleted file mode 100644 index 2ed7285..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/OutputFilePathGenerator.java +++ /dev/null @@ -1,41 +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.cli.command.validate; - -import java.nio.file.Path; - -public class OutputFilePathGenerator { - - public static final int FILE_NAME_ABBREVIATION_INDEX = 0; - public static final String BY_PERIOD_REGEX = "\\."; - public static final String POST_FIX = "-validation-results.json"; - - public Path responsePathFor(Path filePath) { - final Path parent = filePath.getParent(); - final String fileNameAbbreviation = getFileNameAbbreviation(filePath); - return Path.of(parent.toString(), createFileName(fileNameAbbreviation)); - } - - private String createFileName(String fileNameAbbreviation) { - return fileNameAbbreviation + POST_FIX; - } - - private String getFileNameAbbreviation(Path filePath) { - final Path fileName = filePath.getFileName(); - return fileName.toString().split(BY_PERIOD_REGEX)[FILE_NAME_ABBREVIATION_INDEX]; - } -} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ResponseModel.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ResponseModel.java deleted file mode 100644 index 033031d..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ResponseModel.java +++ /dev/null @@ -1,51 +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.cli.command.validate; - -import org.onap.validation.yaml.error.YamlDocumentValidationError; - -import java.util.Collections; -import java.util.List; - -public class ResponseModel { - - private final String file; - private final ResponseStatus status; - private final List errors; - - public ResponseModel(String file, ResponseStatus status, List errors) { - this.file = file; - this.status = status; - this.errors = errors; - } - - public String getFile() { - return file; - } - - public List getErrors() { - return Collections.unmodifiableList(errors); - } - - public ResponseStatus getStatus() { - return status; - } - - public enum ResponseStatus { - PASS, FAILED - } -} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ResponseStorage.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ResponseStorage.java deleted file mode 100644 index 3daed16..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ResponseStorage.java +++ /dev/null @@ -1,30 +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.cli.command.validate; - -import java.io.IOException; -import java.io.PrintWriter; -import java.nio.file.Path; - -public class ResponseStorage{ - - public void store(Path filePath, T response) throws IOException { - try (PrintWriter out = new PrintWriter(filePath.toFile())) { - out.println(response); - } - } -} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ToJsonConverter.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ToJsonConverter.java deleted file mode 100644 index 168daf8..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ToJsonConverter.java +++ /dev/null @@ -1,28 +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.cli.command.validate; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - - -public class ToJsonConverter { - public String convert(ResponseModel responseModel) { - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - return gson.toJson(responseModel); - } -} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ToResponseModelConverter.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ToResponseModelConverter.java deleted file mode 100644 index 674068f..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ToResponseModelConverter.java +++ /dev/null @@ -1,31 +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.cli.command.validate; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -public final class ToResponseModelConverter { - - private ToResponseModelConverter() { - } - - public static ResponseModel toModel(String json) { - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - return gson.fromJson(json, ResponseModel.class); - } -} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ValidatePmDictionaryYamlCommand.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ValidatePmDictionaryYamlCommand.java deleted file mode 100644 index ceb46d3..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/command/validate/ValidatePmDictionaryYamlCommand.java +++ /dev/null @@ -1,92 +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.cli.command.validate; - -import org.onap.validation.cli.core.Command; -import org.onap.validation.cli.core.CommandException; -import org.onap.validation.cli.core.CommandResponse; -import org.onap.validation.yaml.YamlContentValidator; -import org.onap.validation.yaml.error.YamlDocumentValidationError; -import org.onap.validation.yaml.exception.YamlProcessingException; -import org.onap.validation.yaml.util.Args; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; - -public class ValidatePmDictionaryYamlCommand implements Command { - - public static final int PATH_TO_FILE_INDEX = 0; - private final YamlContentValidator yamlContentValidator = new YamlContentValidator(); - - private final ToJsonConverter toJsonConverter; - private final OutputFilePathGenerator filePathGenerator = new OutputFilePathGenerator(); - - public ValidatePmDictionaryYamlCommand(ToJsonConverter toJsonConverter) { - this.toJsonConverter = toJsonConverter; - } - - @Override - public CommandResponse execute(Args args) throws CommandException { - final String pathToFile = resolvePathToFile(args); - - try { - return validate(pathToFile); - } catch (YamlProcessingException e) { - throw new CommandException("Provided yaml file has invalid structure!", e); - } - } - - @Override - public String getName() { - return "Validate PM Dictionary yaml"; - } - - @Override - public Path getOutputFilePath(Args args) throws CommandException { - final String pathToFile = resolvePathToFile(args); - return this.filePathGenerator.responsePathFor(Path.of(pathToFile)); - } - - private CommandResponse validate(String pathToFile) throws YamlProcessingException { - final List errors = yamlContentValidator.validate(pathToFile); - return new CommandResponse<>( - toJsonConverter.convert(new ResponseModel(pathToFile, resolveResponseStatus(errors), errors)) - ,resolveCommandStatus(errors) - ); - } - - private ResponseModel.ResponseStatus resolveResponseStatus(List errors) { - return errors.isEmpty() ? ResponseModel.ResponseStatus.PASS : ResponseModel.ResponseStatus.FAILED; - } - - private CommandResponse.CommandStatus resolveCommandStatus(List errors) { - return errors.isEmpty() ? CommandResponse.CommandStatus.PASS : CommandResponse.CommandStatus.FAILED; - } - - private String resolvePathToFile(Args args) throws CommandException { - try { - final String pathToFile = args.getArg(PATH_TO_FILE_INDEX); - if (!Files.exists(Path.of(pathToFile))) { - throw new CommandException(String.format("File '%s' does not exist!", pathToFile)); - } - return pathToFile; - } catch (IllegalArgumentException ex) { - throw new CommandException("Command argument is missing: provide a path to file", ex); - } - } -} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/Cli.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/Cli.java deleted file mode 100644 index bf2abad..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/Cli.java +++ /dev/null @@ -1,85 +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.cli.core; - -import org.onap.validation.cli.command.validate.ResponseStorage; -import org.onap.validation.cli.core.CommandResponse.CommandStatus; -import org.onap.validation.yaml.util.Args; - -import java.nio.file.Path; - -public class Cli { - - public static final int INTERNAL_ERROR_STATUS_CODE = 2; - public static final int FAILED_STATUS_CODE = 1; - public static final int PASS_STATUS_CODE = 0; - - public static final String APPLICATION_INTERNAL_ERROR_MSG = "\n# Application fails with internal error."; - public static final String APPLICATION_EXIT_SUCCESSFULLY_MSG = "\n# Application exits successfully."; - - private final Console console; - private final ResponseStorage responseStorage; - - public Cli(Console console, ResponseStorage responseStorage) { - this.console = console; - this.responseStorage = responseStorage; - } - - public int run(Args args, Command command) { - try { - final CommandResponse commandResponse = processCommand(args, command); - - logResultInfo(commandResponse.getResult()); - storeResult(args, command, commandResponse.getResult()); - - this.console.info(APPLICATION_EXIT_SUCCESSFULLY_MSG); - - return resolveCliStatusCodeFor(commandResponse); - } catch (Exception e) { - logException(e); - return INTERNAL_ERROR_STATUS_CODE; - } - } - - private int resolveCliStatusCodeFor(CommandResponse commandResponse) { - return commandResponse.getCommandStatus() == CommandStatus.PASS ? PASS_STATUS_CODE : FAILED_STATUS_CODE; - } - - private void logException(Exception e) { - this.console.error("# Command error: "); - this.console.error(e); - this.console.error(APPLICATION_INTERNAL_ERROR_MSG); - } - - private void storeResult(Args args, Command command, T result) throws CommandException, java.io.IOException { - final Path pathToFileWithResponse = command.getOutputFilePath(args); - this.responseStorage.store(pathToFileWithResponse, result); - this.console.info(String.format("%n# Result was stored in a file: '%s'", pathToFileWithResponse)); - } - - private void logResultInfo(T result) { - this.console.info("\n# Operation result:\n"); - this.console.info(result.toString()); - } - - private CommandResponse processCommand(Args args, Command command) throws CommandException { - this.console.info(String.format("# Executing a '%s' operation ...", command.getName())); - final CommandResponse commandResponse = command.execute(args); - this.console.info("# ... Done."); - return commandResponse; - } -} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/Command.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/Command.java deleted file mode 100644 index 1da724f..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/Command.java +++ /dev/null @@ -1,29 +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.cli.core; - -import org.onap.validation.yaml.util.Args; - -import java.nio.file.Path; - -public interface Command { - CommandResponse execute(Args args) throws CommandException; - - String getName(); - - Path getOutputFilePath(Args args) throws CommandException; -} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/CommandException.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/CommandException.java deleted file mode 100644 index 2c72ff8..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/CommandException.java +++ /dev/null @@ -1,27 +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.cli.core; - -public class CommandException extends Exception { - public CommandException(String msg) { - super(msg); - } - - public CommandException(String msg, Exception ex) { - super(msg, ex); - } -} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/CommandResponse.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/CommandResponse.java deleted file mode 100644 index 73db4ab..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/CommandResponse.java +++ /dev/null @@ -1,48 +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.cli.core; - -public class CommandResponse { - - private final T result; - private final CommandStatus commandStatus; - - public CommandResponse(T result, CommandStatus commandStatus) { - this.result = result; - this.commandStatus = commandStatus; - } - - public T getResult() { - return result; - } - - public CommandStatus getCommandStatus() { - return commandStatus; - } - - public enum CommandStatus { - PASS, FAILED - } - - @Override - public String toString() { - return "CommandResponse{" + - "result=" + result + - ", commandStatus=" + commandStatus + - '}'; - } -} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/Console.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/Console.java deleted file mode 100644 index 4c20437..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/cli/core/Console.java +++ /dev/null @@ -1,41 +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.cli.core; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Console { - - public static final Logger logger = LoggerFactory.getLogger(Console.class); - - public void info(String msg) { - System.out.println(msg); - logger.info(msg); - } - - public void error(Exception ex) { - System.err.println(ex.getMessage() + ", more information in log file."); - logger.error("Internal error", ex); - } - - public void error(String msg) { - System.err.println(msg); - logger.error(msg); - } - -} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/rule/PMDictionaryValidate.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/rule/PMDictionaryValidate.java deleted file mode 100644 index 663dceb..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/rule/PMDictionaryValidate.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2019 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.rule; - -import com.google.gson.Gson; -import org.onap.cli.fw.cmd.OnapCommand; -import org.onap.cli.fw.error.OnapCommandException; -import org.onap.cli.fw.output.OnapCommandResultType; -import org.onap.cli.fw.schema.OnapCommandSchema; -import org.onap.validation.cli.command.validate.ResponseModel; -import org.onap.validation.cli.command.validate.ResponseModel.ResponseStatus; -import org.onap.validation.cli.command.validate.ToJsonConverter; -import org.onap.validation.cli.command.validate.ToResponseModelConverter; -import org.onap.validation.cli.command.validate.ValidatePmDictionaryYamlCommand; -import org.onap.validation.cli.core.CommandException; -import org.onap.validation.cli.core.CommandResponse; -import org.onap.validation.yaml.util.Args; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Date; -import java.util.List; - -/** - * Validates CSAR - */ -@OnapCommandSchema(schema = "pm-dictionary-validate.yaml") -public class PMDictionaryValidate extends OnapCommand { - - private static final String VALIDATION_PASS = "PASS"; - private static final String VALIDATION_FAILED = "FAILED"; - public static final String PARAM_IN_YAML = "yaml"; - public static final String PARAM_OUT_FILE = "file"; - public static final String PARAM_OUT_DATE = "date"; - public static final String PARAM_OUT_CRITERIA = "criteria"; - public static final String PARAM_OUT_ERRORS = "errors"; - private final Gson gson = new Gson(); - - private static final Logger logger = LoggerFactory.getLogger(PMDictionaryValidate.class); - - @Override - protected void run() throws OnapCommandException { - - final Date timestamp = new Date(); - final String yamlPath = (String) getParametersMap().get(PARAM_IN_YAML).getValue(); - - try { - final ResponseModel responseModel = executeValidation(yamlPath); - handleResponse(responseModel, timestamp); - } catch (CommandException e) { - handleError(timestamp, yamlPath, e); - } - } - - private void handleResponse(ResponseModel responseModel, Date timestamp) { - setOclipResponse(responseModel.getFile(), - timestamp, - getCriteria(responseModel), - transformToJson(responseModel.getErrors()) - ); - } - - private void handleError(Date validationTimestamp, String path, CommandException e) { - setOclipResponse(path, - validationTimestamp, - VALIDATION_FAILED, - transformToJson(e.getMessage()) - ); - logger.error("Internal application error", e); - } - - private String getCriteria(ResponseModel responseModel) { - return responseModel.getStatus().equals(ResponseStatus.PASS) ? VALIDATION_PASS : VALIDATION_FAILED; - } - - private String transformToJson(T data) { - return gson.toJson(data); - } - - private void setOclipResponse(String pathToFile, Date timestamp, String criteria, String errors) { - final PMDictionaryValidateResponse pmDictionaryValidateResponse = new PMDictionaryValidateResponse( - pathToFile, - timestamp.toString(), - criteria, - errors - ); - setOclipResponse(pmDictionaryValidateResponse); - } - - private void setOclipResponse(PMDictionaryValidateResponse pmDictionaryValidateResponse) { - this.getResult().getRecordsMap().get(PARAM_OUT_FILE).getValues().add(pmDictionaryValidateResponse.getFile()); - this.getResult().getRecordsMap().get(PARAM_OUT_DATE).getValues().add(pmDictionaryValidateResponse.getDate()); - this.getResult().getRecordsMap().get(PARAM_OUT_CRITERIA).getValues().add(pmDictionaryValidateResponse.getCriteria()); - this.getResult().getRecordsMap().get(PARAM_OUT_ERRORS).getValues().add(pmDictionaryValidateResponse.getErrors()); - this.getResult().setOutput(transformToJson(pmDictionaryValidateResponse)); - this.getResult().setType(OnapCommandResultType.TEXT); - } - - private ResponseModel executeValidation(String path) throws CommandException { - final ValidatePmDictionaryYamlCommand validation = new ValidatePmDictionaryYamlCommand(new ToJsonConverter()); - final CommandResponse commandResponse = validation.execute(new Args(List.of(path))); - final String result = commandResponse.getResult(); - - return ToResponseModelConverter.toModel(result); - } -} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/rule/PMDictionaryValidateResponse.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/rule/PMDictionaryValidateResponse.java deleted file mode 100644 index 3eb706b..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/rule/PMDictionaryValidateResponse.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2019 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.rule; - -public class PMDictionaryValidateResponse { - - public static final String PLATFORM_VTP_1_0 = "PM Dictionary Test Platform (VTP) 1.0"; - public static final String ONAP_DISCUSS_LISTS_ONAP_ORG = "ONAP VTP Team onap-discuss@lists.onap.org"; - private final String file; - private final String date; - private final String criteria; - private final String errors; - - public PMDictionaryValidateResponse(String file, String date, String criteria, String errors) { - this.file = file; - this.date = date; - this.criteria = criteria; - this.errors = errors; - } - - public String getFile() { - return file; - } - - public String getDate() { - return date; - } - - public String getContact() { - return ONAP_DISCUSS_LISTS_ONAP_ORG; - } - - public String getPlatform() { - return PLATFORM_VTP_1_0; - } - - public String getCriteria() { - return criteria; - } - - public String getErrors() { - return errors; - } -} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlContentValidator.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlContentValidator.java deleted file mode 100644 index 5e1238b..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlContentValidator.java +++ /dev/null @@ -1,83 +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.model.YamlDocumentFactory; -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 YamlContentValidator { - - private static final int FIRST_DOCUMENT_INDEX = 1; - private static final YamlLoader YAML_LOADER = new YamlLoader(new YamlDocumentFactory()); - - public List validate(String pathToFile) - throws YamlProcessingException { - List documents = YAML_LOADER.loadMultiDocumentYamlFile(pathToFile); - return getYamlDocumentValidationErrors(documents); - } - - public List validate(byte[] yamlWithSchema) - throws YamlProcessingException { - List documents = YAML_LOADER.loadMultiDocumentYaml(yamlWithSchema); - return getYamlDocumentValidationErrors(documents); - } - - private List getYamlDocumentValidationErrors(List documents) throws YamlProcessingException { - if (documents.isEmpty()) { - throw new YamlProcessingException("PM_Dictionary YAML file is empty"); - } else { - return validateDocuments(documents); - } - } - - 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 deleted file mode 100644 index c23da0a..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java +++ /dev/null @@ -1,82 +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.ByteArrayInputStream; -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); - private final YamlDocumentFactory documentFactory; - - YamlLoader(YamlDocumentFactory documentFactory) { - this.documentFactory = documentFactory; - } - - List loadMultiDocumentYaml(byte[] yamlWithSchema) - throws YamlDocumentFactory.YamlDocumentParsingException { - List documents = new ArrayList<>(); - try (InputStream yamlStream = new ByteArrayInputStream(yamlWithSchema)) { - documents.addAll(loadMultiDocumentYaml(yamlStream)); - } catch (IOException e) { - LOGGER.error("Failed to load multi document YAML", e); - } - return documents; - } - - List loadMultiDocumentYamlFile(URL path) - throws YamlDocumentFactory.YamlDocumentParsingException { - List documents = new ArrayList<>(); - try (InputStream yamlStream = path.openStream()) { - documents.addAll(loadMultiDocumentYaml(yamlStream)); - } catch (IOException e) { - LOGGER.error("Failed to load multi document YAML file", e); - } - return documents; - } - - 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); - } - } - - private List loadMultiDocumentYaml(InputStream yamlStream) throws YamlDocumentFactory.YamlDocumentParsingException { - List documents = new ArrayList<>(); - for (Object yamlDocument : new Yaml().loadAll(yamlStream)) { - documents.add(documentFactory.createYamlDocument(yamlDocument)); - } - return documents; - } -} diff --git a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java deleted file mode 100644 index 30ba646..0000000 --- a/pmdictionaryvalidation/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.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 deleted file mode 100644 index 6ffe6d4..0000000 --- a/pmdictionaryvalidation/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/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java deleted file mode 100644 index f04708f..0000000 --- a/pmdictionaryvalidation/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/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java deleted file mode 100644 index 99c2437..0000000 --- a/pmdictionaryvalidation/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/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java deleted file mode 100644 index 557b6fd..0000000 --- a/pmdictionaryvalidation/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/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java deleted file mode 100644 index b56422c..0000000 --- a/pmdictionaryvalidation/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/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java deleted file mode 100644 index 5f41c5c..0000000 --- a/pmdictionaryvalidation/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/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java deleted file mode 100644 index 2b93c74..0000000 --- a/pmdictionaryvalidation/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/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java deleted file mode 100644 index ebd37ce..0000000 --- a/pmdictionaryvalidation/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.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 deleted file mode 100644 index eb5ab8e..0000000 --- a/pmdictionaryvalidation/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/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java deleted file mode 100644 index 69bb6cd..0000000 --- a/pmdictionaryvalidation/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/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java deleted file mode 100644 index df7d673..0000000 --- a/pmdictionaryvalidation/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/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 deleted file mode 100644 index a3e9636..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java +++ /dev/null @@ -1,78 +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; - -public class YamlSchemaBranchNode extends YamlSchemaNode { - - private final YamlDocument nextNodesInLazyForm; - private List nextNodes = Collections.emptyList(); - - YamlSchemaBranchNode(String name, String path, boolean required, String comment, - YamlDocument nextNodesInLazyForm) { - super(name, path, required, comment); - this.nextNodesInLazyForm = nextNodesInLazyForm; - } - - @Override - public boolean isContainingSubStructure() { - return true; - } - - @Override - public List getAcceptedValues() { - return Collections.emptyList(); - } - - @Override - public synchronized List getNextNodes() throws YamlSchemaProcessingException { - try { - return nextNodes.isEmpty() ? this.loadNextNodes() : nextNodes; - } 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 = 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 deleted file mode 100644 index c98f41e..0000000 --- a/pmdictionaryvalidation/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/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 deleted file mode 100644 index 28913a2..0000000 --- a/pmdictionaryvalidation/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/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 deleted file mode 100644 index 79a8f14..0000000 --- a/pmdictionaryvalidation/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/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/util/Args.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/util/Args.java deleted file mode 100644 index 9ae44c8..0000000 --- a/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/util/Args.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.util; - -import java.util.ArrayList; -import java.util.List; - -public class Args { - - private final List data; - - public Args(List data) { - this.data = new ArrayList<>(data); - } - - public String getArg(int index) { - if (this.data.size() <= index) { - throw new IllegalArgumentException(String.format("Argument with index %d is not available!", index)); - } - return this.data.get(index); - } -} diff --git a/pmdictionaryvalidation/src/main/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand b/pmdictionaryvalidation/src/main/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand deleted file mode 100644 index 72d9f1f..0000000 --- a/pmdictionaryvalidation/src/main/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand +++ /dev/null @@ -1,15 +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. - -org.onap.validation.rule.PMDictionaryValidate diff --git a/pmdictionaryvalidation/src/main/resources/log4j2.properties b/pmdictionaryvalidation/src/main/resources/log4j2.properties deleted file mode 100644 index c7e5092..0000000 --- a/pmdictionaryvalidation/src/main/resources/log4j2.properties +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright Nokia 2020 -# -# 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 - - -status = error -dest = err -name = PropertiesConfig - -property.filename = ./pmdictionary-validate.log - -filter.threshold.type = ThresholdFilter -filter.threshold.level = debug - -appender.console.type = Console -appender.console.name = STDOUT -appender.console.layout.type = PatternLayout -appender.console.layout.pattern = %m%n -appender.console.filter.threshold.type = ThresholdFilter -appender.console.filter.threshold.level = error - -appender.rolling.type = RollingFile -appender.rolling.name = RollingFile -appender.rolling.fileName = ${filename} -appender.rolling.filePattern = ./pmdictionary-validate.%d{yyyy-MM-dd-HH:mm:ss}.log -appender.rolling.layout.type = PatternLayout -appender.rolling.layout.pattern = %d %p %C{1.} [%t] %m%n -appender.rolling.policies.type = Policies -appender.rolling.policies.time.type = TimeBasedTriggeringPolicy -appender.rolling.policies.time.interval = 2 -appender.rolling.policies.time.modulate = true -appender.rolling.policies.size.type = SizeBasedTriggeringPolicy -appender.rolling.policies.size.size=5MB -appender.rolling.strategy.type = DefaultRolloverStrategy -appender.rolling.strategy.max = 5 - -logger.rolling.name = org.onap.validation -logger.rolling.level = debug -logger.rolling.additivity = false -logger.rolling.appenderRef.rolling.ref = RollingFile - -rootLogger.level = info -rootLogger.appenderRef.stdout.ref = STDOUT diff --git a/pmdictionaryvalidation/src/main/resources/open-cli-schema/pm-dictionary-validate.yaml b/pmdictionaryvalidation/src/main/resources/open-cli-schema/pm-dictionary-validate.yaml deleted file mode 100644 index b779361..0000000 --- a/pmdictionaryvalidation/src/main/resources/open-cli-schema/pm-dictionary-validate.yaml +++ /dev/null @@ -1,63 +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. - -open_cli_schema_version: 1.0 - -name: pm-dictionary-validate - -description: Validate PM Dictionary Yaml file - -info: - product: onap-honolulu - version: 1.0 - service: vnf-compliance - author: ONAP VTP Team onap-discuss@lists.onap.org - -parameters: - - name: yaml - description: Yaml file path - long_option: yaml - short_option: b - type: binary - is_optional: false - -results: - direction: portrait - attributes: - - name: file - description: PM Dictionary Yaml file - scope: short - type: string - - name: date - description: Validation date - scope: short - type: string - - name: platform - description: Platform used to test the reqs - scope: short - type: string - default_value: PM Dictionary Test Platform (VTP) 1.0 - - name: contact - description: Owner for this test case - scope: short - type: string - default_value: ONAP VTP Team onap-discuss@lists.onap.org - - name: criteria - description: Overall test reqs passed? PASS or FAILED - scope: short - type: string - - name: errors - description: All test cases errors - scope: short - type: json diff --git a/pmdictionaryvalidation/src/test/java/org/onap/functional/PmDictionaryValidateRuleFunctionalTest.java b/pmdictionaryvalidation/src/test/java/org/onap/functional/PmDictionaryValidateRuleFunctionalTest.java deleted file mode 100644 index fc212e7..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/functional/PmDictionaryValidateRuleFunctionalTest.java +++ /dev/null @@ -1,133 +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.functional; - -import org.junit.Test; -import org.onap.functional.util.OnapCliWrapper; -import org.onap.validation.rule.PMDictionaryValidate; -import org.onap.validation.rule.PMDictionaryValidateResponse; - -import java.net.URISyntaxException; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.onap.functional.util.ValidationUtility.OPERATION_STATUS_FAILED; -import static org.onap.functional.util.ValidationUtility.OPERATION_STATUS_PASS; -import static org.onap.functional.util.ValidationUtility.getCliCommandValidationResult; -import static org.onap.functional.util.ValidationUtility.verifyThatOperationFinishedWithError; -import static org.onap.functional.util.ValidationUtility.verifyThatOperationFinishedWithoutAnyError; - - -public class PmDictionaryValidateRuleFunctionalTest { - - - private static final String YAML_SCHEMA_SIMPLE_VALID_SCHEMA_YAML = "yaml_schema/Simple_Valid_Schema.yaml"; - private static final String NO_ERRORS = "[]"; - private static final String YAML_SCHEMA_PM_DICTIONARY_YAML = "yaml_schema/PM_Dictionary.yaml"; - private static final String PATH_TO_NON_EXITING_FILE_YAML = "path/to/nonExitingFile.yaml"; - private static final String NOT_YAML_FILE_TXT = "Not_Yaml_File.txt"; - - @Test - public void shouldSuccessfullyValidatePMDictionaryYamlFile() throws URISyntaxException { - // given - OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo(YAML_SCHEMA_SIMPLE_VALID_SCHEMA_YAML)); - - // when - cli.handle(); - - // then - final PMDictionaryValidateResponse result = getCliCommandValidationResult(cli, PMDictionaryValidateResponse.class); - - assertThat(result.getFile()).contains(YAML_SCHEMA_SIMPLE_VALID_SCHEMA_YAML); - assertThat(result.getPlatform()).contains(PMDictionaryValidateResponse.PLATFORM_VTP_1_0); - assertThat(result.getContact()).contains(PMDictionaryValidateResponse.ONAP_DISCUSS_LISTS_ONAP_ORG); - assertThat(result.getCriteria()).isEqualTo(OPERATION_STATUS_PASS); - assertThat(result.getErrors()).isEqualTo(NO_ERRORS); - verifyThatOperationFinishedWithoutAnyError(cli); - } - - @Test - public void shouldFailsWhenPMDictionaryYamlFileHasSomeErrors() throws URISyntaxException { - // given - OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo(YAML_SCHEMA_PM_DICTIONARY_YAML)); - - // when - cli.handle(); - - // then - final PMDictionaryValidateResponse result = getCliCommandValidationResult(cli, PMDictionaryValidateResponse.class); - - assertThat(result.getFile()).contains(YAML_SCHEMA_PM_DICTIONARY_YAML); - assertThat(result.getPlatform()).contains(PMDictionaryValidateResponse.PLATFORM_VTP_1_0); - assertThat(result.getContact()).contains(PMDictionaryValidateResponse.ONAP_DISCUSS_LISTS_ONAP_ORG); - assertThat(result.getCriteria()).isEqualTo(OPERATION_STATUS_FAILED); - final String errors = result.getErrors(); - assertThat(errors).contains( - "Value(s) is/are not in array of accepted values.", - "accepted value(s): [float, uint32, uint64]", - "Key not found: measChangeType", - "accepted value(s): [X, Y, Z]" - ); - verifyThatOperationFinishedWithoutAnyError(cli); - } - - @Test - public void shouldReportAnErrorWhenYamlFileDoesNotExist() { - // given - OnapCliWrapper cli = new OnapCliWrapper(new String[]{PATH_TO_NON_EXITING_FILE_YAML}); - - // when - cli.handle(); - - verifyThatOperationFinishedWithError(cli); - } - - - @Test - public void shouldReportThatValidationFailedWithInternalError() throws URISyntaxException { - // given - OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo(NOT_YAML_FILE_TXT)); - - // when - cli.handle(); - - // then - final PMDictionaryValidateResponse result = getCliCommandValidationResult(cli, PMDictionaryValidateResponse.class); - - assertThat(result.getFile()).contains(NOT_YAML_FILE_TXT); - assertThat(result.getPlatform()).contains(PMDictionaryValidateResponse.PLATFORM_VTP_1_0); - assertThat(result.getContact()).contains(PMDictionaryValidateResponse.ONAP_DISCUSS_LISTS_ONAP_ORG); - assertThat(result.getCriteria()).isEqualTo(OPERATION_STATUS_FAILED); - assertThat(result.getErrors()).contains("Provided yaml file has invalid structure!"); - verifyThatOperationFinishedWithoutAnyError(cli); - } - - - private String[] createPnfValidationRequestInfo(String yamlPath) throws URISyntaxException { - return new String[]{ - "--product", "onap-honolulu", - "pm-dictionary-validate", - "--format", "json", - "--yaml", absoluteFilePath(yamlPath) - }; - } - - - public static String absoluteFilePath(String relativeFilePath) throws URISyntaxException { - return PMDictionaryValidate.class.getClassLoader().getResource(relativeFilePath) - .toURI().getPath(); - } -} diff --git a/pmdictionaryvalidation/src/test/java/org/onap/functional/util/OnapCliWrapper.java b/pmdictionaryvalidation/src/test/java/org/onap/functional/util/OnapCliWrapper.java deleted file mode 100644 index 347a7bb..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/functional/util/OnapCliWrapper.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.functional.util; - - -import org.onap.cli.fw.cmd.OnapCommand; -import org.onap.cli.fw.error.OnapCommandException; -import org.onap.cli.fw.output.OnapCommandResult; -import org.onap.cli.main.OnapCli; - -public class OnapCliWrapper extends OnapCli { - - private OnapCommandResult commandResult; - - public OnapCliWrapper(String[] args) { - super(args); - } - - @Override - public void handleTracking(OnapCommand cmd) throws OnapCommandException { - super.handleTracking(cmd); - this.commandResult = cmd.getResult(); - } - - public OnapCommandResult getCommandResult() { - return this.commandResult; - } -} diff --git a/pmdictionaryvalidation/src/test/java/org/onap/functional/util/ValidationUtility.java b/pmdictionaryvalidation/src/test/java/org/onap/functional/util/ValidationUtility.java deleted file mode 100644 index 3a497f4..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/functional/util/ValidationUtility.java +++ /dev/null @@ -1,49 +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.functional.util; - -import com.google.gson.Gson; -import org.onap.cli.fw.output.OnapCommandResult; - - -import static org.assertj.core.api.Assertions.assertThat; - - -public final class ValidationUtility { - - private static final int NO_ERROR_CODE = 0; - public static final int ERROR_CODE = 1; - - private ValidationUtility(){} - - public static final String OPERATION_STATUS_PASS = "PASS"; - public static final String OPERATION_STATUS_FAILED = "FAILED"; - - public static T getCliCommandValidationResult(OnapCliWrapper cli, Class clazz) { - final OnapCommandResult onapCommandResult = cli.getCommandResult(); - final String json = onapCommandResult.getOutput().toString(); - return new Gson().fromJson(json, clazz); - } - - public static void verifyThatOperationFinishedWithoutAnyError(OnapCliWrapper cli) { - assertThat(cli.getExitCode()).isEqualTo(NO_ERROR_CODE); - } - - public static void verifyThatOperationFinishedWithError(OnapCliWrapper cli) { - assertThat(cli.getExitCode()).isEqualTo(ERROR_CODE); - } -} diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/cli/MainCITest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/cli/MainCITest.java deleted file mode 100644 index 307d388..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/validation/cli/MainCITest.java +++ /dev/null @@ -1,144 +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.cli; - - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.onap.validation.cli.command.validate.OutputFilePathGenerator; -import org.onap.validation.cli.command.validate.ResponseModel; -import org.onap.validation.cli.command.validate.ResponseStorage; -import org.onap.validation.cli.core.Cli; -import org.onap.validation.cli.core.CommandException; -import org.onap.validation.cli.core.Console; -import org.onap.validation.cli.command.validate.ToResponseModelConverter; -import org.onap.validation.yaml.YamlLoadingUtils; - -import java.io.IOException; -import java.nio.file.Path; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -@ExtendWith(MockitoExtension.class) -class MainCITest { - - public static final int JSON_RESPONSE_INDEX = 3; - public static final int OPERATION_INFO_MSG_INDEX = 5; - public static final int NO_ERROR = 0; - @Mock - private Console console; - @Mock - private ResponseStorage responseStorage; - private final OutputFilePathGenerator filePathGenerator = new OutputFilePathGenerator(); - - @Test - void shouldReportThatPathToFileWasNotProvided() { - // when - final int statusCode = Main.run(new String[0], console, responseStorage); - - // then - assertThat(statusCode).isEqualTo(Cli.INTERNAL_ERROR_STATUS_CODE); - final ArgumentCaptor exceptionCaptor = ArgumentCaptor.forClass(CommandException.class); - verify(console).error(exceptionCaptor.capture()); - verify(console).error(Cli.APPLICATION_INTERNAL_ERROR_MSG); - assertThat(exceptionCaptor.getValue().getMessage()).isEqualTo("Command argument is missing: provide a path to file"); - - } - - @Test - void shouldReportThatFileDoseNotExist() throws IOException { - // when - final String pathToYaml = "/path/to/nonExisting.yaml"; - final int statusCode = Main.run(new String[]{pathToYaml}, console, new ResponseStorage()); - - // then - assertThat(statusCode).isEqualTo(Cli.INTERNAL_ERROR_STATUS_CODE); - final ArgumentCaptor exceptionCaptor = ArgumentCaptor.forClass(CommandException.class); - verify(console).error(exceptionCaptor.capture()); - verify(console).error(Cli.APPLICATION_INTERNAL_ERROR_MSG); - assertThat(exceptionCaptor.getValue().getMessage()).isEqualTo("File '/path/to/nonExisting.yaml' does not exist!"); - verify(responseStorage, never()).store(eq(Path.of(pathToYaml)), anyString()); - } - - @Test - void shouldReportThatFileIsBroken() throws IOException { - // when - final String pathToFile = YamlLoadingUtils.getUrlForGivenPath("Not_Yaml_File.txt").getPath(); - final int statusCode = Main.run(new String[]{pathToFile}, console, new ResponseStorage()); - - // then - assertThat(statusCode).isEqualTo(Cli.INTERNAL_ERROR_STATUS_CODE); - final ArgumentCaptor exceptionCaptor = ArgumentCaptor.forClass(CommandException.class); - verify(console).error(exceptionCaptor.capture()); - verify(console).error(Cli.APPLICATION_INTERNAL_ERROR_MSG); - assertThat(exceptionCaptor.getValue().getMessage()).isEqualTo("Provided yaml file has invalid structure!"); - verify(responseStorage, never()).store(eq(Path.of(pathToFile)), anyString()); - } - - @Test - void shouldValidateProperYamlFile() throws IOException { - // when - final String path = YamlLoadingUtils.getUrlForGivenPath(YamlLoadingUtils.PATH_TO_SIMPLE_VALID_SCHEMA).getPath(); - final int statusCode = Main.run(new String[]{path}, console, responseStorage); - - // then - assertThat(statusCode).isEqualTo(Cli.PASS_STATUS_CODE); - assertThatResponseWasLoggedAtConsole( - path, - ResponseModel.ResponseStatus.PASS, - NO_ERROR - ); - } - - @Test - void shouldValidateYamlWithErrors() throws IOException { - // when - final String path = YamlLoadingUtils.getUrlForGivenPath(YamlLoadingUtils.PATH_TO_YAML_WITH_WRONG_VALUES).getPath(); - final int statusCode = Main.run(new String[]{path}, console, responseStorage); - - // then - assertThat(statusCode).isEqualTo(Cli.FAILED_STATUS_CODE); - assertThatResponseWasLoggedAtConsole( - path, - ResponseModel.ResponseStatus.FAILED, - 4 - ); - } - - private void assertThatResponseWasLoggedAtConsole(String pathToFile, ResponseModel.ResponseStatus responseStatus, int expectedErrors) throws IOException { - ArgumentCaptor consoleInfoCaptor = ArgumentCaptor.forClass(String.class); - verify(console, times(6)).info(consoleInfoCaptor.capture()); - final List allValues = consoleInfoCaptor.getAllValues(); - final String json = allValues.get(JSON_RESPONSE_INDEX); - final ResponseModel responseModel = ToResponseModelConverter.toModel(json); - assertThat(responseModel.getFile()).isEqualTo(pathToFile); - assertThat(responseModel.getStatus()).isEqualTo(responseStatus); - assertThat(responseModel.getErrors()).hasSize(expectedErrors); - assertThat(consoleInfoCaptor.getAllValues().get(OPERATION_INFO_MSG_INDEX)).isEqualTo(Cli.APPLICATION_EXIT_SUCCESSFULLY_MSG); - verify(responseStorage).store(eq(filePathGenerator.responsePathFor(Path.of(pathToFile))), eq(json)); - } - -} diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/OutputFilePathGeneratorTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/OutputFilePathGeneratorTest.java deleted file mode 100644 index b4d68b4..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/OutputFilePathGeneratorTest.java +++ /dev/null @@ -1,43 +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.cli.command.validate; - -import org.junit.jupiter.api.Test; - -import java.nio.file.Path; - -import static org.assertj.core.api.Assertions.assertThat; - - -class OutputFilePathGeneratorTest { - - private final OutputFilePathGenerator filePathGenerator = new OutputFilePathGenerator(); - - @Test - void shouldReturnPathToFileWithResponse() { - // given - final Path pathToYaml = Path.of("/some/path/PMDictionary.yaml"); - final Path expected = Path.of("/some/path/PMDictionary-validation-results.json"); - - // when - final Path actual = filePathGenerator.responsePathFor(pathToYaml); - - // then - assertThat(actual).isEqualTo(expected); - } - -} diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/ToJsonConverterTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/ToJsonConverterTest.java deleted file mode 100644 index 06a15bb..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/ToJsonConverterTest.java +++ /dev/null @@ -1,70 +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.cli.command.validate; - -import org.junit.jupiter.api.Test; -import org.onap.validation.yaml.error.YamlDocumentValidationError; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.onap.validation.cli.command.validate.ToResponseModelConverter.toModel; - - -class ToJsonConverterTest { - - private static final String PATH_TO_TEST_YAML = "/path/to/test.yaml"; - private final ToJsonConverter toJsonConverter = new ToJsonConverter(); - - @Test - void shouldConvertEmptyArray() { - // given - final ResponseModel responseModel = new ResponseModel(PATH_TO_TEST_YAML, - ResponseModel.ResponseStatus.PASS, - List.of()); - - // when - String json = toJsonConverter.convert(responseModel); - - // then - ResponseModel actual = toModel(json); - assertThat(actual.getFile()).isEqualTo(PATH_TO_TEST_YAML); - assertThat(actual.getStatus()).isEqualTo(ResponseModel.ResponseStatus.PASS); - assertThat(actual.getErrors()).isEmpty(); - } - - - @Test - void shouldConvertListOfErrors() { - // given - final ResponseModel responseModel = new ResponseModel(PATH_TO_TEST_YAML, - ResponseModel.ResponseStatus.FAILED, - List.of( - new YamlDocumentValidationError(1, PATH_TO_TEST_YAML, "error1"), - new YamlDocumentValidationError(2, PATH_TO_TEST_YAML, "error2"))); - - // when - String json = toJsonConverter.convert(responseModel); - - // then - - ResponseModel actual = toModel(json); - assertThat(actual.getFile()).isEqualTo(PATH_TO_TEST_YAML); - assertThat(actual.getStatus()).isEqualTo(ResponseModel.ResponseStatus.FAILED); - assertThat(actual.getErrors()).hasSize(2); - } -} diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/ValidateYamlCommandTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/ValidateYamlCommandTest.java deleted file mode 100644 index 44622db..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/validation/cli/command/validate/ValidateYamlCommandTest.java +++ /dev/null @@ -1,96 +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.cli.command.validate; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.junit.jupiter.MockitoExtension; -import org.onap.validation.cli.core.CommandException; -import org.onap.validation.cli.core.CommandResponse; -import org.onap.validation.yaml.YamlLoadingUtils; -import org.onap.validation.yaml.util.Args; - -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.cli.command.validate.ToResponseModelConverter.toModel; - -@ExtendWith(MockitoExtension.class) -class ValidateYamlCommandTest { - - private final ToJsonConverter toJsonConverter = new ToJsonConverter(); - private ValidatePmDictionaryYamlCommand validateYamlCommand; - - @BeforeEach - void setUp() { - this.validateYamlCommand = new ValidatePmDictionaryYamlCommand(toJsonConverter); - } - - @Test - void shouldReportAnErrorWhenFileDoesNotExist() { - // given - Args args = new Args(List.of("/invalid/filePath/toValidate.yaml")); - - // when - assertThatThrownBy(() -> validateYamlCommand.execute(args)).hasMessage("File '/invalid/filePath/toValidate.yaml' does not exist!"); - } - - @Test - void shouldReportAnErrorWhenPathToFileWasNotPass() { - // given - Args args = new Args(List.of()); - - // when - assertThatThrownBy(() -> validateYamlCommand.execute(args)).hasMessage("Command argument is missing: provide a path to file"); - } - - @Test - void shouldValidateFileWithoutAnyError() throws CommandException { - // given - final String path = YamlLoadingUtils.getUrlForGivenPath(YamlLoadingUtils.PATH_TO_SIMPLE_VALID_SCHEMA).getPath(); - Args args = new Args(List.of(path)); - - // when - final CommandResponse commandResponse = validateYamlCommand.execute(args); - - // then - assertThat(commandResponse.getCommandStatus()).isEqualTo(CommandResponse.CommandStatus.PASS); - ResponseModel actual = toModel(commandResponse.getResult()); - assertThat(actual.getFile()).isEqualTo(path); - assertThat(actual.getStatus()).isEqualTo(ResponseModel.ResponseStatus.PASS); - assertThat(actual.getErrors()).isEmpty(); - } - - @Test - void shouldReportThatFileHasSomeErrors() throws CommandException { - // given - final String path = YamlLoadingUtils.getUrlForGivenPath(YamlLoadingUtils.PATH_TO_YAML_WITH_WRONG_VALUES).getPath(); - Args args = new Args(List.of(path)); - - // when - final CommandResponse commandResponse = validateYamlCommand.execute(args); - - // then - assertThat(commandResponse.getCommandStatus()).isEqualTo(CommandResponse.CommandStatus.FAILED); - ResponseModel actual = toModel(commandResponse.getResult()); - assertThat(actual.getFile()).isEqualTo(path); - assertThat(actual.getStatus()).isEqualTo(ResponseModel.ResponseStatus.FAILED); - assertThat(actual.getErrors()).hasSize(4); - } -} diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/cli/core/CliTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/cli/core/CliTest.java deleted file mode 100644 index c8ad629..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/validation/cli/core/CliTest.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.cli.core; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; -import org.onap.validation.cli.command.validate.ResponseStorage; -import org.onap.validation.yaml.util.Args; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - - -@ExtendWith(MockitoExtension.class) -class CliTest { - @Mock - private Console console; - - @Mock - private ResponseStorage responseStorage; - - @Mock - private Command validationCommand; - - private Cli cli; - - @BeforeEach - void setUp() { - cli = new Cli<>(console, responseStorage); - } - - @Test - void shouldExecuteCommandWithoutAnyError() throws CommandException { - - // given - Args args = new Args(List.of()); - when(validationCommand.execute(args)).thenReturn( - new CommandResponse<>("{ 'errors': [] }", CommandResponse.CommandStatus.PASS) - ); - - // when - final int exitCode = cli.run(args, validationCommand); - - // then - assertThat(exitCode).isEqualTo(Cli.PASS_STATUS_CODE); - verify(console).info("{ 'errors': [] }"); - } - - @Test - void shouldHandleErrorReportedByCommand() throws CommandException { - - // given - Args args = new Args(List.of()); - final CommandException commandException = new CommandException("It should be reported"); - Mockito.doThrow(commandException).when(validationCommand).execute(args); - - // when - final int exitCode = cli.run(args, validationCommand); - - // then - assertThat(exitCode).isEqualTo(Cli.INTERNAL_ERROR_STATUS_CODE); - verify(console).error(commandException); - } - - @Test - void shouldHandleRuntimeException() throws CommandException { - - // given - Args args = new Args(List.of()); - final RuntimeException commandException = new RuntimeException(); - Mockito.doThrow(commandException).when(validationCommand).execute(args); - - // when - final int exitCode = cli.run(args, validationCommand); - - // then - assertThat(exitCode).isEqualTo(Cli.INTERNAL_ERROR_STATUS_CODE); - verify(console).error(commandException); - } -} diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlContentValidatorTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlContentValidatorTest.java deleted file mode 100644 index 1412085..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlContentValidatorTest.java +++ /dev/null @@ -1,164 +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.jupiter.api.Nested; -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.io.IOException; -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.PATH_TO_MULTI_DOCUMENT_INVALID_YAML; -import static org.onap.validation.yaml.YamlLoadingUtils.PATH_TO_VALID_JSON_STYLE_YAML; -import static org.onap.validation.yaml.YamlLoadingUtils.PATH_TO_YAML_WITH_WRONG_VALUES; -import static org.onap.validation.yaml.YamlLoadingUtils.readFile; - -class YamlContentValidatorTest { - - final YamlContentValidator yamlContentValidator = new YamlContentValidator(); - - @Nested - class FromStringPathValidator { - @Test - void shouldReturnCorrectErrorsWhenGivenPathToValidPmDictionaryFile() throws YamlProcessingException { - // given - String path = getFullPathForGivenResources(PATH_TO_YAML_WITH_WRONG_VALUES); - - // when - List validationErrors = new YamlContentValidator().validate(path); - - // then - assertValidationReturnedExpectedErrors(validationErrors); - } - - @Test - void shouldReturnCorrectErrorsWhenGivenPathToValidJsonStylePmDictionaryFile() throws YamlProcessingException { - // given - String path = getFullPathForGivenResources(PATH_TO_VALID_JSON_STYLE_YAML); - - // when - List validationErrors = new YamlContentValidator().validate(path); - - // then - assertValidationReturnedExpectedErrors(validationErrors); - } - - @Test - void shouldThrowErrorWhenGivenPathToInvalidPmDictionaryFile() { - // given - String path = getFullPathForGivenResources(PATH_TO_MULTI_DOCUMENT_INVALID_YAML); - - //when then - assertThatThrownBy(() -> yamlContentValidator.validate(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(() -> yamlContentValidator.validate(path)) - .isInstanceOf(YamlProcessingException.class) - .hasMessageContaining("PM_Dictionary YAML file is empty"); - } - } - - @Nested - class FromByteArrayValidator { - @Test - void shouldReturnCorrectErrorsWhenGivenPmDictionaryFileWithErrors() throws YamlProcessingException, IOException { - // given - byte[] yaml = readFile(PATH_TO_YAML_WITH_WRONG_VALUES); - - // when - List validationErrors = new YamlContentValidator().validate(yaml); - - // then - assertValidationReturnedExpectedErrors(validationErrors); - } - - @Test - void shouldReturnCorrectErrorsWhenGivenValidJsonStylePmDictionary() throws YamlProcessingException, IOException { - // given - byte[] yaml = readFile(PATH_TO_VALID_JSON_STYLE_YAML); - - // when - List validationErrors = new YamlContentValidator().validate(yaml); - - // then - assertValidationReturnedExpectedErrors(validationErrors); - } - - @Test - void shouldThrowErrorWhenGivenInvalidPmDictionary() throws IOException { - // given - byte[] yaml = readFile(PATH_TO_MULTI_DOCUMENT_INVALID_YAML); - - //when then - assertThatThrownBy(() -> new YamlContentValidator().validate(yaml)) - .isInstanceOf(ParserException.class) - .hasMessageContaining("expected the node content, but found ''"); - } - - @Test - void shouldThrowErrorWhenGivenEmptyPmDictionary() { - //when then - assertThatThrownBy(() -> new YamlContentValidator().validate(new byte[0])) - .isInstanceOf(YamlProcessingException.class) - .hasMessageContaining("PM_Dictionary YAML file is empty"); - } - } - - private void assertValidationReturnedExpectedErrors(List validationErrors) { - assertThat(validationErrors) - .isNotNull() - .hasSize(4) - .usingRecursiveFieldByFieldElementComparator() - .containsAll( - List.of( - 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]") - ) - ); - } - - 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 deleted file mode 100644 index 3e1f601..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java +++ /dev/null @@ -1,148 +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.jupiter.api.Nested; -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.io.IOException; -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)"; - - @Nested - class FromUrlLoader { - @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 shouldThrowExceptionWhenLoadingDocumentsFromInvalidYamlFile() { - // when then - assertThatThrownBy(YamlLoadingUtils::tryToLoadMultiDocumentInvalidYamlFile) - .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); - } - } - - @Nested - class FromStringPathLoader { - @Test - void shouldLoadAllDocumentsFromYamlFileUsingPathInString() throws YamlProcessingException { - // when - List documents = YamlLoadingUtils.loadValidMultiDocumentYamlFileUsingStringPath(); - - // then - assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS); - } - - @Test - void shouldThrowExceptionWhenLoadingDocumentsFromInvalidYamlFileUsingPathInString() { - // when then - assertThatThrownBy(YamlLoadingUtils::tryToLoadMultiDocumentInvalidYamlFileUsingStringPath) - .isInstanceOf(ParserException.class) - .hasMessageContaining("expected the node content, but found ''"); - } - } - - @Nested - class FromByteArrayLoader { - private final YamlLoader YAML_LOADER = new YamlLoader(new YamlDocumentFactory()); - - @Test - void shouldLoadAllDocumentsFromYamlFile() throws YamlDocumentFactory.YamlDocumentParsingException, IOException { - // when - List documents = YAML_LOADER.loadMultiDocumentYaml(YamlLoadingUtils.readFile(YamlLoadingUtils.PATH_TO_YAML_WITH_WRONG_VALUES)); - - // then - assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS); - } - - @Test - void shouldLoadAllDocumentsFromJsonStyleYamlFile() throws YamlDocumentFactory.YamlDocumentParsingException, IOException { - // when - List documents = YAML_LOADER.loadMultiDocumentYaml(YamlLoadingUtils.readFile(YamlLoadingUtils.PATH_TO_VALID_JSON_STYLE_YAML)); - - // then - assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS); - } - - @Test - void shouldThrowExceptionWhenLoadingDocumentsFromInvalidYamlFile() { - // when then - assertThatThrownBy(() -> YAML_LOADER.loadMultiDocumentYaml(YamlLoadingUtils.readFile(YamlLoadingUtils.PATH_TO_MULTI_DOCUMENT_INVALID_YAML))) - .isInstanceOf(ParserException.class) - .hasMessageContaining("expected the node content, but found ''"); - } - - @Test - void shouldThrowExceptionWhenLoadingInvalidYamlFileWithIncorrectKeyMapping() { - // when then - assertThatThrownBy(() -> YAML_LOADER.loadMultiDocumentYaml(YamlLoadingUtils.readFile(YamlLoadingUtils.PATH_TO_INVALID_YAML_WITH_INCORRECT_KEY_MAPPING))) - .isInstanceOf(ScannerException.class) - .hasMessageContaining("mapping values are not allowed here"); - } - - @Test - void shouldThrowExceptionWhenLoadingInvalidYamlFileWithUnknownEscapeCharacter() { - // when then - assertThatThrownBy(() -> YAML_LOADER.loadMultiDocumentYaml(YamlLoadingUtils.readFile(YamlLoadingUtils.PATH_TO_INVALID_YAML_WITH_UNKNOWN_ESCAPE_CHARACTER))) - .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 deleted file mode 100644 index dc1ce3b..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java +++ /dev/null @@ -1,104 +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 java.io.IOException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; - -import static org.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException; - -public final class YamlLoadingUtils { - - public static final YamlLoader YAML_LOADER = new YamlLoader(new YamlDocumentFactory()); - - 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; - public static final String PATH_TO_YAML_WITH_WRONG_VALUES = "yaml_schema/PM_Dictionary.yaml"; - public static final String PATH_TO_VALID_JSON_STYLE_YAML = "yaml_schema/PM_Dictionary_JSON_Style.yaml"; - public static final String PATH_TO_SIMPLE_VALID_SCHEMA = "yaml_schema/Simple_Valid_Schema.yaml"; - public static final String PATH_TO_SIMPLE_VALID_SCHEMA_MULTI_ROOT = "yaml_schema/Simple_Valid_Schema_Multi_Root.yaml"; - public static final String PATH_TO_SIMPLE_INVALID_SCHEMA = "yaml_schema/Simple_Invalid_Schema_Construction.yaml"; - public static final String PATH_TO_SIMPLE_INVALID_SCHEMA_FOR_LAZY_LOADING = "yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml"; - public static final String PATH_TO_MULTI_DOCUMENT_INVALID_YAML = "yaml_schema/Multi_Document_Invalid.yaml"; - public static final String PATH_TO_INVALID_YAML_WITH_INCORRECT_KEY_MAPPING = "yaml_schema/Simple_Invalid_Mapping_Value.yaml"; - public 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 YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_YAML_WITH_WRONG_VALUES)); - } - - public static List loadValidJsonStyleMultiDocumentYamlFile() throws YamlDocumentParsingException { - return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_VALID_JSON_STYLE_YAML)); - } - - public static List loadValidMultiDocumentYamlFileUsingStringPath() throws YamlProcessingException { - return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_YAML_WITH_WRONG_VALUES).getPath()); - } - - public static YamlDocument loadSimpleValidYamlSchemaFile() throws YamlDocumentParsingException { - return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_VALID_SCHEMA)).get(0); - } - - public static YamlDocument loadSimpleInvalidYamlSchemaFile() throws YamlDocumentParsingException { - return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_INVALID_SCHEMA)).get(0); - } - - public static YamlDocument loadSimpleInvalidYamlSchemaForLazyLoadingFile() throws YamlDocumentParsingException { - return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_INVALID_SCHEMA_FOR_LAZY_LOADING)).get(0); - } - - public static YamlDocument loadSimpleValidYamlSchemaWithMultiRootFile() throws YamlDocumentParsingException { - return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_VALID_SCHEMA_MULTI_ROOT)).get(0); - } - - public static List tryToLoadMultiDocumentInvalidYamlFile() throws YamlDocumentParsingException { - return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_MULTI_DOCUMENT_INVALID_YAML)); - } - - public static List tryToLoadMultiDocumentInvalidYamlFileUsingStringPath() throws YamlProcessingException { - return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_MULTI_DOCUMENT_INVALID_YAML).getPath()); - } - - public static List tryToLoadInvalidYamlFileWithIncorrectKeyMapping() throws YamlDocumentParsingException { - return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_INVALID_YAML_WITH_INCORRECT_KEY_MAPPING)); - } - - public static List tryToLoadInvalidYamlFileWithUnknownEscapeCharacter() throws YamlDocumentParsingException { - return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_INVALID_YAML_WITH_UNKNOWN_ESCAPE_CHARACTER)); - } - - public static byte[] readFile(String path) throws IOException { - String file = getUrlForGivenPath(path).getFile(); - return Files.readAllBytes(Path.of(file)); - } - - public 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 deleted file mode 100644 index 3d993f8..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java +++ /dev/null @@ -1,115 +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.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(List.of( - 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)).isEmpty(); - } - -} diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java deleted file mode 100644 index d7d1153..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java +++ /dev/null @@ -1,130 +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.junit.jupiter.api.Test; - -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; -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 - assertYamlDocument(document, inputMap); - } - - @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 - assertYamlDocument(document, inputMap); - } - - @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 - assertYamlDocument(document, inputMap); - } - - @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 - Throwable ex = catchThrowable(() -> document.getSubStructure("test")); - - // then - assertYamlDocumentParsingException(ex, testList); - } - - @Test - void shouldThrowExceptionIfGetSubStructureIsCalledOnString() - throws YamlDocumentParsingException { - // given - Map inputMap = Collections.singletonMap("test", "testElement"); - YamlDocument document = new YamlDocumentFactory().createYamlDocument(inputMap); - - // when - Throwable ex = catchThrowable(() -> document.getSubStructure("test")); - - // then - assertYamlDocumentParsingException(ex, "testElement"); - } - - private void assertYamlDocument(YamlDocument document, Map inputMap) { - assertThat(document).isNotNull(); - assertThat(document.getYaml()).containsExactlyEntriesOf(mapKeyToString(inputMap)); - } - - private Map mapKeyToString(Map inputMap) { - return inputMap.entrySet().stream() - .collect(Collectors.toMap(w -> w.getKey().toString(), Map.Entry::getValue)); - } - - private void assertYamlDocumentParsingException(Throwable ex, Object unparsed) { - assertThat(ex) - .isInstanceOf(YamlDocumentParsingException.class) - .hasMessageContaining(String.format("Fail to parse given objects: %s as yaml document.", unparsed)); - } -} diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java deleted file mode 100644 index ab6f882..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java +++ /dev/null @@ -1,85 +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.junit.jupiter.api.Test; - -import java.util.Collections; -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 testList = List.of("test1", 3, 23.45, 'a', "test2"); - - // when - YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testList); - - // then - assertYamlParametersList(parametersList, testList); - } - - @Test - void shouldCreateParametersListContainingStringsFromListContainingVariousTypes() { - // given - List testList = List.of("test1", 3, List.of(2, 3, 4), "test2"); - - // when - YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testList); - - // then - assertYamlParametersList(parametersList, testList); - } - - @Test - void shouldCreateListWithOneStringWhenGivenObjectIsNotList() { - // given - Object testObject = "test"; - - // when - YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testObject); - - // then - assertYamlParametersList(parametersList, Collections.singletonList(testObject)); - } - - private void assertYamlParametersList(YamlParametersList parametersList, List testList) { - assertThat(parametersList).isNotNull(); - assertThat(parametersList.getParameters()) - .containsExactly(mapToStrings(testList)); - } - - private String[] mapToStrings(List elements) { - return elements.stream().map(Object::toString).toArray(String[]::new); - } - -} diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java deleted file mode 100644 index 5c9d8e5..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java +++ /dev/null @@ -1,100 +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.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.catchThrowable; -import static org.onap.validation.yaml.YamlLoadingUtils.VALID_YAML_DOCUMENT_INDEX; -import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX; -import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX; - -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 - Throwable ex = catchThrowable(() -> new YamlValidationProcess(schema, document).validate()); - - // then - assertThat(ex) - .isInstanceOf(YamlProcessingException.class) - .hasMessageContaining("Lazy loading failed, due to yaml parsing exception."); - } -} diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java deleted file mode 100644 index efc304c..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java +++ /dev/null @@ -1,115 +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.jupiter.api.Disabled; -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()) - .extracting(YamlSchemaNode::getName) - .containsExactly("root1", "root2", "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 deleted file mode 100644 index 646b8a2..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java +++ /dev/null @@ -1,147 +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.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.catchThrowable; -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 - Throwable ex = catchThrowable(node::getNextNodes); - - // then - assertThat(ex) - .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 = List.of("val1", "val2"); - Map nodeInYamlFormat = Map.of( - YamlSchemaNodeFactory.PRESENCE_KEY, YamlSchemaNodeFactory.PRESENCE_REQUIRED_KEY, - YamlSchemaNodeFactory.COMMENT_KEY, comment, - 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[0]) - ); - } - - @Test - void shouldCreateBranchNodeIfGivenYamlDocumentHaveSubStructure() - throws YamlProcessingException { - // given - String nodeName = "branch_test"; - String comment = "test branch node"; - - String subNode1Name = "branch_test_node1"; - String subNode2Name = "branch_test_node2"; - - Map subStructure = Map.of( - subNode1Name, new HashMap<>(), - subNode2Name, new HashMap<>()); - - Map nodeInYamlFormat = Map.of( - YamlSchemaNodeFactory.PRESENCE_KEY, YamlSchemaNodeFactory.PRESENCE_REQUIRED_KEY, - YamlSchemaNodeFactory.COMMENT_KEY, comment, - 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/java/org/onap/validation/yaml/util/ArgsTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/util/ArgsTest.java deleted file mode 100644 index 0090683..0000000 --- a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/util/ArgsTest.java +++ /dev/null @@ -1,39 +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.util; - -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.List; - -class ArgsTest { - - @Test - void shouldThrowAnExceptionWhenArgIsNotAvailable() { - Args args = new Args(List.of()); - Assertions.assertThatThrownBy(() -> args.getArg(0)).hasMessage("Argument with index 0 is not available!"); - } - - @Test - void shouldReturnArgumentForGivenIndex() { - Args args = new Args(List.of("one","two", "three")); - Assertions.assertThat(args.getArg(0)).isEqualTo("one"); - Assertions.assertThat(args.getArg(1)).isEqualTo("two"); - Assertions.assertThat(args.getArg(2)).isEqualTo("three"); - } -} diff --git a/pmdictionaryvalidation/src/test/resources/Not_Yaml_File.txt b/pmdictionaryvalidation/src/test/resources/Not_Yaml_File.txt deleted file mode 100644 index be6ee44..0000000 --- a/pmdictionaryvalidation/src/test/resources/Not_Yaml_File.txt +++ /dev/null @@ -1 +0,0 @@ -Not a Yaml file! diff --git a/pmdictionaryvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml deleted file mode 100644 index aab34fa..0000000 --- a/pmdictionaryvalidation/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/pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml deleted file mode 100644 index 12a4af9..0000000 --- a/pmdictionaryvalidation/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/pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml deleted file mode 100644 index f4cbddf..0000000 --- a/pmdictionaryvalidation/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/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml deleted file mode 100644 index 25c72cd..0000000 --- a/pmdictionaryvalidation/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/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml deleted file mode 100644 index c5e7b7c..0000000 --- a/pmdictionaryvalidation/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/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml deleted file mode 100644 index 7f9f946..0000000 --- a/pmdictionaryvalidation/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/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml deleted file mode 100644 index 2cac9e6..0000000 --- a/pmdictionaryvalidation/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/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml deleted file mode 100644 index a125b13..0000000 --- a/pmdictionaryvalidation/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/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 deleted file mode 100644 index d73ca4f..0000000 --- a/pmdictionaryvalidation/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/pom.xml b/pom.xml index 56a65d6..1415928 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ csarvalidation deployment - pmdictionaryvalidation + dictionaryvalidation -- cgit 1.2.3-korg