From 4e0ee29b4d51058961ffa8bca672edcde0ee2493 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Fri, 23 Mar 2012 16:20:51 -0400 Subject: [PATCH] Update to Wicket 1.4.20 --- tests/com/gitblit/tests/RpcTests.java | 83 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 83 insertions(+), 0 deletions(-) diff --git a/tests/com/gitblit/tests/RpcTests.java b/tests/com/gitblit/tests/RpcTests.java index 30dc84d..f85dd79 100644 --- a/tests/com/gitblit/tests/RpcTests.java +++ b/tests/com/gitblit/tests/RpcTests.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -34,12 +35,14 @@ import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.GitBlitException.UnauthorizedException; import com.gitblit.Keys; +import com.gitblit.RpcServlet; import com.gitblit.models.FederationModel; import com.gitblit.models.FederationProposal; import com.gitblit.models.FederationSet; import com.gitblit.models.RepositoryModel; import com.gitblit.models.ServerSettings; import com.gitblit.models.ServerStatus; +import com.gitblit.models.TeamModel; import com.gitblit.models.UserModel; import com.gitblit.utils.RpcUtils; @@ -70,6 +73,12 @@ } @Test + public void testGetProtocolVersion() throws IOException { + int protocol = RpcUtils.getProtocolVersion(url, null, null); + assertEquals(RpcServlet.PROTOCOL_VERSION, protocol); + } + + @Test public void testListRepositories() throws IOException { Map<String, RepositoryModel> map = RpcUtils.getRepositories(url, null, null); assertNotNull("Repository list is null!", map); @@ -87,6 +96,20 @@ list = RpcUtils.getUsers(url, "admin", "admin".toCharArray()); assertTrue("User list is empty!", list.size() > 0); + } + + @Test + public void testListTeams() throws IOException { + List<TeamModel> list = null; + try { + list = RpcUtils.getTeams(url, null, null); + } catch (UnauthorizedException e) { + } + assertNull("Server allows anyone to admin!", list); + + list = RpcUtils.getTeams(url, "admin", "admin".toCharArray()); + assertTrue("Team list is empty!", list.size() > 0); + assertEquals("admins", list.get(0).name); } @Test @@ -214,6 +237,61 @@ } @Test + public void testTeamAdministration() throws IOException { + List<TeamModel> teams = RpcUtils.getTeams(url, account, password.toCharArray()); + assertEquals(1, teams.size()); + + // Create the A-Team + TeamModel aTeam = new TeamModel("A-Team"); + aTeam.users.add("admin"); + aTeam.repositories.add("helloworld.git"); + assertTrue(RpcUtils.createTeam(aTeam, url, account, password.toCharArray())); + + aTeam = null; + teams = RpcUtils.getTeams(url, account, password.toCharArray()); + assertEquals(2, teams.size()); + for (TeamModel team : teams) { + if (team.name.equals("A-Team")) { + aTeam = team; + break; + } + } + assertNotNull(aTeam); + assertTrue(aTeam.hasUser("admin")); + assertTrue(aTeam.hasRepository("helloworld.git")); + + RepositoryModel helloworld = null; + Map<String, RepositoryModel> repositories = RpcUtils.getRepositories(url, account, + password.toCharArray()); + for (RepositoryModel repository : repositories.values()) { + if (repository.name.equals("helloworld.git")) { + helloworld = repository; + break; + } + } + assertNotNull(helloworld); + + // Confirm that we have added the team + List<String> helloworldTeams = RpcUtils.getRepositoryTeams(helloworld, url, account, + password.toCharArray()); + assertEquals(1, helloworldTeams.size()); + assertTrue(helloworldTeams.contains(aTeam.name)); + + // set no teams + assertTrue(RpcUtils.setRepositoryTeams(helloworld, new ArrayList<String>(), url, account, + password.toCharArray())); + helloworldTeams = RpcUtils.getRepositoryTeams(helloworld, url, account, + password.toCharArray()); + assertEquals(0, helloworldTeams.size()); + + // delete the A-Team + assertTrue(RpcUtils.deleteTeam(aTeam, url, account, password.toCharArray())); + + teams = RpcUtils.getTeams(url, account, password.toCharArray()); + assertEquals(1, teams.size()); + } + + @Test public void testFederationRegistrations() throws Exception { List<FederationModel> registrations = RpcUtils.getFederationRegistrations(url, account, password.toCharArray()); @@ -274,6 +352,11 @@ // restore setting newValue = !newValue; updated.put(Keys.web.showRepositorySizes, String.valueOf(newValue)); + success = RpcUtils.updateSettings(updated, url, account, password.toCharArray()); + assertTrue("Failed to update server settings", success); + settings = RpcUtils.getSettings(url, account, password.toCharArray()); + showSizes = settings.get(Keys.web.showRepositorySizes).getBoolean(true); + assertEquals(newValue, showSizes); } @Test -- Gitblit v1.9.1