| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertEquals;
|
| | | import static org.junit.Assert.assertNotNull;
|
| | | import static org.junit.Assert.assertNull;
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.util.Collection;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.concurrent.atomic.AtomicBoolean;
|
| | |
|
| | | 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;
|
| | |
| | | * @author James Moger
|
| | | *
|
| | | */
|
| | | public class RpcTests extends TestCase {
|
| | | public class RpcTests {
|
| | |
|
| | | String url = "https://localhost:8443";
|
| | | String account = "admin";
|
| | | String password = "admin";
|
| | | String url = GitBlitSuite.url;
|
| | | String account = GitBlitSuite.account;
|
| | | String password = GitBlitSuite.password;
|
| | |
|
| | | private static final AtomicBoolean started = new AtomicBoolean(false);
|
| | |
|
| | | @BeforeClass
|
| | | public static void startGitblit() throws Exception {
|
| | | started.set(GitBlitSuite.startGitblit());
|
| | | }
|
| | |
|
| | | @AfterClass
|
| | | public static void stopGitblit() throws Exception {
|
| | | if (started.get()) {
|
| | | GitBlitSuite.stopGitblit();
|
| | | }
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testListRepositories() throws IOException {
|
| | | Map<String, RepositoryModel> map = RpcUtils.getRepositories(url, null, null);
|
| | | assertTrue("Repository list is null!", map != null);
|
| | | assertNotNull("Repository list is null!", map);
|
| | | assertTrue("Repository list is empty!", map.size() > 0);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testListUsers() throws IOException {
|
| | | List<UserModel> list = null;
|
| | | try {
|
| | | list = RpcUtils.getUsers(url, null, null);
|
| | | } catch (UnauthorizedException e) {
|
| | | }
|
| | | assertTrue("Server allows anyone to admin!", list == null);
|
| | | assertNull("Server allows anyone to admin!", list);
|
| | |
|
| | | list = RpcUtils.getUsers(url, "admin", "admin".toCharArray());
|
| | | assertTrue("User list is empty!", list.size() > 0);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testUserAdministration() throws IOException {
|
| | | UserModel user = new UserModel("garbage");
|
| | | user.canAdmin = true;
|
| | |
| | | RpcUtils.createUser(user, url, account, password.toCharArray()));
|
| | |
|
| | | UserModel retrievedUser = findUser(user.username);
|
| | | assertTrue("Failed to find " + user.username, retrievedUser != null);
|
| | | assertNotNull("Failed to find " + user.username, retrievedUser);
|
| | | assertTrue("Retrieved user can not administer Gitblit", retrievedUser.canAdmin);
|
| | |
|
| | | // rename and toggle admin permission
|
| | |
| | | RpcUtils.updateUser(originalName, user, url, account, password.toCharArray()));
|
| | |
|
| | | retrievedUser = findUser(user.username);
|
| | | assertTrue("Failed to find " + user.username, retrievedUser != null);
|
| | | assertNotNull("Failed to find " + user.username, retrievedUser);
|
| | | assertTrue("Retrieved user did not update", !retrievedUser.canAdmin);
|
| | |
|
| | | // delete
|
| | |
| | | RpcUtils.deleteUser(retrievedUser, url, account, password.toCharArray()));
|
| | |
|
| | | retrievedUser = findUser(user.username);
|
| | | assertTrue("Failed to delete " + user.username, retrievedUser == null);
|
| | | assertNull("Failed to delete " + user.username, retrievedUser);
|
| | | }
|
| | |
|
| | | private UserModel findUser(String name) throws IOException {
|
| | |
| | | return retrievedUser;
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testRepositoryAdministration() throws IOException {
|
| | | RepositoryModel model = new RepositoryModel();
|
| | | model.name = "garbagerepo.git";
|
| | |
| | | RpcUtils.createRepository(model, url, account, password.toCharArray()));
|
| | |
|
| | | RepositoryModel retrievedRepository = findRepository(model.name);
|
| | | assertTrue("Failed to find " + model.name, retrievedRepository != null);
|
| | | assertTrue("Access retriction type is wrong",
|
| | | AccessRestrictionType.VIEW.equals(retrievedRepository.accessRestriction));
|
| | | assertNotNull("Failed to find " + model.name, retrievedRepository);
|
| | | assertEquals(AccessRestrictionType.VIEW, retrievedRepository.accessRestriction);
|
| | |
|
| | | // rename and change access restriciton
|
| | | String originalName = model.name;
|
| | |
| | | url, account, password.toCharArray()));
|
| | |
|
| | | retrievedRepository = findRepository(model.name);
|
| | | assertTrue("Failed to find " + model.name, retrievedRepository != null);
|
| | | assertNotNull("Failed to find " + model.name, retrievedRepository);
|
| | | assertTrue("Access retriction type is wrong",
|
| | | AccessRestrictionType.PUSH.equals(retrievedRepository.accessRestriction));
|
| | |
|
| | | // memberships
|
| | | String testMember = "justadded";
|
| | | UserModel testMember = new UserModel("justadded");
|
| | | assertTrue(RpcUtils.createUser(testMember, url, account, password.toCharArray()));
|
| | |
|
| | | List<String> members = RpcUtils.getRepositoryMembers(retrievedRepository, url, account,
|
| | | password.toCharArray());
|
| | | assertTrue("Membership roster is not empty!", members.size() == 0);
|
| | | members.add(testMember);
|
| | | assertEquals("Membership roster is not empty!", 0, members.size());
|
| | | members.add(testMember.username);
|
| | | assertTrue(
|
| | | "Failed to set memberships!",
|
| | | RpcUtils.setRepositoryMembers(retrievedRepository, members, url, account,
|
| | |
| | | password.toCharArray());
|
| | | boolean foundMember = false;
|
| | | for (String member : members) {
|
| | | if (member.equalsIgnoreCase(testMember)) {
|
| | | if (member.equalsIgnoreCase(testMember.username)) {
|
| | | foundMember = true;
|
| | | break;
|
| | | }
|
| | |
| | | url, account, password.toCharArray()));
|
| | |
|
| | | retrievedRepository = findRepository(model.name);
|
| | | assertTrue("Failed to delete " + model.name, retrievedRepository == null);
|
| | | assertNull("Failed to delete " + model.name, retrievedRepository);
|
| | |
|
| | | for (UserModel u : RpcUtils.getUsers(url, account, password.toCharArray())) {
|
| | | if (u.username.equals(testMember)) {
|
| | | RpcUtils.deleteUser(u, url, account, password.toCharArray());
|
| | | if (u.username.equals(testMember.username)) {
|
| | | assertTrue(RpcUtils.deleteUser(u, url, account, password.toCharArray()));
|
| | | break;
|
| | | }
|
| | | }
|
| | |
| | | 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);
|
| | | assertNotNull("No settings were retrieved!", settings);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testServerStatus() throws Exception {
|
| | | ServerStatus status = RpcUtils.getStatus(url, account, password.toCharArray());
|
| | | assertTrue("No status was retrieved!", status != null);
|
| | | assertNotNull("No status was retrieved!", status);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testUpdateSettings() throws Exception {
|
| | | Map<String, String> updated = new HashMap<String, String>();
|
| | |
|
| | |
| | |
|
| | | // update setting
|
| | | updated.put(Keys.web.showRepositorySizes, String.valueOf(showSizes));
|
| | | boolean success = RpcUtils.updateSettings(updated, "http://localhost:8080/gb", account,
|
| | | password.toCharArray());
|
| | | boolean success = RpcUtils.updateSettings(updated, url, account, password.toCharArray());
|
| | | assertTrue("Failed to update server settings", success);
|
| | |
|
| | | // confirm setting change
|
| | |
| | | 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);
|
| | | assertNotNull(branches);
|
| | | assertTrue(branches.size() > 0);
|
| | | }
|
| | | }
|