use of org.jowidgets.invocation.common.api.IMethod in project jo-client-platform by jo-source.
the class InvocationServiceServerRegistryImpl method register.
@Override
public void register(final String methodName, final IMethodInvocationService<?, ?, ?, ?, ?> methodService) {
final IMethod method = new MethodImpl(invocationServer, cancelService, responseService, methodService);
invocationServerServiceRegistry.register(methodName, method);
}
use of org.jowidgets.invocation.common.api.IMethod in project jo-client-platform by jo-source.
the class InvocationIntegrationTest method testCancelAfterMessageInvocation.
@Test
public void testCancelAfterMessageInvocation() {
final String methodName = "Method";
final Integer invocationId = Integer.valueOf(0);
final String invocationParameter = "InvocationParameter";
// setup server
final ICancelService serverCancelService = Mockito.mock(ICancelService.class);
InvocationServerToolkit.getRegistry(BROKER_ID).register(serverCancelService);
final IMethod serverMethodMock = Mockito.mock(IMethod.class);
InvocationServerToolkit.getRegistry(BROKER_ID).register(methodName, serverMethodMock);
// setup client
final IInvocationCallbackService clientInvocationCallback = Mockito.mock(IInvocationCallbackService.class);
InvocationClientToolkit.getRegistry(BROKER_ID).register(clientInvocationCallback);
final IInvocationClient client = InvocationClientToolkit.getClient(BROKER_ID);
final IMethod clientMethod = client.getMethod(methodName);
final ICancelService clientCancelService = client.getCancelService();
// invoke methods 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);
clientCancelService.canceled(invocationId);
Mockito.verify(serverCancelService, Mockito.never()).canceled(invocationId);
messaging.getMessageReceiverBroker().dispatchMessages();
Mockito.verify(serverCancelService, Mockito.times(1)).canceled(invocationId);
assertNoLogErrorOrWarning();
}
use of org.jowidgets.invocation.common.api.IMethod in project jo-client-platform by jo-source.
the class InvocationIntegrationTest method testInterimServerResponse.
@Test
public void testInterimServerResponse() {
final String methodName = "Method";
final Integer invocationId = Integer.valueOf(0);
final String invocationParameter = "InvocationParameter";
final Integer interimResponse1 = Integer.valueOf(1);
final Integer interimResponse2 = Integer.valueOf(2);
final Integer interimResponse3 = Integer.valueOf(3);
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 {
final Integer invocationIdArg = invocation.getArgumentAt(0, Integer.class);
serverInvocationCallback.interimResponse(invocationIdArg, interimResponse1);
serverInvocationCallback.interimResponse(invocationIdArg, interimResponse2);
serverInvocationCallback.interimResponse(invocationIdArg, interimResponse3);
serverInvocationCallback.finished(invocationIdArg, methodResult);
return null;
}
}).when(serverMethod).invoke(Mockito.any(), Mockito.any());
InvocationServerToolkit.getRegistry(BROKER_ID).register(methodName, serverMethod);
// 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(serverMethod, Mockito.never()).invoke(invocationId, invocationParameter);
messaging.getMessageReceiverBroker().dispatchMessages();
Mockito.verify(serverMethod, Mockito.times(1)).invoke(invocationId, invocationParameter);
Mockito.verify(clientInvocationCallback, Mockito.never()).interimResponse(invocationId, interimResponse1);
Mockito.verify(clientInvocationCallback, Mockito.never()).interimResponse(invocationId, interimResponse2);
Mockito.verify(clientInvocationCallback, Mockito.never()).interimResponse(invocationId, interimResponse3);
Mockito.verify(clientInvocationCallback, Mockito.never()).finished(invocationId, methodResult);
messaging.getMessageChannelBroker().dispatchReturnedMessages();
Mockito.verify(clientInvocationCallback, Mockito.times(1)).interimResponse(invocationId, interimResponse1);
Mockito.verify(clientInvocationCallback, Mockito.times(1)).interimResponse(invocationId, interimResponse2);
Mockito.verify(clientInvocationCallback, Mockito.times(1)).interimResponse(invocationId, interimResponse3);
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 testInvokeMethod.
@Test
public void testInvokeMethod() {
final String methodName = "Method";
final Integer invocationId = Integer.valueOf(0);
final String invocationParameter = "InvocationParameter";
// setup server
final IMethod serverMethodMock = Mockito.mock(IMethod.class);
InvocationServerToolkit.getRegistry(BROKER_ID).register(methodName, serverMethodMock);
// setup client
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);
assertNoLogErrorOrWarning();
}
use of org.jowidgets.invocation.common.api.IMethod in project jo-client-platform by jo-source.
the class InvocationIntegrationTest method testInvokeMethodWithResult.
@Test
public void testInvokeMethodWithResult() {
final String methodName = "Method";
final String methodResult = "Result";
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);
final String invocationParameterArg = invocation.getArgumentAt(1, String.class);
serverInvocationCallback.finished(invocationIdArg, invocationParameterArg + 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);
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()).finished(invocationId, invocationParameter + methodResult);
messaging.getMessageChannelBroker().dispatchReturnedMessages();
Mockito.verify(clientInvocationCallback, Mockito.times(1)).finished(invocationId, invocationParameter + methodResult);
assertNoLogErrorOrWarning();
}
Aggregations