From bda41d029193295a064f50bcfb814d79efafbb49 Mon Sep 17 00:00:00 2001 From: Julien Iguchi-Cartigny Date: Mon, 18 Jul 2016 06:50:17 +0200 Subject: [PATCH] All tests method prototypes ready --- src/main/java/fr/plil/sio/persistence/api/GroupService.java | 21 --------------------- src/test/java/fr/plil/sio/persistence/jdbc/GroupServiceTest.java | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------- src/test/java/fr/plil/sio/persistence/jdbc/RightServiceTest.java | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/test/java/fr/plil/sio/persistence/jdbc/UserServiceTest.java | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------- 4 files changed, 230 insertions(+), 79 deletions(-) diff --git a/src/main/java/fr/plil/sio/persistence/api/GroupService.java b/src/main/java/fr/plil/sio/persistence/api/GroupService.java index 93dc768..f2992a9 100644 --- a/src/main/java/fr/plil/sio/persistence/api/GroupService.java +++ b/src/main/java/fr/plil/sio/persistence/api/GroupService.java @@ -32,32 +32,11 @@ public interface GroupService { Group findByName(String name); /** - * Add an user in the group. - * - * @param groupName the name of the group. - * @param userName the name of the user to add in the group. - * @return true if user is added in the group, false if user was already present. - * @throws IllegalArgumentException if groupName or userName is null, or if group or user cannot be found. - */ - boolean addUser(String groupName, String userName); - - /** - * Remove an user in the group. - * - * @param groupName the name of the group. - * @param userName the name of the user to remove from the group. - * @return true if user is removed from the group, false if user was not present in the group. - * @throws IllegalArgumentException if groupName or userName is null, or if group or user cannot be found. - */ - boolean removeUser(String groupName, String userName); - - /** * Add a right in the group. Right is inserted at the end of rights list of the group. * * @param groupName the name of the group. * @param right the right to add * @return true if right is added in the group, false if right was already present. - * @throws IllegalStateException if a parent right is already present * @throws IllegalArgumentException if groupName or right is null, or if group or right cannot be found. */ boolean addRight(String groupName, Right right); diff --git a/src/test/java/fr/plil/sio/persistence/jdbc/GroupServiceTest.java b/src/test/java/fr/plil/sio/persistence/jdbc/GroupServiceTest.java index 6b6625a..8f7a19c 100644 --- a/src/test/java/fr/plil/sio/persistence/jdbc/GroupServiceTest.java +++ b/src/test/java/fr/plil/sio/persistence/jdbc/GroupServiceTest.java @@ -1,61 +1,114 @@ 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; + @Test + public void testCreateGroupAndFindByName() { + } - @Autowired - private GroupService groupService; + @Test(expected = IllegalArgumentException.class) + public void testCreateGroupFailsWhenNameNull() { + } + + @Test(expected = IllegalStateException.class) + public void testCreateFailsWhenSameGroupUserAlreadyPresent() { + } + + public void testDeleteGroup() { + } + + public void testDeleteGroupIfNotFound() { + } + + @Test(expected = IllegalArgumentException.class) + public void testDeleteGroupFailsIfNameNull() { + } @Test - public void testCreateAndFindByName() { - groupService.create("group1"); - Group group2 = groupService.findByName("group1"); - assertNotNull(group2); - assertNotNull(group2.getName()); - assertEquals("group1", group2.getName()); + public void deleteGroupDoesDeleteUsers() { + } + + public void testFindByNameIfUserNotFound() { + } + + @Test(expected = IllegalArgumentException.class) + public void testFindByNameFailsIfNameNull() { } @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()); + public void testAddRight() { + } @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")); + public void testAddRightIfAlreadyPresent() { + } + @Test(expected = IllegalArgumentException.class) + public void testAddRightFailsIfGroupNameNull() { + + } + + @Test(expected = IllegalArgumentException.class) + public void testAddRightFailsIfRightNull() { + + } + + @Test(expected = IllegalArgumentException.class) + public void testAddRightFailsIfGroupNotInDatabase() { + + } + + @Test(expected = IllegalArgumentException.class) + public void testAddUserFailsIfRightNotInDatabase() { + + } + + + /** + * Remove a right associated with a group. + * + * @param groupName the name of the group. + * @param right the right to remove + * @return true if right is removed from the group, false if teh right was not present in the group. + * @throws IllegalArgumentException if groupName or right is null, or if group or right cannot be found. + */ + + @Test + public void testRemoveRight() { + + } + + @Test + public void testRemoveRightIfNotPresent() { + + } + + @Test(expected = IllegalArgumentException.class) + public void testRemoveRightFailsIfGroupNameNull() { + + } + + @Test(expected = IllegalArgumentException.class) + public void testRemoveRightFailsIfRightNull() { + + } + + @Test(expected = IllegalArgumentException.class) + public void testRemoveRightFailsIfGroupNotInDatabase() { + + } + + @Test(expected = IllegalArgumentException.class) + public void testRemoveRightFailsIfRightNotInDatabase() { + + } } diff --git a/src/test/java/fr/plil/sio/persistence/jdbc/RightServiceTest.java b/src/test/java/fr/plil/sio/persistence/jdbc/RightServiceTest.java index 81e848c..584c4d2 100644 --- a/src/test/java/fr/plil/sio/persistence/jdbc/RightServiceTest.java +++ b/src/test/java/fr/plil/sio/persistence/jdbc/RightServiceTest.java @@ -1,5 +1,6 @@ package fr.plil.sio.persistence.jdbc; +import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -7,4 +8,88 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = JdbcApplication.class) public class RightServiceTest { + + @Test + public void testCreateParentRightAndFindOne() { + + } + + @Test + public void testCreateTwoParentRightsWithSameNameAndFindByName() { + + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateFailsIfNameNull() { + + } + + @Test + public void testCreateSiblingRightAndFindOne() { + + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateSiblingFailsIfNameNull() { + + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateSiblingFailsIfParentNull() { + + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateSiblingFailsIfParentNotInDatabase() { + + } + + @Test + public void testDeleteParentRight() { + } + + @Test + public void testDeleteSiblingRight() { + } + + + @Test + public void testDeleteParentAndSiblingRights() { + } + + @Test + public void testDeleteRightIfNotFound() { + } + + @Test(expected = IllegalArgumentException.class) + public void testDeleteRightFailsIfRightNull() { + } + + @Test + public void testFindByName() { + } + + @Test + public void testFindSeveralByName() { + } + + @Test + public void testFindByNameIfNameNotFound() { + } + + @Test(expected = IllegalArgumentException.class) + public void testFindByNameFailsIfNameNull() { + } + + @Test + public void testFindOne() { + } + + @Test + public void testFindOneIfIdNotFound() { + } + + @Test(expected = IllegalArgumentException.class) + public void testFindOneFailsIfIdNull() { + } } diff --git a/src/test/java/fr/plil/sio/persistence/jdbc/UserServiceTest.java b/src/test/java/fr/plil/sio/persistence/jdbc/UserServiceTest.java index 5e5e590..09150c4 100644 --- a/src/test/java/fr/plil/sio/persistence/jdbc/UserServiceTest.java +++ b/src/test/java/fr/plil/sio/persistence/jdbc/UserServiceTest.java @@ -1,35 +1,69 @@ package fr.plil.sio.persistence.jdbc; -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 UserServiceTest { - @Autowired - private UserService userService; - @Test public void testCreateAndFindByName() { - final String name = "blabla"; - User user1 = userService.create(name); - User user2 = userService.findByName(name); - assertNotNull(user1); - assertNotNull(user2); - assertNotNull(user1.getName()); - assertNotNull(user2.getName()); - assertNotNull(user1.getGroup()); - assertNotNull(user2.getGroup()); - assertEquals(user1.getName(), user2.getName()); - assertEquals(user1.getGroup(), user2.getGroup()); + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateFailsWhenNameNull() { + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateFailsWhenGroupNameNull() { + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateFailsWhenGroupDoesNotExist() { + } + + @Test(expected = IllegalStateException.class) + public void testCreateFailsWhenSameNameUserAlreadyPresent() { + } + + public void testDeleteUser() { + } + + public void testDeleteUserIfNotFound() { + } + + @Test(expected = IllegalArgumentException.class) + public void testDeleteUserFailsIfNameNull() { + } + + public void testFindUserByNameIfUserNotFound() { + } + + @Test(expected = IllegalArgumentException.class) + public void testFindUserByNameFailsIfNameNull() { + } + + public void testIsUserHasExactRight() { + } + + public void testIsUserHasRightByParents() { + } + + public void testIsUserHasNotTheExactRight() { + } + + @Test(expected = IllegalArgumentException.class) + public void testIsUserHasRightFailsWhenUsernameNull() { + } + + @Test(expected = IllegalArgumentException.class) + public void testIsUserHasRightFailsWhenRightNull() { + } + + @Test(expected = IllegalArgumentException.class) + public void testIsUserHasRightFailsWhenRightNotInDatabase() { } } -- libgit2 0.21.2