Search in sources :

Example 31 with MetadataReader

use of org.springframework.core.type.classreading.MetadataReader in project spring-framework by spring-projects.

the class AnnotationTypeFilterTests method testNonInheritedAnnotationDoesNotMatch.

@Test
public void testNonInheritedAnnotationDoesNotMatch() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeSubclassOfSomeClassMarkedWithNonInheritedAnnotation";
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
    AnnotationTypeFilter filter = new AnnotationTypeFilter(NonInheritedAnnotation.class);
    // Must fail as annotation isn't inherited
    assertFalse(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
Also used : AnnotationTypeFilter(org.springframework.core.type.filter.AnnotationTypeFilter) 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) Test(org.junit.Test)

Example 32 with MetadataReader

use of org.springframework.core.type.classreading.MetadataReader in project spring-framework by spring-projects.

the class AnnotationTypeFilterTests method testMatchesInterfacesIfConfigured.

@Test
public void testMatchesInterfacesIfConfigured() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeComponentInterface";
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
    AnnotationTypeFilter filter = new AnnotationTypeFilter(InheritedAnnotation.class, false, true);
    assertTrue(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
Also used : AnnotationTypeFilter(org.springframework.core.type.filter.AnnotationTypeFilter) 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) Test(org.junit.Test)

Example 33 with MetadataReader

use of org.springframework.core.type.classreading.MetadataReader in project spring-framework by spring-projects.

the class AspectJTypeFilterTests method assertNoMatch.

private void assertNoMatch(String type, String typePattern) throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(type);
    AspectJTypeFilter filter = new AspectJTypeFilter(typePattern, getClass().getClassLoader());
    assertFalse(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(type);
}
Also used : AspectJTypeFilter(org.springframework.core.type.filter.AspectJTypeFilter) 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 34 with MetadataReader

use of org.springframework.core.type.classreading.MetadataReader in project spring-framework by spring-projects.

the class AssignableTypeFilterTests method directMatch.

@Test
public void directMatch() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$TestNonInheritingClass";
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
    AssignableTypeFilter matchingFilter = new AssignableTypeFilter(TestNonInheritingClass.class);
    AssignableTypeFilter notMatchingFilter = new AssignableTypeFilter(TestInterface.class);
    assertFalse(notMatchingFilter.match(metadataReader, metadataReaderFactory));
    assertTrue(matchingFilter.match(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) AssignableTypeFilter(org.springframework.core.type.filter.AssignableTypeFilter) Test(org.junit.Test)

Example 35 with MetadataReader

use of org.springframework.core.type.classreading.MetadataReader in project spring-framework by spring-projects.

the class AssignableTypeFilterTests method superClassMatch.

@Test
public void superClassMatch() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$SomeDaoLikeImpl";
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
    AssignableTypeFilter filter = new AssignableTypeFilter(SimpleJdbcDaoSupport.class);
    assertTrue(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
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) AssignableTypeFilter(org.springframework.core.type.filter.AssignableTypeFilter) Test(org.junit.Test)

Aggregations

MetadataReader (org.springframework.core.type.classreading.MetadataReader)37 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)27 SimpleMetadataReaderFactory (org.springframework.core.type.classreading.SimpleMetadataReaderFactory)24 Test (org.junit.Test)23 IOException (java.io.IOException)7 Resource (org.springframework.core.io.Resource)7 AnnotationTypeFilter (org.springframework.core.type.filter.AnnotationTypeFilter)7 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)5 AssignableTypeFilter (org.springframework.core.type.filter.AssignableTypeFilter)5 AnnotatedGenericBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition)4 CachingMetadataReaderFactory (org.springframework.core.type.classreading.CachingMetadataReaderFactory)4 AnnotationMetadata (org.springframework.core.type.AnnotationMetadata)3 URL (java.net.URL)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)2 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)2 AspectJTypeFilter (org.springframework.core.type.filter.AspectJTypeFilter)2 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1