Skip to content

Commit

Permalink
added a test case showing the use of the array accessor style access …
Browse files Browse the repository at this point in the history
…to headers/properties
  • Loading branch information
jstrachan committed May 12, 2012
1 parent 730def6 commit 6a4fa0d
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 6 deletions.
10 changes: 10 additions & 0 deletions koolapp-camel/src/main/kotlin/org/koolapp/camel/Exchanges.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,13 @@ var Exchange.out: Message
*/
inline fun Exchange.bodyString(nullValue: String = ""): String = body<String>(javaClass<String>) ?: nullValue

/**
* Provides array style access to properties on the exchange
*/
inline fun Exchange.get(propertyName: String): Any? = getProperty(propertyName)

/**
* Provides array style access to properties on the exchange
*/
inline fun Exchange.set(propertyName: String, value: Any?): Unit = setProperty(propertyName, value)

19 changes: 19 additions & 0 deletions koolapp-camel/src/main/kotlin/org/koolapp/camel/Messages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,28 @@ package org.koolapp.camel

import org.apache.camel.Exchange
import org.apache.camel.Message
import java.util.Map

var Message.body: Any?
get() = getBody()
set(value) {
setBody(value)
}

var Message.headers: Map<String?, Any?>
get() = getHeaders().orEmpty()
set(value) {
setHeaders(value)
}


/**
* Provides array style access to headers on the message
*/
inline fun Message.get(headerName: String): Any? = getHeader(headerName)

/**
* Provides array style access to headers on the message
*/
inline fun Message.set(headerName: String, value: Any?): Unit = setHeader(headerName, value)

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ChoiceTest {
result.assertIsSatisfied()
println("$result has messages:")
for (exchange in result.getReceivedExchanges()) {
println(" ${exchange?.getIn()}")
println(" ${exchange?.input}")
}
println()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FilterTest {
result.assertIsSatisfied()

for (exchange in result.getReceivedExchanges()) {
println("Found message ${exchange?.getIn()}")
println("Found message ${exchange?.input}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FilterThenTest {
result.assertIsSatisfied()

for (exchange in result.getReceivedExchanges()) {
println("Found message ${exchange?.getIn()}")
println("Found message ${exchange?.input}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ProcessTest {
result.assertIsSatisfied()

for (exchange in result.getReceivedExchanges()) {
println("Found message ${exchange?.getIn()}")
println("Found message ${exchange?.input}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RouteBuilderTest {
result.assertIsSatisfied()

for (exchange in result.getReceivedExchanges()) {
println("Found message ${exchange?.getIn()}")
println("Found message ${exchange?.input}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package test.koolapp.camel

import org.koolapp.camel.*

import org.junit.Test as test
import org.apache.camel.component.mock.MockEndpoint

class TransformAndSetHeaderTest {
test fun createRoute() {
camel {
val result = mockEndpoint("mock:result")
routes {
from("seda:foo") {
transform {
out["foo"] = "bar"
"Hello ${bodyString()}"
}.sendTo(result)
}
}
result.expectedBodiesReceived("Hello world!")

val producer = producerTemplate()
producer.sendBody("seda:foo", "world!")

result.assertIsSatisfied()

for (exchange in result.getReceivedExchanges()) {
println("Found message ${exchange?.input} with headers ${exchange?.input?.headers}")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TransformTest {
result.assertIsSatisfied()

for (exchange in result.getReceivedExchanges()) {
println("Found message ${exchange?.getIn()}")
println("Found message ${exchange?.input}")
}
}
}
Expand Down

0 comments on commit 6a4fa0d

Please sign in to comment.