Author: ningjiang
Date: Tue Aug 23 04:54:59 2011
New Revision: 1160547
URL: http://svn.apache.org/viewvc?rev=1160547&view=rev
Log:
CAMEL-4368 Fixed the issue of the debug doesn't work in the
CamelSpringTestSupport
Added:
camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/DebugSpringTest.java
(with props)
camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugSpringTest.java
(with props)
Modified:
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java
camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelSpringTestSupport.java
Modified:
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java?rev=1160547&r1=1160546&r2=1160547&view=diff
==============================================================================
---
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
(original)
+++
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
Tue Aug 23 04:54:59 2011
@@ -77,7 +77,12 @@ public class SpringCamelContext extends
NO_START.remove();
}
}
+
public static SpringCamelContext springCamelContext(ApplicationContext
applicationContext) throws Exception {
+ return springCamelContext(applicationContext, true);
+ }
+
+ public static SpringCamelContext springCamelContext(ApplicationContext
applicationContext, boolean maybeStart) throws Exception {
// lets try and look up a configured camel context in the context
String[] names =
applicationContext.getBeanNamesForType(SpringCamelContext.class);
if (names.length == 1) {
@@ -85,7 +90,9 @@ public class SpringCamelContext extends
}
SpringCamelContext answer = new SpringCamelContext();
answer.setApplicationContext(applicationContext);
- answer.afterPropertiesSet();
+ if (maybeStart) {
+ answer.afterPropertiesSet();
+ }
return answer;
}
Modified:
camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java?rev=1160547&r1=1160546&r2=1160547&view=diff
==============================================================================
---
camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java
(original)
+++
camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java
Tue Aug 23 04:54:59 2011
@@ -201,6 +201,7 @@ public abstract class CamelSpringTestSup
@Override
protected CamelContext createCamelContext() throws Exception {
- return SpringCamelContext.springCamelContext(applicationContext);
+ // don't start the springCamelContext if we
+ return SpringCamelContext.springCamelContext(applicationContext,
false);
}
}
Added:
camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/DebugSpringTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/DebugSpringTest.java?rev=1160547&view=auto
==============================================================================
---
camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/DebugSpringTest.java
(added)
+++
camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/DebugSpringTest.java
Tue Aug 23 04:54:59 2011
@@ -0,0 +1,81 @@
+/**
+ * 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.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
+
+public class DebugSpringTest extends CamelSpringTestSupport {
+ private boolean debugged;
+
+ @Override
+ public boolean isUseDebugger() {
+ // must enable debugger
+ return true;
+ }
+
+ @Override
+ protected void debugBefore(Exchange exchange, Processor processor,
+ ProcessorDefinition definition, String id,
String shortName) {
+ // this method is invoked before we are about to enter the given
processor
+ // from your Java editor you can just add a breakpoint in the code
line below
+ log.info("Before " + definition + " with body " +
exchange.getIn().getBody());
+ debugged = true;
+ }
+
+
+ @Test
+ public void testDebugger() throws Exception {
+ // set mock expectations
+ getMockEndpoint("mock:a").expectedMessageCount(1);
+ getMockEndpoint("mock:b").expectedMessageCount(1);
+
+ // send a message
+ template.sendBody("direct:start", "World");
+
+ // assert mocks
+ assertMockEndpointsSatisfied();
+ assertTrue("The debugger is not called!", debugged);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // this is the route we want to debug
+ from("direct:start")
+ .to("mock:a")
+ .transform(body().prepend("Hello "))
+ .to("mock:b");
+ }
+ };
+ }
+
+
+ @Override
+ protected AbstractApplicationContext createApplicationContext() {
+ return new GenericApplicationContext();
+ }
+
+}
Propchange:
camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/DebugSpringTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/DebugSpringTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelSpringTestSupport.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelSpringTestSupport.java?rev=1160547&r1=1160546&r2=1160547&view=diff
==============================================================================
---
camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelSpringTestSupport.java
(original)
+++
camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/CamelSpringTestSupport.java
Tue Aug 23 04:54:59 2011
@@ -167,6 +167,6 @@ public abstract class CamelSpringTestSup
@Override
protected CamelContext createCamelContext() throws Exception {
- return SpringCamelContext.springCamelContext(applicationContext);
+ return SpringCamelContext.springCamelContext(applicationContext,
false);
}
}
Added:
camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugSpringTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugSpringTest.java?rev=1160547&view=auto
==============================================================================
---
camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugSpringTest.java
(added)
+++
camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugSpringTest.java
Tue Aug 23 04:54:59 2011
@@ -0,0 +1,81 @@
+/**
+ * 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.testng.patterns;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.testng.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
+
+public class DebugSpringTest extends CamelSpringTestSupport {
+ private boolean debugged;
+
+ @Override
+ public boolean isUseDebugger() {
+ // must enable debugger
+ return true;
+ }
+
+ @Override
+ protected void debugBefore(Exchange exchange, Processor processor,
+ ProcessorDefinition definition, String id,
String shortName) {
+ // this method is invoked before we are about to enter the given
processor
+ // from your Java editor you can just add a breakpoint in the code
line below
+ log.info("Before " + definition + " with body " +
exchange.getIn().getBody());
+ debugged = true;
+ }
+
+
+ @Test
+ public void testDebugger() throws Exception {
+ // set mock expectations
+ getMockEndpoint("mock:a").expectedMessageCount(1);
+ getMockEndpoint("mock:b").expectedMessageCount(1);
+
+ // send a message
+ template.sendBody("direct:start", "World");
+
+ // assert mocks
+ assertMockEndpointsSatisfied();
+ assertTrue(debugged, "The debugger is not called!");
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // this is the route we want to debug
+ from("direct:start")
+ .to("mock:a")
+ .transform(body().prepend("Hello "))
+ .to("mock:b");
+ }
+ };
+ }
+
+
+ @Override
+ protected AbstractApplicationContext createApplicationContext() {
+ return new GenericApplicationContext();
+ }
+
+}
Propchange:
camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugSpringTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-testng/src/test/java/org/apache/camel/testng/patterns/DebugSpringTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date