public PolicyTestResponse send(final PolicyTestRequest ptRequest) throws PolicyFailureError, Throwable {
        final Set<Throwable> errorHolder = new HashSet<>();
        final Set<PolicyFailure> failureHolder = new HashSet<>();
        final Set<ApiResponse> responseHolder = new HashSet<>();
        final StringBuilder responseBody = new StringBuilder();

        IEngine engine = tester.getEngine();
        ApiRequest srequest = tester.createApiRequest();
        srequest.setUrl("http://localhost:8080" + ptRequest.resource()); //$NON-NLS-1$
        srequest.setDestination(ptRequest.resource());
        srequest.setType(ptRequest.method().name());
        srequest.getHeaders().putAll(ptRequest.headers());
        srequest.getQueryParams().putAll(ptRequest.queryParams());

        IApiRequestExecutor executor = engine.executor(srequest, new IAsyncResultHandler<IEngineResult>() {
            @Override
            public void handle(IAsyncResult<IEngineResult> result) {
                if (result.isError()) {
                    errorHolder.add(result.getError());
                } else {
                    IEngineResult engineResult = result.getResult();
                    if (engineResult.isFailure()) {
                        failureHolder.add(engineResult.getPolicyFailure());
                    } else {
                        responseHolder.add(engineResult.getApiResponse());
                        engineResult.bodyHandler(new IAsyncHandler<IApimanBuffer>() {
                            @Override
                            public void handle(IApimanBuffer result) {
                                responseBody.append(new String(result.getBytes()));
                            }
                        });
                        engineResult.endHandler(new IAsyncHandler<Void>() {
                            @Override
                            public void handle(Void result) {
                            }
                        });
                    }
                }
            }
        });
        executor.streamHandler(new IAsyncHandler<ISignalWriteStream>() {
            @Override
            public void handle(ISignalWriteStream stream) {
                if (ptRequest.body() != null) {
                    ByteBuffer buffer = new ByteBuffer(ptRequest.body());
                    stream.write(buffer);
                }
                stream.end();
            }
        });

        // Push any context attributes into the Policy Context.
        IPolicyContext policyContext = getContext(executor);
        Map<String, Object> contextAttributes = ptRequest.contextAttributes();
        for (Entry<String, Object> entry : contextAttributes.entrySet()) {
            policyContext.setAttribute(entry.getKey(), entry.getValue());
        }

        // Execute the request.
        executor.execute();

        if (!errorHolder.isEmpty()) {
            throw errorHolder.iterator().next();
        }
        if (!failureHolder.isEmpty()) {
            throw new PolicyFailureError(failureHolder.iterator().next());
        }
        if (!responseHolder.isEmpty()) {
            ApiResponse response = responseHolder.iterator().next();
            return new PolicyTestResponse(response, responseBody.toString());
        }
        throw new Exception("No response found from request!"); //$NON-NLS-1$
    }
Base class for all apiman policy tests.

@author eric.wittmann@redhat.com
test/policies/src/main/java/io/apiman/test/policies/ApimanPolicyTest.java