1
0
Fork 0

Adding test for the Agile API

master
Pierre-Luc Dupont 2016-05-19 11:24:06 -04:00
parent 93d7d52031
commit 69592a9d4e
9 changed files with 203 additions and 3 deletions

View File

@ -3,3 +3,4 @@ Kyle Chaplin <chaplinkyle@gmail.com> @chaplinkyle
Alesandro Lang <info@alesandro-lang.com> @alesandroLang
Javier Molina <javinovich@gmail.com> @javinovich
Joseph McCarthy <luckymikuhatsune@gmail.com>
Pierre-Luc Dupont <pldupont@gmail.com> @pldupont

View File

@ -274,3 +274,38 @@ public class Example {
}
}
```
## Agile Example ##
https://docs.atlassian.com/jira-software/REST/cloud/
```java
import java.util.List;
import net.rcarz.jiraclient.BasicCredentials;
import net.rcarz.jiraclient.Issue;
import net.rcarz.jiraclient.JiraClient;
import net.rcarz.jiraclient.JiraException;
import net.rcarz.jiraclient.agile.Board;
import net.rcarz.jiraclient.agile.AgileClient;
public class Example {
public static void main(String[] args) {
BasicCredentials creds = new BasicCredentials("batman", "pow! pow!");
JiraClient jira = new JiraClient("https://jira.example.com/jira", creds);
AgileClient agileClient = new AgileClient(jira);
try {
/* Retrieve all Boards */
List<Board> allBoards = agileClient.getBoards();
} catch (JiraException ex) {
System.err.println(ex.getMessage());
if (ex.getCause() != null) {
System.err.println(ex.getCause().getMessage());
}
}
}
}
```

View File

@ -27,6 +27,7 @@ import java.util.List;
/**
* An Agile extension to the JIRA client.
* @see "https://docs.atlassian.com/jira-software/REST/cloud/"
*/
public class AgileClient {

View File

@ -45,7 +45,7 @@ public abstract class AgileResource {
public static final String ATTR_NAME = "name";
public static final String ATTR_SELF = "self";
protected static final String RESOURCE_URI = "/rest/agile/1.0/";
public static final String RESOURCE_URI = "/rest/agile/1.0/";
private RestClient restclient = null;
private int id = 0;

View File

@ -19,6 +19,7 @@
package net.rcarz.jiraclient.agile;
import net.rcarz.jiraclient.Field;
import net.rcarz.jiraclient.JiraException;
import net.rcarz.jiraclient.RestClient;
import net.sf.json.JSONObject;
@ -34,8 +35,10 @@ public class Board extends AgileResource {
public static final String ATTR_TYPE = "type";
private String type;
/**
* Creates a rapid view from a JSON payload.
* Creates a Board from a JSON payload.
*
* @param restclient REST client instance
* @param json JSON payload
@ -44,6 +47,12 @@ public class Board extends AgileResource {
super(restclient, json);
}
@Override
protected void deserialize(JSONObject json) {
super.deserialize(json);
type = Field.getString(json.get(ATTR_TYPE));
}
/**
* Retrieves the given rapid view.
*
@ -71,7 +80,7 @@ public class Board extends AgileResource {
* @return The board type.
*/
public String getType() {
return getAttribute(ATTR_TYPE);
return this.type;
}
public List<Sprint> getSprints() throws JiraException {

View File

@ -0,0 +1,40 @@
package net.rcarz.jiraclient.agile
import net.rcarz.jiraclient.JiraClient
import net.rcarz.jiraclient.RestClient
import org.hamcrest.core.IsEqual
import org.hamcrest.core.IsNot
import org.hamcrest.core.IsNull
import static org.junit.Assert.assertThat
import static org.mockito.Mockito.mock
import static org.mockito.Mockito.when
/**
* Created by pldupont on 2016-05-19.
*/
class AbstractResourceTest {
AgileClient agileClient;
RestClient mockRestClient;
void "given an Agile Client"() {
mockRestClient = mock RestClient.class
def mockJiraClient = mock JiraClient.class
when(mockJiraClient.getRestClient()).thenReturn(mockRestClient)
agileClient = new AgileClient(mockJiraClient)
}
RestClient "given a REST Client"() {
mockRestClient = mock RestClient.class
return mockRestClient
}
void "Assert equals to Board 84"(Board board) {
assertThat board, new IsNot<>(new IsNull())
assertThat board.getId(), new IsEqual<Integer>(JSONResources.BOARD_84_ID)
assertThat board.getName(), new IsEqual<Integer>(JSONResources.BOARD_84_NAME)
assertThat board.getType(), new IsEqual<Integer>(JSONResources.BOARD_84_TYPE)
assertThat board.getSelfURL(), new IsEqual<Integer>(JSONResources.BOARD_84_SELF)
}
}

View File

@ -0,0 +1,39 @@
package net.rcarz.jiraclient.agile
import net.sf.json.JSONSerializer
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.when
/**
* Created by pldupont on 2016-05-19.
*/
class AgileClientTest extends AbstractResourceTest {
@Test
void "Given an agileClient, when calling getBoards(), then receive a list of Board."() {
"given an Agile Client"()
when(mockRestClient.get(AgileResource.RESOURCE_URI + "board"))
.thenReturn(JSONSerializer.toJSON(JSONResources.LIST_OF_BOARDS))
List<Board> boards = agileClient.getBoards();
assertThat boards, new IsNot<>(new IsNull())
assertThat boards.size(), new IsEqual<Integer>(2)
}
@Test
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))
Board board = agileClient.getBoard(84);
assertThat board, new IsNot<>(new IsNull())
}
}

View File

@ -0,0 +1,41 @@
package net.rcarz.jiraclient.agile
import net.rcarz.jiraclient.RestClient
import net.sf.json.JSONSerializer
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.when
/**
* Created by pldupont on 2016-05-19.
*/
class BoardTest extends AbstractResourceTest {
@Test
void "Given an RestClient, when calling getAll(), then receive a list of Board."() {
RestClient mockRestClient = "given a REST Client"()
when(mockRestClient.get(AgileResource.RESOURCE_URI + "board"))
.thenReturn(JSONSerializer.toJSON(JSONResources.LIST_OF_BOARDS))
List<Board> boards = Board.getAll(mockRestClient);
assertThat boards, new IsNot<>(new IsNull())
assertThat boards.size(), new IsEqual<Integer>(2)
"Assert equals to Board 84"(boards.get(0))
}
@Test
void "Given an agileClient, 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))
Board board = Board.get(mockRestClient, 84);
"Assert equals to Board 84"(board)
}
}

View File

@ -0,0 +1,34 @@
package net.rcarz.jiraclient.agile
/**
* Created by pldupont on 2016-05-19.
*/
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_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,
"values": [
${BOARD_84},
{
"id": 92,
"self": "http://www.example.com/jira/rest/agile/1.0/board/92",
"name": "kanban board",
"type": "kanban"
}
]
}"""
}