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;
}
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());
}
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);
}
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));
}
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);
}
Aggregations