use of org.motechproject.server.web.form.StartupForm in project motech by motech.
the class PersistedUserValidatorTest method shouldRejectPasswordIfConfirmPasswordValueIsDifferent.
@Test
public void shouldRejectPasswordIfConfirmPasswordValueIsDifferent() {
PersistedUserValidator persistedUserValidator = new PersistedUserValidator(userService);
StartupForm startupForm = getExampleStartupForm();
startupForm.setAdminConfirmPassword("Password");
when(userService.hasUser("admin")).thenReturn(false);
List<String> errors = new ArrayList<>();
persistedUserValidator.validate(startupForm, errors, ConfigSource.FILE);
// If password is empty do not check against confirmPassword as empty password error is already added
assertTrue(errors.contains("server.error.invalid.password"));
}
use of org.motechproject.server.web.form.StartupForm in project motech by motech.
the class PersistedUserValidatorTest method getExampleStartupForm.
private StartupForm getExampleStartupForm() {
StartupForm startupForm = new StartupForm();
startupForm.setAdminLogin("admin");
startupForm.setAdminPassword("password");
startupForm.setAdminConfirmPassword("password");
startupForm.setAdminEmail("admin@motech.org");
return startupForm;
}
use of org.motechproject.server.web.form.StartupForm in project motech by motech.
the class PersistedUserValidatorTest method shouldValidateFieldsAndRejectEmptyFields.
@Test
public void shouldValidateFieldsAndRejectEmptyFields() {
PersistedUserValidator persistedUserValidator = new PersistedUserValidator(userService);
List<String> errors = new ArrayList<>();
persistedUserValidator.validate(new StartupForm(), errors, ConfigSource.FILE);
assertTrue(errors.contains("server.error.required.adminLogin"));
assertTrue(errors.contains("server.error.required.adminPassword"));
assertTrue(errors.contains("server.error.invalid.email"));
assertFalse(errors.contains("server.error.invalid.password"));
}
use of org.motechproject.server.web.form.StartupForm in project motech by motech.
the class StartupFormValidatorFactoryTest method shouldCreateStartupFormValidator.
@Test
public void shouldCreateStartupFormValidator() {
when(motechUserService.hasActiveMotechAdmin()).thenReturn(false);
StartupFormValidator startupFormValidator = startupFormValidatorFactory.getStartupFormValidator(new StartupForm(), motechUserService);
assertNotNull(startupFormValidator);
List<AbstractValidator> validators = startupFormValidator.getValidators();
assertFalse(validators.isEmpty());
assertTrue(validators.contains(new RequiredFieldValidator(StartupForm.LANGUAGE, "")));
assertTrue(validators.contains(new RequiredFieldValidator(StartupForm.LOGIN_MODE, "")));
assertContainsValidatorOfType(UserRegistrationValidator.class, validators);
}
use of org.motechproject.server.web.form.StartupForm in project motech by motech.
the class UserRegistrationValidatorTest method shouldValidateUserDetailsWithPersistentUserWhenLoginModeIsRepository.
@Test
public void shouldValidateUserDetailsWithPersistentUserWhenLoginModeIsRepository() {
PersistedUserValidator persistedUserValidator = mock(PersistedUserValidator.class);
OpenIdUserValidator openIdUserValidator = mock(OpenIdUserValidator.class);
StartupForm target = new StartupForm();
target.setLoginMode("repository");
UserRegistrationValidator userRegistrationValidator = new UserRegistrationValidator(persistedUserValidator, openIdUserValidator);
userRegistrationValidator.validate(target, new ArrayList<String>(), ConfigSource.FILE);
verify(persistedUserValidator).validate(target, new ArrayList<String>(), ConfigSource.FILE);
verify(openIdUserValidator, never()).validate(target, new ArrayList<String>(), ConfigSource.FILE);
}
Aggregations