List of usage examples for org.springframework.mock.web MockServletContext addInitParameter
public void addInitParameter(String name, String value)
From source file:org.jasig.cas.client.configuration.WebXmlConfigurationStrategyImplTests.java
@Test public void servletConfigValueForLong() { final ConfigurationKey<Long> key = ConfigurationKeys.TOLERANCE; final long value = 1500; final MockServletContext context = (MockServletContext) this.filterConfig.getServletContext(); context.addInitParameter(key.getName(), Long.toString(value)); assertEquals(value, this.impl.getLong(key)); }
From source file:org.jasig.cas.client.configuration.WebXmlConfigurationStrategyImplTests.java
@Test public void servletConfigValueForInt() { final ConfigurationKey<Integer> key = ConfigurationKeys.MILLIS_BETWEEN_CLEAN_UPS; final int value = 1500; final MockServletContext context = (MockServletContext) this.filterConfig.getServletContext(); context.addInitParameter(key.getName(), Integer.toString(value)); assertEquals(value, this.impl.getInt(key)); }
From source file:org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilterTests.java
public void testAllowsRenewContextParam() throws Exception { final Cas20ProxyReceivingTicketValidationFilter f = new Cas20ProxyReceivingTicketValidationFilter(); final MockServletContext context = new MockServletContext(); context.addInitParameter("casServerUrlPrefix", "https://cas.example.com"); context.addInitParameter("renew", "true"); context.addInitParameter("service", "http://www.jasig.org"); final MockFilterConfig config = new MockFilterConfig(context); f.init(config);/*w w w .j av a 2s . c o m*/ final TicketValidator validator = f.getTicketValidator(config); assertTrue(validator instanceof AbstractUrlBasedTicketValidator); assertTrue(((AbstractUrlBasedTicketValidator) validator).isRenew()); }
From source file:org.parancoe.web.test.BaseTest.java
@Override protected ConfigurableApplicationContext createApplicationContext(String[] locations) { FileSystemResourceLoader rl = new FileSystemResourceLoader(); MockServletContext servletContext = new MockServletContext(rl); servletContext.setMinorVersion(4);//from www .j a v a2 s .com servletContext.registerContext("/test", servletContext); servletContext.setServletContextName("/test"); servletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, arrayToString(locations)); ContextLoader loader = new ContextLoader(); WebApplicationContext context = loader.initWebApplicationContext(servletContext); return (ConfigurableApplicationContext) context; }
From source file:org.settings4j.helper.web.Log4jConfigurationLoaderTest.java
private MockServletContext prepareServletContext(final String log4DefaultConfiguration, final String log4ConfigurationKey) { final StringBuffer propertiesString = new StringBuffer(); if (StringUtils.isNotEmpty(log4DefaultConfiguration)) { propertiesString.append(log4ConfigurationKey); propertiesString.append("="); propertiesString.append(log4DefaultConfiguration); }//from w ww . j av a 2 s .co m final MockServletContext servletContext = new MockServletContext(); servletContext.addInitParameter(DefaultPropertiesLoader.DEFAULT_PROPERTIES, propertiesString.toString()); servletContext.addInitParameter(Log4jConfigurationLoader.LOG4J_CONFIG_SETTINGS4JKEY, log4ConfigurationKey); return servletContext; }
From source file:org.jasig.springframework.web.portlet.context.PortletContextLoaderTests.java
@Test public void testContextLoaderWithInvalidLocation() throws Exception { MockServletContext sc = new MockServletContext(""); sc.addInitParameter(PortletContextLoader.CONFIG_LOCATION_PARAM, "/WEB-INF/myContext.xml"); ServletContextListener listener = new PortletContextLoaderListener(); ServletContextEvent event = new ServletContextEvent(sc); listener.contextInitialized(event);/* ww w . j ava 2s.c o m*/ try { //initialize the portlet application context, needed because PortletContextLoaderListener.contextInitialized doesn't actually create //the portlet app context due to lack of PortletContext reference MockPortletContext pc = new MockPortletContext(sc); PortletApplicationContextUtils2.getPortletApplicationContext(pc); fail("Should have thrown BeanDefinitionStoreException"); } catch (BeanDefinitionStoreException ex) { // expected assertTrue(ex.getCause() instanceof FileNotFoundException); } }
From source file:org.jasig.springframework.web.portlet.context.PortletContextLoaderTests.java
@Test public void testContextLoaderWithInvalidContext() throws Exception { MockServletContext sc = new MockServletContext(""); sc.addInitParameter(PortletContextLoader.CONTEXT_CLASS_PARAM, "org.springframework.web.context.support.InvalidWebApplicationContext"); ServletContextListener listener = new PortletContextLoaderListener(); ServletContextEvent event = new ServletContextEvent(sc); listener.contextInitialized(event);//from ww w . j a v a 2s . c o m try { //initialize the portlet application context, needed because PortletContextLoaderListener.contextInitialized doesn't actually create //the portlet app context due to lack of PortletContext reference MockPortletContext pc = new MockPortletContext(sc); PortletApplicationContextUtils2.getPortletApplicationContext(pc); fail("Should have thrown ApplicationContextException"); } catch (ApplicationContextException ex) { // expected assertTrue(ex.getCause() instanceof ClassNotFoundException); } }
From source file:org.jasig.springframework.web.portlet.context.PortletContextLoaderTests.java
@Test public void testContextLoaderListenerWithRegisteredContextInitializer() { MockServletContext sc = new MockServletContext(""); sc.addInitParameter(PortletContextLoader.CONFIG_LOCATION_PARAM, "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml"); sc.addInitParameter(PortletContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, StringUtils.arrayToCommaDelimitedString(new Object[] { TestContextInitializer.class.getName(), TestWebContextInitializer.class.getName() })); PortletContextLoaderListener listener = new PortletContextLoaderListener(); listener.contextInitialized(new ServletContextEvent(sc)); //initialize the portlet application context, needed because PortletContextLoaderListener.contextInitialized doesn't actually create //the portlet app context due to lack of PortletContext reference MockPortletContext pc = new MockPortletContext(sc); PortletApplicationContextUtils2.getPortletApplicationContext(pc); PortletApplicationContext pac = PortletContextLoader.getCurrentPortletApplicationContext(); TestBean testBean = pac.getBean(TestBean.class); assertThat(testBean.getName(), equalTo("testName")); // assertThat(pac.getServletContext().getAttribute("initialized"), notNullValue()); assertThat(pac.getPortletContext().getAttribute("initialized"), notNullValue()); }
From source file:org.jasig.springframework.web.portlet.context.PortletContextLoaderTests.java
@Test public void testContextLoaderWithCustomContextAndParent() throws Exception { MockServletContext sc = new MockServletContext(""); sc.addInitParameter(ContextLoader.CONTEXT_CLASS_PARAM, StaticWebApplicationContext.class.getName()); sc.addInitParameter(PortletContextLoader.CONTEXT_CLASS_PARAM, SimplePortletApplicationContext.class.getName()); ContextLoaderListener servletListener = new ContextLoaderListener(); ServletContextListener listener = new PortletContextLoaderListener(); ServletContextEvent event = new ServletContextEvent(sc); servletListener.contextInitialized(event); listener.contextInitialized(event);/*from w w w .ja v a2 s.com*/ //initialize the portlet application context, needed because PortletContextLoaderListener.contextInitialized doesn't actually create //the portlet app context due to lack of PortletContext reference MockPortletContext pc = new MockPortletContext(sc); PortletApplicationContextUtils2.getPortletApplicationContext(pc); PortletApplicationContext wc = (PortletApplicationContext) pc .getAttribute(PortletApplicationContext.ROOT_PORTLET_APPLICATION_CONTEXT_ATTRIBUTE); assertTrue("Correct PortletApplicationContext exposed in PortletContext", wc instanceof SimplePortletApplicationContext); }
From source file:org.jasig.springframework.web.portlet.context.PortletContextLoaderTests.java
@Test public void testContextLoaderListenerWithDefaultContext() { MockServletContext sc = new MockServletContext(""); sc.addInitParameter(PortletContextLoader.CONFIG_LOCATION_PARAM, "/org/springframework/web/context/WEB-INF/applicationContext.xml " + "/org/springframework/web/context/WEB-INF/context-addition.xml"); ServletContextListener listener = new PortletContextLoaderListener(); ServletContextEvent event = new ServletContextEvent(sc); listener.contextInitialized(event);// ww w. j a v a 2 s.co m PortletContextLoader contextLoader = (PortletContextLoader) sc .getAttribute(PortletApplicationContextUtils2.ROOT_PORTLET_APPLICATION_CONTEXT_LOADER_ATTRIBUTE); assertNotNull(contextLoader); //initialize the portlet application context, needed because PortletContextLoaderListener.contextInitialized doesn't actually create //the portlet app context due to lack of PortletContext reference MockPortletContext pc = new MockPortletContext(sc); PortletApplicationContext context = PortletApplicationContextUtils2.getPortletApplicationContext(pc); assertTrue("Correct PortletApplicationContext exposed in PortletContext", context instanceof ContribXmlPortletApplicationContext); assertTrue(PortletContextLoader .getCurrentPortletApplicationContext() instanceof ContribXmlPortletApplicationContext); LifecycleBean lb = (LifecycleBean) context.getBean("lifecycle"); assertTrue("Has father", context.containsBean("father")); assertTrue("Has rod", context.containsBean("rod")); assertTrue("Has kerry", context.containsBean("kerry")); assertTrue("Not destroyed", !lb.isDestroyed()); assertFalse(context.containsBean("beans1.bean1")); assertFalse(context.containsBean("beans1.bean2")); listener.contextDestroyed(event); assertTrue("Destroyed", lb.isDestroyed()); assertNull(sc.getAttribute(PortletApplicationContext.ROOT_PORTLET_APPLICATION_CONTEXT_ATTRIBUTE)); assertNull(PortletContextLoader.getCurrentPortletApplicationContext()); }