1 package dynaop.remote; 2 3 import java.net.URL ; 4 5 import org.mortbay.http.HttpContext; 6 import org.mortbay.http.HttpServer; 7 import org.mortbay.http.SocketListener; 8 import org.mortbay.jetty.servlet.ServletHandler; 9 import org.mortbay.jetty.servlet.ServletHolder; 10 11 import junit.framework.TestCase; 12 13 18 public class RemoteTest extends TestCase { 19 20 static final int PORT = 12345; 21 22 public void testMyService() throws Exception { 23 HttpServer server = new HttpServer(); 24 try { 25 SocketListener listener = new SocketListener(); 27 listener.setPort(PORT); 28 server.addListener(listener); 29 30 HttpContext context = server.getContext("/"); 32 ServletHandler handler = new ServletHandler(); 33 ServletHolder holder = 34 handler.addServlet("MyService", "/myService", 35 Service.class.getName()); 36 holder.setInitParameter("class", MyServiceImpl.class.getName()); 37 context.addHandler(handler); 38 39 server.start(); 41 42 MyService stub = (MyService) new Home().create( 44 new URL ("http://localhost:" + PORT + "/myService"), 45 MyService.class 46 ); 47 assertEquals("TEST", stub.toUpperCase("test")); 48 assertEquals(5, stub.add(2, 3)); 49 try { 50 stub.throwException(); 51 } 52 catch (MyException e) {} 53 } 54 finally { 55 server.stop(); 56 } 57 } 58 59 98 } 99 | Popular Tags |