assertFalse("empty string shouldn't validate as TLD", validator.isValid("", null));
}
@Test
public void testAllowLocal() {
DomainValidator noLocal = new DomainValidator();
DomainValidator allowLocal = new DomainValidator();
allowLocal.initialize( new Domain()
{
public Class<? extends Annotation> annotationType() {
// not needed
return null;
}
public Class<? extends Payload>[] payload() {
// not needed
return null;
}
public String message() {
// not needed
return null;
}
public Class<?>[] groups() {
// not needed
return null;
}
public boolean allowLocal() {
// enable the local
return true;
}
});
// Default won't allow local
assertFalse("localhost.localdomain should validate", noLocal.isValid("localhost.localdomain", null));
assertFalse("localhost should validate", noLocal.isValid("localhost", null));
// But it may be requested
assertTrue("localhost.localdomain should validate", allowLocal.isValid("localhost.localdomain", null));
assertTrue("localhost should validate", allowLocal.isValid("localhost", null));
assertTrue("hostname should validate", allowLocal.isValid("hostname", null));
assertTrue("machinename should validate", allowLocal.isValid("machinename", null));
// Check the localhost one with a few others
assertTrue("apache.org should validate", allowLocal.isValid("apache.org", null));
assertFalse("domain name with spaces shouldn't validate", allowLocal.isValid(" apache.org ", null));
}