@Before public void setUp() throws Exception { config = (DefaultJBakeConfiguration) new ConfigUtil().loadConfig(TestUtils.getTestResourcesAsSourceFolder()); }
private CompositeConfiguration load(File source) throws ConfigurationException { if (!source.exists()) { throw new JBakeException("The given source folder '" + source.getAbsolutePath() + "' does not exist."); } if (!source.isDirectory()) { throw new JBakeException("The given source folder is not a directory."); } CompositeConfiguration config = new CompositeConfiguration(); config.setListDelimiter(','); File customConfigFile = new File(source, LEGACY_CONFIG_FILE); if (customConfigFile.exists()) { displayLegacyConfigFileWarningIfRequired(); config.addConfiguration(new PropertiesConfiguration(customConfigFile)); } customConfigFile = new File(source, CONFIG_FILE); if (customConfigFile.exists()) { config.addConfiguration(new PropertiesConfiguration(customConfigFile)); } config.addConfiguration(new PropertiesConfiguration(DEFAULT_CONFIG_FILE)); config.addConfiguration(new SystemConfiguration()); return config; }
public JBakeConfiguration loadConfig(File source) throws ConfigurationException { CompositeConfiguration configuration = load(source); return new DefaultJBakeConfiguration(source, configuration); }
/** * Creates a {@link DefaultJBakeConfiguration} * @param sourceFolder The source folder of the project * @param destination The destination folder to render and copy files to * @param isClearCache Whether to clear database cache or not * @return A configuration by given parameters * @throws ConfigurationException if loading the configuration fails */ public DefaultJBakeConfiguration createDefaultJbakeConfiguration(File sourceFolder, File destination, boolean isClearCache) throws ConfigurationException { DefaultJBakeConfiguration configuration = (DefaultJBakeConfiguration) getConfigUtil().loadConfig(sourceFolder); configuration.setDestinationFolder(destination); configuration.setClearCache(isClearCache); return configuration; }
public JBakeConfigurationFactory() { this.configUtil = new ConfigUtil(); }
@Test public void shouldThrowAnExceptionIfSourcefolderIsNotADirectory() throws Exception { File sourceFolder = mock(File.class); when(sourceFolder.exists()).thenReturn(true); when(sourceFolder.isDirectory()).thenReturn(false); try { util.loadConfig(sourceFolder); fail("Exception should be thrown if given source folder is not a directory."); } catch (JBakeException e) { assertThat(e.getMessage()).isEqualTo("The given source folder is not a directory."); } }
@BeforeEach public void setup(@TempDir Path folder) { this.sourceFolder = folder; this.util = new ConfigUtil(); }
private DefaultJBakeConfiguration stubConfig() throws ConfigurationException { File sourceFolder = TestUtils.getTestResourcesAsSourceFolder(); DefaultJBakeConfiguration configuration = (DefaultJBakeConfiguration) new ConfigUtil().loadConfig( sourceFolder ); configuration.setServerPort(8820); return configuration; }
@Test public void shouldLoadACustomConfiguration() throws Exception { File customConfigFile = new File(sourceFolder.toFile(), "jbake.properties"); BufferedWriter writer = new BufferedWriter(new FileWriter(customConfigFile)); writer.append("test.property=12345"); writer.close(); JBakeConfiguration configuration = util.loadConfig(sourceFolder.toFile()); assertThat(configuration.get("test.property")).isEqualTo("12345"); assertDefaultPropertiesPresent(configuration); }
public JBakeConfigurationFactory() { this.configUtil = new ConfigUtil(); }
public JBakeConfiguration loadConfig(File source) throws ConfigurationException { CompositeConfiguration configuration = load(source); return new DefaultJBakeConfiguration(source, configuration); }
private CompositeConfiguration load(File source) throws ConfigurationException { if (!source.exists()) { throw new JBakeException("The given source folder '" + source.getAbsolutePath() + "' does not exist."); } if (!source.isDirectory()) { throw new JBakeException("The given source folder is not a directory."); } CompositeConfiguration config = new CompositeConfiguration(); config.setListDelimiter(','); File customConfigFile = new File(source, LEGACY_CONFIG_FILE); if (customConfigFile.exists()) { displayLegacyConfigFileWarningIfRequired(); config.addConfiguration(new PropertiesConfiguration(customConfigFile)); } customConfigFile = new File(source, CONFIG_FILE); if (customConfigFile.exists()) { config.addConfiguration(new PropertiesConfiguration(customConfigFile)); } config.addConfiguration(new PropertiesConfiguration(DEFAULT_CONFIG_FILE)); config.addConfiguration(new SystemConfiguration()); return config; }
@Before public void setup() throws Exception { rootPath = TestUtils.getTestResourcesAsSourceFolder(); if (!rootPath.exists()) { throw new Exception("Cannot find base path for test!"); } config = (DefaultJBakeConfiguration) new ConfigUtil().loadConfig(rootPath); // override base template config option config.setExampleProject("freemarker", "test.zip"); }
@Test public void shouldThrowAnExceptionIfSourcefolderDoesNotExist() throws Exception { File nonExistentSourceFolder = mock(File.class); when(nonExistentSourceFolder.getAbsolutePath()).thenReturn("/tmp/nonexistent"); when(nonExistentSourceFolder.exists()).thenReturn(false); try { util.loadConfig(nonExistentSourceFolder); fail("Exception should be thrown, as source folder does not exist"); } catch (JBakeException e) { assertThat(e.getMessage()).isEqualTo("The given source folder '/tmp/nonexistent' does not exist."); } }
@BeforeEach public void setup(@TempDir Path folder) throws Exception { fixtureDir = new File(this.getClass().getResource("/fixture").getFile()); this.folder = folder; config = (DefaultJBakeConfiguration) new ConfigUtil().loadConfig(fixtureDir); config.setDestinationFolder(folder.toFile()); Assertions.assertEquals(".html", config.getOutputExtension()); }
@Test public void shouldLoadSiteHost() throws Exception { JBakeConfiguration config = util.loadConfig(TestUtils.getTestResourcesAsSourceFolder()); assertThat(config.getSiteHost()).isEqualTo("http://www.jbake.org"); }
@Before public void setup() throws Exception { File sourcePath = TestUtils.getTestResourcesAsSourceFolder(); if (!sourcePath.exists()) { throw new Exception("Cannot find base path for test!"); } outputPath = folder.newFolder("output"); config = (DefaultJBakeConfiguration) new ConfigUtil().loadConfig(sourcePath); config.setDestinationFolder(outputPath); }
@Test public void shouldLogAWarningIfAsciidocOptionCouldNotBeFound() throws Exception { File sourceFolder = TestUtils.getTestResourcesAsSourceFolder(); DefaultJBakeConfiguration config = (DefaultJBakeConfiguration) util.loadConfig(sourceFolder); config.getAsciidoctorOption("template_dirs"); verify(mockAppender, times(1)).doAppend(captorLoggingEvent.capture()); LoggingEvent loggingEvent = captorLoggingEvent.getValue(); assertThat(loggingEvent.getMessage()).isEqualTo("Cannot find asciidoctor option '{}.{}'"); }
@Test public void testGetContentRoothPath() throws Exception { File source = TestUtils.getTestResourcesAsSourceFolder(); ConfigUtil util = new ConfigUtil(); DefaultJBakeConfiguration config = (DefaultJBakeConfiguration) util.loadConfig(source); String path = FileUtil.getUriPathToContentRoot(config, new File(config.getContentFolder(), "index.html")); assertThat(path).isEqualTo(""); path = FileUtil.getUriPathToContentRoot(config, new File(config.getContentFolder(), "/blog/index.html")); assertThat(path).isEqualTo("../"); path = FileUtil.getUriPathToContentRoot(config, new File(config.getContentFolder(), "/blog/level2/index.html")); assertThat(path).isEqualTo("../../"); } }
@Test public void shouldLogWarningIfDocumentTypeNotFound() throws Exception { File sourceFolder = TestUtils.getTestResourcesAsSourceFolder(); JBakeConfiguration config = util.loadConfig(sourceFolder); config.getTemplateFileByDocType("none"); verify(mockAppender, times(1)).doAppend(captorLoggingEvent.capture()); LoggingEvent loggingEvent = captorLoggingEvent.getValue(); assertThat(loggingEvent.getMessage()).isEqualTo("Cannot find configuration key '{}' for document type '{}'"); }