From e23cd08c09ac25b671edd07895596b2ad274e5d7 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Fri, 12 Oct 2012 18:04:17 -0400
Subject: [PATCH] Added an IntelliJ module file for fun
---
tests/com/gitblit/tests/RpcTests.java | 86 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 86 insertions(+), 0 deletions(-)
diff --git a/tests/com/gitblit/tests/RpcTests.java b/tests/com/gitblit/tests/RpcTests.java
index 30dc84d..3ad0ec5 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;
@@ -32,14 +33,17 @@
import org.junit.Test;
import com.gitblit.Constants.AccessRestrictionType;
+import com.gitblit.Constants.AuthorizationControl;
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 +74,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 +97,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
@@ -141,6 +165,7 @@
model.description = "created by RpcUtils";
model.owner = "garbage";
model.accessRestriction = AccessRestrictionType.VIEW;
+ model.authorizationControl = AuthorizationControl.AUTHENTICATED;
// create
assertTrue("Failed to create repository!",
@@ -149,6 +174,7 @@
RepositoryModel retrievedRepository = findRepository(model.name);
assertNotNull("Failed to find " + model.name, retrievedRepository);
assertEquals(AccessRestrictionType.VIEW, retrievedRepository.accessRestriction);
+ assertEquals(AuthorizationControl.AUTHENTICATED, retrievedRepository.authorizationControl);
// rename and change access restriciton
String originalName = model.name;
@@ -214,6 +240,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.addRepositoryPermission("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.hasRepositoryPermission("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 +355,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