Просмотр исходного кода

pushFailsOnInvalidProject integration test.

Winston Li 11 лет назад
Родитель
Сommit
a0eb4b0946

+ 9 - 0
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/servermock/response/push/postback/SnapshotPostbackRequestInvalidProject.java

@@ -1,9 +1,11 @@
 package uk.ac.ic.wlgitbridge.snapshot.servermock.response.push.postback;
 
 import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import com.google.gson.JsonPrimitive;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -18,6 +20,13 @@ public class SnapshotPostbackRequestInvalidProject extends SnapshotPostbackReque
         this.errors = errors;
     }
 
+    public SnapshotPostbackRequestInvalidProject(JsonArray errors) {
+        this(new ArrayList<String>());
+        for (JsonElement error : errors) {
+            this.errors.add(error.getAsString());
+        }
+    }
+
     @Override
     public JsonObject toJson() {
         JsonObject jsonThis = super.toJson();

+ 1 - 1
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/servermock/state/SnapshotAPIStateBuilder.java

@@ -140,7 +140,7 @@ public class SnapshotAPIStateBuilder {
         } else if (type.equals("invalidFiles")) {
             p = new SnapshotPostbackRequestInvalidFiles(jsonPostback.get("errors").getAsJsonArray());
         } else if (type.equals("invalidProject")) {
-            p = new SnapshotPostbackRequestInvalidProject(new LinkedList<String>());
+            p = new SnapshotPostbackRequestInvalidProject(jsonPostback.get("errors").getAsJsonArray());
         } else if (type.equals("error")) {
             p = new SnapshotPostbackRequestError();
         } else {

+ 40 - 0
services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest.java

@@ -76,6 +76,9 @@ public class WLGitBridgeIntegrationTest {
                 put("pushFailsOnInvalidFiles", new HashMap<String, SnapshotAPIState>() {{
                     put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/pushFailsOnInvalidFiles/state/state.json")).build());
                 }});
+                put("pushFailsOnInvalidProject", new HashMap<String, SnapshotAPIState>() {{
+                    put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/pushFailsOnInvalidProject/state/state.json")).build());
+                }});
             }};
 
     @Rule
@@ -416,6 +419,43 @@ public class WLGitBridgeIntegrationTest {
         assertEquals(EXPECTED_OUT_PUSH_INVALID_FILES, actual);
     }
 
+
+    private static final List<String> EXPECTED_OUT_PUSH_INVALID_PROJECT =
+            Arrays.asList(
+                    "remote: error: invalid project",
+                    "remote: hint: project: no main file",
+                    "remote: hint: The project would have no (editable) main .tex file.",
+                    "To http://127.0.0.1:33870/testproj.git",
+                    "! [remote rejected] master -> master (invalid project)",
+                    "error: failed to push some refs to 'http://127.0.0.1:33870/testproj.git'"
+            );
+
+    @Test
+    public void pushFailsOnInvalidProject() throws IOException, GitAPIException, InterruptedException {
+        MockSnapshotServer server = new MockSnapshotServer(3870, getResource("/pushFailsOnInvalidProject").toFile());
+        server.start();
+        server.setState(states.get("pushFailsOnInvalidProject").get("state"));
+        GitBridgeApp wlgb = new GitBridgeApp(new String[] {
+                makeConfigFile(33870, 3870)
+        });
+        wlgb.run();
+        File dir = folder.newFolder();
+        Process git = runtime.exec("git clone http://127.0.0.1:33870/testproj.git", null, dir);
+        int exitCode = git.waitFor();
+        File testprojDir = new File(dir, "testproj");
+        assertEquals(0, exitCode);
+        assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/pushFailsOnInvalidProject/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(1, pushExitCode);
+        List<String> actual = Util.linesFromStream(gitPush.getErrorStream(), 2, "[K");
+        assertEquals(EXPECTED_OUT_PUSH_INVALID_PROJECT, actual);
+    }
+
     private String makeConfigFile(int port, int apiPort) throws IOException {
         File wlgb = folder.newFolder();
         File config = folder.newFile();

+ 49 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/pushFailsOnInvalidProject/state/state.json

@@ -0,0 +1,49 @@
+[
+	{
+		"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:3870/state/testproj/min_mean_wait_evm_7_eps_150dpi.png",
+	            		"path": "min_mean_wait_evm_7_eps_150dpi.png"
+	            	}
+	            ]
+	        }
+		],
+		"push": "success",
+		"postback": {
+			"type": "invalidProject",
+            "errors": [
+                "project: no main file",
+                "The project would have no (editable) main .tex file."
+            ]
+		}
+	}
+]

+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/pushFailsOnInvalidProject/state/testproj/foo/bar/test.tex

@@ -0,0 +1 @@
+This text is from another file.

+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/pushFailsOnInvalidProject/state/testproj/main.tex

@@ -0,0 +1 @@
+content

BIN
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/pushFailsOnInvalidProject/state/testproj/min_mean_wait_evm_7_eps_150dpi.png