Added canCloneMultipleRepositories integration test.

This commit is contained in:
Winston Li 2015-01-11 15:21:11 +00:00
parent 3a63d9c225
commit 984969b155
15 changed files with 171 additions and 24 deletions

View file

@ -11,7 +11,7 @@ import java.io.File;
public class Main {
public static void main(String[] args) {
MockSnapshotServer server = new MockSnapshotServer(new File("/Users/Roxy/Code/java/writelatex-git-bridge"));
MockSnapshotServer server = new MockSnapshotServer(60000, new File("/Users/Roxy/Code/java/writelatex-git-bridge"));
server.setState(new SnapshotAPIState());
server.start();
}

View file

@ -19,8 +19,8 @@ public class MockSnapshotServer {
private final SnapshotResponseBuilder responseBuilder;
private int port;
public MockSnapshotServer(File resourceBase) {
server = new Server(60000);
public MockSnapshotServer(int port, File resourceBase) {
server = new Server(port);
responseBuilder = new SnapshotResponseBuilder();
server.setHandler(getHandlerForResourceBase(resourceBase));
}

View file

@ -36,7 +36,13 @@ public class FileUtil {
public static boolean gitDirectoriesAreEqual(Path dir1, Path dir2) {
Set<String> dir1Contents = getAllFilesRecursivelyInDirectoryApartFrom(dir1, dir1.resolve(".git"));
Set<String> dir2Contents = getAllFilesRecursivelyInDirectoryApartFrom(dir2, dir2.resolve(".git"));
return dir1Contents.equals(dir2Contents) && directoryContentsEqual(dir1Contents, dir1, dir2);
boolean filesEqual = dir1Contents.equals(dir2Contents);
if (!filesEqual) {
System.out.println("Not equal: (" + dir1Contents + ", " + dir2Contents + ")");
System.out.println(dir1 + ": " + dir1Contents);
System.out.println(dir2 + ": " + dir2Contents);
}
return filesEqual && directoryContentsEqual(dir1Contents, dir1, dir2);
}
static boolean directoryContentsEqual(Set<String> dirContents, Path dir1, Path dir2) {

View file

@ -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()));
}
private String makeConfigFile() throws IOException {
@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(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();

View file

@ -21,7 +21,7 @@
"versionID": 1,
"srcs": [
{
"content": "content",
"content": "content\n",
"path": "main.tex"
},
{
@ -31,7 +31,7 @@
],
"atts": [
{
"url": "http://127.0.0.1:60000/canCloneARepository/state/repo/min_mean_wait_evm_7_eps_150dpi.png",
"url": "http://127.0.0.1:3857/state/testproj/min_mean_wait_evm_7_eps_150dpi.png",
"path": "min_mean_wait_evm_7_eps_150dpi.png"
}
]

@ -0,0 +1 @@
Subproject commit 613ff7782d3aaa92617ce07d6c355ca146d023fa

View file

@ -0,0 +1,90 @@
[
{
"project": "testproj1",
"getDoc": {
"versionID": 1,
"createdAt": "2014-11-30T18:40:58Z",
"email": "jdleesmiller+1@gmail.com",
"name": "John+1"
},
"getSavedVers": [
{
"versionID": 1,
"comment": "added more info on doc GET and error details",
"email": "jdleesmiller+1@gmail.com",
"name": "John+1",
"createdAt": "2014-11-30T18:47:01Z"
}
],
"getForVers": [
{
"versionID": 1,
"srcs": [
{
"content": "content\n",
"path": "main.tex"
},
{
"content": "This text is from another file.",
"path": "foo/bar/test.tex"
}
],
"atts": [
{
"url": "http://127.0.0.1:3858/state/testproj1/overleaf-white-410.png",
"path": "overleaf-white-410.png"
}
]
}
],
"push": "success",
"postback": {
"type": "success",
"versionID": 2
}
},
{
"project": "testproj2",
"getDoc": {
"versionID": 1,
"createdAt": "2014-11-30T18:40:58Z",
"email": "jdleesmiller+1@gmail.com",
"name": "John+1"
},
"getSavedVers": [
{
"versionID": 1,
"comment": "added more info on doc GET and error details",
"email": "jdleesmiller+1@gmail.com",
"name": "John+1",
"createdAt": "2014-11-30T18:47:01Z"
}
],
"getForVers": [
{
"versionID": 1,
"srcs": [
{
"content": "different content\n",
"path": "main.tex"
},
{
"content": "a different one",
"path": "foo/bar/test.tex"
}
],
"atts": [
{
"url": "http://127.0.0.1:3858/state/testproj2/editor-versions-a7e4de19d015c3e7477e3f7eaa6c418e.png",
"path": "editor-versions-a7e4de19d015c3e7477e3f7eaa6c418e.png"
}
]
}
],
"push": "success",
"postback": {
"type": "success",
"versionID": 2
}
}
]

View file

@ -0,0 +1,12 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 404 </title>
</head>
<body>
<h2>HTTP ERROR: 404</h2>
<p>Problem accessing /state/testproj1/overleaf-white-410.png. Reason:
<pre> Not Found</pre></p>
<hr /><i><small>Powered by Jetty://</small></i>
</body>
</html>

View file

@ -0,0 +1,12 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 404 </title>
</head>
<body>
<h2>HTTP ERROR: 404</h2>
<p>Problem accessing /state/testproj2/editor-versions-a7e4de19d015c3e7477e3f7eaa6c418e.png. Reason:
<pre> Not Found</pre></p>
<hr /><i><small>Powered by Jetty://</small></i>
</body>
</html>