use of org.apache.camel.test.ExcludingPackageScanClassResolver in project camel by apache.
the class CamelSpringTestSupport method getRouteExcludingApplicationContext.
/**
* Create a parent context that initializes a
* {@link org.apache.camel.spi.PackageScanClassResolver} to exclude a set of given classes from
* being resolved. Typically this is used at test time to exclude certain routes,
* which might otherwise be just noisy, from being discovered and initialized.
* <p/>
* To use this filtering mechanism it is necessary to provide the
* {@link ApplicationContext} returned from here as the parent context to
* your test context e.g.
*
* <pre>
* protected AbstractXmlApplicationContext createApplicationContext() {
* return new ClassPathXmlApplicationContext(new String[] {"test-context.xml"}, getRouteExcludingApplicationContext());
* }
* </pre>
*
* This will, in turn, call the template methods <code>excludedRoutes</code>
* and <code>excludedRoute</code> to determine the classes to be excluded from scanning.
*
* @return ApplicationContext a parent {@link ApplicationContext} configured
* to exclude certain classes from package scanning
*/
protected ApplicationContext getRouteExcludingApplicationContext() {
GenericApplicationContext routeExcludingContext = new GenericApplicationContext();
routeExcludingContext.registerBeanDefinition("excludingResolver", new RootBeanDefinition(ExcludingPackageScanClassResolver.class));
routeExcludingContext.refresh();
ExcludingPackageScanClassResolver excludingResolver = routeExcludingContext.getBean("excludingResolver", ExcludingPackageScanClassResolver.class);
List<Class<?>> excluded = Arrays.asList(excludeRoutes());
excludingResolver.setExcludedClasses(new HashSet<Class<?>>(excluded));
return routeExcludingContext;
}
use of org.apache.camel.test.ExcludingPackageScanClassResolver in project camel by apache.
the class CamelSpringTestContextLoader method createContext.
/**
* 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, MergedContextConfiguration mergedConfig) {
ApplicationContext parentContext = null;
GenericApplicationContext routeExcludingContext = null;
if (mergedConfig != null) {
parentContext = mergedConfig.getParentApplicationContext();
}
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) + "].");
}
if (parentContext == null) {
routeExcludingContext = new GenericApplicationContext();
} else {
routeExcludingContext = new GenericApplicationContext(parentContext);
}
routeExcludingContext.registerBeanDefinition("excludingResolver", new RootBeanDefinition(ExcludingPackageScanClassResolver.class));
routeExcludingContext.refresh();
ExcludingPackageScanClassResolver excludingResolver = routeExcludingContext.getBean("excludingResolver", ExcludingPackageScanClassResolver.class);
List<Class<?>> excluded = 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 {
if (parentContext != null) {
context = new GenericApplicationContext(parentContext);
} else {
context = new GenericApplicationContext();
}
}
return context;
}
use of org.apache.camel.test.ExcludingPackageScanClassResolver in project camel by apache.
the class CamelSpringTestSupport method getRouteExcludingApplicationContext.
/**
* Create a parent context that initializes a
* {@link org.apache.camel.spi.PackageScanClassResolver} to exclude a set of given classes from
* being resolved. Typically this is used at test time to exclude certain routes,
* which might otherwise be just noisy, from being discovered and initialized.
* <p/>
* To use this filtering mechanism it is necessary to provide the
* {@link org.springframework.context.ApplicationContext} returned from here as the parent context to
* your test context e.g.
*
* <pre>
* protected AbstractXmlApplicationContext createApplicationContext() {
* return new ClassPathXmlApplicationContext(new String[] {"test-context.xml"}, getRouteExcludingApplicationContext());
* }
* </pre>
*
* This will, in turn, call the template methods <code>excludedRoutes</code>
* and <code>excludedRoute</code> to determine the classes to be excluded from scanning.
*
* @return ApplicationContext a parent {@link org.springframework.context.ApplicationContext} configured
* to exclude certain classes from package scanning
*/
protected ApplicationContext getRouteExcludingApplicationContext() {
GenericApplicationContext routeExcludingContext = new GenericApplicationContext();
routeExcludingContext.registerBeanDefinition("excludingResolver", new RootBeanDefinition(ExcludingPackageScanClassResolver.class));
routeExcludingContext.refresh();
ExcludingPackageScanClassResolver excludingResolver = routeExcludingContext.getBean("excludingResolver", ExcludingPackageScanClassResolver.class);
List<Class<?>> excluded = Arrays.asList(excludeRoutes());
excludingResolver.setExcludedClasses(new HashSet<Class<?>>(excluded));
return routeExcludingContext;
}
Aggregations