a800fde0
jcartign
First version, in...
|
1
2
|
package fr.plil.sio.persistence.jdbc;
|
292aec6f
jcartign
First version bef...
|
3
4
|
import fr.plil.sio.persistence.api.Right;
import fr.plil.sio.persistence.api.RightService;
|
bda41d02
jcartign
All tests method ...
|
5
|
import org.junit.Test;
|
a800fde0
jcartign
First version, in...
|
6
|
import org.junit.runner.RunWith;
|
292aec6f
jcartign
First version bef...
|
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;
|
292aec6f
jcartign
First version bef...
|
11
12
|
import static org.junit.Assert.*;
|
a800fde0
jcartign
First version, in...
|
13
|
@RunWith(SpringJUnit4ClassRunner.class)
|
29f04eb8
jcartign
Parameter "classe...
|
14
|
@SpringBootTest
|
292aec6f
jcartign
First version bef...
|
15
16
17
18
|
public class RightServiceTest extends AbstractServiceSupport {
@Autowired
private RightService rightService;
|
bda41d02
jcartign
All tests method ...
|
19
20
21
|
@Test
public void testCreateParentRightAndFindOne() {
|
292aec6f
jcartign
First version bef...
|
22
23
|
rightService.create("right");
assertEquals(1, rightService.findByName("right").size());
|
bda41d02
jcartign
All tests method ...
|
24
25
26
27
|
}
@Test
public void testCreateTwoParentRightsWithSameNameAndFindByName() {
|
292aec6f
jcartign
First version bef...
|
28
29
|
rightService.create("right");
rightService.create("right");
|
60e63100
msahmane
Test des Right à ...
|
30
|
assertEquals(1, rightService.findByName("right").size());
|
bda41d02
jcartign
All tests method ...
|
31
32
33
34
|
}
@Test(expected = IllegalArgumentException.class)
public void testCreateFailsIfNameNull() {
|
292aec6f
jcartign
First version bef...
|
35
|
rightService.create(null);
|
bda41d02
jcartign
All tests method ...
|
36
37
38
39
|
}
@Test
public void testCreateSiblingRightAndFindOne() {
|
292aec6f
jcartign
First version bef...
|
40
41
42
|
Right parent = rightService.create("parent");
rightService.create("sibling", parent);
assertEquals(1, rightService.findByName("sibling").size());
|
bda41d02
jcartign
All tests method ...
|
43
44
45
46
|
}
@Test(expected = IllegalArgumentException.class)
public void testCreateSiblingFailsIfNameNull() {
|
292aec6f
jcartign
First version bef...
|
47
48
|
Right parent = rightService.create("parent");
rightService.create(null, parent);
|
bda41d02
jcartign
All tests method ...
|
49
50
51
52
|
}
@Test(expected = IllegalArgumentException.class)
public void testCreateSiblingFailsIfParentNull() {
|
292aec6f
jcartign
First version bef...
|
53
54
|
rightService.create("parent");
rightService.create("sibling", null);
|
bda41d02
jcartign
All tests method ...
|
55
56
57
58
|
}
@Test(expected = IllegalArgumentException.class)
public void testCreateSiblingFailsIfParentNotInDatabase() {
|
292aec6f
jcartign
First version bef...
|
59
60
61
|
Right right = new Right();
right.setName("not-a-right");
rightService.create("sibling", right);
|
bda41d02
jcartign
All tests method ...
|
62
63
64
65
|
}
@Test
public void testDeleteParentRight() {
|
292aec6f
jcartign
First version bef...
|
66
67
68
69
|
Right right = rightService.create("right");
assertEquals(1, rightService.findByName("right").size());
rightService.delete(right);
assertEquals(0, rightService.findByName("right").size());
|
bda41d02
jcartign
All tests method ...
|
70
71
72
73
|
}
@Test
public void testDeleteSiblingRight() {
|
292aec6f
jcartign
First version bef...
|
74
75
76
77
|
Right parent = rightService.create("parent");
Right sibling = rightService.create("sibling", parent);
rightService.delete(sibling);
assertEquals(0, rightService.findByName("sibling").size());
|
bda41d02
jcartign
All tests method ...
|
78
79
|
}
|
bda41d02
jcartign
All tests method ...
|
80
81
|
@Test
public void testDeleteParentAndSiblingRights() {
|
292aec6f
jcartign
First version bef...
|
82
83
84
|
Right parent = rightService.create("parent");
rightService.create("sibling", parent);
rightService.delete(parent);
|
60e63100
msahmane
Test des Right à ...
|
85
|
assertEquals(1, rightService.findByName("sibling").size());
|
292aec6f
jcartign
First version bef...
|
86
|
assertEquals(0, rightService.findByName("parent").size());
|
bda41d02
jcartign
All tests method ...
|
87
88
89
90
|
}
@Test
public void testDeleteRightIfNotFound() {
|
292aec6f
jcartign
First version bef...
|
91
92
93
|
Right right = new Right();
right.setName("not-a-right");
assertFalse(rightService.delete(right));
|
bda41d02
jcartign
All tests method ...
|
94
95
96
97
|
}
@Test(expected = IllegalArgumentException.class)
public void testDeleteRightFailsIfRightNull() {
|
292aec6f
jcartign
First version bef...
|
98
|
rightService.delete(null);
|
bda41d02
jcartign
All tests method ...
|
99
100
101
102
|
}
@Test
public void testFindByNameIfNameNotFound() {
|
292aec6f
jcartign
First version bef...
|
103
|
assertEquals(0, rightService.findByName("no").size());
|
bda41d02
jcartign
All tests method ...
|
104
105
106
107
|
}
@Test(expected = IllegalArgumentException.class)
public void testFindByNameFailsIfNameNull() {
|
292aec6f
jcartign
First version bef...
|
108
|
rightService.findByName(null);
|
bda41d02
jcartign
All tests method ...
|
109
110
111
112
|
}
@Test
public void testFindOne() {
|
292aec6f
jcartign
First version bef...
|
113
114
|
Right right = rightService.create("right");
assertNotNull(rightService.findOne(right.getId()));
|
bda41d02
jcartign
All tests method ...
|
115
116
117
118
|
}
@Test
public void testFindOneIfIdNotFound() {
|
292aec6f
jcartign
First version bef...
|
119
|
assertNull(rightService.findOne(153463167809232L));
|
bda41d02
jcartign
All tests method ...
|
120
121
122
123
|
}
@Test(expected = IllegalArgumentException.class)
public void testFindOneFailsIfIdNull() {
|
292aec6f
jcartign
First version bef...
|
124
|
rightService.findOne(null);
|
bda41d02
jcartign
All tests method ...
|
125
|
}
|
a800fde0
jcartign
First version, in...
|
126
|
}
|