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)
|
|
50 |
@SuiteClasses({ FileUtilsTest.class, TimeUtilsTest.class, StringUtilsTest.class, Base64Test.class,
|
|
51 |
JsonUtilsTest.class, ByteFormatTest.class, ObjectCacheTest.class, UserServiceTest.class,
|
|
52 |
MarkdownUtilsTest.class, JGitUtilsTest.class, SyndicationUtilsTest.class,
|
|
53 |
DiffUtilsTest.class, MetricUtilsTest.class, TicgitUtilsTest.class, GitBlitTest.class,
|
|
54 |
FederationTests.class, RpcTests.class, GitServletTest.class })
|
|
55 |
public class GitBlitSuite {
|
143fc9
|
56 |
|
2a7306
|
57 |
public static final File REPOSITORIES = new File("git");
|
143fc9
|
58 |
|
JM |
59 |
static int port = 8280;
|
|
60 |
static int shutdownPort = 8281;
|
|
61 |
|
|
62 |
public static String url = "http://localhost:" + port;
|
|
63 |
public static String account = "admin";
|
|
64 |
public static String password = "admin";
|
2a7306
|
65 |
|
7e8873
|
66 |
private static AtomicBoolean started = new AtomicBoolean(false);
|
1f9dae
|
67 |
|
2a7306
|
68 |
public static Repository getHelloworldRepository() throws Exception {
|
JM |
69 |
return new FileRepository(new File(REPOSITORIES, "helloworld.git"));
|
|
70 |
}
|
|
71 |
|
|
72 |
public static Repository getTicgitRepository() throws Exception {
|
|
73 |
return new FileRepository(new File(REPOSITORIES, "ticgit.git"));
|
|
74 |
}
|
|
75 |
|
4ab184
|
76 |
public static Repository getJGitRepository() throws Exception {
|
168566
|
77 |
return new FileRepository(new File(REPOSITORIES, "test/jgit.git"));
|
4ab184
|
78 |
}
|
JM |
79 |
|
|
80 |
public static Repository getBluezGnomeRepository() throws Exception {
|
168566
|
81 |
return new FileRepository(new File(REPOSITORIES, "test/bluez-gnome.git"));
|
143fc9
|
82 |
}
|
JM |
83 |
|
7e8873
|
84 |
public static boolean startGitblit() throws Exception {
|
JM |
85 |
if (started.get()) {
|
|
86 |
// already started
|
|
87 |
return false;
|
|
88 |
}
|
143fc9
|
89 |
// Start a Gitblit instance
|
JM |
90 |
Executors.newSingleThreadExecutor().execute(new Runnable() {
|
|
91 |
public void run() {
|
|
92 |
GitBlitServer.main("--httpPort", "" + port, "--httpsPort", "0", "--shutdownPort",
|
|
93 |
"" + shutdownPort, "--repositoriesFolder",
|
|
94 |
"\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService",
|
7e8873
|
95 |
"test-users.conf", "--settings", "test-gitblit.properties");
|
143fc9
|
96 |
}
|
JM |
97 |
});
|
|
98 |
|
|
99 |
// Wait a few seconds for it to be running
|
|
100 |
Thread.sleep(2500);
|
7e8873
|
101 |
|
JM |
102 |
started.set(true);
|
|
103 |
return true;
|
143fc9
|
104 |
}
|
JM |
105 |
|
|
106 |
public static void stopGitblit() throws Exception {
|
|
107 |
// Stop Gitblit
|
|
108 |
GitBlitServer.main("--stop", "--shutdownPort", "" + shutdownPort);
|
|
109 |
|
|
110 |
// Wait a few seconds for it to be running
|
|
111 |
Thread.sleep(2500);
|
4ab184
|
112 |
}
|
JM |
113 |
|
7e8873
|
114 |
@BeforeClass
|
JM |
115 |
public static void setUp() throws Exception {
|
|
116 |
startGitblit();
|
a125cf
|
117 |
|
JM |
118 |
if (REPOSITORIES.exists() || REPOSITORIES.mkdirs()) {
|
168566
|
119 |
cloneOrFetch("helloworld.git", "https://github.com/git/hello-world.git");
|
JM |
120 |
cloneOrFetch("ticgit.git", "https://github.com/jeffWelling/ticgit.git");
|
|
121 |
cloneOrFetch("test/bluez-gnome.git",
|
|
122 |
"https://git.kernel.org/pub/scm/bluetooth/bluez-gnome.git");
|
|
123 |
cloneOrFetch("test/jgit.git", "https://github.com/eclipse/jgit.git");
|
|
124 |
cloneOrFetch("test/helloworld.git", "https://github.com/git/hello-world.git");
|
a125cf
|
125 |
|
JM |
126 |
enableTickets("ticgit.git");
|
|
127 |
enableDocs("ticgit.git");
|
|
128 |
showRemoteBranches("ticgit.git");
|
168566
|
129 |
showRemoteBranches("test/jgit.git");
|
a125cf
|
130 |
}
|
143fc9
|
131 |
}
|
JM |
132 |
|
7e8873
|
133 |
@AfterClass
|
JM |
134 |
public static void tearDown() throws Exception {
|
143fc9
|
135 |
stopGitblit();
|
2a7306
|
136 |
}
|
JM |
137 |
|
7e8873
|
138 |
private static void cloneOrFetch(String name, String fromUrl) throws Exception {
|
168566
|
139 |
System.out.print("Fetching " + name + "... ");
|
JM |
140 |
JGitUtils.cloneRepository(REPOSITORIES, name, fromUrl);
|
|
141 |
System.out.println("done.");
|
4ab184
|
142 |
}
|
a125cf
|
143 |
|
7e8873
|
144 |
private static void enableTickets(String repositoryName) {
|
a125cf
|
145 |
try {
|
JM |
146 |
RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
|
|
147 |
model.useTickets = true;
|
892570
|
148 |
GitBlit.self().updateRepositoryModel(model.name, model, false);
|
a125cf
|
149 |
} catch (GitBlitException g) {
|
JM |
150 |
g.printStackTrace();
|
|
151 |
}
|
|
152 |
}
|
168566
|
153 |
|
7e8873
|
154 |
private static void enableDocs(String repositoryName) {
|
a125cf
|
155 |
try {
|
JM |
156 |
RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
|
|
157 |
model.useDocs = true;
|
892570
|
158 |
GitBlit.self().updateRepositoryModel(model.name, model, false);
|
a125cf
|
159 |
} catch (GitBlitException g) {
|
JM |
160 |
g.printStackTrace();
|
|
161 |
}
|
|
162 |
}
|
168566
|
163 |
|
7e8873
|
164 |
private static void showRemoteBranches(String repositoryName) {
|
a125cf
|
165 |
try {
|
JM |
166 |
RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
|
|
167 |
model.showRemoteBranches = true;
|
892570
|
168 |
GitBlit.self().updateRepositoryModel(model.name, model, false);
|
a125cf
|
169 |
} catch (GitBlitException g) {
|
JM |
170 |
g.printStackTrace();
|
|
171 |
}
|
|
172 |
}
|
2a7306
|
173 |
}
|