Package org.jboss.aerogear.controller.mocks

Examples of org.jboss.aerogear.controller.mocks.RouteTester


public class DefaultRouteProcessorTest {

    @Test
    public void testRouteForbidden() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/car/{id}").roles("admin")
                        .on(GET)
                        .to(SampleController.class).find(param("id"));
            }
        }).requestMethod(GET).acceptHeader(HTML);
        final Route route = routeTester.routeFor("/car/3");
        doThrow(new ServletException("RouteForbiddenTest")).when(routeTester.getSecurityProvider()).isRouteAllowed(route);
        final InvocationResult processResult = routeTester.process(route);
        assertThat(processResult.getResult()).isInstanceOf(ServletException.class);
    }
View Full Code Here


        assertThat(processResult.getResult()).isInstanceOf(ServletException.class);
    }

    @Test
    public void testMvcRouteWithPathParam() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/car/{id}").roles("admin")
                        .on(GET)
                        .produces(JSP)
                        .to(SampleController.class).find(param("id"));
            }
        });
        routeTester.acceptHeader(HTML).processGetRequest("/car/3");
        verify(routeTester.<SampleController>getController()).find("3");
        verify(routeTester.jspResponder()).respond(any(), any(RouteContext.class));
    }
View Full Code Here

        verify(routeTester.jspResponder()).respond(any(), any(RouteContext.class));
    }

    @Test
    public void testRestRouteWithPathParam() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/car/{id}").roles("admin")
                        .on(GET)
                        .produces(JSP, JSON)
                        .to(SampleController.class).find(param("id"));
            }
        });
        routeTester.acceptHeader(JSON).processGetRequest("/car/3");
        verify(routeTester.<SampleController>getController()).find("3");
        verify(routeTester.jsonResponder()).respond(any(), any(RouteContext.class));
    }
View Full Code Here

        verify(routeTester.jsonResponder()).respond(any(), any(RouteContext.class));
    }

    @Test
    public void testRestRouteWithTypedPathParam() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/car/{id}").roles("admin")
                        .on(GET)
                        .produces(JSP, JSON)
                        .to(SampleController.class).find(param("id",Long.class));
            }
        });
        routeTester.acceptHeader(JSON).processGetRequest("/car/3");
        verify(routeTester.<SampleController>getController()).find(new Long(3));
        verify(routeTester.jsonResponder()).respond(any(), any(RouteContext.class));
    }
View Full Code Here

        verify(routeTester.jsonResponder()).respond(any(), any(RouteContext.class));
    }

    @Test
    public void testFormParameters() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/cars")
                        .on(RequestMethod.POST)
                        .produces(JSP)
                        .to(SampleController.class).save(param("color"), param("brand"));
            }
        }).requestMethod(POST).acceptHeader(HTML).param("color", "red").param("brand", "Ferrari");
        routeTester.spyController(new SampleController());
        final InvocationResult r = routeTester.process("/cars");
        final Car car = (Car) r.getResult();
        assertThat(car.getColor()).isEqualTo("red");
        assertThat(car.getBrand()).isEqualTo("Ferrari");
        verify(routeTester.jspResponder()).respond(any(), any(RouteContext.class));
    }
View Full Code Here

        verify(routeTester.jspResponder()).respond(any(), any(RouteContext.class));
    }

    @Test
    public void testFormParametersWithOneDefaultValue() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/cars")
                        .on(RequestMethod.POST)
                        .produces(JSP)
                        .to(SampleController.class).save(param("color", "gray"), param("brand", "Lada"));
            }
        }).acceptHeader(HTML).param("color", "gray");
        routeTester.processPostRequest("/cars");
        verify(routeTester.<SampleController>getController()).save("gray", "Lada");
        verify(routeTester.jspResponder()).respond(any(), any(RouteContext.class));
    }
View Full Code Here

        verify(routeTester.jspResponder()).respond(any(), any(RouteContext.class));
    }

    @Test
    public void testEntityFormParameter() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/cars")
                        .on(POST)
                        .produces(JSP)
                        .to(SampleController.class).save(param(Car.class));
            }
        }).acceptHeader(HTML).param("car.color", "Blue").param("car.brand", "BMW");
        routeTester.processPostRequest("/cars");
        verify(routeTester.<SampleController>getController()).save(any(Car.class));
    }
View Full Code Here

        verify(routeTester.<SampleController>getController()).save(any(Car.class));
    }

    @Test
    public void testQueryParameters() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/cars")
                        .on(RequestMethod.GET)
                        .produces(JSP)
                        .to(SampleController.class).find(param("color"), param("brand", "Ferrari"));
            }
        }).acceptHeader(HTML);
        routeTester.processGetRequest("/cars?color=red");
        verify(routeTester.<SampleController>getController()).find("red", "Ferrari");
    }
View Full Code Here

        verify(routeTester.<SampleController>getController()).find("red", "Ferrari");
    }

    @Test
    public void testPathAndQueryParameters() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/cars/{color}")
                        .on(RequestMethod.GET)
                        .produces(JSP)
                        .to(SampleController.class).find(param("color"), param("brand"));
            }
        }).acceptHeader(HTML).param("brand", "BMW");
        routeTester.processGetRequest("/cars/blue?brand=BMW");
        verify(routeTester.<SampleController>getController()).find("blue", "BMW");
    }
View Full Code Here

        verify(routeTester.<SampleController>getController()).find("blue", "BMW");
    }

    @Test
    public void testHeaderParameters() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/cars")
                        .on(RequestMethod.GET)
                        .produces(JSP)
                        .to(SampleController.class).find(param("color"), param("brand", "Ferrari"));
            }
        }).acceptHeader(HTML).header("color", "red");
        routeTester.processGetRequest("/cars");
        verify(routeTester.<SampleController>getController()).find("red", "Ferrari");
    }
View Full Code Here

TOP

Related Classes of org.jboss.aerogear.controller.mocks.RouteTester

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.