use of org.apache.nifi.components.ValidationContext in project nifi by apache.
the class TestStandardValidators method testListValidator.
@Test
public void testListValidator() {
Validator val = StandardValidators.createListValidator(true, false, StandardValidators.NON_EMPTY_VALIDATOR);
ValidationResult vr;
final ValidationContext validationContext = Mockito.mock(ValidationContext.class);
vr = val.validate("List", null, validationContext);
assertFalse(vr.isValid());
vr = val.validate("List", "", validationContext);
assertFalse(vr.isValid());
// Whitespace will be trimmed
vr = val.validate("List", " ", validationContext);
assertFalse(vr.isValid());
vr = val.validate("List", "1", validationContext);
assertTrue(vr.isValid());
vr = val.validate("List", "1,2,3", validationContext);
assertTrue(vr.isValid());
// The parser will not bother with whitespace after the last comma
vr = val.validate("List", "a,", validationContext);
assertTrue(vr.isValid());
// However it will bother if there is an empty element in the list (two commas in a row, e.g.)
vr = val.validate("List", "a,,c", validationContext);
assertFalse(vr.isValid());
vr = val.validate("List", "a, ,c, ", validationContext);
assertFalse(vr.isValid());
// Try without trim and use a non-blank validator instead of a non-empty one
val = StandardValidators.createListValidator(false, true, StandardValidators.NON_BLANK_VALIDATOR);
vr = val.validate("List", null, validationContext);
assertFalse(vr.isValid());
// Validator will ignore empty entries
vr = val.validate("List", "", validationContext);
assertTrue(vr.isValid());
// Whitespace will not be trimmed, but it is still invalid because a non-blank validator is used
vr = val.validate("List", " ", validationContext);
assertFalse(vr.isValid());
vr = val.validate("List", "a,,c", validationContext);
assertTrue(vr.isValid());
vr = val.validate("List", "a, ,c, ", validationContext);
assertFalse(vr.isValid());
// Try without trim and use a non-empty validator
val = StandardValidators.createListValidator(false, false, StandardValidators.NON_EMPTY_VALIDATOR);
vr = val.validate("List", null, validationContext);
assertFalse(vr.isValid());
vr = val.validate("List", "", validationContext);
assertFalse(vr.isValid());
// Whitespace will not be trimmed
vr = val.validate("List", " ", validationContext);
assertTrue(vr.isValid());
vr = val.validate("List", "a, ,c, ", validationContext);
assertTrue(vr.isValid());
// Try with trim and use a boolean validator
val = StandardValidators.createListValidator(true, true, StandardValidators.BOOLEAN_VALIDATOR);
vr = val.validate("List", "notbool", validationContext);
assertFalse(vr.isValid());
vr = val.validate("List", " notbool \n ", validationContext);
assertFalse(vr.isValid());
vr = val.validate("List", "true", validationContext);
assertTrue(vr.isValid());
vr = val.validate("List", " true \n ", validationContext);
assertTrue(vr.isValid());
vr = val.validate("List", " , false, true,\n", validationContext);
assertTrue(vr.isValid());
}
use of org.apache.nifi.components.ValidationContext in project nifi by apache.
the class TestStandardValidators method testiso8061InstantValidator.
@Test
public void testiso8061InstantValidator() {
Validator val = StandardValidators.ISO8061_INSTANT_VALIDATOR;
ValidationContext vc = mock(ValidationContext.class);
ValidationResult vr = val.validate("foo", "", vc);
assertFalse(vr.isValid());
vr = val.validate("foo", "2016-01-01T01:01:01.000-0100", vc);
assertFalse(vr.isValid());
vr = val.validate("foo", "2016-01-01T01:01:01.000Z", vc);
assertTrue(vr.isValid());
}
use of org.apache.nifi.components.ValidationContext in project nifi by apache.
the class TestStandardValidators method testDataSizeBoundsValidator.
@Test
public void testDataSizeBoundsValidator() {
Validator val = StandardValidators.createDataSizeBoundsValidator(100, 1000);
ValidationResult vr;
final ValidationContext validationContext = Mockito.mock(ValidationContext.class);
vr = val.validate("DataSizeBounds", "5 GB", validationContext);
assertFalse(vr.isValid());
vr = val.validate("DataSizeBounds", "0 B", validationContext);
assertFalse(vr.isValid());
vr = val.validate("DataSizeBounds", "99 B", validationContext);
assertFalse(vr.isValid());
vr = val.validate("DataSizeBounds", "100 B", validationContext);
assertTrue(vr.isValid());
vr = val.validate("DataSizeBounds", "999 B", validationContext);
assertTrue(vr.isValid());
vr = val.validate("DataSizeBounds", "1000 B", validationContext);
assertTrue(vr.isValid());
vr = val.validate("DataSizeBounds", "1001 B", validationContext);
assertFalse(vr.isValid());
vr = val.validate("DataSizeBounds", "water", validationContext);
assertFalse(vr.isValid());
}
use of org.apache.nifi.components.ValidationContext in project nifi by apache.
the class TestCSVValidators method testSingleCharNullValue.
/**
* SingleCharValidator *
*/
@Test
public void testSingleCharNullValue() {
CSVValidators.SingleCharacterValidator validator = new CSVValidators.SingleCharacterValidator();
ValidationContext mockContext = Mockito.mock(ValidationContext.class);
ValidationResult result = validator.validate("EscapeChar", null, mockContext);
assertEquals("Input is null for this property", result.getExplanation());
assertFalse(result.isValid());
}
use of org.apache.nifi.components.ValidationContext in project nifi by apache.
the class TestCSVValidators method testSingleCharGoodChar.
@Test
public void testSingleCharGoodChar() {
CSVValidators.SingleCharacterValidator validator = new CSVValidators.SingleCharacterValidator();
ValidationContext mockContext = Mockito.mock(ValidationContext.class);
ValidationResult result = validator.validate("EscapeChar", "'", mockContext);
assertTrue(result.isValid());
}
Aggregations