use of org.apache.dubbo.rpc.AppResponse 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());
}
use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.
the class ExecuteLimitFilterTest method testNoExecuteLimitInvoke.
@Test
public void testNoExecuteLimitInvoke() throws Exception {
Invoker invoker = Mockito.mock(Invoker.class);
when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse("result"));
when(invoker.getUrl()).thenReturn(URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1"));
Invocation invocation = Mockito.mock(Invocation.class);
when(invocation.getMethodName()).thenReturn("testNoExecuteLimitInvoke");
Result result = executeLimitFilter.invoke(invoker, invocation);
Assertions.assertEquals("result", result.getValue());
}
use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.
the class ExecuteLimitFilterTest method testExecuteLimitInvoke.
@Test
public void testExecuteLimitInvoke() throws Exception {
Invoker invoker = Mockito.mock(Invoker.class);
when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse("result"));
when(invoker.getUrl()).thenReturn(URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&executes=10"));
Invocation invocation = Mockito.mock(Invocation.class);
when(invocation.getMethodName()).thenReturn("testExecuteLimitInvoke");
Result result = executeLimitFilter.invoke(invoker, invocation);
Assertions.assertEquals("result", result.getValue());
}
use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.
the class GenericImplFilterTest method testInvokeWith$Invoke.
@Test
public void testInvokeWith$Invoke() throws Exception {
Method genericInvoke = GenericService.class.getMethods()[0];
Map<String, Object> person = new HashMap<String, Object>();
person.put("name", "dubbo");
person.put("age", 10);
RpcInvocation invocation = new RpcInvocation($INVOKE, GenericService.class.getName(), "org.apache.dubbo.rpc.support.DemoService:dubbo", genericInvoke.getParameterTypes(), new Object[] { "getPerson", new String[] { Person.class.getCanonicalName() }, new Object[] { person } });
URL url = URL.valueOf("test://test:11/org.apache.dubbo.rpc.support.DemoService?" + "accesslog=true&group=dubbo&version=1.1&generic=true");
Invoker invoker = Mockito.mock(Invoker.class);
when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse(new Person("person", 10)));
when(invoker.getUrl()).thenReturn(url);
genericImplFilter.invoke(invoker, invocation);
Assertions.assertEquals("true", invocation.getAttachment(GENERIC_KEY));
}
use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.
the class GenericFilterTest method testInvokeWithMethodNamtNot$Invoke.
@Test
public void testInvokeWithMethodNamtNot$Invoke() {
Method genericInvoke = GenericService.class.getMethods()[0];
Map<String, Object> person = new HashMap<String, Object>();
person.put("name", "dubbo");
person.put("age", 10);
RpcInvocation invocation = new RpcInvocation("sayHi", GenericService.class.getName(), "", genericInvoke.getParameterTypes(), new Object[] { "getPerson", new String[] { Person.class.getCanonicalName() }, new Object[] { person } });
URL url = URL.valueOf("test://test:11/org.apache.dubbo.rpc.support.DemoService?" + "accesslog=true&group=dubbo&version=1.1");
Invoker invoker = Mockito.mock(Invoker.class);
when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse(new Person("person", 10)));
when(invoker.getUrl()).thenReturn(url);
when(invoker.getInterface()).thenReturn(DemoService.class);
Result result = genericFilter.invoke(invoker, invocation);
Assertions.assertEquals(Person.class, result.getValue().getClass());
Assertions.assertEquals(10, ((Person) (result.getValue())).getAge());
}
Aggregations