KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > arooa > handlers > MappedPropertyHandlerTest


1 /*
2  * Copyright (c) 2004, Rob Gordon.
3  */

4 package org.oddjob.arooa.handlers;
5
6 import java.util.Date JavaDoc;
7 import java.util.Properties JavaDoc;
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 JavaDoc;
18 import org.xml.sax.helpers.AttributesImpl JavaDoc;
19
20 /**
21  *
22  * @author Rob Gordon.
23  */

24 public class MappedPropertyHandlerTest extends TestCase {
25
26     boolean called;
27
28     protected void setUp() {
29         called = false;
30     }
31     
32     // calls the onStartElementMethod to check the property gets
33
// set.
34
public void testFactoryAdded() throws SAXParseException JavaDoc {
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 JavaDoc atts = new AttributesImpl JavaDoc();
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 JavaDoc {
61         ArooaContext context = new ArooaContext();
62                 
63         PropertyProxyResolver vr = new PropertyProxyResolver();
64         Properties JavaDoc proxies = new Properties JavaDoc();
65         proxies.setProperty(Date JavaDoc.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 JavaDoc atts = new AttributesImpl JavaDoc();
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 JavaDoc name, Date JavaDoc d) {
89         assertEquals("fred", name);
90         called = true;
91         System.out.println(d);
92     }
93 }
94
Popular Tags