Search in sources :

Example 1 with PasswordTooShortException

use of org.motechproject.security.exception.PasswordTooShortException in project motech by motech.

the class UserControllerTest method shouldPrintMinPasswordLengthError.

@Test
public void shouldPrintMinPasswordLengthError() throws Exception {
    when(localeService.getUserLocale(any(HttpServletRequest.class))).thenReturn(Locale.GERMAN);
    when(settingService.getPasswordValidator()).thenReturn(validator);
    when(validator.getValidationError(Locale.GERMAN)).thenReturn("Error from validator");
    doThrow(new PasswordTooShortException(20)).when(userService).register(eq("john"), eq("invalid"), eq("john@gmail.com"), eq(""), anyListOf(String.class), any(Locale.class));
    UserDto userDto = new UserDto();
    userDto.setUserName("john");
    userDto.setEmail("john@gmail.com");
    userDto.setPassword("invalid");
    mockMvc.perform(post("/users/create").body(new ObjectMapper().writeValueAsBytes(userDto)).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isBadRequest()).andExpect(content().string("key:security.validator.error.min_length\nparams:20"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Locale(java.util.Locale) UserDto(org.motechproject.security.model.UserDto) PasswordTooShortException(org.motechproject.security.exception.PasswordTooShortException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Aggregations

Locale (java.util.Locale)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 Test (org.junit.Test)1 PasswordTooShortException (org.motechproject.security.exception.PasswordTooShortException)1 UserDto (org.motechproject.security.model.UserDto)1