Search in sources :

Example 6 with StartupForm

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

Example 7 with StartupForm

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

Example 8 with StartupForm

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

Example 9 with StartupForm

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

Example 10 with StartupForm

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"));
}
Also used : StartupForm(org.motechproject.server.web.form.StartupForm) ArrayList(java.util.ArrayList) 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