io.vertx.ext.web.client.HttpRequest.expect()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(85)

本文整理了Java中io.vertx.ext.web.client.HttpRequest.expect()方法的一些代码示例,展示了HttpRequest.expect()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.expect()方法的具体详情如下:
包路径:io.vertx.ext.web.client.HttpRequest
类名称:HttpRequest
方法名:expect

HttpRequest.expect介绍

暂无

代码示例

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Add an expectation that the response is valid according to the provided <code>predicate</code>.
 * <p>
 * Multiple predicates can be added.
 * @param predicate the predicate
 * @return a reference to this, so the API can be used fluently
 */
public io.vertx.rxjava.ext.web.client.HttpRequest<T> expect(Function<io.vertx.rxjava.ext.web.client.HttpResponse<Void>, io.vertx.rxjava.ext.web.client.predicate.ResponsePredicateResult> predicate) { 
 delegate.expect(new java.util.function.Function<io.vertx.ext.web.client.HttpResponse<java.lang.Void>,io.vertx.ext.web.client.predicate.ResponsePredicateResult>() {
  public io.vertx.ext.web.client.predicate.ResponsePredicateResult apply(io.vertx.ext.web.client.HttpResponse<java.lang.Void> arg) {
   io.vertx.rxjava.ext.web.client.predicate.ResponsePredicateResult ret = predicate.apply(io.vertx.rxjava.ext.web.client.HttpResponse.newInstance(arg, io.vertx.lang.rx.TypeArg.unknown()));
   return ret.getDelegate();
  }
 });
 return this;
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * Add an expectation that the response is valid according to the provided <code>predicate</code>.
 * <p>
 * Multiple predicates can be added.
 * @param predicate the predicate
 * @return a reference to this, so the API can be used fluently
 */
public io.vertx.rxjava.ext.web.client.HttpRequest<T> expect(Function<io.vertx.rxjava.ext.web.client.HttpResponse<Void>, io.vertx.rxjava.ext.web.client.predicate.ResponsePredicateResult> predicate) { 
 delegate.expect(new java.util.function.Function<io.vertx.ext.web.client.HttpResponse<java.lang.Void>,io.vertx.ext.web.client.predicate.ResponsePredicateResult>() {
  public io.vertx.ext.web.client.predicate.ResponsePredicateResult apply(io.vertx.ext.web.client.HttpResponse<java.lang.Void> arg) {
   io.vertx.rxjava.ext.web.client.predicate.ResponsePredicateResult ret = predicate.apply(io.vertx.rxjava.ext.web.client.HttpResponse.newInstance(arg, io.vertx.lang.rx.TypeArg.unknown()));
   return ret.getDelegate();
  }
 });
 return this;
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * Add an expectation that the response is valid according to the provided <code>predicate</code>.
 * <p>
 * Multiple predicates can be added.
 * @param predicate the predicate
 * @return a reference to this, so the API can be used fluently
 */
public io.vertx.rxjava.ext.web.client.HttpRequest<T> expect(io.vertx.rxjava.ext.web.client.predicate.ResponsePredicate predicate) { 
 delegate.expect(predicate.getDelegate());
 return this;
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Add an expectation that the response is valid according to the provided <code>predicate</code>.
 * <p>
 * Multiple predicates can be added.
 * @param predicate the predicate
 * @return a reference to this, so the API can be used fluently
 */
public io.vertx.rxjava.ext.web.client.HttpRequest<T> expect(io.vertx.rxjava.ext.web.client.predicate.ResponsePredicate predicate) { 
 delegate.expect(predicate.getDelegate());
 return this;
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testExpectContentTypeFail() throws Exception {
 testExpectation(true,
  req -> req.expect(ResponsePredicate.JSON),
  HttpServerResponse::end);
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testExpectFunctionThrowsException() throws Exception {
 ResponsePredicate predicate = ResponsePredicate.create(r -> {
  throw new IndexOutOfBoundsException("boom");
 });
 testExpectation(true, req -> req.expect(predicate), HttpServerResponse::end, ar -> {
  assertThat(ar.cause(), instanceOf(IndexOutOfBoundsException.class));
 });
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testExpectStatusRangeFail() throws Exception {
 testExpectation(true,
  req -> req.expect(ResponsePredicate.SC_SUCCESS),
  resp -> resp.setStatusCode(500).end());
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testExpectContentTypePass() throws Exception {
 testExpectation(false,
  req -> req.expect(ResponsePredicate.JSON),
  resp -> resp.putHeader("content-type", "application/JSON").end());
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testExpectStatusRangePass1() throws Exception {
 testExpectation(false,
  req -> req.expect(ResponsePredicate.SC_SUCCESS),
  resp -> resp.setStatusCode(200).end());
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testExpectStatusRangePass2() throws Exception {
 testExpectation(false,
  req -> req.expect(ResponsePredicate.SC_SUCCESS),
  resp -> resp.setStatusCode(299).end());
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testExpectOneOfContentTypesPass() throws Exception {
 testExpectation(false,
  req -> req.expect(ResponsePredicate.contentType(Arrays.asList("text/plain", "text/HTML"))),
  httpServerResponse -> httpServerResponse.putHeader(HttpHeaders.CONTENT_TYPE, HttpHeaders.TEXT_HTML).end());
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testExpectOneOfContentTypesFail() throws Exception {
 testExpectation(true,
  req -> req.expect(ResponsePredicate.contentType(Arrays.asList("text/plain", "text/csv"))),
  httpServerResponse -> httpServerResponse.putHeader(HttpHeaders.CONTENT_TYPE, HttpHeaders.TEXT_HTML).end());
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testErrorConverterReturnsNull() throws Exception {
 ResponsePredicate predicate = ResponsePredicate.create(r -> {
  return ResponsePredicateResult.failure("boom");
 }, r -> null);
 testExpectation(true, req -> req.expect(predicate), HttpServerResponse::end, ar -> {
  assertThat(ar.cause(), not(instanceOf(NullPointerException.class)));
 });
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testErrorConverterThrowsException() throws Exception {
 ResponsePredicate predicate = ResponsePredicate.create(r -> {
  return ResponsePredicateResult.failure("boom");
 }, result -> {
  throw new IndexOutOfBoundsException();
 });
 testExpectation(true, req -> req.expect(predicate), HttpServerResponse::end, ar -> {
  assertThat(ar.cause(), instanceOf(IndexOutOfBoundsException.class));
 });
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testExpectStatusFail() throws Exception {
 testExpectation(true,
  req -> req.expect(ResponsePredicate.status(200)),
  resp -> resp.setStatusCode(201).end());
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testExpectStatusPass() throws Exception {
 testExpectation(false,
  req -> req.expect(ResponsePredicate.status(200)),
  resp -> resp.setStatusCode(200).end());
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testExpectFail() throws Exception {
 testExpectation(true,
  req -> req.expect(ResponsePredicate.create(r -> ResponsePredicateResult.failure("boom"))),
  HttpServerResponse::end);
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testExpectCustomExceptionWithResponseBody() throws Exception {
 UUID uuid = UUID.randomUUID();
 ResponsePredicate predicate = ResponsePredicate.create(ResponsePredicate.SC_SUCCESS, ErrorConverter.createFullBody(result -> {
   JsonObject body = result.response().bodyAsJsonObject();
   return new CustomException(UUID.fromString(body.getString("tag")), body.getString("message"));
  }));
 testExpectation(true, req -> req.expect(predicate), httpServerResponse -> {
  httpServerResponse
   .setStatusCode(400)
   .end(new JsonObject().put("tag", uuid.toString()).put("message", "tilt").toBuffer());
 }, ar -> {
  Throwable cause = ar.cause();
  assertThat(cause, instanceOf(CustomException.class));
  CustomException customException = (CustomException) cause;
  assertEquals("tilt", customException.getMessage());
  assertEquals(uuid, customException.tag);
 });
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testExpectPass() throws Exception {
 testExpectation(false,
  req -> req.expect(ResponsePredicate.create(r -> ResponsePredicateResult.success())),
  HttpServerResponse::end);
}

代码示例来源:origin: io.vertx/vertx-web-client

@Test
public void testExpectCustomException() throws Exception {
 ResponsePredicate predicate = ResponsePredicate.create(r -> ResponsePredicateResult.failure("boom"), result -> new CustomException(result.message()));
 testExpectation(true, req -> req.expect(predicate), HttpServerResponse::end, ar -> {
  Throwable cause = ar.cause();
  assertThat(cause, instanceOf(CustomException.class));
  CustomException customException = (CustomException) cause;
  assertEquals("boom", customException.getMessage());
 });
}

相关文章