use of com.vaadin.flow.server.VaadinServletContext in project flow by vaadin.
the class JavaScriptBootstrapHandlerTest method should_respondPushScript_when_annotatedInAppShell.
@Test
public void should_respondPushScript_when_annotatedInAppShell() throws Exception {
VaadinServletContext context = new VaadinServletContext(mocks.getServletContext());
AppShellRegistry registry = AppShellRegistry.getInstance(context);
registry.setShell(PushAppShell.class);
mocks.setAppShellRegistry(registry);
VaadinRequest request = mocks.createRequest(mocks, "/", "v-r=init&foo&location");
jsInitHandler.handleRequest(session, request, response);
Assert.assertEquals(200, response.getErrorCode());
Assert.assertEquals("application/json", response.getContentType());
JsonObject json = Json.parse(response.getPayload());
// Using regex, because version depends on the build
Assert.assertTrue(json.getString("pushScript").matches("^\\./VAADIN/static/push/vaadinPush\\.js\\?v=[\\w\\.\\-]+$"));
}
use of com.vaadin.flow.server.VaadinServletContext in project flow by vaadin.
the class AbstractDevModeTest method setup.
@Before
public void setup() throws Exception {
baseDir = temporaryFolder.getRoot().getPath();
npmFolder = temporaryFolder.getRoot();
Boolean enablePnpm = Boolean.TRUE;
appConfig = Mockito.mock(ApplicationConfiguration.class);
servletContext = Mockito.mock(ServletContext.class);
Mockito.when(servletContext.getAttribute(ApplicationConfiguration.class.getName())).thenReturn(appConfig);
Mockito.when(servletContext.getClassLoader()).thenReturn(servletContext.getClass().getClassLoader());
vaadinContext = new VaadinServletContext(servletContext);
mockApplicationConfiguration(appConfig, enablePnpm);
lookup = Mockito.mock(Lookup.class);
Mockito.when(servletContext.getAttribute(Lookup.class.getName())).thenReturn(lookup);
ResourceProvider resourceProvider = Mockito.mock(ResourceProvider.class);
Mockito.when(lookup.lookup(ResourceProvider.class)).thenReturn(resourceProvider);
devModeHandlerManager = new DevModeHandlerManagerImpl();
Mockito.when(lookup.lookup(DevModeHandlerManager.class)).thenReturn(devModeHandlerManager);
configuration = new MockDeploymentConfiguration();
Mockito.when(lookup.lookup(DeploymentConfiguration.class)).thenReturn(configuration);
Mockito.when(lookup.lookup(ApplicationConfiguration.class)).thenReturn(appConfig);
Mockito.when(lookup.lookup(StaticFileHandlerFactory.class)).thenReturn(service -> new StaticFileServer(service));
vaadinService = Mockito.mock(VaadinService.class);
Mockito.when(vaadinService.getContext()).thenReturn(vaadinContext);
Mockito.when(vaadinService.getDeploymentConfiguration()).thenReturn(configuration);
}
use of com.vaadin.flow.server.VaadinServletContext in project flow by vaadin.
the class SpringLookupInitializer method getApplicationContext.
/**
* Gets a {@link WebApplicationContext} instance for the {@code context}.
*
* @param context
* a Vaadin context
* @return a {@link WebApplicationContext} instance for the {@code context}
*/
static WebApplicationContext getApplicationContext(VaadinContext context) {
VaadinServletContext servletContext = (VaadinServletContext) context;
WebApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(servletContext.getContext());
if (appContext == null) {
// Spring behavior is always unbelievably surprising: under some
// circumstances {@code appContext} may be null even though the app
// context has been set via ApplicationContextAware: no idea WHY
ApplicationContextWrapper wrapper = context.getAttribute(ApplicationContextWrapper.class);
appContext = wrapper == null ? null : wrapper.appContext;
}
return appContext;
}
use of com.vaadin.flow.server.VaadinServletContext in project flow by vaadin.
the class EndpointInvoker method getAccessChecker.
EndpointAccessChecker getAccessChecker(ServletContext servletContext) {
VaadinServletContext vaadinServletContext = new VaadinServletContext(servletContext);
VaadinConnectAccessCheckerWrapper wrapper = vaadinServletContext.getAttribute(VaadinConnectAccessCheckerWrapper.class, () -> {
EndpointAccessChecker accessChecker = applicationContext.getBean(EndpointAccessChecker.class);
return new VaadinConnectAccessCheckerWrapper(accessChecker);
});
return wrapper.accessChecker;
}
use of com.vaadin.flow.server.VaadinServletContext in project flow by vaadin.
the class SpringInstantiatorTest method getService.
public static VaadinService getService(ApplicationContext context, Properties configProperties, boolean rootMapping) throws ServletException {
SpringServlet servlet = new SpringServlet(context, rootMapping) {
@Override
protected DeploymentConfiguration createDeploymentConfiguration(Properties initParameters) {
if (configProperties != null) {
configProperties.putAll(initParameters);
return super.createDeploymentConfiguration(configProperties);
}
return super.createDeploymentConfiguration(initParameters);
}
};
ServletConfig config = Mockito.mock(ServletConfig.class);
ServletContext servletContext = Mockito.mock(ServletContext.class);
Mockito.when(servletContext.getClassLoader()).thenReturn(servlet.getClass().getClassLoader());
ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
Mockito.when(appConfig.getContext()).thenReturn(new VaadinServletContext(servletContext));
Mockito.when(servletContext.getAttribute(ApplicationConfiguration.class.getName())).thenReturn(appConfig);
Lookup lookup = Mockito.mock(Lookup.class);
ResourceProvider provider = Mockito.mock(ResourceProvider.class);
Mockito.when(lookup.lookup(ResourceProvider.class)).thenReturn(provider);
StaticFileHandlerFactory staticFileHandlerFactory = vaadinService -> new StaticFileServer((VaadinServletService) vaadinService);
Mockito.when(lookup.lookup(StaticFileHandlerFactory.class)).thenReturn(staticFileHandlerFactory);
Mockito.when(servletContext.getAttribute(Lookup.class.getName())).thenReturn(lookup);
Mockito.when(config.getServletContext()).thenReturn(servletContext);
Mockito.when(config.getInitParameterNames()).thenReturn(Collections.emptyEnumeration());
Mockito.when(servletContext.getInitParameterNames()).thenReturn(Collections.emptyEnumeration());
servlet.init(config);
return servlet.getService();
}
Aggregations