This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new c559751 CAMEL-14640: Upgrade to http client 4.x for testing.
c559751 is described below
commit c559751931ec10f5a4da37b7ec078d5dc14caf91
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Mar 26 07:26:50 2020 +0100
CAMEL-14640: Upgrade to http client 4.x for testing.
---
components/camel-undertow/pom.xml | 5 ---
.../undertow/UndertowMethodRestricTest.java | 37 +++++++++-------
.../undertow/UndertowMuteExceptionTest.java | 51 +++++++++++++---------
.../undertow/UndertowTransferExceptionTest.java | 23 ++++++----
4 files changed, 67 insertions(+), 49 deletions(-)
diff --git a/components/camel-undertow/pom.xml
b/components/camel-undertow/pom.xml
index 30997f0..f0a96c4 100644
--- a/components/camel-undertow/pom.xml
+++ b/components/camel-undertow/pom.xml
@@ -68,11 +68,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http</artifactId>
<scope>test</scope>
diff --git
a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowMethodRestricTest.java
b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowMethodRestricTest.java
index 87fb263..905177e 100644
---
a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowMethodRestricTest.java
+++
b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowMethodRestricTest.java
@@ -18,10 +18,13 @@ package org.apache.camel.component.undertow;
import org.apache.camel.Message;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -36,27 +39,31 @@ public class UndertowMethodRestricTest extends
BaseUndertowTest {
@Test
public void testProperHttpMethod() throws Exception {
- HttpClient httpClient = new HttpClient();
- PostMethod httpPost = new PostMethod(url);
+ CloseableHttpClient client = HttpClients.createDefault();
- StringRequestEntity reqEntity = new StringRequestEntity("This is a
test", null, null);
- httpPost.setRequestEntity(reqEntity);
+ HttpPost httpPost = new HttpPost(url);
+ httpPost.setEntity(new StringEntity("This is a test"));
- int status = httpClient.executeMethod(httpPost);
+ HttpResponse response = client.execute(httpPost);
- assertEquals(200, status);
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ String responseString = EntityUtils.toString(response.getEntity(),
"UTF-8");
+ assertEquals("This is a test response", responseString);
- String result = httpPost.getResponseBodyAsString();
- assertEquals("This is a test response", result);
+ client.close();
}
@Test
public void testImproperHttpMethod() throws Exception {
- HttpClient httpClient = new HttpClient();
- GetMethod httpGet = new GetMethod(url);
- int status = httpClient.executeMethod(httpGet);
+ CloseableHttpClient client = HttpClients.createDefault();
+
+ HttpGet httpGet = new HttpGet(url);
+ HttpResponse response = client.execute(httpGet);
+ int status = response.getStatusLine().getStatusCode();
assertEquals("Get a wrong response status", 405, status);
+
+ client.close();
}
@Override
diff --git
a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowMuteExceptionTest.java
b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowMuteExceptionTest.java
index 970815e..4c45d18 100644
---
a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowMuteExceptionTest.java
+++
b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowMuteExceptionTest.java
@@ -17,8 +17,11 @@
package org.apache.camel.component.undertow;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
import org.junit.Assert;
import org.junit.Test;
@@ -26,28 +29,36 @@ public class UndertowMuteExceptionTest extends
BaseUndertowTest {
@Test
public void muteExceptionTest() throws Exception {
- HttpClient client = new HttpClient();
- GetMethod get = new GetMethod("http://localhost:" + getPort() +
"/test/mute");
- get.setRequestHeader("Accept", "application/text");
- client.executeMethod(get);
-
- String body = get.getResponseBodyAsString();
- Assert.assertNotNull(body);
- Assert.assertEquals("Exception", body);
- Assert.assertEquals(500, get.getStatusCode());
+ CloseableHttpClient client = HttpClients.createDefault();
+
+ HttpGet get = new HttpGet("http://localhost:" + getPort() +
"/test/mute");
+ get.addHeader("Accept", "application/text");
+ HttpResponse response = client.execute(get);
+
+ String responseString = EntityUtils.toString(response.getEntity(),
"UTF-8");
+ Assert.assertNotNull(responseString);
+ Assert.assertEquals("Exception", responseString);
+ Assert.assertEquals(500, response.getStatusLine().getStatusCode());
+
+ client.close();
}
@Test
public void muteExceptionWithTransferExceptionTest() throws Exception {
- HttpClient client = new HttpClient();
- GetMethod get = new GetMethod("http://localhost:" + getPort() +
"/test/muteWithTransfer");
- get.setRequestHeader("Accept", "application/text");
- client.executeMethod(get);
-
- String body = get.getResponseBodyAsString();
- Assert.assertNotNull(body);
- Assert.assertEquals("Exception", body);
- Assert.assertEquals(500, get.getStatusCode());
+ CloseableHttpClient client = HttpClients.createDefault();
+
+ HttpGet get = new HttpGet("http://localhost:" + getPort() +
"/test/muteWithTransfer");
+ get.addHeader("Accept", "application/text");
+
+ HttpResponse response = client.execute(get);
+
+ String responseString = EntityUtils.toString(response.getEntity(),
"UTF-8");
+ Assert.assertNotNull(responseString);
+ Assert.assertEquals("Exception", responseString);
+
+ Assert.assertEquals(500, response.getStatusLine().getStatusCode());
+
+ client.close();
}
@Override
diff --git
a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowTransferExceptionTest.java
b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowTransferExceptionTest.java
index 7b8db64..f52e5c4 100644
---
a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowTransferExceptionTest.java
+++
b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowTransferExceptionTest.java
@@ -20,8 +20,10 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
import org.junit.Assert;
import org.junit.Test;
@@ -29,15 +31,19 @@ public class UndertowTransferExceptionTest extends
BaseUndertowTest {
@Test
public void getSerializedExceptionTest() throws IOException,
ClassNotFoundException {
- HttpClient client = new HttpClient();
- GetMethod get = new GetMethod("http://localhost:" + getPort() +
"/test/transfer");
- get.setRequestHeader("Accept", "application/x-java-serialized-object");
- client.executeMethod(get);
- ObjectInputStream in = new
ObjectInputStream(get.getResponseBodyAsStream());
+ CloseableHttpClient client = HttpClients.createDefault();
+ HttpGet get = new HttpGet("http://localhost:" + getPort() +
"/test/transfer");
+ get.addHeader("Accept", "application/x-java-serialized-object");
+
+ HttpResponse response = client.execute(get);
+
+ ObjectInputStream in = new
ObjectInputStream(response.getEntity().getContent());
IllegalArgumentException e = (IllegalArgumentException)in.readObject();
Assert.assertNotNull(e);
- Assert.assertEquals(500, get.getStatusCode());
+ Assert.assertEquals(500, response.getStatusLine().getStatusCode());
Assert.assertEquals("Camel cannot do this", e.getMessage());
+
+ client.close();
}
@Override
@@ -45,7 +51,6 @@ public class UndertowTransferExceptionTest extends
BaseUndertowTest {
return new RouteBuilder() {
public void configure() {
-
from("undertow:http://localhost:" + getPort() +
"/test/transfer?transferException=true").to("mock:input")
.throwException(new IllegalArgumentException("Camel cannot
do this"));
}