Search in sources :

Example 16 with MinijaxRequestContext

use of org.minijax.rs.MinijaxRequestContext in project minijax by minijax.

the class RequestScopedProvider method get.

@Override
public T get(final Object obj) {
    final MinijaxRequestContext context = (MinijaxRequestContext) obj;
    final ResourceCache resourceCache = context.getResourceCache();
    T instance = resourceCache.get(key);
    if (instance == null) {
        instance = sourceProvider.get(context);
        resourceCache.put(key, instance);
    }
    return instance;
}
Also used : MinijaxRequestContext(org.minijax.rs.MinijaxRequestContext)

Example 17 with MinijaxRequestContext

use of org.minijax.rs.MinijaxRequestContext in project minijax by minijax.

the class AdapterTest method testOnMessage.

@Test
void testOnMessage() throws IOException {
    try (final MinijaxRequestContext ctx = createRequestContext()) {
        final MinijaxUndertowWebSocketAdapter adapter = new MinijaxUndertowWebSocketAdapter(ctx, TestSocket2.class);
        adapter.onOpen(emptyMap());
        adapter.onMessage(singletonMap(String.class, "test"));
        adapter.onClose(emptyMap());
        adapter.onError(emptyMap());
    }
}
Also used : MinijaxRequestContext(org.minijax.rs.MinijaxRequestContext) Test(org.junit.jupiter.api.Test) MinijaxTest(org.minijax.rs.test.MinijaxTest)

Example 18 with MinijaxRequestContext

use of org.minijax.rs.MinijaxRequestContext in project minijax by minijax.

the class AdapterTest method testOnClose.

@Test
void testOnClose() throws IOException {
    try (final MinijaxRequestContext ctx = createRequestContext()) {
        final MinijaxUndertowWebSocketAdapter adapter = new MinijaxUndertowWebSocketAdapter(ctx, TestSocket3.class);
        adapter.onOpen(emptyMap());
        adapter.onMessage(emptyMap());
        adapter.onClose(emptyMap());
        adapter.onError(emptyMap());
    }
}
Also used : MinijaxRequestContext(org.minijax.rs.MinijaxRequestContext) Test(org.junit.jupiter.api.Test) MinijaxTest(org.minijax.rs.test.MinijaxTest)

Example 19 with MinijaxRequestContext

use of org.minijax.rs.MinijaxRequestContext in project minijax by minijax.

the class ExceptionMapperTest method testNotFound.

@Test
void testNotFound() throws IOException {
    try (final MinijaxRequestContext ctx = createRequestContext()) {
        final MinijaxJsonExceptionMapper mapper = new MinijaxJsonExceptionMapper();
        final Response response = mapper.toResponse(new NotFoundException());
        assertNotNull(response);
        assertEquals(404, response.getStatus());
        assertEquals(404, ((MinijaxJsonExceptionWrapper) response.getEntity()).getCode());
        assertEquals("HTTP 404 Not Found", ((MinijaxJsonExceptionWrapper) response.getEntity()).getMessage());
    }
}
Also used : Response(jakarta.ws.rs.core.Response) MinijaxRequestContext(org.minijax.rs.MinijaxRequestContext) NotFoundException(jakarta.ws.rs.NotFoundException) Test(org.junit.jupiter.api.Test) MinijaxTest(org.minijax.rs.test.MinijaxTest)

Example 20 with MinijaxRequestContext

use of org.minijax.rs.MinijaxRequestContext in project minijax by minijax.

the class ExceptionMapperTest method testNotFound.

@Test
void testNotFound() throws IOException {
    try (final MinijaxRequestContext ctx = createRequestContext()) {
        final MinijaxMustacheExceptionMapper mapper = new MinijaxMustacheExceptionMapper();
        final Response response = mapper.toResponse(new NotFoundException());
        assertNotNull(response);
        assertEquals(404, response.getStatus());
        assertEquals("error", ((View) response.getEntity()).getTemplateName());
    }
}
Also used : Response(jakarta.ws.rs.core.Response) MinijaxRequestContext(org.minijax.rs.MinijaxRequestContext) NotFoundException(jakarta.ws.rs.NotFoundException) Test(org.junit.jupiter.api.Test) MinijaxTest(org.minijax.rs.test.MinijaxTest)

Aggregations

MinijaxRequestContext (org.minijax.rs.MinijaxRequestContext)33 Test (org.junit.jupiter.api.Test)23 MinijaxTest (org.minijax.rs.test.MinijaxTest)21 Response (jakarta.ws.rs.core.Response)13 Form (jakarta.ws.rs.core.Form)8 MinijaxApplication (org.minijax.rs.MinijaxApplication)7 Cookie (jakarta.ws.rs.core.Cookie)6 MediaType (jakarta.ws.rs.core.MediaType)4 Minijax (org.minijax.Minijax)4 IOException (java.io.IOException)3 List (java.util.List)3 NotFoundException (jakarta.ws.rs.NotFoundException)2 InputStream (java.io.InputStream)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 MinijaxTestRequestContext (org.minijax.rs.test.MinijaxTestRequestContext)2 ByteBuf (io.netty.buffer.ByteBuf)1 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)1 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)1 AsciiString (io.netty.util.AsciiString)1 HttpString (io.undertow.util.HttpString)1