use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class VaadinUIScopeTest method mockUI.
private UI mockUI() {
VaadinSession session = mockSession();
RouterInterface routerIface = mock(RouterInterface.class);
VaadinService service = session.getService();
when(service.getRouter()).thenReturn(routerIface);
ImmutableRouterConfiguration config = mock(ImmutableRouterConfiguration.class);
when(routerIface.getConfiguration()).thenReturn(config);
when(config.isConfigured()).thenReturn(false);
UI ui = new UI();
ui.getInternals().setSession(session);
ui.doInit(null, 1);
UI.setCurrent(ui);
// prevent UI from being GCed.
this.ui = ui;
return ui;
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class VaadinServiceTest method createService.
private static VaadinService createService() {
ServletConfig servletConfig = new MockServletConfig();
VaadinServlet servlet = new VaadinServlet();
try {
servlet.init(servletConfig);
} catch (ServletException e) {
throw new RuntimeException(e);
}
VaadinService service = servlet.getService();
return service;
}
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) {
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 UIInternals method setSession.
/**
* Sets the session to which the related UI is assigned.
* <p>
* This method is for internal use by the framework. To explicitly close a
* UI, see {@link UI#close()}.
*
* @param session
* the session to set
*
* @throws IllegalStateException
* if the session has already been set
*
* @see #getSession()
*/
public void setSession(VaadinSession session) {
if (session == null && this.session == null) {
throw new IllegalStateException("Session should never be set to null when UI.session is already null");
} else if (session != null && this.session != null) {
throw new IllegalStateException("Session has already been set. Old session: " + getSessionDetails(this.session) + ". New session: " + getSessionDetails(session) + ".");
} else {
if (session == null) {
try {
ComponentUtil.onComponentDetach(ui);
} catch (Exception e) {
getLogger().warn("Error while detaching UI from session", e);
}
// Disable push when the UI is detached. Otherwise the
// push connection and possibly VaadinSession will live on.
ui.getPushConfiguration().setPushMode(PushMode.DISABLED);
setPushConnection(null);
}
this.session = session;
}
if (session != null) {
VaadinService service = getSession().getService();
if (service != null) {
// Allow null service to simplify testing mocks
RouterInterface serviceRouter = service.getRouter();
if (serviceRouter != null && serviceRouter.getConfiguration().isConfigured()) {
router = serviceRouter;
}
}
ComponentUtil.onComponentAttach(ui, true);
}
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class PolymerTemplateTest method createService.
@Override
public VaadinService createService() {
configuration = Mockito.mock(DeploymentConfiguration.class);
Mockito.when(configuration.isProductionMode()).thenReturn(false);
VaadinService service = Mockito.mock(VaadinService.class);
Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
Instantiator instantiator = Mockito.mock(Instantiator.class);
TemplateParser.TemplateParserFactory factory = Mockito.mock(TemplateParser.TemplateParserFactory.class);
Mockito.when(instantiator.getOrCreate(TemplateParserFactory.class)).thenReturn(factory);
Mockito.when(factory.createParser()).thenReturn(NpmTemplateParser.getInstance());
Mockito.when(service.getInstantiator()).thenReturn(instantiator);
return service;
}
Aggregations