You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GitServletTest.java 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package com.gitblit.tests;
  2. import java.io.BufferedWriter;
  3. import java.io.File;
  4. import java.io.FileOutputStream;
  5. import java.io.OutputStreamWriter;
  6. import java.text.MessageFormat;
  7. import java.util.Date;
  8. import java.util.concurrent.Executors;
  9. import org.eclipse.jgit.api.CloneCommand;
  10. import org.eclipse.jgit.api.Git;
  11. import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
  12. import org.eclipse.jgit.util.FileUtils;
  13. import org.junit.AfterClass;
  14. import org.junit.BeforeClass;
  15. import org.junit.Test;
  16. import com.gitblit.GitBlitServer;
  17. public class GitServletTest {
  18. File folder = new File(GitBlitSuite.REPOSITORIES, "working/ticgit");
  19. static int port = 8180;
  20. static int shutdownPort = 8181;
  21. @BeforeClass
  22. public static void startGitblit() throws Exception {
  23. // Start a Gitblit instance
  24. Executors.newSingleThreadExecutor().execute(new Runnable() {
  25. public void run() {
  26. GitBlitServer.main("--httpPort", "" + port, "--httpsPort", "0", "--shutdownPort",
  27. "" + shutdownPort, "--repositoriesFolder",
  28. "\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService",
  29. "distrib/users.conf");
  30. }
  31. });
  32. // Wait a few seconds for it to be running
  33. Thread.sleep(2500);
  34. }
  35. @AfterClass
  36. public static void stopGitblit() throws Exception {
  37. // Stop Gitblit
  38. GitBlitServer.main("--stop", "--shutdownPort", "" + shutdownPort);
  39. // Wait a few seconds for it to be running
  40. Thread.sleep(2500);
  41. }
  42. @Test
  43. public void testClone() throws Exception {
  44. if (folder.exists()) {
  45. FileUtils.delete(folder, FileUtils.RECURSIVE);
  46. }
  47. CloneCommand clone = Git.cloneRepository();
  48. clone.setURI(MessageFormat.format("http://localhost:{0,number,#}/git/ticgit.git", port));
  49. clone.setDirectory(folder);
  50. clone.setBare(false);
  51. clone.setCloneAllBranches(true);
  52. clone.call();
  53. }
  54. @Test
  55. public void testAnonymousCommit() throws Exception {
  56. Git git = Git.open(folder);
  57. File file = new File(folder, "TODO");
  58. OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true));
  59. BufferedWriter w = new BufferedWriter(os);
  60. w.write("// " + new Date().toString() + "\n");
  61. w.close();
  62. git.add().addFilepattern(file.getName()).call();
  63. git.commit().setMessage("test commit").call();
  64. git.push().setPushAll().call();
  65. git.getRepository().close();
  66. }
  67. @Test
  68. public void testBogusLoginClone() throws Exception {
  69. File folder = new File(GitBlitSuite.REPOSITORIES, "working/gitblit");
  70. if (folder.exists()) {
  71. FileUtils.delete(folder, FileUtils.RECURSIVE);
  72. }
  73. CloneCommand clone = Git.cloneRepository();
  74. clone.setURI(MessageFormat.format("http://localhost:{0,number,#}/git/gitblit.git", port));
  75. clone.setDirectory(folder);
  76. clone.setBare(false);
  77. clone.setCloneAllBranches(true);
  78. clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider("bogus", "bogus"));
  79. clone.call();
  80. }
  81. }