James Moger
2011-10-27 8e40cd53b6b1579e383bd5e993cb3c35ce4583c4
commit | author | age
ec97f7 1 /*
JM 2  * Copyright 2011 gitblit.com.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
2a7306 16 package com.gitblit.tests;
JM 17
18 import java.io.File;
19
20 import junit.extensions.TestSetup;
21 import junit.framework.Test;
22 import junit.framework.TestSuite;
23
24 import org.eclipse.jgit.lib.Repository;
25 import org.eclipse.jgit.storage.file.FileRepository;
26
28d6b2 27 import com.gitblit.FileSettings;
88598b 28 import com.gitblit.FileUserService;
28d6b2 29 import com.gitblit.GitBlit;
a125cf 30 import com.gitblit.GitBlitException;
JM 31 import com.gitblit.models.RepositoryModel;
168566 32 import com.gitblit.utils.JGitUtils;
28d6b2 33
2a7306 34 public class GitBlitSuite extends TestSetup {
JM 35     public static final File REPOSITORIES = new File("git");
36
37     private GitBlitSuite(TestSuite suite) {
38         super(suite);
39     }
40
41     public static Test suite() {
42         TestSuite suite = new TestSuite();
88598b 43         suite.addTestSuite(FileUtilsTest.class);
28d6b2 44         suite.addTestSuite(TimeUtilsTest.class);
ec97f7 45         suite.addTestSuite(StringUtilsTest.class);
JM 46         suite.addTestSuite(ByteFormatTest.class);
a125cf 47         suite.addTestSuite(MarkdownUtilsTest.class);
2a7306 48         suite.addTestSuite(JGitUtilsTest.class);
85c2e6 49         suite.addTestSuite(SyndicationUtilsTest.class);
db653a 50         suite.addTestSuite(DiffUtilsTest.class);
793f76 51         suite.addTestSuite(MetricUtilsTest.class);
JM 52         suite.addTestSuite(TicgitUtilsTest.class);
28d6b2 53         suite.addTestSuite(GitBlitTest.class);
2a7306 54         return new GitBlitSuite(suite);
JM 55     }
1f9dae 56
2a7306 57     public static Repository getHelloworldRepository() throws Exception {
JM 58         return new FileRepository(new File(REPOSITORIES, "helloworld.git"));
59     }
60
61     public static Repository getTicgitRepository() throws Exception {
62         return new FileRepository(new File(REPOSITORIES, "ticgit.git"));
63     }
64
4ab184 65     public static Repository getJGitRepository() throws Exception {
168566 66         return new FileRepository(new File(REPOSITORIES, "test/jgit.git"));
4ab184 67     }
JM 68
69     public static Repository getBluezGnomeRepository() throws Exception {
168566 70         return new FileRepository(new File(REPOSITORIES, "test/bluez-gnome.git"));
4ab184 71     }
JM 72
2a7306 73     @Override
JM 74     protected void setUp() throws Exception {
28d6b2 75         FileSettings settings = new FileSettings("distrib/gitblit.properties");
f6740d 76         GitBlit.self().configureContext(settings, true);
85c2e6 77         FileUserService loginService = new FileUserService(new File("distrib/users.properties"));
JM 78         GitBlit.self().setUserService(loginService);
a125cf 79
JM 80         if (REPOSITORIES.exists() || REPOSITORIES.mkdirs()) {
168566 81             cloneOrFetch("helloworld.git", "https://github.com/git/hello-world.git");
JM 82             cloneOrFetch("ticgit.git", "https://github.com/jeffWelling/ticgit.git");
83             cloneOrFetch("test/bluez-gnome.git",
84                     "https://git.kernel.org/pub/scm/bluetooth/bluez-gnome.git");
85             cloneOrFetch("test/jgit.git", "https://github.com/eclipse/jgit.git");
86             cloneOrFetch("test/helloworld.git", "https://github.com/git/hello-world.git");
a125cf 87
JM 88             enableTickets("ticgit.git");
89             enableDocs("ticgit.git");
90             showRemoteBranches("ticgit.git");
168566 91             showRemoteBranches("test/jgit.git");
a125cf 92         }
2a7306 93     }
JM 94
168566 95     private void cloneOrFetch(String name, String fromUrl) throws Exception {
JM 96         System.out.print("Fetching " + name + "... ");
97         JGitUtils.cloneRepository(REPOSITORIES, name, fromUrl);
98         System.out.println("done.");
4ab184 99     }
a125cf 100
JM 101     private void enableTickets(String repositoryName) {
102         try {
103             RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
104             model.useTickets = true;
892570 105             GitBlit.self().updateRepositoryModel(model.name, model, false);
a125cf 106         } catch (GitBlitException g) {
JM 107             g.printStackTrace();
108         }
109     }
168566 110
a125cf 111     private void enableDocs(String repositoryName) {
JM 112         try {
113             RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
114             model.useDocs = true;
892570 115             GitBlit.self().updateRepositoryModel(model.name, model, false);
a125cf 116         } catch (GitBlitException g) {
JM 117             g.printStackTrace();
118         }
119     }
168566 120
a125cf 121     private void showRemoteBranches(String repositoryName) {
JM 122         try {
123             RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
124             model.showRemoteBranches = true;
892570 125             GitBlit.self().updateRepositoryModel(model.name, model, false);
a125cf 126         } catch (GitBlitException g) {
JM 127             g.printStackTrace();
128         }
129     }
2a7306 130 }