2
* JBoss, Home of Professional Open Source
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23
package org.jboss.test.remoting.transport.http.method;
25
import junit.framework.TestCase;
26
import org.jboss.remoting.Client;
27
import org.jboss.remoting.InvokerLocator;
28
import org.jboss.remoting.transport.http.HTTPMetadataConstants;
29
import org.jboss.test.remoting.performance.synchronous.PerformanceTestCase;
30
import org.jboss.test.remoting.transport.http.HTTPInvokerConstants;
31
import org.jboss.test.remoting.transport.web.ComplexObject;
33
import java.util.HashMap;
34
import java.util.List;
38
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
40
public class HTTPInvokerTestClient extends TestCase implements HTTPInvokerConstants
42
public String getLocatorURI()
44
String bindAddr = System.getProperty("jrunit.bind_addr", host);
45
String locatorURI = transport + "://" + bindAddr + ":" + port;
46
String metadata = System.getProperty(PerformanceTestCase.REMOTING_METADATA);
47
if(metadata != null && metadata.length() > 0)
49
locatorURI = locatorURI + "/?" + metadata;
54
public String getLocatorURIWithPath()
56
String bindAddr = System.getProperty("jrunit.bind_addr", host);
57
String locatorURI = transport + "://" + bindAddr + ":" + port + "/this/is/some/path";
58
String metadata = System.getProperty(PerformanceTestCase.REMOTING_METADATA);
59
if(metadata != null && metadata.length() > 0)
61
locatorURI = locatorURI + "/?" + metadata;
66
public void testOptionsInvocation() throws Exception
68
Client remotingClient = null;
72
InvokerLocator locator = new InvokerLocator(getLocatorURI());
73
System.out.println("Calling remoting server with locator uri of: " + getLocatorURI());
75
remotingClient = new Client(locator);
76
remotingClient.connect();
78
Map metadata = new HashMap();
79
metadata.put("TYPE", "OPTIONS");
81
// test with null return expected
82
Object response = remotingClient.invoke((Object) null, metadata);
84
assertNull("OPTIONS http invocation should return null", response);
85
String publicValue = (String) ((List) metadata.get(MethodInvocationHandler.PUBLIC)).get(0);
86
assertEquals("Metadata value for " + MethodInvocationHandler.PUBLIC + " should be " + MethodInvocationHandler.PUBLIC_VALUE +
87
" and was " + publicValue, MethodInvocationHandler.PUBLIC_VALUE, publicValue);
88
String allowValue = (String) ((List) metadata.get(MethodInvocationHandler.ALLOW)).get(0);
89
assertEquals("Metadata value for " + MethodInvocationHandler.ALLOW + " should be " + MethodInvocationHandler.ALLOW_VALUE +
90
" and was " + allowValue, MethodInvocationHandler.ALLOW_VALUE, allowValue);
92
catch(Throwable throwable)
94
throw new Exception(throwable);
98
if(remotingClient != null)
100
remotingClient.disconnect();
107
public void testPutInvocation() throws Exception
109
Client remotingClient = null;
113
InvokerLocator locator = new InvokerLocator(getLocatorURIWithPath());
114
System.out.println("Calling remoting server with locator uri of: " + getLocatorURI());
116
remotingClient = new Client(locator);
117
remotingClient.connect();
119
Map metadata = new HashMap();
120
metadata.put("TYPE", "PUT");
122
// test with null return expected
123
Object response = remotingClient.invoke(new ComplexObject(2, "foo", true), metadata);
124
System.out.println("response: " + response);
125
if(response instanceof Exception)
127
((Exception)response).printStackTrace();
130
Integer responseCode = (Integer) metadata.get(HTTPMetadataConstants.RESPONSE_CODE);
131
assertEquals("Metadata value for " + HTTPMetadataConstants.RESPONSE_CODE + " should be " + MethodInvocationHandler.PUT_RESPONSE_CODE +
132
" and was " + responseCode, MethodInvocationHandler.PUT_RESPONSE_CODE, responseCode);
134
Object respHdr = metadata.get(MethodInvocationHandler.PUBLIC);
138
catch(Throwable throwable)
140
throw new Exception(throwable);
144
if(remotingClient != null)
146
remotingClient.disconnect();
153
public void testGetInvocation() throws Exception
155
Client remotingClient = null;
159
InvokerLocator locator = new InvokerLocator(getLocatorURIWithPath());
160
System.out.println("Calling remoting server with locator uri of: " + getLocatorURI());
162
remotingClient = new Client(locator);
163
remotingClient.connect();
165
Map metadata = new HashMap();
166
metadata.put("TYPE", "GET");
168
// test with null return expected
169
Object response = remotingClient.invoke((Object)null, metadata);
171
Integer responseCode = (Integer) metadata.get(HTTPMetadataConstants.RESPONSE_CODE);
172
assertEquals("Metadata value for " + HTTPMetadataConstants.RESPONSE_CODE + " should be " + MethodInvocationHandler.GET_RESPONSE_CODE +
173
" and was " + responseCode, MethodInvocationHandler.GET_RESPONSE_CODE, responseCode);
174
assertEquals("Response value should be " + MethodInvocationHandler.RESPONSE_HTML + " and was " + response,
175
MethodInvocationHandler.RESPONSE_HTML, response);
177
Object respHdr = metadata.get(MethodInvocationHandler.PUBLIC);
182
catch(Throwable throwable)
184
throw new Exception(throwable);
188
if(remotingClient != null)
190
remotingClient.disconnect();
197
public void testHeadInvocation() throws Exception
199
Client remotingClient = null;
203
InvokerLocator locator = new InvokerLocator(getLocatorURIWithPath());
204
System.out.println("Calling remoting server with locator uri of: " + getLocatorURI());
206
remotingClient = new Client(locator);
207
remotingClient.connect();
209
Map metadata = new HashMap();
210
metadata.put("TYPE", "HEAD");
212
// test with null return expected
213
Object response = remotingClient.invoke((Object)null, metadata);
215
Integer responseCode = (Integer) metadata.get(HTTPMetadataConstants.RESPONSE_CODE);
216
assertEquals("Metadata value for " + HTTPMetadataConstants.RESPONSE_CODE + " should be " + MethodInvocationHandler.HEAD_RESPONSE_CODE +
217
" and was " + responseCode, MethodInvocationHandler.HEAD_RESPONSE_CODE, responseCode);
221
catch(Throwable throwable)
223
throw new Exception(throwable);
227
if(remotingClient != null)
229
remotingClient.disconnect();
236
public static void main(String[] args)
238
HTTPInvokerTestClient client = new HTTPInvokerTestClient();
241
client.testOptionsInvocation();
242
client.testPutInvocation();
b'\\ No newline at end of file'