Source Code Cross Referenced for RouterTest.java in  » ESB » celtix-1.0 » org » objectweb » celtix » routing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » celtix 1.0 » org.objectweb.celtix.routing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.celtix.routing;
002:
003:        import java.io.File;
004:        import java.lang.reflect.InvocationHandler;
005:        import java.lang.reflect.Proxy;
006:        import java.net.URL;
007:        import java.net.URLClassLoader;
008:        import java.util.HashMap;
009:        import java.util.List;
010:        import java.util.Map;
011:
012:        import javax.wsdl.Definition;
013:        import javax.wsdl.Port;
014:        import javax.wsdl.Service;
015:        import javax.xml.namespace.QName;
016:        import javax.xml.ws.Endpoint;
017:        import javax.xml.ws.Provider;
018:        import javax.xml.ws.WebServiceException;
019:
020:        import junit.framework.TestCase;
021:        import org.objectweb.celtix.Bus;
022:        import org.objectweb.celtix.bus.configuration.wsdl.WsdlPortProvider;
023:        import org.objectweb.celtix.routing.configuration.RouteType;
024:
025:        public class RouterTest extends TestCase {
026:
027:            private Map<String, Object> properties;
028:            private String javaClasspath;
029:            private File srcDir;
030:
031:            public void setUp() {
032:                properties = new HashMap<String, Object>();
033:                javaClasspath = System.getProperty("java.class.path");
034:                srcDir = new File(getClass().getResource(".").getFile(),
035:                        "/temp");
036:            }
037:
038:            public void tearDown() throws Exception {
039:                System.setProperty("java.class.path", javaClasspath);
040:                RouteTypeUtil.deleteDir(srcDir);
041:
042:                Bus bus = Bus.getCurrent();
043:                bus.shutdown(true);
044:                Bus.setCurrent(null);
045:            }
046:
047:            public void testRouterCreation() throws Exception {
048:                properties.put("org.objectweb.celtix.BusId", "RT1");
049:                Bus bus = Bus.init(null, properties);
050:                Bus.setCurrent(bus);
051:
052:                Definition def = bus.getWSDLManager().getDefinition(
053:                        getClass().getResource("resources/router.wsdl"));
054:
055:                QName sourceSrv = new QName("http://objectweb.org/HWRouter",
056:                        "HTTPSoapServiceSource");
057:                String sourcePort = new String("HTTPSoapPortSource");
058:                QName destSrv = new QName("http://objectweb.org/HWRouter",
059:                        "HTTPSoapServiceDestination");
060:                String destPort = new String("HTTPSoapPortDestination");
061:
062:                testRouterSourceAndDestination(def, sourceSrv, sourcePort,
063:                        destSrv, destPort, true);
064:
065:                sourceSrv = new QName("http://objectweb.org/HWRouter",
066:                        "HTTPXMLServiceSource");
067:                sourcePort = new String("HTTPXMLPortSource");
068:                destSrv = new QName("http://objectweb.org/HWRouter",
069:                        "HTTPSoapServiceDestination");
070:                destPort = new String("HTTPSoapPortDestination");
071:
072:                testRouterSourceAndDestination(def, sourceSrv, sourcePort,
073:                        destSrv, destPort, false);
074:            }
075:
076:            public void testPassThroughRouterInit() throws Exception {
077:                properties.put("org.objectweb.celtix.BusId", "RT2");
078:                Bus bus = Bus.init(null, properties);
079:                Bus.setCurrent(bus);
080:
081:                Definition def = bus.getWSDLManager().getDefinition(
082:                        getClass().getResource("resources/router.wsdl"));
083:
084:                QName sourceSrv = new QName("http://objectweb.org/HWRouter",
085:                        "HTTPSoapServiceSource");
086:                String sourcePort = new String("HTTPSoapPortSource");
087:                QName destSrv = new QName("http://objectweb.org/HWRouter",
088:                        "HTTPSoapServiceDestination");
089:                String destPort = new String("HTTPSoapPortDestination");
090:
091:                RouteType rt = RouteTypeUtil.createRouteType("route_0",
092:                        sourceSrv, sourcePort, destSrv, destPort);
093:
094:                TestRouter router = new TestRouter(null, def, rt);
095:                router.init();
096:                assertEquals(1, router.epList.size());
097:                Endpoint ep = router.epList.get(0);
098:                assertNotNull("Should have a Endpoint for Source Service", ep);
099:                assertNotNull("Should have a wsdl model", ep.getMetadata());
100:                Map<String, Object> props = ep.getProperties();
101:                assertNotNull("Should have a wsdl model", props);
102:                assertEquals(sourceSrv, props.get(Endpoint.WSDL_SERVICE));
103:                QName portName = (QName) props.get(Endpoint.WSDL_PORT);
104:                assertEquals(sourceSrv.getNamespaceURI(), portName
105:                        .getNamespaceURI());
106:                assertEquals(sourcePort, portName.getLocalPart());
107:                Object impl = ep.getImplementor();
108:                assertTrue("Should be instance of Provider<Source>",
109:                        impl instanceof  Provider);
110:                StreamSourceMessageProvider ssmp = (StreamSourceMessageProvider) impl;
111:                assertNull(
112:                        "WebServiceContext is not set as endpoint is not published",
113:                        ssmp.getContext());
114:            }
115:
116:            public void testNormalRouterInit() throws Exception {
117:                properties.put("org.objectweb.celtix.BusId", "RT3");
118:                Bus bus = Bus.init(null, properties);
119:                Bus.setCurrent(bus);
120:
121:                URL wsdlURl = getClass().getResource("resources/router.wsdl");
122:                Definition def = bus.getWSDLManager().getDefinition(wsdlURl);
123:
124:                QName sourceSrv = new QName("http://objectweb.org/HWRouter",
125:                        "HTTPXMLServiceSource");
126:                String sourcePort = new String("HTTPXMLPortSource");
127:                QName destSrv = new QName("http://objectweb.org/HWRouter",
128:                        "HTTPSoapServiceDestination");
129:                String destPort = new String("HTTPSoapPortDestination");
130:
131:                RouteType rt = RouteTypeUtil.createRouteType("route_1",
132:                        sourceSrv, sourcePort, destSrv, destPort);
133:
134:                ClassLoader loader = new URLClassLoader(new URL[] { srcDir
135:                        .toURL() }, null);
136:                //Test with no code generation.
137:                TestRouter router = new TestRouter(loader, def, rt);
138:                try {
139:                    router.init();
140:                    fail("Should throw a WebServiceException with cause of ClassNotFoundError");
141:                } catch (WebServiceException ex) {
142:                    if (ex.getCause() instanceof  ClassNotFoundException) {
143:                        //Expected
144:                    }
145:                }
146:
147:                //Test With CodeGeneration and URLClassLoadere
148:                loader = doCodeGeneration(wsdlURl.getFile(), srcDir);
149:
150:                router = new TestRouter(loader, def, rt);
151:                router.init();
152:                assertEquals(1, router.epList.size());
153:                Endpoint ep = router.epList.get(0);
154:                assertNotNull("Should have a Endpoint for Source Service", ep);
155:                assertNotNull("Should have a wsdl model", ep.getMetadata());
156:                Map<String, Object> props = ep.getProperties();
157:                assertNotNull("Should have a wsdl model", props);
158:                assertEquals(sourceSrv, props.get(Endpoint.WSDL_SERVICE));
159:                QName portName = (QName) props.get(Endpoint.WSDL_PORT);
160:                assertEquals(sourceSrv.getNamespaceURI(), portName
161:                        .getNamespaceURI());
162:                assertEquals(sourcePort, portName.getLocalPart());
163:                Object impl = ep.getImplementor();
164:
165:                //The Implementor Should be a proxy class.
166:                assertTrue("Implemetor Should be a proxy Class", Proxy
167:                        .isProxyClass(impl.getClass()));
168:
169:                InvocationHandler implHandler = Proxy
170:                        .getInvocationHandler(impl);
171:                assertTrue(
172:                        "Invocation Handler should be instance of SEIImplHandler",
173:                        implHandler instanceof  SEIImplHandler);
174:                SEIImplHandler seiHandler = (SEIImplHandler) implHandler;
175:                assertNull("Should have a WebServiceContext set", seiHandler
176:                        .getContext());
177:            }
178:
179:            private ClassLoader doCodeGeneration(String wsdlUrl, File opDir)
180:                    throws Exception {
181:                //maven doesn't set java.class.path while eclipse does.
182:                boolean isClassPathSet = javaClasspath != null
183:                        && (javaClasspath.indexOf("JAXWS") >= 0);
184:                if (!isClassPathSet) {
185:                    System.setProperty("java.class.path", RouteTypeUtil
186:                            .getClassPath(getClass().getClassLoader()));
187:                }
188:
189:                File classDir = new File(opDir, "/classes");
190:                classDir.mkdirs();
191:
192:                RouteTypeUtil.invokeWSDLToJava(wsdlUrl, opDir, classDir);
193:
194:                URLClassLoader loader = URLClassLoader.newInstance(
195:                        new URL[] { classDir.toURL() }, getClass()
196:                                .getClassLoader());
197:                return loader;
198:            }
199:
200:            private void testRouterSourceAndDestination(Definition def,
201:                    QName sourceSrv, String sourcePort, QName destSrv,
202:                    String destPort, boolean isSameBinding) {
203:                RouteType rt = RouteTypeUtil.createRouteType("route_0",
204:                        sourceSrv, sourcePort, destSrv, destPort);
205:
206:                TestRouter router = new TestRouter(null, def, rt);
207:                assertNotNull("WSDL Model should be set for the router", router
208:                        .getWSDLModel());
209:                assertNotNull("RouteType should be set for the router", router
210:                        .getRoute());
211:
212:                Service s = def.getService(destSrv);
213:                Port p = router.getDestinationPorts(s);
214:
215:                assertNotNull("Should have a wsdl port", p);
216:                assertEquals(destPort, p.getName());
217:
218:                s = def.getService(sourceSrv);
219:                p = router.getSourcePort(s);
220:
221:                assertNotNull("Should have a wsdl port", p);
222:                assertEquals(sourcePort, p.getName());
223:
224:                //Check For Same Binding
225:                assertEquals(isSameBinding, router.testIsSameBindingId(p));
226:            }
227:
228:            public static void main(String[] args) {
229:                junit.textui.TestRunner.run(RouterTest.class);
230:            }
231:
232:            class TestRouter extends RouterImpl {
233:
234:                public TestRouter(ClassLoader loader, Definition model,
235:                        RouteType rt) {
236:                    super (loader, model, rt);
237:                }
238:
239:                public boolean testIsSameBindingId(Port p) {
240:                    WsdlPortProvider provider = new WsdlPortProvider(p);
241:                    return super .isSameBindingId((String) provider
242:                            .getObject("bindingId"));
243:                }
244:
245:                public Port getSourcePort(Service service) {
246:                    return (Port) super .sourcePortMap.get(service.getQName());
247:                }
248:
249:                public Port getDestinationPorts(Service service) {
250:                    return (Port) super .destPortMap.get(service.getQName());
251:                }
252:
253:                public List<Endpoint> getEndpoints() {
254:                    return super.epList;
255:                }
256:            }
257:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.