This page will explains how you can extends the DSL from Babel Camel by adding new keywords and grammar parts to the existing DSL.
Warning
The extension of the DSL requires some knowledge of the Scala language.
To create an extension, you need to create a new DSL, some definition objects and a Parser.
io.xtech.babel.camel.mock
io.xtech.babel.fish.parsing.StepDefinition
.io.xtech.babel.fish.BaseDSL
and extends a io.xtech.babel.fish.DSL2BaseDSL
io.xtech.babel.camel.parsing.CamelParsing
.Process
type and add it to the steps
of the trait.package io.xtech.babel.camel.mock
import io.xtech.babel.camel.parsing.CamelParsing
import io.xtech.babel.fish.model.StepDefinition
import io.xtech.babel.fish.parsing.StepInformation
import io.xtech.babel.fish.{ BaseDSL, DSL2BaseDSL }
import org.apache.camel.model.ProcessorDefinition
import scala.collection.immutable
import scala.language.implicitConversions
import scala.reflect.ClassTag
case class MockDefinition(filePath: String) extends StepDefinition
class MockDSL[I: ClassTag](protected val baseDsl: BaseDSL[I]) extends DSL2BaseDSL[I] {
/**
* The mock keyword. Stores received exchanges in order to assert properties in tests.
* @param endpointUri target mock endpoint which translates to "mock:endpointUri"
* @see io.xtech.babel.camel.mock
* @return the possibility to add other steps to the current DSL
*/
def mock(endpointUri: String): BaseDSL[I] = MockDefinition(endpointUri)
}
trait Mock extends CamelParsing {
abstract override def steps: immutable.Seq[Process] = super.steps :+ parse
val parse: Process = {
case StepInformation(MockDefinition(uri), camelProcessor: ProcessorDefinition[_]) =>
camelProcessor.to(s"mock:$uri")
}
implicit def mockDSLExtension[I: ClassTag](baseDsl: BaseDSL[I]) = new MockDSL(baseDsl)
}