GetFromEndpointHandler implements OutputOperationHandler<GetFromEndpoint, String> { @Override public String doOperation(final GetFromEndpoint operation, final Context context, final Store store) throws OperationException { try { return IOUtils.toString(new URL(operation.getEndpoint())); } catch (final IOException e) { throw new OperationException("Exception reading data from endpoint", e); } }  @Override String doOperation(final GetFromEndpoint operation, final Context context, final Store store);  }
@Test public void shouldGetElementsFromEndpoint() throws OperationException { mockServer.when(request() .withMethod("GET") .withPath(ENDPOINT_PATH)) .respond(response() .withStatusCode(200) .withBody(RESPONSE)); final String endpointString = ENDPOINT_BASE_PATH + port + ENDPOINT_PATH; GetFromEndpoint op = new GetFromEndpoint.Builder() .endpoint(endpointString) .build(); String result = handler.doOperation(op, context, store); assertEquals(RESPONSE, result); }
@Test public void shouldThrowExceptionWithMalformedEndpoint() { final String endpointString = "malformedUrl:" + port + ENDPOINT_PATH; GetFromEndpoint op = new GetFromEndpoint.Builder() .endpoint(endpointString) .build(); try { handler.doOperation(op, context, store); fail("Exception expected"); } catch (final OperationException e) { assertTrue(e.getCause().getClass().equals(MalformedURLException.class)); } }