Search in sources :

Example 31 with SerializationPolicy

use of com.google.gwt.user.server.rpc.SerializationPolicy in project pentaho-platform by pentaho.

the class AbstractGwtRpcTest method testLoadSerializationPolicyFromInputStreamLogsAndReturnsNullAndClosesStreamIfLoadThrowsParseException.

@Test
public void testLoadSerializationPolicyFromInputStreamLogsAndReturnsNullAndClosesStreamIfLoadThrowsParseException() throws IOException {
    String serializationPolicyFileName = "ABCDF12345.gwt.rpc";
    InputStream inputStreamMock = mock(InputStream.class);
    ThrowingSupplier<InputStream, IOException> inputStreamSupplier = () -> inputStreamMock;
    ParseException error = new ParseException("ABC", 0);
    try (MockedStatic<SerializationPolicyLoader> serializationPolicyLoader = Mockito.mockStatic(SerializationPolicyLoader.class)) {
        serializationPolicyLoader.when(() -> SerializationPolicyLoader.loadFromStream(inputStreamMock, null)).thenThrow(error);
        SerializationPolicy result = AbstractGwtRpc.loadSerializationPolicyFromInputStream(inputStreamSupplier, serializationPolicyFileName);
        assertNull(result);
        verify(loggerMock).error(nullable(String.class), eq(error));
        verify(inputStreamMock).close();
    }
}
Also used : SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) InputStream(java.io.InputStream) SerializationPolicyLoader(com.google.gwt.user.server.rpc.SerializationPolicyLoader) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IOException(java.io.IOException) ParseException(java.text.ParseException)

Example 32 with SerializationPolicy

use of com.google.gwt.user.server.rpc.SerializationPolicy in project pentaho-platform by pentaho.

the class AbstractGwtRpcTest method testLoadSerializationPolicyFromInputStreamLogsAndReturnsNullIfSupplierThrowsIOException.

@Test
public void testLoadSerializationPolicyFromInputStreamLogsAndReturnsNullIfSupplierThrowsIOException() {
    String serializationPolicyFileName = "ABCDF12345.gwt.rpc";
    IOException error = new IOException();
    ThrowingSupplier<InputStream, IOException> inputStreamSupplier = () -> {
        throw error;
    };
    SerializationPolicy result = AbstractGwtRpc.loadSerializationPolicyFromInputStream(inputStreamSupplier, serializationPolicyFileName);
    assertNull(result);
    verify(loggerMock).error(nullable(String.class), eq(error));
}
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 33 with SerializationPolicy

use of com.google.gwt.user.server.rpc.SerializationPolicy in project pentaho-platform by pentaho.

the class AbstractGwtRpcTest method testLoadSerializationPolicyFromInputStreamDoesNotLogErrorAndClosesStreamWhenSuccessful.

@Test
public void testLoadSerializationPolicyFromInputStreamDoesNotLogErrorAndClosesStreamWhenSuccessful() throws IOException {
    String serializationPolicyFileName = "ABCDF12345.gwt.rpc";
    InputStream inputStreamMock = mock(InputStream.class);
    ThrowingSupplier<InputStream, IOException> inputStreamSupplier = () -> inputStreamMock;
    SerializationPolicy policy = mock(SerializationPolicy.class);
    try (MockedStatic<SerializationPolicyLoader> serializationPolicyLoader = Mockito.mockStatic(SerializationPolicyLoader.class)) {
        serializationPolicyLoader.when(() -> SerializationPolicyLoader.loadFromStream(inputStreamMock, null)).thenReturn(policy);
        AbstractGwtRpc.loadSerializationPolicyFromInputStream(inputStreamSupplier, serializationPolicyFileName);
        verify(loggerMock, never()).error(nullable(String.class), any());
        verify(loggerMock, never()).error(nullable(String.class));
        verify(inputStreamMock).close();
    }
}
Also used : SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) InputStream(java.io.InputStream) SerializationPolicyLoader(com.google.gwt.user.server.rpc.SerializationPolicyLoader) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IOException(java.io.IOException)

Example 34 with SerializationPolicy

use of com.google.gwt.user.server.rpc.SerializationPolicy in project pentaho-platform by pentaho.

the class PluginGwtRpcTest method testLoadSerializationPolicySupportsPluginBean.

// endregion
// region Serialization Policy
@Test
public void testLoadSerializationPolicySupportsPluginBean() {
    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);
        // ---
        SerializationPolicy pluginPolicyMock = mock(SerializationPolicy.class);
        pentahoSystemMock = mockStatic(PentahoSystem.class);
        pentahoSystemMock.when(() -> PentahoSystem.get(eq(SerializationPolicy.class), eq(null), anyMap())).thenAnswer(invocationOnMock -> {
            Map<String, String> props = (Map<String, String>) invocationOnMock.getArguments()[2];
            if (pluginId.equals(props.get("plugin"))) {
                return pluginPolicyMock;
            }
            fail();
            return mock(SerializationPolicy.class);
        });
        // ---
        HttpServletRequest httpRequestMock = setupHttpRequest(pathInfo);
        PluginGwtRpc gwtRpc = new PluginGwtRpc(httpRequestMock);
        SerializationPolicy result = gwtRpc.loadSerializationPolicy(moduleContextPath, strongName);
        assertEquals(pluginPolicyMock, result);
    }
}
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) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) Map(java.util.Map) 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