diff --git a/avaje-jex-test/src/main/java/io/avaje/jex/test/TestPair.java b/avaje-jex-test/src/main/java/io/avaje/jex/test/TestPair.java index 2a665c5b..5c0d3dee 100644 --- a/avaje-jex-test/src/main/java/io/avaje/jex/test/TestPair.java +++ b/avaje-jex-test/src/main/java/io/avaje/jex/test/TestPair.java @@ -1,14 +1,12 @@ package io.avaje.jex.test; -import java.util.Random; +import java.net.http.HttpClient.Version; import io.avaje.http.client.HttpClient; import io.avaje.http.client.HttpClientRequest; import io.avaje.jex.Jex; -/** - * Server and Client pair for a test. - */ +/** Server and Client pair for a test. */ public class TestPair { private final int port; @@ -39,18 +37,13 @@ public String url() { return client.url().build(); } - /** - * Create a Server and Client pair for a given set of tests. - */ + /** Create a Server and Client pair for a given set of tests. */ public static TestPair create(Jex app) { - int port = 10000 + new Random().nextInt(1000); - var jexServer = app.port(port).start(); - + var jexServer = app.port(0).start(); + var port = jexServer.port(); var url = "http://localhost:" + port; - var client = HttpClient.builder() - .baseUrl(url) - .build(); + var client = HttpClient.builder().version(Version.HTTP_1_1).baseUrl(url).build(); return new TestPair(port, jexServer, client); } diff --git a/avaje-jex/src/main/java/io/avaje/jex/core/Constants.java b/avaje-jex/src/main/java/io/avaje/jex/core/Constants.java index 5a90e9bb..fc6a9132 100644 --- a/avaje-jex/src/main/java/io/avaje/jex/core/Constants.java +++ b/avaje-jex/src/main/java/io/avaje/jex/core/Constants.java @@ -5,17 +5,13 @@ public final class Constants { private Constants() {} public static final String ACCEPT = "Accept"; - public static final String CONTENT_ENCODING = "Content-Encoding"; - public static final String CONTENT_DISPOSITION = "Content-Disposition"; - public static final String CONTENT_LANGUAGE = "Content-Language"; - public static final String CONTENT_LENGTH = "Content-Length"; - public static final String CONTENT_LOCATION = "Content-Location"; - public static final String CONTENT_RANGE = "Content-Range"; - public static final String CONTENT_TYPE = "Content-Type"; + public static final String CONTENT_ENCODING = "Content-encoding"; + public static final String CONTENT_LENGTH = "Content-length"; + public static final String CONTENT_TYPE = "Content-type"; public static final String LOCATION = "Location"; public static final String HOST = "Host"; - public static final String USER_AGENT = "User-Agent"; - public static final String ACCEPT_ENCODING = "Accept-Encoding"; + public static final String USER_AGENT = "User-agent"; + public static final String ACCEPT_ENCODING = "Accept-encoding"; public static final String TEXT_HTML = "text/html"; public static final String TEXT_PLAIN = "text/plain"; @@ -23,5 +19,4 @@ private Constants() {} public static final String TEXT_PLAIN_UTF8 = "text/plain;charset=utf-8"; public static final String APPLICATION_JSON = "application/json"; public static final String APPLICATION_X_JSON_STREAM = "application/x-json-stream"; - } diff --git a/avaje-jex/src/test/java/io/avaje/jex/core/CookieServerTest.java b/avaje-jex/src/test/java/io/avaje/jex/core/CookieServerTest.java index 6c8433e9..1061e37c 100644 --- a/avaje-jex/src/test/java/io/avaje/jex/core/CookieServerTest.java +++ b/avaje-jex/src/test/java/io/avaje/jex/core/CookieServerTest.java @@ -1,15 +1,15 @@ package io.avaje.jex.core; -import io.avaje.jex.Jex; -import io.avaje.jex.http.Context; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; import java.net.http.HttpResponse; import java.time.Duration; -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; + +import io.avaje.jex.Jex; +import io.avaje.jex.http.Context; class CookieServerTest { @@ -28,7 +28,7 @@ static TestPair init() { ctx.cookie(httpCookie).text("ok"); }) ); - return TestPair.create(app, 9001); + return TestPair.create(app); } @AfterAll diff --git a/avaje-jex/src/test/java/io/avaje/jex/core/FilterTest.java b/avaje-jex/src/test/java/io/avaje/jex/core/FilterTest.java index 36b9b097..0945e695 100644 --- a/avaje-jex/src/test/java/io/avaje/jex/core/FilterTest.java +++ b/avaje-jex/src/test/java/io/avaje/jex/core/FilterTest.java @@ -1,8 +1,6 @@ package io.avaje.jex.core; -import io.avaje.jex.Jex; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; import java.net.http.HttpHeaders; import java.net.http.HttpResponse; @@ -10,7 +8,10 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.LockSupport; -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; + +import io.avaje.jex.Jex; class FilterTest { @@ -25,7 +26,11 @@ static TestPair init() { routing -> routing .get("/", ctx -> ctx.text("roo")) - .get("/noResponse", ctx -> {}) + .get( + "/noResponse", + ctx -> { + ctx.header("Content-Type", ""); + }) .get("/one", ctx -> ctx.text("one")) .get("/two", ctx -> ctx.text("two")) .get("/two/{id}", ctx -> ctx.text("two-id")) diff --git a/avaje-jex/src/test/java/io/avaje/jex/core/TestPair.java b/avaje-jex/src/test/java/io/avaje/jex/core/TestPair.java index b53288c0..f9429ed2 100644 --- a/avaje-jex/src/test/java/io/avaje/jex/core/TestPair.java +++ b/avaje-jex/src/test/java/io/avaje/jex/core/TestPair.java @@ -1,16 +1,12 @@ package io.avaje.jex.core; +import java.net.http.HttpClient.Version; + import io.avaje.http.client.HttpClient; import io.avaje.http.client.HttpClientRequest; -import io.avaje.http.client.JacksonBodyAdapter; import io.avaje.jex.Jex; -import java.time.Duration; -import java.util.Random; - -/** - * Server and Client pair for a test. - */ +/** Server and Client pair for a test. */ public class TestPair { private final int port; @@ -41,24 +37,13 @@ public String url() { return client.url().build(); } - /** - * Create a Server and Client pair for a given set of tests. - */ + /** Create a Server and Client pair for a given set of tests. */ public static TestPair create(Jex app) { - int port = 10000 + new Random().nextInt(1000); - return create(app, port); - } - - public static TestPair create(Jex app, int port) { - - var jexServer = app.port(port).start(); + var jexServer = app.port(0).start(); + var port = jexServer.port(); var url = "http://localhost:" + port; - var client = HttpClient.builder() - .baseUrl(url) - .bodyAdapter(new JacksonBodyAdapter()) - .requestTimeout(Duration.ofMinutes(2)) - .build(); + var client = HttpClient.builder().version(Version.HTTP_1_1).baseUrl(url).build(); return new TestPair(port, jexServer, client); }