1 20 package org.enhydra.barracuda.core.comp; 21 22 import java.io.*; 23 import java.util.*; 24 25 import org.w3c.dom.*; 26 import junit.framework.*; 27 28 import org.enhydra.barracuda.core.util.dom.*; 31 import org.apache.log4j.*; 32 import org.enhydra.barracuda.core.view.*; 33 import org.enhydra.barracuda.examples.xmlc.*; 34 import org.enhydra.barracuda.testbed.*; 35 import org.enhydra.barracuda.testbed.servlet.*; 36 37 38 41 public class TestBTextRender extends DefaultTestCase { 42 private static String testClass = TestBTextRender.class.getName(); 44 private static Logger logger = Logger.getLogger("test."+testClass); 45 46 48 52 public TestBTextRender(String name) { 53 super(name); 54 } 55 56 63 public static void main(String args[]) { 64 TestUtil.parseParams(args); 66 67 if (TestUtil.BATCH_MODE) junit.textui.TestRunner.main(new String [] {testClass}); 69 else junit.swingui.TestRunner.main(new String [] {testClass}); 70 } 71 72 73 79 82 public void testBTextRender() throws IOException, RenderException { 83 if (logger.isInfoEnabled()) logger.info("testing BText render"); 85 CompEx7 cg = new CompEx7(); 86 BComponent root = new BComponent(); 87 root.initCycle(); 88 89 MockHttpServletRequest req = new MockHttpServletRequest(); 91 req.setHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); 92 ViewCapabilities vcap = new ViewCapabilities(req, null); 93 95 ViewContext vc = new DefaultViewContext(vcap, req, null); 97 Document doc = cg.handleDefault(root, vc, req, null); 98 root.render(vc); 99 root.destroyCycle(); 100 DefaultDOMWriter ddw = new DefaultDOMWriter(false); 101 StringWriter sw = new StringWriter(2000); 103 ddw.write(doc, sw); 104 String html = sw.toString(); 105 System.out.println("html:"+html); 106 107 int fpos = html.indexOf("Text1: <strong>bold</strong>"); 109 assertTrue("BText render err1", fpos>0); 110 fpos = html.indexOf("<em>zing1</em>"); 111 assertTrue("BText render err2", fpos>0); 112 fpos = html.indexOf("Text2: <strong>bold</strong>"); 113 assertTrue("BText render err3", fpos>0); 114 fpos = html.indexOf("<em>zing2</em>"); 115 assertTrue("BText render err4", fpos>0); 116 fpos = html.indexOf("customattr1"); 118 assertTrue("BText render err5.1", fpos>0); 119 fpos = html.indexOf("customattr2"); 120 assertTrue("BText render err5.2", fpos>0); 121 fpos = html.indexOf("customattr3"); 122 assertTrue("BText render err5.3", fpos>0); 123 fpos = html.indexOf("customattr4"); 124 assertTrue("BText render err5.4", fpos>0); 125 } 126 } 127 | Popular Tags |