use of com.vaadin.flow.router.legacy.Resolver in project flow by vaadin.
the class RouterTest method testReconfigureThreadSafety.
@Test
public void testReconfigureThreadSafety() throws InterruptedException {
Router router = new Router();
Resolver newResolver = e -> null;
CountDownLatch configUpdated = new CountDownLatch(1);
CountDownLatch configVerified = new CountDownLatch(1);
Thread updaterThread = new Thread() {
@Override
public void run() {
router.reconfigure(config -> {
config.setResolver(newResolver);
// Signal that config has been updated
configUpdated.countDown();
// configuration is not yet in effect
try {
configVerified.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
}
};
updaterThread.start();
// Wait until updater thread has updated the config
configUpdated.await();
Assert.assertNotSame("Update should not yet be visible", newResolver, router.getConfiguration().getResolver());
// Allow the update thread to exit the configure method
configVerified.countDown();
// Wait for updater thread to finish
updaterThread.join();
Assert.assertSame("Update should now be visible", newResolver, router.getConfiguration().getResolver());
}
use of com.vaadin.flow.router.legacy.Resolver in project flow by vaadin.
the class RouterTest method testLeakedConfigurationImmutable.
@Test
public void testLeakedConfigurationImmutable() {
Router router = new Router();
AtomicReference<RouterConfiguration> configurationLeak = new AtomicReference<>();
router.reconfigure(configurationLeak::set);
Resolver newResolver = e -> null;
configurationLeak.get().setResolver(newResolver);
Assert.assertNotSame(newResolver, router.getConfiguration().getResolver());
}
use of com.vaadin.flow.router.legacy.Resolver in project flow by vaadin.
the class RouterTest method testResolverBeforeSetRoute.
@Test
public void testResolverBeforeSetRoute() {
Router router = new Router();
AtomicReference<String> usedHandler = new AtomicReference<>();
router.reconfigure(configuration -> {
configuration.setResolver(resolveEvent -> Optional.of(handlerEvent -> {
usedHandler.set("resolver");
return HttpServletResponse.SC_OK;
}));
configuration.setRoute("*", e -> {
usedHandler.set("route");
return HttpServletResponse.SC_OK;
});
});
router.navigate(new RouterTestUI(), new Location(""), NavigationTrigger.PROGRAMMATIC);
Assert.assertEquals("resolver", usedHandler.get());
}
Aggregations