Java Code Examples for io.vertx.junit5.VertxTestContext#ExecutionBlock

The following examples show how to use io.vertx.junit5.VertxTestContext#ExecutionBlock . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestRequest.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
private Handler<AsyncResult<HttpResponse<Buffer>>> generateHandleResponse(VertxTestContext testContext, VertxTestContext.ExecutionBlock onEnd, Promise<HttpResponse<Buffer>> fut, StackTraceElement[] stackTrace) {
  return ar -> {
    if (ar.failed()) {
      testContext.failNow(ar.cause());
    } else {
      testContext.verify(() -> {
        try {
          this.responseAsserts.forEach(c -> c.accept(ar.result()));
        } catch (AssertionError e) {
          AssertionError newE = new AssertionError("Assertion error in response: " + e.getMessage(), e);
          newE.setStackTrace(stackTrace);
          throw newE;
        }
        onEnd.apply();
      });
      fut.complete(ar.result());
    }
  };
}
 
Example 2
Source File: TestRequest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
private Future<HttpResponse<Buffer>> internalSend(VertxTestContext testContext, Consumer<Handler<AsyncResult<HttpResponse<Buffer>>>> reqSendFunction, VertxTestContext.ExecutionBlock onEnd) {
  Promise<HttpResponse<Buffer>> promise = Promise.promise();
  this.requestTranformations.forEach(c -> c.accept(req));
  StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
  reqSendFunction.accept(generateHandleResponse(testContext, onEnd, promise, Arrays.copyOfRange(
    stackTrace,
    3,
    stackTrace.length
  )));
  return promise.future();
}
 
Example 3
Source File: TestRequest.java    From vertx-web with Apache License 2.0 2 votes vote down vote up
/**
 * Send and execute {@code onEnd} code block wrapped in {@link VertxTestContext#verify(VertxTestContext.ExecutionBlock)}
 * when request is completed and no assertion fails
 *
 * @param testContext
 * @param onEnd
 * @return a future that will be completed when the response is ready and no response assertion fails
 */
public Future<HttpResponse<Buffer>> send(VertxTestContext testContext, VertxTestContext.ExecutionBlock onEnd) {
  return internalSend(testContext, h -> req.send(h), onEnd);
}
 
Example 4
Source File: TestRequest.java    From vertx-web with Apache License 2.0 2 votes vote down vote up
/**
 * Send a json and execute {@code onEnd} code block wrapped in {@link VertxTestContext#verify(VertxTestContext.ExecutionBlock)}
 * when request is completed and no assertion fails
 *
 * @param json
 * @param testContext
 * @param onEnd
 * @return a future that will be completed when the response is ready and no response assertion fails
 */
public Future<HttpResponse<Buffer>> sendJson(Object json, VertxTestContext testContext, VertxTestContext.ExecutionBlock onEnd) {
  return internalSend(testContext, h -> req.sendJson(json, h), onEnd);
}
 
Example 5
Source File: TestRequest.java    From vertx-web with Apache License 2.0 2 votes vote down vote up
/**
 * Send a {@link Buffer} and execute {@code onEnd} code block wrapped in {@link VertxTestContext#verify(VertxTestContext.ExecutionBlock)}
 * when request is completed and no assertion fails
 *
 * @param buf
 * @param testContext
 * @param onEnd
 * @return a future that will be completed when the response is ready and no response assertion fails
 */
public Future<HttpResponse<Buffer>> sendBuffer(Buffer buf, VertxTestContext testContext, VertxTestContext.ExecutionBlock onEnd) {
  return internalSend(testContext, h -> req.sendBuffer(buf, h), onEnd);
}
 
Example 6
Source File: TestRequest.java    From vertx-web with Apache License 2.0 2 votes vote down vote up
/**
 * Send an URL Encoded form and execute {@code onEnd} code block wrapped in {@link VertxTestContext#verify(VertxTestContext.ExecutionBlock)}
 * when request is completed and no assertion fails
 *
 * @param form
 * @param testContext
 * @param onEnd
 * @return a future that will be completed when the response is ready and no response assertion fails
 */
public Future<HttpResponse<Buffer>> sendURLEncodedForm(MultiMap form, VertxTestContext testContext, VertxTestContext.ExecutionBlock onEnd) {
  return internalSend(testContext, h -> req.sendForm(form, h), onEnd);
}
 
Example 7
Source File: TestRequest.java    From vertx-web with Apache License 2.0 2 votes vote down vote up
/**
 * Send a multipart form and execute {@code onEnd} code block wrapped in {@link VertxTestContext#verify(VertxTestContext.ExecutionBlock)}
 * when request is completed and no assertion fails
 *
 * @param form
 * @param testContext
 * @param onEnd
 * @return a future that will be completed when the response is ready and no response assertion fails
 */
public Future<HttpResponse<Buffer>> sendMultipartForm(MultipartForm form, VertxTestContext testContext, VertxTestContext.ExecutionBlock onEnd) {
  return internalSend(testContext, h -> req.sendMultipartForm(form, h), onEnd);
}