Search in sources :

Example 11 with ServerResponse

use of io.helidon.webserver.ServerResponse in project helidon by oracle.

the class StaticContentHandlerTest method handleOutside.

@Test
void handleOutside() {
    ServerRequest request = mockRequestWithPath("/../foo/some.txt");
    ServerResponse response = mock(ServerResponse.class);
    TestContentHandler handler = TestContentHandler.create(true);
    handler.handle(Http.Method.GET, request, response);
    verify(request).next();
    assertThat(handler.counter.get(), is(0));
}
Also used : ServerResponse(io.helidon.webserver.ServerResponse) ServerRequest(io.helidon.webserver.ServerRequest) Test(org.junit.jupiter.api.Test)

Example 12 with ServerResponse

use of io.helidon.webserver.ServerResponse in project helidon by oracle.

the class StaticContentHandlerTest method handleIllegalMethod.

@Test
void handleIllegalMethod() {
    ServerRequest request = mockRequestWithPath("/");
    ServerResponse response = mock(ServerResponse.class);
    TestContentHandler handler = TestContentHandler.create(true);
    handler.handle(Http.Method.POST, request, response);
    verify(request).next();
    assertThat(handler.counter.get(), is(0));
}
Also used : ServerResponse(io.helidon.webserver.ServerResponse) ServerRequest(io.helidon.webserver.ServerRequest) Test(org.junit.jupiter.api.Test)

Example 13 with ServerResponse

use of io.helidon.webserver.ServerResponse in project helidon by oracle.

the class StaticContentHandlerTest method handleRoot.

@Test
void handleRoot() {
    ServerRequest request = mockRequestWithPath("/");
    ServerResponse response = mock(ServerResponse.class);
    TestContentHandler handler = TestContentHandler.create(true);
    handler.handle(Http.Method.GET, request, response);
    verify(request, never()).next();
    assertThat(handler.path, is(Paths.get(".").toAbsolutePath().normalize()));
}
Also used : ServerResponse(io.helidon.webserver.ServerResponse) ServerRequest(io.helidon.webserver.ServerRequest) Test(org.junit.jupiter.api.Test)

Example 14 with ServerResponse

use of io.helidon.webserver.ServerResponse in project helidon by oracle.

the class AccessLogSupportTest method testHelidonFormat.

@Test
void testHelidonFormat() {
    AccessLogSupport accessLog = AccessLogSupport.create();
    ServerRequest request = mock(ServerRequest.class);
    Context context = Context.create();
    when(request.remoteAddress()).thenReturn(REMOTE_IP);
    when(request.context()).thenReturn(context);
    when(request.method()).thenReturn(Http.Method.PUT);
    HttpRequest.Path path = mock(HttpRequest.Path.class);
    when(path.toRawString()).thenReturn(PATH);
    when(request.path()).thenReturn(path);
    when(request.version()).thenReturn(Http.Version.V1_1);
    ServerResponse response = mock(ServerResponse.class);
    when(response.status()).thenReturn(Http.Status.I_AM_A_TEAPOT);
    AccessLogContext accessLogContext = mock(AccessLogContext.class);
    when(accessLogContext.requestDateTime()).thenReturn(BEGIN_TIME);
    String expectedTimestamp = TimestampLogEntry.create().doApply(accessLogContext);
    String logRecord = accessLog.createLogRecord(request, response, BEGIN_TIME, 0L, END_TIME, TIME_TAKEN_MICROS * 1000);
    // 192.168.0.104 - [18/Jun/2019:23:10:44 +0200] "GET /greet/test HTTP/1.1" 200 55 2248
    String expected = REMOTE_IP + " - " + expectedTimestamp + " \"" + METHOD + " " + PATH + " " + HTTP_VERSION + "\" " + STATUS_CODE + " " + CONTENT_LENGTH + " " + TIME_TAKEN_MICROS;
    assertThat(logRecord, is(expected));
}
Also used : Context(io.helidon.common.context.Context) HttpRequest(io.helidon.common.http.HttpRequest) ServerResponse(io.helidon.webserver.ServerResponse) ServerRequest(io.helidon.webserver.ServerRequest) Test(org.junit.jupiter.api.Test)

Example 15 with ServerResponse

use of io.helidon.webserver.ServerResponse in project helidon by oracle.

the class StaticContentHandlerTest method classpathHandleSpaces.

@Test
void classpathHandleSpaces() {
    ServerRequest request = mockRequestWithPath("foo/I have spaces.txt");
    ServerResponse response = mock(ServerResponse.class);
    TestClassPathContentHandler handler = TestClassPathContentHandler.create();
    handler.handle(Http.Method.GET, request, response);
    verify(request, never()).next();
    assertThat(handler.counter.get(), is(1));
}
Also used : ServerResponse(io.helidon.webserver.ServerResponse) ServerRequest(io.helidon.webserver.ServerRequest) Test(org.junit.jupiter.api.Test)

Aggregations

ServerResponse (io.helidon.webserver.ServerResponse)37 ServerRequest (io.helidon.webserver.ServerRequest)36 Routing (io.helidon.webserver.Routing)23 Logger (java.util.logging.Logger)18 JsonObject (jakarta.json.JsonObject)13 Config (io.helidon.config.Config)12 Map (java.util.Map)12 Service (io.helidon.webserver.Service)11 Json (jakarta.json.Json)11 Optional (java.util.Optional)11 Single (io.helidon.common.reactive.Single)10 DbClient (io.helidon.dbclient.DbClient)10 Test (org.junit.jupiter.api.Test)10 Http (io.helidon.common.http.Http)9 Pokemon (io.helidon.tests.integration.dbclient.appl.model.Pokemon)9 AppResponse (io.helidon.tests.integration.tools.service.AppResponse)9 RemoteTestException (io.helidon.tests.integration.tools.service.RemoteTestException)9 List (java.util.List)9 SecurityContext (io.helidon.security.SecurityContext)8 AbstractService (io.helidon.tests.integration.dbclient.appl.AbstractService)8