use of com.google.gwt.user.server.rpc.SerializationPolicy in project pentaho-platform by pentaho.
the class AbstractGwtRpcTest method testLoadSerializationPolicyFromInputStreamLogsAndReturnsNullIfSupplierReturnsNull.
@Test
public void testLoadSerializationPolicyFromInputStreamLogsAndReturnsNullIfSupplierReturnsNull() {
String serializationPolicyFileName = "ABCDF12345.gwt.rpc";
ThrowingSupplier<InputStream, IOException> inputStreamSupplier = () -> null;
SerializationPolicy result = AbstractGwtRpc.loadSerializationPolicyFromInputStream(inputStreamSupplier, serializationPolicyFileName);
assertNull(result);
verify(loggerMock).error(nullable(String.class));
}
use of com.google.gwt.user.server.rpc.SerializationPolicy 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.SerializationPolicy 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.SerializationPolicy in project pentaho-platform by pentaho.
the class AbstractGwtRpcTest method testGetSerializationPolicyLogsAndReturnsDefaultIfModuleBaseURLIsNull.
@Test
public void testGetSerializationPolicyLogsAndReturnsDefaultIfModuleBaseURLIsNull() {
String moduleBaseURL = null;
String strongName = "ABCDF12345";
HttpServletRequest httpRequestMock = mock(HttpServletRequest.class);
SerializationPolicy defaultPolicyMock = mock(SerializationPolicy.class);
try (MockedStatic<AbstractGwtRpc> rpc = Mockito.mockStatic(AbstractGwtRpc.class)) {
rpc.when(AbstractGwtRpc::getDefaultSerializationPolicy).thenReturn(defaultPolicyMock);
TestGwtRpc gwtRpc = new TestGwtRpc(httpRequestMock);
SerializationPolicy result = gwtRpc.getSerializationPolicy(moduleBaseURL, strongName);
assertEquals(defaultPolicyMock, result);
verify(loggerMock).error(anyString());
}
}
use of com.google.gwt.user.server.rpc.SerializationPolicy in project pentaho-platform by pentaho.
the class PluginGwtRpcTest method testLoadSerializationPolicyLogsErrorAndReturnsNullIfNoPluginClassLoader.
@Test
public void testLoadSerializationPolicyLogsErrorAndReturnsNullIfNoPluginClassLoader() {
String pathInfo = "/serviceName";
String pluginId = "data-access";
String moduleContextPath = "/content/data-access/resources/gwt/";
String strongName = "ABC";
try (MockedStatic<PluginUtil> pluginUtilMock = mockStatic(PluginUtil.class)) {
pluginUtilMock.when(() -> PluginUtil.getPluginIdFromPath(moduleContextPath)).thenReturn(pluginId);
// ----
// There is no configured SP bean.
pentahoSystemMock = mockStatic(PentahoSystem.class);
pentahoSystemMock.when(() -> PentahoSystem.get(eq(SerializationPolicy.class), eq(null), anyMap())).thenReturn(null);
// ---
when(PluginUtil.getClassLoaderForService(moduleContextPath)).thenReturn(null);
// ---
HttpServletRequest httpRequestMock = setupHttpRequest(pathInfo);
PluginGwtRpc gwtRpc = new PluginGwtRpc(httpRequestMock);
SerializationPolicy result = gwtRpc.loadSerializationPolicy(moduleContextPath, strongName);
assertNull(result);
verify(loggerMock, times(1)).error(nullable(String.class));
}
}
Aggregations