From: Florian Zschocke Date: Sun, 7 Aug 2022 12:09:27 +0000 (+0200) Subject: Add init test for getting repository permissions X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bf5aa7f42e22547e3ea95ece0b142ac6c9282e52;p=gitblit.git Add init test for getting repository permissions --- diff --git a/src/test/java/com/gitblit/tests/UserModelTest.java b/src/test/java/com/gitblit/tests/UserModelTest.java index 0de02d57..699de213 100644 --- a/src/test/java/com/gitblit/tests/UserModelTest.java +++ b/src/test/java/com/gitblit/tests/UserModelTest.java @@ -15,10 +15,15 @@ */ package com.gitblit.tests; +import com.gitblit.Constants; +import com.gitblit.models.RegistrantAccessPermission; +import com.gitblit.models.TeamModel; import org.junit.Test; import com.gitblit.models.UserModel; +import java.util.List; + /** * @author Alfred Schmid * @@ -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()); } + + @Test + public void getRepositoryPermissionsMultipleTeams() + { + + TeamModel aTeam = new TeamModel("A team"); + aTeam.addRepositoryPermission("RW+:acerepo.git"); + aTeam.addRepositoryPermission("V:boobrepo.git"); + + TeamModel bTeam = new TeamModel("Team B"); + bTeam.addRepositoryPermission("R:acerepo.git"); + bTeam.addRepositoryPermission("RWC:boobrepo.git"); + + UserModel user = new UserModel("tessiur"); + user.teams.add(aTeam); + user.teams.add(bTeam); + user.addRepositoryPermission("RW+:myrepo.git"); + + List repoPerms = user.getRepositoryPermissions(); + int found = 0; + for (RegistrantAccessPermission p : repoPerms) { + switch (p.registrant) { + case "acerepo.git": + assertEquals("Expected REWIND(RW+) permission for " + p.registrant, Constants.AccessPermission.REWIND, p.permission); + found++; + break; + case "boobrepo.git": + assertEquals("Expected CREATE(RWC) permission for " + p.registrant, Constants.AccessPermission.CREATE, p.permission); + found++; + break; + case "myrepo.git": + assertEquals("Expected REWIND(RW+) permission for " + p.registrant, Constants.AccessPermission.REWIND, p.permission); + found++; + break; + default: + fail("Unknown repository registrant " + p.registrant); + break; + } + } + + assertEquals("Repostory permissions missing in list.", 3, found); + + } + }