Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MODE-1474 - Changed schema validation so that "enum" validation is ca…

…se insensitive
  • Loading branch information...
commit b9c6632fabcd922aaadc947c377602e8a16d0f1c 1 parent e2e665f
@hchiorean hchiorean authored rhauch committed
View
11 modeshape-schematic/src/main/java/org/infinispan/schematic/internal/schema/JsonSchemaValidatorFactory.java
@@ -1061,12 +1061,15 @@ public String toString() {
protected static class EnumValidator implements Validator {
private static final long serialVersionUID = 1L;
private final String propertyName;
- private final Set<?> values;
+ private final Set<String> values;
public EnumValidator( String propertyName,
Collection<?> values ) {
this.propertyName = propertyName;
- this.values = new HashSet<Object>(values);
+ this.values = new HashSet<String>(values.size());
+ for (Object value : values) {
+ this.values.add(value.toString().toLowerCase());
+ }
}
@Override
@@ -1080,7 +1083,7 @@ public void validate( Object fieldValue,
// This only applies if the value is a JSON array ...
if (fieldValue instanceof List) {
for (Object value : (List<?>)fieldValue) {
- if (values.contains(value)) {
+ if (values.contains(value.toString().toLowerCase())) {
problems.recordSuccess();
} else {
problems.recordError(pathToParent.with(fieldName),
@@ -1089,7 +1092,7 @@ public void validate( Object fieldValue,
}
}
} else if (fieldValue != null) {
- if (values.contains(fieldValue)) {
+ if (values.contains(fieldValue.toString().toLowerCase())) {
problems.recordSuccess();
} else {
problems.recordError(pathToParent.with(fieldName), "The '" + fieldName + "' field on '" + pathToParent
View
8 modeshape-schematic/src/test/java/org/infinispan/schematic/SchemaValidationTest.java
@@ -27,6 +27,8 @@ public static void beforeAll() throws Exception {
docs.put("json/sample-repo-config.json", Json.read(resource("json/sample-repo-config.json")));
docs.put("json/empty.json", Json.read(resource("json/empty.json")));
docs.put("json/schema/repository-config-schema.json", Json.read(resource("json/schema/repository-config-schema.json")));
+ docs.put("json/schema/enum-example.json", Json.read(resource("json/schema/enum-example.json")));
+ docs.put("json/enum-example-doc.json", Json.read(resource("json/enum-example-doc.json")));
}
protected static InputStream resource( String resourcePath ) {
@@ -71,6 +73,12 @@ public void shouldBeAbleToValidateSampleDocumentUsingSchemaDocument() throws Exc
}
@Test
+ public void shouldBeAbleToValidateDocumentUsingCaseInsensitiveEnums() throws Exception {
+ results = validate("json/enum-example-doc.json", "json/schema/enum-example.json");
+ assertNoProblems(results);
+ }
+
+ @Test
public void shouldNotBeAbleToValidateEmptyDocumentUsingSchemaDocument() throws Exception {
results = validate("json/empty.json", "json/schema/repository-config-schema.json");
assert results.errorCount() == 1;
View
5 modeshape-schematic/src/test/resources/json/enum-example-doc.json
@@ -0,0 +1,5 @@
+{
+ "color1":"rEd",
+ "color2":"GREEN",
+ "color3":"Blue"
+}
View
23 modeshape-schematic/src/test/resources/json/schema/enum-example.json
@@ -0,0 +1,23 @@
+{
+ "name":"Colors",
+ "properties":{
+ "color1":{
+ "type":"string",
+ "enum" : ["red", "green", "blue"],
+ "description":"Colors enum",
+ "required":true
+ },
+ "color2":{
+ "type":"string",
+ "enum" : ["red", "green", "blue"],
+ "description":"Colors enum",
+ "required":true
+ },
+ "color3":{
+ "type":"string",
+ "enum" : ["red", "green", "blue"],
+ "description":"Colors enum",
+ "required":true
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.