Search in sources :

Example 1 with RegisteredBean

use of org.springframework.beans.factory.support.RegisteredBean in project spring-framework by spring-projects.

the class AutowiredMethodArgumentsResolverTests method resolveRequiredWithSingleDependencyReturnsValue.

@Test
void resolveRequiredWithSingleDependencyReturnsValue() {
    this.beanFactory.registerSingleton("test", "testValue");
    RegisteredBean registeredBean = registerTestBean(this.beanFactory);
    AutowiredMethodArgumentsResolver resolver = AutowiredMethodArgumentsResolver.forRequiredMethod("injectString", String.class);
    AutowiredArguments resolved = resolver.resolve(registeredBean);
    assertThat(resolved.toArray()).containsExactly("testValue");
}
Also used : RegisteredBean(org.springframework.beans.factory.support.RegisteredBean) Test(org.junit.jupiter.api.Test)

Example 2 with RegisteredBean

use of org.springframework.beans.factory.support.RegisteredBean in project spring-framework by spring-projects.

the class AutowiredMethodArgumentsResolverTests method resolveNonRequiredWhenNoSuchBeanReturnsNull.

@Test
void resolveNonRequiredWhenNoSuchBeanReturnsNull() {
    RegisteredBean registeredBean = registerTestBean(this.beanFactory);
    AutowiredMethodArgumentsResolver resolver = AutowiredMethodArgumentsResolver.forMethod("injectString", String.class);
    assertThat(resolver.resolve(registeredBean)).isNull();
}
Also used : RegisteredBean(org.springframework.beans.factory.support.RegisteredBean) Test(org.junit.jupiter.api.Test)

Example 3 with RegisteredBean

use of org.springframework.beans.factory.support.RegisteredBean in project spring-framework by spring-projects.

the class BeanDefinitionMethodGeneratorFactoryTests method getBeanDefinitionMethodGeneratorWhenRegisteredBeanIsAotProcessorAndFilteresBeanBeanRegistrationExcludeFilterDoesNotFilterBean.

@Test
void getBeanDefinitionMethodGeneratorWhenRegisteredBeanIsAotProcessorAndFilteresBeanBeanRegistrationExcludeFilterDoesNotFilterBean() {
    MockSpringFactoriesLoader springFactoriesLoader = new MockSpringFactoriesLoader();
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    beanFactory.registerBeanDefinition("test", BeanDefinitionBuilder.rootBeanDefinition(TestBeanRegistrationAotProcessorAndFilterBean.class).getBeanDefinition());
    RegisteredBean registeredBean1 = RegisteredBean.of(beanFactory, "test");
    BeanDefinitionMethodGeneratorFactory methodGeneratorFactory = new BeanDefinitionMethodGeneratorFactory(new AotFactoriesLoader(beanFactory, springFactoriesLoader));
    assertThat(methodGeneratorFactory.getBeanDefinitionMethodGenerator(registeredBean1, null)).isNotNull();
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RegisteredBean(org.springframework.beans.factory.support.RegisteredBean) MockSpringFactoriesLoader(org.springframework.core.mock.MockSpringFactoriesLoader) Test(org.junit.jupiter.api.Test)

Example 4 with RegisteredBean

use of org.springframework.beans.factory.support.RegisteredBean in project spring-framework by spring-projects.

the class BeanDefinitionMethodGeneratorFactoryTests method getBeanDefinitionMethodGeneratorAddsContributionsFromProcessors.

@Test
void getBeanDefinitionMethodGeneratorAddsContributionsFromProcessors() {
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    BeanRegistrationAotContribution beanContribution = mock(BeanRegistrationAotContribution.class);
    BeanRegistrationAotProcessor processorBean = registeredBean -> beanContribution;
    beanFactory.registerSingleton("processorBean", processorBean);
    MockSpringFactoriesLoader springFactoriesLoader = new MockSpringFactoriesLoader();
    BeanRegistrationAotContribution loaderContribution = mock(BeanRegistrationAotContribution.class);
    BeanRegistrationAotProcessor loaderProcessor = registeredBean -> loaderContribution;
    springFactoriesLoader.addInstance(BeanRegistrationAotProcessor.class, loaderProcessor);
    RegisteredBean registeredBean = registerTestBean(beanFactory);
    BeanDefinitionMethodGeneratorFactory methodGeneratorFactory = new BeanDefinitionMethodGeneratorFactory(new AotFactoriesLoader(beanFactory, springFactoriesLoader));
    BeanDefinitionMethodGenerator methodGenerator = methodGeneratorFactory.getBeanDefinitionMethodGenerator(registeredBean, null);
    assertThat(methodGenerator).extracting("aotContributions").asList().containsExactly(beanContribution, loaderContribution);
}
Also used : Test(org.junit.jupiter.api.Test) Ordered(org.springframework.core.Ordered) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RegisteredBean(org.springframework.beans.factory.support.RegisteredBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) MockSpringFactoriesLoader(org.springframework.core.mock.MockSpringFactoriesLoader) Mockito.mock(org.mockito.Mockito.mock) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RegisteredBean(org.springframework.beans.factory.support.RegisteredBean) MockSpringFactoriesLoader(org.springframework.core.mock.MockSpringFactoriesLoader) Test(org.junit.jupiter.api.Test)

Example 5 with RegisteredBean

use of org.springframework.beans.factory.support.RegisteredBean in project spring-framework by spring-projects.

the class BeanDefinitionMethodGeneratorFactoryTests method getBeanDefinitionMethodGeneratorWhenExcludedByBeanRegistrationExcludeFilterBeanReturnsNull.

@Test
void getBeanDefinitionMethodGeneratorWhenExcludedByBeanRegistrationExcludeFilterBeanReturnsNull() {
    MockSpringFactoriesLoader springFactoriesLoader = new MockSpringFactoriesLoader();
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    RegisteredBean registeredBean = registerTestBean(beanFactory);
    beanFactory.registerSingleton("filter", new MockBeanRegistrationExcludeFilter(true, 0));
    BeanDefinitionMethodGeneratorFactory methodGeneratorFactory = new BeanDefinitionMethodGeneratorFactory(new AotFactoriesLoader(beanFactory, springFactoriesLoader));
    assertThat(methodGeneratorFactory.getBeanDefinitionMethodGenerator(registeredBean, null)).isNull();
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RegisteredBean(org.springframework.beans.factory.support.RegisteredBean) MockSpringFactoriesLoader(org.springframework.core.mock.MockSpringFactoriesLoader) Test(org.junit.jupiter.api.Test)

Aggregations

RegisteredBean (org.springframework.beans.factory.support.RegisteredBean)57 Test (org.junit.jupiter.api.Test)50 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)13 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)12 MethodReference (org.springframework.aot.generate.MethodReference)11 MockSpringFactoriesLoader (org.springframework.core.mock.MockSpringFactoriesLoader)8 TestBean (org.springframework.beans.testfixture.beans.TestBean)7 ArrayList (java.util.ArrayList)6 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)5 CompileWithTargetClassAccess (org.springframework.aot.test.generator.compile.CompileWithTargetClassAccess)5 Environment (org.springframework.core.env.Environment)5 SourceFile (org.springframework.aot.test.generator.file.SourceFile)4 StandardEnvironment (org.springframework.core.env.StandardEnvironment)4 LinkedHashMap (java.util.LinkedHashMap)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 DefaultGenerationContext (org.springframework.aot.generate.DefaultGenerationContext)3 GenerationContext (org.springframework.aot.generate.GenerationContext)3 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)3 InstanceSupplier (org.springframework.beans.factory.support.InstanceSupplier)3 AnnotatedBean (org.springframework.beans.testfixture.beans.AnnotatedBean)3