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 2009/06/24 10:58:03 UTC
svn commit: r787947 - in /camel/trunk:
components/camel-jaxb/src/test/java/org/apache/camel/example/
components/camel-jms/src/main/java/org/apache/camel/component/jms/
tests/camel-itest/
tests/camel-itest/src/test/java/org/apache/camel/itest/jms/ tests...
Author: davsclaus
Date: Wed Jun 24 08:58:02 2009
New Revision: 787947
URL: http://svn.apache.org/viewvc?rev=787947&view=rev
Log:
CAMEL-1749: Added unit test based on user problem with loosing body sending over JMS. Improved feedback from Camel when it uses a generic JMS message instead of specialized.
Added:
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/InvalidOrderException.java (with props)
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/RouteWithErrorHandlerTest.java (with props)
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/InvalidOrderException.java (with props)
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsJaxbTest.java (with props)
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/PurchaseOrder.java (with props)
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/jaxb.index
Modified:
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
camel/trunk/tests/camel-itest/pom.xml
Added: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/InvalidOrderException.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/InvalidOrderException.java?rev=787947&view=auto
==============================================================================
--- camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/InvalidOrderException.java (added)
+++ camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/InvalidOrderException.java Wed Jun 24 08:58:02 2009
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.example;
+
+/**
+ * @version $Revision$
+ */
+public class InvalidOrderException extends Exception {
+
+ public InvalidOrderException(String message) {
+ super(message);
+ }
+
+}
Propchange: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/InvalidOrderException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/InvalidOrderException.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/RouteWithErrorHandlerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/RouteWithErrorHandlerTest.java?rev=787947&view=auto
==============================================================================
--- camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/RouteWithErrorHandlerTest.java (added)
+++ camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/RouteWithErrorHandlerTest.java Wed Jun 24 08:58:02 2009
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.example;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.jaxb.JaxbDataFormat;
+import org.apache.camel.spi.DataFormat;
+
+/**
+ * @version $Revision$
+ */
+public class RouteWithErrorHandlerTest extends ContextTestSupport {
+
+ public void testOk() throws Exception {
+ PurchaseOrder order = new PurchaseOrder();
+ order.setName("Wine");
+ order.setAmount(123.45);
+ order.setPrice(2.22);
+
+ MockEndpoint result = getMockEndpoint("mock:wine");
+ result.expectedBodiesReceived(order);
+
+ template.sendBody("direct:start", "<purchaseOrder name='Wine' amount='123.45' price='2.22'/>");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testUnmarshalError() throws Exception {
+ MockEndpoint error = getMockEndpoint("mock:error");
+ error.expectedBodiesReceived("<foo/>");
+ getMockEndpoint("mock:invalid").expectedMessageCount(0);
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+
+ template.sendBody("direct:start", "<foo/>");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testNotWine() throws Exception {
+ PurchaseOrder order = new PurchaseOrder();
+ order.setName("Beer");
+ order.setAmount(2);
+ order.setPrice(1.99);
+
+ MockEndpoint error = getMockEndpoint("mock:invalid");
+ error.expectedBodiesReceived(order);
+ getMockEndpoint("mock:error").expectedMessageCount(0);
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+
+ template.sendBody("direct:start", "<purchaseOrder name='Beer' amount='2.0' price='1.99'/>");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ errorHandler(deadLetterChannel("mock:error").redeliverDelay(0));
+
+ onException(InvalidOrderException.class).maximumRedeliveries(0).handled(true)
+ .to("mock:invalid");
+
+ DataFormat jaxb = new JaxbDataFormat("org.apache.camel.example");
+
+ from("direct:start")
+ .unmarshal(jaxb)
+ .choice()
+ .when().method(RouteWithErrorHandlerTest.class, "isWine").to("mock:wine")
+ .otherwise().throwException(new InvalidOrderException("We only like wine"))
+ .end();
+ }
+ };
+ }
+
+ public static boolean isWine(PurchaseOrder order) {
+ return "Wine".equalsIgnoreCase(order.getName());
+ }
+}
Propchange: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/RouteWithErrorHandlerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/RouteWithErrorHandlerTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java?rev=787947&r1=787946&r2=787947&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java Wed Jun 24 08:58:02 2009
@@ -398,10 +398,12 @@
}
// TODO: should we throw an exception instead?
- if (LOG.isDebugEnabled()) {
- LOG.debug("Could not determine specific JmsMessage type to use from body."
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Cannot determine specific JmsMessage type to use from body class."
+ " Will use generic JmsMessage."
- + (body != null ? (" Body class: " + body.getClass().getCanonicalName()) : ""));
+ + (body != null ? (" Body class: " + body.getClass().getCanonicalName()) : " Body is null")
+ + ". If you want to send a POJO then your class might need to implement java.io.Serializable"
+ + ", or you can force a specific type by setting the jmsMessageType option on the JMS endpoint.");
}
// return a default message
Modified: camel/trunk/tests/camel-itest/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/pom.xml?rev=787947&r1=787946&r2=787947&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/pom.xml (original)
+++ camel/trunk/tests/camel-itest/pom.xml Wed Jun 24 08:58:02 2009
@@ -62,7 +62,12 @@
<artifactId>camel-http</artifactId>
<scope>test</scope>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jaxb</artifactId>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-mail</artifactId>
Added: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/InvalidOrderException.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/InvalidOrderException.java?rev=787947&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/InvalidOrderException.java (added)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/InvalidOrderException.java Wed Jun 24 08:58:02 2009
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.itest.jms;
+
+/**
+ * @version $Revision$
+ */
+public class InvalidOrderException extends Exception {
+
+ public InvalidOrderException(String message) {
+ super(message);
+ }
+}
Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/InvalidOrderException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/InvalidOrderException.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsJaxbTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsJaxbTest.java?rev=787947&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsJaxbTest.java (added)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsJaxbTest.java Wed Jun 24 08:58:02 2009
@@ -0,0 +1,116 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.itest.jms;
+
+import javax.naming.Context;
+
+import org.apache.activemq.camel.component.ActiveMQComponent;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.jaxb.JaxbDataFormat;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.util.jndi.JndiContext;
+
+/**
+ * @version $Revision$
+ */
+public class JmsJaxbTest extends ContextTestSupport {
+
+ public void testOk() throws Exception {
+ PurchaseOrder order = new PurchaseOrder();
+ order.setName("Wine");
+ order.setAmount(123.45);
+ order.setPrice(2.22);
+
+ MockEndpoint result = getMockEndpoint("mock:wine");
+ result.expectedBodiesReceived(order);
+
+ template.sendBody("jms:queue:in", "<purchaseOrder name='Wine' amount='123.45' price='2.22'/>");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testUnmarshalError() throws Exception {
+ MockEndpoint error = getMockEndpoint("mock:error");
+ error.expectedBodiesReceived("<foo/>");
+ getMockEndpoint("mock:invalid").expectedMessageCount(0);
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+
+ template.sendBody("jms:queue:in", "<foo/>");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testNotWine() throws Exception {
+ PurchaseOrder order = new PurchaseOrder();
+ order.setName("Beer");
+ order.setAmount(2);
+ order.setPrice(1.99);
+
+ MockEndpoint error = getMockEndpoint("mock:invalid");
+ error.expectedBodiesReceived(order);
+ getMockEndpoint("mock:error").expectedMessageCount(0);
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+
+ template.sendBody("jms:queue:in", "<purchaseOrder name='Beer' amount='2.0' price='1.99'/>");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected Context createJndiContext() throws Exception {
+ JndiContext answer = new JndiContext();
+
+ // add ActiveMQ with embedded broker
+ ActiveMQComponent amq = ActiveMQComponent.activeMQComponent("vm://localhost?broker.persistent=false");
+ amq.setCamelContext(context);
+ answer.bind("jms", amq);
+ return answer;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ errorHandler(deadLetterChannel("jms:queue:error").redeliverDelay(0));
+
+ onException(InvalidOrderException.class).maximumRedeliveries(0).handled(true)
+ .to("jms:queue:invalid");
+
+ DataFormat jaxb = new JaxbDataFormat("org.apache.camel.itest.jms");
+
+ from("jms:queue:in")
+ .unmarshal(jaxb)
+ .choice()
+ .when().method(JmsJaxbTest.class, "isWine").to("jms:queue:wine")
+ .otherwise().throwException(new InvalidOrderException("We only like wine"))
+ .end();
+
+ from("jms:queue:wine").to("mock:wine");
+ from("jms:queue:error").to("mock:error");
+ from("jms:queue:invalid").to("mock:invalid");
+ }
+ };
+ }
+
+ public static boolean isWine(PurchaseOrder order) {
+ return "Wine".equalsIgnoreCase(order.getName());
+ }
+
+}
Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsJaxbTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsJaxbTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/PurchaseOrder.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/PurchaseOrder.java?rev=787947&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/PurchaseOrder.java (added)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/PurchaseOrder.java Wed Jun 24 08:58:02 2009
@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.itest.jms;
+
+import java.io.Serializable;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * @version $Revision$
+ */
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class PurchaseOrder implements Serializable {
+ @XmlAttribute
+ private String name;
+ @XmlAttribute
+ private double price;
+ @XmlAttribute
+ private double amount;
+
+ @Override
+ public String toString() {
+ return "PurchaseOrder[name: " + name + " amount: " + amount + " price: " + price + "]";
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof PurchaseOrder) {
+ PurchaseOrder that = (PurchaseOrder)o;
+ return ObjectHelper.equal(this.name, that.name) && ObjectHelper.equal(this.amount, that.amount)
+ && ObjectHelper.equal(this.price, that.price);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode() + (int)Math.round(price * 100) + (int)Math.round(amount * 100);
+ }
+
+ public double getAmount() {
+ return amount;
+ }
+
+ public void setAmount(double amount) {
+ this.amount = amount;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public double getPrice() {
+ return price;
+ }
+
+ public void setPrice(double price) {
+ this.price = price;
+ }
+
+}
Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/PurchaseOrder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/PurchaseOrder.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/jaxb.index
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/jaxb.index?rev=787947&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/jaxb.index (added)
+++ camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/jaxb.index Wed Jun 24 08:58:02 2009
@@ -0,0 +1,17 @@
+## ------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You 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.
+## ------------------------------------------------------------------------
+PurchaseOrder
\ No newline at end of file