1 4 package org.oddjob.arooa.handlers; 5 6 import java.util.Date ; 7 import java.util.Properties ; 8 9 import junit.framework.TestCase; 10 11 import org.oddjob.arooa.ArooaContext; 12 import org.oddjob.arooa.ArooaConstants; 13 import org.oddjob.arooa.ArooaRuntime; 14 import org.oddjob.arooa.PropertyProxyResolver; 15 import org.oddjob.arooa.SimpleObjectFactory; 16 import org.oddjob.values.types.DateType; 17 import org.xml.sax.SAXParseException ; 18 import org.xml.sax.helpers.AttributesImpl ; 19 20 24 public class MappedPropertyHandlerTest extends TestCase { 25 26 boolean called; 27 28 protected void setUp() { 29 called = false; 30 } 31 32 public void testFactoryAdded() throws SAXParseException { 35 ArooaContext context = new ArooaContext(); 36 37 SimpleObjectFactory oFactory = new SimpleObjectFactory(); 38 oFactory.set("date", DateType.class.getName()); 39 40 context.set(ArooaConstants.VALUE_FACTORY, oFactory); 41 context.set(ArooaConstants.PROPERTY_PROXY_RESOLVER, new PropertyProxyResolver()); 42 43 ArooaRuntime rtc = new ArooaRuntime(this, "test", context); 44 MappedPropertyHandler propertyHandler = new MappedPropertyHandler(); 45 context.set(ArooaConstants.CURRENTLY_CONFIGURING, rtc); 46 context.set(ArooaConstants.ELEMENT_NAME, "date"); 47 context = new ArooaContext(context); 48 49 AttributesImpl atts = new AttributesImpl (); 50 atts.addAttribute("", "name", "name", "java.lang.String", "fred"); 51 atts.addAttribute("", "date", "date", "java.lang.String", "25-dec-05"); 52 atts.addAttribute("", "timeZone", "timeZone", "java.lang.String", "Europe/London"); 53 54 propertyHandler.onStartElement("", "date", "date", atts, context); 55 56 rtc.configure(); 57 assertTrue("addValue method called.", called); 58 } 59 60 public void testProxyAdded() throws SAXParseException { 61 ArooaContext context = new ArooaContext(); 62 63 PropertyProxyResolver vr = new PropertyProxyResolver(); 64 Properties proxies = new Properties (); 65 proxies.setProperty(Date .class.getName(), DateType.class.getName()); 66 vr.addProperties(proxies); 67 68 context.set(ArooaConstants.VALUE_FACTORY, new SimpleObjectFactory()); 69 context.set(ArooaConstants.PROPERTY_PROXY_RESOLVER, vr); 70 71 ArooaRuntime rtc = new ArooaRuntime(this, "test", context); 72 MappedPropertyHandler propertyHandler = new MappedPropertyHandler(); 73 context.set(ArooaConstants.CURRENTLY_CONFIGURING, rtc); 74 context.set(ArooaConstants.ELEMENT_NAME, "date"); 75 context = new ArooaContext(context); 76 77 AttributesImpl atts = new AttributesImpl (); 78 atts.addAttribute("", "name", "name", "java.lang.String", "fred"); 79 atts.addAttribute("", "date", "date", "java.lang.String", "25-dec-05"); 80 atts.addAttribute("", "timeZone", "timeZone", "java.lang.String", "Europe/London"); 81 82 propertyHandler.onStartElement("", "date", "date", atts, context); 83 84 rtc.configure(); 85 assertTrue("addValue method called.", called); 86 } 87 88 public void setDate(String name, Date d) { 89 assertEquals("fred", name); 90 called = true; 91 System.out.println(d); 92 } 93 } 94 | Popular Tags |