Search in sources :

Example 6 with Application

use of cn.taketoday.framework.Application in project today-framework by TAKETODAY.

the class ConfigDataEnvironmentPostProcessorIntegrationTests method setup.

@BeforeEach
void setup() {
    this.application = new Application(Config.class);
    this.application.setApplicationType(ApplicationType.NONE_WEB);
}
Also used : Application(cn.taketoday.framework.Application) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with Application

use of cn.taketoday.framework.Application in project today-framework by TAKETODAY.

the class ConfigDataEnvironmentPostProcessorBootstrapContextIntegrationTests method setup.

@BeforeEach
void setup() {
    this.application = new Application(Config.class);
    this.application.setApplicationType(ApplicationType.NONE_WEB);
}
Also used : Application(cn.taketoday.framework.Application) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with Application

use of cn.taketoday.framework.Application in project today-framework by TAKETODAY.

the class ConfigurationPropertiesTests method loadWhenEnvironmentPrefixSetShouldBind.

@Test
void loadWhenEnvironmentPrefixSetShouldBind() {
    PropertySources sources = this.context.getEnvironment().getPropertySources();
    sources.replace(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, new SystemEnvironmentPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, Collections.singletonMap("MY_SPRING_FOO_NAME", "Jane")));
    Application application = new Application(PrefixConfiguration.class);
    application.setApplicationContextFactory((webApplicationType) -> ConfigurationPropertiesTests.this.context);
    application.setEnvironmentPrefix("my");
    application.setEnvironment(this.context.getEnvironment());
    application.run();
    BasicProperties bean = this.context.getBean(BasicProperties.class);
    assertThat(bean.name).isEqualTo("Jane");
}
Also used : SystemEnvironmentPropertySource(cn.taketoday.core.env.SystemEnvironmentPropertySource) PropertySources(cn.taketoday.core.env.PropertySources) Application(cn.taketoday.framework.Application) Test(org.junit.jupiter.api.Test)

Example 9 with Application

use of cn.taketoday.framework.Application in project today-framework by TAKETODAY.

the class ApplicationContextLoader method loadContext.

@Override
public ApplicationContext loadContext(MergedContextConfiguration config) throws Exception {
    Class<?>[] configClasses = config.getClasses();
    String[] configLocations = config.getLocations();
    Assert.state(ObjectUtils.isNotEmpty(configClasses) || ObjectUtils.isNotEmpty(configLocations), () -> "No configuration classes or locations found in @SpringApplicationConfiguration. " + "For default configuration detection to work you need Spring 4.0.3 or better (found " + cn.taketoday.lang.Version.get() + ").");
    Application application = getSpringApplication();
    application.setMainApplicationClass(config.getTestClass());
    application.addPrimarySources(Arrays.asList(configClasses));
    application.getSources().addAll(Arrays.asList(configLocations));
    List<ApplicationContextInitializer> initializers = getInitializers(config, application);
    if (config instanceof WebMergedContextConfiguration) {
        application.setApplicationType(ApplicationType.SERVLET_WEB);
        if (!isEmbeddedWebEnvironment(config)) {
            new WebConfigurer().configure(config, application, initializers);
        }
    } else if (config instanceof ReactiveWebMergedContextConfiguration) {
        application.setApplicationType(ApplicationType.REACTIVE_WEB);
        if (!isEmbeddedWebEnvironment(config)) {
            application.setApplicationContextFactory(ApplicationContextFactory.from(GenericReactiveWebApplicationContext::new));
        }
    } else {
        application.setApplicationType(ApplicationType.NONE_WEB);
    }
    application.setInitializers(initializers);
    ConfigurableEnvironment environment = getEnvironment();
    if (environment != null) {
        prepareEnvironment(config, application, environment, false);
        application.setEnvironment(environment);
    } else {
        application.addListeners(new PrepareEnvironmentListener(config));
    }
    String[] args = ApplicationTestArgs.get(config.getContextCustomizers());
    return application.run(args);
}
Also used : GenericReactiveWebApplicationContext(cn.taketoday.framework.web.reactive.context.GenericReactiveWebApplicationContext) WebMergedContextConfiguration(cn.taketoday.test.context.web.WebMergedContextConfiguration) ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) ServletContextApplicationContextInitializer(cn.taketoday.framework.web.servlet.support.ServletContextApplicationContextInitializer) ApplicationContextInitializer(cn.taketoday.context.ApplicationContextInitializer) Application(cn.taketoday.framework.Application)

Example 10 with Application

use of cn.taketoday.framework.Application in project today-infrastructure by TAKETODAY.

the class ApplicationContextLoader method loadContext.

@Override
public ApplicationContext loadContext(MergedContextConfiguration config) throws Exception {
    Class<?>[] configClasses = config.getClasses();
    String[] configLocations = config.getLocations();
    Assert.state(ObjectUtils.isNotEmpty(configClasses) || ObjectUtils.isNotEmpty(configLocations), () -> "No configuration classes or locations found in @SpringApplicationConfiguration. " + "For default configuration detection to work you need Spring 4.0.3 or better (found " + cn.taketoday.lang.Version.get() + ").");
    Application application = getSpringApplication();
    application.setMainApplicationClass(config.getTestClass());
    application.addPrimarySources(Arrays.asList(configClasses));
    application.getSources().addAll(Arrays.asList(configLocations));
    List<ApplicationContextInitializer> initializers = getInitializers(config, application);
    if (config instanceof WebMergedContextConfiguration) {
        application.setApplicationType(ApplicationType.SERVLET_WEB);
        if (!isEmbeddedWebEnvironment(config)) {
            new WebConfigurer().configure(config, application, initializers);
        }
    } else if (config instanceof ReactiveWebMergedContextConfiguration) {
        application.setApplicationType(ApplicationType.REACTIVE_WEB);
        if (!isEmbeddedWebEnvironment(config)) {
            application.setApplicationContextFactory(ApplicationContextFactory.from(GenericReactiveWebApplicationContext::new));
        }
    } else {
        application.setApplicationType(ApplicationType.NONE_WEB);
    }
    application.setInitializers(initializers);
    ConfigurableEnvironment environment = getEnvironment();
    if (environment != null) {
        prepareEnvironment(config, application, environment, false);
        application.setEnvironment(environment);
    } else {
        application.addListeners(new PrepareEnvironmentListener(config));
    }
    String[] args = ApplicationTestArgs.get(config.getContextCustomizers());
    return application.run(args);
}
Also used : GenericReactiveWebApplicationContext(cn.taketoday.framework.web.reactive.context.GenericReactiveWebApplicationContext) WebMergedContextConfiguration(cn.taketoday.test.context.web.WebMergedContextConfiguration) ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) ServletContextApplicationContextInitializer(cn.taketoday.framework.web.servlet.support.ServletContextApplicationContextInitializer) ApplicationContextInitializer(cn.taketoday.context.ApplicationContextInitializer) Application(cn.taketoday.framework.Application)

Aggregations

Application (cn.taketoday.framework.Application)10 BeforeEach (org.junit.jupiter.api.BeforeEach)6 ApplicationContextInitializer (cn.taketoday.context.ApplicationContextInitializer)2 ConfigurableEnvironment (cn.taketoday.core.env.ConfigurableEnvironment)2 PropertySources (cn.taketoday.core.env.PropertySources)2 SystemEnvironmentPropertySource (cn.taketoday.core.env.SystemEnvironmentPropertySource)2 Config (cn.taketoday.framework.context.config.ConfigDataEnvironmentPostProcessorIntegrationTests.Config)2 GenericReactiveWebApplicationContext (cn.taketoday.framework.web.reactive.context.GenericReactiveWebApplicationContext)2 ServletContextApplicationContextInitializer (cn.taketoday.framework.web.servlet.support.ServletContextApplicationContextInitializer)2 WebMergedContextConfiguration (cn.taketoday.test.context.web.WebMergedContextConfiguration)2 Test (org.junit.jupiter.api.Test)2