Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions http-client/src/test/java/io/avaje/http/client/AsyncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

class AsyncTest extends BaseWebTest {

final HttpClientContext clientContext = client();
final HttpClient clientContext = client();

@Test
void waitForAsync() {
void waitForAsync() {
final CompletableFuture<HttpResponse<Stream<String>>> future = clientContext.request()
.path("hello").path("stream")
.GET()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public AuthToken obtainToken(HttpClientRequest tokenRequest) {
@Test
void sendEmail() {

HttpClientContext ctx = HttpClientContext.builder()
var ctx = HttpClient.builder()
.baseUrl("https://foo")
.bodyAdapter(new JacksonBodyAdapter(objectMapper))
.authTokenProvider(new MyAuthTokenProvider())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.avaje.http.client;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.example.webserver.App;
import io.javalin.Javalin;
import org.example.webserver.App;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;

Expand All @@ -25,8 +25,8 @@ public static void shutdown() {
webServer.stop();
}

public static HttpClientContext client() {
return HttpClientContext.builder()
public static HttpClient client() {
return HttpClient.builder()
.baseUrl(baseUrl)
.connectionTimeout(Duration.ofSeconds(1))
.requestTimeout(Duration.ofSeconds(1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void encode() {
void beforeRequest() {
// setup
final BasicAuthIntercept intercept = new BasicAuthIntercept("Aladdin", "open sesame");
final HttpClientContext ctx = HttpClientContext.builder().baseUrl("junk").build();
final var ctx = HttpClient.builder().baseUrl("junk").build();

// act
final HttpClientRequest request = ctx.request();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import io.avaje.jsonb.Jsonb;
import org.example.github.Repo;
import org.example.github.RepoJsonAdapter;
import org.example.github.Simple;
import org.example.github.httpclient.Simple$HttpClient;
import org.example.github.RepoJsonAdapter;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

Expand All @@ -18,7 +18,7 @@ class DHttpApiTest {
@Test
void test_github_listRepos() {

final HttpClientContext clientContext = HttpClientContext.builder()
final var clientContext = HttpClient.builder()
.baseUrl("https://api.github.com")
.bodyAdapter(new JacksonBodyAdapter())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

class HelloBasicAuthTest extends BaseWebTest {

final HttpClientContext clientContext = client();
final HttpClient clientContext = client();

public static HttpClientContext client() {
return HttpClientContext.builder()
public static HttpClient client() {
return HttpClient.builder()
.baseUrl(baseUrl)
.bodyAdapter(new JacksonBodyAdapter(new ObjectMapper()))
.requestIntercept(new BasicAuthIntercept("rob", "bot"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class HelloControllerTest extends BaseWebTest {

private static final ObjectMapper objectMapper = new ObjectMapper();

final HttpClientContext clientContext = client();
final HttpClient clientContext = client();

@Test
void newClientTest() {
Expand Down Expand Up @@ -77,7 +77,7 @@ void queryParamMap() {
assertThat(hres.statusCode()).isEqualTo(200);
assertThat(hres.uri().toString()).isEqualTo("http://localhost:8889/hello/message?A=a&B=b");

HttpClientContext.Metrics metrics = clientContext.metrics();
HttpClient.Metrics metrics = clientContext.metrics();
assertThat(metrics.totalCount()).isEqualTo(1);
assertThat(metrics.errorCount()).isEqualTo(0);
assertThat(metrics.responseBytes()).isGreaterThan(0);
Expand Down Expand Up @@ -116,7 +116,7 @@ void asLines_async() throws ExecutionException, InterruptedException {

assertThat(lines).hasSize(4);
assertThat(lines.get(0)).contains("{\"id\":1, \"name\":\"one\"}");
HttpClientContext.Metrics metrics = clientContext.metrics();
HttpClient.Metrics metrics = clientContext.metrics();
assertThat(metrics.totalCount()).isEqualTo(1);
assertThat(metrics.errorCount()).isEqualTo(0);
assertThat(metrics.responseBytes()).isEqualTo(0);
Expand Down Expand Up @@ -281,7 +281,7 @@ void get_stream_NotFoundException() {

assertThat(httpException.statusCode()).isEqualTo(404);
assertThat(httpException.httpResponse().statusCode()).isEqualTo(404);
HttpClientContext.Metrics metrics = clientContext.metrics(true);
HttpClient.Metrics metrics = clientContext.metrics(true);
assertThat(metrics.totalCount()).isEqualTo(1);
assertThat(metrics.errorCount()).isEqualTo(1);
assertThat(metrics.responseBytes()).isEqualTo(0);
Expand Down Expand Up @@ -475,7 +475,7 @@ void get_notFound() {

assertThat(hres.statusCode()).isEqualTo(404);
assertThat(hres.body()).contains("Not Found");
HttpClientContext.Metrics metrics = clientContext.metrics(true);
HttpClient.Metrics metrics = clientContext.metrics(true);
assertThat(metrics.totalCount()).isEqualTo(1);
assertThat(metrics.errorCount()).isEqualTo(1);
assertThat(metrics.responseBytes()).isGreaterThan(0);
Expand Down Expand Up @@ -506,11 +506,11 @@ void asPlainString_200() {
void asPlainString_throwingHttpException() {
final HttpException httpException = assertThrows(HttpException.class, () ->
clientContext.request()
.path("hello/saveform3")
.formParam("name", "Bax")
.formParam("email", "notValidEmail")
.POST()
.asPlainString());
.path("hello/saveform3")
.formParam("name", "Bax")
.formParam("email", "notValidEmail")
.POST()
.asPlainString());

assertThat(httpException.statusCode()).isEqualTo(422);

Expand All @@ -532,7 +532,7 @@ void asString_readInvalidResponse() {
assertThat(hres.statusCode()).isEqualTo(422);

// convert json error response body to a bean
final ErrorResponse errorResponse = clientContext.converters()
final ErrorResponse errorResponse = clientContext.bodyAdapter()
.beanReader(ErrorResponse.class).readBody(hres.body());

final Map<String, String> errorMap = errorResponse.getErrors();
Expand Down Expand Up @@ -936,7 +936,7 @@ void async_whenComplete_throwingHttpException() {
} catch (CompletionException e) {
assertThat(e.getCause()).isSameAs(causeRef.get());
}
HttpClientContext.Metrics metrics = clientContext.metrics(true);
HttpClient.Metrics metrics = clientContext.metrics(true);
assertThat(metrics.totalCount()).isEqualTo(1);
assertThat(metrics.errorCount()).isEqualTo(1);
assertThat(metrics.responseBytes()).isGreaterThan(0);
Expand Down Expand Up @@ -981,8 +981,8 @@ void post_bean_returningBean_usingExplicitConverters() {

HelloDto dto = new HelloDto(12, "rob", "other");

final BodyWriter from = clientContext.converters().beanWriter(HelloDto.class);
final BodyReader<HelloDto> toDto = clientContext.converters().beanReader(HelloDto.class);
final BodyWriter from = clientContext.bodyAdapter().beanWriter(HelloDto.class);
final BodyReader<HelloDto> toDto = clientContext.bodyAdapter().beanReader(HelloDto.class);

final HelloDto bean = clientContext.request()
.path("hello")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public void response(Event event) {
}
}

private HttpClientContext createClient(TDRequestListener tdRequestListener) {
return HttpClientContext.builder()
private HttpClient createClient(TDRequestListener tdRequestListener) {
return HttpClient.builder()
.baseUrl(baseUrl)
.requestLogging(false)
.requestListener(new RequestLogger())
Expand All @@ -45,7 +45,7 @@ private HttpClientContext createClient(TDRequestListener tdRequestListener) {
@Test
void get_no_request_body() {
final TDRequestListener tdRequestListener = new TDRequestListener(false);
final HttpClientContext client = createClient(tdRequestListener);
final HttpClient client = createClient(tdRequestListener);

final HttpResponse<String> hres = client.request()
.path("hello").path("message")
Expand All @@ -58,7 +58,7 @@ void get_no_request_body() {
@Test
void post() {
final TDRequestListener tdRequestListener = new TDRequestListener(true);
final HttpClientContext client = createClient(tdRequestListener);
final HttpClient client = createClient(tdRequestListener);

final HttpResponse<String> hres = client.request()
.path("post")
Expand Down
10 changes: 5 additions & 5 deletions http-client/src/test/java/io/avaje/http/client/RetryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
class RetryTest extends BaseWebTest {


HttpClientContext initClientWithRetry(MyIntercept myIntercept, RetryHandler retryHandler) {
return HttpClientContext.builder()
HttpClient initClientWithRetry(MyIntercept myIntercept, RetryHandler retryHandler) {
return HttpClient.builder()
.baseUrl("http://localhost:8889")
.bodyAdapter(new JacksonBodyAdapter())
.retryHandler(retryHandler)
Expand All @@ -21,18 +21,18 @@ HttpClientContext initClientWithRetry(MyIntercept myIntercept, RetryHandler retr
@Test
void retryTest() {
final MyIntercept myIntercept = new MyIntercept();
final HttpClientContext clientContext = initClientWithRetry(myIntercept, new SimpleRetryHandler(4, 1));
final HttpClient clientContext = initClientWithRetry(myIntercept, new SimpleRetryHandler(4, 1));
performGetRequestAndAssert(myIntercept, clientContext);
}

@Test
void retryWithGitterTest() {
final MyIntercept myIntercept = new MyIntercept();
final HttpClientContext clientContext = initClientWithRetry(myIntercept, new SimpleRetryHandler(4, 10, 20));
final HttpClient clientContext = initClientWithRetry(myIntercept, new SimpleRetryHandler(4, 10, 20));
performGetRequestAndAssert(myIntercept, clientContext);
}

private void performGetRequestAndAssert(MyIntercept myIntercept, HttpClientContext clientContext) {
private void performGetRequestAndAssert(MyIntercept myIntercept, HttpClient clientContext) {
HttpResponse<String> res = clientContext.request()
.label("http_client_hello_retry")
.path("hello/retry")
Expand Down
13 changes: 5 additions & 8 deletions http-client/src/test/java/io/avaje/http/client/VerbTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.function.Supplier;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;

public class VerbTest extends BaseWebTest {

private final HttpClientContext clientContext = client();
private final HttpClient clientContext = client();

@Test
void post() {
Expand Down Expand Up @@ -148,9 +145,9 @@ void delete_with_body_Path_NotFound_expects_IllegalArgumentException() {
@Test
void delete_with_body_InputStream() {
HttpResponse<String> res = clientContext.request()
.path("delete")
.body(() -> getClass().getResourceAsStream("/dummy.txt"))
.DELETE().asString();
.path("delete")
.body(() -> getClass().getResourceAsStream("/dummy.txt"))
.DELETE().asString();

assertThat(res.body()).isEqualTo("delete body[dummyFileContent]");
}
Expand Down Expand Up @@ -183,7 +180,7 @@ void get_BodyHandler_null_expect() {

HttpResponse<String> res = clientContext.request()
.path("post")
.body((HttpRequest.BodyPublisher)null)
.body((HttpRequest.BodyPublisher) null)
.POST().asString();

assertThat(res.body()).isEqualTo("post");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.example.dinject;

import io.avaje.http.client.BodyAdapter;
import io.avaje.http.client.HttpClientContext;
import io.avaje.http.client.HttpClient;
import io.avaje.http.client.JsonbBodyAdapter;
import io.avaje.inject.BeanScope;
import org.junit.jupiter.api.Test;
Expand All @@ -18,8 +18,8 @@ void configureWith() {

assertThat(beanScope.contains("io.avaje.jsonb.Jsonb")).isTrue();

HttpClientContext.Builder builder = HttpClientContext.builder();
HttpClientContext.Builder.State state = builder.state();
HttpClient.Builder builder = HttpClient.builder();
HttpClient.Builder.State state = builder.state();
assertThat(state.baseUrl()).isNull();
assertThat(state.bodyAdapter()).isNull();
assertThat(state.client()).isNull();
Expand Down
4 changes: 2 additions & 2 deletions http-client/src/test/java/org/example/github/GithubTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.example.github;

import io.avaje.http.client.HttpClientContext;
import io.avaje.http.client.HttpClient;
import io.avaje.http.client.JacksonBodyAdapter;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
Expand All @@ -15,7 +15,7 @@ public class GithubTest {
@Disabled
void test() {

final HttpClientContext clientContext = HttpClientContext.builder()
final HttpClient clientContext = HttpClient.builder()
.baseUrl("https://api.github.com")
.bodyAdapter(new JacksonBodyAdapter())
.requestLogging(false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.example;

import io.avaje.http.client.HttpClientContext;
import io.avaje.http.client.HttpClient;
import io.avaje.http.client.JacksonBodyAdapter;
import org.example.server.Main;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -21,7 +21,7 @@ static void start() {
final int port = new Random().nextInt(1000) + 10_000;
Main.start(port);

final HttpClientContext clientContext = HttpClientContext.builder()
final HttpClient clientContext = HttpClient.builder()
.baseUrl("http://localhost:" + port)
.bodyAdapter(new JacksonBodyAdapter())
.build();
Expand Down