Change 2 tests to launch git in separate process.

This commit is contained in:
Winston Li
2015-03-05 15:21:28 +00:00
parent 3d53226853
commit 5df8b2b65f
@@ -27,6 +27,8 @@ import static org.junit.Assert.fail;
*/ */
public class WLGitBridgeIntegrationTest { public class WLGitBridgeIntegrationTest {
private Runtime runtime = Runtime.getRuntime();
private Map<String, Map<String, SnapshotAPIState>> states = private Map<String, Map<String, SnapshotAPIState>> states =
new HashMap<String, Map<String, SnapshotAPIState>>() {{ new HashMap<String, Map<String, SnapshotAPIState>>() {{
put("canCloneARepository", new HashMap<String, SnapshotAPIState>() {{ put("canCloneARepository", new HashMap<String, SnapshotAPIState>() {{
@@ -48,7 +50,7 @@ public class WLGitBridgeIntegrationTest {
public TemporaryFolder folder = new TemporaryFolder(); public TemporaryFolder folder = new TemporaryFolder();
@Test @Test
public void canCloneARepository() throws IOException, GitAPIException { public void canCloneARepository() throws IOException, GitAPIException, InterruptedException {
MockSnapshotServer server = new MockSnapshotServer(3857, getResource("/canCloneARepository").toFile()); MockSnapshotServer server = new MockSnapshotServer(3857, getResource("/canCloneARepository").toFile());
server.start(); server.start();
server.setState(states.get("canCloneARepository").get("state")); server.setState(states.get("canCloneARepository").get("state"));
@@ -56,19 +58,16 @@ public class WLGitBridgeIntegrationTest {
makeConfigFile(33857, 3857) makeConfigFile(33857, 3857)
}); });
wlgb.run(); wlgb.run();
folder.create(); File dir = folder.newFolder();
File git = folder.newFolder(); Process git = runtime.exec("git clone http://127.0.0.1:33857/testproj.git", null, dir);
Git.cloneRepository() int exitCode = git.waitFor();
.setURI("http://127.0.0.1:33857/testproj.git")
.setDirectory(git)
.call()
.close();
wlgb.stop(); wlgb.stop();
assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneARepository/state/testproj"), git.toPath())); assertEquals(0, exitCode);
assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneARepository/state/testproj"), new File(dir, "testproj").toPath()));
} }
@Test @Test
public void canCloneMultipleRepositories() throws IOException, GitAPIException { public void canCloneMultipleRepositories() throws IOException, GitAPIException, InterruptedException {
MockSnapshotServer server = new MockSnapshotServer(3858, getResource("/canCloneMultipleRepositories").toFile()); MockSnapshotServer server = new MockSnapshotServer(3858, getResource("/canCloneMultipleRepositories").toFile());
server.start(); server.start();
server.setState(states.get("canCloneMultipleRepositories").get("state")); server.setState(states.get("canCloneMultipleRepositories").get("state"));
@@ -76,22 +75,16 @@ public class WLGitBridgeIntegrationTest {
makeConfigFile(33858, 3858) makeConfigFile(33858, 3858)
}); });
wlgb.run(); wlgb.run();
folder.create(); File dir = folder.newFolder();
File testproj1 = folder.newFolder(); Process git1 = runtime.exec("git clone http://127.0.0.1:33858/testproj1.git", null, dir);
Git.cloneRepository() int exitCode1 = git1.waitFor();
.setURI("http://127.0.0.1:33858/testproj1.git") Process git2 = runtime.exec("git clone http://127.0.0.1:33858/testproj2.git", null, dir);
.setDirectory(testproj1) int exitCode2 = git2.waitFor();
.call()
.close();
File testproj2 = folder.newFolder();
Git.cloneRepository()
.setURI("http://127.0.0.1:33858/testproj2.git")
.setDirectory(testproj2)
.call()
.close();
wlgb.stop(); wlgb.stop();
assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneMultipleRepositories/state/testproj1"), testproj1.toPath())); assertEquals(0, exitCode1);
assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneMultipleRepositories/state/testproj2"), testproj2.toPath())); assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneMultipleRepositories/state/testproj1"), new File(dir, "testproj1").toPath()));
assertEquals(0, exitCode2);
assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneMultipleRepositories/state/testproj2"), new File(dir, "testproj2").toPath()));
} }
@Test @Test