KickJava   Java API By Example, From Geeks To Geeks.

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


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 NestedPropertyHandlerTest extends TestCase {
25
26     boolean called = false;
27     
28     // calls the onStartElementMethod to check the property gets
29
// set.
30
public void testPropertyAdded() throws SAXParseException JavaDoc {
31         ArooaContext context = new ArooaContext();
32         
33         SimpleObjectFactory oFactory = new SimpleObjectFactory();
34         Properties JavaDoc defs = new Properties JavaDoc();
35         defs.setProperty("date", DateType.class.getName());
36         oFactory.addProperties(defs);
37         context.set(ArooaConstants.VALUE_FACTORY, oFactory);
38         
39         PropertyProxyResolver vr = new PropertyProxyResolver();
40         Properties JavaDoc proxies = new Properties JavaDoc();
41         proxies.setProperty(Date JavaDoc.class.getName(), DateType.class.getName());
42         vr.addProperties(proxies);
43         
44         context.set(ArooaConstants.PROPERTY_PROXY_RESOLVER, vr);
45         
46         ArooaRuntime rtc = new ArooaRuntime(this, "test", context);
47         NestedPropertyHandler typeHandler = new NestedPropertyHandler();
48         context.set(ArooaConstants.CURRENTLY_CONFIGURING, rtc);
49         context.set(ArooaConstants.ELEMENT_NAME, "date");
50         context = new ArooaContext(context);
51         
52         AttributesImpl JavaDoc atts = new AttributesImpl JavaDoc();
53         atts.addAttribute("", "date", "date", "java.lang.String", "25-dec-05");
54         atts.addAttribute("", "timeZone", "timeZone", "java.lang.String", "Europe/London");
55         
56         typeHandler.onStartElement("", "date", "date", atts, context);
57         
58         rtc.configure();
59         assertTrue("addValue method called.", called);
60     }
61     
62     public void setDate(Date JavaDoc d) {
63         called = true;
64         System.out.println(d);
65     }
66 }
67
Popular Tags