@Test
public void testRpcException() throws XmppException {
MockServer mockServer = new MockServer();
XmppSession xmppSession1 = new TestXmppSession(ROMEO, mockServer);
XmppSession xmppSession2 = new TestXmppSession(JULIET, mockServer);
RpcManager rpcManager = xmppSession1.getExtensionManager(RpcManager.class);
rpcManager.setEnabled(true);
rpcManager.executorService = new SameThreadExecutorService();
rpcManager.setRpcHandler(new RpcHandler() {
@Override
public Value process(Jid requester, String methodName, List<Value> parameters) throws RpcException {
if (methodName.equals("fault")) {
throw new RpcException(2, "faulty");
}
return null;
}
});
try {
xmppSession2.getExtensionManager(RpcManager.class).call(ROMEO, "fault", new Value(2));
} catch (RpcException e) {
Assert.assertEquals(e.getFaultCode(), 2);
Assert.assertEquals(e.getFaultString(), "faulty");
return;
}