DiscoveredServiceWorkItemHandler implements WorkItemHandler { protected Map<String, Object> discoverAndCall(WorkItem workItem, String namespace, String serviceName, HttpMethods method) { Map<String, Object> data = new HashMap<>(workItem.getParameters()); String service = (String) data.remove(serviceName); INTERNAL_FIELDS.forEach(field -> data.remove(field)); ServiceInfo endpoint = serviceEndpoints.computeIfAbsent(service, (s) -> findEndpoint(namespace, s)); LOGGER.debug("Found endpoint for service {} with location {}", service, endpoint); RequestBody body = produceRequestPayload(data); Request request = null; switch (method) { case POST: request = producePostRequest(endpoint, body); break; case GET: request = produceGetRequest(endpoint); break; case PUT: request = producePutRequest(endpoint, body); break; case DELETE: request = produceDeleteRequest(endpoint, body); break; default: break; } try (Response response = this.buildHttpClient().newCall(request).execute()) { Map<String, Object> results = produceResultsFromResponse(response); return results; } catch (IOException e) { throw new RuntimeException(e); } } DiscoveredServiceWorkItemHandler(); protected  DiscoveredServiceWorkItemHandler(final KogitoKubeClient kubeClient);   }
@Test public void testGivenEndpoint() throws IOException { DiscoveredServiceWorkItemHandler handler = new TestDiscoveredServiceWorkItemHandler("test", "http: WorkItem workItem = Mockito.mock(WorkItem.class); when(workItem.getParameters()).thenReturn(Collections.singletonMap("service", "test")); Call call = mock(Call.class); ResponseBody body = new ResponseBody() { private String content = "{\"test\" : \"fake\"}"; @Override public BufferedSource source() { Buffer b = new Buffer(); b.write(content.getBytes()); return b; } @Override public MediaType contentType() { return MediaType.parse("application/json"); } @Override public long contentLength() { return content.length(); } }; Response response = new Response.Builder().body(body).protocol(Protocol.HTTP_1_1).message("test").request(new Request.Builder().url("http: when(call.execute()).thenReturn(response); when(httpClient.newCall(any())).thenReturn(call); Map<String, Object> results = handler.discoverAndCall(workItem, "", "service", HttpMethods.POST); assertThat(results).isNotNull().containsKey("test").containsValue("fake"); }