@Override
  public JHttpResponse invoke(JHttpQuery query, JHttpEndpoint endpoint) throws InvocationException {
    if (query.getMethod().equals(HttpMethod.DELETE)) {
      String path = query.getPath();
      Long id = Long.valueOf(path.substring(path.lastIndexOf("/") + 1));
      TestContext.getCreatedExecutionIds().remove(id);
      TestContext.setFirstRemovedExecution(id);
    }

    JHttpResponse result = super.invoke(query, endpoint);

    if (query.getMethod().equals(HttpMethod.POST) && result.getStatus().is2xxSuccessful()) {
      TestContext.addCreatedExecutionId(((ExecutionEntity) result.getBody()).getId());
    }
    return result;
  }
  @Override
  public JHttpResponse execute(JHttpEndpoint endpoint, JHttpQuery query) {
    if (query == null) return execute(endpoint);

    URI endpointURI = endpoint.getURI(query.getPath(), query.getQueryParams());
    RequestEntity requestEntity = mapToRequestEntity(query, endpointURI);
    ResponseEntity responseEntity;
    if (query.getResponseBodyType() != null) {
      responseEntity =
          restTemplate.exchange(
              endpointURI, query.getMethod(), requestEntity, query.getResponseBodyType());
    } else {
      responseEntity =
          restTemplate.exchange(endpointURI, query.getMethod(), requestEntity, byte[].class);
    }
    return mapToJHttpResponse(responseEntity);
  }
 private <T> RequestEntity<T> mapToRequestEntity(JHttpQuery<T> query, URI endpointURI) {
   return new RequestEntity<>(query.getBody(), query.getHeaders(), query.getMethod(), endpointURI);
 }