You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2011/01/04 18:19:41 UTC
svn commit: r1055107 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/builder/NotifyBuilder.java
test/java/org/apache/camel/builder/NotifyBuilderTest.java
Author: davsclaus
Date: Tue Jan 4 17:19:40 2011
New Revision: 1055107
URL: http://svn.apache.org/viewvc?rev=1055107&view=rev
Log:
CAMEL-3486: NotifyBuilder should be created before matches can be used
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
camel/trunk/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.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=1055107&r1=1055106&r2=1055107&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 Tue Jan 4 17:19:40 2011
@@ -68,6 +68,7 @@ public class NotifyBuilder {
// the current state while building an event predicate where we use a stack and the operation
private final Stack<EventPredicate> stack = new Stack<EventPredicate>();
private EventOperation operation;
+ private boolean created;
// computed value whether all the predicates matched
private boolean matches;
@@ -1005,6 +1006,7 @@ public class NotifyBuilder {
*/
public NotifyBuilder create() {
doCreate(EventOperation.and);
+ created = true;
return this;
}
@@ -1016,6 +1018,9 @@ public class NotifyBuilder {
* @return <tt>true</tt> if matching, <tt>false</tt> otherwise
*/
public boolean matches() {
+ if (!created) {
+ throw new IllegalStateException("NotifyBuilder has not been created. Invoke the create() method before matching.");
+ }
return matches;
}
@@ -1030,6 +1035,9 @@ public class NotifyBuilder {
* @return <tt>true</tt> if matching, <tt>false</tt> otherwise due to timeout
*/
public boolean matches(long timeout, TimeUnit timeUnit) {
+ if (!created) {
+ throw new IllegalStateException("NotifyBuilder has not been created. Invoke the create() method before matching.");
+ }
try {
latch.await(timeout, timeUnit);
} catch (InterruptedException e) {
@@ -1053,6 +1061,9 @@ public class NotifyBuilder {
* @return <tt>true</tt> if matching, <tt>false</tt> otherwise due to timeout
*/
public boolean matchesMockWaitTime() {
+ if (!created) {
+ throw new IllegalStateException("NotifyBuilder has not been created. Invoke the create() method before matching.");
+ }
long timeout = 0;
for (Endpoint endpoint : context.getEndpoints()) {
if (endpoint instanceof MockEndpoint) {
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java?rev=1055107&r1=1055106&r2=1055107&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java Tue Jan 4 17:19:40 2011
@@ -24,6 +24,17 @@ import org.apache.camel.component.mock.M
*/
public class NotifyBuilderTest extends ContextTestSupport {
+ public void testMustBeCreated() throws Exception {
+ NotifyBuilder notify = new NotifyBuilder(context).whenDone(1);
+
+ try {
+ notify.matches();
+ fail("Should have thrown an exception");
+ } catch (IllegalStateException e) {
+ assertEquals("NotifyBuilder has not been created. Invoke the create() method before matching.", e.getMessage());
+ }
+ }
+
public void testDirectWhenExchangeDoneSimple() throws Exception {
NotifyBuilder notify = new NotifyBuilder(context)
.from("direct:foo").whenDone(1)