diff options
author | James Moger <james.moger@gitblit.com> | 2013-11-17 16:15:24 -0500 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2013-11-26 16:07:04 -0500 |
commit | db4f6b5740c6ea45d9e2209dc569bc18904a8b4d (patch) | |
tree | 8dd6c651876359ea2d66e844b77af29394f8cd1e /src/test/java | |
parent | 99d0d4fd66f3490b61c700065b7d16bc4e73f226 (diff) | |
download | gitblit-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')
40 files changed, 193 insertions, 233 deletions
diff --git a/src/test/java/com/gitblit/tests/ActivityTest.java b/src/test/java/com/gitblit/tests/ActivityTest.java index 3c8d9902..b7382b87 100644 --- a/src/test/java/com/gitblit/tests/ActivityTest.java +++ b/src/test/java/com/gitblit/tests/ActivityTest.java @@ -15,8 +15,6 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-
import java.io.IOException;
import org.junit.Test;
@@ -24,7 +22,7 @@ import org.junit.Test; import com.gitblit.models.GravatarProfile;
import com.gitblit.utils.ActivityUtils;
-public class ActivityTest {
+public class ActivityTest extends GitblitUnitTest {
@Test
public void testGravatarProfile() throws IOException {
diff --git a/src/test/java/com/gitblit/tests/ArrayUtilsTest.java b/src/test/java/com/gitblit/tests/ArrayUtilsTest.java index 45964a18..93089782 100644 --- a/src/test/java/com/gitblit/tests/ArrayUtilsTest.java +++ b/src/test/java/com/gitblit/tests/ArrayUtilsTest.java @@ -15,9 +15,6 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -28,7 +25,7 @@ import org.junit.Test; import com.gitblit.utils.ArrayUtils;
-public class ArrayUtilsTest {
+public class ArrayUtilsTest extends GitblitUnitTest {
@Test
public void testArrays() {
diff --git a/src/test/java/com/gitblit/tests/Base64Test.java b/src/test/java/com/gitblit/tests/Base64Test.java index 2962c36f..16ca2adb 100644 --- a/src/test/java/com/gitblit/tests/Base64Test.java +++ b/src/test/java/com/gitblit/tests/Base64Test.java @@ -15,13 +15,11 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-
import org.junit.Test;
import com.gitblit.utils.Base64;
-public class Base64Test {
+public class Base64Test extends GitblitUnitTest {
@Test
public void testBase64() {
diff --git a/src/test/java/com/gitblit/tests/ByteFormatTest.java b/src/test/java/com/gitblit/tests/ByteFormatTest.java index ec3b395e..a6a98708 100644 --- a/src/test/java/com/gitblit/tests/ByteFormatTest.java +++ b/src/test/java/com/gitblit/tests/ByteFormatTest.java @@ -15,15 +15,13 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-
import java.util.Locale;
import org.junit.Test;
import com.gitblit.utils.ByteFormat;
-public class ByteFormatTest {
+public class ByteFormatTest extends GitblitUnitTest {
@Test
public void testByteFormat() throws Exception {
diff --git a/src/test/java/com/gitblit/tests/DiffUtilsTest.java b/src/test/java/com/gitblit/tests/DiffUtilsTest.java index 48cd19f8..9d627b80 100644 --- a/src/test/java/com/gitblit/tests/DiffUtilsTest.java +++ b/src/test/java/com/gitblit/tests/DiffUtilsTest.java @@ -15,9 +15,6 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import java.util.List;
import org.eclipse.jgit.lib.Repository;
@@ -29,7 +26,7 @@ import com.gitblit.utils.DiffUtils; import com.gitblit.utils.DiffUtils.DiffOutputType;
import com.gitblit.utils.JGitUtils;
-public class DiffUtilsTest {
+public class DiffUtilsTest extends GitblitUnitTest {
@Test
public void testDiffOutputTypes() throws Exception {
diff --git a/src/test/java/com/gitblit/tests/FanoutServiceTest.java b/src/test/java/com/gitblit/tests/FanoutServiceTest.java index 056a6c34..5ee0ac93 100644 --- a/src/test/java/com/gitblit/tests/FanoutServiceTest.java +++ b/src/test/java/com/gitblit/tests/FanoutServiceTest.java @@ -15,8 +15,6 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-
import java.text.MessageFormat;
import java.util.Date;
import java.util.Map;
@@ -31,7 +29,7 @@ import com.gitblit.fanout.FanoutNioService; import com.gitblit.fanout.FanoutService;
import com.gitblit.fanout.FanoutSocketService;
-public class FanoutServiceTest {
+public class FanoutServiceTest extends GitblitUnitTest {
int fanoutPort = FanoutService.DEFAULT_PORT;
diff --git a/src/test/java/com/gitblit/tests/FederationTests.java b/src/test/java/com/gitblit/tests/FederationTests.java index 688ae289..144fe3da 100644 --- a/src/test/java/com/gitblit/tests/FederationTests.java +++ b/src/test/java/com/gitblit/tests/FederationTests.java @@ -15,10 +15,6 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -42,7 +38,7 @@ import com.gitblit.utils.FederationUtils; import com.gitblit.utils.JsonUtils;
import com.gitblit.utils.RpcUtils;
-public class FederationTests {
+public class FederationTests extends GitblitUnitTest {
String url = GitBlitSuite.url;
String account = GitBlitSuite.account;
diff --git a/src/test/java/com/gitblit/tests/FileUtilsTest.java b/src/test/java/com/gitblit/tests/FileUtilsTest.java index f345690c..fd970844 100644 --- a/src/test/java/com/gitblit/tests/FileUtilsTest.java +++ b/src/test/java/com/gitblit/tests/FileUtilsTest.java @@ -15,16 +15,13 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import java.io.File;
import org.junit.Test;
import com.gitblit.utils.FileUtils;
-public class FileUtilsTest {
+public class FileUtilsTest extends GitblitUnitTest {
@Test
public void testReadContent() throws Exception {
diff --git a/src/test/java/com/gitblit/tests/GitBlitSuite.java b/src/test/java/com/gitblit/tests/GitBlitSuite.java index 96787fdf..f623032c 100644 --- a/src/test/java/com/gitblit/tests/GitBlitSuite.java +++ b/src/test/java/com/gitblit/tests/GitBlitSuite.java @@ -36,6 +36,7 @@ import org.junit.runners.Suite.SuiteClasses; import com.gitblit.GitBlit;
import com.gitblit.GitBlitException;
import com.gitblit.GitBlitServer;
+import com.gitblit.manager.IRepositoryManager;
import com.gitblit.models.RepositoryModel;
import com.gitblit.utils.JGitUtils;
@@ -179,9 +180,10 @@ public class GitBlitSuite { private static void showRemoteBranches(String repositoryName) {
try {
- RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
+ RepositoryModel model = repositoryManager.getRepositoryModel(repositoryName);
model.showRemoteBranches = true;
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositoryManager.updateRepositoryModel(model.name, model, false);
} catch (GitBlitException g) {
g.printStackTrace();
}
@@ -189,9 +191,10 @@ public class GitBlitSuite { private static void automaticallyTagBranchTips(String repositoryName) {
try {
- RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
+ IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
+ RepositoryModel model = repositoryManager.getRepositoryModel(repositoryName);
model.useIncrementalPushTags = true;
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositoryManager.updateRepositoryModel(model.name, model, false);
} catch (GitBlitException g) {
g.printStackTrace();
}
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);
}
}
diff --git a/src/test/java/com/gitblit/tests/GitDaemonStopTest.java b/src/test/java/com/gitblit/tests/GitDaemonStopTest.java index 7febc7a1..6e940cbe 100644 --- a/src/test/java/com/gitblit/tests/GitDaemonStopTest.java +++ b/src/test/java/com/gitblit/tests/GitDaemonStopTest.java @@ -15,12 +15,11 @@ */ package com.gitblit.tests; -import org.junit.Assert; import org.junit.Test; import com.gitblit.git.GitDaemon; -public class GitDaemonStopTest extends Assert { +public class GitDaemonStopTest extends GitblitUnitTest { @Test public void testGitDaemonStop() throws Exception { diff --git a/src/test/java/com/gitblit/tests/GitDaemonTest.java b/src/test/java/com/gitblit/tests/GitDaemonTest.java index a283e6b0..74af251f 100644 --- a/src/test/java/com/gitblit/tests/GitDaemonTest.java +++ b/src/test/java/com/gitblit/tests/GitDaemonTest.java @@ -31,16 +31,14 @@ import org.eclipse.jgit.transport.RemoteRefUpdate; import org.eclipse.jgit.transport.RemoteRefUpdate.Status; import org.eclipse.jgit.util.FileUtils; import org.junit.AfterClass; -import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.Constants.AuthorizationControl; -import com.gitblit.GitBlit; import com.gitblit.models.RepositoryModel; -public class GitDaemonTest extends Assert { +public class GitDaemonTest extends GitblitUnitTest { static File ticgitFolder = new File(GitBlitSuite.REPOSITORIES, "working/ticgit"); @@ -94,10 +92,10 @@ public class GitDaemonTest extends Assert { } // set push restriction - RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git"); + RepositoryModel model = repositories().getRepositoryModel("ticgit.git"); model.accessRestriction = AccessRestrictionType.PUSH; model.authorizationControl = AuthorizationControl.NAMED; - GitBlit.self().updateRepositoryModel(model.name, model, false); + repositories().updateRepositoryModel(model.name, model, false); CloneCommand clone = Git.cloneRepository(); clone.setURI(MessageFormat.format("{0}/ticgit.git", url)); @@ -110,7 +108,7 @@ public class GitDaemonTest extends Assert { // restore anonymous repository access model.accessRestriction = AccessRestrictionType.NONE; model.authorizationControl = AuthorizationControl.NAMED; - GitBlit.self().updateRepositoryModel(model.name, model, false); + repositories().updateRepositoryModel(model.name, model, false); } @Test @@ -121,10 +119,10 @@ public class GitDaemonTest extends Assert { } // restrict repository access - RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git"); + RepositoryModel model = repositories().getRepositoryModel("ticgit.git"); model.accessRestriction = AccessRestrictionType.CLONE; model.authorizationControl = AuthorizationControl.NAMED; - GitBlit.self().updateRepositoryModel(model.name, model, false); + repositories().updateRepositoryModel(model.name, model, false); // delete any existing working folder boolean cloned = false; @@ -147,7 +145,7 @@ public class GitDaemonTest extends Assert { // restore anonymous repository access model.accessRestriction = AccessRestrictionType.NONE; model.authorizationControl = AuthorizationControl.NAMED; - GitBlit.self().updateRepositoryModel(model.name, model, false); + repositories().updateRepositoryModel(model.name, model, false); } @Test @@ -158,10 +156,10 @@ public class GitDaemonTest extends Assert { } // restore anonymous repository access - RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git"); + RepositoryModel model = repositories().getRepositoryModel("ticgit.git"); model.accessRestriction = AccessRestrictionType.NONE; model.authorizationControl = AuthorizationControl.NAMED; - GitBlit.self().updateRepositoryModel(model.name, model, false); + repositories().updateRepositoryModel(model.name, model, false); CloneCommand clone = Git.cloneRepository(); clone.setURI(MessageFormat.format("{0}/ticgit.git", url)); @@ -196,10 +194,10 @@ public class GitDaemonTest extends Assert { } // restore anonymous repository access - RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git"); + RepositoryModel model = repositories().getRepositoryModel("ticgit.git"); model.accessRestriction = AccessRestrictionType.PUSH; model.authorizationControl = AuthorizationControl.NAMED; - GitBlit.self().updateRepositoryModel(model.name, model, false); + repositories().updateRepositoryModel(model.name, model, false); CloneCommand clone = Git.cloneRepository(); clone.setURI(MessageFormat.format("{0}/ticgit.git", url)); @@ -242,9 +240,9 @@ public class GitDaemonTest extends Assert { assertTrue(true); // freeze repo - RepositoryModel model = GitBlit.self().getRepositoryModel("test/jgit.git"); + RepositoryModel model = repositories().getRepositoryModel("test/jgit.git"); model.isFrozen = true; - GitBlit.self().updateRepositoryModel(model.name, model, false); + repositories().updateRepositoryModel(model.name, model, false); Git git = Git.open(jgitFolder); File file = new File(jgitFolder, "TODO"); @@ -264,7 +262,7 @@ public class GitDaemonTest extends Assert { // unfreeze repo model.isFrozen = false; - GitBlit.self().updateRepositoryModel(model.name, model, false); + repositories().updateRepositoryModel(model.name, model, false); results = git.push().setPushAll().call(); GitBlitSuite.close(git); diff --git a/src/test/java/com/gitblit/tests/GitServletTest.java b/src/test/java/com/gitblit/tests/GitServletTest.java index 08c4a234..b197a915 100644 --- a/src/test/java/com/gitblit/tests/GitServletTest.java +++ b/src/test/java/com/gitblit/tests/GitServletTest.java @@ -15,10 +15,6 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
@@ -53,7 +49,6 @@ import org.junit.Test; import com.gitblit.Constants.AccessPermission;
import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.Constants.AuthorizationControl;
-import com.gitblit.GitBlit;
import com.gitblit.Keys;
import com.gitblit.models.RefLogEntry;
import com.gitblit.models.RepositoryModel;
@@ -62,7 +57,7 @@ import com.gitblit.utils.ArrayUtils; import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.RefLogUtils;
-public class GitServletTest {
+public class GitServletTest extends GitblitUnitTest {
static File ticgitFolder = new File(GitBlitSuite.REPOSITORIES, "working/ticgit");
@@ -87,8 +82,8 @@ public class GitServletTest { }
private static void delete(UserModel user) {
- if (GitBlit.self().getUserModel(user.username) != null) {
- GitBlit.self().deleteUser(user.username);
+ if (users().getUserModel(user.username) != null) {
+ users().deleteUser(user.username);
}
}
@@ -148,9 +143,9 @@ public class GitServletTest { @Test
public void testBogusLoginClone() throws Exception {
// restrict repository access
- RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
+ RepositoryModel model = repositories().getRepositoryModel("ticgit.git");
model.accessRestriction = AccessRestrictionType.CLONE;
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositories().updateRepositoryModel(model.name, model, false);
// delete any existing working folder
boolean cloned = false;
@@ -169,7 +164,7 @@ public class GitServletTest { // restore anonymous repository access
model.accessRestriction = AccessRestrictionType.NONE;
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositories().updateRepositoryModel(model.name, model, false);
assertFalse("Bogus login cloned a repository?!", cloned);
}
@@ -177,13 +172,13 @@ public class GitServletTest { @Test
public void testUnauthorizedLoginClone() throws Exception {
// restrict repository access
- RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
+ RepositoryModel model = repositories().getRepositoryModel("ticgit.git");
model.accessRestriction = AccessRestrictionType.CLONE;
model.authorizationControl = AuthorizationControl.NAMED;
UserModel user = new UserModel("james");
user.password = "james";
- GitBlit.self().updateUserModel(user.username, user, true);
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ gitblit().updateUserModel(user.username, user, true);
+ repositories().updateRepositoryModel(model.name, model, false);
FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE);
@@ -208,7 +203,7 @@ public class GitServletTest { // switch to authenticated
model.authorizationControl = AuthorizationControl.AUTHENTICATED;
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositories().updateRepositoryModel(model.name, model, false);
// try clone again
cloned = false;
@@ -228,7 +223,7 @@ public class GitServletTest { // restore anonymous repository access
model.accessRestriction = AccessRestrictionType.NONE;
model.authorizationControl = AuthorizationControl.NAMED;
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositories().updateRepositoryModel(model.name, model, false);
delete(user);
}
@@ -240,9 +235,9 @@ public class GitServletTest { FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);
}
- RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
+ RepositoryModel model = repositories().getRepositoryModel("ticgit.git");
model.accessRestriction = AccessRestrictionType.NONE;
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositories().updateRepositoryModel(model.name, model, false);
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
@@ -320,9 +315,9 @@ public class GitServletTest { assertTrue(true);
// freeze repo
- RepositoryModel model = GitBlit.self().getRepositoryModel("test/jgit.git");
+ RepositoryModel model = repositories().getRepositoryModel("test/jgit.git");
model.isFrozen = true;
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositories().updateRepositoryModel(model.name, model, false);
Git git = Git.open(jgitFolder);
File file = new File(jgitFolder, "TODO");
@@ -342,7 +337,7 @@ public class GitServletTest { // unfreeze repo
model.isFrozen = false;
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ repositories().updateRepositoryModel(model.name, model, false);
results = git.push().setPushAll().setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password)).call();
GitBlitSuite.close(git);
@@ -428,7 +423,7 @@ public class GitServletTest { GitBlitSuite.close(clone.call());
// require push permissions and committer verification
- RepositoryModel model = GitBlit.self().getRepositoryModel("refchecks/verify-committer.git");
+ RepositoryModel model = repositories().getRepositoryModel("refchecks/verify-committer.git");
model.authorizationControl = AuthorizationControl.NAMED;
model.accessRestriction = AccessRestrictionType.PUSH;
model.verifyCommitter = true;
@@ -436,8 +431,8 @@ public class GitServletTest { // grant user push permission
user.setRepositoryPermission(model.name, AccessPermission.PUSH);
- GitBlit.self().updateUserModel(user.username, user, true);
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ gitblit().updateUserModel(user.username, user, true);
+ repositories().updateRepositoryModel(model.name, model, false);
// clone temp bare repo to working copy
File local = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-wc");
@@ -513,7 +508,7 @@ public class GitServletTest { GitBlitSuite.close(clone.call());
// require push permissions and committer verification
- RepositoryModel model = GitBlit.self().getRepositoryModel("refchecks/verify-committer.git");
+ RepositoryModel model = repositories().getRepositoryModel("refchecks/verify-committer.git");
model.authorizationControl = AuthorizationControl.NAMED;
model.accessRestriction = AccessRestrictionType.PUSH;
model.verifyCommitter = true;
@@ -521,8 +516,8 @@ public class GitServletTest { // grant user push permission
user.setRepositoryPermission(model.name, AccessPermission.PUSH);
- GitBlit.self().updateUserModel(user.username, user, true);
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ gitblit().updateUserModel(user.username, user, true);
+ repositories().updateRepositoryModel(model.name, model, false);
// clone temp bare repo to working copy
File local = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-wc");
@@ -648,7 +643,7 @@ public class GitServletTest { GitBlitSuite.close(clone.call());
// elevate repository to clone permission
- RepositoryModel model = GitBlit.self().getRepositoryModel("refchecks/ticgit.git");
+ RepositoryModel model = repositories().getRepositoryModel("refchecks/ticgit.git");
switch (permission) {
case VIEW:
model.accessRestriction = AccessRestrictionType.CLONE;
@@ -664,8 +659,8 @@ public class GitServletTest { // grant user specified
user.setRepositoryPermission(model.name, permission);
- GitBlit.self().updateUserModel(user.username, user, true);
- GitBlit.self().updateRepositoryModel(model.name, model, false);
+ gitblit().updateUserModel(user.username, user, true);
+ repositories().updateRepositoryModel(model.name, model, false);
// clone temp bare repo to working copy
File local = new File(GitBlitSuite.REPOSITORIES, "refchecks/ticgit-wc");
@@ -834,7 +829,7 @@ public class GitServletTest { user.canCreate = canCreate;
user.canAdmin = canAdmin;
- GitBlit.self().updateUserModel(user.username, user, true);
+ gitblit().updateUserModel(user.username, user, true);
CredentialsProvider cp = new UsernamePasswordCredentialsProvider(user.username, user.password);
@@ -885,7 +880,7 @@ public class GitServletTest { assertTrue("User canAdmin:" + user.canAdmin + " canCreate:" + user.canCreate, user.canAdmin || user.canCreate);
// confirm default personal repository permissions
- RepositoryModel model = GitBlit.self().getRepositoryModel(MessageFormat.format("~{0}/ticgit.git", user.username));
+ RepositoryModel model = repositories().getRepositoryModel(MessageFormat.format("~{0}/ticgit.git", user.username));
assertEquals("Unexpected owner", user.username, ArrayUtils.toString(model.owners));
assertEquals("Unexpected authorization control", AuthorizationControl.NAMED, model.authorizationControl);
assertEquals("Unexpected access restriction", AccessRestrictionType.VIEW, model.accessRestriction);
@@ -909,10 +904,10 @@ public class GitServletTest { assertTrue("User canAdmin:" + user.canAdmin, user.canAdmin);
// confirm default project repository permissions
- RepositoryModel model = GitBlit.self().getRepositoryModel("project/ticgit.git");
+ RepositoryModel model = repositories().getRepositoryModel("project/ticgit.git");
assertEquals("Unexpected owner", user.username, ArrayUtils.toString(model.owners));
- assertEquals("Unexpected authorization control", AuthorizationControl.fromName(GitBlit.getString(Keys.git.defaultAuthorizationControl, "NAMED")), model.authorizationControl);
- assertEquals("Unexpected access restriction", AccessRestrictionType.fromName(GitBlit.getString(Keys.git.defaultAccessRestriction, "NONE")), model.accessRestriction);
+ assertEquals("Unexpected authorization control", AuthorizationControl.fromName(settings().getString(Keys.git.defaultAuthorizationControl, "NAMED")), model.authorizationControl);
+ assertEquals("Unexpected access restriction", AccessRestrictionType.fromName(settings().getString(Keys.git.defaultAccessRestriction, "NONE")), model.accessRestriction);
} catch (GitAPIException e) {
assertTrue(e.getMessage(), e.getMessage().contains("git-receive-pack not found"));
diff --git a/src/test/java/com/gitblit/tests/GitblitUnitTest.java b/src/test/java/com/gitblit/tests/GitblitUnitTest.java new file mode 100644 index 00000000..fc70e107 --- /dev/null +++ b/src/test/java/com/gitblit/tests/GitblitUnitTest.java @@ -0,0 +1,67 @@ +/* + * Copyright 2013 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.tests; + +import com.gitblit.GitBlit; +import com.gitblit.IStoredSettings; +import com.gitblit.manager.IFederationManager; +import com.gitblit.manager.IGitblitManager; +import com.gitblit.manager.INotificationManager; +import com.gitblit.manager.IProjectManager; +import com.gitblit.manager.IRepositoryManager; +import com.gitblit.manager.IRuntimeManager; +import com.gitblit.manager.ISessionManager; +import com.gitblit.manager.IUserManager; + + +public class GitblitUnitTest extends org.junit.Assert { + + public static IStoredSettings settings() { + return runtime().getSettings(); + } + + public static IRuntimeManager runtime() { + return GitBlit.getManager(IRuntimeManager.class); + } + + public static INotificationManager notifier() { + return GitBlit.getManager(INotificationManager.class); + } + + public static IUserManager users() { + return GitBlit.getManager(IUserManager.class); + } + + public static ISessionManager session() { + return GitBlit.getManager(ISessionManager.class); + } + + public static IRepositoryManager repositories() { + return GitBlit.getManager(IRepositoryManager.class); + } + + public static IProjectManager projects() { + return GitBlit.getManager(IProjectManager.class); + } + + public static IFederationManager federation() { + return GitBlit.getManager(IFederationManager.class); + } + + public static IGitblitManager gitblit() { + return GitBlit.getManager(IGitblitManager.class); + } +} diff --git a/src/test/java/com/gitblit/tests/GroovyScriptTest.java b/src/test/java/com/gitblit/tests/GroovyScriptTest.java index 2aa881f8..1b5b0f39 100644 --- a/src/test/java/com/gitblit/tests/GroovyScriptTest.java +++ b/src/test/java/com/gitblit/tests/GroovyScriptTest.java @@ -15,8 +15,6 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import groovy.lang.Binding;
import groovy.util.GroovyScriptEngine;
@@ -41,7 +39,6 @@ import org.junit.AfterClass; import org.junit.BeforeClass;
import org.junit.Test;
-import com.gitblit.GitBlit;
import com.gitblit.GitBlitException;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.TeamModel;
@@ -54,7 +51,7 @@ import com.gitblit.utils.StringUtils; * @author James Moger
*
*/
-public class GroovyScriptTest {
+public class GroovyScriptTest extends GitblitUnitTest {
private static final AtomicBoolean started = new AtomicBoolean(false);
@@ -83,7 +80,7 @@ public class GroovyScriptTest { .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));
- RepositoryModel repository = GitBlit.self().getRepositoryModel("helloworld.git");
+ RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");
repository.customFields = new HashMap<String,String>();
repository.customFields.put( "fogbugzUrl", "http://bugs.test.com" );
repository.customFields.put( "fogbugzRepositoryId", "1" );
@@ -105,7 +102,7 @@ public class GroovyScriptTest { .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));
- RepositoryModel repository = GitBlit.self().getRepositoryModel("helloworld.git");
+ RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");
repository.mailingLists.add("list@helloworld.git");
test("sendmail-html.groovy", gitblit, logger, clientLogger, commands, repository);
@@ -130,7 +127,7 @@ public class GroovyScriptTest { .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));
- RepositoryModel repository = GitBlit.self().getRepositoryModel("helloworld.git");
+ RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");
repository.mailingLists.add("list@helloworld.git");
test("sendmail.groovy", gitblit, logger, clientLogger, commands, repository);
@@ -270,7 +267,7 @@ public class GroovyScriptTest { RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
- File groovyDir = GitBlit.getGroovyScriptsFolder();
+ File groovyDir = repositories().getHooksFolder();
File tempScript = File.createTempFile("testClientLogging", "groovy", groovyDir);
tempScript.deleteOnExit();
@@ -291,7 +288,7 @@ public class GroovyScriptTest { String gitblitUrl = GitBlitSuite.url;
- File groovyDir = GitBlit.getGroovyScriptsFolder();
+ File groovyDir = repositories().getHooksFolder();
GroovyScriptEngine gse = new GroovyScriptEngine(groovyDir.getAbsolutePath());
Binding binding = new Binding();
diff --git a/src/test/java/com/gitblit/tests/HtpasswdUserServiceTest.java b/src/test/java/com/gitblit/tests/HtpasswdUserServiceTest.java index e223e6bb..e20c82a7 100644 --- a/src/test/java/com/gitblit/tests/HtpasswdUserServiceTest.java +++ b/src/test/java/com/gitblit/tests/HtpasswdUserServiceTest.java @@ -15,12 +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.assertNull; -import static org.junit.Assert.assertTrue; - import java.io.File; import java.io.FilenameFilter; import java.io.IOException; @@ -40,7 +34,7 @@ import com.gitblit.utils.StringUtils; * Test the Htpasswd user service. * */ -public class HtpasswdUserServiceTest { +public class HtpasswdUserServiceTest extends GitblitUnitTest { private static final String RESOURCE_DIR = "src/test/resources/htpasswdUSTest/"; private static final String KEY_SUPPORT_PLAINTEXT_PWD = "realm.htpasswd.supportPlaintextPasswords"; diff --git a/src/test/java/com/gitblit/tests/Issue0259Test.java b/src/test/java/com/gitblit/tests/Issue0259Test.java index 8e2acaf8..df2ccd0b 100644 --- a/src/test/java/com/gitblit/tests/Issue0259Test.java +++ b/src/test/java/com/gitblit/tests/Issue0259Test.java @@ -17,7 +17,6 @@ package com.gitblit.tests; import java.io.File;
-import org.junit.Assert;
import org.junit.Test;
import com.gitblit.ConfigUserService;
@@ -40,7 +39,7 @@ import com.gitblit.models.UserModel; * @author James Moger
*
*/
-public class Issue0259Test extends Assert {
+public class Issue0259Test extends GitblitUnitTest {
RepositoryModel repo(String name, AccessRestrictionType restriction) {
RepositoryModel repo = new RepositoryModel();
diff --git a/src/test/java/com/gitblit/tests/Issue0271Test.java b/src/test/java/com/gitblit/tests/Issue0271Test.java index 8bab8f2c..15c6ff23 100644 --- a/src/test/java/com/gitblit/tests/Issue0271Test.java +++ b/src/test/java/com/gitblit/tests/Issue0271Test.java @@ -17,7 +17,6 @@ package com.gitblit.tests; import java.io.File;
-import org.junit.Assert;
import org.junit.Test;
import com.gitblit.ConfigUserService;
@@ -37,7 +36,7 @@ import com.gitblit.models.UserModel; * @author James Moger
*
*/
-public class Issue0271Test extends Assert {
+public class Issue0271Test extends GitblitUnitTest {
RepositoryModel repo(String name, AccessRestrictionType restriction) {
RepositoryModel repo = new RepositoryModel();
diff --git a/src/test/java/com/gitblit/tests/JGitUtilsTest.java b/src/test/java/com/gitblit/tests/JGitUtilsTest.java index a9374958..f60343ae 100644 --- a/src/test/java/com/gitblit/tests/JGitUtilsTest.java +++ b/src/test/java/com/gitblit/tests/JGitUtilsTest.java @@ -15,12 +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.assertNull;
-import static org.junit.Assert.assertTrue;
-
import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
@@ -57,7 +51,7 @@ import com.gitblit.utils.JGitUtils; import com.gitblit.utils.JnaUtils;
import com.gitblit.utils.StringUtils;
-public class JGitUtilsTest {
+public class JGitUtilsTest extends GitblitUnitTest {
@Test
public void testDisplayName() throws Exception {
diff --git a/src/test/java/com/gitblit/tests/JnaUtilsTest.java b/src/test/java/com/gitblit/tests/JnaUtilsTest.java index 96782156..c7d5be93 100644 --- a/src/test/java/com/gitblit/tests/JnaUtilsTest.java +++ b/src/test/java/com/gitblit/tests/JnaUtilsTest.java @@ -15,10 +15,6 @@ */ package com.gitblit.tests; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - import java.io.File; import java.io.IOException; @@ -36,7 +32,7 @@ import com.gitblit.utils.JnaUtils; * * @author Florian Zschocke */ -public class JnaUtilsTest { +public class JnaUtilsTest extends GitblitUnitTest { @Test public void testGetgid() { diff --git a/src/test/java/com/gitblit/tests/JsonUtilsTest.java b/src/test/java/com/gitblit/tests/JsonUtilsTest.java index 40e8f975..1cd31b8b 100644 --- a/src/test/java/com/gitblit/tests/JsonUtilsTest.java +++ b/src/test/java/com/gitblit/tests/JsonUtilsTest.java @@ -15,8 +15,6 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
@@ -27,7 +25,7 @@ import org.junit.Test; import com.gitblit.utils.JsonUtils;
import com.google.gson.reflect.TypeToken;
-public class JsonUtilsTest {
+public class JsonUtilsTest extends GitblitUnitTest {
@Test
public void testSerialization() {
diff --git a/src/test/java/com/gitblit/tests/LdapUserServiceTest.java b/src/test/java/com/gitblit/tests/LdapUserServiceTest.java index ae8933ea..86d1f3ca 100644 --- a/src/test/java/com/gitblit/tests/LdapUserServiceTest.java +++ b/src/test/java/com/gitblit/tests/LdapUserServiceTest.java @@ -16,11 +16,6 @@ */ 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.util.HashMap; import java.util.Map; @@ -44,7 +39,7 @@ import com.unboundid.ldif.LDIFReader; * @author jcrygier * */ -public class LdapUserServiceTest { +public class LdapUserServiceTest extends GitblitUnitTest { private LdapUserService ldapUserService; diff --git a/src/test/java/com/gitblit/tests/LuceneExecutorTest.java b/src/test/java/com/gitblit/tests/LuceneExecutorTest.java index ec25c519..0f7e55ca 100644 --- a/src/test/java/com/gitblit/tests/LuceneExecutorTest.java +++ b/src/test/java/com/gitblit/tests/LuceneExecutorTest.java @@ -15,10 +15,6 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -43,7 +39,7 @@ import com.gitblit.utils.JGitUtils; * @author James Moger
*
*/
-public class LuceneExecutorTest {
+public class LuceneExecutorTest extends GitblitUnitTest {
LuceneExecutor lucene;
diff --git a/src/test/java/com/gitblit/tests/MailTest.java b/src/test/java/com/gitblit/tests/MailTest.java index 4feedb06..7598568b 100644 --- a/src/test/java/com/gitblit/tests/MailTest.java +++ b/src/test/java/com/gitblit/tests/MailTest.java @@ -15,8 +15,6 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertTrue;
-
import javax.mail.Message;
import org.junit.Test;
@@ -25,7 +23,7 @@ import com.gitblit.FileSettings; import com.gitblit.Keys;
import com.gitblit.MailExecutor;
-public class MailTest {
+public class MailTest extends GitblitUnitTest {
@Test
public void testSendMail() throws Exception {
diff --git a/src/test/java/com/gitblit/tests/MarkdownUtilsTest.java b/src/test/java/com/gitblit/tests/MarkdownUtilsTest.java index 34583747..e40f1057 100644 --- a/src/test/java/com/gitblit/tests/MarkdownUtilsTest.java +++ b/src/test/java/com/gitblit/tests/MarkdownUtilsTest.java @@ -15,13 +15,11 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-
import org.junit.Test;
import com.gitblit.utils.MarkdownUtils;
-public class MarkdownUtilsTest {
+public class MarkdownUtilsTest extends GitblitUnitTest {
@Test
public void testMarkdown() throws Exception {
diff --git a/src/test/java/com/gitblit/tests/MetricUtilsTest.java b/src/test/java/com/gitblit/tests/MetricUtilsTest.java index bb8261af..4d620ae6 100644 --- a/src/test/java/com/gitblit/tests/MetricUtilsTest.java +++ b/src/test/java/com/gitblit/tests/MetricUtilsTest.java @@ -15,9 +15,6 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import java.util.List;
import java.util.TimeZone;
@@ -27,7 +24,7 @@ import org.junit.Test; import com.gitblit.models.Metric;
import com.gitblit.utils.MetricUtils;
-public class MetricUtilsTest {
+public class MetricUtilsTest extends GitblitUnitTest {
@Test
public void testMetrics() throws Exception {
diff --git a/src/test/java/com/gitblit/tests/ModelUtilsTest.java b/src/test/java/com/gitblit/tests/ModelUtilsTest.java index 9dd29b64..e34e0aa4 100644 --- a/src/test/java/com/gitblit/tests/ModelUtilsTest.java +++ b/src/test/java/com/gitblit/tests/ModelUtilsTest.java @@ -1,16 +1,12 @@ package com.gitblit.tests; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import org.junit.After; import org.junit.Test; import com.gitblit.Constants; import com.gitblit.utils.ModelUtils; -public class ModelUtilsTest { +public class ModelUtilsTest extends GitblitUnitTest { @After public void resetPrefix() diff --git a/src/test/java/com/gitblit/tests/ObjectCacheTest.java b/src/test/java/com/gitblit/tests/ObjectCacheTest.java index 8d07fe65..0330f062 100644 --- a/src/test/java/com/gitblit/tests/ObjectCacheTest.java +++ b/src/test/java/com/gitblit/tests/ObjectCacheTest.java @@ -15,17 +15,13 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import java.util.Date;
import org.junit.Test;
import com.gitblit.utils.ObjectCache;
-public class ObjectCacheTest {
+public class ObjectCacheTest extends GitblitUnitTest {
@Test
public void testCache() throws Exception {
diff --git a/src/test/java/com/gitblit/tests/PermissionsTest.java b/src/test/java/com/gitblit/tests/PermissionsTest.java index 42ef9935..cffce51b 100644 --- a/src/test/java/com/gitblit/tests/PermissionsTest.java +++ b/src/test/java/com/gitblit/tests/PermissionsTest.java @@ -17,7 +17,6 @@ package com.gitblit.tests; import java.util.Date; -import org.junit.Assert; import org.junit.Test; import com.gitblit.Constants.AccessPermission; @@ -33,7 +32,7 @@ import com.gitblit.models.UserModel; * @author James Moger * */ -public class PermissionsTest extends Assert { +public class PermissionsTest extends GitblitUnitTest { /** * Admin access rights/permissions diff --git a/src/test/java/com/gitblit/tests/PushLogTest.java b/src/test/java/com/gitblit/tests/PushLogTest.java index f5d5965b..be097cc4 100644 --- a/src/test/java/com/gitblit/tests/PushLogTest.java +++ b/src/test/java/com/gitblit/tests/PushLogTest.java @@ -28,7 +28,7 @@ import org.junit.Test; import com.gitblit.models.RefLogEntry;
import com.gitblit.utils.RefLogUtils;
-public class PushLogTest {
+public class PushLogTest extends GitblitUnitTest {
@Test
public void testPushLog() throws IOException {
diff --git a/src/test/java/com/gitblit/tests/RedmineUserServiceTest.java b/src/test/java/com/gitblit/tests/RedmineUserServiceTest.java index 7e04a915..75376239 100644 --- a/src/test/java/com/gitblit/tests/RedmineUserServiceTest.java +++ b/src/test/java/com/gitblit/tests/RedmineUserServiceTest.java @@ -1,10 +1,6 @@ package com.gitblit.tests;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import java.util.HashMap;
@@ -15,7 +11,7 @@ import com.gitblit.models.UserModel; import com.gitblit.tests.mock.MemorySettings;
import com.gitblit.utils.StringUtils;
-public class RedmineUserServiceTest {
+public class RedmineUserServiceTest extends GitblitUnitTest {
private static final String JSON = "{\"user\":{\"created_on\":\"2011-03-28T00:41:29Z\",\"lastname\":\"foo\","
+ "\"last_login_on\":\"2012-09-06T23:59:26Z\",\"firstname\":\"baz\","
diff --git a/src/test/java/com/gitblit/tests/RepositoryModelTest.java b/src/test/java/com/gitblit/tests/RepositoryModelTest.java index 56c1ebbc..4520adad 100644 --- a/src/test/java/com/gitblit/tests/RepositoryModelTest.java +++ b/src/test/java/com/gitblit/tests/RepositoryModelTest.java @@ -16,8 +16,6 @@ */ package com.gitblit.tests; -import static org.junit.Assert.assertEquals; - import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.StoredConfig; import org.junit.After; @@ -27,10 +25,9 @@ import org.junit.BeforeClass; import org.junit.Test; import com.gitblit.Constants; -import com.gitblit.GitBlit; import com.gitblit.models.RepositoryModel; -public class RepositoryModelTest { +public class RepositoryModelTest extends GitblitUnitTest { private static boolean wasStarted = false; @@ -68,7 +65,7 @@ public class RepositoryModelTest { @Test public void testGetCustomProperty() throws Exception { - RepositoryModel model = GitBlit.self().getRepositoryModel( + RepositoryModel model = repositories().getRepositoryModel( GitBlitSuite.getHelloworldRepository().getDirectory().getName()); assertEquals("\\d", model.customFields.get("commitMessageRegEx")); @@ -77,16 +74,16 @@ public class RepositoryModelTest { @Test public void testSetCustomProperty() throws Exception { - RepositoryModel model = GitBlit.self().getRepositoryModel( + RepositoryModel model = repositories().getRepositoryModel( GitBlitSuite.getHelloworldRepository().getDirectory().getName()); assertEquals("\\d", model.customFields.get("commitMessageRegEx")); assertEquals("Hello", model.customFields.get("anotherProperty")); assertEquals("Hello", model.customFields.put("anotherProperty", "GoodBye")); - GitBlit.self().updateRepositoryModel(model.name, model, false); + repositories().updateRepositoryModel(model.name, model, false); - model = GitBlit.self().getRepositoryModel( + model = repositories().getRepositoryModel( GitBlitSuite.getHelloworldRepository().getDirectory().getName()); assertEquals("\\d", model.customFields.get("commitMessageRegEx")); diff --git a/src/test/java/com/gitblit/tests/RpcTests.java b/src/test/java/com/gitblit/tests/RpcTests.java index f816ff63..33e8505e 100644 --- a/src/test/java/com/gitblit/tests/RpcTests.java +++ b/src/test/java/com/gitblit/tests/RpcTests.java @@ -15,11 +15,6 @@ */
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.ArrayList;
import java.util.Collection;
@@ -58,7 +53,7 @@ import com.gitblit.utils.RpcUtils; * @author James Moger
*
*/
-public class RpcTests {
+public class RpcTests extends GitblitUnitTest {
String url = GitBlitSuite.url;
String account = GitBlitSuite.account;
diff --git a/src/test/java/com/gitblit/tests/StringUtilsTest.java b/src/test/java/com/gitblit/tests/StringUtilsTest.java index bec5c542..0fd42aad 100644 --- a/src/test/java/com/gitblit/tests/StringUtilsTest.java +++ b/src/test/java/com/gitblit/tests/StringUtilsTest.java @@ -15,10 +15,6 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import java.util.Arrays;
import java.util.List;
@@ -26,7 +22,7 @@ import org.junit.Test; import com.gitblit.utils.StringUtils;
-public class StringUtilsTest {
+public class StringUtilsTest extends GitblitUnitTest {
@Test
public void testIsEmpty() throws Exception {
diff --git a/src/test/java/com/gitblit/tests/SyndicationUtilsTest.java b/src/test/java/com/gitblit/tests/SyndicationUtilsTest.java index 66d0c3a9..d206bbdb 100644 --- a/src/test/java/com/gitblit/tests/SyndicationUtilsTest.java +++ b/src/test/java/com/gitblit/tests/SyndicationUtilsTest.java @@ -15,9 +15,6 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Date;
@@ -31,7 +28,7 @@ import com.gitblit.Constants.SearchType; import com.gitblit.models.FeedEntryModel;
import com.gitblit.utils.SyndicationUtils;
-public class SyndicationUtilsTest {
+public class SyndicationUtilsTest extends GitblitUnitTest {
@Test
public void testSyndication() throws Exception {
diff --git a/src/test/java/com/gitblit/tests/TimeUtilsTest.java b/src/test/java/com/gitblit/tests/TimeUtilsTest.java index 851fb453..fb38ffd3 100644 --- a/src/test/java/com/gitblit/tests/TimeUtilsTest.java +++ b/src/test/java/com/gitblit/tests/TimeUtilsTest.java @@ -15,16 +15,13 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import java.util.Date;
import org.junit.Test;
import com.gitblit.utils.TimeUtils;
-public class TimeUtilsTest {
+public class TimeUtilsTest extends GitblitUnitTest {
private Date offset(long subtract) {
return new Date(System.currentTimeMillis() - subtract);
diff --git a/src/test/java/com/gitblit/tests/UserServiceTest.java b/src/test/java/com/gitblit/tests/UserServiceTest.java index f6cdd6a3..613e46df 100644 --- a/src/test/java/com/gitblit/tests/UserServiceTest.java +++ b/src/test/java/com/gitblit/tests/UserServiceTest.java @@ -15,10 +15,6 @@ */
package com.gitblit.tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import java.io.File;
import java.io.IOException;
@@ -31,7 +27,7 @@ import com.gitblit.models.RepositoryModel; import com.gitblit.models.TeamModel;
import com.gitblit.models.UserModel;
-public class UserServiceTest {
+public class UserServiceTest extends GitblitUnitTest {
@Test
public void testConfigUserService() throws IOException {
diff --git a/src/test/java/com/gitblit/tests/X509UtilsTest.java b/src/test/java/com/gitblit/tests/X509UtilsTest.java index 668626ba..740f908b 100644 --- a/src/test/java/com/gitblit/tests/X509UtilsTest.java +++ b/src/test/java/com/gitblit/tests/X509UtilsTest.java @@ -26,7 +26,6 @@ import java.util.zip.ZipInputStream; import org.eclipse.jgit.util.FileUtils;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -43,7 +42,7 @@ import com.gitblit.utils.X509Utils.X509Metadata; * @author James Moger
*
*/
-public class X509UtilsTest extends Assert {
+public class X509UtilsTest extends GitblitUnitTest {
// passwords are case-sensitive and may be length-limited
// based on the JCE policy files
diff --git a/src/test/java/de/akquinet/devops/GitBlit4UITests.java b/src/test/java/de/akquinet/devops/GitBlit4UITests.java index 966d72b1..d4e32222 100644 --- a/src/test/java/de/akquinet/devops/GitBlit4UITests.java +++ b/src/test/java/de/akquinet/devops/GitBlit4UITests.java @@ -9,6 +9,7 @@ public class GitBlit4UITests extends GitBlit { private boolean luceneIndexingEnabled; public GitBlit4UITests(boolean luceneIndexingEnabled) { + super(null); this.luceneIndexingEnabled = luceneIndexingEnabled; } @@ -21,5 +22,5 @@ public class GitBlit4UITests extends GitBlit { .info("Lucene executor is scheduled to process indexed branches every 2 minutes."); } } - + } diff --git a/src/test/java/de/akquinet/devops/GitBlitServer4UITests.java b/src/test/java/de/akquinet/devops/GitBlitServer4UITests.java index 2d54be2a..6ee98a03 100644 --- a/src/test/java/de/akquinet/devops/GitBlitServer4UITests.java +++ b/src/test/java/de/akquinet/devops/GitBlitServer4UITests.java @@ -1,5 +1,6 @@ package de.akquinet.devops; +import java.io.File; import java.util.ArrayList; import java.util.List; @@ -7,6 +8,8 @@ import com.beust.jcommander.JCommander; import com.beust.jcommander.ParameterException; import com.gitblit.GitBlit; import com.gitblit.GitBlitServer; +import com.gitblit.IStoredSettings; +import com.gitblit.Keys; public class GitBlitServer4UITests extends GitBlitServer { @@ -50,13 +53,9 @@ public class GitBlitServer4UITests extends GitBlitServer { } } - private GitBlit4UITests instance; - @Override - protected GitBlit getGitBlitInstance() { - if (instance == null) { - instance = new GitBlit4UITests(false); - } - return instance; + protected GitBlit newGitblit(IStoredSettings settings, File baseFolder) { + settings.overrideSetting(Keys.web.allowLuceneIndexing, false); + return new GitBlit(settings, baseFolder); } } |