SchemaValidation implements ValidateInterface<Schema> { @Override public void check(Schema input) throws AbstractValidationException { new NamingConvensionValidation().check(input.getName()); Set<String> tableNames = Sets.newHashSet(); for (Table cur : input.getTableList()) { if (tableNames.contains(cur.getName())) { throw new NameDuplicationException(cur.getName()); } else { tableNames.add(cur.getName()); } tableValidator.check(cur);; } }  @Override void check(Schema input);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void checkUndefinedTable() throws AbstractValidationException { String json_str = "{\r\n" + " \"schema\": \"simple_schema\",\r\n" + " \"table_list\": [\r\n" + " {\r\n" + " \"table\": \"main_table\",\r\n" + " \"fields\": [\r\n" + " {\"id\": 1, \"name\": \"long_required_column\", \"type\": \"Long\", \"isRequired\": true, \"isFrequentlyUsed\": true},\r\n" + " {\"id\": 2, \"name\": \"int_sorted_column\", \"type\": \"Integer\", \"isRequired\": true, \"isDesSortKey\": true},\r\n" + " {\"id\": 3, \"name\": \"byte_column\", \"type\": \"Byte\", \"default\": \"-1\"},\r\n" + " {\"id\": 4, \"name\": \"boolean_column\", \"type\": \"Boolean\", \"default\": \"false\"},\r\n" + " {\"id\": 5, \"name\": \"nested_table_column\", \"type\": \"List:first_level_nested_table\", \"hasLargeList\": true}\r\n" + " ]\r\n" + " }\r\n" + " ]\r\n" + "}"; Schema schema = new JsonSchemaConvertor().apply(json_str); new SchemaValidation().check(schema); }
@Test(expectedExceptions = IllegalTableVersionException.class) public void checkTableVersion() throws AbstractValidationException { String json_str = "{\r\n" + " \"schema\": \"simple_schema\",\r\n" + " \"table_list\": [\r\n" + " {\r\n" + " \"table\": \"main_table\",\r\n" + " \"version\": \"-1\",\r\n" + " \"fields\": [\r\n" + " {\"id\": 1, \"name\": \"long_required_column\", \"type\": \"Long\", \"isRequired\": true, \"isFrequentlyUsed\": true},\r\n" + " {\"id\": 2, \"name\": \"int_sorted_column\", \"type\": \"Integer\", \"isRequired\": true, \"isDesSortKey\": true},\r\n" + " {\"id\": 3, \"name\": \"byte_column\", \"type\": \"Byte\", \"default\": \"-1\"},\r\n" + " {\"id\": 4, \"name\": \"boolean_column\", \"type\": \"Boolean\", \"default\": \"false\"}\r\n" + " ]\r\n" + " }\r\n" + " ]\r\n" + "}"; Schema schema = new JsonSchemaConvertor().apply(json_str); new SchemaValidation().check(schema); }
@Test(expectedExceptions = IdentityDuplicationException.class) public void checkFieldDuplicateId() throws AbstractValidationException { String json_str = "{\r\n" + " \"schema\": \"simple_schema\",\r\n" + " \"table_list\": [\r\n" + " {\r\n" + " \"table\": \"main_table\",\r\n" + " \"fields\": [\r\n" + " {\"id\": 1, \"name\": \"long_required_column\", \"type\": \"Long\", \"isRequired\": true, \"isFrequentlyUsed\": true},\r\n" + " {\"id\": 2, \"name\": \"int_required_column\", \"type\": \"Integer\", \"isRequired\": true, \"isDesSortKey\": true},\r\n" + " {\"id\": 3, \"name\": \"byte_column\", \"type\": \"Byte\", \"default\": \"-1\"},\r\n" + " {\"id\": 3, \"name\": \"boolean_column\", \"type\": \"Boolean\", \"default\": \"false\"}\r\n" + " ]\r\n" + " }\r\n" + " ]\r\n" + "}"; Schema schema = new JsonSchemaConvertor().apply(json_str); new SchemaValidation().check(schema); }
@Test(expectedExceptions = IllegalFieldIdentityException.class) public void checkFieldFalseId() throws AbstractValidationException { String json_str = "{\r\n" + " \"schema\": \"simple_schema\",\r\n" + " \"table_list\": [\r\n" + " {\r\n" + " \"table\": \"main_table\",\r\n" + " \"fields\": [\r\n" + " {\"id\": 1, \"name\": \"long_required_column\", \"type\": \"Long\", \"isRequired\": true, \"isFrequentlyUsed\": true},\r\n" + " {\"id\": 5, \"name\": \"int_sorted_column\", \"type\": \"Integer\", \"isRequired\": true, \"isDesSortKey\": true},\r\n" + " {\"id\": 3, \"name\": \"byte_column\", \"type\": \"Byte\", \"default\": \"-1\"},\r\n" + " {\"id\": 4, \"name\": \"boolean_column\", \"type\": \"Boolean\", \"default\": \"false\"}\r\n" + " ]\r\n" + " }\r\n" + " ]\r\n" + "}"; Schema schema = new JsonSchemaConvertor().apply(json_str); new SchemaValidation().check(schema); }
@Test(expectedExceptions = IllegalNamingConversionException.class) public void checkInvalidName() throws AbstractValidationException { String json_str = "{\r\n" + " \"schema\": \"simple_schema\",\r\n" + " \"table_list\": [\r\n" + " {\r\n" + " \"table\": \"main_table\",\r\n" + " \"fields\": [\r\n" + " {\"id\": 1, \"name\": \"_2243+!#long_required_column\", \"type\": \"Long\", \"isRequired\": true, \"isFrequentlyUsed\": true},\r\n" + " {\"id\": 2, \"name\": \"int_sorted_column\", \"type\": \"Integer\", \"isRequired\": true, \"isDesSortKey\": true},\r\n" + " {\"id\": 3, \"name\": \"byte_column\", \"type\": \"Byte\", \"default\": \"-1\"},\r\n" + " {\"id\": 4, \"name\": \"boolean_column\", \"type\": \"Boolean\", \"default\": \"false\"}\r\n" + " ]\r\n" + " }\r\n" + " ]\r\n" + "}"; Schema schema = new JsonSchemaConvertor().apply(json_str); new SchemaValidation().check(schema); }
@Test(expectedExceptions = NameDuplicationException.class) public void checkDuplicateName() throws AbstractValidationException { String json_str = "{\r\n" + " \"schema\": \"simple_schema\",\r\n" + " \"table_list\": [\r\n" + " {\r\n" + " \"table\": \"main_table\",\r\n" + " \"fields\": [\r\n" + " {\"id\": 1, \"name\": \"long_required_column\", \"type\": \"Long\", \"isRequired\": true, \"isFrequentlyUsed\": true},\r\n" + " {\"id\": 2, \"name\": \"long_required_column\", \"type\": \"Integer\", \"isRequired\": true, \"isDesSortKey\": true},\r\n" + " {\"id\": 3, \"name\": \"byte_column\", \"type\": \"Byte\", \"default\": \"-1\"},\r\n" + " {\"id\": 4, \"name\": \"boolean_column\", \"type\": \"Boolean\", \"default\": \"false\"}\r\n" + " ]\r\n" + " }\r\n" + " ]\r\n" + "}"; Schema schema = new JsonSchemaConvertor().apply(json_str); new SchemaValidation().check(schema); }
@Test(expectedExceptions = MultipleSortKeysException.class) public void checkSortKey() throws AbstractValidationException { String json_str = "{\r\n" + " \"schema\": \"simple_schema\",\r\n" + " \"table_list\": [\r\n" + " {\r\n" + " \"table\": \"main_table\",\r\n" + " \"fields\": [\r\n" + " {\"id\": 1, \"name\": \"long_required_column\", \"type\": \"Long\", \"isRequired\": true, \"isDesSortKey\": true, \"isFrequentlyUsed\": true},\r\n" + " {\"id\": 2, \"name\": \"int_sorted_column\", \"type\": \"Integer\", \"isRequired\": true, \"isDesSortKey\": true},\r\n" + " {\"id\": 3, \"name\": \"byte_column\", \"type\": \"Byte\", \"default\": \"-1\"},\r\n" + " {\"id\": 4, \"name\": \"boolean_column\", \"type\": \"Boolean\", \"default\": \"false\"}\r\n" + " ]\r\n" + " }\r\n" + " ]\r\n" + "}"; Schema schema = new JsonSchemaConvertor().apply(json_str); new SchemaValidation().check(schema); }
@Test(expectedExceptions = IllegalFieldIdentityException.class) public void checkFieldId() throws AbstractValidationException { String json_str = "{\r\n" + " \"schema\": \"simple_schema\",\r\n" + " \"table_list\": [\r\n" + " {\r\n" + " \"table\": \"main_table\",\r\n" + " \"fields\": [\r\n" + " {\"id\": 1, \"name\": \"long_required_column\", \"type\": \"Long\", \"isRequired\": true, \"isFrequentlyUsed\": true},\r\n" + " {\"id\": 2, \"name\": \"int_sorted_column\", \"type\": \"Integer\", \"isRequired\": true, \"isDesSortKey\": true},\r\n" + " {\"id\": 3, \"name\": \"byte_column\", \"type\": \"Byte\", \"default\": \"-1\"},\r\n" + " {\"id\": 4, \"name\": \"boolean_column\", \"type\": \"Boolean\", \"default\": \"false\", \"isDerived\": true}\r\n" + " ]\r\n" + " }\r\n" + " ]\r\n" + "}"; Schema schema = new JsonSchemaConvertor().apply(json_str); new SchemaValidation().check(schema); }
@Test(expectedExceptions = IllegalDerivedFieldException.class) public void checkDerivedFieldMustBePrimitive() throws AbstractValidationException { String json_str = "{\r\n" + " \"schema\": \"simple_schema\",\r\n" + " \"table_list\": [\r\n" + " {\r\n" + " \"table\": \"main_table\",\r\n" + " \"fields\": [\r\n" + " {\"id\": 1, \"name\": \"long_required_column\", \"type\": \"Long\", \"isRequired\": true, \"isFrequentlyUsed\": true},\r\n" + " {\"id\": 2, \"name\": \"int_sorted_column\", \"type\": \"Integer\", \"isRequired\": true, \"isDesSortKey\": true},\r\n" + " {\"id\": 3, \"name\": \"byte_column\", \"type\": \"Byte\", \"default\": \"-1\"},\r\n" + " {\"id\": 0, \"name\": \"boolean_column\", \"type\": \"List:Boolean\", \"isDerived\": true}\r\n" + " ]\r\n" + " }\r\n" + " ]\r\n" + "}"; Schema schema = new JsonSchemaConvertor().apply(json_str); new SchemaValidation().check(schema); }
@Test(expectedExceptions = IllegalDerivedFieldException.class) public void checkDerivedFieldMustBeOptional() throws AbstractValidationException { String json_str = "{\r\n" + " \"schema\": \"simple_schema\",\r\n" + " \"table_list\": [\r\n" + " {\r\n" + " \"table\": \"main_table\",\r\n" + " \"fields\": [\r\n" + " {\"id\": 1, \"name\": \"long_required_column\", \"type\": \"Long\", \"isRequired\": true, \"isFrequentlyUsed\": true},\r\n" + " {\"id\": 2, \"name\": \"int_sorted_column\", \"type\": \"Integer\", \"isRequired\": true, \"isDesSortKey\": true},\r\n" + " {\"id\": 3, \"name\": \"byte_column\", \"type\": \"Byte\", \"default\": \"-1\"},\r\n" + " {\"id\": 0, \"name\": \"boolean_column\", \"type\": \"Boolean\", \"default\": \"false\", \"isRequired\": true, \"isDerived\": true}\r\n" + " ]\r\n" + " }\r\n" + " ]\r\n" + "}"; Schema schema = new JsonSchemaConvertor().apply(json_str); new SchemaValidation().check(schema); }
@Test(expectedExceptions = IllegalDerivedFieldException.class) public void checkDerivedFieldCannotBeSortKey() throws AbstractValidationException { String json_str = "{\r\n" + " \"schema\": \"simple_schema\",\r\n" + " \"table_list\": [\r\n" + " {\r\n" + " \"table\": \"main_table\",\r\n" + " \"fields\": [\r\n" + " {\"id\": 1, \"name\": \"long_required_column\", \"type\": \"Long\", \"isRequired\": true, \"isFrequentlyUsed\": true},\r\n" + " {\"id\": 2, \"name\": \"int_sorted_column\", \"type\": \"Integer\", \"isRequired\": true, \"isDesSortKey\": true},\r\n" + " {\"id\": 3, \"name\": \"byte_column\", \"type\": \"Byte\", \"default\": \"-1\"},\r\n" + " {\"id\": 0, \"name\": \"boolean_column\", \"type\": \"Boolean\", \"default\": \"false\", \"isRequired\": true, \"isDesSortKey\": true, \"isDerived\": true}\r\n" + " ]\r\n" + " }\r\n" + " ]\r\n" + "}"; Schema schema = new JsonSchemaConvertor().apply(json_str); new SchemaValidation().check(schema); }
@Test(expectedExceptions = IllegalDerivedFieldException.class) public void checkDerivedFieldCannotBeFrequentlyUsed() throws AbstractValidationException { String json_str = "{\r\n" + " \"schema\": \"simple_schema\",\r\n" + " \"table_list\": [\r\n" + " {\r\n" + " \"table\": \"main_table\",\r\n" + " \"fields\": [\r\n" + " {\"id\": 1, \"name\": \"long_required_column\", \"type\": \"Long\", \"isRequired\": true, \"isFrequentlyUsed\": true},\r\n" + " {\"id\": 2, \"name\": \"int_sorted_column\", \"type\": \"Integer\", \"isRequired\": true, \"isDesSortKey\": true},\r\n" + " {\"id\": 3, \"name\": \"byte_column\", \"type\": \"Byte\", \"default\": \"-1\"},\r\n" + " {\"id\": 0, \"name\": \"boolean_column\", \"type\": \"Boolean\", \"default\": \"false\", \"isFrequentlyUsed\": true, \"isDerived\": true}\r\n" + " ]\r\n" + " }\r\n" + " ]\r\n" + "}"; Schema schema = new JsonSchemaConvertor().apply(json_str); new SchemaValidation().check(schema); }
@Test(expectedExceptions = IllegalFieldRestrictionException.class) public void checkNonCollectionFieldCannotBeLargeList() throws AbstractValidationException { String json_str = "{\r\n" + " \"schema\": \"simple_schema\",\r\n" + " \"table_list\": [\r\n" + " {\r\n" + " \"table\": \"main_table\",\r\n" + " \"fields\": [\r\n" + " {\"id\": 1, \"name\": \"long_required_column\", \"type\": \"Long\", \"isRequired\": true, \"isFrequentlyUsed\": true},\r\n" + " {\"id\": 2, \"name\": \"int_sorted_column\", \"type\": \"Integer\", \"isRequired\": true, \"isDesSortKey\": true, \"hasLargeList\": true},\r\n" + " {\"id\": 3, \"name\": \"byte_column\", \"type\": \"Byte\", \"default\": \"-1\"}\r\n" + " ]\r\n" + " }\r\n" + " ]\r\n" + "}"; Schema schema = new JsonSchemaConvertor().apply(json_str); new SchemaValidation().check(schema); }