use of org.apache.nifi.components.ValidationContext in project nifi by apache.
the class TestAvroSchemaRegistry method validateStrictAndNonStrictSchemaRegistrationFromDynamicProperties.
@Test
public void validateStrictAndNonStrictSchemaRegistrationFromDynamicProperties() throws Exception {
String schemaName = "fooSchema";
ConfigurationContext configContext = mock(ConfigurationContext.class);
Map<PropertyDescriptor, String> properties = new HashMap<>();
PropertyDescriptor fooSchema = new PropertyDescriptor.Builder().name(schemaName).dynamic(true).build();
// NOTE: name of record and name of first field are not Avro-compliant, verified below
String fooSchemaText = "{\"namespace\": \"example.avro\", " + "\"type\": \"record\", " + "\"name\": \"$User\", " + "\"fields\": [ " + "{\"name\": \"@name\", \"type\": [\"string\", \"null\"]}, " + "{\"name\": \"favorite_number\", \"type\": [\"int\", \"null\"]}, " + "{\"name\": \"foo\", \"type\": [\"int\", \"null\"]}, " + "{\"name\": \"favorite_color\", \"type\": [\"string\", \"null\"]} " + "]" + "}";
PropertyDescriptor barSchema = new PropertyDescriptor.Builder().name("barSchema").dynamic(false).build();
properties.put(fooSchema, fooSchemaText);
properties.put(barSchema, "");
AvroSchemaRegistry delegate = new AvroSchemaRegistry();
delegate.getSupportedPropertyDescriptors().forEach(prop -> properties.put(prop, prop.getDisplayName()));
when(configContext.getProperties()).thenReturn(properties);
ValidationContext validationContext = mock(ValidationContext.class);
when(validationContext.getProperties()).thenReturn(properties);
PropertyValue propertyValue = mock(PropertyValue.class);
when(validationContext.getProperty(AvroSchemaRegistry.VALIDATE_FIELD_NAMES)).thenReturn(propertyValue);
// Strict parsing
when(propertyValue.asBoolean()).thenReturn(true);
Collection<ValidationResult> results = delegate.customValidate(validationContext);
assertTrue(results.stream().anyMatch(result -> !result.isValid()));
// Non-strict parsing
when(propertyValue.asBoolean()).thenReturn(false);
results = delegate.customValidate(validationContext);
results.forEach(result -> assertTrue(result.isValid()));
}
use of org.apache.nifi.components.ValidationContext in project nifi by apache.
the class TestCSVValidators method testSingleCharTab.
@Test
public void testSingleCharTab() {
CSVValidators.SingleCharacterValidator validator = new CSVValidators.SingleCharacterValidator();
ValidationContext mockContext = Mockito.mock(ValidationContext.class);
ValidationResult result = validator.validate("EscapeChar", "\\t", mockContext);
assertTrue(result.isValid());
}
use of org.apache.nifi.components.ValidationContext in project nifi by apache.
the class TestCSVValidators method testUnescapedSingleCharGoodChar.
@Test
public void testUnescapedSingleCharGoodChar() {
Validator validator = CSVValidators.UNESCAPED_SINGLE_CHAR_VALIDATOR;
ValidationContext mockContext = Mockito.mock(ValidationContext.class);
ValidationResult result = validator.validate("Delimiter", ",", mockContext);
assertTrue(result.isValid());
}
use of org.apache.nifi.components.ValidationContext in project nifi by apache.
the class TestCSVValidators method testUnescapedSingleCharUnicodeChar.
@Test
public void testUnescapedSingleCharUnicodeChar() {
Validator validator = CSVValidators.UNESCAPED_SINGLE_CHAR_VALIDATOR;
ValidationContext mockContext = Mockito.mock(ValidationContext.class);
ValidationResult result = validator.validate("Delimiter", "\\u0001", mockContext);
assertTrue(result.isValid());
}
use of org.apache.nifi.components.ValidationContext in project nifi by apache.
the class TestCSVValidators method testSingleCharIllegalChar.
@Test
public void testSingleCharIllegalChar() {
CSVValidators.SingleCharacterValidator validator = new CSVValidators.SingleCharacterValidator();
ValidationContext mockContext = Mockito.mock(ValidationContext.class);
ValidationResult result = validator.validate("EscapeChar", "\\r", mockContext);
assertEquals("\\r is not a valid character for this property", result.getExplanation());
assertFalse(result.isValid());
}
Aggregations