Skip to content

Commit

Permalink
add java tests in sbt build
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Pache committed Mar 13, 2015
1 parent 77eea33 commit 34fad47
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@

package io.xtech.babel.camel.choice


import io.xtech.babel.camel.model.Aggregation.{ReduceBody, CompletionSize, FoldBody}
import io.xtech.babel.camel.model.{CamelSink, CamelSource}
import io.xtech.babel.camel.model.Aggregation.{ ReduceBody, CompletionSize, FoldBody }
import io.xtech.babel.camel.model.{ CamelSink, CamelSource }
import io.xtech.babel.camel.test.camel
import io.xtech.babel.fish.{BaseDSL, FromDSL}
import io.xtech.babel.fish.{ BaseDSL, FromDSL }
import io.xtech.babel.fish.model.Message
import org.apache.camel.component.mock.MockEndpoint
import org.apache.camel.processor.aggregate.{AggregationStrategy, UseLatestAggregationStrategy}
import org.apache.camel.{Exchange, Predicate, Processor}
import org.apache.camel.processor.aggregate.{ AggregationStrategy, UseLatestAggregationStrategy }
import org.apache.camel.{ Exchange, Predicate, Processor }
import org.specs2.mutable.SpecificationWithJUnit

import scala.collection.JavaConverters._
Expand All @@ -25,10 +24,8 @@ class DemoSpec extends SpecificationWithJUnit {

"demo route" in new camel {


sequential


//#doc:babel-camel-demo-2
val doAggregate = ReduceBody(
//defines how message bodies are aggregated
Expand All @@ -39,11 +36,8 @@ class DemoSpec extends SpecificationWithJUnit {
completionStrategies = List(CompletionSize(3))
)


//#doc:babel-camel-demo-2



//#doc:babel-camel-demo-1
import io.xtech.babel.camel.builder.RouteBuilder

Expand All @@ -54,19 +48,16 @@ class DemoSpec extends SpecificationWithJUnit {
aggregate(doAggregate).

choice { c =>
c.whenBody(_ > 0).
to("mock:database")
c.whenBody(_ > 0).
to("mock:database")

c.whenBody(_ < 0).
processBody(int => s"$int is negative").
to("mock:error")
}
c.whenBody(_ < 0).
processBody(int => s"$int is negative").
to("mock:error")
}
}
//#doc:babel-camel-demo-1




myRoute.addRoutesToCamelContext(camelContext)
camelContext.start()

Expand All @@ -89,23 +80,21 @@ class DemoSpec extends SpecificationWithJUnit {
"demo camel-scalaroute" in new camel {
sequential


//#doc:babel-camel-demo-scala-2
val aggregationStrategy = new AggregationStrategy {
def aggregate(old: Exchange, news: Exchange) =
(old, news) match {
case (old, null) => old
case (old, null) => old
case (null, news) => news
case (old, news) =>
old.getIn.setBody(
old.getIn.getBody(classOf[Int]) +
news.getIn.getBody(classOf[Int]))
news.getIn.getBody(classOf[Int]))
old
}
}
//#doc:babel-camel-demo-scala-2


//#doc:babel-camel-demo-scala-1
import org.apache.camel.scala.dsl.builder.RouteBuilder

Expand All @@ -116,13 +105,13 @@ class DemoSpec extends SpecificationWithJUnit {
aggregate("a", aggregationStrategy).completionSize(3).

choice {
when(_.in[Int] > 0).
to("mock:database-camel-scala")
when(_.in[Int] > 0).
to("mock:database-camel-scala")

when(_.in[Int] < 0).
process(msg =>msg.in = s"${msg.in} is negative").
to("mock:error-camel-scala")
}
when(_.in[Int] < 0).
process(msg => msg.in = s"${msg.in} is negative").
to("mock:error-camel-scala")
}
}
//#doc:babel-camel-demo-scala-1

Expand Down
16 changes: 9 additions & 7 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ object Dependencies {
private lazy val camelDependencies = Seq(
Build.camelVersion := fixedCamelVersion,
version <<= (version, Build.camelVersion) { parseCamelVersion },
//libraryDependencies ++= Seq("com.novocode" % "junit-interface" % "0.8" % "test->default"),
libraryDependencies <++= (Build.camelVersion) { (dv) =>
Dependencies.test ++ Dependencies.camel(dv) ++ Seq(Dependencies.commoncsv)
}
Expand All @@ -45,14 +46,15 @@ object Dependencies {
}
)

private def camelCore(camelVersion: String) = "org.apache.camel" % "camel-core" % camelVersion
private def camelXmlJson(camelVersion: String) = "org.apache.camel" % "camel-xmljson" % camelVersion % "test"
private def camelCsv(camelVersion: String) = "org.apache.camel" % "camel-csv" % camelVersion % "test"
private def camelSql(camelVersion: String) = "org.apache.camel" % "camel-sql" % camelVersion % "test"
private def camelSpring(camelVersion: String) = "org.apache.camel" % "camel-spring" % camelVersion % "optional"
private def camelScala(camelVersion: String) = "org.apache.camel" % "camel-scala" % camelVersion % "optional"
private val camelCore = (camelVersion: String) => "org.apache.camel" % "camel-core" % camelVersion
private val camelXmlJson = (camelVersion: String) => "org.apache.camel" % "camel-xmljson" % camelVersion % "test"
private val camelCsv = (camelVersion: String) => "org.apache.camel" % "camel-csv" % camelVersion % "test"
private val camelSql = (camelVersion: String) => "org.apache.camel" % "camel-sql" % camelVersion % "test"
private val camelSpring = (camelVersion: String) => "org.apache.camel" % "camel-spring" % camelVersion % "optional"
private val camelScala = (camelVersion: String) => "org.apache.camel" % "camel-scala" % camelVersion % "optional"
private val camelTest = (camelVersion: String) => "org.apache.camel" % "camel-test" % camelVersion % "test"

private def camel(camelVersion: String) = Seq(camelCore(camelVersion), camelXmlJson(camelVersion), camelCsv(camelVersion), camelSql(camelVersion), camelSpring(camelVersion), camelScala(camelVersion))
private def camel(camelVersion: String) = Seq(camelCore, camelXmlJson, camelCsv, camelSql, camelSpring, camelScala, camelTest).map(x => (x(camelVersion)))

private val commoncsv = "org.apache.servicemix.bundles" % "org.apache.servicemix.bundles.commons-csv" % "1.0-r706900_3" % "test"

Expand Down

0 comments on commit 34fad47

Please sign in to comment.