Examples of DomainValidator


Examples of org.apache.bval.extras.constraints.net.DomainValidator

    private DomainValidator validator;

    @Before
    public void setUp() {
        validator = new DomainValidator();
    }
View Full Code Here

Examples of org.apache.bval.extras.constraints.net.DomainValidator

        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));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.