Commit 5ffec843 authored by Greg Messner's avatar Greg Messner
Browse files

Fixed issues exposed by unit tests.

parent 3489473f
...@@ -5,9 +5,11 @@ import static org.junit.Assert.assertTrue; ...@@ -5,9 +5,11 @@ import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException; import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
import org.json.JSONException;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
...@@ -16,7 +18,7 @@ import com.messners.gitlab.api.webhook.PushEvent; ...@@ -16,7 +18,7 @@ import com.messners.gitlab.api.webhook.PushEvent;
public class TestGitLabApiEvents { public class TestGitLabApiEvents {
private static JacksonJson jacksonJsonConfig; private static JacksonJson jacksonJson;
public TestGitLabApiEvents () { public TestGitLabApiEvents () {
super(); super();
...@@ -24,7 +26,7 @@ public class TestGitLabApiEvents { ...@@ -24,7 +26,7 @@ public class TestGitLabApiEvents {
@BeforeClass @BeforeClass
public static void setup () { public static void setup () {
jacksonJsonConfig = new JacksonJson(); jacksonJson = new JacksonJson();
} }
@Test @Test
...@@ -32,7 +34,7 @@ public class TestGitLabApiEvents { ...@@ -32,7 +34,7 @@ public class TestGitLabApiEvents {
try { try {
EventObject issueEvent = makeFakeApiCall(EventObject.class, "issue-event"); EventObject issueEvent = makeFakeApiCall(EventObject.class, "issue-event");
assertTrue(issueEvent != null); assertTrue(compareJson(issueEvent, "issue-event"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -43,7 +45,7 @@ public class TestGitLabApiEvents { ...@@ -43,7 +45,7 @@ public class TestGitLabApiEvents {
try { try {
EventObject mergeRequestEvent = makeFakeApiCall(EventObject.class, "merge-request-event"); EventObject mergeRequestEvent = makeFakeApiCall(EventObject.class, "merge-request-event");
assertTrue(mergeRequestEvent != null); assertTrue(compareJson(mergeRequestEvent, "merge-request-event"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -54,7 +56,7 @@ public class TestGitLabApiEvents { ...@@ -54,7 +56,7 @@ public class TestGitLabApiEvents {
try { try {
PushEvent pushEvent = makeFakeApiCall(PushEvent.class, "push-event"); PushEvent pushEvent = makeFakeApiCall(PushEvent.class, "push-event");
assertTrue(pushEvent != null); assertTrue(compareJson(pushEvent, "push-event"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -63,7 +65,17 @@ public class TestGitLabApiEvents { ...@@ -63,7 +65,17 @@ public class TestGitLabApiEvents {
private <T> T makeFakeApiCall (Class<T> returnType, String file) throws JsonParseException, JsonMappingException, IOException { private <T> T makeFakeApiCall (Class<T> returnType, String file) throws JsonParseException, JsonMappingException, IOException {
InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream(file + ".json")); InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream(file + ".json"));
ObjectMapper objectMapper = jacksonJsonConfig.getContext(returnType); ObjectMapper objectMapper = jacksonJson.getContext(returnType);
return (objectMapper.readValue(reader, returnType)); return (objectMapper.readValue(reader, returnType));
} }
private <T> boolean compareJson (T apiObject, String file) throws IOException, JSONException {
InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream(file + ".json"));
String objectJson = jacksonJson.marshal(apiObject);
JsonNode tree1 = jacksonJson.getObjectMapper().readTree(objectJson.getBytes());
JsonNode tree2 = jacksonJson.getObjectMapper().readTree(reader);
boolean sameJson = tree1.equals(tree2);
return (sameJson);
}
} }
...@@ -9,9 +9,7 @@ ...@@ -9,9 +9,7 @@
"created_at":"2013-12-03T17:15:43Z", "created_at":"2013-12-03T17:15:43Z",
"updated_at":"2013-12-03T17:15:43Z", "updated_at":"2013-12-03T17:15:43Z",
"position":0, "position":0,
"branch_name":null,
"description":"Create new API for manipulations with repository", "description":"Create new API for manipulations with repository",
"milestone_id":null,
"state":"opened", "state":"opened",
"iid":23 "iid":23
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment