Search in sources :

Example 1 with UserNotFoundException

use of com.thoughtworks.go.server.exceptions.UserNotFoundException in project gocd by gocd.

the class UserSqlMapDao method deleteUser.

@Override
public boolean deleteUser(final String username) {
    return (Boolean) transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus status) {
            User user = findUser(username);
            if (user instanceof NullUser) {
                throw new UserNotFoundException();
            }
            if (user.isEnabled()) {
                throw new UserEnabledException();
            }
            sessionFactory.getCurrentSession().delete(user);
            return Boolean.TRUE;
        }
    });
}
Also used : UserNotFoundException(com.thoughtworks.go.server.exceptions.UserNotFoundException) TransactionCallback(org.springframework.transaction.support.TransactionCallback) User(com.thoughtworks.go.domain.User) NullUser(com.thoughtworks.go.domain.NullUser) NullUser(com.thoughtworks.go.domain.NullUser) UserEnabledException(com.thoughtworks.go.server.exceptions.UserEnabledException) TransactionStatus(org.springframework.transaction.TransactionStatus)

Example 2 with UserNotFoundException

use of com.thoughtworks.go.server.exceptions.UserNotFoundException in project gocd by gocd.

the class UserSqlMapDaoIntegrationTest method shouldAddNewUserWhenDeleteQueryForTheUserHasCachedANullUser.

@Test
public void shouldAddNewUserWhenDeleteQueryForTheUserHasCachedANullUser() {
    String userName = "invalidForNowUser";
    try {
        userDao.deleteUser(userName);
        fail("should have failed");
    } catch (Exception e) {
        assertThat(e instanceof UserNotFoundException, is(true));
    }
    User addingTheUserNow = new User(userName);
    addingTheUserNow.disable();
    userDao.saveOrUpdate(addingTheUserNow);
    User retrievedUser = userDao.findUser(userName);
    assertThat(retrievedUser instanceof NullUser, is(false));
    assertThat(retrievedUser, is(addingTheUserNow));
    assertThat(userDao.deleteUser(userName), is(true));
}
Also used : UserNotFoundException(com.thoughtworks.go.server.exceptions.UserNotFoundException) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ExpectedException(org.springframework.test.annotation.ExpectedException) UserEnabledException(com.thoughtworks.go.server.exceptions.UserEnabledException) UserNotFoundException(com.thoughtworks.go.server.exceptions.UserNotFoundException) Test(org.junit.Test)

Example 3 with UserNotFoundException

use of com.thoughtworks.go.server.exceptions.UserNotFoundException in project gocd by gocd.

the class UserServiceTest method shouldFailWithErrorWhenDeletingAUserFails.

@Test
public void shouldFailWithErrorWhenDeletingAUserFails() {
    String username = "username";
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    when(userDao.deleteUser(username)).thenThrow(new UserNotFoundException());
    userService.deleteUser(username, result);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.hasMessage(), is(true));
}
Also used : UserNotFoundException(com.thoughtworks.go.server.exceptions.UserNotFoundException) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.Test)

Aggregations

UserNotFoundException (com.thoughtworks.go.server.exceptions.UserNotFoundException)3 UserEnabledException (com.thoughtworks.go.server.exceptions.UserEnabledException)2 Test (org.junit.Test)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 NullUser (com.thoughtworks.go.domain.NullUser)1 User (com.thoughtworks.go.domain.User)1 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)1 ExpectedException (org.springframework.test.annotation.ExpectedException)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallback (org.springframework.transaction.support.TransactionCallback)1