CAMEL-8783 Fixed the issue that the Transacted DSL doesn'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/cc1c7d01 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/cc1c7d01 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/cc1c7d01 Branch: refs/heads/camel-2.14.x Commit: cc1c7d011d887f8e92cad7f1d383598f2918d216 Parents: 98ba97b Author: Willem Jiang <willem.ji...@gmail.com> Authored: Wed May 20 15:25:55 2015 +0800 Committer: Willem Jiang <willem.ji...@gmail.com> Committed: Wed May 20 15:39:27 2015 +0800 ---------------------------------------------------------------------- .../camel/scala/dsl/SAbstractDefinition.scala | 4 +- .../camel/scala/dsl/STransactedDefinition.scala | 28 +++++++++ .../apache/camel/scala/dsl/TransactedTest.scala | 61 ++++++++++++++++++++ 3 files changed, 91 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/cc1c7d01/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 275b6d0..c98abe1 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 @@ -140,8 +140,8 @@ abstract class SAbstractDefinition[P <: ProcessorDefinition[_]] extends DSL with def threads = SThreadsDefinition(target.threads) def throttle(frequency: Frequency) = SThrottleDefinition(target.throttle(frequency.count).timePeriodMillis(frequency.period.milliseconds)) def throwException(exception: Exception) = wrap(target.throwException(exception)) - def transacted = wrap(target.transacted) - def transacted(ref: String) = wrap(target.transacted(ref)) + def transacted = STransactedDefinition(target.transacted) + def transacted(ref: String) = STransactedDefinition(target.transacted(ref)) def transform(expression: Exchange => Any) = wrap(target.transform(expression)) def unmarshal(format: DataFormatDefinition) = wrap(target.unmarshal(format)) http://git-wip-us.apache.org/repos/asf/camel/blob/cc1c7d01/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/STransactedDefinition.scala ---------------------------------------------------------------------- diff --git a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/STransactedDefinition.scala b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/STransactedDefinition.scala new file mode 100644 index 0000000..ca7ddae --- /dev/null +++ b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/STransactedDefinition.scala @@ -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.scala.dsl + +import org.apache.camel.model.TransactedDefinition +import org.apache.camel.scala.dsl.builder.RouteBuilder + +/** + * Scala enrichment for Camel's TransactedDefinition + */ +case class STransactedDefinition(override val target: TransactedDefinition)(implicit val builder: RouteBuilder) extends SAbstractDefinition[TransactedDefinition] { + +} + http://git-wip-us.apache.org/repos/asf/camel/blob/cc1c7d01/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/TransactedTest.scala ---------------------------------------------------------------------- diff --git a/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/TransactedTest.scala b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/TransactedTest.scala new file mode 100644 index 0000000..4c22782 --- /dev/null +++ b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/TransactedTest.scala @@ -0,0 +1,61 @@ +/* + * 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.impl.{JndiRegistry, SimpleRegistry, CompositeRegistry} +import org.apache.camel.scala.dsl.builder.RouteBuilder +import org.junit.Test +import org.springframework.transaction.support.{DefaultTransactionStatus, AbstractPlatformTransactionManager} +import org.springframework.transaction.{TransactionDefinition, TransactionStatus, PlatformTransactionManager} + + +class TransactedTest extends ScalaTestSupport { + + @throws(classOf[Exception]) + override def createRegistry: JndiRegistry = { + val registry = super.createRegistry + // Just setup a dummy platform transaction manager for testing + registry.bind("transactionManager", new AbstractPlatformTransactionManager() { + override def doCommit(status: DefaultTransactionStatus): Unit = {} + + override def doBegin(transaction: scala.Any, definition: TransactionDefinition): Unit = {} + + override def doRollback(status: DefaultTransactionStatus): Unit = {} + + override def doGetTransaction(): AnyRef = {new Object()} + }) + registry + } + + @Test + def testScalaRouteBuilder() { + getMockEndpoint("mock:result").expectedMessageCount(1) + + template().sendBody("direct:start", "Hello World") + + assertMockEndpointsSatisfied() + } + + // must use lazy as we want to evaluate this after CamelContext has been created + override lazy val builder = { + + new RouteBuilder { + from("direct:start").transacted.to("mock:result") + } + } +} +