Search in sources :

Example 76 with BeanDefinitionRegistry

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

the class AnnotationBeanNameGeneratorTests method generateBeanNameWithNamedComponent.

@Test
public void generateBeanNameWithNamedComponent() {
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentWithName.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    assertThat(beanName).as("The generated beanName must *never* be null.").isNotNull();
    assertThat(StringUtils.hasText(beanName)).as("The generated beanName must *never* be blank.").isTrue();
    assertThat(beanName).isEqualTo("walden");
}
Also used : SimpleBeanDefinitionRegistry(org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry) AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) SimpleBeanDefinitionRegistry(org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) AnnotatedGenericBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 77 with BeanDefinitionRegistry

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

the class AnnotationBeanNameGeneratorTests method generateBeanNameFromMetaComponentWithNonStringValue.

@Test
public void generateBeanNameFromMetaComponentWithNonStringValue() {
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentFromNonStringMeta.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    assertThat(beanName).isEqualTo("annotationBeanNameGeneratorTests.ComponentFromNonStringMeta");
}
Also used : SimpleBeanDefinitionRegistry(org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry) AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) SimpleBeanDefinitionRegistry(org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) AnnotatedGenericBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 78 with BeanDefinitionRegistry

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

the class AnnotationBeanNameGeneratorTests method generateBeanNameFromComposedControllerAnnotationWithoutName.

@Test
public void generateBeanNameFromComposedControllerAnnotationWithoutName() {
    // SPR-11360
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComposedControllerAnnotationWithoutName.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd);
    assertThat(beanName).isEqualTo(expectedGeneratedBeanName);
}
Also used : SimpleBeanDefinitionRegistry(org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry) AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) SimpleBeanDefinitionRegistry(org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) AnnotatedGenericBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 79 with BeanDefinitionRegistry

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

the class AnnotationBeanNameGeneratorTests method generateBeanNameWithAnonymousComponentYieldsGeneratedBeanName.

@Test
public void generateBeanNameWithAnonymousComponentYieldsGeneratedBeanName() {
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnonymousComponent.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    assertThat(beanName).as("The generated beanName must *never* be null.").isNotNull();
    assertThat(StringUtils.hasText(beanName)).as("The generated beanName must *never* be blank.").isTrue();
    String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd);
    assertThat(beanName).isEqualTo(expectedGeneratedBeanName);
}
Also used : SimpleBeanDefinitionRegistry(org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry) AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) SimpleBeanDefinitionRegistry(org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) AnnotatedGenericBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 80 with BeanDefinitionRegistry

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

the class AnnotationBeanNameGeneratorTests method generateBeanNameFromComposedControllerAnnotationWithBlankName.

@Test
public void generateBeanNameFromComposedControllerAnnotationWithBlankName() {
    // SPR-11360
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComposedControllerAnnotationWithBlankName.class);
    String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
    String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd);
    assertThat(beanName).isEqualTo(expectedGeneratedBeanName);
}
Also used : SimpleBeanDefinitionRegistry(org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry) AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) SimpleBeanDefinitionRegistry(org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) AnnotatedGenericBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)86 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)36 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)20 Test (org.junit.jupiter.api.Test)15 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)13 SimpleBeanDefinitionRegistry (org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry)13 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)12 ApplicationContext (org.springframework.context.ApplicationContext)10 Map (java.util.Map)9 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)8 AnnotatedGenericBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition)7 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)7 Test (org.junit.Test)5 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)5 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)5 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)5 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)4 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)4 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)4 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)4