001/* 002 * Copyright 2002-2014 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.mock.http.client; 018 019import java.io.IOException; 020import java.net.URI; 021 022import org.springframework.http.HttpMethod; 023import org.springframework.http.client.AsyncClientHttpRequest; 024import org.springframework.http.client.ClientHttpResponse; 025import org.springframework.util.concurrent.ListenableFuture; 026import org.springframework.util.concurrent.SettableListenableFuture; 027 028/** 029 * An extension of {@link MockClientHttpRequest} that also implements 030 * {@link AsyncClientHttpRequest} by wrapping the response in a 031 * {@link SettableListenableFuture}. 032 * 033 * @author Rossen Stoyanchev 034 * @author Sam Brannen 035 * @since 4.1 036 */ 037public class MockAsyncClientHttpRequest extends MockClientHttpRequest implements AsyncClientHttpRequest { 038 039 public MockAsyncClientHttpRequest() { 040 } 041 042 public MockAsyncClientHttpRequest(HttpMethod httpMethod, URI uri) { 043 super(httpMethod, uri); 044 } 045 046 047 @Override 048 public ListenableFuture<ClientHttpResponse> executeAsync() throws IOException { 049 SettableListenableFuture<ClientHttpResponse> future = new SettableListenableFuture<ClientHttpResponse>(); 050 future.set(execute()); 051 return future; 052 } 053 054}