| | |
| | | package com.gitblit.tests;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.util.Collection;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | |
|
| | | import org.junit.AfterClass;
|
| | | import org.junit.BeforeClass;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.GitBlitException.UnauthorizedException;
|
| | | import com.gitblit.Keys;
|
| | | 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.UserModel;
|
| | | import com.gitblit.utils.RpcUtils;
|
| | |
|
| | |
| | | *
|
| | | */
|
| | | public class RpcTests extends TestCase {
|
| | | |
| | | String url = GitBlitSuite.url;
|
| | | String account = GitBlitSuite.account;
|
| | | String password = GitBlitSuite.password;
|
| | | |
| | |
|
| | | String url = "https://localhost:8443";
|
| | | String account = "admin";
|
| | | String password = "admin";
|
| | | @BeforeClass
|
| | | public static void startGitblit() throws Exception {
|
| | | GitBlitSuite.startGitblit();
|
| | | }
|
| | |
|
| | | @AfterClass
|
| | | public static void stopGitblit() throws Exception {
|
| | | GitBlitSuite.stopGitblit();
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testListRepositories() throws IOException {
|
| | | Map<String, RepositoryModel> map = RpcUtils.getRepositories(url, null, null);
|
| | | assertTrue("Repository list is null!", map != null);
|
| | | assertTrue("Repository list is empty!", map.size() > 0);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testListUsers() throws IOException {
|
| | | List<UserModel> list = null;
|
| | | try {
|
| | |
| | | assertTrue("User list is empty!", list.size() > 0);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testUserAdministration() throws IOException {
|
| | | UserModel user = new UserModel("garbage");
|
| | | user.canAdmin = true;
|
| | |
| | | return retrievedUser;
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testRepositoryAdministration() throws IOException {
|
| | | RepositoryModel model = new RepositoryModel();
|
| | | model.name = "garbagerepo.git";
|
| | |
| | | return retrievedRepository;
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFederationRegistrations() throws Exception {
|
| | | List<FederationModel> registrations = RpcUtils.getFederationRegistrations(url, account,
|
| | | password.toCharArray());
|
| | | assertTrue("No federation registrations wre retrieved!", registrations.size() > 0);
|
| | | assertTrue("No federation registrations were retrieved!", registrations.size() >= 0);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFederationResultRegistrations() throws Exception {
|
| | | List<FederationModel> registrations = RpcUtils.getFederationResultRegistrations(url,
|
| | | account, password.toCharArray());
|
| | | assertTrue("No federation result registrations were retrieved!", registrations.size() > 0);
|
| | | assertTrue("No federation result registrations were retrieved!", registrations.size() >= 0);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFederationProposals() throws Exception {
|
| | | List<FederationProposal> proposals = RpcUtils.getFederationProposals(url, account,
|
| | | password.toCharArray());
|
| | | assertTrue("No federation proposals were retrieved!", proposals.size() > 0);
|
| | | assertTrue("No federation proposals were retrieved!", proposals.size() >= 0);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFederationSets() throws Exception {
|
| | | List<FederationSet> sets = RpcUtils.getFederationSets(url, account, password.toCharArray());
|
| | | assertTrue("No federation sets were retrieved!", sets.size() > 0);
|
| | | assertTrue("No federation sets were retrieved!", sets.size() >= 0);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testSettings() throws Exception {
|
| | | ServerSettings settings = RpcUtils.getSettings(url, account, password.toCharArray());
|
| | | assertTrue("No settings were retrieved!", settings != null);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testServerStatus() throws Exception {
|
| | | ServerStatus status = RpcUtils.getStatus(url, account, password.toCharArray());
|
| | | assertTrue("No status was retrieved!", status != null);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testUpdateSettings() throws Exception {
|
| | | Map<String, String> updated = new HashMap<String, String>();
|
| | |
|
| | | // grab current setting
|
| | | ServerSettings settings = RpcUtils.getSettings(url, account, password.toCharArray());
|
| | | boolean showSizes = settings.get(Keys.web.showRepositorySizes).getBoolean(true);
|
| | | showSizes = !showSizes;
|
| | |
|
| | | // update setting
|
| | | updated.put(Keys.web.showRepositorySizes, String.valueOf(showSizes));
|
| | | boolean success = RpcUtils.updateSettings(updated, url, account, password.toCharArray());
|
| | | assertTrue("Failed to update server settings", success);
|
| | |
|
| | | // confirm setting change
|
| | | settings = RpcUtils.getSettings(url, account, password.toCharArray());
|
| | | boolean newValue = settings.get(Keys.web.showRepositorySizes).getBoolean(false);
|
| | | assertEquals(newValue, showSizes);
|
| | |
|
| | | // restore setting
|
| | | newValue = !newValue;
|
| | | updated.put(Keys.web.showRepositorySizes, String.valueOf(newValue));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testBranches() throws Exception {
|
| | | Map<String, Collection<String>> branches = RpcUtils.getBranches(url, account,
|
| | | password.toCharArray());
|
| | | assertTrue(branches != null);
|
| | | assertTrue(branches.size() > 0);
|
| | | }
|
| | | }
|