Search in sources :

Example 1 with ApplicationPropertySourcesProcessor

use of cn.taketoday.context.support.ApplicationPropertySourcesProcessor in project today-infrastructure by TAKETODAY.

the class ConditionalTests method testConditionalOnResource.

@Test
public void testConditionalOnResource() throws Exception {
    try (StandardApplicationContext context = new StandardApplicationContext()) {
        ApplicationPropertySourcesProcessor processor = new ApplicationPropertySourcesProcessor(context);
        processor.setPropertiesLocation("info.properties");
        processor.postProcessEnvironment();
        context.scan("cn.taketoday.context.condition");
        BeanDefinitionRegistry registry = context.unwrapFactory(BeanDefinitionRegistry.class);
        Assertions.assertFalse(registry.containsBeanDefinition(ConditionalOnResource_.class));
        Assertions.assertTrue(registry.containsBeanDefinition(ConditionalOnResource__.class));
        Assertions.assertTrue(registry.containsBeanDefinition(ConditionalOnResource___.class));
        Assertions.assertTrue(registry.containsBeanDefinition(ConditionalOnResource____.class));
    }
}
Also used : ApplicationPropertySourcesProcessor(cn.taketoday.context.support.ApplicationPropertySourcesProcessor) StandardApplicationContext(cn.taketoday.context.support.StandardApplicationContext) BeanDefinitionRegistry(cn.taketoday.beans.factory.support.BeanDefinitionRegistry) Test(org.junit.jupiter.api.Test)

Example 2 with ApplicationPropertySourcesProcessor

use of cn.taketoday.context.support.ApplicationPropertySourcesProcessor in project today-infrastructure by TAKETODAY.

the class ConditionalTests method conditionalOnExpression.

@Test
void conditionalOnExpression() throws IOException {
    try (StandardApplicationContext context = new StandardApplicationContext()) {
        ApplicationPropertySourcesProcessor processor = new ApplicationPropertySourcesProcessor(context);
        processor.setPropertiesLocation("info.properties");
        processor.postProcessEnvironment();
        context.scan("cn.taketoday.context.condition");
        BeanDefinitionRegistry registry = context.unwrapFactory(BeanDefinitionRegistry.class);
        Assertions.assertTrue(registry.containsBeanDefinition(ConditionalExpression_.class));
        Assertions.assertFalse(registry.containsBeanDefinition(ConditionalExpression__.class));
    }
}
Also used : ApplicationPropertySourcesProcessor(cn.taketoday.context.support.ApplicationPropertySourcesProcessor) StandardApplicationContext(cn.taketoday.context.support.StandardApplicationContext) BeanDefinitionRegistry(cn.taketoday.beans.factory.support.BeanDefinitionRegistry) Test(org.junit.jupiter.api.Test)

Example 3 with ApplicationPropertySourcesProcessor

use of cn.taketoday.context.support.ApplicationPropertySourcesProcessor in project today-infrastructure by TAKETODAY.

the class ConditionalTests method testConditionalOnClass.

// ConditionalOnClass
// ------------------------------
@Test
void testConditionalOnClass() throws IOException {
    try (StandardApplicationContext context = new StandardApplicationContext()) {
        ApplicationPropertySourcesProcessor processor = new ApplicationPropertySourcesProcessor(context);
        processor.setPropertiesLocation("info.properties");
        processor.postProcessEnvironment();
        context.scan("cn.taketoday.context.condition");
        BeanDefinitionRegistry registry = context.unwrapFactory(BeanDefinitionRegistry.class);
        Assertions.assertTrue(registry.containsBeanDefinition(ConditionalClass.class));
        Assertions.assertTrue(registry.containsBeanDefinition(ConditionalOnMissing.class));
        Assertions.assertFalse(registry.containsBeanDefinition(ConditionalMissingClass.class));
        Assertions.assertFalse(registry.containsBeanDefinition(ConditionalMissed.class));
    }
}
Also used : ApplicationPropertySourcesProcessor(cn.taketoday.context.support.ApplicationPropertySourcesProcessor) StandardApplicationContext(cn.taketoday.context.support.StandardApplicationContext) BeanDefinitionRegistry(cn.taketoday.beans.factory.support.BeanDefinitionRegistry) Test(org.junit.jupiter.api.Test)

Example 4 with ApplicationPropertySourcesProcessor

use of cn.taketoday.context.support.ApplicationPropertySourcesProcessor in project today-infrastructure by TAKETODAY.

the class StandardEnvironmentTests method addActiveProfile.

@Test
void addActiveProfile() throws IOException {
    try (StandardApplicationContext context = new StandardApplicationContext()) {
        ApplicationPropertySourcesProcessor processor = new ApplicationPropertySourcesProcessor(context);
        processor.setPropertiesLocation("info.properties");
        processor.postProcessEnvironment();
        context.scan("cn.taketoday.context.env");
        ConfigurableEnvironment environment = context.getEnvironment();
        environment.addActiveProfile("prod");
        String[] activeProfiles = environment.getActiveProfiles();
        assert activeProfiles.length == 3;
        assert environment.acceptsProfiles("prod");
    }
}
Also used : ApplicationPropertySourcesProcessor(cn.taketoday.context.support.ApplicationPropertySourcesProcessor) StandardApplicationContext(cn.taketoday.context.support.StandardApplicationContext) ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) Test(org.junit.jupiter.api.Test)

Example 5 with ApplicationPropertySourcesProcessor

use of cn.taketoday.context.support.ApplicationPropertySourcesProcessor in project today-framework by TAKETODAY.

the class ELFieldTests method testEnv.

@Test
void testEnv() throws IOException {
    try (StandardApplicationContext applicationContext = new StandardApplicationContext()) {
        User user = new User();
        // 
        user.setAge(20).setBrithday(// 
        new Date()).setId(1);
        ApplicationPropertySourcesProcessor processor = new ApplicationPropertySourcesProcessor(applicationContext);
        processor.setPropertiesLocation("info.properties");
        processor.postProcessEnvironment();
        applicationContext.registerSingleton(user);
        applicationContext.register(ELFieldTests.class);
        applicationContext.refresh();
        ELFieldTests bean = applicationContext.getBean(getClass());
        System.err.println(bean);
        assert bean.user == user;
        assert bean.siteName.equals("TODAY BLOG");
    }
}
Also used : ApplicationPropertySourcesProcessor(cn.taketoday.context.support.ApplicationPropertySourcesProcessor) StandardApplicationContext(cn.taketoday.context.support.StandardApplicationContext) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

ApplicationPropertySourcesProcessor (cn.taketoday.context.support.ApplicationPropertySourcesProcessor)22 Test (org.junit.jupiter.api.Test)21 StandardApplicationContext (cn.taketoday.context.support.StandardApplicationContext)19 BeanDefinitionRegistry (cn.taketoday.beans.factory.support.BeanDefinitionRegistry)9 ConfigurableEnvironment (cn.taketoday.core.env.ConfigurableEnvironment)6 Environment (cn.taketoday.core.env.Environment)4 StandardEnvironment (cn.taketoday.core.env.StandardEnvironment)4 User (test.demo.config.User)3 BeanDefinition (cn.taketoday.beans.factory.config.BeanDefinition)2 AnnotationConfigApplicationContext (cn.taketoday.context.annotation.AnnotationConfigApplicationContext)2 Date (java.util.Date)2 GenericApplicationContext (cn.taketoday.context.support.GenericApplicationContext)1 ApplicationConversionService (cn.taketoday.format.support.ApplicationConversionService)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Config (test.demo.config.Config)1 ConfigFactoryBean (test.demo.config.ConfigFactoryBean)1 UserRepository (test.demo.repository.UserRepository)1 DefaultUserRepository (test.demo.repository.impl.DefaultUserRepository)1 UserService (test.demo.service.UserService)1 DefaultUserService (test.demo.service.impl.DefaultUserService)1