You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/02/23 10:55:08 UTC
svn commit: r915262 - in /camel/trunk/components/camel-cxf: ./
src/test/java/org/apache/camel/component/cxf/cxfbean/
src/test/java/org/apache/camel/component/cxf/jaxrs/
Author: davsclaus
Date: Tue Feb 23 09:55:07 2010
New Revision: 915262
URL: http://svn.apache.org/viewvc?rev=915262&view=rev
Log:
CAMEL-2437: Upgraded camel-cxf to use http client 4.0.1 for testing.
Modified:
camel/trunk/components/camel-cxf/pom.xml
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java
Modified: camel/trunk/components/camel-cxf/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/pom.xml?rev=915262&r1=915261&r2=915262&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/pom.xml (original)
+++ camel/trunk/components/camel-cxf/pom.xml Tue Feb 23 09:55:07 2010
@@ -126,9 +126,9 @@
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.1</version>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>${httpclient4-version}</version>
<scope>test</scope>
</dependency>
Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java?rev=915262&r1=915261&r2=915262&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java (original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java Tue Feb 23 09:55:07 2010
@@ -25,19 +25,18 @@
import org.apache.camel.component.cxf.util.CxfUtils;
import org.apache.camel.wsdl_first.Person;
import org.apache.camel.wsdl_first.PersonService;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.commons.httpclient.methods.RequestEntity;
-import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.util.EntityUtils;
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
/**
*
@@ -61,91 +60,88 @@
in = url.openStream();
assertEquals("{\"Product\":{\"description\":\"product 323\",\"id\":323}}", CxfUtils.getStringFromInputStream(in));
// END SNIPPET: clientInvocation
-
+
}
@Test
public void testPutConsumer() throws Exception {
- PutMethod put = new PutMethod("http://localhost:9000/customerservice/customers");
- RequestEntity entity = new StringRequestEntity(PUT_REQUEST, "text/xml", "ISO-8859-1");
- put.setRequestEntity(entity);
- HttpClient httpclient = new HttpClient();
+ HttpPut put = new HttpPut("http://localhost:9000/customerservice/customers");
+ StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
+ entity.setContentType("text/xml; charset=ISO-8859-1");
+ put.setEntity(entity);
+ HttpClient httpclient = new DefaultHttpClient();
try {
- assertEquals(200, httpclient.executeMethod(put));
- assertEquals("", put.getResponseBodyAsString());
- // need to check the content type
- assertEquals("We should get content-type from the response", "text/xml", put.getResponseHeader("content-type").getValue());
+ HttpResponse response = httpclient.execute(put);
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ assertEquals("", EntityUtils.toString(response.getEntity()));
} finally {
- put.releaseConnection();
+ httpclient.getConnectionManager().shutdown();
}
}
@Test
public void testPostConsumer() throws Exception {
- PostMethod post = new PostMethod("http://localhost:9000/customerservice/customers");
- post.addRequestHeader("Accept" , "text/xml");
- RequestEntity entity = new StringRequestEntity(POST_REQUEST, "text/xml", "ISO-8859-1");
- post.setRequestEntity(entity);
- HttpClient httpclient = new HttpClient();
+ HttpPost post = new HttpPost("http://localhost:9000/customerservice/customers");
+ post.addHeader("Accept" , "text/xml");
+ StringEntity entity = new StringEntity(POST_REQUEST, "ISO-8859-1");
+ entity.setContentType("text/xml; charset=ISO-8859-1");
+ post.setEntity(entity);
+ HttpClient httpclient = new DefaultHttpClient();
try {
- assertEquals(200, httpclient.executeMethod(post));
+ HttpResponse response = httpclient.execute(post);
+ assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Customer><id>124</id><name>Jack</name></Customer>",
- post.getResponseBodyAsString());
- // need to check the content type
- assertEquals("We should get content-type from the response", "text/xml", post.getResponseHeader("content-type").getValue());
+ EntityUtils.toString(response.getEntity()));
} finally {
- post.releaseConnection();
+ httpclient.getConnectionManager().shutdown();
}
-
}
@Test
public void testPostConsumerUniqueResponseCode() throws Exception {
- PostMethod post = new PostMethod("http://localhost:9000/customerservice/customersUniqueResponseCode");
- post.addRequestHeader("Accept" , "text/xml");
- RequestEntity entity = new StringRequestEntity(POST_REQUEST, "text/xml", "ISO-8859-1");
- post.setRequestEntity(entity);
- HttpClient httpclient = new HttpClient();
+ HttpPost post = new HttpPost("http://localhost:9000/customerservice/customersUniqueResponseCode");
+ post.addHeader("Accept" , "text/xml");
+ StringEntity entity = new StringEntity(POST_REQUEST, "ISO-8859-1");
+ entity.setContentType("text/xml; charset=ISO-8859-1");
+ post.setEntity(entity);
+ HttpClient httpclient = new DefaultHttpClient();
try {
- assertEquals(201, httpclient.executeMethod(post));
+ HttpResponse response = httpclient.execute(post);
+ assertEquals(201, response.getStatusLine().getStatusCode());
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Customer><id>125</id><name>Jack</name></Customer>",
- post.getResponseBodyAsString());
- // need to check the content type
- assertEquals("We should get content-type from the response", "text/xml", post.getResponseHeader("content-type").getValue());
+ EntityUtils.toString(response.getEntity()));
} finally {
- post.releaseConnection();
+ httpclient.getConnectionManager().shutdown();
}
-
}
@Test
public void testJaxWsBean() throws Exception {
- PostMethod post = new PostMethod("http://localhost:9090/customerservice/customers");
- post.addRequestHeader("Accept" , "text/xml");
+ HttpPost post = new HttpPost("http://localhost:9090/customerservice/customers");
+ post.addHeader("Accept" , "text/xml");
String body = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<soap:Body><GetPerson xmlns=\"http://camel.apache.org/wsdl-first/types\">"
+ "<personId>hello</personId></GetPerson></soap:Body></soap:Envelope>";
- RequestEntity entity = new StringRequestEntity(body, "text/xml", "ISO-8859-1");
- post.setRequestEntity(entity);
- HttpClient httpclient = new HttpClient();
+ StringEntity entity = new StringEntity(body, "ISO-8859-1");
+ entity.setContentType("text/xml; charset=ISO-8859-1");
+ post.setEntity(entity);
+ HttpClient httpclient = new DefaultHttpClient();
try {
- assertEquals(200, httpclient.executeMethod(post));
- String response = post.getResponseBodyAsString();
+ HttpResponse response = httpclient.execute(post);
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ String responseBody = EntityUtils.toString(response.getEntity());
String correct = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>"
+ "<GetPersonResponse xmlns=\"http://camel.apache.org/wsdl-first/types\">"
+ "<personId>hello</personId><ssn>000-000-0000</ssn><name>Bonjour</name></GetPersonResponse></soap:Body></soap:Envelope>";
- assertEquals("Get a wrong response", correct, response);
- System.out.println(post.getResponseHeader("content-type"));
- // need to check the content type
- assertEquals("We should get content-type from the response", "text/xml", post.getResponseHeader("content-type").getValue());
+ assertEquals("Get a wrong response", correct, responseBody);
} finally {
- post.releaseConnection();
+ httpclient.getConnectionManager().shutdown();
}
}
Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java?rev=915262&r1=915261&r2=915262&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java (original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java Tue Feb 23 09:55:07 2010
@@ -20,8 +20,6 @@
import java.util.LinkedHashMap;
import java.util.Map;
-import javax.ws.rs.core.Response;
-
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Message;
Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java?rev=915262&r1=915261&r2=915262&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java (original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java Tue Feb 23 09:55:07 2010
@@ -18,12 +18,14 @@
package org.apache.camel.component.cxf.jaxrs;
import org.apache.camel.test.junit4.CamelSpringTestSupport;
-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.PutMethod;
-import org.apache.commons.httpclient.methods.RequestEntity;
-import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.util.EntityUtils;
import org.junit.Test;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -39,31 +41,31 @@
@Test
public void testGetCustomer() throws Exception {
- GetMethod get = new GetMethod("http://localhost:9000/customerservice/customers/123");
- get.addRequestHeader("Accept" , "application/json");
-
- HttpClient httpclient = new HttpClient();
+ HttpGet get = new HttpGet("http://localhost:9000/customerservice/customers/123");
+ get.addHeader("Accept" , "application/json");
+ HttpClient httpclient = new DefaultHttpClient();
try {
- assertEquals(200, httpclient.executeMethod(get));
+ HttpResponse response = httpclient.execute(get);
+ assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals("{\"Customer\":{\"id\":123,\"name\":\"John\"}}",
- get.getResponseBodyAsString());
+ EntityUtils.toString(response.getEntity()));
} finally {
- get.releaseConnection();
+ httpclient.getConnectionManager().shutdown();
}
}
@Test
public void testGetCustomers() throws Exception {
- GetMethod get = new GetMethod("http://localhost:9000/customerservice/customers/");
- get.addRequestHeader("Accept" , "application/xml");
-
- HttpClient httpclient = new HttpClient();
+ HttpGet get = new HttpGet("http://localhost:9000/customerservice/customers/");
+ get.addHeader("Accept" , "application/xml");
+ HttpClient httpclient = new DefaultHttpClient();
try {
- assertEquals(200, httpclient.executeMethod(get));
+ HttpResponse response = httpclient.execute(get);
+ assertEquals(200, response.getStatusLine().getStatusCode());
// order returned can differ on OS so match for both orders
- String s = get.getResponseBodyAsString();
+ String s = EntityUtils.toString(response.getEntity());
boolean m1 = "<Customers><Customer><id>123</id><name>John</name></Customer><Customer><id>113</id><name>Dan</name></Customer></Customers>".equals(s);
boolean m2 = "<Customers><Customer><id>113</id><name>Dan</name></Customer><Customer><id>123</id><name>John</name></Customer></Customers>".equals(s);
@@ -71,75 +73,79 @@
fail("Not expected body returned: " + s);
}
} finally {
- get.releaseConnection();
+ httpclient.getConnectionManager().shutdown();
}
}
@Test
public void testGetSubResource() throws Exception {
- GetMethod get = new GetMethod("http://localhost:9000/customerservice/orders/223/products/323");
- get.addRequestHeader("Accept" , "application/json");
-
- HttpClient httpclient = new HttpClient();
+ HttpGet get = new HttpGet("http://localhost:9000/customerservice/orders/223/products/323");
+ get.addHeader("Accept" , "application/json");
+ HttpClient httpclient = new DefaultHttpClient();
try {
- assertEquals(200, httpclient.executeMethod(get));
+ HttpResponse response = httpclient.execute(get);
+ assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals("{\"Product\":{\"description\":\"product 323\",\"id\":323}}",
- get.getResponseBodyAsString());
+ EntityUtils.toString(response.getEntity()));
} finally {
- get.releaseConnection();
+ httpclient.getConnectionManager().shutdown();
}
}
@Test
public void testPutConsumer() throws Exception {
- PutMethod put = new PutMethod("http://localhost:9000/customerservice/customers");
- RequestEntity entity = new StringRequestEntity(PUT_REQUEST, "text/xml", "ISO-8859-1");
- put.setRequestEntity(entity);
- HttpClient httpclient = new HttpClient();
+ HttpPut put = new HttpPut("http://localhost:9000/customerservice/customers");
+ StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
+ entity.setContentType("text/xml; charset=ISO-8859-1");
+ put.setEntity(entity);
+ HttpClient httpclient = new DefaultHttpClient();
try {
- assertEquals(200, httpclient.executeMethod(put));
- assertEquals("", put.getResponseBodyAsString());
+ HttpResponse response = httpclient.execute(put);
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ assertEquals("", EntityUtils.toString(response.getEntity()));
} finally {
- put.releaseConnection();
+ httpclient.getConnectionManager().shutdown();
}
}
@Test
public void testPostConsumer() throws Exception {
- PostMethod post = new PostMethod("http://localhost:9000/customerservice/customers");
- post.addRequestHeader("Accept" , "text/xml");
- RequestEntity entity = new StringRequestEntity(POST_REQUEST, "text/xml", "ISO-8859-1");
- post.setRequestEntity(entity);
- HttpClient httpclient = new HttpClient();
+ HttpPost post = new HttpPost("http://localhost:9000/customerservice/customers");
+ post.addHeader("Accept" , "text/xml");
+ StringEntity entity = new StringEntity(POST_REQUEST, "ISO-8859-1");
+ entity.setContentType("text/xml; charset=ISO-8859-1");
+ post.setEntity(entity);
+ HttpClient httpclient = new DefaultHttpClient();
try {
- assertEquals(200, httpclient.executeMethod(post));
+ HttpResponse response = httpclient.execute(post);
+ assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Customer><id>124</id><name>Jack</name></Customer>",
- post.getResponseBodyAsString());
+ EntityUtils.toString(response.getEntity()));
} finally {
- post.releaseConnection();
+ httpclient.getConnectionManager().shutdown();
}
}
@Test
public void testPostConsumerUniqueResponseCode() throws Exception {
- PostMethod post = new PostMethod("http://localhost:9000/customerservice/customersUniqueResponseCode");
- post.addRequestHeader("Accept" , "text/xml");
- RequestEntity entity = new StringRequestEntity(POST_REQUEST, "text/xml", "ISO-8859-1");
- post.setRequestEntity(entity);
- HttpClient httpclient = new HttpClient();
+ HttpPost post = new HttpPost("http://localhost:9000/customerservice/customersUniqueResponseCode");
+ post.addHeader("Accept" , "text/xml");
+ StringEntity entity = new StringEntity(POST_REQUEST, "ISO-8859-1");
+ entity.setContentType("text/xml; charset=ISO-8859-1");
+ post.setEntity(entity);
+ HttpClient httpclient = new DefaultHttpClient();
try {
- assertEquals(201, httpclient.executeMethod(post));
+ HttpResponse response = httpclient.execute(post);
+ assertEquals(201, response.getStatusLine().getStatusCode());
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Customer><id>124</id><name>Jack</name></Customer>",
- post.getResponseBodyAsString());
+ EntityUtils.toString(response.getEntity()));
} finally {
- post.releaseConnection();
+ httpclient.getConnectionManager().shutdown();
}
-
}
-
-}
+}
\ No newline at end of file