Search in sources :

Example 1 with ThrowingSupplier

use of org.pentaho.platform.web.gwt.rpc.util.ThrowingSupplier in project pentaho-platform by pentaho.

the class SystemGwtRpcTest method testLoadSerializationPolicy.

// endregion
// region Serialization Policy
@Test
public void testLoadSerializationPolicy() {
    String servletPath = "/ws";
    String pathInfo = "/gwt/serviceName";
    String moduleContextPath = "/mantle/";
    String strongName = "ABC";
    String policyFilePath = moduleContextPath + strongName + ".gwt.rpc";
    // ---
    InputStream systemPolicyInputStreamMock = mock(InputStream.class);
    ServletContext servletContextMock = mock(ServletContext.class);
    when(servletContextMock.getResourceAsStream(policyFilePath)).thenReturn(systemPolicyInputStreamMock);
    // ---
    SerializationPolicy systemPolicyMock = mock(SerializationPolicy.class);
    try (MockedStatic<AbstractGwtRpc> rpc = Mockito.mockStatic(AbstractGwtRpc.class)) {
        rpc.when(() -> AbstractGwtRpc.loadSerializationPolicyFromInputStream(any(), eq(policyFilePath))).thenAnswer((Answer<SerializationPolicy>) invocationOnMock -> {
            @SuppressWarnings("unchecked") ThrowingSupplier<InputStream, IOException> inputStreamSupplier = (ThrowingSupplier<InputStream, IOException>) invocationOnMock.getArguments()[0];
            InputStream inputStream = inputStreamSupplier.get();
            assertEquals(systemPolicyInputStreamMock, inputStream);
            return systemPolicyMock;
        });
        // ---
        HttpServletRequest httpRequestMock = setupHttpRequest(servletPath, pathInfo);
        SystemGwtRpc gwtRpcSpy = spy(new SystemGwtRpc(httpRequestMock));
        doReturn(servletContextMock).when(gwtRpcSpy).getServletContext();
        // ---
        SerializationPolicy result = gwtRpcSpy.loadSerializationPolicy(moduleContextPath, strongName);
        // ---
        assertEquals(systemPolicyMock, result);
        rpc.verify(() -> AbstractGwtRpc.loadSerializationPolicyFromInputStream(any(), eq(policyFilePath)), times(1));
    }
}
Also used : SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RunWith(org.junit.runner.RunWith) ThrowingSupplier(org.pentaho.platform.web.gwt.rpc.util.ThrowingSupplier) Test(org.junit.Test) BeansException(org.springframework.beans.BeansException) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) GwtRpcProxyException(org.pentaho.platform.web.servlet.GwtRpcProxyException) Mockito.spy(org.mockito.Mockito.spy) ApplicationContext(org.springframework.context.ApplicationContext) Mockito(org.mockito.Mockito) Answer(org.mockito.stubbing.Answer) MockedStatic(org.mockito.MockedStatic) HttpServletRequest(javax.servlet.http.HttpServletRequest) VerificationModeFactory.times(org.mockito.internal.verification.VerificationModeFactory.times) ServletContext(javax.servlet.ServletContext) SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Mockito.mock(org.mockito.Mockito.mock) HttpServletRequest(javax.servlet.http.HttpServletRequest) InputStream(java.io.InputStream) ServletContext(javax.servlet.ServletContext) ThrowingSupplier(org.pentaho.platform.web.gwt.rpc.util.ThrowingSupplier) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

SerializationPolicy (com.google.gwt.user.server.rpc.SerializationPolicy)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ServletContext (javax.servlet.ServletContext)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)1 MockedStatic (org.mockito.MockedStatic)1 Mockito (org.mockito.Mockito)1 Mockito.doReturn (org.mockito.Mockito.doReturn)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.spy (org.mockito.Mockito.spy)1 Mockito.when (org.mockito.Mockito.when)1 VerificationModeFactory.times (org.mockito.internal.verification.VerificationModeFactory.times)1 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)1 Answer (org.mockito.stubbing.Answer)1 ThrowingSupplier (org.pentaho.platform.web.gwt.rpc.util.ThrowingSupplier)1