1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.proxy.invoker;
19
20 import junit.extensions.TestSetup;
21 import junit.framework.Protectable;
22 import junit.framework.Test;
23 import junit.framework.TestCase;
24 import junit.framework.TestResult;
25 import junit.framework.TestSuite;
26 import org.apache.commons.proxy.exception.InvokerException;
27 import org.apache.commons.proxy.factory.cglib.CglibProxyFactory;
28 import org.apache.commons.proxy.util.Echo;
29 import org.apache.commons.proxy.util.EchoImpl;
30 import org.apache.xmlrpc.WebServer;
31 import org.apache.xmlrpc.XmlRpcClient;
32 import org.apache.xmlrpc.XmlRpcClientLite;
33
34
35
36
37 public class TestXmlRpcInvoker extends TestCase
38 {
39 private static WebServer server;
40 private static XmlRpcClient client;
41
42 public static Test suite()
43 {
44 return new TestSetup( new TestSuite( TestXmlRpcInvoker.class ) )
45 {
46 public void run( final TestResult testResult )
47 {
48 Protectable p = new Protectable()
49 {
50 public void protect() throws Throwable
51 {
52 try
53 {
54 setUp();
55 basicRun( testResult );
56 }
57 finally
58 {
59 tearDown();
60 }
61 }
62 };
63 testResult.runProtected( this, p );
64 }
65
66 protected void setUp() throws Exception
67 {
68 server = new WebServer( 9999 );
69 server.addHandler( "echo", new EchoImpl() );
70 server.start();
71 client = new XmlRpcClientLite( "http://localhost:9999/RPC2" );
72 }
73
74 protected void tearDown() throws Exception
75 {
76 server.shutdown();
77 }
78 };
79 }
80
81 public void testInvalidHandlerName()
82 {
83 final XmlRpcInvoker handler = new XmlRpcInvoker( client, "invalid" );
84 final Echo echo = ( Echo ) new CglibProxyFactory()
85 .createInvokerProxy( handler, new Class[]{ Echo.class } );
86 try
87 {
88 echo.echoBack( "Hello" );
89 fail();
90 }
91 catch( InvokerException e )
92 {
93 }
94 }
95
96 public void testValidInvocation() throws Exception
97 {
98 final XmlRpcInvoker handler = new XmlRpcInvoker( client, "echo" );
99 final Echo echo = ( Echo ) new CglibProxyFactory()
100 .createInvokerProxy( handler, new Class[]{ Echo.class } );
101 assertEquals( "Hello", echo.echoBack( "Hello" ) );
102
103 }
104 }