KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > designer > components > OddjobDCTest


1 /*
2  * (c) Rob Gordon 2005.
3  */

4 package org.oddjob.designer.components;
5
6 import java.io.ByteArrayInputStream JavaDoc;
7 import java.io.ByteArrayOutputStream JavaDoc;
8
9 import junit.framework.TestCase;
10
11 import org.oddjob.Oddjob;
12 import org.oddjob.arooa.ArooaFactory;
13 import org.oddjob.arooa.ArooaContext;
14 import org.oddjob.arooa.PropertyProxyResolver;
15 import org.oddjob.arooa.SimpleObjectFactory;
16 import org.oddjob.arooa.handlers.MainHandler;
17 import org.oddjob.arooa.handlers.XmlHandler;
18 import org.oddjob.designer.DesignerXMLParser;
19 import org.oddjob.designer.arooa.DesignParser;
20 import org.xml.sax.SAXParseException JavaDoc;
21
22 /**
23  *
24  */

25 public class OddjobDCTest extends TestCase {
26     
27     static final String JavaDoc xml =
28         "<oddjob file=\"${oddjob.dir}/treesched/persist.xml\"" +
29         " name=\"Scheduling Example\"" +
30         " classpath='${oddjob.dir}/treesched/lib/*.jar' />";
31     
32     synchronized static OddjobDC create() {
33         Object JavaDoc o = DesignerXMLParser.buildComponent(xml);
34         assertEquals(OddjobDC.class, o.getClass());
35         return (OddjobDC) o;
36         
37     }
38     
39     public void testCreate() {
40         OddjobDC result = create();
41         assertNotNull("created", result);
42     }
43
44     public void testParse() throws SAXParseException JavaDoc {
45
46         OddjobDC result = create();
47         
48         ByteArrayOutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc();
49         XmlHandler handler = new XmlHandler(out);
50         DesignParser dp = new DesignParser(new ArooaContext());
51         try {
52             dp.parse("oddjob", result, new MainHandler(handler));
53         } catch (SAXParseException JavaDoc ex) {
54             ex.printStackTrace();
55         }
56         System.out.println(new String JavaDoc(out.toByteArray()));
57         
58         ArooaFactory f = new ArooaFactory();
59
60         SimpleObjectFactory componentFactory = new SimpleObjectFactory();
61         componentFactory.addResource("/org/oddjob/oddjob.properties");
62         SimpleObjectFactory vFactory = new SimpleObjectFactory();
63         vFactory.addResource("/org/oddjob/values/types.properties");
64         PropertyProxyResolver typeManager = new PropertyProxyResolver();
65         typeManager.addResource("/org/oddjob/values/proxies.properties");
66
67         f.setComponentFactory(componentFactory);
68         f.setPropertProxyResolver(typeManager);
69         
70         Oddjob oj = (Oddjob) f.build(new ByteArrayInputStream JavaDoc(out.toByteArray()));
71         assertNotNull("oddjob produced again", xml);
72     }
73 }
74
Popular Tags