001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.rest.mock2;
014
015import java.io.*;
016import java.util.concurrent.*;
017
018import org.apache.http.*;
019import org.apache.http.conn.*;
020import org.apache.http.conn.routing.*;
021import org.apache.http.protocol.*;
022
023/**
024 * An implementation of {@link HttpClientConnectionManager} specifically for use in mocked connections using the {@link MockHttpConnection} class.
025 *
026 * This implementation is NOT thread safe.
027 */
028public class MockHttpClientConnectionManager implements HttpClientConnectionManager {
029
030   final ConnectionRequest cr;
031
032   /**
033    * Constructor.
034    *
035    * @param c The mocked connection.
036    */
037   public MockHttpClientConnectionManager(final MockHttpConnection c) {
038      final HttpClientConnection hcc = new MockHttpClientConnection(c);
039      this.cr = new ConnectionRequest() {
040         @Override
041         public boolean cancel() {
042            return false;
043         }
044         @Override
045         public HttpClientConnection get(long timeout, TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException {
046            return hcc;
047         }
048      };
049   }
050
051   @Override /* HttpClientConnectionManager */
052   public ConnectionRequest requestConnection(HttpRoute route, Object state) {
053      return cr;
054   }
055
056   @Override /* HttpClientConnectionManager */
057   public void releaseConnection(HttpClientConnection conn, Object newState, long validDuration, TimeUnit timeUnit) {}
058
059   @Override /* HttpClientConnectionManager */
060   public void connect(HttpClientConnection conn, HttpRoute route, int connectTimeout, HttpContext context) throws IOException {}
061
062   @Override /* HttpClientConnectionManager */
063   public void upgrade(HttpClientConnection conn, HttpRoute route, HttpContext context) throws IOException {}
064
065   @Override /* HttpClientConnectionManager */
066   public void routeComplete(HttpClientConnection conn, HttpRoute route, HttpContext context) throws IOException {}
067
068   @Override /* HttpClientConnectionManager */
069   public void closeIdleConnections(long idletime, TimeUnit tunit) {}
070
071   @Override /* HttpClientConnectionManager */
072   public void closeExpiredConnections() {}
073
074   @Override /* HttpClientConnectionManager */
075   public void shutdown() {}
076}