Search in sources :

Example 16 with UserSearchModel

use of com.thoughtworks.go.presentation.UserSearchModel in project gocd by gocd.

the class UserServiceTest method shouldReturnErrorMessageWhenUserValidationsFail.

@Test
public void shouldReturnErrorMessageWhenUserValidationsFail() throws Exception {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    User invalidUser = new User("fooUser", "Foo User", "invalidEmail");
    UserSearchModel searchModel = new UserSearchModel(invalidUser, UserSourceType.LDAP);
    when(userDao.findUser("fooUser")).thenReturn(new NullUser());
    when(userDao.enabledUserCount()).thenReturn(1);
    userService.create(Arrays.asList(searchModel), result);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.httpCode(), is(HttpServletResponse.SC_BAD_REQUEST));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) UserSearchModel(com.thoughtworks.go.presentation.UserSearchModel) Test(org.junit.Test)

Example 17 with UserSearchModel

use of com.thoughtworks.go.presentation.UserSearchModel in project gocd by gocd.

the class UserServiceTest method shouldReturnConflictWhenUserAlreadyExists.

@Test
public void shouldReturnConflictWhenUserAlreadyExists() {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    User existsingUser = new User("existingUser", "Existing User", "existing@user.com");
    UserSearchModel searchModel = new UserSearchModel(existsingUser, UserSourceType.LDAP);
    when(userDao.findUser("existingUser")).thenReturn(existsingUser);
    userService.create(Arrays.asList(searchModel), result);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.httpCode(), is(HttpServletResponse.SC_CONFLICT));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) UserSearchModel(com.thoughtworks.go.presentation.UserSearchModel) Test(org.junit.Test)

Aggregations

UserSearchModel (com.thoughtworks.go.presentation.UserSearchModel)17 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)16 Test (org.junit.Test)16 User (com.thoughtworks.go.domain.User)6 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)1