@Test public void testRemoveOldPersistentTokens() { User admin = userRepository.findOneByLogin("admin").get(); int existingCount = persistentTokenRepository.findByUser(admin).size(); generateUserToken(admin, "1111-1111", new LocalDate()); LocalDate now = new LocalDate(); generateUserToken(admin, "2222-2222", now.minusDays(32)); assertThat(persistentTokenRepository.findByUser(admin)).hasSize(existingCount + 2); userService.removeOldPersistentTokens(); assertThat(persistentTokenRepository.findByUser(admin)).hasSize(existingCount + 1); }
private void generateUserToken(User user, String tokenSeries, LocalDate localDate) { PersistentToken token = new PersistentToken(); token.setSeries(tokenSeries); token.setUser(user); token.setTokenValue(tokenSeries + "-data"); token.setTokenDate(localDate); token.setIpAddress("127.0.0.1"); token.setUserAgent("Test agent"); persistentTokenRepository.save(token); }