Search in sources :

Example 1 with UntypedAnnotationDescriptor

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

the class MetaAnnotationUtilsTests method findAnnotationDescriptorForTypesOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation.

/**
	 * @since 4.0.3
	 */
@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() {
    UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(MetaCycleAnnotatedClass.class, Service.class, Component.class, Order.class);
    assertNull("Should not find @Component on MetaCycleAnnotatedClass", descriptor);
}
Also used : UntypedAnnotationDescriptor(org.springframework.test.util.MetaAnnotationUtils.UntypedAnnotationDescriptor) Test(org.junit.Test)

Example 2 with UntypedAnnotationDescriptor

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

the class MetaAnnotationUtilsTests method assertAtComponentOnComposedAnnotationForMultipleCandidateTypes.

@SuppressWarnings("unchecked")
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass, Class<?> rootDeclaringClass, Class<?> declaringClass, String name, Class<? extends Annotation> composedAnnotationType) {
    Class<Component> annotationType = Component.class;
    UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class, annotationType, Order.class, Transactional.class);
    assertNotNull("UntypedAnnotationDescriptor should not be null", descriptor);
    assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass());
    assertEquals("declaringClass", declaringClass, descriptor.getDeclaringClass());
    assertEquals("annotationType", annotationType, descriptor.getAnnotationType());
    assertEquals("component name", name, ((Component) descriptor.getAnnotation()).value());
    assertNotNull("composedAnnotation should not be null", descriptor.getComposedAnnotation());
    assertEquals("composedAnnotationType", composedAnnotationType, descriptor.getComposedAnnotationType());
}
Also used : Component(org.springframework.stereotype.Component) UntypedAnnotationDescriptor(org.springframework.test.util.MetaAnnotationUtils.UntypedAnnotationDescriptor)

Example 3 with UntypedAnnotationDescriptor

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

the class MetaAnnotationUtilsTests method findAnnotationDescriptorForTypesOnAnnotatedClassWithMissingTargetMetaAnnotation.

/**
	 * @since 4.0.3
	 */
@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesOnAnnotatedClassWithMissingTargetMetaAnnotation() {
    // InheritedAnnotationClass is NOT annotated or meta-annotated with @Component,
    // @Service, or @Order, but it is annotated with @Transactional.
    UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(InheritedAnnotationClass.class, Service.class, Component.class, Order.class);
    assertNull("Should not find @Component on InheritedAnnotationClass", descriptor);
}
Also used : UntypedAnnotationDescriptor(org.springframework.test.util.MetaAnnotationUtils.UntypedAnnotationDescriptor) Test(org.junit.Test)

Example 4 with UntypedAnnotationDescriptor

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

the class MetaAnnotationUtilsTests method findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes.

@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes() throws Exception {
    Class<?> startClass = MetaConfigWithDefaultAttributesTestCase.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[] { MetaConfig.DevConfig.class, MetaConfig.ProductionConfig.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 5 with UntypedAnnotationDescriptor

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

the class MetaAnnotationUtilsTests method findAnnotationDescriptorForTypesWithInheritedAnnotationOnInterface.

@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnInterface() throws Exception {
    // Note: @Transactional is inherited
    Transactional rawAnnotation = InheritedAnnotationInterface.class.getAnnotation(Transactional.class);
    UntypedAnnotationDescriptor descriptor;
    descriptor = findAnnotationDescriptorForTypes(InheritedAnnotationInterface.class, Transactional.class);
    assertNotNull(descriptor);
    assertEquals(InheritedAnnotationInterface.class, descriptor.getRootDeclaringClass());
    assertEquals(InheritedAnnotationInterface.class, descriptor.getDeclaringClass());
    assertEquals(rawAnnotation, descriptor.getAnnotation());
    descriptor = findAnnotationDescriptorForTypes(SubInheritedAnnotationInterface.class, Transactional.class);
    assertNotNull(descriptor);
    assertEquals(SubInheritedAnnotationInterface.class, descriptor.getRootDeclaringClass());
    assertEquals(InheritedAnnotationInterface.class, descriptor.getDeclaringClass());
    assertEquals(rawAnnotation, descriptor.getAnnotation());
    descriptor = findAnnotationDescriptorForTypes(SubSubInheritedAnnotationInterface.class, Transactional.class);
    assertNotNull(descriptor);
    assertEquals(SubSubInheritedAnnotationInterface.class, descriptor.getRootDeclaringClass());
    assertEquals(InheritedAnnotationInterface.class, descriptor.getDeclaringClass());
    assertEquals(rawAnnotation, descriptor.getAnnotation());
}
Also used : Transactional(org.springframework.transaction.annotation.Transactional) 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