use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class InternalServerError method reportException.
private void reportException(Exception exception, String path, String exceptionText, boolean isRootCauseAvailable) {
if (isRootCauseAvailable) {
getElement().appendChild(ElementFactory.createHeading3(exceptionText));
} else {
getElement().appendChild(Element.createText(exceptionText));
}
VaadinService vaadinService = VaadinService.getCurrent();
// Check that we have a vaadinService as else we will fail on a NPE and
// the stacktrace we actually got will disappear and getting a NPE is
// confusing.
boolean productionMode = vaadinService != null && vaadinService.getDeploymentConfiguration().isProductionMode();
if (!productionMode) {
checkLogBinding();
printStacktrace(exception);
}
getLogger().error("There was an exception while trying to navigate to '{}'", path, exception);
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class JavaScriptBootstrapUITest method navigate_firsClientSideRoutingThrows_navigationInProgressIsReset_secondClientSideRoutingWorks.
@Test
public void navigate_firsClientSideRoutingThrows_navigationInProgressIsReset_secondClientSideRoutingWorks() {
VaadinSession session = Mockito.mock(VaadinSession.class);
VaadinService service = Mockito.mock(VaadinService.class);
Mockito.when(session.getService()).thenReturn(service);
Router router = Mockito.mock(Router.class);
Mockito.when(service.getRouter()).thenReturn(router);
Mockito.doThrow(RuntimeException.class).when(router).resolveNavigationTarget(Mockito.any());
JavaScriptBootstrapUI ui = new JavaScriptBootstrapUI();
ui.getInternals().setSession(session);
try {
ui.navigate("foo", QueryParameters.empty());
} catch (RuntimeException expected) {
router = Mockito.mock(Router.class);
Mockito.when(service.getRouter()).thenReturn(router);
Mockito.when(router.resolveNavigationTarget(Mockito.any())).thenReturn(Optional.empty());
ui.navigate("foo", QueryParameters.empty());
Mockito.verify(router).resolveNavigationTarget(Mockito.any());
return;
}
// self control: code inside catch should be invoked
Assert.fail();
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class WebComponentBootstrapHandlerTest method mockRequest.
private VaadinRequest mockRequest(boolean hasConfig) {
VaadinContext context = Mockito.mock(VaadinContext.class);
VaadinService service = Mockito.mock(VaadinService.class);
VaadinRequest request = Mockito.mock(VaadinRequest.class);
Mockito.when(request.getService()).thenReturn(service);
Mockito.when(service.getContext()).thenReturn(context);
WebComponentConfigurationRegistry registry = Mockito.mock(WebComponentConfigurationRegistry.class);
Mockito.when(context.getAttribute(Mockito.eq(WebComponentConfigurationRegistry.class), Mockito.any())).thenReturn(registry);
Mockito.when(registry.hasConfigurations()).thenReturn(hasConfig);
Mockito.when(request.getPathInfo()).thenReturn("/web-component/web-component-ui.js");
return request;
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class UidlRequestHandlerTest method writeSessionExpired_whenUINotFound.
@Test
public void writeSessionExpired_whenUINotFound() throws IOException {
VaadinService service = mock(VaadinService.class);
VaadinSession session = mock(VaadinSession.class);
when(session.getService()).thenReturn(service);
when(service.findUI(request)).thenReturn(null);
boolean result = handler.synchronizedHandleRequest(session, request, response);
Assert.assertTrue("Result should be true", result);
String responseContent = CommunicationUtil.getStringWhenWriteString(outputStream);
// response shouldn't contain async
Assert.assertEquals("Invalid response", "for(;;);[{\"meta\":{\"sessionExpired\":true}}]", responseContent);
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class UidlRequestHandlerTest method writeSessionExpired.
@Test
public void writeSessionExpired() throws Exception {
ApplicationConfiguration config = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(config.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
Mockito.when(config.getBuildFolder()).thenReturn(".");
VaadinContext context = new MockVaadinContext();
Mockito.when(config.getContext()).thenReturn(context);
VaadinService service = new VaadinServletService(null, new DefaultDeploymentConfiguration(config, getClass(), new Properties()));
when(request.getService()).thenReturn(service);
when(request.getParameter(ApplicationConstants.REQUEST_TYPE_PARAMETER)).thenReturn(RequestType.UIDL.getIdentifier());
boolean result = handler.handleSessionExpired(request, response);
Assert.assertTrue("Result should be true", result);
String responseContent = CommunicationUtil.getStringWhenWriteBytesOffsetLength(outputStream);
// response shouldn't contain async
Assert.assertEquals("Invalid response", "for(;;);[{\"meta\":{\"sessionExpired\":true}}]", responseContent);
}
Aggregations