List of usage examples for org.springframework.mock.web MockServletContext MockServletContext
public MockServletContext(@Nullable ResourceLoader resourceLoader)
From source file:org.guanxi.idp.IdPTest.java
@BeforeClass public static void initIdPTest() { idpProperties = ResourceBundle.getBundle("test"); servletContext = new MockServletContext(Paths.path("servlet.context.home")); principal = new GuanxiPrincipal(); principal.setName(TEST_USER_NAME);//from ww w.ja v a 2s .co m principal.getPrivateProfileData().put("username", TEST_USER_NAME); principal.setUniqueId(Utils.getUniqueID()); }
From source file:org.web4thejob.test.TestWebContextLoader.java
@Override public ApplicationContext loadContext(String... locations) throws Exception { final MockServletContext ctx = new MockServletContext(""); ctx.addInitParameter("contextConfigLocation", locations[0]); final org.springframework.web.context.ContextLoader loader = new org.springframework.web.context.ContextLoader(); return loader.initWebApplicationContext(ctx); }
From source file:ar.com.zauber.commons.spring.beans.factory.impl.ContextPathRegexCaseBlockTest.java
/** test */ public final void testCtxHome() { final MockServletContext servletCtx = new MockServletContext("/home"); servletCtx.addInitParameter("contextConfigLocation", "classpath:/spring-test-switch-regex.xml"); final TestFriendlyContextLoaderListener listener = new TestFriendlyContextLoaderListener(); listener.contextInitialized(new ServletContextEvent(servletCtx)); final WebApplicationContext ctx = ((TestFriendlyContextLoader) listener.getContextLoader()).getCtx(); assertEquals("home", ctx.getBean("test1")); }
From source file:com.xinlv.test.MockContextLoader.java
@Override public ConfigurableApplicationContext loadContext(String... locations) throws Exception { ConfigurableWebApplicationContext context = new XmlWebApplicationContext(); MockServletContext servletContext = new MockServletContext("") { @Override/*ww w .jav a 2s. co m*/ public String getRealPath(String arg0) { return System.getProperty("java.io.tmpdir"); } }; servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context); context.setServletContext(servletContext); String configLocation = "/xinlv-test-context.xml"; context.setConfigLocation(configLocation); /*String[] configLocations = PortalContextLoaderListener.locateConfigLocations(locations); context.setConfigLocations(configLocations);*/ context.refresh(); context.registerShutdownHook(); return context; }
From source file:org.openmrs.contrib.metadatarepository.webapp.listener.StartupListenerTest.java
protected void setUp() throws Exception { super.setUp(); sc = new MockServletContext(""); sc.addInitParameter(Constants.CSS_THEME, "simplicity"); // initialize Spring sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "classpath:/applicationContext-dao.xml, " + "classpath:/applicationContext-service.xml, " + "classpath:/applicationContext-resources.xml"); springListener = new ContextLoaderListener(); springListener.contextInitialized(new ServletContextEvent(sc)); listener = new StartupListener(); }
From source file:ar.com.zauber.commons.spring.servlet.mvc.support.ZauberBeanNameBasedClassNameHandlerMappingTest.java
/** @throws Exception on error */ protected final void setUp() throws Exception { final MockServletContext sc = new MockServletContext(""); wac = new XmlWebApplicationContext(); wac.setServletContext(sc);// w w w . j ava 2 s .c o m wac.setConfigLocations(new String[] { CONF }); wac.refresh(); hm = (HandlerMapping) wac.getBean("handlerMapping"); }
From source file:org.jasig.cas.WiringTests.java
@Before public void setUp() { applicationContext = new XmlWebApplicationContext(); applicationContext.setConfigLocations("file:src/main/webapp/WEB-INF/cas-servlet.xml", "file:src/main/webapp/WEB-INF/deployerConfigContext.xml", "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"); applicationContext.setServletContext(new MockServletContext(new ResourceLoader() { @Override//from w w w . j a va2 s . c o m public Resource getResource(final String location) { return new FileSystemResource("src/main/webapp" + location); } @Override public ClassLoader getClassLoader() { return getClassLoader(); } })); applicationContext.refresh(); }
From source file:ar.com.zauber.commons.spring.beans.factory.impl.ContextPathRegexCaseBlockTest.java
/** test */ public final void testCtxHouse() { final MockServletContext servletCtx = new MockServletContext("/house"); servletCtx.addInitParameter("contextConfigLocation", "classpath:/spring-test-switch-regex.xml"); final TestFriendlyContextLoaderListener listener = new TestFriendlyContextLoaderListener(); listener.contextInitialized(new ServletContextEvent(servletCtx)); final WebApplicationContext ctx = ((TestFriendlyContextLoader) listener.getContextLoader()).getCtx(); assertEquals("house", ctx.getBean("test1")); }
From source file:com.amashchenko.struts2.actionflow.ActionFlowAwareTest.java
/** Initializes servlet mock objects but preserves session. */ private void initServletMockObjectsPreserveSession() { servletContext = new MockServletContext(resourceLoader); response = new MockHttpServletResponse(); // preserve session HttpSession session = null;// www.j a v a2s . c o m if (request != null && request.getSession() != null) { session = request.getSession(); } request = new MockHttpServletRequest(); request.setSession(session); pageContext = new MockPageContext(servletContext, request, response); }
From source file:org.gwtwidgets.server.spring.test.HandlerTest.java
@Override @Before/* w w w . j a v a2 s . co m*/ public void setUp() throws Exception { super.setUp(); ServletContext servletContext = new MockServletContext(new FileSystemResourceLoader()); requestService = new MockHttpServletRequest("PUT", "/service"); applicationContext = new XmlWebApplicationContext(); applicationContext.setServletContext(servletContext); applicationContext.setConfigLocations(new String[] { "src/main/webapp/WEB-INF/handler-servlet.xml", "src/main/webapp/WEB-INF/applicationContext.xml" }); try { applicationContext.refresh(); } catch (Throwable e) { e.printStackTrace(); } handler = (GWTHandler) applicationContext.getBean("urlMapping", GWTHandler.class); }