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.inner;
20
21 import static org.junit.jupiter.api.Assertions.assertFalse;
22 import static org.junit.jupiter.api.Assertions.assertNotNull;
23 import static org.junit.jupiter.api.Assertions.assertNull;
24 import static org.junit.jupiter.api.Assertions.assertTrue;
25
26 import java.util.List;
27 import org.apache.syncope.common.lib.types.IdRepoEntitlement;
28 import org.apache.syncope.core.persistence.api.dao.RealmDAO;
29 import org.apache.syncope.core.persistence.api.dao.RoleDAO;
30 import org.apache.syncope.core.persistence.api.entity.Role;
31 import org.apache.syncope.core.persistence.jpa.AbstractTest;
32 import org.junit.jupiter.api.Assertions;
33 import org.junit.jupiter.api.Test;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.transaction.annotation.Transactional;
36
37 @Transactional("Master")
38 public class RoleTest extends AbstractTest {
39
40 @Autowired
41 private RoleDAO roleDAO;
42
43 @Autowired
44 private RealmDAO realmDAO;
45
46 @Test
47 public void find() {
48 Role role = roleDAO.find("User manager");
49 assertNotNull(role);
50 assertNotNull(role.getKey());
51 assertFalse(role.getRealms().isEmpty());
52 assertFalse(role.getEntitlements().isEmpty());
53 assertTrue(role.getEntitlements().contains(IdRepoEntitlement.USER_SEARCH));
54 }
55
56 @Test
57 public void findAll() {
58 List<Role> list = roleDAO.findAll();
59 assertNotNull(list);
60 assertFalse(list.isEmpty());
61 list.forEach(Assertions::assertNotNull);
62 }
63
64 @Test
65 public void save() {
66 Role role = entityFactory.newEntity(Role.class);
67 role.setKey("new");
68 role.add(realmDAO.getRoot());
69 role.add(realmDAO.findByFullPath("/even/two"));
70 role.getEntitlements().add(IdRepoEntitlement.AUDIT_LIST);
71 role.getEntitlements().add(IdRepoEntitlement.AUDIT_SET);
72
73 Role actual = roleDAO.save(role);
74 assertNotNull(actual);
75 }
76
77 @Test
78 public void delete() {
79 assertNotNull(roleDAO.find("Other"));
80
81 roleDAO.delete("Other");
82 assertNull(roleDAO.find("Other"));
83 }
84 }