@Test public void validFileAgainstSchema() throws Exception { GenerateConnectorInspectionsMojo mojo = new GenerateConnectorInspectionsMojo(); JsonNode jsonNode = mojo.validateWithSchema(getFile("/my-test-connector.json")); assertNotNull(jsonNode); }
public JsonNode validateWithSchema(File jsonFile) throws MojoExecutionException { InputStream jsonStream = null; try { jsonStream = new FileInputStream(jsonFile); JsonNode jsonNode = JsonUtils.reader().readTree(jsonStream); ProcessingReport report = jsonSchema.validate(jsonNode, true); if (! report.isSuccess()) { for (final ProcessingMessage processingMessage : report) { getLog().warn(processingMessage.toString()); } throw new MojoExecutionException("Validation of json file " + jsonFile.getName() + " failed, see previous logs"); } return jsonNode; } catch (IOException | ProcessingException ex) { throw new MojoExecutionException("Failure to validate json file " + jsonFile.getName(), ex); } finally { if (jsonStream != null) { try { jsonStream.close(); } catch (IOException e) { getLog().error(e); } } } }
GenerateConnectorInspectionsMojo extends AbstractMojo { public JsonNode validateWithSchema(File jsonFile) throws MojoExecutionException { InputStream jsonStream = null; try { jsonStream = new FileInputStream(jsonFile); JsonNode jsonNode = JsonUtils.reader().readTree(jsonStream); ProcessingReport report = jsonSchema.validate(jsonNode, true); if (! report.isSuccess()) { for (final ProcessingMessage processingMessage : report) { getLog().warn(processingMessage.toString()); } throw new MojoExecutionException("Validation of json file " + jsonFile.getName() + " failed, see previous logs"); } return jsonNode; } catch (IOException | ProcessingException ex) { throw new MojoExecutionException("Failure to validate json file " + jsonFile.getName(), ex); } finally { if (jsonStream != null) { try { jsonStream.close(); } catch (IOException e) { getLog().error(e); } } } } }
GenerateConnectorInspectionsMojo extends AbstractMojo { public JsonNode validateWithSchema(File jsonFile) throws MojoExecutionException { InputStream jsonStream = null; try { jsonStream = new FileInputStream(jsonFile); JsonNode jsonNode = JsonUtils.reader().readTree(jsonStream); ProcessingReport report = jsonSchema.validate(jsonNode, true); if (! report.isSuccess()) { for (final ProcessingMessage processingMessage : report) { getLog().warn(processingMessage.toString()); } throw new MojoExecutionException("Validation of json file " + jsonFile.getName() + " failed, see previous logs"); } return jsonNode; } catch (IOException | ProcessingException ex) { throw new MojoExecutionException("Failure to validate json file " + jsonFile.getName(), ex); } finally { if (jsonStream != null) { try { jsonStream.close(); } catch (IOException e) { getLog().error(e); } } } } GenerateConnectorInspectionsMojo(); }
GenerateConnectorInspectionsMojo extends AbstractMojo { public JsonNode validateWithSchema(File jsonFile) throws MojoExecutionException { InputStream jsonStream = null; try { jsonStream = new FileInputStream(jsonFile); JsonNode jsonNode = JsonUtils.reader().readTree(jsonStream); ProcessingReport report = jsonSchema.validate(jsonNode, true); if (! report.isSuccess()) { for (final ProcessingMessage processingMessage : report) { getLog().warn(processingMessage.toString()); } throw new MojoExecutionException("Validation of json file " + jsonFile.getName() + " failed, see previous logs"); } return jsonNode; } catch (IOException | ProcessingException ex) { throw new MojoExecutionException("Failure to validate json file " + jsonFile.getName(), ex); } finally { if (jsonStream != null) { try { jsonStream.close(); } catch (IOException e) { getLog().error(e); } } } } GenerateConnectorInspectionsMojo(); @Override void execute(); JsonNode validateWithSchema(File jsonFile); static DataShape generateInspections(URL[] classpath, DataShape shape); static JavaClass inspect(URL[] classpath, DataShape shape); }
GenerateConnectorInspectionsMojo extends AbstractMojo { public JsonNode validateWithSchema(File jsonFile) throws MojoExecutionException { InputStream jsonStream = null; try { jsonStream = new FileInputStream(jsonFile); JsonNode jsonNode = JsonUtils.reader().readTree(jsonStream); ProcessingReport report = jsonSchema.validate(jsonNode, true); if (! report.isSuccess()) { for (final ProcessingMessage processingMessage : report) { getLog().warn(processingMessage.toString()); } throw new MojoExecutionException("Validation of json file " + jsonFile.getName() + " failed, see previous logs"); } return jsonNode; } catch (IOException | ProcessingException ex) { throw new MojoExecutionException("Failure to validate json file " + jsonFile.getName(), ex); } finally { if (jsonStream != null) { try { jsonStream.close(); } catch (IOException e) { getLog().error(e); } } } } GenerateConnectorInspectionsMojo(); @Override void execute(); JsonNode validateWithSchema(File jsonFile); static DataShape generateInspections(URL[] classpath, DataShape shape); static JavaClass inspect(URL[] classpath, DataShape shape);  }