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