コード例 #1
0
  @Test
  public void findAndSynthesizeAnnotationAttributesOnClassWithAttributeAliasesInTargetAnnotation() {
    String qualifier = "aliasForQualifier";

    // 1) Find and merge AnnotationAttributes from the annotation hierarchy
    AnnotationAttributes attributes =
        findMergedAnnotationAttributes(
            AliasedTransactionalComponentClass.class, AliasedTransactional.class);
    assertNotNull("@AliasedTransactional on AliasedTransactionalComponentClass.", attributes);

    // 2) Synthesize the AnnotationAttributes back into the target annotation
    AliasedTransactional annotation =
        AnnotationUtils.synthesizeAnnotation(
            attributes, AliasedTransactional.class, AliasedTransactionalComponentClass.class);
    assertNotNull(annotation);

    // 3) Verify that the AnnotationAttributes and synthesized annotation are equivalent
    assertEquals("TX value via attributes.", qualifier, attributes.getString("value"));
    assertEquals("TX value via synthesized annotation.", qualifier, annotation.value());
    assertEquals("TX qualifier via attributes.", qualifier, attributes.getString("qualifier"));
    assertEquals("TX qualifier via synthesized annotation.", qualifier, annotation.qualifier());
  }
コード例 #2
0
  @Test
  public void findMergedAnnotationForMultipleMetaAnnotationsWithClashingAttributeNames() {
    String[] xmlLocations = asArray("test.xml");
    String[] propFiles = asArray("test.properties");

    Class<?> element = AliasedComposedContextConfigAndTestPropSourceClass.class;

    ContextConfig contextConfig = findMergedAnnotation(element, ContextConfig.class);
    assertNotNull("@ContextConfig on " + element, contextConfig);
    assertArrayEquals("locations", xmlLocations, contextConfig.locations());
    assertArrayEquals("value", xmlLocations, contextConfig.value());

    // Synthesized annotation
    TestPropSource testPropSource = AnnotationUtils.findAnnotation(element, TestPropSource.class);
    assertArrayEquals("locations", propFiles, testPropSource.locations());
    assertArrayEquals("value", propFiles, testPropSource.value());

    // Merged annotation
    testPropSource = findMergedAnnotation(element, TestPropSource.class);
    assertNotNull("@TestPropSource on " + element, testPropSource);
    assertArrayEquals("locations", propFiles, testPropSource.locations());
    assertArrayEquals("value", propFiles, testPropSource.value());
  }