use of com.google.gwt.user.server.rpc.SerializationPolicy in project pentaho-platform by pentaho.
the class AbstractGwtRpcTest method testLoadSerializationPolicyFromInputStreamLogsAndReturnsNullAndClosesStreamIfLoadThrowsParseException.
@Test
public void testLoadSerializationPolicyFromInputStreamLogsAndReturnsNullAndClosesStreamIfLoadThrowsParseException() throws IOException {
String serializationPolicyFileName = "ABCDF12345.gwt.rpc";
InputStream inputStreamMock = mock(InputStream.class);
ThrowingSupplier<InputStream, IOException> inputStreamSupplier = () -> inputStreamMock;
ParseException error = new ParseException("ABC", 0);
try (MockedStatic<SerializationPolicyLoader> serializationPolicyLoader = Mockito.mockStatic(SerializationPolicyLoader.class)) {
serializationPolicyLoader.when(() -> SerializationPolicyLoader.loadFromStream(inputStreamMock, null)).thenThrow(error);
SerializationPolicy result = AbstractGwtRpc.loadSerializationPolicyFromInputStream(inputStreamSupplier, serializationPolicyFileName);
assertNull(result);
verify(loggerMock).error(nullable(String.class), eq(error));
verify(inputStreamMock).close();
}
}
use of com.google.gwt.user.server.rpc.SerializationPolicy in project pentaho-platform by pentaho.
the class AbstractGwtRpcTest method testLoadSerializationPolicyFromInputStreamLogsAndReturnsNullIfSupplierThrowsIOException.
@Test
public void testLoadSerializationPolicyFromInputStreamLogsAndReturnsNullIfSupplierThrowsIOException() {
String serializationPolicyFileName = "ABCDF12345.gwt.rpc";
IOException error = new IOException();
ThrowingSupplier<InputStream, IOException> inputStreamSupplier = () -> {
throw error;
};
SerializationPolicy result = AbstractGwtRpc.loadSerializationPolicyFromInputStream(inputStreamSupplier, serializationPolicyFileName);
assertNull(result);
verify(loggerMock).error(nullable(String.class), eq(error));
}
use of com.google.gwt.user.server.rpc.SerializationPolicy in project pentaho-platform by pentaho.
the class AbstractGwtRpcTest method testLoadSerializationPolicyFromInputStreamDoesNotLogErrorAndClosesStreamWhenSuccessful.
@Test
public void testLoadSerializationPolicyFromInputStreamDoesNotLogErrorAndClosesStreamWhenSuccessful() throws IOException {
String serializationPolicyFileName = "ABCDF12345.gwt.rpc";
InputStream inputStreamMock = mock(InputStream.class);
ThrowingSupplier<InputStream, IOException> inputStreamSupplier = () -> inputStreamMock;
SerializationPolicy policy = mock(SerializationPolicy.class);
try (MockedStatic<SerializationPolicyLoader> serializationPolicyLoader = Mockito.mockStatic(SerializationPolicyLoader.class)) {
serializationPolicyLoader.when(() -> SerializationPolicyLoader.loadFromStream(inputStreamMock, null)).thenReturn(policy);
AbstractGwtRpc.loadSerializationPolicyFromInputStream(inputStreamSupplier, serializationPolicyFileName);
verify(loggerMock, never()).error(nullable(String.class), any());
verify(loggerMock, never()).error(nullable(String.class));
verify(inputStreamMock).close();
}
}
use of com.google.gwt.user.server.rpc.SerializationPolicy in project pentaho-platform by pentaho.
the class PluginGwtRpcTest method testLoadSerializationPolicySupportsPluginBean.
// endregion
// region Serialization Policy
@Test
public void testLoadSerializationPolicySupportsPluginBean() {
String pathInfo = "/serviceName";
String pluginId = "data-access";
String moduleContextPath = "/content/data-access/resources/gwt/";
String strongName = "ABC";
// ---
try (MockedStatic<PluginUtil> pluginUtilMock = mockStatic(PluginUtil.class)) {
pluginUtilMock.when(() -> PluginUtil.getPluginIdFromPath(moduleContextPath)).thenReturn(pluginId);
// ---
SerializationPolicy pluginPolicyMock = mock(SerializationPolicy.class);
pentahoSystemMock = mockStatic(PentahoSystem.class);
pentahoSystemMock.when(() -> PentahoSystem.get(eq(SerializationPolicy.class), eq(null), anyMap())).thenAnswer(invocationOnMock -> {
Map<String, String> props = (Map<String, String>) invocationOnMock.getArguments()[2];
if (pluginId.equals(props.get("plugin"))) {
return pluginPolicyMock;
}
fail();
return mock(SerializationPolicy.class);
});
// ---
HttpServletRequest httpRequestMock = setupHttpRequest(pathInfo);
PluginGwtRpc gwtRpc = new PluginGwtRpc(httpRequestMock);
SerializationPolicy result = gwtRpc.loadSerializationPolicy(moduleContextPath, strongName);
assertEquals(pluginPolicyMock, result);
}
}
Aggregations