Repository: camel Updated Branches: refs/heads/master 8bf2af2c7 -> 02d6e0a45
CAMEL-8784 Fixed the issue of Policy, Validate, Wiretap Scala DSL don't work out of box Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/02d6e0a4 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/02d6e0a4 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/02d6e0a4 Branch: refs/heads/master Commit: 02d6e0a45fd13250818a0a7b01a6d012d60ae8f1 Parents: 8bf2af2 Author: Willem Jiang <willem.ji...@gmail.com> Authored: Wed May 20 19:59:32 2015 +0800 Committer: Willem Jiang <willem.ji...@gmail.com> Committed: Wed May 20 19:59:32 2015 +0800 ---------------------------------------------------------------------- .../camel/scala/dsl/SAbstractDefinition.scala | 11 +++---- .../camel/scala/dsl/SPolicyDefinition.scala | 27 ++++++++++++++++ .../camel/scala/dsl/SValidateDefinition.scala | 27 ++++++++++++++++ .../camel/scala/dsl/SWireTapDefinition.scala | 27 ++++++++++++++++ .../camel/scala/dsl/SPolicyPerRouteTest.scala | 34 ++++++++++++++++++++ .../apache/camel/scala/dsl/SValidateTest.scala | 6 ++++ .../apache/camel/scala/dsl/WiretapTest.scala | 8 +++++ 7 files changed, 134 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/02d6e0a4/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala ---------------------------------------------------------------------- diff --git a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala index a166f37..ff632df 100644 --- a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala +++ b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala @@ -18,14 +18,12 @@ package org.apache.camel package scala package dsl -import org.apache.camel.Exchange import org.apache.camel.model._ import org.apache.camel.processor.aggregate.AggregationStrategy import org.apache.camel.scala.dsl.builder.RouteBuilder import spi.Policy import reflect.{ClassTag, classTag} -import java.lang.String import java.util.Comparator abstract class SAbstractDefinition[P <: ProcessorDefinition[_]] extends DSL with Wrapper[P] with Block { @@ -51,6 +49,7 @@ abstract class SAbstractDefinition[P <: ProcessorDefinition[_]] extends DSL with this } + // EIPs //----------------------------------------------------------------- @@ -109,7 +108,7 @@ abstract class SAbstractDefinition[P <: ProcessorDefinition[_]] extends DSL with def otherwise: SChoiceDefinition = throw new Exception("otherwise is only supported in a choice block or after a when statement") def pipeline = SPipelineDefinition(target.pipeline) - def policy(policy: Policy) = wrap(target.policy(policy)) + def policy(policy: Policy) = SPolicyDefinition(target.policy(policy)) def pollEnrich(uri: String, strategy: AggregationStrategy = null, timeout: Long = -1) = wrap(target.pollEnrich(uri, timeout, strategy)) def pollEnrich(uri: String, strategy: AggregationStrategy, timeout: Long, aggregateOnException: Boolean) = @@ -155,11 +154,11 @@ abstract class SAbstractDefinition[P <: ProcessorDefinition[_]] extends DSL with def unmarshal(format: DataFormatDefinition) = wrap(target.unmarshal(format)) def unmarshal(dataFormatRef: String) = wrap(target.unmarshal(dataFormatRef)) - def validate(expression: Exchange => Any) = wrap(target.validate(predicateBuilder(expression))) + def validate(expression: Exchange => Any) = SValidateDefinition(target.validate(predicateBuilder(expression))) def when(filter: Exchange => Any): DSL with Block = SChoiceDefinition(target.choice).when(filter) - def wireTap(uri: String) = wrap(target.wireTap(uri)) - def wireTap(uri: String, expression: Exchange => Any) = wrap(target.wireTap(uri).newExchangeBody(expression)) + def wireTap(uri: String) = SWireTapDefinition(target.wireTap(uri)) + def wireTap(uri: String, expression: Exchange => Any) = SWireTapDefinition(target.wireTap(uri).newExchangeBody(expression)) def -->(pattern: ExchangePattern, uri: String) = wrap(target.to(pattern, uri)) def -->(uris: String*) = to(uris:_*) http://git-wip-us.apache.org/repos/asf/camel/blob/02d6e0a4/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SPolicyDefinition.scala ---------------------------------------------------------------------- diff --git a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SPolicyDefinition.scala b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SPolicyDefinition.scala new file mode 100644 index 0000000..4853ff4 --- /dev/null +++ b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SPolicyDefinition.scala @@ -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.scala.dsl + +import org.apache.camel.model.PolicyDefinition +import org.apache.camel.scala.dsl.builder.RouteBuilder + +/** + * Scala enrichment for Camel's PolicyDefinition + */ +case class SPolicyDefinition (override val target: PolicyDefinition)(implicit val builder: RouteBuilder) extends SAbstractDefinition[PolicyDefinition] { + +} http://git-wip-us.apache.org/repos/asf/camel/blob/02d6e0a4/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SValidateDefinition.scala ---------------------------------------------------------------------- diff --git a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SValidateDefinition.scala b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SValidateDefinition.scala new file mode 100644 index 0000000..f29e456 --- /dev/null +++ b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SValidateDefinition.scala @@ -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.scala.dsl + +import org.apache.camel.model.ValidateDefinition +import org.apache.camel.scala.dsl.builder.RouteBuilder + +/** + * Scala enrichment for Camel's VaildateDefinition + */ +case class SValidateDefinition (override val target: ValidateDefinition)(implicit val builder: RouteBuilder) extends SAbstractDefinition[ValidateDefinition] { + +} http://git-wip-us.apache.org/repos/asf/camel/blob/02d6e0a4/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SWireTapDefinition.scala ---------------------------------------------------------------------- diff --git a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SWireTapDefinition.scala b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SWireTapDefinition.scala new file mode 100644 index 0000000..3a0ceda --- /dev/null +++ b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SWireTapDefinition.scala @@ -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.scala.dsl + +import org.apache.camel.model.WireTapDefinition +import org.apache.camel.scala.dsl.builder.RouteBuilder + +/** + * Scala enrichment for Camel's WireTapDefinition + */ +case class SWireTapDefinition (override val target: WireTapDefinition[_])(implicit val builder: RouteBuilder) extends SAbstractDefinition[WireTapDefinition[_]] { + +} http://git-wip-us.apache.org/repos/asf/camel/blob/02d6e0a4/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SPolicyPerRouteTest.scala ---------------------------------------------------------------------- diff --git a/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SPolicyPerRouteTest.scala b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SPolicyPerRouteTest.scala new file mode 100644 index 0000000..a18ba7d --- /dev/null +++ b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SPolicyPerRouteTest.scala @@ -0,0 +1,34 @@ +/** + * 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.scala.dsl + +import org.apache.camel.processor.PolicyPerRouteTest +import org.apache.camel.scala.dsl.builder.{RouteBuilder, RouteBuilderSupport} + +class SPolicyPerRouteTest extends PolicyPerRouteTest with RouteBuilderSupport { + + override def createRouteBuilder = new RouteBuilder { + from("direct:start") + .policy("foo").to("mock:foo").to("mock:bar").to("mock:result") + + from("direct:send") + .to("direct:start") + .to("mock:response") + +} + +} http://git-wip-us.apache.org/repos/asf/camel/blob/02d6e0a4/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SValidateTest.scala ---------------------------------------------------------------------- diff --git a/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SValidateTest.scala b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SValidateTest.scala index 988ba07..7ddacd0 100644 --- a/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SValidateTest.scala +++ b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SValidateTest.scala @@ -56,6 +56,12 @@ class SValidateSimpleTest extends ValidateSimpleTest with RouteBuilderSupport { } } +class SValidateSimpleBuilderTest extends SValidateSimpleTest with RouteBuilderSupport { + override def createRouteBuilder = new RouteBuilder { + from("direct:start").validate(simple("${body} contains 'Camel'")).to("mock:result") + } +} + /** * Scala DSL equivalent for the ValidateRegExpTest, using the Scala DSL block syntax */ http://git-wip-us.apache.org/repos/asf/camel/blob/02d6e0a4/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/WiretapTest.scala ---------------------------------------------------------------------- diff --git a/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/WiretapTest.scala b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/WiretapTest.scala index 3aa5aac..5598d7a 100644 --- a/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/WiretapTest.scala +++ b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/WiretapTest.scala @@ -45,6 +45,12 @@ class WiretapTest extends ScalaTestSupport { def testBlockTapWithBody() { doTestWiretapWithBody("direct:d", "mock:d") } + + + @Test + def testBuilderWiretap() { + doTestWiretap("direct:e", "mock:e") + } def doTestWiretap(from: String, to: String) { to expect { _.received("Calling Elvis", "Calling Paul")} @@ -87,6 +93,8 @@ class WiretapTest extends ScalaTestSupport { }) to "mock:tap" "direct:tap-with-body" to "mock:tap-with-body" + + from("direct:e").wireTap("direct:tap").setBody("Calling " + _.in[Adult].name).to("mock:e") } }