Search in sources :

Example 1 with SerializationPolicyLoader

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();
    }
}
Also used : SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) InputStream(java.io.InputStream) SerializationPolicyLoader(com.google.gwt.user.server.rpc.SerializationPolicyLoader) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IOException(java.io.IOException)

Example 2 with SerializationPolicyLoader

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);
    }
}
Also used : SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) InputStream(java.io.InputStream) SerializationPolicyLoader(com.google.gwt.user.server.rpc.SerializationPolicyLoader) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IOException(java.io.IOException)

Example 3 with SerializationPolicyLoader

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();
    }
}
Also used : SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) InputStream(java.io.InputStream) SerializationPolicyLoader(com.google.gwt.user.server.rpc.SerializationPolicyLoader) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IOException(java.io.IOException) ParseException(java.text.ParseException)

Example 4 with SerializationPolicyLoader

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();
    }
}
Also used : SerializationPolicy(com.google.gwt.user.server.rpc.SerializationPolicy) InputStream(java.io.InputStream) SerializationPolicyLoader(com.google.gwt.user.server.rpc.SerializationPolicyLoader) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IOException(java.io.IOException)

Aggregations

SerializationPolicy (com.google.gwt.user.server.rpc.SerializationPolicy)4 SerializationPolicyLoader (com.google.gwt.user.server.rpc.SerializationPolicyLoader)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 ParseException (java.text.ParseException)1