/** * Create new MockServletConfig. * @param servletContext the ServletContext that the JSP page runs in * @param request the current HttpServletRequest * @param response the current HttpServletResponse * @param servletConfig the ServletConfig (hardly ever accessed from within a tag) */ public MockPageContext(@Nullable ServletContext servletContext, @Nullable HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable ServletConfig servletConfig) { this.servletContext = (servletContext != null ? servletContext : new MockServletContext()); this.request = (request != null ? request : new MockHttpServletRequest(servletContext)); this.response = (response != null ? response : new MockHttpServletResponse()); this.servletConfig = (servletConfig != null ? servletConfig : new MockServletConfig(servletContext)); }
/** * Build a {@link org.springframework.test.web.servlet.MockMvc} instance. */ @Override @SuppressWarnings("rawtypes") public final MockMvc build() { WebApplicationContext wac = initWebAppContext(); ServletContext servletContext = wac.getServletContext(); MockServletConfig mockServletConfig = new MockServletConfig(servletContext); for (MockMvcConfigurer configurer : this.configurers) { RequestPostProcessor processor = configurer.beforeMockMvcCreated(this, wac); if (processor != null) { if (this.defaultRequestBuilder == null) { this.defaultRequestBuilder = MockMvcRequestBuilders.get("/"); } if (this.defaultRequestBuilder instanceof ConfigurableSmartRequestBuilder) { ((ConfigurableSmartRequestBuilder) this.defaultRequestBuilder).with(processor); } } } Filter[] filterArray = this.filters.toArray(new Filter[0]); return super.createMockMvc(filterArray, mockServletConfig, wac, this.defaultRequestBuilder, this.globalResultMatchers, this.globalResultHandlers, this.dispatcherServletCustomizers); }
protected DispatcherServlet getDispatcher() throws Exception { // create an instance of the spring dispatcher ServletContext context = applicationContext.getServletContext(); MockServletConfig config = new MockServletConfig(context, "dispatcher"); DispatcherServlet dispatcher = new DispatcherServlet(); dispatcher.setContextConfigLocation( GeoServerAbstractTestSupport.class .getResource("dispatcher-servlet.xml") .toString()); dispatcher.init(config); return dispatcher; }
protected DispatcherServlet buildDispatcher() throws ServletException { // create an instance of the spring dispatcher ServletContext context = applicationContext.getServletContext(); MockServletConfig config = new MockServletConfig(context, "dispatcher"); DispatcherServlet dispatcher = new DispatcherServlet(applicationContext); dispatcher.setContextConfigLocation( GeoServerAbstractTestSupport.class .getResource("dispatcher-servlet.xml") .toString()); dispatcher.init(config); return dispatcher; }
private void loadConfig(Class<?>... configs) { context = new AnnotationConfigWebApplicationContext(); context.register(configs); context.setServletConfig(new MockServletConfig()); context.refresh(); }
private void loadConfig(Class<?>... configs) { context = new AnnotationConfigWebApplicationContext(); context.register(configs); context.register(WebSocketConfig.class, SyncExecutorConfig.class); context.setServletConfig(new MockServletConfig()); context.refresh(); }
public void initializeContext(ConfigurableWebApplicationContext context, String yamlPath) { MockServletContext servletContext = new MockServletContext() { @Override public <Type extends EventListener> void addListener(Type t) { //no op } }; MockServletConfig servletConfig = new MockServletConfig(servletContext); servletConfig.addInitParameter("environmentConfigDefaults", yamlPath); context.setServletContext(servletContext); context.setServletConfig(servletConfig); new YamlServletProfileInitializer().initialize(context); } }
@Test public void shouldDelegateToTheGivenServlet() throws IOException, ServletException { MockServletContext ctx = new MockServletContext(); ctx.addInitParameter(DelegatingListener.DELEGATE_SERVLET, DummyServlet.class.getCanonicalName()); ServletContextEvent evt = new ServletContextEvent(ctx); DelegatingListener listener = new DelegatingListener(); listener.contextInitialized(evt); assertThat((DummyServlet) ctx.getAttribute(DelegatingListener.DELEGATE_SERVLET), isA(DummyServlet.class)); DelegatingServlet servlet = new DelegatingServlet(); servlet.init(new MockServletConfig(ctx)); servlet.service(httpServletRequest, new MockHttpServletResponse()); verify(servletRequestWrapper).setRequestURI("/go/stuff/action"); } }
servletContext.addInitParameter("pContext1", "pContext1Value"); MockServletConfig servletConfig = new MockServletConfig(servletContext); servletConfig.addInitParameter("pCommon", "pCommonConfigValue"); servletConfig.addInitParameter("pConfig1", "pConfig1Value");
@Before public void setUp() throws Exception { fileServlet = new StagemonitorFileServlet(); fileServlet.init(new MockServletConfig(new MockServletContext())); request = new MockHttpServletRequest("GET", "/stagemonitor/static/test.js"); response = new MockHttpServletResponse(); }
servletContext.addInitParameter("pContext1", "pContext1Value"); MockServletConfig servletConfig = new MockServletConfig(servletContext); servletConfig.addInitParameter("pCommon", "pCommonConfigValue"); servletConfig.addInitParameter("pConfig1", "pConfig1Value");
MockServletConfig servletConfig = new MockServletConfig(servletContext); servletConfig.addInitParameter("environmentConfigLocations", StringUtils.arrayToCommaDelimitedString(yamlFiles)); context.setServletConfig(servletConfig);
public void autowire() { this.context.setServletContext(new MockServletContext()); this.context.setServletConfig(new MockServletConfig()); this.context.refresh(); if (this.context.containsBean(SPRING_SECURITY_FILTER_CHAIN)) { MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context) .apply(springSecurity()) .apply(new AddFilter()).build(); this.context.getBeanFactory() .registerResolvableDependency(MockMvc.class, mockMvc); } AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(this.context.getBeanFactory()); bpp.processInjection(this.test); }
private void prepareSVN() throws IOException, SVNException { File tempRepo = new File(System.getProperty("java.io.tmpdir"), "repo"); fileEntityRepository.setUserRepository(new File(tempRepo, getTestUser().getUserId())); tempRepo.deleteOnExit(); File testUserRoot = fileEntityRepository.getUserRepoDirectory(getTestUser()).getParentFile(); FileUtils.deleteQuietly(testUserRoot); testUserRoot.mkdirs(); CompressionUtils.unzip(new ClassPathResource("TEST_USER.zip").getFile(), testUserRoot); testUserRoot.deleteOnExit(); MockServletConfig servletConfig = new MockServletConfig(); servletConfig.addInitParameter("SVNParentPath", testUserRoot.getAbsolutePath()); DAVConfig davConfig = new DAVConfig(servletConfig); svnController.setDAVConfig(davConfig); }
protected void setUp() throws Exception { super.setUp(); servlet = (HttpServlet)Class.forName("org.apache.wink.server.internal.servlet.RestServlet") .newInstance(); MockServletConfig servletConfig = new MockServletConfig(servletContext); servlet.init(servletConfig); }
/** * Build a {@link MockMvc} instance. */ public final MockMvc build() { WebApplicationContext webAppContext = initWebApplicationContext(); Assert.state(webAppContext != null, "WebApplicationContext not provided by concrete MockMvcBuilder"); ServletContext servletContext = webAppContext.getServletContext(); Assert.state(servletContext != null,"ServletContext not configured by concrete MockMvcBuilder"); Filter[] filterArray = this.filters.toArray(new Filter[this.filters.size()]); MockServletConfig mockServletConfig = new MockServletConfig(servletContext); return super.createMockMvc(filterArray, mockServletConfig, webAppContext, this.defaultRequestBuilder, this.globalResultMatchers, this.globalResultHandlers); }
/** * Create new MockServletConfig. * @param servletContext the ServletContext that the JSP page runs in * @param request the current HttpServletRequest * @param response the current HttpServletResponse * @param servletConfig the ServletConfig (hardly ever accessed from within a tag) */ public MockPageContext(@Nullable ServletContext servletContext, @Nullable HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable ServletConfig servletConfig) { this.servletContext = (servletContext != null ? servletContext : new MockServletContext()); this.request = (request != null ? request : new MockHttpServletRequest(servletContext)); this.response = (response != null ? response : new MockHttpServletResponse()); this.servletConfig = (servletConfig != null ? servletConfig : new MockServletConfig(servletContext)); }
public DispatcherServletChannelInitializer() throws ServletException { MockServletContext servletContext = new MockServletContext(); MockServletConfig servletConfig = new MockServletConfig(servletContext); //set spring config in xml this.dispatcherServlet = new DispatcherServlet(); this.dispatcherServlet.setContextConfigLocation("classpath*:/dubboss-server.xml"); this.dispatcherServlet.init(servletConfig); }
public DispatcherServletChannelInitializer() throws ServletException { MockServletContext servletContext = new MockServletContext(); MockServletConfig servletConfig = new MockServletConfig(servletContext); XmlWebApplicationContext wac = new XmlWebApplicationContext(); wac.setServletContext(servletContext); wac.setServletConfig(servletConfig); wac.setConfigLocations(new String[] { "classpath:/servlet-context.xml", "classpath:dubbo-consumer.xml" }); wac.refresh(); this.dispatcherServlet = new DispatcherServlet(wac); this.dispatcherServlet.init(servletConfig); }
public DispatcherServletChannelInitializer() throws ServletException { MockServletContext servletContext = new MockServletContext(); MockServletConfig servletConfig = new MockServletConfig(servletContext); AnnotationConfigWebApplicationContext wac = new AnnotationConfigWebApplicationContext(); wac.setServletContext(servletContext); wac.setServletConfig(servletConfig); wac.register(AppConfig.class); wac.refresh(); this.dispatcherServlet = new DispatcherServlet(wac); this.dispatcherServlet.init(servletConfig); //set spring config in xml //this.dispatcherServlet = new DispatcherServlet(); //this.dispatcherServlet.setContextConfigLocation("classpath*:/applicationContext.xml"); //this.dispatcherServlet.init(servletConfig); }