1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.apache.camel.impl; |
19 |
|
|
20 |
|
import org.apache.camel.Predicate; |
21 |
|
import org.apache.camel.Exchange; |
22 |
|
import org.apache.camel.Expression; |
23 |
|
import org.apache.camel.util.ObjectHelper; |
24 |
|
import static org.apache.camel.util.ObjectHelper.notNull; |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
25 |
public abstract class BinaryPredicateSupport<E extends Exchange> implements Predicate<E> { |
32 |
|
|
33 |
|
private final Expression<E> left; |
34 |
|
private final Expression<E> right; |
35 |
|
|
36 |
25 |
protected BinaryPredicateSupport(Expression<E> left, Expression<E> right) { |
37 |
25 |
notNull(left, "left"); |
38 |
25 |
notNull(right, "right"); |
39 |
|
|
40 |
25 |
this.left = left; |
41 |
25 |
this.right = right; |
42 |
25 |
} |
43 |
|
|
44 |
|
@Override |
45 |
|
public String toString() { |
46 |
46 |
return left + " " + getOperationText() + " " + right; |
47 |
|
} |
48 |
|
|
49 |
|
public boolean matches(E exchange) { |
50 |
17 |
Object leftValue = left.evaluate(exchange); |
51 |
17 |
Object rightValue = right.evaluate(exchange); |
52 |
17 |
return matches(exchange, leftValue, rightValue); |
53 |
|
} |
54 |
|
|
55 |
|
public void assertMatches(String text, E exchange) { |
56 |
8 |
Object leftValue = left.evaluate(exchange); |
57 |
8 |
Object rightValue = right.evaluate(exchange); |
58 |
8 |
if (!matches(exchange, leftValue, rightValue)) { |
59 |
2 |
throw new AssertionError(assertionFailureMessage(exchange, leftValue, rightValue)); |
60 |
|
} |
61 |
6 |
} |
62 |
|
|
63 |
|
protected abstract boolean matches(E exchange, Object leftValue, Object rightValue); |
64 |
|
|
65 |
|
protected abstract String getOperationText(); |
66 |
|
|
67 |
|
protected String assertionFailureMessage(E exchange, Object leftValue, Object rightValue) { |
68 |
2 |
return this + " failed on " + exchange + " with left value <" + leftValue + "> right value <" + rightValue + ">"; |
69 |
|
} |
70 |
|
} |