Search in sources :

Example 6 with UntypedAnnotationDescriptor

use of org.springframework.test.util.MetaAnnotationUtils.UntypedAnnotationDescriptor in project spring-framework by spring-projects.

the class MetaAnnotationUtilsTests method findAnnotationDescriptorForTypesForClassWithMetaAnnotatedInterface.

@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesForClassWithMetaAnnotatedInterface() {
    Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, Component.class);
    UntypedAnnotationDescriptor descriptor;
    descriptor = findAnnotationDescriptorForTypes(ClassWithMetaAnnotatedInterface.class, Service.class, Component.class, Order.class, Transactional.class);
    assertNotNull(descriptor);
    assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass());
    assertEquals(Meta1.class, descriptor.getDeclaringClass());
    assertEquals(rawAnnotation, descriptor.getAnnotation());
    assertEquals(Meta1.class, descriptor.getComposedAnnotation().annotationType());
}
Also used : Order(org.springframework.core.annotation.Order) Service(org.springframework.stereotype.Service) Component(org.springframework.stereotype.Component) UntypedAnnotationDescriptor(org.springframework.test.util.MetaAnnotationUtils.UntypedAnnotationDescriptor) Transactional(org.springframework.transaction.annotation.Transactional) Test(org.junit.Test)

Example 7 with UntypedAnnotationDescriptor

use of org.springframework.test.util.MetaAnnotationUtils.UntypedAnnotationDescriptor in project spring-framework by spring-projects.

the class MetaAnnotationUtilsTests method findAnnotationDescriptorForTypesWithMetaAnnotationWithOverriddenAttributes.

@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithOverriddenAttributes() throws Exception {
    Class<?> startClass = MetaConfigWithOverriddenAttributesTestCase.class;
    Class<ContextConfiguration> annotationType = ContextConfiguration.class;
    UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class, ContextConfiguration.class, Order.class, Transactional.class);
    assertNotNull(descriptor);
    assertEquals(startClass, descriptor.getRootDeclaringClass());
    assertEquals(annotationType, descriptor.getAnnotationType());
    assertArrayEquals(new Class[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value());
    assertArrayEquals(new Class[] { MetaAnnotationUtilsTests.class }, descriptor.getAnnotationAttributes().getClassArray("classes"));
    assertNotNull(descriptor.getComposedAnnotation());
    assertEquals(MetaConfig.class, descriptor.getComposedAnnotationType());
}
Also used : ContextConfiguration(org.springframework.test.context.ContextConfiguration) UntypedAnnotationDescriptor(org.springframework.test.util.MetaAnnotationUtils.UntypedAnnotationDescriptor) Test(org.junit.Test)

Example 8 with UntypedAnnotationDescriptor

use of org.springframework.test.util.MetaAnnotationUtils.UntypedAnnotationDescriptor in project spring-framework by spring-projects.

the class MetaAnnotationUtilsTests method findAnnotationDescriptorForTypesWithLocalAndMetaComponentAnnotation.

@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesWithLocalAndMetaComponentAnnotation() throws Exception {
    Class<Component> annotationType = Component.class;
    UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(HasLocalAndMetaComponentAnnotation.class, Transactional.class, annotationType, Order.class);
    assertEquals(HasLocalAndMetaComponentAnnotation.class, descriptor.getRootDeclaringClass());
    assertEquals(annotationType, descriptor.getAnnotationType());
    assertNull(descriptor.getComposedAnnotation());
    assertNull(descriptor.getComposedAnnotationType());
}
Also used : Component(org.springframework.stereotype.Component) UntypedAnnotationDescriptor(org.springframework.test.util.MetaAnnotationUtils.UntypedAnnotationDescriptor) Test(org.junit.Test)

Example 9 with UntypedAnnotationDescriptor

use of org.springframework.test.util.MetaAnnotationUtils.UntypedAnnotationDescriptor in project spring-framework by spring-projects.

the class MetaAnnotationUtilsTests method findAnnotationDescriptorForTypesForNonInheritedAnnotationOnInterface.

@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnInterface() throws Exception {
    // Note: @Order is not inherited.
    Order rawAnnotation = NonInheritedAnnotationInterface.class.getAnnotation(Order.class);
    UntypedAnnotationDescriptor descriptor;
    descriptor = findAnnotationDescriptorForTypes(NonInheritedAnnotationInterface.class, Order.class);
    assertNotNull(descriptor);
    assertEquals(NonInheritedAnnotationInterface.class, descriptor.getRootDeclaringClass());
    assertEquals(NonInheritedAnnotationInterface.class, descriptor.getDeclaringClass());
    assertEquals(rawAnnotation, descriptor.getAnnotation());
    descriptor = findAnnotationDescriptorForTypes(SubNonInheritedAnnotationInterface.class, Order.class);
    assertNotNull(descriptor);
    assertEquals(SubNonInheritedAnnotationInterface.class, descriptor.getRootDeclaringClass());
    assertEquals(NonInheritedAnnotationInterface.class, descriptor.getDeclaringClass());
    assertEquals(rawAnnotation, descriptor.getAnnotation());
}
Also used : Order(org.springframework.core.annotation.Order) UntypedAnnotationDescriptor(org.springframework.test.util.MetaAnnotationUtils.UntypedAnnotationDescriptor) Test(org.junit.Test)

Aggregations

UntypedAnnotationDescriptor (org.springframework.test.util.MetaAnnotationUtils.UntypedAnnotationDescriptor)9 Test (org.junit.Test)8 Component (org.springframework.stereotype.Component)3 Order (org.springframework.core.annotation.Order)2 ContextConfiguration (org.springframework.test.context.ContextConfiguration)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Service (org.springframework.stereotype.Service)1