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