GroupServiceTest.java
2.05 KB
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
package fr.plil.sio.persistence.jdbc;
import fr.plil.sio.persistence.api.Group;
import fr.plil.sio.persistence.api.GroupService;
import fr.plil.sio.persistence.api.User;
import fr.plil.sio.persistence.api.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = JdbcApplication.class)
public class GroupServiceTest {
@Autowired
private UserService userService;
@Autowired
private GroupService groupService;
@Test
public void testCreateAndFindByName() {
groupService.create("group1");
Group group2 = groupService.findByName("group1");
assertNotNull(group2);
assertNotNull(group2.getName());
assertEquals("group1", group2.getName());
}
@Test
public void addUsersAndCheckIfPresent() {
Group group1 = groupService.create("group1");
User user1 = userService.create("user1");
User user2 = userService.create("user2");
groupService.addUser(group1, user1);
groupService.addUser(group1, user2);
Group group2 = groupService.findByName("group1");
assertNotNull(group2);
assertNotNull(group2.getName());
assertEquals("group1", group2.getName());
assertEquals(2, group2.getUsers().size());
}
@Test
public void deleteGroupDoesNotDeleteUsers() {
Group group1 = groupService.create("group1");
User user1 = userService.create("user1");
User user2 = userService.create("user2");
groupService.addUser(group1, user1);
groupService.addUser(group1, user2);
groupService.delete(group1);
assertNotNull(userService.findByName("user1"));
assertNotNull(userService.findByName("user2"));
}
}