Updated Branches:
refs/heads/camel-2.11.x f79a58a94 -> 2176e5885
refs/heads/camel-2.12.x aca1edfad -> ed2c71a4c
CAMEL-6792: Added getMockEndpoint method to not auto create. Thanks to James
Carman for the patch.
Conflicts:
components/camel-test/src/test/java/org/apache/camel/test/CamelTestSupportTest.java
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2176e588
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2176e588
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2176e588
Branch: refs/heads/camel-2.11.x
Commit: 2176e5885d693e17ec66208e604eff1f9140b55d
Parents: 5dbe9ce
Author: Claus Ibsen <[email protected]>
Authored: Sun Sep 29 10:25:27 2013 +0200
Committer: Claus Ibsen <[email protected]>
Committed: Sun Sep 29 10:28:39 2013 +0200
----------------------------------------------------------------------
.../camel/test/junit4/CamelTestSupport.java | 24 +++++++++++++++++++-
.../apache/camel/testng/CamelTestSupport.java | 24 +++++++++++++++++++-
2 files changed, 46 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2176e588/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
----------------------------------------------------------------------
diff --git
a/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
b/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
index 9702810..b648dd6 100644
---
a/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
+++
b/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
@@ -30,6 +30,7 @@ import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Expression;
import org.apache.camel.Message;
+import org.apache.camel.NoSuchEndpointException;
import org.apache.camel.Predicate;
import org.apache.camel.Processor;
import org.apache.camel.ProducerTemplate;
@@ -535,7 +536,28 @@ public abstract class CamelTestSupport extends TestSupport
{
* @return the mandatory mock endpoint or an exception is thrown if it
could not be resolved
*/
protected MockEndpoint getMockEndpoint(String uri) {
- return resolveMandatoryEndpoint(uri, MockEndpoint.class);
+ return getMockEndpoint(uri, true);
+ }
+
+ /**
+ * Resolves the {@link MockEndpoint} using a URI of the form
<code>mock:someName</code>, optionally
+ * creating it if it does not exist.
+ *
+ * @param uri the URI which typically starts with "mock:" and has
some name
+ * @param create whether or not to allow the endpoint to be created if
it doesn't exist
+ * @return the mock endpoint or an {@link NoSuchEndpointException} is
thrown if it could not be resolved
+ * @throws NoSuchEndpointException is the mock endpoint does not exists
+ */
+ protected MockEndpoint getMockEndpoint(String uri, boolean create) throws
NoSuchEndpointException {
+ if (create) {
+ return resolveMandatoryEndpoint(uri, MockEndpoint.class);
+ } else {
+ Endpoint endpoint = context.hasEndpoint(uri);
+ if (endpoint instanceof MockEndpoint) {
+ return (MockEndpoint) endpoint;
+ }
+ throw new NoSuchEndpointException(String.format("MockEndpoint %s
does not exist.", uri));
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/camel/blob/2176e588/components/camel-testng/src/main/java/org/apache/camel/testng/CamelTestSupport.java
----------------------------------------------------------------------
diff --git
a/components/camel-testng/src/main/java/org/apache/camel/testng/CamelTestSupport.java
b/components/camel-testng/src/main/java/org/apache/camel/testng/CamelTestSupport.java
index a4b2e46..33d42e2 100644
---
a/components/camel-testng/src/main/java/org/apache/camel/testng/CamelTestSupport.java
+++
b/components/camel-testng/src/main/java/org/apache/camel/testng/CamelTestSupport.java
@@ -30,6 +30,7 @@ import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Expression;
import org.apache.camel.Message;
+import org.apache.camel.NoSuchEndpointException;
import org.apache.camel.Predicate;
import org.apache.camel.Processor;
import org.apache.camel.ProducerTemplate;
@@ -512,7 +513,28 @@ public abstract class CamelTestSupport extends TestSupport
{
* @return the mandatory mock endpoint or an exception is thrown if it
could not be resolved
*/
protected MockEndpoint getMockEndpoint(String uri) {
- return resolveMandatoryEndpoint(uri, MockEndpoint.class);
+ return getMockEndpoint(uri, true);
+ }
+
+ /**
+ * Resolves the {@link MockEndpoint} using a URI of the form
<code>mock:someName</code>, optionally
+ * creating it if it does not exist.
+ *
+ * @param uri the URI which typically starts with "mock:" and has
some name
+ * @param create whether or not to allow the endpoint to be created if
it doesn't exist
+ * @return the mock endpoint or an {@link NoSuchEndpointException} is
thrown if it could not be resolved
+ * @throws NoSuchEndpointException is the mock endpoint does not exists
+ */
+ protected MockEndpoint getMockEndpoint(String uri, boolean create) throws
NoSuchEndpointException {
+ if (create) {
+ return resolveMandatoryEndpoint(uri, MockEndpoint.class);
+ } else {
+ Endpoint endpoint = context.hasEndpoint(uri);
+ if (endpoint instanceof MockEndpoint) {
+ return (MockEndpoint) endpoint;
+ }
+ throw new NoSuchEndpointException(String.format("MockEndpoint %s
does not exist.", uri));
+ }
}
/**