コード例 #1
0
 @Test
 public void testRemoveOldPersistentTokens() {
   User admin = userRepository.findOneByLogin("admin").get();
   int existingCount = persistentTokenRepository.findByUser(admin).size();
   generateUserToken(admin, "1111-1111", LocalDate.now());
   LocalDate now = LocalDate.now();
   generateUserToken(admin, "2222-2222", now.minusDays(32));
   assertThat(persistentTokenRepository.findByUser(admin)).hasSize(existingCount + 2);
   userService.removeOldPersistentTokens();
   assertThat(persistentTokenRepository.findByUser(admin)).hasSize(existingCount + 1);
 }
コード例 #2
0
 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.saveAndFlush(token);
 }