[ 
https://issues.apache.org/jira/browse/CAMEL-7380?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14026523#comment-14026523
 ] 

Chris Watts edited comment on CAMEL-7380 at 6/10/14 2:49 PM:
-------------------------------------------------------------

Hi Willem,
Yes, that is essentially the point of this JIRA.
By making the necessary changes to support ContextHierarchy you can cache the 
parent context(s), so only recreate the child context (presumably containing 
the camel instance) for each test (depending on the DirtiesContext annotation)

Essentially the impl would need to be:
{code:java}
//change method signature
protected GenericApplicationContext createContext(Class<?> testClass, 
MergedContextConfiguration mergedConfig) {
        GenericApplicationContext parentContext = null;

        if (mergedConfig != null) {
                //new method
                parentContext = getParentContext(mergedConfig);
        }
        
        if (testClass.isAnnotationPresent(ExcludeRoutes.class)) {
                //.....
                if (parentContext != null) {
                        parentContext = new 
GenericApplicationContext(parentContext);
                } else {
                        parentContext = new GenericApplicationContext();
                }
                parentContext.registerBeanDefinition("excludingResolver", new 
RootBeanDefinition(ExcludingPackageScanClassResolver.class));
                parentContext.refresh();
                //.....
        } else {
                //.....
        }
}

GenericApplicationContext context;

if (parentContext != null) {
        context = new GenericApplicationContext(parentContext);
} else {
        context = new GenericApplicationContext();
}
//.....
{code}


was (Author: wattsc3):
Hi Willem,
That essentially the point of this JIRA.
By making the necessary changes to support ContextHierarchy you can cache the 
parent context(s) yet so only recreate the child context (presumably containing 
the camel instance).

Essentially the impl would need to be:
{code:java}
//change method signature
protected GenericApplicationContext createContext(Class<?> testClass, 
MergedContextConfiguration mergedConfig) {
        GenericApplicationContext parentContext = null;

        if (mergedConfig != null) {
                //new method
                parentContext = getParentContext(mergedConfig);
        }
        
        if (testClass.isAnnotationPresent(ExcludeRoutes.class)) {
                //.....
                if (parentContext != null) {
                        parentContext = new 
GenericApplicationContext(parentContext);
                } else {
                        parentContext = new GenericApplicationContext();
                }
                parentContext.registerBeanDefinition("excludingResolver", new 
RootBeanDefinition(ExcludingPackageScanClassResolver.class));
                parentContext.refresh();
                //.....
        } else {
                //.....
        }
}

GenericApplicationContext context;

if (parentContext != null) {
        context = new GenericApplicationContext(parentContext);
} else {
        context = new GenericApplicationContext();
}
//.....
{code}

> Add test support for ContextHierarchy
> -------------------------------------
>
>                 Key: CAMEL-7380
>                 URL: https://issues.apache.org/jira/browse/CAMEL-7380
>             Project: Camel
>          Issue Type: New Feature
>          Components: camel-test
>            Reporter: Chris Watts
>
> In Spring 3.2 they've added ContextHierarchy, which allows loading nested of 
> spring contexts. See
> http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/testing.html
> This would improve the loading time of tests where DirtiesContext is required 
> to cause the camel context to be reloaded by having everything except the 
> camel context defined in the parent context and the child context would have 
> the camel definition. By only dirtying the child context, the larger parent 
> context can remain.
> CamelSpringTestContextLoader would need to be modified to call (via 
> reflection) MergedContextConfiguration.getParentApplicationContext()



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to