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

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

Introduction

In this page you can find the example usage for org.springframework.data.gemfire.snapshot ImportSnapshotException 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 = ImportSnapshotException.class)
public void loadCacheSnapshotWithDirectoryAndFormatHandlesExceptionAppropriately() throws Exception {
    CacheSnapshotService mockCacheSnapshotService = mock(CacheSnapshotService.class,
            "MockCacheSnapshotService");

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

    CacheSnapshotServiceAdapter adapter = new CacheSnapshotServiceAdapter(mockCacheSnapshotService);

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

    try {// ww w .  ja v  a2  s  .c o  m
        adapter.load(FileSystemUtils.WORKING_DIRECTORY, SnapshotFormat.GEMFIRE);
    } catch (ImportSnapshotException expected) {
        assertThat(expected.getMessage(),
                is(equalTo(String.format("Failed to load snapshots from 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)).load(eq(FileSystemUtils.WORKING_DIRECTORY),
                eq(SnapshotFormat.GEMFIRE));
    }
}

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

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

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

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

    CacheSnapshotServiceAdapter adapter = new CacheSnapshotServiceAdapter(mockCacheSnapshotService);

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

    try {/*from   www  .ja  v  a 2s .c o  m*/
        adapter.load(SnapshotFormat.GEMFIRE, mockSnapshotOptions, snapshotDat);
    } catch (ImportSnapshotException expected) {
        assertThat(expected.getMessage(),
                is(equalTo(String.format(
                        "Failed to load snapshots (%1$s) in format (GEMFIRE) using options (%2$s)",
                        Arrays.toString(new File[] { snapshotDat }), mockSnapshotOptions))));
        assertThat(expected.getCause(), is(instanceOf(ClassCastException.class)));
        assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
        throw expected;
    } finally {
        verify(mockCacheSnapshotService, times(1)).load(eq(new File[] { snapshotDat }),
                eq(SnapshotFormat.GEMFIRE), Matchers.isA(SnapshotOptions.class));
    }
}

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

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

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

    RegionSnapshotServiceAdapter adapter = new RegionSnapshotServiceAdapter(mockRegionSnapshotService);

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

    try {//from w  w w.  j a  va 2s  .  c  o  m
        adapter.load(snapshotDat, SnapshotFormat.GEMFIRE);
    } catch (ImportSnapshotException expected) {
        assertThat(expected.getMessage(), is(equalTo(
                String.format("Failed to load snapshot from 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)).load(eq(snapshotDat), eq(SnapshotFormat.GEMFIRE));
    }
}

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

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

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

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

    RegionSnapshotServiceAdapter adapter = new RegionSnapshotServiceAdapter(mockRegionSnapshotService);

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

    try {//www  .j  a va2 s.c o  m
        adapter.load(SnapshotFormat.GEMFIRE, mockSnapshotOptions, snapshotDat);
    } catch (ImportSnapshotException expected) {
        assertThat(expected.getMessage(),
                is(equalTo(String.format(
                        "Failed to load snapshots (%1$s) in format (GEMFIRE) using options (%2$s)",
                        Arrays.toString(new File[] { snapshotDat }), mockSnapshotOptions))));
        assertThat(expected.getCause(), is(instanceOf(ClassCastException.class)));
        assertThat(expected.getCause().getMessage(), is(equalTo("TEST")));
        throw expected;
    } finally {
        verify(mockRegionSnapshotService, times(1)).load(eq(snapshotDat), eq(SnapshotFormat.GEMFIRE),
                eq(mockSnapshotOptions));
    }
}