Search in sources :

Example 1 with IMethod

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);
}
Also used : IMethod(org.jowidgets.invocation.common.api.IMethod)

Example 2 with IMethod

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();
}
Also used : IInvocationClient(org.jowidgets.invocation.client.api.IInvocationClient) IMethod(org.jowidgets.invocation.common.api.IMethod) ICancelService(org.jowidgets.invocation.common.api.ICancelService) IInvocationCallbackService(org.jowidgets.invocation.common.api.IInvocationCallbackService) Test(org.junit.Test)

Example 3 with IMethod

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();
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) IMethod(org.jowidgets.invocation.common.api.IMethod) IInvocationCallbackService(org.jowidgets.invocation.common.api.IInvocationCallbackService) Test(org.junit.Test)

Example 4 with IMethod

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();
}
Also used : IMethod(org.jowidgets.invocation.common.api.IMethod) Test(org.junit.Test)

Example 5 with IMethod

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();
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) IMethod(org.jowidgets.invocation.common.api.IMethod) IInvocationCallbackService(org.jowidgets.invocation.common.api.IInvocationCallbackService) Test(org.junit.Test)

Aggregations

IMethod (org.jowidgets.invocation.common.api.IMethod)14 Test (org.junit.Test)10 IInvocationCallbackService (org.jowidgets.invocation.common.api.IInvocationCallbackService)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)7 IInvocationClient (org.jowidgets.invocation.client.api.IInvocationClient)3 ICancelService (org.jowidgets.invocation.common.api.ICancelService)3 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 IResponseService (org.jowidgets.invocation.common.api.IResponseService)1 MethodInvocationMessage (org.jowidgets.invocation.common.impl.MethodInvocationMessage)1 IInterimRequestCallback (org.jowidgets.invocation.service.common.api.IInterimRequestCallback)1 IInterimResponseCallback (org.jowidgets.invocation.service.common.api.IInterimResponseCallback)1 IInvocationCallback (org.jowidgets.invocation.service.common.api.IInvocationCallback)1 IMethodInvocationService (org.jowidgets.invocation.service.common.api.IMethodInvocationService)1 JUnitLogger (org.jowidgets.logging.tools.JUnitLogger)1