use of io.helidon.webserver.testsupport.TestResponse in project helidon by oracle.
the class MainTest method organiseCode.
@Test
public void organiseCode() throws Exception {
// List
TestResponse response = createClient(Main::organiseCode).path("/catalog-context-path").get();
assertEquals(200, response.status().code());
assertEquals("1, 2, 3, 4, 5", response.asString().get());
// Get by id
response = createClient(Main::organiseCode).path("/catalog-context-path/aaa").get();
assertEquals(200, response.status().code());
assertEquals("Item: aaa", response.asString().get());
}
use of io.helidon.webserver.testsupport.TestResponse in project helidon by oracle.
the class PrometheusSupportTest method doTestRequest.
private TestResponse doTestRequest(String nameQuery) throws Exception {
TestRequest request = TestClient.create(routing).path("/metrics");
if (nameQuery != null && !nameQuery.isEmpty()) {
request.queryParameter("name[]", nameQuery);
}
TestResponse response = request.get();
assertThat(response.status(), is(Http.Status.OK_200));
return response;
}
use of io.helidon.webserver.testsupport.TestResponse in project helidon by oracle.
the class PrometheusSupportTest method filter.
@Test
public void filter() throws Exception {
TestResponse response = doTestRequest("alpha");
assertThat(response.status(), is(Http.Status.OK_200));
String body = response.asString().get(5, TimeUnit.SECONDS);
assertThat(body, not(containsString("# TYPE beta")));
assertThat(body, not(containsString("beta 3.0")));
assertThat(body, containsString("# TYPE alpha counter"));
assertThat(body, containsString("alpha{method=\"bar\",} 6.0"));
}
use of io.helidon.webserver.testsupport.TestResponse in project helidon by oracle.
the class JsonSupportTest method explicitJsonSupportRegistrationMissingJsonProperty.
@Test
public void explicitJsonSupportRegistrationMissingJsonProperty() throws Exception {
Routing routing = Routing.builder().post("/foo", Handler.create(JsonObject.class, (req, res, json) -> res.send(json))).build();
JsonObject json = createJson();
TestResponse response = TestClient.create(routing).path("/foo").post(MediaPublisher.create(MediaType.APPLICATION_JSON.withCharset("UTF-8"), json.toString()));
assertThat(response.status(), is(equalTo(Http.Status.INTERNAL_SERVER_ERROR_500)));
}
use of io.helidon.webserver.testsupport.TestResponse in project helidon by oracle.
the class TestJsonBindingSupport method genericType.
@Test
public void genericType() throws Exception {
GenericType<List<Person>> personsType = new GenericType<>() {
};
final Routing routing = Routing.builder().post("/foo", (req, res) -> {
req.content().as(personsType).thenAccept(res::send);
}).build();
final String personsJson = "[{\"name\":\"Frank\"},{\"name\":\"John\"}]";
final TestResponse response = TestClient.create(routing, JsonbSupport.create()).path("/foo").post(MediaPublisher.create(MediaType.APPLICATION_JSON.withCharset("UTF-8"), personsJson));
assertThat(response.headers().first(Http.Header.CONTENT_TYPE).orElse(null), is(MediaType.APPLICATION_JSON.toString()));
final String json = response.asString().get(10, TimeUnit.SECONDS);
assertThat(json, is(personsJson));
}
Aggregations