public static TaskIdDto from(TaskId id) { return new TaskIdDto(id.getValue()); }
public UUID getTaskId() { return executionDetails.getTaskId().getValue(); }
private Object respondStatus(TaskId taskId, Supplier<TaskExecutionDetails> executionDetailsSupplier) { try { TaskExecutionDetails executionDetails = executionDetailsSupplier.get(); return ExecutionDetailsDto.from(executionDetails); } catch (TaskNotFoundException e) { throw ErrorResponder.builder() .message(String.format("%s can not be found", taskId.getValue())) .statusCode(HttpStatus.NOT_FOUND_404) .type(ErrorResponder.ErrorType.NOT_FOUND) .haltError(); } }
public static TaskIdDto respond(Response response, TaskId taskId) { response.status(HttpStatus.CREATED_201); response.header(LOCATION.asString(), TasksRoutes.BASE + "/" + taskId.getValue()); return TaskIdDto.from(taskId); }
@Test public void listShouldReturnTaskDetailsWhenTaskInProgress() throws Exception { CountDownLatch taskInProgressLatch = new CountDownLatch(1); TaskId taskId = taskManager.submit(() -> { taskInProgressLatch.countDown(); await(); return Task.Result.COMPLETED; }); taskInProgressLatch.await(); when() .get() .then() .statusCode(HttpStatus.OK_200) .body("", hasSize(1)) .body("[0].status", is(TaskManager.Status.IN_PROGRESS.getValue())) .body("[0].taskId", is(taskId.getValue().toString())) .body("[0].class", is(not(empty()))); }
@Test public void listShouldReturnTaskDetailsWhenTaskInProgress() throws Exception { CountDownLatch taskInProgressLatch = new CountDownLatch(1); TaskId taskId = taskManager.submit(() -> { taskInProgressLatch.countDown(); await(); return Task.Result.COMPLETED; }); taskInProgressLatch.await(); when() .get() .then() .statusCode(HttpStatus.OK_200) .body("", hasSize(1)) .body("[0].status", is(TaskManager.Status.IN_PROGRESS.getValue())) .body("[0].taskId", is(taskId.getValue().toString())) .body("[0].class", is(not(empty()))); }
@Test public void getShouldReturnTaskDetails() throws Exception { CountDownLatch inProgressLatch = new CountDownLatch(1); TaskId taskId = taskManager.submit(() -> { inProgressLatch.countDown(); await(); return Task.Result.COMPLETED; }); inProgressLatch.await(); when() .get("/" + taskId.getValue()) .then() .statusCode(HttpStatus.OK_200) .body("status", is("inProgress")); }
@Test public void getShouldReturnTaskDetails() throws Exception { CountDownLatch inProgressLatch = new CountDownLatch(1); TaskId taskId = taskManager.submit(() -> { inProgressLatch.countDown(); await(); return Task.Result.COMPLETED; }); inProgressLatch.await(); when() .get("/" + taskId.getValue()) .then() .statusCode(HttpStatus.OK_200) .body("status", is("inProgress")); }
@Test public void getAwaitShouldAwaitTaskCompletion() { TaskId taskId = taskManager.submit(() -> { try { Thread.sleep(100); } catch (InterruptedException e) { throw new RuntimeException(e); } return Task.Result.COMPLETED; }); when() .get("/" + taskId.getValue() + "/await") .then() .statusCode(HttpStatus.OK_200) .body("status", is("completed")); }
@Test public void getAwaitShouldAwaitTaskCompletion() { TaskId taskId = taskManager.submit(() -> { try { Thread.sleep(100); } catch (InterruptedException e) { throw new RuntimeException(e); } return Task.Result.COMPLETED; }); when() .get("/" + taskId.getValue() + "/await") .then() .statusCode(HttpStatus.OK_200) .body("status", is("completed")); }
@Test public void listShouldListTaskWhenStatusFilter() throws Exception { CountDownLatch inProgressLatch = new CountDownLatch(1); TaskId taskId = taskManager.submit(() -> { inProgressLatch.countDown(); await(); return Task.Result.COMPLETED; }); inProgressLatch.await(); given() .param("status", TaskManager.Status.IN_PROGRESS.getValue()) .when() .get() .then() .statusCode(HttpStatus.OK_200) .body("", hasSize(1)) .body("[0].status", is(TaskManager.Status.IN_PROGRESS.getValue())) .body("[0].taskId", is(taskId.getValue().toString())) .body("[0].type", is(Task.UNKNOWN)); }
@Test public void listShouldListTaskWhenStatusFilter() throws Exception { CountDownLatch inProgressLatch = new CountDownLatch(1); TaskId taskId = taskManager.submit(() -> { inProgressLatch.countDown(); await(); return Task.Result.COMPLETED; }); inProgressLatch.await(); given() .param("status", TaskManager.Status.IN_PROGRESS.getValue()) .when() .get() .then() .statusCode(HttpStatus.OK_200) .body("", hasSize(1)) .body("[0].status", is(TaskManager.Status.IN_PROGRESS.getValue())) .body("[0].taskId", is(taskId.getValue().toString())) .body("[0].type", is(Task.UNKNOWN)); }
@Test public void deleteShouldReturnOk() { TaskId taskId = taskManager.submit(() -> { await(); return Task.Result.COMPLETED; }); when() .delete("/" + taskId.getValue()) .then() .statusCode(HttpStatus.NO_CONTENT_204); }
@Test public void deleteShouldReturnOk() { TaskId taskId = taskManager.submit(() -> { await(); return Task.Result.COMPLETED; }); when() .delete("/" + taskId.getValue()) .then() .statusCode(HttpStatus.NO_CONTENT_204); }