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;
|
5b26096d
jcartign
Switch to @Spring...
|
8
|
import org.springframework.boot.test.context.SpringBootTest;
|
a800fde0
jcartign
First version, in...
|
9
10
|
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
|
@RunWith(SpringJUnit4ClassRunner.class)
|
29f04eb8
jcartign
Parameter "classe...
|
16
|
@SpringBootTest
|
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
|
}
|
77b66887
jcartign
Forgot some @Test...
|
59
|
@Test
|
bda41d02
jcartign
All tests method ...
|
60
|
public void testDeleteGroup() {
|
7a831760
msahmane
Version où les te...
|
61
|
logger.info("testDeleteGroup");
|
7940aa22
jcartign
Finishing API jav...
|
62
63
|
assertTrue(groupService.delete("group"));
assertNull(groupService.findByName("group"));
|
292aec6f
jcartign
First version bef...
|
64
|
assertFalse(groupService.delete("group"));
|
bda41d02
jcartign
All tests method ...
|
65
66
|
}
|
77b66887
jcartign
Forgot some @Test...
|
67
|
@Test
|
292aec6f
jcartign
First version bef...
|
68
|
public void testDeleteNotExistingGroup() {
|
7a831760
msahmane
Version où les te...
|
69
|
logger.info("testDeleteNotExistingGroup");
|
292aec6f
jcartign
First version bef...
|
70
71
72
73
|
assertFalse(groupService.delete("not-a-group"));
}
|
bda41d02
jcartign
All tests method ...
|
74
75
|
@Test(expected = IllegalArgumentException.class)
public void testDeleteGroupFailsIfNameNull() {
|
7a831760
msahmane
Version où les te...
|
76
|
logger.info("testDeleteGroupFailsIfNameNull");
|
7940aa22
jcartign
Finishing API jav...
|
77
|
groupService.delete(null);
|
bda41d02
jcartign
All tests method ...
|
78
|
}
|
a800fde0
jcartign
First version, in...
|
79
80
|
@Test
|
bda41d02
jcartign
All tests method ...
|
81
|
public void deleteGroupDoesDeleteUsers() {
|
7a831760
msahmane
Version où les te...
|
82
|
logger.info("deleteGroupDoesDeleteUsers");
|
7940aa22
jcartign
Finishing API jav...
|
83
84
85
86
87
88
89
|
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 ...
|
90
91
|
}
|
292aec6f
jcartign
First version bef...
|
92
|
public void testFindByNameIfGroupNotFound() {
|
7a831760
msahmane
Version où les te...
|
93
|
logger.info("testFindByNameIfGroupNotFound");
|
7940aa22
jcartign
Finishing API jav...
|
94
|
assertNull(groupService.findByName("unknown"));
|
bda41d02
jcartign
All tests method ...
|
95
96
97
98
|
}
@Test(expected = IllegalArgumentException.class)
public void testFindByNameFailsIfNameNull() {
|
7a831760
msahmane
Version où les te...
|
99
|
logger.info("testFindByNameFailsIfNameNull");
|
7940aa22
jcartign
Finishing API jav...
|
100
|
groupService.findByName(null);
|
a800fde0
jcartign
First version, in...
|
101
102
103
|
}
@Test
|
bda41d02
jcartign
All tests method ...
|
104
|
public void testAddRight() {
|
7a831760
msahmane
Version où les te...
|
105
|
logger.info("testAddRight");
|
292aec6f
jcartign
First version bef...
|
106
107
108
109
110
111
|
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...
|
112
113
114
|
}
@Test
|
bda41d02
jcartign
All tests method ...
|
115
|
public void testAddRightIfAlreadyPresent() {
|
7a831760
msahmane
Version où les te...
|
116
|
logger.info("testAddRightIfAlreadyPresent");
|
292aec6f
jcartign
First version bef...
|
117
118
|
assertTrue(groupService.addRight("group", parent));
assertFalse(groupService.addRight("group", parent));
|
a800fde0
jcartign
First version, in...
|
119
120
|
}
|
bda41d02
jcartign
All tests method ...
|
121
122
|
@Test(expected = IllegalArgumentException.class)
public void testAddRightFailsIfGroupNameNull() {
|
7a831760
msahmane
Version où les te...
|
123
|
logger.info("testAddRightFailsIfGroupNameNull");
|
292aec6f
jcartign
First version bef...
|
124
|
groupService.addRight(null, parent);
|
bda41d02
jcartign
All tests method ...
|
125
126
127
128
|
}
@Test(expected = IllegalArgumentException.class)
public void testAddRightFailsIfRightNull() {
|
7a831760
msahmane
Version où les te...
|
129
|
logger.info("testAddRightFailsIfRightNull");
|
292aec6f
jcartign
First version bef...
|
130
|
groupService.addRight("group", null);
|
bda41d02
jcartign
All tests method ...
|
131
132
133
134
|
}
@Test(expected = IllegalArgumentException.class)
public void testAddRightFailsIfGroupNotInDatabase() {
|
7a831760
msahmane
Version où les te...
|
135
|
logger.info("testAddRightFailsIfGroupNotInDatabase");
|
292aec6f
jcartign
First version bef...
|
136
|
groupService.addRight("not-a-group", null);
|
bda41d02
jcartign
All tests method ...
|
137
138
|
}
|
bda41d02
jcartign
All tests method ...
|
139
140
|
@Test
public void testRemoveRight() {
|
7a831760
msahmane
Version où les te...
|
141
|
logger.info("testRemoveRight");
|
292aec6f
jcartign
First version bef...
|
142
143
144
145
146
147
|
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 ...
|
148
149
150
151
|
}
@Test
public void testRemoveRightIfNotPresent() {
|
7a831760
msahmane
Version où les te...
|
152
|
logger.info("testRemoveRightIfNotPresent");
|
292aec6f
jcartign
First version bef...
|
153
154
155
|
Right right = new Right();
right.setName("not-a-right");
assertFalse(groupService.removeRight("group", right));
|
bda41d02
jcartign
All tests method ...
|
156
157
158
159
|
}
@Test(expected = IllegalArgumentException.class)
public void testRemoveRightFailsIfGroupNameNull() {
|
7a831760
msahmane
Version où les te...
|
160
|
logger.info("testRemoveRightFailsIfGroupNameNull");
|
292aec6f
jcartign
First version bef...
|
161
|
groupService.removeRight(null, parent);
|
bda41d02
jcartign
All tests method ...
|
162
163
164
165
|
}
@Test(expected = IllegalArgumentException.class)
public void testRemoveRightFailsIfRightNull() {
|
7a831760
msahmane
Version où les te...
|
166
|
logger.info("testRemoveRightFailsIfRightNull");
|
292aec6f
jcartign
First version bef...
|
167
|
groupService.removeRight("group", null);
|
bda41d02
jcartign
All tests method ...
|
168
169
170
171
|
}
@Test(expected = IllegalArgumentException.class)
public void testRemoveRightFailsIfGroupNotInDatabase() {
|
7a831760
msahmane
Version où les te...
|
172
|
logger.info("testRemoveRightFailsIfGroupNotInDatabase");
|
292aec6f
jcartign
First version bef...
|
173
|
groupService.removeRight("not-a-group", null);
|
bda41d02
jcartign
All tests method ...
|
174
|
}
|
a800fde0
jcartign
First version, in...
|
175
|
}
|