Search in sources :

Example 1 with SerializationPolicy

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));
}
Also used : SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) InputStream(java.io.InputStream) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IOException(java.io.IOException)

Example 2 with SerializationPolicy

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()));
    }
}
Also used : SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) HttpServletRequest(javax.servlet.http.HttpServletRequest) RPCRequest(com.google.gwt.user.server.rpc.RPCRequest) Method(java.lang.reflect.Method) GwtRpcProxyException(org.pentaho.platform.web.servlet.GwtRpcProxyException)

Example 3 with SerializationPolicy

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));
    }
}
Also used : SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) HttpServletRequest(javax.servlet.http.HttpServletRequest) RPC(com.google.gwt.user.server.rpc.RPC) RPCRequest(com.google.gwt.user.server.rpc.RPCRequest) Method(java.lang.reflect.Method) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 4 with SerializationPolicy

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());
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 5 with SerializationPolicy

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));
    }
}
Also used : SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) HttpServletRequest(javax.servlet.http.HttpServletRequest) PluginUtil(org.pentaho.platform.plugin.services.pluginmgr.PluginUtil) PentahoSystem(org.pentaho.platform.engine.core.system.PentahoSystem) Test(org.junit.Test)

Aggregations

SerializationPolicy (com.google.gwt.user.server.rpc.SerializationPolicy)34 HttpServletRequest (javax.servlet.http.HttpServletRequest)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)16 IOException (java.io.IOException)11 InputStream (java.io.InputStream)11 Test (org.junit.Test)9 RPC (com.google.gwt.user.server.rpc.RPC)5 RPCRequest (com.google.gwt.user.server.rpc.RPCRequest)5 SerializationPolicyLoader (com.google.gwt.user.server.rpc.SerializationPolicyLoader)5 Method (java.lang.reflect.Method)5 URL (java.net.URL)5 PentahoSystem (org.pentaho.platform.engine.core.system.PentahoSystem)5 PluginUtil (org.pentaho.platform.plugin.services.pluginmgr.PluginUtil)5 MalformedURLException (java.net.MalformedURLException)4 GwtRpcProxyException (org.pentaho.platform.web.servlet.GwtRpcProxyException)4 NonNull (edu.umd.cs.findbugs.annotations.NonNull)3 ParseException (java.text.ParseException)3 IPluginResourceLoader (org.pentaho.platform.api.engine.IPluginResourceLoader)3 SerializationException (com.google.gwt.user.client.rpc.SerializationException)2 SerializationPolicyProvider (com.google.gwt.user.server.rpc.SerializationPolicyProvider)2