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/28 16:28:54 UTC
svn commit: r1064732 [2/2] - in /camel/trunk:
camel-core/src/main/java/org/apache/camel/
camel-core/src/main/java/org/apache/camel/builder/
camel-core/src/main/java/org/apache/camel/component/mock/
camel-core/src/main/java/org/apache/camel/impl/ camel-...
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithRecipientListMockEndpointsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithRecipientListMockEndpointsTest.java?rev=1064732&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithRecipientListMockEndpointsTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithRecipientListMockEndpointsTest.java Fri Jan 28 15:28:53 2011
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor.interceptor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision: 938376 $
+ */
+public class AdviceWithRecipientListMockEndpointsTest extends ContextTestSupport {
+
+ public void testAdvisedMockEndpoints() throws Exception {
+ // advice the second route using the inlined AdviceWith route builder
+ // which has extended capabilities than the regular route builder
+ context.getRouteDefinitions().get(1).adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // mock all endpoints
+ mockEndpoints("log*");
+ }
+ });
+
+ // log:bar is a dynamic endpoint created on-the-fly (eg not in the route)
+ getMockEndpoint("mock:log:bar").expectedMessageCount(1);
+ // log:foo is in the route
+ getMockEndpoint("mock:log:foo").expectedMessageCount(1);
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "foo", "log:bar,direct:foo");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").recipientList(header("foo"));
+
+ from("direct:foo").to("log:foo").to("mock:result");
+ }
+ };
+ }
+}
Modified: camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/CamelTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/CamelTestSupport.java?rev=1064732&r1=1064731&r2=1064732&view=diff
==============================================================================
--- camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/CamelTestSupport.java (original)
+++ camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/CamelTestSupport.java Fri Jan 28 15:28:53 2011
@@ -39,6 +39,7 @@ import org.apache.camel.component.mock.M
import org.apache.camel.impl.BreakpointSupport;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.DefaultDebugger;
+import org.apache.camel.impl.InterceptSendToMockEndpointStrategy;
import org.apache.camel.impl.JndiRegistry;
import org.apache.camel.management.JmxSystemPropertyKeys;
import org.apache.camel.model.ProcessorDefinition;
@@ -64,6 +65,17 @@ public abstract class CamelTestSupport e
return useRouteBuilder;
}
+ /**
+ * Override to enable auto mocking endpoints based on the pattern.
+ * <p/>
+ * Return <tt>*</tt> to mock all endpoints.
+ *
+ * @see org.apache.camel.util.EndpointHelper#matchEndpoint(String, String)
+ */
+ public String isMockEndpoints() {
+ return null;
+ }
+
public void setUseRouteBuilder(boolean useRouteBuilder) {
this.useRouteBuilder = useRouteBuilder;
}
@@ -110,6 +122,12 @@ public abstract class CamelTestSupport e
consumer = context.createConsumerTemplate();
consumer.start();
+ // enable auto mocking if enabled
+ String pattern = isMockEndpoints();
+ if (pattern != null) {
+ context.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(pattern));
+ }
+
postProcessTest();
if (isUseRouteBuilder()) {
Modified: camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java?rev=1064732&r1=1064731&r2=1064732&view=diff
==============================================================================
--- camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java (original)
+++ camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java Fri Jan 28 15:28:53 2011
@@ -39,6 +39,7 @@ import org.apache.camel.component.mock.M
import org.apache.camel.impl.BreakpointSupport;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.DefaultDebugger;
+import org.apache.camel.impl.InterceptSendToMockEndpointStrategy;
import org.apache.camel.impl.JndiRegistry;
import org.apache.camel.management.JmxSystemPropertyKeys;
import org.apache.camel.model.ProcessorDefinition;
@@ -66,6 +67,17 @@ public abstract class CamelTestSupport e
return useRouteBuilder;
}
+ /**
+ * Override to enable auto mocking endpoints based on the pattern.
+ * <p/>
+ * Return <tt>*</tt> to mock all endpoints.
+ *
+ * @see org.apache.camel.util.EndpointHelper#matchEndpoint(String, String)
+ */
+ public String isMockEndpoints() {
+ return null;
+ }
+
public void setUseRouteBuilder(boolean useRouteBuilder) {
this.useRouteBuilder = useRouteBuilder;
}
@@ -112,6 +124,12 @@ public abstract class CamelTestSupport e
consumer = context.createConsumerTemplate();
consumer.start();
+ // enable auto mocking if enabled
+ String pattern = isMockEndpoints();
+ if (pattern != null) {
+ context.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(pattern));
+ }
+
postProcessTest();
if (isUseRouteBuilder()) {
Added: camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsJUnit4Test.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsJUnit4Test.java?rev=1064732&view=auto
==============================================================================
--- camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsJUnit4Test.java (added)
+++ camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsJUnit4Test.java Fri Jan 28 15:28:53 2011
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.test.patterns;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class IsMockEndpointsJUnit4Test extends CamelTestSupport {
+
+ @Override
+ public String isMockEndpoints() {
+ return "*";
+ }
+
+ @Test
+ public void testMockAllEndpoints() throws Exception {
+ getMockEndpoint("mock:direct:start").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:direct:foo").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:log:foo").expectedBodiesReceived("Bye World");
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+
+ // additional test to ensure correct endpoints in registry
+ assertNotNull(context.hasEndpoint("direct:start"));
+ assertNotNull(context.hasEndpoint("direct:foo"));
+ assertNotNull(context.hasEndpoint("log:foo"));
+ assertNotNull(context.hasEndpoint("mock:result"));
+ // all the endpoints was mocked
+ assertNotNull(context.hasEndpoint("mock:direct:start"));
+ assertNotNull(context.hasEndpoint("mock:direct:foo"));
+ assertNotNull(context.hasEndpoint("mock:log:foo"));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to("direct:foo").to("log:foo").to("mock:result");
+
+ from("direct:foo").transform(constant("Bye World"));
+ }
+ };
+ }
+}
Added: camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsTest.java?rev=1064732&view=auto
==============================================================================
--- camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsTest.java (added)
+++ camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsTest.java Fri Jan 28 15:28:53 2011
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.test.patterns;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.CamelTestSupport;
+
+/**
+ * @version $Revision$
+ */
+public class IsMockEndpointsTest extends CamelTestSupport {
+
+ @Override
+ public String isMockEndpoints() {
+ return "*";
+ }
+
+ public void testMockAllEndpoints() throws Exception {
+ getMockEndpoint("mock:direct:start").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:direct:foo").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:log:foo").expectedBodiesReceived("Bye World");
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+
+ // additional test to ensure correct endpoints in registry
+ assertNotNull(context.hasEndpoint("direct:start"));
+ assertNotNull(context.hasEndpoint("direct:foo"));
+ assertNotNull(context.hasEndpoint("log:foo"));
+ assertNotNull(context.hasEndpoint("mock:result"));
+ // all the endpoints was mocked
+ assertNotNull(context.hasEndpoint("mock:direct:start"));
+ assertNotNull(context.hasEndpoint("mock:direct:foo"));
+ assertNotNull(context.hasEndpoint("mock:log:foo"));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to("direct:foo").to("log:foo").to("mock:result");
+
+ from("direct:foo").transform(constant("Bye World"));
+ }
+ };
+ }
+}