1 38 package com.gargoylesoftware.htmlunit.html.xpath; 39 40 import java.util.Arrays; 41 import java.util.Collection; 42 import java.util.List; 43 44 import org.apache.commons.collections.CollectionUtils; 45 import org.apache.commons.collections.Transformer; 46 import org.jaxen.Navigator; 47 48 import com.gargoylesoftware.htmlunit.WebTestCase; 49 import com.gargoylesoftware.htmlunit.html.DomNode; 50 import com.gargoylesoftware.htmlunit.html.HtmlPage; 51 52 58 public class DocumentNavigatorTest extends WebTestCase { 59 private static final Transformer NODE_TO_NODENAME = new Transformer() { 60 public Object transform(final Object obj) { 61 return ((DomNode) obj).getNodeName(); 62 } 63 }; 64 65 private static final Navigator NAVIGATOR = DocumentNavigator.instance; 66 static final String CONTENT = "<html><head><title>Test page</title></head>" 67 + "<body><a HREF='foo.html' id='myLink'>foo</a></body>" 68 + "</html>"; 69 private final HtmlPage page_; 70 71 72 78 public DocumentNavigatorTest( final String name ) throws Exception { 79 super( name ); 80 page_ = loadPage(CONTENT); 81 } 82 83 87 public void testFollowingAxisIterator() throws Exception { 88 89 final List expected = Arrays.asList(new String[] {"html", "head", "title", "#text", "body", "a", "#text"}); 90 final Collection received= CollectionUtils 91 .collect(NAVIGATOR.getFollowingAxisIterator(page_), 92 NODE_TO_NODENAME); 93 assertEquals(expected, received); 94 95 } 96 97 101 public void testFollowingSiblingAxisIterator() throws Exception { 102 103 final List expected = Arrays.asList(new String[] {"body"}); 104 final Collection received= CollectionUtils 105 .collect(NAVIGATOR.getFollowingSiblingAxisIterator(page_.getDocumentElement().getFirstChild()), 106 NODE_TO_NODENAME); 107 assertEquals(expected, received); 108 } 109 } 110 | Popular Tags |