Examples of RackResponse


Examples of org.jrack.RackResponse

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

    RackResponse response = micro.call(input);
    Assert.assertTrue(RackResponse.getBodyAsString(response).contains("Hello"));
  }
View Full Code Here

Examples of org.jrack.RackResponse

    Context<String> input = new MapContext<String>()
        .with(Rack.REQUEST_METHOD, "GET")
        .with(Rack.PATH_INFO, "/index.html")
        .with(Rack.RACK_BROWSER_LOCALE, "de");

    RackResponse response = micro.call(input);
    Assert.assertTrue("Context based localization failed",
        RackResponse.getBodyAsString(response).contains("Grüß Gott!"));
  }
View Full Code Here

Examples of org.jrack.RackResponse

        .with(Rack.PARAMS, Collections.singletonMap("language", "en"))
        .with(Rack.PATH_INFO, "/index.html")
        .with(Rack.REQUEST_METHOD, "GET");

    // English
    RackResponse response = micro.call(input);
    Assert.assertTrue("Expecting: Hello", RackResponse.getBodyAsString(response).contains("Hello"));

    // Romanian
    input.with(Rack.PARAMS, Collections.singletonMap("language", "ro"));
    response = micro.call(input);
View Full Code Here

Examples of org.jrack.RackResponse

    Context<String> input = new MapContext<String>()
        .with(Rack.REQUEST_METHOD, "GET")
        .with(Rack.PATH_INFO, "/result.html")
        .with(Rack.PARAMS, Collections.singletonMap("exp", URLEncoder.encode("2+2", Globals.UTF8)));

    RackResponse response = micro.call(input);
    Assert.assertTrue("Can't use the request parameters",
        RackResponse.getBodyAsString(response).contains("=4"));
  }
View Full Code Here

Examples of org.jrack.RackResponse

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

    RackResponse response = micro.call(input);
    Assert.assertTrue("Wrong template",
        RackResponse.getBodyAsString(response).contains("TXT DEFAULT TEMPLATE, content: Some text."));

    input.with(Rack.PATH_INFO, "/another_text.txt");
    response = micro.call(input);
View Full Code Here

Examples of org.jrack.RackResponse

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

    RackResponse response = micro.call(input);
    Assert.assertTrue(RackResponse.getBodyAsString(response)
        .contains("<h3>Markdown</h3><p>This is a simple markdown document</p>"));
  }
View Full Code Here

Examples of org.jrack.RackResponse

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

    RackResponse response = micro.call(input);
    Assert.assertTrue(response.getStatus() == HttpServletResponse.SC_SEE_OTHER);
    String location = response.getHeaders().get("Location");
    Assert.assertTrue("Invalid redirection control", location.contains("redirected.html"));
    Assert.assertTrue("The response must be empty", RackResponse.getBodyAsString(response).isEmpty());
  }
View Full Code Here

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

Examples of org.jrack.RackResponse

     * @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

Examples of org.jrack.RackResponse

    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
TOP
Copyright © 2018 www.massapi.com. 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.