-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute.groovy
38 lines (30 loc) · 1007 Bytes
/
execute.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@GrabConfig(systemClassLoader=true)
// additonal dependencies required by the Generic API
@Grab(group='org.apache.camel', module='camel-core', version='2.20.4')
@Grab(group='javax.activation', module='activation', version='1.1.1')
import groovy.json.*
import impl.*
// setup Groovy scripting engine
def binding = new Binding()
def logFactory = new MessageLogFactoryImpl()
binding.setVariable("messageLogFactory", logFactory)
def shell = new GroovyShell(binding)
def scriptFile = new File('script.groovy')
shell.evaluate(scriptFile)
def script = shell.parse(scriptFile)
// setup message
def message = new MessageImpl()
message.headers.foo = "bar"
message.properties.bar = "foo"
message.body = "Hello World"
// execute script and log output
println "==== BEFORE ===="
println message
result = script.invokeMethod("processData", message)
println ""
println "==== AFTER ===="
println result
println ""
println logFactory.messageLog
// Assert correct result
assert result.body == "Hello World processed"