Search in sources :

Example 1 with BeanReference

use of cn.taketoday.beans.factory.config.BeanReference in project today-framework by TAKETODAY.

the class AopNamespaceHandlerEventTests method aspectEvent.

@Test
void aspectEvent() {
    this.reader.loadBeanDefinitions(CONTEXT);
    ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
    assertThat(componentDefinitions).as("Incorrect number of events fired").hasSize(2);
    assertThat(componentDefinitions[0]).as("No holder with nested components").isInstanceOf(CompositeComponentDefinition.class);
    CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
    assertThat(compositeDef.getName()).isEqualTo("aop:config");
    ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
    assertThat(nestedComponentDefs).as("Incorrect number of inner components").hasSize(2);
    AspectComponentDefinition acd = null;
    for (ComponentDefinition componentDefinition : nestedComponentDefs) {
        if (componentDefinition instanceof AspectComponentDefinition) {
            acd = (AspectComponentDefinition) componentDefinition;
            break;
        }
    }
    assertThat(acd).as("AspectComponentDefinition not found").isNotNull();
    BeanDefinition[] beanDefinitions = acd.getBeanDefinitions();
    assertThat(beanDefinitions).hasSize(5);
    BeanReference[] beanReferences = acd.getBeanReferences();
    assertThat(beanReferences).hasSize(6);
    Set<String> expectedReferences = new HashSet<>();
    expectedReferences.add("pc");
    expectedReferences.add("countingAdvice");
    for (BeanReference beanReference : beanReferences) {
        expectedReferences.remove(beanReference.getBeanName());
    }
    assertThat(expectedReferences).as("Incorrect references found").isEmpty();
    Arrays.stream(componentDefinitions).skip(1).forEach(definition -> assertThat(definition).isInstanceOf(BeanComponentDefinition.class));
    ComponentDefinition[] nestedComponentDefs2 = acd.getNestedComponents();
    assertThat(nestedComponentDefs2).as("Inner PointcutComponentDefinition not found").hasSize(1);
    assertThat(nestedComponentDefs2[0]).isInstanceOf(PointcutComponentDefinition.class);
    PointcutComponentDefinition pcd = (PointcutComponentDefinition) nestedComponentDefs2[0];
    assertThat(pcd.getBeanDefinitions()).as("Incorrect number of BeanDefinitions").hasSize(1);
}
Also used : CompositeComponentDefinition(cn.taketoday.beans.factory.parsing.CompositeComponentDefinition) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) BeanReference(cn.taketoday.beans.factory.config.BeanReference) BeanComponentDefinition(cn.taketoday.beans.factory.parsing.BeanComponentDefinition) CompositeComponentDefinition(cn.taketoday.beans.factory.parsing.CompositeComponentDefinition) ComponentDefinition(cn.taketoday.beans.factory.parsing.ComponentDefinition) BeanComponentDefinition(cn.taketoday.beans.factory.parsing.BeanComponentDefinition) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with BeanReference

use of cn.taketoday.beans.factory.config.BeanReference in project today-infrastructure by TAKETODAY.

the class AopNamespaceHandlerEventTests method aspectEvent.

@Test
void aspectEvent() {
    this.reader.loadBeanDefinitions(CONTEXT);
    ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
    assertThat(componentDefinitions).as("Incorrect number of events fired").hasSize(2);
    assertThat(componentDefinitions[0]).as("No holder with nested components").isInstanceOf(CompositeComponentDefinition.class);
    CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
    assertThat(compositeDef.getName()).isEqualTo("aop:config");
    ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
    assertThat(nestedComponentDefs).as("Incorrect number of inner components").hasSize(2);
    AspectComponentDefinition acd = null;
    for (ComponentDefinition componentDefinition : nestedComponentDefs) {
        if (componentDefinition instanceof AspectComponentDefinition) {
            acd = (AspectComponentDefinition) componentDefinition;
            break;
        }
    }
    assertThat(acd).as("AspectComponentDefinition not found").isNotNull();
    BeanDefinition[] beanDefinitions = acd.getBeanDefinitions();
    assertThat(beanDefinitions).hasSize(5);
    BeanReference[] beanReferences = acd.getBeanReferences();
    assertThat(beanReferences).hasSize(6);
    Set<String> expectedReferences = new HashSet<>();
    expectedReferences.add("pc");
    expectedReferences.add("countingAdvice");
    for (BeanReference beanReference : beanReferences) {
        expectedReferences.remove(beanReference.getBeanName());
    }
    assertThat(expectedReferences).as("Incorrect references found").isEmpty();
    Arrays.stream(componentDefinitions).skip(1).forEach(definition -> assertThat(definition).isInstanceOf(BeanComponentDefinition.class));
    ComponentDefinition[] nestedComponentDefs2 = acd.getNestedComponents();
    assertThat(nestedComponentDefs2).as("Inner PointcutComponentDefinition not found").hasSize(1);
    assertThat(nestedComponentDefs2[0]).isInstanceOf(PointcutComponentDefinition.class);
    PointcutComponentDefinition pcd = (PointcutComponentDefinition) nestedComponentDefs2[0];
    assertThat(pcd.getBeanDefinitions()).as("Incorrect number of BeanDefinitions").hasSize(1);
}
Also used : CompositeComponentDefinition(cn.taketoday.beans.factory.parsing.CompositeComponentDefinition) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) BeanReference(cn.taketoday.beans.factory.config.BeanReference) BeanComponentDefinition(cn.taketoday.beans.factory.parsing.BeanComponentDefinition) CompositeComponentDefinition(cn.taketoday.beans.factory.parsing.CompositeComponentDefinition) ComponentDefinition(cn.taketoday.beans.factory.parsing.ComponentDefinition) BeanComponentDefinition(cn.taketoday.beans.factory.parsing.BeanComponentDefinition) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

BeanDefinition (cn.taketoday.beans.factory.config.BeanDefinition)2 BeanReference (cn.taketoday.beans.factory.config.BeanReference)2 BeanComponentDefinition (cn.taketoday.beans.factory.parsing.BeanComponentDefinition)2 ComponentDefinition (cn.taketoday.beans.factory.parsing.ComponentDefinition)2 CompositeComponentDefinition (cn.taketoday.beans.factory.parsing.CompositeComponentDefinition)2 HashSet (java.util.HashSet)2 Test (org.junit.jupiter.api.Test)2