Package javaguide.testhelpers

Examples of javaguide.testhelpers.MockJavaAction


public class JavaBodyParsers extends WithApplication {

    @Test
    public void accessRequestBody() {
        assertThat(contentAsString(call(new MockJavaAction() {
            //#request-body
            public Result index() {
                RequestBody body = request().body();
                return ok("Got body: " + body);
            }
View Full Code Here


        }, fakeRequest().withTextBody("foo"))), containsString("foo"));
    }

    @Test
    public void particularBodyParser() {
        assertThat(contentAsString(call(new MockJavaAction() {
                    //#particular-body-parser
                    @BodyParser.Of(BodyParser.Json.class)
                    public Result index() {
                        RequestBody body = request().body();
                        return ok("Got json: " + body.asJson());
View Full Code Here

                containsString("\"foo\""));
    }

    @Test
    public void defaultParser() {
        assertThat(status(call(new MockJavaAction() {
                    //#default-parser
                    public Result save() {
                        RequestBody body = request().body();
                        String textBody = body.asText();
View Full Code Here

    public void maxLength() {
        StringBuilder body = new StringBuilder();
        for (int i = 0; i < 1100; i++) {
            body.append("1234567890");
        }
        assertThat(status(callWithStringBody(new MockJavaAction() {
                    //#max-length
                    // Accept only 10KB of data.
                    @BodyParser.Of(value = BodyParser.Text.class, maxLength = 10 * 1024)
                    public Result index() {
                        return ok("Got body: " + request().body().asText());
View Full Code Here

        return fakeApplication(ImmutableMap.of("application.secret", "pass"));
    }

    @Test
    public void readSession() {
        assertThat(contentAsString(call(new MockJavaAction() {
                    //#read-session
                    public Result index() {
                        String user = session("connected");
                        if(user != null) {
                            return ok("Hello " + user);
View Full Code Here

                equalTo("Hello foo"));
    }

    @Test
    public void storeSession() {
        Session session = session(call(new MockJavaAction() {
            //#store-session
            public Result login() {
                session("connected", "user@gmail.com");
                return ok("Welcome!");
            }
View Full Code Here

        assertThat(session.get("connected"), equalTo("user@gmail.com"));
    }

    @Test
    public void removeFromSession() {
        Session session = session(call(new MockJavaAction() {
            //#remove-from-session
            public Result logout() {
                session().remove("connected");
                return ok("Bye");
            }
View Full Code Here

        assertThat(session.get("connected"), nullValue());
    }

    @Test
    public void discardWholeSession() {
        Session session = session(call(new MockJavaAction() {
            //#discard-whole-session
            public Result logout() {
                session().clear();
                return ok("Bye");
            }
View Full Code Here

        assertThat(session.get("connected"), nullValue());
    }

    @Test
    public void readFlash() {
        assertThat(contentAsString(call(new MockJavaAction() {
                    //#read-flash
                    public Result index() {
                        String message = flash("success");
                        if(message == null) {
                            message = "Welcome!";
View Full Code Here

                equalTo("hi"));
    }

    @Test
    public void storeFlash() {
        Flash flash = flash(call(new MockJavaAction() {
            //#store-flash
            public Result save() {
                flash("success", "The item has been created");
                return redirect("/home");
            }
View Full Code Here

TOP

Related Classes of javaguide.testhelpers.MockJavaAction

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.