|
|
@@ -1,8 +1,6 @@
|
|
|
package uk.ac.ic.wlgitbridge;
|
|
|
|
|
|
-import org.eclipse.jgit.api.Git;
|
|
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
|
|
-import org.eclipse.jgit.api.errors.TransportException;
|
|
|
import org.junit.Rule;
|
|
|
import org.junit.Test;
|
|
|
import org.junit.rules.TemporaryFolder;
|
|
|
@@ -11,6 +9,7 @@ import uk.ac.ic.wlgitbridge.test.server.MockSnapshotServer;
|
|
|
import uk.ac.ic.wlgitbridge.test.state.SnapshotAPIState;
|
|
|
import uk.ac.ic.wlgitbridge.test.state.SnapshotAPIStateBuilder;
|
|
|
import uk.ac.ic.wlgitbridge.test.util.FileUtil;
|
|
|
+import uk.ac.ic.wlgitbridge.util.Util;
|
|
|
|
|
|
import java.io.*;
|
|
|
import java.nio.file.Path;
|
|
|
@@ -20,7 +19,6 @@ import java.util.Map;
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
-import static org.junit.Assert.fail;
|
|
|
|
|
|
/**
|
|
|
* Created by Winston on 11/01/15.
|
|
|
@@ -62,8 +60,9 @@ public class WLGitBridgeIntegrationTest {
|
|
|
Process git = runtime.exec("git clone http://127.0.0.1:33857/testproj.git", null, dir);
|
|
|
int exitCode = git.waitFor();
|
|
|
wlgb.stop();
|
|
|
+ File testprojDir = new File(dir, "testproj");
|
|
|
assertEquals(0, exitCode);
|
|
|
- assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneARepository/state/testproj"), new File(dir, "testproj").toPath()));
|
|
|
+ assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneARepository/state/testproj"), testprojDir.toPath()));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -81,14 +80,16 @@ public class WLGitBridgeIntegrationTest {
|
|
|
Process git2 = runtime.exec("git clone http://127.0.0.1:33858/testproj2.git", null, dir);
|
|
|
int exitCode2 = git2.waitFor();
|
|
|
wlgb.stop();
|
|
|
+ File testproj1Dir = new File(dir, "testproj1");
|
|
|
+ File testproj2Dir = new File(dir, "testproj2");
|
|
|
assertEquals(0, exitCode1);
|
|
|
- assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneMultipleRepositories/state/testproj1"), new File(dir, "testproj1").toPath()));
|
|
|
+ assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneMultipleRepositories/state/testproj1"), testproj1Dir.toPath()));
|
|
|
assertEquals(0, exitCode2);
|
|
|
- assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneMultipleRepositories/state/testproj2"), new File(dir, "testproj2").toPath()));
|
|
|
+ assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneMultipleRepositories/state/testproj2"), testproj2Dir.toPath()));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void canPullADeletedTexFile() throws IOException, GitAPIException {
|
|
|
+ public void canPullADeletedTexFile() throws IOException, GitAPIException, InterruptedException {
|
|
|
MockSnapshotServer server = new MockSnapshotServer(3860, getResource("/canPullADeletedTexFile").toFile());
|
|
|
server.start();
|
|
|
server.setState(states.get("canPullADeletedTexFile").get("base"));
|
|
|
@@ -96,22 +97,26 @@ public class WLGitBridgeIntegrationTest {
|
|
|
makeConfigFile(33860, 3860)
|
|
|
});
|
|
|
wlgb.run();
|
|
|
- folder.create();
|
|
|
- File git = folder.newFolder();
|
|
|
- Git base = Git.cloneRepository()
|
|
|
- .setURI("http://127.0.0.1:33860/testproj.git")
|
|
|
- .setDirectory(git)
|
|
|
- .call();
|
|
|
- assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullADeletedTexFile/base/testproj"), git.toPath()));
|
|
|
+ File dir = folder.newFolder();
|
|
|
+ Process gitBase = runtime.exec("git clone http://127.0.0.1:33860/testproj.git", null, dir);
|
|
|
+ int exitCodeBase = gitBase.waitFor();
|
|
|
+ File testprojDir = new File(dir, "testproj");
|
|
|
+ assertEquals(0, exitCodeBase);
|
|
|
+ assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullADeletedTexFile/base/testproj"), testprojDir.toPath()));
|
|
|
server.setState(states.get("canPullADeletedTexFile").get("withDeletedTexFile"));
|
|
|
- base.pull().call();
|
|
|
- base.close();
|
|
|
+ Process gitWithDeletedTexFile = runtime.exec("git pull", null, testprojDir);
|
|
|
+ int exitCodeWithDeletedTexFile = gitWithDeletedTexFile.waitFor();
|
|
|
wlgb.stop();
|
|
|
- assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullADeletedTexFile/withDeletedTexFile/testproj"), git.toPath()));
|
|
|
+ assertEquals(0, exitCodeWithDeletedTexFile);
|
|
|
+ assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullADeletedTexFile/withDeletedTexFile/testproj"), testprojDir.toPath()));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private static final String EXPECTED_OUT_PROTECTED =
|
|
|
+ "Cloning into 'protected'...\n" +
|
|
|
+ "fatal: remote error: Your project is protected, and can't be cloned (yet).\n";
|
|
|
@Test
|
|
|
- public void cannotCloneAProtectedProject() throws IOException, GitAPIException {
|
|
|
+ public void cannotCloneAProtectedProject() throws IOException, GitAPIException, InterruptedException {
|
|
|
MockSnapshotServer server = new MockSnapshotServer(3861, getResource("/cannotCloneAProtectedProject").toFile());
|
|
|
server.start();
|
|
|
server.setState(states.get("cannotCloneAProtectedProject").get("state"));
|
|
|
@@ -119,21 +124,13 @@ public class WLGitBridgeIntegrationTest {
|
|
|
makeConfigFile(33861, 3861)
|
|
|
});
|
|
|
wlgb.run();
|
|
|
- folder.create();
|
|
|
- File git = folder.newFolder();
|
|
|
- try {
|
|
|
- Git.cloneRepository()
|
|
|
- .setURI("http://127.0.0.1:33861/protected.git")
|
|
|
- .setDirectory(git)
|
|
|
- .call()
|
|
|
- .close();
|
|
|
- } catch (TransportException e) {
|
|
|
- assertEquals("http://127.0.0.1:33861/protected.git: Your project is protected, and can't be cloned (yet).", e.getMessage());
|
|
|
- return;
|
|
|
- } finally {
|
|
|
- wlgb.stop();
|
|
|
- }
|
|
|
- fail();
|
|
|
+ File dir = folder.newFolder();
|
|
|
+ Process git = runtime.exec("git clone http://127.0.0.1:33861/protected.git", null, dir);
|
|
|
+ String output = Util.fromStream(git.getErrorStream());
|
|
|
+ int exitCode = git.waitFor();
|
|
|
+ assertEquals(128, exitCode);
|
|
|
+ assertEquals(EXPECTED_OUT_PROTECTED, output);
|
|
|
+ wlgb.stop();
|
|
|
}
|
|
|
|
|
|
private String makeConfigFile(int port, int apiPort) throws IOException {
|