Search in sources :

Example 16 with JsonSchema

use of org.leadpony.justify.api.JsonSchema in project tcases by Cornutum.

the class GeneratorSetJsonReader method getGeneratorSet.

/**
 * Returns a {@link IGeneratorSet} instance.
 */
@Override
public IGeneratorSet getGeneratorSet() {
    JsonValidationService service = JsonValidationService.newInstance();
    JsonSchema schema = service.readSchema(getClass().getResourceAsStream("/schema/generators-schema.json"));
    ProblemHandler handler = ProblemHandler.throwing();
    try (JsonReader reader = service.createReader(stream_, schema, handler)) {
        JsonObject json;
        try {
            json = reader.readObject();
        } catch (Exception e) {
            throw new GeneratorSetException("Invalid generator set definition", e);
        }
        return GeneratorSetJson.asGeneratorSet(json);
    }
}
Also used : ProblemHandler(org.leadpony.justify.api.ProblemHandler) JsonValidationService(org.leadpony.justify.api.JsonValidationService) JsonSchema(org.leadpony.justify.api.JsonSchema) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject)

Example 17 with JsonSchema

use of org.leadpony.justify.api.JsonSchema in project tcases by Cornutum.

the class SystemTestJsonReader method getSystemTestDef.

/**
 * Returns a {@link SystemTestDef} instance.
 */
@Override
public SystemTestDef getSystemTestDef() {
    JsonValidationService service = JsonValidationService.newInstance();
    JsonSchema schema = service.readSchema(getClass().getResourceAsStream("/schema/system-test-schema.json"));
    ProblemHandler handler = ProblemHandler.throwing();
    try (JsonReader reader = service.createReader(stream_, schema, handler)) {
        JsonObject json;
        try {
            json = reader.readObject();
        } catch (Exception e) {
            throw new SystemTestException("Invalid system test definition", e);
        }
        return SystemTestJson.asSystemTestDef(json);
    }
}
Also used : ProblemHandler(org.leadpony.justify.api.ProblemHandler) JsonValidationService(org.leadpony.justify.api.JsonValidationService) JsonSchema(org.leadpony.justify.api.JsonSchema) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject)

Aggregations

JsonSchema (org.leadpony.justify.api.JsonSchema)17 ProblemHandler (org.leadpony.justify.api.ProblemHandler)13 JsonValidationService (org.leadpony.justify.api.JsonValidationService)10 ArrayList (java.util.ArrayList)7 JsonReader (javax.json.JsonReader)7 StringReader (java.io.StringReader)5 JsonObject (javax.json.JsonObject)5 JsonReader (jakarta.json.JsonReader)4 List (java.util.List)4 InputStream (java.io.InputStream)3 JsonSchemaReader (org.leadpony.justify.api.JsonSchemaReader)3 Problem (org.leadpony.justify.api.Problem)3 JsonArray (jakarta.json.JsonArray)2 JsonException (jakarta.json.JsonException)2 JsonObject (jakarta.json.JsonObject)2 JsonPatch (jakarta.json.JsonPatch)2 JsonProvider (jakarta.json.spi.JsonProvider)2 JsonParser (jakarta.json.stream.JsonParser)2 IOException (java.io.IOException)2 JsonParser (javax.json.stream.JsonParser)2