Search in sources :

Example 1 with Adaptive

use of org.apache.dubbo.common.extension.Adaptive in project dubbo by alibaba.

the class AnnotationUtilsTest method testGetValue.

@Test
public void testGetValue() {
    Adaptive adaptive = A.class.getAnnotation(Adaptive.class);
    String[] value = getValue(adaptive);
    assertEquals(asList("a", "b", "c"), asList(value));
}
Also used : Adaptive(org.apache.dubbo.common.extension.Adaptive) Test(org.junit.jupiter.api.Test)

Example 2 with Adaptive

use of org.apache.dubbo.common.extension.Adaptive in project dubbo by alibaba.

the class AnnotationUtilsTest method assertADeclaredAnnotations.

private void assertADeclaredAnnotations(List<Annotation> annotations, int offset) {
    int size = 3 + offset;
    assertEquals(size, annotations.size());
    Service service = (Service) annotations.get(offset++);
    assertEquals("java.lang.CharSequence", service.interfaceName());
    assertEquals(CharSequence.class, service.interfaceClass());
    com.alibaba.dubbo.config.annotation.Service s = (com.alibaba.dubbo.config.annotation.Service) annotations.get(offset++);
    assertEquals("java.lang.CharSequence", service.interfaceName());
    assertEquals(CharSequence.class, service.interfaceClass());
    Adaptive adaptive = (Adaptive) annotations.get(offset++);
    assertArrayEquals(new String[] { "a", "b", "c" }, adaptive.value());
}
Also used : Adaptive(org.apache.dubbo.common.extension.Adaptive) Service(org.apache.dubbo.config.annotation.Service) DubboService(org.apache.dubbo.config.annotation.DubboService)

Example 3 with Adaptive

use of org.apache.dubbo.common.extension.Adaptive in project dubbo by alibaba.

the class AnnotationUtilsTest method testGetAllDeclaredAnnotations.

@Test
public void testGetAllDeclaredAnnotations() {
    List<Annotation> annotations = getAllDeclaredAnnotations(A.class);
    assertADeclaredAnnotations(annotations, 0);
    annotations = getAllDeclaredAnnotations(B.class);
    assertTrue(isSameType(annotations.get(0), Service5.class));
    assertADeclaredAnnotations(annotations, 1);
    annotations = new LinkedList<>(getAllDeclaredAnnotations(C.class));
    assertTrue(isSameType(annotations.get(0), MyAdaptive.class));
    assertTrue(isSameType(annotations.get(1), Service5.class));
    assertADeclaredAnnotations(annotations, 2);
    annotations = getAllDeclaredAnnotations(findMethod(A.class, "execute"));
    MyAdaptive myAdaptive = (MyAdaptive) annotations.get(0);
    assertArrayEquals(new String[] { "e" }, myAdaptive.value());
    annotations = getAllDeclaredAnnotations(findMethod(B.class, "execute"));
    Adaptive adaptive = (Adaptive) annotations.get(0);
    assertArrayEquals(new String[] { "f" }, adaptive.value());
}
Also used : Adaptive(org.apache.dubbo.common.extension.Adaptive) AnnotationUtils.findMetaAnnotation(org.apache.dubbo.common.utils.AnnotationUtils.findMetaAnnotation) AnnotationUtils.getAnnotation(org.apache.dubbo.common.utils.AnnotationUtils.getAnnotation) Annotation(java.lang.annotation.Annotation) AnnotationUtils.findAnnotation(org.apache.dubbo.common.utils.AnnotationUtils.findAnnotation) Test(org.junit.jupiter.api.Test)

Aggregations

Adaptive (org.apache.dubbo.common.extension.Adaptive)3 Test (org.junit.jupiter.api.Test)2 Annotation (java.lang.annotation.Annotation)1 AnnotationUtils.findAnnotation (org.apache.dubbo.common.utils.AnnotationUtils.findAnnotation)1 AnnotationUtils.findMetaAnnotation (org.apache.dubbo.common.utils.AnnotationUtils.findMetaAnnotation)1 AnnotationUtils.getAnnotation (org.apache.dubbo.common.utils.AnnotationUtils.getAnnotation)1 DubboService (org.apache.dubbo.config.annotation.DubboService)1 Service (org.apache.dubbo.config.annotation.Service)1