Commit d9c722ae authored by Greg Messner's avatar Greg Messner
Browse files

Mods to support and test Discussions API (#279).

parent 4bd96b69
...@@ -554,6 +554,15 @@ public abstract class AbstractApi implements Constants { ...@@ -554,6 +554,15 @@ public abstract class AbstractApi implements Constants {
return (new GitLabApiException(thrown)); return (new GitLabApiException(thrown));
} }
/**
* Creates a MultivaluedMap instance containing the "per_page" param.
*
* @param perPage the number of projects per page
* @return a MultivaluedMap instance containing the "per_page" param
*/
protected MultivaluedMap<String, String> getPerPageQueryParam(int perPage) {
return (new GitLabApiForm().withParam(PER_PAGE_PARAM, perPage).asMap());
}
/** /**
* Creates a MultivaluedMap instance containing "page" and "per_page" params. * Creates a MultivaluedMap instance containing "page" and "per_page" params.
......
...@@ -10,7 +10,6 @@ import javax.ws.rs.core.Response; ...@@ -10,7 +10,6 @@ import javax.ws.rs.core.Response;
import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Commit; import org.gitlab4j.api.models.Commit;
import org.gitlab4j.api.models.Discussion;
import org.gitlab4j.api.models.Issue; import org.gitlab4j.api.models.Issue;
import org.gitlab4j.api.models.MergeRequest; import org.gitlab4j.api.models.MergeRequest;
import org.gitlab4j.api.models.MergeRequestFilter; import org.gitlab4j.api.models.MergeRequestFilter;
...@@ -280,44 +279,6 @@ public class MergeRequestApi extends AbstractApi { ...@@ -280,44 +279,6 @@ public class MergeRequestApi extends AbstractApi {
"projects", projectId, "merge_requests", mergeRequestIid, "commits")); "projects", projectId, "merge_requests", mergeRequestIid, "commits"));
} }
/**
* Get a list of merge request discussions.
*
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
*
* GET /projects/:id/merge_requests/:merge_request_iid/discussions
*
* @param projectId the project ID for the merge request
* @param mergeRequestIid the internal ID of the merge request
* @param page the page to get
* @param perPage the number of commits per page
* @return a list containing the discussions for the specified merge request
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public List<Discussion> getDiscussions(int projectId, int mergeRequestIid, int page, int perPage) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("owned", false).withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage);
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "merge_requests", mergeRequestIid, "discussions");
return (response.readEntity(new GenericType<List<Discussion>>() {}));
}
/**
* Get a Pager of merge request discussions.
*
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
*
* GET /projects/:id/merge_requests/:merge_request_iid/discussions
*
* @param projectId the project ID for the merge request
* @param mergeRequestIid the internal ID of the merge request
* @param itemsPerPage the number of Commit instances that will be fetched per page
* @return a Pager containing the discussions for the specified merge request
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public Pager<Discussion> getDiscussions(int projectId, int mergeRequestIid, int itemsPerPage) throws GitLabApiException {
return (new Pager<Discussion>(this, Discussion.class, itemsPerPage, null,
"projects", projectId, "merge_requests", mergeRequestIid, "discussions"));
}
/** /**
* Creates a merge request and optionally assigns a reviewer to it. * Creates a merge request and optionally assigns a reviewer to it.
* *
...@@ -361,7 +322,6 @@ public class MergeRequestApi extends AbstractApi { ...@@ -361,7 +322,6 @@ public class MergeRequestApi extends AbstractApi {
return (response.readEntity(MergeRequest.class)); return (response.readEntity(MergeRequest.class));
} }
/** /**
* Creates a merge request and optionally assigns a reviewer to it. * Creates a merge request and optionally assigns a reviewer to it.
* *
......
...@@ -3,7 +3,6 @@ package org.gitlab4j.api; ...@@ -3,7 +3,6 @@ package org.gitlab4j.api;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
...@@ -87,7 +86,7 @@ public class Pager<T> implements Iterator<List<T>>, Constants { ...@@ -87,7 +86,7 @@ public class Pager<T> implements Iterator<List<T>>, Constants {
try { try {
currentItems = mapper.readValue((InputStream) response.getEntity(), javaType); currentItems = mapper.readValue((InputStream) response.getEntity(), javaType);
} catch (IOException e) { } catch (Exception e) {
throw new GitLabApiException(e); throw new GitLabApiException(e);
} }
...@@ -310,8 +309,8 @@ public class Pager<T> implements Iterator<List<T>>, Constants { ...@@ -310,8 +309,8 @@ public class Pager<T> implements Iterator<List<T>>, Constants {
// regardless of what page the instance is currently on. // regardless of what page the instance is currently on.
currentPage = 0; currentPage = 0;
// Create a Stream.Builder to ontain all the items. This is more efficient than // Create a Stream.Builder to contain all the items. This is more efficient than
// getting a List with all() and streaming that List // getting a List with all() and streaming that List
Stream.Builder<T> streamBuilder = Stream.builder(); Stream.Builder<T> streamBuilder = Stream.builder();
// Iterate through the pages and append each page of items to the stream builder // Iterate through the pages and append each page of items to the stream builder
......
...@@ -3,8 +3,6 @@ package org.gitlab4j.api; ...@@ -3,8 +3,6 @@ package org.gitlab4j.api;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.List; import java.util.List;
......
...@@ -12,37 +12,36 @@ import org.gitlab4j.api.utils.JacksonJson; ...@@ -12,37 +12,36 @@ import org.gitlab4j.api.utils.JacksonJson;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class Discussion { public class Discussion {
private String id; private String id;
private Boolean individualNote; private Boolean individualNote;
private List<Note> notes; private List<Note> notes;
public String getId() { public String getId() {
return id; return id;
} }
public Boolean getIndividualNote() { public Boolean getIndividualNote() {
return individualNote; return individualNote;
} }
public List<Note> getNotes() { public List<Note> getNotes() {
return notes; return notes;
} }
public void setId(String id) { public void setId(String id) {
this.id = id; this.id = id;
} }
public void setIndividualNote(Boolean individualNote) { public void setIndividualNote(Boolean individualNote) {
this.individualNote = individualNote; this.individualNote = individualNote;
} }
public void setNotes(List<Note> notes) { public void setNotes(List<Note> notes) {
this.notes = notes; this.notes = notes;
} }
@Override @Override
public String toString() { public String toString() {
return (JacksonJson.toJsonString(this)); return (JacksonJson.toJsonString(this));
} }
} }
...@@ -40,7 +40,7 @@ public class Note { ...@@ -40,7 +40,7 @@ public class Note {
public static enum NoteableType { public static enum NoteableType {
COMMIT, ISSUE, MERGE_REQUEST, SNIPPET; COMMIT, EPIC, ISSUE, MERGE_REQUEST, SNIPPET;
private static JacksonJsonEnumHelper<NoteableType> enumHelper = new JacksonJsonEnumHelper<>(NoteableType.class, true, true); private static JacksonJsonEnumHelper<NoteableType> enumHelper = new JacksonJsonEnumHelper<>(NoteableType.class, true, true);
@JsonCreator @JsonCreator
...@@ -93,7 +93,7 @@ public class Note { ...@@ -93,7 +93,7 @@ public class Note {
private Integer noteableIid; private Integer noteableIid;
private Boolean system; private Boolean system;
private String title; private String title;
private String updatedAt; private Date updatedAt;
private Boolean upvote; private Boolean upvote;
private Boolean resolved; private Boolean resolved;
private Boolean resolvable; private Boolean resolvable;
...@@ -204,11 +204,11 @@ public class Note { ...@@ -204,11 +204,11 @@ public class Note {
this.title = title; this.title = title;
} }
public String getUpdatedAt() { public Date getUpdatedAt() {
return updatedAt; return updatedAt;
} }
public void setUpdatedAt(String updatedAt) { public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt; this.updatedAt = updatedAt;
} }
......
...@@ -8,6 +8,7 @@ import java.text.SimpleDateFormat; ...@@ -8,6 +8,7 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
...@@ -23,6 +24,7 @@ import com.fasterxml.jackson.core.JsonGenerator; ...@@ -23,6 +24,7 @@ import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonDeserializer;
...@@ -87,12 +89,12 @@ public class JacksonJson extends JacksonJaxbJsonProvider implements ContextResol ...@@ -87,12 +89,12 @@ public class JacksonJson extends JacksonJaxbJsonProvider implements ContextResol
/** /**
* Unmarshal the JSON data on the specified Reader instance to an instance of the provided class. * Unmarshal the JSON data on the specified Reader instance to an instance of the provided class.
* *
* @param <T> the generics type for the return value * @param <T> the generics type for the return value
* @param returnType an instance of this type class will be returned * @param returnType an instance of this type class will be returned
* @param reader the Reader instance that contains the JSON data * @param reader the Reader instance that contains the JSON data
* @return an instance of the provided class containing the parsed data from the Reader * @return an instance of the provided class containing the parsed data from the Reader
* @throws JsonParseException when an error occurs paresing the provided JSON * @throws JsonParseException when an error occurs parsing the provided JSON
* @throws JsonMappingException if a JSON error occurs * @throws JsonMappingException if a JSON error occurs
* @throws IOException if an error occurs reading the JSON data * @throws IOException if an error occurs reading the JSON data
*/ */
...@@ -103,12 +105,12 @@ public class JacksonJson extends JacksonJaxbJsonProvider implements ContextResol ...@@ -103,12 +105,12 @@ public class JacksonJson extends JacksonJaxbJsonProvider implements ContextResol
/** /**
* Unmarshal the JSON data contained by the string and populate an instance of the provided returnType class. * Unmarshal the JSON data contained by the string and populate an instance of the provided returnType class.
* *
* @param <T> the generics type for the return value * @param <T> the generics type for the return value
* @param returnType an instance of this type class will be returned * @param returnType an instance of this type class will be returned
* @param postData a String holding the POST data * @param postData a String holding the POST data
* @return an instance of the provided class containing the parsed data from the string * @return an instance of the provided class containing the parsed data from the string
* @throws JsonParseException when an error occurs paresing the provided JSON * @throws JsonParseException when an error occurs parsing the provided JSON
* @throws JsonMappingException if a JSON error occurs * @throws JsonMappingException if a JSON error occurs
* @throws IOException if an error occurs reading the JSON data * @throws IOException if an error occurs reading the JSON data
*/ */
...@@ -117,6 +119,70 @@ public class JacksonJson extends JacksonJaxbJsonProvider implements ContextResol ...@@ -117,6 +119,70 @@ public class JacksonJson extends JacksonJaxbJsonProvider implements ContextResol
return (objectMapper.readValue(postData, returnType)); return (objectMapper.readValue(postData, returnType));
} }
/**
* Unmarshal the JSON data on the specified Reader instance and populate a List of instances of the provided returnType class.
*
* @param <T> the generics type for the List
* @param returnType an instance of this type class will be contained in the returned List
* @param reader the Reader instance that contains the JSON data
* @return a List of the provided class containing the parsed data from the Reader
* @throws JsonParseException when an error occurs parsing the provided JSON
* @throws JsonMappingException if a JSON error occurs
* @throws IOException if an error occurs reading the JSON data
*/
public <T> List<T> unmarshalList(Class<T> returnType, Reader reader) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper objectMapper = getContext(null);
return (objectMapper.readValue(reader, new TypeReference<List<T>>() {}));
}
/**
* Unmarshal the JSON data contained by the string and populate a List of instances of the provided returnType class.
*
* @param <T> the generics type for the List
* @param returnType an instance of this type class will be contained in the returned List
* @param postData a String holding the POST data
* @return a List of the provided class containing the parsed data from the string
* @throws JsonParseException when an error occurs parsing the provided JSON
* @throws JsonMappingException if a JSON error occurs
* @throws IOException if an error occurs reading the JSON data
*/
public <T> List<T> unmarshalList(Class<T> returnType, String postData) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper objectMapper = getContext(null);
return objectMapper.readValue(postData, new TypeReference<List<T>>() {});
}
/**
* Unmarshal the JSON data on the specified Reader instance and populate a Map of String keys and values of the provided returnType class.
*
* @param <T> the generics type for the Map value
* @param returnType an instance of this type class will be contained the values of the Map
* @param reader the Reader instance that contains the JSON data
* @return a Map containing the parsed data from the Reader
* @throws JsonParseException when an error occurs parsing the provided JSON
* @throws JsonMappingException if a JSON error occurs
* @throws IOException if an error occurs reading the JSON data
*/
public <T> Map<String, T> unmarshalMap(Class<T> returnType, Reader reader) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper objectMapper = getContext(null);
return (objectMapper.readValue(reader, new TypeReference<Map<String, T>>() {}));
}
/**
* Unmarshal the JSON data and populate a Map of String keys and values of the provided returnType class.
*
* @param <T> the generics type for the Map value
* @param returnType an instance of this type class will be contained the values of the Map
* @param jsonData the String containing the JSON data
* @return a Map containing the parsed data from the String
* @throws JsonParseException when an error occurs parsing the provided JSON
* @throws JsonMappingException if a JSON error occurs
* @throws IOException if an error occurs reading the JSON data
*/
public <T> Map<String, T> unmarshalMap(Class<T> returnType, String jsonData) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper objectMapper = getContext(null);
return (objectMapper.readValue(jsonData, new TypeReference<Map<String, T>>() {}));
}
/** /**
* Marshals the supplied object out as a formatted JSON string. * Marshals the supplied object out as a formatted JSON string.
* *
......
...@@ -26,7 +26,6 @@ package org.gitlab4j.api; ...@@ -26,7 +26,6 @@ package org.gitlab4j.api;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -40,6 +39,7 @@ import org.gitlab4j.api.models.CommitStatus; ...@@ -40,6 +39,7 @@ import org.gitlab4j.api.models.CommitStatus;
import org.gitlab4j.api.models.CompareResults; import org.gitlab4j.api.models.CompareResults;
import org.gitlab4j.api.models.DeployKey; import org.gitlab4j.api.models.DeployKey;
import org.gitlab4j.api.models.Diff; import org.gitlab4j.api.models.Diff;
import org.gitlab4j.api.models.Discussion;
import org.gitlab4j.api.models.Epic; import org.gitlab4j.api.models.Epic;
import org.gitlab4j.api.models.EpicIssue; import org.gitlab4j.api.models.EpicIssue;
import org.gitlab4j.api.models.Event; import org.gitlab4j.api.models.Event;
...@@ -78,37 +78,31 @@ import org.gitlab4j.api.systemhooks.ProjectSystemHookEvent; ...@@ -78,37 +78,31 @@ import org.gitlab4j.api.systemhooks.ProjectSystemHookEvent;
import org.gitlab4j.api.systemhooks.PushSystemHookEvent; import org.gitlab4j.api.systemhooks.PushSystemHookEvent;
import org.gitlab4j.api.systemhooks.SystemHookEvent; import org.gitlab4j.api.systemhooks.SystemHookEvent;
import org.gitlab4j.api.systemhooks.TeamMemberSystemHookEvent; import org.gitlab4j.api.systemhooks.TeamMemberSystemHookEvent;
import org.gitlab4j.api.utils.JacksonJson;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
public class TestGitLabApiBeans { public class TestGitLabApiBeans {
private static JacksonJson jacksonJson; private <T> T unmarshal(Class<T> returnType, String file) throws JsonParseException, JsonMappingException, IOException {
return (JsonUtils.unmarshal(returnType, file + ".json"));
}
public TestGitLabApiBeans() { private <T> List<T> unmarshalList(Class<T> returnType, String file) throws JsonParseException, JsonMappingException, IOException {
super(); return (JsonUtils.unmarshalList(returnType, file + ".json"));
} }
@BeforeClass private <T> boolean compareJson(T apiObject, String file) throws IOException {
public static void setup() { return (JsonUtils.compareJson(apiObject, file + ".json"));
jacksonJson = new JacksonJson();
jacksonJson.getObjectMapper().configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
} }
@Test @Test
public void testAwardEmoji() { public void testAwardEmoji() {
try { try {
AwardEmoji awardEmoji = makeFakeApiCall(AwardEmoji.class, "award-emoji"); AwardEmoji awardEmoji = unmarshal(AwardEmoji.class, "award-emoji");
assertTrue(compareJson(awardEmoji, "award-emoji")); assertTrue(compareJson(awardEmoji, "award-emoji"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -119,10 +113,10 @@ public class TestGitLabApiBeans { ...@@ -119,10 +113,10 @@ public class TestGitLabApiBeans {
public void testBranch() { public void testBranch() {
try { try {
Branch branch = makeFakeApiCall(Branch.class, "branch"); Branch branch = unmarshal(Branch.class, "branch");
assertTrue(compareJson(branch, "branch")); assertTrue(compareJson(branch, "branch"));
branch = makeFakeApiCall(Branch.class, "bad-branch"); branch = unmarshal(Branch.class, "bad-branch");
assertTrue(!Branch.isValid(branch)); assertTrue(!Branch.isValid(branch));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -133,7 +127,7 @@ public class TestGitLabApiBeans { ...@@ -133,7 +127,7 @@ public class TestGitLabApiBeans {
public void testCommit() { public void testCommit() {
try { try {
Commit commit = makeFakeApiCall(Commit.class, "commit"); Commit commit = unmarshal(Commit.class, "commit");
assertTrue(compareJson(commit, "commit")); assertTrue(compareJson(commit, "commit"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -144,7 +138,7 @@ public class TestGitLabApiBeans { ...@@ -144,7 +138,7 @@ public class TestGitLabApiBeans {
public void testCommitPayload() { public void testCommitPayload() {
try { try {
CommitPayload commitPayload = makeFakeApiCall(CommitPayload.class, "commit-payload"); CommitPayload commitPayload = unmarshal(CommitPayload.class, "commit-payload");
assertTrue(compareJson(commitPayload, "commit-payload")); assertTrue(compareJson(commitPayload, "commit-payload"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -155,7 +149,7 @@ public class TestGitLabApiBeans { ...@@ -155,7 +149,7 @@ public class TestGitLabApiBeans {
public void testCommitStatus() { public void testCommitStatus() {
try { try {
CommitStatus commitStatus = makeFakeApiCall(CommitStatus.class, "commit-status"); CommitStatus commitStatus = unmarshal(CommitStatus.class, "commit-status");
assertTrue(compareJson(commitStatus, "commit-status")); assertTrue(compareJson(commitStatus, "commit-status"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -166,7 +160,7 @@ public class TestGitLabApiBeans { ...@@ -166,7 +160,7 @@ public class TestGitLabApiBeans {
public void testCompareResults() { public void testCompareResults() {
try { try {
CompareResults compareResults = makeFakeApiCall(CompareResults.class, "compare-results"); CompareResults compareResults = unmarshal(CompareResults.class, "compare-results");
assertTrue(compareJson(compareResults, "compare-results")); assertTrue(compareJson(compareResults, "compare-results"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -177,7 +171,7 @@ public class TestGitLabApiBeans { ...@@ -177,7 +171,7 @@ public class TestGitLabApiBeans {
public void testDiff() { public void testDiff() {
try { try {
Diff diff = makeFakeApiCall(Diff.class, "diff"); Diff diff = unmarshal(Diff.class, "diff");
assertTrue(compareJson(diff, "diff")); assertTrue(compareJson(diff, "diff"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -188,7 +182,7 @@ public class TestGitLabApiBeans { ...@@ -188,7 +182,7 @@ public class TestGitLabApiBeans {
public void testComment() { public void testComment() {
try { try {
Comment comment = makeFakeApiCall(Comment.class, "comment"); Comment comment = unmarshal(Comment.class, "comment");
assertTrue(compareJson(comment, "comment")); assertTrue(compareJson(comment, "comment"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -199,7 +193,7 @@ public class TestGitLabApiBeans { ...@@ -199,7 +193,7 @@ public class TestGitLabApiBeans {
public void testEpic() { public void testEpic() {
try { try {
Epic epic = makeFakeApiCall(Epic.class, "epic"); Epic epic = unmarshal(Epic.class, "epic");
assertTrue(compareJson(epic, "epic")); assertTrue(compareJson(epic, "epic"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -210,7 +204,7 @@ public class TestGitLabApiBeans { ...@@ -210,7 +204,7 @@ public class TestGitLabApiBeans {
public void testEpicIssue() { public void testEpicIssue() {
try { try {
EpicIssue epicIssue = makeFakeApiCall(EpicIssue.class, "epic-issue"); EpicIssue epicIssue = unmarshal(EpicIssue.class, "epic-issue");
assertTrue(compareJson(epicIssue, "epic-issue")); assertTrue(compareJson(epicIssue, "epic-issue"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -221,7 +215,7 @@ public class TestGitLabApiBeans { ...@@ -221,7 +215,7 @@ public class TestGitLabApiBeans {
public void testEvent() { public void testEvent() {
try { try {
Event event = makeFakeApiCall(Event.class, "event"); Event event = unmarshal(Event.class, "event");
assertTrue(compareJson(event, "event")); assertTrue(compareJson(event, "event"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -232,7 +226,7 @@ public class TestGitLabApiBeans { ...@@ -232,7 +226,7 @@ public class TestGitLabApiBeans {
public void testFileUpload() { public void testFileUpload() {
try { try {
FileUpload fileUpload = makeFakeApiCall(FileUpload.class, "file-upload"); FileUpload fileUpload = unmarshal(FileUpload.class, "file-upload");
assertTrue(compareJson(fileUpload, "file-upload")); assertTrue(compareJson(fileUpload, "file-upload"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -243,7 +237,7 @@ public class TestGitLabApiBeans { ...@@ -243,7 +237,7 @@ public class TestGitLabApiBeans {
public void testGroup() { public void testGroup() {
try { try {
Group group = makeFakeApiCall(Group.class, "group"); Group group = unmarshal(Group.class, "group");
assertTrue(compareJson(group, "group")); assertTrue(compareJson(group, "group"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -254,7 +248,7 @@ public class TestGitLabApiBeans { ...@@ -254,7 +248,7 @@ public class TestGitLabApiBeans {
public void testHealthCheckInfo() { public void testHealthCheckInfo() {
try { try {
HealthCheckInfo healthCheck = makeFakeApiCall(HealthCheckInfo.class, "health-check"); HealthCheckInfo healthCheck = unmarshal(HealthCheckInfo.class, "health-check");
assertTrue(compareJson(healthCheck, "health-check")); assertTrue(compareJson(healthCheck, "health-check"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -265,18 +259,74 @@ public class TestGitLabApiBeans { ...@@ -265,18 +259,74 @@ public class TestGitLabApiBeans {
public void testIssue() { public void testIssue() {
try { try {
Issue issue = makeFakeApiCall(Issue.class, "issue"); Issue issue = unmarshal(Issue.class, "issue");
assertTrue(compareJson(issue, "issue")); assertTrue(compareJson(issue, "issue"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Test
public void testCommitDiscussions() {
try {
List<Discussion> discussions = unmarshalList(Discussion.class, "commit-discussions");
assertTrue(compareJson(discussions, "commit-discussions"));
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void testEpicDiscussions() {
try {
List<Discussion> discussions = unmarshalList(Discussion.class, "epic-discussions");
assertTrue(compareJson(discussions, "epic-discussions"));
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void testIssueDiscussions() {
try {
List<Discussion> discussions = unmarshalList(Discussion.class, "issue-discussions");
assertTrue(compareJson(discussions, "issue-discussions"));
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void testMergeRequestDiscussions() {
try {
List<Discussion> discussions = unmarshalList(Discussion.class, "merge-request-discussions");
assertTrue(compareJson(discussions, "merge-request-discussions"));
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void testSnippetDiscussions() {
try {
List<Discussion> discussions = unmarshalList(Discussion.class, "snippet-discussions");
assertTrue(compareJson(discussions, "snippet-discussions"));
} catch (Exception e) {
e.printStackTrace();
}
}
@Test @Test
public void testPipeline() { public void testPipeline() {
try { try {
Pipeline pipeline = makeFakeApiCall(Pipeline.class, "pipeline"); Pipeline pipeline = unmarshal(Pipeline.class, "pipeline");
assertTrue(compareJson(pipeline, "pipeline")); assertTrue(compareJson(pipeline, "pipeline"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -287,7 +337,7 @@ public class TestGitLabApiBeans { ...@@ -287,7 +337,7 @@ public class TestGitLabApiBeans {
public void testJob() { public void testJob() {
try { try {
Job job = makeFakeApiCall(Job.class, "job"); Job job = unmarshal(Job.class, "job");
assertTrue(compareJson(job, "job")); assertTrue(compareJson(job, "job"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -298,12 +348,8 @@ public class TestGitLabApiBeans { ...@@ -298,12 +348,8 @@ public class TestGitLabApiBeans {
public void testDeployKeys() { public void testDeployKeys() {
try { try {
List<DeployKey> deployKeys = unmarshalList(DeployKey.class, "deploy-keys");
InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream("deploy-keys.json"));
ObjectMapper objectMapper = jacksonJson.getContext(null);
List<DeployKey> deployKeys = objectMapper.readValue(reader, new TypeReference<List<DeployKey>>() {});
assertTrue(compareJson(deployKeys, "deploy-keys")); assertTrue(compareJson(deployKeys, "deploy-keys"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -313,7 +359,7 @@ public class TestGitLabApiBeans { ...@@ -313,7 +359,7 @@ public class TestGitLabApiBeans {
public void testArtifactsFile() { public void testArtifactsFile() {
try { try {
ArtifactsFile artifactFile = makeFakeApiCall(ArtifactsFile.class, "artifacts-file"); ArtifactsFile artifactFile = unmarshal(ArtifactsFile.class, "artifacts-file");
assertTrue(compareJson(artifactFile, "artifacts-file")); assertTrue(compareJson(artifactFile, "artifacts-file"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -324,21 +370,18 @@ public class TestGitLabApiBeans { ...@@ -324,21 +370,18 @@ public class TestGitLabApiBeans {
public void testProjectLanguages() { public void testProjectLanguages() {
try { try {
InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream("project-languages.json")); Map<String, Float> projectLanguages = JsonUtils.unmarshalMap(Float.class, "project-languages.json");
ObjectMapper objectMapper = jacksonJson.getContext(null);
Map<String, Float> projectLanguages = objectMapper.readValue(reader, new TypeReference<Map<String, Float>>() {});
assertTrue(compareJson(projectLanguages, "project-languages")); assertTrue(compareJson(projectLanguages, "project-languages"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Test @Test
public void testProjectUsers() { public void testProjectUsers() {
try { try {
InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream("project-users.json")); List<ProjectUser> projectUsers = unmarshalList(ProjectUser.class, "project-users");
ObjectMapper objectMapper = jacksonJson.getContext(null);
List<ProjectUser> projectUsers = objectMapper.readValue(reader, new TypeReference<List<ProjectUser>>() {});
assertTrue(compareJson(projectUsers, "project-users")); assertTrue(compareJson(projectUsers, "project-users"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -349,7 +392,7 @@ public class TestGitLabApiBeans { ...@@ -349,7 +392,7 @@ public class TestGitLabApiBeans {
public void testProjectHook() { public void testProjectHook() {
try { try {
ProjectHook hook = makeFakeApiCall(ProjectHook.class, "hook"); ProjectHook hook = unmarshal(ProjectHook.class, "hook");
assertTrue(compareJson(hook, "hook")); assertTrue(compareJson(hook, "hook"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -360,12 +403,8 @@ public class TestGitLabApiBeans { ...@@ -360,12 +403,8 @@ public class TestGitLabApiBeans {
public void testProjectEvents() { public void testProjectEvents() {
try { try {
List<Event> events = unmarshalList(Event.class, "project-events");
InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream("project-events.json"));
ObjectMapper objectMapper = jacksonJson.getContext(null);
List<Event> events = objectMapper.readValue(reader, new TypeReference<List<Event>>() {});
assertTrue(compareJson(events, "project-events")); assertTrue(compareJson(events, "project-events"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -375,7 +414,7 @@ public class TestGitLabApiBeans { ...@@ -375,7 +414,7 @@ public class TestGitLabApiBeans {
public void testProtectedBranch() { public void testProtectedBranch() {
try { try {
ProtectedBranch protectedBranch = makeFakeApiCall(ProtectedBranch.class, "protected-branch"); ProtectedBranch protectedBranch = unmarshal(ProtectedBranch.class, "protected-branch");
assertTrue(compareJson(protectedBranch, "protected-branch")); assertTrue(compareJson(protectedBranch, "protected-branch"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -386,7 +425,7 @@ public class TestGitLabApiBeans { ...@@ -386,7 +425,7 @@ public class TestGitLabApiBeans {
public void testPushRule() { public void testPushRule() {
try { try {
PushRules pushRule = makeFakeApiCall(PushRules.class, "push-rule"); PushRules pushRule = unmarshal(PushRules.class, "push-rule");
assertTrue(compareJson(pushRule, "push-rule")); assertTrue(compareJson(pushRule, "push-rule"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -397,7 +436,7 @@ public class TestGitLabApiBeans { ...@@ -397,7 +436,7 @@ public class TestGitLabApiBeans {
public void testRunnerDetail() { public void testRunnerDetail() {
try { try {
RunnerDetail runnerDetail = makeFakeApiCall(RunnerDetail.class, "runner-detail"); RunnerDetail runnerDetail = unmarshal(RunnerDetail.class, "runner-detail");
assertTrue(compareJson(runnerDetail, "runner-detail")); assertTrue(compareJson(runnerDetail, "runner-detail"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -408,10 +447,7 @@ public class TestGitLabApiBeans { ...@@ -408,10 +447,7 @@ public class TestGitLabApiBeans {
public void testAllRunners() { public void testAllRunners() {
try { try {
List<Runner> allRunners = unmarshalList(Runner.class, "all-runners");
InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream("all-runners.json"));
ObjectMapper objectMapper = jacksonJson.getContext(null);
List<Runner> allRunners = objectMapper.readValue(reader, new TypeReference<List<Runner>>() {});
assertTrue(compareJson(allRunners, "all-runners")); assertTrue(compareJson(allRunners, "all-runners"));
} catch (Exception e) { } catch (Exception e) {
...@@ -423,7 +459,7 @@ public class TestGitLabApiBeans { ...@@ -423,7 +459,7 @@ public class TestGitLabApiBeans {
public void testJiraService() { public void testJiraService() {
try { try {
JiraService jira = makeFakeApiCall(JiraService.class, "jira"); JiraService jira = unmarshal(JiraService.class, "jira");
assertTrue(compareJson(jira, "jira")); assertTrue(compareJson(jira, "jira"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -434,7 +470,7 @@ public class TestGitLabApiBeans { ...@@ -434,7 +470,7 @@ public class TestGitLabApiBeans {
public void testKey() { public void testKey() {
try { try {
Key key = makeFakeApiCall(Key.class, "key"); Key key = unmarshal(Key.class, "key");
assertTrue(compareJson(key, "key")); assertTrue(compareJson(key, "key"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -445,7 +481,7 @@ public class TestGitLabApiBeans { ...@@ -445,7 +481,7 @@ public class TestGitLabApiBeans {
public void testMember() { public void testMember() {
try { try {
Member member = makeFakeApiCall(Member.class, "member"); Member member = unmarshal(Member.class, "member");
assertTrue(compareJson(member, "member")); assertTrue(compareJson(member, "member"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -456,7 +492,7 @@ public class TestGitLabApiBeans { ...@@ -456,7 +492,7 @@ public class TestGitLabApiBeans {
public void testMergeRequestApprovals() { public void testMergeRequestApprovals() {
try { try {
MergeRequest mergeRequestApprovals = makeFakeApiCall(MergeRequest.class, "approvals"); MergeRequest mergeRequestApprovals = unmarshal(MergeRequest.class, "approvals");
assertTrue(compareJson(mergeRequestApprovals, "approvals")); assertTrue(compareJson(mergeRequestApprovals, "approvals"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -467,7 +503,7 @@ public class TestGitLabApiBeans { ...@@ -467,7 +503,7 @@ public class TestGitLabApiBeans {
public void testMergeRequest() { public void testMergeRequest() {
try { try {
MergeRequest mergeRequest = makeFakeApiCall(MergeRequest.class, "merge-request"); MergeRequest mergeRequest = unmarshal(MergeRequest.class, "merge-request");
assertTrue(compareJson(mergeRequest, "merge-request")); assertTrue(compareJson(mergeRequest, "merge-request"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -478,7 +514,7 @@ public class TestGitLabApiBeans { ...@@ -478,7 +514,7 @@ public class TestGitLabApiBeans {
public void testMilestone() { public void testMilestone() {
try { try {
Milestone milestone = makeFakeApiCall(Milestone.class, "milestone"); Milestone milestone = unmarshal(Milestone.class, "milestone");
assertTrue(compareJson(milestone, "milestone")); assertTrue(compareJson(milestone, "milestone"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -489,7 +525,7 @@ public class TestGitLabApiBeans { ...@@ -489,7 +525,7 @@ public class TestGitLabApiBeans {
public void testNote() { public void testNote() {
try { try {
Note note = makeFakeApiCall(Note.class, "note"); Note note = unmarshal(Note.class, "note");
assertTrue(compareJson(note, "note")); assertTrue(compareJson(note, "note"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -500,7 +536,7 @@ public class TestGitLabApiBeans { ...@@ -500,7 +536,7 @@ public class TestGitLabApiBeans {
public void testMergeRequestNote() { public void testMergeRequestNote() {
try { try {
Note note = makeFakeApiCall(Note.class, "merge-request-note"); Note note = unmarshal(Note.class, "merge-request-note");
assertTrue(compareJson(note, "merge-request-note")); assertTrue(compareJson(note, "merge-request-note"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -511,7 +547,7 @@ public class TestGitLabApiBeans { ...@@ -511,7 +547,7 @@ public class TestGitLabApiBeans {
public void testNotificationSettings() { public void testNotificationSettings() {
try { try {
NotificationSettings settings = makeFakeApiCall(NotificationSettings.class, "notification-settings"); NotificationSettings settings = unmarshal(NotificationSettings.class, "notification-settings");
assertTrue(compareJson(settings, "notification-settings")); assertTrue(compareJson(settings, "notification-settings"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -522,7 +558,7 @@ public class TestGitLabApiBeans { ...@@ -522,7 +558,7 @@ public class TestGitLabApiBeans {
public void testProject() { public void testProject() {
try { try {
Project project = makeFakeApiCall(Project.class, "project"); Project project = unmarshal(Project.class, "project");
assertTrue(compareJson(project, "project")); assertTrue(compareJson(project, "project"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -533,7 +569,7 @@ public class TestGitLabApiBeans { ...@@ -533,7 +569,7 @@ public class TestGitLabApiBeans {
public void testProjectSnippet() { public void testProjectSnippet() {
try { try {
Snippet snippet = makeFakeApiCall(Snippet.class, "snippet"); Snippet snippet = unmarshal(Snippet.class, "snippet");
assertTrue(compareJson(snippet, "snippet")); assertTrue(compareJson(snippet, "snippet"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -544,7 +580,7 @@ public class TestGitLabApiBeans { ...@@ -544,7 +580,7 @@ public class TestGitLabApiBeans {
public void testSession() { public void testSession() {
try { try {
Session session = makeFakeApiCall(Session.class, "session"); Session session = unmarshal(Session.class, "session");
assertTrue(compareJson(session, "session")); assertTrue(compareJson(session, "session"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -555,7 +591,7 @@ public class TestGitLabApiBeans { ...@@ -555,7 +591,7 @@ public class TestGitLabApiBeans {
public void testSlackService() { public void testSlackService() {
try { try {
SlackService slackNotifications = makeFakeApiCall(SlackService.class, "slack-notifications"); SlackService slackNotifications = unmarshal(SlackService.class, "slack-notifications");
assertTrue(compareJson(slackNotifications, "slack-notifications")); assertTrue(compareJson(slackNotifications, "slack-notifications"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -566,7 +602,7 @@ public class TestGitLabApiBeans { ...@@ -566,7 +602,7 @@ public class TestGitLabApiBeans {
public void testSystemHook() { public void testSystemHook() {
try { try {
SystemHook systemHook = makeFakeApiCall(SystemHook.class, "system-hook"); SystemHook systemHook = unmarshal(SystemHook.class, "system-hook");
assertTrue(compareJson(systemHook, "system-hook")); assertTrue(compareJson(systemHook, "system-hook"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -577,7 +613,7 @@ public class TestGitLabApiBeans { ...@@ -577,7 +613,7 @@ public class TestGitLabApiBeans {
public void testTag() { public void testTag() {
try { try {
Tag tag = makeFakeApiCall(Tag.class, "tag"); Tag tag = unmarshal(Tag.class, "tag");
assertTrue(compareJson(tag, "tag")); assertTrue(compareJson(tag, "tag"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -588,7 +624,7 @@ public class TestGitLabApiBeans { ...@@ -588,7 +624,7 @@ public class TestGitLabApiBeans {
public void testSshKey() { public void testSshKey() {
try { try {
SshKey sshKey = makeFakeApiCall(SshKey.class, "sshkey"); SshKey sshKey = unmarshal(SshKey.class, "sshkey");
assertTrue(compareJson(sshKey, "sshkey")); assertTrue(compareJson(sshKey, "sshkey"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -599,12 +635,8 @@ public class TestGitLabApiBeans { ...@@ -599,12 +635,8 @@ public class TestGitLabApiBeans {
public void testTree() { public void testTree() {
try { try {
List<TreeItem> tree = unmarshalList(TreeItem.class, "tree");
InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream("tree.json"));
ObjectMapper objectMapper = jacksonJson.getContext(null);
List<TreeItem> tree = objectMapper.readValue(reader, new TypeReference<List<TreeItem>>() {});
assertTrue(compareJson(tree, "tree")); assertTrue(compareJson(tree, "tree"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -614,7 +646,7 @@ public class TestGitLabApiBeans { ...@@ -614,7 +646,7 @@ public class TestGitLabApiBeans {
public void testUser() { public void testUser() {
try { try {
User user = makeFakeApiCall(User.class, "user"); User user = unmarshal(User.class, "user");
assertTrue(compareJson(user, "user")); assertTrue(compareJson(user, "user"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -625,7 +657,7 @@ public class TestGitLabApiBeans { ...@@ -625,7 +657,7 @@ public class TestGitLabApiBeans {
public void testImpersonationToken() { public void testImpersonationToken() {
try { try {
ImpersonationToken token = makeFakeApiCall(ImpersonationToken.class, "impersonation-token"); ImpersonationToken token = unmarshal(ImpersonationToken.class, "impersonation-token");
assertTrue(compareJson(token, "impersonation-token")); assertTrue(compareJson(token, "impersonation-token"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -636,7 +668,7 @@ public class TestGitLabApiBeans { ...@@ -636,7 +668,7 @@ public class TestGitLabApiBeans {
public void testOauthToken() { public void testOauthToken() {
try { try {
OauthTokenResponse token = makeFakeApiCall(OauthTokenResponse.class, "oauth-token"); OauthTokenResponse token = unmarshal(OauthTokenResponse.class, "oauth-token");
assertTrue(compareJson(token, "oauth-token")); assertTrue(compareJson(token, "oauth-token"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -647,7 +679,7 @@ public class TestGitLabApiBeans { ...@@ -647,7 +679,7 @@ public class TestGitLabApiBeans {
public void testProjectSystemHookEvent() { public void testProjectSystemHookEvent() {
try { try {
ProjectSystemHookEvent event = makeFakeApiCall(ProjectSystemHookEvent.class, "project-system-hook-event"); ProjectSystemHookEvent event = unmarshal(ProjectSystemHookEvent.class, "project-system-hook-event");
assertTrue(compareJson(event, "project-system-hook-event")); assertTrue(compareJson(event, "project-system-hook-event"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -658,7 +690,7 @@ public class TestGitLabApiBeans { ...@@ -658,7 +690,7 @@ public class TestGitLabApiBeans {
public void testTeamMemberSystemHookEvent() { public void testTeamMemberSystemHookEvent() {
try { try {
TeamMemberSystemHookEvent event = makeFakeApiCall(TeamMemberSystemHookEvent.class, "team-member-system-hook-event"); TeamMemberSystemHookEvent event = unmarshal(TeamMemberSystemHookEvent.class, "team-member-system-hook-event");
assertTrue(compareJson(event, "team-member-system-hook-event")); assertTrue(compareJson(event, "team-member-system-hook-event"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -669,7 +701,7 @@ public class TestGitLabApiBeans { ...@@ -669,7 +701,7 @@ public class TestGitLabApiBeans {
public void testPushSystemHookEvent() { public void testPushSystemHookEvent() {
try { try {
PushSystemHookEvent event = makeFakeApiCall(PushSystemHookEvent.class, "push-system-hook-event"); PushSystemHookEvent event = unmarshal(PushSystemHookEvent.class, "push-system-hook-event");
assertTrue(compareJson(event, "push-system-hook-event")); assertTrue(compareJson(event, "push-system-hook-event"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -680,7 +712,7 @@ public class TestGitLabApiBeans { ...@@ -680,7 +712,7 @@ public class TestGitLabApiBeans {
public void testUserSystemHookEvent() { public void testUserSystemHookEvent() {
try { try {
SystemHookEvent event = makeFakeApiCall(SystemHookEvent.class, "user-system-hook-event"); SystemHookEvent event = unmarshal(SystemHookEvent.class, "user-system-hook-event");
assertTrue(compareJson(event, "user-system-hook-event")); assertTrue(compareJson(event, "user-system-hook-event"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -691,7 +723,7 @@ public class TestGitLabApiBeans { ...@@ -691,7 +723,7 @@ public class TestGitLabApiBeans {
public void testGroupSystemHookEvent() { public void testGroupSystemHookEvent() {
try { try {
SystemHookEvent event = makeFakeApiCall(SystemHookEvent.class, "group-system-hook-event"); SystemHookEvent event = unmarshal(SystemHookEvent.class, "group-system-hook-event");
assertTrue(compareJson(event, "group-system-hook-event")); assertTrue(compareJson(event, "group-system-hook-event"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -702,7 +734,7 @@ public class TestGitLabApiBeans { ...@@ -702,7 +734,7 @@ public class TestGitLabApiBeans {
public void testGroupMemberSystemHookEvent() { public void testGroupMemberSystemHookEvent() {
try { try {
SystemHookEvent event = makeFakeApiCall(SystemHookEvent.class, "group-member-system-hook-event"); SystemHookEvent event = unmarshal(SystemHookEvent.class, "group-member-system-hook-event");
assertTrue(compareJson(event, "group-member-system-hook-event")); assertTrue(compareJson(event, "group-member-system-hook-event"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -713,7 +745,7 @@ public class TestGitLabApiBeans { ...@@ -713,7 +745,7 @@ public class TestGitLabApiBeans {
public void testTagPushSystemHookEvent() { public void testTagPushSystemHookEvent() {
try { try {
SystemHookEvent event = makeFakeApiCall(SystemHookEvent.class, "tag-push-system-hook-event"); SystemHookEvent event = unmarshal(SystemHookEvent.class, "tag-push-system-hook-event");
assertTrue(compareJson(event, "tag-push-system-hook-event")); assertTrue(compareJson(event, "tag-push-system-hook-event"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -724,7 +756,7 @@ public class TestGitLabApiBeans { ...@@ -724,7 +756,7 @@ public class TestGitLabApiBeans {
public void testRepositorySystemHookEvent() { public void testRepositorySystemHookEvent() {
try { try {
SystemHookEvent event = makeFakeApiCall(SystemHookEvent.class, "repository-system-hook-event"); SystemHookEvent event = unmarshal(SystemHookEvent.class, "repository-system-hook-event");
assertTrue(compareJson(event, "repository-system-hook-event")); assertTrue(compareJson(event, "repository-system-hook-event"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -735,42 +767,10 @@ public class TestGitLabApiBeans { ...@@ -735,42 +767,10 @@ public class TestGitLabApiBeans {
public void testLabels() { public void testLabels() {
try { try {
List<Label> labels = unmarshalList(Label.class, "labels");
InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream("labels.json"));
ObjectMapper objectMapper = jacksonJson.getContext(null);
List<Label> labels = objectMapper.readValue(reader, new TypeReference<List<Label>>() {});
assertTrue(compareJson(labels, "labels")); assertTrue(compareJson(labels, "labels"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
private <T> T makeFakeApiCall(Class<T> returnType, String file) throws JsonParseException, JsonMappingException, IOException {
InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream(file + ".json"));
ObjectMapper objectMapper = jacksonJson.getContext(returnType);
return (objectMapper.readValue(reader, returnType));
}
private <T> boolean compareJson(T apiObject, String file) throws IOException {
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);
if (!sameJson) {
System.out.println("JSON did not match:");
sortedDump(tree1);
sortedDump(tree2);
}
return (sameJson);
}
private void sortedDump(final JsonNode node) throws JsonProcessingException {
final Object obj = jacksonJson.getObjectMapper().treeToValue(node, Object.class);
System.out.println(jacksonJson.getObjectMapper().writeValueAsString(obj));
}
} }
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