Search in sources :

Example 1 with ConfigurableWebServletApplicationContext

use of cn.taketoday.web.context.ConfigurableWebServletApplicationContext in project today-framework by TAKETODAY.

the class WebApplicationContextRunner method withMockServletContext.

/**
 * Decorate the specified {@code contextFactory} to set a {@link MockServletContext}
 * on each newly created {@link WebApplicationContext}.
 *
 * @param contextFactory the context factory to decorate
 * @return an updated supplier that will set the {@link MockServletContext}
 */
public static Supplier<ConfigurableWebApplicationContext> withMockServletContext(Supplier<ConfigurableWebServletApplicationContext> contextFactory) {
    return (contextFactory != null) ? () -> {
        ConfigurableWebServletApplicationContext context = contextFactory.get();
        context.setServletContext(new MockServletContext());
        return context;
    } : null;
}
Also used : ConfigurableWebServletApplicationContext(cn.taketoday.web.context.ConfigurableWebServletApplicationContext) MockServletContext(cn.taketoday.mock.web.MockServletContext)

Example 2 with ConfigurableWebServletApplicationContext

use of cn.taketoday.web.context.ConfigurableWebServletApplicationContext in project today-infrastructure by TAKETODAY.

the class WebApplicationContextRunner method withMockServletContext.

/**
 * Decorate the specified {@code contextFactory} to set a {@link MockServletContext}
 * on each newly created {@link WebApplicationContext}.
 *
 * @param contextFactory the context factory to decorate
 * @return an updated supplier that will set the {@link MockServletContext}
 */
public static Supplier<ConfigurableWebApplicationContext> withMockServletContext(Supplier<ConfigurableWebServletApplicationContext> contextFactory) {
    return (contextFactory != null) ? () -> {
        ConfigurableWebServletApplicationContext context = contextFactory.get();
        context.setServletContext(new MockServletContext());
        return context;
    } : null;
}
Also used : ConfigurableWebServletApplicationContext(cn.taketoday.web.context.ConfigurableWebServletApplicationContext) MockServletContext(cn.taketoday.mock.web.MockServletContext)

Aggregations

MockServletContext (cn.taketoday.mock.web.MockServletContext)2 ConfigurableWebServletApplicationContext (cn.taketoday.web.context.ConfigurableWebServletApplicationContext)2