@Override public CompletableFuture<Boolean> isHealthy(Endpoint endpoint) { return httpClient.get(healthCheckPath) .aggregate() .thenApply(message -> HttpStatus.OK.equals(message.status())); } }
@Test public void hello() throws Exception { final AggregatedHttpMessage res = client.get("/hello").aggregate().join(); assertThat(res.status()).isEqualTo(HttpStatus.OK); assertThat(res.content().toStringUtf8()).isEqualTo("Hello, World"); }
@Test public void success() { final AggregatedHttpMessage response = client.get("/hello/Spring").aggregate().join(); assertThat(response.status()).isEqualTo(HttpStatus.OK); assertThat(response.content().toStringUtf8()) .isEqualTo("Hello, Spring! This message is from Armeria annotated service!"); }
@Test public void healthCheck() throws Exception { final AggregatedHttpMessage res = client.get("/internal/healthcheck").aggregate().join(); assertThat(res.status()).isEqualTo(HttpStatus.OK); assertThat(res.content().toStringUtf8()).isEqualTo("ok"); } }
@Test public void index() { final AggregatedHttpMessage res = client.get("/").aggregate().join(); assertThat(res.status()).isEqualTo(HttpStatus.OK); assertThat(res.content().toStringUtf8()).isEqualTo("index"); }
@Test public void testAnnotatedServiceRegistrationBean() throws Exception { final HttpClient client = HttpClient.of(newUrl("h1c")); HttpResponse response = client.get("/annotated/get"); AggregatedHttpMessage msg = response.aggregate().get(); assertThat(msg.status()).isEqualTo(HttpStatus.OK); assertThat(msg.content().toStringUtf8()).isEqualTo("annotated"); response = client.get("/annotated/get/2"); msg = response.aggregate().get(); assertThat(msg.status()).isEqualTo(HttpStatus.OK); assertThat(msg.content().toStringUtf8()).isEqualTo("exception"); }
@Test public void shouldGetHelloFromRestController() throws Exception { protocols.forEach(scheme -> { final HttpClient client = HttpClient.of(clientFactory, scheme + "://example.com:" + port); final AggregatedHttpMessage response = client.get("/hello").aggregate().join(); assertThat(response.content().toStringUtf8()).isEqualTo("hello"); }); }
@Test public void shouldGetHelloFromRestController() throws Exception { final HttpClient client = HttpClient.of("http://127.0.0.1:" + port); final AggregatedHttpMessage response = client.get("/proxy?port=" + port).aggregate().join(); assertThat(response.content().toStringUtf8()).isEqualTo("hello"); } }
@Test public void testHttpServiceRegistrationBean() throws Exception { final HttpClient client = HttpClient.of(newUrl("h1c")); final HttpResponse response = client.get("/ok"); final AggregatedHttpMessage msg = response.aggregate().get(); assertThat(msg.status()).isEqualTo(HttpStatus.OK); assertThat(msg.content().toStringUtf8()).isEqualTo("ok"); } }
@Test public void withoutTracking() throws Exception { final HttpClient client = HttpClient.of(rule.uri("/")); assertThat(client.execute(HttpHeaders.of(HttpMethod.GET, "/foo")).aggregate().get().status()) .isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); }
private AggregatedHttpMessage sendPostRequest(HttpClient client) { final HttpHeaders requestHeaders = HttpHeaders.of(HttpMethod.POST, "/hello") .add(HttpHeaderNames.USER_AGENT, "test-agent/1.0.0") .add(HttpHeaderNames.ACCEPT_ENCODING, "gzip"); return client.execute(requestHeaders, HttpData.of(POST_BODY.getBytes())).aggregate().join(); }
private AggregatedHttpMessage sendViaHttpPostBindingProtocol( String path, String paramName, SignableSAMLObject sinableObj) throws Exception { final String encoded = toSignedBase64(sinableObj, idpCredential, signatureAlgorithm); final QueryStringEncoder encoder = new QueryStringEncoder("/"); encoder.addParam(paramName, encoded); final HttpRequest req = HttpRequest.of(HttpMethod.POST, path, MediaType.FORM_DATA, encoder.toUri().getRawQuery()); return client.execute(req).aggregate().join(); }
private static AggregatedHttpMessage makeMetricsRequest() throws ExecutionException, InterruptedException { final HttpClient client = HttpClient.of("http://127.0.0.1:" + server.httpPort()); return client.execute(HttpHeaders.of(HttpMethod.GET, "/internal/prometheus/metrics") .setObject(HttpHeaderNames.ACCEPT, MediaType.PLAIN_TEXT_UTF_8)) .aggregate().get(); }
@Test public void failure() { final AggregatedHttpMessage response = client.get("/hello/a").aggregate().join(); assertThat(response.status()).isEqualTo(HttpStatus.BAD_REQUEST); assertThatJson(response.content().toStringUtf8()) .node("message") .isEqualTo("hello.name: name should have between 3 and 10 characters"); } }
@Test public void enableTracking() throws Exception { try { RequestContextAssembly.enable(); final HttpClient client = HttpClient.of(rule.uri("/")); assertThat(client.execute(HttpHeaders.of(HttpMethod.GET, "/foo")).aggregate().get().status()) .isEqualTo(HttpStatus.OK); } finally { RequestContextAssembly.disable(); } }
@Test public void testMetrics() throws Exception { final String metricReport = HttpClient.of(newUrl("http")) .get("/internal/metrics") .aggregate().join() .content().toStringUtf8(); assertThat(metricReport).contains("# TYPE jvm_gc_live_data_size_bytes gauge"); } }
@Test public void shouldReturnEchoResponse() { final ArmeriaReactiveWebServerFactory factory = factory(); runEchoServer(factory, server -> { final HttpClient client = httpClient(server); validateEchoResponse(sendPostRequest(client)); final AggregatedHttpMessage res = client.get("/hello").aggregate().join(); assertThat(res.status()).isEqualTo(com.linecorp.armeria.common.HttpStatus.OK); assertThat(res.content().toStringUtf8()).isEmpty(); }); }
@Test public void testThriftServiceRegistrationBean() throws Exception { final HelloService.Iface client = Clients.newClient(newUrl("tbinary+h1c") + "/thrift", HelloService.Iface.class); assertThat(client.hello("world")).isEqualTo("hello world"); final HttpClient httpClient = HttpClient.of(newUrl("h1c")); final HttpResponse response = httpClient.get("/internal/docs/specification.json"); final AggregatedHttpMessage msg = response.aggregate().get(); assertThat(msg.status()).isEqualTo(HttpStatus.OK); assertThatJson(msg.content().toStringUtf8()) .node("services[1].exampleHttpHeaders[0].x-additional-header").isStringEqualTo("headerVal"); }
@Test public void unframed_grpcEncoding() throws Exception { final HttpClient client = HttpClient.of(server.httpUri("/")); final AggregatedHttpMessage response = client.execute( HttpHeaders.of(HttpMethod.POST, UnitTestServiceGrpc.getStaticUnaryCallMethod().getFullMethodName()) .set(HttpHeaderNames.CONTENT_TYPE, "application/protobuf") .set(GrpcHeaderNames.GRPC_ENCODING, "gzip"), REQUEST_MESSAGE.toByteArray()).aggregate().get(); assertThat(response.status()).isEqualTo(HttpStatus.UNSUPPORTED_MEDIA_TYPE); assertNoRpcContent(); }
@Test public void unframed_streamingApi() throws Exception { final HttpClient client = HttpClient.of(server.httpUri("/")); final AggregatedHttpMessage response = client.execute( HttpHeaders.of(HttpMethod.POST, UnitTestServiceGrpc.getStaticStreamedOutputCallMethod().getFullMethodName()) .set(HttpHeaderNames.CONTENT_TYPE, "application/protobuf"), StreamingOutputCallRequest.getDefaultInstance().toByteArray()).aggregate().get(); assertThat(response.status()).isEqualTo(HttpStatus.BAD_REQUEST); assertNoRpcContent(); }