use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class DefaultBindingExceptionHandlerTest method mockUI.
private UI mockUI(boolean productionMode) {
UI ui = new UI();
VaadinService service = Mockito.mock(VaadinService.class);
VaadinSession session = Mockito.mock(VaadinSession.class);
ui.getInternals().setSession(session);
Mockito.when(session.getService()).thenReturn(service);
VaadinContext context = Mockito.mock(VaadinContext.class);
Mockito.when(service.getContext()).thenReturn(context);
ApplicationConfiguration configuration = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(context.getAttribute(Mockito.eq(ApplicationConfiguration.class), Mockito.any())).thenReturn(configuration);
Mockito.when(configuration.isProductionMode()).thenReturn(productionMode);
return ui;
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class AbstractDnDUnitTest method setup.
@Before
public void setup() {
ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
Mockito.when(appConfig.getBuildFolder()).thenReturn(".");
VaadinContext context = Mockito.mock(VaadinContext.class);
Mockito.when(appConfig.getContext()).thenReturn(context);
Lookup lookup = Mockito.mock(Lookup.class);
Mockito.when(context.getAttribute(Lookup.class)).thenReturn(lookup);
DefaultDeploymentConfiguration configuration = new DefaultDeploymentConfiguration(appConfig, VaadinServlet.class, new Properties());
VaadinService service = Mockito.mock(VaadinService.class);
Mockito.when(service.resolveResource(Mockito.anyString())).thenReturn("");
VaadinSession session = Mockito.mock(VaadinSession.class);
Mockito.when(session.getConfiguration()).thenReturn(configuration);
Mockito.when(session.getService()).thenReturn(service);
ui = new MockUI(session);
}
use of com.vaadin.flow.server.VaadinService 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.VaadinService in project flow by vaadin.
the class LookupInitializerTest method initialize_noStaticFileHandlerFactory_defaultStaticFileHandlerFactoryCreated.
@Test
public void initialize_noStaticFileHandlerFactory_defaultStaticFileHandlerFactoryCreated() throws ServletException {
AtomicReference<Lookup> capture = new AtomicReference<>();
initializer.initialize(null, new HashMap<>(), capture::set);
Lookup lookup = capture.get();
StaticFileHandlerFactory factory = lookup.lookup(StaticFileHandlerFactory.class);
VaadinService service = Mockito.mock(VaadinService.class);
DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
ClassLoader loader = Mockito.mock(ClassLoader.class);
Mockito.when(service.getClassLoader()).thenReturn(loader);
StaticFileHandler handler = factory.createHandler(service);
Assert.assertNotNull(handler);
Assert.assertEquals(StaticFileServer.class, handler.getClass());
}
use of com.vaadin.flow.server.VaadinService 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());
}
}
Aggregations