use of org.apache.dubbo.rpc.support.DemoService in project dubbo by alibaba.
the class AbstractProxyTest method testGetProxy.
@Test
public void testGetProxy() throws Exception {
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
Invoker<DemoService> invoker = new MyInvoker<>(url);
DemoService proxy = factory.getProxy(invoker);
Assertions.assertNotNull(proxy);
Assertions.assertTrue(Arrays.asList(proxy.getClass().getInterfaces()).contains(DemoService.class));
// Not equal
// Assertions.assertEquals(proxy.toString(), invoker.toString());
// Assertions.assertEquals(proxy.hashCode(), invoker.hashCode());
Assertions.assertEquals(invoker.invoke(new RpcInvocation("echo", DemoService.class.getName(), DemoService.class.getName() + ":dubbo", new Class[] { String.class }, new Object[] { "aa" })).getValue(), proxy.echo("aa"));
}
use of org.apache.dubbo.rpc.support.DemoService in project dubbo by alibaba.
the class ExceptionFilterTest method testRuntimeException.
@SuppressWarnings("unchecked")
@Test
public void testRuntimeException() {
ExceptionFilter exceptionFilter = new ExceptionFilter();
RpcInvocation invocation = new RpcInvocation("sayHello", DemoService.class.getName(), "", new Class<?>[] { String.class }, new Object[] { "world" });
AppResponse appResponse = new AppResponse();
appResponse.setException(new LocalException("localException"));
Invoker<DemoService> invoker = mock(Invoker.class);
when(invoker.invoke(invocation)).thenReturn(appResponse);
when(invoker.getInterface()).thenReturn(DemoService.class);
Result newResult = exceptionFilter.invoke(invoker, invocation);
Assertions.assertEquals(appResponse.getException(), newResult.getException());
}
use of org.apache.dubbo.rpc.support.DemoService in project dubbo by alibaba.
the class ExceptionFilterTest method testJavaException.
@SuppressWarnings("unchecked")
@Test
public void testJavaException() {
ExceptionFilter exceptionFilter = new ExceptionFilter();
RpcInvocation invocation = new RpcInvocation("sayHello", DemoService.class.getName(), "", new Class<?>[] { String.class }, new Object[] { "world" });
AppResponse appResponse = new AppResponse();
appResponse.setException(new IllegalArgumentException("java"));
Invoker<DemoService> invoker = mock(Invoker.class);
when(invoker.invoke(invocation)).thenReturn(appResponse);
when(invoker.getInterface()).thenReturn(DemoService.class);
Result newResult = exceptionFilter.invoke(invoker, invocation);
Assertions.assertEquals(appResponse.getException(), newResult.getException());
}
use of org.apache.dubbo.rpc.support.DemoService in project dubbo by alibaba.
the class ContextFilterTest method testWithAttachments.
@Test
public void testWithAttachments() {
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
Invoker<DemoService> invoker = new MyInvoker<DemoService>(url);
Invocation invocation = new MockInvocation();
Result result = contextFilter.invoke(invoker, invocation);
assertNull(RpcContext.getContext().getInvoker());
}
use of org.apache.dubbo.rpc.support.DemoService in project dubbo by alibaba.
the class EchoFilterTest method testNonEcho.
@SuppressWarnings("unchecked")
@Test
public void testNonEcho() {
Invocation invocation = mock(Invocation.class);
given(invocation.getMethodName()).willReturn("echo");
given(invocation.getParameterTypes()).willReturn(new Class<?>[] { Enum.class });
given(invocation.getArguments()).willReturn(new Object[] { "hello" });
given(invocation.getObjectAttachments()).willReturn(null);
Invoker<DemoService> invoker = mock(Invoker.class);
given(invoker.isAvailable()).willReturn(true);
given(invoker.getInterface()).willReturn(DemoService.class);
AppResponse result = new AppResponse();
result.setValue("High");
given(invoker.invoke(invocation)).willReturn(result);
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
given(invoker.getUrl()).willReturn(url);
Result filterResult = echoFilter.invoke(invoker, invocation);
assertEquals("High", filterResult.getValue());
}
Aggregations