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

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/marshall/compress/WrappedHttpUnMarshallerTestCase.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: package-import@ubuntu.com-20110909140103-o8ucrolqt5g25k57
Tags: upstream-2.5.3.SP1
ImportĀ upstreamĀ versionĀ 2.5.3.SP1

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.marshall.compress;
23
 
 
24
 
import java.net.InetAddress;
25
 
import java.util.HashMap;
26
 
import java.util.Map;
27
 
 
28
 
import javax.management.MBeanServer;
29
 
 
30
 
import junit.framework.TestCase;
31
 
 
32
 
import org.apache.log4j.ConsoleAppender;
33
 
import org.apache.log4j.Level;
34
 
import org.apache.log4j.Logger;
35
 
import org.apache.log4j.PatternLayout;
36
 
import org.jboss.logging.XLevel;
37
 
import org.jboss.remoting.Client;
38
 
import org.jboss.remoting.InvocationRequest;
39
 
import org.jboss.remoting.InvokerLocator;
40
 
import org.jboss.remoting.ServerInvocationHandler;
41
 
import org.jboss.remoting.ServerInvoker;
42
 
import org.jboss.remoting.callback.InvokerCallbackHandler;
43
 
import org.jboss.remoting.marshal.MarshalFactory;
44
 
import org.jboss.remoting.marshal.Marshaller;
45
 
import org.jboss.remoting.marshal.UnMarshaller;
46
 
import org.jboss.remoting.marshal.compress.CompressingMarshaller;
47
 
import org.jboss.remoting.marshal.compress.CompressingUnMarshaller;
48
 
import org.jboss.remoting.marshal.http.HTTPMarshaller;
49
 
import org.jboss.remoting.marshal.http.HTTPUnMarshaller;
50
 
import org.jboss.remoting.transport.Connector;
51
 
import org.jboss.remoting.transport.PortUtil;
52
 
 
53
 
 
54
 
/**
55
 
 * Unit test for JBREM-927.
56
 
 * 
57
 
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
58
 
 * @version $Revision: 1.1 $
59
 
 * <p>
60
 
 * Copyright Mar 13, 2008
61
 
 * </p>
62
 
 */
63
 
public class WrappedHttpUnMarshallerTestCase extends TestCase
64
 
{
65
 
   private static Logger log = Logger.getLogger(WrappedHttpUnMarshallerTestCase.class);
66
 
   
67
 
   private static boolean firstTime = true;
68
 
   
69
 
   protected String host;
70
 
   protected int port;
71
 
   protected String locatorURI;
72
 
   protected InvokerLocator serverLocator;
73
 
   protected Connector connector;
74
 
   protected TestInvocationHandler invocationHandler;
75
 
   protected String longMessage;
76
 
 
77
 
   
78
 
   public void setUp() throws Exception
79
 
   {
80
 
      if (firstTime)
81
 
      {
82
 
         firstTime = false;
83
 
         Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
84
 
         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
85
 
         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
86
 
         PatternLayout layout = new PatternLayout(pattern);
87
 
         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
88
 
         Logger.getRootLogger().addAppender(consoleAppender);
89
 
         
90
 
         Marshaller marshaller = new CompressingMarshaller(new HTTPMarshaller());
91
 
         UnMarshaller unmarshaller = new CompressingUnMarshaller(new HTTPUnMarshaller());
92
 
         MarshalFactory.addMarshaller("compressedHttp", marshaller, unmarshaller);
93
 
         
94
 
         StringBuffer sb = new StringBuffer();
95
 
         for (int i = 0; i < 200; i++)
96
 
         {
97
 
            sb.append("abcdefghij");
98
 
         }
99
 
         longMessage = sb.toString();
100
 
      }
101
 
   }
102
 
 
103
 
   
104
 
   public void tearDown()
105
 
   {
106
 
   }
107
 
   
108
 
   
109
 
   public void testMethod() throws Throwable
110
 
   {
111
 
      log.info("entering " + getName());
112
 
      
113
 
      // Start server.
114
 
      setupServer();
115
 
      
116
 
      // Create client.
117
 
      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
118
 
      HashMap clientConfig = new HashMap();
119
 
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
120
 
      addExtraClientConfig(clientConfig);
121
 
      Client client = new Client(clientLocator, clientConfig);
122
 
      client.connect();
123
 
      log.info("client is connected");
124
 
      
125
 
      Map metadata = new HashMap();
126
 
      metadata.put(Client.RAW, "true");
127
 
      assertEquals(longMessage, client.invoke(longMessage, metadata));
128
 
      
129
 
      client.disconnect();
130
 
      shutdownServer();
131
 
      log.info(getName() + " PASSES");
132
 
   }
133
 
   
134
 
   
135
 
   protected String getTransport()
136
 
   {
137
 
      return "http";
138
 
   }
139
 
   
140
 
   
141
 
   protected void addExtraClientConfig(Map config) {}
142
 
   protected void addExtraServerConfig(Map config) {}
143
 
   
144
 
 
145
 
   protected void setupServer() throws Exception
146
 
   {
147
 
      host = InetAddress.getLocalHost().getHostAddress();
148
 
      port = PortUtil.findFreePort(host);
149
 
      locatorURI = getTransport() + "://" + host + ":" + port;
150
 
      locatorURI += "/?datatype=compressedHttp";
151
 
      serverLocator = new InvokerLocator(locatorURI);
152
 
      log.info("Starting remoting server with locator uri of: " + locatorURI);
153
 
      HashMap config = new HashMap();
154
 
      config.put(InvokerLocator.FORCE_REMOTE, "true");
155
 
      addExtraServerConfig(config);
156
 
      connector = new Connector(serverLocator, config);
157
 
      connector.create();
158
 
      invocationHandler = new TestInvocationHandler();
159
 
      connector.addInvocationHandler("test", invocationHandler);
160
 
      connector.start();
161
 
   }
162
 
   
163
 
   
164
 
   protected void shutdownServer() throws Exception
165
 
   {
166
 
      if (connector != null)
167
 
         connector.stop();
168
 
   }
169
 
   
170
 
   
171
 
   static class TestInvocationHandler implements ServerInvocationHandler
172
 
   {
173
 
      public void addListener(InvokerCallbackHandler callbackHandler) {}
174
 
      public Object invoke(final InvocationRequest invocation) throws Throwable
175
 
      {
176
 
         return invocation.getParameter();
177
 
      }
178
 
      public void removeListener(InvokerCallbackHandler callbackHandler) {}
179
 
      public void setMBeanServer(MBeanServer server) {}
180
 
      public void setInvoker(ServerInvoker invoker) {}
181
 
   }
182
 
}
 
 
b'\\ No newline at end of file'