1
0
Fork 0
jira-client/src/test/groovy/net/rcarz/jiraclient/agile/SprintTest.groovy

89 lines
3.7 KiB
Groovy
Raw Normal View History

package net.rcarz.jiraclient.agile
import net.rcarz.jiraclient.JiraException
import net.rcarz.jiraclient.RestClient
import net.rcarz.jiraclient.RestException
2016-06-01 15:27:50 -05:00
import net.sf.json.JSONObject
import net.sf.json.JSONSerializer
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 static org.junit.Assert.assertThat
import static org.mockito.Mockito.when
/**
2016-05-30 15:40:26 -05:00
* Created on 2016-05-19.
* @author pldupont
*/
class SprintTest extends AbstractResourceTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
void "Given a RestClient, when calling getAll(), then receive a list of Sprint."() {
RestClient mockRestClient = "given a REST Client"()
2016-05-30 09:15:14 -05:00
when(mockRestClient.get(AgileResource.RESOURCE_URI + "board/" + JSONResources.SPRINT_ORIGIN_BOARD_ID + "/sprint"))
.thenReturn(JSONSerializer.toJSON(JSONResources.LIST_OF_SPRINTS))
2016-05-30 09:15:14 -05:00
List<Sprint> sprints = Sprint.getAll(mockRestClient, JSONResources.SPRINT_ORIGIN_BOARD_ID);
assertThat sprints, new IsNot<>(new IsNull())
assertThat sprints.size(), new IsEqual<Integer>(2)
"Assert equals to Sprint"(sprints.get(0))
}
@Test
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"()
2016-05-30 09:15:14 -05:00
when(mockRestClient.get(AgileResource.RESOURCE_URI + "board/" + JSONResources.SPRINT_ORIGIN_BOARD_ID + "/sprint"))
.thenThrow(unauthorized)
expectedException.expect(JiraException.class);
2016-05-30 09:15:14 -05:00
expectedException.expectMessage("Failed to retrieve a list of Sprint : /rest/agile/1.0/board/" + JSONResources.SPRINT_ORIGIN_BOARD_ID + "/sprint");
2016-05-30 15:40:26 -05:00
Sprint.getAll(mockRestClient, JSONResources.SPRINT_ORIGIN_BOARD_ID);
}
@Test
2016-05-30 15:40:26 -05:00
void "Given a RestClient, when calling getSprint(sprintId), then receive one Sprint."() {
RestClient mockRestClient = "given a REST Client"()
2016-05-30 15:40:26 -05:00
when(mockRestClient.get(AgileResource.RESOURCE_URI + "sprint/${JSONResources.SPRINT_ID}"))
2016-05-30 09:15:14 -05:00
.thenReturn(JSONSerializer.toJSON(JSONResources.SPRINT))
2016-05-30 15:40:26 -05:00
Sprint sprint = Sprint.get(mockRestClient, JSONResources.SPRINT_ID);
"Assert equals to Sprint"(sprint)
}
@Test
void "Given a RestClient, when calling getSprint(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 + "sprint/666"))
.thenThrow(unauthorized)
expectedException.expect(JiraException.class);
expectedException.expectMessage("Failed to retrieve Sprint : /rest/agile/1.0/sprint/666");
2016-05-30 15:40:26 -05:00
Sprint.get(mockRestClient, 666);
}
2016-06-01 15:27:50 -05:00
@Test
void "Given a valid Sprint, when calling getIssues(), then receive a list of Issues."() {
RestClient mockRestClient = "given a REST Client"()
Sprint mockSprint = new Sprint(mockRestClient, JSONSerializer.toJSON(JSONResources.SPRINT) as JSONObject)
when(mockRestClient.get(AgileResource.RESOURCE_URI + "sprint/${JSONResources.SPRINT_ID}/issue"))
.thenReturn(JSONSerializer.toJSON(JSONResources.LIST_OF_ISSUES))
List<Issue> issues = mockSprint.getIssues();
assertThat issues, new IsNot<>(new IsNull())
assertThat issues.size(), new IsEqual<Integer>(4)
"Assert equals to Issue"(issues.get(0))
2016-06-01 15:27:50 -05:00
}
}