/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.redblackit.web.client;
import org.apache.http.client.HttpClient;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
/**
* @author djnorth
*
* Based on Spring test class AbstractHttpRequestFactoryTestCase, but
* <ul>
* <li>allowing for http and https tests using appropriate http clients</li>
* <li>correcting redirect test to allow for transparent re-direction by
* HttpClient 4.x.</li>
* <li>using EmbeddedJettyServer wrapper class</li>
* <li>using EchoServer from com.redblacit.web</li>
* </ul>
*/
public class HttpComponentsHttpRequestFactoryTest extends AbstractClientHttpRequestFactoryTestBase {
/**
* HttpClient we wrap
*/
private HttpClient httpClient;
/**
* Constructor taking the variables for the tests i.e. the HttpClient to
* use, scheme and port
*
* @param httpClient
* @param scheme
* @param port
*/
public HttpComponentsHttpRequestFactoryTest(HttpClient httpClient,
String scheme, int port) {
super(scheme + "://" + hostname + ':' + port);
this.httpClient = httpClient;
}
/**
* Override template method to create new Spring request factory
*
* @return factory
* @see AbstractClientHttpRequestFactoryTestBase#createSpecificFactory()
*/
@Override
protected ClientHttpRequestFactory createSpecificFactory() {
HttpComponentsClientHttpRequestFactory specificFactory = new HttpComponentsClientHttpRequestFactory();
specificFactory.setHttpClient(httpClient);
return specificFactory;
}
}