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);
}
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());
}
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);
}
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());
}
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);
}
}
Aggregations