The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

megachucky (17) [Avatar] Offline
#1
Hey,

I am playing with the scala code of the book source code. I also downloaded camel-scala sources from svn. I use IntelliJ IDEA as IDE. Probably all of you do use it too, because it is the only one with good Scala support yet?

I have created several Scala routes, beans, processors. Everything works fine. But I cannot manage to get a simple Camel test running. First I tried to use CamelTestSupport. After asking google I found out, that I should use "extends ContextTestSupport with RouteBuilderSupport". Everything compiles fine. But I cannot start the test (using run configuration as scala test).
The error in IntelliJ IDEA is: "Error running RunFileToFileTest: Not found suite class"
How can I start these tests? Do I need a specific Runner when I start it? Or do I need another Run Configuration in IntelliJ IDEA when I start it?

I also looked at the camel-scala component, there you have a class ScalaTestSupport which uses ContextTestSupport. Do I have to compile and use it?

Here is my example:

package test


import org.apache.camel.scala.dsl.builder.{RouteBuilderSupport, RouteBuilder}
import org.apache.camel.{ContextTestSupport, Exchange}


class FileToFileTest extends ContextTestSupport with RouteBuilderSupport {

override def createRouteBuilder = new RouteBuilder {

"direct:start" ==> {
onCompletion(containsHello(_)) {
to("mock:sync")
}
to("mock:result")
}

def containsHello(exchange: Exchange) = exchange.getIn().getBody(classOf[String]).contains("Hello");
}
}


I also tried out another simple ScalaTest example. This one works perfectly:

package test

import java.lang.StringBuilder
import collection.mutable.ListBuffer
import org.junit.{Test, Before}
import org.junit.Assert._
import org.scalatest.junit.JUnitSuite



class UsingScalaTest extends JUnitSuite {
var sb: StringBuilder = _
var lb: ListBuffer[String] = _

@Before def init {
sb = new StringBuilder("ScalaTest is ")
lb = new ListBuffer[String]
}

@Test def verifyEasy() { // Uses JUnit-style assertions
sb.append("easy!")
assertEquals("ScalaTest is easy!", sb.toString)
assertTrue(lb.isEmpty)
lb += "sweet"
try {
"verbose".charAt(-1)
fail()
}
catch {
case e: StringIndexOutOfBoundsException => // Expected
}
}

@Test def verifyFun() { // Uses ScalaTest assertions
sb.append("fun!")
assert(sb.toString === "ScalaTest is fun!")
assert(lb.isEmpty)
lb += "sweeter"
intercept[StringIndexOutOfBoundsException] {
"concise".charAt(-1)
}
}


}


So my question is: How can I run a real Camel-Test? Or does there exists any downloadable Scala-Camel example which also uses CamelTestSupport or ContextTestSupport? I only found some examples at github which do not use these classes smilie

Thanks for some hints...

Best regards,
Kai
davsclaus (413) [Avatar] Offline
#2
Re: Testing camel-scala Code
Hi

You can check out the unit tests in camel-scala component from the Camel source code
https://svn.apache.org/repos/asf/camel/trunk/components/camel-scala/