Search in sources :

Example 1 with SimpleMetadataReaderFactory

use of org.springframework.core.type.classreading.SimpleMetadataReaderFactory in project spring-boot by spring-projects.

the class FilterAnnotationsTests method match.

private boolean match(FilterAnnotations filterAnnotations, Class<?> type) throws IOException {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(type.getName());
    return filterAnnotations.anyMatches(metadataReader, metadataReaderFactory);
}
Also used : MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) MetadataReader(org.springframework.core.type.classreading.MetadataReader)

Example 2 with SimpleMetadataReaderFactory

use of org.springframework.core.type.classreading.SimpleMetadataReaderFactory in project spring-boot by spring-projects.

the class TypeExcludeFiltersContextCustomizerFactoryTests method getContextCustomizerShouldAddExcludeFilters.

@Test
public void getContextCustomizerShouldAddExcludeFilters() throws Exception {
    ContextCustomizer customizer = this.factory.createContextCustomizer(WithExcludeFilters.class, null);
    customizer.customizeContext(this.context, this.mergedContextConfiguration);
    this.context.refresh();
    TypeExcludeFilter filter = this.context.getBean(TypeExcludeFilter.class);
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(NoAnnotation.class.getName());
    assertThat(filter.match(metadataReader, metadataReaderFactory)).isFalse();
    metadataReader = metadataReaderFactory.getMetadataReader(SimpleExclude.class.getName());
    assertThat(filter.match(metadataReader, metadataReaderFactory)).isTrue();
    metadataReader = metadataReaderFactory.getMetadataReader(TestClassAwareExclude.class.getName());
    assertThat(filter.match(metadataReader, metadataReaderFactory)).isTrue();
}
Also used : MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) ContextCustomizer(org.springframework.test.context.ContextCustomizer) TypeExcludeFilter(org.springframework.boot.context.TypeExcludeFilter) MetadataReader(org.springframework.core.type.classreading.MetadataReader) Test(org.junit.Test)

Example 3 with SimpleMetadataReaderFactory

use of org.springframework.core.type.classreading.SimpleMetadataReaderFactory in project spring-boot by spring-projects.

the class WebFilterHandlerTests method filterWithCustomName.

@Test
public void filterWithCustomName() throws IOException {
    ScannedGenericBeanDefinition scanned = new ScannedGenericBeanDefinition(new SimpleMetadataReaderFactory().getMetadataReader(CustomNameFilter.class.getName()));
    this.handler.handle(scanned, this.registry);
    BeanDefinition filterRegistrationBean = this.registry.getBeanDefinition("custom");
    MutablePropertyValues propertyValues = filterRegistrationBean.getPropertyValues();
    assertThat(propertyValues.get("name")).isEqualTo("custom");
}
Also used : SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) ScannedGenericBeanDefinition(org.springframework.context.annotation.ScannedGenericBeanDefinition) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) ScannedGenericBeanDefinition(org.springframework.context.annotation.ScannedGenericBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Test(org.junit.Test)

Example 4 with SimpleMetadataReaderFactory

use of org.springframework.core.type.classreading.SimpleMetadataReaderFactory in project spring-boot by spring-projects.

the class WebListenerHandlerTests method listener.

@Test
public void listener() throws IOException {
    ScannedGenericBeanDefinition scanned = new ScannedGenericBeanDefinition(new SimpleMetadataReaderFactory().getMetadataReader(TestListener.class.getName()));
    this.handler.handle(scanned, this.registry);
    this.registry.getBeanDefinition(TestListener.class.getName());
}
Also used : SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) ScannedGenericBeanDefinition(org.springframework.context.annotation.ScannedGenericBeanDefinition) Test(org.junit.Test)

Example 5 with SimpleMetadataReaderFactory

use of org.springframework.core.type.classreading.SimpleMetadataReaderFactory in project spring-boot by spring-projects.

the class WebServletHandlerTests method defaultServletConfiguration.

@SuppressWarnings("unchecked")
@Test
public void defaultServletConfiguration() throws IOException {
    ScannedGenericBeanDefinition scanned = new ScannedGenericBeanDefinition(new SimpleMetadataReaderFactory().getMetadataReader(DefaultConfigurationServlet.class.getName()));
    this.handler.handle(scanned, this.registry);
    BeanDefinition servletRegistrationBean = this.registry.getBeanDefinition(DefaultConfigurationServlet.class.getName());
    MutablePropertyValues propertyValues = servletRegistrationBean.getPropertyValues();
    assertThat(propertyValues.get("asyncSupported")).isEqualTo(false);
    assertThat(((Map<String, String>) propertyValues.get("initParameters"))).isEmpty();
    assertThat((Integer) propertyValues.get("loadOnStartup")).isEqualTo(-1);
    assertThat(propertyValues.get("name")).isEqualTo(DefaultConfigurationServlet.class.getName());
    assertThat((String[]) propertyValues.get("urlMappings")).isEmpty();
    assertThat(propertyValues.get("servlet")).isEqualTo(scanned);
}
Also used : SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) ScannedGenericBeanDefinition(org.springframework.context.annotation.ScannedGenericBeanDefinition) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) ScannedGenericBeanDefinition(org.springframework.context.annotation.ScannedGenericBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Test(org.junit.Test)

Aggregations

SimpleMetadataReaderFactory (org.springframework.core.type.classreading.SimpleMetadataReaderFactory)32 Test (org.junit.Test)25 MetadataReader (org.springframework.core.type.classreading.MetadataReader)24 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)23 ScannedGenericBeanDefinition (org.springframework.context.annotation.ScannedGenericBeanDefinition)7 AnnotationTypeFilter (org.springframework.core.type.filter.AnnotationTypeFilter)6 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)4 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)4 AssignableTypeFilter (org.springframework.core.type.filter.AssignableTypeFilter)4 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)2 AnnotatedGenericBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition)2 AspectJTypeFilter (org.springframework.core.type.filter.AspectJTypeFilter)2 ArrayList (java.util.ArrayList)1 EnumSet (java.util.EnumSet)1 HashSet (java.util.HashSet)1 TypeExcludeFilter (org.springframework.boot.context.TypeExcludeFilter)1 Configuration (org.springframework.context.annotation.Configuration)1 Resource (org.springframework.core.io.Resource)1 AnnotationMetadata (org.springframework.core.type.AnnotationMetadata)1 Component (org.springframework.stereotype.Component)1