@Before
  public void setup() throws Exception, IOException, URISyntaxException {
    URL sourceUrl = this.getClass().getResource("/");

    sourceFolder = new File(sourceUrl.getFile());
    if (!sourceFolder.exists()) {
      throw new Exception("Cannot find sample data structure!");
    }

    destinationFolder = folder.getRoot();

    templateFolder = new File(sourceFolder, templateDir);
    if (!templateFolder.exists()) {
      throw new Exception("Cannot find template folder!");
    }

    config = ConfigUtil.load(new File(this.getClass().getResource("/").getFile()));
    Iterator<String> keys = config.getKeys();
    while (keys.hasNext()) {
      String key = keys.next();
      if (key.startsWith("template") && key.endsWith(".file")) {
        String old = (String) config.getProperty(key);
        config.setProperty(key, old.substring(0, old.length() - 4) + "." + templateExtension);
      }
    }
    Assert.assertEquals(".html", config.getString(ConfigUtil.Keys.OUTPUT_EXTENSION));
    db = DBUtil.createDataStore("memory", "documents" + System.currentTimeMillis());
  }
  @Test
  public void renderSitemap() throws Exception {
    DocumentTypes.addDocumentType("paper");
    DBUtil.updateSchema(db);

    renderer.renderSitemap("sitemap.xml");
    File outputFile = new File(destinationFolder, "sitemap.xml");
    Assert.assertTrue(outputFile.exists());

    // verify
    String output = FileUtils.readFileToString(outputFile, Charset.defaultCharset());
    for (String string : getOutputStrings("sitemap")) {
      assertThat(output).contains(string);
    }
    assertThat(output).doesNotContain("draft-paper.html");
  }
  @Test
  public void renderSitemap() throws Exception {
    DocumentTypes.addDocumentType("paper");
    DBUtil.updateSchema(db);

    Crawler crawler = new Crawler(db, sourceFolder, config);
    crawler.crawl(new File(sourceFolder.getPath() + File.separator + "content"));
    Renderer renderer = new Renderer(db, destinationFolder, templateFolder, config);
    renderer.renderSitemap("sitemap.xml");
    File outputFile = new File(destinationFolder, "sitemap.xml");
    Assert.assertTrue(outputFile.exists());

    // verify
    String output = FileUtils.readFileToString(outputFile);
    for (String string : getOutputStrings("sitemap")) {
      assertThat(output).contains(string);
    }
    assertThat(output).doesNotContain("draft-paper.html");
  }
  @Before
  public void setup() throws Exception {
    currentLocale = Locale.getDefault();
    Locale.setDefault(Locale.ENGLISH);

    ModelExtractorsDocumentTypeListener listener = new ModelExtractorsDocumentTypeListener();
    DocumentTypes.addListener(listener);

    URL sourceUrl = this.getClass().getResource("/");

    sourceFolder = new File(sourceUrl.getFile());
    if (!sourceFolder.exists()) {
      throw new Exception("Cannot find sample data structure!");
    }

    destinationFolder = folder.getRoot();

    templateFolder = new File(sourceFolder, templateDir);
    if (!templateFolder.exists()) {
      throw new Exception("Cannot find template folder!");
    }

    config = ConfigUtil.load(new File(this.getClass().getResource("/").getFile()));
    Iterator<String> keys = config.getKeys();
    while (keys.hasNext()) {
      String key = keys.next();
      if (key.startsWith("template") && key.endsWith(".file")) {
        String old = (String) config.getProperty(key);
        config.setProperty(key, old.substring(0, old.length() - 4) + "." + templateExtension);
      }
    }
    Assert.assertEquals(".html", config.getString(ConfigUtil.Keys.OUTPUT_EXTENSION));
    db = DBUtil.createDataStore("memory", "documents" + System.currentTimeMillis());

    crawler = new Crawler(db, sourceFolder, config);
    crawler.crawl(new File(sourceFolder.getPath() + File.separator + "content"));
    parser = new Parser(config, sourceFolder.getPath());
    renderer = new Renderer(db, destinationFolder, templateFolder, config);

    setupExpectedOutputStrings();
  }