From 38f9fe441bde6f2a46051b2ca2ec201ceed2ba2f Mon Sep 17 00:00:00 2001 From: Pierre-Luc Dupont Date: Mon, 30 May 2016 10:15:14 -0400 Subject: [PATCH] Adding Issue resource, with test. --- README.md | 25 ++- .../rcarz/jiraclient/agile/AgileResource.java | 12 +- .../net/rcarz/jiraclient/agile/Comment.java | 20 ++ .../java/net/rcarz/jiraclient/agile/Epic.java | 20 ++ .../rcarz/jiraclient/agile/Estimation.java | 7 + .../net/rcarz/jiraclient/agile/Issue.java | 47 +++++ .../net/rcarz/jiraclient/agile/Project.java | 20 ++ .../rcarz/jiraclient/agile/TimeTracking.java | 20 ++ .../net/rcarz/jiraclient/agile/Worklog.java | 20 ++ .../agile/AbstractResourceTest.groovy | 42 ++-- .../jiraclient/agile/AgileClientTest.groovy | 4 +- .../rcarz/jiraclient/agile/BoardTest.groovy | 7 +- .../rcarz/jiraclient/agile/IssueTest.groovy | 67 +++++++ .../jiraclient/agile/JSONResources.groovy | 185 +++++++++++++++--- .../rcarz/jiraclient/agile/SprintTest.groovy | 12 +- 15 files changed, 446 insertions(+), 62 deletions(-) create mode 100644 src/main/java/net/rcarz/jiraclient/agile/Comment.java create mode 100644 src/main/java/net/rcarz/jiraclient/agile/Epic.java create mode 100644 src/main/java/net/rcarz/jiraclient/agile/Estimation.java create mode 100644 src/main/java/net/rcarz/jiraclient/agile/Issue.java create mode 100644 src/main/java/net/rcarz/jiraclient/agile/Project.java create mode 100644 src/main/java/net/rcarz/jiraclient/agile/TimeTracking.java create mode 100644 src/main/java/net/rcarz/jiraclient/agile/Worklog.java create mode 100644 src/test/groovy/net/rcarz/jiraclient/agile/IssueTest.groovy diff --git a/README.md b/README.md index 77268e0..b3d328c 100644 --- a/README.md +++ b/README.md @@ -280,7 +280,30 @@ https://docs.atlassian.com/jira-software/REST/cloud/ ### Agile supported calls ### 1. [AgileClient](src/main/java/net/rcarz/jiraclient/agile/AgileClient.java) - * GET /rest/agile/1.0/board + 1. GET /rest/agile/1.0/board + 1. GET /rest/agile/1.0/board/{boardId} + 1. GET /rest/agile/1.0/sprint/{sprintId} + 1. [Board](src/main/java/net/rcarz/jiraclient/agile/Board.java) + 1. GET /rest/agile/1.0/board + 1. GET /rest/agile/1.0/board/{boardId} + 1. GET /rest/agile/1.0/board/{boardId}/sprint + 1. [Sprint](src/main/java/net/rcarz/jiraclient/agile/Sprint.java) + 1. GET /rest/agile/1.0/sprint/{sprintId} + 1. GET /rest/agile/1.0/board/{boardId}/sprint + 1. To implement + 1. -- GET /rest/agile/1.0/board/{boardId}/backlog + 1. -- GET /rest/agile/1.0/board/{boardId}/epic + 1. -- GET /rest/agile/1.0/board/{boardId}/epic/{epicId}/issue + 1. -- GET /rest/agile/1.0/board/{boardId}/epic/none/issue + 1. -- GET /rest/agile/1.0/board/{boardId}/sprint/{sprintId}/issue + 1. -- GET /rest/agile/1.0/epic/{epicIdOrKey} + 1. -- GET /rest/agile/1.0/epic/{epicIdOrKey}/issue + 1. -- GET /rest/agile/1.0/epic/none/issue + 1. -- GET /rest/agile/1.0/issue/{issueIdOrKey} + 1. -- GET /rest/agile/1.0/issue/{issueIdOrKey}/estimation + 1. -- GET /rest/agile/1.0/sprint/{sprintId}/issue + + ### Agile Example ### diff --git a/src/main/java/net/rcarz/jiraclient/agile/AgileResource.java b/src/main/java/net/rcarz/jiraclient/agile/AgileResource.java index bacb52a..9fb7e35 100644 --- a/src/main/java/net/rcarz/jiraclient/agile/AgileResource.java +++ b/src/main/java/net/rcarz/jiraclient/agile/AgileResource.java @@ -133,12 +133,22 @@ public abstract class AgileResource { protected void deserialize(JSONObject json) { Map map = json; - id = Field.getInteger(map.get("id")); + id = getInteger(map.get("id")); name = Field.getString(map.get("name")); self = Field.getString(map.get("self")); attributes.putAll(map); } + private int getInteger(Object o) { + if (o instanceof Integer) { + return Field.getInteger(o); + } else if (o instanceof String && NumberUtils.isDigits((String) o)) { + return NumberUtils.toInt((String) o, 0); + } else { + return 0; + } + } + @Override public String toString() { return String.format("%s{id=%s, name='%s'}", getClass().getSimpleName(), id, name); diff --git a/src/main/java/net/rcarz/jiraclient/agile/Comment.java b/src/main/java/net/rcarz/jiraclient/agile/Comment.java new file mode 100644 index 0000000..256cab2 --- /dev/null +++ b/src/main/java/net/rcarz/jiraclient/agile/Comment.java @@ -0,0 +1,20 @@ +package net.rcarz.jiraclient.agile; + +import net.rcarz.jiraclient.RestClient; +import net.sf.json.JSONObject; + +/** + * Created by pldupont on 2016-05-20. + */ +public class Comment extends AgileResource { + + /** + * Creates a new Agile resource. + * + * @param restclient REST client instance + * @param json JSON payload + */ + public Comment(RestClient restclient, JSONObject json) { + super(restclient, json); + } +} diff --git a/src/main/java/net/rcarz/jiraclient/agile/Epic.java b/src/main/java/net/rcarz/jiraclient/agile/Epic.java new file mode 100644 index 0000000..0fc3b3f --- /dev/null +++ b/src/main/java/net/rcarz/jiraclient/agile/Epic.java @@ -0,0 +1,20 @@ +package net.rcarz.jiraclient.agile; + +import net.rcarz.jiraclient.RestClient; +import net.sf.json.JSONObject; + +/** + * Created by pldupont on 2016-05-20. + */ +public class Epic extends AgileResource { + + /** + * Creates a new Agile resource. + * + * @param restclient REST client instance + * @param json JSON payload + */ + public Epic(RestClient restclient, JSONObject json) { + super(restclient, json); + } +} diff --git a/src/main/java/net/rcarz/jiraclient/agile/Estimation.java b/src/main/java/net/rcarz/jiraclient/agile/Estimation.java new file mode 100644 index 0000000..b864c65 --- /dev/null +++ b/src/main/java/net/rcarz/jiraclient/agile/Estimation.java @@ -0,0 +1,7 @@ +package net.rcarz.jiraclient.agile; + +/** + * Created by pldupont on 2016-05-20. + */ +public class Estimation { +} diff --git a/src/main/java/net/rcarz/jiraclient/agile/Issue.java b/src/main/java/net/rcarz/jiraclient/agile/Issue.java new file mode 100644 index 0000000..d834995 --- /dev/null +++ b/src/main/java/net/rcarz/jiraclient/agile/Issue.java @@ -0,0 +1,47 @@ +package net.rcarz.jiraclient.agile; + +import net.rcarz.jiraclient.JiraException; +import net.rcarz.jiraclient.RestClient; +import net.sf.json.JSONObject; + +import java.util.List; + +/** + * Created by pldupont on 2016-05-20. + */ +public class Issue extends AgileResource { + + /** + * Creates a new Agile Issue resource. + * + * @param restclient REST client instance + * @param json JSON payload + */ + public Issue(RestClient restclient, JSONObject json) { + super(restclient, json); + } + + /** + * Retrieves the issue matching the ID. + * + * @param restclient REST client instance + * @param id Internal JIRA ID of the issue + * @return an issue instance + * @throws JiraException when the retrieval fails + */ + public static Issue get(RestClient restclient, int id) throws JiraException { + return AgileResource.get(restclient, Issue.class, RESOURCE_URI + "issue/" + id); + } + + /** + * Retrieves the issue matching the ID. + * + * @param restclient REST client instance + * @param key JIRA key of the issue + * @return an issue instance + * @throws JiraException when the retrieval fails + */ + public static Issue get(RestClient restclient, String key) throws JiraException { + return AgileResource.get(restclient, Issue.class, RESOURCE_URI + "issue/" + key); + } +} diff --git a/src/main/java/net/rcarz/jiraclient/agile/Project.java b/src/main/java/net/rcarz/jiraclient/agile/Project.java new file mode 100644 index 0000000..2607c66 --- /dev/null +++ b/src/main/java/net/rcarz/jiraclient/agile/Project.java @@ -0,0 +1,20 @@ +package net.rcarz.jiraclient.agile; + +import net.rcarz.jiraclient.RestClient; +import net.sf.json.JSONObject; + +/** + * Created by pldupont on 2016-05-20. + */ +public class Project extends AgileResource { + + /** + * Creates a new Agile resource. + * + * @param restclient REST client instance + * @param json JSON payload + */ + public Project(RestClient restclient, JSONObject json) { + super(restclient, json); + } +} diff --git a/src/main/java/net/rcarz/jiraclient/agile/TimeTracking.java b/src/main/java/net/rcarz/jiraclient/agile/TimeTracking.java new file mode 100644 index 0000000..54b8d88 --- /dev/null +++ b/src/main/java/net/rcarz/jiraclient/agile/TimeTracking.java @@ -0,0 +1,20 @@ +package net.rcarz.jiraclient.agile; + +import net.rcarz.jiraclient.RestClient; +import net.sf.json.JSONObject; + +/** + * Created by pldupont on 2016-05-20. + */ +public class TimeTracking extends AgileResource { + + /** + * Creates a new Agile resource. + * + * @param restclient REST client instance + * @param json JSON payload + */ + public TimeTracking(RestClient restclient, JSONObject json) { + super(restclient, json); + } +} diff --git a/src/main/java/net/rcarz/jiraclient/agile/Worklog.java b/src/main/java/net/rcarz/jiraclient/agile/Worklog.java new file mode 100644 index 0000000..7112079 --- /dev/null +++ b/src/main/java/net/rcarz/jiraclient/agile/Worklog.java @@ -0,0 +1,20 @@ +package net.rcarz.jiraclient.agile; + +import net.rcarz.jiraclient.RestClient; +import net.sf.json.JSONObject; + +/** + * Created by pldupont on 2016-05-20. + */ +public class Worklog extends AgileResource { + + /** + * Creates a new Agile resource. + * + * @param restclient REST client instance + * @param json JSON payload + */ + public Worklog(RestClient restclient, JSONObject json) { + super(restclient, json); + } +} diff --git a/src/test/groovy/net/rcarz/jiraclient/agile/AbstractResourceTest.groovy b/src/test/groovy/net/rcarz/jiraclient/agile/AbstractResourceTest.groovy index 965c4e4..b1f317b 100644 --- a/src/test/groovy/net/rcarz/jiraclient/agile/AbstractResourceTest.groovy +++ b/src/test/groovy/net/rcarz/jiraclient/agile/AbstractResourceTest.groovy @@ -5,7 +5,6 @@ import net.rcarz.jiraclient.RestClient import org.hamcrest.core.IsEqual import org.hamcrest.core.IsNot import org.hamcrest.core.IsNull -import org.junit.Test import static org.junit.Assert.assertThat import static org.mockito.Mockito.mock @@ -32,28 +31,41 @@ class AbstractResourceTest { void "Assert equals to Board 84"(Board board) { assertThat board, new IsNot<>(new IsNull()) - assertThat board.getId(), new IsEqual(JSONResources.BOARD_84_ID) - assertThat board.getName(), new IsEqual(JSONResources.BOARD_84_NAME) - assertThat board.getType(), new IsEqual(JSONResources.BOARD_84_TYPE) - assertThat board.getSelfURL(), new IsEqual(JSONResources.BOARD_84_SELF) + assertThat board.getId(), new IsEqual(JSONResources.BOARD_ID) + assertThat board.getName(), new IsEqual(JSONResources.BOARD_NAME) + assertThat board.getType(), new IsEqual(JSONResources.BOARD_TYPE) + assertThat board.getSelfURL(), new IsEqual(JSONResources.BOARD_SELF) assertThat board.toString(), new IsEqual( String.format("Board{id=%s, name='%s'}", - JSONResources.BOARD_84_ID, JSONResources.BOARD_84_NAME)) + JSONResources.BOARD_ID, JSONResources.BOARD_NAME)) } void "Assert equals to Sprint 37"(Sprint sprint) { assertThat sprint, new IsNot<>(new IsNull()) - assertThat sprint.getId(), new IsEqual(JSONResources.SPRINT_37_ID) - assertThat sprint.getName(), new IsEqual(JSONResources.SPRINT_37_NAME) - assertThat sprint.getSelfURL(), new IsEqual(JSONResources.SPRINT_37_SELF) - assertThat sprint.getState(), new IsEqual(JSONResources.SPRINT_37_STATE) - assertThat sprint.getOriginBoardId(), new IsEqual(JSONResources.SPRINT_37_ORIGIN_BOARD_ID) - assertThat sprint.getStartDate(), new IsEqual(JSONResources.SPRINT_37_START_DATE) - assertThat sprint.getEndDate(), new IsEqual(JSONResources.SPRINT_37_END_DATE) - assertThat sprint.getCompleteDate(), new IsEqual(JSONResources.SPRINT_37_COMPLETE_DATE) + assertThat sprint.getId(), new IsEqual(JSONResources.SPRINT_ID) + assertThat sprint.getName(), new IsEqual(JSONResources.SPRINT_NAME) + assertThat sprint.getSelfURL(), new IsEqual(JSONResources.SPRINT_SELF) + assertThat sprint.getState(), new IsEqual(JSONResources.SPRINT_STATE) + assertThat sprint.getOriginBoardId(), new IsEqual(JSONResources.SPRINT_ORIGIN_BOARD_ID) + assertThat sprint.getStartDate(), new IsEqual(JSONResources.SPRINT_START_DATE) + assertThat sprint.getEndDate(), new IsEqual(JSONResources.SPRINT_END_DATE) + assertThat sprint.getCompleteDate(), new IsEqual(JSONResources.SPRINT_COMPLETE_DATE) assertThat sprint.toString(), new IsEqual( String.format("Sprint{id=%s, name='%s'}", - JSONResources.SPRINT_37_ID, JSONResources.SPRINT_37_NAME)) + JSONResources.SPRINT_ID, JSONResources.SPRINT_NAME)) + } + + void "Assert equals to Issue 10001"(Issue issue) { + assertThat issue, new IsNot<>(new IsNull()) + assertThat issue.getId(), new IsEqual(JSONResources.ISSUE_ID) + assertThat issue.getName(), new IsNull() + assertThat issue.getSelfURL(), new IsEqual(JSONResources.ISSUE_SELF) + + } + + void "Assert equals to Issue HSP-1"(Issue issue) { + "Assert equals to Issue 10001"(issue) + } } diff --git a/src/test/groovy/net/rcarz/jiraclient/agile/AgileClientTest.groovy b/src/test/groovy/net/rcarz/jiraclient/agile/AgileClientTest.groovy index 80fbcc8..7820536 100644 --- a/src/test/groovy/net/rcarz/jiraclient/agile/AgileClientTest.groovy +++ b/src/test/groovy/net/rcarz/jiraclient/agile/AgileClientTest.groovy @@ -31,7 +31,7 @@ class AgileClientTest extends AbstractResourceTest { void "Given an agileClient, when calling getBoard(84), then receive one Board."() { "given an Agile Client"() when(mockRestClient.get(AgileResource.RESOURCE_URI + "board/84")) - .thenReturn(JSONSerializer.toJSON(JSONResources.BOARD_84)) + .thenReturn(JSONSerializer.toJSON(JSONResources.BOARD)) Board board = agileClient.getBoard(84); @@ -43,7 +43,7 @@ class AgileClientTest extends AbstractResourceTest { void "Given an agileClient, when calling getSprint(37), then receive one Sprint."() { "given an Agile Client"() when(mockRestClient.get(AgileResource.RESOURCE_URI + "sprint/37")) - .thenReturn(JSONSerializer.toJSON(JSONResources.SPRINT_37)) + .thenReturn(JSONSerializer.toJSON(JSONResources.SPRINT)) Sprint sprint = agileClient.getSprint(37); diff --git a/src/test/groovy/net/rcarz/jiraclient/agile/BoardTest.groovy b/src/test/groovy/net/rcarz/jiraclient/agile/BoardTest.groovy index 4311a42..8ed3fa0 100644 --- a/src/test/groovy/net/rcarz/jiraclient/agile/BoardTest.groovy +++ b/src/test/groovy/net/rcarz/jiraclient/agile/BoardTest.groovy @@ -4,15 +4,12 @@ import net.rcarz.jiraclient.JiraException import net.rcarz.jiraclient.RestClient import net.rcarz.jiraclient.RestException import net.sf.json.JSONSerializer -import org.hamcrest.Description -import org.hamcrest.Matcher import org.hamcrest.core.IsEqual import org.hamcrest.core.IsNot import org.hamcrest.core.IsNull import org.junit.Rule import org.junit.Test import org.junit.rules.ExpectedException -import org.mockito.internal.matchers.Contains import static org.junit.Assert.assertThat import static org.mockito.Mockito.when @@ -54,7 +51,7 @@ class BoardTest extends AbstractResourceTest { void "Given a RestClient, when calling getBoard(84), then receive one Board."() { RestClient mockRestClient = "given a REST Client"() when(mockRestClient.get(AgileResource.RESOURCE_URI + "board/84")) - .thenReturn(JSONSerializer.toJSON(JSONResources.BOARD_84)) + .thenReturn(JSONSerializer.toJSON(JSONResources.BOARD)) Board board = Board.get(mockRestClient, 84); @@ -77,7 +74,7 @@ class BoardTest extends AbstractResourceTest { void "Given a valid Board, when calling getSprints(), then receive a list of Sprints."() { RestClient mockRestClient = "given a REST Client"() when(mockRestClient.get(AgileResource.RESOURCE_URI + "board/84")) - .thenReturn(JSONSerializer.toJSON(JSONResources.BOARD_84)) + .thenReturn(JSONSerializer.toJSON(JSONResources.BOARD)) when(mockRestClient.get(AgileResource.RESOURCE_URI + "board/84/sprint")) .thenReturn(JSONSerializer.toJSON(JSONResources.LIST_OF_SPRINTS)) diff --git a/src/test/groovy/net/rcarz/jiraclient/agile/IssueTest.groovy b/src/test/groovy/net/rcarz/jiraclient/agile/IssueTest.groovy new file mode 100644 index 0000000..33ff1f4 --- /dev/null +++ b/src/test/groovy/net/rcarz/jiraclient/agile/IssueTest.groovy @@ -0,0 +1,67 @@ +package net.rcarz.jiraclient.agile + +import net.rcarz.jiraclient.JiraException +import net.rcarz.jiraclient.RestClient +import net.rcarz.jiraclient.RestException +import net.sf.json.JSONSerializer +import org.junit.Rule +import org.junit.Test +import org.junit.rules.ExpectedException + +import static org.mockito.Mockito.when +import static org.mockito.Mockito.when + +/** + * Created by pldupont on 2016-05-20. + */ +class IssueTest extends AbstractResourceTest { + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test + void "Given a valid issue ID, when calling Issue.get(id), then receive one Issue."() { + RestClient mockRestClient = "given a REST Client"() + when(mockRestClient.get(AgileResource.RESOURCE_URI + "issue/" + JSONResources.ISSUE_ID)) + .thenReturn(JSONSerializer.toJSON(JSONResources.ISSUE)) + + Issue issue = Issue.get(mockRestClient, JSONResources.ISSUE_ID); + + "Assert equals to Issue ${JSONResources.ISSUE_ID}"(issue) + } + + @Test + void "Given an invalid issue ID, when calling getIssue(666), then throws an 404 error."() { + RestException unauthorized = new RestException("Do not have access", 404, "Unauthorized") + RestClient mockRestClient = "given a REST Client"() + when(mockRestClient.get(AgileResource.RESOURCE_URI + "issue/666")) + .thenThrow(unauthorized) + expectedException.expect(JiraException.class); + expectedException.expectMessage("Failed to retrieve Issue : /rest/agile/1.0/issue/666"); + + Issue issue = Issue.get(mockRestClient, 666); + } + + @Test + void "Given a valid issue Key, when calling Issue.get(key), then receive one Issue."() { + RestClient mockRestClient = "given a REST Client"() + when(mockRestClient.get(AgileResource.RESOURCE_URI + "issue/" + JSONResources.ISSUE_KEY)) + .thenReturn(JSONSerializer.toJSON(JSONResources.ISSUE)) + + Issue issue = Issue.get(mockRestClient, JSONResources.ISSUE_KEY); + + "Assert equals to Issue ${JSONResources.ISSUE_KEY}"(issue) + } + + @Test + void "Given an invalid issue Key, when calling getIssue('HSP-2'), then throws an 404 error."() { + RestException unauthorized = new RestException("Do not have access", 404, "Unauthorized") + RestClient mockRestClient = "given a REST Client"() + when(mockRestClient.get(AgileResource.RESOURCE_URI + "issue/HSP-2")) + .thenThrow(unauthorized) + expectedException.expect(JiraException.class); + expectedException.expectMessage("Failed to retrieve Issue : /rest/agile/1.0/issue/HSP-2"); + + Issue issue = Issue.get(mockRestClient, "HSP-2"); + } +} diff --git a/src/test/groovy/net/rcarz/jiraclient/agile/JSONResources.groovy b/src/test/groovy/net/rcarz/jiraclient/agile/JSONResources.groovy index 3f5bb18..3b8c90c 100644 --- a/src/test/groovy/net/rcarz/jiraclient/agile/JSONResources.groovy +++ b/src/test/groovy/net/rcarz/jiraclient/agile/JSONResources.groovy @@ -7,24 +7,24 @@ import net.rcarz.jiraclient.Field */ interface JSONResources { - String BOARD_84 = """{ - "id": 84, - "self": "http://www.example.com/jira/rest/agile/1.0/board/84", - "name": "scrum board", - "type": "scrum" + String BOARD_SELF = "http://www.example.com/jira/rest/agile/1.0/board/84" + String BOARD_NAME = "scrum board" + String BOARD_TYPE = "scrum" + int BOARD_ID = 84 + String BOARD = """{ + "id": ${BOARD_ID}, + "self": "${BOARD_SELF}", + "name": "${BOARD_NAME}", + "type": "${BOARD_TYPE}" }""" - String BOARD_84_SELF = "http://www.example.com/jira/rest/agile/1.0/board/84" - String BOARD_84_NAME = "scrum board" - String BOARD_84_TYPE = "scrum" - int BOARD_84_ID = 84 String LIST_OF_BOARDS = """{ "maxResults": 2, "startAt": 1, - "total": 5, - "isLast": false, + "total": 2, + "isLast": true, "values": [ - ${BOARD_84}, + ${BOARD}, { "id": 92, "self": "http://www.example.com/jira/rest/agile/1.0/board/92", @@ -34,32 +34,32 @@ interface JSONResources { ] }""" - String SPRINT_37 = """{ - "id": 37, - "self": "http://www.example.com/jira/rest/agile/1.0/sprint/23", - "state": "closed", - "name": "sprint 1", - "startDate": "2015-04-11T15:22:00.000+10:00", - "endDate": "2015-04-20T01:22:00.000+10:00", - "completeDate": "2015-04-20T11:04:00.000+10:00", - "originBoardId": 84 + int SPRINT_ID = 37 + String SPRINT_NAME = "sprint 1" + String SPRINT_SELF = "http://www.example.com/jira/rest/agile/1.0/sprint/23" + String SPRINT_STATE = "closed" + int SPRINT_ORIGIN_BOARD_ID = BOARD_ID + Date SPRINT_START_DATE = Field.getDateTime("2015-04-11T15:22:00.000+10:00") + Date SPRINT_END_DATE = Field.getDateTime("2015-04-20T01:22:00.000+10:00") + Date SPRINT_COMPLETE_DATE = Field.getDateTime("2015-04-20T11:04:00.000+10:00") + String SPRINT = """{ + "id": ${SPRINT_ID}, + "self": "${SPRINT_SELF}", + "state": "${SPRINT_STATE}", + "name": "${SPRINT_NAME}", + "startDate": "${SPRINT_START_DATE}", + "endDate": "${SPRINT_END_DATE}", + "completeDate": "${SPRINT_COMPLETE_DATE}", + "originBoardId": ${BOARD_ID} }""" - int SPRINT_37_ID = 37 - String SPRINT_37_NAME = "sprint 1" - String SPRINT_37_SELF = "http://www.example.com/jira/rest/agile/1.0/sprint/23" - String SPRINT_37_STATE = "closed" - int SPRINT_37_ORIGIN_BOARD_ID = 84 - Date SPRINT_37_START_DATE = Field.getDateTime("2015-04-11T15:22:00.000+10:00") - Date SPRINT_37_END_DATE = Field.getDateTime("2015-04-20T01:22:00.000+10:00") - Date SPRINT_37_COMPLETE_DATE = Field.getDateTime("2015-04-20T11:04:00.000+10:00") String LIST_OF_SPRINTS = """{ "maxResults": 2, "startAt": 1, - "total": 5, - "isLast": false, + "total": 2, + "isLast": true, "values": [ - ${SPRINT_37}, + ${SPRINT}, { "id": 72, "self": "http://www.example.com/jira/rest/agile/1.0/sprint/73", @@ -68,4 +68,125 @@ interface JSONResources { } ] }""" + + int ISSUE_ID = 10001 + String ISSUE_SELF = "http://www.example.com/jira/rest/agile/1.0/board/92/issue/10001" + String ISSUE_KEY = "HSP-1" + String ISSUE = """{ + "expand": "", + "id": "${ISSUE_ID}", + "self": "${ISSUE_SELF}", + "key": "${ISSUE_KEY}", + "fields": { + "flagged": true, + "sprint": { + "id": 37, + "self": "http://www.example.com/jira/rest/agile/1.0/sprint/13", + "state": "future", + "name": "sprint 2" + }, + "closedSprints": [ + { + "id": 37, + "self": "http://www.example.com/jira/rest/agile/1.0/sprint/23", + "state": "closed", + "name": "sprint 1", + "startDate": "2015-04-11T15:22:00.000+10:00", + "endDate": "2015-04-20T01:22:00.000+10:00", + "completeDate": "2015-04-20T11:04:00.000+10:00" + } + ], + "description": "example bug report", + "project": { + "self": "http://www.example.com/jira/rest/api/2/project/EX", + "id": "10000", + "key": "EX", + "name": "Example", + "avatarUrls": { + "48x48": "http://www.example.com/jira/secure/projectavatar?size=large&pid=10000", + "24x24": "http://www.example.com/jira/secure/projectavatar?size=small&pid=10000", + "16x16": "http://www.example.com/jira/secure/projectavatar?size=xsmall&pid=10000", + "32x32": "http://www.example.com/jira/secure/projectavatar?size=medium&pid=10000" + }, + "projectCategory": { + "self": "http://www.example.com/jira/rest/api/2/projectCategory/10000", + "id": "10000", + "name": "FIRST", + "description": "First Project Category" + } + }, + "comment": [ + { + "self": "http://www.example.com/jira/rest/api/2/issue/10010/comment/10000", + "id": "10000", + "author": { + "self": "http://www.example.com/jira/rest/api/2/user?username=fred", + "name": "fred", + "displayName": "Fred F. User", + "active": false + }, + "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.", + "updateAuthor": { + "self": "http://www.example.com/jira/rest/api/2/user?username=fred", + "name": "fred", + "displayName": "Fred F. User", + "active": false + }, + "created": "2016-03-21T15:26:17.875+0100", + "updated": "2016-03-21T15:26:17.878+0100", + "visibility": { + "type": "role", + "value": "Administrators" + } + } + ], + "epic": { + "id": 37, + "self": "http://www.example.com/jira/rest/agile/1.0/epic/23", + "name": "epic 1", + "summary": "epic 1 summary", + "color": { + "key": "color_4" + }, + "done": true + }, + "worklog": [ + { + "self": "http://www.example.com/jira/rest/api/2/issue/10010/worklog/10000", + "author": { + "self": "http://www.example.com/jira/rest/api/2/user?username=fred", + "name": "fred", + "displayName": "Fred F. User", + "active": false + }, + "updateAuthor": { + "self": "http://www.example.com/jira/rest/api/2/user?username=fred", + "name": "fred", + "displayName": "Fred F. User", + "active": false + }, + "comment": "I did some work here.", + "updated": "2016-03-21T15:26:17.882+0100", + "visibility": { + "type": "group", + "value": "jira-developers" + }, + "started": "2016-03-21T15:26:17.881+0100", + "timeSpent": "3h 20m", + "timeSpentSeconds": 12000, + "id": "100028", + "issueId": "10002" + } + ], + "updated": 1, + "timetracking": { + "originalEstimate": "10m", + "remainingEstimate": "3m", + "timeSpent": "6m", + "originalEstimateSeconds": 600, + "remainingEstimateSeconds": 200, + "timeSpentSeconds": 400 + } + } +}""" } diff --git a/src/test/groovy/net/rcarz/jiraclient/agile/SprintTest.groovy b/src/test/groovy/net/rcarz/jiraclient/agile/SprintTest.groovy index e310bf9..8ae4c1f 100644 --- a/src/test/groovy/net/rcarz/jiraclient/agile/SprintTest.groovy +++ b/src/test/groovy/net/rcarz/jiraclient/agile/SprintTest.groovy @@ -25,10 +25,10 @@ class SprintTest extends AbstractResourceTest { @Test void "Given a RestClient, when calling getAll(), then receive a list of Sprint."() { RestClient mockRestClient = "given a REST Client"() - when(mockRestClient.get(AgileResource.RESOURCE_URI + "board/" + JSONResources.SPRINT_37_ORIGIN_BOARD_ID + "/sprint")) + when(mockRestClient.get(AgileResource.RESOURCE_URI + "board/" + JSONResources.SPRINT_ORIGIN_BOARD_ID + "/sprint")) .thenReturn(JSONSerializer.toJSON(JSONResources.LIST_OF_SPRINTS)) - List sprints = Sprint.getAll(mockRestClient, JSONResources.SPRINT_37_ORIGIN_BOARD_ID); + List sprints = Sprint.getAll(mockRestClient, JSONResources.SPRINT_ORIGIN_BOARD_ID); assertThat sprints, new IsNot<>(new IsNull()) assertThat sprints.size(), new IsEqual(2) @@ -39,19 +39,19 @@ class SprintTest extends AbstractResourceTest { void "Given a RestClient, when calling getAll() and use doesn't have access, then throws an 401 error."() { RestException unauthorized = new RestException("Do not have access", 401, "Unauthorized") RestClient mockRestClient = "given a REST Client"() - when(mockRestClient.get(AgileResource.RESOURCE_URI + "board/" + JSONResources.SPRINT_37_ORIGIN_BOARD_ID + "/sprint")) + when(mockRestClient.get(AgileResource.RESOURCE_URI + "board/" + JSONResources.SPRINT_ORIGIN_BOARD_ID + "/sprint")) .thenThrow(unauthorized) expectedException.expect(JiraException.class); - expectedException.expectMessage("Failed to retrieve a list of Sprint : /rest/agile/1.0/board/" + JSONResources.SPRINT_37_ORIGIN_BOARD_ID + "/sprint"); + expectedException.expectMessage("Failed to retrieve a list of Sprint : /rest/agile/1.0/board/" + JSONResources.SPRINT_ORIGIN_BOARD_ID + "/sprint"); - List sprints = Sprint.getAll(mockRestClient, JSONResources.SPRINT_37_ORIGIN_BOARD_ID); + List sprints = Sprint.getAll(mockRestClient, JSONResources.SPRINT_ORIGIN_BOARD_ID); } @Test void "Given a RestClient, when calling getSprint(84), then receive one Sprint."() { RestClient mockRestClient = "given a REST Client"() when(mockRestClient.get(AgileResource.RESOURCE_URI + "sprint/37")) - .thenReturn(JSONSerializer.toJSON(JSONResources.SPRINT_37)) + .thenReturn(JSONSerializer.toJSON(JSONResources.SPRINT)) Sprint sprint = Sprint.get(mockRestClient, 37);