1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.core.persistence.jpa.outer;
20
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.junit.jupiter.api.Assertions.assertNotNull;
23 import static org.junit.jupiter.api.Assertions.assertNull;
24
25 import java.time.OffsetDateTime;
26 import java.util.UUID;
27 import org.apache.syncope.core.persistence.api.dao.AccessTokenDAO;
28 import org.apache.syncope.core.persistence.api.entity.AccessToken;
29 import org.apache.syncope.core.persistence.jpa.AbstractTest;
30 import org.junit.jupiter.api.Test;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.transaction.annotation.Transactional;
33
34 @Transactional("Master")
35 public class AccessTokenTest extends AbstractTest {
36
37 @Autowired
38 private AccessTokenDAO accessTokenDAO;
39
40 @Test
41 public void crud() {
42 AccessToken accessToken = entityFactory.newEntity(AccessToken.class);
43 accessToken.setKey(UUID.randomUUID().toString());
44 accessToken.setBody("pointless body");
45 accessToken.setExpirationTime(OffsetDateTime.now());
46 accessToken.setOwner("bellini");
47
48 accessToken = accessTokenDAO.save(accessToken);
49 assertNotNull(accessToken);
50
51 entityManager().flush();
52
53 accessToken = accessTokenDAO.findByOwner("bellini");
54 assertNotNull(accessToken);
55 assertEquals("bellini", accessToken.getOwner());
56
57 accessTokenDAO.deleteExpired();
58
59 entityManager().flush();
60
61 accessToken = accessTokenDAO.findByOwner("bellini");
62 assertNull(accessToken);
63 }
64 }