Search in sources :

Example 21 with SerializationPolicy

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

the class AbstractGwtRpcTest method testGetSerializationPolicyLogsAndReturnsDefaultIfModuleBaseURLIsNotPrefixByAppContextPath.

@Test
public void testGetSerializationPolicyLogsAndReturnsDefaultIfModuleBaseURLIsNotPrefixByAppContextPath() {
    String moduleBaseURL = "http://localhost:8080/pentaho/content/data-access/resources/gwt/";
    String appContextPath = "/sixtaho";
    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 gwtRpcSpy = spy(new TestGwtRpc(httpRequestMock));
        doReturn(appContextPath).when(gwtRpcSpy).getAppContextPath();
        SerializationPolicy result = gwtRpcSpy.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 22 with SerializationPolicy

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

the class AbstractGwtRpcTest method testLoadSerializationPolicyFromInputStreamSuccessfully.

// endregion
// region static loadSerializationPolicyFromInputStream
@Test
public void testLoadSerializationPolicyFromInputStreamSuccessfully() {
    String serializationPolicyFileName = "ABCDF12345.gwt.rpc";
    InputStream inputStreamMock = mock(InputStream.class);
    ThrowingSupplier<InputStream, IOException> inputStreamSupplier = () -> inputStreamMock;
    SerializationPolicy policyMock = mock(SerializationPolicy.class);
    try (MockedStatic<SerializationPolicyLoader> serializationPolicyLoader = Mockito.mockStatic(SerializationPolicyLoader.class)) {
        serializationPolicyLoader.when(() -> SerializationPolicyLoader.loadFromStream(inputStreamMock, null)).thenReturn(policyMock);
        SerializationPolicy result = AbstractGwtRpc.loadSerializationPolicyFromInputStream(inputStreamSupplier, serializationPolicyFileName);
        assertEquals(policyMock, result);
    }
}
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 23 with SerializationPolicy

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

the class AbstractGwtRpcTest method testGetSerializationPolicyCallsLoadSerializationPolicyReturnsDefaultIfItReturnsNull.

@Test
public void testGetSerializationPolicyCallsLoadSerializationPolicyReturnsDefaultIfItReturnsNull() {
    String moduleBaseURL = "http://localhost:8080/pentaho/content/data-access/resources/gwt/";
    String appContextPath = "/pentaho";
    String moduleContextPath = "/content/data-access/resources/gwt/";
    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 gwtRpcSpy = spy(new TestGwtRpc(httpRequestMock));
        doReturn(appContextPath).when(gwtRpcSpy).getAppContextPath();
        doReturn(null).when(gwtRpcSpy).loadSerializationPolicy(moduleContextPath, strongName);
        SerializationPolicy result = gwtRpcSpy.getSerializationPolicy(moduleBaseURL, strongName);
        assertEquals(defaultPolicyMock, result);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 24 with SerializationPolicy

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

the class AbstractGwtRpcTest method testGetSerializationPolicyLogsAndReturnsDefaultIfModuleBaseURLIsNotValidURL.

@Test
public void testGetSerializationPolicyLogsAndReturnsDefaultIfModuleBaseURLIsNotValidURL() {
    String moduleBaseURL = "ht123_-tp:localhost:8080/pentaho/content/data-access/resources/gwt/";
    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(nullable(String.class), any(MalformedURLException.class));
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) MalformedURLException(java.net.MalformedURLException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 25 with SerializationPolicy

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

the class AbstractGwtRpcTest method testGetDefaultSerializationPolicyDelegatesToRPCClass.

// endregion
// region static getDefaultSerializationPolicy
@Test
public void testGetDefaultSerializationPolicyDelegatesToRPCClass() {
    SerializationPolicy defaultPolicyMock = mock(SerializationPolicy.class);
    try (MockedStatic<RPC> rpc = Mockito.mockStatic(RPC.class)) {
        rpc.when(RPC::getDefaultSerializationPolicy).thenReturn(defaultPolicyMock);
        SerializationPolicy result = AbstractGwtRpc.getDefaultSerializationPolicy();
        assertEquals(defaultPolicyMock, result);
    }
}
Also used : SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) RPC(com.google.gwt.user.server.rpc.RPC)

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