|
|
@@ -2,7 +2,6 @@ package uk.ac.ic.wlgitbridge;
|
|
|
|
|
|
import org.eclipse.jgit.api.Git;
|
|
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
|
|
-import org.junit.Before;
|
|
|
import org.junit.Rule;
|
|
|
import org.junit.Test;
|
|
|
import org.junit.rules.TemporaryFolder;
|
|
|
@@ -13,64 +12,89 @@ import uk.ac.ic.wlgitbridge.test.state.SnapshotAPIStateBuilder;
|
|
|
import uk.ac.ic.wlgitbridge.test.util.FileUtil;
|
|
|
|
|
|
import java.io.*;
|
|
|
-import java.net.URISyntaxException;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
-import static org.junit.Assert.*;
|
|
|
+
|
|
|
+import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
/**
|
|
|
* Created by Winston on 11/01/15.
|
|
|
*/
|
|
|
public class WLGitBridgeIntegrationTest {
|
|
|
|
|
|
- private MockSnapshotServer server;
|
|
|
private Map<String, Map<String, SnapshotAPIState>> states =
|
|
|
new HashMap<String, Map<String, SnapshotAPIState>>() {{
|
|
|
put("canCloneARepository", new HashMap<String, SnapshotAPIState>() {{
|
|
|
put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/canCloneARepository/state/state.json")).build());
|
|
|
}});
|
|
|
+ put("canCloneMultipleRepositories", new HashMap<String, SnapshotAPIState>() {{
|
|
|
+ put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/canCloneMultipleRepositories/state/state.json")).build());
|
|
|
+ }});
|
|
|
}};
|
|
|
|
|
|
@Rule
|
|
|
public TemporaryFolder folder = new TemporaryFolder();
|
|
|
|
|
|
- @Before
|
|
|
- public void startMockSnapshotAPIServer() throws URISyntaxException {
|
|
|
- server = new MockSnapshotServer(getResource("/").toFile());
|
|
|
- server.start();
|
|
|
- }
|
|
|
-
|
|
|
@Test
|
|
|
public void canCloneARepository() throws IOException, GitAPIException {
|
|
|
+ MockSnapshotServer server = new MockSnapshotServer(3857, getResource("/canCloneARepository").toFile());
|
|
|
+ server.start();
|
|
|
server.setState(states.get("canCloneARepository").get("state"));
|
|
|
WLGitBridgeApplication wlgb = new WLGitBridgeApplication(new String[] {
|
|
|
- makeConfigFile()
|
|
|
+ makeConfigFile(33857, 3857)
|
|
|
});
|
|
|
wlgb.run();
|
|
|
folder.create();
|
|
|
File git = folder.newFolder();
|
|
|
Git.cloneRepository()
|
|
|
- .setURI("http://127.0.0.1:30080/testproj.git")
|
|
|
+ .setURI("http://127.0.0.1:33857/testproj.git")
|
|
|
.setDirectory(git)
|
|
|
.call()
|
|
|
.close();
|
|
|
wlgb.stop();
|
|
|
- assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneARepository/state/repo"), git.toPath()));
|
|
|
+ assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneARepository/state/testproj"), git.toPath()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void canCloneMultipleRepositories() throws IOException, GitAPIException {
|
|
|
+ MockSnapshotServer server = new MockSnapshotServer(3858, getResource("/canCloneMultipleRepositories").toFile());
|
|
|
+ server.start();
|
|
|
+ server.setState(states.get("canCloneMultipleRepositories").get("state"));
|
|
|
+ WLGitBridgeApplication wlgb = new WLGitBridgeApplication(new String[] {
|
|
|
+ makeConfigFile(33858, 3858)
|
|
|
+ });
|
|
|
+ wlgb.run();
|
|
|
+ folder.create();
|
|
|
+ File testproj1 = folder.newFolder();
|
|
|
+ Git.cloneRepository()
|
|
|
+ .setURI("http://127.0.0.1:33858/testproj1.git")
|
|
|
+ .setDirectory(testproj1)
|
|
|
+ .call()
|
|
|
+ .close();
|
|
|
+ File testproj2 = folder.newFolder();
|
|
|
+ Git.cloneRepository()
|
|
|
+ .setURI("http://127.0.0.1:33858/testproj2.git")
|
|
|
+ .setDirectory(testproj2)
|
|
|
+ .call()
|
|
|
+ .close();
|
|
|
+ wlgb.stop();
|
|
|
+ assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneMultipleRepositories/state/testproj1"), testproj1.toPath()));
|
|
|
+ assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneMultipleRepositories/state/testproj2"), testproj2.toPath()));
|
|
|
}
|
|
|
|
|
|
- private String makeConfigFile() throws IOException {
|
|
|
+ private String makeConfigFile(int port, int apiPort) throws IOException {
|
|
|
File wlgb = folder.newFolder();
|
|
|
File config = folder.newFile();
|
|
|
PrintWriter writer = new PrintWriter(config);
|
|
|
writer.println("{\n" +
|
|
|
- "\t\"port\": 30080,\n" +
|
|
|
+ "\t\"port\": " + port + ",\n" +
|
|
|
"\t\"rootGitDirectory\": \"" + wlgb.getAbsolutePath() + "\",\n" +
|
|
|
- "\t\"apiBaseUrl\": \"http://127.0.0.1:60000/api/v0\",\n" +
|
|
|
+ "\t\"apiBaseUrl\": \"http://127.0.0.1:" + apiPort + "/api/v0\",\n" +
|
|
|
"\t\"username\": \"\",\n" +
|
|
|
"\t\"password\": \"\",\n" +
|
|
|
- "\t\"postbackBaseUrl\": \"http://127.0.0.1:30080\",\n" +
|
|
|
+ "\t\"postbackBaseUrl\": \"http://127.0.0.1:" + port + "\",\n" +
|
|
|
"\t\"serviceName\": \"Overleaf\"\n" +
|
|
|
"}\n");
|
|
|
writer.close();
|