List of usage examples for org.springframework.mock.web MockServletContext MockServletContext
public MockServletContext()
From source file:org.terasoluna.gfw.web.pagination.PaginationTagTest.java
protected MockPageContext createPageContext() { MockServletContext sc = new MockServletContext(); WebApplicationContext wac = mock(WebApplicationContext.class); when(wac.getServletContext()).thenReturn(sc); MockHttpServletRequest request = new MockHttpServletRequest(sc); MockHttpServletResponse response = new MockHttpServletResponse(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); return new MockPageContext(sc, request, response); }
From source file:org.eclipse.virgo.snaps.core.SnapHostFilterTests.java
@Test public void testRouteToSnap() throws ServletException, IOException { MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setServletPath("/hotels/booking"); Snap snap = createMock(Snap.class); snap.handleRequest(request, response); expectLastCall();// w w w . j ava2 s. c o m this.stubRegistry.snaps.put("/hotels", snap); MockServletContext servletContext = new MockServletContext(); MockFilterConfig config = new MockFilterConfig(servletContext); MockFilterChain chain = new MockFilterChain(); replay(snap); TestFilter filter = new TestFilter(); filter.init(config); filter.doFilter(request, response, chain); filter.destroy(); verify(snap); }
From source file:org.sventon.cache.direntrycache.DirEntryCacheUpdaterTest.java
@Test public void testUpdate() throws Exception { final RepositoryService serviceMock = mock(RepositoryService.class); assertEquals(0, entryCache.getSize()); final List<LogEntry> logEntries = new ArrayList<LogEntry>(); final SortedSet<ChangedPath> changedPaths1 = new TreeSet<ChangedPath>(); changedPaths1.add(new ChangedPath("/file1.java", null, -1, ChangeType.MODIFIED)); changedPaths1.add(new ChangedPath("/file2.abc", null, -1, ChangeType.ADDED)); changedPaths1.add(new ChangedPath("/trunk/file3.def", null, -1, ChangeType.REPLACED)); logEntries.add(createLogEntry(123, "author", new Date(), "Log message for revision 123.", changedPaths1)); final SortedSet<ChangedPath> changedPaths2 = new TreeSet<ChangedPath>(); changedPaths2.add(new ChangedPath("/branch", "/trunk", 123, ChangeType.ADDED)); changedPaths2.add(new ChangedPath("/trunk/file3.def", null, -1, ChangeType.DELETED)); logEntries.add(createLogEntry(124, "author", new Date(), "Log message for revision 124.", changedPaths2)); 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); when(serviceMock.getLatestRevision(null)).thenReturn(124L); when(serviceMock.getEntryInfo(null, "/file1.java", 123)) .thenReturn(new DirEntry("/", "file1.java", "author", new Date(), DirEntry.Kind.FILE, 123, 12345)); when(serviceMock.getEntryInfo(null, "/file2.abc", 123)) .thenReturn(new DirEntry("/", "file2.abc", "author", new Date(), DirEntry.Kind.FILE, 123, 12345)); when(serviceMock.getEntryInfo(null, "/trunk/file3.def", 123)).thenReturn( new DirEntry("/trunk", "file3.def", "author", new Date(), DirEntry.Kind.FILE, 123, 12345)); when(serviceMock.getEntryInfo(null, "/branch", 124)) .thenReturn(new DirEntry("/", "branch", "author", new Date(), DirEntry.Kind.DIR, 123, 12345)); when(serviceMock.list(null, "/branch/", 124)) .thenReturn(new DirList(Collections.<DirEntry>emptyList(), new Properties())); when(serviceMock.getEntryInfo(null, "/trunk/file3.def", 123)).thenReturn( new DirEntry("/trunk", "file3.def", "author", new Date(), DirEntry.Kind.FILE, 123, 12345)); final RepositoryName repositoryName = new RepositoryName("defaultsvn"); final RevisionUpdate revisionUpdate = new RevisionUpdate(repositoryName, logEntries, false); final DirEntryCacheUpdater cacheUpdater = new DirEntryCacheUpdater(null, application); cacheUpdater.setRepositoryService(serviceMock); cacheUpdater.updateInternal(entryCache, null, revisionUpdate); Thread.sleep(500L); // TODO: Get rid of this! assertEquals(4, entryCache.getSize()); }
From source file:net.node42.filter.SimpleTimeoutLoadLimitingFilterTest.java
@Test public void testSpecifiedSettings() throws Exception { final SimpleTimeoutLoadLimitingFilter target = new SimpleTimeoutLoadLimitingFilter(); final MockFilterConfig filterConfig = new MockFilterConfig(new MockServletContext()); filterConfig.addInitParameter("request_count_concurrent_max", "1"); filterConfig.addInitParameter("request_count_check_interval", "1000"); filterConfig.addInitParameter("request_timeout", "2000"); filterConfig.addInitParameter("response_timeout_file_name", "target/test-classes/ILuvLinux.txt"); target.init(filterConfig);/*from www.ja va 2s . c o m*/ assertThat(target.maxConcurrentRequests).isNotNull().isEqualTo(1); assertThat(target.requestCountCheckInterval).isNotNull().isEqualTo(1000L); assertThat(target.requestTimeoutMillis).isNotNull().isEqualTo(2000L); assertThat(target.timeoutResponseContent).isNotNull() .isEqualTo("It's true.\n\nThis is just a stub file for targeting some unit tests."); }
From source file:org.springsource.restbucks.PaymentProcessIntegrationTest.java
@BeforeClass public static void beforeClass() { MockServletContext servletContext = new MockServletContext(); osivFilter = new OpenEntityManagerInViewFilter(); osivFilter.setServletContext(servletContext); servletApplicationContext = new AnnotationConfigWebApplicationContext(); servletApplicationContext.register(WebConfiguration.class); servletApplicationContext.setParent(new AnnotationConfigApplicationContext(ApplicationConfig.class)); servletApplicationContext.setServletContext(servletContext); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, servletApplicationContext);/* w ww. j a va 2s . c o m*/ servletApplicationContext.refresh(); mvc = MockMvcBuilders.webAppContextSetup(servletApplicationContext). // addFilter(new ShallowEtagHeaderFilter()). // addFilter(osivFilter). // build(); links = new DefaultLinkDiscoverer(); }
From source file:ar.com.zauber.commons.web.uri.assets.AssetsTest.java
/** test */ @Test/*from w w w . jav a2s.c o m*/ public final void testAssetsUriFactory() throws Exception { // Creado el servlet final XmlWebApplicationContext ctx = new XmlWebApplicationContext(); ctx.setConfigLocations(new String[] { "classpath:ar/com/zauber/commons/web/uri/assets/" + profile + "-assets-spring.xml", }); ctx.setServletContext(new MockServletContext()); ctx.refresh(); for (int i = 0; i < 2; i++) { // Armo el request final PageContext pageCtx = createPageContext(ctx); // <assets:javascript key="/_js/lib/jquery-1.4.2.js"/> JavascriptTag js = new JavascriptTag(); js.setPageContext(pageCtx); js.setKey("/_js/lib/jquery-1.4.2.js"); js.doStartTag(); js.doEndTag(); // <assets:javascript key="/_js/model/foo.js"/> js = new JavascriptTag(); js.setPageContext(pageCtx); js.setKey("/_js/model/foo.js"); js.setCharset("utf-8"); js.doStartTag(); js.doEndTag(); // <assets:css key="/stylesheet.css"/> final CssTag t = new CssTag(); t.setPageContext(pageCtx); t.setCharset("utf-8"); t.setKey("/stylesheet.css"); t.doStartTag(); t.doEndTag(); // <assets:css key="/stylesheet.css"/> final ImageTag image = new ImageTag(); image.setPageContext(pageCtx); image.setKey("/1.gif"); image.doStartTag(); image.doEndTag(); // <assets:print/> final PrintTag printTag = new PrintTag(); printTag.setPageContext(pageCtx); printTag.doStartTag(); printTag.doEndTag(); // Validaciones final MockHttpServletResponse response = (MockHttpServletResponse) pageCtx.getResponse(); final String result = new String(response.getContentAsByteArray(), "utf8"); final InputStream is = getClass().getResourceAsStream(profile + "-expected.txt"); try { Assert.assertEquals(IOUtils.toString(is), result); } finally { is.close(); } } }
From source file:com.github.woonsan.katharsis.servlet.KatharsisServletTest.java
@Before public void before() throws Exception { katharsisServlet = new SampleKatharsisServlet(); servletContext = new MockServletContext(); ((MockServletContext) servletContext).setContextPath(""); servletConfig = new MockServletConfig(servletContext); ((MockServletConfig) servletConfig).addInitParameter( SampleKatharsisServlet.INIT_PARAM_RESOURCE_SEARCH_PACKAGE, RESOURCE_SEARCH_PACKAGE); ((MockServletConfig) servletConfig).addInitParameter( SampleKatharsisServlet.INIT_PARAM_RESOURCE_DEFAULT_DOMAIN, RESOURCE_DEFAULT_DOMAIN); katharsisServlet.init(servletConfig); }
From source file:org.jasig.cas.web.flow.InitialFlowSetupActionTests.java
public void testSettingContextPath() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final String CONST_CONTEXT_PATH = "/test"; request.setContextPath(CONST_CONTEXT_PATH); final MockRequestContext context = new MockRequestContext(); context.setExternalContext(//from w ww .ja v a 2s . c om 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()); }
From source file:org.codehaus.groovy.grails.commons.test.AbstractGrailsMockTests.java
protected MockServletContext createMockServletContext() { return new MockServletContext(); }
From source file:com.github.woonsan.katharsis.servlet.KatharsisFilterTest.java
@Before public void before() throws Exception { katharsisFilter = new SampleKatharsisFilter(); servletContext = new MockServletContext(); ((MockServletContext) servletContext).setContextPath(""); filterConfig = new MockFilterConfig(servletContext); ((MockFilterConfig) filterConfig).addInitParameter("filterBasePath", "/api"); ((MockFilterConfig) filterConfig).addInitParameter(SampleKatharsisFilter.INIT_PARAM_RESOURCE_SEARCH_PACKAGE, RESOURCE_SEARCH_PACKAGE);//from ww w . j a v a2 s.c om ((MockFilterConfig) filterConfig).addInitParameter(SampleKatharsisFilter.INIT_PARAM_RESOURCE_DEFAULT_DOMAIN, RESOURCE_DEFAULT_DOMAIN); katharsisFilter.init(filterConfig); }