MutationSchemaValidator implements Validator<MysqlMutation> { @Override public void validate(@NonNull final MysqlMutation mutation) { log.debug("Validating schema for mutation: {}", mutation); if (!hasValidSchema(mutation.getRow())) { log.warn("Invalid schema detected for mutation: {}", mutation); handler.accept(mutation); } }  @Override void validate(@NonNull final MysqlMutation mutation); @Override void reset();  }
@Test public void testValidSchema() throws Exception { Row row = new Row( TABLE, ImmutableMap.of( ID_COLUMN, createColumn(ID_COLUMN, ColumnDataType.LONGLONG, true, 1L, 0), NAME_COLUMN, createColumn(NAME_COLUMN, ColumnDataType.VARCHAR, false, "bob", 1), AGE_COLUMN, createColumn(AGE_COLUMN, ColumnDataType.INT24, false, 25, 2))); validator.validate(createMutation(row)); }
@Test(expected = IllegalStateException.class) public void testMissingColumn() throws Exception { Row row = new Row( TABLE, ImmutableMap.of( ID_COLUMN, createColumn(ID_COLUMN, ColumnDataType.LONGLONG, true, 1L, 0), NAME_COLUMN, createColumn(NAME_COLUMN, ColumnDataType.VARCHAR, false, "bob", 1))); validator.validate(createMutation(row)); }
@Test(expected = IllegalStateException.class) public void testIncorrectColumn() throws Exception { Row row = new Row( TABLE, ImmutableMap.of( ID_COLUMN, createColumn(ID_COLUMN, ColumnDataType.LONGLONG, true, 1L, 0), NAME_COLUMN, createColumn(NAME_COLUMN, ColumnDataType.VARCHAR, false, "bob", 1), AGE_COLUMN, createColumn(AGE_COLUMN, ColumnDataType.INT24, false, 25, 2), "bad_column", createColumn("bad_column", ColumnDataType.VARCHAR, false, "bad", 3))); validator.validate(createMutation(row)); }
@Test(expected = IllegalStateException.class) public void testIncorrectColumnDataType() throws Exception { Row row = new Row( TABLE, ImmutableMap.of( ID_COLUMN, createColumn(ID_COLUMN, ColumnDataType.LONGLONG, true, 1L, 0), NAME_COLUMN, createColumn(NAME_COLUMN, ColumnDataType.VARCHAR, false, "bob", 1), AGE_COLUMN, createColumn(AGE_COLUMN, ColumnDataType.LONGLONG, false, 25, 2))); validator.validate(createMutation(row)); }