diff --git a/src/main/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBean.java b/src/main/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBean.java index ebe5c665..a9ca334c 100644 --- a/src/main/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBean.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.snapshot; -import static com.gemstone.gemfire.cache.snapshot.SnapshotOptions.SnapshotFormat; import static org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBean.SnapshotServiceAdapter; import java.io.Closeable; @@ -32,8 +30,17 @@ import java.util.jar.JarFile; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.snapshot.CacheSnapshotService; +import com.gemstone.gemfire.cache.snapshot.RegionSnapshotService; +import com.gemstone.gemfire.cache.snapshot.SnapshotFilter; +import com.gemstone.gemfire.cache.snapshot.SnapshotOptions; +import com.gemstone.gemfire.cache.snapshot.SnapshotOptions.SnapshotFormat; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; @@ -46,13 +53,6 @@ import org.springframework.util.FileCopyUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.snapshot.CacheSnapshotService; -import com.gemstone.gemfire.cache.snapshot.RegionSnapshotService; -import com.gemstone.gemfire.cache.snapshot.SnapshotFilter; -import com.gemstone.gemfire.cache.snapshot.SnapshotOptions; - /** * The SnapshotServiceFactoryBean class is a Spring FactoryBean used to configure and create an instance * of an appropriate GemFire Snapshot Service to perform data import and exports. A CacheSnapshotService is created @@ -188,7 +188,7 @@ public class SnapshotServiceFactoryBean implements FactoryBean getRegion() { - return region; + return this.region; } /** @@ -349,8 +349,7 @@ public class SnapshotServiceFactoryBean implements FactoryBean implements FactoryBean implements FactoryBean[] resolveSnapshotMetadata(SnapshotApplicationEvent event) { SnapshotMetadata[] eventSnapshotMetadata = event.getSnapshotMetadata(); - return (!ObjectUtils.isEmpty(eventSnapshotMetadata) ? eventSnapshotMetadata - : (event instanceof ExportSnapshotApplicationEvent ? getExports() : getImports())); + return !ObjectUtils.isEmpty(eventSnapshotMetadata) + ? eventSnapshotMetadata + : (event instanceof ExportSnapshotApplicationEvent ? getExports() : getImports()); } /** @@ -453,8 +453,11 @@ public class SnapshotServiceFactoryBean implements FactoryBean configuration); protected File[] handleDirectoryLocation(File directory) { + return directory.listFiles(new FileFilter() { - @Override public boolean accept(File pathname) { + + @Override + public boolean accept(File pathname) { return nullSafeIsFile(pathname); } }); @@ -506,8 +509,8 @@ public class SnapshotServiceFactoryBean implements FactoryBean implements FactoryBean configuration) { - return (configuration.isFile() ? handleFileLocation(configuration.getLocation()) - : handleDirectoryLocation(configuration.getLocation())); + + return configuration.isFile() + ? handleFileLocation(configuration.getLocation()) + : handleDirectoryLocation(configuration.getLocation()); } @Override diff --git a/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanTest.java b/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanTest.java index aadff68d..89b7edb0 100644 --- a/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanTest.java +++ b/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanTest.java @@ -703,14 +703,14 @@ public class SnapshotServiceFactoryBeanTest { SnapshotOptions mockSnapshotOptionsTwo = mock(SnapshotOptions.class, "MockSnapshotOptionsTwo"); when(mockCache.getSnapshotService()).thenReturn(mockCacheSnapshotService); - when(mockCacheSnapshotService.createOptions()).thenReturn(mockSnapshotOptionsOne) - .thenReturn(mockSnapshotOptionsTwo); + when(mockCacheSnapshotService.createOptions()).thenReturn(mockSnapshotOptionsOne).thenReturn(mockSnapshotOptionsTwo); when(mockSnapshotOptionsOne.setFilter(eq(mockSnapshotFilterOne))).thenReturn(mockSnapshotOptionsOne); when(mockSnapshotOptionsTwo.setFilter(eq(mockSnapshotFilterTwo))).thenReturn(mockSnapshotOptionsTwo); SnapshotMetadata[] expectedImports = toArray( - newSnapshotMetadata(FileSystemUtils.USER_HOME, mockSnapshotFilterOne), - newSnapshotMetadata(mockSnapshotFilterTwo)); + newSnapshotMetadata(FileSystemUtils.TEMPORARY_DIRECTORY, mockSnapshotFilterOne), + newSnapshotMetadata(mockSnapshotFilterTwo) + ); SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean(); @@ -730,11 +730,12 @@ public class SnapshotServiceFactoryBeanTest { verify(mockCache, times(1)).getSnapshotService(); verify(mockCacheSnapshotService, times(2)).createOptions(); - verify(mockCacheSnapshotService, times(1)).load(eq(FileSystemUtils.safeListFiles(FileSystemUtils.USER_HOME, FileSystemUtils.FileOnlyFilter.INSTANCE)), - eq(SnapshotFormat.GEMFIRE), eq(mockSnapshotOptionsOne)); - verify(mockCacheSnapshotService, times(1)).load(eq(FileSystemUtils.safeListFiles( - FileSystemUtils.WORKING_DIRECTORY, FileSystemUtils.FileOnlyFilter.INSTANCE)), - eq(SnapshotFormat.GEMFIRE), eq(mockSnapshotOptionsTwo)); + verify(mockCacheSnapshotService, times(1)) + .load(eq(FileSystemUtils.safeListFiles(FileSystemUtils.TEMPORARY_DIRECTORY, FileSystemUtils.FileOnlyFilter.INSTANCE)), + eq(SnapshotFormat.GEMFIRE), eq(mockSnapshotOptionsOne)); + verify(mockCacheSnapshotService, times(1)) + .load(eq(FileSystemUtils.safeListFiles(FileSystemUtils.WORKING_DIRECTORY, FileSystemUtils.FileOnlyFilter.INSTANCE)), + eq(SnapshotFormat.GEMFIRE), eq(mockSnapshotOptionsTwo)); verify(mockSnapshotOptionsOne, times(1)).setFilter(eq(mockSnapshotFilterOne)); verify(mockSnapshotOptionsTwo, times(1)).setFilter(eq(mockSnapshotFilterTwo)); } @@ -1252,7 +1253,7 @@ public class SnapshotServiceFactoryBeanTest { } @Test - public void createSnapshotMetadataWithFileNullFilterAndGemFireFormat() throws Exception { + public void createSnapshotMetadataWithFileNullFilterAndGemFireFormat() { SnapshotMetadata snapshotMetadata = new SnapshotMetadata(snapshotDat, null, SnapshotFormat.GEMFIRE);