use of org.jowidgets.invocation.common.api.IMethod in project jo-client-platform by jo-source.
the class InvocationIntegrationTest method testExceptionAfterFinsihed.
@Test
public void testExceptionAfterFinsihed() {
JUnitLoggerProvider.getConsoleLoggerEnablement().setEnabled(false);
final String methodName = "Method";
final String methodResult = "Result";
final RuntimeException expectedException = new RuntimeException("Something goes wrong");
final Integer invocationId = Integer.valueOf(0);
final String invocationParameter = "InvocationParameter";
// setup server
final IInvocationCallbackService serverInvocationCallback = InvocationServerToolkit.getServer(BROKER_ID).getInvocationCallbackService();
final IMethod serverMethodMock = Mockito.mock(IMethod.class);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(final InvocationOnMock invocation) throws Throwable {
final Integer invocationIdArg = invocation.getArgumentAt(0, Integer.class);
try {
serverInvocationCallback.finished(invocationIdArg, methodResult);
throw expectedException;
} catch (final Exception e) {
serverInvocationCallback.exeption(invocationIdArg, e);
}
return null;
}
}).when(serverMethodMock).invoke(Mockito.any(), Mockito.any());
InvocationServerToolkit.getRegistry(BROKER_ID).register(methodName, serverMethodMock);
// setup client
final IInvocationCallbackService clientInvocationCallback = Mockito.mock(IInvocationCallbackService.class);
InvocationClientToolkit.getRegistry(BROKER_ID).register(clientInvocationCallback);
final IMethod clientMethod = InvocationClientToolkit.getClient(BROKER_ID).getMethod(methodName);
// invoke method on client
clientMethod.invoke(invocationId, invocationParameter);
messaging.getMessageReceiverBroker().dispatchMessages();
messaging.getMessageChannelBroker().dispatchReturnedMessages();
Mockito.verify(clientInvocationCallback, Mockito.never()).exeption(invocationId, expectedException);
Mockito.verify(clientInvocationCallback, Mockito.times(1)).finished(invocationId, methodResult);
assertNoLogErrorOrWarning();
}
use of org.jowidgets.invocation.common.api.IMethod in project jo-client-platform by jo-source.
the class InvocationIntegrationTest method testException.
@Test
public void testException() {
final String methodName = "Method";
final String methodResult = "Result";
final RuntimeException expectedException = new RuntimeException("Something goes wrong");
final Integer invocationId = Integer.valueOf(0);
final String invocationParameter = "InvocationParameter";
// setup server
final IInvocationCallbackService serverInvocationCallback = InvocationServerToolkit.getServer(BROKER_ID).getInvocationCallbackService();
final IMethod serverMethodMock = Mockito.mock(IMethod.class);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(final InvocationOnMock invocation) throws Throwable {
final Integer invocationIdArg = invocation.getArgumentAt(0, Integer.class);
try {
throwException();
serverInvocationCallback.finished(invocationIdArg, methodResult);
} catch (final Exception e) {
serverInvocationCallback.exeption(invocationIdArg, e);
}
return null;
}
private void throwException() {
throw expectedException;
}
}).when(serverMethodMock).invoke(Mockito.any(), Mockito.any());
InvocationServerToolkit.getRegistry(BROKER_ID).register(methodName, serverMethodMock);
// setup client
final IInvocationCallbackService clientInvocationCallback = Mockito.mock(IInvocationCallbackService.class);
InvocationClientToolkit.getRegistry(BROKER_ID).register(clientInvocationCallback);
final IMethod clientMethod = InvocationClientToolkit.getClient(BROKER_ID).getMethod(methodName);
// invoke method on client
clientMethod.invoke(invocationId, invocationParameter);
Mockito.verify(serverMethodMock, Mockito.never()).invoke(invocationId, invocationParameter);
messaging.getMessageReceiverBroker().dispatchMessages();
Mockito.verify(serverMethodMock, Mockito.times(1)).invoke(invocationId, invocationParameter);
Mockito.verify(clientInvocationCallback, Mockito.never()).exeption(invocationId, expectedException);
Mockito.verify(clientInvocationCallback, Mockito.never()).finished(invocationId, methodResult);
messaging.getMessageChannelBroker().dispatchReturnedMessages();
Mockito.verify(clientInvocationCallback, Mockito.times(1)).exeption(invocationId, expectedException);
Mockito.verify(clientInvocationCallback, Mockito.never()).finished(invocationId, methodResult);
assertNoLogErrorOrWarning();
}
use of org.jowidgets.invocation.common.api.IMethod in project jo-client-platform by jo-source.
the class InvocationIntegrationTest method testRequestResponse.
@Test
public void testRequestResponse() {
final String methodName = "Method";
final Integer invocationId = Integer.valueOf(0);
final Integer requestId = Integer.valueOf(1);
final String invocationParameter = "InvocationParameter";
final String request = "Request";
final String response = "Response";
final String methodResult = "Result";
// setup server
final IInvocationCallbackService serverInvocationCallback = InvocationServerToolkit.getServer(BROKER_ID).getInvocationCallbackService();
final IMethod serverMethod = Mockito.mock(IMethod.class);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(final InvocationOnMock invocation) throws Throwable {
serverInvocationCallback.interimRequest(invocationId, requestId, request);
return null;
}
}).when(serverMethod).invoke(Mockito.any(), Mockito.any());
InvocationServerToolkit.getRegistry(BROKER_ID).register(methodName, serverMethod);
final IResponseService serverResponseService = Mockito.mock(IResponseService.class);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(final InvocationOnMock invocation) throws Throwable {
final String responseArg = invocation.getArgumentAt(1, String.class);
serverInvocationCallback.finished(invocationId, responseArg + methodResult);
return null;
}
}).when(serverResponseService).response(Mockito.any(), Mockito.any());
InvocationServerToolkit.getRegistry(BROKER_ID).register(serverResponseService);
// setup client
final IInvocationCallbackService clientInvocationCallback = Mockito.mock(IInvocationCallbackService.class);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(final InvocationOnMock invocation) throws Throwable {
final Integer requestIdArg = invocation.getArgumentAt(1, Integer.class);
final String requestArg = invocation.getArgumentAt(2, String.class);
InvocationClientToolkit.getClient(BROKER_ID).getResponseService().response(requestIdArg, requestArg + response);
return null;
}
}).when(clientInvocationCallback).interimRequest(Mockito.any(), Mockito.any(), Mockito.any());
InvocationClientToolkit.getRegistry(BROKER_ID).register(clientInvocationCallback);
final IMethod clientMethod = InvocationClientToolkit.getClient(BROKER_ID).getMethod(methodName);
// invoke method on client
clientMethod.invoke(invocationId, invocationParameter);
Mockito.verify(serverMethod, Mockito.never()).invoke(invocationId, invocationParameter);
messaging.getMessageReceiverBroker().dispatchMessages();
Mockito.verify(serverMethod, Mockito.times(1)).invoke(invocationId, invocationParameter);
Mockito.verify(clientInvocationCallback, Mockito.never()).interimRequest(invocationId, requestId, request);
messaging.getMessageChannelBroker().dispatchReturnedMessages();
Mockito.verify(clientInvocationCallback, Mockito.times(1)).interimRequest(invocationId, requestId, request);
Mockito.verify(serverResponseService, Mockito.never()).response(requestId, request + response);
messaging.getMessageReceiverBroker().dispatchMessages();
Mockito.verify(serverResponseService, Mockito.times(1)).response(requestId, request + response);
Mockito.verify(clientInvocationCallback, Mockito.never()).finished(invocationId, request + response + methodResult);
messaging.getMessageChannelBroker().dispatchReturnedMessages();
Mockito.verify(clientInvocationCallback, Mockito.times(1)).finished(invocationId, request + response + methodResult);
assertNoLogErrorOrWarning();
}
use of org.jowidgets.invocation.common.api.IMethod in project jo-client-platform by jo-source.
the class InvocationIntegrationTest method testExceptionBeforeFinsihed.
@Test
public void testExceptionBeforeFinsihed() {
JUnitLoggerProvider.getConsoleLoggerEnablement().setEnabled(false);
final String methodName = "Method";
final String methodResult = "Result";
final RuntimeException expectedException = new RuntimeException("Something goes wrong");
final Integer invocationId = Integer.valueOf(0);
final String invocationParameter = "InvocationParameter";
// setup server
final IInvocationCallbackService serverInvocationCallback = InvocationServerToolkit.getServer(BROKER_ID).getInvocationCallbackService();
final IMethod serverMethodMock = Mockito.mock(IMethod.class);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(final InvocationOnMock invocation) throws Throwable {
final Integer invocationIdArg = invocation.getArgumentAt(0, Integer.class);
try {
throw expectedException;
} catch (final Exception e) {
serverInvocationCallback.exeption(invocationIdArg, e);
}
serverInvocationCallback.finished(invocationIdArg, methodResult);
return null;
}
}).when(serverMethodMock).invoke(Mockito.any(), Mockito.any());
InvocationServerToolkit.getRegistry(BROKER_ID).register(methodName, serverMethodMock);
// setup client
final IInvocationCallbackService clientInvocationCallback = Mockito.mock(IInvocationCallbackService.class);
InvocationClientToolkit.getRegistry(BROKER_ID).register(clientInvocationCallback);
final IMethod clientMethod = InvocationClientToolkit.getClient(BROKER_ID).getMethod(methodName);
// invoke method on client
clientMethod.invoke(invocationId, invocationParameter);
messaging.getMessageReceiverBroker().dispatchMessages();
messaging.getMessageChannelBroker().dispatchReturnedMessages();
Mockito.verify(clientInvocationCallback, Mockito.times(1)).exeption(invocationId, expectedException);
Mockito.verify(clientInvocationCallback, Mockito.never()).finished(invocationId, methodResult);
assertLogError();
}
Aggregations