removed all checkstyle errors, updated sprint backlog
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / dataschema / UserTest.java
CommitLineData
ed6d035d
M
1/*\r
2 * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
3 *\r
4 * Project Smart Reservation System.\r
5 *\r
6 * Distributable under GPL license. See terms of license at gnu.org.\r
7 */\r
496127a5 8package ch.bfh.ti.srs.dataschema;\r
ed6d035d
M
9\r
10import static org.junit.Assert.assertEquals;\r
11import static org.junit.Assert.assertFalse;\r
12import static org.junit.Assert.assertTrue;\r
13\r
ed6d035d 14import org.junit.Test;\r
5c0ee08b
M
15\r
16import ch.bfh.ti.srs.dataschema.User;\r
1f7b5004
M
17import ch.bfh.ti.srs.extern.Password;\r
18\r
1ec0e01f
M
19/**\r
20 * @author Michael Grossen\r
21 */\r
ed6d035d 22public class UserTest {\r
66cc653d
D
23 // @Rule\r
24 // public ExpectedException createUserException = ExpectedException.none();\r
25\r
ed6d035d 26 @Test\r
66cc653d 27 public void createUserTest() throws Exception {\r
ed6d035d
M
28 User testUser = new User("TestUser", "pass");\r
29 assertEquals("TestUser", testUser.getUserName());\r
66cc653d
D
30\r
31 // Zweite Moeglichkeit um Exceptions zu testen, so lange keine Exception\r
32 // erwartet wird reicht es\r
33 // eine allfaellige mit 'throws Exception' an junit weiterzuleiten.\r
34 // --------------------------------------------------------------------------------------------\r
35 /*\r
36 * createUserException.expect(IllegalArgumentException.class);\r
37 * createUserException.expectMessage("Invalid username"); User\r
38 * wrongArgumentUser1 = new User(null, "1234");\r
39 * createUserException.expectMessage("Invalid password"); User\r
40 * wrongArgumentUser2 = new User("TestUser2", null);\r
41 */\r
42 }\r
43\r
1f7b5004 44 @Test\r
66cc653d 45 public void createExistingTest() throws Exception {\r
1f7b5004
M
46 User testUser = new User("TestUser", "pass", "grosm9@bfh.ch", "Test", "Dummy");\r
47 assertEquals("TestUser", testUser.getUserName());\r
48 assertEquals("pass", testUser.getEncryptedPassword());\r
49 assertEquals("grosm9@bfh.ch", testUser.getMail());\r
50 assertEquals("Test", testUser.getName());\r
51 assertEquals("Dummy", testUser.getLastname());\r
52 }\r
66cc653d 53\r
1f7b5004 54 @Test\r
66cc653d 55 public void getEncryptedPasswordTest() throws Exception {\r
1f7b5004
M
56 String encryptedPass = Password.getSaltedHash("testPassword");\r
57 User testUser = new User("TestUser", encryptedPass, "grosm9@bfh.ch", "Test", "Dummy");\r
58 assertEquals(encryptedPass, testUser.getEncryptedPassword());\r
59 }\r
66cc653d
D
60\r
61 @Test(expected = IllegalArgumentException.class)\r
62 public void createUserInvalidUsernameTest() throws Exception {\r
63 User testUser = new User(null, "pass");\r
ed6d035d 64 }\r
66cc653d
D
65\r
66 @Test(expected = IllegalArgumentException.class)\r
67 public void createUserTooShortUsernameTest() throws Exception {\r
68 User testUser = new User(new String(), "pass");\r
69 User testUser2 = new User(new String("tes"), "pass");\r
ed6d035d 70 }\r
66cc653d
D
71\r
72 @Test(expected = IllegalArgumentException.class)\r
73 public void createUserInvalidPasswordTest() throws Exception {\r
ed6d035d
M
74 User testUser = new User("TestUser", null);\r
75 }\r
76\r
77 @Test\r
66cc653d 78 public void checkPasswordTest() throws Exception {\r
ed6d035d
M
79 User testUser = new User("TestUser", "pass");\r
80 assertTrue(testUser.checkPassword("pass"));\r
81 assertFalse(testUser.checkPassword("notmypass"));\r
82 }\r
66cc653d
D
83\r
84 @Test(expected = IllegalArgumentException.class)\r
85 public void checkPasswordInvalidTest() throws Exception {\r
ed6d035d
M
86 User testUser = new User("TestUser", "pass");\r
87 assertTrue(testUser.checkPassword(null));\r
88 }\r
66cc653d 89\r
ed6d035d 90 @Test\r
66cc653d 91 public void changePasswordTest() throws Exception {\r
ed6d035d
M
92 User testUser = new User("TestUser", "pass");\r
93 assertTrue(testUser.checkPassword("pass"));\r
94 testUser.changePassword("newpass");\r
95 assertTrue(testUser.checkPassword("newpass"));\r
96 assertFalse(testUser.checkPassword("pass"));\r
97 assertFalse(testUser.checkPassword("notmypass"));\r
98 }\r
66cc653d
D
99\r
100 @Test(expected = IllegalArgumentException.class)\r
101 public void changePasswordInvalid1Test() throws Exception {\r
ed6d035d
M
102 User testUser = new User("TestUser", "pass");\r
103 testUser.changePassword(null);\r
104 }\r
66cc653d
D
105\r
106 @Test(expected = IllegalArgumentException.class)\r
107 public void changePasswordInvalid2Test() throws Exception {\r
ed6d035d
M
108 User testUser = new User("TestUser", "pass");\r
109 testUser.changePassword("pass");\r
110 }\r
111\r
112 @Test\r
66cc653d 113 public void setMailTest() throws Exception {\r
ed6d035d
M
114 User testUser = new User("TestUser", "pass");\r
115 testUser.setMail("grosm9@bfh.ch");\r
116 }\r
66cc653d
D
117\r
118 @Test(expected = IllegalArgumentException.class)\r
119 public void setMailIllegal1Test() throws Exception {\r
ed6d035d
M
120 User testUser = new User("TestUser", "pass");\r
121 testUser.setMail("fda.ds");\r
122\r
123 }\r
66cc653d
D
124\r
125 @Test(expected = IllegalArgumentException.class)\r
126 public void setMailIllegal2Test() throws Exception {\r
ed6d035d
M
127 User testUser = new User("TestUser", "pass");\r
128 testUser.setMail("adfiug@fs");\r
129 }\r
66cc653d
D
130\r
131 @Test(expected = IllegalArgumentException.class)\r
132 public void setMailIllegal3Test() throws Exception {\r
ed6d035d
M
133 User testUser = new User("TestUser", "pass");\r
134 testUser.setMail(null);\r
135 }\r
136\r
137 @Test\r
66cc653d 138 public void getMailTest() throws Exception {\r
ed6d035d
M
139 User testUser = new User("TestUser", "pass");\r
140 String mail = "grosm9@bfh.ch";\r
141\r
142 testUser.setMail(mail);\r
143 assertEquals(mail, testUser.getMail());\r
144 }\r
145\r
146 @Test\r
66cc653d 147 public void setAndGetNameTest() throws Exception {\r
ed6d035d
M
148 User testUser = new User("TestUser", "pass");\r
149 testUser.setName("Tester");\r
66cc653d 150 assertEquals("Tester", testUser.getName());\r
ed6d035d
M
151 testUser.setName(null);\r
152 assertEquals(null, testUser.getName());\r
153 }\r
154\r
155 @Test\r
66cc653d 156 public void setAndGetLastnameTest() throws Exception {\r
ed6d035d
M
157 User testUser = new User("TestUser", "pass");\r
158 testUser.setLastname("Dummy");\r
159 assertEquals("Dummy", testUser.getLastname());\r
160 testUser.setLastname(null);\r
161 assertEquals(null, testUser.getLastname());\r
162 }\r
163}\r