use of org.motechproject.server.web.form.StartupForm in project motech by motech.
the class RequiredFieldValidatorTest method shouldRejectIfFieldIsNull.
@Test
public void shouldRejectIfFieldIsNull() {
RequiredFieldValidator fieldValidator = new RequiredFieldValidator("name", null);
List<String> errors = new ArrayList<>();
fieldValidator.validate(new StartupForm(), errors, ConfigSource.UI);
assertTrue(errors.contains(String.format(RequiredFieldValidator.ERROR_REQUIRED, "name")));
}
use of org.motechproject.server.web.form.StartupForm in project motech by motech.
the class StartupFormValidatorTest method shouldRejectEmptyUserFieldsWhenLoginModeIsRepository.
@Test
public void shouldRejectEmptyUserFieldsWhenLoginModeIsRepository() {
StartupForm startupForm = new StartupForm();
when(userService.hasActiveMotechAdmin()).thenReturn(false);
startupForm.setLoginMode("repository");
startupForm.setLanguage("en");
startupFormValidator = new StartupFormValidatorFactory().getStartupFormValidator(startupForm, userService);
List<String> errors = startupFormValidator.validate(startupForm, ConfigSource.FILE);
assertTrue(errors.contains(String.format("server.error.required.%s", ADMIN_LOGIN)));
assertTrue(errors.contains(String.format("server.error.required.%s", ADMIN_PASSWORD)));
assertTrue(errors.contains("server.error.invalid.email"));
}
use of org.motechproject.server.web.form.StartupForm in project motech by motech.
the class StartupFormValidatorTest method shouldAcceptEmptyQueueURLAndLoginModeWhenConfigSourceIsFile.
@Test
public void shouldAcceptEmptyQueueURLAndLoginModeWhenConfigSourceIsFile() {
StartupForm startupForm = new StartupForm();
startupForm.setAdminLogin(ADMIN_LOGIN);
startupForm.setAdminPassword(ADMIN_PASSWORD);
startupForm.setAdminConfirmPassword(ADMIN_CONFIRM_PASSWORD);
startupForm.setAdminEmail(EMAIL);
startupFormValidator = new StartupFormValidatorFactory().getStartupFormValidator(startupForm, userService);
List<String> errors = startupFormValidator.validate(startupForm, ConfigSource.FILE);
assertTrue(errors.isEmpty());
}
use of org.motechproject.server.web.form.StartupForm in project motech by motech.
the class StartupFormValidatorTest method shouldRejectEmptyFields.
@Test
public void shouldRejectEmptyFields() {
StartupForm startupForm = new StartupForm();
startupForm.setAdminEmail(EMAIL);
startupFormValidator = new StartupFormValidatorFactory().getStartupFormValidator(startupForm, userService);
List<String> errors = startupFormValidator.validate(startupForm, ConfigSource.UI);
assertTrue(errors.contains(String.format("server.error.required.%s", LOGIN_MODE)));
assertTrue(errors.contains(String.format("server.error.required.%s", LANGUAGE)));
}
use of org.motechproject.server.web.form.StartupForm in project motech by motech.
the class PersistedUserValidatorTest method shouldRejectInvalidEmail.
@Test
public void shouldRejectInvalidEmail() {
PersistedUserValidator persistedUserValidator = new PersistedUserValidator(userService);
StartupForm startupForm = getExampleStartupForm();
startupForm.setAdminEmail("admin@motech");
when(userService.hasUser("admin")).thenReturn(false);
List<String> errors = new ArrayList<>();
persistedUserValidator.validate(startupForm, errors, ConfigSource.FILE);
assertTrue(errors.contains("server.error.invalid.email"));
}
Aggregations