Skip to content

Commit e57a846

Browse files
committed
Merge branch 'chirontt-external_repos_zipped' into master.
2 parents 845de9d + c7bf84f commit e57a846

22 files changed

+259
-136
lines changed

build.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@
132132
-->
133133
<target name="test" depends="compile" description="compiles Gitblit from source and runs unit tests">
134134

135+
<!-- Generate the HelloworldKeys class from the hello-world.properties file -->
136+
<mx:keys propertiesfile="${basedir}/src/test/data/hello-world.properties"
137+
outputclass="com.gitblit.tests.HelloworldKeys"
138+
todir="${basedir}/src/test/java" />
139+
135140
<!-- Compile unit tests -->
136141
<mx:javac scope="test" />
137142

src/test/data/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/*.git/

src/test/data/ambition.git.zip

195 KB
Binary file not shown.

src/test/data/gitective.git.zip

2.84 MB
Binary file not shown.

src/test/data/hello-world.git.zip

53.8 KB
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
commit.first=192cdede1cc81da7b393aeb7aba9f88998b04713
2+
commit.second=8caad51
3+
commit.fifth=55f6796044dc51f0bb9301f07920f0fb64c3d12c
4+
commit.fifteen=5ebfaca
5+
commit.added=192cded
6+
commit.changed=b2c50ce
7+
commit.deleted=8613bee10bde27a0fbaca66447cdc3f0f9483365
8+
users.byEmail=9
9+
users.byName=8

src/test/data/ticgit.git.zip

356 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/HelloworldKeys.java

src/test/java/com/gitblit/tests/DiffUtilsTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void testDiffOutputTypes() throws Exception {
4040
public void testParentCommitDiff() throws Exception {
4141
Repository repository = GitBlitSuite.getHelloworldRepository();
4242
RevCommit commit = JGitUtils.getCommit(repository,
43-
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
43+
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
4444
String diff = DiffUtils.getCommitDiff(repository, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content;
4545
repository.close();
4646
assertTrue(diff != null && diff.length() > 0);
@@ -52,9 +52,9 @@ public void testParentCommitDiff() throws Exception {
5252
public void testArbitraryCommitDiff() throws Exception {
5353
Repository repository = GitBlitSuite.getHelloworldRepository();
5454
RevCommit baseCommit = JGitUtils.getCommit(repository,
55-
"8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
55+
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first));
5656
RevCommit commit = JGitUtils.getCommit(repository,
57-
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
57+
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
5858
String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content;
5959
repository.close();
6060
assertTrue(diff != null && diff.length() > 0);
@@ -66,7 +66,7 @@ public void testArbitraryCommitDiff() throws Exception {
6666
public void testPlainFileDiff() throws Exception {
6767
Repository repository = GitBlitSuite.getHelloworldRepository();
6868
RevCommit commit = JGitUtils.getCommit(repository,
69-
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
69+
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
7070
String diff = DiffUtils.getDiff(repository, commit, "java.java", DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content;
7171
repository.close();
7272
assertTrue(diff != null && diff.length() > 0);
@@ -78,7 +78,7 @@ public void testPlainFileDiff() throws Exception {
7878
public void testFilePatch() throws Exception {
7979
Repository repository = GitBlitSuite.getHelloworldRepository();
8080
RevCommit commit = JGitUtils.getCommit(repository,
81-
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
81+
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
8282
String patch = DiffUtils.getCommitPatch(repository, null, commit, "java.java");
8383
repository.close();
8484
assertTrue(patch != null && patch.length() > 0);
@@ -90,9 +90,9 @@ public void testFilePatch() throws Exception {
9090
public void testArbitraryFilePatch() throws Exception {
9191
Repository repository = GitBlitSuite.getHelloworldRepository();
9292
RevCommit baseCommit = JGitUtils.getCommit(repository,
93-
"8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
93+
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first));
9494
RevCommit commit = JGitUtils.getCommit(repository,
95-
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
95+
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
9696
String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, "java.java");
9797
repository.close();
9898
assertTrue(patch != null && patch.length() > 0);
@@ -104,9 +104,9 @@ public void testArbitraryFilePatch() throws Exception {
104104
public void testArbitraryCommitPatch() throws Exception {
105105
Repository repository = GitBlitSuite.getHelloworldRepository();
106106
RevCommit baseCommit = JGitUtils.getCommit(repository,
107-
"8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
107+
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first));
108108
RevCommit commit = JGitUtils.getCommit(repository,
109-
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
109+
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
110110
String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, null);
111111
repository.close();
112112
assertTrue(patch != null && patch.length() > 0);
@@ -118,9 +118,9 @@ public void testArbitraryCommitPatch() throws Exception {
118118
public void testBlame() throws Exception {
119119
Repository repository = GitBlitSuite.getHelloworldRepository();
120120
List<AnnotatedLine> lines = DiffUtils.blame(repository, "java.java",
121-
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
121+
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
122122
repository.close();
123123
assertTrue(lines.size() > 0);
124-
assertEquals("c6d31dccf5cc75e8e46299fc62d38f60ec6d41e0", lines.get(0).commitId);
124+
assertEquals(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first), lines.get(0).commitId);
125125
}
126126
}

src/test/java/com/gitblit/tests/FederationTests.java

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.gitblit.tests;
1717

18+
import java.io.IOException;
1819
import java.util.Date;
1920
import java.util.HashMap;
2021
import java.util.List;
@@ -45,6 +46,12 @@ public class FederationTests extends GitblitUnitTest {
4546
String password = GitBlitSuite.password;
4647
String token = "d7cc58921a80b37e0329a4dae2f9af38bf61ef5c";
4748

49+
//test data
50+
static final String testUser = "test";
51+
static final String testUserPwd = "whocares";
52+
static final String testTeam = "testteam";
53+
static final String testTeamRepository = "helloworld.git";
54+
4855
private static final AtomicBoolean started = new AtomicBoolean(false);
4956

5057
@BeforeClass
@@ -54,11 +61,27 @@ public static void startGitblit() throws Exception {
5461

5562
@AfterClass
5663
public static void stopGitblit() throws Exception {
64+
//clean up test user and team if left over
65+
deleteTestUser();
66+
deleteTestTeam();
67+
5768
if (started.get()) {
5869
GitBlitSuite.stopGitblit();
5970
}
6071
}
6172

73+
private static void deleteTestUser() throws IOException {
74+
UserModel user = new UserModel(testUser);
75+
user.password = testUserPwd;
76+
RpcUtils.deleteUser(user, GitBlitSuite.url, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
77+
}
78+
79+
private static void deleteTestTeam() throws IOException {
80+
TeamModel team = new TeamModel(testTeam);
81+
team.addRepositoryPermission(testTeamRepository);
82+
RpcUtils.deleteTeam(team, GitBlitSuite.url, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
83+
}
84+
6285
@Test
6386
public void testProposal() throws Exception {
6487
// create dummy repository data
@@ -121,36 +144,43 @@ public void testPullRepositories() throws Exception {
121144

122145
@Test
123146
public void testPullUsers() throws Exception {
147+
//clean up test user and team left over from previous run, if any
148+
deleteTestUser();
149+
deleteTestTeam();
150+
124151
List<UserModel> users = FederationUtils.getUsers(getRegistration());
125152
assertNotNull(users);
126-
// admin is excluded
127-
assertEquals(0, users.size());
153+
// admin is excluded, hence there should be no other users in the list
154+
assertEquals("Gitblit server still contains " + users + " user account(s).", 0, users.size());
128155

129-
UserModel newUser = new UserModel("test");
130-
newUser.password = "whocares";
156+
UserModel newUser = new UserModel(testUser);
157+
newUser.password = testUserPwd;
131158
assertTrue(RpcUtils.createUser(newUser, url, account, password.toCharArray()));
132159

133-
TeamModel team = new TeamModel("testteam");
134-
team.addUser("test");
135-
team.addRepositoryPermission("helloworld.git");
160+
TeamModel team = new TeamModel(testTeam);
161+
team.addUser(testUser);
162+
team.addRepositoryPermission(testTeamRepository);
136163
assertTrue(RpcUtils.createTeam(team, url, account, password.toCharArray()));
137164

138165
users = FederationUtils.getUsers(getRegistration());
139166
assertNotNull(users);
140167
assertEquals(1, users.size());
141168

142169
newUser = users.get(0);
143-
assertTrue(newUser.isTeamMember("testteam"));
170+
assertTrue(newUser.isTeamMember(testTeam));
144171

145172
assertTrue(RpcUtils.deleteUser(newUser, url, account, password.toCharArray()));
146173
assertTrue(RpcUtils.deleteTeam(team, url, account, password.toCharArray()));
147174
}
148175

149176
@Test
150177
public void testPullTeams() throws Exception {
151-
TeamModel team = new TeamModel("testteam");
152-
team.addUser("test");
153-
team.addRepositoryPermission("helloworld.git");
178+
//clean up test team left over from previous run, if any
179+
deleteTestTeam();
180+
181+
TeamModel team = new TeamModel(testTeam);
182+
team.addUser(testUser);
183+
team.addRepositoryPermission(testTeamRepository);
154184
assertTrue(RpcUtils.createTeam(team, url, account, password.toCharArray()));
155185

156186
List<TeamModel> teams = FederationUtils.getTeams(getRegistration());

0 commit comments

Comments
 (0)