Commit 284b11e4 authored by Greg Messner's avatar Greg Messner
Browse files

Fixed Label entity and added unit test for same.

parent cdf53b78
...@@ -8,19 +8,13 @@ import javax.ws.rs.core.Response; ...@@ -8,19 +8,13 @@ import javax.ws.rs.core.Response;
import org.gitlab4j.api.models.Label; import org.gitlab4j.api.models.Label;
public class LabelsApi extends AbstractApi { public class LabelsApi extends AbstractApi {
public LabelsApi(GitLabApi gitLabApi) { public LabelsApi(GitLabApi gitLabApi) {
super(gitLabApi); super(gitLabApi);
} }
public List<Label> getLabels(Integer projectId) throws GitLabApiException { public List<Label> getLabels(Integer projectId) throws GitLabApiException {
return (getLabels(projectId, 1, getDefaultPerPage()));
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
Response response = get(javax.ws.rs.core.Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "labels");
return (response.readEntity(new GenericType<List<Label>>() {
}));
} }
public List<Label> getLabels(Integer projectId, int page, int perPage) throws GitLabApiException { public List<Label> getLabels(Integer projectId, int page, int perPage) throws GitLabApiException {
...@@ -30,8 +24,7 @@ public class LabelsApi extends AbstractApi { ...@@ -30,8 +24,7 @@ public class LabelsApi extends AbstractApi {
} }
Response response = get(javax.ws.rs.core.Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "labels"); Response response = get(javax.ws.rs.core.Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "labels");
return (response.readEntity(new GenericType<List<Label>>() { return (response.readEntity(new GenericType<List<Label>>() {}));
}));
} }
public Label createLabel(Integer projectId, String name, String color, String description) throws GitLabApiException { public Label createLabel(Integer projectId, String name, String color, String description) throws GitLabApiException {
......
...@@ -7,22 +7,15 @@ import javax.xml.bind.annotation.XmlRootElement; ...@@ -7,22 +7,15 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement @XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class Label { public class Label {
private Integer id;
private Integer id;
private String name; private String name;
private String color; private String color;
private String description; private String description;
private Integer openIssuesCount; private Integer openIssuesCount;
private Integer closedIssuesCount; private Integer closedIssuesCount;
private Integer openMergeRequestsCount;
private Integer openMergeRequestCount;
private boolean subscribed; private boolean subscribed;
private Integer priority; private Integer priority;
public Integer getId() { public Integer getId() {
...@@ -73,12 +66,12 @@ public class Label { ...@@ -73,12 +66,12 @@ public class Label {
this.closedIssuesCount = closedIssuesCount; this.closedIssuesCount = closedIssuesCount;
} }
public Integer getOpenMergeRequestCount() { public Integer getOpenMergeRequestsCount() {
return openMergeRequestCount; return openMergeRequestsCount;
} }
public void setOpenMergeRequestCount(Integer openMergeRequestCount) { public void setOpenMergeRequestsCount(Integer openMergeRequestsCount) {
this.openMergeRequestCount = openMergeRequestCount; this.openMergeRequestsCount = openMergeRequestsCount;
} }
public boolean isSubscribed() { public boolean isSubscribed() {
......
...@@ -43,6 +43,7 @@ import org.gitlab4j.api.models.ImpersonationToken; ...@@ -43,6 +43,7 @@ import org.gitlab4j.api.models.ImpersonationToken;
import org.gitlab4j.api.models.Issue; import org.gitlab4j.api.models.Issue;
import org.gitlab4j.api.models.Job; import org.gitlab4j.api.models.Job;
import org.gitlab4j.api.models.Key; import org.gitlab4j.api.models.Key;
import org.gitlab4j.api.models.Label;
import org.gitlab4j.api.models.Member; import org.gitlab4j.api.models.Member;
import org.gitlab4j.api.models.MergeRequest; import org.gitlab4j.api.models.MergeRequest;
import org.gitlab4j.api.models.Milestone; import org.gitlab4j.api.models.Milestone;
...@@ -417,6 +418,21 @@ public class TestGitLabApiBeans { ...@@ -417,6 +418,21 @@ public class TestGitLabApiBeans {
} }
} }
@Test
public void testLabels() {
try {
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"));
} catch (Exception e) {
e.printStackTrace();
}
}
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"));
......
[
{
"id" : 1,
"name" : "bug",
"color" : "#d9534f",
"description": "Bug reported by user",
"open_issues_count": 1,
"closed_issues_count": 0,
"open_merge_requests_count": 1,
"subscribed": false,
"priority": 10
},
{
"id" : 4,
"color" : "#d9534f",
"name" : "confirmed",
"description": "Confirmed issue",
"open_issues_count": 2,
"closed_issues_count": 5,
"open_merge_requests_count": 0,
"subscribed": false
},
{
"id" : 7,
"name" : "critical",
"color" : "#d9534f",
"description": "Critical issue. Need fix ASAP",
"open_issues_count": 1,
"closed_issues_count": 3,
"open_merge_requests_count": 1,
"subscribed": false
},
{
"id" : 8,
"name" : "documentation",
"color" : "#f0ad4e",
"description": "Issue about documentation",
"open_issues_count": 1,
"closed_issues_count": 0,
"open_merge_requests_count": 2,
"subscribed": false
},
{
"id" : 9,
"color" : "#5cb85c",
"name" : "enhancement",
"description": "Enhancement proposal",
"open_issues_count": 1,
"closed_issues_count": 0,
"open_merge_requests_count": 1,
"subscribed": true
}
]
\ No newline at end of file
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