use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class MaxPayloadSizeTest method testContentLengthExceededWithPayload.
/**
* If content length is greater than max, a 413 must be returned.
*/
@Test
public void testContentLengthExceededWithPayload() {
WebClientRequestBuilder builder = webClient.post();
WebClientResponse response = builder.path("/maxpayload").contentType(MediaType.APPLICATION_OCTET_STREAM).submit(PAYLOAD).await(5, TimeUnit.SECONDS);
assertThat(response.status().code(), is(Http.Status.REQUEST_ENTITY_TOO_LARGE_413.code()));
}
use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class CompressionTest method testDeflateContent.
/**
* Test that the entity is decompressed using the correct algorithm.
*
* @throws Exception if error occurs.
*/
@Test
public void testDeflateContent() throws Exception {
WebClientRequestBuilder builder = webClient.get();
builder.headers().add("Accept-Encoding", "deflate");
WebClientResponse response = builder.path("/compressed").request().await(10, TimeUnit.SECONDS);
assertThat(response.content().as(String.class).get(), equalTo("It works!"));
}
use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class CompressionTest method testGzipContent.
/**
* Test that the entity is decompressed using the correct algorithm.
*
* @throws Exception if error occurs.
*/
@Test
public void testGzipContent() throws Exception {
WebClientRequestBuilder builder = webClient.get();
builder.headers().add("Accept-Encoding", "gzip");
WebClientResponse response = builder.path("/compressed").request().await(10, TimeUnit.SECONDS);
assertThat(response.content().as(String.class).get(), equalTo("It works!"));
}
use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class MainTest method testAnonymousGreetWithCors.
// Run after the non-CORS tests (so the greeting is Hola) but before the CORS test that changes the greeting again.
@Order(10)
@Test
void testAnonymousGreetWithCors() {
WebClientRequestBuilder builder = webClient.get();
Headers headers = builder.headers();
headers.add("Origin", "http://foo.com");
headers.add("Host", "here.com");
WebClientResponse r = getResponse("/greet", builder);
assertEquals(200, r.status().code(), "HTTP response");
String payload = fromPayload(r).getMessage();
assertTrue(payload.contains("Hola World"), "HTTP response payload was " + payload);
headers = r.headers();
Optional<String> allowOrigin = headers.value(CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN);
assertTrue(allowOrigin.isPresent(), "Expected CORS header " + CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN + " is absent");
assertEquals(allowOrigin.get(), "*");
}
use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class MainTest method testGreetingChangeWithCors.
// Run after the non-CORS tests but before other CORS tests.
@Order(11)
@Test
void testGreetingChangeWithCors() {
// Send the pre-flight request and check the response.
WebClientRequestBuilder builder = webClient.options();
Headers headers = builder.headers();
headers.add("Origin", "http://foo.com");
headers.add("Host", "here.com");
headers.add("Access-Control-Request-Method", "PUT");
WebClientResponse r = builder.path("/greet/greeting").submit().await();
Headers preflightResponseHeaders = r.headers();
List<String> allowMethods = preflightResponseHeaders.values(CrossOriginConfig.ACCESS_CONTROL_ALLOW_METHODS);
assertFalse(allowMethods.isEmpty(), "pre-flight response does not include " + CrossOriginConfig.ACCESS_CONTROL_ALLOW_METHODS);
assertTrue(allowMethods.contains("PUT"));
List<String> allowOrigins = preflightResponseHeaders.values(CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN);
assertFalse(allowOrigins.isEmpty(), "pre-flight response does not include " + CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN);
assertTrue(allowOrigins.contains("http://foo.com"), "Header " + CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN + " should contain '*' but does not; " + allowOrigins);
// Send the follow-up request.
builder = webClient.put();
headers = builder.headers();
headers.add("Origin", "http://foo.com");
headers.add("Host", "here.com");
headers.addAll(preflightResponseHeaders);
r = putResponse("/greet/greeting", new GreetingMessage("Cheers"), builder);
assertEquals(204, r.status().code(), "HTTP response3");
headers = r.headers();
allowOrigins = headers.values(CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN);
assertFalse(allowOrigins.isEmpty(), "Expected CORS header " + CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN + " has no value(s)");
assertTrue(allowOrigins.contains("http://foo.com"), "Header " + CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN + " should contain '*' but does not; " + allowOrigins);
}
Aggregations