WLGitBridgeIntegrationTest.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. package uk.ac.ic.wlgitbridge;
  2. import org.eclipse.jgit.api.errors.GitAPIException;
  3. import org.junit.Rule;
  4. import org.junit.Test;
  5. import org.junit.rules.TemporaryFolder;
  6. import uk.ac.ic.wlgitbridge.application.GitBridgeApp;
  7. import uk.ac.ic.wlgitbridge.snapshot.servermock.server.MockSnapshotServer;
  8. import uk.ac.ic.wlgitbridge.snapshot.servermock.state.SnapshotAPIState;
  9. import uk.ac.ic.wlgitbridge.snapshot.servermock.state.SnapshotAPIStateBuilder;
  10. import uk.ac.ic.wlgitbridge.snapshot.servermock.util.FileUtil;
  11. import uk.ac.ic.wlgitbridge.util.Util;
  12. import java.io.*;
  13. import java.nio.file.Path;
  14. import java.nio.file.Paths;
  15. import java.util.HashMap;
  16. import java.util.Map;
  17. import static org.junit.Assert.assertEquals;
  18. import static org.junit.Assert.assertTrue;
  19. /**
  20. * Created by Winston on 11/01/15.
  21. */
  22. public class WLGitBridgeIntegrationTest {
  23. private Runtime runtime = Runtime.getRuntime();
  24. private Map<String, Map<String, SnapshotAPIState>> states =
  25. new HashMap<String, Map<String, SnapshotAPIState>>() {{
  26. put("canCloneARepository", new HashMap<String, SnapshotAPIState>() {{
  27. put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/canCloneARepository/state/state.json")).build());
  28. }});
  29. put("canCloneMultipleRepositories", new HashMap<String, SnapshotAPIState>() {{
  30. put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/canCloneMultipleRepositories/state/state.json")).build());
  31. }});
  32. put("cannotCloneAProtectedProject", new HashMap<String, SnapshotAPIState>() {{
  33. put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/cannotCloneAProtectedProject/state/state.json")).build());
  34. }});
  35. put("canPullAModifiedTexFile", new HashMap<String, SnapshotAPIState>() {{
  36. put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedTexFile/base/state.json")).build());
  37. put("withModifiedTexFile", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedTexFile/withModifiedTexFile/state.json")).build());
  38. }});
  39. put("canPullADeletedTexFile", new HashMap<String, SnapshotAPIState>() {{
  40. put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullADeletedTexFile/base/state.json")).build());
  41. put("withDeletedTexFile", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullADeletedTexFile/withDeletedTexFile/state.json")).build());
  42. }});
  43. put("canPullAModifiedBinaryFile", new HashMap<String, SnapshotAPIState>() {{
  44. put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedBinaryFile/base/state.json")).build());
  45. put("withModifiedBinaryFile", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedBinaryFile/withModifiedBinaryFile/state.json")).build());
  46. }});
  47. put("canPullADeletedBinaryFile", new HashMap<String, SnapshotAPIState>() {{
  48. put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullADeletedBinaryFile/base/state.json")).build());
  49. put("withDeletedBinaryFile", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullADeletedBinaryFile/withDeletedBinaryFile/state.json")).build());
  50. }});
  51. put("canPullAModifiedNestedFile", new HashMap<String, SnapshotAPIState>() {{
  52. put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullADeletedBinaryFile/base/state.json")).build());
  53. put("withModifiedNestedFile", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedNestedFile/withModifiedNestedFile/state.json")).build());
  54. }});
  55. put("canPullDeletedNestedFiles", new HashMap<String, SnapshotAPIState>() {{
  56. put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullDeletedNestedFiles/base/state.json")).build());
  57. put("withDeletedNestedFiles", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullDeletedNestedFiles/withDeletedNestedFiles/state.json")).build());
  58. }});
  59. put("canPushFilesSuccessfully", new HashMap<String, SnapshotAPIState>() {{
  60. put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/canPushFilesSuccessfully/state/state.json")).build());
  61. }});
  62. put("pushFailsOnFirstStageOutOfDate", new HashMap<String, SnapshotAPIState>() {{
  63. put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/pushFailsOnFirstStageOutOfDate/state/state.json")).build());
  64. }});
  65. put("pushFailsOnSecondStageOutOfDate", new HashMap<String, SnapshotAPIState>() {{
  66. put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/pushFailsOnSecondStageOutOfDate/state/state.json")).build());
  67. }});
  68. }};
  69. @Rule
  70. public TemporaryFolder folder = new TemporaryFolder();
  71. @Test
  72. public void canCloneARepository() throws IOException, GitAPIException, InterruptedException {
  73. MockSnapshotServer server = new MockSnapshotServer(3857, getResource("/canCloneARepository").toFile());
  74. server.start();
  75. server.setState(states.get("canCloneARepository").get("state"));
  76. GitBridgeApp wlgb = new GitBridgeApp(new String[] {
  77. makeConfigFile(33857, 3857)
  78. });
  79. wlgb.run();
  80. File dir = folder.newFolder();
  81. Process git = runtime.exec("git clone http://127.0.0.1:33857/testproj.git", null, dir);
  82. int exitCode = git.waitFor();
  83. wlgb.stop();
  84. File testprojDir = new File(dir, "testproj");
  85. assertEquals(0, exitCode);
  86. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneARepository/state/testproj"), testprojDir.toPath()));
  87. }
  88. @Test
  89. public void canCloneMultipleRepositories() throws IOException, GitAPIException, InterruptedException {
  90. MockSnapshotServer server = new MockSnapshotServer(3858, getResource("/canCloneMultipleRepositories").toFile());
  91. server.start();
  92. server.setState(states.get("canCloneMultipleRepositories").get("state"));
  93. GitBridgeApp wlgb = new GitBridgeApp(new String[] {
  94. makeConfigFile(33858, 3858)
  95. });
  96. wlgb.run();
  97. File dir = folder.newFolder();
  98. Process git1 = runtime.exec("git clone http://127.0.0.1:33858/testproj1.git", null, dir);
  99. int exitCode1 = git1.waitFor();
  100. Process git2 = runtime.exec("git clone http://127.0.0.1:33858/testproj2.git", null, dir);
  101. int exitCode2 = git2.waitFor();
  102. wlgb.stop();
  103. File testproj1Dir = new File(dir, "testproj1");
  104. File testproj2Dir = new File(dir, "testproj2");
  105. assertEquals(0, exitCode1);
  106. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneMultipleRepositories/state/testproj1"), testproj1Dir.toPath()));
  107. assertEquals(0, exitCode2);
  108. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneMultipleRepositories/state/testproj2"), testproj2Dir.toPath()));
  109. }
  110. private static final String EXPECTED_OUT_PROTECTED =
  111. "Cloning into 'protected'...\n" +
  112. "fatal: remote error: Your project is protected, and can't be cloned (yet).\n";
  113. @Test
  114. public void cannotCloneAProtectedProject() throws IOException, GitAPIException, InterruptedException {
  115. MockSnapshotServer server = new MockSnapshotServer(3861, getResource("/cannotCloneAProtectedProject").toFile());
  116. server.start();
  117. server.setState(states.get("cannotCloneAProtectedProject").get("state"));
  118. GitBridgeApp wlgb = new GitBridgeApp(new String[] {
  119. makeConfigFile(33861, 3861)
  120. });
  121. wlgb.run();
  122. File dir = folder.newFolder();
  123. Process git = runtime.exec("git clone http://127.0.0.1:33861/protected.git", null, dir);
  124. String output = Util.fromStream(git.getErrorStream());
  125. int exitCode = git.waitFor();
  126. assertEquals(128, exitCode);
  127. assertEquals(EXPECTED_OUT_PROTECTED, output);
  128. wlgb.stop();
  129. }
  130. @Test
  131. public void canPullAModifiedTexFile() throws IOException, GitAPIException, InterruptedException {
  132. MockSnapshotServer server = new MockSnapshotServer(3859, getResource("/canPullAModifiedTexFile").toFile());
  133. server.start();
  134. server.setState(states.get("canPullAModifiedTexFile").get("base"));
  135. GitBridgeApp wlgb = new GitBridgeApp(new String[] {
  136. makeConfigFile(33859, 3859)
  137. });
  138. wlgb.run();
  139. File dir = folder.newFolder();
  140. Process gitBase = runtime.exec("git clone http://127.0.0.1:33859/testproj.git", null, dir);
  141. int exitCodeBase = gitBase.waitFor();
  142. File testprojDir = new File(dir, "testproj");
  143. assertEquals(0, exitCodeBase);
  144. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullAModifiedTexFile/base/testproj"), testprojDir.toPath()));
  145. server.setState(states.get("canPullAModifiedTexFile").get("withModifiedTexFile"));
  146. Process gitWithModifiedTexFile = runtime.exec("git pull", null, testprojDir);
  147. int exitCodeWithModifiedTexFile = gitWithModifiedTexFile.waitFor();
  148. wlgb.stop();
  149. assertEquals(0, exitCodeWithModifiedTexFile);
  150. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullAModifiedTexFile/withModifiedTexFile/testproj"), testprojDir.toPath()));
  151. }
  152. @Test
  153. public void canPullADeletedTexFile() throws IOException, GitAPIException, InterruptedException {
  154. MockSnapshotServer server = new MockSnapshotServer(3860, getResource("/canPullADeletedTexFile").toFile());
  155. server.start();
  156. server.setState(states.get("canPullADeletedTexFile").get("base"));
  157. GitBridgeApp wlgb = new GitBridgeApp(new String[] {
  158. makeConfigFile(33860, 3860)
  159. });
  160. wlgb.run();
  161. File dir = folder.newFolder();
  162. Process gitBase = runtime.exec("git clone http://127.0.0.1:33860/testproj.git", null, dir);
  163. int exitCodeBase = gitBase.waitFor();
  164. File testprojDir = new File(dir, "testproj");
  165. assertEquals(0, exitCodeBase);
  166. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullADeletedTexFile/base/testproj"), testprojDir.toPath()));
  167. server.setState(states.get("canPullADeletedTexFile").get("withDeletedTexFile"));
  168. Process gitWithDeletedTexFile = runtime.exec("git pull", null, testprojDir);
  169. int exitCodeWithDeletedTexFile = gitWithDeletedTexFile.waitFor();
  170. wlgb.stop();
  171. assertEquals(0, exitCodeWithDeletedTexFile);
  172. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullADeletedTexFile/withDeletedTexFile/testproj"), testprojDir.toPath()));
  173. }
  174. @Test
  175. public void canPullAModifiedBinaryFile() throws IOException, GitAPIException, InterruptedException {
  176. MockSnapshotServer server = new MockSnapshotServer(3862, getResource("/canPullAModifiedBinaryFile").toFile());
  177. server.start();
  178. server.setState(states.get("canPullAModifiedBinaryFile").get("base"));
  179. GitBridgeApp wlgb = new GitBridgeApp(new String[] {
  180. makeConfigFile(33862, 3862)
  181. });
  182. wlgb.run();
  183. File dir = folder.newFolder();
  184. Process gitBase = runtime.exec("git clone http://127.0.0.1:33862/testproj.git", null, dir);
  185. int exitCodeBase = gitBase.waitFor();
  186. File testprojDir = new File(dir, "testproj");
  187. assertEquals(0, exitCodeBase);
  188. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullAModifiedBinaryFile/base/testproj"), testprojDir.toPath()));
  189. server.setState(states.get("canPullAModifiedBinaryFile").get("withModifiedBinaryFile"));
  190. Process gitWithModifiedBinaryFile = runtime.exec("git pull", null, testprojDir);
  191. int exitCodeWithModifiedBinaryFile = gitWithModifiedBinaryFile.waitFor();
  192. wlgb.stop();
  193. assertEquals(0, exitCodeWithModifiedBinaryFile);
  194. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullAModifiedBinaryFile/withModifiedBinaryFile/testproj"), testprojDir.toPath()));
  195. }
  196. @Test
  197. public void canPullADeletedBinaryFile() throws IOException, GitAPIException, InterruptedException {
  198. MockSnapshotServer server = new MockSnapshotServer(3863, getResource("/canPullADeletedBinaryFile").toFile());
  199. server.start();
  200. server.setState(states.get("canPullADeletedBinaryFile").get("base"));
  201. GitBridgeApp wlgb = new GitBridgeApp(new String[] {
  202. makeConfigFile(33863, 3863)
  203. });
  204. wlgb.run();
  205. File dir = folder.newFolder();
  206. Process gitBase = runtime.exec("git clone http://127.0.0.1:33863/testproj.git", null, dir);
  207. int exitCodeBase = gitBase.waitFor();
  208. File testprojDir = new File(dir, "testproj");
  209. assertEquals(0, exitCodeBase);
  210. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullADeletedBinaryFile/base/testproj"), testprojDir.toPath()));
  211. server.setState(states.get("canPullADeletedBinaryFile").get("withDeletedBinaryFile"));
  212. Process gitWithDeletedBinaryFile = runtime.exec("git pull", null, testprojDir);
  213. int exitCodeWithDeletedBinaryFile = gitWithDeletedBinaryFile.waitFor();
  214. wlgb.stop();
  215. assertEquals(0, exitCodeWithDeletedBinaryFile);
  216. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullADeletedBinaryFile/withDeletedBinaryFile/testproj"), testprojDir.toPath()));
  217. }
  218. @Test
  219. public void canPullAModifiedNestedFile() throws IOException, GitAPIException, InterruptedException {
  220. MockSnapshotServer server = new MockSnapshotServer(3864, getResource("/canPullAModifiedNestedFile").toFile());
  221. server.start();
  222. server.setState(states.get("canPullAModifiedNestedFile").get("base"));
  223. GitBridgeApp wlgb = new GitBridgeApp(new String[] {
  224. makeConfigFile(33864, 3864)
  225. });
  226. wlgb.run();
  227. File dir = folder.newFolder();
  228. Process gitBase = runtime.exec("git clone http://127.0.0.1:33864/testproj.git", null, dir);
  229. int exitCodeBase = gitBase.waitFor();
  230. File testprojDir = new File(dir, "testproj");
  231. assertEquals(0, exitCodeBase);
  232. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullAModifiedNestedFile/base/testproj"), testprojDir.toPath()));
  233. server.setState(states.get("canPullAModifiedNestedFile").get("withModifiedNestedFile"));
  234. Process gitWithModifiedNestedFile = runtime.exec("git pull", null, testprojDir);
  235. int exitCodeWithModifiedNestedFile = gitWithModifiedNestedFile.waitFor();
  236. wlgb.stop();
  237. assertEquals(0, exitCodeWithModifiedNestedFile);
  238. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullAModifiedNestedFile/withModifiedNestedFile/testproj"), testprojDir.toPath()));
  239. }
  240. @Test
  241. public void canPullDeletedNestedFiles() throws IOException, GitAPIException, InterruptedException {
  242. MockSnapshotServer server = new MockSnapshotServer(3865, getResource("/canPullDeletedNestedFiles").toFile());
  243. server.start();
  244. server.setState(states.get("canPullDeletedNestedFiles").get("base"));
  245. GitBridgeApp wlgb = new GitBridgeApp(new String[] {
  246. makeConfigFile(33865, 3865)
  247. });
  248. wlgb.run();
  249. File dir = folder.newFolder();
  250. Process gitBase = runtime.exec("git clone http://127.0.0.1:33865/testproj.git", null, dir);
  251. int exitCodeBase = gitBase.waitFor();
  252. File testprojDir = new File(dir, "testproj");
  253. assertEquals(0, exitCodeBase);
  254. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullDeletedNestedFiles/base/testproj"), testprojDir.toPath()));
  255. server.setState(states.get("canPullDeletedNestedFiles").get("withDeletedNestedFiles"));
  256. Process gitWithDeletedBinaryFile = runtime.exec("git pull", null, testprojDir);
  257. int exitCodeWithDeletedBinaryFile = gitWithDeletedBinaryFile.waitFor();
  258. wlgb.stop();
  259. assertEquals(0, exitCodeWithDeletedBinaryFile);
  260. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullDeletedNestedFiles/withDeletedNestedFiles/testproj"), testprojDir.toPath()));
  261. }
  262. @Test
  263. public void canPushFilesSuccessfully() throws IOException, GitAPIException, InterruptedException {
  264. MockSnapshotServer server = new MockSnapshotServer(3866, getResource("/canPushFilesSuccessfully").toFile());
  265. server.start();
  266. server.setState(states.get("canPushFilesSuccessfully").get("state"));
  267. GitBridgeApp wlgb = new GitBridgeApp(new String[] {
  268. makeConfigFile(33866, 3866)
  269. });
  270. wlgb.run();
  271. File dir = folder.newFolder();
  272. Process git = runtime.exec("git clone http://127.0.0.1:33866/testproj.git", null, dir);
  273. int exitCode = git.waitFor();
  274. File testprojDir = new File(dir, "testproj");
  275. assertEquals(0, exitCode);
  276. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPushFilesSuccessfully/state/testproj"), testprojDir.toPath()));
  277. runtime.exec("touch push.tex", null, testprojDir).waitFor();
  278. runtime.exec("git add -A", null, testprojDir).waitFor();
  279. runtime.exec("git commit -m \"push\"", null, testprojDir).waitFor();
  280. Process gitPush = runtime.exec("git push", null, testprojDir);
  281. int pushExitCode = gitPush.waitFor();
  282. wlgb.stop();
  283. assertEquals(0, pushExitCode);
  284. }
  285. private static final String EXPECTED_OUT_PUSH_OUT_OF_DATE_FIRST =
  286. "To http://127.0.0.1:33867/testproj.git\n" +
  287. " ! [rejected] master -> master (non-fast-forward)\n" +
  288. "error: failed to push some refs to 'http://127.0.0.1:33867/testproj.git'\n" +
  289. "hint: Updates were rejected because the tip of your current branch is behind\n" +
  290. "hint: its remote counterpart. Integrate the remote changes (e.g.\n" +
  291. "hint: 'git pull ...') before pushing again.\n" +
  292. "hint: See the 'Note about fast-forwards' in 'git push --help' for details.\n";
  293. @Test
  294. public void pushFailsOnFirstStageOutOfDate() throws IOException, GitAPIException, InterruptedException {
  295. MockSnapshotServer server = new MockSnapshotServer(3867, getResource("/pushFailsOnFirstStageOutOfDate").toFile());
  296. server.start();
  297. server.setState(states.get("pushFailsOnFirstStageOutOfDate").get("state"));
  298. GitBridgeApp wlgb = new GitBridgeApp(new String[] {
  299. makeConfigFile(33867, 3867)
  300. });
  301. wlgb.run();
  302. File dir = folder.newFolder();
  303. Process git = runtime.exec("git clone http://127.0.0.1:33867/testproj.git", null, dir);
  304. int exitCode = git.waitFor();
  305. File testprojDir = new File(dir, "testproj");
  306. assertEquals(0, exitCode);
  307. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/pushFailsOnFirstStageOutOfDate/state/testproj"), testprojDir.toPath()));
  308. runtime.exec("touch push.tex", null, testprojDir).waitFor();
  309. runtime.exec("git add -A", null, testprojDir).waitFor();
  310. runtime.exec("git commit -m \"push\"", null, testprojDir).waitFor();
  311. Process gitPush = runtime.exec("git push", null, testprojDir);
  312. gitPush.waitFor();
  313. wlgb.stop();
  314. assertEquals(EXPECTED_OUT_PUSH_OUT_OF_DATE_FIRST, Util.fromStream(gitPush.getErrorStream(), 2));
  315. }
  316. private static final String EXPECTED_OUT_PUSH_OUT_OF_DATE_SECOND =
  317. "To http://127.0.0.1:33868/testproj.git\n" +
  318. " ! [rejected] master -> master (non-fast-forward)\n" +
  319. "error: failed to push some refs to 'http://127.0.0.1:33868/testproj.git'\n" +
  320. "hint: Updates were rejected because the tip of your current branch is behind\n" +
  321. "hint: its remote counterpart. Integrate the remote changes (e.g.\n" +
  322. "hint: 'git pull ...') before pushing again.\n" +
  323. "hint: See the 'Note about fast-forwards' in 'git push --help' for details.\n";
  324. @Test
  325. public void pushFailsOnSecondStageOutOfDate() throws IOException, GitAPIException, InterruptedException {
  326. MockSnapshotServer server = new MockSnapshotServer(3868, getResource("/pushFailsOnSecondStageOutOfDate").toFile());
  327. server.start();
  328. server.setState(states.get("pushFailsOnSecondStageOutOfDate").get("state"));
  329. GitBridgeApp wlgb = new GitBridgeApp(new String[] {
  330. makeConfigFile(33868, 3868)
  331. });
  332. wlgb.run();
  333. File dir = folder.newFolder();
  334. Process git = runtime.exec("git clone http://127.0.0.1:33868/testproj.git", null, dir);
  335. int exitCode = git.waitFor();
  336. File testprojDir = new File(dir, "testproj");
  337. assertEquals(0, exitCode);
  338. assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/pushFailsOnSecondStageOutOfDate/state/testproj"), testprojDir.toPath()));
  339. runtime.exec("touch push.tex", null, testprojDir).waitFor();
  340. runtime.exec("git add -A", null, testprojDir).waitFor();
  341. runtime.exec("git commit -m \"push\"", null, testprojDir).waitFor();
  342. Process gitPush = runtime.exec("git push", null, testprojDir);
  343. gitPush.waitFor();
  344. wlgb.stop();
  345. assertEquals(EXPECTED_OUT_PUSH_OUT_OF_DATE_SECOND, Util.fromStream(gitPush.getErrorStream(), 2));
  346. }
  347. private String makeConfigFile(int port, int apiPort) throws IOException {
  348. File wlgb = folder.newFolder();
  349. File config = folder.newFile();
  350. PrintWriter writer = new PrintWriter(config);
  351. writer.println("{\n" +
  352. "\t\"port\": " + port + ",\n" +
  353. "\t\"rootGitDirectory\": \"" + wlgb.getAbsolutePath() + "\",\n" +
  354. "\t\"apiBaseUrl\": \"http://127.0.0.1:" + apiPort + "/api/v0\",\n" +
  355. "\t\"username\": \"\",\n" +
  356. "\t\"password\": \"\",\n" +
  357. "\t\"postbackBaseUrl\": \"http://127.0.0.1:" + port + "\",\n" +
  358. "\t\"serviceName\": \"Overleaf\"\n" +
  359. "}\n");
  360. writer.close();
  361. return config.getAbsolutePath();
  362. }
  363. private Path getResource(String path) {
  364. return Paths.get("src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest" + path);
  365. }
  366. private InputStream getResourceAsStream(String path) {
  367. try {
  368. return new FileInputStream(getResource(path).toFile());
  369. } catch (FileNotFoundException e) {
  370. throw new RuntimeException(e);
  371. }
  372. }
  373. }