ConfigDirectory implements ServletContextAware { public ConfigDirectory(final File sventonConfigDirectory, final String exportDirectoryName, final String repositoriesDirectoryName) { this.sventonConfigDirectory = sventonConfigDirectory; this.exportDirectoryName = exportDirectoryName; this.repositoriesDirectoryName = repositoriesDirectoryName; } ConfigDirectory(final File sventonConfigDirectory, final String exportDirectoryName,
                         final String repositoriesDirectoryName); void setCreateDirectories(final boolean createDirectories); @Override void setServletContext(final ServletContext servletContext); File getConfigRootDirectory(); String getContextPath(); ConfigDirectoryFactory createConfigDirectoryFactory(); File getExportDirectory(); File getRepositoriesDirectory(); static final String PROPERTY_KEY_SVENTON_DIR_SYSTEM; }
@Test public void testConfigDirectory() throws Exception { final ConfigDirectory configDir = new ConfigDirectory(TEMP_DIR, EXPORT_DIR, REPOSITORIES_DIR); configDir.setCreateDirectories(false); try { configDir.getConfigRootDirectory(); fail("Should cause IllegalStateException"); } catch (IllegalStateException e) { } try { configDir.getExportDirectory(); fail("Should cause IllegalStateException"); } catch (IllegalStateException e) { } try { configDir.getRepositoriesDirectory(); fail("Should cause IllegalStateException"); } catch (IllegalStateException e) { } 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)); }