This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch mock in repository https://gitbox.apache.org/repos/asf/camel.git
commit 636e29bf388d896c3a459b47fb72580158612a92 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Apr 17 07:34:01 2019 +0200 Move mock component out of camel-core. Work in progress. --- MIGRATION.md | 4 +++ .../org/apache/camel/builder/NotifyBuilder.java | 30 +++++++++++++++++++--- .../camel/component/seda/SedaNoConsumerTest.java | 4 +-- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index f60ae99..6377a66 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -92,6 +92,10 @@ We have also renamed `camel-jetty9` to `camel-jetty`. The `dataset` component has been moved out of `camel-core`, and is no longer a transient dependency from `camel-core`, and therefore you should add `camel-dataset` as dependency if you use this component. +### Mock component + +The `mock` component has been moved out of `camel-core` and as part of this work, we had to remove a number of methods on its _assertion clause builder_ that were seldom in use. Also we had to remove a few methods on `NotifyBuilder` that were using the `mock` component. + ### ActiveMQ If you are using the `activemq-camel` component, then you should migrate to use `camel-activemq` component, where the component name has changed from `org.apache.activemq.camel.component.ActiveMQComponent` to `org.apache.camel.component.activemq.ActiveMQComponent`. diff --git a/core/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java b/core/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java index 1a6153c..764e235 100644 --- a/core/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java +++ b/core/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java @@ -32,7 +32,6 @@ import org.apache.camel.Exchange; import org.apache.camel.Expression; import org.apache.camel.Predicate; import org.apache.camel.RuntimeCamelException; -import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.spi.CamelEvent; import org.apache.camel.spi.CamelEvent.ExchangeCompletedEvent; import org.apache.camel.spi.CamelEvent.ExchangeCreatedEvent; @@ -76,6 +75,8 @@ public class NotifyBuilder { private boolean created; // keep state of how many wereSentTo we have added private int wereSentToIndex; + // default wait time + private long waitTime = 10000L; // computed value whether all the predicates matched private volatile boolean matches; @@ -956,6 +957,14 @@ public class NotifyBuilder { } /** + * Specifies the wait time in millis to use in the {@link #matchesWaitTime()} method. + */ + public NotifyBuilder waitTime(long waitTime) { + this.waitTime = waitTime; + return this; + } + + /** * Creates the expression this builder should use for matching. * <p/> * You must call this method when you are finished building the expressions. @@ -1031,16 +1040,29 @@ public class NotifyBuilder { * The timeout value is by default 10 seconds. * * @return <tt>true</tt> if matching, <tt>false</tt> otherwise due to timeout - * @deprecated use {@link #matches(long, TimeUnit)} instead + * @deprecated use {@link #matchesWaitTime()} instead */ @Deprecated public boolean matchesMockWaitTime() { + return matchesWaitTime(); + } + + /** + * Does all the expressions 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. + * + * @return <tt>true</tt> if matching, <tt>false</tt> otherwise due to timeout + */ + public boolean matchesWaitTime() { if (!created) { throw new IllegalStateException("NotifyBuilder has not been created. Invoke the create() method before matching."); } - // use 10 sec as default - return matches(10000, TimeUnit.MILLISECONDS); + return matches(waitTime, TimeUnit.MILLISECONDS); } /** diff --git a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaNoConsumerTest.java b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaNoConsumerTest.java index 1300510..b6b622f 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaNoConsumerTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaNoConsumerTest.java @@ -42,12 +42,12 @@ public class SedaNoConsumerTest extends ContextTestSupport { }); context.start(); - NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create(); + NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).waitTime(2000).create(); // no problem for in only as we do not expect a reply template.sendBody("direct:start", "Hello World"); - notify.matches(2, TimeUnit.SECONDS); + assertTrue(notify.matchesWaitTime()); } public void testInOut() throws Exception {