@Test
 public void isAnnotatedOnClassWithMetaDepth2() {
   assertTrue(isAnnotated(ComposedTransactionalComponentClass.class, TX_NAME));
   assertTrue(isAnnotated(ComposedTransactionalComponentClass.class, Component.class.getName()));
   assertTrue(
       isAnnotated(
           ComposedTransactionalComponentClass.class,
           ComposedTransactionalComponent.class.getName()));
 }
 @Test
 public void hasMetaAnnotationTypesOnClassWithMetaDepth2() {
   assertTrue(hasMetaAnnotationTypes(ComposedTransactionalComponentClass.class, TX_NAME));
   assertTrue(
       hasMetaAnnotationTypes(
           ComposedTransactionalComponentClass.class, Component.class.getName()));
   assertFalse(
       hasMetaAnnotationTypes(
           ComposedTransactionalComponentClass.class,
           ComposedTransactionalComponent.class.getName()));
 }
 @Test
 public void getMergedAnnotationAttributesFavorsLocalComposedAnnotationOverInheritedAnnotation() {
   Class<?> element = SubClassWithInheritedAnnotation.class;
   String name = TX_NAME;
   AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name);
   assertNotNull(
       "AnnotationAttributes for @Transactional on SubClassWithInheritedAnnotation", attributes);
   // Verify contracts between utility methods:
   assertTrue(isAnnotated(element, name));
   assertTrue(
       "readOnly flag for SubClassWithInheritedAnnotation.", attributes.getBoolean("readOnly"));
 }
예제 #4
0
  @Test
  public void buildNodeTree() throws Exception {

    SortingNode<String> root = new SortingNode.Builder<String>().build();
    assertFalse(root.hasChild());
    assertTrue(root.isRoot());
    assertFalse(root.hasParent());

    SortingNode<Integer> tree =
        new SortingNode.Builder<Integer>() //
            .childNode(100)
            .siblingNode(200)
            .childNode(210)
            .siblingNode(220)
            .parent()
            .siblingNode(300)
            .siblingNode(400)
            .childNode(410)
            .siblingNode(420)
            .siblingNode(430)
            .childNode(431)
            .build();

    assertFalse(tree.hasParent());
    assertTrue(tree.isRoot());
    assertFalse(tree.hasParent());

    String expected =
        ""
            + "*\n"
            + "  100\n"
            + "  200\n"
            + "    210\n"
            + "    220\n"
            + "  300\n"
            + "  400\n"
            + "    410\n"
            + "    420\n"
            + "    430\n"
            + "      431";
    assertEquals(expected, tree.prettyPrint());

    SortingNode<Integer> n410 = tree.getChildren().get(3).getChildren().get(0);
    assertFalse(n410.hasChild());
    assertTrue(n410.hasParent());
    assertFalse(n410.isRoot());

    assertEquals("410", n410.prettyPrint());
  }
예제 #5
0
 @Test
 public void emptyRoot() throws Exception {
   SortingNode<Long> emptyRoot = SortingNode.emptyRoot();
   assertFalse(emptyRoot.hasChild());
   assertTrue(emptyRoot.isRoot());
   assertFalse(emptyRoot.hasParent());
 }
 @Test
 public void getMergedAnnotationAttributesOnNonInheritedAnnotationInterface() {
   Class<?> element = NonInheritedAnnotationInterface.class;
   String name = Order.class.getName();
   AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name);
   assertNotNull("Should find @Order on NonInheritedAnnotationInterface", attributes);
   // Verify contracts between utility methods:
   assertTrue(isAnnotated(element, name));
 }
 @Test
 public void getMergedAnnotationAttributesOnInheritedAnnotationInterface() {
   Class<?> element = InheritedAnnotationInterface.class;
   String name = TX_NAME;
   AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name);
   assertNotNull("Should find @Transactional on InheritedAnnotationInterface", attributes);
   // Verify contracts between utility methods:
   assertTrue(isAnnotated(element, name));
 }
 @Test
 public void getMergedAnnotationAttributesOnClassWithLocalAnnotation() {
   Class<?> element = TxConfig.class;
   String name = TX_NAME;
   AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name);
   assertNotNull("Annotation attributes for @Transactional on TxConfig", attributes);
   assertEquals("value for TxConfig.", "TxConfig", attributes.getString("value"));
   // Verify contracts between utility methods:
   assertTrue(isAnnotated(element, name));
 }
  private void assertGetMergedAnnotation(Class<?> element, String... expected) {
    String name = ContextConfig.class.getName();
    ContextConfig contextConfig = getMergedAnnotation(element, ContextConfig.class);

    assertNotNull("Should find @ContextConfig on " + element.getSimpleName(), contextConfig);
    assertArrayEquals("locations", expected, contextConfig.locations());
    assertArrayEquals("value", expected, contextConfig.value());
    assertArrayEquals("classes", new Class<?>[0], contextConfig.classes());

    // Verify contracts between utility methods:
    assertTrue(isAnnotated(element, name));
  }
  @Test
  public void getMergedAnnotationAttributesWithAliasedValueComposedAnnotation() {
    Class<?> element = AliasedValueComposedContextConfigClass.class;
    String name = ContextConfig.class.getName();
    AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name);

    assertNotNull("Should find @ContextConfig on " + element.getSimpleName(), attributes);
    assertArrayEquals("locations", asArray("test.xml"), attributes.getStringArray("locations"));
    assertArrayEquals("value", asArray("test.xml"), attributes.getStringArray("value"));

    // Verify contracts between utility methods:
    assertTrue(isAnnotated(element, name));
  }
  /**
   * Bridge/bridged method setup code copied from {@link
   * org.springframework.core.BridgeMethodResolverTests#testWithGenericParameter()}.
   *
   * @since 4.2
   */
  @Test
  public void findMergedAnnotationAttributesFromBridgeMethod() throws NoSuchMethodException {
    Method[] methods = StringGenericParameter.class.getMethods();
    Method bridgeMethod = null;
    Method bridgedMethod = null;

    for (Method method : methods) {
      if ("getFor".equals(method.getName())
          && !method.getParameterTypes()[0].equals(Integer.class)) {
        if (method.getReturnType().equals(Object.class)) {
          bridgeMethod = method;
        } else {
          bridgedMethod = method;
        }
      }
    }
    assertTrue(bridgeMethod != null && bridgeMethod.isBridge());
    assertTrue(bridgedMethod != null && !bridgedMethod.isBridge());

    AnnotationAttributes attributes = findMergedAnnotationAttributes(bridgeMethod, Order.class);
    assertNotNull(
        "Should find @Order on StringGenericParameter.getFor() bridge method", attributes);
  }
  @Test
  public void getMergedAnnotationWithImplicitAliasesInMetaAnnotationOnComposedAnnotation() {
    Class<?> element = ComposedImplicitAliasesContextConfigClass.class;
    String name = ImplicitAliasesContextConfig.class.getName();
    ImplicitAliasesContextConfig config =
        getMergedAnnotation(element, ImplicitAliasesContextConfig.class);
    String[] expected = asArray("A.xml", "B.xml");

    assertNotNull(
        "Should find @ImplicitAliasesContextConfig on " + element.getSimpleName(), config);
    assertArrayEquals("groovyScripts", expected, config.groovyScripts());
    assertArrayEquals("xmlFiles", expected, config.xmlFiles());
    assertArrayEquals("locations", expected, config.locations());
    assertArrayEquals("value", expected, config.value());

    // Verify contracts between utility methods:
    assertTrue(isAnnotated(element, name));
  }
  private void getMergedAnnotationAttributesWithHalfConventionBasedAndHalfAliasedComposedAnnotation(
      Class<?> clazz) {
    String[] expected = asArray("explicitDeclaration");
    String name = ContextConfig.class.getName();
    String simpleName = clazz.getSimpleName();
    AnnotationAttributes attributes = getMergedAnnotationAttributes(clazz, name);

    assertNotNull("Should find @ContextConfig on " + simpleName, attributes);
    assertArrayEquals(
        "locations for class [" + clazz.getSimpleName() + "]",
        expected,
        attributes.getStringArray("locations"));
    assertArrayEquals(
        "value for class [" + clazz.getSimpleName() + "]",
        expected,
        attributes.getStringArray("value"));

    // Verify contracts between utility methods:
    assertTrue(isAnnotated(clazz, name));
  }
 @Test
 public void isAnnotatedOnClassWithMetaDepth0() {
   assertTrue(
       isAnnotated(TransactionalComponentClass.class, TransactionalComponent.class.getName()));
 }