List of usage examples for org.springframework.mock.web MockServletContext MockServletContext
public MockServletContext()
From source file:com.xemantic.tadedon.guice.servlet.GuiceServletsTest.java
@Test public void shouldGetProductionStageWhenNoFooParamStageSpecified() throws Exception { // given/*from w ww.j a va 2 s. co m*/ MockServletContext context = new MockServletContext(); // when Stage stage = GuiceServlets.getStage(context, "fooParam"); // then assertThat(stage, is(Stage.PRODUCTION)); }
From source file:org.sventon.appl.ConfigDirectoryTest.java
@Test public void testDirectoryOverrideBySettingSystemProperty() throws Exception { System.setProperty(ConfigDirectory.PROPERTY_KEY_SVENTON_DIR_SYSTEM, SEPARATOR + "override"); final ConfigDirectory configDir = new ConfigDirectory(TEMP_DIR, EXPORT_DIR, REPOSITORIES_DIR); configDir.setCreateDirectories(false); final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath(SERVLET_CONTEXT_PATH); configDir.setServletContext(servletContext); final String path = configDir.getConfigRootDirectory().getAbsolutePath(); assertTrue(path.contains(SEPARATOR + "override" + SEPARATOR)); assertTrue(path.endsWith(SERVLET_CONTEXT_PATH)); System.clearProperty(ConfigDirectory.PROPERTY_KEY_SVENTON_DIR_SYSTEM); }
From source file:newcontroller.handler.impl.DefaultRequestTest.java
@Test public void testUnwrap() throws Exception { HttpServletRequest request = MockMvcRequestBuilders.get("/").param("foo", "aaa") .buildRequest(new MockServletContext()); Request req = new DefaultRequest(request); assertThat(req.unwrap(HttpServletRequest.class), is(sameInstance(request))); }
From source file:org.jasig.cas.web.flow.SendTicketGrantingTicketActionTests.java
@Test public void testTgtToSet() throws Exception { final MockHttpServletResponse response = new MockHttpServletResponse(); final String TICKET_VALUE = "test"; WebUtils.putTicketGrantingTicketInRequestScope(this.context, TICKET_VALUE); this.context.setExternalContext( new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), response)); assertEquals("success", this.action.execute(this.context).getId()); assertEquals(TICKET_VALUE, response.getCookies()[0].getValue()); }
From source file:org.parancoe.web.test.junit4.WebXmlContextLoader.java
/** * Loads a Spring ApplicationContext from the supplied * <code>locations</code>. and creates a standard {@link GenericWebApplicationContext} instance. * * @return a new application context//from ww w . j a v a 2 s. c o m * @see org.springframework.test.context.ContextLoader#loadContext * @see GenericWebApplicationContext * @see #createBeanDefinitionReader(GenericApplicationContext) * @see BeanDefinitionReader */ @Override public final ConfigurableApplicationContext loadContext(String... locations) throws Exception { if (logger.isDebugEnabled()) { logger.debug("Loading ApplicationContext for locations [{}].", StringUtils.arrayToCommaDelimitedString(locations)); } GenericWebApplicationContext context = new GenericWebApplicationContext(); createBeanDefinitionReader(context).loadBeanDefinitions(locations); MockServletContext servletContext = new MockServletContext(); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context); context.setServletContext(servletContext); AnnotationConfigUtils.registerAnnotationConfigProcessors(context); context.refresh(); context.registerShutdownHook(); return context; }
From source file:org.ngrinder.script.controller.SvnDavControllerTest.java
@Test public void testDavServletEnv() { assertThat(svnController.getServletName(), is("svnDavServlet")); ServletContext context = new MockServletContext(); svnController.setServletContext(context); assertThat(svnController.getServletContext(), is(context)); assertThat(svnController.getInitParameter("param"), nullValue()); assertThat(svnController.getInitParameterNames().nextElement(), is((Object) "SVNParentPath")); }
From source file:edu.internet2.middleware.shibboleth.idp.system.conf1.SAML2SSOTestCase.java
/** Tests initial leg of the SSO request where request is decoded and sent to the authentication engine. */ public void testFirstAuthenticationLeg() throws Exception { MockServletContext servletContext = new MockServletContext(); MockHttpServletRequest servletRequest = buildServletRequest("urn:example.org:sp1"); MockHttpServletResponse servletResponse = new MockHttpServletResponse(); ProfileHandlerManager handlerManager = (ProfileHandlerManager) getApplicationContext() .getBean("shibboleth.HandlerManager"); AbstractShibbolethProfileHandler handler = (AbstractShibbolethProfileHandler) handlerManager .getProfileHandler(servletRequest); assertNotNull(handler);/*from w w w. j ava2 s. co m*/ // Process request HTTPInTransport profileRequest = new HttpServletRequestAdapter(servletRequest); HTTPOutTransport profileResponse = new HttpServletResponseAdapter(servletResponse, false); handler.processRequest(profileRequest, profileResponse); servletRequest.setCookies(servletResponse.getCookies()); Saml2LoginContext loginContext = (Saml2LoginContext) HttpServletHelper .getLoginContext(handler.getStorageService(), servletContext, servletRequest); assertNotNull(loginContext); assertEquals(false, loginContext.getAuthenticationAttempted()); assertEquals(false, loginContext.isForceAuthRequired()); assertEquals(false, loginContext.isPassiveAuthRequired()); assertEquals("/AuthnEngine", loginContext.getAuthenticationEngineURL()); assertEquals("/saml2/POST/SSO", loginContext.getProfileHandlerURL()); assertEquals("urn:example.org:sp1", loginContext.getRelyingPartyId()); assertEquals(0, loginContext.getRequestedAuthenticationMethods().size()); assertTrue(servletResponse.getRedirectedUrl().endsWith("/AuthnEngine")); }
From source file:org.springframework.test.web.servlet.htmlunit.HtmlUnitRequestBuilderTest.java
@Before public void setUp() throws Exception { sessions = new HashMap<String, MockHttpSession>(); cookieManager = new CookieManager(); webRequest = new WebRequest(new URL("http://example.com:80/test/this/here")); webRequest.setHttpMethod(HttpMethod.GET); webRequest.setRequestParameters(new ArrayList<NameValuePair>()); requestBuilder = new HtmlUnitRequestBuilder(sessions, cookieManager, webRequest); servletContext = new MockServletContext(); }
From source file:org.sventon.repository.DefaultRepositoryChangeMonitorTest.java
@Test public void testUpdate() throws Exception { final ConfigDirectory configDirectory = TestUtils.getTestConfigDirectory(); configDirectory.setCreateDirectories(false); final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("sventon-test"); configDirectory.setServletContext(servletContext); final Application application = new Application(configDirectory); final RepositoryConfiguration configuration = new RepositoryConfiguration("name"); configuration.setCacheUsed(true);/* ww w . jav a 2 s . c o m*/ application.addConfiguration(configuration); application.setConfigured(true); final ObjectCache cache = createMemoryCache(); try { final List<RepositoryChangeListener> listeners = new ArrayList<RepositoryChangeListener>(); listeners.add(repositoryChangeListenerMock); final DefaultRepositoryChangeMonitor changeMonitor = new DefaultRepositoryChangeMonitor(); changeMonitor.setListeners(listeners); changeMonitor.setMaxRevisionCountPerUpdate(3); changeMonitor.setApplication(application); changeMonitor.setRepositoryService(repositoryServiceMock); assertFalse(application.isUpdating(configuration.getName())); expect(repositoryServiceMock.getLatestRevision(null)).andReturn(6L); expect(repositoryServiceMock.getLogEntriesFromRepositoryRoot(null, 1L, 3L)) .andReturn(firstBatchOfRevisions); repositoryChangeListenerMock.update(isA(RevisionUpdate.class)); expect(repositoryServiceMock.getLogEntriesFromRepositoryRoot(null, 4L, 6L)) .andReturn(secondBatchOfRevisions); repositoryChangeListenerMock.update(isA(RevisionUpdate.class)); replay(repositoryServiceMock); replay(repositoryChangeListenerMock); changeMonitor.update(configuration.getName(), null, cache); verify(repositoryServiceMock); verify(repositoryChangeListenerMock); assertFalse(application.isUpdating(configuration.getName())); } finally { cache.shutdown(); } }
From source file:ar.com.zauber.commons.web.proxy.impl.PathBasedURLRequestMapperTest.java
/** @throws Exception on error */ public final void testResultDelegate() throws Exception { final PathBasedURLRequestMapper mapper = new PathBasedURLRequestMapper( new InmutableURLRequestMapper(new InmutableURLResult())); final MockServletContext ctx = new MockServletContext(); final String ctxPath = "/nexusaaa-0.0"; final String servletContext = "/bin"; final MockHttpServletRequest request = new MockHttpServletRequest(ctx, "GET", ctxPath + servletContext + "/"); request.setContextPath(ctxPath);/*from w w w .j a va2 s . c om*/ request.setServletPath(servletContext); assertFalse(mapper.getProxiedURLFromRequest(request).hasResult()); }