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
commit 8ae074c51f2ce43141a9fc5fe40ca7bd88e24426 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Aug 6 13:12:28 2019 +0200 CAMEL-10910: A route with a single output should also use a pipeline so its the same behaviour as if the route has 2+ outputs. --- .../cxf/jaxrs/CxfRsSpringConsumerTest.java | 2 +- .../camel/impl/engine/DefaultRouteContext.java | 4 +- .../impl/cloud/ServiceCallConfigurationTest.java | 6 ++ .../test/java/org/apache/camel/TestSupport.java | 4 + .../camel/language/XPathOutFunctionTest.java | 114 --------------------- .../RandomLoadBalanceJavaDSLBuilderTest.java | 4 + .../camel/processor/SagaPropagationTest.java | 4 +- .../processor/SimpleSingleOutputMockTest.java | 51 +++++++++ 8 files changed, 71 insertions(+), 118 deletions(-) diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringConsumerTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringConsumerTest.java index b52b221..9748268 100644 --- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringConsumerTest.java +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringConsumerTest.java @@ -49,7 +49,7 @@ public class CxfRsSpringConsumerTest extends CamelSpringTestSupport { public void process(Exchange exchange) throws Exception { // do something else with the request properties as usual // do something else with the response - exchange.getOut().getBody(Customer.class).setId(246); + exchange.getMessage().getBody(Customer.class).setId(246); } }; return new RouteBuilder() { diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultRouteContext.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultRouteContext.java index be269db..282fbd5 100644 --- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultRouteContext.java +++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultRouteContext.java @@ -171,7 +171,9 @@ public class DefaultRouteContext implements RouteContext { public Route commit() { // now lets turn all of the event driven consumer processors into a single route if (!eventDrivenProcessors.isEmpty()) { - Processor target = Pipeline.newInstance(getCamelContext(), eventDrivenProcessors); + // always use an pipeline even if there are only 1 processor as the pipeline + // handles preparing the response from the exchange in regard to IN vs OUT messages etc + Processor target = new Pipeline(getCamelContext(), eventDrivenProcessors); // and wrap it in a unit of work so the UoW is on the top, so the entire route will be in the same UoW CamelInternalProcessor internal = new CamelInternalProcessor(target); diff --git a/core/camel-cloud/src/test/java/org/apache/camel/impl/cloud/ServiceCallConfigurationTest.java b/core/camel-cloud/src/test/java/org/apache/camel/impl/cloud/ServiceCallConfigurationTest.java index ecd8832..8644bb9 100644 --- a/core/camel-cloud/src/test/java/org/apache/camel/impl/cloud/ServiceCallConfigurationTest.java +++ b/core/camel-cloud/src/test/java/org/apache/camel/impl/cloud/ServiceCallConfigurationTest.java @@ -30,6 +30,8 @@ import org.apache.camel.model.cloud.ServiceCallConfigurationDefinition; import org.apache.camel.model.cloud.ServiceCallDefinitionConstants; import org.apache.camel.model.cloud.ServiceCallExpressionConfiguration; import org.apache.camel.model.language.SimpleExpression; +import org.apache.camel.processor.Pipeline; +import org.apache.camel.processor.channel.DefaultChannel; import org.junit.Assert; import org.junit.Test; @@ -441,7 +443,11 @@ public class ServiceCallConfigurationTest { // ********************************************** private DefaultServiceCallProcessor findServiceCallProcessor(Route route) { + for (Processor processor : route.navigate().next()) { + if (processor instanceof DefaultChannel) { + processor = ((DefaultChannel) processor).getNextProcessor(); + } if (processor instanceof DefaultServiceCallProcessor) { return (DefaultServiceCallProcessor)processor; } diff --git a/core/camel-core/src/test/java/org/apache/camel/TestSupport.java b/core/camel-core/src/test/java/org/apache/camel/TestSupport.java index 2ec15e3..d2dd5b4 100644 --- a/core/camel-core/src/test/java/org/apache/camel/TestSupport.java +++ b/core/camel-core/src/test/java/org/apache/camel/TestSupport.java @@ -25,6 +25,7 @@ import org.apache.camel.builder.Builder; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.builder.ValueBuilder; import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.processor.Pipeline; import org.apache.camel.processor.errorhandler.ErrorHandlerSupport; import org.apache.camel.support.DefaultExchange; import org.apache.camel.support.PredicateAssertHelper; @@ -378,6 +379,9 @@ public abstract class TestSupport extends Assert { */ public static Channel unwrapChannel(Processor processor) { while (true) { + if (processor instanceof Pipeline) { + processor = ((Pipeline) processor).getProcessors().get(0); + } if (processor instanceof Channel) { return (Channel) processor; } else if (processor instanceof DelegateProcessor) { diff --git a/core/camel-core/src/test/java/org/apache/camel/language/XPathOutFunctionTest.java b/core/camel-core/src/test/java/org/apache/camel/language/XPathOutFunctionTest.java deleted file mode 100644 index 35b4692..0000000 --- a/core/camel-core/src/test/java/org/apache/camel/language/XPathOutFunctionTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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.language; -import org.w3c.dom.NodeList; - -import org.apache.camel.ContextTestSupport; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.Before; -import org.junit.Test; - -import static org.apache.camel.component.mock.MockEndpoint.expectsMessageCount; - -public class XPathOutFunctionTest extends ContextTestSupport { - - protected MockEndpoint x; - protected MockEndpoint y; - protected MockEndpoint z; - protected MockEndpoint end; - - @Test - public void testCheckHeader() throws Exception { - String body = "<one/>"; - x.expectedBodiesReceived(body); - expectsMessageCount(0, y, z); - - sendMessage("bar", body); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testCheckBody() throws Exception { - String body = "<two/>"; - y.expectedBodiesReceived(body); - expectsMessageCount(0, x, z); - - sendMessage("cheese", body); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testSetXpathProperty() throws Exception { - String body = "<soapenv:Body xmlns:ns=\"http://myNamesapce\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" - + "<ns:Addresses> <Address>address1</Address>" - + " <Address>address2</Address> <Address>address3</Address>" - + " <Address>address4</Address> </ns:Addresses> </soapenv:Body>"; - end.reset(); - end.expectedMessageCount(1); - template.sendBody("direct:setProperty", body); - assertMockEndpointsSatisfied(); - Exchange exchange = end.getExchanges().get(0); - NodeList nodeList = exchange.getProperty("Addresses", NodeList.class); - assertNotNull("The node list should not be null", nodeList); - } - - protected void sendMessage(final Object headerValue, final Object body) throws Exception { - template.send("direct:start", new Processor() { - public void process(Exchange exchange) throws Exception { - // use OUT to test the OUT namespaces - exchange.getOut().setBody(body); - exchange.getOut().setHeader("foo", headerValue); - } - }); - } - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - - x = getMockEndpoint("mock:x"); - y = getMockEndpoint("mock:y"); - z = getMockEndpoint("mock:z"); - end = getMockEndpoint("mock:end"); - } - - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - public void configure() { - - // START SNIPPET: ex - from("direct:start").choice() - .when().xpath("out:header('foo') = 'bar'").to("mock:foo").to("mock:x") - .when().xpath("out:body() = '<two/>'").to("mock:foo").to("mock:y") - .otherwise().to("mock:foo").to("mock:z"); - // END SNIPPET: ex - - from("direct:setProperty") - .setProperty("Addresses").xpath("//Address", NodeList.class) - .to("mock:end"); - } - }; - } - -} \ No newline at end of file diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/RandomLoadBalanceJavaDSLBuilderTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/RandomLoadBalanceJavaDSLBuilderTest.java index c3bd4b1..d0e2426 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/RandomLoadBalanceJavaDSLBuilderTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/RandomLoadBalanceJavaDSLBuilderTest.java @@ -73,6 +73,10 @@ public class RandomLoadBalanceJavaDSLBuilderTest extends RandomLoadBalanceTest { } private void navigateRoute(Navigate<Processor> nav, StringBuilder sb) { + if (nav instanceof Pipeline) { + nav = (Navigate<Processor>) ((Pipeline) nav).getProcessors().get(0); + } + if (!nav.hasNext()) { return; } diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/SagaPropagationTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/SagaPropagationTest.java index 333d987..122fd58 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/SagaPropagationTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/SagaPropagationTest.java @@ -67,7 +67,7 @@ public class SagaPropagationTest extends ContextTestSupport { context.createFluentProducerTemplate().to("direct:supports").request(); assertListSize(sagaIds, 2); - assertNonNullSagaIds(1); + assertNonNullSagaIds(2); } @Test @@ -184,7 +184,7 @@ public class SagaPropagationTest extends ContextTestSupport { } private Processor addSagaIdToList() { - return ex -> sagaIds.add(ex.getIn().getHeader(Exchange.SAGA_LONG_RUNNING_ACTION, String.class)); + return ex -> sagaIds.add(ex.getMessage().getHeader(Exchange.SAGA_LONG_RUNNING_ACTION, String.class)); } private void assertUniqueNonNullSagaIds(int num) { diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/SimpleSingleOutputMockTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/SimpleSingleOutputMockTest.java new file mode 100644 index 0000000..6323e43 --- /dev/null +++ b/core/camel-core/src/test/java/org/apache/camel/processor/SimpleSingleOutputMockTest.java @@ -0,0 +1,51 @@ +/* + * 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.processor; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.ExchangePattern; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.Test; + +public class SimpleSingleOutputMockTest extends ContextTestSupport { + + @Test + public void testSimple() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedBodiesReceived("Hello World"); + + Exchange out = template.request("direct:start", e -> e.getMessage().setBody("Hello World")); + assertNotNull(out); + assertEquals(ExchangePattern.InOut, out.getPattern()); + assertTrue(out.hasOut()); + + assertMockEndpointsSatisfied(); + } + + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start").to("mock:result"); + } + }; + } +}