List of usage examples for org.springframework.mock.web MockServletContext MockServletContext
public MockServletContext()
From source file:org.araneaframework.tests.integration.SmokeTests.java
public ServletServiceAdapterComponent initAdapter(String configFile) throws Exception { if (servlet == null) { servlet = new MockServlet(); }/*from w w w .j av a 2 s .c o m*/ ServletServiceAdapterComponent comp = (ServletServiceAdapterComponent) initedAdapters.get(configFile); if (comp == null) { servlet.setConfFile(configFile); servlet.init(new MockServletConfig(new MockServletContext())); initedAdapters.put(configFile, comp); return servlet.getBuiltComponent(); } return comp; }
From source file:org.sventon.appl.ApplicationTest.java
@Test public void testPersistRepositoryConfigurations() throws Exception { final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("sventon-test"); configDirectory.setServletContext(servletContext); final File repos1 = new File(configDirectory.getRepositoriesDirectory(), "testrepos1"); final File repos2 = new File(configDirectory.getRepositoriesDirectory(), "testrepos2"); final Application application = new Application(configDirectory); application.setConfigurationFileName(CONFIG_FILE_NAME); final RepositoryConfiguration repositoryConfiguration1 = new RepositoryConfiguration("testrepos1"); repositoryConfiguration1.setRepositoryUrl("http://localhost/1"); repositoryConfiguration1.setUserCredentials(new Credentials("user1", "abc123")); repositoryConfiguration1.setCacheUsed(false); repositoryConfiguration1.setZippedDownloadsAllowed(false); final RepositoryConfiguration repositoryConfiguration2 = new RepositoryConfiguration("testrepos2"); repositoryConfiguration2.setRepositoryUrl("http://localhost/2"); repositoryConfiguration2.setUserCredentials(new Credentials("user2", "123abc")); repositoryConfiguration2.setCacheUsed(false); repositoryConfiguration2.setZippedDownloadsAllowed(false); application.addConfiguration(repositoryConfiguration1); application.addConfiguration(repositoryConfiguration2); assertFalse(new File(repos1, CONFIG_FILE_NAME).exists()); assertFalse(new File(repos2, CONFIG_FILE_NAME).exists()); application.persistRepositoryConfigurations(); //File should now be written assertTrue(new File(repos1, CONFIG_FILE_NAME).exists()); assertTrue(new File(repos2, CONFIG_FILE_NAME).exists()); }
From source file:org.jasig.cas.web.flow.GenerateServiceTicketActionTests.java
@Test public void testServiceTicketFromCookie() throws Exception { MockRequestContext context = new MockRequestContext(); context.getFlowScope().put("service", TestUtils.getService()); context.getFlowScope().put("ticketGrantingTicketId", this.ticketGrantingTicket); MockHttpServletRequest request = new MockHttpServletRequest(); context.setExternalContext(/*from w w w .j a v a2 s.co m*/ new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse())); request.addParameter("service", "service"); request.setCookies(new Cookie[] { new Cookie("TGT", this.ticketGrantingTicket) }); this.action.execute(context); assertNotNull(WebUtils.getServiceTicketFromRequestScope(context)); }
From source file:org.soybeanMilk.test.unit.web.TestDispatchServlet.java
@Before public void setUp() { servletContext = new MockServletContext(); servletInitParameters = new HashMap<String, String>(); servletInitParameters.put(WebConstants.ServletInitParams.SOYBEAN_MILK_CONFIG, mySoybeanMilkFile); }
From source file:edu.internet2.middleware.shibboleth.idp.system.conf1.ShibbolethSSOTestCase.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(); MockHttpServletResponse servletResponse = new MockHttpServletResponse(); ProfileHandlerManager handlerManager = (ProfileHandlerManager) getApplicationContext() .getBean("shibboleth.HandlerManager"); AbstractShibbolethProfileHandler handler = (AbstractShibbolethProfileHandler) handlerManager .getProfileHandler(servletRequest); assertNotNull(handler);/*from w w w . j a v a 2s . co m*/ // Process request HTTPInTransport profileRequest = new HttpServletRequestAdapter(servletRequest); HTTPOutTransport profileResponse = new HttpServletResponseAdapter(servletResponse, false); handler.processRequest(profileRequest, profileResponse); servletRequest.setCookies(servletResponse.getCookies()); ShibbolethSSOLoginContext loginContext = (ShibbolethSSOLoginContext) 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("/shibboleth/SSO", loginContext.getProfileHandlerURL()); assertEquals("urn:example.org:sp1", loginContext.getRelyingPartyId()); assertEquals(0, loginContext.getRequestedAuthenticationMethods().size()); assertEquals("https://example.org/mySP", loginContext.getSpAssertionConsumerService()); assertEquals("https://example.org/mySP", loginContext.getSpAssertionConsumerService()); assertTrue(servletResponse.getRedirectedUrl().endsWith("/AuthnEngine")); }
From source file:com.github.mike10004.stormpathacctmgr.NewPasswordFormServletTest.java
@Test public void testDoGet() throws Exception { System.out.println("NewPasswordFormServletTest.testDoGet"); String emailAddress = "somebody@example.com"; String token = "981ng9014ng4nh9014h901nh4jhqg8rejg089rjg09zahg49hqg08"; final Application application = createNiceMock(Application.class); Account account = createNiceMock(Account.class); final RequestDispatcher requestDispatcher = createNiceMock(RequestDispatcher.class); MockHttpServletResponse mockResponse = new MockHttpServletResponse(); MockHttpServletRequest mockRequest = new MockHttpServletRequest() { @Override// w w w . ja v a2s . com public RequestDispatcher getRequestDispatcher(String path) { assertEquals(NewPasswordFormServlet.RESET_ENTER_NEW_PASSWORD_JSP_PATH, path); return requestDispatcher; } }; mockRequest.setParameter(PasswordReset.PARAM_RESET_TOKEN, token); requestDispatcher.forward(mockRequest, mockResponse); EasyMock.expectLastCall().times(1); expect(account.getEmail()).andReturn(emailAddress).anyTimes(); expect(application.verifyPasswordResetToken(token)).andReturn(account).times(1); replay(application, account, requestDispatcher); final Stormpaths stormpaths = new Stormpaths() { @Override public Application buildApplication() { return application; } }; NewPasswordFormServlet instance = new NewPasswordFormServlet() { @Override protected Stormpaths createStormpaths() { return stormpaths; } }; MockServletContext servletContext = new MockServletContext(); instance.init(new MockServletConfig(servletContext)); instance.doGet(mockRequest, mockResponse); String actualTargetEmailAttribute = (String) mockRequest .getAttribute(NewPasswordFormServlet.ATTR_TARGET_EMAIL); System.out.println("email attribute: " + actualTargetEmailAttribute); assertEquals(emailAddress, actualTargetEmailAttribute); System.out.println("status: " + mockResponse.getStatus()); assertEquals(HttpServletResponse.SC_OK, mockResponse.getStatus()); }
From source file:nl.surfnet.coin.shared.log.ApiCallLogServiceImplTest.java
@Before public void init() { service = new ApiCallLogServiceImpl(super.getJdbcTemplate()); ApiCallLogContextListener listener = new ApiCallLogContextListener(); ServletRequestEvent requestEvent = new ServletRequestEvent(new MockServletContext(), new MockHttpServletRequest("GET", "http://127.0.0.1/social/people/test")); listener.requestInitialized(requestEvent); }
From source file:org.hdiv.web.servlet.view.freemarker.FreeMarkerViewTests.java
@Test public void testNoFreeMarkerConfig() throws Exception { FreeMarkerView fv = new FreeMarkerView(); MockControl wmc = MockControl.createControl(WebApplicationContext.class); WebApplicationContext wac = (WebApplicationContext) wmc.getMock(); wac.getBeansOfType(FreeMarkerConfig.class, true, false); wmc.setReturnValue(new HashMap()); wac.getParentBeanFactory();//from w ww . j a v a 2 s.c om wmc.setReturnValue(null); wac.getServletContext(); wmc.setReturnValue(new MockServletContext()); wmc.replay(); fv.setUrl("anythingButNull"); try { fv.setApplicationContext(wac); fv.afterPropertiesSet(); fail("Should have thrown BeanDefinitionStoreException"); } catch (ApplicationContextException ex) { // Check there's a helpful error message assertTrue(ex.getMessage().indexOf("FreeMarkerConfig") != -1); } wmc.verify(); }
From source file:org.sventon.web.tags.UrlTagTest.java
protected MockPageContext createPageContext() { final MockServletContext sc = new MockServletContext(); final MockHttpServletRequest request = new MockHttpServletRequest(sc); final MockHttpServletResponse response = new MockHttpServletResponse(); request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, Mockito.mock(WebApplicationContext.class)); return new MockPageContext(sc, request, response); }
From source file:org.terasoluna.gfw.web.message.MessagesPanelTagTest.java
/** * create mock PageContext.//from w ww. jav a2s . c o m */ protected MockPageContext createPageContext() { MockServletContext sc = new MockServletContext(); wac = mock(WebApplicationContext.class); when(wac.getMessage(eq("hello.world"), eq(new Object[] {}), (Locale) anyObject())) .thenReturn("hello world!"); when(wac.getMessage(eq("foo.bar"), eq(new Object[] { 1, 2 }), (Locale) anyObject())) .thenReturn("foo1 and bar2"); when(wac.getServletContext()).thenReturn(sc); request = new MockHttpServletRequest(sc); MockHttpServletResponse response = new MockHttpServletResponse(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); return new MockPageContext(sc, request, response); }