summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Zschocke <florian.zschocke@devolo.de>2019-06-07 22:43:51 +0200
committerFlorian Zschocke <florian.zschocke@devolo.de>2019-06-07 22:43:51 +0200
commite57a8461c0f8cd9fda3e859abdcea93d80879b1d (patch)
tree76816049216a38a0b03f2822eb75b82ac7704e64
parent845de9dbdd4a19ea7d4bd15d66fe9e22a16eae23 (diff)
parentc7bf84f79a03613368447ca87d86f033f0fedb7d (diff)
downloadgitblit-e57a8461c0f8cd9fda3e859abdcea93d80879b1d.tar.gz
gitblit-e57a8461c0f8cd9fda3e859abdcea93d80879b1d.zip
Merge branch 'chirontt-external_repos_zipped' into master.
-rw-r--r--build.xml5
-rw-r--r--src/test/data/.gitignore1
-rw-r--r--src/test/data/ambition.git.zipbin0 -> 199401 bytes
-rw-r--r--src/test/data/gitective.git.zipbin0 -> 2974989 bytes
-rw-r--r--src/test/data/hello-world.git.zipbin0 -> 55129 bytes
-rw-r--r--src/test/data/hello-world.properties9
-rw-r--r--src/test/data/ticgit.git.zipbin0 -> 364736 bytes
-rw-r--r--src/test/java/com/gitblit/tests/.gitignore1
-rw-r--r--src/test/java/com/gitblit/tests/DiffUtilsTest.java22
-rw-r--r--src/test/java/com/gitblit/tests/FederationTests.java52
-rw-r--r--src/test/java/com/gitblit/tests/GitBlitSuite.java94
-rw-r--r--src/test/java/com/gitblit/tests/GitServletTest.java19
-rw-r--r--src/test/java/com/gitblit/tests/GroovyScriptTest.java46
-rw-r--r--src/test/java/com/gitblit/tests/HtpasswdAuthenticationTest.java4
-rw-r--r--src/test/java/com/gitblit/tests/JGitUtilsTest.java11
-rw-r--r--src/test/java/com/gitblit/tests/JsonUtilsTest.java9
-rw-r--r--src/test/java/com/gitblit/tests/MetricUtilsTest.java4
-rw-r--r--src/test/java/com/gitblit/tests/PushLogTest.java41
-rw-r--r--src/test/java/com/gitblit/tests/RpcTests.java15
-rw-r--r--src/test/java/com/gitblit/tests/TicketReferenceTest.java21
-rw-r--r--src/test/java/com/gitblit/tests/TicketServiceTest.java6
-rw-r--r--src/test/java/com/gitblit/tests/UITicketTest.java35
22 files changed, 259 insertions, 136 deletions
diff --git a/build.xml b/build.xml
index f3414d7f..4db5d9f1 100644
--- a/build.xml
+++ b/build.xml
@@ -132,6 +132,11 @@
-->
<target name="test" depends="compile" description="compiles Gitblit from source and runs unit tests">
+ <!-- Generate the HelloworldKeys class from the hello-world.properties file -->
+ <mx:keys propertiesfile="${basedir}/src/test/data/hello-world.properties"
+ outputclass="com.gitblit.tests.HelloworldKeys"
+ todir="${basedir}/src/test/java" />
+
<!-- Compile unit tests -->
<mx:javac scope="test" />
diff --git a/src/test/data/.gitignore b/src/test/data/.gitignore
new file mode 100644
index 00000000..7056b036
--- /dev/null
+++ b/src/test/data/.gitignore
@@ -0,0 +1 @@
+/*.git/
diff --git a/src/test/data/ambition.git.zip b/src/test/data/ambition.git.zip
new file mode 100644
index 00000000..9aaa4997
--- /dev/null
+++ b/src/test/data/ambition.git.zip
Binary files differ
diff --git a/src/test/data/gitective.git.zip b/src/test/data/gitective.git.zip
new file mode 100644
index 00000000..1071d911
--- /dev/null
+++ b/src/test/data/gitective.git.zip
Binary files differ
diff --git a/src/test/data/hello-world.git.zip b/src/test/data/hello-world.git.zip
new file mode 100644
index 00000000..e1057a6b
--- /dev/null
+++ b/src/test/data/hello-world.git.zip
Binary files differ
diff --git a/src/test/data/hello-world.properties b/src/test/data/hello-world.properties
new file mode 100644
index 00000000..99ed126b
--- /dev/null
+++ b/src/test/data/hello-world.properties
@@ -0,0 +1,9 @@
+commit.first=192cdede1cc81da7b393aeb7aba9f88998b04713
+commit.second=8caad51
+commit.fifth=55f6796044dc51f0bb9301f07920f0fb64c3d12c
+commit.fifteen=5ebfaca
+commit.added=192cded
+commit.changed=b2c50ce
+commit.deleted=8613bee10bde27a0fbaca66447cdc3f0f9483365
+users.byEmail=9
+users.byName=8
diff --git a/src/test/data/ticgit.git.zip b/src/test/data/ticgit.git.zip
new file mode 100644
index 00000000..18df11cc
--- /dev/null
+++ b/src/test/data/ticgit.git.zip
Binary files differ
diff --git a/src/test/java/com/gitblit/tests/.gitignore b/src/test/java/com/gitblit/tests/.gitignore
new file mode 100644
index 00000000..44874597
--- /dev/null
+++ b/src/test/java/com/gitblit/tests/.gitignore
@@ -0,0 +1 @@
+/HelloworldKeys.java
diff --git a/src/test/java/com/gitblit/tests/DiffUtilsTest.java b/src/test/java/com/gitblit/tests/DiffUtilsTest.java
index e8e839a5..9ba7202f 100644
--- a/src/test/java/com/gitblit/tests/DiffUtilsTest.java
+++ b/src/test/java/com/gitblit/tests/DiffUtilsTest.java
@@ -40,7 +40,7 @@ public class DiffUtilsTest extends GitblitUnitTest {
public void testParentCommitDiff() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit commit = JGitUtils.getCommit(repository,
- "1d0c2933a4ae69c362f76797d42d6bd182d05176");
+ GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String diff = DiffUtils.getCommitDiff(repository, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content;
repository.close();
assertTrue(diff != null && diff.length() > 0);
@@ -52,9 +52,9 @@ public class DiffUtilsTest extends GitblitUnitTest {
public void testArbitraryCommitDiff() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit baseCommit = JGitUtils.getCommit(repository,
- "8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
+ GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first));
RevCommit commit = JGitUtils.getCommit(repository,
- "1d0c2933a4ae69c362f76797d42d6bd182d05176");
+ GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content;
repository.close();
assertTrue(diff != null && diff.length() > 0);
@@ -66,7 +66,7 @@ public class DiffUtilsTest extends GitblitUnitTest {
public void testPlainFileDiff() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit commit = JGitUtils.getCommit(repository,
- "1d0c2933a4ae69c362f76797d42d6bd182d05176");
+ GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String diff = DiffUtils.getDiff(repository, commit, "java.java", DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content;
repository.close();
assertTrue(diff != null && diff.length() > 0);
@@ -78,7 +78,7 @@ public class DiffUtilsTest extends GitblitUnitTest {
public void testFilePatch() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit commit = JGitUtils.getCommit(repository,
- "1d0c2933a4ae69c362f76797d42d6bd182d05176");
+ GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String patch = DiffUtils.getCommitPatch(repository, null, commit, "java.java");
repository.close();
assertTrue(patch != null && patch.length() > 0);
@@ -90,9 +90,9 @@ public class DiffUtilsTest extends GitblitUnitTest {
public void testArbitraryFilePatch() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit baseCommit = JGitUtils.getCommit(repository,
- "8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
+ GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first));
RevCommit commit = JGitUtils.getCommit(repository,
- "1d0c2933a4ae69c362f76797d42d6bd182d05176");
+ GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, "java.java");
repository.close();
assertTrue(patch != null && patch.length() > 0);
@@ -104,9 +104,9 @@ public class DiffUtilsTest extends GitblitUnitTest {
public void testArbitraryCommitPatch() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit baseCommit = JGitUtils.getCommit(repository,
- "8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
+ GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first));
RevCommit commit = JGitUtils.getCommit(repository,
- "1d0c2933a4ae69c362f76797d42d6bd182d05176");
+ GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, null);
repository.close();
assertTrue(patch != null && patch.length() > 0);
@@ -118,9 +118,9 @@ public class DiffUtilsTest extends GitblitUnitTest {
public void testBlame() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository();
List<AnnotatedLine> lines = DiffUtils.blame(repository, "java.java",
- "1d0c2933a4ae69c362f76797d42d6bd182d05176");
+ GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
repository.close();
assertTrue(lines.size() > 0);
- assertEquals("c6d31dccf5cc75e8e46299fc62d38f60ec6d41e0", lines.get(0).commitId);
+ assertEquals(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first), lines.get(0).commitId);
}
}
diff --git a/src/test/java/com/gitblit/tests/FederationTests.java b/src/test/java/com/gitblit/tests/FederationTests.java
index 144fe3da..36ea56c3 100644
--- a/src/test/java/com/gitblit/tests/FederationTests.java
+++ b/src/test/java/com/gitblit/tests/FederationTests.java
@@ -15,6 +15,7 @@
*/
package com.gitblit.tests;
+import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -45,6 +46,12 @@ public class FederationTests extends GitblitUnitTest {
String password = GitBlitSuite.password;
String token = "d7cc58921a80b37e0329a4dae2f9af38bf61ef5c";
+ //test data
+ static final String testUser = "test";
+ static final String testUserPwd = "whocares";
+ static final String testTeam = "testteam";
+ static final String testTeamRepository = "helloworld.git";
+
private static final AtomicBoolean started = new AtomicBoolean(false);
@BeforeClass
@@ -54,11 +61,27 @@ public class FederationTests extends GitblitUnitTest {
@AfterClass
public static void stopGitblit() throws Exception {
+ //clean up test user and team if left over
+ deleteTestUser();
+ deleteTestTeam();
+
if (started.get()) {
GitBlitSuite.stopGitblit();
}
}
+ private static void deleteTestUser() throws IOException {
+ UserModel user = new UserModel(testUser);
+ user.password = testUserPwd;
+ RpcUtils.deleteUser(user, GitBlitSuite.url, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
+ }
+
+ private static void deleteTestTeam() throws IOException {
+ TeamModel team = new TeamModel(testTeam);
+ team.addRepositoryPermission(testTeamRepository);
+ RpcUtils.deleteTeam(team, GitBlitSuite.url, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
+ }
+
@Test
public void testProposal() throws Exception {
// create dummy repository data
@@ -121,18 +144,22 @@ public class FederationTests extends GitblitUnitTest {
@Test
public void testPullUsers() throws Exception {
+ //clean up test user and team left over from previous run, if any
+ deleteTestUser();
+ deleteTestTeam();
+
List<UserModel> users = FederationUtils.getUsers(getRegistration());
assertNotNull(users);
- // admin is excluded
- assertEquals(0, users.size());
+ // admin is excluded, hence there should be no other users in the list
+ assertEquals("Gitblit server still contains " + users + " user account(s).", 0, users.size());
- UserModel newUser = new UserModel("test");
- newUser.password = "whocares";
+ UserModel newUser = new UserModel(testUser);
+ newUser.password = testUserPwd;
assertTrue(RpcUtils.createUser(newUser, url, account, password.toCharArray()));
- TeamModel team = new TeamModel("testteam");
- team.addUser("test");
- team.addRepositoryPermission("helloworld.git");
+ TeamModel team = new TeamModel(testTeam);
+ team.addUser(testUser);
+ team.addRepositoryPermission(testTeamRepository);
assertTrue(RpcUtils.createTeam(team, url, account, password.toCharArray()));
users = FederationUtils.getUsers(getRegistration());
@@ -140,7 +167,7 @@ public class FederationTests extends GitblitUnitTest {
assertEquals(1, users.size());
newUser = users.get(0);
- assertTrue(newUser.isTeamMember("testteam"));
+ assertTrue(newUser.isTeamMember(testTeam));
assertTrue(RpcUtils.deleteUser(newUser, url, account, password.toCharArray()));
assertTrue(RpcUtils.deleteTeam(team, url, account, password.toCharArray()));
@@ -148,9 +175,12 @@ public class FederationTests extends GitblitUnitTest {
@Test
public void testPullTeams() throws Exception {
- TeamModel team = new TeamModel("testteam");
- team.addUser("test");
- team.addRepositoryPermission("helloworld.git");
+ //clean up test team left over from previous run, if any
+ deleteTestTeam();
+
+ TeamModel team = new TeamModel(testTeam);
+ team.addUser(testUser);
+ team.addRepositoryPermission(testTeamRepository);
assertTrue(RpcUtils.createTeam(team, url, account, password.toCharArray()));
List<TeamModel> teams = FederationUtils.getTeams(getRegistration());
diff --git a/src/test/java/com/gitblit/tests/GitBlitSuite.java b/src/test/java/com/gitblit/tests/GitBlitSuite.java
index 133be77f..3292d090 100644
--- a/src/test/java/com/gitblit/tests/GitBlitSuite.java
+++ b/src/test/java/com/gitblit/tests/GitBlitSuite.java
@@ -16,10 +16,15 @@
package com.gitblit.tests;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.lang.reflect.Field;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository;
@@ -27,12 +32,14 @@ import org.eclipse.jgit.lib.RepositoryCache;
import org.eclipse.jgit.lib.RepositoryCache.FileKey;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.FileUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
+import com.gitblit.FileSettings;
import com.gitblit.GitBlitException;
import com.gitblit.GitBlitServer;
import com.gitblit.manager.IRepositoryManager;
@@ -77,6 +84,18 @@ public class GitBlitSuite {
public static final File USERSCONF = new File("src/test/config/test-users.conf");
+ private static final File AMBITION_REPO_SOURCE = new File("src/test/data/ambition.git");
+
+ private static final File TICGIT_REPO_SOURCE = new File("src/test/data/ticgit.git");
+
+ private static final File GITECTIVE_REPO_SOURCE = new File("src/test/data/gitective.git");
+
+ private static final File HELLOWORLD_REPO_SOURCE = new File("src/test/data/hello-world.git");
+
+ private static final File HELLOWORLD_REPO_PROPERTIES = new File("src/test/data/hello-world.properties");
+
+ public static final FileSettings helloworldSettings = new FileSettings(HELLOWORLD_REPO_PROPERTIES.getAbsolutePath());
+
static int port = 8280;
static int gitPort = 8300;
static int shutdownPort = 8281;
@@ -167,17 +186,39 @@ public class GitBlitSuite {
Thread.sleep(5000);
}
+ public static void deleteRefChecksFolder() throws IOException {
+ File refChecks = new File(GitBlitSuite.REPOSITORIES, "refchecks");
+ if (refChecks.exists()) {
+ FileUtils.delete(refChecks, FileUtils.RECURSIVE | FileUtils.RETRY);
+ }
+ }
+
@BeforeClass
public static void setUp() throws Exception {
+ //"refchecks" folder is used in GitServletTest;
+ //need be deleted before Gitblit server instance is started
+ deleteRefChecksFolder();
startGitblit();
if (REPOSITORIES.exists() || REPOSITORIES.mkdirs()) {
- cloneOrFetch("helloworld.git", "https://github.com/git/hello-world.git");
- cloneOrFetch("ticgit.git", "https://github.com/schacon/ticgit.git");
+ if (!HELLOWORLD_REPO_SOURCE.exists()) {
+ unzipRepository(HELLOWORLD_REPO_SOURCE.getPath() + ".zip", HELLOWORLD_REPO_SOURCE.getParentFile());
+ }
+ if (!TICGIT_REPO_SOURCE.exists()) {
+ unzipRepository(TICGIT_REPO_SOURCE.getPath() + ".zip", TICGIT_REPO_SOURCE.getParentFile());
+ }
+ if (!AMBITION_REPO_SOURCE.exists()) {
+ unzipRepository(AMBITION_REPO_SOURCE.getPath() + ".zip", AMBITION_REPO_SOURCE.getParentFile());
+ }
+ if (!GITECTIVE_REPO_SOURCE.exists()) {
+ unzipRepository(GITECTIVE_REPO_SOURCE.getPath() + ".zip", GITECTIVE_REPO_SOURCE.getParentFile());
+ }
+ cloneOrFetch("helloworld.git", HELLOWORLD_REPO_SOURCE.getAbsolutePath());
+ cloneOrFetch("ticgit.git", TICGIT_REPO_SOURCE.getAbsolutePath());
cloneOrFetch("test/jgit.git", "https://github.com/eclipse/jgit.git");
- cloneOrFetch("test/helloworld.git", "https://github.com/git/hello-world.git");
- cloneOrFetch("test/ambition.git", "https://github.com/defunkt/ambition.git");
- cloneOrFetch("test/gitective.git", "https://github.com/kevinsawicki/gitective.git");
+ cloneOrFetch("test/helloworld.git", HELLOWORLD_REPO_SOURCE.getAbsolutePath());
+ cloneOrFetch("test/ambition.git", AMBITION_REPO_SOURCE.getAbsolutePath());
+ cloneOrFetch("test/gitective.git", GITECTIVE_REPO_SOURCE.getAbsolutePath());
showRemoteBranches("ticgit.git");
automaticallyTagBranchTips("ticgit.git");
@@ -254,4 +295,47 @@ public class GitBlitSuite {
r.close();
}
}
+
+ private static void unzipRepository(String zippedRepo, File destDir) throws IOException {
+ System.out.print("Unzipping " + zippedRepo + "... ");
+ if (!destDir.exists()) {
+ destDir.mkdir();
+ }
+ byte[] buffer = new byte[1024];
+ ZipInputStream zis = new ZipInputStream(new FileInputStream(zippedRepo));
+ ZipEntry zipEntry = zis.getNextEntry();
+ while (zipEntry != null) {
+ File newFile = newFile(destDir, zipEntry);
+ if (zipEntry.isDirectory()) {
+ newFile.mkdirs();
+ }
+ else {
+ FileOutputStream fos = new FileOutputStream(newFile);
+ int len;
+ while ((len = zis.read(buffer)) > 0) {
+ fos.write(buffer, 0, len);
+ }
+ fos.close();
+ }
+ zipEntry = zis.getNextEntry();
+ }
+ zis.closeEntry();
+ zis.close();
+ System.out.println("done.");
+ }
+
+ private static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
+ File destFile = new File(destinationDir, zipEntry.getName());
+
+ String destDirPath = destinationDir.getCanonicalPath();
+ String destFilePath = destFile.getCanonicalPath();
+ //guards against writing files to the file system outside of the target folder
+ //to prevent Zip Slip exploit
+ if (!destFilePath.startsWith(destDirPath + File.separator)) {
+ throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
+ }
+
+ return destFile;
+ }
+
}
diff --git a/src/test/java/com/gitblit/tests/GitServletTest.java b/src/test/java/com/gitblit/tests/GitServletTest.java
index 705684a3..f9a1bec4 100644
--- a/src/test/java/com/gitblit/tests/GitServletTest.java
+++ b/src/test/java/com/gitblit/tests/GitServletTest.java
@@ -89,6 +89,9 @@ public class GitServletTest extends GitblitUnitTest {
@BeforeClass
public static void startGitblit() throws Exception {
+ //"refchecks" folder is used in this test class;
+ //need be deleted before Gitblit server instance is started
+ GitBlitSuite.deleteRefChecksFolder();
started.set(GitBlitSuite.startGitblit());
delete(getUser());
@@ -107,19 +110,19 @@ public class GitServletTest extends GitblitUnitTest {
public static void deleteWorkingFolders() throws Exception {
if (ticgitFolder.exists()) {
GitBlitSuite.close(ticgitFolder);
- FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE);
+ FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);
}
if (ticgit2Folder.exists()) {
GitBlitSuite.close(ticgit2Folder);
- FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE);
+ FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE | FileUtils.RETRY);
}
if (jgitFolder.exists()) {
GitBlitSuite.close(jgitFolder);
- FileUtils.delete(jgitFolder, FileUtils.RECURSIVE);
+ FileUtils.delete(jgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);
}
if (jgit2Folder.exists()) {
GitBlitSuite.close(jgit2Folder);
- FileUtils.delete(jgit2Folder, FileUtils.RECURSIVE);
+ FileUtils.delete(jgit2Folder, FileUtils.RECURSIVE | FileUtils.RETRY);
}
}
@@ -400,7 +403,7 @@ public class GitServletTest extends GitblitUnitTest {
// fork from original to a temporary bare repo
File verification = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-committer.git");
if (verification.exists()) {
- FileUtils.delete(verification, FileUtils.RECURSIVE);
+ FileUtils.delete(verification, FileUtils.RECURSIVE | FileUtils.RETRY);
}
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
@@ -485,7 +488,7 @@ public class GitServletTest extends GitblitUnitTest {
// fork from original to a temporary bare repo
File verification = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-committer.git");
if (verification.exists()) {
- FileUtils.delete(verification, FileUtils.RECURSIVE);
+ FileUtils.delete(verification, FileUtils.RECURSIVE | FileUtils.RETRY);
}
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
@@ -630,7 +633,7 @@ public class GitServletTest extends GitblitUnitTest {
// fork from original to a temporary bare repo
File refChecks = new File(GitBlitSuite.REPOSITORIES, forkName);
if (refChecks.exists()) {
- FileUtils.delete(refChecks, FileUtils.RECURSIVE);
+ FileUtils.delete(refChecks, FileUtils.RECURSIVE | FileUtils.RETRY);
}
CloneCommand clone = Git.cloneRepository();
clone.setURI(url + "/" + originName);
@@ -663,7 +666,7 @@ public class GitServletTest extends GitblitUnitTest {
// clone temp bare repo to working copy
File local = new File(GitBlitSuite.REPOSITORIES, workingCopy);
if (local.exists()) {
- FileUtils.delete(local, FileUtils.RECURSIVE);
+ FileUtils.delete(local, FileUtils.RECURSIVE | FileUtils.RETRY);
}
clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/{1}", url, model.name));
diff --git a/src/test/java/com/gitblit/tests/GroovyScriptTest.java b/src/test/java/com/gitblit/tests/GroovyScriptTest.java
index ff40972f..81c6c23a 100644
--- a/src/test/java/com/gitblit/tests/GroovyScriptTest.java
+++ b/src/test/java/com/gitblit/tests/GroovyScriptTest.java
@@ -74,11 +74,11 @@ public class GroovyScriptTest extends GitblitUnitTest {
MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId
- .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
- .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
commands.add(new ReceiveCommand(ObjectId
- .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
- .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master2"));
RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");
repository.customFields = new HashMap<String,String>();
@@ -96,11 +96,11 @@ public class GroovyScriptTest extends GitblitUnitTest {
MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId
- .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
- .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
commands.add(new ReceiveCommand(ObjectId
- .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
- .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master2"));
RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");
repository.mailingLists.add("list@helloworld.git");
@@ -121,11 +121,11 @@ public class GroovyScriptTest extends GitblitUnitTest {
MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId
- .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
- .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
commands.add(new ReceiveCommand(ObjectId
- .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
- .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master2"));
RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");
repository.mailingLists.add("list@helloworld.git");
@@ -145,7 +145,7 @@ public class GroovyScriptTest extends GitblitUnitTest {
MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId
- .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
@@ -159,7 +159,7 @@ public class GroovyScriptTest extends GitblitUnitTest {
MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId
- .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/tags/v1.0"));
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/tags/v1.0"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
@@ -174,8 +174,8 @@ public class GroovyScriptTest extends GitblitUnitTest {
MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId
- .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
- .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
@@ -190,7 +190,7 @@ public class GroovyScriptTest extends GitblitUnitTest {
MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
ReceiveCommand command = new ReceiveCommand(ObjectId
- .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(),
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), ObjectId.zeroId(),
"refs/heads/master");
commands.add(command);
@@ -208,7 +208,7 @@ public class GroovyScriptTest extends GitblitUnitTest {
MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId
- .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(),
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), ObjectId.zeroId(),
"refs/heads/other"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
@@ -224,7 +224,7 @@ public class GroovyScriptTest extends GitblitUnitTest {
MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
ReceiveCommand command = new ReceiveCommand(ObjectId
- .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(),
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), ObjectId.zeroId(),
"refs/tags/v1.0");
commands.add(command);
@@ -242,8 +242,8 @@ public class GroovyScriptTest extends GitblitUnitTest {
MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId
- .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
- .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
@@ -262,8 +262,8 @@ public class GroovyScriptTest extends GitblitUnitTest {
MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId
- .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
- .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
+ .fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
diff --git a/src/test/java/com/gitblit/tests/HtpasswdAuthenticationTest.java b/src/test/java/com/gitblit/tests/HtpasswdAuthenticationTest.java
index 26a49b24..40379f7d 100644
--- a/src/test/java/com/gitblit/tests/HtpasswdAuthenticationTest.java
+++ b/src/test/java/com/gitblit/tests/HtpasswdAuthenticationTest.java
@@ -200,11 +200,11 @@ public class HtpasswdAuthenticationTest extends GitblitUnitTest {
public void testAuthenticationManager()
{
MS.put(KEY_SUPPORT_PLAINTEXT_PWD, "true");
- UserModel user = auth.authenticate("user1", "pass1".toCharArray(), null);
+ UserModel user = auth.authenticate("user1", "#externalAccount".toCharArray(), null);
assertNotNull(user);
assertEquals("user1", user.username);
- user = auth.authenticate("user2", "pass2".toCharArray(), null);
+ user = auth.authenticate("user2", "#externalAccount".toCharArray(), null);
assertNotNull(user);
assertEquals("user2", user.username);
diff --git a/src/test/java/com/gitblit/tests/JGitUtilsTest.java b/src/test/java/com/gitblit/tests/JGitUtilsTest.java
index c273e860..b133a8c8 100644
--- a/src/test/java/com/gitblit/tests/JGitUtilsTest.java
+++ b/src/test/java/com/gitblit/tests/JGitUtilsTest.java
@@ -108,7 +108,8 @@ public class JGitUtilsTest extends GitblitUnitTest {
Date firstChange = JGitUtils.getFirstChange(repository, null);
repository.close();
assertNotNull("Could not get first commit!", commit);
- assertEquals("Incorrect first commit!", "f554664a346629dc2b839f7292d06bad2db4aece",
+ assertEquals("Incorrect first commit!",
+ GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first),
commit.getName());
assertTrue(firstChange.equals(new Date(commit.getCommitTime() * 1000L)));
}
@@ -442,10 +443,10 @@ public class JGitUtilsTest extends GitblitUnitTest {
public void testFilesInCommit() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit commit = JGitUtils.getCommit(repository,
- "1d0c2933a4ae69c362f76797d42d6bd182d05176");
+ GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifteen));
List<PathChangeModel> paths = JGitUtils.getFilesInCommit(repository, commit);
- commit = JGitUtils.getCommit(repository, "af0e9b2891fda85afc119f04a69acf7348922830");
+ commit = JGitUtils.getCommit(repository, GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted));
List<PathChangeModel> deletions = JGitUtils.getFilesInCommit(repository, commit);
commit = JGitUtils.getFirstCommit(repository, null);
@@ -537,8 +538,8 @@ public class JGitUtilsTest extends GitblitUnitTest {
public void testRevLogRange() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository();
List<RevCommit> commits = JGitUtils.getRevLog(repository,
- "fbd14fa6d1a01d4aefa1fca725792683800fc67e",
- "85a0e4087b8439c0aa6b1f4f9e08c26052ab7e87");
+ GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second),
+ GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifteen));
repository.close();
assertEquals(14, commits.size());
}
diff --git a/src/test/java/com/gitblit/tests/JsonUtilsTest.java b/src/test/java/com/gitblit/tests/JsonUtilsTest.java
index 1cd31b8b..b9cfc7a6 100644
--- a/src/test/java/com/gitblit/tests/JsonUtilsTest.java
+++ b/src/test/java/com/gitblit/tests/JsonUtilsTest.java
@@ -17,7 +17,7 @@ package com.gitblit.tests;
import java.text.SimpleDateFormat;
import java.util.Date;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Test;
@@ -29,7 +29,8 @@ public class JsonUtilsTest extends GitblitUnitTest {
@Test
public void testSerialization() {
- Map<String, String> map = new HashMap<String, String>();
+ Map<String, String> map = new LinkedHashMap<String, String>();
+ //LinkedHashMap preserves the order of insertion
map.put("a", "alligator");
map.put("b", "bear");
map.put("c", "caterpillar");
@@ -37,7 +38,7 @@ public class JsonUtilsTest extends GitblitUnitTest {
map.put("e", "eagle");
String json = JsonUtils.toJsonString(map);
assertEquals(
- "{\"d\":\"dingo\",\"e\":\"eagle\",\"b\":\"bear\",\"c\":\"caterpillar\",\"a\":\"alligator\"}",
+ "{\"a\":\"alligator\",\"b\":\"bear\",\"c\":\"caterpillar\",\"d\":\"dingo\",\"e\":\"eagle\"}",
json);
Map<String, String> map2 = JsonUtils.fromJsonString(json,
new TypeToken<Map<String, String>>() {
@@ -56,4 +57,4 @@ public class JsonUtilsTest extends GitblitUnitTest {
Date date = new Date();
String name = "myJson";
}
-} \ No newline at end of file
+}
diff --git a/src/test/java/com/gitblit/tests/MetricUtilsTest.java b/src/test/java/com/gitblit/tests/MetricUtilsTest.java
index 4d620ae6..c5b943d4 100644
--- a/src/test/java/com/gitblit/tests/MetricUtilsTest.java
+++ b/src/test/java/com/gitblit/tests/MetricUtilsTest.java
@@ -45,7 +45,7 @@ public class MetricUtilsTest extends GitblitUnitTest {
List<Metric> byEmail = MetricUtils.getAuthorMetrics(repository, null, true);
List<Metric> byName = MetricUtils.getAuthorMetrics(repository, null, false);
repository.close();
- assertEquals("No author metrics found!", 9, byEmail.size());
- assertEquals("No author metrics found!", 8, byName.size());
+ assertEquals("No author metrics found!", GitBlitSuite.helloworldSettings.getInteger(HelloworldKeys.users.byEmail, -1), byEmail.size());
+ assertEquals("No author metrics found!", GitBlitSuite.helloworldSettings.getInteger(HelloworldKeys.users.byName, -1), byName.size());
}
} \ No newline at end of file
diff --git a/src/test/java/com/gitblit/tests/PushLogTest.java b/src/test/java/com/gitblit/tests/PushLogTest.java
deleted file mode 100644
index be097cc4..00000000
--- a/src/test/java/com/gitblit/tests/PushLogTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2013 gitblit.com.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gitblit.tests;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
-import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.lib.RepositoryCache.FileKey;
-import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
-import org.eclipse.jgit.util.FS;
-import org.junit.Test;
-
-import com.gitblit.models.RefLogEntry;
-import com.gitblit.utils.RefLogUtils;
-
-public class PushLogTest extends GitblitUnitTest {
-
- @Test
- public void testPushLog() throws IOException {
- String name = "~james/helloworld.git";
- File gitDir = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, name), FS.DETECTED);
- Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
- List<RefLogEntry> pushes = RefLogUtils.getRefLog(name, repository);
- GitBlitSuite.close(repository);
- }
-} \ No newline at end of file
diff --git a/src/test/java/com/gitblit/tests/RpcTests.java b/src/test/java/com/gitblit/tests/RpcTests.java
index 51b4671b..4c794656 100644
--- a/src/test/java/com/gitblit/tests/RpcTests.java
+++ b/src/test/java/com/gitblit/tests/RpcTests.java
@@ -68,6 +68,11 @@ public class RpcTests extends GitblitUnitTest {
@AfterClass
public static void stopGitblit() throws Exception {
+ //clean up the "A-Team" if left over
+ TeamModel aTeam = new TeamModel("A-Team");
+ aTeam.addRepositoryPermission("helloworld.git");
+ RpcUtils.deleteTeam(aTeam, GitBlitSuite.url, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
+
if (started.get()) {
GitBlitSuite.stopGitblit();
}
@@ -265,11 +270,17 @@ public class RpcTests extends GitblitUnitTest {
@Test
public void testTeamAdministration() throws IOException {
+ //clean up the "A-Team" left over from previous run, if any
+ TeamModel aTeam = new TeamModel("A-Team");
+ aTeam.addRepositoryPermission("helloworld.git");
+ RpcUtils.deleteTeam(aTeam, url, account, password.toCharArray());
+
List<TeamModel> teams = RpcUtils.getTeams(url, account, password.toCharArray());
- assertEquals(1, teams.size());
+ //should be just the admins team
+ assertEquals("In addition to 'admins', too many left-over team(s) in Gitblit server: " + teams, 1, teams.size());
// Create the A-Team
- TeamModel aTeam = new TeamModel("A-Team");
+ aTeam = new TeamModel("A-Team");
aTeam.users.add("admin");
aTeam.addRepositoryPermission("helloworld.git");
assertTrue(RpcUtils.createTeam(aTeam, url, account, password.toCharArray()));
diff --git a/src/test/java/com/gitblit/tests/TicketReferenceTest.java b/src/test/java/com/gitblit/tests/TicketReferenceTest.java
index 59e00c53..827ba59d 100644
--- a/src/test/java/com/gitblit/tests/TicketReferenceTest.java
+++ b/src/test/java/com/gitblit/tests/TicketReferenceTest.java
@@ -57,6 +57,7 @@ import com.gitblit.tickets.ITicketService;
*/
public class TicketReferenceTest extends GitblitUnitTest {
+ static final String repoName = "TicketReferenceTest.git";
static File workingCopy = new File(GitBlitSuite.REPOSITORIES, "working/TicketReferenceTest.git-wc");
static ITicketService ticketService;
@@ -73,13 +74,13 @@ public class TicketReferenceTest extends GitblitUnitTest {
@BeforeClass
public static void configure() throws Exception {
- File repositoryName = new File("TicketReferenceTest.git");;
+ File repositoryName = new File(repoName);
GitBlitSuite.close(repositoryName);
if (repositoryName.exists()) {
FileUtils.delete(repositoryName, FileUtils.RECURSIVE | FileUtils.RETRY);
}
- repo = new RepositoryModel("TicketReferenceTest.git", null, null, null);
+ repo = new RepositoryModel(repoName, null, null, null);
if (gitblit().hasRepository(repo.name)) {
gitblit().deleteRepositoryModel(repo);
@@ -141,7 +142,23 @@ public class TicketReferenceTest extends GitblitUnitTest {
@AfterClass
public static void cleanup() throws Exception {
+ //clean up the test user account if left over
+ if (gitblit().getUserModel(user.username) != null) {
+ gitblit().deleteUser(user.username);
+ }
+
GitBlitSuite.close(git);
+
+ //clean up the TicketReferenceTest.git repo
+ File repositoryName = new File(repoName);
+ GitBlitSuite.close(repositoryName);
+ if (repositoryName.exists()) {
+ FileUtils.delete(repositoryName, FileUtils.RECURSIVE | FileUtils.RETRY);
+ }
+ RepositoryModel repo = new RepositoryModel(repoName, null, null, null);
+ if (gitblit().hasRepository(repo.name)) {
+ gitblit().deleteRepositoryModel(repo);
+ }
}
@Test
diff --git a/src/test/java/com/gitblit/tests/TicketServiceTest.java b/src/test/java/com/gitblit/tests/TicketServiceTest.java
index c654383d..c0d93531 100644
--- a/src/test/java/com/gitblit/tests/TicketServiceTest.java
+++ b/src/test/java/com/gitblit/tests/TicketServiceTest.java
@@ -21,8 +21,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.commons.io.FileUtils;
import org.bouncycastle.util.Arrays;
+import org.eclipse.jgit.util.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -65,7 +65,9 @@ public abstract class TicketServiceTest extends GitblitUnitTest {
protected IStoredSettings getSettings(boolean deleteAll) throws Exception {
File dir = new File(GitBlitSuite.REPOSITORIES, getRepository().name);
if (deleteAll) {
- FileUtils.deleteDirectory(dir);
+ if (dir.exists()) {
+ FileUtils.delete(dir, FileUtils.RECURSIVE | FileUtils.RETRY);
+ }
JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, getRepository().name).close();
}
diff --git a/src/test/java/com/gitblit/tests/UITicketTest.java b/src/test/java/com/gitblit/tests/UITicketTest.java
index e89c32fc..266bee40 100644
--- a/src/test/java/com/gitblit/tests/UITicketTest.java
+++ b/src/test/java/com/gitblit/tests/UITicketTest.java
@@ -16,15 +16,13 @@
package com.gitblit.tests;
import java.io.File;
-import java.util.Date;
+import java.io.IOException;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
-import org.apache.commons.io.FileUtils;
-import org.bouncycastle.util.Arrays;
-import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.util.FileUtils;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
@@ -40,26 +38,16 @@ import com.gitblit.manager.PluginManager;
import com.gitblit.manager.RepositoryManager;
import com.gitblit.manager.RuntimeManager;
import com.gitblit.manager.UserManager;
-import com.gitblit.models.Mailing;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.TicketModel;
-import com.gitblit.models.TicketModel.Attachment;
import com.gitblit.models.TicketModel.Change;
import com.gitblit.models.TicketModel.Field;
-import com.gitblit.models.TicketModel.Patchset;
import com.gitblit.models.TicketModel.Priority;
import com.gitblit.models.TicketModel.Severity;
-import com.gitblit.models.TicketModel.Status;
import com.gitblit.models.TicketModel.Type;
import com.gitblit.tests.mock.MemorySettings;
import com.gitblit.tickets.ITicketService;
-import com.gitblit.tickets.ITicketService.TicketFilter;
-import com.gitblit.tickets.QueryResult;
-import com.gitblit.tickets.TicketIndexer.Lucene;
import com.gitblit.tickets.BranchTicketService;
-import com.gitblit.tickets.TicketLabel;
-import com.gitblit.tickets.TicketMilestone;
-import com.gitblit.tickets.TicketNotifier;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.XssFilter;
import com.gitblit.utils.XssFilter.AllowXssFilter;
@@ -70,7 +58,7 @@ import com.gitblit.utils.XssFilter.AllowXssFilter;
public class UITicketTest extends GitblitUnitTest {
private ITicketService service;
- final String repoName = "UITicketTest.git";
+ static final String repoName = "UITicketTest.git";
final RepositoryModel repo = new RepositoryModel(repoName, null, null, null);
protected ITicketService getService(boolean deleteAll) throws Exception {
@@ -99,7 +87,9 @@ public class UITicketTest extends GitblitUnitTest {
protected IStoredSettings getSettings(boolean deleteAll) throws Exception {
File dir = new File(GitBlitSuite.REPOSITORIES, repoName);
if (deleteAll) {
- FileUtils.deleteDirectory(dir);
+ if (dir.exists()) {
+ FileUtils.delete(dir, FileUtils.RECURSIVE | FileUtils.RETRY);
+ }
JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, repoName).close();
}
@@ -114,6 +104,15 @@ public class UITicketTest extends GitblitUnitTest {
return settings;
}
+ @AfterClass
+ public static void deleteUITicketTestRepo() throws IOException {
+ //delete the UITicketTest.git folder, at end of the test
+ File dir = new File(GitBlitSuite.REPOSITORIES, repoName);
+ if (dir.exists()) {
+ FileUtils.delete(dir, FileUtils.RECURSIVE | FileUtils.RETRY);
+ }
+ }
+
@Before
public void setup() throws Exception {
service = getService(true);
@@ -148,4 +147,4 @@ public class UITicketTest extends GitblitUnitTest {
return change;
}
-} \ No newline at end of file
+}