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 2017/09/22 07:29:52 UTC
camel git commit: CAMEL-11804:Add tests that checks
DESTINATION_OVERRIDE_URL
Repository: camel
Updated Branches:
refs/heads/master 280d9e948 -> de3127e63
CAMEL-11804:Add tests that checks DESTINATION_OVERRIDE_URL
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/de3127e6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/de3127e6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/de3127e6
Branch: refs/heads/master
Commit: de3127e638ecc1dc3d9563209acd60a3bc2ca5f9
Parents: 280d9e9
Author: Rajani-K <ra...@gmail.com>
Authored: Fri Sep 22 10:33:48 2017 +0530
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Sep 22 09:24:02 2017 +0200
----------------------------------------------------------------------
.../cxf/jaxrs/CxfRsAsyncProducerTest.java | 20 ++--
.../jaxrs/CxfRsProducerAddressOverrideTest.java | 114 ++++++++++++++++++-
.../component/cxf/jaxrs/CxfRsProducerTest.java | 24 ++--
3 files changed, 133 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/de3127e6/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsAsyncProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsAsyncProducerTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsAsyncProducerTest.java
index b7ee1c4..4f083f4 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsAsyncProducerTest.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsAsyncProducerTest.java
@@ -101,8 +101,8 @@ public class CxfRsAsyncProducerTest extends CamelSpringTestSupport {
Customer response = (Customer) exchange.getOut().getBody();
assertNotNull("The response should not be null ", response);
- assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
- assertEquals("Get a wrong customer name", response.getName(), "John");
+ assertEquals("Get a wrong customer id ", 123, response.getId());
+ assertEquals("Get a wrong customer name", "John", response.getName());
assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
assertEquals("Get a wrong header value", "value", exchange.getOut().getHeader("key"));
// END SNIPPET: ProxyExample
@@ -181,8 +181,8 @@ public class CxfRsAsyncProducerTest extends CamelSpringTestSupport {
Customer response = (Customer) exchange.getOut().getBody();
assertNotNull("The response should not be null ", response);
- assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
- assertEquals("Get a wrong customer name", response.getName(), "John");
+ assertEquals("Get a wrong customer id ", 123, response.getId());
+ assertEquals("Get a wrong customer name", "John", response.getName());
assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
assertEquals("Get a wrong header value", "value", exchange.getOut().getHeader("key"));
}
@@ -207,7 +207,7 @@ public class CxfRsAsyncProducerTest extends CamelSpringTestSupport {
// we should get the exception here
assertNull("Don't expect the exception here", exchange.getException());
Message result = exchange.getOut();
- assertEquals("Get a wrong http status code.", result.getHeader(Exchange.HTTP_RESPONSE_CODE), 406);
+ assertEquals("Get a wrong http status code.", 406, result.getHeader(Exchange.HTTP_RESPONSE_CODE));
}
@@ -256,8 +256,8 @@ public class CxfRsAsyncProducerTest extends CamelSpringTestSupport {
// get the response message
Customer response = (Customer) exchange.getOut().getBody();
assertNotNull("The response should not be null ", response);
- assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
- assertEquals("Get a wrong customer name", response.getName(), "John");
+ assertEquals("Get a wrong customer id ", 123, response.getId());
+ assertEquals("Get a wrong customer name", "John", response.getName());
assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
}
@@ -281,8 +281,8 @@ public class CxfRsAsyncProducerTest extends CamelSpringTestSupport {
// get the response message
Customer response = (Customer) exchange.getOut().getBody();
assertNotNull("The response should not be null ", response);
- assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
- assertEquals("Get a wrong customer name", response.getName(), "John");
+ assertEquals("Get a wrong customer id ", 123, response.getId());
+ assertEquals("Get a wrong customer name", "John", response.getName());
assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
}
@@ -367,7 +367,7 @@ public class CxfRsAsyncProducerTest extends CamelSpringTestSupport {
Customer response = (Customer) exchange.getOut().getBody();
assertNotNull("The response should not be null ", response);
assertTrue("Get a wrong customer id ", response.getId() != 8888);
- assertEquals("Get a wrong customer name", response.getName(), "Willem");
+ assertEquals("Get a wrong customer name", "Willem", response.getName());
assertEquals("Get a wrong response code", 201, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
}
http://git-wip-us.apache.org/repos/asf/camel/blob/de3127e6/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerAddressOverrideTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerAddressOverrideTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerAddressOverrideTest.java
index 3f9eebb..4690778 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerAddressOverrideTest.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerAddressOverrideTest.java
@@ -17,13 +17,23 @@
package org.apache.camel.component.cxf.jaxrs;
import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
import org.apache.camel.Message;
+import org.apache.camel.Processor;
import org.apache.camel.component.cxf.CXFTestSupport;
+import org.apache.camel.component.cxf.common.message.CxfConstants;
+import org.apache.camel.component.cxf.jaxrs.testbean.Customer;
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.junit.Test;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
-public class CxfRsProducerAddressOverrideTest extends CxfRsProducerTest {
+public class CxfRsProducerAddressOverrideTest extends CamelSpringTestSupport {
+ private static int port1 = CXFTestSupport.getPort1();
private static int port2 = CXFTestSupport.getPort("CxfRsProducerAddressOverrideTest.jetty");
+ public int getPort1() {
+ return port1;
+ }
public int getPort2() {
return port2;
}
@@ -37,4 +47,106 @@ public class CxfRsProducerAddressOverrideTest extends CxfRsProducerTest {
inMessage.setHeader(Exchange.DESTINATION_OVERRIDE_URL,
"http://localhost:" + getPort1() + "/CxfRsProducerAddressOverrideTest");
}
+
+ @Test
+ public void testGetCustomerWithSyncProxyAPIByOverrideDest() {
+ Exchange exchange = template.send("direct://proxy", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.setPattern(ExchangePattern.InOut);
+ Message inMessage = exchange.getIn();
+ // set the operation name
+ inMessage.setHeader(CxfConstants.OPERATION_NAME, "getCustomer");
+ // using the proxy client API
+ inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.FALSE);
+ // set the parameters , if you just have one parameter
+ // camel will put this object into an Object[] itself
+ inMessage.setBody("123");
+ setupDestinationURL(inMessage);
+ }
+ });
+
+ // get the response message
+ Customer response = (Customer) exchange.getOut().getBody();
+
+ assertNotNull("The response should not be null ", response);
+ assertEquals("Get a wrong customer id ", 123, response.getId());
+ assertEquals("Get a wrong customer name", "John", response.getName());
+ }
+
+ @Test
+ public void testGetCustomerWithSyncHttpAPIByOverrideDest() {
+ Exchange exchange = template.send("direct://http", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.setPattern(ExchangePattern.InOut);
+ Message inMessage = exchange.getIn();
+ // using the http central client API
+ inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.TRUE);
+ // set the Http method
+ inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
+ // set the relative path
+ inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");
+ // Specify the response class , cxfrs will use InputStream as the response object type
+ inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
+ setupDestinationURL(inMessage);
+ }
+ });
+
+ // get the response message
+ Customer response = (Customer) exchange.getOut().getBody();
+
+ assertNotNull("The response should not be null ", response);
+ assertEquals("Get a wrong customer id ", 123, response.getId());
+ assertEquals("Get a wrong customer name", "John", response.getName());
+ }
+
+ @Test
+ public void testGetCustomerWithAsyncProxyAPIByOverrideDest() {
+ Exchange exchange = template.send("cxfrs:bean:rsClientProxy", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.setPattern(ExchangePattern.InOut);
+ Message inMessage = exchange.getIn();
+ // set the operation name
+ inMessage.setHeader(CxfConstants.OPERATION_NAME, "getCustomer");
+ // using the proxy client API
+ inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.FALSE);
+ // set the parameters , if you just have one parameter
+ // camel will put this object into an Object[] itself
+ inMessage.setBody("123");
+ setupDestinationURL(inMessage);
+ }
+ });
+
+ // get the response message
+ Customer response = (Customer) exchange.getOut().getBody();
+
+ assertNotNull("The response should not be null ", response);
+ assertEquals("Get a wrong customer id ", 123, response.getId());
+ assertEquals("Get a wrong customer name", "John", response.getName());
+ }
+
+ @Test
+ public void testGetCustomerWithAsyncHttpAPIByOverrideDest() {
+ Exchange exchange = template.send("cxfrs:bean:rsClientHttp", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.setPattern(ExchangePattern.InOut);
+ Message inMessage = exchange.getIn();
+ // using the http central client API
+ inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.TRUE);
+ // set the Http method
+ inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
+ // set the relative path
+ inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");
+ // Specify the response class , cxfrs will use InputStream as the response object type
+ inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
+ setupDestinationURL(inMessage);
+ }
+ });
+
+ // get the response message
+ Customer response = (Customer) exchange.getOut().getBody();
+
+ assertNotNull("The response should not be null", response);
+ assertEquals("Get a wrong customer id ", 123, response.getId());
+ assertEquals("Get a wrong customer name", "John", response.getName());
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/de3127e6/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
index 4c10298..7ec6f9d 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
@@ -84,7 +84,6 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOut);
Message inMessage = exchange.getIn();
- setupDestinationURL(inMessage);
// set the operation name
inMessage.setHeader(CxfConstants.OPERATION_NAME, "getCustomer");
// using the proxy client API
@@ -103,8 +102,8 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
Customer response = (Customer) exchange.getOut().getBody();
assertNotNull("The response should not be null ", response);
- assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
- assertEquals("Get a wrong customer name", response.getName(), "John");
+ assertEquals("Get a wrong customer id ", 123, response.getId());
+ assertEquals("Get a wrong customer name", "John", response.getName());
assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
assertEquals("Get a wrong header value", "value", exchange.getOut().getHeader("key"));
// END SNIPPET: ProxyExample
@@ -116,7 +115,6 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOut);
Message inMessage = exchange.getIn();
- setupDestinationURL(inMessage);
// set the operation name
inMessage.setHeader(CxfConstants.OPERATION_NAME, "getCustomers");
// using the proxy client API
@@ -143,7 +141,6 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOut);
Message inMessage = exchange.getIn();
- setupDestinationURL(inMessage);
// using the http central client API
inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.TRUE);
// set the Http method
@@ -163,8 +160,8 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
Customer response = (Customer) exchange.getOut().getBody();
assertNotNull("The response should not be null ", response);
- assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
- assertEquals("Get a wrong customer name", response.getName(), "John");
+ assertEquals("Get a wrong customer id ", 123, response.getId());
+ assertEquals("Get a wrong customer name", "John", response.getName());
assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
assertEquals("Get a wrong header value", "value", exchange.getOut().getHeader("key"));
// END SNIPPET: HttpExample
@@ -192,7 +189,7 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
// we should get the exception here
assertNull("Don't expect the exception here", exchange.getException());
Message result = exchange.getOut();
- assertEquals("Get a wrong http status code.", result.getHeader(Exchange.HTTP_RESPONSE_CODE), 406);
+ assertEquals("Get a wrong http status code.", 406, result.getHeader(Exchange.HTTP_RESPONSE_CODE));
}
@@ -245,8 +242,8 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
// get the response message
Customer response = (Customer) exchange.getOut().getBody();
assertNotNull("The response should not be null ", response);
- assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
- assertEquals("Get a wrong customer name", response.getName(), "John");
+ assertEquals("Get a wrong customer id ", 123, response.getId());
+ assertEquals("Get a wrong customer name", "John", response.getName());
assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
}
@@ -272,8 +269,8 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
// get the response message
Customer response = (Customer) exchange.getOut().getBody();
assertNotNull("The response should not be null ", response);
- assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
- assertEquals("Get a wrong customer name", response.getName(), "John");
+ assertEquals("Get a wrong customer id ", 123, response.getId());
+ assertEquals("Get a wrong customer name", "John", response.getName());
assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
}
@@ -312,7 +309,6 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOut);
Message inMessage = exchange.getIn();
- setupDestinationURL(inMessage);
// set the operation name
inMessage.setHeader(CxfConstants.OPERATION_NAME, "addCustomerUniqueResponseCode");
// using the proxy client API
@@ -362,7 +358,7 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
Customer response = (Customer) exchange.getOut().getBody();
assertNotNull("The response should not be null ", response);
assertTrue("Get a wrong customer id ", response.getId() != 8888);
- assertEquals("Get a wrong customer name", response.getName(), "Willem");
+ assertEquals("Get a wrong customer name", "Willem", response.getName());
assertEquals("Get a wrong response code", 201, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
}