Added DataSystem schema validation when the DataSystem resource is present
This commit is contained in:
parent
5fdf4f9158
commit
2677a2646f
|
@ -39,6 +39,9 @@ dependencies {
|
|||
compile 'io.cucumber:cucumber-junit:5.4.0'
|
||||
|
||||
compile 'net.masterthought:cucumber-reporting:5.1.1'
|
||||
|
||||
compile 'com.networknt:json-schema-validator:1.0.35'
|
||||
|
||||
}
|
||||
|
||||
configurations {
|
||||
|
|
|
@ -454,7 +454,7 @@ Feature: Web API Server 1.0.2 Certification
|
|||
And the response is valid JSON
|
||||
And the response has results
|
||||
|
||||
@REQ-WA103-QM3 @platinum @2.4.6 @queryability-endorsement
|
||||
@REQ-WA103-QM3 @platinum @2.4.6 @queryability-endorsement @deprecated
|
||||
Scenario: REQ-WA103-QM3 - Support Literals: $any
|
||||
When a GET request is made to the resolved Url in "REQ-WA103-QM3"
|
||||
Then the server responds with a status code of 200
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
package org.reso.certification.stepdefs;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.fasterxml.jackson.databind.node.POJONode;
|
||||
import com.networknt.schema.JsonSchema;
|
||||
import com.networknt.schema.JsonSchemaFactory;
|
||||
import com.networknt.schema.ValidationMessage;
|
||||
import io.cucumber.java8.En;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
@ -31,6 +35,7 @@ import org.reso.models.Settings;
|
|||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
|
@ -237,12 +242,30 @@ public class WebAPIServer_1_0_2 implements En {
|
|||
});
|
||||
|
||||
/*
|
||||
* REQ-WA103-END2
|
||||
* REQ-WA103-END2 - validate DataSystem endpoint, if present.
|
||||
*/
|
||||
And("^the results match the expected DataSystem JSON schema$", () -> {
|
||||
//TODO - need to add JSON Schema for DataSystem
|
||||
});
|
||||
if (responseCode.get() == HttpStatus.SC_OK && responseData.get() != null) {
|
||||
try {
|
||||
JsonSchemaFactory factory = JsonSchemaFactory.getInstance();
|
||||
InputStream is = Thread.currentThread().getContextClassLoader()
|
||||
.getResourceAsStream("datasystem.schema.4.json");
|
||||
JsonSchema schema = factory.getSchema(is);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node = mapper.readTree(responseData.get());
|
||||
|
||||
if (node.findPath(JSON_VALUE_PATH).size() > 0) {
|
||||
Set<ValidationMessage> errors = schema.validate(node);
|
||||
assertEquals("ERROR: data system response does not match the RESO specification. See: https://github.com/RESOStandards/web-api-commander/tree/master/src/main/resources/datasystem.schema.4.json",
|
||||
0, errors.size());
|
||||
LOG.info("DataSystem response matches reference schema!");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Edm Metadata Validator
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"type": "object",
|
||||
"title": "The Root Schema",
|
||||
"description": "The root schema comprises the entire JSON document.",
|
||||
"required": [
|
||||
"@odata.context",
|
||||
"value"
|
||||
],
|
||||
"properties": {
|
||||
"@odata.context": {
|
||||
"type": "string",
|
||||
"title": "The @odata.context Schema",
|
||||
"description": "The @odata.context variable is required for odata.metadata=minimal and above, and tells the user where the results came from.",
|
||||
"default": ""
|
||||
},
|
||||
"value": {
|
||||
"type": "array",
|
||||
"title": "OData value array",
|
||||
"description": "OData responses return their values in an array.",
|
||||
"default": [],
|
||||
"items": {
|
||||
"type": "object",
|
||||
"title": "Data System Items",
|
||||
"description": "Each item represents a potential data system configuration.",
|
||||
"default": {},
|
||||
"required": [
|
||||
"kind",
|
||||
"name",
|
||||
"url"
|
||||
],
|
||||
"properties": {
|
||||
"kind": {
|
||||
"type": "string",
|
||||
"title": "The Kind Schema",
|
||||
"description": "The kind of object a consumer of the service can expect.",
|
||||
"default": ""
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"title": "The Name Schema",
|
||||
"description": "The name of the resource that can be retrieved from the data system.",
|
||||
"default": ""
|
||||
},
|
||||
"url": {
|
||||
"type": "string",
|
||||
"title": "The Url Schema",
|
||||
"description": "The URL for this resource, which may either be absolute or relative to the service root.",
|
||||
"default": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue