Search in sources :

Example 1 with MethodConfig

use of org.apache.dubbo.config.MethodConfig in project dubbo by alibaba.

the class ReferenceBuilderTest method build.

@Test
void build() {
    ConsumerConfig consumer = new ConsumerConfig();
    MethodConfig method = new MethodConfig();
    ReferenceBuilder<DemoService> builder = new ReferenceBuilder<>();
    builder.id("id").interfaceClass(DemoService.class).protocol("protocol").client("client").url("url").consumer(consumer).addMethod(method).services("test-service", "test-service2");
    ReferenceConfig config = builder.build();
    ReferenceConfig config2 = builder.build();
    Assertions.assertEquals("org.apache.dubbo.config.api.DemoService", config.getInterface());
    Assertions.assertEquals(DemoService.class, config.getInterfaceClass());
    Assertions.assertEquals("protocol", config.getProtocol());
    Assertions.assertEquals("client", config.getClient());
    Assertions.assertEquals("url", config.getUrl());
    Assertions.assertEquals(consumer, config.getConsumer());
    Assertions.assertEquals("test-service,test-service2", config.getServices());
    Assertions.assertEquals(ofSet("test-service", "test-service2"), config.getSubscribedServices());
    Assertions.assertTrue(config.getMethods().contains(method));
    Assertions.assertEquals(1, config.getMethods().size());
    Assertions.assertNotSame(config, config2);
}
Also used : MethodConfig(org.apache.dubbo.config.MethodConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.config.api.DemoService) ConsumerConfig(org.apache.dubbo.config.ConsumerConfig) Test(org.junit.jupiter.api.Test)

Example 2 with MethodConfig

use of org.apache.dubbo.config.MethodConfig in project dubbo by alibaba.

the class ReferenceBuilderTest method addMethod.

@Test
void addMethod() {
    MethodConfig method = new MethodConfig();
    ReferenceBuilder builder = new ReferenceBuilder();
    builder.addMethod(method);
    Assertions.assertTrue(builder.build().getMethods().contains(method));
    Assertions.assertEquals(1, builder.build().getMethods().size());
}
Also used : MethodConfig(org.apache.dubbo.config.MethodConfig) Test(org.junit.jupiter.api.Test)

Example 3 with MethodConfig

use of org.apache.dubbo.config.MethodConfig in project dubbo by alibaba.

the class ServiceBuilderTest method build.

// 
// @Test
// public void Mock() throws Exception {
// Assertions.assertThrows(IllegalArgumentException.class, () -> {
// ServiceBuilder builder = new ServiceBuilder();
// builder.mock("true");
// });
// }
// 
// @Test
// public void Mock1() throws Exception {
// Assertions.assertThrows(IllegalArgumentException.class, () -> {
// ServiceBuilder builder = new ServiceBuilder();
// builder.mock(true);
// });
// }
@Test
void build() {
    MethodConfig method = new MethodConfig();
    ProviderConfig provider = new ProviderConfig();
    ServiceBuilder builder = new ServiceBuilder();
    builder.path("path").addMethod(method).provider(provider).providerIds("providerIds").generic(GENERIC_SERIALIZATION_DEFAULT);
    ServiceConfig config = builder.build();
    ServiceConfig config2 = builder.build();
    assertThat(config.getGeneric(), equalTo(GENERIC_SERIALIZATION_DEFAULT));
    Assertions.assertEquals("path", config.getPath());
    Assertions.assertEquals("providerIds", config.getProviderIds());
    Assertions.assertSame(provider, config.getProvider());
    Assertions.assertTrue(config.getMethods().contains(method));
    Assertions.assertEquals(1, config.getMethods().size());
    Assertions.assertNotSame(config, config2);
}
Also used : MethodConfig(org.apache.dubbo.config.MethodConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ProviderConfig(org.apache.dubbo.config.ProviderConfig) Test(org.junit.jupiter.api.Test)

Example 4 with MethodConfig

use of org.apache.dubbo.config.MethodConfig in project dubbo by alibaba.

the class ServiceBuilderTest method addMethod.

@Test
void addMethod() {
    MethodConfig method = new MethodConfig();
    ServiceBuilder builder = new ServiceBuilder();
    builder.addMethod(method);
    Assertions.assertTrue(builder.build().getMethods().contains(method));
    Assertions.assertEquals(1, builder.build().getMethods().size());
}
Also used : MethodConfig(org.apache.dubbo.config.MethodConfig) Test(org.junit.jupiter.api.Test)

Example 5 with MethodConfig

use of org.apache.dubbo.config.MethodConfig in project dubbo by alibaba.

the class ReferenceBeanBuilder method configureMethodConfig.

void configureMethodConfig(AnnotationAttributes attributes, ReferenceBean<?> referenceBean) {
    Method[] methods = (Method[]) attributes.get("methods");
    List<MethodConfig> methodConfigs = MethodConfig.constructMethodConfig(methods);
    for (MethodConfig methodConfig : methodConfigs) {
        if (!StringUtils.isEmpty(methodConfig.getOninvoke())) {
            Object invokeRef = this.applicationContext.getBean((String) methodConfig.getOninvoke());
            methodConfig.setOninvoke(invokeRef);
        }
        if (!StringUtils.isEmpty(methodConfig.getOnreturn())) {
            Object returnRef = this.applicationContext.getBean((String) methodConfig.getOnreturn());
            methodConfig.setOnreturn(returnRef);
        }
        if (!StringUtils.isEmpty(methodConfig.getOnthrow())) {
            Object throwRef = this.applicationContext.getBean((String) methodConfig.getOnthrow());
            methodConfig.setOnthrow(throwRef);
        }
    }
    if (!methodConfigs.isEmpty()) {
        referenceBean.setMethods(methodConfigs);
    }
}
Also used : MethodConfig(org.apache.dubbo.config.MethodConfig) Method(org.apache.dubbo.config.annotation.Method)

Aggregations

MethodConfig (org.apache.dubbo.config.MethodConfig)13 Test (org.junit.jupiter.api.Test)7 RegistryConfig (org.apache.dubbo.config.RegistryConfig)3 DemoService (org.apache.dubbo.config.api.DemoService)3 ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)2 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)2 ProviderConfig (org.apache.dubbo.config.ProviderConfig)2 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)2 ServiceConfig (org.apache.dubbo.config.ServiceConfig)2 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)1 ArgumentConfig (org.apache.dubbo.config.ArgumentConfig)1 Method (org.apache.dubbo.config.annotation.Method)1 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)1 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)1 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)1 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)1