Skip to content

Commit

Permalink
rebase to master. make OventTest pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
ancho committed May 9, 2017
1 parent 2113539 commit 9f91a7f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public String getTemplateFolderName() {
}

@Override
public String getContentFolderName() {
public String getContentFolderName() {
return getAsString(CONTENT_FOLDER);
}

Expand Down Expand Up @@ -342,7 +342,7 @@ public void setTemplateFolder(File templateFolder) {
setProperty(TEMPLATE_FOLDER_KEY, templateFolder);
}

private void setContentFolder(File contentFolder) {
public void setContentFolder(File contentFolder) {
setProperty(CONTENT_FOLDER_KEY, contentFolder);
}

Expand Down Expand Up @@ -448,22 +448,21 @@ private void setupPathsRelativeToSourceFile() {
}

private void setupDefaultContentFolder() {
String destinationPath = (String) get(CONTENT_FOLDER);
setContentFolder(new File(getSourceFolder(),destinationPath));
setContentFolder(new File(getSourceFolder(),getContentFolderName()));
}

private void setupDefaultDestination() {
String destinationPath = (String) get(DESTINATION_FOLDER);
String destinationPath = getAsString(DESTINATION_FOLDER);
setDestinationFolder(new File(getSourceFolder(),destinationPath));
}

private void setupDefaultAssetFolder() {
String assetFolder = (String) get(ASSET_FOLDER);
String assetFolder = getAsString(ASSET_FOLDER);
setAssetFolder(new File(getSourceFolder(), assetFolder));
}

private void setupDefaultTemplateFolder() {
String destinationPath = (String) get(TEMPLATE_FOLDER);
String destinationPath = getAsString(TEMPLATE_FOLDER);
setTemplateFolder(new File(getSourceFolder(),destinationPath));
}

Expand Down
40 changes: 13 additions & 27 deletions src/test/java/org/jbake/app/OvenTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.jbake.app.configuration.ConfigUtil;
import org.jbake.app.configuration.DefaultJBakeConfiguration;
import org.jbake.model.DocumentTypes;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand All @@ -24,10 +25,11 @@ public class OvenTest {

@Before
public void setUp() throws Exception {
// reset values to known state otherwise previous test case runs can affect the success of this test case
DocumentTypes.resetDocumentTypes();
sourceFolder = new File(this.getClass().getResource("/").getPath());
configuration = (DefaultJBakeConfiguration) new ConfigUtil().loadConfig(sourceFolder);
configuration.setDestinationFolder(folder.newFolder("output"));
configuration.setTemplatePath("freemarkerTemplates");
}

@After
Expand All @@ -36,34 +38,18 @@ public void tearDown() throws Exception {
contentStore.close();
contentStore.shutdown();
}

}

@Test
public void bakeWithRelativePaths() throws IOException, ConfigurationException {
final Oven oven = new Oven(configuration);
oven.setupPaths();
oven.bake();

assertThat("There shouldn't be any errors: " + oven.getErrors(), oven.getErrors().isEmpty());
}

@Test
public void bakeWithAbsolutePaths() throws IOException, ConfigurationException {
makeAbsolute(config, rootPath, Key.TEMPLATE_FOLDER.toString());
makeAbsolute(config, rootPath, Key.CONTENT_FOLDER.toString());
makeAbsolute(config, rootPath, Key.ASSET_FOLDER.toString());
public void bakeWithAbsolutePaths() {
configuration.setTemplateFolder( new File(sourceFolder, "freemarkerTemplates") );
configuration.setContentFolder( new File(sourceFolder, "content") );
configuration.setAssetFolder( new File(sourceFolder, "assets") );

final Oven oven = new Oven(rootPath, outputPath, config, true);
oven.setupPaths();
final Oven oven = new Oven(configuration);
oven.bake();

assertThat("There shouldn't be any errors: " + oven.getErrors(), oven.getErrors().isEmpty());
}

private void makeAbsolute(Configuration configuration, File source, String key) {
final File folder = new File(source, configuration.getString(key));
configuration.setProperty(key, folder.getAbsolutePath());
assertThat(oven.getErrors()).isEmpty();
}

@Test(expected = JBakeException.class)
Expand All @@ -76,8 +62,8 @@ public void should_throw_exception_if_source_folder_does_not_exist() throws Exce
public void should_instantiate_needed_Utensils() throws Exception {

configuration.setTemplateFolder( folder.newFolder("template") );
configuration.setTemplateFolder( folder.newFolder("content") );
configuration.setTemplateFolder( folder.newFolder("assets") );
configuration.setContentFolder( folder.newFolder("content") );
configuration.setAssetFolder( folder.newFolder("assets") );

Oven oven = new Oven(configuration);

Expand All @@ -102,8 +88,8 @@ public void should_inspect_configuration_during_instantiation_from_utils() throw
@Test
public void should_crawl_render_and_copy_assets() throws Exception {
configuration.setTemplateFolder( folder.newFolder("template") );
configuration.setTemplateFolder( folder.newFolder("content") );
configuration.setTemplateFolder( folder.newFolder("assets") );
configuration.setContentFolder( folder.newFolder("content") );
configuration.setAssetFolder( folder.newFolder("assets") );

contentStore = spy(new ContentStore("memory", "documents"+ System.currentTimeMillis()));

Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/jbake/app/configuration/ConfigUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ public void should_return_template_folder_from_configuration() throws Exception
assertThat(config.getTemplateFolder()).isEqualTo(expectedDestinationFolder);
}

@Test
public void should_return_content_folder_from_configuration() throws Exception {
File sourceFolder = getTestResourcesAsSourceFolder();
File expectedDestinationFolder = new File(sourceFolder,"content");
JBakeConfiguration config = util.loadConfig(sourceFolder);

assertThat(config.getContentFolder()).isEqualTo(expectedDestinationFolder);
}

@Test
public void should_get_template_file_doctype() throws Exception {
File sourceFolder = getTestResourcesAsSourceFolder();
Expand Down

0 comments on commit 9f91a7f

Please sign in to comment.