Package org.jboss.aerogear.controller.mocks

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


public class ErrorHandlerTest {

    @Test
    public void testOnException() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() throws Exception {
                route()
                        .on(IllegalStateException.class)
                        .produces(JSP)
                        .to(SampleController.class).errorPage();
                route()
                        .from("/home")
                        .on(RequestMethod.GET, RequestMethod.POST)
                        .to(SampleController.class).throwIllegalStateException();
            }
        }).acceptHeader(JSP).spyController(new SampleController());
        routeTester.processGetRequest("/home");
        verify(routeTester.<SampleController>getController()).errorPage();
        verify(routeTester.jspResponder()).respond(anyObject(), any(RouteContext.class));
    }
View Full Code Here


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

    @Test
    public void testOnExceptions() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() throws Exception {
                route()
                        .on(SampleControllerException.class, IllegalStateException.class)
                        .produces(JSP)
                        .to(SampleController.class).error(param(Exception.class));
                route().from("/home").on(RequestMethod.GET, RequestMethod.POST).to(SampleController.class)
                        .throwSampleControllerException();
            }
        }).acceptHeader(MediaType.JSP).spyController(new SampleController());
        routeTester.processGetRequest("/home");
        verify(routeTester.<SampleController>getController()).error(any(IllegalArgumentException.class));
        verify(routeTester.jspResponder()).respond(anyObject(), any(RouteContext.class));
        verify(routeTester.jsonResponder(), never()).respond(anyObject(), any(RouteContext.class));
    }
View Full Code Here

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

    @Test
    public void testDefaultErrorRoute() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() throws Exception {
                route()
                        .from("/home").on(RequestMethod.GET, RequestMethod.POST)
                        .to(SampleController.class).throwSampleControllerException();
            }
        }).acceptHeader(JSP).spyController(new SampleController());
        routeTester.processGetRequest("/home");
        verify(routeTester.getErrorTarget()).error(any(SampleControllerException.class));
        verify(routeTester.errorViewResponder()).respond(anyObject(), any(RouteContext.class));
        assertThat(routeTester.errorViewResponder().getViewResolver()).isInstanceOf(ErrorViewResolver.class);
    }
View Full Code Here

        assertThat(routeTester.errorViewResponder().getViewResolver()).isInstanceOf(ErrorViewResolver.class);
    }

    @Test
    public void testJsonResponseOnException() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() throws Exception {
                route()
                        .on(IllegalStateException.class)
                        .produces(JSON)
                        .to(SampleController.class).errorResponse();
                route()
                        .from("/home")
                        .on(RequestMethod.GET, RequestMethod.POST)
                        .produces(JSON)
                        .to(SampleController.class).throwIllegalStateException();
            }
        }).acceptHeader(JSON).spyController(new SampleController());
        final InvocationResult processResult = routeTester.processGetRequest("/home");
        verify(routeTester.<SampleController>getController()).errorResponse();
        verify(routeTester.jsonResponder()).respond(anyObject(), any(RouteContext.class));
        verify(processResult.getRouteContext().getResponse()).setStatus(HttpServletResponse.SC_NOT_FOUND);
        assertThat(routeTester.getStringWriter().toString()).isEqualTo("[]");
    }
View Full Code Here

        assertThat(routeTester.getStringWriter().toString()).isEqualTo("[]");
    }
   
    @Test
    public void testDefaultErrorRouteJsonRequested() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() throws Exception {
                route()
                        .from("/home")
                        .on(RequestMethod.GET)
                        .produces(JSON)
                        .to(SampleController.class).throwIllegalStateException();
            }
        }).acceptHeader(JSON).spyController(new SampleController());
        routeTester.processGetRequest("/home");
        verify(routeTester.getErrorTarget()).error(any(SampleControllerException.class));
        verify(routeTester.errorViewResponder()).respond(anyObject(), any(RouteContext.class));
    }
View Full Code Here

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

    @Test
    public void testCookieAndPathParameters() 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).cookie("brand", "Ferrari");
        routeTester.processGetRequest("/cars/red");
        verify(routeTester.<SampleController>getController()).find("red", "Ferrari");
    }
View Full Code Here

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

    @Test
    public void testQueryAndCookieParameters() 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"));
            }
        }).acceptHeader(HTML).cookie("brand", "Ferrari");
        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 testQueryAndHeaderParameters() 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"));
            }
        }).acceptHeader(HTML).header("brand", "Ferrari");
        routeTester.processGetRequest("/cars?color=red");
        verify(routeTester.<SampleController>getController()).find("red", "Ferrari");
    }
View Full Code Here

        verify(routeTester.<SampleController>getController()).find("red", "Ferrari");
    }
   
    @Test (expected = RuntimeException.class)
    public void testNoRespondersForMediaType() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/car/{id}")
                        .on(GET)
                        .produces(new MediaType("custom/type", CustomResponder.class))
                        .to(SampleController.class).find(param("id"));
            }
        }).acceptHeader("custom/type");
        routeTester.processGetRequest("/car/3");
    }
View Full Code Here

        routeTester.processGetRequest("/car/3");
    }

    @Test
    public void testDefaultResponder() 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"));
            }
        }).acceptHeader(JSP).header("brand", "Lada");
        routeTester.processPostRequest("/cars?color=gray");
        verify(routeTester.<SampleController>getController()).save("gray", "Lada");
        verify(routeTester.jspResponder()).respond(anyObject(), any(RouteContext.class));
    }
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.