Search in sources :

Example 1 with RPCServletUtils

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

the class AbstractGwtRpcTest method testGetRequestPayloadFirstTime.

// endregion
// region Request Payload
@Test
public void testGetRequestPayloadFirstTime() {
    String requestPayload = "REQUEST_PAYLOAD";
    HttpServletRequest httpRequestMock = mock(HttpServletRequest.class);
    TestGwtRpc gwtRpc = new TestGwtRpc(httpRequestMock);
    try (MockedStatic<RPCServletUtils> rpcServletUtils = Mockito.mockStatic(RPCServletUtils.class)) {
        rpcServletUtils.when(() -> RPCServletUtils.readContentAsGwtRpc(any())).thenReturn(requestPayload);
        String result = gwtRpc.getRequestPayload();
        assertEquals(requestPayload, result);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RPCServletUtils(com.google.gwt.user.server.rpc.RPCServletUtils)

Example 2 with RPCServletUtils

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

the class AbstractGwtRpcTest method testGetRequestPayloadSecondTimeIsCached.

@Test
public void testGetRequestPayloadSecondTimeIsCached() throws ServletException, IOException {
    String requestPayload = "REQUEST_PAYLOAD";
    HttpServletRequest httpRequestMock = mock(HttpServletRequest.class);
    TestGwtRpc gwtRpc = new TestGwtRpc(httpRequestMock);
    try (MockedStatic<RPCServletUtils> rpcServletUtils = Mockito.mockStatic(RPCServletUtils.class)) {
        rpcServletUtils.when(() -> RPCServletUtils.readContentAsGwtRpc(any())).thenReturn(requestPayload);
        gwtRpc.getRequestPayload();
        String result = gwtRpc.getRequestPayload();
        assertEquals(requestPayload, result);
        rpcServletUtils.verify(() -> RPCServletUtils.readContentAsGwtRpc(any()));
        RPCServletUtils.readContentAsGwtRpc(any());
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RPCServletUtils(com.google.gwt.user.server.rpc.RPCServletUtils)

Example 3 with RPCServletUtils

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

the class AbstractGwtRpcTest method testGetRequestPayloadLogsAndWrapsThrownIOException.

@Test
public void testGetRequestPayloadLogsAndWrapsThrownIOException() {
    IOException error = mock(IOException.class);
    HttpServletRequest httpRequestMock = mock(HttpServletRequest.class);
    TestGwtRpc gwtRpc = new TestGwtRpc(httpRequestMock);
    try (MockedStatic<RPCServletUtils> rpcServletUtils = Mockito.mockStatic(RPCServletUtils.class)) {
        rpcServletUtils.when(() -> RPCServletUtils.readContentAsGwtRpc(any())).thenThrow(error);
        try {
            gwtRpc.getRequestPayload();
            fail();
        } catch (GwtRpcProxyException ex) {
            assertEquals(error, ex.getCause());
            verify(loggerMock).error(nullable(String.class), eq(error));
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IOException(java.io.IOException) GwtRpcProxyException(org.pentaho.platform.web.servlet.GwtRpcProxyException) RPCServletUtils(com.google.gwt.user.server.rpc.RPCServletUtils)

Example 4 with RPCServletUtils

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

the class AbstractGwtRpcTest method testGetRequestPayloadLogsAndWrapsThrownServletException.

@Test
public void testGetRequestPayloadLogsAndWrapsThrownServletException() {
    ServletException error = mock(ServletException.class);
    HttpServletRequest httpRequestMock = mock(HttpServletRequest.class);
    TestGwtRpc gwtRpc = new TestGwtRpc(httpRequestMock);
    try (MockedStatic<RPCServletUtils> rpcServletUtils = Mockito.mockStatic(RPCServletUtils.class)) {
        rpcServletUtils.when(() -> RPCServletUtils.readContentAsGwtRpc(any())).thenThrow(error);
        try {
            gwtRpc.getRequestPayload();
            fail();
        } catch (GwtRpcProxyException ex) {
            assertEquals(error, ex.getCause());
            verify(loggerMock).error(nullable(String.class), eq(error));
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) HttpServletRequest(javax.servlet.http.HttpServletRequest) GwtRpcProxyException(org.pentaho.platform.web.servlet.GwtRpcProxyException) RPCServletUtils(com.google.gwt.user.server.rpc.RPCServletUtils)

Aggregations

RPCServletUtils (com.google.gwt.user.server.rpc.RPCServletUtils)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 GwtRpcProxyException (org.pentaho.platform.web.servlet.GwtRpcProxyException)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1