Search in sources :

Example 1 with HtmlHeading4

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

the class NestedItemsVerifier 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();
    // ----------------------------------------------------------------------
    // Verify link
    // ----------------------------------------------------------------------
    HtmlSection section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    HtmlHeading2 h2 = (HtmlHeading2) elementIterator.next();
    assertNotNull(h2);
    assertEquals("List Section", h2.asText().trim());
    HtmlAnchor a = (HtmlAnchor) elementIterator.next();
    assertNotNull(a);
    assertEquals("List_Section", a.getAttribute("name"));
    // ----------------------------------------------------------------------
    // Unordered lists
    // ----------------------------------------------------------------------
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    HtmlHeading4 h4 = (HtmlHeading4) elementIterator.next();
    assertNotNull(h4);
    assertEquals("Unordered lists", h4.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertNotNull(a);
    assertEquals("Unordered_lists", a.getAttribute("name"));
    HtmlParagraph p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Below is an unordered list, followed by six paragraphs.", p.asText().trim());
    HtmlUnorderedList ul = (HtmlUnorderedList) elementIterator.next();
    assertNotNull(ul);
    HtmlListItem li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 1.", li.getFirstChild().asText().trim());
    ul = (HtmlUnorderedList) elementIterator.next();
    assertNotNull(ul);
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Item 11.", p.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Item 12.", p.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 13.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 14.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 2.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 3.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 4.", li.getFirstChild().asText().trim());
    ul = (HtmlUnorderedList) elementIterator.next();
    assertNotNull(ul);
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 41.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 42.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 43.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 44.", li.getFirstChild().asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 1 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 2 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 3 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 4 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 5 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 6 below list.", p.asText().trim());
    // ----------------------------------------------------------------------
    // Ordered lists
    // ----------------------------------------------------------------------
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    h4 = (HtmlHeading4) elementIterator.next();
    assertNotNull(h4);
    assertEquals("Ordered lists", h4.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertNotNull(a);
    assertEquals("Ordered_lists", a.getAttribute("name"));
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Below is an ordered list, followed by six paragraphs.", p.asText().trim());
    HtmlOrderedList ol = (HtmlOrderedList) elementIterator.next();
    assertNotNull(ol);
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 1.", li.getFirstChild().asText().trim());
    ol = (HtmlOrderedList) elementIterator.next();
    assertNotNull(ol);
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 11.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 12.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 13.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 14.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 2.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 3.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 4.", li.getFirstChild().asText().trim());
    ol = (HtmlOrderedList) elementIterator.next();
    assertNotNull(ol);
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 41.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 42.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 43.", li.getFirstChild().asText().trim());
    li = (HtmlListItem) elementIterator.next();
    assertNotNull(li);
    assertEquals("Item 44.", li.getFirstChild().asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 1 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 2 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 3 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 4 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 5 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 6 below list.", p.asText().trim());
    // ----------------------------------------------------------------------
    // Definition lists
    // ----------------------------------------------------------------------
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    h4 = (HtmlHeading4) elementIterator.next();
    assertNotNull(h4);
    assertEquals("Definition lists", h4.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertNotNull(a);
    assertEquals("Definition_lists", a.getAttribute("name"));
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Below is a definition list, followed by six paragraphs.", p.asText().trim());
    HtmlDefinitionList dl = (HtmlDefinitionList) elementIterator.next();
    assertNotNull(dl);
    HtmlDefinitionTerm dt = (HtmlDefinitionTerm) elementIterator.next();
    assertNotNull(dt);
    assertEquals("Term 1.", dt.getFirstChild().asText().trim());
    HtmlDefinitionDescription dd = (HtmlDefinitionDescription) elementIterator.next();
    assertNotNull(dd);
    assertEquals("Description 1.", dd.getFirstChild().asText().trim());
    dt = (HtmlDefinitionTerm) elementIterator.next();
    assertNotNull(dt);
    assertEquals("Term 2.", dt.getFirstChild().asText().trim());
    dd = (HtmlDefinitionDescription) elementIterator.next();
    assertNotNull(dd);
    assertEquals("Description 2.", dd.getFirstChild().asText().trim());
    dl = (HtmlDefinitionList) elementIterator.next();
    assertNotNull(dl);
    dt = (HtmlDefinitionTerm) elementIterator.next();
    assertNotNull(dt);
    assertEquals("Term 21.", dt.getFirstChild().asText().trim());
    dd = (HtmlDefinitionDescription) elementIterator.next();
    assertNotNull(dd);
    assertEquals("Description 21.", dd.getFirstChild().asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 1 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 2 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 3 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 4 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 5 below list.", p.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("Paragraph 6 below list.", p.asText().trim());
    assertFalse(elementIterator.hasNext());
}
Also used : HtmlUnorderedList(com.gargoylesoftware.htmlunit.html.HtmlUnorderedList) HtmlHeading4(com.gargoylesoftware.htmlunit.html.HtmlHeading4) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlHeading2(com.gargoylesoftware.htmlunit.html.HtmlHeading2) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HtmlDivision(com.gargoylesoftware.htmlunit.html.HtmlDivision) HtmlOrderedList(com.gargoylesoftware.htmlunit.html.HtmlOrderedList) HtmlAnchor(com.gargoylesoftware.htmlunit.html.HtmlAnchor) HtmlDefinitionList(com.gargoylesoftware.htmlunit.html.HtmlDefinitionList) HtmlParagraph(com.gargoylesoftware.htmlunit.html.HtmlParagraph) HtmlSection(com.gargoylesoftware.htmlunit.html.HtmlSection) HtmlDefinitionTerm(com.gargoylesoftware.htmlunit.html.HtmlDefinitionTerm) HtmlListItem(com.gargoylesoftware.htmlunit.html.HtmlListItem) HtmlDefinitionDescription(com.gargoylesoftware.htmlunit.html.HtmlDefinitionDescription)

Example 2 with HtmlHeading4

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

the class EntitiesVerifier method verify.

/**
 * {@inheritDoc}
 */
public void verify(String file) throws Exception {
    HtmlPage page = htmlPage(file);
    assertNotNull(page);
    HtmlMeta author = (HtmlMeta) page.getElementsByName("author").get(0);
    assertNotNull(author);
    assertTrue(author.toString().indexOf("Ligature \u00C6") > 0);
    assertEquals("Ligature \u00C6", author.getContentAttribute());
    author = (HtmlMeta) page.getElementsByName("author").get(1);
    assertNotNull(author);
    assertTrue(author.toString().indexOf("Ampersand &amp;") > 0);
    assertEquals("Ampersand &", author.getContentAttribute());
    author = (HtmlMeta) page.getElementsByName("author").get(2);
    assertNotNull(author);
    assertTrue(author.toString().indexOf("Less than &lt;") > 0);
    assertEquals("Less than <", author.getContentAttribute());
    author = (HtmlMeta) page.getElementsByName("author").get(3);
    assertNotNull(author);
    assertTrue(author.toString().indexOf("Greater than >") > 0);
    assertEquals("Greater than >", author.getContentAttribute());
    author = (HtmlMeta) page.getElementsByName("author").get(4);
    assertNotNull(author);
    assertEquals("Apostrophe '", author.getContentAttribute());
    author = (HtmlMeta) page.getElementsByName("author").get(5);
    assertNotNull(author);
    assertTrue(author.toString().indexOf("Quote &quot;") > 0);
    assertEquals("Quote \"", author.getContentAttribute());
    author = (HtmlMeta) page.getElementsByName("author").get(6);
    assertNotNull(author);
    assertTrue(author.toString().indexOf("test@email.com") > 0);
    assertEquals("test@email.com", author.getContentAttribute());
    author = (HtmlMeta) page.getElementsByName("author").get(7);
    assertNotNull(author);
    assertTrue(author.toString().indexOf("test\u00A9email.com") > 0);
    assertEquals("test\u00A9email.com", author.getContentAttribute());
    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(h2.asText().trim(), "section name with entities: '&' '\u0391' ' ' '\uD835\uDFED'");
    HtmlAnchor a = (HtmlAnchor) elementIterator.next();
    assertNotNull(a);
    assertEquals("section_name_with_entities:_.27.26.27_.27.CE.91.27_.27.C2.A0.27_.27.3F.3F.27", a.getAttribute("name"));
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    HtmlHeading4 h4 = (HtmlHeading4) elementIterator.next();
    assertNotNull(h4);
    assertEquals("Entities", h4.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertNotNull(a);
    assertEquals("Entities", a.getAttribute("name"));
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    HtmlHeading3 h3 = (HtmlHeading3) elementIterator.next();
    assertNotNull(h3);
    assertEquals("Generic Entities: '&' '<' '>' '\"' '''", h3.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    HtmlParagraph p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("'&' '<' '>' '\"' '''", p.asText().trim());
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    h3 = (HtmlHeading3) elementIterator.next();
    assertNotNull(h3);
    assertEquals("Local Entities: '\u0391' '\u0392' '\u0393' '\uD835\uDFED'", h3.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("'\u0391' '\u0392' '\u0393' '\uD835\uDFED\uD835\uDFED' '\u0159\u0159' '\u0159'", p.asText().trim());
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    h3 = (HtmlHeading3) elementIterator.next();
    assertNotNull(h3);
    assertEquals("DTD Entities: ' ' '\u00A1' '\u00A2'", h3.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("' ' '\u00A1' '\u00A2'", p.asText().trim());
    section = (HtmlSection) elementIterator.next();
    assertNotNull(section);
    h4 = (HtmlHeading4) elementIterator.next();
    assertNotNull(h4);
    assertEquals("CDATA", h4.asText().trim());
    a = (HtmlAnchor) elementIterator.next();
    assertNotNull(a);
    assertEquals("CDATA", a.getAttribute("name"));
    HtmlDivision div = (HtmlDivision) elementIterator.next();
    assertNotNull(div);
    HtmlPreformattedText pre = (HtmlPreformattedText) elementIterator.next();
    assertNotNull(pre);
    assertEquals("<project xmlns:ant=\"jelly:ant\">", pre.asText().trim());
    p = (HtmlParagraph) elementIterator.next();
    assertNotNull(p);
    assertEquals("'&nbsp;' '&iexcl;'", p.asText().trim());
    assertFalse(elementIterator.hasNext());
}
Also used : HtmlAnchor(com.gargoylesoftware.htmlunit.html.HtmlAnchor) HtmlHeading3(com.gargoylesoftware.htmlunit.html.HtmlHeading3) HtmlHeading4(com.gargoylesoftware.htmlunit.html.HtmlHeading4) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlHeading2(com.gargoylesoftware.htmlunit.html.HtmlHeading2) HtmlParagraph(com.gargoylesoftware.htmlunit.html.HtmlParagraph) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HtmlSection(com.gargoylesoftware.htmlunit.html.HtmlSection) HtmlDivision(com.gargoylesoftware.htmlunit.html.HtmlDivision) HtmlMeta(com.gargoylesoftware.htmlunit.html.HtmlMeta) HtmlPreformattedText(com.gargoylesoftware.htmlunit.html.HtmlPreformattedText)

Aggregations

HtmlAnchor (com.gargoylesoftware.htmlunit.html.HtmlAnchor)2 HtmlDivision (com.gargoylesoftware.htmlunit.html.HtmlDivision)2 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)2 HtmlHeading2 (com.gargoylesoftware.htmlunit.html.HtmlHeading2)2 HtmlHeading4 (com.gargoylesoftware.htmlunit.html.HtmlHeading4)2 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)2 HtmlParagraph (com.gargoylesoftware.htmlunit.html.HtmlParagraph)2 HtmlSection (com.gargoylesoftware.htmlunit.html.HtmlSection)2 HtmlDefinitionDescription (com.gargoylesoftware.htmlunit.html.HtmlDefinitionDescription)1 HtmlDefinitionList (com.gargoylesoftware.htmlunit.html.HtmlDefinitionList)1 HtmlDefinitionTerm (com.gargoylesoftware.htmlunit.html.HtmlDefinitionTerm)1 HtmlHeading3 (com.gargoylesoftware.htmlunit.html.HtmlHeading3)1 HtmlListItem (com.gargoylesoftware.htmlunit.html.HtmlListItem)1 HtmlMeta (com.gargoylesoftware.htmlunit.html.HtmlMeta)1 HtmlOrderedList (com.gargoylesoftware.htmlunit.html.HtmlOrderedList)1 HtmlPreformattedText (com.gargoylesoftware.htmlunit.html.HtmlPreformattedText)1 HtmlUnorderedList (com.gargoylesoftware.htmlunit.html.HtmlUnorderedList)1