James Moger
2011-06-09 81f881a10f2c8456cc4ebfa26327e15655db4646
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;
JM 28 import com.gitblit.GitBlit;
a125cf 29 import com.gitblit.GitBlitException;
28d6b2 30 import com.gitblit.JettyLoginService;
a125cf 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();
28d6b2 43         suite.addTestSuite(TimeUtilsTest.class);
ec97f7 44         suite.addTestSuite(StringUtilsTest.class);
JM 45         suite.addTestSuite(ByteFormatTest.class);
a125cf 46         suite.addTestSuite(MarkdownUtilsTest.class);
2a7306 47         suite.addTestSuite(JGitUtilsTest.class);
db653a 48         suite.addTestSuite(DiffUtilsTest.class);
793f76 49         suite.addTestSuite(MetricUtilsTest.class);
JM 50         suite.addTestSuite(TicgitUtilsTest.class);
28d6b2 51         suite.addTestSuite(GitBlitTest.class);
2a7306 52         return new GitBlitSuite(suite);
JM 53     }
1f9dae 54
2a7306 55     public static Repository getHelloworldRepository() throws Exception {
JM 56         return new FileRepository(new File(REPOSITORIES, "helloworld.git"));
57     }
58
59     public static Repository getTicgitRepository() throws Exception {
60         return new FileRepository(new File(REPOSITORIES, "ticgit.git"));
61     }
62
4ab184 63     public static Repository getJGitRepository() throws Exception {
168566 64         return new FileRepository(new File(REPOSITORIES, "test/jgit.git"));
4ab184 65     }
JM 66
67     public static Repository getBluezGnomeRepository() throws Exception {
168566 68         return new FileRepository(new File(REPOSITORIES, "test/bluez-gnome.git"));
4ab184 69     }
JM 70
2a7306 71     @Override
JM 72     protected void setUp() throws Exception {
28d6b2 73         FileSettings settings = new FileSettings("distrib/gitblit.properties");
JM 74         GitBlit.self().configureContext(settings);
75         JettyLoginService loginService = new JettyLoginService(new File("distrib/users.properties"));
76         loginService.loadUsers();
77         GitBlit.self().setLoginService(loginService);
a125cf 78
JM 79         if (REPOSITORIES.exists() || REPOSITORIES.mkdirs()) {
168566 80             cloneOrFetch("helloworld.git", "https://github.com/git/hello-world.git");
JM 81             cloneOrFetch("ticgit.git", "https://github.com/jeffWelling/ticgit.git");
82             cloneOrFetch("test/bluez-gnome.git",
83                     "https://git.kernel.org/pub/scm/bluetooth/bluez-gnome.git");
84             cloneOrFetch("test/jgit.git", "https://github.com/eclipse/jgit.git");
85             cloneOrFetch("test/helloworld.git", "https://github.com/git/hello-world.git");
a125cf 86
JM 87             enableTickets("ticgit.git");
88             enableDocs("ticgit.git");
89             showRemoteBranches("ticgit.git");
168566 90             showRemoteBranches("test/jgit.git");
a125cf 91         }
2a7306 92     }
JM 93
168566 94     private void cloneOrFetch(String name, String fromUrl) throws Exception {
JM 95         System.out.print("Fetching " + name + "... ");
96         JGitUtils.cloneRepository(REPOSITORIES, name, fromUrl);
97         System.out.println("done.");
4ab184 98     }
a125cf 99
JM 100     private void enableTickets(String repositoryName) {
101         try {
102             RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
103             model.useTickets = true;
104             GitBlit.self().editRepositoryModel(model.name, model, false);
105         } catch (GitBlitException g) {
106             g.printStackTrace();
107         }
108     }
168566 109
a125cf 110     private void enableDocs(String repositoryName) {
JM 111         try {
112             RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
113             model.useDocs = true;
114             GitBlit.self().editRepositoryModel(model.name, model, false);
115         } catch (GitBlitException g) {
116             g.printStackTrace();
117         }
118     }
168566 119
a125cf 120     private void showRemoteBranches(String repositoryName) {
JM 121         try {
122             RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
123             model.showRemoteBranches = true;
124             GitBlit.self().editRepositoryModel(model.name, model, false);
125         } catch (GitBlitException g) {
126             g.printStackTrace();
127         }
128     }
2a7306 129 }