KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > routing > RouterManagerTest


1 package org.objectweb.celtix.routing;
2
3 import java.io.File JavaDoc;
4 import java.net.URL JavaDoc;
5 import java.net.URLClassLoader JavaDoc;
6 import java.util.HashMap JavaDoc;
7 import java.util.List JavaDoc;
8 import java.util.Map JavaDoc;
9
10 import junit.framework.TestCase;
11
12 import org.objectweb.celtix.Bus;
13
14 public class RouterManagerTest extends TestCase {
15     private Map JavaDoc<String JavaDoc, Object JavaDoc> properties;
16     private String JavaDoc javaClasspath;
17     private File JavaDoc opDir;
18     
19     public void setUp() {
20         properties = new HashMap JavaDoc<String JavaDoc, Object JavaDoc>();
21         URL JavaDoc routerConfigFileUrl = getClass().getResource("resources/router_config1.xml");
22         System.setProperty("celtix.config.file", routerConfigFileUrl.toString());
23         javaClasspath = System.getProperty("java.class.path");
24         
25         opDir = new File JavaDoc(getClass().getResource(".").getFile(), "/temp");
26     }
27
28     public void tearDown() throws Exception JavaDoc {
29         System.setProperty("java.class.path", javaClasspath);
30         RouteTypeUtil.deleteDir(opDir);
31         
32         Bus bus = Bus.getCurrent();
33         bus.shutdown(true);
34         Bus.setCurrent(null);
35         
36         System.clearProperty("celtix.config.file");
37     }
38     
39     public void testGetRouterWSDLList() throws Exception JavaDoc {
40         
41         properties.put("org.objectweb.celtix.BusId", "celtix1");
42         Bus bus = Bus.init(null, properties);
43         
44         RouterManager rm = new RouterManager(bus);
45         List JavaDoc<String JavaDoc> urlList = rm.getRouteWSDLList();
46         
47         assertNotNull("a valid list should be present", urlList);
48         assertEquals(1, urlList.size());
49     }
50
51     public void testInvokeWSDLToJava() throws Exception JavaDoc {
52         properties.put("org.objectweb.celtix.BusId", "celtix2");
53         Bus bus = Bus.init(null, properties);
54
55         TestRouterManager rm = new TestRouterManager(bus);
56
57         //maven doesn't set java.class.path while eclipse does.
58
boolean isClassPathSet = javaClasspath != null
59                                   && (javaClasspath.indexOf("JAXWS") >= 0);
60         if (!isClassPathSet) {
61             System.setProperty("java.class.path",
62                                RouteTypeUtil.getClassPath(getClass().getClassLoader()));
63         }
64
65         File JavaDoc classDir = new File JavaDoc(opDir, "/classes");
66         classDir.mkdirs();
67         
68         rm.testInvokeWSDLToJava(opDir, classDir);
69         
70         URLClassLoader JavaDoc loader =
71             URLClassLoader.newInstance(new URL JavaDoc[] {classDir.toURL()},
72                                        null);
73         
74         Class JavaDoc<?> clz = loader.loadClass("org.objectweb.header_test.TestHeader");
75         assertNotNull("TestHeader class instance should be present", clz);
76         
77         clz = loader.loadClass("org.objectweb.header_test.types.ObjectFactory");
78         assertNotNull("ObjectFactory class instance should be present", clz);
79         
80         clz = loader.loadClass("org.objectweb.hwrouter.types.FaultDetail");
81         assertNotNull("FaultDetail class instance should be present", clz);
82         
83         try {
84             clz = loader.loadClass("org.objectweb.hwrouter.types.NotPresent");
85             fail("Should throw a ClassNotFoundException");
86         } catch (ClassNotFoundException JavaDoc cnfe) {
87             //Expecetd Exception
88
}
89     }
90     
91     public void testInit() throws Exception JavaDoc {
92         properties.put("org.objectweb.celtix.BusId", "celtix2");
93         Bus bus = Bus.init(null, properties);
94         
95         TestRouterManager rm = new TestRouterManager(bus);
96         
97         //maven doesn't set java.class.path while eclipse does.
98
boolean isClassPathSet = javaClasspath != null
99                                   && (javaClasspath.indexOf("JAXWS") >= 0);
100         if (!isClassPathSet) {
101             System.setProperty("java.class.path",
102                                RouteTypeUtil.getClassPath(getClass().getClassLoader()));
103         }
104         
105         rm.init();
106
107         assertNotNull("Router Factory should be intialized", rm.getRouterFactory());
108         
109         List JavaDoc<Router> rList = rm.getRouters();
110         assertNotNull("Router List should be initialized", rList);
111         assertEquals(4, rList.size());
112         
113         //Calling of init creates a celtix-router-temp dir for the generated code
114
RouteTypeUtil.deleteDir(new File JavaDoc(System.getProperty("user.dir"), "/celtix-router-tmp"));
115     }
116     
117     public static void main(String JavaDoc[] args) {
118         junit.textui.TestRunner.run(RouterManagerTest.class);
119     }
120     
121     class TestRouterManager extends RouterManager {
122         public TestRouterManager(Bus bus) {
123             super(bus);
124         }
125
126         protected void publishRoutes() {
127             //Complete
128
}
129         
130         public void testInvokeWSDLToJava(File JavaDoc srcDir, File JavaDoc classDir) {
131             super.invokeWSDLToJava(srcDir, classDir);
132         }
133     }
134 }
135
Popular Tags