List of usage examples for org.springframework.mock.web MockServletContext MockServletContext
public MockServletContext()
From source file:org.settings4j.helper.web.Log4jConfigurationLoaderTest.java
/** * The normal usage of the DefaultPropertiesLoader: Load default Properties from ServletContext and add Connector to * Settings4j.// ww w.j av a2 s .c o m */ @Test public void testInitLog4jConfigurationEmptyProperties() { new Log4jConfigurationLoader().initLog4jConfiguration(new MockServletContext()); // assert PreReQuirements InMemoryLog4jAppender.linesClear(); // Log SomeThing LOG.info("test"); // validate Result assertThat(InMemoryLog4jAppender.linesSize(), is(1)); assertThat(InMemoryLog4jAppender.linesGet(0).toString().trim(), is("[CONFIG-DEFAULT] INFO test")); }
From source file:com.github.mike10004.stormpathacctmgr.PasswordResetTest.java
protected MockServletContext createServletContext() { MockServletContext context = new MockServletContext(); return context; }
From source file:de.uni_koeln.spinfo.maalr.mongo.integration.ITSpringMongoBackend.java
License:asdf
@Before public void beforeTest() throws Exception { Database.getInstance().deleteAllEntries(); loginManager.logout();/*from w w w . jav a2 s .co m*/ GenericWebApplicationContext context = new GenericWebApplicationContext(); MockServletContext servlet = new MockServletContext(); context.setServletContext(servlet); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpSession session = new MockHttpSession(); request.setSession(session); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); context.refresh(); context.getBeanFactory().registerScope("session", new SessionScope()); }
From source file:fi.okm.mpass.idp.authn.impl.SocialUserAuthServletTest.java
@BeforeMethod public void initTests() throws Exception { nullAuthenticator = "/method1"; throwingAuthenticator = "/method2"; subjectAuthenticator = "/method3"; throwingEvent = "throwingEvent"; username = "mockUser"; authnRedirectUrl = "http://localhost/redirect"; servlet = new SocialUserAuthServlet(); SocialIdentityFactory factory = new SocialIdentityFactory(); Map<String, Object> authenticators = new HashMap<String, Object>(); authenticators.put(nullAuthenticator, initNullAuthenticator()); authenticators.put(throwingAuthenticator, initThrowingAuthenticator()); authenticators.put(subjectAuthenticator, initSubjectAuthenticator()); factory.setSocialImplBeans(authenticators); MockServletContext servletContext = new MockServletContext(); servletContext.setAttribute("socialUserImplementationFactoryBeanInServletContext", factory); MockServletConfig servletConfig = new MockServletConfig(servletContext); servlet.init(servletConfig);// w w w.j ava 2 s. c o m }
From source file:org.jasig.cas.web.flow.InitialFlowSetupActionTests.java
public void testResettingContexPath() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final String CONST_CONTEXT_PATH = "/test"; final String CONST_CONTEXT_PATH_2 = "/test1"; request.setContextPath(CONST_CONTEXT_PATH); final MockRequestContext context = new MockRequestContext(); context.setExternalContext(// w w w . ja v a 2s .co m new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse())); this.action.doExecute(context); assertEquals(CONST_CONTEXT_PATH + "/", this.warnCookieGenerator.getCookiePath()); assertEquals(CONST_CONTEXT_PATH + "/", this.tgtCookieGenerator.getCookiePath()); request.setContextPath(CONST_CONTEXT_PATH_2); this.action.doExecute(context); assertNotSame(CONST_CONTEXT_PATH_2 + "/", this.warnCookieGenerator.getCookiePath()); assertNotSame(CONST_CONTEXT_PATH_2 + "/", this.tgtCookieGenerator.getCookiePath()); assertEquals(CONST_CONTEXT_PATH + "/", this.warnCookieGenerator.getCookiePath()); assertEquals(CONST_CONTEXT_PATH + "/", this.tgtCookieGenerator.getCookiePath()); }
From source file:com.xemantic.tadedon.guice.servlet.GuiceServletsTest.java
@Test public void shouldGetDevelopmentStageWhenFooParamDevelopmentIsSpecified() throws Exception { // given//from ww w. j ava 2 s . c o m MockServletContext context = new MockServletContext(); context.addInitParameter("fooParam", "DEVELOPMENT"); // when Stage stage = GuiceServlets.getStage(context, "fooParam"); // then assertThat(stage, is(Stage.DEVELOPMENT)); }
From source file:org.jasig.cas.web.flow.SendTicketGrantingTicketActionTests.java
@Test public void testTgtToSetRemovingOldTgt() throws Exception { final MockHttpServletResponse response = new MockHttpServletResponse(); final MockHttpServletRequest request = new MockHttpServletRequest(); final String TICKET_VALUE = "test"; request.setCookies(new Cookie[] { new Cookie("TGT", "test5") }); WebUtils.putTicketGrantingTicketInRequestScope(this.context, TICKET_VALUE); this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response)); assertEquals("success", this.action.execute(this.context).getId()); assertEquals(TICKET_VALUE, response.getCookies()[0].getValue()); }
From source file:org.motechproject.server.osgi.OsgiFrameworkServiceTest.java
private WebApplicationContext getWebApplicationContext() { GenericWebApplicationContext wac = BeanUtils.instantiateClass(GenericWebApplicationContext.class); wac.setParent(applicationContext);//from w w w.ja va2 s . com wac.setServletContext(new MockServletContext()); return wac; }
From source file:org.eclipse.virgo.snaps.core.SnapHostFilterTests.java
@Test public void testRouteToChain() throws IOException, ServletException { MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setPathInfo("/hotels/booking"); Snap snap = createMock(Snap.class); FilterChain chain = createMock(FilterChain.class); chain.doFilter(request, response);//w w w . ja v a 2s .c o m expectLastCall(); MockServletContext servletContext = new MockServletContext(); MockFilterConfig config = new MockFilterConfig(servletContext); replay(snap, chain); TestFilter filter = new TestFilter(); filter.init(config); filter.doFilter(request, response, chain); filter.destroy(); verify(snap, chain); }
From source file:newcontroller.handler.impl.DefaultRequestTest.java
@Test public void testPopulateCollection() throws Exception { HttpServletRequest request = MockMvcRequestBuilders.get("/").param("text", "aaa").param("vars", "a") .param("vars", "b").param("vars", "c").buildRequest(new MockServletContext()); Request req = new DefaultRequest(request); Bar bar = req.params(Bar.class); assertThat(bar.getText(), is("aaa")); assertThat(bar.getVars(), is(Arrays.asList("a", "b", "c"))); }