1
0
Fork 0

fluent remote link issue creation

created test cases
master
pejobo 2015-06-22 23:56:59 +02:00
parent 822c4c9593
commit 763232eced
2 changed files with 72 additions and 16 deletions

View File

@ -149,22 +149,14 @@ public class Issue extends Resource {
final private RestClient restclient;
final private String key;
final private JSONObject request;
final private JSONObject object;
private FluentRemoteLink(final RestClient restclient, String key) {
this.restclient = restclient;
this.key = key;
request = new JSONObject();
}
private JSONObject getObject() {
JSONObject object = (JSONObject) request.get("object");
if (object == null) {
object = new JSONObject();
request.put("object", object);
}
return object;
object = new JSONObject();
}
@ -188,7 +180,7 @@ public class Issue extends Resource {
* @return this instance
*/
public FluentRemoteLink url(final String url) {
getObject().put("url", url);
object.put("url", url);
return this;
}
@ -199,7 +191,7 @@ public class Issue extends Resource {
* @return this instance
*/
public FluentRemoteLink title(final String title) {
getObject().put("title", title);
object.put("title", title);
return this;
}
@ -214,7 +206,7 @@ public class Issue extends Resource {
final JSONObject icon = new JSONObject();
icon.put("url16x16", url);
icon.put("title", title);
getObject().put("icon", icon);
object.put("icon", icon);
return this;
}
@ -239,7 +231,7 @@ public class Issue extends Resource {
icon.put("link", statusUrl);
}
status.put("icon", icon);
getObject().put("status", status);
object.put("status", status);
return this;
}
@ -250,7 +242,7 @@ public class Issue extends Resource {
* @return this instance
*/
public FluentRemoteLink summary(final String summary) {
getObject().put("summary", summary);
object.put("summary", summary);
return this;
}
@ -293,6 +285,7 @@ public class Issue extends Resource {
*/
public void create() throws JiraException {
try {
request.put("object", object);
restclient.post(getRestUri(key) + "/remotelink", request);
} catch (Exception ex) {
throw new JiraException("Failed add remote link to issue " + key, ex);

View File

@ -8,6 +8,9 @@ import static org.junit.Assert.assertNotNull;
import java.util.List;
import java.util.Map;
import net.sf.json.JSON;
import net.sf.json.JSONNull;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.Assert;
@ -100,7 +103,7 @@ public class IssueTest {
@Test
public void testGetVersion(){
Issue issue = new Issue(null,Utils.getTestIssue());
Issue issue = new Issue(null, Utils.getTestIssue());
List<Version> versions = issue.getFixVersions();
assertNotNull(versions);
@ -136,4 +139,64 @@ public class IssueTest {
assertEquals(new DateTime(2013, 10, 9, 22, 24, 55, 961, DateTimeZone.forOffsetHours(1)).toDate(), issue.getUpdatedDate());
}
@Test
public void testAddRemoteLink() throws JiraException {
final TestableRestClient restClient = new TestableRestClient();
Issue issue = new Issue(restClient, Utils.getTestIssue());
issue.addRemoteLink("test-url", "test-title", "test-summary");
assertEquals("/rest/api/latest/issue/FILTA-43/remotelink", restClient.postPath);
assertEquals("{\"object\":{\"url\":\"test-url\",\"title\":\"test-title\",\"summary\":\"test-summary\"}}", restClient.postPayload.toString(0));
}
@Test
public void testRemoteLink() throws JiraException {
final TestableRestClient restClient = new TestableRestClient();
Issue issue = new Issue(restClient, Utils.getTestIssue());
issue.remoteLink()
.globalId("gid")
.title("test-title")
.summary("summary")
.application("app-type", "app-name")
.relationship("fixes")
.icon("icon", "icon-url")
.status(true, "status-icon", "status-title", "status-url")
.create();
assertEquals("/rest/api/latest/issue/FILTA-43/remotelink", restClient.postPath);
assertEquals(
"{\"globalId\":\"gid\"," +
"\"application\":" +
"{\"type\":\"app-type\",\"name\":\"app-name\"}," +
"\"relationship\":\"fixes\"," +
"\"object\":{" +
"\"url\":\"gid\"," +
"\"title\":\"test-title\"," +
"\"summary\":\"summary\"," +
"\"icon\":" +
"{\"url16x16\":\"icon\",\"title\":\"icon-url\"}," +
"\"status\":{\"resolved\":\"true\",\"icon\":" +
"{\"title\":\"status-title\",\"url16x16\":\"status-icon\",\"link\":\"status-url\"}" +
"}}}",
restClient.postPayload.toString(0));
}
private static class TestableRestClient extends RestClient {
public String postPath = "not called";
public JSON postPayload = JSONNull.getInstance();
public TestableRestClient() {
super(null, null);
}
@Override
public JSON post(String path, JSON payload) {
postPath = path;
postPayload = payload;
return null;
}
}
}