Example usage for org.springframework.data.gemfire.snapshot ExportSnapshotException getCause

List of usage examples for org.springframework.data.gemfire.snapshot ExportSnapshotException getCause

Introduction

In this page you can find the example usage for org.springframework.data.gemfire.snapshot ExportSnapshotException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBeanTest.java

@Test(expected = ExportSnapshotException.class)
public void saveCacheSnapshotWithDirectoryAndFormatHandlesExceptionAppropriately() throws Exception {
    CacheSnapshotService mockCacheSnapshotService = mock(CacheSnapshotService.class,
            "MockCacheSnapshotService");

    doThrow(new IOException("TEST")).when(mockCacheSnapshotService).save(any(File.class),
            any(SnapshotFormat.class));

    CacheSnapshotServiceAdapter adapter = new CacheSnapshotServiceAdapter(mockCacheSnapshotService);

    assertThat(adapter.getSnapshotService(), is(equalTo(mockCacheSnapshotService)));

    try {//from   w  w w. j a  va  2 s  .  c  o  m
        adapter.save(FileSystemUtils.WORKING_DIRECTORY, SnapshotFormat.GEMFIRE);
    } catch (ExportSnapshotException expected) {
        assertThat(expected.getMessage(),
                is(equalTo(String.format("Failed to save snapshots to directory (%1$s) in format (GEMFIRE)",
                        FileSystemUtils.WORKING_DIRECTORY))));
        assertThat(expected.getCause(), is(instanceOf(IOException.class)));
        assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
        throw expected;
    } finally {
        verify(mockCacheSnapshotService, times(1)).save(eq(FileSystemUtils.WORKING_DIRECTORY),
                eq(SnapshotFormat.GEMFIRE));
    }
}

From source file:org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBeanTest.java

@Test(expected = ExportSnapshotException.class)
public void saveCacheSnapshotWithDirectoryFormatAndOptionsHandlesExceptionAppropriately() throws Exception {
    SnapshotOptions mockSnapshotOptions = mock(SnapshotOptions.class, "MockSnapshotOptions");

    CacheSnapshotService mockCacheSnapshotService = mock(CacheSnapshotService.class,
            "MockCacheSnapshotService");

    doThrow(new ClassCastException("TEST")).when(mockCacheSnapshotService).save(any(File.class),
            any(SnapshotFormat.class), any(SnapshotOptions.class));

    CacheSnapshotServiceAdapter adapter = new CacheSnapshotServiceAdapter(mockCacheSnapshotService);

    assertThat(adapter.getSnapshotService(), is(equalTo(mockCacheSnapshotService)));

    try {/* w  w w. ja v a2 s . c  o m*/
        adapter.save(FileSystemUtils.USER_HOME, SnapshotFormat.GEMFIRE, mockSnapshotOptions);
    } catch (ExportSnapshotException expected) {
        assertThat(expected.getMessage(),
                is(equalTo(String.format(
                        "Failed to save snapshots to directory (%1$s) in format (GEMFIRE) using options (%2$s)",
                        FileSystemUtils.USER_HOME, mockSnapshotOptions))));
        assertThat(expected.getCause(), is(instanceOf(ClassCastException.class)));
        assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
        throw expected;
    } finally {
        verify(mockCacheSnapshotService, times(1)).save(eq(FileSystemUtils.USER_HOME),
                eq(SnapshotFormat.GEMFIRE), Matchers.isA(SnapshotOptions.class));
    }
}

From source file:org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBeanTest.java

@Test(expected = ExportSnapshotException.class)
public void saveRegionSnapshotWithSnapshotFileAndFormatHandlesExceptionAppropriately() throws Exception {
    RegionSnapshotService mockRegionSnapshotService = mock(RegionSnapshotService.class,
            "MockRegionSnapshotService");

    doThrow(new IOException("TEST")).when(mockRegionSnapshotService).save(any(File.class),
            any(SnapshotFormat.class));

    RegionSnapshotServiceAdapter adapter = new RegionSnapshotServiceAdapter(mockRegionSnapshotService);

    assertThat(adapter.getSnapshotService(), is(equalTo(mockRegionSnapshotService)));

    try {// w  w w  .  ja va  2  s .  com
        adapter.save(snapshotDat, SnapshotFormat.GEMFIRE);
    } catch (ExportSnapshotException expected) {
        assertThat(expected.getMessage(), is(equalTo(
                String.format("Failed to save snapshot to file (%1$s) in format (GEMFIRE)", snapshotDat))));
        assertThat(expected.getCause(), is(instanceOf(IOException.class)));
        assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
        throw expected;
    } finally {
        verify(mockRegionSnapshotService, times(1)).save(eq(snapshotDat), eq(SnapshotFormat.GEMFIRE));
    }
}

From source file:org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBeanTest.java

@Test(expected = ExportSnapshotException.class)
public void saveRegionSnapshotWithSnapshotFileFormatAndOptionsHandlesExceptionAppropriately() throws Exception {
    SnapshotOptions mockSnapshotOptions = mock(SnapshotOptions.class, "MockSnapahotOptions");

    RegionSnapshotService mockRegionSnapshotService = mock(RegionSnapshotService.class,
            "MockRegionSnapshotService");

    doThrow(new ClassCastException("TEST")).when(mockRegionSnapshotService).save(any(File.class),
            any(SnapshotFormat.class), any(SnapshotOptions.class));

    RegionSnapshotServiceAdapter adapter = new RegionSnapshotServiceAdapter(mockRegionSnapshotService);

    assertThat(adapter.getSnapshotService(), is(equalTo(mockRegionSnapshotService)));

    try {/*from   w w  w  .  j  av a  2 s  .c  o  m*/
        adapter.save(snapshotDat, SnapshotFormat.GEMFIRE, mockSnapshotOptions);
    } catch (ExportSnapshotException expected) {
        assertThat(expected.getMessage(),
                is(equalTo(String.format(
                        "Failed to save snapshot to file (%1$s) in format (GEMFIRE) using options (%2$s)",
                        snapshotDat, mockSnapshotOptions))));
        assertThat(expected.getCause(), is(instanceOf(ClassCastException.class)));
        assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
        throw expected;
    } finally {
        verify(mockRegionSnapshotService, times(1)).save(eq(snapshotDat), eq(SnapshotFormat.GEMFIRE),
                eq(mockSnapshotOptions));
    }
}