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 TestBTemplateRender extends DefaultTestCase { 42 private static String testClass = TestBTemplateRender.class.getName(); 44 private static Logger logger = Logger.getLogger("test."+testClass); 45 46 48 52 public TestBTemplateRender(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 testBTemplateRender() throws IOException, RenderException { 83 if (logger.isInfoEnabled()) logger.info("testing BTemplate render"); 85 CompEx6 cg = new CompEx6(); 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); 102 ddw.write(doc, sw); 103 String html = sw.toString(); 104 105 107 int fpos = html.indexOf("Dir::"); 110 assertTrue("BTemplate render err: "+(fpos>20 ? html.substring(fpos-20,fpos+20) : "??"), fpos<0); 111 fpos = html.indexOf("Iterative Item99"); assertTrue("BTemplate render err: "+(fpos>20 ? html.substring(fpos-20,fpos+20) : "??"), fpos<0); 113 } 114 } 115 | Popular Tags |