Search in sources :

Example 36 with AnnotatedBeanDefinition

use of org.springframework.beans.factory.annotation.AnnotatedBeanDefinition 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 37 with AnnotatedBeanDefinition

use of org.springframework.beans.factory.annotation.AnnotatedBeanDefinition 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 38 with AnnotatedBeanDefinition

use of org.springframework.beans.factory.annotation.AnnotatedBeanDefinition 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 39 with AnnotatedBeanDefinition

use of org.springframework.beans.factory.annotation.AnnotatedBeanDefinition 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 40 with AnnotatedBeanDefinition

use of org.springframework.beans.factory.annotation.AnnotatedBeanDefinition 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

AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)43 Test (org.junit.jupiter.api.Test)22 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)17 AnnotatedGenericBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition)16 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)13 SimpleBeanDefinitionRegistry (org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry)9 MethodMetadata (org.springframework.core.type.MethodMetadata)7 AnnotationMetadata (org.springframework.core.type.AnnotationMetadata)5 SimpleMetadataReaderFactory (org.springframework.core.type.classreading.SimpleMetadataReaderFactory)5 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)4 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)4 Map (java.util.Map)3 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)3 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)3 AnnotationAttributes (org.springframework.core.annotation.AnnotationAttributes)3 MetadataReader (org.springframework.core.type.classreading.MetadataReader)3 ManagedMap (org.springframework.beans.factory.support.ManagedMap)2 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)2 StandardMethodMetadata (org.springframework.core.type.StandardMethodMetadata)2 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)2