diff --git a/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest.java b/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest.java index d02c337b98..274e1f7b01 100644 --- a/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest.java +++ b/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest.java @@ -35,6 +35,9 @@ public class WLGitBridgeIntegrationTest { put("canCloneMultipleRepositories", new HashMap() {{ put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/canCloneMultipleRepositories/state/state.json")).build()); }}); + put("cannotCloneAProtectedProject", new HashMap() {{ + put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/cannotCloneAProtectedProject/state/state.json")).build()); + }}); put("canPullAModifiedTexFile", new HashMap() {{ put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedTexFile/base/state.json")).build()); put("withModifiedTexFile", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedTexFile/withModifiedTexFile/state.json")).build()); @@ -59,8 +62,8 @@ public class WLGitBridgeIntegrationTest { put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullDeletedNestedFiles/base/state.json")).build()); put("withDeletedNestedFiles", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullDeletedNestedFiles/withDeletedNestedFiles/state.json")).build()); }}); - put("cannotCloneAProtectedProject", new HashMap() {{ - put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/cannotCloneAProtectedProject/state/state.json")).build()); + put("canPushFilesSuccessfully", new HashMap() {{ + put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/canPushFilesSuccessfully/state/state.json")).build()); }}); }}; @@ -108,6 +111,28 @@ public class WLGitBridgeIntegrationTest { assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneMultipleRepositories/state/testproj2"), testproj2Dir.toPath())); } + + private static final String EXPECTED_OUT_PROTECTED = + "Cloning into 'protected'...\n" + + "fatal: remote error: Your project is protected, and can't be cloned (yet).\n"; + @Test + public void cannotCloneAProtectedProject() throws IOException, GitAPIException, InterruptedException { + MockSnapshotServer server = new MockSnapshotServer(3861, getResource("/cannotCloneAProtectedProject").toFile()); + server.start(); + server.setState(states.get("cannotCloneAProtectedProject").get("state")); + GitBridgeApp wlgb = new GitBridgeApp(new String[] { + makeConfigFile(33861, 3861) + }); + wlgb.run(); + File dir = folder.newFolder(); + Process git = runtime.exec("git clone http://127.0.0.1:33861/protected.git", null, dir); + String output = Util.fromStream(git.getErrorStream()); + int exitCode = git.waitFor(); + assertEquals(128, exitCode); + assertEquals(EXPECTED_OUT_PROTECTED, output); + wlgb.stop(); + } + @Test public void canPullAModifiedTexFile() throws IOException, GitAPIException, InterruptedException { MockSnapshotServer server = new MockSnapshotServer(3859, getResource("/canPullAModifiedTexFile").toFile()); @@ -246,26 +271,28 @@ public class WLGitBridgeIntegrationTest { assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullDeletedNestedFiles/withDeletedNestedFiles/testproj"), testprojDir.toPath())); } - - private static final String EXPECTED_OUT_PROTECTED = - "Cloning into 'protected'...\n" + - "fatal: remote error: Your project is protected, and can't be cloned (yet).\n"; @Test - public void cannotCloneAProtectedProject() throws IOException, GitAPIException, InterruptedException { - MockSnapshotServer server = new MockSnapshotServer(3861, getResource("/cannotCloneAProtectedProject").toFile()); + public void canPushFilesSuccessfully() throws IOException, GitAPIException, InterruptedException { + MockSnapshotServer server = new MockSnapshotServer(3866, getResource("/canPushFilesSuccessfully").toFile()); server.start(); - server.setState(states.get("cannotCloneAProtectedProject").get("state")); + server.setState(states.get("canPushFilesSuccessfully").get("state")); GitBridgeApp wlgb = new GitBridgeApp(new String[] { - makeConfigFile(33861, 3861) + makeConfigFile(33866, 3866) }); wlgb.run(); File dir = folder.newFolder(); - Process git = runtime.exec("git clone http://127.0.0.1:33861/protected.git", null, dir); - String output = Util.fromStream(git.getErrorStream()); + Process git = runtime.exec("git clone http://127.0.0.1:33866/testproj.git", null, dir); int exitCode = git.waitFor(); - assertEquals(128, exitCode); - assertEquals(EXPECTED_OUT_PROTECTED, output); + File testprojDir = new File(dir, "testproj"); + assertEquals(0, exitCode); + assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPushFilesSuccessfully/state/testproj"), testprojDir.toPath())); + runtime.exec("touch push.tex", null, testprojDir).waitFor(); + runtime.exec("git add -A", null, testprojDir).waitFor(); + runtime.exec("git commit -m \"push\"", null, testprojDir).waitFor(); + Process gitPush = runtime.exec("git push", null, testprojDir); + int pushExitCode = gitPush.waitFor(); wlgb.stop(); + assertEquals(0, pushExitCode); } private String makeConfigFile(int port, int apiPort) throws IOException { diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canCloneARepository/state/testproj/min_mean_wait_evm_7_eps_150dpi.png b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canCloneARepository/state/testproj/min_mean_wait_evm_7_eps_150dpi.png index 77270e6677..74e1fcd990 100644 Binary files a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canCloneARepository/state/testproj/min_mean_wait_evm_7_eps_150dpi.png and b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canCloneARepository/state/testproj/min_mean_wait_evm_7_eps_150dpi.png differ diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPushFilesSuccessfully/state/state.json b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPushFilesSuccessfully/state/state.json new file mode 100644 index 0000000000..112ff2b9ff --- /dev/null +++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPushFilesSuccessfully/state/state.json @@ -0,0 +1,46 @@ +[ + { + "project": "testproj", + "getDoc": { + "versionID": 1, + "createdAt": "2014-11-30T18:40:58.123Z", + "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:01.333Z" + } + ], + "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:3866/state/testproj/min_mean_wait_evm_7_eps_150dpi.png", + "path": "min_mean_wait_evm_7_eps_150dpi.png" + } + ] + } + ], + "push": "success", + "postback": { + "type": "success", + "versionID": 2 + } + } +] \ No newline at end of file diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPushFilesSuccessfully/state/testproj/foo/bar/test.tex b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPushFilesSuccessfully/state/testproj/foo/bar/test.tex new file mode 100644 index 0000000000..046794f19a --- /dev/null +++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPushFilesSuccessfully/state/testproj/foo/bar/test.tex @@ -0,0 +1 @@ +This text is from another file. \ No newline at end of file diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPushFilesSuccessfully/state/testproj/main.tex b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPushFilesSuccessfully/state/testproj/main.tex new file mode 100644 index 0000000000..d95f3ad14d --- /dev/null +++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPushFilesSuccessfully/state/testproj/main.tex @@ -0,0 +1 @@ +content diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPushFilesSuccessfully/state/testproj/min_mean_wait_evm_7_eps_150dpi.png b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPushFilesSuccessfully/state/testproj/min_mean_wait_evm_7_eps_150dpi.png new file mode 100644 index 0000000000..74e1fcd990 Binary files /dev/null and b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPushFilesSuccessfully/state/testproj/min_mean_wait_evm_7_eps_150dpi.png differ