use of com.vaadin.flow.server.startup.ApplicationConfiguration 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.startup.ApplicationConfiguration in project flow by vaadin.
the class VaadinSession method writeObject.
private void writeObject(java.io.ObjectOutputStream stream) throws IOException {
boolean serializeUIs = true;
// the same way again
if (getService() != null) {
ApplicationConfiguration appConfiguration = ApplicationConfiguration.get(getService().getContext());
if (!appConfiguration.isProductionMode() && !appConfiguration.isDevModeSessionSerializationEnabled()) {
serializeUIs = false;
}
}
stream.defaultWriteObject();
if (serializeUIs) {
stream.writeObject(uIs);
} else {
stream.writeObject(new HashMap<>());
}
}
use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class IndexHtmlRequestHandlerTest method should_attachWebpackErrors.
@Test
public void should_attachWebpackErrors() throws Exception {
deploymentConfiguration.setEnableDevServer(true);
deploymentConfiguration.setProductionMode(false);
DevModeHandler devServer = Mockito.mock(DevModeHandler.class);
Mockito.when(devServer.getFailedOutput()).thenReturn("Failed to compile");
Mockito.when(devServer.prepareConnection(Mockito.anyString(), Mockito.anyString())).thenReturn(Mockito.mock(HttpURLConnection.class));
service.setContext(context);
DevModeHandlerManager devModeHandlerManager = new DevModeHandlerManager() {
@Override
public Class<?>[] getHandlesTypes() {
return new Class[0];
}
@Override
public void initDevModeHandler(Set<Class<?>> classes, VaadinContext context) throws VaadinInitializerException {
}
@Override
public void setDevModeHandler(DevModeHandler devModeHandler) {
}
@Override
public DevModeHandler getDevModeHandler() {
return devServer;
}
};
ResourceProvider resourceProvider = Mockito.mock(ResourceProvider.class);
Lookup lookup = Lookup.compose(Lookup.of(devModeHandlerManager, DevModeHandlerManager.class), Lookup.of(resourceProvider, ResourceProvider.class));
Mockito.when(context.getAttribute(Lookup.class)).thenReturn(lookup);
ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
mockApplicationConfiguration(appConfig);
URL resource = Mockito.mock(URL.class);
Mockito.when(resourceProvider.getApplicationResource(VAADIN_WEBAPP_RESOURCES + INDEX_HTML)).thenReturn(resource);
when(resource.openStream()).thenReturn(new ByteArrayInputStream("<html><head></head></html>".getBytes()));
// Send the request
indexHtmlRequestHandler.synchronizedHandleRequest(session, createVaadinRequest("/"), response);
String indexHtml = responseOutput.toString(StandardCharsets.UTF_8.name());
Assert.assertTrue("Should have a system error dialog", indexHtml.contains("<div class=\"v-system-error\">"));
Assert.assertTrue("Should show webpack failure error", indexHtml.contains("Failed to compile"));
}
use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class PushHandlerTest method onConnect_devMode_websocket_refreshConnection_onConnectIsCalled_callWithUIIsNotCalled.
@Test
public void onConnect_devMode_websocket_refreshConnection_onConnectIsCalled_callWithUIIsNotCalled() throws ServiceException {
MockVaadinServletService service = Mockito.spy(MockVaadinServletService.class);
MockDeploymentConfiguration deploymentConfiguration = (MockDeploymentConfiguration) service.getDeploymentConfiguration();
deploymentConfiguration.setProductionMode(false);
deploymentConfiguration.setDevModeLiveReloadEnabled(true);
deploymentConfiguration.setDevModeGizmoEnabled(true);
ApplicationConfiguration applicationConfiguration = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(applicationConfiguration.isProductionMode()).thenReturn(false);
VaadinContext context = service.getContext();
context.setAttribute(ApplicationConfiguration.class, applicationConfiguration);
BrowserLiveReload liveReload = mockBrowserLiveReloadImpl(context);
AtomicReference<AtmosphereResource> res = new AtomicReference<>();
runTest(service, (handler, resource) -> {
AtmosphereRequest request = resource.getRequest();
Mockito.when(request.getParameter(ApplicationConstants.DEBUG_WINDOW_CONNECTION)).thenReturn("");
Mockito.when(resource.transport()).thenReturn(TRANSPORT.WEBSOCKET);
handler.onConnect(resource);
res.set(resource);
});
Mockito.verify(service, Mockito.times(0)).requestStart(Mockito.any(), Mockito.any());
Mockito.verify(liveReload).onConnect(res.get());
}
use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class PushHandlerTest method debugWindowConnection_productionMode_mustNeverBeConnected.
@Test
public void debugWindowConnection_productionMode_mustNeverBeConnected() throws Exception {
ApplicationConfiguration applicationConfiguration = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(applicationConfiguration.isProductionMode()).thenReturn(true);
MockVaadinServletService service = Mockito.spy(MockVaadinServletService.class);
VaadinContext context = service.getContext();
context.setAttribute(ApplicationConfiguration.class, applicationConfiguration);
runTest(service, (handler, resource) -> {
Mockito.when(resource.transport()).thenReturn(TRANSPORT.WEBSOCKET);
Mockito.when(resource.getRequest().getParameter(ApplicationConstants.DEBUG_WINDOW_CONNECTION)).thenReturn("");
Mockito.doNothing().when(handler).callWithService(Mockito.any(), Mockito.any());
handler.onConnect(resource);
Mockito.verify(handler, Mockito.never()).callWithService(Mockito.any(), Mockito.any());
Mockito.verify(handler, Mockito.never()).callWithUi(Mockito.any(), Mockito.any());
});
}
Aggregations