Skip to content

Commit

Permalink
Issue helidon-io#7102 - Review notes applied.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>
  • Loading branch information
Tomas-Kraus committed Jul 26, 2024
1 parent d3c7363 commit 217c6cb
Showing 1 changed file with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@

public class HeadersTest {

private static final String INVALID_CONTENT_TYPE_VALUE = "invalid header value";
private static final String INVALID_CONTENT_TYPE_TEXT = "text";
private static final String RELAXED_CONTENT_TYPE_TEXT = "text/plain";

private static WebServer server;
private static WebClient client;

Expand All @@ -66,6 +70,18 @@ static void beforeAll() throws ExecutionException, InterruptedException, Timeout
.build();
}

// HTTP service with invalid Content-Type
private static void invalidContentType(ServerRequest request, ServerResponse response) {
response.addHeader(Http.Header.CONTENT_TYPE, INVALID_CONTENT_TYPE_VALUE)
.send();
}

// HTTP service with Content-Type: text instead of text/plain
private static void invalidTextContentType(ServerRequest request, ServerResponse response) {
response.addHeader(Http.Header.CONTENT_TYPE, INVALID_CONTENT_TYPE_TEXT)
.send();
}

@AfterAll
static void afterAll() throws ExecutionException, InterruptedException, TimeoutException {
if (server != null) {
Expand All @@ -82,7 +98,7 @@ void testInvalidContentType() {
client.get()
.path("/invalidContentType")
.request()
.await();
.await(10, TimeUnit.SECONDS);
fail("WebClient shall throw an exception");
} catch (Exception ex) {
assertThat(ex, is(instanceOf(CompletionException.class)));
Expand All @@ -97,10 +113,10 @@ void testInvalidContentType() {
@Test
void testInvalidTextContentTypeStrict() {
try {
client.get()
.path("/invalidTextContentType")
.request()
.await();
client.get()
.path("/invalidTextContentType")
.request()
.await(10, TimeUnit.SECONDS);
} catch (Exception ex) {
assertThat(ex, is(instanceOf(CompletionException.class)));
Throwable cause = ex.getCause();
Expand All @@ -122,27 +138,10 @@ void testInvalidTextContentTypeRelaxed() {
WebClientResponse response = client.get()
.path("/invalidTextContentType")
.request()
.await();
.await(10, TimeUnit.SECONDS);
Optional<MediaType> maybeContentType = response.headers().contentType();
assertThat(maybeContentType.isPresent(), is(true));
assertThat(maybeContentType.get().toString(), is(RELAXED_CONTENT_TYPE_TEXT));
}

private static final String INVALID_CONTENT_TYPE_VALUE = "invalid header value";

// HTTP service with invalid Content-Type
private static void invalidContentType(ServerRequest request, ServerResponse response) {
response.addHeader(Http.Header.CONTENT_TYPE, INVALID_CONTENT_TYPE_VALUE)
.send();
}

private static final String INVALID_CONTENT_TYPE_TEXT = "text";
private static final String RELAXED_CONTENT_TYPE_TEXT = "text/plain";

// HTTP service with Content-Type: text instead of text/plain
private static void invalidTextContentType(ServerRequest request, ServerResponse response) {
response.addHeader(Http.Header.CONTENT_TYPE, INVALID_CONTENT_TYPE_TEXT)
.send();
}

}

0 comments on commit 217c6cb

Please sign in to comment.