Search in sources :

Example 36 with Location

use of com.vaadin.flow.router.Location in project flow by vaadin.

the class LocationTest method parseLocationWithQueryString_emptyValue.

@Test
public void parseLocationWithQueryString_emptyValue() {
    Location location = new Location("path?query=");
    assertEquals("path", location.getPath());
    assertEquals(Collections.singletonMap("query", Collections.singletonList("")), location.getQueryParameters().getParameters());
    assertEquals("path?query=", location.getPathWithQueryParameters());
}
Also used : Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Example 37 with Location

use of com.vaadin.flow.router.Location in project flow by vaadin.

the class LocationTest method locationWithParamAndEmptyValue.

@Test
public void locationWithParamAndEmptyValue() {
    Location location = new Location("foo?param=&param=bar");
    Assert.assertEquals("param=&param=bar", location.getQueryParameters().getQueryString());
}
Also used : Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Example 38 with Location

use of com.vaadin.flow.router.Location in project flow by vaadin.

the class RouteLocationTest method walkRouteWithInvalidWildcard.

@Test(expected = IllegalArgumentException.class)
public void walkRouteWithInvalidWildcard() {
    RouteLocation location = new RouteLocation(new Location("foo/*/*"));
    RouteSegmentVisitor visitor = EasyMock.createMock(RouteSegmentVisitor.class);
    location.visitSegments(visitor);
}
Also used : RouteLocation(com.vaadin.flow.router.legacy.RouteLocation) RouteSegmentVisitor(com.vaadin.flow.router.legacy.RouteLocation.RouteSegmentVisitor) RouteLocation(com.vaadin.flow.router.legacy.RouteLocation) Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Example 39 with Location

use of com.vaadin.flow.router.Location in project flow by vaadin.

the class RouteLocationTest method testWalkRoute.

@Test
public void testWalkRoute() {
    RouteLocation location = new RouteLocation(new Location("foo/{bar}/*"));
    AtomicInteger calls = new AtomicInteger();
    location.visitSegments(new RouteSegmentVisitor() {

        @Override
        public void acceptSegment(String segmentName) {
            Assert.assertEquals("foo", segmentName);
            Assert.assertEquals(1, calls.incrementAndGet());
        }

        @Override
        public void acceptPlaceholder(String placeholderName) {
            Assert.assertEquals("bar", placeholderName);
            Assert.assertEquals(2, calls.incrementAndGet());
        }

        @Override
        public void acceptWildcard() {
            Assert.assertEquals(3, calls.incrementAndGet());
        }
    });
    Assert.assertEquals(3, calls.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RouteLocation(com.vaadin.flow.router.legacy.RouteLocation) RouteSegmentVisitor(com.vaadin.flow.router.legacy.RouteLocation.RouteSegmentVisitor) RouteLocation(com.vaadin.flow.router.legacy.RouteLocation) Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Example 40 with Location

use of com.vaadin.flow.router.Location in project flow by vaadin.

the class RouterConfigurationTest method testParentViewsWithParent.

@Test
public void testParentViewsWithParent() {
    UI ui = new UI();
    Router router = new Router();
    router.reconfigure(conf -> {
        conf.setRoute("route", TestView.class, ParentView.class);
        conf.setParentView(ParentView.class, AnotherParentView.class);
    });
    router.navigate(ui, new Location("route"), NavigationTrigger.PROGRAMMATIC);
    Assert.assertEquals(ParentView.class, router.getConfiguration().getParentView(TestView.class).get());
    Assert.assertEquals(AnotherParentView.class, router.getConfiguration().getParentView(ParentView.class).get());
    Assert.assertEquals(Arrays.asList(TestView.class, ParentView.class, AnotherParentView.class), getViewChainTypes(ui));
}
Also used : AnotherParentView(com.vaadin.flow.router.legacy.ViewRendererTest.AnotherParentView) ParentView(com.vaadin.flow.router.legacy.ViewRendererTest.ParentView) UI(com.vaadin.flow.component.UI) AnotherParentView(com.vaadin.flow.router.legacy.ViewRendererTest.AnotherParentView) TestView(com.vaadin.flow.router.legacy.ViewRendererTest.TestView) AnotherTestView(com.vaadin.flow.router.legacy.ViewRendererTest.AnotherTestView) Router(com.vaadin.flow.router.legacy.Router) Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Aggregations

Location (com.vaadin.flow.router.Location)51 Test (org.junit.Test)40 UI (com.vaadin.flow.component.UI)15 Router (com.vaadin.flow.router.legacy.Router)15 NavigationEvent (com.vaadin.flow.router.NavigationEvent)10 NavigationHandler (com.vaadin.flow.router.NavigationHandler)8 RouterConfiguration (com.vaadin.flow.router.legacy.RouterConfiguration)7 HistoryStateChangeEvent (com.vaadin.flow.component.page.History.HistoryStateChangeEvent)6 TestView (com.vaadin.flow.router.legacy.ViewRendererTest.TestView)6 NavigationTrigger (com.vaadin.flow.router.NavigationTrigger)5 QueryParameters (com.vaadin.flow.router.QueryParameters)5 DefaultErrorView (com.vaadin.flow.router.legacy.DefaultErrorView)5 VaadinRequest (com.vaadin.flow.server.VaadinRequest)5 VaadinResponse (com.vaadin.flow.server.VaadinResponse)5 Optional (java.util.Optional)4 CurrentInstance (com.vaadin.flow.internal.CurrentInstance)3 RouterInterface (com.vaadin.flow.router.RouterInterface)3 ImmutableRouterConfiguration (com.vaadin.flow.router.legacy.ImmutableRouterConfiguration)3 Resolver (com.vaadin.flow.router.legacy.Resolver)3 RouteSegmentVisitor (com.vaadin.flow.router.legacy.RouteLocation.RouteSegmentVisitor)3