Java Code Examples for org.everit.json.schema.ObjectSchema#validate()
The following examples show how to use
org.everit.json.schema.ObjectSchema#validate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchemaLoaderTest.java From json-schema with Apache License 2.0 | 5 votes |
@Test public void applyDefaultNumberTest() { JSONObject rawSchema = ALL_SCHEMAS.getJSONObject("defaultsTest"); ObjectSchema schema = (ObjectSchema) SchemaLoader .builder() .useDefaults(true) .schemaJson(rawSchema) .build().load().build(); JSONObject obj = new JSONObject(); schema.validate(obj); assertEquals(10, obj.getNumber("numberDefault")); }
Example 2
Source File: SchemaLoaderTest.java From json-schema with Apache License 2.0 | 5 votes |
@Test public void applyDefaultStringTest() { JSONObject rawSchema = ALL_SCHEMAS.getJSONObject("defaultsTest"); ObjectSchema schema = (ObjectSchema) SchemaLoader .builder() .useDefaults(true) .schemaJson(rawSchema) .build().load().build(); JSONObject obj = new JSONObject(); schema.validate(obj); assertEquals("yee", obj.getString("stringDefault")); }
Example 3
Source File: SchemaLoaderTest.java From json-schema with Apache License 2.0 | 5 votes |
@Test public void applyDefaultBooleanTest() { JSONObject rawSchema = ALL_SCHEMAS.getJSONObject("defaultsTest"); ObjectSchema schema = (ObjectSchema) SchemaLoader .builder() .useDefaults(true) .schemaJson(rawSchema) .build().load().build(); JSONObject obj = new JSONObject(); schema.validate(obj); assertEquals(true, obj.getBoolean("booleanDefault")); }
Example 4
Source File: SchemaLoaderTest.java From json-schema with Apache License 2.0 | 5 votes |
@Test public void applyDefaultObjectTest() { JSONObject rawSchema = ALL_SCHEMAS.getJSONObject("defaultsTest"); ObjectSchema schema = (ObjectSchema) SchemaLoader .builder() .useDefaults(true) .schemaJson(rawSchema) .build().load().build(); JSONObject obj = new JSONObject(); schema.validate(obj); assertEquals(new JSONObject("{\"hello\": \"world\"}").toString(), obj.getJSONObject("objectDefault").toString()); }
Example 5
Source File: SchemaLoaderTest.java From json-schema with Apache License 2.0 | 5 votes |
@Test public void applyDefaultArrayTest() { JSONObject rawSchema = ALL_SCHEMAS.getJSONObject("defaultsTest"); ObjectSchema schema = (ObjectSchema) SchemaLoader .builder() .useDefaults(true) .schemaJson(rawSchema) .build().load().build(); JSONObject obj = new JSONObject(); schema.validate(obj); assertEquals(new JSONArray("[\"a\",\"b\",\"c\"]").toString(), obj.getJSONArray("arrayDefault").toString()); }
Example 6
Source File: SchemaLoaderTest.java From json-schema with Apache License 2.0 | 5 votes |
@Test public void applyDefaultNullTest() { JSONObject rawSchema = ALL_SCHEMAS.getJSONObject("defaultsTest"); ObjectSchema schema = (ObjectSchema) SchemaLoader .builder() .useDefaults(true) .schemaJson(rawSchema) .build().load().build(); JSONObject obj = new JSONObject(); schema.validate(obj); assertEquals(JSONObject.NULL, obj.get("nullDefault")); }
Example 7
Source File: DefinesPropertyTest.java From json-schema with Apache License 2.0 | 5 votes |
@Test public void testOfTest() { ObjectSchema actual = (ObjectSchema) SchemaLoader.load(get("patternPropsAndSchemaDeps")); JSONObject input = ResourceLoader.DEFAULT .readObj("objecttestcases.json") .getJSONObject("validOfPatternPropsAndSchemaDeps"); actual.validate(input); }