use of com.google.gwt.user.server.rpc.SerializationPolicyLoader in project pentaho-platform by pentaho.
the class AbstractGwtRpcTest method testLoadSerializationPolicyFromInputStreamLogsAndReturnsNullAndClosesStreamIfLoadThrowsIOException.
@Test
public void testLoadSerializationPolicyFromInputStreamLogsAndReturnsNullAndClosesStreamIfLoadThrowsIOException() throws IOException {
String serializationPolicyFileName = "ABCDF12345.gwt.rpc";
InputStream inputStreamMock = mock(InputStream.class);
ThrowingSupplier<InputStream, IOException> inputStreamSupplier = () -> inputStreamMock;
IOException error = new IOException();
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.SerializationPolicyLoader in project pentaho-platform by pentaho.
the class AbstractGwtRpcTest method testLoadSerializationPolicyFromInputStreamSuccessfully.
// endregion
// region static loadSerializationPolicyFromInputStream
@Test
public void testLoadSerializationPolicyFromInputStreamSuccessfully() {
String serializationPolicyFileName = "ABCDF12345.gwt.rpc";
InputStream inputStreamMock = mock(InputStream.class);
ThrowingSupplier<InputStream, IOException> inputStreamSupplier = () -> inputStreamMock;
SerializationPolicy policyMock = mock(SerializationPolicy.class);
try (MockedStatic<SerializationPolicyLoader> serializationPolicyLoader = Mockito.mockStatic(SerializationPolicyLoader.class)) {
serializationPolicyLoader.when(() -> SerializationPolicyLoader.loadFromStream(inputStreamMock, null)).thenReturn(policyMock);
SerializationPolicy result = AbstractGwtRpc.loadSerializationPolicyFromInputStream(inputStreamSupplier, serializationPolicyFileName);
assertEquals(policyMock, result);
}
}
use of com.google.gwt.user.server.rpc.SerializationPolicyLoader 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.SerializationPolicyLoader 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();
}
}
Aggregations