Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADDED: TasksApi gained endpoint 'get' #108

Merged
merged 1 commit into from
Jul 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public abstract class TaskAnchor {

public abstract long updatedDate();

@Nullable
public abstract PermittedOperations permittedOperations();

@Nullable
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/cdancy/bitbucket/rest/features/TasksApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@

import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import javax.ws.rs.core.MediaType;
Expand All @@ -46,4 +48,13 @@ public interface TasksApi {
@Fallback(BitbucketFallbacks.TaskOnError.class)
@POST
Task create(@BinderParam(BindToJsonPayload.class) CreateTask createTask);


@Named("tasks:get")
@Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/latest/bitbucket-rest.html#idm45701777641664"})
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{taskId}")
@Fallback(BitbucketFallbacks.TaskOnError.class)
@GET
Task get(@PathParam("taskId") int taskId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class TasksApiLiveTest extends BaseBitbucketApiLiveTest {
private final String commentText = randomString();
private final String taskComment = randomString();
private int commentId = -1;
private int taskId = -1;

@BeforeClass
public void init() {
Expand Down Expand Up @@ -93,6 +94,7 @@ public void testCreateTask() {
assertThat(createdTask).isNotNull();
assertThat(createdTask.errors().isEmpty()).isTrue();
assertThat(createTask.text()).isEqualTo(taskComment);
this.taskId = createdTask.id();
}

@Test
Expand All @@ -103,6 +105,21 @@ public void testCreateTaskOnError() {
assertThat(createdTask.errors().isEmpty()).isFalse();
}

@Test (dependsOnMethods = "testCreateTask")
public void testGetTask() {
final Task getTask = api().get(this.taskId);
assertThat(getTask).isNotNull();
assertThat(getTask.errors().isEmpty()).isTrue();
assertThat(getTask.text()).isEqualTo(taskComment);
}

@Test
public void testGetTaskOnError() {
final Task getTask = api().get(99999);
assertThat(getTask).isNotNull();
assertThat(getTask.errors().isEmpty()).isFalse();
}

@AfterClass
public void fin() {
terminateGeneratedTestContents(generatedTestContents);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,44 @@ public void testCreateTaskOnErrors() throws Exception {
server.shutdown();
}
}

public void testGetTask() throws Exception {
MockWebServer server = mockEtcdJavaWebServer();

server.enqueue(new MockResponse().setBody(payloadFromResource("/task.json")).setResponseCode(200));
BitbucketApi baseApi = api(server.getUrl("/"));
TasksApi api = baseApi.tasksApi();
try {

final int taskId = 99;
final Task task = api.get(taskId);
assertThat(task).isNotNull();
assertThat(task.errors().isEmpty()).isTrue();
assertThat(task.id()).isEqualTo(taskId);
assertSent(server, "GET", "/rest/api/1.0/tasks/" + taskId);
} finally {
baseApi.close();
server.shutdown();
}
}

public void testGetTaskOnErrors() throws Exception {
MockWebServer server = mockEtcdJavaWebServer();

server.enqueue(new MockResponse().setBody(payloadFromResource("/errors.json")).setResponseCode(404));
BitbucketApi baseApi = api(server.getUrl("/"));
TasksApi api = baseApi.tasksApi();
try {

final int taskId = 99;
final Task task = api.get(taskId);
assertThat(task).isNotNull();
assertThat(task.errors().isEmpty()).isFalse();
assertThat(task.anchor()).isNull();
assertSent(server, "GET", "/rest/api/1.0/tasks/" + taskId);
} finally {
baseApi.close();
server.shutdown();
}
}
}