1 19 20 33 package org.htmlparser.tests.scannersTests; 34 35 import junit.framework.TestSuite; 36 37 import org.htmlparser.scanners.BodyScanner; 38 import org.htmlparser.tags.BodyTag; 39 import org.htmlparser.tests.ParserTestCase; 40 import org.htmlparser.util.ParserException; 41 42 public class BodyScannerTest extends ParserTestCase 43 { 44 45 public BodyScannerTest(String name) 46 { 47 super(name); 48 } 49 50 public void testSimpleBody() throws ParserException 51 { 52 createParser("<html><head><title>Test 1</title></head><body>This is a body tag</body></html>"); 53 parser.registerScanners(); 54 BodyScanner bodyScanner = new BodyScanner("-b"); 55 parser.addScanner(bodyScanner); 56 parseAndAssertNodeCount(6); 57 assertTrue(node[4] instanceof BodyTag); 58 BodyTag bodyTag = (BodyTag) node[4]; 60 assertEquals("Body", "This is a body tag", bodyTag.getBody()); 61 assertEquals( 62 "Body", 63 "<BODY>This is a body tag</BODY>", 64 bodyTag.toHtml()); 65 assertEquals("Body Scanner", bodyScanner, bodyTag.getThisScanner()); 66 } 67 68 public void testBodywithJsp() throws ParserException 69 { 70 createParser("<html><head><title>Test 1</title></head><body><%=BodyValue%></body></html>"); 71 parser.registerScanners(); 72 BodyScanner bodyScanner = new BodyScanner("-b"); 73 parser.addScanner(bodyScanner); 74 parseAndAssertNodeCount(6); 75 assertTrue(node[4] instanceof BodyTag); 76 BodyTag bodyTag = (BodyTag) node[4]; 78 assertStringEquals( 79 "Body", 80 "<BODY><%=BodyValue%></BODY>", 81 bodyTag.toHtml()); 82 assertEquals("Body Scanner", bodyScanner, bodyTag.getThisScanner()); 83 } 84 85 public void testBodyMixed() throws ParserException 86 { 87 createParser("<html><head><title>Test 1</title></head><body>before jsp<%=BodyValue%>after jsp</body></html>"); 88 parser.registerScanners(); 89 BodyScanner bodyScanner = new BodyScanner("-b"); 90 parser.addScanner(bodyScanner); 91 parseAndAssertNodeCount(6); 92 assertTrue(node[4] instanceof BodyTag); 93 BodyTag bodyTag = (BodyTag) node[4]; 95 assertEquals( 96 "Body", 97 "<BODY>before jsp<%=BodyValue%>after jsp</BODY>", 98 bodyTag.toHtml()); 99 assertEquals("Body Scanner", bodyScanner, bodyTag.getThisScanner()); 100 } 101 102 public void testBodyEnding() throws ParserException 103 { 104 createParser("<html><body>before jsp<%=BodyValue%>after jsp</html>"); 105 parser.registerScanners(); 106 BodyScanner bodyScanner = new BodyScanner("-b"); 107 parser.addScanner(bodyScanner); 108 parseAndAssertNodeCount(3); 109 assertTrue(node[1] instanceof BodyTag); 110 BodyTag bodyTag = (BodyTag) node[1]; 112 assertEquals( 113 "Body", 114 "<BODY>before jsp<%=BodyValue%>after jsp</BODY>", 115 bodyTag.toHtml()); 116 assertEquals("Body Scanner", bodyScanner, bodyTag.getThisScanner()); 117 } 118 119 public static TestSuite suite() 120 { 121 return new TestSuite(BodyScannerTest.class); 122 } 123 124 public static void main(String [] args) 125 { 126 new junit.awtui.TestRunner().start( 127 new String [] { BodyScannerTest.class.getName()}); 128 } 129 130 } 131 | Popular Tags |