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.assertEquals;
22 import static org.junit.jupiter.api.Assertions.assertFalse;
23 import static org.junit.jupiter.api.Assertions.assertNotNull;
24 import static org.junit.jupiter.api.Assertions.assertNull;
25
26 import java.util.List;
27 import org.apache.syncope.common.lib.SyncopeConstants;
28 import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO;
29 import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
30 import org.apache.syncope.core.persistence.api.dao.RealmDAO;
31 import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
32 import org.apache.syncope.core.persistence.jpa.AbstractTest;
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 AnyObjectTest extends AbstractTest {
39
40 @Autowired
41 private AnyTypeDAO anyTypeDAO;
42
43 @Autowired
44 private AnyObjectDAO anyObjectDAO;
45
46 @Autowired
47 private RealmDAO realmDAO;
48
49 @Test
50 public void find() {
51 AnyObject anyObject = anyObjectDAO.find("8559d14d-58c2-46eb-a2d4-a7d35161e8f8");
52 assertNotNull(anyObject);
53 assertNotNull(anyObject.getType());
54 assertFalse(anyObject.getType().getClasses().isEmpty());
55 }
56
57 @Test
58 public void findByName() {
59 AnyObject anyObject = anyObjectDAO.findByName("PRINTER", "HP LJ 1300n");
60 assertNotNull(anyObject);
61 assertEquals("fc6dbc3a-6c07-4965-8781-921e7401a4a5", anyObject.getKey());
62
63 assertEquals(1, anyObjectDAO.findByName("HP LJ 1300n").size());
64 }
65
66 @Test
67 public void findKey() {
68 assertEquals("fc6dbc3a-6c07-4965-8781-921e7401a4a5", anyObjectDAO.findKey("PRINTER", "HP LJ 1300n"));
69 }
70
71 @Test
72 public void findAll() {
73 List<AnyObject> anyObjects = anyObjectDAO.findAll(1, 100);
74 assertNotNull(anyObjects);
75
76 List<String> anyObjectKeys = anyObjectDAO.findAllKeys(1, 100);
77 assertNotNull(anyObjectKeys);
78
79 assertEquals(anyObjects.size(), anyObjectKeys.size());
80 }
81
82 @Test
83 public void save() {
84 AnyObject anyObject = entityFactory.newEntity(AnyObject.class);
85 anyObject.setName("a name");
86 anyObject.setType(anyTypeDAO.find("PRINTER"));
87 anyObject.setRealm(realmDAO.findByFullPath(SyncopeConstants.ROOT_REALM));
88
89 anyObject = anyObjectDAO.save(anyObject);
90 assertNotNull(anyObject);
91 }
92
93 @Test
94 public void delete() {
95 AnyObject anyObject = anyObjectDAO.find("8559d14d-58c2-46eb-a2d4-a7d35161e8f8");
96 anyObjectDAO.delete(anyObject.getKey());
97
98 AnyObject actual = anyObjectDAO.find("8559d14d-58c2-46eb-a2d4-a7d35161e8f8");
99 assertNull(actual);
100 }
101 }