1   /*
2    * Copyright 2001-2004 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  package org.portletbridge.http;
17  
18  import java.io.IOException;
19  import java.io.Serializable;
20  
21  import junit.framework.TestCase;
22  
23  import org.apache.commons.httpclient.HttpClient;
24  import org.apache.commons.httpclient.HttpException;
25  import org.apache.commons.httpclient.HttpState;
26  import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
27  import org.apache.commons.httpclient.methods.GetMethod;
28  
29  import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
30  
31  /***
32   * @author JMcCrindle
33   */
34  public class HttpClientIntegrationTest extends TestCase {
35  
36      private static final class MyHttpState extends HttpState implements Serializable { }
37      
38      /*
39       * @see TestCase#setUp()
40       */
41      protected void setUp() throws Exception {
42          super.setUp();
43      }
44      
45      public void testHttpClient() throws Exception {
46          final HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager());
47          PooledExecutor executor = new PooledExecutor();
48          for(int i = 0; i < 100; i++) {
49              executor.execute(new Runnable() {
50                  public void run() {
51                      GetMethod getMethod = new GetMethod("http://localhost:8080/helloworld/helloworld.jsp");
52                      try {
53                          HttpState state = new MyHttpState();
54                          client.executeMethod(client.getHostConfiguration(), getMethod, state);
55                      } catch (HttpException e) {
56                          throw new RuntimeException(e);
57                      } catch (IOException e) {
58                          throw new RuntimeException(e);
59                      } finally {
60                          getMethod.releaseConnection();
61                      }
62                  }
63              });
64          }
65          executor.shutdownAfterProcessingCurrentlyQueuedTasks();
66          executor.awaitTerminationAfterShutdown();
67      }
68  
69      /*
70       * @see TestCase#tearDown()
71       */
72      protected void tearDown() throws Exception {
73          super.tearDown();
74      }
75  
76      /***
77       * Constructor for HttpClientIntegrationTest.
78       * @param name
79       */
80      public HttpClientIntegrationTest(String name) {
81          super(name);
82      }
83  
84  }