1 4 package org.oddjob.designer.elements; 5 6 import java.io.ByteArrayInputStream ; 7 import java.io.ByteArrayOutputStream ; 8 9 import junit.framework.TestCase; 10 11 import org.oddjob.arooa.ArooaHandler; 12 import org.oddjob.arooa.ArooaContext; 13 import org.oddjob.arooa.ArooaConstants; 14 import org.oddjob.arooa.handlers.MainHandler; 15 import org.oddjob.arooa.handlers.XmlHandler; 16 import org.oddjob.arooa.xml.XMLDefinitionHelper; 17 import org.oddjob.designer.arooa.DesignElementHandler; 18 import org.oddjob.designer.arooa.DesignParser; 19 import org.oddjob.designer.model.DesignElementType; 20 import org.xml.sax.InputSource ; 21 import org.xml.sax.SAXParseException ; 22 23 26 public class VariablesDETest extends TestCase { 27 28 public class DummyParent extends DesignElementType { 29 public DesignElementType createType(String type) { 30 return new MapDE(); 31 } 32 } 33 34 public void testCreate() { 35 36 String xml = "<whatever>" + 37 "<file file=\"test.txt\"/>" + 38 "<files files='temp/*.dat'/>" + 39 "<files files='system/*.sys'/>" + 40 "</whatever>"; 41 42 43 ArooaHandler h = new DesignElementHandler(); 44 ArooaContext context = new ArooaContext(); 45 context.set(ArooaConstants.ELEMENT_HANDLER, h); 46 DummyParent dp = new DummyParent(); 47 context.set(ArooaConstants.CURRENTLY_CONFIGURING, dp); 48 49 XMLDefinitionHelper ph = new XMLDefinitionHelper(context); 50 ph.parse(new InputSource (new ByteArrayInputStream (xml.getBytes())), 51 new MainHandler(h)); 52 53 assertEquals("created", 1, dp.children().length); 54 Object [] c = dp.children()[0].children(); 55 assertTrue("with children", c.length == 3); 56 } 57 58 public void testParse() throws SAXParseException { 59 60 MapDE vs = new MapDE(); 61 62 ValueDE t = new ValueDE(); 63 t.type("value"); 64 t.addText("hello"); 65 66 vs.addChild(t); 67 68 ByteArrayOutputStream out = new ByteArrayOutputStream (); 69 ArooaHandler xmlh = new XmlHandler(out); 70 71 ArooaContext context = new ArooaContext(); 72 73 context = new ArooaContext(context); 74 75 DesignParser dp = new DesignParser(context); 76 dp.parse("fileset", vs, new MainHandler(xmlh)); 77 78 System.out.println(out.toString()); 79 } 80 } 81 | Popular Tags |