Author: davsclaus
Date: Thu Dec 9 09:54:59 2010
New Revision: 1043877
URL: http://svn.apache.org/viewvc?rev=1043877&view=rev
Log:
CAMEL-3418: Added matchesMockWaitTime method to NotifyBuilder
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java?rev=1043877&r1=1043876&r2=1043877&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
Thu Dec 9 09:54:59 2010
@@ -26,6 +26,7 @@ import java.util.concurrent.CountDownLat
import java.util.concurrent.TimeUnit;
import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Expression;
import org.apache.camel.Predicate;
@@ -53,6 +54,8 @@ import org.apache.camel.util.ServiceHelp
*/
public class NotifyBuilder {
+ private final CamelContext context;
+
// notifier to hook into Camel to listen for events
private final EventNotifier eventNotifier;
@@ -75,6 +78,7 @@ public class NotifyBuilder {
* @param context the Camel context
*/
public NotifyBuilder(CamelContext context) {
+ this.context = context;
eventNotifier = new ExchangeNotifier();
try {
ServiceHelper.startService(eventNotifier);
@@ -1035,6 +1039,39 @@ public class NotifyBuilder {
}
/**
+ * Does all the expression match?
+ * <p/>
+ * This operation will wait until the match is <tt>true</tt> or otherwise
a timeout occur
+ * which means <tt>false</tt> will be returned.
+ * <p/>
+ * The timeout value is by default 10 seconds. But it will use the highest
<i>maximum result wait time</i>
+ * from the configured mocks, if such a value has been configured.
+ * <p/>
+ * This method is convenient to use in unit tests to have it adhere and
wait
+ * as long as the mock endpoints.
+ *
+ * @return <tt>true</tt> if matching, <tt>false</tt> otherwise due to
timeout
+ */
+ public boolean matchesMockWaitTime() {
+ long timeout = 0;
+ for (Endpoint endpoint : context.getEndpoints()) {
+ if (endpoint instanceof MockEndpoint) {
+ long waitTime = ((MockEndpoint) endpoint).getResultWaitTime();
+ if (waitTime > 0) {
+ timeout = Math.max(timeout, waitTime);
+ }
+ }
+ }
+
+ // use 10 sec as default
+ if (timeout == 0) {
+ timeout = 10000;
+ }
+
+ return matches(timeout, TimeUnit.MILLISECONDS);
+ }
+
+ /**
* Resets the notifier.
*/
public void reset() {