Package org.jboss.aerogear.controller.router

Examples of org.jboss.aerogear.controller.router.Routes


public class RoutesTest {

    @Test
    public void routesWithParameters() {
        Routes routes = new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route().from("/cars").on(POST).to(SampleController.class).save(param(Car.class));
            }
        }.build();
        assertThat(routes.hasRouteFor(POST, "/cars", acceptHeaders(MediaType.HTML.getType()))).isTrue();
    }
View Full Code Here


        assertThat(routes.hasRouteFor(POST, "/cars", acceptHeaders(MediaType.HTML.getType()))).isTrue();
    }

    @Test
    public void routesWithRoles() {
        Routes routes = new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route().from("/admin").roles("manager").on(GET).to(SampleController.class).admin();
            }
        }.build();
        assertThat(routes.hasRouteFor(GET, "/admin", acceptHeaders(MediaType.HTML.getType()))).isTrue();
    }
View Full Code Here

        assertThat(routes.hasRouteFor(GET, "/admin", acceptHeaders(MediaType.HTML.getType()))).isTrue();
    }

    @Test
    public void routesWithPathParameters() {
        Routes routes = new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route().from("/car/{id}").on(GET).to(SampleController.class).find(param("id"));
            }
        }.build();
        assertThat(routes.hasRouteFor(GET, "/car/1", acceptHeaders(MediaType.HTML.getType()))).isTrue();
    }
View Full Code Here

        assertThat(routes.hasRouteFor(GET, "/car/1", acceptHeaders(MediaType.HTML.getType()))).isTrue();
    }

    @Test
    public void routesWithTypedPathParameters() {
        Routes routes = new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route().from("/car/{id}").on(GET).to(SampleController.class).find(param("id",Long.class));
            }
        }.build();
        assertThat(routes.hasRouteFor(GET, "/car/1", acceptHeaders(MediaType.HTML.getType()))).isTrue();
    }
View Full Code Here

    }

    @Test
    public void restfulRoute() {
        final MediaType custom = new MediaType("application/custom", CustomResponder.class);
        Routes routes = new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route().from("/car/{id}").on(GET).produces(MediaType.JSON, custom).to(SampleController.class).find(param("id"));
            }
        }.build();
        final Route route = routes.routeFor(GET, "/car/1", acceptHeaders(MediaType.JSON.getType(), "application/custom"));
        assertThat(route.produces()).contains(MediaType.JSON, custom);
    }
View Full Code Here

        assertThat(route.produces()).contains(MediaType.JSON, custom);
    }

    @Test
    public void restfulRouteWithMultipleMediaTypes() {
        Routes routes = new AbstractRoutingModule() {
            @Override
            public void configuration() {
                route().from("/car/{id}").on(GET).produces(MediaType.JSON).to(SampleController.class).find(param("id"));
            }
        }.build();
        final Set<String> acceptHeaders = new HashSet<String>(Arrays.asList(MediaType.JSON.getType()));
        assertThat(routes.hasRouteFor(GET, "/car/1", acceptHeaders)).isTrue();
    }
View Full Code Here

        assertThat(routes.hasRouteFor(GET, "/car/1", acceptHeaders)).isTrue();
    }

    @Test
    public void routesWithDefaultExceptionRoute() {
        Routes routes = new AbstractRoutingModule() {
            @Override
            public void configuration() throws Exception {
                route().from("/home").on(GET).to(SampleController.class).index();
            }
        }.build();
        Route route = routes.routeFor(new IllegalStateException());
        assertThat(route).isNotNull();
        assertThat(route.canHandle(new IllegalStateException())).isTrue();
        assertThat(route.canHandle(new Throwable())).isTrue();
        assertThat(route.getTargetClass()).isEqualTo(ErrorTarget.class);
    }
View Full Code Here

        assertThat(route.getTargetClass()).isEqualTo(ErrorTarget.class);
    }

    @Test
    public void exceptionRoutesOrder() {
        Routes routes = new AbstractRoutingModule() {
            @Override
            public void configuration() throws Exception {
                route().on(SubException.class).to(SampleController.class).subException();
                route().on(SuperException.class).to(SampleController.class).superException();
                route().on(Exception.class).to(SampleController.class).error(param(Exception.class));
                route().from("/home").on(GET).to(SampleController.class).index();
            }
        }.build();
        final Route superErrorRoute = routes.routeFor(new SuperException());
        assertThat(superErrorRoute.canHandle(new SuperException())).isTrue();
        assertThat(superErrorRoute.canHandle(new SubException())).isTrue();
        assertThat(superErrorRoute.getTargetMethod().getName()).isEqualTo("superException");

        final Route subErrorRoute = routes.routeFor(new SubException());
        assertThat(subErrorRoute.canHandle(new SubException())).isTrue();
        assertThat(subErrorRoute.canHandle(new SuperException())).isFalse();
        assertThat(subErrorRoute.getTargetMethod().getName()).isEqualTo("subException");

        final Route genErrorRoute = routes.routeFor(new Exception());
        assertThat(genErrorRoute.canHandle(new SuperException())).isTrue();
        assertThat(genErrorRoute.canHandle(new SubException())).isTrue();
        assertThat(genErrorRoute.getTargetMethod().getName()).isEqualTo("error");
    }
View Full Code Here

TOP

Related Classes of org.jboss.aerogear.controller.router.Routes

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.