Webiyo

This page was generated using Webiyo. See its source code and unit tests.

org/webiyo/examples/sourceforge/ChangeLogPageTest.java

package org.webiyo.examples.sourceforge;

import junit.framework.TestCase;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Text;
import org.webiyo.util.test.ElementChecker;
import org.webiyo.web.Renderable;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

public class ChangeLogPageTest extends TestCase {

    private ChangeLog log;
    private FakeProject project;

    protected void setUp() throws Exception {
        super.setUp();
        log = new ChangeLog();

        project = new FakeProject(log, new File("."), Project.WEBIYO_SOURCE_DIRS);
    }

    public void testEmptyLog() throws Exception {
        ChangeLogPage changeLogPage = new ChangeLogPage(project);
        SourceForgePageChecker page = new SourceForgePageChecker((Renderable) changeLogPage);
        page.checkBasics("Webiyo - Development History", "");
        page.checkSeeSource("src/org/webiyo/examples/sourceforge/ChangeLogPage.html",
                            "src/org/webiyo/examples/sourceforge/ChangeLogPageTest.html");
        page.checkText("Development History", "//div[@class='changelog']/h2");
        page.checkText("No entries found", "//div[@class='changelog']/p");
    }

    public void testOneEntry() throws Exception {
        addLog("2005/04/01 20:30:12", "skybrian", "Hello, world!\nSecond line\n");

        ChangeLogPage changeLogPage = new ChangeLogPage(project);
        SourceForgePageChecker page = new SourceForgePageChecker(changeLogPage);
        page.checkBasics("Webiyo - Development History", "");

        ElementChecker changelog = page.navigateTo("//div[@class='changelog']");

        changelog.checkText("April 1, 2005", "div/h3");
        changelog.checkText("skybrian", "div/dl/dt");

        // check that the log entry has a <br> between the two lines
        Iterator<Node> it = changelog.navigateTo("div/dl/dd").children().iterator();

        Text text = (Text) it.next();
        assertEquals("Hello, world!\n", text.getWholeText());

        Element br = (Element) it.next();
        assertEquals("br", br.getNodeName());

        Text text2 = (Text) it.next();
        assertEquals("\nSecond line", text2.getWholeText());

        assertFalse(it.hasNext());
    }

    public void testDivideUpEntriesByDate() throws Exception {
        addLog("2005/04/01 20:30:12", "skybrian", "Hello, world!");
        addLog("2005/04/01 21:30:12", "skybrian", "Same day change");
        addLog("2005/04/02 22:01:02", "skybrian", "Next day change");

        ChangeLogPage changeLogPage = new ChangeLogPage(project);

        SourceForgePageChecker page = new SourceForgePageChecker(changeLogPage);
        page.checkBasics("Webiyo - Development History", "");

        ElementChecker changelog = page.navigateTo("//div[@class='changelog']");

        ElementChecker april2 = changelog.navigateTo("div[1]");

        april2.checkText("April 2, 2005", "h3");
        april2.checkText("skybrian", "dl/dt[1]");
        april2.checkText("Next day change", "dl/dd[1]");

        ElementChecker april1 = changelog.navigateTo("div[2]");

        april1.checkText("April 1, 2005", "h3");

        List<ElementChecker> items = april1.select("dl/*");

        items.get(0).checkName("dt");
        items.get(0).checkText("skybrian", ".");
        items.get(1).checkName("dd");
        items.get(1).checkText("Same day change", ".");
        items.get(2).checkName("dd");
        items.get(2).checkText("Hello, world!", ".");

        assertEquals(3, items.size());
    }

    private void addLog(String date, String author, String comment) throws IOException {
        log.add(new LogEntry(LogEntry.parseUtcDate(date), author, comment));
    }


}
SourceForge