Search in sources :

Example 16 with StartupForm

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);
}
Also used : StartupForm(org.motechproject.server.web.form.StartupForm) Test(org.junit.Test)

Example 17 with StartupForm

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);
}
Also used : StartupForm(org.motechproject.server.web.form.StartupForm) Test(org.junit.Test)

Example 18 with StartupForm

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());
}
Also used : StartupForm(org.motechproject.server.web.form.StartupForm) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 19 with StartupForm

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());
}
Also used : Locale(java.util.Locale) StartupSuggestionsForm(org.motechproject.server.web.form.StartupSuggestionsForm) StartupForm(org.motechproject.server.web.form.StartupForm) Matchers.anyString(org.mockito.Matchers.anyString) Properties(java.util.Properties) TreeMap(java.util.TreeMap) StartupViewData(org.motechproject.server.web.dto.StartupViewData) Test(org.junit.Test)

Example 20 with StartupForm

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)));
}
Also used : StartupForm(org.motechproject.server.web.form.StartupForm) Test(org.junit.Test)

Aggregations

StartupForm (org.motechproject.server.web.form.StartupForm)21 Test (org.junit.Test)18 Locale (java.util.Locale)5 Matchers.anyString (org.mockito.Matchers.anyString)5 ArrayList (java.util.ArrayList)4 MotechSettings (org.motechproject.config.domain.MotechSettings)2 StartupViewData (org.motechproject.server.web.dto.StartupViewData)2 Properties (java.util.Properties)1 TreeMap (java.util.TreeMap)1 ConfigSource (org.motechproject.config.core.domain.ConfigSource)1 StartupSuggestionsForm (org.motechproject.server.web.form.StartupSuggestionsForm)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1