summaryrefslogtreecommitdiffstats
path: root/src/test/java/com/gitblit/tests/GitBlitTest.java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-11-17 16:15:24 -0500
committerJames Moger <james.moger@gitblit.com>2013-11-26 16:07:04 -0500
commitdb4f6b5740c6ea45d9e2209dc569bc18904a8b4d (patch)
tree8dd6c651876359ea2d66e844b77af29394f8cd1e /src/test/java/com/gitblit/tests/GitBlitTest.java
parent99d0d4fd66f3490b61c700065b7d16bc4e73f226 (diff)
downloadgitblit-db4f6b5740c6ea45d9e2209dc569bc18904a8b4d.tar.gz
gitblit-db4f6b5740c6ea45d9e2209dc569bc18904a8b4d.zip
Define manager interfaces and update all of Gitblit to use managers
These manager interfaces define how the GitBlit singleton will eventually be split into smaller component managers. The Wicket app and all servlets have been updated to request the needed managers. There are _very_ few method signature changes - although there are a handful. This is a surgical sharding of responsibility based on a proof of concept refactor. Instead of random references to GittBlit.self() there are now precise references to the manager interface required to accomplish some task. Some tasks may require references to multiple managers. The code is now littered with calls to GitBlit.getManager(class) and those familiar with the code-base will no doubt notice the duplication of methods from IUserService in IUserManager and the addition of implementation methods in the GitBlit context class. When the GitBlit class is broken apart and the existing external authentication user service classes are refactored to AuthenticationService classes, this will again simplify and flatten. But in order to safely and cleanly modularize the stable code-base we will have to live with a little duplication for a short while. Change-Id: I7314ec8acaab2dcc6092785ed4434cc09fdbbe16
Diffstat (limited to 'src/test/java/com/gitblit/tests/GitBlitTest.java')
-rw-r--r--src/test/java/com/gitblit/tests/GitBlitTest.java56
1 files changed, 25 insertions, 31 deletions
diff --git a/src/test/java/com/gitblit/tests/GitBlitTest.java b/src/test/java/com/gitblit/tests/GitBlitTest.java
index 4fb58642..692afb76 100644
--- a/src/test/java/com/gitblit/tests/GitBlitTest.java
+++ b/src/test/java/com/gitblit/tests/GitBlitTest.java
@@ -15,11 +15,6 @@
*/
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
import java.util.List;
import org.eclipse.jgit.lib.Repository;
@@ -27,48 +22,47 @@ import org.junit.Test;
import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.FileSettings;
-import com.gitblit.GitBlit;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
-public class GitBlitTest {
+public class GitBlitTest extends GitblitUnitTest {
@Test
public void testRepositoryModel() throws Exception {
- List<String> repositories = GitBlit.self().getRepositoryList();
+ List<String> repositories = repositories().getRepositoryList();
assertTrue("Repository list is empty!", repositories.size() > 0);
assertTrue(
"Missing Helloworld repository!",
repositories.contains(GitBlitSuite.getHelloworldRepository().getDirectory()
.getName()));
Repository r = GitBlitSuite.getHelloworldRepository();
- RepositoryModel model = GitBlit.self().getRepositoryModel(r.getDirectory().getName());
+ RepositoryModel model = repositories().getRepositoryModel(r.getDirectory().getName());
assertTrue("Helloworld model is null!", model != null);
assertEquals(GitBlitSuite.getHelloworldRepository().getDirectory().getName(), model.name);
- assertTrue(GitBlit.self().updateLastChangeFields(r, model) > 22000L);
+ assertTrue(repositories().updateLastChangeFields(r, model) > 22000L);
r.close();
}
@Test
public void testUserModel() throws Exception {
- List<String> users = GitBlit.self().getAllUsernames();
+ List<String> users = users().getAllUsernames();
assertTrue("No users found!", users.size() > 0);
assertTrue("Admin not found", users.contains("admin"));
- UserModel user = GitBlit.self().getUserModel("admin");
+ UserModel user = users().getUserModel("admin");
assertEquals("admin", user.toString());
assertTrue("Admin missing #admin role!", user.canAdmin);
user.canAdmin = false;
assertFalse("Admin should not have #admin!", user.canAdmin);
String repository = GitBlitSuite.getHelloworldRepository().getDirectory().getName();
- RepositoryModel repositoryModel = GitBlit.self().getRepositoryModel(repository);
+ RepositoryModel repositoryModel = repositories().getRepositoryModel(repository);
repositoryModel.accessRestriction = AccessRestrictionType.VIEW;
assertFalse("Admin can still access repository!",
user.canView(repositoryModel));
user.addRepositoryPermission(repository);
assertTrue("Admin can't access repository!", user.canView(repositoryModel));
- assertEquals(GitBlit.self().getRepositoryModel(user, "pretend"), null);
- assertNotNull(GitBlit.self().getRepositoryModel(user, repository));
- assertTrue(GitBlit.self().getRepositoryModels(user).size() > 0);
+ assertEquals(repositories().getRepositoryModel(user, "pretend"), null);
+ assertNotNull(repositories().getRepositoryModel(user, repository));
+ assertTrue(repositories().getRepositoryModels(user).size() > 0);
}
@Test
@@ -156,34 +150,34 @@ public class GitBlitTest {
@Test
public void testGitblitSettings() throws Exception {
// These are already tested by above test method.
- assertTrue(GitBlit.getBoolean("missing", true));
- assertEquals("default", GitBlit.getString("missing", "default"));
- assertEquals(10, GitBlit.getInteger("missing", 10));
- assertEquals(5, GitBlit.getInteger("realm.userService", 5));
-
- assertTrue(GitBlit.getBoolean("git.enableGitServlet", false));
- assertEquals(GitBlitSuite.USERSCONF.getAbsolutePath(), GitBlit.getString("realm.userService", null));
- assertEquals(5, GitBlit.getInteger("realm.minPasswordLength", 0));
- List<String> mdExtensions = GitBlit.getStrings("web.markdownExtensions");
+ assertTrue(settings().getBoolean("missing", true));
+ assertEquals("default", settings().getString("missing", "default"));
+ assertEquals(10, settings().getInteger("missing", 10));
+ assertEquals(5, settings().getInteger("realm.userService", 5));
+
+ assertTrue(settings().getBoolean("git.enableGitServlet", false));
+ assertEquals(GitBlitSuite.USERSCONF.getAbsolutePath(), settings().getString("realm.userService", null));
+ assertEquals(5, settings().getInteger("realm.minPasswordLength", 0));
+ List<String> mdExtensions = settings().getStrings("web.markdownExtensions");
assertTrue(mdExtensions.size() > 0);
assertTrue(mdExtensions.contains("md"));
- List<String> keys = GitBlit.getAllKeys("server");
+ List<String> keys = settings().getAllKeys("server");
assertTrue(keys.size() > 0);
assertTrue(keys.contains("server.httpsPort"));
- assertTrue(GitBlit.getChar("web.forwardSlashCharacter", ' ') == '/');
- assertFalse(GitBlit.isDebugMode());
+ assertTrue(settings().getChar("web.forwardSlashCharacter", ' ') == '/');
+ assertFalse(runtime().isDebugMode());
}
@Test
public void testAuthentication() throws Exception {
- assertTrue(GitBlit.self().authenticate("admin", "admin".toCharArray()) != null);
+ assertTrue(session().authenticate("admin", "admin".toCharArray()) != null);
}
@Test
public void testRepositories() throws Exception {
- assertTrue(GitBlit.self().getRepository("missing") == null);
- assertTrue(GitBlit.self().getRepositoryModel("missing") == null);
+ assertTrue(repositories().getRepository("missing") == null);
+ assertTrue(repositories().getRepositoryModel("missing") == null);
}
}