kleine Änderungen an UserControllerTest
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / core / UserControllerTest.java
index 2e26d45..3c76c2a 100644 (file)
@@ -18,8 +18,188 @@ import org.junit.Test;
 public class UserControllerTest {\r
 \r
        @Test\r
-       public void test() {\r
-               fail("Not yet implemented");\r
+       public void addUserTest() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\r
+               \r
+               uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
+               uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
+       }\r
+       \r
+       @Test(expected=Exception.class)\r
+       public void addUserExceptionTest() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\r
+               \r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
        }\r
 \r
+       @Test\r
+       public void logInTest() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\r
+               \r
+               uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
+               uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
+               \r
+               uc.logIn("TestUser3", "pass3");\r
+       }\r
+       \r
+       @Test(expected=Exception.class)\r
+       public void logInException1Test() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\r
+               uc.logIn("TestUser3", "pass3");\r
+       }\r
+\r
+       @Test(expected=Exception.class)\r
+       public void logInException2Test() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\r
+               \r
+               uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               \r
+               uc.logIn("TestUser1", "pass1");\r
+               uc.logIn("TestUser2", "pass2");\r
+       }\r
+       \r
+       @Test\r
+       public void logInInvalidCredetialsTest() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\r
+               \r
+               uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               \r
+               assertFalse(uc.logIn("TestUser3", "pass3"));\r
+               assertFalse(uc.logIn("TestUser1", "pass2"));\r
+               assertTrue(uc.logIn("TestUser1", "pass1"));\r
+       }\r
+       \r
+       @Test\r
+       public void getLoggedUserNameTest() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\r
+               \r
+               uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
+               uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
+               \r
+               uc.logIn("TestUser1", "pass1");\r
+               assertEquals("TestUser1", uc.getLoggedUserName());\r
+       }\r
+       \r
+\r
+       @Test(expected=Exception.class)\r
+       public void getLoggedUserNameExceptionTest() throws Exception{\r
+               UserController uc = new UserController();\r
+               String currentUserName = uc.getLoggedUserName();\r
+       }\r
+       \r
+       @Test\r
+       public void getLoggedUserMailTest() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\r
+               \r
+               uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "hanfli@bfh.ch", null, null);\r
+               uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
+               uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
+               \r
+               uc.logIn("TestUser2", "pass2");\r
+               assertEquals("hanfli@bfh.ch", uc.getLoggedMail());\r
+       }\r
+       \r
+       @Test(expected=Exception.class)\r
+       public void getLoggedMailExceptionTest() throws Exception{\r
+               UserController uc = new UserController();\r
+               String currentMail = uc.getLoggedMail();\r
+       }\r
+       \r
+       @Test\r
+       public void getLoggedNameTest() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\r
+               \r
+               uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Hanfli", null);\r
+               uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
+               \r
+               uc.logIn("TestUser3", "pass3");\r
+               assertEquals("Hanfli", uc.getLoggedName());\r
+       }\r
+       \r
+       @Test(expected=Exception.class)\r
+       public void getLoggedNameExceptionTest() throws Exception{\r
+               UserController uc = new UserController();\r
+               String currentName = uc.getLoggedName();\r
+       }\r
+       \r
+       @Test\r
+       public void getLoggedLastnameTest() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\r
+               \r
+               uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
+               uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
+               \r
+               uc.logIn("TestUser4", "pass4");\r
+               assertEquals("User", uc.getLoggedLastname());\r
+       }\r
+       \r
+       @Test(expected=Exception.class)\r
+       public void getLoggedLastnameExceptionTest() throws Exception{\r
+               UserController uc = new UserController();\r
+               String currentLastName = uc.getLoggedLastname();\r
+       }\r
+       \r
+       @Test\r
+       public void logOutTest() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\r
+               \r
+               uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
+               uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
+               \r
+               uc.logIn("TestUser1", "pass1");\r
+               assertEquals("TestUser1", uc.getLoggedUserName());\r
+               uc.logOut();\r
+       }\r
+       \r
+       @Test(expected=Exception.class)\r
+       public void logOutException1Test() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\r
+               \r
+               uc.logOut();\r
+       }\r
+       \r
+       @Test(expected=Exception.class)\r
+       public void logOutException2Test() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\r
+               \r
+               uc.setDataHandler(dh);\r
+               uc.logOut();\r
+       }\r
 }\r