Skip to content

Instantly share code, notes, and snippets.

@jonbullock
Last active January 30, 2017 21:05
Show Gist options
  • Save jonbullock/41dde7da607afe3a78983c984f288693 to your computer and use it in GitHub Desktop.
Save jonbullock/41dde7da607afe3a78983c984f288693 to your computer and use it in GitHub Desktop.
RendererTest for path with dot in it and output file without extension
/**
* Creates a new instance of Renderer with supplied references to folders.
*
* @param db The database holding the content
* @param destination The destination folder
* @param templatesPath The templates folder
* @param config
* @param renderingEngine The instance of DelegatingTemplateEngine to use
*/
public Renderer(ContentStore db, File destination, File templatesPath, CompositeConfiguration config, DelegatingTemplateEngine renderingEngine) {
this.destination = destination;
this.config = config;
this.renderingEngine = renderingEngine;
this.db = db;
}
package org.jbake.render;
import java.io.File;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.configuration.CompositeConfiguration;
import org.jbake.app.ConfigUtil;
import org.jbake.app.ContentStore;
import org.jbake.app.Crawler;
import org.jbake.app.Renderer;
import org.jbake.app.ConfigUtil.Keys;
import org.jbake.template.DelegatingTemplateEngine;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith( MockitoJUnitRunner.class )
public class RendererTest {
@Rule
public TemporaryFolder folder = new TemporaryFolder();
private CompositeConfiguration config;
private File rootPath;
private File outputPath;
@Mock private ContentStore db;
@Mock private DelegatingTemplateEngine renderingEngine;
@Before
public void setup() throws Exception {
URL sourceUrl = this.getClass().getResource("/");
rootPath = new File(sourceUrl.getFile());
if (!rootPath.exists()) {
throw new Exception("Cannot find base path for test!");
}
outputPath = folder.newFolder("output");
config = ConfigUtil.load(rootPath);
}
/**
* See issue #300
*
* @throws Exception
*/
@Test
public void testRenderFileWorksWhenPathHasDotInButFileDoesNot() throws Exception {
final String FOLDER = "real.path";
final String FILENAME = "about";
config.setProperty(Keys.OUTPUT_EXTENSION, "");
Renderer renderer = new Renderer(db, outputPath, folder.newFolder("templates"), config, renderingEngine);
Map<String, Object> content = new HashMap<String, Object>();
content.put(Crawler.Attributes.TYPE, "page");
content.put(Crawler.Attributes.URI, "/" + FOLDER + "/" + FILENAME);
content.put(Crawler.Attributes.STATUS, "published");
renderer.render(content);
File outputFile = new File(outputPath.getAbsolutePath() + File.separatorChar + FOLDER + File.separatorChar + FILENAME);
assertThat(outputFile).isFile();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment