-
Notifications
You must be signed in to change notification settings - Fork 1
/
testing.clj
46 lines (40 loc) · 1.24 KB
/
testing.clj
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
39
40
41
42
43
44
45
46
(ns llama.testing
"Testing utilities for Camel Mock endpoints."
(:import org.apache.camel.component.mock.MockEndpoint))
(defn mock
"Use in a test. Get a mock endpoint in `endpoint` as an `MockEndpoint` in context `ctx`.
```
(let [ctx (DefaultCamelContext.)
mock-endpoint (mock ctx \"mock:bar\")]
(expect-bodies mock-endpoint \"HI!\")
(send-body ctx mock-endpoint \"HI!\")
(is (mock-satisfied? mock-endpoint)))
```
"
[ctx endpoint]
(.getEndpoint ctx endpoint (class (MockEndpoint.))))
(defn expect-bodies
"Testing. Create an expectation on endpoint to have received
the bodies in `messages`. See [[mock]]."
[endpoint & messages]
(.expectedBodiesReceived endpoint messages))
(defn mock-satisfied?
"Runs the mock assertion, returns `true` if the mock endpoint is satisfied,
false if an `AssertionError` is thrown. See [[mock]]."
[mock]
(try
(do
(.assertIsSatisfied mock)
true)
(catch java.lang.AssertionError e
false)))
(defn mock-not-satisfied?
"Runs the mock assertion, returns `true` if the mock endpoint is satisfied,
false if an `AssertionError` is thrown. See [[mock]]."
[mock]
(try
(do
(.assertIsNotSatisfied mock)
true)
(catch java.lang.AssertionError e
false)))