FileDocCategorySizeDatePackage
RepositoryNameValidatorTest.javaAPI DocGlassfish v2 API5147Fri May 04 22:24:34 BST 2007com.sun.enterprise.admin.servermgmt

RepositoryNameValidatorTest

public class RepositoryNameValidatorTest extends TestCase

Fields Summary
static final char[]
INVALID_CHARS
static final char[]
VALID_CHARS
static final int
ITERATIONS
Validator
validator
Random
random
Constructors Summary
public RepositoryNameValidatorTest(String name)

        super(name);
    
Methods Summary
public static voidmain(java.lang.String[] args)

        final TestRunner runner= new TestRunner();
        final TestResult result = runner.doRun(
            RepositoryNameValidatorTest.suite(), false);
        System.exit(result.errorCount() + result.failureCount());
    
protected voidsetUp()

        validator   = new RepositoryNameValidator("repository name");
        random      = new Random();
    
public static junit.framework.Testsuite()

        TestSuite suite = new TestSuite(RepositoryNameValidatorTest.class);
        return suite;
    
protected voidtearDown()

        validator   = null;
        random      = null;
    
public voidtestCombination()

        for (int i = 0; i < ITERATIONS; i++)
        {
            testInvalid("" + 
                VALID_CHARS[random.nextInt(VALID_CHARS.length)] + 
                INVALID_CHARS[random.nextInt(INVALID_CHARS.length)]);
        }
    
voidtestInvalid(java.lang.String invalid)

        try
        {
            validator.validate(invalid);
            System.out.println(invalid);
            Assert.assertTrue(false);
        }
        catch (Exception e)
        {
            //ok
        }
    
public voidtestInvalidChar()

        for (int i = 0; i < INVALID_CHARS.length; i++)
        {
            testInvalid("" + INVALID_CHARS[i]);
        }
    
public voidtestInvalidStr()

        for (int i = 0; i < ITERATIONS; i++)
        {
            testInvalid("" + 
                INVALID_CHARS[random.nextInt(INVALID_CHARS.length)] + 
                INVALID_CHARS[random.nextInt(INVALID_CHARS.length)]);
        }
    
public voidtestNull()


      
    
        testInvalid(null);
    
voidtestValid(java.lang.String valid)

        try
        {
            validator.validate(valid);
        }
        catch (Exception e)
        {
            Assert.assertTrue(false);
        }
    
public voidtestValidChar()

        for (int i = 0; i < VALID_CHARS.length; i++)
        {
            testValid("" + VALID_CHARS[i]);
        }
    
public voidtestValidStr()

        for (int i = 0; i < ITERATIONS; i++)
        {
            testValid("" + 
                VALID_CHARS[random.nextInt(VALID_CHARS.length)] + 
                VALID_CHARS[random.nextInt(VALID_CHARS.length)]);
        }
    
public voidtestZeroLength()

        testInvalid("");