Search in sources :

Example 21 with MinijaxRequestContext

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

the class MinijaxTestInvocationBuilder method method.

@Override
public Response method(final String name) {
    final Minijax container = target.getServer();
    final MinijaxApplication application = container.getApplication(target.getUri());
    final MinijaxUriInfo uriInfo = new MinijaxUriInfo(target.getUri());
    if (!cookies.isEmpty()) {
        headers.add("Cookie", cookies.values().stream().map(c -> c.getName() + "=" + c.getValue()).collect(Collectors.joining("; ")));
    }
    try (final MinijaxRequestContext clientContext = new MinijaxTestRequestContext(application, name, uriInfo);
        final InputStream entityStream = EntityUtils.writeEntity(entity, clientContext.getProviders());
        final MinijaxRequestContext serverContext = new MinijaxTestRequestContext(application, name, new MinijaxUriInfo(target.getUri()), new MinijaxTestHttpHeaders(headers), entityStream)) {
        return application.handle(serverContext);
    } catch (final IOException ex) {
        throw ExceptionUtils.toWebAppException(ex);
    }
}
Also used : MinijaxApplication(org.minijax.rs.MinijaxApplication) MinijaxRequestContext(org.minijax.rs.MinijaxRequestContext) Minijax(org.minijax.Minijax) InputStream(java.io.InputStream) IOException(java.io.IOException) MinijaxUriInfo(org.minijax.rs.MinijaxUriInfo)

Example 22 with MinijaxRequestContext

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

the class RequestScopedTest method testRequestScoped.

@Test
void testRequestScoped() throws IOException {
    final Minijax container = new Minijax();
    final MinijaxApplication application = container.getDefaultApplication();
    A a1;
    A a2;
    try (MinijaxRequestContext context = new MinijaxTestRequestContext(application, GET, "/")) {
        a1 = context.getResource(A.class);
        assertNotNull(a1);
        a2 = context.getResource(A.class);
        assertEquals(a1, a2);
        assertSame(a1, a2);
    }
    A a3;
    A a4;
    try (MinijaxRequestContext context = new MinijaxTestRequestContext(application, GET, "/")) {
        a3 = context.getResource(A.class);
        assertNotNull(a3);
        a4 = context.getResource(A.class);
        assertEquals(a3, a4);
        assertSame(a3, a4);
    }
    assertNotEquals(a1, a3);
    assertNotSame(a1, a3);
    container.getInjector().close();
}
Also used : MinijaxApplication(org.minijax.rs.MinijaxApplication) MinijaxRequestContext(org.minijax.rs.MinijaxRequestContext) Minijax(org.minijax.Minijax) MinijaxTestRequestContext(org.minijax.rs.test.MinijaxTestRequestContext) Test(org.junit.jupiter.api.Test)

Example 23 with MinijaxRequestContext

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

the class EntityProvider method get.

@SuppressWarnings("unchecked")
@Override
public T get(final Object obj) {
    final MinijaxRequestContext context = (MinijaxRequestContext) obj;
    // If you call getInputStream -- even if you don't read from it -- the input stream is moved.
    if (entityClass == MultivaluedMap.class) {
        return (T) context.getForm().asForm().asMap();
    }
    final InputStream entityStream = context.getEntityStream();
    try {
        return EntityUtils.readEntity(entityClass, genericType, annotations, mediaType, context, entityStream);
    } catch (final IOException ex) {
        throw new InjectionException(ex.getMessage(), ex);
    }
}
Also used : InjectionException(jakarta.enterprise.inject.InjectionException) MinijaxRequestContext(org.minijax.rs.MinijaxRequestContext) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 24 with MinijaxRequestContext

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

the class AbstractParamProvider method get.

@Override
public T get(final Object obj) {
    final MinijaxRequestContext context = (MinijaxRequestContext) obj;
    String value = getStringValue(context);
    if (value == null && defaultValue != null) {
        value = defaultValue.value();
    }
    return context.convertParamToType(value, type, annotations);
}
Also used : MinijaxRequestContext(org.minijax.rs.MinijaxRequestContext)

Example 25 with MinijaxRequestContext

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

the class AdapterTest method testOnOpen.

@Test
void testOnOpen() throws IOException {
    try (final MinijaxRequestContext ctx = createRequestContext()) {
        final MinijaxUndertowWebSocketAdapter adapter = new MinijaxUndertowWebSocketAdapter(ctx, TestSocket1.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)

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