diff --git a/services/git-bridge/pom.xml b/services/git-bridge/pom.xml index 5f8c991216..351cc054e0 100644 --- a/services/git-bridge/pom.xml +++ b/services/git-bridge/pom.xml @@ -22,6 +22,14 @@ 1.8 + + + + org.apache.maven.plugins + maven-surefire-plugin + + false + diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/servermock/state/SnapshotAPIStateBuilder.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/servermock/state/SnapshotAPIStateBuilder.java index 2204592ca7..cdc305f2c6 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/servermock/state/SnapshotAPIStateBuilder.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/servermock/state/SnapshotAPIStateBuilder.java @@ -83,16 +83,30 @@ public class SnapshotAPIStateBuilder { String projectName, JsonObject jsonGetDoc ) { - getDoc.put( - projectName, - new GetDocResult( - jsonGetDoc.get("error"), - jsonGetDoc.get("versionID").getAsInt(), - jsonGetDoc.get("createdAt").getAsString(), - jsonGetDoc.get("email").getAsString(), - jsonGetDoc.get("name").getAsString() - ) - ); + if (jsonGetDoc.has("migratedFromId")) { + getDoc.put( + projectName, + new GetDocResult( + jsonGetDoc.get("error"), + jsonGetDoc.get("versionID").getAsInt(), + jsonGetDoc.get("createdAt").getAsString(), + jsonGetDoc.get("email").getAsString(), + jsonGetDoc.get("name").getAsString(), + jsonGetDoc.get("migratedFromId").getAsString() + ) + ); + } else { + getDoc.put( + projectName, + new GetDocResult( + jsonGetDoc.get("error"), + jsonGetDoc.get("versionID").getAsInt(), + jsonGetDoc.get("createdAt").getAsString(), + jsonGetDoc.get("email").getAsString(), + jsonGetDoc.get("name").getAsString() + ) + ); + } } private void addGetSavedVersForProject( diff --git a/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeIntegrationTest.java b/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeIntegrationTest.java index dba7989362..0b45431ed9 100644 --- a/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeIntegrationTest.java +++ b/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeIntegrationTest.java @@ -117,6 +117,9 @@ public class WLGitBridgeIntegrationTest { put("pushSubmoduleFailsWithInvalidGitRepo", new HashMap() {{ put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/pushSubmoduleFailsWithInvalidGitRepo/state/state.json")).build()); }}); + put("canMigrateRepository", new HashMap() {{ + put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/canMigrateRepository/state/state.json")).build()); + }}); }}; @Rule @@ -787,6 +790,24 @@ public class WLGitBridgeIntegrationTest { assertNotEquals(0, gitProcess.waitFor()); } + @Test + public void canMigrateRepository() throws IOException, GitAPIException, InterruptedException { + int gitBridgePort = 33881; + int mockServerPort = 3881; + MockSnapshotServer server = new MockSnapshotServer(mockServerPort, getResource("/canMigrateRepository").toFile()); + server.start(); + server.setState(states.get("canMigrateRepository").get("state")); + GitBridgeApp wlgb = new GitBridgeApp(new String[] { + makeConfigFile(gitBridgePort, mockServerPort) + }); + wlgb.run(); + File testprojDir = gitClone("testproj", gitBridgePort, dir); + File testprojDir2 = gitClone("testproj2", gitBridgePort, dir); + wlgb.stop(); + + assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canMigrateRepository/state/testproj"), testprojDir2.toPath())); + } + private String makeConfigFile( int port, int apiPort diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canMigrateRepository/state/state.json b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canMigrateRepository/state/state.json new file mode 100644 index 0000000000..895cd6ea76 --- /dev/null +++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canMigrateRepository/state/state.json @@ -0,0 +1,83 @@ +[ + { + "project": "testproj2", + "getDoc": { + "versionID": 1, + "createdAt": "2014-11-30T18:40:58.123Z", + "email": "jdleesmiller+1@gmail.com", + "name": "John+1", + "migratedFromId": "testproj" + }, + "getSavedVers": [], + "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:3857/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 + } + }, + { + "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:3857/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 + } + } +] diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canMigrateRepository/state/testproj/foo/bar/test.tex b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canMigrateRepository/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/canMigrateRepository/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/canMigrateRepository/state/testproj/main.tex b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canMigrateRepository/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/canMigrateRepository/state/testproj/main.tex @@ -0,0 +1 @@ +content diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canMigrateRepository/state/testproj/min_mean_wait_evm_7_eps_150dpi.png b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canMigrateRepository/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/canMigrateRepository/state/testproj/min_mean_wait_evm_7_eps_150dpi.png differ