~ubuntu-branches/ubuntu/wily/libjboss-remoting-java/wily

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/transport/http/method/HTTPInvokerTestClient.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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.
 
6
*
 
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.
 
11
*
 
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.
 
16
*
 
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.
 
21
*/
 
22
 
 
23
package org.jboss.test.remoting.transport.http.method;
 
24
 
 
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;
 
32
 
 
33
import java.util.HashMap;
 
34
import java.util.List;
 
35
import java.util.Map;
 
36
 
 
37
/**
 
38
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
 
39
 */
 
40
public class HTTPInvokerTestClient extends TestCase implements HTTPInvokerConstants
 
41
{
 
42
   public String getLocatorURI()
 
43
   {
 
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)
 
48
      {
 
49
         locatorURI = locatorURI + "/?" + metadata;
 
50
      }
 
51
      return locatorURI;
 
52
   }
 
53
 
 
54
   public String getLocatorURIWithPath()
 
55
   {
 
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)
 
60
      {
 
61
         locatorURI = locatorURI + "/?" + metadata;
 
62
      }
 
63
      return locatorURI;
 
64
   }
 
65
 
 
66
   public void testOptionsInvocation() throws Exception
 
67
   {
 
68
      Client remotingClient = null;
 
69
 
 
70
      try
 
71
      {
 
72
         InvokerLocator locator = new InvokerLocator(getLocatorURI());
 
73
         System.out.println("Calling remoting server with locator uri of: " + getLocatorURI());
 
74
 
 
75
         remotingClient = new Client(locator);
 
76
         remotingClient.connect();
 
77
 
 
78
         Map metadata = new HashMap();
 
79
         metadata.put("TYPE", "OPTIONS");
 
80
 
 
81
         // test with null return expected
 
82
         Object response = remotingClient.invoke((Object) null, metadata);
 
83
 
 
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);
 
91
      }
 
92
      catch(Throwable throwable)
 
93
      {
 
94
         throw new Exception(throwable);
 
95
      }
 
96
      finally
 
97
      {
 
98
         if(remotingClient != null)
 
99
         {
 
100
            remotingClient.disconnect();
 
101
         }
 
102
      }
 
103
 
 
104
 
 
105
   }
 
106
 
 
107
   public void testPutInvocation() throws Exception
 
108
   {
 
109
      Client remotingClient = null;
 
110
 
 
111
      try
 
112
      {
 
113
         InvokerLocator locator = new InvokerLocator(getLocatorURIWithPath());
 
114
         System.out.println("Calling remoting server with locator uri of: " + getLocatorURI());
 
115
 
 
116
         remotingClient = new Client(locator);
 
117
         remotingClient.connect();
 
118
 
 
119
         Map metadata = new HashMap();
 
120
         metadata.put("TYPE", "PUT");
 
121
 
 
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)
 
126
         {
 
127
            ((Exception)response).printStackTrace();
 
128
         }
 
129
 
 
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);
 
133
 
 
134
         Object respHdr = metadata.get(MethodInvocationHandler.PUBLIC);
 
135
         assertNull(respHdr);
 
136
 
 
137
      }
 
138
      catch(Throwable throwable)
 
139
      {
 
140
         throw new Exception(throwable);
 
141
      }
 
142
      finally
 
143
      {
 
144
         if(remotingClient != null)
 
145
         {
 
146
            remotingClient.disconnect();
 
147
         }
 
148
      }
 
149
 
 
150
 
 
151
   }
 
152
 
 
153
   public void testGetInvocation() throws Exception
 
154
   {
 
155
      Client remotingClient = null;
 
156
 
 
157
      try
 
158
      {
 
159
         InvokerLocator locator = new InvokerLocator(getLocatorURIWithPath());
 
160
         System.out.println("Calling remoting server with locator uri of: " + getLocatorURI());
 
161
 
 
162
         remotingClient = new Client(locator);
 
163
         remotingClient.connect();
 
164
 
 
165
         Map metadata = new HashMap();
 
166
         metadata.put("TYPE", "GET");
 
167
 
 
168
         // test with null return expected
 
169
         Object response = remotingClient.invoke((Object)null, metadata);
 
170
 
 
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);
 
176
 
 
177
         Object respHdr = metadata.get(MethodInvocationHandler.PUBLIC);
 
178
         assertNull(respHdr);
 
179
 
 
180
 
 
181
      }
 
182
      catch(Throwable throwable)
 
183
      {
 
184
         throw new Exception(throwable);
 
185
      }
 
186
      finally
 
187
      {
 
188
         if(remotingClient != null)
 
189
         {
 
190
            remotingClient.disconnect();
 
191
         }
 
192
      }
 
193
 
 
194
 
 
195
   }
 
196
 
 
197
   public void testHeadInvocation() throws Exception
 
198
   {
 
199
      Client remotingClient = null;
 
200
 
 
201
      try
 
202
      {
 
203
         InvokerLocator locator = new InvokerLocator(getLocatorURIWithPath());
 
204
         System.out.println("Calling remoting server with locator uri of: " + getLocatorURI());
 
205
 
 
206
         remotingClient = new Client(locator);
 
207
         remotingClient.connect();
 
208
 
 
209
         Map metadata = new HashMap();
 
210
         metadata.put("TYPE", "HEAD");
 
211
 
 
212
         // test with null return expected
 
213
         Object response = remotingClient.invoke((Object)null, metadata);
 
214
 
 
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);
 
218
 
 
219
 
 
220
      }
 
221
      catch(Throwable throwable)
 
222
      {
 
223
         throw new Exception(throwable);
 
224
      }
 
225
      finally
 
226
      {
 
227
         if(remotingClient != null)
 
228
         {
 
229
            remotingClient.disconnect();
 
230
         }
 
231
      }
 
232
 
 
233
 
 
234
   }
 
235
 
 
236
   public static void main(String[] args)
 
237
   {
 
238
      HTTPInvokerTestClient client = new HTTPInvokerTestClient();
 
239
      try
 
240
      {
 
241
         client.testOptionsInvocation();
 
242
         client.testPutInvocation();
 
243
      }
 
244
      catch(Exception e)
 
245
      {
 
246
         e.printStackTrace();
 
247
      }
 
248
   }
 
249
 
 
250
}
 
 
b'\\ No newline at end of file'