packaging updated
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / core / 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
8package ch.bfh.ti.srs.core;\r
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
M
22public class UserTest {\r
23 //@Rule\r
24 //public ExpectedException createUserException = ExpectedException.none();\r
25 \r
26 @Test\r
27 public void createUserTest() throws Exception{\r
28 User testUser = new User("TestUser", "pass");\r
29 assertEquals("TestUser", testUser.getUserName());\r
30 \r
31 //Zweite Moeglichkeit um Exceptions zu testen, so lange keine Exception erwartet wird reicht es\r
32 //eine allfaellige mit 'throws Exception' an junit weiterzuleiten.\r
33 //--------------------------------------------------------------------------------------------\r
34 /*createUserException.expect(IllegalArgumentException.class);\r
35 createUserException.expectMessage("Invalid username");\r
36 User wrongArgumentUser1 = new User(null, "1234");\r
37 createUserException.expectMessage("Invalid password");\r
38 User wrongArgumentUser2 = new User("TestUser2", null);*/\r
39 }\r
40 \r
1f7b5004
M
41 @Test\r
42 public void createExistingTest() throws Exception{\r
43 User testUser = new User("TestUser", "pass", "grosm9@bfh.ch", "Test", "Dummy");\r
44 assertEquals("TestUser", testUser.getUserName());\r
45 assertEquals("pass", testUser.getEncryptedPassword());\r
46 assertEquals("grosm9@bfh.ch", testUser.getMail());\r
47 assertEquals("Test", testUser.getName());\r
48 assertEquals("Dummy", testUser.getLastname());\r
49 }\r
50 \r
51 @Test\r
52 public void getEncryptedPasswordTest() throws Exception{\r
53 String encryptedPass = Password.getSaltedHash("testPassword");\r
54 User testUser = new User("TestUser", encryptedPass, "grosm9@bfh.ch", "Test", "Dummy");\r
55 assertEquals(encryptedPass, testUser.getEncryptedPassword());\r
56 }\r
57 \r
ed6d035d
M
58 @Test(expected=IllegalArgumentException.class)\r
59 public void createUserInvalidUsernameTest() throws Exception{\r
60 User testUser = new User(null,"pass");\r
61 }\r
62 \r
63 @Test(expected=IllegalArgumentException.class)\r
64 public void createUserTooShortUsernameTest() throws Exception{\r
65 User testUser = new User(new String(),"pass");\r
66 User testUser2 = new User(new String("tes"),"pass");\r
67 }\r
68 \r
69 @Test(expected=IllegalArgumentException.class)\r
70 public void createUserInvalidPasswordTest() throws Exception{\r
71 User testUser = new User("TestUser", null);\r
72 }\r
73\r
74 @Test\r
75 public void checkPasswordTest() throws Exception{\r
76 User testUser = new User("TestUser", "pass");\r
77 assertTrue(testUser.checkPassword("pass"));\r
78 assertFalse(testUser.checkPassword("notmypass"));\r
79 }\r
80 \r
81 @Test(expected=IllegalArgumentException.class)\r
82 public void checkPasswordInvalidTest() throws Exception{\r
83 User testUser = new User("TestUser", "pass");\r
84 assertTrue(testUser.checkPassword(null));\r
85 }\r
86 \r
87 @Test\r
88 public void changePasswordTest() throws Exception{\r
89 User testUser = new User("TestUser", "pass");\r
90 assertTrue(testUser.checkPassword("pass"));\r
91 testUser.changePassword("newpass");\r
92 assertTrue(testUser.checkPassword("newpass"));\r
93 assertFalse(testUser.checkPassword("pass"));\r
94 assertFalse(testUser.checkPassword("notmypass"));\r
95 }\r
96 \r
97 @Test(expected=IllegalArgumentException.class)\r
98 public void changePasswordInvalid1Test() throws Exception{\r
99 User testUser = new User("TestUser", "pass");\r
100 testUser.changePassword(null);\r
101 }\r
102 \r
103 @Test(expected=IllegalArgumentException.class)\r
104 public void changePasswordInvalid2Test() throws Exception{\r
105 User testUser = new User("TestUser", "pass");\r
106 testUser.changePassword("pass");\r
107 }\r
108\r
109 @Test\r
110 public void setMailTest() throws Exception{\r
111 User testUser = new User("TestUser", "pass");\r
112 testUser.setMail("grosm9@bfh.ch");\r
113 }\r
114 \r
115 @Test(expected=IllegalArgumentException.class)\r
116 public void setMailIllegal1Test() throws Exception{\r
117 User testUser = new User("TestUser", "pass");\r
118 testUser.setMail("fda.ds");\r
119\r
120 }\r
121 \r
122 @Test(expected=IllegalArgumentException.class)\r
123 public void setMailIllegal2Test() throws Exception{\r
124 User testUser = new User("TestUser", "pass");\r
125 testUser.setMail("adfiug@fs");\r
126 }\r
127 \r
128 @Test(expected=IllegalArgumentException.class)\r
129 public void setMailIllegal3Test() throws Exception{\r
130 User testUser = new User("TestUser", "pass");\r
131 testUser.setMail(null);\r
132 }\r
133\r
134 @Test\r
135 public void getMailTest() throws Exception{\r
136 User testUser = new User("TestUser", "pass");\r
137 String mail = "grosm9@bfh.ch";\r
138\r
139 testUser.setMail(mail);\r
140 assertEquals(mail, testUser.getMail());\r
141 }\r
142\r
143 @Test\r
144 public void setAndGetNameTest() throws Exception{\r
145 User testUser = new User("TestUser", "pass");\r
146 testUser.setName("Tester");\r
147 assertEquals("Tester",testUser.getName());\r
148 testUser.setName(null);\r
149 assertEquals(null, testUser.getName());\r
150 }\r
151\r
152 @Test\r
153 public void setAndGetLastnameTest() throws Exception{\r
154 User testUser = new User("TestUser", "pass");\r
155 testUser.setLastname("Dummy");\r
156 assertEquals("Dummy", testUser.getLastname());\r
157 testUser.setLastname(null);\r
158 assertEquals(null, testUser.getLastname());\r
159 }\r
160}\r