use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.
the class MergeableClusterInvokerTest method testAddMenu.
@Test
public void testAddMenu() throws Exception {
String menu = "first";
List<String> menuItems = new ArrayList<String>() {
{
add("1");
add("2");
}
};
given(invocation.getMethodName()).willReturn("addMenu");
given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class, List.class });
given(invocation.getArguments()).willReturn(new Object[] { menu, menuItems });
given(invocation.getObjectAttachments()).willReturn(new HashMap<>());
given(invocation.getInvoker()).willReturn(firstInvoker);
given(firstInvoker.getUrl()).willReturn(url.addParameter(GROUP_KEY, "first"));
given(firstInvoker.getInterface()).willReturn(MenuService.class);
given(firstInvoker.invoke(invocation)).willReturn(new AppResponse());
given(firstInvoker.isAvailable()).willReturn(true);
given(secondInvoker.getUrl()).willReturn(url.addParameter(GROUP_KEY, "second"));
given(secondInvoker.getInterface()).willReturn(MenuService.class);
given(secondInvoker.invoke(invocation)).willReturn(new AppResponse());
given(secondInvoker.isAvailable()).willReturn(true);
given(directory.list(invocation)).willReturn(new ArrayList() {
{
add(firstInvoker);
add(secondInvoker);
}
});
given(directory.getUrl()).willReturn(url);
given(directory.getConsumerUrl()).willReturn(url);
given(directory.getConsumerUrl()).willReturn(url);
given(directory.getInterface()).willReturn(MenuService.class);
mergeableClusterInvoker = new MergeableClusterInvoker<MenuService>(directory);
Result result = mergeableClusterInvoker.invoke(invocation);
Assertions.assertNull(result.getValue());
}
use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.
the class ValidationFilterTest method testItWithNotExistClass.
@Test
public void testItWithNotExistClass() throws Exception {
URL url = URL.valueOf("test://test:11/test?validation=true");
given(validation.getValidator(url)).willThrow(new IllegalStateException("Not found class test, cause: test"));
given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
given(invoker.getUrl()).willReturn(url);
given(invocation.getMethodName()).willReturn("echo1");
given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class });
given(invocation.getArguments()).willReturn(new Object[] { "arg1" });
validationFilter.setValidation(validation);
Result result = validationFilter.invoke(invoker, invocation);
assertThat(result.getException().getMessage(), is("Not found class test, cause: test"));
}
use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.
the class ValidationFilterTest method testItWithoutUrlParameters.
@Test
public void testItWithoutUrlParameters() throws Exception {
URL url = URL.valueOf("test://test:11/test");
given(validation.getValidator(url)).willReturn(validator);
given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
given(invoker.getUrl()).willReturn(url);
given(invocation.getMethodName()).willReturn("echo1");
given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class });
given(invocation.getArguments()).willReturn(new Object[] { "arg1" });
validationFilter.setValidation(validation);
Result result = validationFilter.invoke(invoker, invocation);
assertThat(String.valueOf(result.getValue()), is("success"));
}
use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.
the class ValidationFilterTest method testItWhileThrowoutRpcException.
@Test
public void testItWhileThrowoutRpcException() throws Exception {
Assertions.assertThrows(RpcException.class, () -> {
URL url = URL.valueOf("test://test:11/test?validation=true");
given(validation.getValidator(url)).willThrow(new RpcException("rpc exception"));
given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
given(invoker.getUrl()).willReturn(url);
given(invocation.getMethodName()).willReturn("echo1");
given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class });
given(invocation.getArguments()).willReturn(new Object[] { "arg1" });
validationFilter.setValidation(validation);
validationFilter.invoke(invoker, invocation);
});
}
use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.
the class FutureFilterTest method testSyncCallback.
@Test
public void testSyncCallback() {
@SuppressWarnings("unchecked") 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 = eventFilter.invoke(invoker, invocation);
assertEquals("High", filterResult.getValue());
}
Aggregations