Commit 7a8317609d7c772c8b3d73734b0e9203877bcbfe
1 parent
31bdbe1b
Version où les tests ne passent pas pour des raisons incompréhensibles.(Fichiers de test)
Showing
2 changed files
with
44 additions
and
0 deletions
Show diff stats
src/test/java/fr/plil/sio/persistence/jdbc/AbstractServiceSupport.java
... | ... | @@ -8,13 +8,27 @@ import javax.sql.DataSource; |
8 | 8 | import java.sql.Connection; |
9 | 9 | import java.sql.SQLException; |
10 | 10 | import java.sql.Statement; |
11 | +import org.slf4j.Logger; | |
12 | +import org.slf4j.LoggerFactory; | |
11 | 13 | |
12 | 14 | public abstract class AbstractServiceSupport { |
13 | 15 | |
16 | + private static final Logger logger = LoggerFactory.getLogger(AbstractServiceSupport.class); | |
17 | + | |
14 | 18 | private static final String create_table_group = "CREATE TABLE GROUP_T (GROUP_ID INT NOT NULL AUTO_INCREMENT, " + |
15 | 19 | "NAME_C VARCHAR(50) UNIQUE NOT NULL, PRIMARY KEY(GROUP_ID))"; |
16 | 20 | |
21 | + private static final String create_table_right = "CREATE TABLE RIGHT_T (RIGHT_ID INT NOT NULL AUTO_INCREMENT, "+ | |
22 | + "NAME_R VARCHAR(50) UNIQUE NOT NULL, PRIMARY KEY(RIGHT_ID), PARENT INT, FOREIGN KEY(PARENT) REFERENCES RIGHT_T(RIGHT_ID))"; | |
23 | + | |
24 | + private static final String create_table_user = "CREATE TABLE USER_T (USER_ID INT NOT NULL AUTO_INCREMENT, "+ | |
25 | + "NAME_U VARCHAR(50) UNIQUE NOT NULL, PRIMARY KEY(USER_ID), GROUP_U INT, FOREIGN KEY(GROUP_U) REFERENCES GROUP_T(GROUP_ID)) "; | |
26 | + | |
17 | 27 | private static final String drop_table_group = "DROP TABLE GROUP_T"; |
28 | + | |
29 | + private static final String drop_table_right = "DROP TABLE RIGHT_T"; | |
30 | + | |
31 | + private static final String drop_table_user = "DROP TABLE USER_T"; | |
18 | 32 | |
19 | 33 | @Autowired |
20 | 34 | private DataSource dataSource; |
... | ... | @@ -25,15 +39,21 @@ public abstract class AbstractServiceSupport { |
25 | 39 | |
26 | 40 | @Before |
27 | 41 | public void createTables() throws SQLException { |
42 | + logger.debug("createTables"); | |
28 | 43 | openConnection(); |
29 | 44 | stmt.executeUpdate(create_table_group); |
45 | + stmt.executeUpdate(create_table_right); | |
46 | + stmt.executeUpdate(create_table_user); | |
30 | 47 | closeConnection(); |
31 | 48 | } |
32 | 49 | |
33 | 50 | @After |
34 | 51 | public void cleanupDatabase() throws SQLException { |
52 | + logger.debug("cleanupDatabase"); | |
35 | 53 | openConnection(); |
36 | 54 | stmt.executeUpdate(drop_table_group); |
55 | + stmt.executeUpdate(drop_table_right); | |
56 | + stmt.executeUpdate(drop_table_user); | |
37 | 57 | closeConnection(); |
38 | 58 | } |
39 | 59 | ... | ... |
src/test/java/fr/plil/sio/persistence/jdbc/GroupServiceTest.java
... | ... | @@ -9,11 +9,15 @@ import org.springframework.boot.test.SpringApplicationConfiguration; |
9 | 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
10 | 10 | |
11 | 11 | import static org.junit.Assert.*; |
12 | +import org.slf4j.Logger; | |
13 | +import org.slf4j.LoggerFactory; | |
12 | 14 | |
13 | 15 | @RunWith(SpringJUnit4ClassRunner.class) |
14 | 16 | @SpringApplicationConfiguration(classes = JdbcApplication.class) |
15 | 17 | public class GroupServiceTest extends AbstractServiceSupport { |
16 | 18 | |
19 | + private static final Logger logger = LoggerFactory.getLogger(GroupServiceTest.class); | |
20 | + | |
17 | 21 | @Autowired |
18 | 22 | private GroupService groupService; |
19 | 23 | |
... | ... | @@ -27,6 +31,7 @@ public class GroupServiceTest extends AbstractServiceSupport { |
27 | 31 | |
28 | 32 | @Before |
29 | 33 | public void before() { |
34 | + logger.info("before"); | |
30 | 35 | parent = rightService.create("parent"); |
31 | 36 | rightService.create("sibling", parent); |
32 | 37 | groupService.create("group"); |
... | ... | @@ -34,38 +39,45 @@ public class GroupServiceTest extends AbstractServiceSupport { |
34 | 39 | |
35 | 40 | @Test |
36 | 41 | public void testCreateGroupAndFindByName() { |
42 | + logger.info("testCreateGroupAndFindByName"); | |
37 | 43 | Group group = groupService.findByName("group"); |
38 | 44 | assertEquals("group", group.getName()); |
39 | 45 | } |
40 | 46 | |
41 | 47 | @Test(expected = IllegalArgumentException.class) |
42 | 48 | public void testCreateGroupFailsWhenNameNull() { |
49 | + logger.info("testCreateGroupFailsWhenNameNull"); | |
43 | 50 | groupService.create(null); |
44 | 51 | } |
45 | 52 | |
46 | 53 | @Test(expected = IllegalStateException.class) |
47 | 54 | public void testCreateFailsWhenSameGroupUserAlreadyPresent() { |
55 | + logger.info("testCreateFailsWhenSameGroupUserAlreadyPresent"); | |
48 | 56 | groupService.create("group"); |
49 | 57 | } |
50 | 58 | |
51 | 59 | public void testDeleteGroup() { |
60 | + logger.info("testDeleteGroup"); | |
52 | 61 | assertTrue(groupService.delete("group")); |
53 | 62 | assertNull(groupService.findByName("group")); |
54 | 63 | assertFalse(groupService.delete("group")); |
55 | 64 | } |
56 | 65 | |
57 | 66 | public void testDeleteNotExistingGroup() { |
67 | + logger.info("testDeleteNotExistingGroup"); | |
58 | 68 | assertFalse(groupService.delete("not-a-group")); |
59 | 69 | } |
60 | 70 | |
61 | 71 | |
62 | 72 | @Test(expected = IllegalArgumentException.class) |
63 | 73 | public void testDeleteGroupFailsIfNameNull() { |
74 | + logger.info("testDeleteGroupFailsIfNameNull"); | |
64 | 75 | groupService.delete(null); |
65 | 76 | } |
66 | 77 | |
67 | 78 | @Test |
68 | 79 | public void deleteGroupDoesDeleteUsers() { |
80 | + logger.info("deleteGroupDoesDeleteUsers"); | |
69 | 81 | userService.create("user1", "group"); |
70 | 82 | userService.create("user1", "group"); |
71 | 83 | assertNotNull(userService.findByName("user1")); |
... | ... | @@ -76,16 +88,19 @@ public class GroupServiceTest extends AbstractServiceSupport { |
76 | 88 | } |
77 | 89 | |
78 | 90 | public void testFindByNameIfGroupNotFound() { |
91 | + logger.info("testFindByNameIfGroupNotFound"); | |
79 | 92 | assertNull(groupService.findByName("unknown")); |
80 | 93 | } |
81 | 94 | |
82 | 95 | @Test(expected = IllegalArgumentException.class) |
83 | 96 | public void testFindByNameFailsIfNameNull() { |
97 | + logger.info("testFindByNameFailsIfNameNull"); | |
84 | 98 | groupService.findByName(null); |
85 | 99 | } |
86 | 100 | |
87 | 101 | @Test |
88 | 102 | public void testAddRight() { |
103 | + logger.info("testAddRight"); | |
89 | 104 | assertTrue(groupService.addRight("group", parent)); |
90 | 105 | Group group = groupService.findByName("group"); |
91 | 106 | assertEquals(1, group.getRights().size()); |
... | ... | @@ -96,27 +111,32 @@ public class GroupServiceTest extends AbstractServiceSupport { |
96 | 111 | |
97 | 112 | @Test |
98 | 113 | public void testAddRightIfAlreadyPresent() { |
114 | + logger.info("testAddRightIfAlreadyPresent"); | |
99 | 115 | assertTrue(groupService.addRight("group", parent)); |
100 | 116 | assertFalse(groupService.addRight("group", parent)); |
101 | 117 | } |
102 | 118 | |
103 | 119 | @Test(expected = IllegalArgumentException.class) |
104 | 120 | public void testAddRightFailsIfGroupNameNull() { |
121 | + logger.info("testAddRightFailsIfGroupNameNull"); | |
105 | 122 | groupService.addRight(null, parent); |
106 | 123 | } |
107 | 124 | |
108 | 125 | @Test(expected = IllegalArgumentException.class) |
109 | 126 | public void testAddRightFailsIfRightNull() { |
127 | + logger.info("testAddRightFailsIfRightNull"); | |
110 | 128 | groupService.addRight("group", null); |
111 | 129 | } |
112 | 130 | |
113 | 131 | @Test(expected = IllegalArgumentException.class) |
114 | 132 | public void testAddRightFailsIfGroupNotInDatabase() { |
133 | + logger.info("testAddRightFailsIfGroupNotInDatabase"); | |
115 | 134 | groupService.addRight("not-a-group", null); |
116 | 135 | } |
117 | 136 | |
118 | 137 | @Test |
119 | 138 | public void testRemoveRight() { |
139 | + logger.info("testRemoveRight"); | |
120 | 140 | assertTrue(groupService.addRight("group", parent)); |
121 | 141 | Group group = groupService.findByName("group"); |
122 | 142 | assertEquals(1, group.getRights().size()); |
... | ... | @@ -127,6 +147,7 @@ public class GroupServiceTest extends AbstractServiceSupport { |
127 | 147 | |
128 | 148 | @Test |
129 | 149 | public void testRemoveRightIfNotPresent() { |
150 | + logger.info("testRemoveRightIfNotPresent"); | |
130 | 151 | Right right = new Right(); |
131 | 152 | right.setName("not-a-right"); |
132 | 153 | assertFalse(groupService.removeRight("group", right)); |
... | ... | @@ -134,16 +155,19 @@ public class GroupServiceTest extends AbstractServiceSupport { |
134 | 155 | |
135 | 156 | @Test(expected = IllegalArgumentException.class) |
136 | 157 | public void testRemoveRightFailsIfGroupNameNull() { |
158 | + logger.info("testRemoveRightFailsIfGroupNameNull"); | |
137 | 159 | groupService.removeRight(null, parent); |
138 | 160 | } |
139 | 161 | |
140 | 162 | @Test(expected = IllegalArgumentException.class) |
141 | 163 | public void testRemoveRightFailsIfRightNull() { |
164 | + logger.info("testRemoveRightFailsIfRightNull"); | |
142 | 165 | groupService.removeRight("group", null); |
143 | 166 | } |
144 | 167 | |
145 | 168 | @Test(expected = IllegalArgumentException.class) |
146 | 169 | public void testRemoveRightFailsIfGroupNotInDatabase() { |
170 | + logger.info("testRemoveRightFailsIfGroupNotInDatabase"); | |
147 | 171 | groupService.removeRight("not-a-group", null); |
148 | 172 | } |
149 | 173 | } | ... | ... |