use of com.vaadin.flow.server.MockVaadinContext in project flow by vaadin.
the class RouteUtilTest method newRouteAnnotatedClass_updateRouteRegistry_routeIsAddedToRegistry.
@Test
public void newRouteAnnotatedClass_updateRouteRegistry_routeIsAddedToRegistry() {
// given
@Route("a")
class A extends Component {
}
MockVaadinServletService service = new MockVaadinServletService() {
@Override
public VaadinContext getContext() {
return new MockVaadinContext();
}
};
ApplicationRouteRegistry registry = ApplicationRouteRegistry.getInstance(service.getContext());
// when
RouteUtil.updateRouteRegistry(registry, Collections.singleton(A.class), Collections.emptySet(), Collections.emptySet());
// then
Assert.assertTrue(registry.getConfiguration().hasRoute("a"));
}
use of com.vaadin.flow.server.MockVaadinContext in project flow by vaadin.
the class UITest method initUI.
private static void initUI(UI ui, String initialLocation, ArgumentCaptor<Integer> statusCodeCaptor) throws InvalidRouteConfigurationException {
VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
VaadinResponse response = Mockito.mock(VaadinResponse.class);
String pathInfo;
if (initialLocation.isEmpty()) {
pathInfo = null;
} else {
Assert.assertFalse(initialLocation.startsWith("/"));
pathInfo = "/" + initialLocation;
}
Mockito.when(request.getPathInfo()).thenReturn(pathInfo);
VaadinService service = new MockVaadinServletService() {
@Override
public VaadinContext getContext() {
return new MockVaadinContext();
}
};
service.setCurrentInstances(request, response);
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
DeploymentConfiguration config = Mockito.mock(DeploymentConfiguration.class);
Mockito.when(config.isProductionMode()).thenReturn(false);
session.lock();
session.setConfiguration(config);
ui.getInternals().setSession(session);
RouteConfiguration routeConfiguration = RouteConfiguration.forRegistry(ui.getInternals().getRouter().getRegistry());
routeConfiguration.update(() -> {
routeConfiguration.getHandledRegistry().clean();
Arrays.asList(RootNavigationTarget.class, FooBarNavigationTarget.class, Parameterized.class, FooBarParamNavigationTarget.class).forEach(routeConfiguration::setAnnotatedRoute);
});
ui.doInit(request, 0);
ui.getInternals().getRouter().initializeUI(ui, BootstrapHandlerTest.requestToLocation(request));
session.unlock();
if (statusCodeCaptor != null) {
Mockito.verify(response).setStatus(statusCodeCaptor.capture());
}
}
use of com.vaadin.flow.server.MockVaadinContext in project flow by vaadin.
the class InvalidUrlTest method initUI.
private static void initUI(UI ui, String initialLocation, ArgumentCaptor<Integer> statusCodeCaptor) throws InvalidRouteConfigurationException, ServiceException {
VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
VaadinResponse response = Mockito.mock(VaadinResponse.class);
String pathInfo;
if (initialLocation.isEmpty()) {
pathInfo = null;
} else {
Assert.assertFalse(initialLocation.startsWith("/"));
pathInfo = "/" + initialLocation;
}
Mockito.when(request.getPathInfo()).thenReturn(pathInfo);
VaadinService service = new MockVaadinServletService() {
@Override
public VaadinContext getContext() {
return new MockVaadinContext();
}
};
service.setCurrentInstances(request, response);
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
DeploymentConfiguration config = Mockito.mock(DeploymentConfiguration.class);
Mockito.when(config.isProductionMode()).thenReturn(false);
session.lock();
session.setConfiguration(config);
ui.getInternals().setSession(session);
RouteConfiguration routeConfiguration = RouteConfiguration.forRegistry(ui.getRouter().getRegistry());
routeConfiguration.update(() -> {
routeConfiguration.getHandledRegistry().clean();
Arrays.asList(UITest.RootNavigationTarget.class, UITest.FooBarNavigationTarget.class).forEach(routeConfiguration::setAnnotatedRoute);
});
ui.doInit(request, 0);
ui.getRouter().initializeUI(ui, BootstrapHandlerTest.requestToLocation(request));
session.unlock();
if (statusCodeCaptor != null) {
Mockito.verify(response).setStatus(statusCodeCaptor.capture());
}
}
use of com.vaadin.flow.server.MockVaadinContext in project flow by vaadin.
the class ErrorStateRendererTest method configureMocks.
private UI configureMocks() {
MockVaadinServletService service = new MockVaadinServletService() {
@Override
public VaadinContext getContext() {
return new MockVaadinContext();
}
};
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
session.setConfiguration(new MockDeploymentConfiguration());
MockUI ui = new MockUI(session);
return ui;
}
use of com.vaadin.flow.server.MockVaadinContext in project flow by vaadin.
the class RouteUtilTest method renamedRouteAnnotatedClass_updateRouteRegistry_routeIsUpdatedInRegistry.
@Test
public void renamedRouteAnnotatedClass_updateRouteRegistry_routeIsUpdatedInRegistry() {
// given
@Route("aa")
class A extends Component {
}
MockVaadinServletService service = new MockVaadinServletService() {
@Override
public VaadinContext getContext() {
return new MockVaadinContext();
}
};
ApplicationRouteRegistry registry = ApplicationRouteRegistry.getInstance(service.getContext());
registry.setRoute("a", A.class, Collections.emptyList());
Assert.assertTrue(registry.getConfiguration().hasRoute("a"));
// when
RouteUtil.updateRouteRegistry(registry, Collections.emptySet(), Collections.singleton(A.class), Collections.emptySet());
// then
Assert.assertFalse(registry.getConfiguration().hasRoute("a"));
Assert.assertTrue(registry.getConfiguration().hasRoute("aa"));
}
Aggregations