use of org.leadpony.justify.api.JsonSchema in project tcases by Cornutum.
the class MocoTestConfigReader method getMocoTestConfig.
/**
* Returns a {@link MocoTestConfig} instance.
*/
public MocoTestConfig getMocoTestConfig() {
JsonValidationService service = JsonValidationService.newInstance();
JsonSchema schema = service.readSchema(getClass().getResourceAsStream("/schema/moco-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 MocoTestConfigException("Invalid Moco test configuration", e);
}
return MocoTestConfigJson.asMocoTestConfig(json);
}
}
use of org.leadpony.justify.api.JsonSchema in project selenium_java by sergueik.
the class SchemaCatalog method findRootSchema.
private JsonSchema findRootSchema(URI id) {
JsonSchema schema = cache.get(id);
if (schema != null) {
return schema;
}
Location resource = get(id);
if (resource == null) {
return null;
}
schema = readReferencedSchema(resource);
if (schema != null) {
cache.put(id, schema);
return schema;
} else {
return null;
}
}
use of org.leadpony.justify.api.JsonSchema in project selenium_java by sergueik.
the class Validate method readSchemaCatalogAt.
private void readSchemaCatalogAt(Location location) {
console.print(READ_CATALOG, location);
JsonSchema schema = readSchemaFromResource("catalog.schema.json");
List<Problem> problems = new ArrayList<>();
ProblemHandler handler = createProblemHandler(problems);
try (JsonParser parser = service.createParser(openCatalog(location), schema, handler)) {
parseCatalog(parser, location);
if (!problems.isEmpty()) {
console.withColor(Color.DANGER).print(CATALOG_INVALID, location, Problems.countLeast(problems));
throw new CommandException(CATALOG_FAILED);
}
} catch (JsonParsingException e) {
console.withColor(Color.DANGER).print(CATALOG_MALFORMED, e);
throw new CommandException(CATALOG_FAILED);
} catch (JsonException e) {
throw new CommandException(e);
}
}
use of org.leadpony.justify.api.JsonSchema in project selenium_java by sergueik.
the class SchemaCatalog method resolveSchema.
@Override
public JsonSchema resolveSchema(URI id) {
String fragment = id.getFragment();
URI baseId = withoutFragment(id);
JsonSchema schema = findRootSchema(baseId);
if (schema == null) {
return null;
}
if (fragment == null) {
return schema;
} else {
return schema.getSubschemaAt(fragment);
}
}
use of org.leadpony.justify.api.JsonSchema in project selenium_java by sergueik.
the class Validate method validateSchemaAt.
/**
* Reads and validates a JSON schema.
*
* @param location the location of the JSON schema to be read and validated.
* @return the schema read if successful, or {@code null} if errors occcured.
*/
private JsonSchema validateSchemaAt(Location location) {
JsonSchemaReaderFactory factory = createSchemaReaderFactory();
try (JsonSchemaReader reader = factory.createSchemaReader(openSchema(location))) {
JsonSchema schema = reader.read();
console.withColor(Color.SUCCESS).print(SCHEMA_VALID, location);
return schema;
} catch (JsonValidatingException e) {
List<Problem> problems = e.getProblems();
problemPrinter.handleProblems(problems);
console.withColor(Color.DANGER).print(SCHEMA_INVALID, location, Problems.countLeast(problems));
setStatus(Status.INVALID);
return null;
} catch (JsonParsingException e) {
console.withColor(Color.DANGER).print(SCHEMA_MALFORMED, e);
setStatus(Status.INVALID);
return null;
} catch (JsonException e) {
throw new CommandException(e);
}
}
Aggregations