Search in sources :

Example 1 with ContextCustomizer

use of cn.taketoday.test.context.ContextCustomizer in project today-infrastructure by TAKETODAY.

the class ApplicationContextLoader method getInitializers.

/**
 * Return the {@link ApplicationContextInitializer initializers} that will be applied
 * to the context. By default this method will adapt {@link ContextCustomizer context
 * customizers}, add {@link Application#getInitializers() application
 * initializers} and add
 * {@link MergedContextConfiguration#getContextInitializerClasses() initializers
 * specified on the test}.
 *
 * @param config the source context configuration
 * @param application the application instance
 * @return the initializers to apply
 */
protected List<ApplicationContextInitializer> getInitializers(MergedContextConfiguration config, Application application) {
    List<ApplicationContextInitializer> initializers = new ArrayList<>();
    for (ContextCustomizer contextCustomizer : config.getContextCustomizers()) {
        initializers.add(new ContextCustomizerAdapter(contextCustomizer, config));
    }
    initializers.addAll(application.getInitializers());
    for (Class<? extends ApplicationContextInitializer> initializerClass : config.getContextInitializerClasses()) {
        initializers.add(BeanUtils.newInstance(initializerClass));
    }
    if (config.getParent() != null) {
        initializers.add(new ParentContextApplicationContextInitializer(config.getParentApplicationContext()));
    }
    return initializers;
}
Also used : ContextCustomizer(cn.taketoday.test.context.ContextCustomizer) ArrayList(java.util.ArrayList) ServletContextApplicationContextInitializer(cn.taketoday.framework.web.servlet.support.ServletContextApplicationContextInitializer) ApplicationContextInitializer(cn.taketoday.context.ApplicationContextInitializer)

Example 2 with ContextCustomizer

use of cn.taketoday.test.context.ContextCustomizer in project today-framework by TAKETODAY.

the class ApplicationContextLoader method getInitializers.

/**
 * Return the {@link ApplicationContextInitializer initializers} that will be applied
 * to the context. By default this method will adapt {@link ContextCustomizer context
 * customizers}, add {@link Application#getInitializers() application
 * initializers} and add
 * {@link MergedContextConfiguration#getContextInitializerClasses() initializers
 * specified on the test}.
 *
 * @param config the source context configuration
 * @param application the application instance
 * @return the initializers to apply
 */
protected List<ApplicationContextInitializer> getInitializers(MergedContextConfiguration config, Application application) {
    List<ApplicationContextInitializer> initializers = new ArrayList<>();
    for (ContextCustomizer contextCustomizer : config.getContextCustomizers()) {
        initializers.add(new ContextCustomizerAdapter(contextCustomizer, config));
    }
    initializers.addAll(application.getInitializers());
    for (Class<? extends ApplicationContextInitializer> initializerClass : config.getContextInitializerClasses()) {
        initializers.add(BeanUtils.newInstance(initializerClass));
    }
    if (config.getParent() != null) {
        initializers.add(new ParentContextApplicationContextInitializer(config.getParentApplicationContext()));
    }
    return initializers;
}
Also used : ContextCustomizer(cn.taketoday.test.context.ContextCustomizer) ArrayList(java.util.ArrayList) ServletContextApplicationContextInitializer(cn.taketoday.framework.web.servlet.support.ServletContextApplicationContextInitializer) ApplicationContextInitializer(cn.taketoday.context.ApplicationContextInitializer)

Aggregations

ApplicationContextInitializer (cn.taketoday.context.ApplicationContextInitializer)2 ServletContextApplicationContextInitializer (cn.taketoday.framework.web.servlet.support.ServletContextApplicationContextInitializer)2 ContextCustomizer (cn.taketoday.test.context.ContextCustomizer)2 ArrayList (java.util.ArrayList)2