use of io.helidon.webserver.testsupport.TestResponse in project helidon by oracle.
the class PrometheusSupportTest method doubleCall.
@Test
public void doubleCall() throws Exception {
TestResponse response = doTestRequest(null);
assertThat(response.headers().first(Http.Header.CONTENT_TYPE).orElse(null), StringStartsWith.startsWith("text/plain"));
String body = response.asString().get(5, TimeUnit.SECONDS);
assertThat(body, containsString("alpha{method=\"bar\",} 6.0"));
assertThat(body, not(containsString("alpha{method=\"baz\"")));
alpha.labels("baz").inc();
response = doTestRequest(null);
body = response.asString().get(5, TimeUnit.SECONDS);
assertThat(body, containsString("alpha{method=\"baz\",} 1.0"));
}
use of io.helidon.webserver.testsupport.TestResponse in project helidon by oracle.
the class PrometheusSupportTest method simpleCall.
@Test
public void simpleCall() throws Exception {
TestResponse response = doTestRequest(null);
assertThat(response.headers().first(Http.Header.CONTENT_TYPE).orElse(null), StringStartsWith.startsWith("text/plain"));
String body = response.asString().get(5, TimeUnit.SECONDS);
assertThat(body, containsString("# HELP beta"));
assertThat(body, containsString("# TYPE beta counter"));
assertThat(body, containsString("beta 3.0"));
assertThat(body, containsString("# TYPE alpha counter"));
assertThat(body, containsString("# HELP alpha Alpha help with \\\\ and \\n."));
assertThat(body, containsString("alpha{method=\"bar\",} 6.0"));
assertThat(body, containsString("alpha{method=\"\\\"foo\\\" \\\\ \\n\",} 5.0"));
}
use of io.helidon.webserver.testsupport.TestResponse in project helidon by oracle.
the class CommentServiceTest method testRouting.
@Test
public void testRouting() throws Exception {
Routing routing = Routing.builder().register(new CommentService()).build();
TestResponse response = TestClient.create(routing).path("one").get();
assertEquals(Http.Status.OK_200, response.status());
// Add first comment
response = TestClient.create(routing).path("one").post(MediaPublisher.create(MediaType.TEXT_PLAIN, "aaa"));
assertEquals(Http.Status.OK_200, response.status());
response = TestClient.create(routing).path("one").get();
assertEquals(Http.Status.OK_200, response.status());
byte[] data = response.asBytes().toCompletableFuture().get();
assertEquals("anonymous: aaa\n", new String(data, StandardCharsets.UTF_8));
// Add second comment
response = TestClient.create(routing).path("one").post(MediaPublisher.create(MediaType.TEXT_PLAIN, "bbb"));
assertEquals(Http.Status.OK_200, response.status());
response = TestClient.create(routing).path("one").get();
assertEquals(Http.Status.OK_200, response.status());
data = response.asBytes().toCompletableFuture().get();
assertEquals("anonymous: aaa\nanonymous: bbb\n", new String(data, StandardCharsets.UTF_8));
}
use of io.helidon.webserver.testsupport.TestResponse in project helidon by oracle.
the class MainTest method testShutDown.
@Test
public void testShutDown() throws Exception {
TestResponse response = TestClient.create(Main.createRouting()).path("/mgmt/shutdown").post();
assertEquals(Http.Status.OK_200, response.status());
CountDownLatch latch = new CountDownLatch(1);
WebServer webServer = response.webServer();
webServer.whenShutdown().thenRun(latch::countDown);
assertTrue(latch.await(10, TimeUnit.SECONDS));
}
use of io.helidon.webserver.testsupport.TestResponse in project helidon by oracle.
the class UserFilterTest method filter.
@Test
public void filter() throws Exception {
AtomicReference<User> userReference = new AtomicReference<>();
Routing routing = Routing.builder().any(new UserFilter()).any((req, res) -> {
userReference.set(req.context().get(User.class).orElse(null));
res.send();
}).build();
TestResponse response = TestClient.create(routing).path("/").get();
assertEquals(User.ANONYMOUS, userReference.get());
response = TestClient.create(routing).path("/").header("Cookie", "Unauthenticated-User-Alias=Foo").get();
assertEquals("Foo", userReference.get().getAlias());
}
Aggregations