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