001: package org.objectweb.celtix.routing;
002:
003: import java.io.File;
004: import java.net.URL;
005: import java.net.URLClassLoader;
006: import java.util.HashMap;
007: import java.util.List;
008: import java.util.Map;
009:
010: import junit.framework.TestCase;
011:
012: import org.objectweb.celtix.Bus;
013:
014: public class RouterManagerTest extends TestCase {
015: private Map<String, Object> properties;
016: private String javaClasspath;
017: private File opDir;
018:
019: public void setUp() {
020: properties = new HashMap<String, Object>();
021: URL routerConfigFileUrl = getClass().getResource(
022: "resources/router_config1.xml");
023: System.setProperty("celtix.config.file", routerConfigFileUrl
024: .toString());
025: javaClasspath = System.getProperty("java.class.path");
026:
027: opDir = new File(getClass().getResource(".").getFile(), "/temp");
028: }
029:
030: public void tearDown() throws Exception {
031: System.setProperty("java.class.path", javaClasspath);
032: RouteTypeUtil.deleteDir(opDir);
033:
034: Bus bus = Bus.getCurrent();
035: bus.shutdown(true);
036: Bus.setCurrent(null);
037:
038: System.clearProperty("celtix.config.file");
039: }
040:
041: public void testGetRouterWSDLList() throws Exception {
042:
043: properties.put("org.objectweb.celtix.BusId", "celtix1");
044: Bus bus = Bus.init(null, properties);
045:
046: RouterManager rm = new RouterManager(bus);
047: List<String> urlList = rm.getRouteWSDLList();
048:
049: assertNotNull("a valid list should be present", urlList);
050: assertEquals(1, urlList.size());
051: }
052:
053: public void testInvokeWSDLToJava() throws Exception {
054: properties.put("org.objectweb.celtix.BusId", "celtix2");
055: Bus bus = Bus.init(null, properties);
056:
057: TestRouterManager rm = new TestRouterManager(bus);
058:
059: //maven doesn't set java.class.path while eclipse does.
060: boolean isClassPathSet = javaClasspath != null
061: && (javaClasspath.indexOf("JAXWS") >= 0);
062: if (!isClassPathSet) {
063: System.setProperty("java.class.path", RouteTypeUtil
064: .getClassPath(getClass().getClassLoader()));
065: }
066:
067: File classDir = new File(opDir, "/classes");
068: classDir.mkdirs();
069:
070: rm.testInvokeWSDLToJava(opDir, classDir);
071:
072: URLClassLoader loader = URLClassLoader.newInstance(
073: new URL[] { classDir.toURL() }, null);
074:
075: Class<?> clz = loader
076: .loadClass("org.objectweb.header_test.TestHeader");
077: assertNotNull("TestHeader class instance should be present",
078: clz);
079:
080: clz = loader
081: .loadClass("org.objectweb.header_test.types.ObjectFactory");
082: assertNotNull("ObjectFactory class instance should be present",
083: clz);
084:
085: clz = loader
086: .loadClass("org.objectweb.hwrouter.types.FaultDetail");
087: assertNotNull("FaultDetail class instance should be present",
088: clz);
089:
090: try {
091: clz = loader
092: .loadClass("org.objectweb.hwrouter.types.NotPresent");
093: fail("Should throw a ClassNotFoundException");
094: } catch (ClassNotFoundException cnfe) {
095: //Expecetd Exception
096: }
097: }
098:
099: public void testInit() throws Exception {
100: properties.put("org.objectweb.celtix.BusId", "celtix2");
101: Bus bus = Bus.init(null, properties);
102:
103: TestRouterManager rm = new TestRouterManager(bus);
104:
105: //maven doesn't set java.class.path while eclipse does.
106: boolean isClassPathSet = javaClasspath != null
107: && (javaClasspath.indexOf("JAXWS") >= 0);
108: if (!isClassPathSet) {
109: System.setProperty("java.class.path", RouteTypeUtil
110: .getClassPath(getClass().getClassLoader()));
111: }
112:
113: rm.init();
114:
115: assertNotNull("Router Factory should be intialized", rm
116: .getRouterFactory());
117:
118: List<Router> rList = rm.getRouters();
119: assertNotNull("Router List should be initialized", rList);
120: assertEquals(4, rList.size());
121:
122: //Calling of init creates a celtix-router-temp dir for the generated code
123: RouteTypeUtil.deleteDir(new File(
124: System.getProperty("user.dir"), "/celtix-router-tmp"));
125: }
126:
127: public static void main(String[] args) {
128: junit.textui.TestRunner.run(RouterManagerTest.class);
129: }
130:
131: class TestRouterManager extends RouterManager {
132: public TestRouterManager(Bus bus) {
133: super (bus);
134: }
135:
136: protected void publishRoutes() {
137: //Complete
138: }
139:
140: public void testInvokeWSDLToJava(File srcDir, File classDir) {
141: super.invokeWSDLToJava(srcDir, classDir);
142: }
143: }
144: }
|