@Test void testGetScheduleTimeJobNotFound(@Mock HttpRequest<Buffer> request, @Mock HttpResponse<Buffer> response) { when(webClient.get(anyString())).thenReturn(request); AsyncResult<HttpResponse<Buffer>> asyncResult = mock(AsyncResult.class); when(asyncResult.succeeded()).thenReturn(true); when(asyncResult.result()).thenReturn(response); when(response.statusCode()).thenReturn(404); doAnswer(invocationOnMock -> { Handler<AsyncResult<HttpResponse<Buffer>>> handler = invocationOnMock.getArgument(0); executor.submit(() -> handler.handle(asyncResult)); return null; }).when(request).send(any()); assertThatThrownBy(() -> tested.getScheduledTime("123")) .hasCauseExactlyInstanceOf(JobNotFoundException.class); verify(webClient).get("/jobs/123"); }
@Override public ZonedDateTime getScheduledTime(String id) { CompletableFuture<Job> future = new CompletableFuture<Job>(); client.get(JOBS_PATH + "/" + id).send(res -> { if (res.succeeded() && res.result().statusCode() == 200) { future.complete(res.result().bodyAsJson(Job.class)); } else if (res.succeeded() && res.result().statusCode() == 404) { future.completeExceptionally(new JobNotFoundException(id)); } else { future.completeExceptionally(new RuntimeException("Unable to find job with id " + id)); } }); try { return future.get().getExpirationTime(); } catch (Exception e) { if (e.getCause() != null) { throw new RuntimeException(e.getCause()); } throw new RuntimeException(e); } }
VertxJobsService extends RestJobsService { @Override public ZonedDateTime getScheduledTime(String id) { CompletableFuture<Job> future = new CompletableFuture<Job>(); client.get(JOBS_PATH + "/" + id).send(res -> { if (res.succeeded() && res.result().statusCode() == 200) { future.complete(res.result().bodyAsJson(Job.class)); } else if (res.succeeded() && res.result().statusCode() == 404) { future.completeExceptionally(new JobNotFoundException(id)); } else { future.completeExceptionally(new RuntimeException("Unable to find job with id " + id)); } }); try { return future.get().getExpirationTime(); } catch (Exception e) { if (e.getCause() != null) { throw new RuntimeException(e.getCause()); } throw new RuntimeException(e); } } }
VertxJobsService extends RestJobsService { @Override public ZonedDateTime getScheduledTime(String id) { CompletableFuture<Job> future = new CompletableFuture<Job>(); client.get(JOBS_PATH + "/" + id).send(res -> { if (res.succeeded() && res.result().statusCode() == 200) { future.complete(res.result().bodyAsJson(Job.class)); } else if (res.succeeded() && res.result().statusCode() == 404) { future.completeExceptionally(new JobNotFoundException(id)); } else { future.completeExceptionally(new RuntimeException("Unable to find job with id " + id)); } }); try { return future.get().getExpirationTime(); } catch (Exception e) { if (e.getCause() != null) { throw new RuntimeException(e.getCause()); } throw new RuntimeException(e); } } @Inject  VertxJobsService(@ConfigProperty(name = "kogito.jobs-service.url") String jobServiceUrl,
                            @ConfigProperty(name = "kogito.service.url") String callbackEndpoint,
                            Vertx vertx,
                            Instance<WebClient> providedWebClient);   VertxJobsService(); }
VertxJobsService extends RestJobsService { @Override public ZonedDateTime getScheduledTime(String id) { CompletableFuture<Job> future = new CompletableFuture<Job>(); client.get(JOBS_PATH + "/" + id).send(res -> { if (res.succeeded() && res.result().statusCode() == 200) { future.complete(res.result().bodyAsJson(Job.class)); } else if (res.succeeded() && res.result().statusCode() == 404) { future.completeExceptionally(new JobNotFoundException(id)); } else { future.completeExceptionally(new RuntimeException("Unable to find job with id " + id)); } }); try { return future.get().getExpirationTime(); } catch (Exception e) { if (e.getCause() != null) { throw new RuntimeException(e.getCause()); } throw new RuntimeException(e); } } @Inject  VertxJobsService(@ConfigProperty(name = "kogito.jobs-service.url") String jobServiceUrl,
                            @ConfigProperty(name = "kogito.service.url") String callbackEndpoint,
                            Vertx vertx,
                            Instance<WebClient> providedWebClient);   VertxJobsService(); @Override String scheduleProcessJob(ProcessJobDescription description); @Override String scheduleProcessInstanceJob(ProcessInstanceJobDescription description); @Override boolean cancelJob(String id); @Override ZonedDateTime getScheduledTime(String id); }
VertxJobsService extends RestJobsService { @Override public ZonedDateTime getScheduledTime(String id) { CompletableFuture<Job> future = new CompletableFuture<Job>(); client.get(JOBS_PATH + "/" + id).send(res -> { if (res.succeeded() && res.result().statusCode() == 200) { future.complete(res.result().bodyAsJson(Job.class)); } else if (res.succeeded() && res.result().statusCode() == 404) { future.completeExceptionally(new JobNotFoundException(id)); } else { future.completeExceptionally(new RuntimeException("Unable to find job with id " + id)); } }); try { return future.get().getExpirationTime(); } catch (Exception e) { if (e.getCause() != null) { throw new RuntimeException(e.getCause()); } throw new RuntimeException(e); } } @Inject  VertxJobsService(@ConfigProperty(name = "kogito.jobs-service.url") String jobServiceUrl,
                            @ConfigProperty(name = "kogito.service.url") String callbackEndpoint,
                            Vertx vertx,
                            Instance<WebClient> providedWebClient);   VertxJobsService(); @Override String scheduleProcessJob(ProcessJobDescription description); @Override String scheduleProcessInstanceJob(ProcessInstanceJobDescription description); @Override boolean cancelJob(String id); @Override ZonedDateTime getScheduledTime(String id);  }