JsonSchemaConvertor implements JsonElementVisitor, 
	UnaryOperatorInterface<String, Schema> { @Override public Schema apply(String jsonStr) { JsonSchema js = new Gson().fromJson(jsonStr, JsonSchema.class); if (js == null) { throw new IllegalArgumentException("No valid JsonSchema can be found in \n" + jsonStr); } js.accept(this); embededTableName.removeAll(tableName); if (!embededTableName.isEmpty()) { throw new IllegalArgumentException("Not a valid JsonSchema because " + "no definition can be found for " + embededTableName); } return new Schema(name, tables); }  @Override void visit(JsonSchema schema); @Override void visit(JsonTable table); @Override void visit(JsonField field); @Override Schema apply(String jsonStr);  }
@Test public void getSchema() throws IOException { String filePath = "src/test/resources/RBSchema.json"; BufferedReader br = new BufferedReader(new FileReader(filePath)); JsonSchema jSchema = new Gson().fromJson(br, JsonSchema.class); JsonSchemaConvertor convertor = new JsonSchemaConvertor(); Schema dmSchema = convertor.apply( Files.toString(new File(filePath), Charsets.UTF_8)); Assert.assertEquals(dmSchema.getName(), jSchema.getName()); Assert.assertEquals(dmSchema.getTableList().size(), jSchema.getTableList().size()); }
@Test (expectedExceptions = IllegalArgumentException.class) public void testSchemaValidation() { JsonSchemaConvertor convertor = new JsonSchemaConvertor(); convertor.apply(WRONG_SCHEMA_IN_JSON); }