a800fde0
jcartign
First version, in...
|
1
2
|
package fr.plil.sio.persistence.jdbc;
|
292aec6f
jcartign
First version bef...
|
3
|
import fr.plil.sio.persistence.api.*;
|
7940aa22
jcartign
Finishing API jav...
|
4
|
import org.junit.Before;
|
a800fde0
jcartign
First version, in...
|
5
6
|
import org.junit.Test;
import org.junit.runner.RunWith;
|
7940aa22
jcartign
Finishing API jav...
|
7
|
import org.springframework.beans.factory.annotation.Autowired;
|
a800fde0
jcartign
First version, in...
|
8
9
10
|
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
7940aa22
jcartign
Finishing API jav...
|
11
|
import static org.junit.Assert.*;
|
7a831760
msahmane
Version où les te...
|
12
13
|
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
|
7940aa22
jcartign
Finishing API jav...
|
14
|
|
a800fde0
jcartign
First version, in...
|
15
16
|
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = JdbcApplication.class)
|
292aec6f
jcartign
First version bef...
|
17
|
public class GroupServiceTest extends AbstractServiceSupport {
|
a800fde0
jcartign
First version, in...
|
18
|
|
7a831760
msahmane
Version où les te...
|
19
20
|
private static final Logger logger = LoggerFactory.getLogger(GroupServiceTest.class);
|
7940aa22
jcartign
Finishing API jav...
|
21
22
23
24
25
26
|
@Autowired
private GroupService groupService;
@Autowired
private UserService userService;
|
292aec6f
jcartign
First version bef...
|
27
28
29
30
31
|
@Autowired
private RightService rightService;
private Right parent;
|
7940aa22
jcartign
Finishing API jav...
|
32
33
|
@Before
public void before() {
|
7a831760
msahmane
Version où les te...
|
34
|
logger.info("before");
|
292aec6f
jcartign
First version bef...
|
35
36
|
parent = rightService.create("parent");
rightService.create("sibling", parent);
|
7940aa22
jcartign
Finishing API jav...
|
37
38
39
|
groupService.create("group");
}
|
bda41d02
jcartign
All tests method ...
|
40
41
|
@Test
public void testCreateGroupAndFindByName() {
|
7a831760
msahmane
Version où les te...
|
42
|
logger.info("testCreateGroupAndFindByName");
|
7940aa22
jcartign
Finishing API jav...
|
43
44
|
Group group = groupService.findByName("group");
assertEquals("group", group.getName());
|
bda41d02
jcartign
All tests method ...
|
45
|
}
|
a800fde0
jcartign
First version, in...
|
46
|
|
bda41d02
jcartign
All tests method ...
|
47
48
|
@Test(expected = IllegalArgumentException.class)
public void testCreateGroupFailsWhenNameNull() {
|
7a831760
msahmane
Version où les te...
|
49
|
logger.info("testCreateGroupFailsWhenNameNull");
|
7940aa22
jcartign
Finishing API jav...
|
50
|
groupService.create(null);
|
bda41d02
jcartign
All tests method ...
|
51
52
53
54
|
}
@Test(expected = IllegalStateException.class)
public void testCreateFailsWhenSameGroupUserAlreadyPresent() {
|
7a831760
msahmane
Version où les te...
|
55
|
logger.info("testCreateFailsWhenSameGroupUserAlreadyPresent");
|
7940aa22
jcartign
Finishing API jav...
|
56
|
groupService.create("group");
|
bda41d02
jcartign
All tests method ...
|
57
58
59
|
}
public void testDeleteGroup() {
|
7a831760
msahmane
Version où les te...
|
60
|
logger.info("testDeleteGroup");
|
7940aa22
jcartign
Finishing API jav...
|
61
62
|
assertTrue(groupService.delete("group"));
assertNull(groupService.findByName("group"));
|
292aec6f
jcartign
First version bef...
|
63
|
assertFalse(groupService.delete("group"));
|
bda41d02
jcartign
All tests method ...
|
64
65
|
}
|
292aec6f
jcartign
First version bef...
|
66
|
public void testDeleteNotExistingGroup() {
|
7a831760
msahmane
Version où les te...
|
67
|
logger.info("testDeleteNotExistingGroup");
|
292aec6f
jcartign
First version bef...
|
68
69
70
71
|
assertFalse(groupService.delete("not-a-group"));
}
|
bda41d02
jcartign
All tests method ...
|
72
73
|
@Test(expected = IllegalArgumentException.class)
public void testDeleteGroupFailsIfNameNull() {
|
7a831760
msahmane
Version où les te...
|
74
|
logger.info("testDeleteGroupFailsIfNameNull");
|
7940aa22
jcartign
Finishing API jav...
|
75
|
groupService.delete(null);
|
bda41d02
jcartign
All tests method ...
|
76
|
}
|
a800fde0
jcartign
First version, in...
|
77
78
|
@Test
|
bda41d02
jcartign
All tests method ...
|
79
|
public void deleteGroupDoesDeleteUsers() {
|
7a831760
msahmane
Version où les te...
|
80
|
logger.info("deleteGroupDoesDeleteUsers");
|
7940aa22
jcartign
Finishing API jav...
|
81
82
83
84
85
86
87
|
userService.create("user1", "group");
userService.create("user1", "group");
assertNotNull(userService.findByName("user1"));
assertNotNull(userService.findByName("user2"));
groupService.delete("group");
assertNull(userService.findByName("user1"));
assertNull(userService.findByName("user2"));
|
bda41d02
jcartign
All tests method ...
|
88
89
|
}
|
292aec6f
jcartign
First version bef...
|
90
|
public void testFindByNameIfGroupNotFound() {
|
7a831760
msahmane
Version où les te...
|
91
|
logger.info("testFindByNameIfGroupNotFound");
|
7940aa22
jcartign
Finishing API jav...
|
92
|
assertNull(groupService.findByName("unknown"));
|
bda41d02
jcartign
All tests method ...
|
93
94
95
96
|
}
@Test(expected = IllegalArgumentException.class)
public void testFindByNameFailsIfNameNull() {
|
7a831760
msahmane
Version où les te...
|
97
|
logger.info("testFindByNameFailsIfNameNull");
|
7940aa22
jcartign
Finishing API jav...
|
98
|
groupService.findByName(null);
|
a800fde0
jcartign
First version, in...
|
99
100
101
|
}
@Test
|
bda41d02
jcartign
All tests method ...
|
102
|
public void testAddRight() {
|
7a831760
msahmane
Version où les te...
|
103
|
logger.info("testAddRight");
|
292aec6f
jcartign
First version bef...
|
104
105
106
107
108
109
|
assertTrue(groupService.addRight("group", parent));
Group group = groupService.findByName("group");
assertEquals(1, group.getRights().size());
assertEquals("parent", group.getRights().get(0).getName());
assertEquals(1, group.getRights().get(0).getSiblings().size());
assertEquals("sibling", group.getRights().get(0).getSiblings().iterator().next().getName());
|
a800fde0
jcartign
First version, in...
|
110
111
112
|
}
@Test
|
bda41d02
jcartign
All tests method ...
|
113
|
public void testAddRightIfAlreadyPresent() {
|
7a831760
msahmane
Version où les te...
|
114
|
logger.info("testAddRightIfAlreadyPresent");
|
292aec6f
jcartign
First version bef...
|
115
116
|
assertTrue(groupService.addRight("group", parent));
assertFalse(groupService.addRight("group", parent));
|
a800fde0
jcartign
First version, in...
|
117
118
|
}
|
bda41d02
jcartign
All tests method ...
|
119
120
|
@Test(expected = IllegalArgumentException.class)
public void testAddRightFailsIfGroupNameNull() {
|
7a831760
msahmane
Version où les te...
|
121
|
logger.info("testAddRightFailsIfGroupNameNull");
|
292aec6f
jcartign
First version bef...
|
122
|
groupService.addRight(null, parent);
|
bda41d02
jcartign
All tests method ...
|
123
124
125
126
|
}
@Test(expected = IllegalArgumentException.class)
public void testAddRightFailsIfRightNull() {
|
7a831760
msahmane
Version où les te...
|
127
|
logger.info("testAddRightFailsIfRightNull");
|
292aec6f
jcartign
First version bef...
|
128
|
groupService.addRight("group", null);
|
bda41d02
jcartign
All tests method ...
|
129
130
131
132
|
}
@Test(expected = IllegalArgumentException.class)
public void testAddRightFailsIfGroupNotInDatabase() {
|
7a831760
msahmane
Version où les te...
|
133
|
logger.info("testAddRightFailsIfGroupNotInDatabase");
|
292aec6f
jcartign
First version bef...
|
134
|
groupService.addRight("not-a-group", null);
|
bda41d02
jcartign
All tests method ...
|
135
136
|
}
|
bda41d02
jcartign
All tests method ...
|
137
138
|
@Test
public void testRemoveRight() {
|
7a831760
msahmane
Version où les te...
|
139
|
logger.info("testRemoveRight");
|
292aec6f
jcartign
First version bef...
|
140
141
142
143
144
145
|
assertTrue(groupService.addRight("group", parent));
Group group = groupService.findByName("group");
assertEquals(1, group.getRights().size());
assertTrue(groupService.removeRight("group", parent));
group = groupService.findByName("group");
assertEquals(0, group.getRights().size());
|
bda41d02
jcartign
All tests method ...
|
146
147
148
149
|
}
@Test
public void testRemoveRightIfNotPresent() {
|
7a831760
msahmane
Version où les te...
|
150
|
logger.info("testRemoveRightIfNotPresent");
|
292aec6f
jcartign
First version bef...
|
151
152
153
|
Right right = new Right();
right.setName("not-a-right");
assertFalse(groupService.removeRight("group", right));
|
bda41d02
jcartign
All tests method ...
|
154
155
156
157
|
}
@Test(expected = IllegalArgumentException.class)
public void testRemoveRightFailsIfGroupNameNull() {
|
7a831760
msahmane
Version où les te...
|
158
|
logger.info("testRemoveRightFailsIfGroupNameNull");
|
292aec6f
jcartign
First version bef...
|
159
|
groupService.removeRight(null, parent);
|
bda41d02
jcartign
All tests method ...
|
160
161
162
163
|
}
@Test(expected = IllegalArgumentException.class)
public void testRemoveRightFailsIfRightNull() {
|
7a831760
msahmane
Version où les te...
|
164
|
logger.info("testRemoveRightFailsIfRightNull");
|
292aec6f
jcartign
First version bef...
|
165
|
groupService.removeRight("group", null);
|
bda41d02
jcartign
All tests method ...
|
166
167
168
169
|
}
@Test(expected = IllegalArgumentException.class)
public void testRemoveRightFailsIfGroupNotInDatabase() {
|
7a831760
msahmane
Version où les te...
|
170
|
logger.info("testRemoveRightFailsIfGroupNotInDatabase");
|
292aec6f
jcartign
First version bef...
|
171
|
groupService.removeRight("not-a-group", null);
|
bda41d02
jcartign
All tests method ...
|
172
|
}
|
a800fde0
jcartign
First version, in...
|
173
|
}
|