Search in sources :

Example 1 with CacheAwareContextLoaderDelegate

use of org.springframework.test.context.CacheAwareContextLoaderDelegate in project spring-boot by spring-projects.

the class SpringBootTestContextBootstrapperTests method buildTestContext.

@SuppressWarnings("rawtypes")
private void buildTestContext(Class<?> testClass) {
    SpringBootTestContextBootstrapper bootstrapper = new SpringBootTestContextBootstrapper();
    BootstrapContext bootstrapContext = mock(BootstrapContext.class);
    bootstrapper.setBootstrapContext(bootstrapContext);
    given((Class) bootstrapContext.getTestClass()).willReturn(testClass);
    CacheAwareContextLoaderDelegate contextLoaderDelegate = mock(CacheAwareContextLoaderDelegate.class);
    given(bootstrapContext.getCacheAwareContextLoaderDelegate()).willReturn(contextLoaderDelegate);
    bootstrapper.buildTestContext();
}
Also used : CacheAwareContextLoaderDelegate(org.springframework.test.context.CacheAwareContextLoaderDelegate) BootstrapContext(org.springframework.test.context.BootstrapContext) SpringBootTestContextBootstrapper(org.springframework.boot.test.context.SpringBootTestContextBootstrapper)

Example 2 with CacheAwareContextLoaderDelegate

use of org.springframework.test.context.CacheAwareContextLoaderDelegate in project spring-framework by spring-projects.

the class AbstractTestContextBootstrapper method buildMergedContextConfiguration.

/**
	 * {@inheritDoc}
	 */
@SuppressWarnings("unchecked")
@Override
public final MergedContextConfiguration buildMergedContextConfiguration() {
    Class<?> testClass = getBootstrapContext().getTestClass();
    CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = getCacheAwareContextLoaderDelegate();
    if (MetaAnnotationUtils.findAnnotationDescriptorForTypes(testClass, ContextConfiguration.class, ContextHierarchy.class) == null) {
        return buildDefaultMergedContextConfiguration(testClass, cacheAwareContextLoaderDelegate);
    }
    if (AnnotationUtils.findAnnotation(testClass, ContextHierarchy.class) != null) {
        Map<String, List<ContextConfigurationAttributes>> hierarchyMap = ContextLoaderUtils.buildContextHierarchyMap(testClass);
        MergedContextConfiguration parentConfig = null;
        MergedContextConfiguration mergedConfig = null;
        for (List<ContextConfigurationAttributes> list : hierarchyMap.values()) {
            List<ContextConfigurationAttributes> reversedList = new ArrayList<>(list);
            Collections.reverse(reversedList);
            // Don't use the supplied testClass; instead ensure that we are
            // building the MCC for the actual test class that declared the
            // configuration for the current level in the context hierarchy.
            Assert.notEmpty(reversedList, "ContextConfigurationAttributes list must not be empty");
            Class<?> declaringClass = reversedList.get(0).getDeclaringClass();
            mergedConfig = buildMergedContextConfiguration(declaringClass, reversedList, parentConfig, cacheAwareContextLoaderDelegate, true);
            parentConfig = mergedConfig;
        }
        // Return the last level in the context hierarchy
        return mergedConfig;
    } else {
        return buildMergedContextConfiguration(testClass, ContextLoaderUtils.resolveContextConfigurationAttributes(testClass), null, cacheAwareContextLoaderDelegate, true);
    }
}
Also used : MergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration) ContextConfigurationAttributes(org.springframework.test.context.ContextConfigurationAttributes) CacheAwareContextLoaderDelegate(org.springframework.test.context.CacheAwareContextLoaderDelegate) ContextHierarchy(org.springframework.test.context.ContextHierarchy) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration)

Example 3 with CacheAwareContextLoaderDelegate

use of org.springframework.test.context.CacheAwareContextLoaderDelegate in project spring-framework by spring-projects.

the class AbstractContextConfigurationUtilsTests method buildMergedContextConfiguration.

MergedContextConfiguration buildMergedContextConfiguration(Class<?> testClass) {
    CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = Mockito.mock(CacheAwareContextLoaderDelegate.class);
    BootstrapContext bootstrapContext = BootstrapTestUtils.buildBootstrapContext(testClass, cacheAwareContextLoaderDelegate);
    TestContextBootstrapper bootstrapper = BootstrapTestUtils.resolveTestContextBootstrapper(bootstrapContext);
    return bootstrapper.buildMergedContextConfiguration();
}
Also used : CacheAwareContextLoaderDelegate(org.springframework.test.context.CacheAwareContextLoaderDelegate) BootstrapContext(org.springframework.test.context.BootstrapContext) TestContextBootstrapper(org.springframework.test.context.TestContextBootstrapper)

Aggregations

CacheAwareContextLoaderDelegate (org.springframework.test.context.CacheAwareContextLoaderDelegate)3 BootstrapContext (org.springframework.test.context.BootstrapContext)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SpringBootTestContextBootstrapper (org.springframework.boot.test.context.SpringBootTestContextBootstrapper)1 ContextConfiguration (org.springframework.test.context.ContextConfiguration)1 ContextConfigurationAttributes (org.springframework.test.context.ContextConfigurationAttributes)1 ContextHierarchy (org.springframework.test.context.ContextHierarchy)1 MergedContextConfiguration (org.springframework.test.context.MergedContextConfiguration)1 TestContextBootstrapper (org.springframework.test.context.TestContextBootstrapper)1