1 4 package org.oddjob.designer.components; 5 6 import java.io.ByteArrayOutputStream ; 7 8 import junit.framework.TestCase; 9 10 import org.apache.log4j.Logger; 11 import org.oddjob.arooa.ArooaHandler; 12 import org.oddjob.arooa.ArooaContext; 13 import org.oddjob.arooa.handlers.MainHandler; 14 import org.oddjob.arooa.handlers.XmlHandler; 15 import org.oddjob.designer.DesignerXMLParser; 16 import org.oddjob.designer.arooa.DesignParser; 17 import org.oddjob.designer.elements.FilesDE; 18 import org.oddjob.designer.elements.ListDE; 19 import org.oddjob.designer.elements.ValueDE; 20 import org.oddjob.designer.elements.simple.SimpleTextAttribute; 21 import org.xml.sax.SAXParseException ; 22 23 26 public class ForEachDCTest extends TestCase { 27 private static final Logger logger = Logger.getLogger(ForEachDCTest.class); 28 29 public void setUp() { 30 logger.debug("========================== " + getName() + "===================" ); 31 } 32 33 public void testCreate() { 34 35 String xml = 36 "<foreach name=\"Each of Somehting\">" + 37 " <values>" + 38 " <files files=\"*\"/>" + 39 " </values>" + 40 "</foreach>"; 41 42 Object dc = DesignerXMLParser.buildComponent(xml); 43 44 assertNotNull("created", dc); 45 assertTrue("not unkonwn", dc instanceof ForEachDC); 46 } 47 48 public void testParse() throws SAXParseException { 49 50 FilesDE fs = new FilesDE(); 51 fs.type("files"); 52 SimpleTextAttribute pat = new SimpleTextAttribute(); 53 pat.attribute("*"); 54 fs.attribute("*"); 55 56 ValueDE t = new ValueDE(); 57 t.type("value"); 58 t.addText("hello"); 59 60 61 ListDE v = new ListDE(); 62 v.addChild(fs); 63 v.addChild(t); 64 65 ForEachDC e = new ForEachDC(); 66 e.tag("each"); 67 e.setValues(v); 68 69 ByteArrayOutputStream out = new ByteArrayOutputStream (); 70 ArooaHandler xmlh = new XmlHandler(out); 71 72 ArooaContext context = new ArooaContext(); 73 74 context = new ArooaContext(context); 75 76 DesignParser dp = new DesignParser(context); 77 dp.parse("each", e, new MainHandler(xmlh)); 78 79 System.out.println(out.toString()); 80 81 } 82 } 83 | Popular Tags |