summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Changelog.md8
-rw-r--r--cnf-conformance/README.md7
-rw-r--r--cnf-conformance/cnf-conformance-check.yaml44
-rw-r--r--cnf-conformance/run.sh25
-rw-r--r--csarvalidation/README.md18
-rw-r--r--csarvalidation/pom.xml75
-rwxr-xr-xcsarvalidation/python/main/generate_active_validation_rules_table.py65
-rw-r--r--csarvalidation/python/main/validation/FileManager.py37
-rw-r--r--csarvalidation/python/main/validation/__init__.py0
-rw-r--r--csarvalidation/python/main/validation/rules/ActiveRulesTableGenerator.py70
-rw-r--r--csarvalidation/python/main/validation/rules/__init__.py0
-rw-r--r--csarvalidation/python/main/validation/rules/providers/ActiveRulesProvider.py43
-rw-r--r--csarvalidation/python/main/validation/rules/providers/RulesDescriptionsProvider.py40
-rw-r--r--csarvalidation/python/main/validation/rules/providers/__init__.py0
-rw-r--r--csarvalidation/python/main/validation/rules/table/ActiveRuleEntity.py24
-rw-r--r--csarvalidation/python/main/validation/rules/table/ActiveRulesTable.py37
-rw-r--r--csarvalidation/python/main/validation/rules/table/__init__.py0
-rw-r--r--csarvalidation/python/requirements.txt1
-rw-r--r--csarvalidation/python/setup.py30
-rw-r--r--csarvalidation/python/test/__init__.py0
-rw-r--r--csarvalidation/python/test/test_ActiveRulesTableGenerator.py78
-rw-r--r--csarvalidation/python/test/test_FileManager.py95
-rw-r--r--csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745.java4
-rw-r--r--csarvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java117
-rw-r--r--csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java99
-rw-r--r--csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java94
-rw-r--r--csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java154
-rw-r--r--deployment/pom.xml2
-rw-r--r--pmdictionaryvalidation/README.md26
-rw-r--r--pmdictionaryvalidation/pom.xml71
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlContentValidator.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/YamlFileValidator.java)35
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java)43
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java)2
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java)0
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java)0
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java)0
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java)0
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java)0
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java)0
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java)0
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java)2
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java)0
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java)0
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java)0
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java)8
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java)0
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java)0
-rw-r--r--pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java (renamed from csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java)0
-rw-r--r--pmdictionaryvalidation/src/main/resources/log4j2.properties48
-rw-r--r--pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlContentValidatorTest.java161
-rw-r--r--pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java148
-rw-r--r--pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java104
-rw-r--r--pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java (renamed from csarvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java)96
-rw-r--r--pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java130
-rw-r--r--pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java (renamed from csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java)38
-rw-r--r--pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java (renamed from csarvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java)47
-rw-r--r--pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java (renamed from csarvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java)71
-rw-r--r--pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java (renamed from csarvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java)90
-rw-r--r--pmdictionaryvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml (renamed from csarvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml)0
-rw-r--r--pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml (renamed from csarvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml)0
-rw-r--r--pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml (renamed from csarvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml)0
-rw-r--r--pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml (renamed from csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml)0
-rw-r--r--pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml (renamed from csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml)0
-rw-r--r--pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml (renamed from csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml)0
-rw-r--r--pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml (renamed from csarvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml)0
-rw-r--r--pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml (renamed from csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml)0
-rw-r--r--pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml (renamed from csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml)0
-rw-r--r--pom.xml4
-rw-r--r--releases/1.2.15-maven.yaml5
-rw-r--r--version.properties2
71 files changed, 1616 insertions, 683 deletions
diff --git a/.gitignore b/.gitignore
index c055876..4b30e3b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,4 @@ coverage-report/
*.log
.idea
.attach_pid*
+**/__pycache__/*
diff --git a/Changelog.md b/Changelog.md
index 8bf5b52..001e931 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -104,3 +104,11 @@ All notable changes to this project will be documented in this file.
- https://jira.onap.org/browse/VNFSDK-660
## [1.2.15]
+
+## Move
+- Extract pm-dictionary validation to separate module
+ - https://jira.onap.org/browse/VNFSDK-713
+- Added possibility to validation pm-dictionary from byte array
+ - https://jira.onap.org/browse/VNFSDK-713
+
+## [1.2.16]
diff --git a/cnf-conformance/README.md b/cnf-conformance/README.md
new file mode 100644
index 0000000..cda3dee
--- /dev/null
+++ b/cnf-conformance/README.md
@@ -0,0 +1,7 @@
+Integratation of CNF coformacne tool with VTP:
+
+To enable this integration,
+1. Copy the run.sh under VTP OCOMP bin dir
+2. copy the cnf-conformance-check.yaml under VTP OCOMP open-cli-home dir
+3. Run OCOMP schema-refresh command to enable this test case in VTP
+
diff --git a/cnf-conformance/cnf-conformance-check.yaml b/cnf-conformance/cnf-conformance-check.yaml
new file mode 100644
index 0000000..8ca9376
--- /dev/null
+++ b/cnf-conformance/cnf-conformance-check.yaml
@@ -0,0 +1,44 @@
+# Copyright 2020 Huawei Technologies Co., Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+open_cli_schema_version: 1.0
+name: cnf-conformance-check
+description: |
+ Cnf-conformance sample command.
+info:
+ product: ovp-2.0
+ service: cnf-conformance
+ author: kanagaraj.manickam@huawei.com
+
+parameters:
+ - name: config-path
+ description: Location to cnf-config file
+ type: string
+ short_option: c
+ long_option: cnf-config
+ is_optional: false
+ - name: format
+ type: string
+ description: Output format
+ short_option: f
+ long_option: format
+ default_value: text
+ is_default_param: true
+
+cmd:
+ command:
+ - $s{env:OPEN_CLI_HOME}/bin/run.sh ${config-path}
+ success_codes:
+ - 0
+ output: $stdout
diff --git a/cnf-conformance/run.sh b/cnf-conformance/run.sh
new file mode 100644
index 0000000..aa55f4c
--- /dev/null
+++ b/cnf-conformance/run.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+# Copyright (C) 2020, Huawei Technologies, Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#Helps to run cnf-conformance test cases.
+#Follow the guidelines detailed in https://github.com/cncf/cnf-conformance
+
+# Arg-1: CNF dir where the cnf-conformance.yml is placed
+
+cd $1
+
+cnf-conformance setup > setup.txt
+cnf-conformance all cnf-config=./cnf-conformance.yml > all.txt
+
+cat setup.txt
+cat all.txt
diff --git a/csarvalidation/README.md b/csarvalidation/README.md
index d940d1d..65c12fb 100644
--- a/csarvalidation/README.md
+++ b/csarvalidation/README.md
@@ -77,7 +77,14 @@ How to configure vnfreqs.properties
How to run CSAR validation
--------------------------
-Follow the setups given below to run as csar-validate command
+Follow the setups given below to run as csar-validate command.
+
+<u><b>Warning !!!</b>
+Be default, during project building, documentation generation is being disabled
+(see point "Documentation generation" for more details).</u>
+In order to enable this process, add parameter `-DskipDocsGeneration=false` to mvn command, example:
+`mvn clean package -DskipDocsGeneration=false`
+
1. Install OCLIP (`wget -O - https://raw.githubusercontent.com/onap/cli/master/deployment/zip/installer/install-latest.sh | sh`)
@@ -85,6 +92,13 @@ Follow the setups given below to run as csar-validate command
3. Run `oclip --product onap-vtp csar-validate --csar <CSAR path>`
+Documentation generation
+--------------------------
+During project build, automated generation of tables, containing supported rules, is being performed.
+Created tables are being saved in target directory, `target/generated-docs/{current_release}`.
+This generation is being performed by `exec-maven-plugin`, defined in pom.xml.
+In order to generate tables <b>python3 and pip3 are required</b>.
+
Contact
-------
-Kanagaraj.Manickam@huawei.com \ No newline at end of file
+Kanagaraj.Manickam@huawei.com
diff --git a/csarvalidation/pom.xml b/csarvalidation/pom.xml
index 729c82d..13b4245 100644
--- a/csarvalidation/pom.xml
+++ b/csarvalidation/pom.xml
@@ -14,7 +14,7 @@
<parent>
<groupId>org.onap.vnfsdk.validation</groupId>
<artifactId>validation</artifactId>
- <version>1.2.15-SNAPSHOT</version>
+ <version>1.2.16-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>validation-csar</artifactId>
@@ -50,6 +50,8 @@
<maven-war-plugin.version>2.6</maven-war-plugin.version>
<maven-dependency-plugin.version>3.0.0</maven-dependency-plugin.version>
<mockito-core.version>3.5.0</mockito-core.version>
+ <exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
+ <skipDocsGeneration>true</skipDocsGeneration>
</properties>
<dependencies>
@@ -106,6 +108,11 @@
</exclusions>
</dependency>
<dependency>
+ <groupId>org.onap.vnfsdk.validation</groupId>
+ <artifactId>validation-pmdictionary</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.14</version>
@@ -160,8 +167,72 @@
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
-
<plugins>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>${exec-maven-plugin.version}</version>
+ <executions>
+ <execution>
+ <configuration>
+ <skip>${skipDocsGeneration}</skip>
+ <executable>pip3</executable>
+ <workingDirectory>./python</workingDirectory>
+ <arguments>
+ <argument>install</argument>
+ <argument>-r</argument>
+ <argument>./requirements.txt</argument>
+ </arguments>
+ </configuration>
+ <id>python-requirements</id>
+ <phase>initialize</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ </execution>
+ <execution>
+ <configuration>
+ <skip>${skipDocsGeneration}</skip>
+ <executable>python3</executable>
+ <workingDirectory>./python/</workingDirectory>
+ <environmentVariables>
+ <PYTHONPATH>./main</PYTHONPATH>
+ </environmentVariables>
+ <arguments>
+ <argument>-m</argument>
+ <argument>unittest</argument>
+ <argument>discover</argument>
+ <argument>./test</argument>
+ </arguments>
+ </configuration>
+ <id>python-test</id>
+ <phase>test</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ </execution>
+ <execution>
+ <configuration>
+ <skip>${skipDocsGeneration}</skip>
+ <executable>python3</executable>
+ <workingDirectory>./python/main</workingDirectory>
+ <arguments>
+ <argument>generate_active_validation_rules_table.py</argument>
+ </arguments>
+ <environmentVariables>
+ <OUTPUT_DIRECTORY>${project.build.directory}/generated-docs/${onap.release}/</OUTPUT_DIRECTORY>
+ </environmentVariables>
+ </configuration>
+ <id>python_build</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
diff --git a/csarvalidation/python/main/generate_active_validation_rules_table.py b/csarvalidation/python/main/generate_active_validation_rules_table.py
new file mode 100755
index 0000000..8367e44
--- /dev/null
+++ b/csarvalidation/python/main/generate_active_validation_rules_table.py
@@ -0,0 +1,65 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# 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.
+# ============LICENSE_END=====================================
+
+import os
+
+from validation.FileManager import FileManager
+from validation.rules.ActiveRulesTableGenerator import ActiveRulesTableGenerator
+
+from validation.rules.providers.ActiveRulesProvider import ActiveRulesProvider
+from validation.rules.providers.RulesDescriptionsProvider import RulesDescriptionsProvider
+
+RESOURCES_DIRECTORY = '../../src/main/resources/'
+RULE_DESCRIPTION_SOL001_PATH = RESOURCES_DIRECTORY + 'open-cli-schema/sol001/'
+RULE_DESCRIPTION_SOL004_PATH = RESOURCES_DIRECTORY + 'open-cli-schema/sol004/'
+VNFREWS_PROPERTIES_PATH = RESOURCES_DIRECTORY + 'vnfreqs.properties'
+RULE_DESCRIPTION_FILE_NAME_PATTERN = 'vtp-validate-csar-%s.yaml'
+
+DEFAULT_OUTPUT_DIRECTORY = RESOURCES_DIRECTORY + 'generated/active-validation-rules/'
+
+VNF_REQS_TAG = "vnfreqs"
+PNF_REQS_TAG = "pnfreqs"
+
+def main():
+ output_directory = get_output_directory()
+ table_with_vnf_rules = output_directory + 'VnfActiveRulesTable.csv'
+ table_with_pnf_rules = output_directory + 'PnfActiveRulesTable.csv'
+ requs_tags = [VNF_REQS_TAG, PNF_REQS_TAG]
+
+ tables = ActiveRulesTableGenerator(
+ [
+ RulesDescriptionsProvider(RULE_DESCRIPTION_SOL001_PATH, RULE_DESCRIPTION_FILE_NAME_PATTERN),
+ RulesDescriptionsProvider(RULE_DESCRIPTION_SOL004_PATH, RULE_DESCRIPTION_FILE_NAME_PATTERN)
+ ],
+ ActiveRulesProvider(VNFREWS_PROPERTIES_PATH)
+ ).generate_active_validation_rule_tables(requs_tags)
+ file_manager = FileManager(output_directory)
+ file_manager.save_rule_table(tables[0].get_table_in_csv_format(), table_with_vnf_rules)
+ file_manager.save_rule_table(tables[1].get_table_in_csv_format(), table_with_pnf_rules)
+
+
+def get_output_directory():
+ if 'OUTPUT_DIRECTORY' in os.environ:
+ output_directory = os.getenv('OUTPUT_DIRECTORY')
+ else:
+ output_directory = DEFAULT_OUTPUT_DIRECTORY
+ return output_directory
+
+
+if __name__ == '__main__':
+ main()
diff --git a/csarvalidation/python/main/validation/FileManager.py b/csarvalidation/python/main/validation/FileManager.py
new file mode 100644
index 0000000..2cdaab5
--- /dev/null
+++ b/csarvalidation/python/main/validation/FileManager.py
@@ -0,0 +1,37 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# 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.
+# ============LICENSE_END=====================================
+
+import os
+
+
+class FileManager:
+
+ def __init__(self, output_directory: str):
+ self._output_directory = output_directory
+
+ def save_rule_table(self, csv_table: str, table_name: str):
+ self._create_output_directory()
+ self._write_rules_to_file(csv_table, table_name)
+
+ def _create_output_directory(self):
+ if not os.path.isdir(self._output_directory):
+ os.makedirs(self._output_directory)
+
+ def _write_rules_to_file(self, csv_table: str, file_name: str):
+ with open(file_name, 'w') as vnf_rules_file:
+ vnf_rules_file.write(csv_table)
diff --git a/csarvalidation/python/main/validation/__init__.py b/csarvalidation/python/main/validation/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/csarvalidation/python/main/validation/__init__.py
diff --git a/csarvalidation/python/main/validation/rules/ActiveRulesTableGenerator.py b/csarvalidation/python/main/validation/rules/ActiveRulesTableGenerator.py
new file mode 100644
index 0000000..c8a0f37
--- /dev/null
+++ b/csarvalidation/python/main/validation/rules/ActiveRulesTableGenerator.py
@@ -0,0 +1,70 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# 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.
+# ============LICENSE_END=====================================
+
+from validation.rules.providers.ActiveRulesProvider import ActiveRulesProvider
+
+from validation.rules.table.ActiveRuleEntity import ActiveRuleEntity
+from validation.rules.table.ActiveRulesTable import ActiveRulesTable
+
+
+class ActiveRulesTableGenerator:
+
+ def __init__(self,
+ rules_descriptions_providers: list,
+ active_rules_provider: ActiveRulesProvider
+ ):
+ self._rules_descriptions = rules_descriptions_providers
+ self._active_rules = active_rules_provider
+
+ def generate_active_validation_rule_tables(self, reqs_tags: list) -> list:
+ tables = []
+ for reqs_tag in reqs_tags:
+ tables.append(
+ self._create_rules_table(reqs_tag)
+ )
+ return tables
+
+ def _create_rules_table(self, reqs_tag: str) -> ActiveRulesTable:
+ active_rules_table = ActiveRulesTable()
+ active_rules = self._active_rules.get_active_rules(reqs_tag)
+ for rule in active_rules:
+ yaml_description = self._get_rule_description(rule)
+ active_rules_table.add_entity(
+ ActiveRuleEntity(
+ rule,
+ self._get_description_from_yaml(yaml_description),
+ self._get_product_from_yaml(yaml_description)
+ )
+ )
+ return active_rules_table
+
+ def _get_rule_description(self, rule: str) -> dict:
+ yaml_description = ""
+ for rules_description in self._rules_descriptions:
+ if rules_description.contains_rule(rule):
+ yaml_description = rules_description.get_rule_description(rule)
+ break
+ return yaml_description
+
+ @staticmethod
+ def _get_description_from_yaml(yaml_file: dict) -> str:
+ return yaml_file['description'].replace("\n", " ")
+
+ @staticmethod
+ def _get_product_from_yaml(yaml_file: dict) -> str:
+ return yaml_file['info']['product']
diff --git a/csarvalidation/python/main/validation/rules/__init__.py b/csarvalidation/python/main/validation/rules/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/csarvalidation/python/main/validation/rules/__init__.py
diff --git a/csarvalidation/python/main/validation/rules/providers/ActiveRulesProvider.py b/csarvalidation/python/main/validation/rules/providers/ActiveRulesProvider.py
new file mode 100644
index 0000000..1d601f2
--- /dev/null
+++ b/csarvalidation/python/main/validation/rules/providers/ActiveRulesProvider.py
@@ -0,0 +1,43 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# 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.
+# ============LICENSE_END=====================================
+
+class ActiveRulesProvider:
+
+ def __init__(self, properties_file_path: str, rules_separator: str = ",", key_value_separator: str = "="):
+ self.properties_file_path = properties_file_path
+ self._rules_separator = rules_separator
+ self._key_value_separator = key_value_separator
+
+ def get_active_rules(self, reqs: str) -> list:
+ active_rules = []
+ for line in self._load_file_by_lines():
+ if line.startswith(reqs):
+ active_rules = self._split_properties_line(line, self._rules_separator, self._key_value_separator)
+ break
+ return active_rules
+
+ def _load_file_by_lines(self) -> list:
+ with open(self.properties_file_path, 'r') as properties_file:
+ lines = properties_file.read().splitlines()
+ return lines
+
+ @staticmethod
+ def _split_properties_line(line: str, splitter: str, key_value_separator: str) -> list:
+ key_value_separation_index = line.index(key_value_separator) + 1
+ value = line[key_value_separation_index:]
+ return value.split(splitter)
diff --git a/csarvalidation/python/main/validation/rules/providers/RulesDescriptionsProvider.py b/csarvalidation/python/main/validation/rules/providers/RulesDescriptionsProvider.py
new file mode 100644
index 0000000..a34bbe3
--- /dev/null
+++ b/csarvalidation/python/main/validation/rules/providers/RulesDescriptionsProvider.py
@@ -0,0 +1,40 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# 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.
+# ============LICENSE_END=====================================
+
+import os
+import yaml
+
+
+class RulesDescriptionsProvider:
+
+ def __init__(self, directory_containing_rules: str, rule_description_file_name_pattern: str):
+ self._directory_containing_rules = directory_containing_rules
+ self._rule_description_file_name_pattern = rule_description_file_name_pattern
+
+ def contains_rule(self, rule: str) -> bool:
+ description_file_name = self._rule_description_file_name_pattern % rule
+ return os.path.isfile(self._directory_containing_rules + description_file_name)
+
+ def get_rule_description(self, rule: str) -> str:
+ description_file_name = self._rule_description_file_name_pattern % rule
+ return self._get_yaml_description(description_file_name)
+
+ def _get_yaml_description(self, yaml_file: str) -> str:
+ with open(self._directory_containing_rules + yaml_file, 'r') as description_file:
+ description_yaml = yaml.load(description_file, Loader=yaml.FullLoader)
+ return description_yaml
diff --git a/csarvalidation/python/main/validation/rules/providers/__init__.py b/csarvalidation/python/main/validation/rules/providers/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/csarvalidation/python/main/validation/rules/providers/__init__.py
diff --git a/csarvalidation/python/main/validation/rules/table/ActiveRuleEntity.py b/csarvalidation/python/main/validation/rules/table/ActiveRuleEntity.py
new file mode 100644
index 0000000..ed8c7d5
--- /dev/null
+++ b/csarvalidation/python/main/validation/rules/table/ActiveRuleEntity.py
@@ -0,0 +1,24 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# 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.
+# ============LICENSE_END=====================================
+
+class ActiveRuleEntity:
+
+ def __init__(self, rule, description, product):
+ self.rule = rule
+ self.description = description
+ self.product = product
diff --git a/csarvalidation/python/main/validation/rules/table/ActiveRulesTable.py b/csarvalidation/python/main/validation/rules/table/ActiveRulesTable.py
new file mode 100644
index 0000000..70bb10d
--- /dev/null
+++ b/csarvalidation/python/main/validation/rules/table/ActiveRulesTable.py
@@ -0,0 +1,37 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# 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.
+# ============LICENSE_END=====================================
+
+from validation.rules.table.ActiveRuleEntity import ActiveRuleEntity
+
+
+class ActiveRulesTable:
+
+ def __init__(self):
+ self._active_rules_entities = []
+
+ def add_entity(self, active_rule_entity: ActiveRuleEntity):
+ self._active_rules_entities.append(active_rule_entity)
+
+ def get_table_in_csv_format(self, values_separator=";", entity_separator="\n") -> str:
+ csv_table = ""
+ for entity in self._active_rules_entities:
+ csv_table += \
+ entity.product + values_separator + \
+ entity.rule + values_separator + \
+ entity.description + entity_separator
+ return csv_table
diff --git a/csarvalidation/python/main/validation/rules/table/__init__.py b/csarvalidation/python/main/validation/rules/table/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/csarvalidation/python/main/validation/rules/table/__init__.py
diff --git a/csarvalidation/python/requirements.txt b/csarvalidation/python/requirements.txt
new file mode 100644
index 0000000..7a997b5
--- /dev/null
+++ b/csarvalidation/python/requirements.txt
@@ -0,0 +1 @@
+PyYAML==5.3.1
diff --git a/csarvalidation/python/setup.py b/csarvalidation/python/setup.py
new file mode 100644
index 0000000..060d45c
--- /dev/null
+++ b/csarvalidation/python/setup.py
@@ -0,0 +1,30 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# 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.
+# ============LICENSE_END=====================================
+
+from setuptools import setup
+
+with open('requirements.txt') as f:
+ required = f.read().splitlines()
+
+setup(
+ name='Active rules table generator',
+ version='1.0',
+ description='This project allow generation of tables containing rules that are active for given vnfsdk/validation release.',
+ packages=['main.validation'],
+ install_requires=required
+)
diff --git a/csarvalidation/python/test/__init__.py b/csarvalidation/python/test/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/csarvalidation/python/test/__init__.py
diff --git a/csarvalidation/python/test/test_ActiveRulesTableGenerator.py b/csarvalidation/python/test/test_ActiveRulesTableGenerator.py
new file mode 100644
index 0000000..3103a23
--- /dev/null
+++ b/csarvalidation/python/test/test_ActiveRulesTableGenerator.py
@@ -0,0 +1,78 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# 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.
+# ============LICENSE_END=====================================
+
+import unittest
+
+from validation.rules.ActiveRulesTableGenerator import ActiveRulesTableGenerator
+from validation.rules.providers.ActiveRulesProvider import ActiveRulesProvider
+from validation.rules.providers.RulesDescriptionsProvider import RulesDescriptionsProvider
+
+RESOURCES_DIRECTORY = '../src/main/resources/'
+RULE_DESCRIPTION_SOL001_PATH = RESOURCES_DIRECTORY + 'open-cli-schema/sol001/'
+RULE_DESCRIPTION_SOL004_PATH = RESOURCES_DIRECTORY + 'open-cli-schema/sol004/'
+VNFREWS_PROPERTIES_PATH = RESOURCES_DIRECTORY + 'vnfreqs.properties'
+RULE_DESCRIPTION_FILE_NAME_PATTERN = 'vtp-validate-csar-%s.yaml'
+
+CSV_DELIMITER = ";"
+
+VNF_REQS_TAG = "vnfreqs"
+PNF_REQS_TAG = "pnfreqs"
+
+
+class ActiveRulesTableGeneratorTest(unittest.TestCase):
+
+ @staticmethod
+ def generate_tables_with_active_rules(requs_tags: list) -> list:
+ return ActiveRulesTableGenerator(
+ [
+ RulesDescriptionsProvider(RULE_DESCRIPTION_SOL001_PATH, RULE_DESCRIPTION_FILE_NAME_PATTERN),
+ RulesDescriptionsProvider(RULE_DESCRIPTION_SOL004_PATH, RULE_DESCRIPTION_FILE_NAME_PATTERN)
+ ],
+ ActiveRulesProvider(VNFREWS_PROPERTIES_PATH)
+ ).generate_active_validation_rule_tables(requs_tags)
+
+ def test_generate_table_with_active_pnf_rules(self):
+ tables = self.generate_tables_with_active_rules([PNF_REQS_TAG])
+
+ self.assertTrue(len(tables) == 1)
+ self.validate_csv_table_with_rules(tables[0].get_table_in_csv_format())
+
+ def test_generate_table_with_active_vnf_rules(self):
+ tables = self.generate_tables_with_active_rules([VNF_REQS_TAG])
+
+ self.assertTrue(len(tables) == 1)
+ self.validate_csv_table_with_rules(tables[0].get_table_in_csv_format())
+
+ def test_generate_tables_with_active_vnf_and_pnf_rules(self):
+ tables = self.generate_tables_with_active_rules([PNF_REQS_TAG, VNF_REQS_TAG])
+
+ self.assertTrue(len(tables) == 2)
+ self.validate_csv_table_with_rules(tables[0].get_table_in_csv_format(values_separator=CSV_DELIMITER))
+ self.validate_csv_table_with_rules(tables[1].get_table_in_csv_format(values_separator=CSV_DELIMITER))
+
+ def validate_csv_table_with_rules(self, vnf_rules: str):
+ lines = vnf_rules.splitlines()
+ for line in lines:
+ values = line.split(CSV_DELIMITER)
+ self.assertTrue(len(values) == 3)
+ self.assertTrue(values[0].startswith("onap-"))
+ self.assertTrue(values[1].startswith("r"))
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/csarvalidation/python/test/test_FileManager.py b/csarvalidation/python/test/test_FileManager.py
new file mode 100644
index 0000000..722d1a9
--- /dev/null
+++ b/csarvalidation/python/test/test_FileManager.py
@@ -0,0 +1,95 @@
+# ============LICENSE_START====================================
+# vnfsdk-validation
+# =========================================================
+# Copyright (C) 2020 Nokia. All rights reserved.
+# =========================================================
+# 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.
+# ============LICENSE_END=====================================
+
+import os
+import shutil
+import unittest
+
+from validation.FileManager import FileManager
+from validation.rules.ActiveRulesTableGenerator import ActiveRulesTableGenerator
+from validation.rules.providers.ActiveRulesProvider import ActiveRulesProvider
+from validation.rules.providers.RulesDescriptionsProvider import RulesDescriptionsProvider
+
+RESOURCES_DIRECTORY = '../src/main/resources/'
+RULE_DESCRIPTION_SOL001_PATH = RESOURCES_DIRECTORY + 'open-cli-schema/sol001/'
+RULE_DESCRIPTION_SOL004_PATH = RESOURCES_DIRECTORY + 'open-cli-schema/sol004/'
+VNFREWS_PROPERTIES_PATH = RESOURCES_DIRECTORY + 'vnfreqs.properties'
+RULE_DESCRIPTION_FILE_NAME_PATTERN = 'vtp-validate-csar-%s.yaml'
+
+CSV_DELIMITER = ";"
+
+VNF_REQS_TAG = "vnfreqs"
+PNF_REQS_TAG = "pnfreqs"
+
+OUTPUT_DIRECTORY = './active_rules_table_generator_test/'
+
+TABLE_WITH_VNF_RULES = OUTPUT_DIRECTORY + 'VnfActiveRulesTable.csv'
+TABLE_WITH_PNF_RULES = OUTPUT_DIRECTORY + 'PnfActiveRulesTable.csv'
+
+
+class FileManagerTest(unittest.TestCase):
+
+
+ @staticmethod
+ def generate_tables_with_active_rules(requs_tags: list) -> list:
+ return ActiveRulesTableGenerator(
+ [
+ RulesDescriptionsProvider(RULE_DESCRIPTION_SOL001_PATH, RULE_DESCRIPTION_FILE_NAME_PATTERN),
+ RulesDescriptionsProvider(RULE_DESCRIPTION_SOL004_PATH, RULE_DESCRIPTION_FILE_NAME_PATTERN)
+ ],
+ ActiveRulesProvider(VNFREWS_PROPERTIES_PATH)
+ ).generate_active_validation_rule_tables(requs_tags)
+
+ def generate_and_save_tables(self):
+ tables = self.generate_tables_with_active_rules([VNF_REQS_TAG, PNF_REQS_TAG])
+ file_manager = FileManager(OUTPUT_DIRECTORY)
+ file_manager.save_rule_table(
+ tables[0].get_table_in_csv_format(values_separator=CSV_DELIMITER),
+ TABLE_WITH_VNF_RULES
+ )
+ file_manager.save_rule_table(
+ tables[1].get_table_in_csv_format(values_separator=CSV_DELIMITER),
+ TABLE_WITH_PNF_RULES
+ )
+
+ def tearDown(self):
+ shutil.rmtree(OUTPUT_DIRECTORY)
+
+ def test_generate_and_save_table_with_active_rules(self):
+ self.generate_and_save_tables()
+ self.assertTrue(os.path.isdir(OUTPUT_DIRECTORY))
+
+ self.assertTrue(os.path.isfile(TABLE_WITH_VNF_RULES))
+ with open(TABLE_WITH_VNF_RULES, 'r') as vnf_rules:
+ self.validate_csv_table_with_rules(vnf_rules)
+
+ self.assertTrue(os.path.isfile(TABLE_WITH_PNF_RULES))
+ with open(TABLE_WITH_PNF_RULES, 'r') as pnf_rules:
+ self.validate_csv_table_with_rules(pnf_rules)
+
+ def validate_csv_table_with_rules(self, vnf_rules):
+ lines = vnf_rules.read().splitlines()
+ for line in lines:
+ values = line.split(CSV_DELIMITER)
+ self.assertTrue(len(values) == 3)
+ self.assertTrue(values[0].startswith("onap-"))
+ self.assertTrue(values[1].startswith("r"))
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745.java b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745.java
index b43dbba..ec0b46f 100644
--- a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745.java
+++ b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745.java
@@ -19,7 +19,7 @@ package org.onap.cvc.csar.cc.sol004;
import org.onap.cli.fw.schema.OnapCommandSchema;
import org.onap.cvc.csar.CSARArchive;
import org.onap.cvc.csar.cc.VTPValidateCSARBase;
-import org.onap.validation.yaml.YamlFileValidator;
+import org.onap.validation.yaml.YamlContentValidator;
import org.onap.validation.yaml.error.YamlDocumentValidationError;
import org.onap.validation.yaml.exception.YamlProcessingException;
import org.slf4j.Logger;
@@ -97,7 +97,7 @@ public class VTPValidateCSARR816745 extends VTPValidateCSARBase {
private void validateYamlFile(String rootPath, String artifactPath) {
try {
List<YamlDocumentValidationError> validationErrors =
- new YamlFileValidator().validateYamlFileWithSchema(rootPath+artifactPath);
+ new YamlContentValidator().validate(rootPath+artifactPath);
addAllErrorsReportedByVaidator(artifactPath, validationErrors);
} catch (YamlProcessingException | YAMLException e) {
LOGGER.error("Failed to load PM_Dictionary file.", e);
diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java
deleted file mode 100644
index f89cc68..0000000
--- a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onap.validation.yaml;
-
-import org.assertj.core.util.Lists;
-import org.junit.Test;
-import org.onap.validation.yaml.error.YamlDocumentValidationError;
-import org.onap.validation.yaml.exception.YamlProcessingException;
-import org.yaml.snakeyaml.parser.ParserException;
-
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-public class YamlFileValidatorTest {
-
- @Test
- public void shouldReturnCorrectErrorsWhenGivenPathToValidPmDictionaryFile() throws YamlProcessingException {
- // given
- String path = getFullPathForGivenResources(YamlLoadingUtils.PATH_TO_VALID_YAML);
-
- // when
- List<YamlDocumentValidationError> validationErrors =
- new YamlFileValidator().validateYamlFileWithSchema(path);
-
- // then
- assertValidationReturnedExpectedErrors(validationErrors);
-
- }
-
- @Test
- public void shouldReturnCorrecErrorsWhenGivenPathToValidJsonStylePmDictionaryFile() throws YamlProcessingException {
- // given
- String path = getFullPathForGivenResources(YamlLoadingUtils.PATH_TO_VALID_JSON_STYLE_YAML);
-
- // when
- List<YamlDocumentValidationError> validationErrors =
- new YamlFileValidator().validateYamlFileWithSchema(path);
-
- // then
- assertValidationReturnedExpectedErrors(validationErrors);
- }
-
-
- private void assertValidationReturnedExpectedErrors(List<YamlDocumentValidationError> validationErrors) {
- assertThat(validationErrors).isNotNull();
- assertThat(validationErrors).hasSize(4);
- assertThat(validationErrors).usingRecursiveFieldByFieldElementComparator().containsAll(
- Lists.list(
- new YamlDocumentValidationError(1,
- "/pmMetaData/pmFields/measResultType",
- "Value(s) is/are not in array of accepted values.\n" +
- " value(s): integer\n" +
- " accepted value(s): [float, uint32, uint64]"),
- new YamlDocumentValidationError(1,
- "/pmMetaData/pmFields/",
- "Key not found: measChangeType"),
- new YamlDocumentValidationError(2,
- "/pmMetaData/pmFields/",
- "Key not found: measChangeType"),
- new YamlDocumentValidationError(3,
- "/pmMetaData/pmFields/measAdditionalFields/vendorField1",
- "Value(s) is/are not in array of accepted values.\n" +
- " value(s): [Z, A]\n" +
- " accepted value(s): [X, Y, Z]")
- )
- );
- }
- @Test
- public void shouldThrowErrorWhenGivenPathToInvalidPmDictionaryFile() {
- // given
- String path = getFullPathForGivenResources(YamlLoadingUtils.PATH_TO_MULTI_DOCUMENT_INVALID_YAML);
- // when then
- assertThatThrownBy(() ->
- new YamlFileValidator().validateYamlFileWithSchema(path)
- ).isInstanceOf(ParserException.class)
- .hasMessageContaining(
- "expected the node content, but found '<document end>'"
- );
- }
-
- @Test
- public void shouldThrowErrorWhenGivenInvalidPath() {
- // given
- String path ="invalid/path/to/pm_dictionary";
-
- // when then
- assertThatThrownBy(() ->
- new YamlFileValidator().validateYamlFileWithSchema(path)
- ).isInstanceOf(YamlProcessingException.class)
- .hasMessageContaining(
- "PM_Dictionary YAML file is empty"
- );
- }
-
- private String getFullPathForGivenResources(String pathToValidYaml) {
- return this.getClass().getClassLoader().getResource(
- pathToValidYaml
- ).getPath();
- }
-}
diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java
deleted file mode 100644
index 4c68d60..0000000
--- a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onap.validation.yaml;
-
-import org.junit.Test;
-import org.onap.validation.yaml.exception.YamlProcessingException;
-import org.onap.validation.yaml.model.YamlDocument;
-import org.onap.validation.yaml.model.YamlDocumentFactory;
-import org.yaml.snakeyaml.parser.ParserException;
-import org.yaml.snakeyaml.scanner.ScannerException;
-
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-
-public class YamlLoaderTest {
-
- private static final int EXPECTED_NUMBER_OF_DOCUMENTS = 5;
- private static final String LETTER_S_WITH_ASCII_CODE = "s(115)";
-
- @Test
- public void shouldLoadAllDocumentsFromYamlFile() throws YamlDocumentFactory.YamlDocumentParsingException {
- // when
- List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile();
-
- // then
- assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS);
- }
-
- @Test
- public void shouldLoadAllDocumentsFromJsonStyleYamlFile() throws YamlDocumentFactory.YamlDocumentParsingException {
- // when
- List<YamlDocument> documents = YamlLoadingUtils.loadValidJsonStyleMultiDocumentYamlFile();
-
- // then
- assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS);
- }
-
- @Test
- public void shouldLoadAllDocumentsFromYamlFileUsingPathInString() throws YamlProcessingException {
- // when
- List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFileUsingStringPath();
-
- // then
- assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS);
- }
-
- @Test
- public void shouldThrowExceptionWhenLoadingDocumentsFromInvalidYamlFile() {
- // when then
- assertThatThrownBy(YamlLoadingUtils::tryToLoadMultiDocumentInvalidYamlFile
- ).isInstanceOf(ParserException.class)
- .hasMessageContaining("expected the node content, but found '<document end>'");
- }
-
- @Test
- public void shouldThrowExceptionWhenLoadingDocumentsFromInvalidYamlFileUsingPathInString() {
- // when then
- assertThatThrownBy(YamlLoadingUtils::tryToLoadMultiDocumentInvalidYamlFileUsingStringPath
- ).isInstanceOf(ParserException.class)
- .hasMessageContaining("expected the node content, but found '<document end>'");
- }
-
-
- @Test
- public void shouldThrowExceptionWhenLoadingInvalidYamlFileWithIncorrectKeyMapping() {
- // when then
- assertThatThrownBy(YamlLoadingUtils::tryToLoadInvalidYamlFileWithIncorrectKeyMapping
- ).isInstanceOf(ScannerException.class)
- .hasMessageContaining("mapping values are not allowed here");
- }
-
-
- @Test
- public void shouldThrowExceptionWhenLoadingInvalidYamlFileWithUnknownEscapeCharacter() {
- // when then
- assertThatThrownBy(YamlLoadingUtils::tryToLoadInvalidYamlFileWithUnknownEscapeCharacter
- ).isInstanceOf(ScannerException.class)
- .hasMessageContaining("found unknown escape character " + LETTER_S_WITH_ASCII_CODE);
- }
-
-}
diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java b/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java
deleted file mode 100644
index 8d03910..0000000
--- a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onap.validation.yaml;
-
-import org.onap.validation.yaml.exception.YamlProcessingException;
-import org.onap.validation.yaml.model.YamlDocument;
-
-import java.net.URL;
-import java.util.List;
-
-import static org.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException;
-
-public final class YamlLoadingUtils {
-
- private YamlLoadingUtils() {}
-
- public static final int VALID_YAML_DOCUMENT_INDEX = 4;
- public static final int YAML_DOCUMENT_WITH_WRONG_VALUE_IN_ARRAY_INDEX = 3;
- public static final int YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX = 2;
- public static final int YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX = 1;
-
- static final String PATH_TO_VALID_YAML = "yaml_schema/PM_Dictionary.yaml";
- static final String PATH_TO_VALID_JSON_STYLE_YAML = "yaml_schema/PM_Dictionary_JSON_Style.yaml";
- private static final String PATH_TO_SIMPLE_VALID_SCHEMA = "yaml_schema/Simple_Valid_Schema.yaml";
- private static final String PATH_TO_SIMPLE_VALID_SCHEMA_MULTI_ROOT = "yaml_schema/Simple_Valid_Schema_Multi_Root.yaml";
- private static final String PATH_TO_SIMPLE_INVALID_SCHEMA = "yaml_schema/Simple_Invalid_Schema_Construction.yaml";
- private static final String PATH_TO_SIMPLE_INVALID_SCHEMA_FOR_LAZY_LOADING = "yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml";
- static final String PATH_TO_MULTI_DOCUMENT_INVALID_YAML = "yaml_schema/Multi_Document_Invalid.yaml";
- private static final String PATH_TO_INVALID_YAML_WITH_INCORRECT_KEY_MAPPING = "yaml_schema/Simple_Invalid_Mapping_Value.yaml";
- private static final String PATH_TO_INVALID_YAML_WITH_UNKNOWN_ESCAPE_CHARACTER = "yaml_schema/Simple_Unknown_Escape_Character.yaml";
-
- public static List<YamlDocument> loadValidMultiDocumentYamlFile() throws YamlDocumentParsingException {
- return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_VALID_YAML));
- }
-
- public static List<YamlDocument> loadValidJsonStyleMultiDocumentYamlFile() throws YamlDocumentParsingException {
- return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_VALID_JSON_STYLE_YAML));
- }
-
- public static List<YamlDocument> loadValidMultiDocumentYamlFileUsingStringPath() throws YamlProcessingException {
- return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_VALID_YAML).getPath());
- }
-
- public static YamlDocument loadSimpleValidYamlSchemaFile() throws YamlDocumentParsingException {
- return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_VALID_SCHEMA)).get(0);
- }
-
- public static YamlDocument loadSimpleInvalidYamlSchemaFile() throws YamlDocumentParsingException {
- return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_INVALID_SCHEMA)).get(0);
- }
-
- public static YamlDocument loadSimpleInvalidYamlSchemaForLazyLoadingFile() throws YamlDocumentParsingException {
- return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_INVALID_SCHEMA_FOR_LAZY_LOADING)).get(0);
- }
-
- public static YamlDocument loadSimpleValidYamlSchemaWithMultiRootFile() throws YamlDocumentParsingException {
- return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_VALID_SCHEMA_MULTI_ROOT)).get(0);
- }
-
- public static List<YamlDocument> tryToLoadMultiDocumentInvalidYamlFile() throws YamlDocumentParsingException {
- return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_MULTI_DOCUMENT_INVALID_YAML));
- }
-
- public static List<YamlDocument> tryToLoadMultiDocumentInvalidYamlFileUsingStringPath() throws YamlProcessingException {
- return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_MULTI_DOCUMENT_INVALID_YAML).getPath());
- }
-
- public static List<YamlDocument> tryToLoadInvalidYamlFileWithIncorrectKeyMapping() throws YamlDocumentParsingException {
- return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_INVALID_YAML_WITH_INCORRECT_KEY_MAPPING));
- }
-
- public static List<YamlDocument> tryToLoadInvalidYamlFileWithUnknownEscapeCharacter() throws YamlDocumentParsingException {
- return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_INVALID_YAML_WITH_UNKNOWN_ESCAPE_CHARACTER));
- }
-
- private static URL getUrlForGivenPath(String path) {
- return YamlLoadingUtils.class.getClassLoader().getResource(path);
- }
-}
diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java
deleted file mode 100644
index 7879d4e..0000000
--- a/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright 2020 Nokia
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.onap.validation.yaml.model;
-
-import org.assertj.core.util.Lists;
-import org.junit.Test;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException;
-
-public class YamlDocumentFactoryTest {
-
- @Test
- public void shouldTurnMapOfUnknownKeyTypeToMapWithStringKeysAndBeAbleToReturnStringifyValues()
- throws YamlDocumentParsingException {
- // given
- Map<Object, Object> inputMap = new HashMap<>();
- List<String> testList = Lists.list("element1", "element11");
- Map<Object, Object> testEmptyMap = Collections.emptyMap();
-
- inputMap.put("test", testList);
- inputMap.put(345, "element2");
- inputMap.put("test2", "element3");
- inputMap.put(2.67, testEmptyMap);
-
- // when
- YamlDocument document = new YamlDocumentFactory().createYamlDocument(inputMap);
-
- // then
- assertThat(document).isNotNull();
- assertThat(document.getYaml()).containsKeys("test", "345", "test2", "2.67");
-
- assertThat(document.getYaml()).containsEntry("test", testList);
- assertThat(document.getValue("test")).isEqualTo("[element1, element11]");
-
- assertThat(document.getValue("345")).isEqualTo("element2");
- assertThat(document.getValue("test2")).isEqualTo("element3");
-
- assertThat(document.getYaml()).containsEntry("2.67", testEmptyMap);
- assertThat(document.getValue("2.67")).isEqualTo("{}");
- }
-
- @Test
- public void shouldTurnMapOfUnknownKeyTypeToMapWithStringKeysAndBeAbleToExtractSubStructure()
- throws YamlDocumentParsingException {
- // given
- Map<Object, Object> inputMap = new HashMap<>();
- Map<Object, Object> subStructureMap = new HashMap<>();
-
- inputMap.put("test", "element1");
- inputMap.put("structure", subStructureMap);
-
- subStructureMap.put("subTest1", "subElement1");
- subStructureMap.put("subTest2", "subElement2");
-
- // when
- YamlDocument document = new YamlDocumentFactory().createYamlDocument(inputMap);
-
- // then
- assertThat(document).isNotNull();
- assertThat(document.getYaml()).containsKeys("test", "structure");
- assertThat(document.getValue("test")).isEqualTo("element1");
-
- assertThat(document.getSubStructure("structure")).isNotNull();
- assertThat(document.getSubStructure("structure").getValue("subTest1")).isEqualTo("subElement1");
- assertThat(document.getSubStructure("structure").getValue("subTest2")).isEqualTo("subElement2");
- }
-
- @Test
- public void shouldTurnMapOfUnknownKeyTypeToMapWithStringKeysAndBeAbleToExtractParametersList()
- throws YamlDocumentParsingException {
- // given
- Map<Object, Object> inputMap = new HashMap<>();
- List<String> parametersList = new LinkedList<>();
-
- inputMap.put("test", "element1");
- inputMap.put("parameters", parametersList);
-
- parametersList.add("parameter1");
- parametersList.add("parameter2");
-
- // when
- YamlDocument document = new YamlDocumentFactory().createYamlDocument(inputMap);
-
- // then
- assertThat(document).isNotNull();
- assertThat(document.getYaml()).containsKeys("test", "parameters");
- assertThat(document.getValue("test")).isEqualTo("element1");
-
- assertThat(document.getListOfValues("parameters")).isNotNull();
- assertThat(document.getListOfValues("parameters").getParameters()).contains("parameter1","parameter2");
- }
-
- @Test
- public void shouldThrowExceptionIfGetSubStructureIsCalledOnList()
- throws YamlDocumentParsingException {
- // given
- Map<Object, Object> inputMap = new HashMap<>();
- List<String> testList = Lists.list("element1", "element2");
-
- inputMap.put("test", testList);
-
- YamlDocument document = new YamlDocumentFactory().createYamlDocument(inputMap);
-
- // when then
- assertThatThrownBy(() ->
- document.getSubStructure("test")
- ).isInstanceOf(YamlDocumentParsingException.class)
- .hasMessageContaining(
- String.format("Fail to parse given objects: %s as yaml document", testList)
- );
- }
-
- @Test
- public void shouldThrowExceptionIfGetSubStructureIsCalledOnString()
- throws YamlDocumentParsingException {
- // given
- Map<Object, Object> inputMap = new HashMap<>();
-
- inputMap.put("test", "testElement");
-
- YamlDocument document = new YamlDocumentFactory().createYamlDocument(inputMap);
-
- // when then
- assertThatThrownBy(() ->
- document.getSubStructure("test")
- ).isInstanceOf(YamlDocumentParsingException.class)
- .hasMessageContaining(
- String.format("Fail to parse given objects: %s as yaml document.", "testElement")
- );
- }
-}
diff --git a/deployment/pom.xml b/deployment/pom.xml
index fb720d2..5bf2ca2 100644
--- a/deployment/pom.xml
+++ b/deployment/pom.xml
@@ -24,7 +24,7 @@
<parent>
<groupId>org.onap.vnfsdk.validation</groupId>
<artifactId>validation</artifactId>
- <version>1.2.15-SNAPSHOT</version>
+ <version>1.2.16-SNAPSHOT</version>
</parent>
<artifactId>csarvalidation-deployment</artifactId>
diff --git a/pmdictionaryvalidation/README.md b/pmdictionaryvalidation/README.md
new file mode 100644
index 0000000..2bc91a5
--- /dev/null
+++ b/pmdictionaryvalidation/README.md
@@ -0,0 +1,26 @@
+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.
+
+ <dependency>
+ <groupId>org.onap.vnfsdk.validation</groupId>
+ <artifactId>validation-pmdictionary</artifactId>
+ <version>version</version>
+ </dependency>
+
+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
new file mode 100644
index 0000000..6952b40
--- /dev/null
+++ b/pmdictionaryvalidation/pom.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.onap.vnfsdk.validation</groupId>
+ <artifactId>validation</artifactId>
+ <version>1.2.16-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>validation-pmdictionary</artifactId>
+ <packaging>jar</packaging>
+ <name>pmdictionaryvalidation/validation</name>
+
+ <repositories>
+ <repository>
+ <id>google-collections</id>
+ <name>Google collections repository</name>
+ <url>https://mvnrepository.com/artifact/com.google.collections/google-collections</url>
+ </repository>
+ <repository>
+ <id>onap</id>
+ <name>ONAP repository</name>
+ <url>https://nexus.onap.org/content/repositories/public/</url>
+ </repository>
+ </repositories>
+ <properties>
+ <log4j-slf4j-impl.version>2.13.3</log4j-slf4j-impl.version>
+ <snakeyaml.version>1.26</snakeyaml.version>
+ <junit.version>5.7.0</junit.version>
+ <assertj-core.version>3.18.1</assertj-core.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <version>${log4j-slf4j-impl.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-ext</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
+ <version>${snakeyaml.version}</version>
+ </dependency>
+ <!-- TEST dependencies -->
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.vintage</groupId>
+ <artifactId>junit-vintage-engine</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>${assertj-core.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlFileValidator.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlContentValidator.java
index 2de4f48..5e1238b 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlFileValidator.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlContentValidator.java
@@ -21,6 +21,7 @@ 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;
@@ -28,23 +29,33 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
-public class YamlFileValidator {
+public class YamlContentValidator {
private static final int FIRST_DOCUMENT_INDEX = 1;
+ private static final YamlLoader YAML_LOADER = new YamlLoader(new YamlDocumentFactory());
- public List<YamlDocumentValidationError> validateYamlFileWithSchema(String pathToFile)
- throws YamlProcessingException {
+ public List<YamlDocumentValidationError> validate(String pathToFile)
+ throws YamlProcessingException {
+ List<YamlDocument> documents = YAML_LOADER.loadMultiDocumentYamlFile(pathToFile);
+ return getYamlDocumentValidationErrors(documents);
+ }
- List<YamlDocument> documents = new YamlLoader().loadMultiDocumentYamlFile(pathToFile);
- if(!documents.isEmpty()) {
- return validateDocuments(documents);
- } else {
+ public List<YamlDocumentValidationError> validate(byte[] yamlWithSchema)
+ throws YamlProcessingException {
+ List<YamlDocument> documents = YAML_LOADER.loadMultiDocumentYaml(yamlWithSchema);
+ return getYamlDocumentValidationErrors(documents);
+ }
+
+ private List<YamlDocumentValidationError> getYamlDocumentValidationErrors(List<YamlDocument> documents) throws YamlProcessingException {
+ if (documents.isEmpty()) {
throw new YamlProcessingException("PM_Dictionary YAML file is empty");
+ } else {
+ return validateDocuments(documents);
}
}
private List<YamlDocumentValidationError> validateDocuments(List<YamlDocument> documents)
- throws YamlProcessingException {
+ throws YamlProcessingException {
List<YamlDocumentValidationError> yamlFileValidationErrors = new ArrayList<>();
YamlSchema schema = extractSchema(documents);
@@ -52,7 +63,7 @@ public class YamlFileValidator {
for (int index = FIRST_DOCUMENT_INDEX; index < documents.size(); index++) {
List<SchemaValidationError> validationErrors = validator.validate(documents.get(index));
- yamlFileValidationErrors.addAll(transformErrors(index,validationErrors));
+ yamlFileValidationErrors.addAll(transformErrors(index, validationErrors));
}
return yamlFileValidationErrors;
@@ -60,9 +71,9 @@ public class YamlFileValidator {
private List<YamlDocumentValidationError> transformErrors(int index, List<SchemaValidationError> validationErrors) {
return validationErrors
- .stream()
- .map(error->new YamlDocumentValidationError(index, error.getPath(), error.getMessage()))
- .collect(Collectors.toList());
+ .stream()
+ .map(error -> new YamlDocumentValidationError(index, error.getPath(), error.getMessage()))
+ .collect(Collectors.toList());
}
private YamlSchema extractSchema(List<YamlDocument> documents) throws YamlProcessingException {
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java
index 1a5eef9..c23da0a 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlLoader.java
@@ -24,6 +24,7 @@ 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;
@@ -33,29 +34,49 @@ import java.util.List;
class YamlLoader {
- private static final Logger LOGGER = LoggerFactory.getLogger(YamlLoader.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(YamlLoader.class);
+ private final YamlDocumentFactory documentFactory;
+
+ YamlLoader(YamlDocumentFactory documentFactory) {
+ this.documentFactory = documentFactory;
+ }
+
+ List<YamlDocument> loadMultiDocumentYaml(byte[] yamlWithSchema)
+ throws YamlDocumentFactory.YamlDocumentParsingException {
+ List<YamlDocument> 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<YamlDocument> loadMultiDocumentYamlFile(URL path)
- throws YamlDocumentFactory.YamlDocumentParsingException {
- List<YamlDocument> documentsFromFile = new ArrayList<>();
+ throws YamlDocumentFactory.YamlDocumentParsingException {
+ List<YamlDocument> documents = new ArrayList<>();
try (InputStream yamlStream = path.openStream()) {
- for (Object yamlDocument : new Yaml().loadAll(yamlStream)) {
- documentsFromFile.add(
- new YamlDocumentFactory().createYamlDocument(yamlDocument)
- );
- }
+ documents.addAll(loadMultiDocumentYaml(yamlStream));
} catch (IOException e) {
- LOGGER.error("Failed to load multi document YAML file",e);
+ LOGGER.error("Failed to load multi document YAML file", e);
}
- return documentsFromFile;
+ return documents;
}
List<YamlDocument> loadMultiDocumentYamlFile(String path)
- throws YamlProcessingException {
+ 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<YamlDocument> loadMultiDocumentYaml(InputStream yamlStream) throws YamlDocumentFactory.YamlDocumentParsingException {
+ List<YamlDocument> documents = new ArrayList<>();
+ for (Object yamlDocument : new Yaml().loadAll(yamlStream)) {
+ documents.add(documentFactory.createYamlDocument(yamlDocument));
+ }
+ return documents;
+ }
}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java
index 9430df4..30ba646 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/YamlValidator.java
@@ -17,8 +17,8 @@
package org.onap.validation.yaml;
-import org.onap.validation.yaml.exception.YamlProcessingException;
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;
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java
index 6ffe6d4..6ffe6d4 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/SchemaValidationError.java
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java
index f04708f..f04708f 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/error/YamlDocumentValidationError.java
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java
index 99c2437..99c2437 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/exception/YamlProcessingException.java
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java
index 557b6fd..557b6fd 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java
index b56422c..b56422c 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocumentFactory.java
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java
index 5f41c5c..5f41c5c 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java
index 2b93c74..2b93c74 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/model/YamlParametersList.java
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java
index 273014b..ebd37ce 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java
@@ -17,8 +17,8 @@
package org.onap.validation.yaml.process;
-import org.onap.validation.yaml.exception.YamlProcessingException;
import org.onap.validation.yaml.error.SchemaValidationError;
+import org.onap.validation.yaml.exception.YamlProcessingException;
import org.onap.validation.yaml.model.YamlDocument;
import org.onap.validation.yaml.schema.YamlSchema;
import org.onap.validation.yaml.schema.node.YamlSchemaNode;
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java
index eb5ab8e..eb5ab8e 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationStep.java
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java
index 69bb6cd..69bb6cd 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchema.java
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java
index df7d673..df7d673 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/YamlSchemaFactory.java
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java
index 0f5b480..a3e9636 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaBranchNode.java
@@ -24,18 +24,16 @@ import org.onap.validation.yaml.model.YamlDocumentFactory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.Optional;
public class YamlSchemaBranchNode extends YamlSchemaNode {
private final YamlDocument nextNodesInLazyForm;
- private Optional<List<YamlSchemaNode>> nextNodes;
+ private List<YamlSchemaNode> nextNodes = Collections.emptyList();
YamlSchemaBranchNode(String name, String path, boolean required, String comment,
YamlDocument nextNodesInLazyForm) {
super(name, path, required, comment);
this.nextNodesInLazyForm = nextNodesInLazyForm;
- this.nextNodes = Optional.empty();
}
@Override
@@ -51,7 +49,7 @@ public class YamlSchemaBranchNode extends YamlSchemaNode {
@Override
public synchronized List<YamlSchemaNode> getNextNodes() throws YamlSchemaProcessingException {
try {
- return nextNodes.orElseGet(this::loadNextNodes);
+ return nextNodes.isEmpty() ? this.loadNextNodes() : nextNodes;
} catch (YamlSchemaLazyLoadingException lazyLoadingException) {
throw new YamlSchemaProcessingException(lazyLoadingException);
}
@@ -65,7 +63,7 @@ public class YamlSchemaBranchNode extends YamlSchemaNode {
.createYamlDocument(nextNodesInLazyForm.getYaml().get(key));
loadedNextNodes.add(new YamlSchemaNodeFactory().createNode(key, getPath() + getName() + "/", substructure));
}
- nextNodes = Optional.of(loadedNextNodes);
+ nextNodes = loadedNextNodes;
return loadedNextNodes;
} catch (YamlProcessingException e) {
throw new YamlSchemaLazyLoadingException("Lazy loading failed, due to yaml parsing exception.",e);
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java
index c98f41e..c98f41e 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaLeafNode.java
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java
index 28913a2..28913a2 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNode.java
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java
index 79a8f14..79a8f14 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java
+++ b/pmdictionaryvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java
diff --git a/pmdictionaryvalidation/src/main/resources/log4j2.properties b/pmdictionaryvalidation/src/main/resources/log4j2.properties
new file mode 100644
index 0000000..f3202ee
--- /dev/null
+++ b/pmdictionaryvalidation/src/main/resources/log4j2.properties
@@ -0,0 +1,48 @@
+# Copyright Nokia 2020,2020 Huawei Technologies Co., Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# By default, log4j2 will look for a configuration file named log4j2.xml on the classpath.
+# reference: https://logging.apache.org/log4j/2.x/faq.html#troubleshooting
+
+rootLogger.level=ERROR
+rootLogger.appenderRefs=file
+rootLogger.appenderRef.file.ref=RollingFile
+
+logger.onap.name = org.onap
+logger.onap.level=ERROR
+logger.onap.additivity=false
+logger.onap.appenderRef.stdout.ref=STDOUT
+
+appenders=stdout, file
+
+# Direct log messages to stdout
+appender.stdout.type=Console
+appender.stdout.name=STDOUT
+appender.stdout.target=SYSTEM_OUT
+appender.stdout.layout.type=PatternLayout
+appender.stdout.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
+
+# Redirect log messages to a log file, support file rolling.
+appender.file.type = RollingFile
+appender.file.name = RollingFile
+appender.file.fileName=./pmdictionary-validate.log
+appender.file.filePattern=./pmdictionary-validate.%d{yyyy-MM-dd-HH:mm:ss}.log
+appender.file.append=true
+appender.file.policies.type=Policies
+appender.file.policies.size.type=SizeBasedTriggeringPolicy
+appender.file.policies.size.size=5MB
+appender.file.strategy.type=DefaultRolloverStrategy
+appender.file.strategy.max=10
+appender.file.layout.type=PatternLayout
+appender.file.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlContentValidatorTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlContentValidatorTest.java
new file mode 100644
index 0000000..b6c2548
--- /dev/null
+++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlContentValidatorTest.java
@@ -0,0 +1,161 @@
+/*
+ * 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_VALID_YAML;
+import static org.onap.validation.yaml.YamlLoadingUtils.readFile;
+
+class YamlContentValidatorTest {
+ @Nested
+ class FromStringPathValidator {
+ @Test
+ void shouldReturnCorrectErrorsWhenGivenPathToValidPmDictionaryFile() throws YamlProcessingException {
+ // given
+ String path = getFullPathForGivenResources(PATH_TO_VALID_YAML);
+
+ // when
+ List<YamlDocumentValidationError> 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<YamlDocumentValidationError> validationErrors = new YamlContentValidator().validate(path);
+
+ // then
+ assertValidationReturnedExpectedErrors(validationErrors);
+ }
+
+ @Test
+ void shouldThrowErrorWhenGivenPathToInvalidPmDictionaryFile() {
+ // given
+ String path = getFullPathForGivenResources(PATH_TO_MULTI_DOCUMENT_INVALID_YAML);
+
+ //when then
+ assertThatThrownBy(() -> new YamlContentValidator().validate(path))
+ .isInstanceOf(ParserException.class)
+ .hasMessageContaining("expected the node content, but found '<document end>'");
+ }
+
+ @Test
+ void shouldThrowErrorWhenGivenInvalidPath() {
+ // given
+ String path = "invalid/path/to/pm_dictionary";
+
+ //when then
+ assertThatThrownBy(() -> new 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_VALID_YAML);
+
+ // when
+ List<YamlDocumentValidationError> 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<YamlDocumentValidationError> 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 '<document end>'");
+ }
+
+ @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<YamlDocumentValidationError> 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();
+ }
+} \ No newline at end of file
diff --git a/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java
new file mode 100644
index 0000000..3b26541
--- /dev/null
+++ b/pmdictionaryvalidation/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<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile();
+
+ // then
+ assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS);
+ }
+
+ @Test
+ void shouldLoadAllDocumentsFromJsonStyleYamlFile() throws YamlDocumentFactory.YamlDocumentParsingException {
+ // when
+ List<YamlDocument> 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 '<document end>'");
+ }
+
+ @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<YamlDocument> 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 '<document end>'");
+ }
+ }
+
+ @Nested
+ class FromByteArrayLoader {
+ private final YamlLoader YAML_LOADER = new YamlLoader(new YamlDocumentFactory());
+
+ @Test
+ void shouldLoadAllDocumentsFromYamlFile() throws YamlDocumentFactory.YamlDocumentParsingException, IOException {
+ // when
+ List<YamlDocument> documents = YAML_LOADER.loadMultiDocumentYaml(YamlLoadingUtils.readFile(YamlLoadingUtils.PATH_TO_VALID_YAML));
+
+ // then
+ assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS);
+ }
+
+ @Test
+ void shouldLoadAllDocumentsFromJsonStyleYamlFile() throws YamlDocumentFactory.YamlDocumentParsingException, IOException {
+ // when
+ List<YamlDocument> 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 '<document end>'");
+ }
+
+ @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
new file mode 100644
index 0000000..b16d3ea
--- /dev/null
+++ b/pmdictionaryvalidation/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_VALID_YAML = "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<YamlDocument> loadValidMultiDocumentYamlFile() throws YamlDocumentParsingException {
+ return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_VALID_YAML));
+ }
+
+ public static List<YamlDocument> loadValidJsonStyleMultiDocumentYamlFile() throws YamlDocumentParsingException {
+ return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_VALID_JSON_STYLE_YAML));
+ }
+
+ public static List<YamlDocument> loadValidMultiDocumentYamlFileUsingStringPath() throws YamlProcessingException {
+ return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_VALID_YAML).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<YamlDocument> tryToLoadMultiDocumentInvalidYamlFile() throws YamlDocumentParsingException {
+ return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_MULTI_DOCUMENT_INVALID_YAML));
+ }
+
+ public static List<YamlDocument> tryToLoadMultiDocumentInvalidYamlFileUsingStringPath() throws YamlProcessingException {
+ return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_MULTI_DOCUMENT_INVALID_YAML).getPath());
+ }
+
+ public static List<YamlDocument> tryToLoadInvalidYamlFileWithIncorrectKeyMapping() throws YamlDocumentParsingException {
+ return YAML_LOADER.loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_INVALID_YAML_WITH_INCORRECT_KEY_MAPPING));
+ }
+
+ public static List<YamlDocument> 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));
+ }
+
+ private static URL getUrlForGivenPath(String path) {
+ return YamlLoadingUtils.class.getClassLoader().getResource(path);
+ }
+}
diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java
index efe9d69..3d993f8 100644
--- a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java
+++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java
@@ -17,10 +17,9 @@
package org.onap.validation.yaml;
-import org.assertj.core.util.Lists;
-import org.junit.Test;
-import org.onap.validation.yaml.exception.YamlProcessingException;
+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;
@@ -30,24 +29,22 @@ import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.onap.validation.yaml.YamlLoadingUtils.VALID_YAML_DOCUMENT_INDEX;
-import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX;
import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX;
+import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX;
import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_WRONG_VALUE_IN_ARRAY_INDEX;
-public class YamlValidatorTest {
-
+class YamlValidatorTest {
@Test
- public void shouldCreateValidatorUsingSchemaLoadedFromYamlFileAndValidatedJsonStyleDocumentsFromThatFile()
- throws YamlProcessingException {
-
+ void shouldCreateValidatorUsingSchemaLoadedFromYamlFileAndValidatedJsonStyleDocumentsFromThatFile()
+ throws YamlProcessingException {
// given
List<YamlDocument> documents = YamlLoadingUtils.loadValidJsonStyleMultiDocumentYamlFile();
YamlValidator validator = new YamlValidator(new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0)));
- Map<Integer,List<SchemaValidationError>> validationErrors = new HashMap<>();
+ Map<Integer, List<SchemaValidationError>> validationErrors = new HashMap<>();
// when
- for (int documentIndex = 1 ; documentIndex < documents.size() ; documentIndex++) {
+ for (int documentIndex = 1; documentIndex < documents.size(); documentIndex++) {
validationErrors.put(documentIndex, validator.validate(documents.get(documentIndex)));
}
@@ -56,16 +53,15 @@ public class YamlValidatorTest {
}
@Test
- public void shouldCreateValidatorUsingSchemaLoadedFromYamlFileAndValidatedDocumentsFromThatFile()
- throws YamlProcessingException {
-
+ void shouldCreateValidatorUsingSchemaLoadedFromYamlFileAndValidatedDocumentsFromThatFile()
+ throws YamlProcessingException {
// given
List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile();
YamlValidator validator = new YamlValidator(new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0)));
- Map<Integer,List<SchemaValidationError>> validationErrors = new HashMap<>();
+ Map<Integer, List<SchemaValidationError>> validationErrors = new HashMap<>();
// when
- for (int documentIndex = 1 ; documentIndex < documents.size() ; documentIndex++) {
+ for (int documentIndex = 1; documentIndex < documents.size(); documentIndex++) {
validationErrors.put(documentIndex, validator.validate(documents.get(documentIndex)));
}
@@ -76,48 +72,44 @@ public class YamlValidatorTest {
private void assertValidatorReturnedCorrectErrors(Map<Integer, List<SchemaValidationError>> 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]"
- );
+ 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"
- );
+ new SchemaValidationError(
+ "/pmMetaData/pmFields/",
+ "Key not found: measChangeType"
+ );
SchemaValidationError expectedValidationValuesInArrayError =
- new SchemaValidationError(
- "/pmMetaData/pmFields/measAdditionalFields/vendorField1",
- "Value(s) is/are not in array of accepted values.\n"
- + " value(s): [Z, A]\n"
- + " accepted value(s): [X, Y, Z]"
- );
-
- assertThat(validationErrors.size()).isEqualTo(4);
- assertThat(validationErrors).containsKeys(1,2,3);
- assertThat(validationErrors.get(YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX)).hasSize(2);
+ 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))
- .usingFieldByFieldElementComparator()
- .containsAll(
- Lists.list(
- expectedValidationValueError,
- expectedValidationKeyError
+ .hasSize(2)
+ .usingFieldByFieldElementComparator()
+ .containsAll(List.of(
+ expectedValidationValueError,
+ expectedValidationKeyError
));
- assertThat(validationErrors.get(YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX)).hasSize(1);
assertThat(validationErrors.get(YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX))
- .usingFieldByFieldElementComparator()
- .contains(
- expectedValidationKeyError
- );
- assertThat(validationErrors.get(YAML_DOCUMENT_WITH_WRONG_VALUE_IN_ARRAY_INDEX)).hasSize(1);
+ .hasSize(1)
+ .usingFieldByFieldElementComparator()
+ .contains(expectedValidationKeyError);
assertThat(validationErrors.get(YAML_DOCUMENT_WITH_WRONG_VALUE_IN_ARRAY_INDEX))
- .usingFieldByFieldElementComparator()
- .contains(
- expectedValidationValuesInArrayError
- );
- assertThat(validationErrors.get(VALID_YAML_DOCUMENT_INDEX)).hasSize(0);
+ .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
new file mode 100644
index 0000000..d7d1153
--- /dev/null
+++ b/pmdictionaryvalidation/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<String> testList = List.of("element1", "element11");
+ Map<Object, Object> testEmptyMap = Collections.emptyMap();
+ Map<Object, Object> 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<Object, Object> subStructureMap = Map.of(
+ "subTest1", "subElement1",
+ "subTest2", "subElement2");
+ Map<Object, Object> 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<String> parametersList = List.of("parameter1", "parameter2");
+ Map<Object, Object> 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<String> testList = List.of("element1", "element2");
+ Map<Object, Object> 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<Object, Object> 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<Object, Object> inputMap) {
+ assertThat(document).isNotNull();
+ assertThat(document.getYaml()).containsExactlyEntriesOf(mapKeyToString(inputMap));
+ }
+
+ private Map<String, Object> mapKeyToString(Map<Object, Object> inputMap) {
+ return inputMap.entrySet().stream()
+ .collect(Collectors.toMap(w -> w.getKey().toString(), Map.Entry::getValue));
+ }
+
+ private void assertYamlDocumentParsingException(Throwable ex, Object unparsed) {
+ assertThat(ex)
+ .isInstanceOf(YamlDocumentParsingException.class)
+ .hasMessageContaining(String.format("Fail to parse given objects: %s as yaml document.", unparsed));
+ }
+}
diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java
index 34e61c5..ab6f882 100644
--- a/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java
+++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java
@@ -17,17 +17,17 @@
package org.onap.validation.yaml.model;
-import org.assertj.core.util.Lists;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
-public class YamlParameterListFactoryTest {
+class YamlParameterListFactoryTest {
@Test
- public void shouldCreateEmptyParametersList() {
+ void shouldCreateEmptyParametersList() {
// when
YamlParametersList parametersList = new YamlParameterListFactory().createEmptyYamlParameterList();
@@ -37,35 +37,31 @@ public class YamlParameterListFactoryTest {
}
@Test
- public void shouldCreateParametersListContainingStringsFromListContainingSimpleTypes() {
+ void shouldCreateParametersListContainingStringsFromListContainingSimpleTypes() {
// given
- List<Object> testList = Lists.list("test1",3,23.45,'a',"test2");
+ List<Object> testList = List.of("test1", 3, 23.45, 'a', "test2");
// when
YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testList);
// then
- assertThat(parametersList).isNotNull();
- assertThat(parametersList.getParameters()).hasSize(5);
- assertThat(parametersList.getParameters()).contains("test1","test2","3","23.45","a");
+ assertYamlParametersList(parametersList, testList);
}
@Test
- public void shouldCreateParametersListContainingStringsFromListContainingVariousTypes() {
+ void shouldCreateParametersListContainingStringsFromListContainingVariousTypes() {
// given
- List<Object> testList = Lists.list("test1",3,Lists.list(2,3,4),"test2");
+ List<Object> testList = List.of("test1", 3, List.of(2, 3, 4), "test2");
// when
YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testList);
// then
- assertThat(parametersList).isNotNull();
- assertThat(parametersList.getParameters()).hasSize(4);
- assertThat(parametersList.getParameters()).contains("test1","test2","3","[2, 3, 4]");
+ assertYamlParametersList(parametersList, testList);
}
@Test
- public void shouldCreateListWithOneStringWhenGivenObjectIsNotList() {
+ void shouldCreateListWithOneStringWhenGivenObjectIsNotList() {
// given
Object testObject = "test";
@@ -73,9 +69,17 @@ public class YamlParameterListFactoryTest {
YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testObject);
// then
+ assertYamlParametersList(parametersList, Collections.singletonList(testObject));
+ }
+
+ private void assertYamlParametersList(YamlParametersList parametersList, List<Object> testList) {
assertThat(parametersList).isNotNull();
- assertThat(parametersList.getParameters()).hasSize(1);
- assertThat(parametersList.getParameters()).contains("test");
+ assertThat(parametersList.getParameters())
+ .containsExactly(mapToStrings(testList));
+ }
+
+ private String[] mapToStrings(List<Object> elements) {
+ return elements.stream().map(Object::toString).toArray(String[]::new);
}
}
diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java
index 12fe9ec..5c9d8e5 100644
--- a/csarvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java
+++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java
@@ -17,10 +17,10 @@
package org.onap.validation.yaml.process;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.validation.yaml.YamlLoadingUtils;
-import org.onap.validation.yaml.exception.YamlProcessingException;
import org.onap.validation.yaml.error.SchemaValidationError;
+import org.onap.validation.yaml.exception.YamlProcessingException;
import org.onap.validation.yaml.model.YamlDocument;
import org.onap.validation.yaml.schema.YamlSchema;
import org.onap.validation.yaml.schema.YamlSchemaFactory;
@@ -28,74 +28,73 @@ import org.onap.validation.yaml.schema.YamlSchemaFactory;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.onap.validation.yaml.YamlLoadingUtils.VALID_YAML_DOCUMENT_INDEX;
-import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_MISSING_FIELD_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;
-
-public class YamlValidationProcessTest {
+class YamlValidationProcessTest {
@Test
- public void shouldReturnNoErrorWhenProcessingValidPmDictionaryYaml()
- throws YamlProcessingException {
+ void shouldReturnNoErrorWhenProcessingValidPmDictionaryYaml()
+ throws YamlProcessingException {
// given
List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile();
YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0));
YamlDocument document = documents.get(VALID_YAML_DOCUMENT_INDEX);
// when
- List<SchemaValidationError> errors = new YamlValidationProcess(schema,document).validate();
+ List<SchemaValidationError> errors = new YamlValidationProcess(schema, document).validate();
// then
assertThat(errors).isEmpty();
}
@Test
- public void shouldReturnOneErrorWhenProcessingPmDictionaryYamlWithMissingField()
- throws YamlProcessingException {
+ void shouldReturnOneErrorWhenProcessingPmDictionaryYamlWithMissingField()
+ throws YamlProcessingException {
// given
List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile();
YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0));
YamlDocument document = documents.get(YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX);
// when
- List<SchemaValidationError> errors = new YamlValidationProcess(schema,document).validate();
+ List<SchemaValidationError> errors = new YamlValidationProcess(schema, document).validate();
// then
assertThat(errors).hasSize(1);
}
@Test
- public void shouldReturnTwoErrorsWhenProcessingPmDictionaryYamlWithMissingFieldAndIncorrectValue()
- throws YamlProcessingException {
+ void shouldReturnTwoErrorsWhenProcessingPmDictionaryYamlWithMissingFieldAndIncorrectValue()
+ throws YamlProcessingException {
// given
List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile();
YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0));
YamlDocument document = documents.get(YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX);
// when
- List<SchemaValidationError> errors = new YamlValidationProcess(schema,document).validate();
+ List<SchemaValidationError> errors = new YamlValidationProcess(schema, document).validate();
// then
assertThat(errors).hasSize(2);
}
@Test
- public void shouldThrowExceptionWhenProcessingPmDictionaryIsNotValidYaml()
- throws YamlProcessingException {
+ void shouldThrowExceptionWhenProcessingPmDictionaryIsNotValidYaml()
+ throws YamlProcessingException {
// given
List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile();
YamlDocument schemaInYaml = YamlLoadingUtils.loadSimpleInvalidYamlSchemaForLazyLoadingFile();
YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(schemaInYaml);
YamlDocument document = documents.get(VALID_YAML_DOCUMENT_INDEX);
- // when then
- assertThatThrownBy(() ->
- new YamlValidationProcess(schema,document).validate()
- ).isInstanceOf(YamlProcessingException.class)
- .hasMessageContaining(
- String.format("Lazy loading failed, due to yaml parsing exception.")
- );
+ // 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/csarvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java
index 4c05d71..efc304c 100644
--- a/csarvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java
+++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java
@@ -17,7 +17,8 @@
package org.onap.validation.yaml.schema;
-import org.junit.Test;
+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;
@@ -31,12 +32,11 @@ import static org.onap.validation.yaml.schema.node.YamlSchemaNodeFactoryTest.ass
import static org.onap.validation.yaml.schema.node.YamlSchemaNodeFactoryTest.assertThatLeafNodeIsValid;
-public class YamlSchemaFactoryTest {
+class YamlSchemaFactoryTest {
@Test
- public void shouldCreateYamlSchemaFromYamlDocumentWithMultipleRoots()
- throws YamlProcessingException {
-
+ void shouldCreateYamlSchemaFromYamlDocumentWithMultipleRoots()
+ throws YamlProcessingException {
// given
YamlDocument documents = YamlLoadingUtils.loadSimpleValidYamlSchemaWithMultiRootFile();
@@ -45,17 +45,15 @@ public class YamlSchemaFactoryTest {
// then
assertThat(schema).isNotNull();
- assertThat(schema.getRootNodes()).hasSize(3);
- assertThat(schema.getRootNodes().get(0).getName()).isEqualTo("root1");
- assertThat(schema.getRootNodes().get(1).getName()).isEqualTo("root2");
- assertThat(schema.getRootNodes().get(2).getName()).isEqualTo("root3");
+ assertThat(schema.getRootNodes())
+ .extracting(YamlSchemaNode::getName)
+ .containsExactly("root1", "root2", "root3");
}
@Test
- public void shouldCreateYamlSchemaFromYamlDocument()
- throws YamlProcessingException {
-
+ void shouldCreateYamlSchemaFromYamlDocument()
+ throws YamlProcessingException {
// given
YamlDocument documents = YamlLoadingUtils.loadSimpleValidYamlSchemaFile();
@@ -66,57 +64,52 @@ public class YamlSchemaFactoryTest {
assertThat(schema).isNotNull();
assertThat(schema.getRootNodes()).hasSize(1);
YamlSchemaNode pmMetaData = schema.getRootNodes().get(0);
- assertThatBranchNodeIsValid(pmMetaData, "pmMetaData","/", true, EMPTY_COMMENT,
- 2);
+ assertThatBranchNodeIsValid(pmMetaData, "pmMetaData", "/", true, EMPTY_COMMENT,
+ 2);
YamlSchemaNode pmHeader = pmMetaData.getNextNodes().get(1);
- assertThatBranchNodeIsValid(pmHeader, "pmHeader","/pmMetaData/", true, EMPTY_COMMENT,
- 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);
+ 2);
YamlSchemaNode measChangeType = pmFields.getNextNodes().get(1);
assertThatLeafNodeIsValid(measChangeType, "measChangeType", "/pmMetaData/pmFields/",
- true, "measChangeType comment",
- "added", "modified", "deleted");
+ true, "measChangeType comment",
+ "added", "modified", "deleted");
YamlSchemaNode measAdditionalFields = pmFields.getNextNodes().get(0);
assertThatBranchNodeIsValid(measAdditionalFields, "measAdditionalFields", "/pmMetaData/pmFields/",
- true, "measAdditionalFields comment",
- 2);
+ true, "measAdditionalFields comment",
+ 2);
YamlSchemaNode vendorField1 = measAdditionalFields.getNextNodes().get(0);
assertThatLeafNodeIsValid(vendorField1, "vendorField1", "/pmMetaData/pmFields/measAdditionalFields/",
- true, "vendorField1 comment",
- "X", "Y", "Z");
+ true, "vendorField1 comment",
+ "X", "Y", "Z");
YamlSchemaNode vendorField2 = measAdditionalFields.getNextNodes().get(1);
assertThatLeafNodeIsValid(vendorField2, "vendorField2", "/pmMetaData/pmFields/measAdditionalFields/",
- false, "vendorField2 comment",
- "A", "B");
+ false, "vendorField2 comment",
+ "A", "B");
}
@Test
- public void shouldThrowYamlParsingExceptionWhenLoadedSchemaIsInvalid()
- throws YamlDocumentParsingException {
-
+ 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")
- )
- );
+ //when then
+ assertThatThrownBy(() -> new YamlSchemaFactory().createTreeStructuredYamlSchema(documents))
+ .isInstanceOf(YamlDocumentParsingException.class)
+ .hasMessageContaining(String.format(
+ "Fail to parse given objects: %s as yaml document",
+ documents.getSubStructure("pmMetaData").getYaml().get("structure"))
+ );
}
-
}
diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java
index d35e3b2..646b8a2 100644
--- a/csarvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java
+++ b/pmdictionaryvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java
@@ -17,8 +17,7 @@
package org.onap.validation.yaml.schema.node;
-import org.assertj.core.util.Lists;
-import org.junit.Test;
+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;
@@ -29,7 +28,7 @@ import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.onap.validation.yaml.schema.node.YamlSchemaNodeFactory.EMPTY_COMMENT;
public class YamlSchemaNodeFactoryTest {
@@ -37,87 +36,82 @@ public class YamlSchemaNodeFactoryTest {
private static final String ROOT_PATH = "/";
@Test
- public void shouldThrowExceptionDuringLazyLoadingWhenLoadedSchemaHaveInvalidSubStructure()
- throws YamlProcessingException {
+ void shouldThrowExceptionDuringLazyLoadingWhenLoadedSchemaHaveInvalidSubStructure()
+ throws YamlProcessingException {
// given
String nodeName = "pmMetaData";
-
YamlDocument document = YamlLoadingUtils.loadSimpleInvalidYamlSchemaForLazyLoadingFile();
YamlSchemaNode node = new YamlSchemaNodeFactory()
- .createNode(nodeName, ROOT_PATH, document.getSubStructure(nodeName));
-
- // when/then
- assertThatThrownBy(node::getNextNodes
- ).isInstanceOf(YamlSchemaNode.YamlSchemaProcessingException.class)
- .hasMessageContaining(
- "Lazy loading failed, due to yaml parsing exception."
- );
+ .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
- public void shouldCreateLeafNodeIfGivenYamlDocumentHaveNoSubStructure()
- throws YamlProcessingException {
+ void shouldCreateLeafNodeIfGivenYamlDocumentHaveNoSubStructure()
+ throws YamlProcessingException {
// given
String nodeName = "leaf_test";
String comment = "test leaf node";
- List<String> acceptedValues = Lists.list("val1", "val2");
- Map<Object, Object> nodeInYamlFormat = new HashMap<>();
- nodeInYamlFormat.put(YamlSchemaNodeFactory.PRESENCE_KEY, YamlSchemaNodeFactory.PRESENCE_REQUIRED_KEY);
- nodeInYamlFormat.put(YamlSchemaNodeFactory.COMMENT_KEY, comment);
- nodeInYamlFormat.put(YamlSchemaNodeFactory.VALUE_KET, acceptedValues);
- YamlDocument document = new YamlDocumentFactory().createYamlDocument(
- nodeInYamlFormat
- );
+ List<String> acceptedValues = List.of("val1", "val2");
+ Map<Object, Object> 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[acceptedValues.size()])
+ yamlSchemaNode, nodeName, ROOT_PATH, true, comment,
+ acceptedValues.toArray(new String[0])
);
}
@Test
- public void shouldCreateBranchNodeIfGivenYamlDocumentHaveSubStructure()
- throws YamlProcessingException {
+ void shouldCreateBranchNodeIfGivenYamlDocumentHaveSubStructure()
+ throws YamlProcessingException {
// given
String nodeName = "branch_test";
String comment = "test branch node";
- Map<Object, Object> subStructure = new HashMap<>();
String subNode1Name = "branch_test_node1";
String subNode2Name = "branch_test_node2";
- subStructure.put(subNode1Name, new HashMap<>());
- subStructure.put(subNode2Name, new HashMap<>());
-
- Map<Object, Object> nodeInYamlFormat = new HashMap<>();
- nodeInYamlFormat.put(YamlSchemaNodeFactory.PRESENCE_KEY, YamlSchemaNodeFactory.PRESENCE_REQUIRED_KEY);
- nodeInYamlFormat.put(YamlSchemaNodeFactory.COMMENT_KEY, comment);
- nodeInYamlFormat.put(YamlSchemaNodeFactory.STRUCTURE_KEY, subStructure);
- YamlDocument document = new YamlDocumentFactory().createYamlDocument(
- nodeInYamlFormat
- );
+
+ Map<Object, Object> subStructure = Map.of(
+ subNode1Name, new HashMap<>(),
+ subNode2Name, new HashMap<>());
+
+ Map<Object, Object> 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);
-
+ assertThatBranchNodeIsValid(yamlSchemaNode, nodeName, ROOT_PATH, true, comment, 2);
List<YamlSchemaNode> subNodes = yamlSchemaNode.getNextNodes();
assertThat(subNodes).hasSize(2);
assertThatLeafNodeIsValid(
- subNodes.get(1), subNode1Name, ROOT_PATH + nodeName + "/", false, EMPTY_COMMENT);
+ subNodes.get(1), subNode1Name, ROOT_PATH + nodeName + "/", false, EMPTY_COMMENT);
assertThatLeafNodeIsValid(
- subNodes.get(0), subNode2Name, ROOT_PATH + nodeName + "/", false, EMPTY_COMMENT);
+ 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
+ YamlSchemaNode yamlSchemaNode, String name, String path, boolean isRequired, String comment,
+ int numberOfSubNodes
) throws YamlSchemaNode.YamlSchemaProcessingException {
assertThatNodeIsValid(yamlSchemaNode, name, path, isRequired, comment);
@@ -128,8 +122,8 @@ public class YamlSchemaNodeFactoryTest {
}
public static void assertThatLeafNodeIsValid(
- YamlSchemaNode yamlSchemaNode, String name, String path, boolean isRequired, String comment,
- String... acceptedValues
+ YamlSchemaNode yamlSchemaNode, String name, String path, boolean isRequired, String comment,
+ String... acceptedValues
) throws YamlSchemaNode.YamlSchemaProcessingException {
assertThatNodeIsValid(yamlSchemaNode, name, path, isRequired, comment);
diff --git a/csarvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml
index aab34fa..aab34fa 100644
--- a/csarvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml
+++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml
diff --git a/csarvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml
index 12a4af9..12a4af9 100644
--- a/csarvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml
+++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml
diff --git a/csarvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml
index f4cbddf..f4cbddf 100644
--- a/csarvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml
+++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml
diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml
index 25c72cd..25c72cd 100644
--- a/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml
+++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml
diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml
index c5e7b7c..c5e7b7c 100644
--- a/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml
+++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml
diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml
index 7f9f946..7f9f946 100644
--- a/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml
+++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml
diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml
index 2cac9e6..2cac9e6 100644
--- a/csarvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml
+++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml
diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml
index a125b13..a125b13 100644
--- a/csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml
+++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml
diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml
index d73ca4f..d73ca4f 100644
--- a/csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml
+++ b/pmdictionaryvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml
diff --git a/pom.xml b/pom.xml
index c150b7f..f90c49e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.onap.vnfsdk.validation</groupId>
<artifactId>validation</artifactId>
- <version>1.2.15-SNAPSHOT</version>
+ <version>1.2.16-SNAPSHOT</version>
<name>vnfsdk-validation</name>
<packaging>pom</packaging>
@@ -25,6 +25,7 @@
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
+ <onap.release>Honolulu</onap.release>
</properties>
<scm>
@@ -34,6 +35,7 @@
<modules>
<module>csarvalidation</module>
<module>deployment</module>
+ <module>pmdictionaryvalidation</module>
</modules>
<build>
diff --git a/releases/1.2.15-maven.yaml b/releases/1.2.15-maven.yaml
new file mode 100644
index 0000000..ea5f1c8
--- /dev/null
+++ b/releases/1.2.15-maven.yaml
@@ -0,0 +1,5 @@
+---
+distribution_type: maven
+version: '1.2.15'
+project: 'vnfsdk-validation'
+log_dir: 'vnfsdk-validation-maven-stage-master/529'
diff --git a/version.properties b/version.properties
index c34e299..b19efb8 100644
--- a/version.properties
+++ b/version.properties
@@ -5,7 +5,7 @@
major=1
minor=2
-patch=15
+patch=16
base_version=${major}.${minor}.${patch}