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);
}
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);
}
Aggregations