use of com.thoughtworks.go.domain.NullUser in project gocd by gocd.
the class GoCacheTest method shouldAllowAddingUnpersistedNullObjects.
@Test
public void shouldAllowAddingUnpersistedNullObjects() {
NullUser user = new NullUser();
goCache.put("loser_user", user);
assertThat(goCache.get("loser_user"), is(user));
try (LogFixture logFixture = logFixtureFor(GoCache.class, Level.DEBUG)) {
String allLogs = logFixture.allLogs();
assertThat(allLogs, not(containsString("added to cache without an id.")));
assertThat(allLogs, not(containsString("without an id served out of cache.")));
}
}
use of com.thoughtworks.go.domain.NullUser in project gocd by gocd.
the class UserEnabledCheckFilterTest method shouldNotSetUserIdInSessionIfUserServiceReturnANullUser.
@Test
public void shouldNotSetUserIdInSessionIfUserServiceReturnANullUser() throws IOException, ServletException {
String userName = "none";
SecurityContextHelper.setCurrentUser(userName);
Authentication actual = SecurityContextHolder.getContext().getAuthentication();
when(session.getAttribute(USERID_ATTR)).thenReturn(null);
NullUser nullUser = new NullUser();
when(userService.findUserByName(userName)).thenReturn(nullUser);
filter.doFilterHttp(req, res, chain);
assertThat(SecurityContextHolder.getContext().getAuthentication(), is(actual));
verify(session, never()).setAttribute(eq(USERID_ATTR), Matchers.<Object>any());
verify(chain).doFilter(req, res);
}
use of com.thoughtworks.go.domain.NullUser 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;
}
});
}
Aggregations