Commit 7a8317609d7c772c8b3d73734b0e9203877bcbfe

Authored by msahmane
1 parent 31bdbe1b

Version où les tests ne passent pas pour des raisons incompréhensibles.(Fichiers de test)

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