Author: davsclaus
Date: Wed Oct 31 08:21:32 2012
New Revision: 1404020
URL: http://svn.apache.org/viewvc?rev=1404020&view=rev
Log:
Polished and fixed test on slow CI server.
Modified:
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/junit4/CamelSpringJUnit4ClassRunner.java
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringDelegatingTestContextLoader.java
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoaderTestExecutionListener.java
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestHelper.java
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/DisableJmxTestExecutionListener.java
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/ExcludeRoutes.java
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/ShutdownTimeout.java
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/StopWatchTestExecutionListener.java
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/UseAdviceWith.java
camel/trunk/components/camel-test-spring/src/test/java/org/apache/camel/test/junit4/CamelSpringJUnit4ClassRunnerUseAdviceWithTest.java
Modified:
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/junit4/CamelSpringJUnit4ClassRunner.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/junit4/CamelSpringJUnit4ClassRunner.java?rev=1404020&r1=1404019&r2=1404020&view=diff
==============================================================================
---
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/junit4/CamelSpringJUnit4ClassRunner.java
(original)
+++
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/junit4/CamelSpringJUnit4ClassRunner.java
Wed Oct 31 08:21:32 2012
@@ -34,12 +34,9 @@ import org.springframework.test.context.
* for their Spring based applications/routes using the typical Spring Test
conventions
* for test development.
*/
-public class CamelSpringJUnit4ClassRunner extends
- SpringJUnit4ClassRunner {
+public class CamelSpringJUnit4ClassRunner extends SpringJUnit4ClassRunner {
- public CamelSpringJUnit4ClassRunner(Class<?> clazz)
- throws InitializationError {
-
+ public CamelSpringJUnit4ClassRunner(Class<?> clazz) throws
InitializationError {
super(clazz);
}
@@ -71,8 +68,7 @@ public class CamelSpringJUnit4ClassRunne
*/
public static final class CamelTestContextManager extends
TestContextManager {
- public CamelTestContextManager(Class<?> testClass,
- String defaultContextLoaderClassName) {
+ public CamelTestContextManager(Class<?> testClass, String
defaultContextLoaderClassName) {
super(testClass, defaultContextLoaderClassName);
}
@@ -81,19 +77,16 @@ public class CamelSpringJUnit4ClassRunne
* for the Camel testing features.
*/
@Override
- protected Set<Class<? extends TestExecutionListener>>
- getDefaultTestExecutionListenerClasses() {
-
- Set<Class<? extends TestExecutionListener>> classes =
- new LinkedHashSet<Class<? extends
TestExecutionListener>>();
-
+ protected Set<Class<? extends TestExecutionListener>>
getDefaultTestExecutionListenerClasses() {
+ Set<Class<? extends TestExecutionListener>> classes = new
LinkedHashSet<Class<? extends TestExecutionListener>>();
+
classes.add(CamelSpringTestContextLoaderTestExecutionListener.class);
-
classes.addAll(super.getDefaultTestExecutionListenerClasses());
-
classes.add(DisableJmxTestExecutionListener.class);
classes.add(StopWatchTestExecutionListener.class);
+
return classes;
}
}
+
}
Modified:
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java?rev=1404020&r1=1404019&r2=1404020&view=diff
==============================================================================
---
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java
(original)
+++
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/junit4/CamelSpringTestSupport.java
Wed Oct 31 08:21:32 2012
@@ -35,12 +35,10 @@ import org.springframework.context.suppo
* @version
*/
public abstract class CamelSpringTestSupport extends CamelTestSupport {
- protected static ThreadLocal<AbstractApplicationContext> threadAppContext
- = new ThreadLocal<AbstractApplicationContext>();
+ protected static ThreadLocal<AbstractApplicationContext> threadAppContext
= new ThreadLocal<AbstractApplicationContext>();
protected static Object lock = new Object();
protected AbstractApplicationContext applicationContext;
-
protected abstract AbstractApplicationContext createApplicationContext();
/**
Modified:
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringDelegatingTestContextLoader.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringDelegatingTestContextLoader.java?rev=1404020&r1=1404019&r2=1404020&view=diff
==============================================================================
---
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringDelegatingTestContextLoader.java
(original)
+++
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringDelegatingTestContextLoader.java
Wed Oct 31 08:21:32 2012
@@ -43,30 +43,25 @@ import org.springframework.core.annotati
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.support.DelegatingSmartContextLoader;
+import static org.apache.camel.test.spring.CamelSpringTestHelper.getAllMethods;
+
/**
* Custom TestContextLoader which fixes issues in Camel's
JavaConfigContextLoader. (adds support for Camel's test annotations)
* <br>
* <em>This loader can handle either classes or locations for configuring the
context.</em>
* <br>
*/
-public class CamelSpringDelegatingTestContextLoader extends
DelegatingSmartContextLoader
-{
+public class CamelSpringDelegatingTestContextLoader extends
DelegatingSmartContextLoader {
protected final Logger logger = LoggerFactory.getLogger(getClass());
-
-
- /*
- * (non-Javadoc)
- * @see
org.springframework.test.context.support.DelegatingSmartContextLoader#loadContext(org.springframework.test.context.MergedContextConfiguration)
- */
+
@Override
public ApplicationContext loadContext(MergedContextConfiguration
mergedConfig) throws Exception {
Class<?> testClass = getTestClass();
if (logger.isDebugEnabled()) {
- logger.debug(String.format("Loading ApplicationContext for merged
context configuration [%s].",
- mergedConfig));
+ logger.debug("Loading ApplicationContext for merged context
configuration [{}].", mergedConfig);
}
// Pre CamelContext(s) instantiation setup
@@ -88,7 +83,6 @@ public class CamelSpringDelegatingTestCo
*
* @param context the partially configured context. The context should
have the bean definitions loaded, but nothing else.
* @param testClass the test class being executed
- *
* @return the initialized (refreshed) Spring application context
*
* @throws Exception if there is an error during
initialization/customization
@@ -131,48 +125,25 @@ public class CamelSpringDelegatingTestCo
}
/**
- * Returns all methods defined in {@code clazz} and its
superclasses/interfaces.
- */
- protected Collection<Method> getAllMethods(Class<?> clazz) {
-
- Set<Method> methods = new HashSet<Method>();
- Class<?> currentClass = clazz;
-
- while (currentClass != null) {
- methods.addAll(Arrays.asList(clazz.getMethods()));
- currentClass = currentClass.getSuperclass();
- }
-
- return methods;
- }
-
- /**
* Handles disabling of JMX on Camel contexts based on {@link DisableJmx}.
*
* @param context the initialized Spring context
* @param testClass the test class being executed
*/
protected void handleDisableJmx(ConfigurableApplicationContext context,
Class<?> testClass) {
- CamelSpringTestHelper.setOriginalJmxDisabledValue(
- System.getProperty(JmxSystemPropertyKeys.DISABLED));
+
CamelSpringTestHelper.setOriginalJmxDisabledValue(System.getProperty(JmxSystemPropertyKeys.DISABLED));
if (testClass.isAnnotationPresent(DisableJmx.class)) {
if (testClass.getAnnotation(DisableJmx.class).value()) {
- logger.info("Disabling Camel JMX globally as DisableJmx
annotation was found "
- + "and disableJmx is set to true.");
-
+ logger.info("Disabling Camel JMX globally as DisableJmx
annotation was found and disableJmx is set to true.");
System.setProperty(JmxSystemPropertyKeys.DISABLED, "true");
} else {
- logger.info("Enabling Camel JMX as DisableJmx annotation was
found "
- + "and disableJmx is set to false.");
-
+ logger.info("Enabling Camel JMX as DisableJmx annotation was
found and disableJmx is set to false.");
System.clearProperty(JmxSystemPropertyKeys.DISABLED);
}
} else {
- logger.info("Disabling Camel JMX globally for tests by default.
Use the DisableJMX annotation to "
- + "override the default setting.");
-
+ logger.info("Disabling Camel JMX globally for tests by default.
Use the DisableJMX annotation to override the default setting.");
System.setProperty(JmxSystemPropertyKeys.DISABLED, "true");
}
}
@@ -183,18 +154,14 @@ public class CamelSpringDelegatingTestCo
*
* @param context the initialized Spring context containing the Camel
context(s) to insert breakpoints into
* @param testClass the test class being processed
- * @param log the logger to use
- * @param statics if static methods or instance methods should be processed
*
* @throws Exception if there is an error processing the class
*/
protected void handleProvidesBreakpoint(ConfigurableApplicationContext
context, Class<?> testClass) throws Exception {
-
Collection<Method> methods = getAllMethods(testClass);
final List<Breakpoint> breakpoints = new LinkedList<Breakpoint>();
for (Method method : methods) {
-
if (AnnotationUtils.findAnnotation(method,
ProvidesBreakpoint.class) != null) {
Class<?>[] argTypes = method.getParameterTypes();
if (argTypes.length != 0) {
@@ -212,7 +179,7 @@ public class CamelSpringDelegatingTestCo
}
try {
- breakpoints.add((Breakpoint) method.invoke(null, new
Object[] {}));
+ breakpoints.add((Breakpoint) method.invoke(null));
} catch (Exception e) {
throw new RuntimeException("Method [" + method.getName()
+ "] threw exception during evaluation.", e);
@@ -221,12 +188,10 @@ public class CamelSpringDelegatingTestCo
}
if (breakpoints.size() != 0) {
-
CamelSpringTestHelper.doToSpringCamelContexts(context, new
DoToSpringCamelContextsStrategy() {
public void execute(String contextName, SpringCamelContext
camelContext)
throws Exception {
-
Debugger debugger = camelContext.getDebugger();
if (debugger == null) {
debugger = new DefaultDebugger();
@@ -234,18 +199,15 @@ public class CamelSpringDelegatingTestCo
}
for (Breakpoint breakpoint : breakpoints) {
- logger.info(
- "Adding Breakpoint [{}] to CamelContext with
name [{}].",
- breakpoint, contextName);
-
+ logger.info("Adding Breakpoint [{}] to CamelContext
with name [{}].", breakpoint, contextName);
debugger.addBreakpoint(breakpoint);
}
}
});
}
}
-
-
+
+
/**
* Handles updating shutdown timeouts on Camel contexts based on {@link
ShutdownTimeout}.
*
@@ -253,7 +215,6 @@ public class CamelSpringDelegatingTestCo
* @param testClass the test class being executed
*/
protected void handleShutdownTimeout(ConfigurableApplicationContext
context, Class<?> testClass) throws Exception {
-
final int shutdownTimeout;
final TimeUnit shutdownTimeUnit;
if (testClass.isAnnotationPresent(ShutdownTimeout.class)) {
@@ -268,10 +229,7 @@ public class CamelSpringDelegatingTestCo
public void execute(String contextName, SpringCamelContext
camelContext)
throws Exception {
-
- logger.info(
- "Setting shutdown timeout to [{} {}] on CamelContext
with name [{}].",
- new Object[] {shutdownTimeout, shutdownTimeUnit,
contextName});
+ logger.info("Setting shutdown timeout to [{} {}] on
CamelContext with name [{}].", shutdownTimeout, shutdownTimeUnit, contextName);
camelContext.getShutdownStrategy().setTimeout(shutdownTimeout);
camelContext.getShutdownStrategy().setTimeUnit(shutdownTimeUnit);
}
@@ -286,18 +244,13 @@ public class CamelSpringDelegatingTestCo
*/
protected void handleMockEndpoints(ConfigurableApplicationContext context,
Class<?> testClass) throws Exception {
if (testClass.isAnnotationPresent(MockEndpoints.class)) {
-
- final String mockEndpoints = testClass.getAnnotation(
- MockEndpoints.class).value();
+ final String mockEndpoints =
testClass.getAnnotation(MockEndpoints.class).value();
CamelSpringTestHelper.doToSpringCamelContexts(context, new
DoToSpringCamelContextsStrategy() {
public void execute(String contextName, SpringCamelContext
camelContext)
throws Exception {
-
- logger.info("Enabling auto mocking of endpoints matching
pattern [{}] on "
- + "CamelContext with name [{}].", mockEndpoints,
contextName);
- camelContext.addRegisterEndpointCallback(
- new
InterceptSendToMockEndpointStrategy(mockEndpoints));
+ logger.info("Enabling auto mocking of endpoints matching
pattern [{}] on CamelContext with name [{}].", mockEndpoints, contextName);
+ camelContext.addRegisterEndpointCallback(new
InterceptSendToMockEndpointStrategy(mockEndpoints));
}
});
}
@@ -312,18 +265,13 @@ public class CamelSpringDelegatingTestCo
*/
protected void handleMockEndpointsAndSkip(ConfigurableApplicationContext
context, Class<?> testClass) throws Exception {
if (testClass.isAnnotationPresent(MockEndpoints.class)) {
-
- final String mockEndpoints = testClass.getAnnotation(
- MockEndpoints.class).value();
+ final String mockEndpoints =
testClass.getAnnotation(MockEndpoints.class).value();
CamelSpringTestHelper.doToSpringCamelContexts(context, new
DoToSpringCamelContextsStrategy() {
public void execute(String contextName, SpringCamelContext
camelContext)
throws Exception {
-
- logger.info("Enabling auto mocking and skipping of
endpoints matching pattern [{}] on "
- + "CamelContext with name [{}].", mockEndpoints,
contextName);
- camelContext.addRegisterEndpointCallback(
- new
InterceptSendToMockEndpointStrategy(mockEndpoints, true));
+ logger.info("Enabling auto mocking and skipping of
endpoints matching pattern [{}] on CamelContext with name [{}].",
mockEndpoints, contextName);
+ camelContext.addRegisterEndpointCallback(new
InterceptSendToMockEndpointStrategy(mockEndpoints, true));
}
});
}
@@ -338,16 +286,13 @@ public class CamelSpringDelegatingTestCo
protected void handleCamelContextStartup(ConfigurableApplicationContext
context, Class<?> testClass) throws Exception {
boolean skip =
"true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"));
if (skip) {
- logger.info("Skipping starting CamelContext(s) as system property
"
- + "skipStartingCamelContext is set to be true.");
+ logger.info("Skipping starting CamelContext(s) as system property
skipStartingCamelContext is set to be true.");
} else if (testClass.isAnnotationPresent(UseAdviceWith.class)) {
if (testClass.getAnnotation(UseAdviceWith.class).value()) {
- logger.info("Skipping starting CamelContext(s) as
UseAdviceWith annotation was found "
- + "and isUseAdviceWith is set to true.");
+ logger.info("Skipping starting CamelContext(s) as
UseAdviceWith annotation was found and isUseAdviceWith is set to true.");
skip = true;
} else {
- logger.info("Starting CamelContext(s) as UseAdviceWith
annotation was found, but "
- + "isUseAdviceWith is set to false.");
+ logger.info("Starting CamelContext(s) as UseAdviceWith
annotation was found, but isUseAdviceWith is set to false.");
skip = false;
}
}
Modified:
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java?rev=1404020&r1=1404019&r2=1404020&view=diff
==============================================================================
---
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
(original)
+++
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
Wed Oct 31 08:21:32 2012
@@ -48,6 +48,8 @@ import org.springframework.test.context.
import org.springframework.test.context.support.GenericXmlContextLoader;
import org.springframework.util.StringUtils;
+import static org.apache.camel.test.spring.CamelSpringTestHelper.getAllMethods;
+
/**
* Replacement for the default {@link GenericXmlContextLoader} that provides
hooks for
* processing some class level Camel related test annotations.
@@ -63,7 +65,7 @@ public class CamelSpringTestContextLoade
* pre-post hooks for customization seen in {@link
AbstractGenericContextLoader} because
* they probably are unnecessary for 90+% of users.
* <p/>
- * For some functionality, we cannot use {@link TestExecutionListener}
because we need
+ * For some functionality, we cannot use {@link
org.springframework.test.context.TestExecutionListener} because we need
* to both produce the desired outcome during application context
loading, and also cleanup
* after ourselves even if the test class never executes. Thus the
listeners, which
* only run if the application context is successfully initialized are
insufficient to
@@ -71,12 +73,10 @@ public class CamelSpringTestContextLoade
*/
@Override
public ApplicationContext loadContext(MergedContextConfiguration
mergedConfig) throws Exception {
-
Class<?> testClass = getTestClass();
if (LOG.isDebugEnabled()) {
- LOG.debug(String.format("Loading ApplicationContext for merged
context configuration [%s].",
- mergedConfig));
+ LOG.debug("Loading ApplicationContext for merged context
configuration [{}].", mergedConfig);
}
try {
@@ -96,7 +96,7 @@ public class CamelSpringTestContextLoade
* pre-post hooks for customization seen in {@link
AbstractGenericContextLoader} because
* they probably are unnecessary for 90+% of users.
* <p/>
- * For some functionality, we cannot use {@link TestExecutionListener}
because we need
+ * For some functionality, we cannot use {@link
org.springframework.test.context.TestExecutionListener} because we need
* to both produce the desired outcome during application context
loading, and also cleanup
* after ourselves even if the test class never executes. Thus the
listeners, which
* only run if the application context is successfully initialized are
insufficient to
@@ -108,8 +108,7 @@ public class CamelSpringTestContextLoade
Class<?> testClass = getTestClass();
if (LOG.isDebugEnabled()) {
- LOG.debug("Loading ApplicationContext for locations ["
- + StringUtils.arrayToCommaDelimitedString(locations) +
"].");
+ LOG.debug("Loading ApplicationContext for locations [" +
StringUtils.arrayToCommaDelimitedString(locations) + "].");
}
try {
@@ -134,13 +133,11 @@ public class CamelSpringTestContextLoade
*
* @param context the partially configured context. The context should
have the bean definitions loaded, but nothing else.
* @param testClass the test class being executed
- *
* @return the initialized (refreshed) Spring application context
*
* @throws Exception if there is an error during
initialization/customization
*/
- protected ApplicationContext loadContext(GenericApplicationContext
context, Class<?> testClass)
- throws Exception {
+ protected ApplicationContext loadContext(GenericApplicationContext
context, Class<?> testClass) throws Exception {
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
@@ -195,48 +192,25 @@ public class CamelSpringTestContextLoade
}
/**
- * Returns all methods defined in {@code clazz} and its
superclasses/interfaces.
- */
- protected Collection<Method> getAllMethods(Class<?> clazz) {
-
- Set<Method> methods = new HashSet<Method>();
- Class<?> currentClass = clazz;
-
- while (currentClass != null) {
- methods.addAll(Arrays.asList(clazz.getMethods()));
- currentClass = currentClass.getSuperclass();
- }
-
- return methods;
- }
-
- /**
* Creates and starts the Spring context while optionally starting any
loaded Camel contexts.
*
* @param testClass the test class that is being executed
- *
* @return the loaded Spring context
*/
protected GenericApplicationContext createContext(Class<?> testClass) {
-
GenericApplicationContext routeExcludingContext = null;
if (testClass.isAnnotationPresent(ExcludeRoutes.class)) {
- Class<?>[] excludedClasses = testClass.getAnnotation(
- ExcludeRoutes.class).value();
+ Class<?>[] excludedClasses =
testClass.getAnnotation(ExcludeRoutes.class).value();
if (excludedClasses.length > 0) {
-
if (LOG.isDebugEnabled()) {
LOG.debug("Setting up package scanning excluded classes as
ExcludeRoutes "
- + "annotation was found. Excluding ["
- +
StringUtils.arrayToCommaDelimitedString(excludedClasses) + "].");
+ + "annotation was found. Excluding [" +
StringUtils.arrayToCommaDelimitedString(excludedClasses) + "].");
}
routeExcludingContext = new GenericApplicationContext();
- routeExcludingContext.registerBeanDefinition(
- "excludingResolver", new RootBeanDefinition(
- ExcludingPackageScanClassResolver.class));
+
routeExcludingContext.registerBeanDefinition("excludingResolver", new
RootBeanDefinition(ExcludingPackageScanClassResolver.class));
routeExcludingContext.refresh();
ExcludingPackageScanClassResolver excludingResolver =
routeExcludingContext.getBean("excludingResolver",
ExcludingPackageScanClassResolver.class);
@@ -251,7 +225,7 @@ public class CamelSpringTestContextLoade
}
GenericApplicationContext context;
-
+
if (routeExcludingContext != null) {
context = new GenericApplicationContext(routeExcludingContext);
} else {
@@ -268,26 +242,18 @@ public class CamelSpringTestContextLoade
* @param testClass the test class being executed
*/
protected void handleDisableJmx(GenericApplicationContext context,
Class<?> testClass) {
- CamelSpringTestHelper.setOriginalJmxDisabledValue(
- System.getProperty(JmxSystemPropertyKeys.DISABLED));
+
CamelSpringTestHelper.setOriginalJmxDisabledValue(System.getProperty(JmxSystemPropertyKeys.DISABLED));
if (testClass.isAnnotationPresent(DisableJmx.class)) {
if (testClass.getAnnotation(DisableJmx.class).value()) {
- LOG.info("Disabling Camel JMX globally as DisableJmx
annotation was found "
- + "and disableJmx is set to true.");
-
+ LOG.info("Disabling Camel JMX globally as DisableJmx
annotation was found and disableJmx is set to true.");
System.setProperty(JmxSystemPropertyKeys.DISABLED, "true");
-
} else {
- LOG.info("Enabling Camel JMX as DisableJmx annotation was
found "
- + "and disableJmx is set to false.");
-
+ LOG.info("Enabling Camel JMX as DisableJmx annotation was
found and disableJmx is set to false.");
System.clearProperty(JmxSystemPropertyKeys.DISABLED);
}
} else {
- LOG.info("Disabling Camel JMX globally for tests by default. Use
the DisableJMX annotation to "
- + "override the default setting.");
-
+ LOG.info("Disabling Camel JMX globally for tests by default. Use
the DisableJMX annotation to override the default setting.");
System.setProperty(JmxSystemPropertyKeys.DISABLED, "true");
}
}
@@ -298,18 +264,14 @@ public class CamelSpringTestContextLoade
*
* @param context the initialized Spring context containing the Camel
context(s) to insert breakpoints into
* @param testClass the test class being processed
- * @param log the logger to use
- * @param statics if static methods or instance methods should be processed
*
* @throws Exception if there is an error processing the class
*/
protected void handleProvidesBreakpoint(GenericApplicationContext context,
Class<?> testClass) throws Exception {
-
Collection<Method> methods = getAllMethods(testClass);
final List<Breakpoint> breakpoints = new LinkedList<Breakpoint>();
for (Method method : methods) {
-
if (AnnotationUtils.findAnnotation(method,
ProvidesBreakpoint.class) != null) {
Class<?>[] argTypes = method.getParameterTypes();
if (argTypes.length != 0) {
@@ -327,7 +289,7 @@ public class CamelSpringTestContextLoade
}
try {
- breakpoints.add((Breakpoint) method.invoke(null, new
Object[] {}));
+ breakpoints.add((Breakpoint) method.invoke(null));
} catch (Exception e) {
throw new RuntimeException("Method [" + method.getName()
+ "] threw exception during evaluation.", e);
@@ -336,13 +298,11 @@ public class CamelSpringTestContextLoade
}
if (breakpoints.size() != 0) {
-
CamelSpringTestHelper.doToSpringCamelContexts(context, new
DoToSpringCamelContextsStrategy() {
@Override
public void execute(String contextName, SpringCamelContext
camelContext)
throws Exception {
-
Debugger debugger = camelContext.getDebugger();
if (debugger == null) {
debugger = new DefaultDebugger();
@@ -350,10 +310,7 @@ public class CamelSpringTestContextLoade
}
for (Breakpoint breakpoint : breakpoints) {
- LOG.info(
- "Adding Breakpoint [{}] to CamelContext with
name [{}].",
- breakpoint, contextName);
-
+ LOG.info("Adding Breakpoint [{}] to CamelContext with
name [{}].", breakpoint, contextName);
debugger.addBreakpoint(breakpoint);
}
}
@@ -369,7 +326,6 @@ public class CamelSpringTestContextLoade
* @param testClass the test class being executed
*/
protected void handleShutdownTimeout(GenericApplicationContext context,
Class<?> testClass) throws Exception {
-
final int shutdownTimeout;
final TimeUnit shutdownTimeUnit;
if (testClass.isAnnotationPresent(ShutdownTimeout.class)) {
@@ -385,10 +341,7 @@ public class CamelSpringTestContextLoade
@Override
public void execute(String contextName, SpringCamelContext
camelContext)
throws Exception {
-
- LOG.info(
- "Setting shutdown timeout to [{} {}] on CamelContext
with name [{}].",
- new Object[] {shutdownTimeout, shutdownTimeUnit,
contextName});
+ LOG.info("Setting shutdown timeout to [{} {}] on CamelContext
with name [{}].", shutdownTimeout, shutdownTimeUnit, contextName);
camelContext.getShutdownStrategy().setTimeout(shutdownTimeout);
camelContext.getShutdownStrategy().setTimeUnit(shutdownTimeUnit);
}
@@ -403,19 +356,14 @@ public class CamelSpringTestContextLoade
*/
protected void handleMockEndpoints(GenericApplicationContext context,
Class<?> testClass) throws Exception {
if (testClass.isAnnotationPresent(MockEndpoints.class)) {
-
- final String mockEndpoints = testClass.getAnnotation(
- MockEndpoints.class).value();
+ final String mockEndpoints =
testClass.getAnnotation(MockEndpoints.class).value();
CamelSpringTestHelper.doToSpringCamelContexts(context, new
DoToSpringCamelContextsStrategy() {
@Override
public void execute(String contextName, SpringCamelContext
camelContext)
throws Exception {
-
- LOG.info("Enabling auto mocking of endpoints matching
pattern [{}] on "
- + "CamelContext with name [{}].", mockEndpoints,
contextName);
- camelContext.addRegisterEndpointCallback(
- new
InterceptSendToMockEndpointStrategy(mockEndpoints));
+ LOG.info("Enabling auto mocking of endpoints matching
pattern [{}] on CamelContext with name [{}].", mockEndpoints, contextName);
+ camelContext.addRegisterEndpointCallback(new
InterceptSendToMockEndpointStrategy(mockEndpoints));
}
});
}
@@ -430,19 +378,14 @@ public class CamelSpringTestContextLoade
*/
protected void handleMockEndpointsAndSkip(GenericApplicationContext
context, Class<?> testClass) throws Exception {
if (testClass.isAnnotationPresent(MockEndpointsAndSkip.class)) {
-
- final String mockEndpoints = testClass.getAnnotation(
- MockEndpointsAndSkip.class).value();
+ final String mockEndpoints =
testClass.getAnnotation(MockEndpointsAndSkip.class).value();
CamelSpringTestHelper.doToSpringCamelContexts(context, new
DoToSpringCamelContextsStrategy() {
@Override
public void execute(String contextName, SpringCamelContext
camelContext)
throws Exception {
-
- LOG.info("Enabling auto mocking and skipping of endpoints
matching pattern [{}] on "
- + "CamelContext with name [{}].", mockEndpoints,
contextName);
- camelContext.addRegisterEndpointCallback(
- new
InterceptSendToMockEndpointStrategy(mockEndpoints, true));
+ LOG.info("Enabling auto mocking and skipping of endpoints
matching pattern [{}] on CamelContext with name [{}].", mockEndpoints,
contextName);
+ camelContext.addRegisterEndpointCallback(new
InterceptSendToMockEndpointStrategy(mockEndpoints, true));
}
});
}
@@ -464,9 +407,7 @@ public class CamelSpringTestContextLoade
@Override
public void execute(String contextName, SpringCamelContext
camelContext)
throws Exception {
-
- LOG.info("Enabling lazy loading of type converters on "
- + "CamelContext with name [{}].", contextName);
+ LOG.info("Enabling lazy loading of type converters on
CamelContext with name [{}].", contextName);
camelContext.setLazyLoadTypeConverters(lazy);
}
});
@@ -482,16 +423,13 @@ public class CamelSpringTestContextLoade
protected void handleCamelContextStartup(GenericApplicationContext
context, Class<?> testClass) throws Exception {
boolean skip =
"true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"));
if (skip) {
- LOG.info("Skipping starting CamelContext(s) as system property "
- + "skipStartingCamelContext is set to be true.");
+ LOG.info("Skipping starting CamelContext(s) as system property
skipStartingCamelContext is set to be true.");
} else if (testClass.isAnnotationPresent(UseAdviceWith.class)) {
if (testClass.getAnnotation(UseAdviceWith.class).value()) {
- LOG.info("Skipping starting CamelContext(s) as UseAdviceWith
annotation was found "
- + "and isUseAdviceWith is set to true.");
+ LOG.info("Skipping starting CamelContext(s) as UseAdviceWith
annotation was found and isUseAdviceWith is set to true.");
skip = true;
} else {
- LOG.info("Starting CamelContext(s) as UseAdviceWith annotation
was found, but "
- + "isUseAdviceWith is set to false.");
+ LOG.info("Starting CamelContext(s) as UseAdviceWith annotation
was found, but isUseAdviceWith is set to false.");
skip = false;
}
}
Modified:
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoaderTestExecutionListener.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoaderTestExecutionListener.java?rev=1404020&r1=1404019&r2=1404020&view=diff
==============================================================================
---
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoaderTestExecutionListener.java
(original)
+++
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoaderTestExecutionListener.java
Wed Oct 31 08:21:32 2012
@@ -27,8 +27,7 @@ import org.springframework.test.context.
* Implemented as a listener as the state can be set on a {@code ThreadLocal}
and we are pretty sure
* that the same thread will be used to initialize the Spring context.
*/
-public class CamelSpringTestContextLoaderTestExecutionListener
- extends AbstractTestExecutionListener {
+public class CamelSpringTestContextLoaderTestExecutionListener extends
AbstractTestExecutionListener {
@Override
public void prepareTestInstance(TestContext testContext) throws Exception {
Modified:
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestHelper.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestHelper.java?rev=1404020&r1=1404019&r2=1404020&view=diff
==============================================================================
---
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestHelper.java
(original)
+++
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestHelper.java
Wed Oct 31 08:21:32 2012
@@ -19,7 +19,7 @@ package org.apache.camel.test.spring;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
@@ -40,7 +40,6 @@ import org.springframework.context.Appli
public final class CamelSpringTestHelper {
private static ThreadLocal<String> originalJmxDisabledValue = new
ThreadLocal<String>();
-
private static ThreadLocal<Class<?>> testClazz = new
ThreadLocal<Class<?>>();
private CamelSpringTestHelper() {
@@ -66,8 +65,7 @@ public final class CamelSpringTestHelper
* Returns all methods defined in {@code clazz} and its
superclasses/interfaces.
*/
public static Collection<Method> getAllMethods(Class<?> clazz) {
-
- Set<Method> methods = new HashSet<Method>();
+ Set<Method> methods = new LinkedHashSet<Method>();
Class<?> currentClass = clazz;
while (currentClass != null) {
@@ -87,10 +85,8 @@ public final class CamelSpringTestHelper
*
* @throws Exception if there is an error executing any of the strategies
*/
- public static void doToSpringCamelContexts(ApplicationContext context,
- DoToSpringCamelContextsStrategy strategy) throws Exception {
- Map<String, SpringCamelContext> contexts =
- context.getBeansOfType(SpringCamelContext.class);
+ public static void doToSpringCamelContexts(ApplicationContext context,
DoToSpringCamelContextsStrategy strategy) throws Exception {
+ Map<String, SpringCamelContext> contexts =
context.getBeansOfType(SpringCamelContext.class);
for (Entry<String, SpringCamelContext> entry : contexts.entrySet()) {
strategy.execute(entry.getKey(), entry.getValue());
Modified:
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/DisableJmxTestExecutionListener.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/DisableJmxTestExecutionListener.java?rev=1404020&r1=1404019&r2=1404020&view=diff
==============================================================================
---
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/DisableJmxTestExecutionListener.java
(original)
+++
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/DisableJmxTestExecutionListener.java
Wed Oct 31 08:21:32 2012
@@ -22,19 +22,18 @@ import org.springframework.test.context.
/**
* Provides reset to pre-test state behavior for global enable/disable of JMX
- * support in Camel through the use of {@link DisableJmx}. Tries to ensure
that
- * the pre-test value is restored.
+ * support in Camel through the use of {@link DisableJmx}.
+ * Tries to ensure that the pre-test value is restored.
*/
-public class DisableJmxTestExecutionListener extends
- AbstractTestExecutionListener {
+public class DisableJmxTestExecutionListener extends
AbstractTestExecutionListener {
@Override
public void afterTestClass(TestContext testContext) throws Exception {
if (CamelSpringTestHelper.getOriginalJmxDisabled() == null) {
System.clearProperty(JmxSystemPropertyKeys.DISABLED);
} else {
- System.setProperty(JmxSystemPropertyKeys.DISABLED,
- CamelSpringTestHelper.getOriginalJmxDisabled());
+ System.setProperty(JmxSystemPropertyKeys.DISABLED,
CamelSpringTestHelper.getOriginalJmxDisabled());
}
}
+
}
Modified:
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/ExcludeRoutes.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/ExcludeRoutes.java?rev=1404020&r1=1404019&r2=1404020&view=diff
==============================================================================
---
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/ExcludeRoutes.java
(original)
+++
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/ExcludeRoutes.java
Wed Oct 31 08:21:32 2012
@@ -34,8 +34,9 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface ExcludeRoutes {
+
/**
- * The classes to exlcude from resolution when using package scanning.
+ * The classes to exclude from resolution when using package scanning.
*/
Class<?>[] value() default {};
}
Modified:
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/ShutdownTimeout.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/ShutdownTimeout.java?rev=1404020&r1=1404019&r2=1404020&view=diff
==============================================================================
---
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/ShutdownTimeout.java
(original)
+++
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/ShutdownTimeout.java
Wed Oct 31 08:21:32 2012
@@ -35,8 +35,10 @@ import java.util.concurrent.TimeUnit;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface ShutdownTimeout {
+
/**
- * The shutdown timeout to set on the {@code CamelContext}(s). Defaults
to {@code 10} seconds.
+ * The shutdown timeout to set on the {@code CamelContext}(s).
+ * Defaults to {@code 10} seconds.
*/
int value() default 10;
Modified:
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/StopWatchTestExecutionListener.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/StopWatchTestExecutionListener.java?rev=1404020&r1=1404019&r2=1404020&view=diff
==============================================================================
---
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/StopWatchTestExecutionListener.java
(original)
+++
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/StopWatchTestExecutionListener.java
Wed Oct 31 08:21:32 2012
@@ -24,16 +24,14 @@ import org.springframework.test.context.
import org.springframework.test.context.support.AbstractTestExecutionListener;
/**
- * An execution listener that simulates the timing output built in to {@link
CamelTestSupport}.
+ * An execution listener that simulates the timing output built in to {@link
org.apache.camel.test.junit4.CamelTestSupport}.
*/
-public class StopWatchTestExecutionListener extends
- AbstractTestExecutionListener {
+public class StopWatchTestExecutionListener extends
AbstractTestExecutionListener {
protected static ThreadLocal<StopWatch> threadStopWatch = new
ThreadLocal<StopWatch>();
/**
- * Exists primarily for testing purposes, but allows for access to the
underlying stop watch instance
- * for a test.
+ * Exists primarily for testing purposes, but allows for access to the
underlying stop watch instance for a test.
*/
public static StopWatch getStopWatch() {
return threadStopWatch.get();
@@ -58,4 +56,5 @@ public class StopWatchTestExecutionListe
log.info("Took: " + TimeUtils.printDuration(time) + " (" + time + "
millis)");
log.info("********************************************************************************");
}
+
}
Modified:
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/UseAdviceWith.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/UseAdviceWith.java?rev=1404020&r1=1404019&r2=1404020&view=diff
==============================================================================
---
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/UseAdviceWith.java
(original)
+++
camel/trunk/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/UseAdviceWith.java
Wed Oct 31 08:21:32 2012
@@ -42,7 +42,8 @@ public @interface UseAdviceWith {
/**
* Whether the test annotated with this annotation should be treated as if
* {@code adviceWith()} is in use in the test and the Camel contexts
should not be started
- * automatically. Defaults to {@code true}.
+ * automatically.
+ * Defaults to {@code true}.
*/
boolean value() default true;
}
Modified:
camel/trunk/components/camel-test-spring/src/test/java/org/apache/camel/test/junit4/CamelSpringJUnit4ClassRunnerUseAdviceWithTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-test-spring/src/test/java/org/apache/camel/test/junit4/CamelSpringJUnit4ClassRunnerUseAdviceWithTest.java?rev=1404020&r1=1404019&r2=1404020&view=diff
==============================================================================
---
camel/trunk/components/camel-test-spring/src/test/java/org/apache/camel/test/junit4/CamelSpringJUnit4ClassRunnerUseAdviceWithTest.java
(original)
+++
camel/trunk/components/camel-test-spring/src/test/java/org/apache/camel/test/junit4/CamelSpringJUnit4ClassRunnerUseAdviceWithTest.java
Wed Oct 31 08:21:32 2012
@@ -20,9 +20,9 @@ import org.apache.camel.ServiceStatus;
import org.apache.camel.test.spring.StopWatchTestExecutionListener;
import org.apache.camel.test.spring.UseAdviceWith;
import org.apache.camel.util.StopWatch;
-
import org.junit.Before;
import org.junit.Test;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -37,8 +37,9 @@ public class CamelSpringJUnit4ClassRunne
assertEquals(ServiceStatus.Stopped, camelContext2.getStatus());
camelContext.start();
camelContext2.start();
-
- Thread.sleep(4000);
+
+ // just sleep a little to simulate testing take a bit time
+ Thread.sleep(1000);
}
@Test
@@ -46,6 +47,8 @@ public class CamelSpringJUnit4ClassRunne
StopWatch stopWatch = StopWatchTestExecutionListener.getStopWatch();
assertNotNull(stopWatch);
- assertTrue(stopWatch.taken() < 4100);
+ long taken = stopWatch.taken();
+ assertTrue(taken + " > 0, but was: " + taken, taken > 0);
+ assertTrue(taken + " < 3000, but was: " + taken, taken < 3000);
}
}