Search in sources :

Example 1 with HtmlCode

use of com.gargoylesoftware.htmlunit.html.HtmlCode in project maven-doxia-sitetools by apache.

the class AptVerifier method verify.

/**
 * {@inheritDoc}
 */
public void verify(String file) throws Exception {
    HtmlPage page = htmlPage(file);
    assertNotNull(page);
    HtmlElement element = page.getHtmlElementById("contentBox");
    assertNotNull(element);
    HtmlDivision division = (HtmlDivision) element;
    assertNotNull(division);
    Iterator<HtmlElement> elementIterator = division.getHtmlElementDescendants().iterator();
    // ----------------------------------------------------------------------
    // 
    // ----------------------------------------------------------------------
    HtmlSection section = (HtmlSection) elementIterator.next();
    HtmlHeading2 h2 = (HtmlHeading2) elementIterator.next();
    assertNotNull(h2);
    assertEquals("Links", h2.asText().trim());
    HtmlAnchor a = (HtmlAnchor) elementIterator.next();
    assertEquals("Links", a.getAttribute("name"));
    HtmlParagraph p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    // Expected log: [APT Parser] Ambiguous link: 'cdc.html'. If this is a local link, prepend "./"!
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("Anchor", a.getAttribute("name"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("cdc.html", a.getAttribute("name"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("#Anchor", a.getAttribute("href"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("#Anchor", a.getAttribute("href"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("Anchor_with_space", a.getAttribute("name"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("#Anchor_with_space", a.getAttribute("href"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("http://maven.apache.org/", a.getAttribute("href"));
    assertEquals("externalLink", a.getAttribute("class"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("http://maven.apache.org/", a.getAttribute("href"));
    assertEquals("externalLink", a.getAttribute("class"));
    // Expected log: [APT Parser] Ambiguous link: 'cdc.html'. If this is a local link, prepend "./"!
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("./cdc.html", a.getAttribute("href"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("#cdc.html", a.getAttribute("href"));
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("/index.html", a.getAttribute("href"));
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    h2 = (HtmlHeading2) elementIterator.next();
    assertNotNull(h2);
    // Note: htmlunit strips the white space, actual result is ok
    assertEquals("Section formatting: italic bold mono", h2.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("Section_formatting:_italic_bold_mono", a.getAttribute("name"));
    HtmlItalic italic = (HtmlItalic) elementIterator.next();
    assertEquals("i", italic.getTagName());
    assertEquals("italic", italic.asText().trim());
    HtmlBold bold = (HtmlBold) elementIterator.next();
    assertEquals("b", bold.getTagName());
    assertEquals("bold", bold.asText().trim());
    HtmlCode code = (HtmlCode) elementIterator.next();
    assertEquals("code", code.getTagName());
    assertEquals("mono", code.asText().trim());
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    HtmlHeading3 h3 = (HtmlHeading3) elementIterator.next();
    assertNotNull(h3);
    // Note: htmlunit strips the white space, actual result is ok
    assertEquals("SubSection formatting: italic bold mono", h3.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("SubSection_formatting:_italic_bold_mono", a.getAttribute("name"));
    italic = (HtmlItalic) elementIterator.next();
    assertEquals("i", italic.getTagName());
    assertEquals("italic", italic.asText().trim());
    bold = (HtmlBold) elementIterator.next();
    assertEquals("b", bold.getTagName());
    assertEquals("bold", bold.asText().trim());
    code = (HtmlCode) elementIterator.next();
    assertEquals("code", code.getTagName());
    assertEquals("mono", code.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    italic = (HtmlItalic) elementIterator.next();
    assertEquals("i", italic.getTagName());
    assertEquals("italic", italic.asText().trim());
    bold = (HtmlBold) elementIterator.next();
    assertEquals("b", bold.getTagName());
    assertEquals("bold", bold.asText().trim());
    code = (HtmlCode) elementIterator.next();
    assertEquals("code", code.getTagName());
    assertEquals("mono", code.asText().trim());
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    h2 = (HtmlHeading2) elementIterator.next();
    assertNotNull(h2);
    assertEquals("No Default Anchor in Section Title with Explicit Anchor", h2.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertEquals("No_Default_Anchor_in_Section_Title_with_Explicit_Anchor", a.getAttribute("name"));
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
}
Also used : HtmlCode(com.gargoylesoftware.htmlunit.html.HtmlCode) HtmlAnchor(com.gargoylesoftware.htmlunit.html.HtmlAnchor) HtmlHeading3(com.gargoylesoftware.htmlunit.html.HtmlHeading3) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlHeading2(com.gargoylesoftware.htmlunit.html.HtmlHeading2) HtmlParagraph(com.gargoylesoftware.htmlunit.html.HtmlParagraph) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HtmlItalic(com.gargoylesoftware.htmlunit.html.HtmlItalic) HtmlSection(com.gargoylesoftware.htmlunit.html.HtmlSection) HtmlBold(com.gargoylesoftware.htmlunit.html.HtmlBold) HtmlDivision(com.gargoylesoftware.htmlunit.html.HtmlDivision)

Aggregations

HtmlAnchor (com.gargoylesoftware.htmlunit.html.HtmlAnchor)1 HtmlBold (com.gargoylesoftware.htmlunit.html.HtmlBold)1 HtmlCode (com.gargoylesoftware.htmlunit.html.HtmlCode)1 HtmlDivision (com.gargoylesoftware.htmlunit.html.HtmlDivision)1 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)1 HtmlHeading2 (com.gargoylesoftware.htmlunit.html.HtmlHeading2)1 HtmlHeading3 (com.gargoylesoftware.htmlunit.html.HtmlHeading3)1 HtmlItalic (com.gargoylesoftware.htmlunit.html.HtmlItalic)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 HtmlParagraph (com.gargoylesoftware.htmlunit.html.HtmlParagraph)1 HtmlSection (com.gargoylesoftware.htmlunit.html.HtmlSection)1