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;
|
143fc9
|
19 |
import java.util.concurrent.Executors;
|
7e8873
|
20 |
import java.util.concurrent.atomic.AtomicBoolean;
|
2a7306
|
21 |
|
JM |
22 |
import org.eclipse.jgit.lib.Repository;
|
|
23 |
import org.eclipse.jgit.storage.file.FileRepository;
|
7e8873
|
24 |
import org.junit.AfterClass;
|
JM |
25 |
import org.junit.BeforeClass;
|
|
26 |
import org.junit.runner.RunWith;
|
|
27 |
import org.junit.runners.Suite;
|
|
28 |
import org.junit.runners.Suite.SuiteClasses;
|
2a7306
|
29 |
|
28d6b2
|
30 |
import com.gitblit.GitBlit;
|
a125cf
|
31 |
import com.gitblit.GitBlitException;
|
143fc9
|
32 |
import com.gitblit.GitBlitServer;
|
a125cf
|
33 |
import com.gitblit.models.RepositoryModel;
|
168566
|
34 |
import com.gitblit.utils.JGitUtils;
|
28d6b2
|
35 |
|
7e8873
|
36 |
/**
|
JM |
37 |
* The GitBlitSuite uses test-gitblit.properties and test-users.conf. The suite
|
|
38 |
* is fairly comprehensive for all lower-level functionality. Wicket pages are
|
|
39 |
* currently not unit-tested.
|
|
40 |
*
|
|
41 |
* This suite starts a Gitblit server instance within the same JVM instance as
|
|
42 |
* the unit tests. This allows the unit tests to access the GitBlit static
|
|
43 |
* singleton while also being able to communicate with the instance via tcp/ip
|
|
44 |
* for testing rpc requests, federation requests, and git servlet operations.
|
|
45 |
*
|
|
46 |
* @author James Moger
|
|
47 |
*
|
|
48 |
*/
|
|
49 |
@RunWith(Suite.class)
|
c89745
|
50 |
@SuiteClasses({ ArrayUtilsTest.class, FileUtilsTest.class, TimeUtilsTest.class,
|
JM |
51 |
StringUtilsTest.class, Base64Test.class, JsonUtilsTest.class, ByteFormatTest.class,
|
98b4b9
|
52 |
ObjectCacheTest.class, UserServiceTest.class, LdapUserServiceTest.class,
|
JM |
53 |
MarkdownUtilsTest.class, JGitUtilsTest.class, SyndicationUtilsTest.class,
|
|
54 |
DiffUtilsTest.class, MetricUtilsTest.class, TicgitUtilsTest.class,
|
|
55 |
GitBlitTest.class, FederationTests.class, RpcTests.class, GitServletTest.class,
|
cca55e
|
56 |
GroovyScriptTest.class, LuceneExecutorTest.class, IssuesTest.class, RepositoryModelTest.class })
|
7e8873
|
57 |
public class GitBlitSuite {
|
143fc9
|
58 |
|
2a7306
|
59 |
public static final File REPOSITORIES = new File("git");
|
143fc9
|
60 |
|
JM |
61 |
static int port = 8280;
|
|
62 |
static int shutdownPort = 8281;
|
|
63 |
|
|
64 |
public static String url = "http://localhost:" + port;
|
|
65 |
public static String account = "admin";
|
|
66 |
public static String password = "admin";
|
2a7306
|
67 |
|
7e8873
|
68 |
private static AtomicBoolean started = new AtomicBoolean(false);
|
1f9dae
|
69 |
|
2a7306
|
70 |
public static Repository getHelloworldRepository() throws Exception {
|
JM |
71 |
return new FileRepository(new File(REPOSITORIES, "helloworld.git"));
|
|
72 |
}
|
|
73 |
|
|
74 |
public static Repository getTicgitRepository() throws Exception {
|
|
75 |
return new FileRepository(new File(REPOSITORIES, "ticgit.git"));
|
|
76 |
}
|
|
77 |
|
4ab184
|
78 |
public static Repository getJGitRepository() throws Exception {
|
168566
|
79 |
return new FileRepository(new File(REPOSITORIES, "test/jgit.git"));
|
4ab184
|
80 |
}
|
JM |
81 |
|
11924d
|
82 |
public static Repository getAmbitionRepository() throws Exception {
|
JM |
83 |
return new FileRepository(new File(REPOSITORIES, "test/ambition.git"));
|
|
84 |
}
|
|
85 |
|
|
86 |
public static Repository getTheoreticalPhysicsRepository() throws Exception {
|
|
87 |
return new FileRepository(new File(REPOSITORIES, "test/theoretical-physics.git"));
|
|
88 |
}
|
|
89 |
|
0f43a5
|
90 |
public static Repository getIssuesTestRepository() throws Exception {
|
d896e6
|
91 |
JGitUtils.createRepository(REPOSITORIES, "gb-issues.git").close();
|
0f43a5
|
92 |
return new FileRepository(new File(REPOSITORIES, "gb-issues.git"));
|
d3065f
|
93 |
}
|
JM |
94 |
|
|
95 |
public static Repository getGitectiveRepository() throws Exception {
|
9e2f9d
|
96 |
return new FileRepository(new File(REPOSITORIES, "test/gitective.git"));
|
0f43a5
|
97 |
}
|
JM |
98 |
|
7e8873
|
99 |
public static boolean startGitblit() throws Exception {
|
JM |
100 |
if (started.get()) {
|
|
101 |
// already started
|
|
102 |
return false;
|
|
103 |
}
|
f3ce6e
|
104 |
|
JM |
105 |
GitServletTest.deleteWorkingFolders();
|
|
106 |
|
143fc9
|
107 |
// Start a Gitblit instance
|
JM |
108 |
Executors.newSingleThreadExecutor().execute(new Runnable() {
|
|
109 |
public void run() {
|
|
110 |
GitBlitServer.main("--httpPort", "" + port, "--httpsPort", "0", "--shutdownPort",
|
|
111 |
"" + shutdownPort, "--repositoriesFolder",
|
|
112 |
"\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService",
|
7e8873
|
113 |
"test-users.conf", "--settings", "test-gitblit.properties");
|
143fc9
|
114 |
}
|
JM |
115 |
});
|
|
116 |
|
|
117 |
// Wait a few seconds for it to be running
|
|
118 |
Thread.sleep(2500);
|
7e8873
|
119 |
|
JM |
120 |
started.set(true);
|
|
121 |
return true;
|
143fc9
|
122 |
}
|
JM |
123 |
|
|
124 |
public static void stopGitblit() throws Exception {
|
|
125 |
// Stop Gitblit
|
|
126 |
GitBlitServer.main("--stop", "--shutdownPort", "" + shutdownPort);
|
|
127 |
|
|
128 |
// Wait a few seconds for it to be running
|
f3ce6e
|
129 |
Thread.sleep(5000);
|
4ab184
|
130 |
}
|
JM |
131 |
|
7e8873
|
132 |
@BeforeClass
|
JM |
133 |
public static void setUp() throws Exception {
|
|
134 |
startGitblit();
|
a125cf
|
135 |
|
JM |
136 |
if (REPOSITORIES.exists() || REPOSITORIES.mkdirs()) {
|
168566
|
137 |
cloneOrFetch("helloworld.git", "https://github.com/git/hello-world.git");
|
f3ce6e
|
138 |
cloneOrFetch("ticgit.git", "https://github.com/schacon/ticgit.git");
|
168566
|
139 |
cloneOrFetch("test/jgit.git", "https://github.com/eclipse/jgit.git");
|
JM |
140 |
cloneOrFetch("test/helloworld.git", "https://github.com/git/hello-world.git");
|
11924d
|
141 |
cloneOrFetch("test/ambition.git", "https://github.com/defunkt/ambition.git");
|
JM |
142 |
cloneOrFetch("test/theoretical-physics.git", "https://github.com/certik/theoretical-physics.git");
|
d3065f
|
143 |
cloneOrFetch("test/gitective.git", "https://github.com/kevinsawicki/gitective.git");
|
11924d
|
144 |
|
a125cf
|
145 |
enableTickets("ticgit.git");
|
JM |
146 |
enableDocs("ticgit.git");
|
|
147 |
showRemoteBranches("ticgit.git");
|
168566
|
148 |
showRemoteBranches("test/jgit.git");
|
a125cf
|
149 |
}
|
143fc9
|
150 |
}
|
JM |
151 |
|
7e8873
|
152 |
@AfterClass
|
JM |
153 |
public static void tearDown() throws Exception {
|
143fc9
|
154 |
stopGitblit();
|
2a7306
|
155 |
}
|
JM |
156 |
|
7e8873
|
157 |
private static void cloneOrFetch(String name, String fromUrl) throws Exception {
|
168566
|
158 |
System.out.print("Fetching " + name + "... ");
|
JM |
159 |
JGitUtils.cloneRepository(REPOSITORIES, name, fromUrl);
|
|
160 |
System.out.println("done.");
|
4ab184
|
161 |
}
|
a125cf
|
162 |
|
7e8873
|
163 |
private static void enableTickets(String repositoryName) {
|
a125cf
|
164 |
try {
|
JM |
165 |
RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
|
|
166 |
model.useTickets = true;
|
892570
|
167 |
GitBlit.self().updateRepositoryModel(model.name, model, false);
|
a125cf
|
168 |
} catch (GitBlitException g) {
|
JM |
169 |
g.printStackTrace();
|
|
170 |
}
|
|
171 |
}
|
168566
|
172 |
|
7e8873
|
173 |
private static void enableDocs(String repositoryName) {
|
a125cf
|
174 |
try {
|
JM |
175 |
RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
|
|
176 |
model.useDocs = true;
|
892570
|
177 |
GitBlit.self().updateRepositoryModel(model.name, model, false);
|
a125cf
|
178 |
} catch (GitBlitException g) {
|
JM |
179 |
g.printStackTrace();
|
|
180 |
}
|
|
181 |
}
|
168566
|
182 |
|
7e8873
|
183 |
private static void showRemoteBranches(String repositoryName) {
|
a125cf
|
184 |
try {
|
JM |
185 |
RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
|
|
186 |
model.showRemoteBranches = true;
|
892570
|
187 |
GitBlit.self().updateRepositoryModel(model.name, model, false);
|
a125cf
|
188 |
} catch (GitBlitException g) {
|
JM |
189 |
g.printStackTrace();
|
|
190 |
}
|
|
191 |
}
|
2a7306
|
192 |
}
|