/** * Builds a key to store the <code>FormSet</code> under based on it's * language, country, and variant values. * @param fs The Form Set. * @return generated key for a formset. */ protected String buildKey(FormSet fs) { return this.buildLocale(fs.getLanguage(), fs.getCountry(), fs.getVariant()); }
private void checkForm(Locale locale, String formKey, String expectedVarValue) { // Retrieve the Form Form testForm = resources.getForm(locale, formKey); assertNotNull("Form '" +formKey+"' null for locale " + locale, testForm); // Validate the expected Form is retrieved by checking the "localeVar" // value of the field. Field testField = testForm.getField("testProperty"); assertEquals("Incorrect Form '" + formKey + "' for locale '" + locale + "'", expectedVarValue, testField.getVarValue("localeVar")); }
/** * test Field with only 'default' arguments, positions specified. */ public void testDefaultUsingPositions() { field.addArg(createArg("default-position-1", 1)); field.addArg(createArg("default-position-0", 0)); field.addArg(createArg("default-position-2", 2)); assertEquals("testDefaultUsingPositions(1) ", 3, field.getArgs("required").length); assertEquals("testDefaultUsingPositions(2) ", "default-position-0", field.getArg("required", 0).getKey()); assertEquals("testDefaultUsingPositions(3) ", "default-position-1", field.getArg("required", 1).getKey()); assertEquals("testDefaultUsingPositions(4) ", "default-position-2", field.getArg("required", 2).getKey()); }
/** * Check a validator has run for a field and the result. */ private void checkValidatorResult(ValidatorResults results, String field, String action, boolean expected) { ValidatorResult result = results.getValidatorResult(field); // System.out.println(field + "[" + action + "]=" + result.isValid(action)); assertNotNull(field + " result", result); assertTrue(field + "[" + action + "] not run", result.containsAction(action)); assertEquals(field + "[" + action + "] result", expected, result.isValid(action)); }
public void testAddAllowedCardType() { CreditCardValidator ccv = new CreditCardValidator(CreditCardValidator.NONE); // Turned off all cards so even valid numbers should fail assertFalse(ccv.isValid(VALID_VISA)); assertFalse(ccv.isValid(VALID_AMEX)); assertFalse(ccv.isValid(VALID_MASTERCARD)); assertFalse(ccv.isValid(VALID_DISCOVER)); // test our custom type ccv.addAllowedCardType(new DinersClub()); assertTrue(ccv.isValid(VALID_DINERS)); }
/** * Tests the email validation with ascii control characters. * (i.e. Ascii chars 0 - 31 and 127) */ public void testEmailWithControlChars() { EmailValidator validator = new EmailValidator(); for (char c = 0; c < 32; c++) { assertFalse("Test control char " + ((int)c), validator.isValid("foo" + c + "bar@domain.com")); } assertFalse("Test control char 127", validator.isValid("foo" + ((char)127) + "bar@domain.com")); }
/** * Check a validator has not been run for a field and the result. */ private void checkNotRun(ValidatorResults results, String field, String action) { ValidatorResult result = results.getValidatorResult(field); assertNotNull(field + " result", result); assertFalse(field + "[" + action + "] run", result.containsAction(action)); // System.out.println(field + "[" + action + "] not run"); }
/** * Convenience Method - create argument (name & position specified) */ private Arg createArg(String key, String name, int position) { Arg arg = createArg(key, name); arg.setPosition(position); return arg; }
/** * Tests the email validation with commas. */ public void testEmailWithCommas() throws ValidatorException { ValueBean info = new ValueBean(); info.setValue("joeblow@apa,che.org"); valueTest(info, false); info.setValue("joeblow@apache.o,rg"); valueTest(info, false); info.setValue("joeblow@apache,org"); valueTest(info, false); }
/** * test Field with only 'default' arguments, no positions specified. */ public void testDefaultPositionImplied() { field.addArg(createArg("default-position-0")); field.addArg(createArg("default-position-1")); field.addArg(createArg("default-position-2")); assertEquals("testDefaultPositionImplied(1) ", 3, field.getArgs("required").length); assertEquals("testDefaultPositionImplied(2) ", "default-position-0", field.getArg("required", 0).getKey()); assertEquals("testDefaultPositionImplied(3) ", "default-position-1", field.getArg("required", 1).getKey()); assertEquals("testDefaultPositionImplied(4) ", "default-position-2", field.getArg("required", 2).getKey()); }