Skip to content

Commit

Permalink
CAMEL-8869 Resolve Switching httpClient from 4.3.x to 4.4.x break tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oscerd committed Jun 14, 2015
1 parent 2da8f19 commit 8252672
Show file tree
Hide file tree
Showing 28 changed files with 1,033 additions and 377 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@
*/ */
public class HttpAuthenticationTest extends BaseHttpTest { public class HttpAuthenticationTest extends BaseHttpTest {


private HttpServer localServer;

private String user = "camel"; private String user = "camel";
private String password = "password"; private String password = "password";


protected HttpServer localServer;

@Before @Before
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap(). localServer = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()). setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()). setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()). setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()). setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()). setSslContext(getSSLContext()).
registerHandler("/search", new AuthenticationValidationHandler("GET", null, null, getExpectedContent(), user, password)).create(); registerHandler("/search", new AuthenticationValidationHandler("GET", null, null, getExpectedContent(), user, password)).create();
localServer.start(); localServer.start();


super.setUp(); super.setUp();
Expand All @@ -76,10 +76,11 @@ public void tearDown() throws Exception {


@Test @Test
public void basicAuthenticationShouldSuccess() throws Exception { public void basicAuthenticationShouldSuccess() throws Exception {
Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/search?authUsername=" + user + "&authPassword=" + password, new Processor() { Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/search?authUsername=" + user + "&authPassword="
public void process(Exchange exchange) throws Exception { + password, new Processor() {
} public void process(Exchange exchange) throws Exception {
}); }
});
assertExchange(exchange); assertExchange(exchange);
} }


Expand Down Expand Up @@ -107,10 +108,11 @@ public void process(Exchange exchange) throws Exception {


@Test @Test
public void basicAuthenticationShouldFailWithWrongCreds() throws Exception { public void basicAuthenticationShouldFailWithWrongCreds() throws Exception {
Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/search?throwExceptionOnFailure=false&authUsername=camel&authPassword=wrong", new Processor() { Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort()
public void process(Exchange exchange) throws Exception { + "/search?throwExceptionOnFailure=false&authUsername=camel&authPassword=wrong", new Processor() {
} public void process(Exchange exchange) throws Exception {
}); }
});


assertExchangeFailed(exchange); assertExchangeFailed(exchange);
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
import org.apache.camel.Processor; import org.apache.camel.Processor;
import org.apache.camel.component.http4.handler.BasicValidationHandler; import org.apache.camel.component.http4.handler.BasicValidationHandler;
import org.apache.camel.component.http4.handler.HeaderValidationHandler; import org.apache.camel.component.http4.handler.HeaderValidationHandler;
import org.apache.http.localserver.LocalTestServer; import org.apache.http.impl.bootstrap.HttpServer;
import org.apache.http.impl.bootstrap.ServerBootstrap;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;




Expand All @@ -37,6 +40,37 @@ public class HttpBodyTest extends BaseHttpTest {
private String protocolString = "http4://"; private String protocolString = "http4://";
// default content encoding of the local test server // default content encoding of the local test server
private String charset = "ISO-8859-1"; private String charset = "ISO-8859-1";
private HttpServer localServer;

@Before
@Override
public void setUp() throws Exception {
Map<String, String> expectedHeaders = new HashMap<String, String>();
expectedHeaders.put("Content-Type", "image/jpeg");

localServer = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()).
registerHandler("/post", new BasicValidationHandler("POST", null, getBody(), getExpectedContent())).
registerHandler("/post1", new HeaderValidationHandler("POST", null, null, getExpectedContent(), expectedHeaders)).
create();
localServer.start();

super.setUp();
}

@After
@Override
public void tearDown() throws Exception {
super.tearDown();

if (localServer != null) {
localServer.stop();
}
}


public String getProtocolString() { public String getProtocolString() {
return protocolString; return protocolString;
Expand All @@ -48,7 +82,7 @@ public void setProtocolString(String protocol) {


@Test @Test
public void httpPostWithStringBody() throws Exception { public void httpPostWithStringBody() throws Exception {
Exchange exchange = template.request(getProtocolString() + getHostName() + ":" + getPort() + "/", new Processor() { Exchange exchange = template.request(getProtocolString() + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/post", new Processor() {
public void process(Exchange exchange) throws Exception { public void process(Exchange exchange) throws Exception {
// without this property, camel use the os default encoding // without this property, camel use the os default encoding
// to create the byte array for the StringRequestEntity // to create the byte array for the StringRequestEntity
Expand All @@ -62,7 +96,7 @@ public void process(Exchange exchange) throws Exception {


@Test @Test
public void httpPostWithByteArrayBody() throws Exception { public void httpPostWithByteArrayBody() throws Exception {
Exchange exchange = template.request(getProtocolString() + getHostName() + ":" + getPort() + "/", new Processor() { Exchange exchange = template.request(getProtocolString() + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/post", new Processor() {
public void process(Exchange exchange) throws Exception { public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(getBody().getBytes(charset)); exchange.getIn().setBody(getBody().getBytes(charset));
} }
Expand All @@ -73,7 +107,7 @@ public void process(Exchange exchange) throws Exception {


@Test @Test
public void httpPostWithInputStreamBody() throws Exception { public void httpPostWithInputStreamBody() throws Exception {
Exchange exchange = template.request(getProtocolString() + getHostName() + ":" + getPort() + "/", new Processor() { Exchange exchange = template.request(getProtocolString() + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/post", new Processor() {
public void process(Exchange exchange) throws Exception { public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(new ByteArrayInputStream(getBody().getBytes(charset))); exchange.getIn().setBody(new ByteArrayInputStream(getBody().getBytes(charset)));
} }
Expand All @@ -84,11 +118,8 @@ public void process(Exchange exchange) throws Exception {


@Test @Test
public void httpPostWithImage() throws Exception { public void httpPostWithImage() throws Exception {
Map<String, String> expectedHeaders = new HashMap<String, String>();
expectedHeaders.put("Content-Type", "image/jpeg");
localServer.register("/", new HeaderValidationHandler("POST", null, null, getExpectedContent(), expectedHeaders));


Exchange exchange = template.send(getProtocolString() + getHostName() + ":" + getPort() + "/", new Processor() { Exchange exchange = template.send(getProtocolString() + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/post1", new Processor() {
public void process(Exchange exchange) throws Exception { public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(new File("src/test/data/logo.jpeg")); exchange.getIn().setBody(new File("src/test/data/logo.jpeg"));
exchange.getIn().setHeader("Content-Type", "image/jpeg"); exchange.getIn().setHeader("Content-Type", "image/jpeg");
Expand All @@ -98,11 +129,6 @@ public void process(Exchange exchange) throws Exception {
assertExchange(exchange); assertExchange(exchange);
} }


@Override
protected void registerHandler(LocalTestServer server) {
server.register("/", new BasicValidationHandler("POST", null, getBody(), getExpectedContent()));
}

protected String getBody() { protected String getBody() {
return "hl=de&q=camel+rocks"; return "hl=de&q=camel+rocks";
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import org.apache.camel.Exchange; import org.apache.camel.Exchange;
import org.apache.camel.Processor; import org.apache.camel.Processor;
import org.apache.camel.component.http4.handler.BasicValidationHandler; import org.apache.camel.component.http4.handler.BasicValidationHandler;
import org.apache.http.localserver.LocalTestServer; import org.apache.http.impl.bootstrap.HttpServer;
import org.apache.http.impl.bootstrap.ServerBootstrap;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;


/** /**
Expand All @@ -28,11 +31,38 @@
*/ */
public class HttpBridgeEndpointTest extends BaseHttpTest { public class HttpBridgeEndpointTest extends BaseHttpTest {


private HttpServer localServer;

@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()).
registerHandler("/", new BasicValidationHandler("GET", null, null, getExpectedContent())).create();
localServer.start();

super.setUp();
}

@After
@Override
public void tearDown() throws Exception {
super.tearDown();

if (localServer != null) {
localServer.stop();
}
}

@Test @Test
public void notBridgeEndpoint() throws Exception { public void notBridgeEndpoint() throws Exception {
Exchange exchange = template.request("http4://host/?bridgeEndpoint=false", new Processor() { Exchange exchange = template.request("http4://host/?bridgeEndpoint=false", new Processor() {
public void process(Exchange exchange) throws Exception { public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.HTTP_URI, "http://" + getHostName() + ":" + getPort() + "/"); exchange.getIn().setHeader(Exchange.HTTP_URI, "http://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/");
} }
}); });


Expand All @@ -41,17 +71,12 @@ public void process(Exchange exchange) throws Exception {


@Test @Test
public void bridgeEndpoint() throws Exception { public void bridgeEndpoint() throws Exception {
Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/?bridgeEndpoint=true", new Processor() { Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/?bridgeEndpoint=true", new Processor() {
public void process(Exchange exchange) throws Exception { public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.HTTP_URI, "http://host:8080/"); exchange.getIn().setHeader(Exchange.HTTP_URI, "http://host:8080/");
} }
}); });


assertExchange(exchange); assertExchange(exchange);
} }

@Override
protected void registerHandler(LocalTestServer server) {
server.register("/", new BasicValidationHandler("GET", null, null, getExpectedContent()));
}
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
import org.apache.http.HttpRequest; import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.apache.http.localserver.LocalTestServer; import org.apache.http.impl.bootstrap.HttpServer;
import org.apache.http.impl.bootstrap.ServerBootstrap;
import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;


/** /**
Expand All @@ -37,9 +40,40 @@
*/ */
public class HttpCamelHeadersTest extends BaseHttpTest { public class HttpCamelHeadersTest extends BaseHttpTest {


private HttpServer localServer;

@Before
@Override
public void setUp() throws Exception {
Map<String, String> expectedHeaders = new HashMap<String, String>();
expectedHeaders.put("TestHeader", "test");
expectedHeaders.put("Accept-Language", "pl");

localServer = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()).
registerHandler("/", new MyHeaderValidationHandler("GET", "HTTP/1.0", getExpectedContent(), expectedHeaders)).create();
localServer.start();

super.setUp();
}

@After
@Override
public void tearDown() throws Exception {
super.tearDown();

if (localServer != null) {
localServer.stop();
}
}

@Test @Test
public void httpHeadersShouldPresent() throws Exception { public void httpHeadersShouldPresent() throws Exception {
Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/", new Processor() { Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/", new Processor() {
public void process(Exchange exchange) throws Exception { public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader("TestHeader", "test"); exchange.getIn().setHeader("TestHeader", "test");
exchange.getIn().setHeader("Accept-Language", "pl"); exchange.getIn().setHeader("Accept-Language", "pl");
Expand All @@ -57,15 +91,6 @@ protected void assertHeaders(Map<String, Object> headers) {
assertEquals("test", headers.get("TestHeader")); assertEquals("test", headers.get("TestHeader"));
assertEquals("pl", headers.get("Accept-Language")); assertEquals("pl", headers.get("Accept-Language"));
} }

@Override
protected void registerHandler(LocalTestServer server) {
Map<String, String> expectedHeaders = new HashMap<String, String>();
expectedHeaders.put("TestHeader", "test");
expectedHeaders.put("Accept-Language", "pl");

server.register("/", new MyHeaderValidationHandler("GET", "HTTP/1.0", getExpectedContent(), expectedHeaders));
}


class MyHeaderValidationHandler extends HeaderValidationHandler { class MyHeaderValidationHandler extends HeaderValidationHandler {
private String expectProtocolVersion; private String expectProtocolVersion;
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
import org.apache.camel.Exchange; import org.apache.camel.Exchange;
import org.apache.camel.Processor; import org.apache.camel.Processor;
import org.apache.camel.component.http4.handler.BasicValidationHandler; import org.apache.camel.component.http4.handler.BasicValidationHandler;
import org.apache.http.localserver.LocalTestServer; import org.apache.http.impl.bootstrap.HttpServer;
import org.apache.http.impl.bootstrap.ServerBootstrap;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;


/** /**
Expand All @@ -32,10 +35,37 @@ public class HttpCharsetTest extends BaseHttpTest {


// default content encoding of the local test server // default content encoding of the local test server
private String charset = "ISO-8859-1"; private String charset = "ISO-8859-1";

private HttpServer localServer;

@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()).
registerHandler("/", new BasicValidationHandler("POST", null, getBody(), getExpectedContent())).create();
localServer.start();

super.setUp();
}

@After
@Override
public void tearDown() throws Exception {
super.tearDown();

if (localServer != null) {
localServer.stop();
}
}


@Test @Test
public void sendCharsetInExchangeProperty() throws Exception { public void sendCharsetInExchangeProperty() throws Exception {
Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/", new Processor() { Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/", new Processor() {
public void process(Exchange exchange) throws Exception { public void process(Exchange exchange) throws Exception {
exchange.setProperty(Exchange.CHARSET_NAME, charset); exchange.setProperty(Exchange.CHARSET_NAME, charset);
exchange.getIn().setBody(getBody()); exchange.getIn().setBody(getBody());
Expand All @@ -47,7 +77,7 @@ public void process(Exchange exchange) throws Exception {


@Test @Test
public void sendByteArrayCharsetInExchangeProperty() throws Exception { public void sendByteArrayCharsetInExchangeProperty() throws Exception {
Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/", new Processor() { Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/", new Processor() {
public void process(Exchange exchange) throws Exception { public void process(Exchange exchange) throws Exception {
exchange.setProperty(Exchange.CHARSET_NAME, charset); exchange.setProperty(Exchange.CHARSET_NAME, charset);
exchange.getIn().setBody(getBody().getBytes(charset)); exchange.getIn().setBody(getBody().getBytes(charset));
Expand All @@ -59,7 +89,7 @@ public void process(Exchange exchange) throws Exception {


@Test @Test
public void sendInputStreamCharsetInExchangeProperty() throws Exception { public void sendInputStreamCharsetInExchangeProperty() throws Exception {
Exchange exchange = template.request("http4://" + getHostName() + ":" + getPort() + "/", new Processor() { Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/", new Processor() {
public void process(Exchange exchange) throws Exception { public void process(Exchange exchange) throws Exception {
exchange.setProperty(Exchange.CHARSET_NAME, charset); exchange.setProperty(Exchange.CHARSET_NAME, charset);
exchange.getIn().setBody(new ByteArrayInputStream(getBody().getBytes(charset))); exchange.getIn().setBody(new ByteArrayInputStream(getBody().getBytes(charset)));
Expand All @@ -69,11 +99,6 @@ public void process(Exchange exchange) throws Exception {
assertExchange(exchange); assertExchange(exchange);
} }


@Override
protected void registerHandler(LocalTestServer server) {
server.register("/", new BasicValidationHandler("POST", null, getBody(), getExpectedContent()));
}

protected String getBody() { protected String getBody() {
char lattinSmallLetterAWithDiaeresis = 0x00E4; char lattinSmallLetterAWithDiaeresis = 0x00E4;
char lattinSmallLetterOWithDiaeresis = 0x00F6; char lattinSmallLetterOWithDiaeresis = 0x00F6;
Expand Down
Loading

0 comments on commit 8252672

Please sign in to comment.