@Test public void testValidateWrongButCoerceableType() throws ParseException { final List<RecordField> fields = new ArrayList<>(); fields.add(new RecordField("id", RecordFieldType.INT.getDataType())); final RecordSchema schema = new SimpleRecordSchema(fields); final Map<String, Object> valueMap = new LinkedHashMap<>(); valueMap.put("id", 1); Record record = new MapRecord(schema, valueMap); final SchemaValidationContext strictValidationContext = new SchemaValidationContext(schema, false, true); final SchemaValidationContext lenientValidationContext = new SchemaValidationContext(schema, false, false); StandardSchemaValidator validator = new StandardSchemaValidator(strictValidationContext); SchemaValidationResult result = validator.validate(record); assertTrue(result.isValid()); assertNotNull(result.getValidationErrors()); assertTrue(result.getValidationErrors().isEmpty()); validator = new StandardSchemaValidator(lenientValidationContext); result = validator.validate(record); assertTrue(result.isValid()); assertNotNull(result.getValidationErrors()); assertTrue(result.getValidationErrors().isEmpty()); valueMap.put("id", "1"); record = new MapRecord(schema, valueMap); validator = new StandardSchemaValidator(strictValidationContext); result = validator.validate(record); assertFalse(result.isValid()); final Collection<ValidationError> validationErrors = result.getValidationErrors(); assertEquals(1, validationErrors.size()); final ValidationError validationError = validationErrors.iterator().next(); assertEquals("/id", validationError.getFieldName().get()); validator = new StandardSchemaValidator(lenientValidationContext); result = validator.validate(record); assertTrue(result.isValid()); assertNotNull(result.getValidationErrors()); assertTrue(result.getValidationErrors().isEmpty()); }
@Override public SchemaValidationResult validate(final Record record) { return validate(record, validationContext.getSchema(), ""); }
StandardSchemaValidator implements RecordSchemaValidator { @Override public SchemaValidationResult validate(final Record record) { return validate(record, validationContext.getSchema(), ""); } }
StandardSchemaValidator implements RecordSchemaValidator { @Override public SchemaValidationResult validate(final Record record) { return validate(record, validationContext.getSchema(), ""); } StandardSchemaValidator(final SchemaValidationContext validationContext); }
StandardSchemaValidator implements RecordSchemaValidator { @Override public SchemaValidationResult validate(final Record record) { return validate(record, validationContext.getSchema(), ""); } StandardSchemaValidator(final SchemaValidationContext validationContext); @Override SchemaValidationResult validate(final Record record); }
StandardSchemaValidator implements RecordSchemaValidator { @Override public SchemaValidationResult validate(final Record record) { return validate(record, validationContext.getSchema(), ""); } StandardSchemaValidator(final SchemaValidationContext validationContext); @Override SchemaValidationResult validate(final Record record);  }