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

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/transport/http/headers/ResponseCodeTestCase.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
 
package org.jboss.test.remoting.transport.http.headers;
23
 
 
24
 
import java.net.InetAddress;
25
 
import java.util.Collection;
26
 
import java.util.HashMap;
27
 
import java.util.Iterator;
28
 
import java.util.List;
29
 
import java.util.Map;
30
 
import java.util.Set;
31
 
 
32
 
import javax.management.MBeanServer;
33
 
 
34
 
import junit.framework.TestCase;
35
 
 
36
 
import org.apache.log4j.ConsoleAppender;
37
 
import org.apache.log4j.Level;
38
 
import org.apache.log4j.Logger;
39
 
import org.apache.log4j.PatternLayout;
40
 
import org.jboss.remoting.Client;
41
 
import org.jboss.remoting.InvocationRequest;
42
 
import org.jboss.remoting.InvokerLocator;
43
 
import org.jboss.remoting.ServerInvocationHandler;
44
 
import org.jboss.remoting.ServerInvoker;
45
 
import org.jboss.remoting.callback.Callback;
46
 
import org.jboss.remoting.callback.HandleCallbackException;
47
 
import org.jboss.remoting.callback.InvokerCallbackHandler;
48
 
import org.jboss.remoting.transport.Connector;
49
 
import org.jboss.remoting.transport.PortUtil;
50
 
import org.jboss.remoting.transport.http.HTTPMetadataConstants;
51
 
 
52
 
/**
53
 
 * Unit test for JBREM-728.
54
 
 * 
55
 
 * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
56
 
 * <p>
57
 
 * Copyright (c) November 24, 2007
58
 
 * </p>
59
 
 *
60
 
 */
61
 
public class ResponseCodeTestCase extends TestCase
62
 
{
63
 
   private static Logger log = Logger.getLogger(ResponseCodeTestCase.class);
64
 
   
65
 
   private static boolean firstTime = true;
66
 
   
67
 
   protected static String RESPONSE_KEY = "responseKey";
68
 
   protected static String RESPONSE_VALUE = "responseValue";
69
 
   protected static String RETURN_RESPONSE_HEADER = "returnResponseHeader";
70
 
   
71
 
   protected String host;
72
 
   protected int port;
73
 
   protected String locatorURI;
74
 
   protected InvokerLocator serverLocator;
75
 
   protected Connector connector;
76
 
   protected TestInvocationHandler invocationHandler;
77
 
 
78
 
   
79
 
   public void setUp() throws Exception
80
 
   {
81
 
      if (firstTime)
82
 
      {
83
 
         firstTime = false;
84
 
         Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
85
 
         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
86
 
         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
87
 
         PatternLayout layout = new PatternLayout(pattern);
88
 
         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
89
 
         Logger.getRootLogger().addAppender(consoleAppender);  
90
 
      }
91
 
   }
92
 
 
93
 
   
94
 
   public void tearDown()
95
 
   {
96
 
   }
97
 
   
98
 
   
99
 
   public void testResponseHeaders() throws Throwable
100
 
   {
101
 
      log.info("entering " + getName());
102
 
      
103
 
      // Start server.
104
 
      setupServer();
105
 
      
106
 
      // Create client.
107
 
      InvokerLocator clientLocator1 = new InvokerLocator(locatorURI);
108
 
      HashMap clientConfig = new HashMap();
109
 
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
110
 
      addExtraClientConfig(clientConfig);
111
 
      Client client = new Client(clientLocator1, clientConfig);
112
 
      client.connect();
113
 
      log.info("client is connected");
114
 
      
115
 
      // Test connections.
116
 
      HashMap metadata = new HashMap();
117
 
      assertEquals(RETURN_RESPONSE_HEADER, client.invoke(RETURN_RESPONSE_HEADER, metadata));
118
 
      log.info("connection is good");
119
 
      log.info("metadata: " + metadata);
120
 
      
121
 
      // Verify that all entries in the HTTPMetadataConstants.RESPONSE_HEADERS value
122
 
      // also appear in metadata map.
123
 
      Object o = metadata.remove(HTTPMetadataConstants.RESPONSE_HEADERS);
124
 
      assertTrue(o instanceof Map);
125
 
      Map responseHeaders = (Map) o;
126
 
      Set responseHeadersEntries = responseHeaders.entrySet();
127
 
      Set metadataEntries = metadata.entrySet();
128
 
      
129
 
      Iterator it = responseHeadersEntries.iterator();
130
 
      while (it.hasNext())
131
 
      {
132
 
         Map.Entry entry = (Map.Entry) it.next();
133
 
         log.info("entry: " + entry);
134
 
         if (entry.getKey() == null)
135
 
            continue;
136
 
         assertTrue("metadata does not contain entry " + entry, metadataEntries.contains(entry));
137
 
      }
138
 
      
139
 
      // Verify response map entry generated in invocation handler
140
 
      // was added as a response header.
141
 
      assertTrue(responseHeaders.keySet().contains(RESPONSE_KEY));
142
 
      assertTrue(responseHeaders.get(RESPONSE_KEY) instanceof Collection);
143
 
      List responses = (List) responseHeaders.get(RESPONSE_KEY);
144
 
      assertTrue(responses.size() == 1);
145
 
      assertEquals(RESPONSE_VALUE, responses.get(0));
146
 
      
147
 
      client.disconnect();
148
 
      shutdownServer();
149
 
      log.info(getName() + " PASSES");
150
 
   }
151
 
   
152
 
   
153
 
   protected String getTransport()
154
 
   {
155
 
      return "http";
156
 
   }
157
 
   
158
 
   
159
 
   protected void addExtraClientConfig(Map config) {}
160
 
   protected void addExtraServerConfig(Map config) {}
161
 
   
162
 
 
163
 
   protected void setupServer() throws Exception
164
 
   {
165
 
      host = InetAddress.getLocalHost().getHostAddress();
166
 
      port = PortUtil.findFreePort(host);
167
 
      locatorURI = getTransport() + "://" + host + ":" + port; 
168
 
      serverLocator = new InvokerLocator(locatorURI);
169
 
      log.info("Starting remoting server with locator uri of: " + locatorURI);
170
 
      HashMap config = new HashMap();
171
 
      config.put(InvokerLocator.FORCE_REMOTE, "true");
172
 
      addExtraServerConfig(config);
173
 
      connector = new Connector(serverLocator, config);
174
 
      connector.create();
175
 
      invocationHandler = new TestInvocationHandler();
176
 
      connector.addInvocationHandler("test", invocationHandler);
177
 
      connector.start();
178
 
   }
179
 
   
180
 
   
181
 
   
182
 
   
183
 
   protected void shutdownServer() throws Exception
184
 
   {
185
 
      if (connector != null)
186
 
         connector.stop();
187
 
   }
188
 
   
189
 
   
190
 
   static class TestInvocationHandler implements ServerInvocationHandler
191
 
   {
192
 
      public void addListener(InvokerCallbackHandler callbackHandler) {}
193
 
      public Object invoke(final InvocationRequest invocation) throws Throwable
194
 
      {
195
 
         if (RETURN_RESPONSE_HEADER.equals(invocation.getParameter()))
196
 
            invocation.getReturnPayload().put(RESPONSE_KEY, RESPONSE_VALUE);
197
 
         return invocation.getParameter();
198
 
      }
199
 
      public void removeListener(InvokerCallbackHandler callbackHandler) {}
200
 
      public void setMBeanServer(MBeanServer server) {}
201
 
      public void setInvoker(ServerInvoker invoker) {}
202
 
   }
203
 
   
204
 
   
205
 
   static class TestCallbackHandler implements InvokerCallbackHandler
206
 
   {
207
 
      public void handleCallback(Callback callback) throws HandleCallbackException
208
 
      {
209
 
         log.info("received callback");
210
 
      }  
211
 
   }
212
 
}
 
 
b'\\ No newline at end of file'