\r
public class GitServletTest {\r
\r
- File folder = new File(GitBlitSuite.REPOSITORIES, "working/ticgit");\r
+ static File ticgitFolder = new File(GitBlitSuite.REPOSITORIES, "working/ticgit");\r
\r
- File jgitFolder = new File(GitBlitSuite.REPOSITORIES, "working/jgit");\r
+ static File ticgit2Folder = new File(GitBlitSuite.REPOSITORIES, "working/ticgit2");\r
+\r
+ static File jgitFolder = new File(GitBlitSuite.REPOSITORIES, "working/jgit");\r
\r
String url = GitBlitSuite.url;\r
String account = GitBlitSuite.account;\r
\r
@BeforeClass\r
public static void startGitblit() throws Exception {\r
+ deleteWorkingFolders();\r
started.set(GitBlitSuite.startGitblit());\r
}\r
\r
if (started.get()) {\r
GitBlitSuite.stopGitblit();\r
}\r
+ deleteWorkingFolders();\r
+ }\r
+ \r
+ private static void deleteWorkingFolders() throws Exception {\r
+ if (ticgitFolder.exists()) {\r
+ FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE);\r
+ }\r
+ if (ticgit2Folder.exists()) {\r
+ FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE);\r
+ }\r
+ if (jgitFolder.exists()) {\r
+ FileUtils.delete(jgitFolder, FileUtils.RECURSIVE);\r
+ }\r
}\r
\r
@Test\r
public void testClone() throws Exception {\r
- if (folder.exists()) {\r
- FileUtils.delete(folder, FileUtils.RECURSIVE);\r
- }\r
CloneCommand clone = Git.cloneRepository();\r
clone.setURI(MessageFormat.format("{0}/git/ticgit.git", url));\r
- clone.setDirectory(folder);\r
+ clone.setDirectory(ticgitFolder);\r
clone.setBare(false);\r
clone.setCloneAllBranches(true);\r
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password));\r
- clone.call();\r
+ close(clone.call()); \r
assertTrue(true);\r
}\r
\r
model.accessRestriction = AccessRestrictionType.CLONE;\r
GitBlit.self().updateRepositoryModel(model.name, model, false);\r
\r
- // delete any existing working folder\r
- File folder = new File(GitBlitSuite.REPOSITORIES, "working/gitblit");\r
- if (folder.exists()) {\r
- FileUtils.delete(folder, FileUtils.RECURSIVE);\r
- }\r
+ // delete any existing working folder \r
boolean cloned = false;\r
try {\r
CloneCommand clone = Git.cloneRepository();\r
clone.setURI(MessageFormat.format("{0}/git/ticgit.git", url));\r
- clone.setDirectory(folder);\r
+ clone.setDirectory(ticgit2Folder);\r
clone.setBare(false);\r
clone.setCloneAllBranches(true);\r
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider("bogus", "bogus"));\r
- clone.call();\r
+ close(clone.call());\r
cloned = true;\r
} catch (Exception e) {\r
// swallow the exception which we expect\r
\r
@Test\r
public void testAnonymousPush() throws Exception {\r
- Git git = Git.open(folder);\r
- File file = new File(folder, "TODO");\r
- for (int i = 0; i < 3; i++) {\r
- OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true));\r
- BufferedWriter w = new BufferedWriter(os);\r
- w.write("// " + new Date().toString() + "\n");\r
- w.close();\r
- git.add().addFilepattern(file.getName()).call();\r
- git.commit().setMessage("test commit #" + (i + 1)).call();\r
- }\r
+ Git git = Git.open(ticgitFolder);\r
+ File file = new File(ticgitFolder, "TODO");\r
+ OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true));\r
+ BufferedWriter w = new BufferedWriter(os);\r
+ w.write("// " + new Date().toString() + "\n");\r
+ w.close();\r
+ git.add().addFilepattern(file.getName()).call();\r
+ git.commit().setMessage("test commit").call();\r
git.push().setPushAll().call();\r
- git.getRepository().close();\r
+ close(git);\r
}\r
- \r
+\r
@Test\r
public void testSubfolderPush() throws Exception {\r
- if (jgitFolder.exists()) {\r
- FileUtils.delete(jgitFolder, FileUtils.RECURSIVE);\r
- }\r
CloneCommand clone = Git.cloneRepository();\r
clone.setURI(MessageFormat.format("{0}/git/test/jgit.git", url));\r
clone.setDirectory(jgitFolder);\r
clone.setBare(false);\r
clone.setCloneAllBranches(true);\r
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password));\r
- clone.call();\r
+ close(clone.call());\r
assertTrue(true);\r
- \r
+\r
Git git = Git.open(jgitFolder);\r
File file = new File(jgitFolder, "TODO");\r
- for (int i = 0; i < 3; i++) {\r
- OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true));\r
- BufferedWriter w = new BufferedWriter(os);\r
- w.write("// " + new Date().toString() + "\n");\r
- w.close();\r
- git.add().addFilepattern(file.getName()).call();\r
- git.commit().setMessage("test commit #" + (i + 1)).call();\r
- }\r
+ OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true));\r
+ BufferedWriter w = new BufferedWriter(os);\r
+ w.write("// " + new Date().toString() + "\n");\r
+ w.close();\r
+ git.add().addFilepattern(file.getName()).call();\r
+ git.commit().setMessage("test commit").call();\r
git.push().setPushAll().call();\r
- git.getRepository().close();\r
+ close(git);\r
+ }\r
+ \r
+ private void close(Git git) {\r
+ // really close the repository\r
+ // decrement the use counter to 0\r
+ for (int i = 0; i < 2; i++) {\r
+ git.getRepository().close();\r
+ }\r
}\r
}\r