List of usage examples for org.springframework.mock.web MockServletContext setContextPath
public void setContextPath(String contextPath)
From source file:ar.com.zauber.commons.web.uri.factory.ServletPathUriFactoryTest.java
/** test case */ @Test// w w w .j a v a 2s .c o m public final void testServletPath() { MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("my-path/"); ServletPathUriFactory uriFactory = new ServletPathUriFactory(new IdentityUriFactory()); uriFactory.setServletContext(servletContext); assertEquals("my-path/hello", uriFactory.buildUri("hello")); }
From source file:org.eclipse.virgo.web.core.internal.StubWebApplication.java
StubWebApplication(String contextPath) { MockServletContext mockServletContext = new MockServletContext(); mockServletContext.setContextPath(contextPath); this.servletContext = mockServletContext; }
From source file:org.sventon.cache.DefaultCacheGatewayTest.java
private CacheGateway createCache() throws CacheException { final ConfigDirectory configDirectory = TestUtils.getTestConfigDirectory(); configDirectory.setCreateDirectories(false); final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("sventon-test"); configDirectory.setServletContext(servletContext); final DirEntryCacheManager cacheManager = new DirEntryCacheManager(configDirectory); final DirEntryCache entryCache = new CompassDirEntryCache(new File("test")); entryCache.init();//w ww . j ava 2 s. com cacheManager.addCache(repositoryName, entryCache); for (DirEntry dirEntry : TestUtils.getDirectoryList()) { entryCache.add(dirEntry); } final DefaultCacheGateway cache = new DefaultCacheGateway(); cache.setEntryCacheManager(cacheManager); return cache; }
From source file:ar.com.zauber.commons.web.uri.factory.ConfigurableUriFactoryFactoryBeanTest.java
/** creates the factory bean */ @Before// ww w .j a v a 2 s. com public final void testCreateFactoryBean() { MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("/my-path"); this.factoryBean = new ConfigurableUriFactoryFactoryBean(new IdentityUriFactory()); this.factoryBean.setServletContext(servletContext); }
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:org.sventon.web.filter.ConfigAuthorizationFilterTest.java
@Before public void setUp() throws Exception { ConfigDirectory configDirectory = TestUtils.getTestConfigDirectory(); configDirectory.setCreateDirectories(false); final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("sventon-test"); configDirectory.setServletContext(servletContext); application = new Application(configDirectory); }
From source file:org.sventon.appl.ConfigDirectoryTest.java
@Test public void testConfigDirectory() throws Exception { final ConfigDirectory configDir = new ConfigDirectory(TEMP_DIR, EXPORT_DIR, REPOSITORIES_DIR); configDir.setCreateDirectories(false); try {/*w w w . j av a2 s. com*/ configDir.getConfigRootDirectory(); fail("Should cause IllegalStateException"); } catch (IllegalStateException e) { // expected } try { configDir.getExportDirectory(); fail("Should cause IllegalStateException"); } catch (IllegalStateException e) { // expected } try { configDir.getRepositoriesDirectory(); fail("Should cause IllegalStateException"); } catch (IllegalStateException e) { // expected } final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath(SERVLET_CONTEXT_PATH); configDir.setServletContext(servletContext); assertTrue(configDir.getConfigRootDirectory().getAbsolutePath().endsWith(SERVLET_CONTEXT_PATH)); assertTrue(configDir.getExportDirectory().getAbsolutePath() .endsWith(SERVLET_CONTEXT_PATH + SEPARATOR + EXPORT_DIR)); assertTrue(configDir.getRepositoriesDirectory().getAbsolutePath() .endsWith(SERVLET_CONTEXT_PATH + SEPARATOR + REPOSITORIES_DIR)); }
From source file:org.sventon.web.ctrl.SubmitConfigurationsControllerTest.java
@Before public void setUp() throws Exception { configDirectory = TestUtils.getTestConfigDirectory(); configDirectory.setCreateDirectories(false); final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("sventon-test"); configDirectory.setServletContext(servletContext); application = new Application(configDirectory); application.setConfigurationFileName(TestUtils.CONFIG_FILE_NAME); }
From source file:org.sventon.web.ctrl.template.DirEntryTrayControllerTest.java
@Before public void setUp() 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("test"); configuration.setEnableEntryTray(true); application.addConfiguration(configuration); entry = new DirEntry("/", "/trunk/test", "", null, DirEntry.Kind.FILE, 0, 0); command.setPath("/trunk/test"); command.setName(new RepositoryName("test")); command.setRevision(Revision.create(10)); command.setPegRevision(Revision.create(5)); mockService = EasyMock.createMock(RepositoryService.class); request = new MockHttpServletRequest(); ctrl = new DirEntryTrayController(); ctrl.setRepositoryService(mockService); ctrl.setApplication(application);/*from w w w . j ava 2s.com*/ context = new UserRepositoryContext(); }
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()); }