From d65f712ea3d8941f4b9145c0630c30c20af80d13 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Fri, 11 Nov 2011 17:22:21 -0500 Subject: [PATCH] Documentation. Add javadoc and source jars to the gbapi download. --- tests/com/gitblit/tests/GitBlitSuite.java | 123 ++++++++++++++++++++++------------------ 1 files changed, 68 insertions(+), 55 deletions(-) diff --git a/tests/com/gitblit/tests/GitBlitSuite.java b/tests/com/gitblit/tests/GitBlitSuite.java index fe201b8..ad87cb0 100644 --- a/tests/com/gitblit/tests/GitBlitSuite.java +++ b/tests/com/gitblit/tests/GitBlitSuite.java @@ -16,28 +16,33 @@ package com.gitblit.tests; import java.io.File; -import java.util.ArrayList; -import java.util.List; +import java.util.concurrent.Executors; import junit.extensions.TestSetup; import junit.framework.Test; import junit.framework.TestSuite; -import org.eclipse.jgit.api.CloneCommand; -import org.eclipse.jgit.api.FetchCommand; -import org.eclipse.jgit.api.Git; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.storage.file.FileRepository; -import org.eclipse.jgit.transport.RefSpec; import com.gitblit.FileSettings; +import com.gitblit.FileUserService; import com.gitblit.GitBlit; import com.gitblit.GitBlitException; -import com.gitblit.JettyLoginService; +import com.gitblit.GitBlitServer; import com.gitblit.models.RepositoryModel; +import com.gitblit.utils.JGitUtils; public class GitBlitSuite extends TestSetup { + public static final File REPOSITORIES = new File("git"); + + static int port = 8280; + static int shutdownPort = 8281; + + public static String url = "http://localhost:" + port; + public static String account = "admin"; + public static String password = "admin"; private GitBlitSuite(TestSuite suite) { super(suite); @@ -45,15 +50,21 @@ public static Test suite() { TestSuite suite = new TestSuite(); + suite.addTestSuite(FileUtilsTest.class); suite.addTestSuite(TimeUtilsTest.class); suite.addTestSuite(StringUtilsTest.class); + suite.addTestSuite(Base64Test.class); + suite.addTestSuite(JsonUtilsTest.class); suite.addTestSuite(ByteFormatTest.class); + suite.addTestSuite(ObjectCacheTest.class); suite.addTestSuite(MarkdownUtilsTest.class); suite.addTestSuite(JGitUtilsTest.class); + suite.addTestSuite(SyndicationUtilsTest.class); suite.addTestSuite(DiffUtilsTest.class); suite.addTestSuite(MetricUtilsTest.class); suite.addTestSuite(TicgitUtilsTest.class); suite.addTestSuite(GitBlitTest.class); + suite.addTestSuite(RpcTests.class); return new GitBlitSuite(suite); } @@ -66,94 +77,96 @@ } public static Repository getJGitRepository() throws Exception { - return new FileRepository(new File(REPOSITORIES, "nested/jgit.git")); + return new FileRepository(new File(REPOSITORIES, "test/jgit.git")); } public static Repository getBluezGnomeRepository() throws Exception { - return new FileRepository(new File(REPOSITORIES, "nested/bluez-gnome.git")); + return new FileRepository(new File(REPOSITORIES, "test/bluez-gnome.git")); + } + + public static void startGitblit() throws Exception { + // Start a Gitblit instance + Executors.newSingleThreadExecutor().execute(new Runnable() { + public void run() { + GitBlitServer.main("--httpPort", "" + port, "--httpsPort", "0", "--shutdownPort", + "" + shutdownPort, "--repositoriesFolder", + "\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService", + "distrib/users.properties"); + } + }); + + // Wait a few seconds for it to be running + Thread.sleep(2500); + } + + public static void stopGitblit() throws Exception { + // Stop Gitblit + GitBlitServer.main("--stop", "--shutdownPort", "" + shutdownPort); + + // Wait a few seconds for it to be running + Thread.sleep(2500); } @Override protected void setUp() throws Exception { FileSettings settings = new FileSettings("distrib/gitblit.properties"); - GitBlit.self().configureContext(settings); - JettyLoginService loginService = new JettyLoginService(new File("distrib/users.properties")); - loginService.loadUsers(); - GitBlit.self().setLoginService(loginService); + GitBlit.self().configureContext(settings, true); + FileUserService loginService = new FileUserService(new File("distrib/users.properties")); + GitBlit.self().setUserService(loginService); if (REPOSITORIES.exists() || REPOSITORIES.mkdirs()) { - cloneOrFetch("helloworld.git", "https://github.com/git/hello-world.git", true); - cloneOrFetch("ticgit.git", "https://github.com/jeffWelling/ticgit.git", true); - cloneOrFetch("nested/bluez-gnome.git", "https://git.kernel.org/pub/scm/bluetooth/bluez-gnome.git", true); - cloneOrFetch("nested/jgit.git", "https://github.com/eclipse/jgit.git", true); - cloneOrFetch("nested/helloworld.git", "https://github.com/git/hello-world.git", true); + cloneOrFetch("helloworld.git", "https://github.com/git/hello-world.git"); + cloneOrFetch("ticgit.git", "https://github.com/jeffWelling/ticgit.git"); + cloneOrFetch("test/bluez-gnome.git", + "https://git.kernel.org/pub/scm/bluetooth/bluez-gnome.git"); + cloneOrFetch("test/jgit.git", "https://github.com/eclipse/jgit.git"); + cloneOrFetch("test/helloworld.git", "https://github.com/git/hello-world.git"); enableTickets("ticgit.git"); enableDocs("ticgit.git"); showRemoteBranches("ticgit.git"); - showRemoteBranches("nested/jgit.git"); + showRemoteBranches("test/jgit.git"); } + + startGitblit(); } - private void cloneOrFetch(String toFolder, String fromUrl, boolean bare) throws Exception { - File folder = new File(REPOSITORIES, toFolder + (bare ? "" : "/.git")); - if (folder.exists()) { - System.out.print("Updating " + (bare ? "bare " : " ") + toFolder + "... "); - fetch(toFolder); - System.out.println("done."); - } else { - System.out.println("Cloning " + (bare ? "bare " : " ") + toFolder + "... "); - CloneCommand clone = new CloneCommand(); - clone.setBare(bare); - clone.setCloneAllBranches(true); - clone.setURI(fromUrl); - clone.setDirectory(folder); - clone.call(); - // Now we have to fetch because CloneCommand doesn't fetch - // Notes nor does it allow manual RefSpec. - fetch(toFolder); - System.out.println("done."); - } + @Override + protected void tearDown() throws Exception { + stopGitblit(); } - - private void fetch(String toFolder) throws Exception { - FileRepository repository = new FileRepository(new File(REPOSITORIES, toFolder)); - Git git = new Git(repository); - FetchCommand fetch = git.fetch(); - List<RefSpec> specs = new ArrayList<RefSpec>(); - specs.add(new RefSpec("+refs/heads/*:refs/remotes/origin/*")); - specs.add(new RefSpec("+refs/tags/*:refs/tags/*")); - specs.add(new RefSpec("+refs/notes/*:refs/notes/*")); - fetch.setRefSpecs(specs); - fetch.call(); - repository.close(); + + private void cloneOrFetch(String name, String fromUrl) throws Exception { + System.out.print("Fetching " + name + "... "); + JGitUtils.cloneRepository(REPOSITORIES, name, fromUrl); + System.out.println("done."); } private void enableTickets(String repositoryName) { try { RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName); model.useTickets = true; - GitBlit.self().editRepositoryModel(model.name, model, false); + GitBlit.self().updateRepositoryModel(model.name, model, false); } catch (GitBlitException g) { g.printStackTrace(); } } - + private void enableDocs(String repositoryName) { try { RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName); model.useDocs = true; - GitBlit.self().editRepositoryModel(model.name, model, false); + GitBlit.self().updateRepositoryModel(model.name, model, false); } catch (GitBlitException g) { g.printStackTrace(); } } - + private void showRemoteBranches(String repositoryName) { try { RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName); model.showRemoteBranches = true; - GitBlit.self().editRepositoryModel(model.name, model, false); + GitBlit.self().updateRepositoryModel(model.name, model, false); } catch (GitBlitException g) { g.printStackTrace(); } -- Gitblit v1.9.1