mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-25 10:10:08 +02:00
Moved directory.
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
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;
|
||||
import uk.ac.ic.wlgitbridge.application.WLGitBridgeApplication;
|
||||
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 java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
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.assertTrue;
|
||||
|
||||
/**
|
||||
* Created by Winston on 11/01/15.
|
||||
*/
|
||||
public class WLGitBridgeIT {
|
||||
|
||||
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());
|
||||
}});
|
||||
}};
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
@Before
|
||||
public void startMockSnapshotAPIServer() throws URISyntaxException {
|
||||
server = new MockSnapshotServer(Paths.get(getClass().getResource("/uk/ac/ic/wlgitbridge/WLGitBridgeIT/").toURI()).toFile());
|
||||
server.start();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canCloneARepository() throws IOException, GitAPIException {
|
||||
server.setState(states.get("canCloneARepository").get("state"));
|
||||
WLGitBridgeApplication wlgb = new WLGitBridgeApplication(new String[] {
|
||||
makeConfigFile()
|
||||
});
|
||||
wlgb.run();
|
||||
folder.create();
|
||||
File git = folder.newFolder();
|
||||
Git.cloneRepository()
|
||||
.setURI("http://127.0.0.1:30080/testproj.git")
|
||||
.setDirectory(git)
|
||||
.call()
|
||||
.close();
|
||||
wlgb.stop();
|
||||
assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneARepository/state/git"), git.toPath()));
|
||||
}
|
||||
|
||||
private String makeConfigFile() throws IOException {
|
||||
File wlgb = folder.newFolder();
|
||||
File config = folder.newFile();
|
||||
PrintWriter writer = new PrintWriter(config);
|
||||
writer.println("{\n" +
|
||||
"\t\"port\": 30080,\n" +
|
||||
"\t\"rootGitDirectory\": \"" + wlgb.getAbsolutePath() + "\",\n" +
|
||||
"\t\"apiBaseUrl\": \"http://127.0.0.1:60000/api/v0\",\n" +
|
||||
"\t\"username\": \"\",\n" +
|
||||
"\t\"password\": \"\",\n" +
|
||||
"\t\"postbackBaseUrl\": \"http://127.0.0.1:30080\",\n" +
|
||||
"\t\"serviceName\": \"Overleaf\"\n" +
|
||||
"}\n");
|
||||
writer.close();
|
||||
return config.getAbsolutePath();
|
||||
}
|
||||
|
||||
private Path getResource(String path) {
|
||||
try {
|
||||
return Paths.get(getClass().getResource("/uk/ac/ic/wlgitbridge/WLGitBridgeIT" + path).toURI());
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private InputStream getResourceAsStream(String path) {
|
||||
return getClass().getResourceAsStream("/uk/ac/ic/wlgitbridge/WLGitBridgeIT" + path);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user