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
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.List;
28 import org.apache.syncope.core.persistence.api.dao.WAConfigDAO;
29 import org.apache.syncope.core.persistence.api.entity.am.WAConfigEntry;
30 import org.apache.syncope.core.persistence.jpa.AbstractTest;
31 import org.apache.syncope.core.persistence.jpa.entity.am.JPAWAConfigEntry;
32 import org.junit.jupiter.api.BeforeEach;
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 WAConfigTest extends AbstractTest {
39
40 @Autowired
41 private WAConfigDAO configDAO;
42
43 @BeforeEach
44 public void beforeEach() {
45 entityManager().createQuery("DELETE FROM " + JPAWAConfigEntry.class.getSimpleName()).executeUpdate();
46 }
47
48 @Test
49 public void saveCommaSeparatedValueStrings() {
50 create("system.example.key[0]", Arrays.asList("value1", "value2", "value3"));
51 assertFalse(configDAO.findAll().isEmpty());
52 }
53
54 @Test
55 public void saveNumbers() {
56 create("system.example.key[0]", List.of("1984"));
57 assertFalse(configDAO.findAll().isEmpty());
58 }
59
60 @Test
61 public void saveCollection() {
62 WAConfigEntry entry = create("system.example.key[0]", new ArrayList<>(Arrays.asList("1", "2")));
63 assertNotNull(entry.getValues());
64 assertFalse(configDAO.findAll().isEmpty());
65 }
66
67 @Test
68 public void saveList() {
69 create("system.example.key[0].key1", List.of("value1"));
70 assertFalse(configDAO.findAll().isEmpty());
71 }
72
73 @Test
74 public void update() {
75 WAConfigEntry entry = create("system.syncope.key[0]", Arrays.asList("1", "2", "3", "4"));
76 assertNotNull(entry);
77 entry.setValues(List.of("v1"));
78
79 entry = configDAO.save(entry);
80 assertNotNull(entry);
81 assertNotNull(entry.getKey());
82 WAConfigEntry found = configDAO.find(entry.getKey());
83 assertNotNull(found);
84 assertEquals(List.of("v1"), found.getValues());
85 }
86
87 private WAConfigEntry create(final String name, final List<String> value) {
88 WAConfigEntry entry = entityFactory.newEntity(WAConfigEntry.class);
89 entry.setKey(name);
90 entry.setValues(value);
91 configDAO.save(entry);
92 assertNotNull(entry);
93 assertNotNull(entry.getKey());
94 assertNotNull(configDAO.find(entry.getKey()));
95 return entry;
96 }
97 }