use of com.google.gwt.user.server.rpc.RPCRequest in project pentaho-platform by pentaho.
the class AbstractGwtRpcTest method testInvokeLogsAndThrowsIfServiceClassDoesNotHaveServiceInterfaceMethod.
@Test
public void testInvokeLogsAndThrowsIfServiceClassDoesNotHaveServiceInterfaceMethod() throws NoSuchMethodException {
ServiceClassWhichDoesNotImplementInterface target = new ServiceClassWhichDoesNotImplementInterface();
ClassLoader targetClassLoader = mock(ClassLoader.class);
Method serviceSpecialMethod = ServiceInterface.class.getMethod("methodSpecial", String.class);
Object[] rpcParameters = new Object[] { "id1" };
SerializationPolicy policy = mock(SerializationPolicy.class);
RPCRequest rpcRequest = new RPCRequest(serviceSpecialMethod, rpcParameters, policy, 0);
HttpServletRequest httpRequestMock = mock(HttpServletRequest.class);
TestGwtRpc gwtRpcSpy = spy(new TestGwtRpc(httpRequestMock));
doReturn(target).when(gwtRpcSpy).getTarget();
doReturn(rpcRequest).when(gwtRpcSpy).getRequest();
try {
gwtRpcSpy.invoke();
fail();
} catch (GwtRpcProxyException ex) {
assertTrue(ex.getCause() instanceof NoSuchMethodException);
verify(loggerMock).error(nullable(String.class), eq(ex.getCause()));
}
}
use of com.google.gwt.user.server.rpc.RPCRequest in project pentaho-platform by pentaho.
the class AbstractGwtRpcTest method testInvokeSuccessfully.
@Test
public void testInvokeSuccessfully() throws NoSuchMethodException {
ServiceClassWhichDoesNotImplementInterface target = new ServiceClassWhichDoesNotImplementInterface();
Method targetMethod = target.getClass().getMethod("method", String.class);
ClassLoader targetClassLoader = mock(ClassLoader.class);
Method serviceMethod = ServiceInterface.class.getMethod("method", String.class);
Object[] rpcParameters = new Object[] { "id1" };
SerializationPolicy policy = mock(SerializationPolicy.class);
RPCRequest rpcRequest = new RPCRequest(serviceMethod, rpcParameters, policy, 0);
HttpServletRequest httpRequestMock = mock(HttpServletRequest.class);
String response = "rpc response";
TestGwtRpc gwtRpcSpy = spy(new TestGwtRpc(httpRequestMock));
doReturn(target).when(gwtRpcSpy).getTarget();
doReturn(targetMethod).when(gwtRpcSpy).getTargetMethod(target.getClass(), rpcRequest);
doReturn(targetClassLoader).when(gwtRpcSpy).getTargetClassLoader();
doReturn(rpcRequest).when(gwtRpcSpy).getRequest();
try (MockedStatic<RPC> rpc = Mockito.mockStatic(RPC.class)) {
rpc.when(() -> RPC.invokeAndEncodeResponse(target, targetMethod, rpcParameters, policy)).thenReturn(response);
String result = gwtRpcSpy.invoke();
assertEquals(response, result);
rpc.verify(() -> RPC.invokeAndEncodeResponse(target, targetMethod, rpcParameters, policy));
}
}
use of com.google.gwt.user.server.rpc.RPCRequest in project pentaho-platform by pentaho.
the class AbstractGwtRpcTest method testInvokeServiceClassLogsAndThrowsIfRPCThrowsSerializationException.
@Test
public void testInvokeServiceClassLogsAndThrowsIfRPCThrowsSerializationException() throws NoSuchMethodException {
ServiceClassWhichDoesNotImplementInterface target = new ServiceClassWhichDoesNotImplementInterface();
Method targetMethod = target.getClass().getMethod("method", String.class);
ClassLoader targetClassLoader = mock(ClassLoader.class);
Method serviceSpecialMethod = ServiceInterface.class.getMethod("method", String.class);
Object[] rpcParameters = new Object[] { "id1" };
SerializationPolicy policy = mock(SerializationPolicy.class);
RPCRequest rpcRequest = new RPCRequest(serviceSpecialMethod, rpcParameters, policy, 0);
HttpServletRequest httpRequestMock = mock(HttpServletRequest.class);
TestGwtRpc gwtRpcSpy = spy(new TestGwtRpc(httpRequestMock));
doReturn(target).when(gwtRpcSpy).getTarget();
doReturn(targetClassLoader).when(gwtRpcSpy).getTargetClassLoader();
doReturn(rpcRequest).when(gwtRpcSpy).getRequest();
SerializationException error = new SerializationException();
try (MockedStatic<RPC> rpc = Mockito.mockStatic(RPC.class)) {
rpc.when(() -> RPC.invokeAndEncodeResponse(target, targetMethod, rpcParameters, policy)).thenThrow(error);
try {
gwtRpcSpy.invoke();
fail();
} catch (GwtRpcProxyException ex) {
assertEquals(error, ex.getCause());
verify(loggerMock).error(nullable(String.class), eq(error));
}
}
}
use of com.google.gwt.user.server.rpc.RPCRequest in project pentaho-platform by pentaho.
the class AbstractGwtRpcTest method testInvokeRunsInTargetClassLoader.
@Test
public void testInvokeRunsInTargetClassLoader() throws NoSuchMethodException, SerializationException {
ServiceClassWhichDoesNotImplementInterface target = new ServiceClassWhichDoesNotImplementInterface();
Method targetMethod = target.getClass().getMethod("method", String.class);
ClassLoader targetClassLoader = mock(ClassLoader.class);
Method serviceMethod = ServiceInterface.class.getMethod("method", String.class);
Object[] rpcParameters = new Object[] { "id1" };
SerializationPolicy policy = mock(SerializationPolicy.class);
RPCRequest rpcRequest = new RPCRequest(serviceMethod, rpcParameters, policy, 0);
HttpServletRequest httpRequestMock = mock(HttpServletRequest.class);
String response = "rpc response";
TestGwtRpc gwtRpcSpy = spy(new TestGwtRpc(httpRequestMock));
doReturn(target).when(gwtRpcSpy).getTarget();
doReturn(targetMethod).when(gwtRpcSpy).getTargetMethod(target.getClass(), rpcRequest);
doReturn(targetClassLoader).when(gwtRpcSpy).getTargetClassLoader();
doReturn(rpcRequest).when(gwtRpcSpy).getRequest();
// Stub invokeCore with:
doAnswer((Answer<String>) invocationOnMock -> {
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
assertEquals(targetClassLoader, currentClassLoader);
return response;
}).when(gwtRpcSpy).invokeCore(target, targetMethod, rpcRequest);
gwtRpcSpy.invoke();
verify(gwtRpcSpy).invokeCore(target, targetMethod, rpcRequest);
}
use of com.google.gwt.user.server.rpc.RPCRequest in project pentaho-platform by pentaho.
the class AbstractGwtRpcTest method testGetRequestSecondTimeIsCached.
@Test
public void testGetRequestSecondTimeIsCached() {
String requestPayload = "REQUEST_PAYLOAD";
// new Object would have a null class loader!
Object target = this;
RPCRequest rpcRequest = new RPCRequest(null, null, null, 0);
HttpServletRequest httpRequestMock = mock(HttpServletRequest.class);
TestGwtRpc gwtRpcSpy = spy(new TestGwtRpc(httpRequestMock));
doReturn(requestPayload).when(gwtRpcSpy).getRequestPayload();
doReturn(target).when(gwtRpcSpy).resolveTarget();
try (MockedStatic<RPC> rpc = Mockito.mockStatic(RPC.class)) {
rpc.when(() -> RPC.decodeRequest(eq(requestPayload), eq(null), any())).thenReturn(rpcRequest);
gwtRpcSpy.getRequest();
verify(gwtRpcSpy).getRequestPayload();
RPCRequest result = gwtRpcSpy.getRequest();
verify(gwtRpcSpy).getRequestPayload();
assertEquals(rpcRequest, result);
}
}
Aggregations