Package org.jrack

Examples of org.jrack.RackResponse


  public void testRoutesRedirectToUrl() throws Exception {
    Context<String> input = new MapContext<String>()
        .with(Rack.REQUEST_METHOD, "GET")
        .with(Rack.PATH_INFO, "/redir/me");

    RackResponse response = micro.call(input);
    Assert.assertTrue(response.getStatus() == HttpServletResponse.SC_SEE_OTHER);
    String location = response.getHeaders().get("Location");
    Assert.assertTrue(location.contains("redirected")); // no extension in this case
    Assert.assertTrue(RackResponse.getBodyAsString(response).isEmpty());
  }
View Full Code Here


     * @throws RedirectException a special exception to be intercepted by Micro so it can
     *                           halt the current process and return the control back to the JRack
     */
    public void setRedirect(String path, boolean secure, int redirectCode) throws RedirectException {
        if (path != null && !path.isEmpty()) {
            RackResponse response = getRackResponse();
            String method = getRequest() != null? getRequest().getMethod(): Globals.EMPTY_STRING;
            int rCode = redirectCode != 0 ? redirectCode :
                    (!"GET".equalsIgnoreCase(method) ? 303 : 302);

            response = null;
            response = new RackResponse(rCode)
                    .withBody(Globals.EMPTY_STRING)
                    .withContentLength(0);

            int defaultPort = getRequest() != null? getRequest().getServerPort() : 8080;
            UrlUtilities urlUtilities = new UrlUtilities(getRequest(), getResponse());

            String location = secure ?
                    urlUtilities.buildSecure(path) :
                    urlUtilities.buildStandard(path, defaultPort);

            with(Globals.RACK_RESPONSE, response.withHeader("Location", location));
            throw new RedirectException();
        }
    }
View Full Code Here

    public void testBeforeFilters() throws Exception {
        Context<String> input = new MapContext<String>()
                .with(Rack.PATH_INFO, "/private/repositories/micro")
                .with(Rack.REQUEST_METHOD, "GET");

        RackResponse response = micro.call(input);
        expect200(response);

        Assert.assertTrue("Expecting a set of user roles in the current input",
                RackResponse.getBodyAsString(response).contains("userRoles"));
    }
View Full Code Here

    public void testAfterFilters() throws Exception {
        Context<String> input = new MapContext<String>()
                .with(Rack.PATH_INFO, "/download/")
                .with(Rack.REQUEST_METHOD, "GET");

        RackResponse response = micro.call(input);
        expect200(response);

        Assert.assertTrue("Download activity must be logged",
                ((MicroContext) input.getObject(Globals.CONTEXT))
                        .get("downloadActivity").equals("logged"));
View Full Code Here

    public void testPathLessFilters() throws Exception {
        Context<String> input = new MapContext<String>()
                .with(Rack.PATH_INFO, "/index.html")
                .with(Rack.REQUEST_METHOD, "GET");

        RackResponse response = micro.call(input);
        expect200(response);

        Assert.assertTrue("There is no stickiness in this context, pathless filters failure",
                ((MicroContext) input.getObject(Globals.CONTEXT))
                        .get("sticky").equals("I am a sticky filter"));
View Full Code Here

    public void testWrappedControllers() throws Exception {
        Context<String> input = new MapContext<String>()
                .with(Rack.REQUEST_METHOD, "GET")
                .with(Rack.PATH_INFO, "/view_with_wrappers.html");

        RackResponse response = micro.call(input);
        String body = RackResponse.getBodyAsString(response);

        Assert.assertTrue(body.contains("Before: true"));
        Assert.assertTrue(body.contains("Wrapped with: love"));
        Assert.assertTrue(body.contains("After: true"));
View Full Code Here

    public void testViewWithFilters() throws Exception {
        Context<String> input = new MapContext<String>()
                .with(Rack.REQUEST_METHOD, "GET")
                .with(Rack.PATH_INFO, "/view_with_filters.html");

        RackResponse response = micro.call(input);
        String body = RackResponse.getBodyAsString(response);
        MicroContext context = (MicroContext) ((MapContext) input).get("context");
        Assert.assertTrue("Invalid response", response.getStatus() == HttpServletResponse.SC_OK);
        Assert.assertTrue("Couldn't evaluate the BEFORE filters",
                body.contains("BEFORE: [filters/BeforeViewFilter1.bsh, filters/BeforeViewFilter2.bsh]"));
        Assert.assertNotNull("Should receive some feedback from the AFTER filters",
                context.get("afterFilters"));
    }
View Full Code Here

    public void testBinaryContent() throws Exception {
        Context<String> input = new MapContext<String>()
                .with(Rack.REQUEST_METHOD, "GET")
                .with(Rack.PATH_INFO, "/micro-logo.png");

        RackResponse response = micro.call(input);
        Assert.assertTrue("Can't load binary content from a dynamic repository",
                RackResponse.getBodyAsBytes(response).length == 6898);

        Assert.assertTrue("Invalid Content-Type header",
                RackResponse.getHeaders(response).get("Content-Type")
View Full Code Here

        Context<String> input = new MapContext<String>()
                .with(Rack.REQUEST_METHOD, "GET")
                .with(Rack.PATH_INFO, "/micro/files");

        RackResponse response = micro.call(input);
        Assert.assertEquals("Invalid response", "/micro/files",
                RackResponse.getBodyAsString(response, Charset.forName("UTF-8")));
    }
View Full Code Here

        Context<String> input = new MapContext<String>()
                .with(Rack.REQUEST_METHOD, "GET")
                .with(Rack.PATH_INFO, "/micro/µ/0.1.2");

        RackResponse response = micro.call(input);
        Assert.assertEquals("Invalid response", "{\"micro\":{\"name\":\"µ\",\"version\":\"0.1.2\"}}",
                RackResponse.getBodyAsString(response, Charset.forName("UTF-8")));
    }
View Full Code Here

TOP

Related Classes of org.jrack.RackResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.