AsyncAPISchemaValidator { public static boolean isJsonValid(String schemaText, String jsonText) throws IOException { List<String> errors = validateJson(schemaText, jsonText); if (!errors.isEmpty()) { log.debug("Get validation errors, returning false"); return false; } return true; }  static boolean isJsonValid(String schemaText, String jsonText); static List<String> validateJson(String schemaText, String jsonText); static List<String> validateJson(JsonNode schemaNode, JsonNode jsonNode); static List<String> validateJsonMessage(JsonNode specificationNode, JsonNode jsonNode, String messagePathPointer); static JsonNode getJsonNode(String jsonText); static JsonNode getJsonNodeForSchema(String schemaText);  }
@Test public void testValidateJsonSuccess() { boolean valid = false; String schemaText = null; String jsonText = "{\"fullName\": \"Laurent Broudoux\", \"email\": \"laurent@microcks.io\", \"age\": 41}"; try { schemaText = FileUtils.readFileToString( new File("target/test-classes/io/github/microcks/util/asyncapi/user-signedup-schema.json")); valid = AsyncAPISchemaValidator.isJsonValid(schemaText, jsonText); } catch (Exception e) { fail("Exception should not be thrown"); } assertTrue(valid); }
@Test public void testValidateJsonSuccessFromYaml() { boolean valid = false; String schemaText = null; String jsonText = "{\"fullName\": \"Laurent Broudoux\", \"email\": \"laurent@microcks.io\", \"age\": 41}"; try { schemaText = FileUtils.readFileToString( new File("target/test-classes/io/github/microcks/util/asyncapi/user-signedup-schema.yaml")); valid = AsyncAPISchemaValidator.isJsonValid(schemaText, jsonText); } catch (Exception e) { fail("Exception should not be thrown"); } assertTrue(valid); }
@Test public void testValidateJsonFailure() { boolean valid = false; String schemaText = null; String jsonText = "{\"name\": \"Laurent Broudoux\", \"email\": \"laurent@microcks.io\", \"age\": 41}"; try { schemaText = FileUtils.readFileToString( new File("target/test-classes/io/github/microcks/util/asyncapi/user-signedup-schema.json")); valid = AsyncAPISchemaValidator.isJsonValid(schemaText, jsonText); } catch (Exception e) { fail("Exception should not be thrown"); } assertFalse(valid); }
@Test public void testValidateJsonFailureFromYaml() { boolean valid = false; String schemaText = null; String jsonText = "{\"name\": \"Laurent Broudoux\", \"email\": \"laurent@microcks.io\", \"age\": 41}"; try { schemaText = FileUtils.readFileToString( new File("target/test-classes/io/github/microcks/util/asyncapi/user-signedup-schema.yaml")); valid = AsyncAPISchemaValidator.isJsonValid(schemaText, jsonText); } catch (Exception e) { fail("Exception should not be thrown"); } assertFalse(valid); }