コード例 #1
0
  @Test
  public void renderPost() throws Exception {
    // setup
    Crawler crawler = new Crawler(db, sourceFolder, config);
    crawler.crawl(new File(sourceFolder.getPath() + File.separator + "content"));
    Parser parser = new Parser(config, sourceFolder.getPath());
    Renderer renderer = new Renderer(db, destinationFolder, templateFolder, config);
    String filename = "second-post.html";

    File sampleFile =
        new File(
            sourceFolder.getPath()
                + File.separator
                + "content"
                + File.separator
                + "blog"
                + File.separator
                + "2013"
                + File.separator
                + filename);
    Map<String, Object> content = parser.processFile(sampleFile);
    content.put(Crawler.Attributes.URI, "/" + filename);
    renderer.render(content);
    File outputFile = new File(destinationFolder, filename);
    Assert.assertTrue(outputFile.exists());

    // verify
    String output = FileUtils.readFileToString(outputFile);
    for (String string : getOutputStrings("post")) {
      assertThat(output).contains(string);
    }
  }
コード例 #2
0
  @Test
  public void renderArchive() throws Exception {
    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.renderArchive("archive.html");
    File outputFile = new File(destinationFolder, "archive.html");
    Assert.assertTrue(outputFile.exists());

    // verify
    String output = FileUtils.readFileToString(outputFile);
    for (String string : getOutputStrings("archive")) {
      assertThat(output).contains(string);
    }
  }
コード例 #3
0
  @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");
  }
コード例 #4
0
  @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();
  }