Java Code Examples for org.apache.wicket.validation.IValidator#validate()

The following examples show how to use org.apache.wicket.validation.IValidator#validate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HibernateValidatorPropertyTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testNotNull() {
	IValidator<Object> validator = new HibernateValidatorProperty(new Model<TestBean>(new TestBean("aaa", "aaa")), "a");
	
	Validatable<Object> validatable = new Validatable<Object>(null);
	validator.validate(validatable);
	
	assertEquals(1, validatable.getErrors().size());
	assertEquals("NotNull", getError(validatable).getKeys().get(0));
}
 
Example 2
Source File: HibernateValidatorPropertyTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testSuccess(){
	IValidator<Object> validator = new HibernateValidatorProperty(new Model<TestBean>(new TestBean("aaa", "aaa")), "a");
	
	Validatable<Object> validatable = new Validatable<Object>("bb");
	validator.validate(validatable);
	
	assertEquals(0, validatable.getErrors().size());
}
 
Example 3
Source File: HibernateValidatorPropertyTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testMessageParameters(){
	IValidator<Object> validator = new HibernateValidatorProperty(new Model<TestBean>(new TestBean("aaa", "aaa")), "b");
	
	Validatable<Object> validatable = new Validatable<Object>("a");
	validator.validate(validatable);
	
	assertEquals(1, validatable.getErrors().size());
	assertEquals("Size", getError(validatable).getKeys().get(0));
	
	assertEquals(2, getError(validatable).getVariables().size());
	assertEquals(2, getError(validatable).getVariables().get("min"));
	assertEquals(4, getError(validatable).getVariables().get("max"));
}
 
Example 4
Source File: PortugueseNIFValidatorTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testValidNifUsual() {
	IValidator<String> validator = new PortugueseNIFValidator();
	
	Validatable<String> validatable = new Validatable<String>("123456789");
	validator.validate(validatable);
	
	assertEquals(0, validatable.getErrors().size());
}
 
Example 5
Source File: PortugueseNIFValidatorTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testValidNif0term() {
	IValidator<String> validator = new PortugueseNIFValidator();
	
	Validatable<String> validatable = new Validatable<String>("504426290");
	validator.validate(validatable);
	
	assertEquals(0, validatable.getErrors().size());
}
 
Example 6
Source File: PortugueseNIFValidatorTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testValidNif0TermWithMod1() {
	IValidator<String> validator = new PortugueseNIFValidator();
	
	Validatable<String> validatable = new Validatable<String>("504646680");
	validator.validate(validatable);
	
	assertEquals(0, validatable.getErrors().size());
}
 
Example 7
Source File: PortugueseNIFValidatorTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testInvalidNif() {
	IValidator<String> validator = new PortugueseNIFValidator();
	
	Validatable<String> validatable = new Validatable<String>("124456789");
	validator.validate(validatable);
	
	assertEquals(1, validatable.getErrors().size());
}
 
Example 8
Source File: PortugueseNIFValidatorTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testAnotherInvalidNif() {
	IValidator<String> validator = new PortugueseNIFValidator();
	
	Validatable<String> validatable = new Validatable<String>("505646780");
	validator.validate(validatable);
	
	assertEquals(1, validatable.getErrors().size());
}
 
Example 9
Source File: FormComponent.java    From onedev with MIT License 4 votes vote down vote up
/**
 * Validates this component using the component's validators.
 */
@SuppressWarnings("unchecked")
protected final void validateValidators()
{
	final IValidatable<T> validatable = newValidatable();

	boolean isNull = getConvertedInput() == null;

	IValidator<T> validator;

	for (Behavior behavior : getBehaviors())
	{
		if (isBehaviorAccepted(behavior) == false)
		{
			continue;
		}

		validator = null;
		if (behavior instanceof ValidatorAdapter)
		{
			validator = ((ValidatorAdapter<T>)behavior).getValidator();
		}
		else if (behavior instanceof IValidator)
		{
			validator = (IValidator<T>)behavior;
		}
		if (validator != null)
		{
			if (isNull == false || validator instanceof INullAcceptingValidator<?>)
			{
				try
				{
					validator.validate(validatable);
				}
				catch (Exception e)
				{
					throw new WicketRuntimeException("Exception '" + e.getMessage() +
							"' occurred during validation " + validator.getClass().getName() +
							" on component " + getPath(), e);
				}
			}
			if (!isValid())
			{
				break;
			}
		}
	}
}
 
Example 10
Source File: Admin.java    From openmeetings with Apache License 2.0 4 votes vote down vote up
private void checkAdminDetails() throws Exception {
	cfg.setUsername(cmdl.getOptionValue("user"));
	cfg.setEmail(cmdl.getOptionValue(OPTION_EMAIL));
	cfg.setGroup(cmdl.getOptionValue(OPTION_GROUP));
	if (cfg.getUsername() == null || cfg.getUsername().length() < USER_LOGIN_MINIMUM_LENGTH) {
		doLog("User login was not provided, or too short, should be at least " + USER_LOGIN_MINIMUM_LENGTH + " character long.");
		throw new ExitException();
	}

	if (!MailUtil.isValid(cfg.getEmail())) {
		doLog(String.format("Please provide non-empty valid email: '%s' is not valid.", cfg.getEmail()));
		throw new ExitException();
	}
	if (Strings.isEmpty(cfg.getGroup())) {
		doLog(String.format("User group was not provided, or too short, should be at least 1 character long: %s", cfg.getGroup()));
		throw new ExitException();
	}
	if (cmdl.hasOption(OPTION_PWD)) {
		cfg.setPassword(cmdl.getOptionValue(OPTION_PWD));
	}
	IValidator<String> passValidator = new StrongPasswordValidator(false, new User());
	Validatable<String> passVal;
	do {
		passVal = new Validatable<>(cfg.getPassword());
		passValidator.validate(passVal);
		if (!passVal.isValid()) {
			doLog(String.format("Please enter password for the user '%s':", cfg.getUsername()));
			cfg.setPassword(new BufferedReader(new InputStreamReader(System.in, UTF_8)).readLine());
		}
	} while (!passVal.isValid());
	Map<String, String> tzMap = ImportHelper.getAllTimeZones(TimeZone.getAvailableIDs());
	cfg.setTimeZone(null);
	if (cmdl.hasOption("tz")) {
		String tz = cmdl.getOptionValue("tz");
		cfg.setTimeZone(tzMap.containsKey(tz) ? tz : null);
	}
	if (cfg.getTimeZone() == null) {
		doLog("Please enter timezone, Possible timezones are:");

		for (Map.Entry<String,String> me : tzMap.entrySet()) {
			doLog(String.format("%1$-25s%2$s", "\"" + me.getKey() + "\"", me.getValue()));
		}
		throw new ExitException();
	}
}
 
Example 11
Source File: PortugueseNIFValidatorTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 3 votes vote down vote up
@Test
public void testValidNif() {
	IValidator<String> validator = new PortugueseNIFValidator();
	
	Validatable<String> validatable = new Validatable<String>("241250609");
	validator.validate(validatable);
	
	assertEquals(0, validatable.getErrors().size());

}
 
Example 12
Source File: PortugueseNIFValidatorTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 3 votes vote down vote up
@Test
public void testValidDoubleDigit() {
	IValidator<String> validator = new PortugueseNIFValidator();
	
	Validatable<String> validatable = new Validatable<String>("451234561");
	validator.validate(validatable);
	
	assertEquals(0, validatable.getErrors().size());

}