Skip to content

Instantly share code, notes, and snippets.

@ezidio
Created May 13, 2020 17:00
Show Gist options
  • Save ezidio/f4a492c376c9bd54c6d01f3daacf2235 to your computer and use it in GitHub Desktop.
Save ezidio/f4a492c376c9bd54c6d01f3daacf2235 to your computer and use it in GitHub Desktop.
Kotlin Camel extension funcion test
package br.com.eive.integration.app
import br.com.eive.integration.core.camel.routes.EiveRouteBuilder
import br.com.eive.integration.core.http.EiveHttp
import br.com.eive.integration.core.log.MessageLogger
import br.com.eive.integration.core.log.model.MessageStep
import br.com.eive.integration.test.EiveCamelTestSupport
import br.com.eive.integration.test.junit5.EiveCamelTest
import org.apache.camel.Exchange
import org.apache.camel.Expression
import org.apache.camel.builder.SimpleBuilder
import org.apache.camel.model.ProcessDefinition
import org.apache.camel.model.ProcessorDefinition
import org.apache.camel.model.RouteDefinition
import org.junit.jupiter.api.Test
fun RouteDefinition.logPartnerUpdate(step:MessageStep):RouteDefinition {
return this.routePolicy(MessageLogger.logPartnerUpdate(step))
}
fun RouteDefinition.logOrder(step:MessageStep):RouteDefinition {
return this.routePolicy(MessageLogger.logOrder(step))
}
fun <T: ProcessorDefinition<T>> ProcessorDefinition<T>.logOrderPrepare(): ProcessorDefinition<T> {
return this.process(MessageLogger.logOrder(MessageStep.PREPARE))
}
fun <T: ProcessorDefinition<T>> ProcessorDefinition<T>.post(path:String): HttpDefinition {
val answer = HttpDefinition(EiveHttp("POST", SimpleBuilder.simple(path)))
addOutput(answer)
return answer
}
class HttpDefinition(private val http:EiveHttp): ProcessDefinition(http) {
fun withBody(e:Expression): HttpDefinition {
this.http.withBody(e)
return this
}
fun withBody(bodyFunction:(exchange:Exchange) -> Any): HttpDefinition {
this.http.withBody(bodyFunction)
return this
}
}
@EiveCamelTest
class TestSteps: EiveCamelTestSupport() {
@Test
internal fun steps() {
this.context.addRoutes(MyRoute())
this.template.sendBody("direct:start", "Everton")
}
class MyRoute: EiveRouteBuilder() {
override fun configure() {
from("direct:start")
.validate(body().isInstanceOf(String::class.java))
.logOrderPrepare()
.post("/api").withBody(this::createBody)
.to("mock:end")
}
fun createBody(exchange: Exchange):String {
return "opa"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment