@Test @Transactional(value = "hibernateTransactionManager", readOnly = true) public void shouldLoadAuthoritiesWhichUserHave() { User user = hibernateTemplate.load(User.class, 1); Authority authority = hibernateTemplate.load(Authority.class, 1); assertFalse(user.getAuthorities().isEmpty()); assertTrue(user.getAuthorities().contains(authority)); }
@Test public void shouldFindOnlyOneUserByUsername() { jdbcTemplate.query( "SELECT id, username, password, enabled FROM users WHERE username = ?", new Object[] {"super"}, new RowCallbackHandler() { public void processRow(ResultSet resultSet) throws SQLException { user = new User(resultSet.getString(2), resultSet.getString(3), resultSet.getString(4)); user.setId(resultSet.getInt(1)); } }); assertThat(user.getId(), is(1)); assertThat(user.getUsername(), is("super")); }