Author: ningjiang Date: Wed Apr 24 15:13:10 2013 New Revision: 1471468 URL: http://svn.apache.org/r1471468 Log: CAMEL-6305 Fixed CamelBlueprintTestSupport doesn't call debugBefore() and debugAfter() issue Merged revisions 1471408 via svnmerge from https://svn.apache.org/repos/asf/camel/trunk
........ r1471408 | ningjiang | 2013-04-24 21:34:05 +0800 (Wed, 24 Apr 2013) | 1 line CAMEL-6305 Fixed CamelBlueprintTestSupport doesn't call debugBefore() and debugAfter() issue ........ Modified: camel/branches/camel-2.11.x/ (props changed) camel/branches/camel-2.11.x/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DebugBlueprintTest.java camel/branches/camel-2.11.x/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java Propchange: camel/branches/camel-2.11.x/ ------------------------------------------------------------------------------ Merged /camel/trunk:r1471408 Propchange: camel/branches/camel-2.11.x/ ------------------------------------------------------------------------------ --- svnmerge-integrated (original) +++ svnmerge-integrated Wed Apr 24 15:13:10 2013 @@ -1 +1 @@ -/camel/trunk:1-1468763,1469704,1469819,1470420,1470426-1470427,1470429,1470508,1471293,1471330,1471407 +/camel/trunk:1-1468763,1469704,1469819,1470420,1470426-1470427,1470429,1470508,1471293,1471330,1471407-1471408 Modified: camel/branches/camel-2.11.x/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DebugBlueprintTest.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.11.x/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DebugBlueprintTest.java?rev=1471468&r1=1471467&r2=1471468&view=diff ============================================================================== --- camel/branches/camel-2.11.x/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DebugBlueprintTest.java (original) +++ camel/branches/camel-2.11.x/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DebugBlueprintTest.java Wed Apr 24 15:13:10 2013 @@ -16,6 +16,10 @@ */ package org.apache.camel.test.blueprint; +import org.junit.Assert; + +import org.apache.camel.Exchange; +import org.apache.camel.model.ProcessorDefinition; import org.junit.Test; // START SNIPPET: example @@ -23,15 +27,20 @@ import org.junit.Test; // and add your unit tests methods as shown below. public class DebugBlueprintTest extends CamelBlueprintTestSupport { + public boolean wasDebugBeforeCalled = false; + public boolean wasDebugAfterCalled = false; + + // override this method, and return the location of our Blueprint XML file to be used for testing @Override protected String getBlueprintDescriptor() { return "org/apache/camel/test/blueprint/camelContext.xml"; } - + // here we have regular Junit @Test method @Test public void testRoute() throws Exception { + // set mock expectations getMockEndpoint("mock:a").expectedMessageCount(1); @@ -40,7 +49,29 @@ public class DebugBlueprintTest extends // assert mocks assertMockEndpointsSatisfied(); + Assert.assertTrue(wasDebugBeforeCalled); + Assert.assertTrue(wasDebugAfterCalled); + } + + + @Override + public boolean isUseDebugger() { + // must enable debugger + return true; + } + + + @Override + protected void debugBefore(Exchange exchange, org.apache.camel.Processor processor, ProcessorDefinition<?> definition, String id, String label) { + log.info("Before " + definition + " with body " + exchange.getIn().getBody()); + wasDebugBeforeCalled = true; } + + @Override + protected void debugAfter(Exchange exchange, org.apache.camel.Processor processor, ProcessorDefinition<?> definition, String id, String label, long timeTaken) { + log.info("After " + definition + " with body " + exchange.getIn().getBody()); + wasDebugAfterCalled = true; + } } -// END SNIPPET: example +// END SNIPPET: example \ No newline at end of file Modified: camel/branches/camel-2.11.x/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.11.x/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java?rev=1471468&r1=1471467&r2=1471468&view=diff ============================================================================== --- camel/branches/camel-2.11.x/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java (original) +++ camel/branches/camel-2.11.x/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java Wed Apr 24 15:13:10 2013 @@ -34,6 +34,7 @@ import org.apache.camel.Predicate; import org.apache.camel.Processor; import org.apache.camel.ProducerTemplate; import org.apache.camel.Service; +import org.apache.camel.ServiceStatus; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.component.properties.PropertiesComponent; @@ -245,6 +246,11 @@ public abstract class CamelTestSupport e // set debugger if enabled if (isUseDebugger()) { + if (context.getStatus().equals(ServiceStatus.Started)) { + log.info("Cannot setting the Debugger to the starting CamelConetxt, stop the CamelContext now."); + // we need to stop the context first to setup the debugger + context.stop(); + } context.setDebugger(new DefaultDebugger()); context.getDebugger().addBreakpoint(breakpoint); // note: when stopping CamelContext it will automatic remove the breakpoint