Package org.jboss.aerogear.controller.mocks

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


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

    @Test
    public void testAnyResponder() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/cars/{id}").roles("admin")
                        .on(RequestMethod.GET)
                        .produces(JSP, JSON)
                        .to(SampleController.class).find(param("id"));
            }
        }).requestMethod(GET).acceptHeader(ANY);
        routeTester.process("/cars/10");
        verify(routeTester.<SampleController>getController()).find("10");
        verify(routeTester.jspResponder()).respond(anyObject(), any(RouteContext.class));
    }
View Full Code Here


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

    @Test
    public void testAnyResponderEmptyAcceptHeader() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/cars/{id}")
                        .on(RequestMethod.GET)
                        .produces(JSP)
                        .to(SampleController.class).find(param("id"));
            }
        }).requestMethod(GET);
        routeTester.process("/cars/10");
        verify(routeTester.<SampleController>getController()).find("10");
        verify(routeTester.jspResponder()).respond(anyObject(), any(RouteContext.class));
    }
View Full Code Here

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

    @Test
    public void testConsumes() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/cars").roles("admin")
                        .on(POST)
                        .consumes(JSON)
                        .produces(MediaType.JSON)
                        .to(SampleController.class).save(param(Car.class));
            }
        }).requestMethod(POST).acceptHeader(JSON).body("{\"color\":\"red\", \"brand\":\"mini\"}");
        routeTester.process("/cars");
        verify(routeTester.<SampleController>getController()).save(any(Car.class));
    }
View Full Code Here

        verify(routeTester.<SampleController>getController()).save(any(Car.class));
    }
   
    @Test
    public void testConsumesWithInvalidContentType() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/cars").roles("admin")
                        .on(POST)
                        .consumes(JSON)
                        .produces(MediaType.JSON)
                        .to(SampleController.class).save(param(Car.class));
            }
        }).requestMethod(POST).acceptHeader(JSON).body("{\"color\":\"red\", \"brand\":\"mini\"}");
        final InvocationResult invocationResult = routeTester.contentType("invalid/type").processPostRequest("/cars");
        assertThat(invocationResult.getResult()).isInstanceOf(RuntimeException.class);
    }
View Full Code Here

        assertThat(invocationResult.getResult()).isInstanceOf(RuntimeException.class);
    }

    @Test
    public void testOrderMultipleAcceptHeaders() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/cars/{id}").roles("admin")
                        .on(GET)
                        .produces(JSP, JSON)
                        .to(SampleController.class).find(param("id"));
            }
        }).requestMethod(GET).acceptHeader("application/json, text/html");
        routeTester.process("/cars/10");
        verify(routeTester.<SampleController>getController()).find("10");
        verify(routeTester.jsonResponder()).respond(anyObject(), any(RouteContext.class));
    }
View Full Code Here

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

    @Test(expected = RuntimeException.class)
    public void testNoConsumers() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/cars").roles("admin")
                        .on(POST)
                        .consumes(JSON)
                        .produces(JSON)
                        .to(SampleController.class).save(param(Car.class));
            }
        }).requestMethod(POST).acceptHeader("application/bogus").body("{\"color\":\"red\", \"brand\":\"mini\"}");
        routeTester.process("/cars");
    }
View Full Code Here

        routeTester.process("/cars");
    }

    @Test
    public void testPagedEndpointWithWebLinking() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/ints")
                        .on(GET)
                        .produces(JSON)
                        .to(SampleController.class).findByWithDefaults(param(PaginationInfo.class), param("color"));
            }
        }).spyController(new SampleController()).addResponder(new JsonResponder());
        final InvocationResult result = routeTester.acceptHeader(JSON).processGetRequest("/ints?color=blue");
        verify(result.getRouteContext().getResponse()).setHeader(eq("Link"), anyString());
        verify(routeTester.<SampleController>getController()).findByWithDefaults(any(PaginationInfo.class), eq("blue"));
        assertThat(routeTester.getStringWriter().toString()).isEqualTo("[0,1,2,3,4,5,6,7,8,9]");
    }
View Full Code Here

        assertThat(routeTester.getStringWriter().toString()).isEqualTo("[0,1,2,3,4,5,6,7,8,9]");
    }

    @Test
    public void testPagedEndpointWithCustomHeadersDefaultPrefix() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/ints")
                        .on(RequestMethod.GET)
                        .produces(JSON)
                        .to(SampleController.class).findByWithCustomHeadersDefaultPrefix(param(PaginationInfo.class), param("color"));
            }
        }).spyController(new SampleController()).addResponder(new JsonResponder());
        final InvocationResult result = routeTester.acceptHeader(JSON).processGetRequest("/ints?color=blue");
        final HttpServletResponse response = result.getRouteContext().getResponse();
        verify(routeTester.<SampleController>getController()).findByWithCustomHeadersDefaultPrefix(any(PaginationInfo.class), eq("blue"));
        verify(response).setHeader("AG-Links-Next", "http://localhost:8080/test/ints?color=blue&offset=10&limit=10");
        verify(response, never()).setHeader(eq("AG-Links-Previous"), anyString());
        assertThat(routeTester.getStringWriter().toString()).isEqualTo("[0,1,2,3,4,5,6,7,8,9]");
    }
View Full Code Here

        assertThat(routeTester.getStringWriter().toString()).isEqualTo("[0,1,2,3,4,5,6,7,8,9]");
    }

    @Test
    public void testPagedEndpointCustomHeadersPrefix() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/ints")
                        .on(RequestMethod.GET)
                        .produces(JSON)
                        .to(SampleController.class).findByWithCustomHeadersPrefix(param(PaginationInfo.class), param("color"));
            }
        }).addResponder(new JsonResponder()).spyController(new SampleController())
        .param("color", "blue").param("offset", "0").param("limit", "5");
        final InvocationResult result = routeTester.acceptHeader(JSON).processGetRequest("/ints");
        final HttpServletResponse response = result.getRouteContext().getResponse();
        verify(routeTester.<SampleController>getController()).findByWithCustomHeadersPrefix(any(PaginationInfo.class), eq("blue"));
        verify(response).setHeader("Test-Links-Next", "http://localhost:8080/test/ints?color=blue&offset=5&limit=5");
        verify(response, never()).setHeader(eq("Test-Links-Previous"), anyString());
        assertThat(routeTester.getStringWriter().toString()).isEqualTo("[0,1,2,3,4]");
    }
View Full Code Here

        assertThat(routeTester.getStringWriter().toString()).isEqualTo("[0,1,2,3,4]");
    }

    @Test
    public void testPagedEndpointMiddlePage() throws Exception {
        final RouteTester routeTester = RouteTester.from(new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route()
                        .from("/ints")
                        .on(RequestMethod.GET)
                        .produces(JSON)
                        .to(SampleController.class).findByWithCustomHeadersPrefix(param(PaginationInfo.class), param("color"));
            }
        }).addResponder(new JsonResponder()).spyController(new SampleController())
        .param("color", "blue").param("offset", "5").param("limit", "5");
        final InvocationResult result = routeTester.acceptHeader(JSON).processGetRequest("/ints");
        final HttpServletResponse response = result.getRouteContext().getResponse();
        verify(routeTester.<SampleController>getController()).findByWithCustomHeadersPrefix(any(PaginationInfo.class), eq("blue"));
        verify(response).setHeader("Test-Links-Previous", "http://localhost:8080/test/ints?color=blue&offset=0&limit=5");
        verify(response).setHeader("Test-Links-Next", "http://localhost:8080/test/ints?color=blue&offset=10&limit=5");
        assertThat(routeTester.getStringWriter().toString()).isEqualTo("[5,6,7,8,9]");
    }
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.