Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C51951764D for ; Wed, 20 May 2015 12:05:48 +0000 (UTC) Received: (qmail 42824 invoked by uid 500); 20 May 2015 12:05:48 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 42770 invoked by uid 500); 20 May 2015 12:05:48 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 42755 invoked by uid 99); 20 May 2015 12:05:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 May 2015 12:05:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 40C0FDFCCE; Wed, 20 May 2015 12:05:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ningjiang@apache.org To: commits@camel.apache.org Date: Wed, 20 May 2015 12:05:48 -0000 Message-Id: <85d25f8b120f4c1ca56521f274e8631f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] camel git commit: CAMEL-8784 Fixed the issue of Policy, Validate, Wiretap Scala DSL don't work out of box Repository: camel Updated Branches: refs/heads/camel-2.14.x cc1c7d011 -> 9199e68d7 refs/heads/camel-2.15.x 34ac8df31 -> 15cf03af9 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/9199e68d Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9199e68d Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9199e68d Branch: refs/heads/camel-2.14.x Commit: 9199e68d7a7a69f758ea102ea59468b730ad4501 Parents: cc1c7d0 Author: Willem Jiang Authored: Wed May 20 19:59:32 2015 +0800 Committer: Willem Jiang Committed: Wed May 20 20:00:24 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/9199e68d/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 c98abe1..6d3e055 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 //----------------------------------------------------------------- @@ -108,7 +107,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) = @@ -146,11 +145,11 @@ abstract class SAbstractDefinition[P <: ProcessorDefinition[_]] extends DSL with def unmarshal(format: DataFormatDefinition) = wrap(target.unmarshal(format)) - 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/9199e68d/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/9199e68d/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/9199e68d/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/9199e68d/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/9199e68d/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/9199e68d/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") } }