use of org.pentaho.platform.web.servlet.GwtRpcProxyException 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 org.pentaho.platform.web.servlet.GwtRpcProxyException in project pentaho-platform by pentaho.
the class AbstractGwtRpcTest method testGetTargetLogsAndRethrowsGwtRpcException.
@Test
public void testGetTargetLogsAndRethrowsGwtRpcException() {
// Mocking the exception does not work with doThrow...
// Spies require doThrow instead of thenThrow.
// mock( GwtRpcProxyException.class );
GwtRpcProxyException error = new GwtRpcProxyException();
HttpServletRequest httpRequestMock = mock(HttpServletRequest.class);
TestGwtRpc gwtRpcSpy = spy(new TestGwtRpc(httpRequestMock));
doThrow(error).when(gwtRpcSpy).resolveTarget();
try {
gwtRpcSpy.getTarget();
fail();
} catch (GwtRpcProxyException ex) {
assertEquals(error, ex);
verify(loggerMock).error(nullable(String.class), eq(ex));
}
}
use of org.pentaho.platform.web.servlet.GwtRpcProxyException in project pentaho-platform by pentaho.
the class AbstractGwtRpcTest method testGetRequestLogsAndWrapsThrownIllegalArgumentException.
@Test
public void testGetRequestLogsAndWrapsThrownIllegalArgumentException() {
String requestPayload = "REQUEST_PAYLOAD";
// new Object would have a null class loader!
Object target = this;
IllegalArgumentException error = new IllegalArgumentException();
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())).thenThrow(error);
try {
gwtRpcSpy.getRequest();
fail();
} catch (GwtRpcProxyException ex) {
assertEquals(error, ex.getCause());
verify(loggerMock).error(nullable(String.class), eq(error));
}
}
}
use of org.pentaho.platform.web.servlet.GwtRpcProxyException 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 org.pentaho.platform.web.servlet.GwtRpcProxyException in project pentaho-platform by pentaho.
the class PluginGwtRpc method resolveTarget.
@NonNull
@Override
protected Object resolveTarget() throws GwtRpcProxyException {
IServiceManager serviceManager = PentahoSystem.get(IServiceManager.class, PentahoSessionHolder.getSession());
String key = getServiceKey();
if (serviceManager.getServiceConfig("gwt", key) == null) {
throw new GwtRpcProxyException(Messages.getInstance().getErrorString("GwtRpcPluginProxyServlet.ERROR_0001_SERVICE_NOT_FOUND", key));
}
try {
return serviceManager.getServiceBean("gwt", key);
} catch (ServiceException e) {
throw new GwtRpcProxyException(Messages.getInstance().getErrorString("GwtRpcPluginProxyServlet.ERROR_0002_FAILED_TO_GET_BEAN_REFERENCE", key), e);
}
}
Aggregations