1 package org.objectweb.celtix.routing; 2 3 import java.io.File ; 4 import java.net.URL ; 5 import java.net.URLClassLoader ; 6 import java.util.HashMap ; 7 import java.util.List ; 8 import java.util.Map ; 9 10 import junit.framework.TestCase; 11 12 import org.objectweb.celtix.Bus; 13 14 public class RouterManagerTest extends TestCase { 15 private Map <String , Object > properties; 16 private String javaClasspath; 17 private File opDir; 18 19 public void setUp() { 20 properties = new HashMap <String , Object >(); 21 URL 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 (getClass().getResource(".").getFile(), "/temp"); 26 } 27 28 public void tearDown() throws Exception { 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 { 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 <String > 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 { 52 properties.put("org.objectweb.celtix.BusId", "celtix2"); 53 Bus bus = Bus.init(null, properties); 54 55 TestRouterManager rm = new TestRouterManager(bus); 56 57 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 classDir = new File (opDir, "/classes"); 66 classDir.mkdirs(); 67 68 rm.testInvokeWSDLToJava(opDir, classDir); 69 70 URLClassLoader loader = 71 URLClassLoader.newInstance(new URL [] {classDir.toURL()}, 72 null); 73 74 Class <?> 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 cnfe) { 87 } 89 } 90 91 public void testInit() throws Exception { 92 properties.put("org.objectweb.celtix.BusId", "celtix2"); 93 Bus bus = Bus.init(null, properties); 94 95 TestRouterManager rm = new TestRouterManager(bus); 96 97 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 <Router> rList = rm.getRouters(); 110 assertNotNull("Router List should be initialized", rList); 111 assertEquals(4, rList.size()); 112 113 RouteTypeUtil.deleteDir(new File (System.getProperty("user.dir"), "/celtix-router-tmp")); 115 } 116 117 public static void main(String [] 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 } 129 130 public void testInvokeWSDLToJava(File srcDir, File classDir) { 131 super.invokeWSDLToJava(srcDir, classDir); 132 } 133 } 134 } 135 | Popular Tags |