01: package com.opensymphony.module.sitemesh.multipass;
02:
03: import com.opensymphony.module.sitemesh.Page;
04: import com.opensymphony.module.sitemesh.PageParser;
05: import com.opensymphony.module.sitemesh.multipass.DivExtractingPageParser;
06: import junit.framework.TestCase;
07:
08: import java.io.IOException;
09:
10: /**
11: * @author Joe Walnes
12: */
13: public class DivExtractingPageParserTest extends TestCase {
14:
15: public void testReplacesTopLevelDivsWithPlaceHolders()
16: throws IOException {
17: String input = ""
18: + "<html>\n"
19: + " <head><title>Title</title></head>\n"
20: + " <body>\n"
21: + " <div id='one'>Hello</div>\n"
22: + " Blah\n"
23: + " <div id='two'>World<br><div id=inner>Great</div></div>\n"
24: + " <div>Bye</div>\n" + " </body>\n" + "</html>";
25:
26: PageParser parser = new DivExtractingPageParser();
27: Page page = parser.parse(input.toCharArray());
28:
29: String expectedBody = ""
30: + " <sitemesh:multipass id=\"div.one\"/>\n"
31: + " Blah\n"
32: + " <sitemesh:multipass id=\"div.two\"/>\n"
33: + " <div>Bye</div>\n";
34: assertEquals("Title", page.getTitle());
35: assertEquals(expectedBody.trim(), page.getBody().trim());
36: assertEquals("<div id='one'>Hello</div>", page
37: .getProperty("div.one"));
38: assertEquals(
39: "<div id='two'>World<br><div id=inner>Great</div></div>",
40: page.getProperty("div.two"));
41: }
42:
43: }
|