@Before public void setup() { this.serverContainer = mock(ServerContainer.class); this.servletContext = new MockServletContext(); this.servletContext.setAttribute("javax.websocket.server.ServerContainer", this.serverContainer); this.webAppContext = new AnnotationConfigWebApplicationContext(); this.webAppContext.register(Config.class); this.webAppContext.setServletContext(this.servletContext); this.webAppContext.refresh(); this.exporter = new ServerEndpointExporter(); }
private ApplicationContext initContext(Class<?>... configClasses) { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setServletContext(new MockServletContext()); context.register(configClasses); context.refresh(); return context; }
@Before public void setup() throws Exception { logger.debug("Setting up '" + this.testName.getMethodName() + "', client=" + this.webSocketClient.getClass().getSimpleName() + ", server=" + this.server.getClass().getSimpleName()); this.wac = new AnnotationConfigWebApplicationContext(); this.wac.register(getAnnotatedConfigClasses()); this.wac.register(upgradeStrategyConfigTypes.get(this.server.getClass())); if (this.webSocketClient instanceof Lifecycle) { ((Lifecycle) this.webSocketClient).start(); } this.server.setup(); this.server.deployConfig(this.wac); this.server.start(); this.wac.setServletContext(this.server.getServletContext()); this.wac.refresh(); }
private void initWebApplicationContext(Class<?> configClass) { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setServletContext(new MockServletContext()); context.register(configClass); context.refresh(); this.request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, context); }
@Before @SuppressWarnings("resource") public void setup() throws Exception { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setServletContext(new MockServletContext()); context.register(WebConfig.class); context.refresh(); this.request = new MockHttpServletRequest("GET", "/"); this.request.setContextPath("/myapp"); this.response = new MockHttpServletResponse(); this.filterChain = new MockFilterChain(this.servlet, new ResourceUrlEncodingFilter(), (request, response, chain) -> { Object urlProvider = context.getBean(ResourceUrlProvider.class); request.setAttribute(ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR, urlProvider); chain.doFilter(request, response); }); }
public void loadConfig(Class<?>... configs) { this.context = new AnnotationConfigWebApplicationContext(); this.context.register(configs); this.context.setServletContext(this.servletContext); this.context.refresh(); this.context.getAutowireCapableBeanFactory().autowireBean(this); } }
private void loadConfig(Class<?>... configs) { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setAllowCircularReferences(false); context.register(configs); context.setServletContext(new MockServletContext()); context.refresh(); } }
public void loadConfig(Class<?>... configs) { this.context = new AnnotationConfigWebApplicationContext(); this.context.register(configs); this.context.setServletContext(new MockServletContext()); this.context.refresh(); this.context.getAutowireCapableBeanFactory().autowireBean(this); } }
@Before public void setup() throws Exception { logger.debug("Setting up '" + this.testName.getMethodName() + "'"); this.testFilter = new TestFilter(); this.wac = new AnnotationConfigWebApplicationContext(); this.wac.register(TestConfig.class, upgradeStrategyConfigClass()); this.server = createWebSocketTestServer(); this.server.setup(); this.server.deployConfig(this.wac, this.testFilter); this.server.start(); this.wac.setServletContext(this.server.getServletContext()); this.wac.refresh(); this.baseUrl = "http://localhost:" + this.server.getPort(); }
public void loadConfig(Class<?>... configs) { this.context = new AnnotationConfigWebApplicationContext(); this.context.register(configs); this.context.setServletContext(new MockServletContext()); this.context.refresh(); this.context.getAutowireCapableBeanFactory().autowireBean(this); } }
public void loadConfig(Class<?>... configs) { this.context = new AnnotationConfigWebApplicationContext(); this.context.register(configs); this.context.setServletContext(new MockServletContext()); this.context.refresh(); this.context.getAutowireCapableBeanFactory().autowireBean(this); }
@Test // SPR-12592 @SuppressWarnings("resource") public void initializeOnce() { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setServletContext(new MockServletContext()); context.register(HandlerMappingConfiguration.class); context.refresh(); assertThat(context.getBean(ResourceUrlProvider.class).getHandlerMap(), Matchers.hasKey(pattern("/resources/**"))); }
private MockHttpServletResponse runTest(Class<?> configClass) throws ServletException, IOException { String basePath = "org/springframework/web/servlet/config/annotation"; MockServletContext servletContext = new MockServletContext(basePath); MockServletConfig servletConfig = new MockServletConfig(servletContext); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); MockHttpServletResponse response = new MockHttpServletResponse(); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(configClass); context.setServletContext(servletContext); context.refresh(); DispatcherServlet servlet = new DispatcherServlet(context); servlet.init(servletConfig); servlet.service(request, response); return response; }
@Test // SPR-12592 @SuppressWarnings("resource") public void initializeOnce() throws Exception { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setServletContext(new MockServletContext()); context.register(HandlerMappingConfiguration.class); context.refresh(); ResourceUrlProvider urlProviderBean = context.getBean(ResourceUrlProvider.class); assertThat(urlProviderBean.getHandlerMap(), Matchers.hasKey("/resources/**")); assertFalse(urlProviderBean.isAutodetect()); }
@Test public void runSpringHttpSessionConfig() { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(SpringHttpSessionConfig.class); context.setServletContext(new MockServletContext()); context.refresh(); try { context.getBean(SessionRepositoryFilter.class); } finally { context.close(); } }
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.register(ConfigMVC.class); ctx.setServletContext(servletContext); Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx)); servlet.addMapping("/"); servlet.setLoadOnStartup(1); servlet.setInitParameter("throwExceptionIfNoHandlerFound", "true"); }
private void configureContext(ServletContext container, AnnotationConfigWebApplicationContext rootContext) { rootContext.setServletContext(container); container.addListener(new ContextLoaderListener(rootContext)); studioConfig.getSpringAnnotatedConfigs().forEach(rootContext::register); rootContext.refresh(); }
@Override public WebApplicationContext createWebContext(ApplicationContext rootContext, ServletContextHandler handler, Config config) { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setParent(rootContext); context.setServletContext(handler.getServletContext()); registerConfigClasses(context, config); context.refresh(); return context; }
@Test public void deviceHandlerMethodArgumentResolverCreated() throws Exception { this.context = new AnnotationConfigWebApplicationContext(); this.context.setServletContext(new MockServletContext()); this.context.register(Config.class); this.context.refresh(); DeviceHandlerMethodArgumentResolver resolver = this.context.getBean(DeviceHandlerMethodArgumentResolver.class); assertThat(resolver).isNotNull(); }
@Test public void deviceHandlerMethodArgumentWorksWithSpringData() throws Exception { this.context = new AnnotationConfigWebApplicationContext(); this.context.register(Config.class); this.context.setServletContext(new MockServletContext()); this.context.refresh(); MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build(); mockMvc.perform(get("/")).andExpect(status().isOk()); }