Babel Extension creation

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.

Existing Extensions

Create an extension

To create an extension, you need to create a new DSL, some definition objects and a Parser.

Explanation

  1. Choose a package for your the new extension like io.xtech.babel.camel.mock
  2. Create some definition objects that extends io.xtech.babel.fish.parsing.StepDefinition.
  3. Create a DSL with your new keywords using the definition objects. The DSL will take a io.xtech.babel.fish.BaseDSL and extends a io.xtech.babel.fish.DSL2BaseDSL
  4. Create a trait that extends io.xtech.babel.camel.parsing.CamelParsing.
    1. Declare your parser by defining a parse method which returns a Process type and add it to the steps of the trait.
    2. Declare an implicit method using your new DSL.

Example

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)
}