Search in sources :

Example 1 with AbstractGwtRpc

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

the class AbstractGwtRpcRequestMatcherTest method createGwtRpcMock.

@NonNull
private AbstractGwtRpc createGwtRpcMock(@NonNull String serviceMethodName) throws NoSuchMethodException {
    Method serviceMethodMock = this.getClass().getMethod(serviceMethodName);
    RPCRequest rpcRequestMock = new RPCRequest(serviceMethodMock, new Object[] {}, null, 0);
    AbstractGwtRpc gwtRpcMock = mock(AbstractGwtRpc.class);
    when(gwtRpcMock.getRequest()).thenReturn(rpcRequestMock);
    return gwtRpcMock;
}
Also used : RPCRequest(com.google.gwt.user.server.rpc.RPCRequest) AbstractGwtRpc(org.pentaho.platform.web.gwt.rpc.AbstractGwtRpc) HttpMethod(javax.ws.rs.HttpMethod) Method(java.lang.reflect.Method) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 2 with AbstractGwtRpc

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

the class SystemGwtRpcRequestMatcherTest method testGetGwtRpcReturnsASystemGwtRpc.

// endregion
// region getGwtRpc integration
@Test
public void testGetGwtRpcReturnsASystemGwtRpc() {
    HttpServletRequest requestMock = createRequestMock(HttpMethod.POST, TEST_PATH);
    IGwtRpcSerializationPolicyCache serializationPolicyCache = (moduleBaseURL, strongName, sourceProvider) -> {
        throw new UnsupportedOperationException();
    };
    SystemGwtRpcRequestMatcher matcher = spy(new SystemGwtRpcRequestMatcher(TEST_PATTERN, TEST_RPC_METHODS_SINGLE, serializationPolicyCache));
    // ---
    AbstractGwtRpc gwtRpc = matcher.getGwtRpc(requestMock);
    assertNotNull(gwtRpc);
    assertTrue(gwtRpc instanceof SystemGwtRpc);
    assertEquals(requestMock, gwtRpc.getServletRequest());
    assertEquals(serializationPolicyCache, gwtRpc.getSerializationPolicyCache());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AbstractGwtRpc(org.pentaho.platform.web.gwt.rpc.AbstractGwtRpc) SystemGwtRpc(org.pentaho.platform.web.gwt.rpc.SystemGwtRpc) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) IGwtRpcSerializationPolicyCache(org.pentaho.platform.web.gwt.rpc.IGwtRpcSerializationPolicyCache) Mockito.spy(org.mockito.Mockito.spy) HttpMethod(javax.ws.rs.HttpMethod) Mockito.verify(org.mockito.Mockito.verify) HttpServletRequest(javax.servlet.http.HttpServletRequest) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) NonNull(edu.umd.cs.findbugs.annotations.NonNull) Collections(java.util.Collections) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) IGwtRpcSerializationPolicyCache(org.pentaho.platform.web.gwt.rpc.IGwtRpcSerializationPolicyCache) AbstractGwtRpc(org.pentaho.platform.web.gwt.rpc.AbstractGwtRpc) SystemGwtRpc(org.pentaho.platform.web.gwt.rpc.SystemGwtRpc) Test(org.junit.Test)

Example 3 with AbstractGwtRpc

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

the class SystemGwtRpcRequestMatcherTest method testGetGwtRpcCachesSystemGwtRpcOnRequest.

@Test
public void testGetGwtRpcCachesSystemGwtRpcOnRequest() {
    HttpServletRequest requestMock = createRequestMock(HttpMethod.POST, TEST_PATH);
    SystemGwtRpcRequestMatcher matcher = spy(new SystemGwtRpcRequestMatcher(TEST_PATTERN, TEST_RPC_METHODS_SINGLE, null));
    // ---
    AbstractGwtRpc gwtRpc1 = matcher.getGwtRpc(requestMock);
    verify(requestMock, times(1)).getAttribute(HTTP_GWT_RPC_ATTRIBUTE);
    verify(requestMock, times(1)).setAttribute(HTTP_GWT_RPC_ATTRIBUTE, gwtRpc1);
    // ---
    when(requestMock.getAttribute(HTTP_GWT_RPC_ATTRIBUTE)).thenReturn(gwtRpc1);
    AbstractGwtRpc gwtRpc2 = matcher.getGwtRpc(requestMock);
    assertEquals(gwtRpc1, gwtRpc2);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AbstractGwtRpc(org.pentaho.platform.web.gwt.rpc.AbstractGwtRpc) Test(org.junit.Test)

Example 4 with AbstractGwtRpc

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

the class AbstractGwtRpcRequestMatcherTest method testMatchWithMethodNameFromGwtRpc.

// endregion
// region getGwtRpc integration
@Test
public void testMatchWithMethodNameFromGwtRpc() throws NoSuchMethodException {
    HttpServletRequest request = createRequestMock(HttpMethod.POST, TEST_PATH);
    AbstractGwtRpcRequestMatcher matcher = spy(new TestRequestMatcher(TEST_PATTERN, TEST_RPC_METHODS_SINGLE, null));
    // ---
    AbstractGwtRpc gwtRpcMock = createGwtRpcMock(TEST_RPC_METHOD_1);
    doReturn(gwtRpcMock).when(matcher).getGwtRpc(any());
    assertTrue(matcher.test(request));
    // ---
    gwtRpcMock = createGwtRpcMock(TEST_RPC_METHOD_1 + "Something");
    doReturn(gwtRpcMock).when(matcher).getGwtRpc(any());
    assertFalse(matcher.test(request));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AbstractGwtRpc(org.pentaho.platform.web.gwt.rpc.AbstractGwtRpc) Test(org.junit.Test)

Example 5 with AbstractGwtRpc

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

the class PluginGwtRpcRequestMatcherTest method testGetGwtRpcCachesPluginGwtRpcOnRequest.

@Test
public void testGetGwtRpcCachesPluginGwtRpcOnRequest() {
    HttpServletRequest requestMock = createRequestMock(HttpMethod.POST, TEST_PATH);
    PluginGwtRpcRequestMatcher matcher = spy(new PluginGwtRpcRequestMatcher(TEST_PATTERN, TEST_RPC_METHODS_SINGLE, null));
    // ---
    AbstractGwtRpc gwtRpc1 = matcher.getGwtRpc(requestMock);
    verify(requestMock, times(1)).getAttribute(HTTP_GWT_RPC_ATTRIBUTE);
    verify(requestMock, times(1)).setAttribute(HTTP_GWT_RPC_ATTRIBUTE, gwtRpc1);
    // ---
    when(requestMock.getAttribute(HTTP_GWT_RPC_ATTRIBUTE)).thenReturn(gwtRpc1);
    AbstractGwtRpc gwtRpc2 = matcher.getGwtRpc(requestMock);
    assertEquals(gwtRpc1, gwtRpc2);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AbstractGwtRpc(org.pentaho.platform.web.gwt.rpc.AbstractGwtRpc) Test(org.junit.Test)

Aggregations

AbstractGwtRpc (org.pentaho.platform.web.gwt.rpc.AbstractGwtRpc)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Test (org.junit.Test)5 NonNull (edu.umd.cs.findbugs.annotations.NonNull)3 HttpMethod (javax.ws.rs.HttpMethod)3 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2 Assert.assertNull (org.junit.Assert.assertNull)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 Mockito.doReturn (org.mockito.Mockito.doReturn)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.spy (org.mockito.Mockito.spy)2 Mockito.times (org.mockito.Mockito.times)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.when (org.mockito.Mockito.when)2