Search in sources :

Example 11 with StartupForm

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

Example 12 with StartupForm

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

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

Example 14 with StartupForm

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

Example 15 with StartupForm

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);
}
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