Search in sources :

Example 21 with MinijaxRequestContext

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

the class QueryParamProvider method get.

@Override
public T get() {
    final MinijaxRequestContext context = MinijaxRequestContext.getThreadLocal();
    String value = context.getUriInfo().getQueryParameters().getFirst(key.getName());
    if (value == null && key.getDefaultValue() != null) {
        value = key.getDefaultValue().value();
    }
    return context.getApplication().convertParamToType(value, key.getType(), key.getAnnotations());
}
Also used : MinijaxRequestContext(org.minijax.MinijaxRequestContext)

Example 22 with MinijaxRequestContext

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

the class MinijaxInvocationBuilder method method.

@Override
public Response method(final String name) {
    final Minijax container = target.getServer();
    final MinijaxApplication application = container.getApplication(target.getUri());
    try {
        final MockHttpServletRequest request = new MockHttpServletRequest(name, target.getUri(), headers, getEntityInputStream(), CookieUtils.convertJaxToServlet(cookies));
        final MockHttpServletResponse response = new MockHttpServletResponse();
        try (final MinijaxRequestContext context = new MinijaxRequestContext(application, request, response)) {
            return application.handle(context);
        }
    } catch (final IOException ex) {
        throw ExceptionUtils.toWebAppException(ex);
    }
}
Also used : MinijaxApplication(org.minijax.MinijaxApplication) MinijaxRequestContext(org.minijax.MinijaxRequestContext) Minijax(org.minijax.Minijax) IOException(java.io.IOException)

Example 23 with MinijaxRequestContext

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

the class ExceptionMapperTest method testNotFound.

@Test
public 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(javax.ws.rs.core.Response) MinijaxRequestContext(org.minijax.MinijaxRequestContext) NotFoundException(javax.ws.rs.NotFoundException) MinijaxTest(org.minijax.test.MinijaxTest) Test(org.junit.Test)

Example 24 with MinijaxRequestContext

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

the class CsrfFilterTest method setUpCsrfFilterTest.

@BeforeClass
@SuppressWarnings("unchecked")
public static void setUpCsrfFilterTest() throws IOException {
    register(PersistenceFeature.class);
    register(new SecurityFeature(User.class, Dao.class));
    register(CsrfFilterTest.class);
    try (MinijaxRequestContext ctx = createRequestContext()) {
        user = new User();
        user.setName("Alice");
        user.setEmail("alice@example.com");
        user.setRoles("user");
        final Dao dao = ctx.get(Dao.class);
        user = dao.create(user);
        final Security<User> security = ctx.get(Security.class);
        cookie = security.loginAs(user);
    }
}
Also used : MinijaxRequestContext(org.minijax.MinijaxRequestContext) BeforeClass(org.junit.BeforeClass)

Example 25 with MinijaxRequestContext

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

the class RolesAllowedTest method setUpSecurityTest.

@BeforeClass
public static void setUpSecurityTest() throws IOException {
    resetServer();
    getServer().register(PersistenceFeature.class).register(new SecurityFeature(User.class, Dao.class)).register(RolesAllowedTest.class);
    try (final MinijaxRequestContext ctx = createRequestContext()) {
        final Dao dao = ctx.get(Dao.class);
        alice = new User();
        alice.setName("Alice");
        alice.setEmail("alice@example.com");
        alice.setHandle("alice");
        alice.setPassword("alicepwd");
        alice.setRoles("user", "admin");
        dao.create(alice);
        bob = new User();
        bob.setName("Bob");
        bob.setEmail("bob@example.com");
        bob.setHandle("bob");
        bob.setPassword("bobpwd");
        bob.setRoles("user");
        dao.create(bob);
        aliceCookie = ctx.get(Security.class).loginAs(alice);
        bobCookie = ctx.get(Security.class).loginAs(bob);
    }
}
Also used : DefaultBaseDao(org.minijax.db.DefaultBaseDao) MinijaxRequestContext(org.minijax.MinijaxRequestContext) BeforeClass(org.junit.BeforeClass)

Aggregations

MinijaxRequestContext (org.minijax.MinijaxRequestContext)25 Test (org.junit.Test)16 MinijaxTest (org.minijax.test.MinijaxTest)13 Response (javax.ws.rs.core.Response)10 Form (javax.ws.rs.core.Form)8 Cookie (javax.ws.rs.core.Cookie)7 Minijax (org.minijax.Minijax)4 MinijaxApplication (org.minijax.MinijaxApplication)4 MockHttpServletRequest (org.minijax.test.MockHttpServletRequest)3 IOException (java.io.IOException)2 NotFoundException (javax.ws.rs.NotFoundException)2 BeforeClass (org.junit.BeforeClass)2 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)1 AnnotatedEndpoint (io.undertow.websockets.jsr.annotated.AnnotatedEndpoint)1 InputStream (java.io.InputStream)1 InjectionException (javax.enterprise.inject.InjectionException)1 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)1 DefaultValue (javax.ws.rs.DefaultValue)1 MediaType (javax.ws.rs.core.MediaType)1