use of org.motechproject.server.web.form.StartupForm in project motech by motech.
the class UserRegistrationValidatorTest method shouldNotValidateUserDetailsWhenLoginModeIsNull.
@Test
public void shouldNotValidateUserDetailsWhenLoginModeIsNull() {
PersistedUserValidator persistedUserValidator = mock(PersistedUserValidator.class);
OpenIdUserValidator openIdUserValidator = mock(OpenIdUserValidator.class);
StartupForm target = new StartupForm();
target.setLoginMode(null);
UserRegistrationValidator userRegistrationValidator = new UserRegistrationValidator(persistedUserValidator, openIdUserValidator);
userRegistrationValidator.validate(target, new ArrayList<String>(), ConfigSource.FILE);
verify(persistedUserValidator, never()).validate(target, new ArrayList<String>(), ConfigSource.FILE);
verify(openIdUserValidator, never()).validate(target, new ArrayList<String>(), ConfigSource.FILE);
}
use of org.motechproject.server.web.form.StartupForm in project motech by motech.
the class UserRegistrationValidatorTest method shouldValidateUserDetailsWithOpenIdValidatorWhenLoginModeIsOpenId.
@Test
public void shouldValidateUserDetailsWithOpenIdValidatorWhenLoginModeIsOpenId() {
PersistedUserValidator persistedUserValidator = mock(PersistedUserValidator.class);
OpenIdUserValidator openIdUserValidator = mock(OpenIdUserValidator.class);
StartupForm target = new StartupForm();
target.setLoginMode("openId");
UserRegistrationValidator userRegistrationValidator = new UserRegistrationValidator(persistedUserValidator, openIdUserValidator);
userRegistrationValidator.validate(target, new ArrayList<String>(), ConfigSource.FILE);
verify(openIdUserValidator).validate(target, new ArrayList<String>(), ConfigSource.FILE);
verify(persistedUserValidator, never()).validate(target, new ArrayList<String>(), ConfigSource.FILE);
}
use of org.motechproject.server.web.form.StartupForm in project motech by motech.
the class StartupControllerTest method shouldAddErrorsWhenValidationFails.
@Test
public void shouldAddErrorsWhenValidationFails() throws IOException {
when(userService.hasActiveMotechAdmin()).thenReturn(true);
when(configurationService.getConfigSource()).thenReturn(ConfigSource.UI);
StartupForm startupForm = startupForm();
startupForm.setLanguage("");
List<String> errors = startupController.submitForm(startupForm);
assertFalse(errors.isEmpty());
}
use of org.motechproject.server.web.form.StartupForm in project motech by motech.
the class StartupControllerTest method testStartup.
@Test
public void testStartup() {
Properties properties = new Properties();
properties.put("host", "localhost");
properties.put("port", "12345");
NavigableMap<String, String> map = new TreeMap<>();
when(startupManager.canLaunchBundles()).thenReturn(false);
when(startupManager.getDefaultSettings()).thenReturn(motechSettings);
when(localeService.getUserLocale(httpServletRequest)).thenReturn(new Locale("en"));
when(localeService.getSupportedLanguages()).thenReturn(map);
when(configurationService.getPlatformSettings()).thenReturn(motechSettings);
StartupViewData result = startupController.getStartupViewData(httpServletRequest);
verify(startupManager).canLaunchBundles();
verify(localeService).getSupportedLanguages();
verify(localeService).getUserLocale(httpServletRequest);
assertThat(result.getRedirectHome(), Is.is(false));
StartupSuggestionsForm startupSuggestionsForm = result.getSuggestions();
assertTrue(startupSuggestionsForm.getDatabaseUrls().isEmpty());
assertTrue(startupSuggestionsForm.getQueueUrls().isEmpty());
assertTrue(startupSuggestionsForm.getSchedulerUrls().isEmpty());
StartupForm startupSettings = result.getStartupSettings();
Boolean requiresConfigFiles = result.getRequireConfigFiles();
Assert.assertFalse(requiresConfigFiles);
assertEquals("en", startupSettings.getLanguage());
}
use of org.motechproject.server.web.form.StartupForm in project motech by motech.
the class StartupFormValidatorTest method shouldRejectEmptyUserFieldsWhenLoginModeIsOpenId.
@Test
public void shouldRejectEmptyUserFieldsWhenLoginModeIsOpenId() {
StartupForm startupForm = new StartupForm();
startupForm.setLoginMode("openId");
startupForm.setLanguage("en");
startupFormValidator = new StartupFormValidatorFactory().getStartupFormValidator(startupForm, userService);
List<String> errors = startupFormValidator.validate(startupForm, ConfigSource.UI);
assertTrue(errors.contains(String.format("server.error.required.%s", PROVIDER_NAME)));
assertTrue(errors.contains(String.format("server.error.required.%s", PROVIDER_URL)));
}
Aggregations