KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xmlrpc > LocalServerRpcTest


1 /*
2  * Copyright 1999,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 package org.apache.xmlrpc;
19
20 import junit.framework.TestCase;
21
22 /**
23  * Abstract base class for tests that require a local WebServer for
24  * test XML-RPC messages.
25  *
26  * @author <a HREF="mailto:rhoegg@isisnetworks.net">Ryan Hoegg</a>
27  * @version $Id: LocalServerRpcTest.java,v 1.3 2005/04/22 10:26:17 hgomez Exp $
28  */

29 abstract public class LocalServerRpcTest
30     extends TestCase
31 {
32
33     
34     /**
35      * The name of our RPC handler.
36      */

37     protected static final String JavaDoc HANDLER_NAME = "TestHandler";
38
39     /**
40      * The value to use in our request parameter.
41      */

42     protected static final String JavaDoc REQUEST_PARAM_VALUE = "foobar";
43
44     protected static int SERVER_PORT;
45
46     /**
47      * The value to use in our request parameter.
48      */

49     protected static final String JavaDoc REQUEST_PARAM_XML =
50         "<value>" + REQUEST_PARAM_VALUE + "</value>";
51
52     /**
53      * A RPC request of our echo server in XML.
54      */

55     protected static final String JavaDoc RPC_REQUEST =
56         "<?xml version=\"1.0\"?>\n" +
57         "<methodCall>\n" +
58         " <methodName>" + HANDLER_NAME + ".echo</methodName>\n" +
59         " <params><param>" + REQUEST_PARAM_XML + "</param></params>\n" +
60         "</methodCall>\n";
61     
62     public LocalServerRpcTest(String JavaDoc message) {
63         super(message);
64     }
65     
66     protected WebServer webServer;
67
68     /**
69      * Sets up a @link WebServer instance listening on the localhost.
70      *
71      * @param port Port to use for the WebServer
72      */

73     private void setUpWebServer(int port) {
74         webServer = new WebServer(port);
75         webServer.addHandler(HANDLER_NAME, new TestHandler());
76     }
77     
78     /**
79      * Sets up the @link WebServer with the default port.
80      */

81     protected void setUpWebServer() {
82         setUpWebServer(SERVER_PORT);
83     }
84
85     /**
86      * Starts the WebServer so tests can be run against it.
87      */

88     protected void startWebServer() {
89         webServer.start();
90         SERVER_PORT = webServer.serverSocket.getLocalPort();
91     }
92     
93     /**
94      * Stops the WebServer
95      */

96     protected void stopWebServer() {
97         webServer.shutdown();
98     }
99     
100     protected class TestHandler {
101         public String JavaDoc echo(String JavaDoc message) {
102             return message;
103         }
104     }
105 }
106
Popular Tags