summaryrefslogtreecommitdiffstats
path: root/csarvalidation/src/main
diff options
context:
space:
mode:
authorBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2020-07-21 11:35:49 +0200
committerBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2020-07-21 09:37:20 +0000
commit3dcd5675ad634f5bd3dd859a0362c259de271a06 (patch)
tree6b27163d264c1f2d7037b0b664eb546d87cc4cc7 /csarvalidation/src/main
parentcffcfb03ea1e357a51e80a1c699666cc3b0b3776 (diff)
Add list of values validation using schema in PM Dictionary.
Issue-ID: VNFSDK-594 Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> Change-Id: I1e59bdfb697adb6097636212fa5be8c749f084e6
Diffstat (limited to 'csarvalidation/src/main')
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java3
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java22
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java6
-rw-r--r--csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java4
4 files changed, 7 insertions, 28 deletions
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java b/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java
index 7f80d1c..11582d1 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java
+++ b/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlDocument.java
@@ -39,8 +39,7 @@ public class YamlDocument {
return yaml.get(key).toString();
}
- public YamlParametersList getListOfValues(String key)
- throws YamlParameterListFactory.YamlParameterListParsingException {
+ public YamlParametersList getListOfValues(String key) {
return new YamlParameterListFactory().createYamlParameterList(
yaml.get(key)
);
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java b/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java
index 4ea5ca2..5f41c5c 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java
+++ b/csarvalidation/src/main/java/org/onap/validation/yaml/model/YamlParameterListFactory.java
@@ -17,8 +17,6 @@
package org.onap.validation.yaml.model;
-import org.onap.validation.yaml.exception.YamlProcessingException;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -29,18 +27,7 @@ public class YamlParameterListFactory {
return new YamlParametersList(Collections.emptyList());
}
- public YamlParametersList createYamlParameterList(Object yaml)
- throws YamlParameterListParsingException {
- try {
- return parseYamlToListOfPossibleValues(yaml);
- } catch (ClassCastException e) {
- throw new YamlParameterListParsingException(
- String.format("Fail to parse given objects: %s as list.",yaml), e
- );
- }
- }
-
- private YamlParametersList parseYamlToListOfPossibleValues(Object yaml) {
+ public YamlParametersList createYamlParameterList(Object yaml) {
List<String> parametersList = new ArrayList<>();
if( yaml instanceof List) {
for (Object element : (List) yaml) {
@@ -52,11 +39,4 @@ public class YamlParameterListFactory {
return new YamlParametersList(parametersList);
}
-
- public static class YamlParameterListParsingException extends YamlProcessingException {
- YamlParameterListParsingException(String message, Throwable throwable) {
- super(message, throwable);
- }
- }
-
}
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java b/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java
index e3fadb6..273014b 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java
+++ b/csarvalidation/src/main/java/org/onap/validation/yaml/process/YamlValidationProcess.java
@@ -74,7 +74,9 @@ public class YamlValidationProcess {
private boolean isValueOfNodeInAcceptedValuesList(YamlDocument document, YamlSchemaNode node) {
return node.getAcceptedValues().isEmpty() ||
- node.getAcceptedValues().contains(document.getValue(node.getName()));
+ node.getAcceptedValues().containsAll(
+ document.getListOfValues(node.getName()).getParameters()
+ );
}
private void addNextLevelNodeToValidationNodesQueue(YamlDocument document, YamlSchemaNode node)
@@ -101,7 +103,7 @@ public class YamlValidationProcess {
new SchemaValidationError(
node.getPath() + node.getName(),
String.format(
- "Value is not in array of accepted values.%n value: %s%n accepted values: %s",
+ "Value(s) is/are not in array of accepted values.%n value(s): %s%n accepted value(s): %s",
document.getValue(node.getName()), node.getAcceptedValues())
)
);
diff --git a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java b/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java
index a07935a..79a8f14 100644
--- a/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java
+++ b/csarvalidation/src/main/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactory.java
@@ -24,7 +24,6 @@ import org.onap.validation.yaml.model.YamlParameterListFactory;
import org.onap.validation.yaml.model.YamlParametersList;
import static org.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException;
-import static org.onap.validation.yaml.model.YamlParameterListFactory.YamlParameterListParsingException;
public class YamlSchemaNodeFactory {
@@ -65,8 +64,7 @@ public class YamlSchemaNodeFactory {
: EMPTY_COMMENT;
}
- private YamlParametersList getAcceptedValues(YamlDocument yamlDocument)
- throws YamlParameterListParsingException {
+ private YamlParametersList getAcceptedValues(YamlDocument yamlDocument) {
return isYamlContainingKey(yamlDocument, VALUE_KET)
? new YamlParameterListFactory().createYamlParameterList(yamlDocument.getYaml().get(VALUE_KET))