*
* @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();
if (excludedClasses.length > 0) {
if (LOG.isDebugEnabled()) {
LOG.debug("Setting up package scanning excluded classes as ExcludeRoutes "
+ "annotation was found. Excluding ["
+ StringUtils.arrayToCommaDelimitedString(excludedClasses) + "].");
}
routeExcludingContext = new GenericApplicationContext();
routeExcludingContext.registerBeanDefinition(
"excludingResolver", new RootBeanDefinition(
ExcludingPackageScanClassResolver.class));
routeExcludingContext.refresh();
ExcludingPackageScanClassResolver excludingResolver = routeExcludingContext.getBean("excludingResolver", ExcludingPackageScanClassResolver.class);
List<Class<?>> excluded = CastUtils.cast(Arrays.asList(excludedClasses));
excludingResolver.setExcludedClasses(new HashSet<Class<?>>(excluded));
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Not enabling package scanning excluded classes as ExcludeRoutes "
+ "annotation was found but no classes were excluded.");
}
}
}
GenericApplicationContext context;
if (routeExcludingContext != null) {
context = new GenericApplicationContext(routeExcludingContext);
} else {
context = new GenericApplicationContext();
}
return context;
}