]> source.dussan.org Git - gitblit.git/commitdiff
Add init test for getting repository permissions
authorFlorian Zschocke <f.zschocke+git@gmail.com>
Sun, 7 Aug 2022 12:09:27 +0000 (14:09 +0200)
committerFlorian Zschocke <f.zschocke+git@gmail.com>
Sun, 7 Aug 2022 12:09:27 +0000 (14:09 +0200)
src/test/java/com/gitblit/tests/UserModelTest.java

index 0de02d57f0079fe4482fa308c10e6c52de92dffd..699de21377aea41c7eb28060f9ffef8aee1245ba 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
+import com.gitblit.Constants;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
+import com.gitblit.models.TeamModel;\r
 import org.junit.Test;\r
 \r
 import com.gitblit.models.UserModel;\r
 \r
+import java.util.List;\r
+\r
 /**\r
  * @author Alfred Schmid\r
  *\r
@@ -49,4 +54,48 @@ public class UserModelTest extends GitblitUnitTest {
                assertEquals("When displayName is not empty its value has to be returnd from getDisplayName().", displayName, userModel.getDisplayName());\r
        }\r
 \r
+\r
+       @Test\r
+       public void getRepositoryPermissionsMultipleTeams()\r
+       {\r
+\r
+               TeamModel aTeam = new TeamModel("A team");\r
+               aTeam.addRepositoryPermission("RW+:acerepo.git");\r
+               aTeam.addRepositoryPermission("V:boobrepo.git");\r
+\r
+               TeamModel bTeam = new TeamModel("Team B");\r
+               bTeam.addRepositoryPermission("R:acerepo.git");\r
+               bTeam.addRepositoryPermission("RWC:boobrepo.git");\r
+\r
+               UserModel user = new UserModel("tessiur");\r
+               user.teams.add(aTeam);\r
+               user.teams.add(bTeam);\r
+               user.addRepositoryPermission("RW+:myrepo.git");\r
+\r
+               List<RegistrantAccessPermission> repoPerms = user.getRepositoryPermissions();\r
+               int found = 0;\r
+               for (RegistrantAccessPermission p : repoPerms) {\r
+                       switch (p.registrant) {\r
+                               case "acerepo.git":\r
+                                       assertEquals("Expected REWIND(RW+) permission for " + p.registrant, Constants.AccessPermission.REWIND, p.permission);\r
+                                       found++;\r
+                                       break;\r
+                               case "boobrepo.git":\r
+                                       assertEquals("Expected CREATE(RWC) permission for " + p.registrant, Constants.AccessPermission.CREATE, p.permission);\r
+                                       found++;\r
+                                       break;\r
+                               case "myrepo.git":\r
+                                       assertEquals("Expected REWIND(RW+) permission for " + p.registrant, Constants.AccessPermission.REWIND, p.permission);\r
+                                       found++;\r
+                                       break;\r
+                               default:\r
+                                       fail("Unknown repository registrant " + p.registrant);\r
+                                       break;\r
+                       }\r
+               }\r
+\r
+               assertEquals("Repostory permissions missing in list.", 3, found);\r
+\r
+       }\r
+\r
 }\r