UserTest updated
authorMichael <Michael@Michael-LT.bfh.ch>
Tue, 8 Dec 2015 11:09:55 +0000 (12:09 +0100)
committerMichael <Michael@Michael-LT.bfh.ch>
Tue, 8 Dec 2015 11:09:55 +0000 (12:09 +0100)
src/main/java/ch/bfh/ti/srs/dataschema/User.java
src/test/java/ch/bfh/ti/srs/dataschema/UserTest.java

index 1a77e06..2409875 100644 (file)
@@ -66,6 +66,7 @@ public class User implements Cloneable {
 
                this.userName = userName;
                this.hashedPassword = Password.getSaltedHash(password);
 
                this.userName = userName;
                this.hashedPassword = Password.getSaltedHash(password);
+               this.roles.add(Role.User);
        }
 
        public String getUserName() {
        }
 
        public String getUserName() {
index 51696d3..13715cf 100644 (file)
@@ -11,9 +11,10 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;\r
 import static org.junit.Assert.assertTrue;\r
 \r
 import static org.junit.Assert.assertFalse;\r
 import static org.junit.Assert.assertTrue;\r
 \r
+import java.util.Set;\r
+\r
 import org.junit.Test;\r
 \r
 import org.junit.Test;\r
 \r
-import ch.bfh.ti.srs.dataschema.User;\r
 import ch.bfh.ti.srs.extern.Password;\r
 \r
 /**\r
 import ch.bfh.ti.srs.extern.Password;\r
 \r
 /**\r
@@ -160,4 +161,38 @@ public class UserTest {
                testUser.setLastname(null);\r
                assertEquals(null, testUser.getLastname());\r
        }\r
                testUser.setLastname(null);\r
                assertEquals(null, testUser.getLastname());\r
        }\r
+       \r
+       @Test\r
+       public void RoleTest() throws Exception{\r
+               User testUser = new User("TestUser", "pass");\r
+               Set<Role> roles = testUser.getRoles();\r
+               assertTrue(roles.contains(Role.User));\r
+               assertFalse(roles.contains(Role.ResourceManager));\r
+               assertFalse(roles.contains(Role.Admin));\r
+               \r
+               testUser.addRole(Role.ResourceManager);\r
+               roles = testUser.getRoles();\r
+               assertTrue(roles.contains(Role.User));\r
+               assertTrue(roles.contains(Role.ResourceManager));\r
+               assertFalse(roles.contains(Role.Admin));\r
+               \r
+               testUser.removeRole(Role.User);\r
+               roles = testUser.getRoles();\r
+               assertFalse(roles.contains(Role.User));\r
+               assertTrue(roles.contains(Role.ResourceManager));\r
+               assertFalse(roles.contains(Role.Admin));\r
+               \r
+               testUser.removeRole(Role.Admin);\r
+               roles = testUser.getRoles();\r
+               assertFalse(roles.contains(Role.User));\r
+               assertTrue(roles.contains(Role.ResourceManager));\r
+               assertFalse(roles.contains(Role.Admin));\r
+       }\r
+       \r
+       @Test\r
+       public void cloneTest() throws Exception{\r
+               User testUser = new User("TestUser", "pass");\r
+               User clonedUser = testUser.clone();\r
+               assertEquals(testUser.getUserName(), clonedUser.getUserName());\r
+       }\r
 }\r
 }\r