Search in sources :

Example 1 with DubboReference

use of org.apache.dubbo.config.annotation.DubboReference in project dubbo by alibaba.

the class ReferenceBeanBuilderTest method testBuild.

@Test
public void testBuild() throws Exception {
    DubboReference reference = findAnnotation(findField(getClass(), "TEST_FIELD"), DubboReference.class);
    AnnotationAttributes attributes = AnnotationUtils.getAnnotationAttributes(reference, false, false);
    ReferenceBeanBuilder beanBuilder = ReferenceBeanBuilder.create(attributes, context);
    beanBuilder.interfaceClass(CharSequence.class);
    ReferenceBean referenceBean = beanBuilder.build();
    Assertions.assertEquals(CharSequence.class, referenceBean.getInterfaceClass());
    Assertions.assertEquals("1.0.0", referenceBean.getVersion());
    Assertions.assertEquals("TEST_GROUP", referenceBean.getGroup());
    Assertions.assertEquals("dubbo://localhost:12345", referenceBean.getUrl());
    Assertions.assertEquals("client", referenceBean.getClient());
    Assertions.assertEquals(true, referenceBean.isGeneric());
    Assertions.assertTrue(referenceBean.isInjvm());
    Assertions.assertEquals(false, referenceBean.isCheck());
    Assertions.assertFalse(referenceBean.isInit());
    Assertions.assertEquals(true, referenceBean.getLazy());
    Assertions.assertEquals(true, referenceBean.getStubevent());
    Assertions.assertEquals("reconnect", referenceBean.getReconnect());
    Assertions.assertEquals(true, referenceBean.getSticky());
    Assertions.assertEquals("javassist", referenceBean.getProxy());
    Assertions.assertEquals("java.lang.CharSequence", referenceBean.getStub());
    Assertions.assertEquals("failover", referenceBean.getCluster());
    Assertions.assertEquals(Integer.valueOf(3), referenceBean.getConnections());
    Assertions.assertEquals(Integer.valueOf(1), referenceBean.getCallbacks());
    Assertions.assertEquals("onconnect", referenceBean.getOnconnect());
    Assertions.assertEquals("ondisconnect", referenceBean.getOndisconnect());
    Assertions.assertEquals("owner", referenceBean.getOwner());
    Assertions.assertEquals("layer", referenceBean.getLayer());
    Assertions.assertEquals(Integer.valueOf(1), referenceBean.getRetries());
    Assertions.assertEquals("random", referenceBean.getLoadbalance());
    Assertions.assertEquals(true, referenceBean.isAsync());
    Assertions.assertEquals(Integer.valueOf(3), referenceBean.getActives());
    Assertions.assertEquals(true, referenceBean.getSent());
    Assertions.assertEquals("mock", referenceBean.getMock());
    Assertions.assertEquals("validation", referenceBean.getValidation());
    Assertions.assertEquals(Integer.valueOf(3), referenceBean.getTimeout());
    Assertions.assertEquals("cache", referenceBean.getCache());
    Assertions.assertEquals("echo,generic,accesslog", referenceBean.getFilter());
    Assertions.assertEquals("deprecated", referenceBean.getListener());
    Assertions.assertEquals("reference", referenceBean.getId());
    Assertions.assertEquals(ofSet("service1", "service2", "service3"), referenceBean.getSubscribedServices());
    Assertions.assertEquals("service1,service2,service3", referenceBean.getProvidedBy());
    Assertions.assertEquals("fastjson", referenceBean.getSerialization());
    // parameters
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("n1", "v1");
    parameters.put("n2", "v2");
    parameters.put("n3", "v3");
    Assertions.assertEquals(parameters, referenceBean.getParameters());
    // Asserts Null fields
    Assertions.assertThrows(IllegalStateException.class, () -> referenceBean.getApplication());
    Assertions.assertNull(referenceBean.getModule());
    Assertions.assertNull(referenceBean.getConsumer());
    Assertions.assertNull(referenceBean.getMonitor());
    Assertions.assertEquals(Collections.emptyList(), referenceBean.getRegistries());
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) DubboReference(org.apache.dubbo.config.annotation.DubboReference) HashMap(java.util.HashMap) ReferenceBean(org.apache.dubbo.config.spring.ReferenceBean) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)1 DubboReference (org.apache.dubbo.config.annotation.DubboReference)1 ReferenceBean (org.apache.dubbo.config.spring.ReferenceBean)1 Test (org.junit.jupiter.api.Test)1 AnnotationAttributes (org.springframework.core.annotation.AnnotationAttributes)1