From a9d8dfc33eeb6682e7ac177253f27be4c9c10b96 Mon Sep 17 00:00:00 2001 From: John Blum Date: Wed, 21 Jul 2021 13:15:07 -0700 Subject: [PATCH] Remove old SDG test framework classes. Refactor and cleanup test classes in the SDG test suite using the old SDG test framework to now use STDG. Resolves gh-296. --- ...ClusterConfigurationIntegrationTests.java} | 51 +- ...ngPropertyPlaceholdersIntegrationTest.java | 80 - ...gPropertyPlaceholdersIntegrationTests.java | 79 + .../data/gemfire/ForkUtil.java | 27 +- ...ledClientCacheRegionsIntegrationTests.java | 7 +- .../gemfire/GemfireTemplateUnitTests.java | 6 +- .../gemfire/GenericRegionFactoryBeanTest.java | 37 +- ...ecreatingSpringApplicationContextTest.java | 10 +- ...st.java => SubRegionIntegrationTests.java} | 29 +- ...undCachePutCacheEvictIntegrationTests.java | 2 +- .../cache/GemfireCacheIntegrationTests.java | 76 +- ... ClientCacheIndexingIntegrationTests.java} | 44 +- .../client/ClientCacheIntegrationTests.java | 20 +- ...a => ClientCachePoolIntegrationTests.java} | 25 +- ... ClientCacheSecurityIntegrationTests.java} | 54 +- ...acheVariableLocatorsIntegrationTests.java} | 75 +- .../ClientCacheVariableLocatorsTest.java | 135 - ...tCacheVariableServersIntegrationTests.java | 106 + .../client/ClientRegionIntegrationTests.java | 13 +- .../ClientSubRegionIntegrationTests.java | 57 +- .../DurableClientCacheIntegrationTest.java | 43 +- .../GemFireDataSourceIntegrationTest.java | 59 +- .../GemFireDataSourceIntegrationTests.java | 41 +- ...figuredGemFireServerIntegrationTests.java} | 87 +- ...essionConfiguredPoolsIntegrationTests.java | 15 +- ...actCacheConfigurationIntegrationTests.java | 6 +- ...AbstractGeodeSecurityIntegrationTests.java | 68 +- ...cheShiroRealmSecurityIntegrationTests.java | 5 +- ...ticationConfigurationIntegrationTests.java | 44 +- ...CacheServerConfigurerIntegrationTests.java | 14 +- ...CacheServerPropertiesIntegrationTests.java | 21 +- ...liesRegionConfigurersIntegrationTests.java | 14 +- ...CacheConfigCacheNamesIntegrationTests.java | 19 +- ...onsRegistersInterestsIntegrationTests.java | 24 +- ...entCacheConfigurationIntegrationTests.java | 9 +- ...ClientCacheConfigurerIntegrationTests.java | 14 +- ...ClientCachePropertiesIntegrationTests.java | 10 +- ...erverCacheApplicationIntegrationTests.java | 50 +- ...tpRequestInterceptorsIntegrationTests.java | 8 +- ...emfireAdminOperationsIntegrationTests.java | 12 +- .../DiskStoreConfigurerIntegrationTests.java | 7 +- .../DiskStorePropertiesIntegrationTests.java | 11 +- ...yLocatorConfigurationIntegrationTests.java | 11 +- ...CachingDefinedRegionsIntegrationTests.java | 6 +- .../EnableCachingDefinedRegionsUnitTests.java | 9 +- ...eClusterConfigurationIntegrationTests.java | 41 +- ...igurationWithSecurityIntegrationTests.java | 35 +- ...ClusterDefinedRegionsIntegrationTests.java | 45 +- .../EnableClusterDefinedRegionsUnitTests.java | 4 +- ...ableCompressionConfigurationUnitTests.java | 23 +- ...sQueriesConfigurationIntegrationTests.java | 52 +- ...ntinuousQueriesConfigurationUnitTests.java | 31 +- ...hClusterConfigurationIntegrationTests.java | 32 +- ...nableDiskStoresConfigurationUnitTests.java | 10 +- ...eEntityDefinedRegionsIntegrationTests.java | 10 +- .../EnableEntityDefinedRegionsUnitTests.java | 10 +- ...hAssignableTypeFilterIntegrationTests.java | 9 +- ...egionsWithRegexFilterIntegrationTests.java | 9 +- ...EvictionConfigurationIntegrationTests.java | 7 +- .../EnableEvictionConfigurationUnitTests.java | 8 +- ...pirationConfigurationIntegrationTests.java | 6 +- ...nableExpirationConfigurationUnitTests.java | 33 +- ...ableGatewayReceiverConfigurationTests.java | 6 +- ...ableGemFirePropertiesIntegrationTests.java | 17 +- .../EnableOffHeapConfigurationUnitTests.java | 18 +- ...nablePdxConfigurationIntegrationTests.java | 23 +- .../EnablePdxConfigurationUnitTests.java | 4 +- ...nableSslConfigurationIntegrationTests.java | 23 +- .../EnableSslConfigurationUnitTests.java | 12 +- .../GatewayReceiverConfigurerTests.java | 6 +- .../GatewayReceiverPropertiesTests.java | 6 +- ...ySenderConfigurationIntegrationTests.java} | 73 +- .../GatewaySenderConfigurerTests.java | 62 +- ...ewaySenderPropertiesIntegrationTests.java} | 22 +- ...eAsLastResourceConfigurationUnitTests.java | 4 +- .../IndexConfigurerIntegrationTests.java | 18 +- ...tWithCacheApplicationIntegrationTests.java | 9 +- ...licationConfigurationIntegrationTests.java | 9 +- ...ApplicationConfigurerIntegrationTests.java | 8 +- ...ApplicationPropertiesIntegrationTests.java | 16 +- .../PeerCacheApplicationIntegrationTests.java | 6 +- ...nWithAddedCacheServerIntegrationTests.java | 17 +- .../PeerCacheConfigurerIntegrationTests.java | 18 +- .../PeerCachePropertiesIntegrationTests.java | 11 +- .../PoolPropertiesIntegrationTests.java | 13 +- .../RegionConfigurerIntegrationTests.java | 24 +- ...egionDataAccessTracingAspectUnitTests.java | 31 +- ...eAsLastResourceAspectSupportUnitTests.java | 5 +- ...GemFireAsLastResourceIntegrationTests.java | 6 +- ...rceConnectionAcquiringAspectUnitTests.java | 7 +- ...ourceConnectionClosingAspectUnitTests.java | 5 +- .../schema/SchemaObjectTypeUnitTests.java | 8 +- .../definitions/IndexDefinitionUnitTests.java | 13 +- .../RegionDefinitionUnitTests.java | 11 +- ...posableSchemaObjectCollectorUnitTests.java | 10 +- ...egionLookupBeanPostProcessorUnitTests.java | 6 +- ...itorBeanFactoryPostProcessorUnitTests.java | 4 +- ...edIndexesApplicationListenerUnitTests.java | 9 +- ...toryBeanPostProcessorIntegrationTests.java | 6 +- ...nFactoryPostProcessorIntegrationTests.java | 17 +- ...wareBeanFactoryPostProcessorUnitTests.java | 4 +- .../config/xml/CacheServerNamespaceTest.java | 23 +- ...acheUsingPdxNamespaceIntegrationTests.java | 87 + .../xml/CacheUsingPdxNamespaceTest.java | 84 - ...t.java => ClientRegionNamespaceTests.java} | 38 +- ...erContainerNamespaceIntegrationTests.java} | 30 +- ...irationRegionParsingIntegrationTests.java} | 31 +- .../DiskStoreNamespaceIntegrationTests.java | 80 + .../config/xml/DiskStoreNamespaceTest.java | 82 - ...tionServiceNamespaceIntegrationTests.java} | 43 +- ...erAutoStartNamespaceIntegrationTests.java} | 49 +- ...efaultStartNamespaceIntegrationTests.java} | 51 +- ...rManualStartNamespaceIntegrationTests.java | 78 + ...tewayReceiverManualStartNamespaceTest.java | 78 - .../xml/GemfireV7GatewayNamespaceTest.java | 4 +- ...ireV8GatewayNamespaceIntegrationTests.java | 123 + .../xml/GemfireV8GatewayNamespaceTest.java | 118 - ...va => IndexNamespaceIntegrationTests.java} | 22 +- ...nAttributesNamespaceIntegrationTests.java} | 20 +- ...LocalRegionNamespaceIntegrationTests.java} | 14 +- ...olicyActionNamespaceIntegrationTests.java} | 30 +- .../MembershipAttributesIntegrationTests.java | 70 + .../config/xml/MembershipAttributesTest.java | 63 - ...ionedRegionNamespaceIntegrationTests.java} | 20 +- ...ava => PoolNamespaceIntegrationTests.java} | 17 +- ...nUsingBeansNamespaceIntegrationTests.java} | 47 +- ...nAttributesNamespaceIntegrationTests.java} | 30 +- ...nAttributesNamespaceIntegrationTests.java} | 26 +- ...nAttributesNamespaceIntegrationTests.java} | 46 +- ...anDefinitionHashCodeIntegrationTests.java} | 56 +- ...tenceEvictionSettingsIntegrationTests.java | 120 + ...oreAndPersistenceEvictionSettingsTest.java | 114 - ...catedRegionNamespaceIntegrationTests.java} | 24 +- .../SubRegionNamespaceIntegrationTests.java | 143 + .../config/xml/SubRegionNamespaceTest.java | 132 - ...nSubElementNamespaceIntegrationTests.java} | 40 +- ...itionRegionNamespaceIntegrationTests.java} | 57 +- ...lateRegionsNamespaceIntegrationTests.java} | 30 +- ...a => TxEventHandlersIntegrationTests.java} | 23 +- .../TxManagerNamespaceIntegrationTests.java | 55 + .../config/xml/TxManagerNamespaceTest.java | 51 - ...xpirationConfigurationIntegrationTest.java | 149 +- .../fork/GemFireBasedServerProcess.java | 4 +- .../data/gemfire/fork/LocatorProcess.java | 10 +- .../data/gemfire/fork/ServerProcess.java | 4 +- ...nctionExecutionWithPdxIntegrationTest.java | 29 +- ...ingFunctionExecutionIntegrationTests.java} | 22 +- .../FunctionExecutionIntegrationTests.java | 48 +- .../config/FunctionsWithClientCacheTests.java | 9 +- ...uredFunctionExecutionIntegrationTests.java | 37 +- .../FunctionExecutionIntegrationTests.java | 49 +- .../execution/FunctionIntegrationTests.java | 37 +- ...mfireFunctionTemplateIntegrationTests.java | 42 +- ...ResultsFromAllServersIntegrationTests.java | 22 +- ...> FunctionResultTypeIntegrationTests.java} | 10 +- .../ListenerContainerIntegrationTests.java | 66 +- .../ContainerXmlSetupIntegrationTests.java | 44 +- .../gemfire/process/ProcessConfiguration.java | 102 - .../data/gemfire/process/ProcessExecutor.java | 158 - .../process/ProcessInputStreamListener.java | 41 - .../data/gemfire/process/ProcessWrapper.java | 337 -- .../support/PidUnavailableException.java | 45 - .../gemfire/process/support/ProcessUtils.java | 227 -- ...oryFactoryInformationIntegrationTests.java | 9 +- ...onNamespaceRepositoryIntegrationTests.java | 29 +- ...RepositoriesRegistrarIntegrationTests.java | 9 +- ...AndEntityIdRepositoryIntegrationTests.java | 11 +- ...sitoryRegionDeleteAllIntegrationTests.java | 26 +- ...ggeredImportsExportsIntegrationTests.java} | 57 +- ...otServiceFactoryBeanIntegrationTests.java} | 42 +- .../SnapshotServiceFactoryBeanTest.java | 419 +-- ...hotServiceImportExportIntegrationTest.java | 69 +- .../event/SnapshotApplicationEventTest.java | 130 +- ...catorAnnotationConfigIntegrationTests.java | 15 +- ...toryLocatorJavaConfigIntegrationTests.java | 17 +- ...ringDeclarableSupportIntegrationTests.java | 45 +- ...strappingInitializerIntegrationTests.java} | 19 +- ...ngContextBootstrappingInitializerTest.java | 2 +- .../sample/UserApplicationConfiguration.java | 4 +- ...fireTestApplicationContextInitializer.java | 62 - .../test/GemfireTestBeanPostProcessor.java | 59 - .../gemfire/test/MockCacheFactoryBean.java | 76 - .../test/MockClientCacheFactoryBean.java | 71 - .../gemfire/test/MockClientRegionFactory.java | 329 -- .../data/gemfire/test/MockRegionFactory.java | 484 --- .../gemfire/test/MockRegionFactoryTest.java | 35 - .../test/StubAsyncEventQueueFactory.java | 164 - .../data/gemfire/test/StubCache.java | 874 ----- .../data/gemfire/test/StubCacheServer.java | 422 --- .../test/StubCacheTransactionManager.java | 201 -- .../data/gemfire/test/StubDiskStore.java | 179 - .../test/StubGatewayReceiverFactory.java | 201 -- .../test/StubGatewaySenderFactory.java | 232 -- .../gemfire/test/StubResourceManager.java | 102 - .../logging/slf4j/logback/TestAppender.java | 75 - .../test/mock/GemFireMockObjectsSupport.java | 2912 ----------------- .../gemfire/test/mock/MockObjectsSupport.java | 189 -- .../annotation/EnableGemFireMockObjects.java | 59 - .../GemFireMockObjectsConfiguration.java | 103 - .../test/mock/annotation/GemFireUnitTest.java | 59 - .../GemFireMockObjectsBeanPostProcessor.java | 174 - ...kObjectsApplicationContextInitializer.java | 41 - .../MockObjectInvocationException.java | 73 - .../mock/support/MockObjectsException.java | 71 - .../data/gemfire/test/model/Person.java | 2 +- ...actGemFireClientServerIntegrationTest.java | 154 - .../support/AbstractNativeCacheTests.java | 62 +- .../AbstractRegionFactoryBeanTests.java | 29 +- ...nitAndIntegrationTestsWithMockSupport.java | 58 - .../ClientServerIntegrationTestsSupport.java | 300 -- .../test/support/DataSourceAdapter.java | 85 - .../gemfire/test/support/FileSystemUtils.java | 247 -- .../data/gemfire/test/support/FileUtils.java | 106 - .../data/gemfire/test/support/IOUtils.java | 96 - .../test/support/IdentifierSequence.java | 38 - .../data/gemfire/test/support/MapBuilder.java | 1 - .../gemfire/test/support/SocketUtils.java | 69 - .../gemfire/test/support/StackTraceUtils.java | 82 - .../gemfire/test/support/ThreadUtils.java | 76 - .../gemfire/test/support/ThrowableUtils.java | 41 - .../data/gemfire/test/support/ZipUtils.java | 70 - ...taAccessWithRollbackIntegrationTests.java} | 35 +- ...eByIdXmlConfigurationIntegrationTests.java | 24 +- ...entQueueWithListenerIntegrationTests.java} | 91 +- ...rByIdXmlConfigurationIntegrationTests.java | 24 +- ...alGatewayReceiverStartIntegrationTest.java | 53 +- ...tstrap-initializer-using-base-packages.xml | 2 +- ...h-spring-context-bootstrap-initializer.xml | 2 +- .../src/test/resources/logback.xml | 2 +- .../ClientCachePoolTests-server-context.xml | 2 +- ...ClientCacheSecurityTest-server-context.xml | 2 +- ...cheVariableLocatorsTest-server-context.xml | 2 +- ...acheVariableServersTest-server-context.xml | 2 +- ...irationAttributesNamespaceTest-context.xml | 4 +- ...initionUsingBeansNamespaceTest-context.xml | 4 +- ...irationAttributesNamespaceTest-context.xml | 6 +- ...ntPartitionRegionNamespaceTest-context.xml | 2 +- .../TemplateRegionsNamespaceTests-context.xml | 30 +- .../data/gemfire/config/xml/client-ns.xml | 6 +- .../data/gemfire/config/xml/diskstore-ns.xml | 4 +- .../config/xml/function-service-ns.xml | 4 +- .../data/gemfire/config/xml/gateway-v8-ns.xml | 4 +- .../data/gemfire/config/xml/local-ns.xml | 2 +- .../gemfire/config/xml/partitioned-ns.xml | 12 +- .../data/gemfire/config/xml/replicated-ns.xml | 2 +- .../config/xml/subregionsubelement-ns.xml | 4 +- .../config/xml/tx-listeners-and-writers.xml | 6 +- ...xecutionIntegrationTest-server-context.xml | 2 +- ...dImportsExportsIntegrationTest-context.xml | 10 +- .../sample/initializer-dao-context.xml | 2 +- .../wan/asyncEventQueueWithListener.xml | 6 +- .../asciidoc/reference/gemfire-bootstrap.adoc | 2 +- 252 files changed, 3237 insertions(+), 12995 deletions(-) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/{CacheClusterConfigurationIntegrationTest.java => CacheClusterConfigurationIntegrationTests.java} (83%) delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/DiskStoreBeanUsingPropertyPlaceholdersIntegrationTest.java create mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/DiskStoreBeanUsingPropertyPlaceholdersIntegrationTests.java rename spring-data-geode/src/test/java/org/springframework/data/gemfire/{SubRegionIntegrationTest.java => SubRegionIntegrationTests.java} (85%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/client/{ClientCacheIndexingTest.java => ClientCacheIndexingIntegrationTests.java} (76%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/client/{ClientCachePoolTests.java => ClientCachePoolIntegrationTests.java} (79%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/client/{ClientCacheSecurityTest.java => ClientCacheSecurityIntegrationTests.java} (67%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/client/{ClientCacheVariableServersTest.java => ClientCacheVariableLocatorsIntegrationTests.java} (50%) delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableLocatorsTest.java create mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableServersIntegrationTests.java rename spring-data-geode/src/test/java/org/springframework/data/gemfire/client/{GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTest.java => GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTests.java} (72%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/{GatewaySenderConfigurationTests.java => GatewaySenderConfigurationIntegrationTests.java} (88%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/{GatewaySenderPropertiesTests.java => GatewaySenderPropertiesIntegrationTests.java} (97%) create mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceIntegrationTests.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceTest.java rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{ClientRegionNamespaceTest.java => ClientRegionNamespaceTests.java} (90%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{ContinuousQueryListenerContainerNamespaceTest.java => ContinuousQueryListenerContainerNamespaceIntegrationTests.java} (83%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{DiskStoreAndEvictionRegionParsingTest.java => DiskStoreEvictionAndExpirationRegionParsingIntegrationTests.java} (86%) create mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreNamespaceIntegrationTests.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreNamespaceTest.java rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{FunctionServiceNamespaceTest.java => FunctionServiceNamespaceIntegrationTests.java} (51%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{GatewayReceiverAutoStartNamespaceTest.java => GatewayReceiverAutoStartNamespaceIntegrationTests.java} (50%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{GatewayReceiverDefaultStartNamespaceTest.java => GatewayReceiverDefaultStartNamespaceIntegrationTests.java} (52%) create mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverManualStartNamespaceIntegrationTests.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverManualStartNamespaceTest.java create mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceIntegrationTests.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceTest.java rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{IndexNamespaceTest.java => IndexNamespaceIntegrationTests.java} (78%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{InvalidRegionExpirationAttributesNamespaceTest.java => InvalidRegionExpirationAttributesNamespaceIntegrationTests.java} (79%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{LocalRegionNamespaceTest.java => LocalRegionNamespaceIntegrationTests.java} (91%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{LocalRegionWithEvictionPolicyActionNamespaceTest.java => LocalRegionWithEvictionPolicyActionNamespaceIntegrationTests.java} (78%) create mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesIntegrationTests.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesTest.java rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{PartitionedRegionNamespaceTest.java => PartitionedRegionNamespaceIntegrationTests.java} (91%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{PoolNamespaceTest.java => PoolNamespaceIntegrationTests.java} (91%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{RegionDefinitionUsingBeansNamespaceTest.java => RegionDefinitionUsingBeansNamespaceIntegrationTests.java} (75%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{RegionEvictionAttributesNamespaceTest.java => RegionEvictionAttributesNamespaceIntegrationTests.java} (83%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{RegionExpirationAttributesNamespaceTest.java => RegionExpirationAttributesNamespaceIntegrationTests.java} (88%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{RegionSubscriptionAttributesNamespaceTest.java => RegionSubscriptionAttributesNamespaceIntegrationTests.java} (56%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{RegionWithSubRegionBeanDefinitionHashCodeTest.java => RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests.java} (67%) create mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionsWithDiskStoreAndPersistenceEvictionSettingsIntegrationTests.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest.java rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{ReplicatedRegionNamespaceTest.java => ReplicatedRegionNamespaceIntegrationTests.java} (88%) create mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionNamespaceIntegrationTests.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionNamespaceTest.java rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{SubRegionSubElementNamespaceTest.java => SubRegionSubElementNamespaceIntegrationTests.java} (76%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{TemplatePersistentPartitionRegionNamespaceTest.java => TemplatePersistentPartitionRegionNamespaceIntegrationTests.java} (50%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{TemplateRegionsNamespaceTests.java => TemplateRegionsNamespaceIntegrationTests.java} (97%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{TxEventHandlersTest.java => TxEventHandlersIntegrationTests.java} (72%) create mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceIntegrationTests.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceTest.java rename spring-data-geode/src/test/java/org/springframework/data/gemfire/function/{ExceptionThrowingFunctionExecutionIntegrationTest.java => ExceptionThrowingFunctionExecutionIntegrationTests.java} (87%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/function/result/{FunctionResultTypeIntegrationTest.java => FunctionResultTypeIntegrationTests.java} (93%) delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/process/ProcessConfiguration.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/process/ProcessExecutor.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/process/ProcessInputStreamListener.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/process/ProcessWrapper.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/process/support/PidUnavailableException.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/process/support/ProcessUtils.java rename spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/{SnapshotApplicationEventTriggeredImportsExportsIntegrationTest.java => SnapshotApplicationEventTriggeredImportsExportsIntegrationTests.java} (85%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/{SnapshotServiceFactoryBeanIntegrationTest.java => SnapshotServiceFactoryBeanIntegrationTests.java} (69%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/support/{SpringContextBootstrappingInitializerIntegrationTest.java => SpringContextBootstrappingInitializerIntegrationTests.java} (95%) delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/GemfireTestApplicationContextInitializer.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/GemfireTestBeanPostProcessor.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockCacheFactoryBean.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockClientCacheFactoryBean.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockClientRegionFactory.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockRegionFactory.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockRegionFactoryTest.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubAsyncEventQueueFactory.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubCache.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubCacheServer.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubCacheTransactionManager.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubDiskStore.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubGatewayReceiverFactory.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubGatewaySenderFactory.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubResourceManager.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/logging/slf4j/logback/TestAppender.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/GemFireMockObjectsSupport.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/MockObjectsSupport.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/annotation/EnableGemFireMockObjects.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/annotation/GemFireMockObjectsConfiguration.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/annotation/GemFireUnitTest.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/config/GemFireMockObjectsBeanPostProcessor.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/context/GemFireMockObjectsApplicationContextInitializer.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/support/MockObjectInvocationException.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/support/MockObjectsException.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractGemFireClientServerIntegrationTest.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractUnitAndIntegrationTestsWithMockSupport.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/ClientServerIntegrationTestsSupport.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/DataSourceAdapter.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/FileSystemUtils.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/FileUtils.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/IOUtils.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/IdentifierSequence.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/SocketUtils.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/StackTraceUtils.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/ThreadUtils.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/ThrowableUtils.java delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/ZipUtils.java rename spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/{ConcurrentClientDataAccessTransactionsWithRollbackIntegrationTests.java => ConcurrentClientTransactionalDataAccessWithRollbackIntegrationTests.java} (86%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/{AsyncEventQueueWithListenerIntegrationTest.java => AsyncEventQueueWithListenerIntegrationTests.java} (52%) diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheClusterConfigurationIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheClusterConfigurationIntegrationTests.java similarity index 83% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheClusterConfigurationIntegrationTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheClusterConfigurationIntegrationTests.java index b176dd8e..feb74cde 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheClusterConfigurationIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheClusterConfigurationIntegrationTests.java @@ -31,10 +31,6 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; -import org.apache.geode.cache.DataPolicy; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.Scope; - import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Ignore; @@ -44,25 +40,29 @@ import org.junit.rules.TestRule; import org.junit.rules.TestWatcher; import org.junit.runner.Description; +import org.apache.geode.cache.DataPolicy; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.Scope; + import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.io.ClassPathResource; import org.springframework.data.gemfire.fork.LocatorProcess; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; -import org.springframework.data.gemfire.test.support.FileUtils; -import org.springframework.data.gemfire.test.support.ThreadUtils; -import org.springframework.data.gemfire.test.support.ThrowableUtils; -import org.springframework.data.gemfire.test.support.ZipUtils; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.process.ProcessWrapper; +import org.springframework.data.gemfire.tests.util.FileUtils; +import org.springframework.data.gemfire.tests.util.ThreadUtils; +import org.springframework.data.gemfire.tests.util.ThrowableUtils; +import org.springframework.data.gemfire.tests.util.ZipUtils; import org.springframework.data.gemfire.util.ArrayUtils; import org.springframework.util.FileSystemUtils; import org.springframework.util.StringUtils; /** - * Test suite of test cases testing the integration of Spring Data for Apache Geode with Apache Geode's - * new shared, persistent, cluster configuration service. + * Integration Tests testing the integration of Spring Data for Apache Geode with Apache Geode's new shared, persistent, + * cluster configuration service. * * @author John Blum * @see org.junit.Test @@ -70,16 +70,15 @@ import org.springframework.util.StringUtils; * @see org.springframework.context.support.ClassPathXmlApplicationContext * @see org.springframework.core.io.ClassPathResource * @see org.springframework.data.gemfire.fork.LocatorProcess - * @see org.springframework.data.gemfire.process.ProcessExecutor - * @see org.springframework.data.gemfire.process.ProcessWrapper + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @since 1.5.0 */ @SuppressWarnings("unused") -public class CacheClusterConfigurationIntegrationTest extends ClientServerIntegrationTestsSupport { +public class CacheClusterConfigurationIntegrationTests extends ForkingClientServerIntegrationTestsSupport { private static File locatorWorkingDirectory; - private static List locatorProcessOutput = Collections.synchronizedList(new ArrayList<>()); + private static final List locatorProcessOutput = Collections.synchronizedList(new ArrayList<>()); private static ProcessWrapper locatorProcess; @@ -101,7 +100,7 @@ public class CacheClusterConfigurationIntegrationTest extends ClientServerIntegr @Override protected void finished(Description description) { - if (Boolean.valueOf(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) { + if (Boolean.parseBoolean(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) { try { FileUtils.write(new File(locatorWorkingDirectory.getParent(), String.format("%s-clusterconfiglocator.log", description.getMethodName())), @@ -171,12 +170,13 @@ public class CacheClusterConfigurationIntegrationTest extends ClientServerIntegr private static void waitForLocatorStart(final long milliseconds) { - ThreadUtils.timedWait(milliseconds, 500, new ThreadUtils.WaitCondition() { + ThreadUtils.timedWait(milliseconds, 500, new ThreadUtils.Condition() { - File pidControlFile = new File(locatorWorkingDirectory, LocatorProcess.getLocatorProcessControlFilename()); + final File pidControlFile = new File(locatorWorkingDirectory, + LocatorProcess.getLocatorProcessControlFilename()); @Override - public boolean waiting() { + public boolean evaluate() { return !pidControlFile.isFile(); } }); @@ -189,7 +189,7 @@ public class CacheClusterConfigurationIntegrationTest extends ClientServerIntegr System.clearProperty("spring.data.gemfire.locator.port"); - if (Boolean.valueOf(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) { + if (Boolean.parseBoolean(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) { FileSystemUtils.deleteRecursively(locatorWorkingDirectory); } @@ -200,11 +200,11 @@ public class CacheClusterConfigurationIntegrationTest extends ClientServerIntegr Arrays.stream(logFiles).forEach(File::delete); } - private Region assertRegion(Region actualRegion, String expectedRegionName) { + private Region assertRegion(Region actualRegion, String expectedRegionName) { return assertRegion(actualRegion, expectedRegionName, Region.SEPARATOR+expectedRegionName); } - private Region assertRegion(Region actualRegion, String expectedRegionName, String expectedRegionFullPath) { + private Region assertRegion(Region actualRegion, String expectedRegionName, String expectedRegionFullPath) { assertNotNull(String.format("The [%s] was not properly configured and initialized!", expectedRegionName), actualRegion); @@ -214,7 +214,7 @@ public class CacheClusterConfigurationIntegrationTest extends ClientServerIntegr return actualRegion; } - private Region assertRegionAttributes(Region actualRegion, DataPolicy expectedDataPolicy, Scope expectedScope) { + private Region assertRegionAttributes(Region actualRegion, DataPolicy expectedDataPolicy, Scope expectedScope) { assertNotNull(actualRegion); assertNotNull(actualRegion.getAttributes()); @@ -231,7 +231,7 @@ public class CacheClusterConfigurationIntegrationTest extends ClientServerIntegr return baseLocation.concat(File.separator).concat(configLocation); } - private Region getRegion(ConfigurableApplicationContext applicationContext, String regionBeanName) { + private Region getRegion(ConfigurableApplicationContext applicationContext, String regionBeanName) { return applicationContext.getBean(regionBeanName, Region.class); } @@ -268,7 +268,6 @@ public class CacheClusterConfigurationIntegrationTest extends ClientServerIntegr } @Test - @SuppressWarnings("all") public void localConfigurationTest() { try { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/DiskStoreBeanUsingPropertyPlaceholdersIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/DiskStoreBeanUsingPropertyPlaceholdersIntegrationTest.java deleted file mode 100644 index 5e76500c..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/DiskStoreBeanUsingPropertyPlaceholdersIntegrationTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.Map; - -import javax.annotation.Resource; - -import org.apache.geode.cache.DiskStore; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * The DiskStoreBeanUsingPropertyPlaceholdersIntegrationTest class is a test suite of integration tests testing the use - * of Spring PropertyPlaceholders to configure and initialize a Disk Store bean's properties using property placeholders - * in the SDG XML namespace <disk-store> bean definition attributes. - * - * @author John Blum - * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.data.gemfire.DiskStoreFactoryBean - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner - * @see org.apache.geode.cache.DiskStore - * @link https://jira.springsource.org/browse/SGF-249 - * @since 1.3.4 - */ -@RunWith(SpringRunner.class) -@ContextConfiguration(locations = "diskstore-using-propertyplaceholders-config.xml", - initializers = GemfireTestApplicationContextInitializer.class) -@SuppressWarnings("unused") -public class DiskStoreBeanUsingPropertyPlaceholdersIntegrationTest { - - @Autowired - private DiskStore testDataStore; - - @Resource(name="diskStoreConfiguration") - private Map diskStoreConfiguration; - - @SuppressWarnings("unchecked") - protected Object getExpectedValue(final String propertyPlaceholderName) { - return diskStoreConfiguration.get(propertyPlaceholderName); - } - - @Test - public void testDiskStoreBeanWithPropertyPlaceholderConfiguration() { - assertNotNull("The Disk Store was not configured and initialized!", testDataStore); - assertEquals(getExpectedValue("allowForceCompaction"), testDataStore.getAllowForceCompaction()); - assertEquals(getExpectedValue("autoCompact"), testDataStore.getAutoCompact()); - assertEquals(getExpectedValue("compactionThreshold"), testDataStore.getCompactionThreshold()); - assertEquals(getExpectedValue("maxOplogSize"), testDataStore.getMaxOplogSize()); - assertEquals("TestDataStore", testDataStore.getName()); - assertEquals(getExpectedValue("queueSize"), testDataStore.getQueueSize()); - assertEquals(getExpectedValue("timeInterval"), testDataStore.getTimeInterval()); - assertEquals(getExpectedValue("writeBufferSize"), testDataStore.getWriteBufferSize()); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/DiskStoreBeanUsingPropertyPlaceholdersIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/DiskStoreBeanUsingPropertyPlaceholdersIntegrationTests.java new file mode 100644 index 00000000..95342869 --- /dev/null +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/DiskStoreBeanUsingPropertyPlaceholdersIntegrationTests.java @@ -0,0 +1,79 @@ +/* + * Copyright 2010-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.gemfire; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Map; + +import javax.annotation.Resource; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.geode.cache.DiskStore; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Integration Tests testing the use of Spring PropertyPlaceholders to configure and initialize a {@link DiskStore} bean + * properties using property placeholders in the SDG XML namespace <disk-store> bean definition attributes. + * + * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.DiskStore + * @see org.springframework.data.gemfire.DiskStoreFactoryBean + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner + * @link https://jira.springsource.org/browse/SGF-249 + * @since 1.3.4 + */ +@RunWith(SpringRunner.class) +@ContextConfiguration(locations = "diskstore-using-propertyplaceholders-config.xml", + initializers = GemFireMockObjectsApplicationContextInitializer.class) +@SuppressWarnings("unused") +public class DiskStoreBeanUsingPropertyPlaceholdersIntegrationTests extends IntegrationTestsSupport { + + @Autowired + private DiskStore testDataStore; + + @Resource(name="diskStoreConfiguration") + private Map diskStoreConfiguration; + + private Object getExpectedValue(final String propertyPlaceholderName) { + return this.diskStoreConfiguration.get(propertyPlaceholderName); + } + + @Test + public void testDiskStoreBeanWithPropertyPlaceholderConfiguration() { + + assertThat(testDataStore).describedAs("The Disk Store was not configured and initialized!").isNotNull(); + assertThat(testDataStore.getAllowForceCompaction()).isEqualTo(getExpectedValue("allowForceCompaction")); + assertThat(testDataStore.getAutoCompact()).isEqualTo(getExpectedValue("autoCompact")); + assertThat(testDataStore.getCompactionThreshold()).isEqualTo(getExpectedValue("compactionThreshold")); + assertThat(testDataStore.getMaxOplogSize()).isEqualTo(getExpectedValue("maxOplogSize")); + assertThat(testDataStore.getName()).isEqualTo("TestDataStore"); + assertThat(testDataStore.getQueueSize()).isEqualTo(getExpectedValue("queueSize")); + assertThat(testDataStore.getTimeInterval()).isEqualTo(getExpectedValue("timeInterval")); + assertThat(testDataStore.getWriteBufferSize()).isEqualTo(getExpectedValue("writeBufferSize")); + } +} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/ForkUtil.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/ForkUtil.java index c314bb79..c6ddc58f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/ForkUtil.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/ForkUtil.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire; import java.io.BufferedReader; @@ -27,36 +26,36 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import org.springframework.data.gemfire.fork.CqCacheServerProcess; import org.springframework.data.gemfire.fork.FunctionCacheServerProcess; -import org.springframework.data.gemfire.test.support.IOUtils; -import org.springframework.data.gemfire.test.support.ThreadUtils; +import org.springframework.data.gemfire.tests.process.ProcessExecutor; +import org.springframework.data.gemfire.tests.util.IOUtils; +import org.springframework.data.gemfire.tests.util.ThreadUtils; import org.springframework.util.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * Utility class used to fork Java, JVM processes. * * @author Costin Leau * @author John Blum - * @deprecated ForkUtils has serious design flaws; please use ProcessExecutor instead + * @deprecated {@link ForkUtil} has serious design flaws; please use {@link ProcessExecutor} from STDG instead */ @Deprecated public class ForkUtil { private static final long TIMEOUT = 30000L; - @SuppressWarnings("all") private static final Logger logger = LoggerFactory.getLogger(ForkUtil.class); private static OutputStream processStandardInStream; - private static String JAVA_CLASSPATH = System.getProperty("java.class.path"); - private static String JAVA_HOME = System.getProperty("java.home"); - private static String JAVA_EXE = JAVA_HOME.concat(File.separator).concat("bin").concat(File.separator).concat("java"); - private static String TEMP_DIRECTORY = System.getProperty("java.io.tmpdir"); + private static final String JAVA_CLASSPATH = System.getProperty("java.class.path"); + private static final String JAVA_HOME = System.getProperty("java.home"); + private static final String JAVA_EXE = JAVA_HOME.concat(File.separator).concat("bin").concat(File.separator).concat("java"); + private static final String TEMP_DIRECTORY = System.getProperty("java.io.tmpdir"); private static List buildJavaCommand(String arguments) { return buildJavaCommand(arguments.split("\\s+")); @@ -136,7 +135,9 @@ public class ForkUtil { } private static void registerShutdownHook(AtomicBoolean runCondition, Process javaProcess) { + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + runCondition.set(false); processStandardInStream = null; @@ -167,6 +168,7 @@ public class ForkUtil { } protected static OutputStream startGemFireProcess(String args, String processName) { + String className = args.split(" ")[0]; if (controlFileExists(className)) { @@ -189,6 +191,7 @@ public class ForkUtil { } public static void sendSignal() { + try { processStandardInStream.write("\n".getBytes()); processStandardInStream.flush(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationTests.java index 9e1cd025..f50ad98d 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationTests.java @@ -47,11 +47,11 @@ import org.springframework.data.gemfire.client.ClientCacheFactoryBean; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; import org.springframework.data.gemfire.client.PoolFactoryBean; import org.springframework.data.gemfire.mapping.annotation.Region; -import org.springframework.data.gemfire.process.ProcessWrapper; import org.springframework.data.gemfire.server.CacheServerFactoryBean; import org.springframework.data.gemfire.support.ConnectionEndpoint; import org.springframework.data.gemfire.support.ConnectionEndpointList; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.process.ProcessWrapper; import org.springframework.data.gemfire.util.PropertiesBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -78,6 +78,7 @@ import lombok.RequiredArgsConstructor; * @see org.junit.Test * @see org.junit.runner.RunWith * @see org.springframework.data.gemfire.GemfireTemplate + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @see Repository queries on client Regions associated with a Pool configured with a specified server group can lead to a RegionNotFoundException. @@ -88,7 +89,7 @@ import lombok.RequiredArgsConstructor; GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationTests.GemFireClientCacheConfiguration.class) @SuppressWarnings("unused") public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationTests - extends ClientServerIntegrationTestsSupport{ + extends ForkingClientServerIntegrationTestsSupport { private static ProcessWrapper serverOne; private static ProcessWrapper serverTwo; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateUnitTests.java index 4d0267a7..202a395b 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateUnitTests.java @@ -48,7 +48,7 @@ import org.apache.geode.cache.query.QueryService; import org.apache.geode.cache.query.SelectResults; import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.data.gemfire.test.support.AbstractUnitAndIntegrationTestsWithMockSupport; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; /** * Unit Tests for {@link GemfireTemplate} @@ -66,11 +66,11 @@ import org.springframework.data.gemfire.test.support.AbstractUnitAndIntegrationT * @see org.apache.geode.cache.query.QueryService * @see org.apache.geode.cache.query.SelectResults * @see org.springframework.data.gemfire.GemfireTemplate - * @see org.springframework.data.gemfire.test.support.AbstractUnitAndIntegrationTestsWithMockSupport + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport */ @SuppressWarnings("unused") @RunWith(MockitoJUnitRunner.class) -public class GemfireTemplateUnitTests extends AbstractUnitAndIntegrationTestsWithMockSupport { +public class GemfireTemplateUnitTests extends IntegrationTestsSupport { private GemfireTemplate template; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/GenericRegionFactoryBeanTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/GenericRegionFactoryBeanTest.java index 4b4e69ef..10afe94a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/GenericRegionFactoryBeanTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/GenericRegionFactoryBeanTest.java @@ -13,33 +13,33 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.springframework.data.gemfire.test.support.FileSystemUtils.FileExtensionFilter.newFileExtensionFilter; +import static org.springframework.data.gemfire.tests.util.FileSystemUtils.FileExtensionFilter.newFileExtensionFilter; import java.io.FileFilter; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.Region; import org.apache.geode.cache.Scope; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import org.springframework.data.gemfire.test.support.FileSystemUtils; +import org.springframework.data.gemfire.tests.util.FileSystemUtils; import org.springframework.data.gemfire.util.CacheUtils; /** - * Unit tests for {@link GenericRegionFactoryBean}. + * Unit Tests for {@link GenericRegionFactoryBean}. * * @author John Blum * @see org.junit.Test + * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.GenericRegionFactoryBean * @since 1.7.0 */ @@ -64,14 +64,16 @@ public class GenericRegionFactoryBeanTest { .set("log-level", "error") .create(); - PeerRegionFactoryBean defaultRegionFactory = new GenericRegionFactoryBean(); + PeerRegionFactoryBean defaultRegionFactory = new GenericRegionFactoryBean<>(); + defaultRegionFactory.setCache(gemfireCache); defaultRegionFactory.setName("DefaultRegion"); defaultRegionFactory.afterPropertiesSet(); defaultRegion = defaultRegionFactory.getObject(); - PeerRegionFactoryBean emptyRegionFactory = new GenericRegionFactoryBean(); + PeerRegionFactoryBean emptyRegionFactory = new GenericRegionFactoryBean<>(); + emptyRegionFactory.setCache(gemfireCache); emptyRegionFactory.setDataPolicy(DataPolicy.EMPTY); emptyRegionFactory.setName("EmptyRegion"); @@ -80,7 +82,8 @@ public class GenericRegionFactoryBeanTest { emptyRegion = emptyRegionFactory.getObject(); - PeerRegionFactoryBean localRegionFactory = new GenericRegionFactoryBean(); + PeerRegionFactoryBean localRegionFactory = new GenericRegionFactoryBean<>(); + localRegionFactory.setCache(gemfireCache); localRegionFactory.setDataPolicy(DataPolicy.NORMAL); localRegionFactory.setName("LocalRegion"); @@ -89,7 +92,8 @@ public class GenericRegionFactoryBeanTest { localRegion = localRegionFactory.getObject(); - PeerRegionFactoryBean normalRegionFactory = new GenericRegionFactoryBean(); + PeerRegionFactoryBean normalRegionFactory = new GenericRegionFactoryBean<>(); + normalRegionFactory.setCache(gemfireCache); normalRegionFactory.setDataPolicy(DataPolicy.NORMAL); normalRegionFactory.setName("NormalRegion"); @@ -98,7 +102,8 @@ public class GenericRegionFactoryBeanTest { normalRegion = normalRegionFactory.getObject(); - PeerRegionFactoryBean persistentPartitionRegionFactory = new GenericRegionFactoryBean(); + PeerRegionFactoryBean persistentPartitionRegionFactory = new GenericRegionFactoryBean<>(); + persistentPartitionRegionFactory.setCache(gemfireCache); persistentPartitionRegionFactory.setDataPolicy(DataPolicy.PERSISTENT_PARTITION); persistentPartitionRegionFactory.setName("PersistentPartitionRegion"); @@ -107,7 +112,8 @@ public class GenericRegionFactoryBeanTest { persistentPartitionRegion = persistentPartitionRegionFactory.getObject(); - PeerRegionFactoryBean preloadedRegionFactory = new GenericRegionFactoryBean(); + PeerRegionFactoryBean preloadedRegionFactory = new GenericRegionFactoryBean<>(); + preloadedRegionFactory.setCache(gemfireCache); preloadedRegionFactory.setDataPolicy(DataPolicy.PRELOADED); preloadedRegionFactory.setName("PreloadedRegion"); @@ -115,7 +121,8 @@ public class GenericRegionFactoryBeanTest { preloadedRegion = preloadedRegionFactory.getObject(); - PeerRegionFactoryBean replicateRegionFactory = new GenericRegionFactoryBean(); + PeerRegionFactoryBean replicateRegionFactory = new GenericRegionFactoryBean<>(); + replicateRegionFactory.setCache(gemfireCache); replicateRegionFactory.setDataPolicy(DataPolicy.REPLICATE); replicateRegionFactory.setName("ReplicateRegion"); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/RecreatingSpringApplicationContextTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/RecreatingSpringApplicationContextTest.java index a18248d0..4f9bcbef 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/RecreatingSpringApplicationContextTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/RecreatingSpringApplicationContextTest.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire; import org.junit.After; @@ -21,20 +20,24 @@ import org.junit.Before; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.GenericXmlApplicationContext; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; /** - * The RecreatingSpringApplicationContextTest class is an abstract base class that creates the app context after each method. + * Abstract base test class that creates the Spring {@link ConfigurableApplicationContext} after each method (test case). * Used to properly destroy the beans defined inside Spring. * * @author Costin Leau * @author John Blum + * @see org.springframework.context.ConfigurableApplicationContext + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport */ -public abstract class RecreatingSpringApplicationContextTest { +public abstract class RecreatingSpringApplicationContextTest extends IntegrationTestsSupport { protected GenericXmlApplicationContext applicationContext; @Before public void createContext() { + applicationContext = configureContext(new GenericXmlApplicationContext()); applicationContext.load(location()); applicationContext.registerShutdownHook(); @@ -53,5 +56,4 @@ public abstract class RecreatingSpringApplicationContextTest { applicationContext.destroy(); } } - } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/SubRegionIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/SubRegionIntegrationTests.java similarity index 85% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/SubRegionIntegrationTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/SubRegionIntegrationTests.java index 8fa0b254..b2466a43 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/SubRegionIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/SubRegionIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire; import static org.junit.Assert.assertEquals; @@ -24,6 +23,9 @@ import static org.junit.Assert.assertTrue; import javax.annotation.Resource; +import org.junit.Test; +import org.junit.runner.RunWith; + import org.apache.geode.cache.Cache; import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.EvictionAction; @@ -37,31 +39,31 @@ import org.apache.geode.cache.ResumptionAction; import org.apache.geode.cache.Scope; import org.apache.geode.cache.SubscriptionAttributes; -import org.junit.Test; -import org.junit.runner.RunWith; - import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - * The SubRegionIntegrationTest class is a test suite of test cases testing the functionality of SubRegions in GemFire - * configured with Spring Data GemFire's XML namespace configuration meta-data. This test class tests a complex - * SubRegion configuration in order to ensure functional completeness. + * Integration Tests for Apache Geode sub-Regions defined in Spring configuration metadata, + * i.e. Spring Data Geode's XML namespace configuration metadata. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith + * @see org.apache.geode.cache.Cache + * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner * @since 1.4.0 - * @since 7.0.1 (GemFire) */ -@ContextConfiguration(value = "complex-subregion.xml", initializers = GemfireTestApplicationContextInitializer.class) @RunWith(SpringJUnit4ClassRunner.class) -@SuppressWarnings("unused") -public class SubRegionIntegrationTest { +@ContextConfiguration(value = "complex-subregion.xml", + initializers = GemFireMockObjectsApplicationContextInitializer.class) +@SuppressWarnings({ "rawtypes", "unused" }) +public class SubRegionIntegrationTests extends IntegrationTestsSupport { @Autowired private Cache cache; @@ -140,5 +142,4 @@ public class SubRegionIntegrationTest { assertNotNull(subscriptionAttributes); assertEquals(InterestPolicy.CACHE_CONTENT, subscriptionAttributes.getInterestPolicy()); } - } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CompoundCachePutCacheEvictIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CompoundCachePutCacheEvictIntegrationTests.java index 5d970856..5abe034c 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CompoundCachePutCacheEvictIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CompoundCachePutCacheEvictIntegrationTests.java @@ -47,7 +47,7 @@ import org.springframework.data.gemfire.LocalRegionFactoryBean; import org.springframework.data.gemfire.mapping.GemfireMappingContext; import org.springframework.data.gemfire.mapping.annotation.Region; import org.springframework.data.gemfire.repository.support.GemfireRepositoryFactoryBean; -import org.springframework.data.gemfire.test.support.IdentifierSequence; +import org.springframework.data.gemfire.tests.support.IdentifierSequence; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Service; import org.springframework.test.context.ContextConfiguration; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/GemfireCacheIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/GemfireCacheIntegrationTests.java index 19fa6b64..7f322835 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/GemfireCacheIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/GemfireCacheIntegrationTests.java @@ -14,11 +14,9 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.cache; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.is; import java.util.Properties; import java.util.concurrent.Callable; @@ -27,9 +25,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import edu.umd.cs.mtc.MultithreadedTestCase; import edu.umd.cs.mtc.TestFramework; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.Region; @@ -47,21 +43,18 @@ import org.springframework.data.gemfire.test.support.AbstractNativeCacheTests; * @see org.junit.Test * @see edu.umd.cs.mtc.MultithreadedTestCase * @see edu.umd.cs.mtc.TestFramework - * @see org.springframework.cache.Cache * @see org.apache.geode.cache.Region + * @see org.springframework.cache.Cache */ public class GemfireCacheIntegrationTests extends AbstractNativeCacheTests> { - @Rule - public ExpectedException exception = ExpectedException.none(); - @Override protected Cache newCache(Region nativeCache) { return new GemfireCache(nativeCache); } @Override - protected Region newNativeCache() throws Exception { + protected Region newNativeCache() { Properties gemfireProperties = new Properties(); @@ -70,11 +63,11 @@ public class GemfireCacheIntegrationTests extends AbstractNativeCacheTests region = cache.getRegion(CACHE_NAME); - region = (region != null ? region : cache.createRegionFactory().create(CACHE_NAME)); + region = region != null ? region : cache.createRegionFactory().create(CACHE_NAME); return region; } @@ -84,6 +77,7 @@ public class GemfireCacheIntegrationTests extends AbstractNativeCacheTestsImprove GemfireCache implementation to be able to build on Spring 4.1 */ - @Test + @Test(expected = IllegalStateException.class) public void throwsIllegalStateExceptionIfTypedAccessDoesNotFindMatchingType() throws Exception { + Cache cache = newCache(); - cache.put("key", "value"); + try { + cache.put("key", "value"); + } + catch (IllegalStateException expected) { - exception.expect(IllegalStateException.class); - exception.expectMessage(Integer.class.getName()); - exception.expectMessage(String.format("Cached value [value] is not an instance of type [%s]", - Integer.class.getName())); + assertThat(expected).hasMessageContaining("Cached value [value] is not an instance of type [%s]", + Integer.class.getName()); + assertThat(expected.getCause()).hasNoCause(); - cache.get("key", Integer.class); + throw expected; + } + finally { + cache.get("key", Integer.class); + } } @Test public void cacheGetWithValueLoaderFindsValue() throws Exception { + GemfireCache cache = newCache(); cache.put("key", "value"); @@ -133,6 +136,7 @@ public class GemfireCacheIntegrationTests extends AbstractNativeCacheTests valueLoader = new TestValueLoader("test"); @@ -143,8 +147,8 @@ public class GemfireCacheIntegrationTests extends AbstractNativeCacheTests exceptionThrowingValueLoader = new TestValueLoader( - new IllegalStateException("test")); - exception.expect(Cache.ValueRetrievalException.class); - exception.expectCause(is(IllegalStateException.class)); + TestValueLoader exceptionThrowingValueLoader = + new TestValueLoader<>(new IllegalStateException("test")); cache.get("key", exceptionThrowingValueLoader); } + catch (Cache.ValueRetrievalException expected) { + + assertThat(expected).hasCauseInstanceOf(IllegalStateException.class); + + throw expected; + } finally { assertThat(cache.getNativeCache().containsKey("key")).isFalse(); } @@ -185,12 +193,15 @@ public class GemfireCacheIntegrationTests extends AbstractNativeCacheTests("test") { - @Override public String call() throws Exception { + this.cacheLoader = new TestValueLoader("test") { + + @Override + public String call() throws Exception { waitForTick(2); return super.call(); } @@ -198,15 +209,17 @@ public class GemfireCacheIntegrationTests extends AbstractNativeCacheTests T newCacheHandlesCheckedException() { + try { return newCache(); } - catch (Exception e) { - throw new RuntimeException("Failed to create Cache", e); + catch (Exception cause) { + throw new RuntimeException("Failed to create Cache", cause); } } public void thread1() { + assertTick(0); Thread.currentThread().setName("Cache Loader Thread"); @@ -219,6 +232,7 @@ public class GemfireCacheIntegrationTests extends AbstractNativeCacheTests NULL_VALUE = new TestValueLoader(); - private AtomicBoolean called = new AtomicBoolean(false); + private final AtomicBoolean called = new AtomicBoolean(false); private final T value; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIndexingTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests.java similarity index 76% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIndexingTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests.java index 37e43c8f..75552b83 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIndexingTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests.java @@ -13,12 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.client; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.io.IOException; @@ -39,33 +36,34 @@ import org.apache.geode.cache.query.QueryService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.gemfire.fork.ServerProcess; -import org.springframework.data.gemfire.process.ProcessExecutor; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.FileSystemUtils; -import org.springframework.data.gemfire.test.support.ThreadUtils; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.process.ProcessExecutor; +import org.springframework.data.gemfire.tests.process.ProcessWrapper; +import org.springframework.data.gemfire.tests.util.FileSystemUtils; +import org.springframework.data.gemfire.tests.util.ThreadUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.Assert; /** - * Integration tests for testing {@link ClientCache} {@link Index Indexes}. + * Integration Tests for testing {@link ClientCache} {@link Index Indexes}. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.data.gemfire.IndexFactoryBean - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringRunner * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.client.ClientCache * @see org.apache.geode.cache.query.Index * @see org.apache.geode.cache.query.QueryService + * @see org.springframework.data.gemfire.IndexFactoryBean + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner * @since 1.5.2 */ @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class ClientCacheIndexingTest { +public class ClientCacheIndexingIntegrationTests extends IntegrationTestsSupport { private static ProcessWrapper serverProcess; @@ -98,13 +96,13 @@ public class ClientCacheIndexingTest { private static void waitForServerStart(final long milliseconds) { - ThreadUtils.timedWait(milliseconds, TimeUnit.MILLISECONDS.toMillis(500), new ThreadUtils.WaitCondition() { + ThreadUtils.timedWait(milliseconds, TimeUnit.MILLISECONDS.toMillis(500), new ThreadUtils.Condition() { - private File serverPidControlFile = + private final File serverPidControlFile = new File(serverProcess.getWorkingDirectory(), ServerProcess.getServerProcessControlFilename()); @Override - public boolean waiting() { + public boolean evaluate() { return !serverPidControlFile.isFile(); } }); @@ -115,7 +113,7 @@ public class ClientCacheIndexingTest { serverProcess.shutdown(); - if (Boolean.valueOf(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) { + if (Boolean.parseBoolean(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) { org.springframework.util.FileSystemUtils.deleteRecursively(serverProcess.getWorkingDirectory()); } } @@ -139,13 +137,13 @@ public class ClientCacheIndexingTest { @SuppressWarnings("deprecation") public void testIndexByName() { - assertNotNull("The GemFire ClientCache was not properly configured and initialized!", clientCache); + assertThat(clientCache).as("The GemFire ClientCache was not properly configured and initialized!").isNotNull(); Index actualIndex = getIndex(clientCache, "ExampleIndex"); - assertNotNull(actualIndex); - assertEquals("ExampleIndex", actualIndex.getName()); - assertEquals(IndexType.HASH, actualIndex.getType()); - assertSame(exampleIndex, actualIndex); + assertThat(actualIndex).isNotNull(); + assertThat(actualIndex.getName()).isEqualTo("ExampleIndex"); + assertThat(actualIndex.getType()).isEqualTo(IndexType.HASH); + assertThat(actualIndex).isSameAs(exampleIndex); } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIntegrationTests.java index 58c25bed..48275f13 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIntegrationTests.java @@ -28,25 +28,28 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; -import org.springframework.data.gemfire.test.support.IOUtils; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.util.IOUtils; /** - * Integration tests for {@link org.apache.geode.cache.client.ClientCache}. + * Integration Tests for {@link org.apache.geode.cache.client.ClientCache}. * * @author John Blum * @see org.junit.Test * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.Region * @see org.apache.geode.cache.client.ClientCache - * @see org.apache.geode.cache.client.ClientCache * @see org.springframework.context.ConfigurableApplicationContext + * @see org.springframework.context.annotation.AnnotationConfigApplicationContext * @see org.springframework.context.annotation.Bean * @see org.springframework.context.annotation.Configuration * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean - * @see EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects */ -public class ClientCacheIntegrationTests { +@SuppressWarnings("unused") +public class ClientCacheIntegrationTests extends IntegrationTestsSupport { private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { return new AnnotationConfigApplicationContext(annotatedClasses); @@ -83,7 +86,6 @@ public class ClientCacheIntegrationTests { } @Test - @SuppressWarnings("unchecked") public void multipleClientCachesAreTheSame() { ConfigurableApplicationContext applicationContextOne = newApplicationContext(MultiClientCacheConfiguration.class); @@ -95,8 +97,8 @@ public class ClientCacheIntegrationTests { assertThat(clientCacheOne).isNotNull(); assertThat(clientCacheTwo).isSameAs(clientCacheOne); - Region regionOne = applicationContextOne.getBean(Region.class); - Region regionTwo = applicationContextTwo.getBean(Region.class); + Region regionOne = applicationContextOne.getBean(Region.class); + Region regionTwo = applicationContextTwo.getBean(Region.class); assertThat(regionOne).isNotNull(); assertThat(regionTwo).isSameAs(regionTwo); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCachePoolTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCachePoolIntegrationTests.java similarity index 79% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCachePoolTests.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCachePoolIntegrationTests.java index 98d4065b..ca723c2f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCachePoolTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCachePoolIntegrationTests.java @@ -14,7 +14,6 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.client; import static org.hamcrest.Matchers.equalTo; @@ -23,7 +22,6 @@ import static org.junit.Assert.assertThat; import javax.annotation.Resource; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -33,33 +31,32 @@ import org.apache.geode.cache.CacheLoaderException; import org.apache.geode.cache.LoaderHelper; import org.apache.geode.cache.Region; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.AbstractGemFireClientServerIntegrationTest; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.Assert; /** - * Integration tests for {@link ClientCache} {@link Pool Pools}. + * Integration Tests for {@link ClientCache} {@link Pool Pools}. * * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.Region + * @see org.apache.geode.cache.client.ClientCache + * @see org.apache.geode.cache.client.Pool + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner * @since 1.0.0 */ @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("all") -public class ClientCachePoolTests extends AbstractGemFireClientServerIntegrationTest { - - private static ProcessWrapper gemfireServerProcess; +public class ClientCachePoolIntegrationTests extends ForkingClientServerIntegrationTestsSupport { @BeforeClass public static void setupGemFireServer() throws Exception { - gemfireServerProcess = startGemFireServer(ClientCachePoolTests.class); - } - - @AfterClass - public static void tearDownGemFireServer() { - stopGemFireServer(gemfireServerProcess); + startGemFireServer(ClientCachePoolIntegrationTests.class); } @Resource(name = "Factorials") diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheSecurityTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheSecurityIntegrationTests.java similarity index 67% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheSecurityTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheSecurityIntegrationTests.java index 91900e76..351bc5e9 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheSecurityTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheSecurityIntegrationTests.java @@ -19,11 +19,9 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; -import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.TimeUnit; import javax.annotation.Resource; @@ -40,13 +38,11 @@ import org.apache.geode.cache.Region; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.data.gemfire.fork.ServerProcess; -import org.springframework.data.gemfire.process.ProcessExecutor; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.FileSystemUtils; -import org.springframework.data.gemfire.test.support.ThreadUtils; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.process.ProcessWrapper; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.Assert; +import org.springframework.util.FileSystemUtils; /** * Integration Tests to test SSL configuration between a Pivotal GemFire or Apache Geode client and server @@ -61,56 +57,33 @@ import org.springframework.util.Assert; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("all") -public class ClientCacheSecurityTest { - - private static ProcessWrapper serverProcess; - - @Resource(name = "Example") - private Region example; +public class ClientCacheSecurityIntegrationTests extends ForkingClientServerIntegrationTestsSupport { @BeforeClass - public static void setup() throws IOException { - - String serverName = "GemFireSecurityCacheServer"; - - File serverWorkingDirectory = new File(FileSystemUtils.WORKING_DIRECTORY, serverName.toLowerCase()); - - Assert.isTrue(serverWorkingDirectory.isDirectory() || serverWorkingDirectory.mkdirs()); + public static void startGeodeServer() throws IOException { List arguments = new ArrayList(); - arguments.add(String.format("-Dgemfire.name=%1$s", serverName)); + arguments.add(String.format("-Dgemfire.name=%1$s", ClientCacheSecurityIntegrationTests.class.getSimpleName().concat("Server"))); arguments.add(String.format("-Djavax.net.ssl.keyStore=%1$s", System.getProperty("javax.net.ssl.keyStore"))); arguments.add("/org/springframework/data/gemfire/client/ClientCacheSecurityTest-server-context.xml"); - serverProcess = ProcessExecutor.launch(serverWorkingDirectory, ServerProcess.class, - arguments.toArray(new String[arguments.size()])); - - waitForServerStart(TimeUnit.SECONDS.toMillis(20)); - } - - private static void waitForServerStart(final long milliseconds) { - - ThreadUtils.timedWait(milliseconds, TimeUnit.MILLISECONDS.toMillis(500), new ThreadUtils.WaitCondition() { - private File serverPidControlFile = new File(serverProcess.getWorkingDirectory(), - ServerProcess.getServerProcessControlFilename()); - - @Override public boolean waiting() { - return !serverPidControlFile.isFile(); - } - }); + startGemFireServer(ServerProcess.class, arguments.toArray(new String[arguments.size()])); } @AfterClass public static void tearDown() { - serverProcess.shutdown(); - if (Boolean.valueOf(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) { - org.springframework.util.FileSystemUtils.deleteRecursively(serverProcess.getWorkingDirectory()); + getGemFireServerProcess() + .map(ProcessWrapper::getWorkingDirectory) + .ifPresent(workingDirectory -> FileSystemUtils.deleteRecursively(workingDirectory)); } } + @Resource(name = "Example") + private Region example; + @Test public void exampleRegionGet() { assertThat(String.valueOf(example.get("TestKey")), is(equalTo("TestValue"))); @@ -126,6 +99,7 @@ public class ClientCacheSecurityTest { @Override public void close() { } + } public static class SslGemFireServer { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableServersTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableLocatorsIntegrationTests.java similarity index 50% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableServersTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableLocatorsIntegrationTests.java index db03264b..43ecbfd1 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableServersTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableLocatorsIntegrationTests.java @@ -13,18 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.client; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; -import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Resource; @@ -40,17 +35,15 @@ import org.apache.geode.cache.LoaderHelper; import org.apache.geode.cache.Region; import org.springframework.data.gemfire.fork.ServerProcess; -import org.springframework.data.gemfire.process.ProcessExecutor; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.FileSystemUtils; -import org.springframework.data.gemfire.test.support.ThreadUtils; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.process.ProcessWrapper; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.Assert; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.util.FileSystemUtils; /** - * The ClientCacheVariableServersTest class is a test suite of test cases testing the use of variable "servers" - * attribute on <gfe:pool/< in Spring (Data GemFire) configuration meta-data when connecting a client/server. + * IntegrationTests with test cases testing the use of variable "locators" attribute + * on <gfe:pool/< in SDG XML namespace configuration metadata when connecting a client/server. * * @author John Blum * @see org.junit.Test @@ -59,61 +52,44 @@ import org.springframework.util.Assert; * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner * @since 1.6.3 */ -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("all") -public class ClientCacheVariableServersTest { - - private static ProcessWrapper serverProcess; - - @Resource(name = "Example") - private Region example; +public class ClientCacheVariableLocatorsIntegrationTests extends ForkingClientServerIntegrationTestsSupport { @BeforeClass - public static void setup() throws IOException { - String serverName = ClientCacheVariableServersTest.class.getSimpleName().concat("Server"); - - File serverWorkingDirectory = new File(FileSystemUtils.WORKING_DIRECTORY, serverName.toLowerCase()); - - Assert.isTrue(serverWorkingDirectory.isDirectory() || serverWorkingDirectory.mkdirs()); + public static void startGeodeServer() throws IOException { List arguments = new ArrayList(); - arguments.add(String.format("-Dgemfire.name=%1$s", serverName)); - arguments.add("/".concat(ClientCacheVariableServersTest.class.getName().replace(".", "/") + arguments.add(String.format("-Dgemfire.name=%1$s", + ClientCacheVariableLocatorsIntegrationTests.class.getSimpleName().concat("Server"))); + + arguments.add("/".concat(ClientCacheVariableLocatorsIntegrationTests.class.getName().replace(".", "/") .concat("-server-context.xml"))); - serverProcess = ProcessExecutor.launch(serverWorkingDirectory, ServerProcess.class, - arguments.toArray(new String[arguments.size()])); - - waitForServerToStart(TimeUnit.SECONDS.toMillis(20)); - } - - private static void waitForServerToStart(final long milliseconds) { - ThreadUtils.timedWait(milliseconds, TimeUnit.MILLISECONDS.toMillis(500), new ThreadUtils.WaitCondition() { - private File serverPidControlFile = new File(serverProcess.getWorkingDirectory(), - ServerProcess.getServerProcessControlFilename()); - - @Override public boolean waiting() { - return !serverPidControlFile.isFile(); - } - }); + startGemFireServer(ServerProcess.class, arguments.toArray(new String[arguments.size()])); } @AfterClass public static void tearDown() { - serverProcess.shutdown(); if (Boolean.valueOf(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) { - org.springframework.util.FileSystemUtils.deleteRecursively(serverProcess.getWorkingDirectory()); + getGemFireServerProcess() + .map(ProcessWrapper::getWorkingDirectory) + .ifPresent(workingDirectory -> FileSystemUtils.deleteRecursively(workingDirectory)); } } + @Resource(name = "Example") + private Region example; + @Test public void clientServerConnectionSuccessful() { - assertThat(example.get("one"), is(equalTo(1))); - assertThat(example.get("two"), is(equalTo(2))); - assertThat(example.get("three"), is(equalTo(3))); + + assertThat(example.get("one")).isEqualTo(1); + assertThat(example.get("two")).isEqualTo(2); + assertThat(example.get("three")).isEqualTo(3); } public static class CacheMissCounterCacheLoader implements CacheLoader { @@ -130,5 +106,4 @@ public class ClientCacheVariableServersTest { cacheMissCounter.set(0); } } - } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableLocatorsTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableLocatorsTest.java deleted file mode 100644 index bffa3876..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableLocatorsTest.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.client; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -import javax.annotation.Resource; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.apache.geode.cache.CacheLoader; -import org.apache.geode.cache.CacheLoaderException; -import org.apache.geode.cache.LoaderHelper; -import org.apache.geode.cache.Region; - -import org.springframework.data.gemfire.fork.ServerProcess; -import org.springframework.data.gemfire.process.ProcessExecutor; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.FileSystemUtils; -import org.springframework.data.gemfire.test.support.ThreadUtils; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.Assert; - -/** - * The ClientCacheVariableLocatorsTest class is a test suite of test cases testing the use of variable "locators" - * attribute on <gfe:pool/< in Spring (Data GemFire) configuration meta-data when connecting a client/server. - * - * @author John Blum - * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner - * @since 1.6.3 - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -@SuppressWarnings("all") -public class ClientCacheVariableLocatorsTest { - - private static ProcessWrapper serverProcess; - - @Resource(name = "Example") - private Region example; - - @BeforeClass - public static void setup() throws IOException { - - String serverName = ClientCacheVariableServersTest.class.getSimpleName().concat("Server"); - - File serverWorkingDirectory = new File(FileSystemUtils.WORKING_DIRECTORY, serverName.toLowerCase()); - - Assert.isTrue(serverWorkingDirectory.isDirectory() || serverWorkingDirectory.mkdirs()); - - List arguments = new ArrayList(); - - arguments.add(String.format("-Dgemfire.name=%1$s", serverName)); - arguments.add("/".concat(ClientCacheVariableLocatorsTest.class.getName().replace(".", "/") - .concat("-server-context.xml"))); - - serverProcess = ProcessExecutor.launch(serverWorkingDirectory, ServerProcess.class, - arguments.toArray(new String[arguments.size()])); - - waitForServerToStart(TimeUnit.SECONDS.toMillis(20)); - } - - private static void waitForServerToStart(final long milliseconds) { - ThreadUtils.timedWait(milliseconds, TimeUnit.MILLISECONDS.toMillis(500), new ThreadUtils.WaitCondition() { - private File serverPidControlFile = new File(serverProcess.getWorkingDirectory(), - ServerProcess.getServerProcessControlFilename()); - - @Override public boolean waiting() { - return !serverPidControlFile.isFile(); - } - }); - } - - @AfterClass - public static void tearDown() { - serverProcess.shutdown(); - - if (Boolean.valueOf(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) { - org.springframework.util.FileSystemUtils.deleteRecursively(serverProcess.getWorkingDirectory()); - } - } - - @Test - public void clientServerConnectionSuccessful() { - assertThat(example.get("one"), is(equalTo(1))); - assertThat(example.get("two"), is(equalTo(2))); - assertThat(example.get("three"), is(equalTo(3))); - } - - public static class CacheMissCounterCacheLoader implements CacheLoader { - - private static final AtomicInteger cacheMissCounter = new AtomicInteger(0); - - @Override - public Integer load(final LoaderHelper helper) throws CacheLoaderException { - return cacheMissCounter.incrementAndGet(); - } - - @Override - public void close() { - cacheMissCounter.set(0); - } - } - -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableServersIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableServersIntegrationTests.java new file mode 100644 index 00000000..df5f4277 --- /dev/null +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableServersIntegrationTests.java @@ -0,0 +1,106 @@ +/* + * Copyright 2010-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.gemfire.client; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +import javax.annotation.Resource; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.geode.cache.CacheLoader; +import org.apache.geode.cache.CacheLoaderException; +import org.apache.geode.cache.LoaderHelper; +import org.apache.geode.cache.Region; + +import org.springframework.data.gemfire.fork.ServerProcess; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.process.ProcessWrapper; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.util.FileSystemUtils; + +/** + * Integration Tests with test cases testing the use of variable "servers" attribute on <gfe:pool/< + * in SDG XML namespace configuration metadata when connecting a client/server. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner + * @since 1.6.3 + */ +@RunWith(SpringRunner.class) +@ContextConfiguration +@SuppressWarnings("all") +public class ClientCacheVariableServersIntegrationTests extends ForkingClientServerIntegrationTestsSupport { + + @BeforeClass + public static void startGeodeServer() throws IOException { + + List arguments = new ArrayList(); + + arguments.add(String.format("-Dgemfire.name=%1$s", ClientCacheVariableServersIntegrationTests.class.getSimpleName().concat("Server"))); + arguments.add("/".concat(ClientCacheVariableServersIntegrationTests.class.getName().replace(".", "/") + .concat("-server-context.xml"))); + + startGemFireServer(ServerProcess.class, arguments.toArray(new String[arguments.size()])); + } + + @AfterClass + public static void tearDown() { + + if (Boolean.parseBoolean(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) { + getGemFireServerProcess() + .map(ProcessWrapper::getWorkingDirectory) + .ifPresent(workingDirectory -> FileSystemUtils.deleteRecursively(workingDirectory)); + } + } + + @Resource(name = "Example") + private Region example; + + @Test + public void clientServerConnectionSuccessful() { + + assertThat(example.get("one")).isEqualTo(1); + assertThat(example.get("two")).isEqualTo(2); + assertThat(example.get("three")).isEqualTo(3); + } + + public static class CacheMissCounterCacheLoader implements CacheLoader { + + private static final AtomicInteger cacheMissCounter = new AtomicInteger(0); + + @Override + public Integer load(final LoaderHelper helper) throws CacheLoaderException { + return cacheMissCounter.incrementAndGet(); + } + + @Override + public void close() { + cacheMissCounter.set(0); + } + } +} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientRegionIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientRegionIntegrationTests.java index a59ebb24..b3350026 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientRegionIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientRegionIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.client; import static org.assertj.core.api.Assertions.assertThat; @@ -29,23 +28,29 @@ import org.apache.geode.cache.client.ClientRegionShortcut; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.config.annotation.ClientCacheApplication; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration tests for client {@link Region Regions} created with SDG's {@link ClientRegionFactoryBean}. + * Integration Tests for client {@link Region Regions} created with SDG's {@link ClientRegionFactoryBean}. * * @author John Blum * @see org.junit.Test * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.client.ClientRegionFactoryBean + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner * @since 2.0.0 */ @RunWith(SpringRunner.class) @ContextConfiguration -public class ClientRegionIntegrationTests { +@SuppressWarnings("unused") +public class ClientRegionIntegrationTests extends IntegrationTestsSupport { @Resource(name = "Example") private Region example; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientSubRegionIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientSubRegionIntegrationTests.java index 98b10345..4b227636 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientSubRegionIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientSubRegionIntegrationTests.java @@ -13,14 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.client; import static org.assertj.core.api.Assertions.assertThat; import javax.annotation.Resource; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -31,18 +29,18 @@ import org.apache.geode.cache.client.ClientCache; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.gemfire.GemfireTemplate; import org.springframework.data.gemfire.fork.ServerProcess; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration test testing {@link Region sub-Region} functionality from a GemFire cache client. + * Integration Tests testing {@link Region sub-Region} functionality from a cache client. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport + * @see org.apache.geode.cache.Region + * @see org.apache.geode.cache.client.ClientCache + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 1.4.0 @@ -50,9 +48,13 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class ClientSubRegionIntegrationTests extends ClientServerIntegrationTestsSupport { +public class ClientSubRegionIntegrationTests extends ForkingClientServerIntegrationTestsSupport { - private static ProcessWrapper gemfireServer; + @BeforeClass + public static void startGemFireServer() throws Exception { + startGemFireServer(ServerProcess.class, + getServerContextXmlFileLocation(ClientSubRegionIntegrationTests.class)); + } @Autowired private ClientCache clientCache; @@ -64,64 +66,49 @@ public class ClientSubRegionIntegrationTests extends ClientServerIntegrationTest private GemfireTemplate childTemplate; @Resource(name = "Parent") - private Region parent; + private Region parent; @Resource(name = "/Parent/Child") - private Region child; + private Region child; - @BeforeClass - public static void startGemFireServer() throws Exception { - int availablePort = findAvailablePort(); - - gemfireServer = run(ServerProcess.class, - String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort), - getServerContextXmlFileLocation(ClientSubRegionIntegrationTests.class)); - - waitForServerToStart(DEFAULT_HOSTNAME, availablePort); - - System.setProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY, String.valueOf(availablePort)); - } - - @AfterClass - public static void stopGemFireServer() { - System.clearProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY); - stop(gemfireServer); - } - - protected void assertRegion(Region region, String name) { + private void assertRegion(Region region, String name) { assertRegion(region, name, String.format("%1$s%2$s", Region.SEPARATOR, name)); } - protected void assertRegion(Region region, String name, String fullPath) { + private void assertRegion(Region region, String name, String fullPath) { assertThat(region).isNotNull(); assertThat(region.getName()).isEqualTo(name); assertThat(region.getFullPath()).isEqualTo(fullPath); } + @Test public void gemFireSubRegionCreationConfigurationIsCorrect() { + assertThat(clientCache).describedAs("The Client Cache was not properly initialized!").isNotNull(); - Region parent = clientCache.getRegion("Parent"); + Region parent = clientCache.getRegion("Parent"); assertRegion(parent, "Parent"); - Region child = parent.getSubregion("Child"); + Region child = parent.getSubregion("Child"); assertRegion(child, "Child", "/Parent/Child"); - Region clientCacheChild = clientCache.getRegion("/Parent/Child"); + Region clientCacheChild = clientCache.getRegion("/Parent/Child"); assertThat(child).isSameAs(clientCacheChild); } @Test public void springSubRegionCreationConfigurationIsCorrect() { + assertRegion(parent, "Parent"); assertRegion(child, "Child", "/Parent/Child"); } @Test public void templateCreationConfigurationIsCorrect() { + assertThat(parentTemplate).isNotNull(); assertThat(parentTemplate.getRegion()).isSameAs(parent); assertThat(childTemplate).isNotNull(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/DurableClientCacheIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/DurableClientCacheIntegrationTest.java index 8e5b7363..ff99e1e8 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/DurableClientCacheIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/DurableClientCacheIntegrationTest.java @@ -31,7 +31,6 @@ import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Resource; import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.FixMethodOrder; @@ -54,51 +53,42 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.data.gemfire.GemfireUtils; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.AbstractGemFireClientServerIntegrationTest; -import org.springframework.data.gemfire.test.support.ThreadUtils; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.util.ThreadUtils; import org.springframework.data.gemfire.util.DistributedSystemUtils; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.Assert; -import org.springframework.util.SocketUtils; /** - * The DurableClientCacheIntegrationTest class is a test suite of test cases testing GemFire's Durable Client - * functionality in the context of Spring Data GemFire. + * Integration Tests to test Apache Geode durable clients. * * @author John Blum + * @see java.util.Properties * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.beans.factory.config.BeanPostProcessor - * @see org.springframework.context.ConfigurableApplicationContext - * @see org.springframework.data.gemfire.process.ProcessWrapper - * @see AbstractGemFireClientServerIntegrationTest + * @see org.apache.geode.cache.Region + * @see org.apache.geode.cache.client.ClientCache + * @see org.apache.geode.cache.client.ClientCacheFactory + * @see org.apache.geode.cache.client.Pool + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner - * @see org.apache.geode.cache.client.ClientCache - * @see org.apache.geode.cache.Region - * @see org.apache.geode.cache.util.CacheListenerAdapter * @since 1.6.3 */ @RunWith(SpringRunner.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) @ContextConfiguration @SuppressWarnings("all") -public class DurableClientCacheIntegrationTest extends AbstractGemFireClientServerIntegrationTest { +public class DurableClientCacheIntegrationTest extends ForkingClientServerIntegrationTestsSupport { private static final boolean DEBUG = true; - private static int serverPort; - private static AtomicBoolean dirtiesContext = new AtomicBoolean(false); private static List regionCacheListenerEventValues = Collections.synchronizedList(new ArrayList()); - private static ProcessWrapper serverProcess; - private static final String CACHE_SERVER_PORT = DurableClientCacheIntegrationTest.class.getName().concat(".cache-server-port"); @@ -112,16 +102,7 @@ public class DurableClientCacheIntegrationTest extends AbstractGemFireClientServ @BeforeClass public static void startGemFireServer() throws IOException { - - serverPort = setSystemProperty(CACHE_SERVER_PORT, SocketUtils.findAvailableTcpPort()); - serverProcess = startGemFireServer(DurableClientCacheIntegrationTest.class); - } - - @AfterClass - public static void stopGemFireServer() { - - stopGemFireServer(serverProcess); - clearTestClassSystemProperties(DurableClientCacheIntegrationTest.class); + startGemFireServer(DurableClientCacheIntegrationTest.class); } private static boolean isAfterDirtiesContext() { @@ -205,7 +186,7 @@ public class DurableClientCacheIntegrationTest extends AbstractGemFireClientServ try { ClientCache clientCache = new ClientCacheFactory() - .addPoolServer(SERVER_HOST, serverPort) + .addPoolServer(SERVER_HOST, Integer.getInteger(GEMFIRE_POOL_SERVERS_PROPERTY)) .set("name", "ClientCacheProducer") .set("log-level", "error") .create(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceIntegrationTest.java index 09bfd12a..9dfcbc48 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceIntegrationTest.java @@ -17,7 +17,6 @@ package org.springframework.data.gemfire.client; import static org.assertj.core.api.Assertions.assertThat; -import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -36,76 +35,52 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.fork.ServerProcess; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; -import org.springframework.data.gemfire.test.support.FileSystemUtils; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.process.ProcessWrapper; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.util.FileSystemUtils; /** - * The GemFireDataSourceIntegrationTest class is a test suite of test cases testing the contract and functionality - * of the <gfe-data:datasource> element in the context of a GemFire cluster running both native, - * non-Spring configured GemFire Server(s) in addition to Spring configured and bootstrapped GemFire Server(s). + * Integration Tests with test cases testing the contract and functionality of the <gfe-data:datasource> element + * in the context of an Apache Geode cluster running both native, non-Spring configured Geode Server(s) in addition to + * Spring configured and bootstrapped Geode Server(s). * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.data.gemfire.client.GemfireDataSourcePostProcessor - * @see org.springframework.context.ApplicationContext - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner * @see org.apache.geode.cache.Region * @see org.apache.geode.cache.client.ClientCache + * @see org.springframework.data.gemfire.client.GemfireDataSourcePostProcessor + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner * @since 1.7.0 */ @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings({ "rawtypes", "unused"}) -public class GemFireDataSourceIntegrationTest extends ClientServerIntegrationTestsSupport { - - private static final String GEMFIRE_LOG_LEVEL = "error"; - - private static ProcessWrapper gemfireServer; +public class GemFireDataSourceIntegrationTest extends ForkingClientServerIntegrationTestsSupport { @BeforeClass public static void startGemFireServer() throws IOException { - int availablePort = findAvailablePort(); - - String serverName = GemFireDataSourceIntegrationTest.class.getSimpleName().concat("Server"); - - File serverWorkingDirectory = new File(FileSystemUtils.WORKING_DIRECTORY, serverName.toLowerCase()); - List arguments = new ArrayList<>(); - arguments.add(String.format("-Dgemfire.name=%s", serverName)); - arguments.add(String.format("-Dgemfire.log-level=%s", GEMFIRE_LOG_LEVEL)); - arguments.add(String.format("-Dspring.data.gemfire.cache.server.port=%d", availablePort)); + arguments.add(String.format("-Dgemfire.name=%s", GemFireDataSourceIntegrationTest.class.getSimpleName().concat("Server"))); arguments.add(GemFireDataSourceIntegrationTest.class.getName() .replace(".", "/").concat("-server-context.xml")); - gemfireServer = run(serverWorkingDirectory, ServerProcess.class, arguments.toArray(new String[0])); + startGemFireServer(ServerProcess.class, arguments.toArray(new String[0])); - waitForServerToStart(DEFAULT_HOSTNAME, availablePort); - - configureGemFireClient(availablePort); - } - - private static void configureGemFireClient(int availablePort) { - System.setProperty("gemfire.log-level", "error"); - System.setProperty("spring.data.gemfire.cache.server.port", String.valueOf(availablePort)); } @AfterClass public static void stopGemFireServer() { - stop(gemfireServer); - - System.clearProperty("gemfire.log-level"); - System.clearProperty("spring.data.gemfire.cache.server.port"); - - if (Boolean.valueOf(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) { - org.springframework.util.FileSystemUtils.deleteRecursively(gemfireServer.getWorkingDirectory()); + if (Boolean.parseBoolean(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) { + getGemFireServerProcess() + .map(ProcessWrapper::getWorkingDirectory) + .ifPresent(workingDirectory -> FileSystemUtils.deleteRecursively(workingDirectory)); } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceIntegrationTests.java index fe5be5dc..da8b3534 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceIntegrationTests.java @@ -18,7 +18,6 @@ import java.util.Arrays; import java.util.List; import java.util.Optional; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -31,59 +30,33 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.fork.ServerProcess; -import org.springframework.data.gemfire.process.ProcessWrapper; import org.springframework.data.gemfire.repository.sample.Person; import org.springframework.data.gemfire.repository.sample.PersonRepository; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration tests for a GemFire DataSource. + * Integration Tests for an Apache Geode DataSource. * * @author David Turanski * @author John Blum + * @see org.junit.Test */ @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") // TODO: merge with o.s.d.g.client.GemfireDataSourceIntegrationTest -public class GemFireDataSourceIntegrationTests extends ClientServerIntegrationTestsSupport { - - private static ProcessWrapper gemfireServer; - - @Autowired - private ApplicationContext applicationContext; - - @BeforeClass - public static void setGemFireLogLevel() { - System.setProperty("gemfire.log-level", "error"); - } - - @AfterClass - public static void unsetGemFireLogLevel() { - System.clearProperty("gemfire.log-level"); - } +public class GemFireDataSourceIntegrationTests extends ForkingClientServerIntegrationTestsSupport { @BeforeClass public static void startGemFireServer() throws Exception { - - int availablePort = findAvailablePort(); - - gemfireServer = run(ServerProcess.class, - String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort), + startGemFireServer(ServerProcess.class, getServerContextXmlFileLocation(GemFireDataSourceIntegrationTests.class)); - - waitForServerToStart(DEFAULT_HOSTNAME, availablePort); - - System.setProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY, String.valueOf(availablePort)); } - @AfterClass - public static void stopGemFireServer() { - System.clearProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY); - stop(gemfireServer); - } + @Autowired + private ApplicationContext applicationContext; private void assertRegion(Region region, String name, DataPolicy dataPolicy) { assertRegion(region, name, GemfireUtils.toRegionPath("simple"), dataPolicy); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTests.java similarity index 72% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTests.java index 4f3f8bb2..e989cb78 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTests.java @@ -15,6 +15,8 @@ */ package org.springframework.data.gemfire.client; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -23,6 +25,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; import javax.annotation.Resource; +import javax.sql.DataSource; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -38,26 +41,25 @@ import org.springframework.context.ApplicationContext; import org.springframework.core.io.ClassPathResource; import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.fork.GemFireBasedServerProcess; -import org.springframework.data.gemfire.process.ProcessExecutor; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.FileSystemUtils; -import org.springframework.data.gemfire.test.support.ThreadUtils; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.process.ProcessExecutor; +import org.springframework.data.gemfire.tests.process.ProcessWrapper; +import org.springframework.data.gemfire.tests.util.FileSystemUtils; +import org.springframework.data.gemfire.tests.util.ThreadUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.Assert; import org.springframework.util.FileCopyUtils; import org.springframework.util.StringUtils; -import org.assertj.core.api.Assertions; - /** - * The GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTest class is a test suite of test cases - * testing the contract and functionality of the GemfireDataSourcePostProcessor using the <gfe-data:datasource> - * element in Spring config to setup a GemFire ClientCache connecting to a native, non-Spring configured GemFire Server - * as the DataSource to assert that client Region Proxies are registered as Spring beans - * in the Spring ApplicationContext correctly. + * Integration Tests with test cases testing the contract and functionality of the {@link GemfireDataSourcePostProcessor} + * using the <gfe-data:datasource> element in Spring config to setup a {@link ClientCache} connecting to a native, + * non-Spring configured Apache Geode Server as the {@link DataSource} to assert that client {@link Region} proxies + * are registered as Spring beans in the Spring {@link ApplicationContext} correctly. * * @author John Blum + * @see org.junit.Test * @see org.springframework.data.gemfire.client.GemfireDataSourcePostProcessor * @since 1.7.0 */ @@ -65,33 +67,17 @@ import org.assertj.core.api.Assertions; @ContextConfiguration @SuppressWarnings({ "rawtypes", "unused"}) // TODO: slow test! -public class GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTest { - - private static final String GEMFIRE_LOG_LEVEL = "error"; +public class GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTests + extends ForkingClientServerIntegrationTestsSupport { private static ProcessWrapper gemfireServer; - @Autowired - private ApplicationContext applicationContext; - - @Autowired - private ClientCache gemfireClientCache; - - @Resource(name = "LocalRegion") - private Region localRegion; - - @Resource(name = "ServerRegion") - private Region serverRegion; - - @Resource(name = "AnotherServerRegion") - private Region anotherServerRegion; - @BeforeClass public static void startGemFireServer() throws IOException { System.setProperty("gemfire.log-level", GEMFIRE_LOG_LEVEL); - String serverName = "GemFireDataSourceGemFireBasedServer"; + String serverName = "DataSourceGemFireBasedServer"; File serverWorkingDirectory = new File(FileSystemUtils.WORKING_DIRECTORY, serverName.toLowerCase()); @@ -109,7 +95,7 @@ public class GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTe arguments.add(String.format("-Dgemfire.name=%s", serverName)); arguments.add(String.format("-Dgemfire.log-level=%s", GEMFIRE_LOG_LEVEL)); - gemfireServer = ProcessExecutor.launch(serverWorkingDirectory, customClasspath(), + gemfireServer = run(serverWorkingDirectory, customClasspath(), GemFireBasedServerProcess.class, arguments.toArray(new String[0])); waitForProcessStart(TimeUnit.SECONDS.toMillis(20), gemfireServer, @@ -139,13 +125,13 @@ public class GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTe private static void waitForProcessStart(long milliseconds, ProcessWrapper process, String processControlFilename) { - ThreadUtils.timedWait(milliseconds, TimeUnit.MILLISECONDS.toMillis(500), new ThreadUtils.WaitCondition() { + ThreadUtils.timedWait(milliseconds, TimeUnit.MILLISECONDS.toMillis(500), new ThreadUtils.Condition() { - private File processControlFile = new File(process.getWorkingDirectory(), processControlFilename); + private final File processControlFile = new File(process.getWorkingDirectory(), processControlFilename); @Override - public boolean waiting() { - return !processControlFile.isFile(); + public boolean evaluate() { + return processControlFile.isFile(); } }); } @@ -153,22 +139,35 @@ public class GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTe @AfterClass public static void stopGemFireServer() { - gemfireServer.shutdown(); - - if (Boolean.valueOf(System.getProperty("spring.gemfire.fork.clean", String.valueOf(true)))) { + if (Boolean.parseBoolean(System.getProperty("spring.gemfire.fork.clean", String.valueOf(true)))) { org.springframework.util.FileSystemUtils.deleteRecursively(gemfireServer.getWorkingDirectory()); } } + @Autowired + private ApplicationContext applicationContext; + + @Autowired + private ClientCache gemfireClientCache; + + @Resource(name = "LocalRegion") + private Region localRegion; + + @Resource(name = "ServerRegion") + private Region serverRegion; + + @Resource(name = "AnotherServerRegion") + private Region anotherServerRegion; + @SuppressWarnings("unchecked") private void assertRegion(Region actualRegion, String expectedRegionName) { - Assertions.assertThat(actualRegion).isNotNull(); - Assertions.assertThat(actualRegion.getName()).isEqualTo(expectedRegionName); - Assertions.assertThat(actualRegion.getFullPath()).isEqualTo(GemfireUtils.toRegionPath(expectedRegionName)); - Assertions.assertThat(gemfireClientCache.getRegion(actualRegion.getFullPath())).isSameAs(actualRegion); - Assertions.assertThat(applicationContext.containsBean(expectedRegionName)).isTrue(); - Assertions.assertThat(applicationContext.getBean(expectedRegionName, Region.class)).isSameAs(actualRegion); + assertThat(actualRegion).isNotNull(); + assertThat(actualRegion.getName()).isEqualTo(expectedRegionName); + assertThat(actualRegion.getFullPath()).isEqualTo(GemfireUtils.toRegionPath(expectedRegionName)); + assertThat(gemfireClientCache.getRegion(actualRegion.getFullPath())).isSameAs(actualRegion); + assertThat(applicationContext.containsBean(expectedRegionName)).isTrue(); + assertThat(applicationContext.getBean(expectedRegionName, Region.class)).isSameAs(actualRegion); } @Test diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/SpELExpressionConfiguredPoolsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/SpELExpressionConfiguredPoolsIntegrationTests.java index d82a32f0..328fb256 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/SpELExpressionConfiguredPoolsIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/SpELExpressionConfiguredPoolsIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.client; import static org.assertj.core.api.Assertions.assertThat; @@ -39,31 +38,33 @@ import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.data.gemfire.support.ConnectionEndpoint; import org.springframework.data.gemfire.support.ConnectionEndpointList; -import org.springframework.data.gemfire.test.mock.GemFireMockObjectsSupport; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.GemFireMockObjectsSupport; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration tests that test the use of property placeholders in nested <gfe:locator> and <gfe:server> + * Integration Tests that test the use of property placeholders in nested <gfe:locator> and <gfe:server> * elements of the SDG XML namespace <gfe:pool> element along with testing property placeholders in * the <gfe:pool> element locators and servers attributes. * * @author John Blum + * @see java.util.Properties * @see org.junit.Test - * @see org.junit.runner.RunWith * @see org.apache.geode.cache.client.Pool * @see org.apache.geode.cache.client.PoolFactory - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringRunner * @see org.springframework.data.gemfire.client.PoolFactoryBean * @see org.springframework.data.gemfire.config.xml.PoolParser + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner * @see SGF-433 * @since 1.6.0 */ @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class SpELExpressionConfiguredPoolsIntegrationTests { +public class SpELExpressionConfiguredPoolsIntegrationTests extends IntegrationTestsSupport { private static final ConnectionEndpointList anotherLocators = new ConnectionEndpointList(); private static final ConnectionEndpointList anotherServers = new ConnectionEndpointList(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractCacheConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractCacheConfigurationIntegrationTests.java index 3d5dbe4d..f1fe5f52 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractCacheConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractCacheConfigurationIntegrationTests.java @@ -30,7 +30,7 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.mock.env.MockPropertySource; /** @@ -38,7 +38,11 @@ import org.springframework.mock.env.MockPropertySource; * * @author John Blum * @see org.junit.Test + * @see org.apache.geode.cache.Cache + * @see org.apache.geode.cache.GemFireCache + * @see org.apache.geode.cache.client.ClientCache * @see org.springframework.data.gemfire.config.annotation.AbstractCacheConfiguration + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.0.2 */ public class AbstractCacheConfigurationIntegrationTests { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractGeodeSecurityIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractGeodeSecurityIntegrationTests.java index 705a7ab5..2fd5d220 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractGeodeSecurityIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractGeodeSecurityIntegrationTests.java @@ -14,7 +14,6 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -32,10 +31,11 @@ import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.PostConstruct; import javax.annotation.Resource; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; import org.apache.geode.cache.CacheLoader; import org.apache.geode.cache.CacheLoaderException; @@ -47,14 +47,6 @@ import org.apache.geode.cache.client.ServerOperationException; import org.apache.geode.security.NotAuthorizedException; import org.apache.geode.security.ResourcePermission; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; @@ -62,35 +54,37 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.gemfire.LocalRegionFactoryBean; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; import org.springframework.data.gemfire.config.annotation.support.AbstractAuthInitialize; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.data.gemfire.util.CollectionUtils; import org.springframework.data.gemfire.util.PropertiesBuilder; import org.springframework.test.annotation.DirtiesContext; import org.springframework.util.Assert; import org.springframework.util.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + /** * Abstract base test class for implementing Apache Geode Integrated Security Integration Tests. * * @author John Blum * @see java.security.Principal * @see java.util.Properties - * @see org.junit.FixMethodOrder * @see org.junit.Test - * @see lombok * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.config.annotation.support.AbstractAuthInitialize - * @see org.springframework.data.gemfire.process.ProcessWrapper - * @see org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @since 1.0.0 */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) @SuppressWarnings("unused") -public abstract class AbstractGeodeSecurityIntegrationTests extends ClientServerIntegrationTestsSupport { - - protected static final int CACHE_SERVER_PORT = 13531; +public abstract class AbstractGeodeSecurityIntegrationTests extends ForkingClientServerIntegrationTestsSupport { protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractGeodeSecurityIntegrationTests.class); @@ -101,8 +95,6 @@ public abstract class AbstractGeodeSecurityIntegrationTests extends ClientServer private static final AtomicInteger RUN_COUNT = new AtomicInteger(0); - private static ProcessWrapper geodeServerProcess; - @BeforeClass public static void runGeodeServer() throws IOException { @@ -113,28 +105,23 @@ public abstract class AbstractGeodeSecurityIntegrationTests extends ClientServer } } - protected static ProcessWrapper runGeodeServer(String geodeSecurityProfile) throws IOException { + protected static void runGeodeServer(String geodeSecurityProfile) throws IOException { Assert.hasText(geodeSecurityProfile, String.format("[%s] System property is required", GEODE_SECURITY_PROFILE_PROPERTY)); String debugEndpoint = Boolean.getBoolean(DEBUGGING_ENABLED_PROPERTY) ? DEBUG_ENDPOINT : null; - geodeServerProcess = run(GeodeServerConfiguration.class, + startGemFireServer(GeodeServerConfiguration.class, String.format("-Dgemfire.log-file=%s", logFile()), String.format("-Dgemfire.log-level=%s", logLevel(TEST_GEMFIRE_LOG_LEVEL)), String.format("-Dspring.profiles.active=apache-geode-server,%s", geodeSecurityProfile), debugEndpoint); - - waitForServerToStart(CACHE_SERVER_HOST, CACHE_SERVER_PORT); - - return geodeServerProcess; } @AfterClass public static void stopGeodeServer() { System.clearProperty(GEODE_SECURITY_PROFILE_PROPERTY); - stop(geodeServerProcess); } @Resource(name = "Echo") @@ -215,8 +202,7 @@ public abstract class AbstractGeodeSecurityIntegrationTests extends ClientServer } } - @ClientCacheApplication(name = "GeodeSecurityIntegrationTestsClient", logLevel = "error", - servers = { @ClientCacheApplication.Server(port = CACHE_SERVER_PORT) }) + @ClientCacheApplication(name = "GeodeSecurityIntegrationTestsClient") @EnableAuth(clientAuthenticationInitializer = "org.springframework.data.gemfire.config.annotation.AbstractGeodeSecurityIntegrationTests$GeodeClientAuthInitialize.create") @Profile("apache-geode-client") @@ -235,8 +221,7 @@ public abstract class AbstractGeodeSecurityIntegrationTests extends ClientServer } } - @CacheServerApplication(name = "GeodeSecurityIntegrationTestsServer", logLevel = "error", - port = CACHE_SERVER_PORT) + @CacheServerApplication(name = "GeodeSecurityIntegrationTestsServer") @Import({ ApacheShiroIniSecurityIntegrationTests.ApacheShiroIniConfiguration.class, ApacheShiroRealmSecurityIntegrationTests.ApacheShiroRealmConfiguration.class, @@ -292,16 +277,14 @@ public abstract class AbstractGeodeSecurityIntegrationTests extends ClientServer @Getter @EqualsAndHashCode(of = { "name", "credentials" }) @RequiredArgsConstructor(staticName = "newUser") - @SuppressWarnings("all") public static class User implements Iterable, Principal, Serializable { - private Set roles = new HashSet<>(); + private final Set roles = new HashSet<>(); @NonNull - private String name; + private final String name; private String credentials; - /* (non-Javadoc) */ public boolean hasPermission(ResourcePermission permission) { for (Role role : this) { @@ -313,7 +296,6 @@ public abstract class AbstractGeodeSecurityIntegrationTests extends ClientServer return false; } - /* (non-Javadoc) */ public boolean hasRole(Role role) { return this.roles.contains(role); } @@ -358,9 +340,9 @@ public abstract class AbstractGeodeSecurityIntegrationTests extends ClientServer public static class Role implements Iterable, Serializable { @NonNull - private String name; + private final String name; - private Set permissions = new HashSet<>(); + private final Set permissions = new HashSet<>(); /* (non-Javadoc) */ public boolean hasPermission(ResourcePermission permission) { @@ -378,7 +360,6 @@ public abstract class AbstractGeodeSecurityIntegrationTests extends ClientServer * @inheritDoc */ @Override - @SuppressWarnings("all") public Iterator iterator() { return Collections.unmodifiableSet(this.permissions).iterator(); } @@ -391,7 +372,6 @@ public abstract class AbstractGeodeSecurityIntegrationTests extends ClientServer return getName(); } - /* (non-Javadoc) */ public Role with(ResourcePermission... permissions) { Collections.addAll(this.permissions, permissions); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroRealmSecurityIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroRealmSecurityIntegrationTests.java index ef223459..9ebb3b4a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroRealmSecurityIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroRealmSecurityIntegrationTests.java @@ -18,11 +18,12 @@ package org.springframework.data.gemfire.config.annotation; import java.io.IOException; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; + import org.apache.geode.internal.security.shiro.GeodePermissionResolver; import org.apache.shiro.realm.text.PropertiesRealm; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AutoConfiguredAuthenticationConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AutoConfiguredAuthenticationConfigurationIntegrationTests.java index db1f8443..9ba72c52 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AutoConfiguredAuthenticationConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AutoConfiguredAuthenticationConfigurationIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -22,6 +21,10 @@ import static org.springframework.data.gemfire.config.annotation.TestSecurityMan import java.util.Optional; +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.Test; + import org.apache.geode.cache.CacheLoader; import org.apache.geode.cache.CacheLoaderException; import org.apache.geode.cache.GemFireCache; @@ -29,11 +32,6 @@ import org.apache.geode.cache.LoaderHelper; import org.apache.geode.cache.Region; import org.apache.geode.cache.client.ClientRegionShortcut; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -41,38 +39,28 @@ import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.LocalRegionFactoryBean; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.mock.env.MockPropertySource; /** - * The AutoConfiguredAuthenticationConfigurationIntegrationTests class... + * Integration Tests for auto-configured authentication configuration. * * @author John Blum - * @since 1.0.0 + * @see org.junit.Test + * @see org.apache.geode.cache.GemFireCache + * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport + * @since 1.9.0 */ @SuppressWarnings("unused") -public class AutoConfiguredAuthenticationConfigurationIntegrationTests extends ClientServerIntegrationTestsSupport { - - private static final int PORT = 42124; - - private static ProcessWrapper gemfireServerProcess; +public class AutoConfiguredAuthenticationConfigurationIntegrationTests + extends ForkingClientServerIntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; @BeforeClass public static void setupGemFireServer() throws Exception { - - gemfireServerProcess = run(TestGemFireServerConfiguration.class, String.format("-Dgemfire.name=%1$s", - asApplicationName(AutoConfiguredAuthenticationConfigurationIntegrationTests.class))); - - Optional.ofNullable(gemfireServerProcess) - .ifPresent(server -> waitForServerToStart("localhost", PORT)); - } - - @AfterClass - public static void tearDownGemFireServer() { - stop(gemfireServerProcess); + startGemFireServer(TestGemFireServerConfiguration.class); } @After @@ -116,8 +104,8 @@ public class AutoConfiguredAuthenticationConfigurationIntegrationTests extends C assertThat(echo.get("Good-Bye")).isEqualTo("Good-Bye"); } + @ClientCacheApplication @EnableSecurity - @ClientCacheApplication(logLevel = TEST_GEMFIRE_LOG_LEVEL, servers = @ClientCacheApplication.Server(port = PORT)) static class TestGemFireClientConfiguration { @Bean("Echo") @@ -133,7 +121,7 @@ public class AutoConfiguredAuthenticationConfigurationIntegrationTests extends C } } - @CacheServerApplication(logLevel = TEST_GEMFIRE_LOG_LEVEL, port = PORT) + @CacheServerApplication @EnableSecurity(securityManagerClassName = "org.springframework.data.gemfire.config.annotation.TestSecurityManager") static class TestGemFireServerConfiguration { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerConfigurerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerConfigurerIntegrationTests.java index 1184eb14..72b14c19 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerConfigurerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerConfigurerIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -31,12 +30,13 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.gemfire.server.CacheServerFactoryBean; -import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration tests for {@link CacheServerConfigurer}. + * Integration Tests for {@link CacheServerConfigurer}. * * @author John Blum * @see org.junit.Test @@ -47,6 +47,8 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.data.gemfire.config.annotation.EnableCacheServer * @see org.springframework.data.gemfire.config.annotation.EnableCacheServers * @see org.springframework.data.gemfire.server.CacheServerFactoryBean + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 1.1.0 @@ -54,7 +56,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class CacheServerConfigurerIntegrationTests { +public class CacheServerConfigurerIntegrationTests extends IntegrationTestsSupport { @Autowired @Qualifier("configurerOne") @@ -94,8 +96,8 @@ public class CacheServerConfigurerIntegrationTests { static class TestConfiguration { @Bean - GemfireTestBeanPostProcessor testBeanPostProcessor() { - return new GemfireTestBeanPostProcessor(); + GemFireMockObjectsBeanPostProcessor testBeanPostProcessor() { + return new GemFireMockObjectsBeanPostProcessor(); } @Bean diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerPropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerPropertiesIntegrationTests.java index ef3df913..0c463038 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerPropertiesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerPropertiesIntegrationTests.java @@ -13,44 +13,43 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; import java.util.Optional; -import org.apache.geode.cache.server.CacheServer; -import org.apache.geode.cache.server.ClientSubscriptionConfig; - import org.junit.After; import org.junit.Test; +import org.apache.geode.cache.server.CacheServer; +import org.apache.geode.cache.server.ClientSubscriptionConfig; + import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.mock.env.MockPropertySource; /** - * Integration tests for {@link CacheServerApplication} and {@link EnableCacheServer}. + * Integration Tests for {@link CacheServerApplication} and {@link EnableCacheServer}. * * @author John Blum * @see org.junit.Test * @see org.apache.geode.cache.server.CacheServer * @see org.apache.geode.cache.server.ClientSubscriptionConfig - * @see org.springframework.context.ConfigurableApplicationContext - * @see org.springframework.context.annotation.Bean * @see org.springframework.core.env.PropertySource * @see org.springframework.data.gemfire.config.annotation.CacheServerApplication - * @see org.springframework.data.gemfire.server.SubscriptionEvictionPolicy - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.mock.env.MockPropertySource * @since 2.0.0 */ -public class CacheServerPropertiesIntegrationTests { +public class CacheServerPropertiesIntegrationTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsAppliesRegionConfigurersIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsAppliesRegionConfigurersIntegrationTests.java index def1d205..2e31bb98 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsAppliesRegionConfigurersIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsAppliesRegionConfigurersIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -24,18 +23,19 @@ import java.util.List; import java.util.Objects; import java.util.stream.Collectors; +import org.junit.Test; +import org.junit.runner.RunWith; + import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.Region; import org.apache.geode.cache.client.ClientRegionShortcut; -import org.junit.Test; -import org.junit.runner.RunWith; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.stereotype.Service; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -51,7 +51,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.cache.annotation.Cacheable * @see org.springframework.data.gemfire.config.annotation.CachingDefinedRegionsConfiguration * @see org.springframework.data.gemfire.config.annotation.EnableCachingDefinedRegions - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.2.0 @@ -59,7 +59,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class CachingDefinedRegionsAppliesRegionConfigurersIntegrationTests { +public class CachingDefinedRegionsAppliesRegionConfigurersIntegrationTests extends IntegrationTestsSupport { private static final List configuredRegionNames = Collections.synchronizedList(new ArrayList<>()); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests.java index 188e481c..2dd0eac0 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests.java @@ -22,18 +22,19 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; -import org.apache.geode.cache.GemFireCache; -import org.apache.geode.cache.Region; - import org.junit.After; import org.junit.Test; +import org.apache.geode.cache.GemFireCache; +import org.apache.geode.cache.Region; + import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.Cacheable; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.util.CollectionUtils; import org.springframework.stereotype.Service; @@ -47,19 +48,16 @@ import org.springframework.stereotype.Service; * @see org.apache.geode.cache.Region * @see org.springframework.cache.annotation.CacheConfig * @see org.springframework.cache.annotation.Cacheable - * @see org.springframework.context.ConfigurableApplicationContext - * @see org.springframework.context.annotation.AnnotationConfigApplicationContext - * @see org.springframework.context.annotation.Bean - * @see org.springframework.context.annotation.Configuration * @see org.springframework.data.gemfire.config.annotation.EnableCachingDefinedRegions * @see org.springframework.data.gemfire.config.annotation.CachingDefinedRegionsConfiguration - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.stereotype.Service * @see Add support for @CacheConfig in @EnableCachingDefinedRegions * @since 2.2.0 */ @SuppressWarnings("unused") -public class CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests { +public class CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; @@ -219,5 +217,4 @@ public class CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests return "TWO"; } } - } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsRegistersInterestsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsRegistersInterestsIntegrationTests.java index cac15b51..b189248f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsRegistersInterestsIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsRegistersInterestsIntegrationTests.java @@ -24,18 +24,19 @@ import java.util.Arrays; import javax.annotation.Resource; -import org.apache.geode.cache.InterestResultPolicy; -import org.apache.geode.cache.Region; - import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.InterestResultPolicy; +import org.apache.geode.cache.Region; + import org.springframework.cache.annotation.Cacheable; import org.springframework.context.Lifecycle; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; import org.springframework.data.gemfire.client.Interest; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.util.ArrayUtils; import org.springframework.stereotype.Service; import org.springframework.test.context.ContextConfiguration; @@ -49,10 +50,10 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.junit.Test * @see org.apache.geode.cache.Region * @see org.springframework.cache.annotation.Cacheable - * @see org.springframework.context.Lifecycle * @see org.springframework.data.gemfire.client.ClientRegionFactoryBean - * @see org.springframework.data.gemfire.client.Interest - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.config.annotation.EnableCachingDefinedRegions + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @see DATAGEODE-219 @@ -60,8 +61,8 @@ import org.springframework.test.context.junit4.SpringRunner; */ @RunWith(SpringRunner.class) @ContextConfiguration -@SuppressWarnings({ "unchecked", "unused" }) -public class CachingDefinedRegionsRegistersInterestsIntegrationTests { +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +public class CachingDefinedRegionsRegistersInterestsIntegrationTests extends IntegrationTestsSupport { private static final Interest testInterest = new Interest<>("TestKey", InterestResultPolicy.KEYS_VALUES, false, true); @@ -80,11 +81,10 @@ public class CachingDefinedRegionsRegistersInterestsIntegrationTests { assertThat(this.cacheTwo).isNotNull(); assertThat(this.cacheTwo.getName()).isEqualTo("CacheTwo"); - Arrays.asList(this.cacheOne, this.cacheTwo).forEach(cache -> { + Arrays.asList(this.cacheOne, this.cacheTwo).forEach(cache -> verify(cache, times(1)) .registerInterest(eq(testInterest.getKey()), eq(testInterest.getPolicy()), eq(testInterest.isDurable()), - eq(testInterest.isReceiveValues())); - }); + eq(testInterest.isReceiveValues()))); } @ClientCacheApplication diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCacheConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCacheConfigurationIntegrationTests.java index 57699ab6..8e1b0db5 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCacheConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCacheConfigurationIntegrationTests.java @@ -30,7 +30,8 @@ import org.apache.geode.cache.client.SocketFactory; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; /** * Integration Tests for {@link ClientCacheConfiguration}. @@ -40,13 +41,13 @@ import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockOb * @see org.apache.geode.cache.client.Pool * @see org.junit.Test * @see org.mockito.Mockito - * @see org.springframework.context.ConfigurableApplicationContext * @see org.springframework.data.gemfire.config.annotation.ClientCacheConfiguration - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.4.0 */ @SuppressWarnings("unused") -public class ClientCacheConfigurationIntegrationTests { +public class ClientCacheConfigurationIntegrationTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCacheConfigurerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCacheConfigurerIntegrationTests.java index 8f31e90b..89d8b84e 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCacheConfigurerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCacheConfigurerIntegrationTests.java @@ -23,17 +23,18 @@ import java.util.Iterator; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; -import org.apache.geode.cache.client.ClientCache; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.client.ClientCache; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.client.ClientCacheFactoryBean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.test.context.junit4.SpringRunner; /** @@ -47,13 +48,14 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean * @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication * @see org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.test.context.junit4.SpringRunner * @since 2.1.0 */ @RunWith(SpringRunner.class) @SuppressWarnings("unused") -public class ClientCacheConfigurerIntegrationTests { +public class ClientCacheConfigurerIntegrationTests extends IntegrationTestsSupport { private static final AtomicBoolean testClientCacheConfigurerThreeCalled = new AtomicBoolean(false); @@ -125,7 +127,7 @@ public class ClientCacheConfigurerIntegrationTests { static final class TestClientCacheConfigurer implements ClientCacheConfigurer, Iterable { - private Set beanNames = new HashSet<>(); + private final Set beanNames = new HashSet<>(); @Override public void configure(String beanName, ClientCacheFactoryBean bean) { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java index 575a2f5a..0c900b58 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java @@ -37,7 +37,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.client.ClientCacheFactoryBean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.mock.env.MockPropertySource; /** @@ -47,14 +48,15 @@ import org.springframework.mock.env.MockPropertySource; * @see java.util.Properties * @see org.junit.Test * @see org.apache.geode.cache.client.ClientCache - * @see org.apache.geode.cache.client.Pool * @see org.springframework.core.env.PropertySource * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean * @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.mock.env.MockPropertySource * @since 2.0.0 */ -public class ClientCachePropertiesIntegrationTests { +public class ClientCachePropertiesIntegrationTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientServerCacheApplicationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientServerCacheApplicationIntegrationTests.java index 30637a53..a0717139 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientServerCacheApplicationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientServerCacheApplicationIntegrationTests.java @@ -14,13 +14,16 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; import javax.annotation.Resource; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheLoader; import org.apache.geode.cache.CacheLoaderException; @@ -29,56 +32,38 @@ import org.apache.geode.cache.Region; import org.apache.geode.cache.client.ClientCache; import org.apache.geode.cache.client.ClientRegionShortcut; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * Test suite of test cases testing the contract and functionality of the {@link CacheServerApplication} - * and {@link ClientCacheApplication} SDG annotations for configuring and bootstrapping a Pivotal GemFire - * or Apache Geode client/server topology + * Integration Tests testing the contract and functionality of the {@link CacheServerApplication} + * and {@link ClientCacheApplication} SDG annotations for configuring and bootstrapping an Apache Geode + * client/server topology * * @author John Blum * @see org.junit.Test - * @see org.springframework.data.gemfire.config.annotation.CacheServerApplication - * @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringRunner * @see org.apache.geode.cache.client.ClientCache * @see org.apache.geode.cache.server.CacheServer + * @see org.springframework.data.gemfire.config.annotation.CacheServerApplication + * @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner * @since 1.9.0 */ @RunWith(SpringRunner.class) @ContextConfiguration(classes = ClientServerCacheApplicationIntegrationTests.ClientTestConfiguration.class) @SuppressWarnings("all") -public class ClientServerCacheApplicationIntegrationTests extends ClientServerIntegrationTestsSupport { - - private static final int PORT = 12480; - - private static ProcessWrapper gemfireServerProcess; +public class ClientServerCacheApplicationIntegrationTests extends ForkingClientServerIntegrationTestsSupport { @BeforeClass public static void setupGemFireServer() throws Exception { - - gemfireServerProcess = run(ServerTestConfiguration.class, String.format("-Dgemfire.name=%1$s", - asApplicationName(ClientServerCacheApplicationIntegrationTests.class))); - - waitForServerToStart("localhost", PORT); - } - - @AfterClass - public static void tearDownGemFireServer() { - stop(gemfireServerProcess); + startGemFireServer(ServerTestConfiguration.class); } @Autowired @@ -93,7 +78,7 @@ public class ClientServerCacheApplicationIntegrationTests extends ClientServerIn assertThat(echo.get("Test")).isEqualTo("Test"); } - @ClientCacheApplication(logLevel = TEST_GEMFIRE_LOG_LEVEL, servers = { @ClientCacheApplication.Server(port = PORT)}) + @ClientCacheApplication static class ClientTestConfiguration { @Bean(name = "Echo") @@ -109,8 +94,7 @@ public class ClientServerCacheApplicationIntegrationTests extends ClientServerIn } } - @CacheServerApplication(name = "ClientServerCacheApplicationIntegrationTests", - logLevel = TEST_GEMFIRE_LOG_LEVEL, port = PORT) + @CacheServerApplication(name = "ClientServerCacheApplicationIntegrationTests") public static class ServerTestConfiguration { public static void main(String[] args) { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClusterConfigurationWithClientHttpRequestInterceptorsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClusterConfigurationWithClientHttpRequestInterceptorsIntegrationTests.java index 4c87611b..3cfae06b 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClusterConfigurationWithClientHttpRequestInterceptorsIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClusterConfigurationWithClientHttpRequestInterceptorsIntegrationTests.java @@ -41,7 +41,8 @@ import org.springframework.core.annotation.Order; import org.springframework.data.gemfire.config.admin.GemfireAdminOperations; import org.springframework.data.gemfire.config.admin.remote.RestHttpGemfireAdminTemplate; import org.springframework.data.gemfire.config.support.RestTemplateConfigurer; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.InterceptingClientHttpRequestFactory; import org.springframework.lang.Nullable; @@ -60,7 +61,8 @@ import org.springframework.web.client.RestTemplate; * @see org.apache.geode.cache.client.ClientCache * @see org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration * @see org.springframework.data.gemfire.config.annotation.EnableClusterConfiguration - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.http.client.ClientHttpRequestInterceptor * @see org.springframework.http.client.InterceptingClientHttpRequestFactory * @see org.springframework.test.context.ContextConfiguration @@ -70,7 +72,7 @@ import org.springframework.web.client.RestTemplate; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class ClusterConfigurationWithClientHttpRequestInterceptorsIntegrationTests { +public class ClusterConfigurationWithClientHttpRequestInterceptorsIntegrationTests extends IntegrationTestsSupport { @Autowired private ClientCache clientCache; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClusterConfigurationWithCustomGemfireAdminOperationsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClusterConfigurationWithCustomGemfireAdminOperationsIntegrationTests.java index 51701244..e759cc15 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClusterConfigurationWithCustomGemfireAdminOperationsIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClusterConfigurationWithCustomGemfireAdminOperationsIntegrationTests.java @@ -22,18 +22,19 @@ import static org.mockito.Mockito.spy; import static org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration.ClusterSchemaObjectInitializer; import static org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration.SchemaObjectContext; -import org.apache.geode.cache.client.ClientCache; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.client.ClientCache; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.config.admin.GemfireAdminOperations; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.lang.Nullable; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -47,7 +48,8 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.mockito.Mockito * @see org.apache.geode.cache.client.ClientCache * @see org.springframework.data.gemfire.config.admin.GemfireAdminOperations - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.2.0 @@ -55,7 +57,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class ClusterConfigurationWithCustomGemfireAdminOperationsIntegrationTests { +public class ClusterConfigurationWithCustomGemfireAdminOperationsIntegrationTests extends IntegrationTestsSupport { @Autowired private ClientCache clientCache; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStoreConfigurerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStoreConfigurerIntegrationTests.java index 204eeb6c..af6a95ff 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStoreConfigurerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStoreConfigurerIntegrationTests.java @@ -29,7 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.DiskStoreFactoryBean; -import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor; +import org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -48,6 +48,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.data.gemfire.config.annotation.DiskStoreConfigurer * @see org.springframework.data.gemfire.config.annotation.EnableDiskStore * @see org.springframework.data.gemfire.config.annotation.EnableDiskStores + * @see org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 1.1.0 @@ -90,8 +91,8 @@ public class DiskStoreConfigurerIntegrationTests { static class TestConfiguration { @Bean - GemfireTestBeanPostProcessor testBeanPostProcessor() { - return new GemfireTestBeanPostProcessor(); + GemFireMockObjectsBeanPostProcessor testBeanPostProcessor() { + return new GemFireMockObjectsBeanPostProcessor(); } @Bean diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStorePropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStorePropertiesIntegrationTests.java index c62b397c..189daa35 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStorePropertiesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStorePropertiesIntegrationTests.java @@ -30,7 +30,8 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.mock.env.MockPropertySource; /** @@ -38,10 +39,16 @@ import org.springframework.mock.env.MockPropertySource; * * @author John Blum * @see org.junit.Test + * @see org.apache.geode.cache.DiskStore + * @see org.apache.geode.cache.DiskStoreFactory + * @see org.springframework.core.env.PropertySource * @see org.springframework.data.gemfire.config.annotation.EnableDiskStore + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.mock.env.MockPropertySource * @since 2.0.0 */ -public class DiskStorePropertiesIntegrationTests { +public class DiskStorePropertiesIntegrationTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationIntegrationTests.java index bfc55f17..1c656df3 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationIntegrationTests.java @@ -26,7 +26,8 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.data.gemfire.CacheFactoryBean; import org.springframework.data.gemfire.support.GemfireBeanFactoryLocator; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; /** * Integration Tests for {@link EnableBeanFactoryLocator} and {@link BeanFactoryLocatorConfiguration}. @@ -34,14 +35,14 @@ import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockOb * @author John Blum * @see org.junit.Test * @see org.springframework.context.ConfigurableApplicationContext - * @see org.springframework.data.gemfire.CacheFactoryBean - * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean + * @see org.springframework.context.annotation.AnnotationConfigApplicationContext * @see org.springframework.data.gemfire.config.annotation.BeanFactoryLocatorConfiguration * @see org.springframework.data.gemfire.config.annotation.EnableBeanFactoryLocator - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.0.0 */ -public class EnableBeanFactoryLocatorConfigurationIntegrationTests { +public class EnableBeanFactoryLocatorConfigurationIntegrationTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCachingDefinedRegionsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCachingDefinedRegionsIntegrationTests.java index 412420d6..951bb246 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCachingDefinedRegionsIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCachingDefinedRegionsIntegrationTests.java @@ -24,13 +24,13 @@ import javax.cache.annotation.CacheDefaults; import javax.cache.annotation.CacheRemoveAll; import javax.cache.annotation.CacheResult; -import org.apache.geode.cache.GemFireCache; -import org.apache.geode.cache.client.ClientRegionShortcut; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.GemFireCache; +import org.apache.geode.cache.client.ClientRegionShortcut; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.Cacheable; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCachingDefinedRegionsUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCachingDefinedRegionsUnitTests.java index 3e3c9e39..7e2d1579 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCachingDefinedRegionsUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCachingDefinedRegionsUnitTests.java @@ -52,22 +52,23 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Caching; import org.springframework.core.type.AnnotationMetadata; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; -import org.springframework.data.gemfire.test.mock.GemFireMockObjectsSupport; import org.springframework.data.gemfire.test.support.MapBuilder; +import org.springframework.data.gemfire.tests.mock.GemFireMockObjectsSupport; import org.springframework.stereotype.Service; /** - * Unit tests for {@link EnableCachingDefinedRegions} and {@link CachingDefinedRegionsConfiguration}. + * Unit Tests for {@link EnableCachingDefinedRegions} and {@link CachingDefinedRegionsConfiguration}. * * @author John Blum * @see org.junit.Test * @see org.apache.geode.cache.Region - * @see org.springframework.beans.factory.config.BeanDefinition - * @see org.springframework.beans.factory.support.BeanDefinitionRegistry * @see org.springframework.cache.annotation.Cacheable * @see org.springframework.cache.annotation.CacheEvict * @see org.springframework.cache.annotation.CachePut * @see org.springframework.cache.annotation.Caching + * @see org.springframework.data.gemfire.config.annotation.CachingDefinedRegionsConfiguration + * @see org.springframework.data.gemfire.config.annotation.EnableCachingDefinedRegions + * @see org.springframework.data.gemfire.tests.mock.GemFireMockObjectsSupport * @see org.springframework.stereotype.Service * @since 2.0.0 */ diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationIntegrationTests.java index 79194904..f0702715 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationIntegrationTests.java @@ -20,16 +20,15 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.Arrays; import java.util.Collections; -import org.apache.geode.cache.GemFireCache; -import org.apache.geode.cache.client.ClientCache; -import org.apache.geode.cache.client.ClientRegionShortcut; - -import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.GemFireCache; +import org.apache.geode.cache.client.ClientCache; +import org.apache.geode.cache.client.ClientRegionShortcut; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -44,9 +43,8 @@ import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; import org.springframework.data.gemfire.config.admin.GemfireAdminOperations; import org.springframework.data.gemfire.config.admin.remote.RestHttpGemfireAdminTemplate; -import org.springframework.data.gemfire.process.ProcessWrapper; import org.springframework.data.gemfire.support.ConnectionEndpoint; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -68,7 +66,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration * @see org.springframework.data.gemfire.config.annotation.EnableClusterConfiguration * @see org.springframework.data.gemfire.process.ProcessWrapper - * @see org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.0.0 @@ -76,11 +74,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration(classes = EnableClusterConfigurationIntegrationTests.TestConfiguration.class) @SuppressWarnings("unused") -public class EnableClusterConfigurationIntegrationTests extends ClientServerIntegrationTestsSupport { - - private static final String GEMFIRE_LOG_LEVEL = "error"; - - private static ProcessWrapper gemfireServer; +public class EnableClusterConfigurationIntegrationTests extends ForkingClientServerIntegrationTestsSupport { @Autowired private ClientCache gemfireCache; @@ -89,22 +83,7 @@ public class EnableClusterConfigurationIntegrationTests extends ClientServerInte @BeforeClass public static void startGemFireServer() throws Exception { - - int availablePort = findAvailablePort(); - - gemfireServer = run(ServerTestConfiguration.class, - String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort)); - - waitForServerToStart("localhost", availablePort); - - System.setProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY, String.valueOf(availablePort)); - } - - @AfterClass - public static void stopGemFireServer() { - - stop(gemfireServer); - System.clearProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY); + startGemFireServer(ServerTestConfiguration.class); } @Before @@ -136,7 +115,7 @@ public class EnableClusterConfigurationIntegrationTests extends ClientServerInte @Import(ClientTestConfiguration.class) static class TestConfiguration { } - @ClientCacheApplication(logLevel = GEMFIRE_LOG_LEVEL, subscriptionEnabled = true) + @ClientCacheApplication(subscriptionEnabled = true) static class ClientTestConfiguration { @Bean @@ -198,7 +177,7 @@ public class EnableClusterConfigurationIntegrationTests extends ClientServerInte } } - @CacheServerApplication(name = "EnableClusterConfigurationIntegrationTests", logLevel = GEMFIRE_LOG_LEVEL) + @CacheServerApplication(name = "EnableClusterConfigurationIntegrationTests") static class ServerTestConfiguration { public static void main(String[] args) { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationWithSecurityIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationWithSecurityIntegrationTests.java index aa52ec85..635306bd 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationWithSecurityIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationWithSecurityIntegrationTests.java @@ -26,11 +26,9 @@ import static org.mockito.Mockito.when; import static org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration.ClusterSchemaObjectInitializer; import static org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration.SchemaObjectContext; -import java.lang.reflect.Field; import java.net.Authenticator; import java.net.PasswordAuthentication; import java.net.URI; -import java.util.Optional; import java.util.Properties; import org.junit.Before; @@ -48,7 +46,9 @@ import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.PropertiesPropertySource; import org.springframework.data.gemfire.config.admin.GemfireAdminOperations; import org.springframework.data.gemfire.config.admin.remote.RestHttpGemfireAdminTemplate; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.util.ReflectionUtils; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpRequest; import org.springframework.http.client.ClientHttpRequestExecution; @@ -56,11 +56,10 @@ import org.springframework.http.client.InterceptingClientHttpRequestFactory; import org.springframework.lang.Nullable; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.ReflectionUtils; import org.springframework.web.client.RestTemplate; /** - * Integration Test for {@link EnableClusterConfiguration} and {@link EnableSecurity}. + * Integration Tests for {@link EnableClusterConfiguration} and {@link EnableSecurity}. * * @author John Blum * @see java.net.Authenticator @@ -74,7 +73,7 @@ import org.springframework.web.client.RestTemplate; * @see org.springframework.core.env.ConfigurableEnvironment * @see org.springframework.core.env.PropertiesPropertySource * @see org.springframework.data.gemfire.config.admin.GemfireAdminOperations - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.http.client.ClientHttpRequestInterceptor * @see org.springframework.http.client.InterceptingClientHttpRequestFactory * @see org.springframework.test.context.ContextConfiguration @@ -84,8 +83,9 @@ import org.springframework.web.client.RestTemplate; */ @SuppressWarnings("unused") @RunWith(SpringRunner.class) -@ContextConfiguration(initializers = EnableClusterConfigurationWithSecurityIntegrationTests.SecurityConfigurationApplicationContextInitializer.class) -public class EnableClusterConfigurationWithSecurityIntegrationTests { +@ContextConfiguration(initializers = + EnableClusterConfigurationWithSecurityIntegrationTests.SecurityConfigurationApplicationContextInitializer.class) +public class EnableClusterConfigurationWithSecurityIntegrationTests extends IntegrationTestsSupport { private static final String SECURITY_USERNAME = "security-username"; private static final String SECURITY_PASSWORD = "security-password"; @@ -100,23 +100,6 @@ public class EnableClusterConfigurationWithSecurityIntegrationTests { @Autowired private ClusterSchemaObjectInitializer initializer; - // TODO: Replace with STDG. - @SuppressWarnings("unchecked") - private T getFieldValue(Object target, String fieldName) throws NoSuchFieldException { - - Field field = ReflectionUtils.findField(target.getClass(), fieldName); - - return Optional.ofNullable(field) - .map(it -> { - ReflectionUtils.makeAccessible(it); - return field; - }) - .map(it -> (T) ReflectionUtils.getField(it, target)) - .orElseThrow(() -> - new NoSuchFieldException(String.format("Field with name [%s] was not found on Object of type [%s]", - fieldName, target.getClass().getName()))); - } - @Before public void setup() { assertThat(this.authenticator).isNotNull(); @@ -146,7 +129,7 @@ public class EnableClusterConfigurationWithSecurityIntegrationTests { RestHttpGemfireAdminTemplate template = schemaObjectContext.getGemfireAdminOperations(); - RestTemplate restTemplate = getFieldValue(template, "restTemplate"); + RestTemplate restTemplate = ReflectionUtils.getFieldValue(template, "restTemplate"); assertThat(restTemplate).isNotNull(); assertThat(restTemplate.getInterceptors()).hasSize(2); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterDefinedRegionsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterDefinedRegionsIntegrationTests.java index 8eaa50fa..91b3ee94 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterDefinedRegionsIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterDefinedRegionsIntegrationTests.java @@ -21,17 +21,16 @@ import java.util.Collections; import javax.annotation.Resource; -import org.apache.geode.cache.DataPolicy; -import org.apache.geode.cache.GemFireCache; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.client.ClientCache; - -import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.DataPolicy; +import org.apache.geode.cache.GemFireCache; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.client.ClientCache; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; @@ -41,16 +40,15 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.data.gemfire.LocalRegionFactoryBean; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; -import org.springframework.data.gemfire.process.ProcessWrapper; import org.springframework.data.gemfire.support.ConnectionEndpoint; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.data.gemfire.util.CacheUtils; import org.springframework.data.gemfire.util.RegionUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration tests for {@link EnableClusterDefinedRegions} and {@link ClusterDefinedRegionsConfiguration}. + * Integration Tests for {@link EnableClusterDefinedRegions} and {@link ClusterDefinedRegionsConfiguration}. * * @author John Blum * @see org.junit.Test @@ -58,8 +56,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.config.annotation.ClusterDefinedRegionsConfiguration * @see org.springframework.data.gemfire.config.annotation.EnableClusterDefinedRegions - * @see org.springframework.data.gemfire.process.ProcessWrapper - * @see org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.1.0 @@ -67,29 +64,11 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration(classes = EnableClusterDefinedRegionsIntegrationTests.ClientTestConfiguration.class) @SuppressWarnings("unused") -public class EnableClusterDefinedRegionsIntegrationTests extends ClientServerIntegrationTestsSupport { - - private static final String GEMFIRE_LOG_LEVEL = "error"; - - private static ProcessWrapper gemfireServer; +public class EnableClusterDefinedRegionsIntegrationTests extends ForkingClientServerIntegrationTestsSupport { @BeforeClass public static void startGemFireServer() throws Exception { - - int availablePort = findAvailablePort(); - - gemfireServer = run(ServerTestConfiguration.class, - String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort)); - - waitForServerToStart("localhost", availablePort); - - System.setProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY, String.valueOf(availablePort)); - } - - @AfterClass - public static void stopGemFireServer() { - System.clearProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY); - stop(gemfireServer); + startGemFireServer(ServerTestConfiguration.class); } @Autowired @@ -128,7 +107,7 @@ public class EnableClusterDefinedRegionsIntegrationTests extends ClientServerInt assertRegion(this.replicateClientProxyRegion, "ReplicateRegion"); } - @ClientCacheApplication(logLevel = GEMFIRE_LOG_LEVEL) + @ClientCacheApplication @EnableClusterDefinedRegions static class ClientTestConfiguration { @@ -151,7 +130,7 @@ public class EnableClusterDefinedRegionsIntegrationTests extends ClientServerInt } } - @CacheServerApplication(name = "EnableClusterDefinedRegionsIntegrationTests", logLevel = GEMFIRE_LOG_LEVEL) + @CacheServerApplication(name = "EnableClusterDefinedRegionsIntegrationTests") static class ServerTestConfiguration { public static void main(String[] args) { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterDefinedRegionsUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterDefinedRegionsUnitTests.java index d05b81b3..3851b944 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterDefinedRegionsUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterDefinedRegionsUnitTests.java @@ -22,13 +22,13 @@ import static org.mockito.Mockito.when; import java.util.Collections; import java.util.Map; +import org.junit.Test; + import org.apache.geode.cache.Cache; import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.client.ClientCache; import org.apache.geode.cache.client.ClientRegionShortcut; -import org.junit.Test; - import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.type.AnnotationMetadata; import org.springframework.data.gemfire.client.GemfireDataSourcePostProcessor; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCompressionConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCompressionConfigurationUnitTests.java index c7bc83a7..4768932c 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCompressionConfigurationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCompressionConfigurationUnitTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -23,15 +22,15 @@ import static org.springframework.data.gemfire.config.annotation.CompressionConf import java.util.Arrays; import java.util.Optional; +import org.junit.After; +import org.junit.Test; + import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.Region; import org.apache.geode.cache.client.ClientRegionShortcut; import org.apache.geode.compression.Compressor; import org.apache.geode.compression.SnappyCompressor; -import org.junit.After; -import org.junit.Test; - import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -40,16 +39,24 @@ import org.springframework.data.gemfire.LocalRegionFactoryBean; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.test.model.Person; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; /** - * The EnableCompressionConfigurationUnitTests class... + * Integration Tests for {@link EnableCompression} and {@link CompressionConfiguration}. * * @author John Blum - * @since 1.0.0 + * @see org.junit.Test + * @see org.apache.geode.cache.GemFireCache + * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.config.annotation.CompressionConfiguration + * @see org.springframework.data.gemfire.config.annotation.EnableCompression + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects + * @since 2.0.0 */ -public class EnableCompressionConfigurationUnitTests { +public class EnableCompressionConfigurationUnitTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationIntegrationTests.java index a197aa0b..705d88ed 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -25,9 +24,10 @@ import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Resource; -import lombok.Data; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; import org.apache.geode.cache.CacheListener; import org.apache.geode.cache.CacheLoader; @@ -41,12 +41,6 @@ import org.apache.geode.cache.client.ClientRegionShortcut; import org.apache.geode.cache.query.CqEvent; import org.apache.geode.cache.util.CacheListenerAdapter; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; - import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -56,12 +50,15 @@ import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; import org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer; import org.springframework.data.gemfire.listener.annotation.ContinuousQuery; -import org.springframework.data.gemfire.process.ProcessWrapper; import org.springframework.data.gemfire.support.ConnectionEndpoint; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + /** * Integration tests for {@link EnableContinuousQueries}, {@link ContinuousQueryConfiguration}, {@link ContinuousQuery} * and {@link ContinuousQueryListenerContainer}. @@ -74,8 +71,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.data.gemfire.config.annotation.ContinuousQueryConfiguration * @see org.springframework.data.gemfire.config.annotation.EnableContinuousQueries * @see org.springframework.data.gemfire.listener.annotation.ContinuousQuery - * @see org.springframework.data.gemfire.process.ProcessWrapper - * @see org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.0.0 @@ -83,31 +79,15 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration(classes = EnableContinuousQueriesConfigurationIntegrationTests.TestConfiguration.class) @SuppressWarnings("unused") -public class EnableContinuousQueriesConfigurationIntegrationTests extends ClientServerIntegrationTestsSupport { +public class EnableContinuousQueriesConfigurationIntegrationTests extends ForkingClientServerIntegrationTestsSupport { - private static AtomicInteger boilingTemperatureReadingsCounter = new AtomicInteger(0); - private static AtomicInteger freezingTemperatureReadingsCounter = new AtomicInteger(0); - private static AtomicInteger totalTemperatureReadingsCounter = new AtomicInteger(0); - - private static ProcessWrapper gemfireServer; + private static final AtomicInteger boilingTemperatureReadingsCounter = new AtomicInteger(0); + private static final AtomicInteger freezingTemperatureReadingsCounter = new AtomicInteger(0); + private static final AtomicInteger totalTemperatureReadingsCounter = new AtomicInteger(0); @BeforeClass - public static void startGemFireServer() throws Exception { - - int availablePort = findAvailablePort(); - - gemfireServer = run(GemFireServerConfiguration.class, - String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort)); - - waitForServerToStart("localhost", availablePort); - - System.setProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY, String.valueOf(availablePort)); - } - - @AfterClass - public static void stopGemFireServer() { - System.clearProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY); - stop(gemfireServer); + public static void startGeodeServer() throws Exception { + startGemFireServer(GemFireServerConfiguration.class); } @Resource(name = "TemperatureReadings") diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationUnitTests.java index e51a0c7b..a963523e 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationUnitTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -28,7 +27,7 @@ import static org.springframework.data.gemfire.util.ArrayUtils.asArray; import java.lang.reflect.Proxy; import java.util.concurrent.Executor; -import lombok.Data; +import org.junit.Test; import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.Region; @@ -40,8 +39,6 @@ import org.apache.geode.cache.query.CqEvent; import org.apache.geode.cache.query.CqQuery; import org.apache.geode.cache.query.QueryService; -import org.junit.Test; - import org.springframework.aop.framework.ProxyFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Qualifier; @@ -61,25 +58,29 @@ import org.springframework.data.gemfire.listener.annotation.ContinuousQuery; import org.springframework.data.gemfire.mapping.GemfireMappingContext; import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; import org.springframework.data.gemfire.repository.support.GemfireRepositoryFactoryBean; -import org.springframework.data.gemfire.test.mock.GemFireMockObjectsSupport; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.test.model.Person; import org.springframework.data.gemfire.test.repo.PersonRepository; -import org.springframework.data.gemfire.test.support.IOUtils; +import org.springframework.data.gemfire.tests.mock.GemFireMockObjectsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.util.IOUtils; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Component; import org.springframework.util.ErrorHandler; +import lombok.Data; + /** - * Unit tests for {@link EnableContinuousQueries}, {@link ContinuousQueryConfiguration}, {@link ContinuousQuery} + * Unit Tests for {@link EnableContinuousQueries}, {@link ContinuousQueryConfiguration}, {@link ContinuousQuery} * and {@link ContinuousQueryListenerContainer}. * * @author John Blum * @see java.lang.reflect.Proxy + * @see java.util.concurrent.Executor * @see org.junit.Test * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.Region * @see org.apache.geode.cache.client.ClientCache + * @see org.apache.geode.cache.query.CqEvent * @see org.apache.geode.cache.query.CqQuery * @see org.apache.geode.cache.query.QueryService * @see org.springframework.aop.framework.ProxyFactory @@ -176,6 +177,7 @@ public class EnableContinuousQueriesConfigurationUnitTests { @EnableGemFireMockObjects @EnableContinuousQueries(errorHandlerBeanName = "mockErrorHandler", phase = 1, poolName = "mockPool", queryServiceBeanName = "mockQueryService", taskExecutorBeanName = "mockTaskExecutor") + @SuppressWarnings("unused") static class TestContinuousQueryListenerContainerConfiguration { @Bean @@ -261,7 +263,7 @@ public class EnableContinuousQueriesConfigurationUnitTests { } @Bean - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) RegionAttributesFactoryBean peopleRegionAttributes() { RegionAttributesFactoryBean peopleRegionAttributes = new RegionAttributesFactoryBean(); @@ -281,7 +283,7 @@ public class EnableContinuousQueriesConfigurationUnitTests { } @Bean - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) RegionAttributesFactoryBean examplesRegionAttributes() { RegionAttributesFactoryBean examplesRegionAttributes = new RegionAttributesFactoryBean(); @@ -293,6 +295,7 @@ public class EnableContinuousQueriesConfigurationUnitTests { } @Bean + @SuppressWarnings("all") ExampleDataAccessObject exampleDao() { return (ExampleDataAccessObject) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), @@ -300,6 +303,7 @@ public class EnableContinuousQueriesConfigurationUnitTests { } @Bean + @SuppressWarnings("rawtypes") GemfireRepositoryFactoryBean exampleRepository() { GemfireRepositoryFactoryBean exampleRepositoryFactory = @@ -340,9 +344,8 @@ public class EnableContinuousQueriesConfigurationUnitTests { @Id Long id; } - interface ExampleDataAccessObject { - } + interface ExampleDataAccessObject { } + + interface ExampleRepository extends CrudRepository { } - interface ExampleRepository extends CrudRepository { - } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesWithClusterConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesWithClusterConfigurationIntegrationTests.java index ad030133..0e5ae4f8 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesWithClusterConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesWithClusterConfigurationIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -24,13 +23,12 @@ import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import java.util.concurrent.TimeUnit; -import org.apache.geode.cache.query.CqEvent; - -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.query.CqEvent; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -38,18 +36,17 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.data.gemfire.listener.annotation.ContinuousQuery; -import org.springframework.data.gemfire.process.ProcessWrapper; import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; import org.springframework.data.gemfire.support.ConnectionEndpoint; import org.springframework.data.gemfire.test.model.Gender; import org.springframework.data.gemfire.test.model.Person; import org.springframework.data.gemfire.test.repo.PersonRepository; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration tests testing the combination of {@link EnableContinuousQueries} with {@link EnableClusterConfiguration}. + * Integration Tests testing the combination of {@link EnableContinuousQueries} with {@link EnableClusterConfiguration}. * * @author John Blum * @see org.junit.Test @@ -57,6 +54,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.data.gemfire.config.annotation.EnableClusterConfiguration * @see org.springframework.data.gemfire.config.annotation.EnableContinuousQueries * @see org.springframework.data.gemfire.listener.annotation.ContinuousQuery + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @see Fix race condition between ContinuousQuery registration and EnableClusterConfiguration Region creation. @@ -66,29 +64,13 @@ import org.springframework.test.context.junit4.SpringRunner; @ContextConfiguration(classes = EnableContinuousQueriesWithClusterConfigurationIntegrationTests.TestConfiguration.class) @SuppressWarnings("unused") public class EnableContinuousQueriesWithClusterConfigurationIntegrationTests - extends ClientServerIntegrationTestsSupport { + extends ForkingClientServerIntegrationTestsSupport { private static final BlockingQueue events = new ArrayBlockingQueue<>(2); - private static ProcessWrapper gemfireServer; - @BeforeClass public static void startGemFireServer() throws Exception { - - int availablePort = findAvailablePort(); - - gemfireServer = run(EnableContinuousQueriesWithClusterConfigurationIntegrationTests.GemFireServerConfiguration.class, - String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort)); - - waitForServerToStart("localhost", availablePort); - - System.setProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY, String.valueOf(availablePort)); - } - - @AfterClass - public static void stopGemFireServer() { - System.clearProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY); - stop(gemfireServer); + startGemFireServer(GemFireServerConfiguration.class); } @Autowired diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableDiskStoresConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableDiskStoresConfigurationUnitTests.java index 52c2c326..5fbe2b96 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableDiskStoresConfigurationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableDiskStoresConfigurationUnitTests.java @@ -31,7 +31,8 @@ import org.apache.geode.cache.DiskStore; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; /** * Unit Tests for the {@link EnableDiskStore} and {@link EnableDiskStores} annotations as well as @@ -40,15 +41,16 @@ import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockOb * @author John Blum * @see org.junit.Test * @see org.apache.geode.cache.DiskStore - * @see org.springframework.context.ConfigurableApplicationContext * @see org.springframework.data.gemfire.config.annotation.EnableDiskStore * @see org.springframework.data.gemfire.config.annotation.EnableDiskStores * @see org.springframework.data.gemfire.config.annotation.DiskStoreConfiguration * @see org.springframework.data.gemfire.config.annotation.DiskStoresConfiguration - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 1.9.0 */ -public class EnableDiskStoresConfigurationUnitTests { +@SuppressWarnings("unused") +public class EnableDiskStoresConfigurationUnitTests extends IntegrationTestsSupport { private static final AtomicInteger MOCK_ID = new AtomicInteger(0); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsIntegrationTests.java index a233db9c..ccb9cc0f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsIntegrationTests.java @@ -30,8 +30,9 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.GemfireUtils; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.test.model.Person; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.mock.env.MockPropertySource; /** @@ -40,12 +41,15 @@ import org.springframework.mock.env.MockPropertySource; * @author John Blum * @see org.junit.Test * @see org.apache.geode.cache.Region + * @see org.springframework.context.ConfigurableApplicationContext + * @see org.springframework.context.annotation.AnnotationConfigApplicationContext * @see org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions * @see org.springframework.data.gemfire.config.annotation.EntityDefinedRegionsConfiguration - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.0.2 */ -public class EnableEntityDefinedRegionsIntegrationTests { +public class EnableEntityDefinedRegionsIntegrationTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsUnitTests.java index 4b016149..ebe14077 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsUnitTests.java @@ -64,8 +64,8 @@ import org.springframework.data.gemfire.mapping.annotation.ClientRegion; import org.springframework.data.gemfire.mapping.annotation.LocalRegion; import org.springframework.data.gemfire.mapping.annotation.PartitionRegion; import org.springframework.data.gemfire.mapping.annotation.ReplicateRegion; -import org.springframework.data.gemfire.test.mock.MockObjectsSupport; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.mock.MockObjectsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; /** * Unit Tests for the {@link EnableEntityDefinedRegions} annotation and {@link EntityDefinedRegionsConfiguration} class. @@ -75,6 +75,8 @@ import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockOb * @see org.mockito.Mockito * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.Region + * @see org.springframework.context.ConfigurableApplicationContext + * @see org.springframework.context.annotation.AnnotationConfigApplicationContext * @see org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions * @see org.springframework.data.gemfire.config.annotation.EntityDefinedRegionsConfiguration * @see org.springframework.data.gemfire.mapping.annotation.ClientRegion @@ -82,8 +84,8 @@ import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockOb * @see org.springframework.data.gemfire.mapping.annotation.PartitionRegion * @see org.springframework.data.gemfire.mapping.annotation.ReplicateRegion * @see org.springframework.data.gemfire.mapping.annotation.ReplicateRegion - * @see org.springframework.data.gemfire.test.mock.MockObjectsSupport - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.mock.MockObjectsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 1.9.0 */ @SuppressWarnings({ "unchecked", "unused" }) diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsWithAssignableTypeFilterIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsWithAssignableTypeFilterIntegrationTests.java index 2322a689..8dd40d18 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsWithAssignableTypeFilterIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsWithAssignableTypeFilterIntegrationTests.java @@ -36,7 +36,8 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; import org.springframework.data.gemfire.repository.sample.Algorithm; import org.springframework.data.gemfire.repository.sample.User; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -46,10 +47,10 @@ import org.springframework.test.context.junit4.SpringRunner; * @author John Blum * @see org.junit.Test * @see org.apache.geode.cache.Region - * @see org.springframework.context.ApplicationContext * @see org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions * @see org.springframework.data.gemfire.config.annotation.EntityDefinedRegionsConfiguration - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.4.0 @@ -57,7 +58,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class EnableEntityDefinedRegionsWithAssignableTypeFilterIntegrationTests { +public class EnableEntityDefinedRegionsWithAssignableTypeFilterIntegrationTests extends IntegrationTestsSupport { @Autowired private ApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsWithRegexFilterIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsWithRegexFilterIntegrationTests.java index 676ecd20..1bf70079 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsWithRegexFilterIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsWithRegexFilterIntegrationTests.java @@ -43,7 +43,8 @@ import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.filter.RegexPatternTypeFilter; import org.springframework.data.gemfire.repository.sample.Account; import org.springframework.data.gemfire.repository.sample.Programmer; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -54,10 +55,10 @@ import org.springframework.test.context.junit4.SpringRunner; * @see java.util.regex.Pattern * @see org.junit.Test * @see org.apache.geode.cache.Region - * @see org.springframework.context.ApplicationContext * @see org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions * @see org.springframework.data.gemfire.config.annotation.EntityDefinedRegionsConfiguration - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.4.0 @@ -65,7 +66,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class EnableEntityDefinedRegionsWithRegexFilterIntegrationTests { +public class EnableEntityDefinedRegionsWithRegexFilterIntegrationTests extends IntegrationTestsSupport { @Autowired private ApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEvictionConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEvictionConfigurationIntegrationTests.java index b2608fd9..9d9fa772 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEvictionConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEvictionConfigurationIntegrationTests.java @@ -33,8 +33,9 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.eviction.EvictionActionType; import org.springframework.data.gemfire.eviction.EvictionPolicyType; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.test.model.Person; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.stereotype.Service; /** @@ -44,10 +45,12 @@ import org.springframework.stereotype.Service; * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.config.annotation.EnableEviction * @see org.springframework.data.gemfire.config.annotation.EvictionConfiguration + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 1.9.0 */ @SuppressWarnings("unused") -public class EnableEvictionConfigurationIntegrationTests { +public class EnableEvictionConfigurationIntegrationTests extends IntegrationTestsSupport { private static final String GEMFIRE_LOG_LEVEL = "error"; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEvictionConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEvictionConfigurationUnitTests.java index 9b62184e..fa46189e 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEvictionConfigurationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEvictionConfigurationUnitTests.java @@ -26,6 +26,10 @@ import static org.springframework.data.gemfire.config.annotation.EnableEviction. import java.util.concurrent.atomic.AtomicReference; +import org.junit.After; +import org.junit.Test; +import org.mockito.stubbing.Answer; + import org.apache.geode.cache.Cache; import org.apache.geode.cache.EvictionAttributes; import org.apache.geode.cache.Region; @@ -33,10 +37,6 @@ import org.apache.geode.cache.RegionAttributes; import org.apache.geode.cache.RegionFactory; import org.apache.geode.cache.util.ObjectSizer; -import org.junit.After; -import org.junit.Test; -import org.mockito.stubbing.Answer; - import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableExpirationConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableExpirationConfigurationIntegrationTests.java index 4fec5cc9..2fe20c29 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableExpirationConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableExpirationConfigurationIntegrationTests.java @@ -32,7 +32,7 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.expiration.AnnotationBasedExpiration; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.test.model.Person; import org.springframework.stereotype.Service; @@ -42,8 +42,12 @@ import org.springframework.stereotype.Service; * @author John Blum * @see org.junit.Test * @see org.apache.geode.cache.Region + * @see org.springframework.context.ConfigurableApplicationContext + * @see org.springframework.context.annotation.AnnotationConfigApplicationContext * @see org.springframework.data.gemfire.config.annotation.EnableExpiration * @see org.springframework.data.gemfire.config.annotation.ExpirationConfiguration + * @see org.springframework.data.gemfire.expiration.AnnotationBasedExpiration + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 1.9.0 */ @SuppressWarnings("unused") diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableExpirationConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableExpirationConfigurationUnitTests.java index 1487df6b..602639b9 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableExpirationConfigurationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableExpirationConfigurationUnitTests.java @@ -14,7 +14,6 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -25,35 +24,38 @@ import static org.springframework.data.gemfire.config.annotation.EnableExpiratio import java.util.Optional; +import org.junit.After; +import org.junit.Test; + import org.apache.geode.cache.CustomExpiry; import org.apache.geode.cache.ExpirationAction; import org.apache.geode.cache.ExpirationAttributes; import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.Region; -import org.junit.After; -import org.junit.Test; - import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.LocalRegionFactoryBean; import org.springframework.data.gemfire.expiration.ExpirationActionType; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.util.ArrayUtils; /** - * Unit tests for the {@link EnableExpiration} annotation and {@link ExpirationConfiguration} class. + * Unit Tests for the {@link EnableExpiration} annotation and {@link ExpirationConfiguration} class. * * @author John Blum * @see org.junit.Test * @see org.mockito.Mockito - * @see org.springframework.context.ConfigurableApplicationContext - * @see org.springframework.data.gemfire.config.annotation.EnableExpiration - * @see org.springframework.data.gemfire.config.annotation.ExpirationConfiguration * @see org.apache.geode.cache.CustomExpiry * @see org.apache.geode.cache.ExpirationAttributes + * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.Region + * @see org.springframework.context.ConfigurableApplicationContext + * @see org.springframework.context.annotation.AnnotationConfigApplicationContext + * @see org.springframework.data.gemfire.config.annotation.EnableExpiration + * @see org.springframework.data.gemfire.config.annotation.ExpirationConfiguration + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 1.9.0 */ public class EnableExpirationConfigurationUnitTests { @@ -106,8 +108,7 @@ public class EnableExpirationConfigurationUnitTests { assertExpiration(customExpiry.getExpiry(regionEntry), expectedExpirationAttributes); } - @SuppressWarnings({ "unchecked", "unused" }) - private void assertExpiration(ExpirationAttributes actualExpirationAttributes, + private void assertExpiration(ExpirationAttributes actualExpirationAttributes, ExpirationAttributes expectedExpirationAttributes) { assertThat(actualExpirationAttributes).isEqualTo(expectedExpirationAttributes); @@ -131,7 +132,7 @@ public class EnableExpirationConfigurationUnitTests { } @Test - @SuppressWarnings("unchecked") + @SuppressWarnings({ "rawtypes", "unchecked" }) public void usesDefaultExpirationPolicyConfiguration() { this.applicationContext = newApplicationContext(DefaultExpirationPolicyConfiguration.class); @@ -148,7 +149,7 @@ public class EnableExpirationConfigurationUnitTests { } @Test - @SuppressWarnings("unchecked") + @SuppressWarnings({ "rawtypes", "unchecked" }) public void usesCustomIdleTimeoutExpirationPolicyConfiguration() { this.applicationContext = newApplicationContext(CustomIdleTimeoutExpirationPolicyConfiguration.class); @@ -166,7 +167,7 @@ public class EnableExpirationConfigurationUnitTests { } @Test - @SuppressWarnings("unchecked") + @SuppressWarnings({ "rawtypes", "unchecked" }) public void usesCustomTimeToLiveExpirationPolicyConfiguration() { this.applicationContext = newApplicationContext(CustomTimeToLiveTimeoutExpirationPolicyConfiguration.class); @@ -184,7 +185,7 @@ public class EnableExpirationConfigurationUnitTests { } @Test - @SuppressWarnings("unchecked") + @SuppressWarnings({ "rawtypes", "unchecked" }) public void usesRegionSpecificExpirationPolicyConfiguration() { this.applicationContext = newApplicationContext(RegionSpecificExpirationPolicyConfiguration.class); @@ -203,7 +204,7 @@ public class EnableExpirationConfigurationUnitTests { } @Test - @SuppressWarnings("unchecked") + @SuppressWarnings({ "rawtypes", "unchecked" }) public void usesMixedExpirationPolicyConfiguration() { this.applicationContext = newApplicationContext(MixedExpirationPolicyConfiguration.class); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGatewayReceiverConfigurationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGatewayReceiverConfigurationTests.java index 96ada4ef..63efccbf 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGatewayReceiverConfigurationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGatewayReceiverConfigurationTests.java @@ -25,12 +25,12 @@ import java.util.Iterator; import java.util.List; import java.util.Optional; -import org.apache.geode.cache.wan.GatewayReceiver; -import org.apache.geode.cache.wan.GatewayTransportFilter; - import org.junit.After; import org.junit.Test; +import org.apache.geode.cache.wan.GatewayReceiver; +import org.apache.geode.cache.wan.GatewayTransportFilter; + import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGemFirePropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGemFirePropertiesIntegrationTests.java index 6cff191b..1aa7d22d 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGemFirePropertiesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGemFirePropertiesIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -22,19 +21,20 @@ import static org.mockito.Mockito.mock; import java.util.Optional; import java.util.Properties; -import org.apache.geode.cache.GemFireCache; -import org.apache.geode.pdx.PdxSerializer; - import org.junit.After; import org.junit.Test; +import org.apache.geode.cache.GemFireCache; +import org.apache.geode.pdx.PdxSerializer; + import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.CacheFactoryBean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.util.ArrayUtils; import org.springframework.mock.env.MockPropertySource; import org.springframework.util.StringUtils; @@ -50,11 +50,14 @@ import org.springframework.util.StringUtils; * @see org.junit.Test * @see org.apache.geode.cache.GemFireCache * @see org.springframework.context.ConfigurableApplicationContext + * @see org.springframework.context.annotation.AnnotationConfigApplicationContext * @see org.springframework.core.env.PropertySource - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.0.0 */ -public class EnableGemFirePropertiesIntegrationTests { +@SuppressWarnings("rawtypes") +public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableOffHeapConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableOffHeapConfigurationUnitTests.java index f8bbfaf5..3be1f233 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableOffHeapConfigurationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableOffHeapConfigurationUnitTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -21,13 +20,13 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.Arrays; import java.util.Optional; +import org.junit.After; +import org.junit.Test; + import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.Region; import org.apache.geode.cache.control.ResourceManager; -import org.junit.After; -import org.junit.Test; - import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -37,19 +36,24 @@ import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.LocalRegionFactoryBean; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.test.model.Person; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; /** - * Unit tests for {@link EnableOffHeap} and {@link OffHeapConfiguration}. + * Unit Tests for {@link EnableOffHeap} and {@link OffHeapConfiguration}. * * @author John Blum * @see org.junit.Test + * @see org.apache.geode.cache.GemFireCache + * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.config.annotation.EnableOffHeap * @see org.springframework.data.gemfire.config.annotation.OffHeapConfiguration + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.0.2 */ -public class EnableOffHeapConfigurationUnitTests { +public class EnableOffHeapConfigurationUnitTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnablePdxConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnablePdxConfigurationIntegrationTests.java index 1fb0c38a..b99a154f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnablePdxConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnablePdxConfigurationIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -21,13 +20,13 @@ import static org.mockito.Mockito.mock; import java.util.Optional; +import org.junit.After; +import org.junit.Test; + import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.client.ClientRegionShortcut; import org.apache.geode.pdx.PdxSerializer; -import org.junit.After; -import org.junit.Test; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.ConfigurableApplicationContext; @@ -38,15 +37,23 @@ import org.springframework.data.gemfire.DiskStoreFactoryBean; import org.springframework.data.gemfire.LocalRegionFactoryBean; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; import org.springframework.data.gemfire.mapping.MappingPdxSerializer; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; /** - * The EnablePdxConfigurationIntegrationTests class... + * Integration Tests for {@link EnablePdx} and {@link PdxConfiguration}. * * @author John Blum - * @since 1.0.0 + * @see org.junit.Test + * @see org.apache.geode.cache.GemFireCache + * @see org.apache.geode.pdx.PdxSerializer + * @see org.springframework.data.gemfire.config.annotation.EnablePdx + * @see org.springframework.data.gemfire.config.annotation.PdxConfiguration + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects + * @since 1.9.0 */ -public class EnablePdxConfigurationIntegrationTests { +public class EnablePdxConfigurationIntegrationTests extends IntegrationTestsSupport { @Autowired private ConfigurableApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnablePdxConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnablePdxConfigurationUnitTests.java index c11c55f0..b63f5734 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnablePdxConfigurationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnablePdxConfigurationUnitTests.java @@ -34,13 +34,13 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; -import org.apache.geode.pdx.PdxSerializer; - import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; +import org.apache.geode.pdx.PdxSerializer; + import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.config.ConfigurableBeanFactory; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationIntegrationTests.java index 0dd0d945..fe546a31 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationIntegrationTests.java @@ -19,6 +19,11 @@ import static org.assertj.core.api.Assertions.assertThat; import javax.annotation.Resource; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + import org.apache.geode.cache.CacheLoader; import org.apache.geode.cache.CacheLoaderException; import org.apache.geode.cache.GemFireCache; @@ -26,35 +31,35 @@ import org.apache.geode.cache.LoaderHelper; import org.apache.geode.cache.Region; import org.apache.geode.cache.client.ClientRegionShortcut; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; - import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.process.ProcessWrapper; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration tests for {@link EnableSsl} and {@link SslConfiguration}. + * Integration Tests for {@link EnableSsl} and {@link SslConfiguration}. * * @author John Blum * @see org.junit.Test + * @see org.apache.geode.cache.GemFireCache + * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication * @see org.springframework.data.gemfire.config.annotation.EnableSsl * @see org.springframework.data.gemfire.config.annotation.SslConfiguration + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner * @since 2.1.0 */ @RunWith(SpringRunner.class) @ContextConfiguration(classes = EnableSslConfigurationIntegrationTests.ClientTestConfiguration.class) @SuppressWarnings("all") -public class EnableSslConfigurationIntegrationTests extends ClientServerIntegrationTestsSupport { +public class EnableSslConfigurationIntegrationTests extends ForkingClientServerIntegrationTestsSupport { private static final String LOG_LEVEL = "error"; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationUnitTests.java index c54b4a27..38d9ae3a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationUnitTests.java @@ -28,13 +28,14 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.client.ClientCacheFactoryBean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.util.ArrayUtils; import org.springframework.mock.env.MockPropertySource; import org.springframework.util.StringUtils; /** - * Unit tests for {@link EnableSsl} and {@link SslConfiguration}. + * Unit Tests for {@link EnableSsl} and {@link SslConfiguration}. * * @author John Blum * @author Srikanth Manvi @@ -42,9 +43,11 @@ import org.springframework.util.StringUtils; * @see org.apache.geode.cache.GemFireCache * @see org.springframework.data.gemfire.config.annotation.EnableSsl * @see org.springframework.data.gemfire.config.annotation.SslConfiguration + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.1.0 */ -public class EnableSslConfigurationUnitTests { +public class EnableSslConfigurationUnitTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; @@ -107,7 +110,7 @@ public class EnableSslConfigurationUnitTests { @Test public void sslPropertyBasedConfigurationIsCorrect() { - PropertySource testPropertySource = new MockPropertySource("TestPropertySource") + PropertySource testPropertySource = new MockPropertySource("TestPropertySource") .withProperty("spring.data.gemfire.security.ssl.ciphers", "Scream, SEAL, SNOW") .withProperty("spring.data.gemfire.security.ssl.components", "locator, server, gateway") .withProperty("spring.data.gemfire.security.ssl.certificate.alias.default", "MockCert") @@ -125,7 +128,6 @@ public class EnableSslConfigurationUnitTests { .withProperty("spring.data.gemfire.security.ssl.use-default-context", "true") .withProperty("spring.data.gemfire.security.ssl.web-require-authentication", "true"); - this.applicationContext = newApplicationContext(testPropertySource, SslPropertyBasedConfiguration.class); assertThat(this.applicationContext).isNotNull(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverConfigurerTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverConfigurerTests.java index 64953412..8682637a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverConfigurerTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverConfigurerTests.java @@ -22,12 +22,12 @@ import java.io.OutputStream; import java.util.Arrays; import java.util.Optional; -import org.apache.geode.cache.wan.GatewayReceiver; -import org.apache.geode.cache.wan.GatewayTransportFilter; - import org.junit.After; import org.junit.Test; +import org.apache.geode.cache.wan.GatewayReceiver; +import org.apache.geode.cache.wan.GatewayTransportFilter; + import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverPropertiesTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverPropertiesTests.java index 8ab3eee5..f0c1851b 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverPropertiesTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverPropertiesTests.java @@ -25,12 +25,12 @@ import java.util.Iterator; import java.util.List; import java.util.Optional; -import org.apache.geode.cache.wan.GatewayReceiver; -import org.apache.geode.cache.wan.GatewayTransportFilter; - import org.junit.After; import org.junit.Test; +import org.apache.geode.cache.wan.GatewayReceiver; +import org.apache.geode.cache.wan.GatewayTransportFilter; + import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurationIntegrationTests.java similarity index 88% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurationTests.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurationIntegrationTests.java index c21f85a4..bbf32b7f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurationIntegrationTests.java @@ -25,7 +25,9 @@ import java.util.Optional; import java.util.TreeMap; import java.util.stream.Collectors; -import org.apache.geode.cache.DataPolicy; +import org.junit.After; +import org.junit.Test; + import org.apache.geode.cache.EntryEvent; import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.Region; @@ -35,33 +37,39 @@ import org.apache.geode.cache.wan.GatewayQueueEvent; import org.apache.geode.cache.wan.GatewaySender; import org.apache.geode.cache.wan.GatewayTransportFilter; -import org.junit.After; -import org.junit.Test; - import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean; import org.springframework.data.gemfire.wan.OrderPolicyType; /** - * Tests for {@link EnableGatewaySenders} and {@link EnableGatewaySender}. + * Integration Tests for {@link EnableGatewaySender} and {@link EnableGatewaySenders}. * * @author Udo Kohlmeyer + * @author John Blum * @see org.junit.Test * @see org.mockito.Mockito - * @see org.apache.geode.cache.server.CacheServer + * @see org.apache.geode.cache.GemFireCache + * @see org.apache.geode.cache.Region + * @see org.apache.geode.cache.wan.GatewaySender * @see org.springframework.context.annotation.Configuration + * @see org.springframework.data.gemfire.config.annotation.EnableGatewaySender + * @see org.springframework.data.gemfire.config.annotation.EnableGatewaySenders + * @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfigurer + * @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfiguration + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.wan.GatewaySenderFactoryBean * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner - * @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean - * @see GatewaySenderConfigurer - * @see GatewaySenderConfiguration * @since 2.2.0 */ -public class GatewaySenderConfigurationTests { +@SuppressWarnings("unused") +public class GatewaySenderConfigurationIntegrationTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; @@ -108,9 +116,9 @@ public class GatewaySenderConfigurationTests { assertThat(gatewaySender.getSocketBufferSize()).isEqualTo(16384); assertThat(gatewaySender.getGatewayTransportFilters().size()).isEqualTo(2); - assertThat(((GatewaySenderConfigurationTests.TestGatewayTransportFilter) gatewaySender + assertThat(((GatewaySenderConfigurationIntegrationTests.TestGatewayTransportFilter) gatewaySender .getGatewayTransportFilters().get(0)).name).isEqualTo("transportBean2"); - assertThat(((GatewaySenderConfigurationTests.TestGatewayTransportFilter) gatewaySender + assertThat(((GatewaySenderConfigurationIntegrationTests.TestGatewayTransportFilter) gatewaySender .getGatewayTransportFilters().get(1)).name).isEqualTo("transportBean1"); assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray()) .isEqualTo(new String[] { "transportBean2", "transportBean1" }); @@ -219,7 +227,7 @@ public class GatewaySenderConfigurationTests { GatewaySender gatewaySender = this.applicationContext.getBean("TestGatewaySender", GatewaySender.class); assertThat(gatewaySender.getGatewayTransportFilters().size()).isEqualTo(1); - assertThat(((GatewaySenderConfigurationTests.TestGatewayTransportFilter) gatewaySender + assertThat(((GatewaySenderConfigurationIntegrationTests.TestGatewayTransportFilter) gatewaySender .getGatewayTransportFilters().get(0)).name).isEqualTo("transportBean1"); gatewaySender = this.applicationContext.getBean("TestGatewaySender2", GatewaySender.class); @@ -258,7 +266,7 @@ public class GatewaySenderConfigurationTests { static class TestConfigurationWithAnnotations { @Bean("SomeEventSubstitutionFilter") - GatewayEventSubstitutionFilter createGatewayEventSubstitutionFilter() { + GatewayEventSubstitutionFilter createGatewayEventSubstitutionFilter() { return new TestGatewayEventSubstitutionFilter("SomeEventSubstitutionFilter"); } } @@ -278,7 +286,7 @@ public class GatewaySenderConfigurationTests { static class TestConfigurationWithMultipleGatewaySenderAnnotations { @Bean("SomeEventSubstitutionFilter") - GatewayEventSubstitutionFilter createGatewayEventSubstitutionFilter() { + GatewayEventSubstitutionFilter createGatewayEventSubstitutionFilter() { return new TestGatewayEventSubstitutionFilter("SomeEventSubstitutionFilter"); } } @@ -309,11 +317,11 @@ public class GatewaySenderConfigurationTests { private static class TestGatewaySenderConfigurer implements GatewaySenderConfigurer { - private final Map beanNames = new TreeMap<>(); + private final Map> beanNames = new TreeMap<>(); @Override public void configure(String beanName, GatewaySenderFactoryBean bean) { - beanNames.put(beanName, bean.getTransportFilters().stream() + this.beanNames.put(beanName, bean.getTransportFilters().stream() .map(transportFilter -> ((TestGatewayTransportFilter) transportFilter).name) .collect(Collectors.toList())); } @@ -321,7 +329,7 @@ public class GatewaySenderConfigurationTests { private static class TestGatewayEventFilter implements GatewayEventFilter { - private String name; + private final String name; public TestGatewayEventFilter(String name) { this.name = name; @@ -342,9 +350,9 @@ public class GatewaySenderConfigurationTests { } - private static class TestGatewayEventSubstitutionFilter implements GatewayEventSubstitutionFilter { + private static class TestGatewayEventSubstitutionFilter implements GatewayEventSubstitutionFilter { - private String name; + private final String name; public TestGatewayEventSubstitutionFilter(String name) { this.name = name; @@ -362,7 +370,7 @@ public class GatewaySenderConfigurationTests { private static class TestGatewayTransportFilter implements GatewayTransportFilter { - private String name; + private final String name; public TestGatewayTransportFilter(String name) { this.name = name; @@ -385,6 +393,15 @@ public class GatewaySenderConfigurationTests { @Override public boolean equals(Object obj) { + + if (this == obj) { + return true; + } + + if (!(obj instanceof TestGatewayTransportFilter)) { + return false; + } + return this.name.equals(((TestGatewayTransportFilter) obj).name); } } @@ -394,12 +411,12 @@ public class GatewaySenderConfigurationTests { static class BaseGatewaySenderTestConfiguration { @Bean("Region1") - PartitionedRegionFactoryBean createRegion1(GemFireCache gemFireCache) { + PartitionedRegionFactoryBean createRegion1(GemFireCache gemFireCache) { return createRegion("Region1", gemFireCache); } @Bean("Region2") - PartitionedRegionFactoryBean createRegion2(GemFireCache gemFireCache) { + PartitionedRegionFactoryBean createRegion2(GemFireCache gemFireCache) { return createRegion("Region2", gemFireCache); } @@ -423,11 +440,13 @@ public class GatewaySenderConfigurationTests { return new TestGatewayEventFilter("SomeEventFilter"); } - public PartitionedRegionFactoryBean createRegion(String name, GemFireCache gemFireCache) { - final PartitionedRegionFactoryBean regionFactoryBean = new PartitionedRegionFactoryBean(); + public PartitionedRegionFactoryBean createRegion(String name, GemFireCache gemFireCache) { + + PartitionedRegionFactoryBean regionFactoryBean = new PartitionedRegionFactoryBean<>(); + regionFactoryBean.setCache(gemFireCache); - regionFactoryBean.setDataPolicy(DataPolicy.PARTITION); regionFactoryBean.setName(name); + return regionFactoryBean; } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurerTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurerTests.java index 22aa174d..55762c59 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurerTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurerTests.java @@ -22,7 +22,9 @@ import java.io.OutputStream; import java.util.Map; import java.util.Optional; -import org.apache.geode.cache.DataPolicy; +import org.junit.After; +import org.junit.Test; + import org.apache.geode.cache.EntryEvent; import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.Region; @@ -32,9 +34,6 @@ import org.apache.geode.cache.wan.GatewayQueueEvent; import org.apache.geode.cache.wan.GatewaySender; import org.apache.geode.cache.wan.GatewayTransportFilter; -import org.junit.After; -import org.junit.Test; - import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -42,7 +41,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.mock.env.MockPropertySource; /** @@ -51,16 +51,21 @@ import org.springframework.mock.env.MockPropertySource; * @author Udo Kohlmeyer * @see org.junit.Test * @see org.mockito.Mockito - * @see GatewaySenderConfigurer - * @see GatewaySenderConfiguration - * @see org.apache.geode.cache.server.CacheServer + * @see org.apache.geode.cache.GemFireCache + * @see org.apache.geode.cache.Region + * @see org.apache.geode.cache.wan.GatewaySender * @see org.springframework.context.annotation.Configuration + * @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfiguration + * @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfigurer + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.wan.GatewaySenderFactoryBean * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner - * @see org.springframework.data.gemfire.wan.GatewaySenderFactoryBean * @since 2.2.0 */ -public class GatewaySenderConfigurerTests { +@SuppressWarnings("unused") +public class GatewaySenderConfigurerTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; @@ -147,12 +152,12 @@ public class GatewaySenderConfigurerTests { static class BaseGatewaySenderTestConfiguration { @Bean("Region1") - PartitionedRegionFactoryBean createRegion1(GemFireCache gemFireCache) { + PartitionedRegionFactoryBean createRegion1(GemFireCache gemFireCache) { return createRegion("Region1", gemFireCache); } @Bean("Region2") - PartitionedRegionFactoryBean createRegion2(GemFireCache gemFireCache) { + PartitionedRegionFactoryBean createRegion2(GemFireCache gemFireCache) { return createRegion("Region2", gemFireCache); } @@ -171,18 +176,20 @@ public class GatewaySenderConfigurerTests { return new TestGatewayEventFilter("SomeEventFilter"); } - public PartitionedRegionFactoryBean createRegion(String name, GemFireCache gemFireCache) { - final PartitionedRegionFactoryBean regionFactoryBean = new PartitionedRegionFactoryBean(); + public PartitionedRegionFactoryBean createRegion(String name, GemFireCache gemFireCache) { + + PartitionedRegionFactoryBean regionFactoryBean = new PartitionedRegionFactoryBean<>(); + regionFactoryBean.setCache(gemFireCache); - regionFactoryBean.setDataPolicy(DataPolicy.PARTITION); regionFactoryBean.setName(name); + return regionFactoryBean; } } private static class TestGatewayEventFilter implements GatewayEventFilter { - private String name; + private final String name; public TestGatewayEventFilter(String name) { this.name = name; @@ -203,9 +210,9 @@ public class GatewaySenderConfigurerTests { } - private static class TestGatewayEventSubstitutionFilter implements GatewayEventSubstitutionFilter { + private static class TestGatewayEventSubstitutionFilter implements GatewayEventSubstitutionFilter { - private String name; + private final String name; public TestGatewayEventSubstitutionFilter(String name) { this.name = name; @@ -223,7 +230,7 @@ public class GatewaySenderConfigurerTests { private static class TestGatewayTransportFilter implements GatewayTransportFilter { - private String name; + private final String name; public TestGatewayTransportFilter(String name) { this.name = name; @@ -239,11 +246,22 @@ public class GatewaySenderConfigurerTests { return null; } - @Override public int hashCode() { - return name.hashCode(); + @Override + public int hashCode() { + return this.name.hashCode(); } - @Override public boolean equals(Object obj) { + @Override + public boolean equals(Object obj) { + + if (this == obj) { + return true; + } + + if (!(obj instanceof TestGatewayTransportFilter)) { + return false; + } + return this.name.equals(((TestGatewayTransportFilter) obj).name); } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderPropertiesTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderPropertiesIntegrationTests.java similarity index 97% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderPropertiesTests.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderPropertiesIntegrationTests.java index 09335feb..abf3851a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderPropertiesTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderPropertiesIntegrationTests.java @@ -44,28 +44,32 @@ import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean; import org.springframework.data.gemfire.wan.OrderPolicyType; import org.springframework.mock.env.MockPropertySource; /** - * Tests for {@link EnableGatewaySenders} and {@link EnableGatewaySender} to test the configuration of {@link GatewaySender} using properties. + * Integration Tests for {@link EnableGatewaySender} and {@link EnableGatewaySenders} to test the configuration of + * {@link GatewaySender} using properties. * * @author Udo Kohlmeyer * @author John Blum * @see org.junit.Test * @see org.mockito.Mockito + * @see org.apache.geode.cache.wan.GatewaySender + * @see org.springframework.context.annotation.Configuration * @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfiguration * @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfigurer - * @see org.apache.geode.cache.server.CacheServer - * @see org.springframework.context.annotation.Configuration - * @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.wan.GatewaySenderFactoryBean * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.2.0 */ -public class GatewaySenderPropertiesTests { +public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; @@ -557,7 +561,7 @@ public class GatewaySenderPropertiesTests { @SuppressWarnings("rawtypes") private static class TestGatewayEventSubstitutionFilter implements GatewayEventSubstitutionFilter { - private String name; + private final String name; public TestGatewayEventSubstitutionFilter(String name) { this.name = name; @@ -575,7 +579,7 @@ public class GatewaySenderPropertiesTests { private static class TestGatewayEventFilter implements GatewayEventFilter { - private String name; + private final String name; public TestGatewayEventFilter(String name) { this.name = name; @@ -602,7 +606,7 @@ public class GatewaySenderPropertiesTests { private static class TestGatewayTransportFilter implements GatewayTransportFilter { - private String name; + private final String name; public TestGatewayTransportFilter(String name) { this.name = name; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GemFireAsLastResourceConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GemFireAsLastResourceConfigurationUnitTests.java index 04788fb4..ffcf6f05 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GemFireAsLastResourceConfigurationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GemFireAsLastResourceConfigurationUnitTests.java @@ -28,14 +28,14 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.apache.geode.cache.GemFireCache; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.apache.geode.cache.GemFireCache; + import org.springframework.context.annotation.AdviceMode; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.AnnotationAttributes; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/IndexConfigurerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/IndexConfigurerIntegrationTests.java index af0b46d6..83d5adeb 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/IndexConfigurerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/IndexConfigurerIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -25,14 +24,14 @@ import java.util.Iterator; import java.util.Optional; import java.util.Set; -import org.apache.geode.cache.GemFireCache; -import org.apache.geode.cache.lucene.LuceneIndex; -import org.apache.geode.cache.lucene.LuceneService; - import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import org.apache.geode.cache.GemFireCache; +import org.apache.geode.cache.lucene.LuceneIndex; +import org.apache.geode.cache.lucene.LuceneService; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.ConfigurableApplicationContext; @@ -48,10 +47,10 @@ import org.springframework.data.gemfire.mapping.annotation.ClientRegion; import org.springframework.data.gemfire.mapping.annotation.LocalRegion; import org.springframework.data.gemfire.mapping.annotation.ReplicateRegion; import org.springframework.data.gemfire.search.lucene.LuceneIndexFactoryBean; -import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor; +import org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor; /** - * Integration tests for {@link IndexConfigurer}. + * Integration Tests for {@link IndexConfigurer}. * * @author John Blum * @see org.junit.Test @@ -61,6 +60,7 @@ import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor; * @see org.springframework.data.gemfire.IndexFactoryBean * @see org.springframework.data.gemfire.config.annotation.IndexConfigurer * @see org.springframework.data.gemfire.search.lucene.LuceneIndexFactoryBean + * @see org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor * @since 2.0.0 */ @SuppressWarnings("unused") @@ -145,8 +145,8 @@ public class IndexConfigurerIntegrationTests { } @Bean - GemfireTestBeanPostProcessor testBeanPostProcessor() { - return new GemfireTestBeanPostProcessor(); + GemFireMockObjectsBeanPostProcessor testBeanPostProcessor() { + return new GemFireMockObjectsBeanPostProcessor(); } @Bean diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationCannotCoexistWithCacheApplicationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationCannotCoexistWithCacheApplicationIntegrationTests.java index 3d8ec603..5ab59a89 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationCannotCoexistWithCacheApplicationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationCannotCoexistWithCacheApplicationIntegrationTests.java @@ -32,7 +32,8 @@ import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; /** * Integration Tests for {@link LocatorApplication} and {@link LocatorApplicationConfiguration} asserting that @@ -43,15 +44,17 @@ import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockOb * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.client.ClientCache * @see org.apache.geode.distributed.Locator + * @see org.springframework.context.ConfigurableApplicationContext + * @see org.springframework.context.annotation.AnnotationConfigApplicationContext * @see org.springframework.data.gemfire.config.annotation.LocatorApplication * @see org.springframework.data.gemfire.config.annotation.LocatorApplicationConfiguration * @see org.springframework.context.ConfigurableApplicationContext * @see org.springframework.context.annotation.AnnotationConfigApplicationContext - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.2.0 */ @SuppressWarnings("unused") -public class LocatorApplicationCannotCoexistWithCacheApplicationIntegrationTests { +public class LocatorApplicationCannotCoexistWithCacheApplicationIntegrationTests extends IntegrationTestsSupport { private static final String GEMFIRE_LOG_LEVEL = "error"; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationConfigurationIntegrationTests.java index abf6c59d..cb488ef2 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationConfigurationIntegrationTests.java @@ -27,7 +27,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.LocatorFactoryBean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.lang.Nullable; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -38,11 +39,11 @@ import org.springframework.test.context.junit4.SpringRunner; * @author John Blum * @see org.junit.Test * @see org.mockito.Mockito - * @see org.springframework.beans.factory.config.BeanPostProcessor * @see org.springframework.data.gemfire.LocatorFactoryBean * @see org.springframework.data.gemfire.config.annotation.LocatorApplication * @see org.springframework.data.gemfire.config.annotation.LocatorApplicationConfiguration - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.3.0 @@ -50,7 +51,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class LocatorApplicationConfigurationIntegrationTests { +public class LocatorApplicationConfigurationIntegrationTests extends IntegrationTestsSupport { @Autowired private LocatorFactoryBean locatorFactoryBean; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationConfigurerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationConfigurerIntegrationTests.java index 5259d490..d7d5d310 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationConfigurerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationConfigurerIntegrationTests.java @@ -34,7 +34,8 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.LocatorFactoryBean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.lang.Nullable; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -48,7 +49,8 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.data.gemfire.config.annotation.LocatorApplication * @see org.springframework.data.gemfire.config.annotation.LocatorApplicationConfiguration * @see org.springframework.data.gemfire.config.annotation.LocatorConfigurer - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.2.0 @@ -56,7 +58,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class LocatorApplicationConfigurerIntegrationTests { +public class LocatorApplicationConfigurerIntegrationTests extends IntegrationTestsSupport { private static final String GEMFIRE_LOG_LEVEL = "error"; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationPropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationPropertiesIntegrationTests.java index 3f9106f9..44f80b93 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationPropertiesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationPropertiesIntegrationTests.java @@ -22,11 +22,11 @@ import static org.mockito.Mockito.spy; import java.util.Optional; import java.util.Properties; -import org.apache.geode.distributed.Locator; - import org.junit.After; import org.junit.Test; +import org.apache.geode.distributed.Locator; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.ConfigurableApplicationContext; @@ -35,7 +35,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.LocatorFactoryBean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.lang.Nullable; import org.springframework.mock.env.MockPropertySource; @@ -47,16 +48,15 @@ import org.springframework.mock.env.MockPropertySource; * @see java.util.Properties * @see org.junit.Test * @see org.apache.geode.distributed.Locator - * @see org.springframework.context.ConfigurableApplicationContext - * @see org.springframework.context.annotation.AnnotationConfigApplicationContext - * @see org.springframework.core.env.PropertySource +\ * @see org.springframework.core.env.PropertySource * @see org.springframework.data.gemfire.LocatorFactoryBean - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.mock.env.MockPropertySource * @since 2.2.0 */ @SuppressWarnings("unused") -public class LocatorApplicationPropertiesIntegrationTests { +public class LocatorApplicationPropertiesIntegrationTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheApplicationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheApplicationIntegrationTests.java index eedbbef3..9b4ec54a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheApplicationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheApplicationIntegrationTests.java @@ -21,15 +21,15 @@ import static org.assertj.core.api.Assertions.assertThat; import javax.annotation.Resource; +import org.junit.Test; +import org.junit.runner.RunWith; + import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheLoader; import org.apache.geode.cache.CacheLoaderException; import org.apache.geode.cache.LoaderHelper; import org.apache.geode.cache.Region; -import org.junit.Test; -import org.junit.runner.RunWith; - import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.test.context.ContextConfiguration; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheApplicationWithAddedCacheServerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheApplicationWithAddedCacheServerIntegrationTests.java index 88722a61..8b453f9a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheApplicationWithAddedCacheServerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheApplicationWithAddedCacheServerIntegrationTests.java @@ -18,6 +18,7 @@ package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; import java.util.List; +import java.util.Scanner; import org.junit.AfterClass; import org.junit.Before; @@ -31,8 +32,8 @@ import org.apache.geode.cache.server.CacheServer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.data.gemfire.GemFireProperties; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.process.ProcessWrapper; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -44,6 +45,8 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.junit.Test * @see org.apache.geode.cache.Cache * @see org.apache.geode.cache.server.CacheServer + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport + * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.2.0 */ @@ -51,7 +54,8 @@ import org.springframework.test.context.junit4.SpringRunner; @ContextConfiguration(classes = PeerCacheApplicationWithAddedCacheServerIntegrationTests.TestPeerCacheConfiguration.class) @SuppressWarnings("unused") // TODO: Convert to Unit Test once STDG is used by SDG. -public class PeerCacheApplicationWithAddedCacheServerIntegrationTests extends ClientServerIntegrationTestsSupport { +public class PeerCacheApplicationWithAddedCacheServerIntegrationTests + extends ForkingClientServerIntegrationTestsSupport { private static int cacheServerPort; private static int locatorPort; @@ -80,12 +84,7 @@ public class PeerCacheApplicationWithAddedCacheServerIntegrationTests extends Cl @AfterClass public static void stopGemFireLocator() { - stop(gemfireLocator); - - System.getProperties().stringPropertyNames().stream() - .filter(propertyName -> propertyName.startsWith("spring.data.gemfire.")) - .forEach(System::clearProperty); } @Autowired @@ -128,7 +127,7 @@ public class PeerCacheApplicationWithAddedCacheServerIntegrationTests extends Cl applicationContext.registerShutdownHook(); - block(); + new Scanner(System.in).nextLine(); } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheConfigurerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheConfigurerIntegrationTests.java index 5f399449..949377eb 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheConfigurerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheConfigurerIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -23,30 +22,29 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import org.apache.geode.cache.Cache; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.Cache; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.CacheFactoryBean; -import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor; +import org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration tests for {@link PeerCacheConfigurer}. + * Integration Tests for {@link PeerCacheConfigurer}. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith * @see org.apache.geode.cache.Cache * @see org.springframework.data.gemfire.CacheFactoryBean * @see org.springframework.data.gemfire.config.annotation.PeerCacheApplication * @see org.springframework.data.gemfire.config.annotation.PeerCacheConfigurer - * @see org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor + * @see org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor * @see org.springframework.test.context.junit4.SpringRunner * @since 1.0.0 */ @@ -92,8 +90,8 @@ public class PeerCacheConfigurerIntegrationTests { static class TestConfiguration { @Bean - GemfireTestBeanPostProcessor testBeanPostProcessor() { - return new GemfireTestBeanPostProcessor(); + GemFireMockObjectsBeanPostProcessor testBeanPostProcessor() { + return new GemFireMockObjectsBeanPostProcessor(); } @Bean @@ -114,7 +112,7 @@ public class PeerCacheConfigurerIntegrationTests { static class TestPeerCacheConfigurer implements Iterable, PeerCacheConfigurer { - private Set beanNames = new HashSet<>(); + private final Set beanNames = new HashSet<>(); @Override public void configure(String beanName, CacheFactoryBean bean) { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java index 4a4771b5..00045f99 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java @@ -34,7 +34,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.CacheFactoryBean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.mock.env.MockPropertySource; /** @@ -44,17 +45,17 @@ import org.springframework.mock.env.MockPropertySource; * @see java.util.Properties * @see org.junit.Test * @see org.apache.geode.cache.Cache - * @see org.springframework.context.ConfigurableApplicationContext - * @see org.springframework.context.annotation.AnnotationConfigApplicationContext + * @see org.springframework.core.env.MutablePropertySources * @see org.springframework.core.env.PropertySource * @see org.springframework.data.gemfire.CacheFactoryBean * @see org.springframework.data.gemfire.config.annotation.PeerCacheApplication - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.mock.env.MockPropertySource * @since 2.0.0 */ @SuppressWarnings("unused") -public class PeerCachePropertiesIntegrationTests { +public class PeerCachePropertiesIntegrationTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PoolPropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PoolPropertiesIntegrationTests.java index 50089417..9d1f0732 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PoolPropertiesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PoolPropertiesIntegrationTests.java @@ -34,7 +34,8 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.mock.env.MockPropertySource; /** @@ -45,17 +46,17 @@ import org.springframework.mock.env.MockPropertySource; * @see org.apache.geode.cache.client.ClientCache * @see org.apache.geode.cache.client.Pool * @see org.apache.geode.cache.client.PoolFactory - * @see org.springframework.context.ConfigurableApplicationContext - * @see org.springframework.context.annotation.AnnotationConfigApplicationContext - * @see org.springframework.context.annotation.Bean * @see org.springframework.core.env.PropertySource + * @see org.springframework.data.gemfire.config.annotation.AddPoolConfiguration + * @see org.springframework.data.gemfire.config.annotation.AddPoolsConfiguration * @see org.springframework.data.gemfire.config.annotation.EnablePool * @see org.springframework.data.gemfire.config.annotation.EnablePools - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.0.0 */ @SuppressWarnings("unused") -public class PoolPropertiesIntegrationTests { +public class PoolPropertiesIntegrationTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/RegionConfigurerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/RegionConfigurerIntegrationTests.java index 42553ad9..f9d253d4 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/RegionConfigurerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/RegionConfigurerIntegrationTests.java @@ -23,11 +23,11 @@ import java.util.Iterator; import java.util.Optional; import java.util.Set; -import org.apache.geode.cache.GemFireCache; - import org.junit.After; import org.junit.Test; +import org.apache.geode.cache.GemFireCache; + import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -42,27 +42,25 @@ import org.springframework.data.gemfire.mapping.annotation.ClientRegion; import org.springframework.data.gemfire.mapping.annotation.LocalRegion; import org.springframework.data.gemfire.mapping.annotation.PartitionRegion; import org.springframework.data.gemfire.mapping.annotation.ReplicateRegion; -import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor; import org.springframework.util.ReflectionUtils; /** - * Integration tests for {@link RegionConfigurer}. + * Integration Tests for {@link RegionConfigurer}. * * @author John Blum * @see org.junit.Test * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.Region - * @see org.springframework.context.ConfigurableApplicationContext - * @see org.springframework.context.annotation.AnnotationConfigApplicationContext - * @see org.springframework.context.annotation.Bean - * @see org.springframework.data.gemfire.PartitionedRegionFactoryBean * @see org.springframework.data.gemfire.PeerRegionFactoryBean * @see org.springframework.data.gemfire.client.ClientRegionFactoryBean * @see org.springframework.data.gemfire.config.annotation.RegionConfigurer - * @see org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor * @since 2.1.0 */ -public class RegionConfigurerIntegrationTests { +public class RegionConfigurerIntegrationTests extends IntegrationTestsSupport { private ConfigurableApplicationContext applicationContext; @@ -84,7 +82,7 @@ public class RegionConfigurerIntegrationTests { return beanNamesField; }) .map(beanNamesField -> (Set) ReflectionUtils.getField(beanNamesField, target)) - .orElseGet(() -> Collections.emptySet()); + .orElseGet(Collections::emptySet); } private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { @@ -160,8 +158,8 @@ public class RegionConfigurerIntegrationTests { static class AbstractTestConfiguration { @Bean - GemfireTestBeanPostProcessor testBeanPostProcessor() { - return new GemfireTestBeanPostProcessor(); + GemFireMockObjectsBeanPostProcessor testBeanPostProcessor() { + return new GemFireMockObjectsBeanPostProcessor(); } @Bean diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/RegionDataAccessTracingAspectUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/RegionDataAccessTracingAspectUnitTests.java index 3cecba99..55a35887 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/RegionDataAccessTracingAspectUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/RegionDataAccessTracingAspectUnitTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -24,26 +23,27 @@ import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Resource; -import org.apache.geode.cache.GemFireCache; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.client.ClientRegionShortcut; - import org.junit.Assume; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.GemFireCache; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.client.ClientRegionShortcut; + import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; import org.springframework.data.gemfire.config.annotation.support.RegionDataAccessTracingAspect; -import org.springframework.data.gemfire.test.logging.slf4j.logback.TestAppender; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.logging.slf4j.logback.TestAppender; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.ClassUtils; /** - * Unit tests for {@link RegionDataAccessTracingAspect}. + * Unit Tests for {@link RegionDataAccessTracingAspect}. * * @author John Blum * @see org.junit.Test @@ -51,15 +51,17 @@ import org.springframework.util.ClassUtils; * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.client.ClientRegionFactoryBean * @see org.springframework.data.gemfire.config.annotation.support.RegionDataAccessTracingAspect - * @see org.springframework.data.gemfire.test.logging.slf4j.logback.TestAppender - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.logging.slf4j.logback.TestAppender + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.0.2 */ @RunWith(SpringRunner.class) @ContextConfiguration -public class RegionDataAccessTracingAspectUnitTests { +@SuppressWarnings("unused") +public class RegionDataAccessTracingAspectUnitTests extends IntegrationTestsSupport { private static final String LOGBACK_LOGGER_CLASS_NAME = "ch.qos.logback.classic.Logger"; @@ -75,7 +77,6 @@ public class RegionDataAccessTracingAspectUnitTests { } @Resource(name = "ClientRegion") - @SuppressWarnings("all") private Region region; private Runnable regionCallbackArgument(AtomicBoolean called) { @@ -450,7 +451,7 @@ public class RegionDataAccessTracingAspectUnitTests { } @Test - public void logsRegionSize() throws Exception { + public void logsRegionSize() { this.region.size(); @@ -463,7 +464,7 @@ public class RegionDataAccessTracingAspectUnitTests { } @Test - public void logsRegionSizeOnServer() throws Exception { + public void logsRegionSizeOnServer() { this.region.sizeOnServer(); @@ -476,7 +477,7 @@ public class RegionDataAccessTracingAspectUnitTests { } @Test - public void logsRegionValues() throws Exception { + public void logsRegionValues() { this.region.values(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/AbstractGemFireAsLastResourceAspectSupportUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/AbstractGemFireAsLastResourceAspectSupportUnitTests.java index ec4b6626..5b795490 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/AbstractGemFireAsLastResourceAspectSupportUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/AbstractGemFireAsLastResourceAspectSupportUnitTests.java @@ -40,8 +40,6 @@ import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; -import org.apache.geode.cache.GemFireCache; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -50,6 +48,9 @@ import org.mockito.Mock; import org.mockito.Spy; import org.mockito.internal.matchers.VarargMatcher; import org.mockito.junit.MockitoJUnitRunner; + +import org.apache.geode.cache.GemFireCache; + import org.slf4j.Logger; /** diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/EnableGemFireAsLastResourceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/EnableGemFireAsLastResourceIntegrationTests.java index d95368c0..fcd0a09f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/EnableGemFireAsLastResourceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/EnableGemFireAsLastResourceIntegrationTests.java @@ -29,13 +29,13 @@ import java.util.concurrent.atomic.AtomicBoolean; import javax.resource.ResourceException; +import org.junit.Before; +import org.junit.Test; + import org.apache.geode.cache.GemFireCache; import org.apache.geode.ra.GFConnection; import org.apache.geode.ra.GFConnectionFactory; -import org.junit.Before; -import org.junit.Test; - import org.springframework.beans.factory.BeanCreationException; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/GemFireAsLastResourceConnectionAcquiringAspectUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/GemFireAsLastResourceConnectionAcquiringAspectUnitTests.java index 538d4d54..adac88f6 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/GemFireAsLastResourceConnectionAcquiringAspectUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/GemFireAsLastResourceConnectionAcquiringAspectUnitTests.java @@ -30,14 +30,15 @@ import javax.naming.Context; import javax.naming.NamingException; import javax.resource.ResourceException; -import org.apache.geode.ra.GFConnection; -import org.apache.geode.ra.GFConnectionFactory; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; + +import org.apache.geode.ra.GFConnection; +import org.apache.geode.ra.GFConnectionFactory; + import org.slf4j.Logger; /** diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/GemFireAsLastResourceConnectionClosingAspectUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/GemFireAsLastResourceConnectionClosingAspectUnitTests.java index ed9c4724..53a18ed9 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/GemFireAsLastResourceConnectionClosingAspectUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/GemFireAsLastResourceConnectionClosingAspectUnitTests.java @@ -25,13 +25,14 @@ import static org.mockito.Mockito.when; import javax.resource.ResourceException; -import org.apache.geode.ra.GFConnection; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; + +import org.apache.geode.ra.GFConnection; + import org.slf4j.Logger; /** diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/schema/SchemaObjectTypeUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/schema/SchemaObjectTypeUnitTests.java index 17ff4f66..ce224c7e 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/schema/SchemaObjectTypeUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/schema/SchemaObjectTypeUnitTests.java @@ -24,6 +24,10 @@ import static org.springframework.data.gemfire.util.CollectionUtils.asSet; import java.util.Set; import java.util.stream.Collectors; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + import org.apache.geode.cache.Cache; import org.apache.geode.cache.DiskStore; import org.apache.geode.cache.Region; @@ -36,10 +40,6 @@ import org.apache.geode.cache.query.Index; import org.apache.geode.cache.wan.GatewayReceiver; import org.apache.geode.cache.wan.GatewaySender; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; - /** * Unit tests for {@link SchemaObjectType}. * diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/schema/definitions/IndexDefinitionUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/schema/definitions/IndexDefinitionUnitTests.java index 32a9800e..5b0c0820 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/schema/definitions/IndexDefinitionUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/schema/definitions/IndexDefinitionUnitTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.schema.definitions; import static org.assertj.core.api.Assertions.assertThat; @@ -25,22 +24,22 @@ import static org.mockito.Mockito.when; import java.io.IOException; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.query.Index; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.query.Index; + import org.springframework.data.gemfire.IndexType; import org.springframework.data.gemfire.config.admin.GemfireAdminOperations; import org.springframework.data.gemfire.config.schema.SchemaObjectType; -import org.springframework.data.gemfire.test.support.IOUtils; +import org.springframework.data.gemfire.tests.util.IOUtils; /** - * Unit tests for {@link IndexDefinition}. + * Unit Tests for {@link IndexDefinition}. * * @author John Blum * @see org.junit.Test @@ -261,7 +260,7 @@ public class IndexDefinitionUnitTests { public void onNullRegion() { try { - IndexDefinition.from(this.mockIndex).on((Region) null); + IndexDefinition.from(this.mockIndex).on((Region) null); } catch (IllegalArgumentException expected) { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/schema/definitions/RegionDefinitionUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/schema/definitions/RegionDefinitionUnitTests.java index b596f3ec..167edf4b 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/schema/definitions/RegionDefinitionUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/schema/definitions/RegionDefinitionUnitTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.schema.definitions; import static org.assertj.core.api.Assertions.assertThat; @@ -25,21 +24,21 @@ import static org.mockito.Mockito.when; import java.io.IOException; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.RegionShortcut; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.RegionShortcut; + import org.springframework.data.gemfire.config.admin.GemfireAdminOperations; import org.springframework.data.gemfire.config.schema.SchemaObjectType; -import org.springframework.data.gemfire.test.support.IOUtils; +import org.springframework.data.gemfire.tests.util.IOUtils; /** - * Unit tests for {@link RegionDefinition}. + * Unit Tests for {@link RegionDefinition}. * * @author John Blum * @see org.junit.Test diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/schema/support/ComposableSchemaObjectCollectorUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/schema/support/ComposableSchemaObjectCollectorUnitTests.java index a43459c6..a40ee7c8 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/schema/support/ComposableSchemaObjectCollectorUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/schema/support/ComposableSchemaObjectCollectorUnitTests.java @@ -26,20 +26,20 @@ import static org.springframework.data.gemfire.util.CollectionUtils.asSet; import java.util.Collections; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; - -import org.apache.geode.cache.GemFireCache; - import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.apache.geode.cache.GemFireCache; + import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.config.schema.SchemaObjectCollector; import org.springframework.data.gemfire.config.schema.SchemaObjectType; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + /** * Unit tests for {@link ComposableSchemaObjectCollector}. * diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/AutoRegionLookupBeanPostProcessorUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/AutoRegionLookupBeanPostProcessorUnitTests.java index 3ad654bd..7d387146 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/AutoRegionLookupBeanPostProcessorUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/AutoRegionLookupBeanPostProcessorUnitTests.java @@ -36,9 +36,6 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; -import org.apache.geode.cache.GemFireCache; -import org.apache.geode.cache.Region; - import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -47,6 +44,9 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.apache.geode.cache.GemFireCache; +import org.apache.geode.cache.Region; + import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.data.gemfire.util.CollectionUtils; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessorUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessorUnitTests.java index c4ccc0d2..b400d04a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessorUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessorUnitTests.java @@ -23,6 +23,8 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; +import org.junit.Test; + import org.apache.geode.cache.EvictionAction; import org.apache.geode.cache.ExpirationAction; import org.apache.geode.cache.InterestPolicy; @@ -30,8 +32,6 @@ import org.apache.geode.cache.InterestResultPolicy; import org.apache.geode.cache.Scope; import org.apache.geode.cache.wan.GatewaySender; -import org.junit.Test; - import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.data.gemfire.IndexMaintenancePolicyConverter; import org.springframework.data.gemfire.IndexMaintenancePolicyType; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/DefinedIndexesApplicationListenerUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/DefinedIndexesApplicationListenerUnitTests.java index 90b75608..beb50ee7 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/DefinedIndexesApplicationListenerUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/DefinedIndexesApplicationListenerUnitTests.java @@ -30,20 +30,21 @@ import static org.mockito.Mockito.when; import java.util.Collections; import java.util.HashMap; -import org.apache.geode.cache.query.MultiIndexCreationException; -import org.apache.geode.cache.query.QueryService; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.slf4j.Logger; + +import org.apache.geode.cache.query.MultiIndexCreationException; +import org.apache.geode.cache.query.QueryService; import org.springframework.context.ApplicationContext; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.data.gemfire.config.xml.GemfireConstants; +import org.slf4j.Logger; + /** * Unit tests for {@link DefinedIndexesApplicationListener}. * diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/DiskStoreDirectoryBeanPostProcessorIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/DiskStoreDirectoryBeanPostProcessorIntegrationTests.java index dcb442e2..d6899fbd 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/DiskStoreDirectoryBeanPostProcessorIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/DiskStoreDirectoryBeanPostProcessorIntegrationTests.java @@ -22,17 +22,17 @@ import java.io.File; import java.util.Arrays; import java.util.Collections; -import org.apache.geode.cache.GemFireCache; - import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.GemFireCache; + import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.DiskStoreFactoryBean; import org.springframework.data.gemfire.config.annotation.PeerCacheApplication; -import org.springframework.data.gemfire.test.support.FileSystemUtils; +import org.springframework.data.gemfire.tests.util.FileSystemUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/LuceneIndexRegionBeanFactoryPostProcessorIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/LuceneIndexRegionBeanFactoryPostProcessorIntegrationTests.java index 6e4c3042..a1e96eac 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/LuceneIndexRegionBeanFactoryPostProcessorIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/LuceneIndexRegionBeanFactoryPostProcessorIntegrationTests.java @@ -22,11 +22,11 @@ import java.util.List; import java.util.Optional; import java.util.concurrent.CopyOnWriteArrayList; -import org.apache.geode.cache.Region; - import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.Region; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; @@ -34,23 +34,30 @@ import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.ApplicationContext; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.data.gemfire.PeerRegionFactoryBean; -import org.springframework.data.gemfire.test.mock.context.GemFireMockObjectsApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.lang.Nullable; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.Assert; /** - * Unit tests for {@link LuceneIndexRegionBeanFactoryPostProcessor}. + * Integration Tests for {@link LuceneIndexRegionBeanFactoryPostProcessor}. * * @author John Blum * @see org.junit.Test + * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.config.support.LuceneIndexRegionBeanFactoryPostProcessor + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner * @since 2.1.0 */ @RunWith(SpringRunner.class) @ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) -public class LuceneIndexRegionBeanFactoryPostProcessorIntegrationTests { +@SuppressWarnings("unused") +public class LuceneIndexRegionBeanFactoryPostProcessorIntegrationTests extends IntegrationTestsSupport { private static final List beanNames = new CopyOnWriteArrayList<>(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/PdxDiskStoreAwareBeanFactoryPostProcessorUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/PdxDiskStoreAwareBeanFactoryPostProcessorUnitTests.java index 35807d1a..4eb6ccfc 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/PdxDiskStoreAwareBeanFactoryPostProcessorUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/PdxDiskStoreAwareBeanFactoryPostProcessorUnitTests.java @@ -29,13 +29,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.junit.Test; + import org.apache.geode.cache.DiskStore; import org.apache.geode.cache.Region; import org.apache.geode.cache.asyncqueue.AsyncEventQueue; import org.apache.geode.internal.cache.PartitionedRegion; -import org.junit.Test; - import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.AbstractBeanDefinition; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheServerNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheServerNamespaceTest.java index 0e22fa37..ee1bf784 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheServerNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheServerNamespaceTest.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; @@ -28,38 +27,37 @@ import org.apache.geode.cache.server.ClientSubscriptionConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.StringUtils; /** - * The CacheServerNamespaceTest class is a test suite of test cases testing the functionality of the SDG XML namespace - * when configuring a GemFire Cache Servers and Client Subscription. + * Integration Tests for the {@link CacheServer} SDG XML namespace configuration metadata. * * @author Costin Leau * @author David Turanski * @author John Blum * @see org.junit.Test - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer + * @see org.apache.geode.cache.server.CacheServer * @see org.springframework.context.ApplicationContext + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner - * @see org.apache.geode.cache.server.CacheServer - * @see org.apache.geode.cache.server.ClientSubscriptionConfig */ -@ContextConfiguration(locations="server-ns.xml", initializers=GemfireTestApplicationContextInitializer.class) +@ContextConfiguration(locations="server-ns.xml", initializers= GemFireMockObjectsApplicationContextInitializer.class) @RunWith(SpringJUnit4ClassRunner.class) @SuppressWarnings("unused") public class CacheServerNamespaceTest { @Autowired - private ApplicationContext context; + private ApplicationContext applicationContext; @Test @SuppressWarnings("deprecation") - public void testBasicCacheServer() throws Exception { - CacheServer cacheServer = context.getBean("advanced-config", CacheServer.class); + public void testBasicCacheServer() { + + CacheServer cacheServer = applicationContext.getBean("advanced-config", CacheServer.class); assertNotNull(cacheServer); assertEquals(1, cacheServer.getGroups().length); @@ -67,7 +65,7 @@ public class CacheServerNamespaceTest { assertTrue(cacheServer.getPort() != 0); assertEquals("localhost", cacheServer.getHostnameForClients()); assertEquals("test-server", cacheServer.getGroups()[0]); - assertEquals(2000l, cacheServer.getLoadPollInterval()); + assertEquals(2000L, cacheServer.getLoadPollInterval()); assertEquals(22, cacheServer.getMaxConnections()); assertEquals(16, cacheServer.getMaxThreads()); assertEquals(1000, cacheServer.getMaximumMessageCount()); @@ -82,5 +80,4 @@ public class CacheServerNamespaceTest { assertTrue(String.format("Expected empty DiskStoreName; but was (%1$s)", clientSubscriptionConfig.getDiskStoreName()), StringUtils.isEmpty(clientSubscriptionConfig.getDiskStoreName())); } - } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceIntegrationTests.java new file mode 100644 index 00000000..543db67f --- /dev/null +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceIntegrationTests.java @@ -0,0 +1,87 @@ +/* + * Copyright 2010-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.gemfire.config.xml; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.geode.pdx.PdxSerializer; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.data.gemfire.CacheFactoryBean; +import org.springframework.data.gemfire.config.support.PdxDiskStoreAwareBeanFactoryPostProcessor; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Integration Tests with test case testing the SDG XML namespace configuration metadata when PDX is configured + * in Apache Geode. + * + * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.pdx.PdxSerializer + * @see org.springframework.data.gemfire.config.support.PdxDiskStoreAwareBeanFactoryPostProcessor + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner + * @since 1.3.3 + */ +@RunWith(SpringRunner.class) +@ContextConfiguration(locations = "cache-using-pdx-ns.xml", + initializers = GemFireMockObjectsApplicationContextInitializer.class) +@SuppressWarnings("unused") +public class CacheUsingPdxNamespaceIntegrationTests extends IntegrationTestsSupport { + + @Autowired + private ApplicationContext applicationContext; + + @Test + public void testApplicationContextHasPdxDiskStoreAwareBeanFactoryPostProcessor() { + + PdxDiskStoreAwareBeanFactoryPostProcessor postProcessor = + applicationContext.getBean(PdxDiskStoreAwareBeanFactoryPostProcessor.class); + + // NOTE the postProcessor reference will not be null as the ApplicationContext.getBean(:Class) method (getting + // a bean by Class type) will throw a NoSuchBeanDefinitionException if no bean of type + // PdxDiskStoreAwareBeanFactoryPostProcessor could be found, or throw a NoUniqueBeanDefinitionException if + // our PdxDiskStoreAwareBeanFactoryPostProcessor bean is not unique! + assertThat(postProcessor).isNotNull(); + assertThat(postProcessor.getPdxDiskStoreName()).isEqualTo("pdxStore"); + } + + @Test + public void testCachePdxConfiguration() { + + CacheFactoryBean cacheFactoryBean = applicationContext.getBean("&gemfireCache", CacheFactoryBean.class); + + assertThat(cacheFactoryBean).isNotNull(); + assertThat(cacheFactoryBean.getPdxDiskStoreName()).isEqualTo("pdxStore"); + assertThat(Boolean.TRUE.equals(cacheFactoryBean.getPdxPersistent())).isTrue(); + assertThat(Boolean.TRUE.equals(cacheFactoryBean.getPdxReadSerialized())).isTrue(); + + PdxSerializer autoSerializer = applicationContext.getBean("autoSerializer", PdxSerializer.class); + + assertThat(autoSerializer).isNotNull(); + assertThat(cacheFactoryBean.getPdxSerializer()).isSameAs(autoSerializer); + } + +} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceTest.java deleted file mode 100644 index 3b09af86..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.config.xml; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.apache.geode.pdx.PdxSerializer; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.data.gemfire.CacheFactoryBean; -import org.springframework.data.gemfire.config.support.PdxDiskStoreAwareBeanFactoryPostProcessor; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * The CacheUsingPdxNamespaceTest class is a test suite of test case testing the Spring Data GemFire XML namespace - * when PDX is configured in GemFire. - * - * @author John Blum - * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner - * @since 1.3.3 - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "cache-using-pdx-ns.xml", initializers = GemfireTestApplicationContextInitializer.class) -@SuppressWarnings("unused") -public class CacheUsingPdxNamespaceTest { - - @Autowired - private ApplicationContext context; - - @Test - public void testApplicationContextHasPdxDiskStoreAwareBeanFactoryPostProcessor() { - PdxDiskStoreAwareBeanFactoryPostProcessor postProcessor = context.getBean( - PdxDiskStoreAwareBeanFactoryPostProcessor.class); - - // NOTE the postProcessor reference will not be null as the ApplicationContext.getBean(:Class) method (getting - // a bean by Class type) will throw a NoSuchBeanDefinitionException if no bean of type - // PdxDiskStoreAwareBeanFactoryPostProcessor could be found, or throw a NoUniqueBeanDefinitionException if - // our PdxDiskStoreAwareBeanFactoryPostProcessor bean is not unique! - assertNotNull(postProcessor); - assertEquals("pdxStore", postProcessor.getPdxDiskStoreName()); - } - - @Test - public void testCachePdxConfiguration() { - final CacheFactoryBean cacheFactoryBean = context.getBean("&gemfireCache", CacheFactoryBean.class); - - assertNotNull(cacheFactoryBean); - assertEquals("pdxStore", cacheFactoryBean.getPdxDiskStoreName()); - assertTrue(Boolean.TRUE.equals(cacheFactoryBean.getPdxPersistent())); - assertTrue(Boolean.TRUE.equals(cacheFactoryBean.getPdxReadSerialized())); - - final PdxSerializer autoSerializer = context.getBean("autoSerializer", PdxSerializer.class); - - assertNotNull(autoSerializer); - assertSame(autoSerializer, cacheFactoryBean.getPdxSerializer()); - } - -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionNamespaceTests.java similarity index 90% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionNamespaceTests.java index 86dac665..5d281c4e 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionNamespaceTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static java.util.Arrays.stream; @@ -23,7 +22,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray; @@ -57,13 +56,14 @@ import org.springframework.data.gemfire.SimpleObjectSizer; import org.springframework.data.gemfire.TestUtils; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; import org.springframework.data.gemfire.client.Interest; -import org.springframework.data.gemfire.test.mock.context.GemFireMockObjectsApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.ObjectUtils; /** - * Unit tests for Spring Data GemFire's XML namespace support for client {@link Region Regions}. + * Unit Tests for SDG's XML namespace configuration metadata for client {@link Region Regions}. * * @author Costin Leau * @author David Turanski @@ -72,11 +72,15 @@ import org.springframework.util.ObjectUtils; * @see org.apache.geode.cache.client.ClientCache * @see org.springframework.data.gemfire.client.ClientRegionFactoryBean * @see org.springframework.data.gemfire.config.xml.ClientRegionParser + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner */ -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @ContextConfiguration(locations = "client-ns.xml", initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class ClientRegionNamespaceTest { +public class ClientRegionNamespaceTests extends IntegrationTestsSupport { @Autowired private ApplicationContext applicationContext; @@ -88,7 +92,7 @@ public class ClientRegionNamespaceTest { } @Test - public void testBeanNames() throws Exception { + public void testBeanNames() { assertTrue(applicationContext.containsBean("SimpleRegion")); assertTrue(applicationContext.containsBean("Publisher")); @@ -99,7 +103,7 @@ public class ClientRegionNamespaceTest { } @Test - public void testSimpleClientRegion() throws Exception { + public void testSimpleClientRegion() { assertTrue(applicationContext.containsBean("simple")); @@ -157,8 +161,8 @@ public class ClientRegionNamespaceTest { } @Test - @SuppressWarnings({ "deprecation", "rawtypes" }) - public void testPersistentClientRegion() throws Exception { + @SuppressWarnings("rawtypes") + public void testPersistentClientRegion() { assertTrue(applicationContext.containsBean("persistent")); @@ -207,7 +211,8 @@ public class ClientRegionNamespaceTest { assertTrue(applicationContext.containsBean("loadWithWrite")); - ClientRegionFactoryBean factory = applicationContext.getBean("&loadWithWrite", ClientRegionFactoryBean.class); + ClientRegionFactoryBean factory = + applicationContext.getBean("&loadWithWrite", ClientRegionFactoryBean.class); assertNotNull(factory); assertEquals("LoadedFullOfWrites", TestUtils.readField("name", factory)); @@ -265,7 +270,7 @@ public class ClientRegionNamespaceTest { assertTrue(applicationContext.containsBean("client-with-interests")); - ClientRegionFactoryBean factoryBean = + ClientRegionFactoryBean factoryBean = applicationContext.getBean("&client-with-interests", ClientRegionFactoryBean.class); assertNotNull(factoryBean); @@ -278,7 +283,7 @@ public class ClientRegionNamespaceTest { assertInterest(true, false, InterestResultPolicy.KEYS, getInterestWithKey(".*", interests)); assertInterest(true, false, InterestResultPolicy.KEYS_VALUES, getInterestWithKey("keyPrefix.*", interests)); - Region mockClientRegion = applicationContext.getBean("client-with-interests", Region.class); + Region mockClientRegion = applicationContext.getBean("client-with-interests", Region.class); assertNotNull(mockClientRegion); @@ -290,7 +295,7 @@ public class ClientRegionNamespaceTest { } private void assertInterest(boolean expectedDurable, boolean expectedReceiveValues, - InterestResultPolicy expectedPolicy, Interest actualInterest) { + InterestResultPolicy expectedPolicy, Interest actualInterest) { assertNotNull(actualInterest); assertEquals(expectedDurable, actualInterest.isDurable()); @@ -298,7 +303,8 @@ public class ClientRegionNamespaceTest { assertEquals(expectedPolicy, actualInterest.getPolicy()); } - private Interest getInterestWithKey(final String key, final Interest... interests) { + @SuppressWarnings("rawtypes") + private Interest getInterestWithKey(String key, Interest... interests) { for (Interest interest : interests) { if (interest.getKey().equals(key)) { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ContinuousQueryListenerContainerNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ContinuousQueryListenerContainerNamespaceIntegrationTests.java similarity index 83% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ContinuousQueryListenerContainerNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ContinuousQueryListenerContainerNamespaceIntegrationTests.java index 67684f0d..b0be8098 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ContinuousQueryListenerContainerNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ContinuousQueryListenerContainerNamespaceIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; @@ -29,7 +28,6 @@ import java.util.concurrent.Executor; import javax.annotation.Resource; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -45,23 +43,22 @@ import org.springframework.data.gemfire.listener.ContinuousQueryListener; import org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer; import org.springframework.data.gemfire.listener.GemfireMDP; import org.springframework.data.gemfire.listener.adapter.ContinuousQueryListenerAdapter; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.ErrorHandler; /** - * Integration tests for the configuration and initialization of the SDG {@link ContinuousQueryListenerContainer} + * Integration Tests for the configuration and initialization of the SDG {@link ContinuousQueryListenerContainer} * using the SDG XML namespace. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith * @see org.apache.geode.cache.client.ClientCache * @see org.apache.geode.cache.query.CqListener * @see org.apache.geode.cache.query.CqQuery * @see org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 1.4.0 @@ -69,27 +66,12 @@ import org.springframework.util.ErrorHandler; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class ContinuousQueryListenerContainerNamespaceTest extends ClientServerIntegrationTestsSupport { - - private static ProcessWrapper gemfireServer; +public class ContinuousQueryListenerContainerNamespaceIntegrationTests + extends ForkingClientServerIntegrationTestsSupport { @BeforeClass public static void startGemFireServer() throws Exception { - - int availablePort = findAvailablePort(); - - gemfireServer = run(CqCacheServerProcess.class, - String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort)); - - waitForServerToStart(DEFAULT_HOSTNAME, availablePort); - - System.setProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY, String.valueOf(availablePort)); - } - - @AfterClass - public static void stopGemFireServer() { - System.clearProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY); - stop(gemfireServer); + startGemFireServer(CqCacheServerProcess.class); } @Autowired diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreAndEvictionRegionParsingTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreEvictionAndExpirationRegionParsingIntegrationTests.java similarity index 86% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreAndEvictionRegionParsingTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreEvictionAndExpirationRegionParsingIntegrationTests.java index b9fc95c0..0be6ae3e 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreAndEvictionRegionParsingTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreEvictionAndExpirationRegionParsingIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; @@ -55,21 +54,36 @@ import org.springframework.data.gemfire.PeerRegionFactoryBean; import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; import org.springframework.data.gemfire.SimpleObjectSizer; import org.springframework.data.gemfire.TestUtils; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.FileSystemUtils; /** + * Integration Tests for {@link Region}, {@link EvictionAttributes} and {@link DiskStore} SDG XML namespace + * configuration metadata parsing. + * * @author Costin Leau * @author David Turanski * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.DiskStore + * @see org.apache.geode.cache.ExpirationAttributes + * @see org.apache.geode.cache.EvictionAttributes + * @see org.apache.geode.cache.Region + * @see org.apache.geode.cache.RegionAttributes + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations="diskstore-ns.xml", initializers=GemfireTestApplicationContextInitializer.class) +@ContextConfiguration(locations = "diskstore-ns.xml", + initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -// TODO move test cases into a DiskStoreIntegrationTests class -public class DiskStoreAndEvictionRegionParsingTest { +// TODO: Move test cases into a DiskStoreIntegrationTests class +public class DiskStoreEvictionAndExpirationRegionParsingIntegrationTests extends IntegrationTestsSupport { private static File diskStoreDirectory; @@ -106,7 +120,7 @@ public class DiskStoreAndEvictionRegionParsingTest { assertNotNull(diskStore); assertEquals("diskStore1", diskStore.getName()); assertEquals(50, diskStore.getQueueSize()); - assertEquals(true, diskStore.getAutoCompact()); + assertTrue(diskStore.getAutoCompact()); assertEquals(DiskStoreFactory.DEFAULT_COMPACTION_THRESHOLD, diskStore.getCompactionThreshold()); assertEquals(9999, diskStore.getTimeInterval()); assertEquals(1, diskStore.getMaxOplogSize()); @@ -152,15 +166,12 @@ public class DiskStoreAndEvictionRegionParsingTest { assertTrue(applicationContext.containsBean("partition-data")); PeerRegionFactoryBean fb = applicationContext.getBean("&partition-data", PeerRegionFactoryBean.class); assertTrue(fb instanceof PartitionedRegionFactoryBean); - assertTrue((Boolean) TestUtils.readField("persistent", fb)); + assertTrue(TestUtils.readField("persistent", fb)); RegionAttributes attrs = TestUtils.readField("attributes", fb); EvictionAttributes evicAttr = attrs.getEvictionAttributes(); assertEquals(EvictionAction.LOCAL_DESTROY, evicAttr.getAction()); assertEquals(EvictionAlgorithm.LRU_MEMORY, evicAttr.getAlgorithm()); - // for some reason GemFire resets this to 56 on my machine (not sure - // why) - // assertEquals(10, evicAttr.getMaximum()); ObjectSizer sizer = evicAttr.getObjectSizer(); assertEquals(SimpleObjectSizer.class, sizer.getClass()); } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreNamespaceIntegrationTests.java new file mode 100644 index 00000000..c3db9122 --- /dev/null +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreNamespaceIntegrationTests.java @@ -0,0 +1,80 @@ +/* + * Copyright 2010-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.gemfire.config.xml; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.util.Properties; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.geode.cache.DiskStore; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Integration Tests with test cases testing the contract and functionality of using SDG's XML namespace configuration + * metadata to configure {@link DiskStore DiskStores}. + * + * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.DiskStore + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner + * @since 2.0.0 + */ +@RunWith(SpringRunner.class) +@ContextConfiguration(locations = "diskstore-ns.xml", initializers = GemFireMockObjectsApplicationContextInitializer.class) +@SuppressWarnings("unused") +public class DiskStoreNamespaceIntegrationTests extends IntegrationTestsSupport { + + @Autowired + @Qualifier("fullyConfiguredDiskStore") + private DiskStore diskStore; + + @Autowired + @Qualifier("props") + private Properties props; + + @Test + public void testDiskStoreConfiguration() { + + assertThat(diskStore).as("The 'fullyConfiguredDiskStore' was not properly configured and initialized").isNotNull(); + assertThat(diskStore.getName()).isEqualTo("fullyConfiguredDiskStore"); + assertThat(diskStore.getAllowForceCompaction()).isEqualTo(Boolean.valueOf(props.getProperty("allowForceCompaction"))); + assertThat(diskStore.getAutoCompact()).isEqualTo(Boolean.valueOf(props.getProperty("autoCompact"))); + assertThat(Long.valueOf(diskStore.getCompactionThreshold())).isEqualTo(Long.valueOf(props.getProperty("compactionThreshold"))); + assertThat(Double.valueOf(diskStore.getDiskUsageCriticalPercentage())).isEqualTo(Double.valueOf(props.getProperty("diskUsageCriticalPercentage"))); + assertThat(Double.valueOf(diskStore.getDiskUsageWarningPercentage())).isEqualTo(Double.valueOf(props.getProperty("diskUsageWarningPercentage"))); + assertThat(Long.valueOf(diskStore.getMaxOplogSize())).isEqualTo(Long.valueOf(props.getProperty("maxOplogSize"))); + assertThat(Long.valueOf(diskStore.getQueueSize())).isEqualTo(Long.valueOf(props.getProperty("queueSize"))); + assertThat(Long.valueOf(diskStore.getTimeInterval())).isEqualTo(Long.valueOf(props.getProperty("timeInterval"))); + assertThat(Long.valueOf(diskStore.getWriteBufferSize())).isEqualTo(Long.valueOf(props.getProperty("writeBufferSize"))); + assertThat(diskStore.getDiskDirs()).isNotNull(); + assertThat(diskStore.getDiskDirs().length).isEqualTo(1); + assertThat(diskStore.getDiskDirs()[0]).isEqualTo(new File(props.getProperty("location"))); + assertThat(Long.valueOf(diskStore.getDiskDirSizes()[0])).isEqualTo(Long.valueOf(props.getProperty("maxSize"))); + } +} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreNamespaceTest.java deleted file mode 100644 index ddad5a9a..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreNamespaceTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.config.xml; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.File; -import java.util.Properties; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.apache.geode.cache.DiskStore; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * The DiskStoreNamespaceTest class is a test suite of test cases testing the contract and functionality of using - * Spring Data GemFire's XML namespace to configure GemFire Disk Stores. - * - * @author John Blum - * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner - * @since 2.0.0 - */ -@RunWith(SpringRunner.class) -@ContextConfiguration(locations = "diskstore-ns.xml", initializers = GemfireTestApplicationContextInitializer.class) -@SuppressWarnings("unused") -public class DiskStoreNamespaceTest { - - @Autowired - @Qualifier("fullyConfiguredDiskStore") - private DiskStore diskStore; - - @Autowired - @Qualifier("props") - private Properties props; - - @Test - public void testDiskStoreConfiguration() { - - assertNotNull("The 'fullyConfiguredDiskStore' was not properly configured and initialized", diskStore); - assertEquals("fullyConfiguredDiskStore", diskStore.getName()); - assertEquals(Boolean.valueOf(props.getProperty("allowForceCompaction")), diskStore.getAllowForceCompaction()); - assertEquals(Boolean.valueOf(props.getProperty("autoCompact")), diskStore.getAutoCompact()); - assertEquals(Long.valueOf(props.getProperty("compactionThreshold")), - Long.valueOf(diskStore.getCompactionThreshold())); - assertEquals(Double.valueOf(props.getProperty("diskUsageCriticalPercentage")), - Double.valueOf(diskStore.getDiskUsageCriticalPercentage())); - assertEquals(Double.valueOf(props.getProperty("diskUsageWarningPercentage")), - Double.valueOf(diskStore.getDiskUsageWarningPercentage())); - assertEquals(Long.valueOf(props.getProperty("maxOplogSize")), Long.valueOf(diskStore.getMaxOplogSize())); - assertEquals(Long.valueOf(props.getProperty("queueSize")), Long.valueOf(diskStore.getQueueSize())); - assertEquals(Long.valueOf(props.getProperty("timeInterval")), Long.valueOf(diskStore.getTimeInterval())); - assertEquals(Long.valueOf(props.getProperty("writeBufferSize")), Long.valueOf(diskStore.getWriteBufferSize())); - assertNotNull(diskStore.getDiskDirs()); - assertEquals(1, diskStore.getDiskDirs().length); - assertEquals(new File(props.getProperty("location")), diskStore.getDiskDirs()[0]); - assertEquals(Long.valueOf(props.getProperty("maxSize")), Long.valueOf(diskStore.getDiskDirSizes()[0])); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/FunctionServiceNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/FunctionServiceNamespaceIntegrationTests.java similarity index 51% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/FunctionServiceNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/FunctionServiceNamespaceIntegrationTests.java index fdd4a70c..8b49f65c 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/FunctionServiceNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/FunctionServiceNamespaceIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; @@ -22,57 +21,63 @@ import static org.junit.Assert.assertNotNull; import org.junit.Test; import org.junit.runner.RunWith; -import org.apache.geode.cache.execute.FunctionAdapter; +import org.apache.geode.cache.execute.Function; import org.apache.geode.cache.execute.FunctionContext; import org.apache.geode.cache.execute.FunctionService; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** + * Integration Tests for SDG Function XML namespace configuration metadata + * * @author Costin Leau * @author David Turanski * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.execute.Function + * @see org.apache.geode.cache.execute.FunctionContext + * @see org.apache.geode.cache.execute.FunctionService + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations="function-service-ns.xml", initializers=GemfireTestApplicationContextInitializer.class) +@RunWith(SpringRunner.class) +@ContextConfiguration(locations="function-service-ns.xml", + initializers= GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class FunctionServiceNamespaceTest { +public class FunctionServiceNamespaceIntegrationTests extends IntegrationTestsSupport { @Test - public void testFunctionsRegistered() throws Exception { + public void testFunctionsRegistered() { + assertEquals(2, FunctionService.getRegisteredFunctions().size()); assertNotNull(FunctionService.getFunction("function1")); assertNotNull(FunctionService.getFunction("function2")); } - @SuppressWarnings("serial") - public static class Function1 extends FunctionAdapter { + public static class Function1 implements Function { @Override - public void execute(FunctionContext arg0) { - } + public void execute(FunctionContext functionContext) { } @Override public String getId() { return "function1"; } - } - @SuppressWarnings("serial") - public static class Function2 extends FunctionAdapter { + public static class Function2 implements Function { @Override - public void execute(FunctionContext arg0) { - } + public void execute(FunctionContext functionContext) { } @Override public String getId() { return "function2"; } - } - } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverAutoStartNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverAutoStartNamespaceIntegrationTests.java similarity index 50% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverAutoStartNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverAutoStartNamespaceIntegrationTests.java index 38a26dc9..08265e32 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverAutoStartNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverAutoStartNamespaceIntegrationTests.java @@ -15,9 +15,7 @@ */ package org.springframework.data.gemfire.config.xml; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import javax.annotation.Resource; @@ -26,7 +24,8 @@ import org.junit.runner.RunWith; import org.apache.geode.cache.wan.GatewayReceiver; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; @@ -34,27 +33,28 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.StringUtils; /** - * The GatewayReceiverAutoStartNamespaceTest class is a test suite of test cases testing the contract - * and functionality of Gateway Receiver configuration in Spring Data GemFire using the XML namespace (XSD). - * This test class tests the auto start configuration of the GatewayReceiver Gemfire Component in SDG. + * Integration Tests with test cases testing the contract and functionality of {@link GatewayReceiver} configuration + * in SDG using the XML namespace (XSD) configuration metadata. + * + * This test class tests the auto start configuration of the {@link GatewayReceiver} component in SDG. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer + * @see org.apache.geode.cache.wan.GatewayReceiver + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer * @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean * @see org.springframework.test.context.ActiveProfiles * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner - * @see org.apache.geode.cache.wan.GatewayReceiver + * @see org.springframework.test.context.junit4.SpringRunner * @since 1.5.0 */ @RunWith(SpringRunner.class) -@ContextConfiguration(value = "GatewayReceiverNamespaceTest-context.xml", - initializers = GemfireTestApplicationContextInitializer.class) +@ContextConfiguration(locations = "GatewayReceiverNamespaceTest-context.xml", + initializers = GemFireMockObjectsApplicationContextInitializer.class) @ActiveProfiles("autoStart") @SuppressWarnings("unused") -public class GatewayReceiverAutoStartNamespaceTest { +public class GatewayReceiverAutoStartNamespaceIntegrationTests extends IntegrationTestsSupport { @Resource(name = "&Auto") private GatewayReceiverFactoryBean autoGatewayReceiverFactory; @@ -62,20 +62,21 @@ public class GatewayReceiverAutoStartNamespaceTest { @Test public void testAuto() throws Exception { - assertNotNull("The 'Auto' GatewayReceiverFactoryBean was not properly configured and initialized!", - this.autoGatewayReceiverFactory); + assertThat(this.autoGatewayReceiverFactory) + .describedAs("The 'Auto' GatewayReceiverFactoryBean was not properly configured and initialized!") + .isNotNull(); GatewayReceiver autoGatewayReceiver = this.autoGatewayReceiverFactory.getObject(); try { - assertNotNull(autoGatewayReceiver); - assertTrue(StringUtils.isEmpty(autoGatewayReceiver.getBindAddress())); - assertEquals("neo", autoGatewayReceiver.getHost()); - assertEquals(15500, autoGatewayReceiver.getStartPort()); - assertEquals(25500, autoGatewayReceiver.getEndPort()); - assertEquals(10000, autoGatewayReceiver.getMaximumTimeBetweenPings()); - assertTrue(autoGatewayReceiver.isRunning()); - assertEquals(16384, autoGatewayReceiver.getSocketBufferSize()); + assertThat(autoGatewayReceiver).isNotNull(); + assertThat(StringUtils.hasText(autoGatewayReceiver.getBindAddress())).isFalse(); + assertThat(autoGatewayReceiver.getHost()).isEqualTo("neo"); + assertThat(autoGatewayReceiver.getStartPort()).isEqualTo(15500); + assertThat(autoGatewayReceiver.getEndPort()).isEqualTo(25500); + assertThat(autoGatewayReceiver.getMaximumTimeBetweenPings()).isEqualTo(10000); + assertThat(autoGatewayReceiver.isRunning()).isTrue(); + assertThat(autoGatewayReceiver.getSocketBufferSize()).isEqualTo(16384); } finally { autoGatewayReceiver.stop(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverDefaultStartNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverDefaultStartNamespaceIntegrationTests.java similarity index 52% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverDefaultStartNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverDefaultStartNamespaceIntegrationTests.java index 7e1486d1..032761cc 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverDefaultStartNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverDefaultStartNamespaceIntegrationTests.java @@ -15,9 +15,7 @@ */ package org.springframework.data.gemfire.config.xml; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import javax.annotation.Resource; @@ -26,7 +24,8 @@ import org.junit.runner.RunWith; import org.apache.geode.cache.wan.GatewayReceiver; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; @@ -34,27 +33,28 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.StringUtils; /** - * The GatewayReceiverDefaultStartNamespaceTest class is a test suite of test cases testing the contract - * and functionality of Gateway Receiver configuration in Spring Data GemFire using the XML namespace (XSD). - * This test class tests the default start configuration of the GatewayReceiver Gemfire Component in SDG. + * Integration Tests with test cases testing the contract and functionality of {@link GatewayReceiver} configuration + * in SDG using the XML namespace (XSD) configuration metadata. + * + * This test class tests the default start configuration of the {@link GatewayReceiver} component in SDG. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer + * @see org.apache.geode.cache.wan.GatewayReceiver + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer * @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean * @see org.springframework.test.context.ActiveProfiles * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner - * @see org.apache.geode.cache.wan.GatewayReceiver + * @see org.springframework.test.context.junit4.SpringRunner * @since 1.5.0 */ -@RunWith(SpringRunner.class) -@ContextConfiguration(value = "GatewayReceiverNamespaceTest-context.xml", - initializers = GemfireTestApplicationContextInitializer.class) @ActiveProfiles("defaultStart") +@RunWith(SpringRunner.class) +@ContextConfiguration(locations = "GatewayReceiverNamespaceTest-context.xml", + initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class GatewayReceiverDefaultStartNamespaceTest { +public class GatewayReceiverDefaultStartNamespaceIntegrationTests extends IntegrationTestsSupport { @Resource(name = "&Default") private GatewayReceiverFactoryBean defaultGatewayReceiverFactory; @@ -62,20 +62,21 @@ public class GatewayReceiverDefaultStartNamespaceTest { @Test public void testDefault() throws Exception { - assertNotNull("The 'Default' GatewayReceiverFactoryBean was not properly configured and initialized!", - this.defaultGatewayReceiverFactory); + assertThat(this.defaultGatewayReceiverFactory) + .describedAs("The 'Default' GatewayReceiverFactoryBean was not properly configured and initialized!") + .isNotNull(); GatewayReceiver defaultGatewayReceiver = this.defaultGatewayReceiverFactory.getObject(); try { - assertNotNull(defaultGatewayReceiver); - assertTrue(StringUtils.isEmpty(defaultGatewayReceiver.getBindAddress())); - assertEquals("skullbox", defaultGatewayReceiver.getHost()); - assertEquals(12345, defaultGatewayReceiver.getStartPort()); - assertEquals(54321, defaultGatewayReceiver.getEndPort()); - assertEquals(5000, defaultGatewayReceiver.getMaximumTimeBetweenPings()); - assertTrue(defaultGatewayReceiver.isRunning()); - assertEquals(32768, defaultGatewayReceiver.getSocketBufferSize()); + assertThat(defaultGatewayReceiver).isNotNull(); + assertThat(StringUtils.hasText(defaultGatewayReceiver.getBindAddress())).isFalse(); + assertThat(defaultGatewayReceiver.getHost()).isEqualTo("skullbox"); + assertThat(defaultGatewayReceiver.getStartPort()).isEqualTo(12345); + assertThat(defaultGatewayReceiver.getEndPort()).isEqualTo(54321); + assertThat(defaultGatewayReceiver.getMaximumTimeBetweenPings()).isEqualTo(5000); + assertThat(defaultGatewayReceiver.isRunning()).isTrue(); + assertThat(defaultGatewayReceiver.getSocketBufferSize()).isEqualTo(32768); } finally { defaultGatewayReceiver.stop(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverManualStartNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverManualStartNamespaceIntegrationTests.java new file mode 100644 index 00000000..135998c9 --- /dev/null +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverManualStartNamespaceIntegrationTests.java @@ -0,0 +1,78 @@ +/* + * Copyright 2010-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.gemfire.config.xml; + +import static org.assertj.core.api.Assertions.assertThat; + +import javax.annotation.Resource; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.geode.cache.wan.GatewayReceiver; + +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; +import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Integration Tests with test cases testing the contract and functionality of {@link GatewayReceiver} configuration + * in SDG using XML namespace (XSD) configuration metadata. + * + * This test class tests the manual start configuration of the {@link GatewayReceiver} Component in SDG. + * + * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.wan.GatewayReceiver + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean + * @see org.springframework.test.context.ActiveProfiles + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner + * @since 1.5.0 + */ +@RunWith(SpringRunner.class) +@ContextConfiguration(locations = "GatewayReceiverNamespaceTest-context.xml", + initializers = GemFireMockObjectsApplicationContextInitializer.class) +@ActiveProfiles("manualStart") +@SuppressWarnings("unused") +public class GatewayReceiverManualStartNamespaceIntegrationTests extends IntegrationTestsSupport { + + @Resource(name = "&Manual") + private GatewayReceiverFactoryBean manualGatewayReceiverFactory; + + @Test + public void testManual() throws Exception { + + assertThat(this.manualGatewayReceiverFactory) + .as("The 'Manual' GatewayReceiverFactoryBean was not properly configured and initialized!").isNotNull(); + + GatewayReceiver manualGatewayReceiver = this.manualGatewayReceiverFactory.getObject(); + + assertThat(manualGatewayReceiver).isNotNull(); + assertThat(manualGatewayReceiver.getBindAddress()).isEqualTo("192.168.0.1"); + assertThat(manualGatewayReceiver.getHost()).isEqualTo("theOne"); + assertThat(manualGatewayReceiver.getStartPort()).isEqualTo(100); + assertThat(manualGatewayReceiver.getEndPort()).isEqualTo(900); + assertThat(manualGatewayReceiver.getMaximumTimeBetweenPings()).isEqualTo(1000); + assertThat(manualGatewayReceiver.isRunning()).isFalse(); + assertThat(manualGatewayReceiver.getSocketBufferSize()).isEqualTo(8192); + } +} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverManualStartNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverManualStartNamespaceTest.java deleted file mode 100644 index 784d7f99..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverManualStartNamespaceTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.gemfire.config.xml; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; - -import javax.annotation.Resource; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.apache.geode.cache.wan.GatewayReceiver; - -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; -import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * The GatewayReceiverManualStartNamespaceTest class is a test suite of test cases testing the contract - * and functionality of Gateway Receiver configuration in Spring Data GemFire using the XML namespace (XSD). - * This test class tests the manual start configuration of the GatewayReceiver Gemfire Component in SDG. - * - * @author John Blum - * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer - * @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean - * @see org.springframework.test.context.ActiveProfiles - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner - * @see org.apache.geode.cache.wan.GatewayReceiver - * @since 1.5.0 - */ -@RunWith(SpringRunner.class) -@ContextConfiguration(value = "GatewayReceiverNamespaceTest-context.xml", - initializers = GemfireTestApplicationContextInitializer.class) -@ActiveProfiles("manualStart") -@SuppressWarnings("unused") -public class GatewayReceiverManualStartNamespaceTest { - - @Resource(name = "&Manual") - private GatewayReceiverFactoryBean manualGatewayReceiverFactory; - - @Test - public void testManual() throws Exception { - - assertNotNull("The 'Manual' GatewayReceiverFactoryBean was not properly configured and initialized!", - this.manualGatewayReceiverFactory); - - GatewayReceiver manualGatewayReceiver = this.manualGatewayReceiverFactory.getObject(); - - assertNotNull(manualGatewayReceiver); - assertEquals("192.168.0.1", manualGatewayReceiver.getBindAddress()); - assertEquals("theOne", manualGatewayReceiver.getHost()); - assertEquals(100, manualGatewayReceiver.getStartPort()); - assertEquals(900, manualGatewayReceiver.getEndPort()); - assertEquals(1000, manualGatewayReceiver.getMaximumTimeBetweenPings()); - assertFalse(manualGatewayReceiver.isRunning()); - assertEquals(8192, manualGatewayReceiver.getSocketBufferSize()); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV7GatewayNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV7GatewayNamespaceTest.java index f7226a09..a574c3a3 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV7GatewayNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV7GatewayNamespaceTest.java @@ -40,7 +40,7 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.data.gemfire.PeerRegionFactoryBean; import org.springframework.data.gemfire.RecreatingSpringApplicationContextTest; import org.springframework.data.gemfire.TestUtils; -import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor; +import org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor; import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean; /** @@ -67,7 +67,7 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo @Override protected T configureContext(T context) { - context.getBeanFactory().addBeanPostProcessor(new GemfireTestBeanPostProcessor()); + context.getBeanFactory().addBeanPostProcessor(new GemFireMockObjectsBeanPostProcessor()); return context; } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceIntegrationTests.java new file mode 100644 index 00000000..110882cc --- /dev/null +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceIntegrationTests.java @@ -0,0 +1,123 @@ +/* + * Copyright 2010-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.gemfire.config.xml; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.geode.cache.EntryEvent; +import org.apache.geode.cache.wan.GatewayEventSubstitutionFilter; +import org.apache.geode.cache.wan.GatewayReceiver; +import org.apache.geode.cache.wan.GatewaySender; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Integration Tests with test cases testing the contract and functionality of GemFire 8 {@link GatewaySender} + * and {@link GatewayReceiver} support. + * + * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.wan.GatewaySender + * @see org.apache.geode.cache.wan.GatewayEventSubstitutionFilter + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.data.gemfire.wan.GatewaySenderFactoryBean + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner + * @since 2.0.0 + */ +@RunWith(SpringRunner.class) +@ContextConfiguration(locations = "gateway-v8-ns.xml", + initializers = GemFireMockObjectsApplicationContextInitializer.class) +@SuppressWarnings("unused") +public class GemfireV8GatewayNamespaceIntegrationTests extends IntegrationTestsSupport { + + @Autowired + @Qualifier("gateway-sender-with-event-substitution-filter") + private GatewaySender gatewaySenderWithEventSubstitutionFilter; + + @Autowired + @Qualifier("gateway-sender-with-event-substitution-filter-ref") + private GatewaySender gatewaySenderWithEventSubstitutionFilterRef; + + @Test + public void testGatewaySenderEventSubstitutionFilter() { + + assertThat(gatewaySenderWithEventSubstitutionFilter) + .describedAs("The 'gatewaySenderEventSubtitutionFilter' bean was not properly configured and initialized!") + .isNotNull(); + + assertThat(gatewaySenderWithEventSubstitutionFilter.getId()).isEqualTo("gateway-sender-with-event-substitution-filter"); + assertThat(gatewaySenderWithEventSubstitutionFilter.getRemoteDSId()).isEqualTo(3); + assertThat(gatewaySenderWithEventSubstitutionFilter.getDispatcherThreads()).isEqualTo(10); + assertThat(gatewaySenderWithEventSubstitutionFilter.isParallel()).isTrue(); + assertThat(gatewaySenderWithEventSubstitutionFilter.isRunning()).isFalse(); + assertThat(gatewaySenderWithEventSubstitutionFilter.getGatewayEventSubstitutionFilter()).isNotNull(); + assertThat(gatewaySenderWithEventSubstitutionFilter.getGatewayEventSubstitutionFilter().toString()) + .isEqualTo("inner"); + } + + @Test + public void testGatewaySenderEventSubstitutionFilterRef() { + + assertThat(gatewaySenderWithEventSubstitutionFilterRef) + .describedAs("The 'gatewaySenderEventSubtitutionFilter' bean was not properly configured and initialized!") + .isNotNull(); + + assertThat(gatewaySenderWithEventSubstitutionFilterRef.getId()).isEqualTo("gateway-sender-with-event-substitution-filter-ref"); + assertThat(gatewaySenderWithEventSubstitutionFilterRef.getRemoteDSId()).isEqualTo(33); + assertThat(gatewaySenderWithEventSubstitutionFilterRef.getDispatcherThreads()).isEqualTo(1); + assertThat(gatewaySenderWithEventSubstitutionFilterRef.isParallel()).isFalse(); + assertThat(gatewaySenderWithEventSubstitutionFilterRef.isRunning()).isFalse(); + assertThat(gatewaySenderWithEventSubstitutionFilterRef.getGatewayEventSubstitutionFilter()).isNotNull(); + assertThat(gatewaySenderWithEventSubstitutionFilterRef.getGatewayEventSubstitutionFilter().toString()) + .isEqualTo("ref"); + } + + public static class TestGatewayEventSubstitutionFilter implements GatewayEventSubstitutionFilter { + + private String name; + + public final void setName(String name) { + this.name = name; + } + + protected String getName() { + return this.name; + } + + @Override + public Object getSubstituteValue(EntryEvent objectObjectEntryEvent) { + throw new UnsupportedOperationException("Not Implemented!"); + } + + @Override + public void close() { } + + @Override + public String toString() { + return getName(); + } + } +} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceTest.java deleted file mode 100644 index d51785d8..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.config.xml; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.apache.geode.cache.EntryEvent; -import org.apache.geode.cache.wan.GatewayEventSubstitutionFilter; -import org.apache.geode.cache.wan.GatewaySender; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * The GemfireV8GatewayNamespaceTest class is a test suite of test cases testing the contract and functionality of - * GemFire 8 Gateway Sender/Receiver support. - * - * @author John Blum - * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer - * @see org.springframework.data.gemfire.wan.GatewaySenderFactoryBean - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner - * @see org.apache.geode.cache.wan.GatewaySender - * @see org.apache.geode.cache.wan.GatewayEventSubstitutionFilter - * @since 2.0.0 - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(value = "gateway-v8-ns.xml", initializers = GemfireTestApplicationContextInitializer.class) -@SuppressWarnings("unused") -public class GemfireV8GatewayNamespaceTest { - - @Autowired - @Qualifier("gateway-sender-with-event-substitution-filter") - private GatewaySender gatewaySenderWithEventSubstitutionFilter; - - @Autowired - @Qualifier("gateway-sender-with-event-substitution-filter-ref") - private GatewaySender gatewaySenderWithEventSubstitutionFilterRef; - - @Test - public void testGatewaySenderEventSubstitutionFilter() { - assertNotNull("The 'gatewaySenderEventSubtitutionFilter' bean was not properly configured and initialized!", - gatewaySenderWithEventSubstitutionFilter); - assertEquals("gateway-sender-with-event-substitution-filter", gatewaySenderWithEventSubstitutionFilter.getId()); - assertEquals(3, gatewaySenderWithEventSubstitutionFilter.getRemoteDSId()); - assertEquals(10, gatewaySenderWithEventSubstitutionFilter.getDispatcherThreads()); - assertTrue(gatewaySenderWithEventSubstitutionFilter.isParallel()); - assertFalse(gatewaySenderWithEventSubstitutionFilter.isRunning()); - assertNotNull(gatewaySenderWithEventSubstitutionFilter.getGatewayEventSubstitutionFilter()); - assertEquals("inner", gatewaySenderWithEventSubstitutionFilter.getGatewayEventSubstitutionFilter().toString()); - } - - @Test - public void testGatewaySenderEventSubstitutionFilterRef() { - assertNotNull("The 'gatewaySenderEventSubtitutionFilter' bean was not properly configured and initialized!", - gatewaySenderWithEventSubstitutionFilterRef); - assertEquals("gateway-sender-with-event-substitution-filter-ref", gatewaySenderWithEventSubstitutionFilterRef.getId()); - assertEquals(33, gatewaySenderWithEventSubstitutionFilterRef.getRemoteDSId()); - assertEquals(1, gatewaySenderWithEventSubstitutionFilterRef.getDispatcherThreads()); - assertFalse(gatewaySenderWithEventSubstitutionFilterRef.isParallel()); - assertFalse(gatewaySenderWithEventSubstitutionFilterRef.isRunning()); - assertNotNull(gatewaySenderWithEventSubstitutionFilterRef.getGatewayEventSubstitutionFilter()); - assertEquals("ref", gatewaySenderWithEventSubstitutionFilterRef.getGatewayEventSubstitutionFilter().toString()); - } - - public static class TestGatewayEventSubstitutionFilter implements GatewayEventSubstitutionFilter { - - private String name; - - public final void setName(final String name) { - this.name = name; - } - - protected String getName() { - return name; - } - - @Override - public Object getSubstituteValue(final EntryEvent objectObjectEntryEvent) { - throw new UnsupportedOperationException("Not Implemented!"); - } - - @Override - public void close() { - } - - @Override - public String toString() { - return getName(); - } - } - -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/IndexNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/IndexNamespaceIntegrationTests.java similarity index 78% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/IndexNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/IndexNamespaceIntegrationTests.java index b0540fb2..cdae8bc6 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/IndexNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/IndexNamespaceIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static org.assertj.core.api.Assertions.assertThat; @@ -30,28 +29,31 @@ import org.apache.geode.cache.query.Index; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.IndexFactoryBean; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration tests with test cases testing the functionality of GemFire Index creation using - * the Spring Data GemFire XML namespace (XSD) and the {@link IndexParser}. + * Integration Tests with test cases testing the functionality of GemFire Index creation using + * the Spring Data for Apache Geode XML namespace (XSD) configuration metadata and the {@link IndexParser}. * * @author Costin Leau * @author David Turanski * @author John Blum + * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.IndexFactoryBean * @see org.springframework.data.gemfire.config.xml.IndexParser - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner * @since 1.1.0 */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations="index-ns.xml", initializers=GemfireTestApplicationContextInitializer.class) +@ContextConfiguration(locations = "index-ns.xml", initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings({ "deprecation", "unused" }) -public class IndexNamespaceTest { +public class IndexNamespaceIntegrationTests extends IntegrationTestsSupport { private static final String TEST_REGION_NAME = "IndexedRegion"; @@ -65,7 +67,8 @@ public class IndexNamespaceTest { private Index complex; @Test - public void basicIndexIsCorrect() throws Exception { + public void basicIndexIsCorrect() { + assertEquals("basic", basic.getName()); assertEquals("status", basic.getIndexedExpression()); assertEquals(Region.SEPARATOR + TEST_REGION_NAME, basic.getFromClause()); @@ -83,7 +86,8 @@ public class IndexNamespaceTest { } @Test - public void complexIndexIsCorrect() throws Exception { + public void complexIndexIsCorrect() { + assertEquals("complex-index", complex.getName()); assertEquals("tsi.name", complex.getIndexedExpression()); assertEquals(Region.SEPARATOR + TEST_REGION_NAME + " tsi", complex.getFromClause()); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceIntegrationTests.java similarity index 79% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceIntegrationTests.java index be0d17bd..8d47e88e 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static org.assertj.core.api.Assertions.assertThat; @@ -25,23 +24,25 @@ import org.apache.geode.cache.Region; import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.GenericXmlApplicationContext; -import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor; import org.xml.sax.SAXParseException; /** - * Unit test testing the proper syntax for declaring "custom" expiration attributes on a {@link Region}. + * Unit Tests testing the proper syntax for declaring "custom" expiration attributes on a {@link Region}. * * @author John Blum * @see org.junit.Test - * @see org.springframework.context.ConfigurableApplicationContext - * @see org.springframework.context.support.GenericXmlApplicationContext - * @see org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor * @see org.apache.geode.cache.ExpirationAttributes * @see org.apache.geode.cache.Region + * @see org.springframework.context.ConfigurableApplicationContext + * @see org.springframework.context.support.GenericXmlApplicationContext + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor * @since 1.5.0 */ -public class InvalidRegionExpirationAttributesNamespaceTest { +public class InvalidRegionExpirationAttributesNamespaceIntegrationTests extends IntegrationTestsSupport { private String contextConfigLocation() { return getClass().getName().replaceAll("\\.", "/").concat("-context.xml"); @@ -52,20 +53,23 @@ public class InvalidRegionExpirationAttributesNamespaceTest { } private ConfigurableApplicationContext configureContext(ConfigurableApplicationContext applicationContext) { - applicationContext.getBeanFactory().addBeanPostProcessor(new GemfireTestBeanPostProcessor()); + applicationContext.getBeanFactory().addBeanPostProcessor(new GemFireMockObjectsBeanPostProcessor()); return applicationContext; } private ConfigurableApplicationContext initializeApplicationContext(ConfigurableApplicationContext applicationContext) { + assertThat(applicationContext).isInstanceOf(GenericXmlApplicationContext.class); ((GenericXmlApplicationContext) applicationContext).load(contextConfigLocation()); applicationContext.registerShutdownHook(); applicationContext.refresh(); + return applicationContext; } @Test(expected = XmlBeanDefinitionStoreException.class) public void testInvalidXmlSyntax() { + try { initializeApplicationContext(configureContext(createApplicationContext())); } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionNamespaceIntegrationTests.java similarity index 91% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionNamespaceIntegrationTests.java index 3a3b81ff..2ece7c01 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionNamespaceIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; @@ -40,24 +39,31 @@ import org.springframework.data.gemfire.PeerRegionFactoryBean; import org.springframework.data.gemfire.ResolvableRegionFactoryBean; import org.springframework.data.gemfire.SimpleCacheListener; import org.springframework.data.gemfire.TestUtils; -import org.springframework.data.gemfire.test.mock.context.GemFireMockObjectsApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.ObjectUtils; /** - * Unit tests for the Local Region Namespace. + * Integration Tests for the Local Region XML namespace configuration metadata. * * @author Costin Leau * @author David Turanski * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.LocalRegionFactoryBean * @see org.springframework.data.gemfire.config.xml.LocalRegionParser + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) @ContextConfiguration(locations="local-ns.xml", initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class LocalRegionNamespaceTest { +public class LocalRegionNamespaceIntegrationTests extends IntegrationTestsSupport { @Autowired private ApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionWithEvictionPolicyActionNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionWithEvictionPolicyActionNamespaceIntegrationTests.java similarity index 78% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionWithEvictionPolicyActionNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionWithEvictionPolicyActionNamespaceIntegrationTests.java index 17986652..24d7a6f3 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionWithEvictionPolicyActionNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionWithEvictionPolicyActionNamespaceIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; @@ -29,38 +28,42 @@ import org.apache.geode.cache.EvictionAction; import org.apache.geode.cache.Region; import org.apache.geode.cache.Scope; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** - * The LocalRegionWithEvictionPolicyActionNamespaceTest class is a test suite of tests cases testing the Eviction Policy - * Actions on Local Regions defined in a Spring context configuration file. + * Integration Tests testing the Eviction Policy Actions on Local {@link Region Regions} defined in + * SDG XML namespace configuration metadata. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith + * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner * @since 1.5.0.M1 * @link https://jira.spring.io/browse/SGF-295 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class) +@RunWith(SpringRunner.class) +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class LocalRegionWithEvictionPolicyActionNamespaceTest { +public class LocalRegionWithEvictionPolicyActionNamespaceIntegrationTests extends IntegrationTestsSupport { @Resource(name = "LocalDestroy") - private Region localDestroyRegion; + private Region localDestroyRegion; @Resource(name = "None") - private Region noneRegion; + private Region noneRegion; @Resource(name = "Overflow") - private Region overflowRegion; + private Region overflowRegion; @Test public void testLocalRegionConfigurationWithEvictionPolicyActionSetToLocalDestroy() { + assertNotNull("The 'LocalDestroy' Region was not properly configured and initialized!", localDestroyRegion); assertEquals("LocalDestroy", localDestroyRegion.getName()); assertEquals("/LocalDestroy", localDestroyRegion.getFullPath()); @@ -73,6 +76,7 @@ public class LocalRegionWithEvictionPolicyActionNamespaceTest { @Test public void testLocalRegionConfigurationWithEvictionPolicyActionSetToNone() { + assertNotNull("The 'None' Region was not properly configured and initialized!", noneRegion); assertEquals("None", noneRegion.getName()); assertEquals("/None", noneRegion.getFullPath()); @@ -85,6 +89,7 @@ public class LocalRegionWithEvictionPolicyActionNamespaceTest { @Test public void testLocalRegionConfigurationWithEvictionPolicyActionSetToOverflowToDisk() { + assertNotNull("The 'Overflow' Region was not properly configured and initialized!", overflowRegion); assertEquals("Overflow", overflowRegion.getName()); assertEquals("/Overflow", overflowRegion.getFullPath()); @@ -94,5 +99,4 @@ public class LocalRegionWithEvictionPolicyActionNamespaceTest { assertNotNull(overflowRegion.getAttributes().getEvictionAttributes()); assertEquals(EvictionAction.OVERFLOW_TO_DISK, overflowRegion.getAttributes().getEvictionAttributes().getAction()); } - } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesIntegrationTests.java new file mode 100644 index 00000000..ad2419ca --- /dev/null +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesIntegrationTests.java @@ -0,0 +1,70 @@ +/* + * Copyright 2010-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.gemfire.config.xml; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.geode.cache.LossAction; +import org.apache.geode.cache.MembershipAttributes; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.ResumptionAction; +import org.apache.geode.distributed.Role; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author David Turanski + * @author John Blum + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = "/org/springframework/data/gemfire/config/xml/membership-attributes-ns.xml", + initializers = GemFireMockObjectsApplicationContextInitializer.class) +@SuppressWarnings("unused") +public class MembershipAttributesIntegrationTests extends IntegrationTestsSupport { + + @Autowired + private ApplicationContext applicationContext; + + @Test + public void membershipAttributesConfigurationIsCorrect() { + + Region simple = applicationContext.getBean("simple", Region.class); + + MembershipAttributes membershipAttributes = simple.getAttributes().getMembershipAttributes(); + + assertThat(membershipAttributes.hasRequiredRoles()).isFalse(); + + Region secure = applicationContext.getBean("secure", Region.class); + + membershipAttributes = secure.getAttributes().getMembershipAttributes(); + + assertThat(membershipAttributes.hasRequiredRoles()).isTrue(); + assertThat(membershipAttributes.getResumptionAction()).isEqualTo(ResumptionAction.REINITIALIZE); + assertThat(membershipAttributes.getLossAction()).isEqualTo(LossAction.LIMITED_ACCESS); + + for (Role role : membershipAttributes.getRequiredRoles()) { + assertThat("ROLE1".equals(role.getName()) || "ROLE2".equals(role.getName())).isTrue(); + } + } +} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesTest.java deleted file mode 100644 index 1c7ad9d0..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.gemfire.config.xml; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.apache.geode.cache.LossAction; -import org.apache.geode.cache.MembershipAttributes; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.ResumptionAction; -import org.apache.geode.distributed.Role; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * @author David Turanski - * - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations= "/org/springframework/data/gemfire/config/xml/membership-attributes-ns.xml", - initializers=GemfireTestApplicationContextInitializer.class) -public class MembershipAttributesTest { - - @Autowired ApplicationContext ctx; - - @Test - public void testMembershipAttributes() { - Region simple = ctx.getBean("simple", Region.class); - MembershipAttributes ma = simple.getAttributes().getMembershipAttributes(); - assertFalse(ma.hasRequiredRoles()); - - Region secure = ctx.getBean("secure", Region.class); - ma = secure.getAttributes().getMembershipAttributes(); - assertTrue(ma.hasRequiredRoles()); - assertEquals(ResumptionAction.REINITIALIZE, ma.getResumptionAction()); - assertEquals(LossAction.LIMITED_ACCESS, ma.getLossAction()); - for (Role role : ma.getRequiredRoles()) { - assertTrue("ROLE1".equals(role.getName()) || "ROLE2".equals(role.getName())); - } - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PartitionedRegionNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PartitionedRegionNamespaceIntegrationTests.java similarity index 91% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PartitionedRegionNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PartitionedRegionNamespaceIntegrationTests.java index 723b36ea..a4a13acf 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PartitionedRegionNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PartitionedRegionNamespaceIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static org.assertj.core.api.Assertions.assertThat; @@ -47,31 +46,38 @@ import org.springframework.data.gemfire.PeerRegionFactoryBean; import org.springframework.data.gemfire.SimpleCacheListener; import org.springframework.data.gemfire.SimplePartitionResolver; import org.springframework.data.gemfire.TestUtils; -import org.springframework.data.gemfire.test.mock.context.GemFireMockObjectsApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.ObjectUtils; /** - * Unit tests for the Partitioned Region Namespace. + * Integration Tests for the Partitioned Region XML namespace configuration metadata. * * @author Costin Leau * @author David Turanski * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.PartitionedRegionFactoryBean * @see org.springframework.data.gemfire.config.xml.PartitionedRegionParser + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) @ContextConfiguration(locations = "partitioned-ns.xml", initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class PartitionedRegionNamespaceTest { +public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTestsSupport { @Autowired private ApplicationContext applicationContext; @Test - public void testSimplePartitionRegion() throws Exception { + public void testSimplePartitionRegion() { assertTrue(applicationContext.containsBean("simple")); @@ -205,7 +211,7 @@ public class PartitionedRegionNamespaceTest { assertNotNull(listeners.getAttributes()); assertEquals(DataPolicy.PARTITION, listeners.getAttributes().getDataPolicy()); - PartitionAttributes listenersPartitionAttributes = listeners.getAttributes().getPartitionAttributes(); + PartitionAttributes listenersPartitionAttributes = listeners.getAttributes().getPartitionAttributes(); assertNotNull(listenersPartitionAttributes); assertNotNull(listenersPartitionAttributes.getPartitionListeners()); @@ -232,7 +238,7 @@ public class PartitionedRegionNamespaceTest { assertNotNull(listeners.getAttributes()); assertEquals(DataPolicy.PARTITION, listeners.getAttributes().getDataPolicy()); - PartitionAttributes listenersPartitionAttributes = listeners.getAttributes().getPartitionAttributes(); + PartitionAttributes listenersPartitionAttributes = listeners.getAttributes().getPartitionAttributes(); assertNotNull(listenersPartitionAttributes); assertNotNull(listenersPartitionAttributes.getPartitionListeners()); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PoolNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PoolNamespaceIntegrationTests.java similarity index 91% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PoolNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PoolNamespaceIntegrationTests.java index bcc5582d..fa8ccb6b 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PoolNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PoolNamespaceIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static org.assertj.core.api.Assertions.assertThat; @@ -32,26 +31,30 @@ import org.springframework.data.gemfire.client.PoolAdapter; import org.springframework.data.gemfire.client.PoolFactoryBean; import org.springframework.data.gemfire.support.ConnectionEndpoint; import org.springframework.data.gemfire.support.ConnectionEndpointList; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration tests for {@link PoolParser} and {@link PoolFactoryBean}. + * Integration Tests for {@link PoolParser} and {@link PoolFactoryBean}. * * @author Costin Leau * @author John Blum * @see org.junit.Test + * @see org.apache.geode.cache.client.Pool * @see org.springframework.data.gemfire.client.PoolAdapter * @see org.springframework.data.gemfire.client.PoolFactoryBean * @see org.springframework.data.gemfire.config.xml.PoolParser - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer - * @see org.apache.geode.cache.client.Pool + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "pool-ns.xml", initializers = GemfireTestApplicationContextInitializer.class) +@ContextConfiguration(locations = "pool-ns.xml", initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class PoolNamespaceTest { +public class PoolNamespaceIntegrationTests extends IntegrationTestsSupport { @Autowired private ApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceIntegrationTests.java similarity index 75% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceIntegrationTests.java index ff7c1b53..5df8212b 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; @@ -34,34 +33,36 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.PeerRegionFactoryBean; import org.springframework.data.gemfire.TestUtils; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** - * The RawRegionBeanDefinitionTest class is a test suite of test cases testing the contract and functionality - * of the SDG RegionFactoryBean class, and specifically the specification of the GemFire Region DataPolicy, - * when used as raw bean definition in Spring XML configuration meta-data. + * Integration Tests testing the contract and functionality of the SDG {@link PeerRegionFactoryBean} class, + * and specifically the specification of the Apache Geode {@link Region} {@link DataPolicy}, when used as + * raw bean definition in Spring XML configuration metadata. * * @author John Blum * @see org.junit.Test - * @see org.springframework.data.gemfire.PartitionAttributesFactoryBean - * @see org.springframework.data.gemfire.RegionAttributesFactoryBean - * @see PeerRegionFactoryBean - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner * @see org.apache.geode.cache.DataPolicy * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.PeerRegionFactoryBean + * @see org.springframework.data.gemfire.PartitionAttributesFactoryBean + * @see org.springframework.data.gemfire.RegionAttributesFactoryBean + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner * @since 1.6.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class) +@RunWith(SpringRunner.class) +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class RegionDefinitionUsingBeansNamespaceTest { +public class RegionDefinitionUsingBeansNamespaceIntegrationTests extends IntegrationTestsSupport { @Autowired - private ApplicationContext context; + private ApplicationContext applicationContext; @Resource(name = "Example") private Region example; @@ -71,6 +72,7 @@ public class RegionDefinitionUsingBeansNamespaceTest { @Test public void testExampleRegionBeanDefinitionConfiguration() { + assertNotNull("The '/Example' Region was not properly configured and initialized!", example); assertEquals("Example", example.getName()); assertEquals("/Example", example.getFullPath()); @@ -84,15 +86,16 @@ public class RegionDefinitionUsingBeansNamespaceTest { @Test public void testAnotherExampleRegionFactoryBeanConfiguration() throws Exception { - PeerRegionFactoryBean anotherExampleRegionFactoryBean = context.getBean("&AnotherExample", - PeerRegionFactoryBean.class); + + PeerRegionFactoryBean anotherExampleRegionFactoryBean = + applicationContext.getBean("&AnotherExample", PeerRegionFactoryBean.class); assertNotNull(anotherExampleRegionFactoryBean); assertEquals(DataPolicy.PERSISTENT_PARTITION, anotherExampleRegionFactoryBean.getDataPolicy()); assertTrue(Boolean.TRUE.equals(TestUtils.readField("persistent", anotherExampleRegionFactoryBean))); - RegionAttributes anotherExampleRegionAttributes = TestUtils.readField("attributes", - anotherExampleRegionFactoryBean); + RegionAttributes anotherExampleRegionAttributes = + TestUtils.readField("attributes", anotherExampleRegionFactoryBean); assertNotNull(anotherExampleRegionAttributes); assertEquals(DataPolicy.PARTITION, anotherExampleRegionAttributes.getDataPolicy()); @@ -105,6 +108,7 @@ public class RegionDefinitionUsingBeansNamespaceTest { @Test public void testAnotherExampleRegionDefinitionConfiguration() { + assertNotNull("The '/AnotherExample' Region was not properly configured and initialized!", anotherExample); assertEquals("AnotherExample", anotherExample.getName()); assertEquals("/AnotherExample", anotherExample.getFullPath()); @@ -114,7 +118,6 @@ public class RegionDefinitionUsingBeansNamespaceTest { assertEquals(2, anotherExample.getAttributes().getPartitionAttributes().getRedundantCopies()); } - public static final class TestRegionFactoryBean extends PeerRegionFactoryBean { - } + public static final class TestRegionFactoryBean extends PeerRegionFactoryBean { } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceIntegrationTests.java similarity index 83% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceIntegrationTests.java index 90f32554..7d0c3515 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; @@ -30,44 +29,47 @@ import org.apache.geode.cache.EvictionAlgorithm; import org.apache.geode.cache.EvictionAttributes; import org.apache.geode.cache.Region; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * The RegionEvictionAttributesNamespaceTest class is a test suite of test cases testing the use of - * Eviction configuration settings (EvictionAttributes) in the SDG XML namespace. + * Integration Tests with test cases testing the use of Eviction configuration settings (EvictionAttributes) + * in the SDG XML namespace configuration metadata. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer + * @see org.apache.geode.cache.EvictionAttributes + * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner * @since 1.3.4 */ @RunWith(SpringRunner.class) -@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class) +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class RegionEvictionAttributesNamespaceTest { +public class RegionEvictionAttributesNamespaceIntegrationTests extends IntegrationTestsSupport { @Resource(name = "One") - private Region one; + private Region one; @Resource(name = "Two") - private Region two; + private Region two; @Resource(name = "Three") - private Region three; + private Region three; @Resource(name = "Four") - private Region four; + private Region four; @Resource(name = "Five") - private Region five; + private Region five; @Resource(name = "Six") - private Region six; + private Region six; @Test public void testEntryCountRegionEvictionAttributes() { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceIntegrationTests.java similarity index 88% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceIntegrationTests.java index 44224705..b2746055 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; @@ -32,30 +31,30 @@ import org.apache.geode.cache.ExpirationAction; import org.apache.geode.cache.ExpirationAttributes; import org.apache.geode.cache.Region; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.Assert; /** - * The RegionExpirationAttributesNamespaceTest class is a test suite of test cases testing the configuration of - * ExpirationAttribute settings on Region Entries. + * Integration Tests with test cases testing the configuration of {@link ExpirationAttributes} settings + * on {@link Region} entries. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner + * @see org.apache.geode.cache.ExpirationAttributes * @see org.apache.geode.cache.Region - * @see org.apache.geode.cache.RegionAttributes - * @see org.apache.geode.cache.EvictionAttributes + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner * @since 1.5.0 */ @RunWith(SpringRunner.class) -@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class) +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class RegionExpirationAttributesNamespaceTest { +public class RegionExpirationAttributesNamespaceIntegrationTests extends IntegrationTestsSupport { @Resource(name = "ReplicateExample") private Region replicateExample; @@ -92,7 +91,8 @@ public class RegionExpirationAttributesNamespaceTest { } private void assertExpirationAttributes(ExpirationAttributes expirationAttributes, - final int timeout, final ExpirationAction action) { + int timeout, ExpirationAction action) { + assertNotNull(expirationAttributes); assertEquals(timeout, expirationAttributes.getTimeout()); assertEquals(action, expirationAttributes.getAction()); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceIntegrationTests.java similarity index 56% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceIntegrationTests.java index 924386d7..1817589d 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceIntegrationTests.java @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; import javax.annotation.Resource; @@ -28,27 +26,30 @@ import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.InterestPolicy; import org.apache.geode.cache.Region; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** - * The RegionSubscriptionAttributesNamespaceTest class is a test suite of test cases testing the contract - * and functionality of declaring and defining Subscription Attributes for a Region in the Spring Data GemFire - * XML namespace (XSD) configuration meta-data. + * Integration Tests with test cases testing the contract and functionality of declaring and defining Subscription + * Attributes for a {@link Region} in the SDG XML namespace (XSD) configuration metadata. * * @author John Blum * @see org.junit.Test * @see org.junit.runner.RunWith + * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.SubscriptionAttributesFactoryBean - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner * @since 1.6.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class) +@RunWith(SpringRunner.class) +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class RegionSubscriptionAttributesNamespaceTest { +public class RegionSubscriptionAttributesNamespaceIntegrationTests extends IntegrationTestsSupport { @Resource(name = "NoSubscriptionRegion") private Region noSubscriptionRegion; @@ -62,15 +63,15 @@ public class RegionSubscriptionAttributesNamespaceTest { @Resource(name = "DefaultSubscriptionRegion") private Region defaultSubscriptionRegion; - protected void assertSubscription(final Region region, final String expectedRegionName, - final DataPolicy expectedDataPolicy, final InterestPolicy expectedInterestedPolicy) { - assertNotNull(String.format("The '%1$s' Region was not properly configured an initialized!", - expectedRegionName), region); - assertEquals(expectedRegionName, region.getName()); - assertNotNull(region.getAttributes()); - assertEquals(expectedDataPolicy, region.getAttributes().getDataPolicy()); - assertNotNull(region.getAttributes().getSubscriptionAttributes()); - assertEquals(expectedInterestedPolicy, region.getAttributes().getSubscriptionAttributes().getInterestPolicy()); + private void assertSubscription(Region region, String expectedRegionName, + DataPolicy expectedDataPolicy, InterestPolicy expectedInterestedPolicy) { + + assertThat(region).describedAs(String.format("The '%1$s' Region was not properly configured an initialized!", expectedRegionName)).isNotNull(); + assertThat(region.getName()).isEqualTo(expectedRegionName); + assertThat(region.getAttributes()).isNotNull(); + assertThat(region.getAttributes().getDataPolicy()).isEqualTo(expectedDataPolicy); + assertThat(region.getAttributes().getSubscriptionAttributes()).isNotNull(); + assertThat(region.getAttributes().getSubscriptionAttributes().getInterestPolicy()).isEqualTo(expectedInterestedPolicy); } @Test @@ -94,5 +95,4 @@ public class RegionSubscriptionAttributesNamespaceTest { assertSubscription(defaultSubscriptionRegion, "DefaultSubscriptionRegion", DataPolicy.PARTITION, InterestPolicy.DEFAULT); } - } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests.java similarity index 67% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests.java index 40f895bd..37471e69 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests.java @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.Test; import org.junit.runner.RunWith; @@ -25,15 +23,15 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.support.AbstractApplicationContext; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** - * The RegionWithSubRegionBeanDefinitionHashCodeTest class is a test suite for testing the hashCode() method of a - * Spring container BeanDefinition representing a GemFire Region having SubRegions. This test suite is meant to - * ensure the correct behavior of and provide regression coverage for, JIRA issue SGF-178, "parent attribute causes - * endless loop in hashCode". + * Integration Tests testing the hashCode() method of a Spring container BeanDefinition representing a Region + * having SubRegions. This test suite is meant to ensure the correct behavior of and provide regression coverage for, + * JIRA issue SGF-178, "parent attribute causes endless loop in hashCode". * * The 'parent' attribute was added to the parent Region's BeanDefinition, referring to the parent Region's * BeanDefinition itself, before it recurses to parse the SubRegion elements, which is then used by the @@ -75,44 +73,48 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer + * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner + * @see org.springframework.test.context.junit4.SpringRunner * @link https://jira.springsource.org/browse/SGF-178 * @since 1.3.3 */ -@ContextConfiguration(locations= "/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeTest-context.xml", - initializers=GemfireTestApplicationContextInitializer.class) -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) +@ContextConfiguration( + locations = "/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeTest-context.xml", + initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class RegionWithSubRegionBeanDefinitionHashCodeTest { +public class RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests extends IntegrationTestsSupport { @Autowired - private AbstractApplicationContext context; + private AbstractApplicationContext applicationContext; @Test public void testNonParentRegionBeanDefinitionHashCode() { - final BeanDefinition nonParentRegionBeanDefinition = context.getBeanFactory().getBeanDefinition("NON_PARENT"); - assertNotNull(nonParentRegionBeanDefinition); - assertTrue(nonParentRegionBeanDefinition.hashCode() != 0); + BeanDefinition nonParentRegionBeanDefinition = applicationContext.getBeanFactory().getBeanDefinition("NON_PARENT"); + + assertThat(nonParentRegionBeanDefinition).isNotNull(); + assertThat(nonParentRegionBeanDefinition.hashCode() != 0).isTrue(); } @Test public void testParentRegionBeanDefinitionHashCode() { - final BeanDefinition parentRegionBeanDefinition = context.getBeanFactory().getBeanDefinition("PARENT"); - assertNotNull(parentRegionBeanDefinition); - assertTrue(parentRegionBeanDefinition.hashCode() != 0); + BeanDefinition parentRegionBeanDefinition = applicationContext.getBeanFactory().getBeanDefinition("PARENT"); + + assertThat(parentRegionBeanDefinition).isNotNull(); + assertThat(parentRegionBeanDefinition.hashCode() != 0).isTrue(); } @Test public void testChildRegionBeanDefinitionHashCode() { - final BeanDefinition childRegionBeanDefinition = context.getBeanFactory().getBeanDefinition("/PARENT/CHILD"); - assertNotNull(childRegionBeanDefinition); - assertTrue(childRegionBeanDefinition.hashCode() != 0); + BeanDefinition childRegionBeanDefinition = applicationContext.getBeanFactory().getBeanDefinition("/PARENT/CHILD"); + + assertThat(childRegionBeanDefinition).isNotNull(); + assertThat(childRegionBeanDefinition.hashCode() != 0).isTrue(); } - } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionsWithDiskStoreAndPersistenceEvictionSettingsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionsWithDiskStoreAndPersistenceEvictionSettingsIntegrationTests.java new file mode 100644 index 00000000..ed239537 --- /dev/null +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionsWithDiskStoreAndPersistenceEvictionSettingsIntegrationTests.java @@ -0,0 +1,120 @@ +/* + * Copyright 2010-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.gemfire.config.xml; + +import static org.assertj.core.api.Assertions.assertThat; + +import javax.annotation.Resource; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.geode.cache.DataPolicy; +import org.apache.geode.cache.DiskStore; +import org.apache.geode.cache.EvictionAction; +import org.apache.geode.cache.Region; + +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Integration Tests testing the functionality of cache {@link Region Regions} when persistent/non-persistent with + * and without Eviction settings when specifying a {@link DiskStore}. + * + * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner + * @since 1.4.0.RC1 + */ +@RunWith(SpringRunner.class) +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) +@SuppressWarnings("unused") +public class RegionsWithDiskStoreAndPersistenceEvictionSettingsIntegrationTests extends IntegrationTestsSupport { + + @Resource(name = "NotPersistentNoOverflowRegion") + private Region notPersistentNoOverflowRegion; + + @Resource(name = "NotPersistentOverflowRegion") + private Region notPersistentOverflowRegion; + + @Resource(name = "PersistentNoOverflowRegion") + private Region persistentNoOverflowRegion; + + @Resource(name = "PersistentOverflowRegion") + private Region persistentOverflowRegion; + + @Test + public void testNotPersistentNoOverflowRegion() { + + assertThat(notPersistentNoOverflowRegion) + .describedAs("The Not Persistent, No Overflow Region was not properly configured and initialized!") + .isNotNull(); + + assertThat(notPersistentNoOverflowRegion.getAttributes()).isNotNull(); + assertThat(notPersistentNoOverflowRegion.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.PARTITION); + assertThat(notPersistentNoOverflowRegion.getAttributes().getEvictionAttributes()).isNotNull(); + assertThat(notPersistentNoOverflowRegion.getAttributes().getEvictionAttributes().getAction()).isEqualTo(EvictionAction.NONE); + assertThat(notPersistentNoOverflowRegion.getAttributes().getDiskStoreName()).isNull(); + } + + @Test + public void testNotPersistentOverflowRegion() { + + assertThat(notPersistentOverflowRegion) + .describedAs("The Not Persistent, Overflow Region was not properly configured and initialized!") + .isNotNull(); + + assertThat(notPersistentOverflowRegion.getAttributes()).isNotNull(); + assertThat(notPersistentOverflowRegion.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.PARTITION); + assertThat(notPersistentOverflowRegion.getAttributes().getEvictionAttributes()).isNotNull(); + assertThat(notPersistentOverflowRegion.getAttributes().getEvictionAttributes().getAction()).isEqualTo(EvictionAction.OVERFLOW_TO_DISK); + assertThat(notPersistentOverflowRegion.getAttributes().getDiskStoreName()).isEqualTo("DiskStoreOne"); + } + + @Test + public void testPersistentNoOverflowRegion() { + + assertThat(persistentNoOverflowRegion) + .describedAs("The Persistent, No Overflow Region was not properly configured and initialized!") + .isNotNull(); + + assertThat(persistentNoOverflowRegion.getAttributes()).isNotNull(); + assertThat(persistentNoOverflowRegion.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.PERSISTENT_PARTITION); + assertThat(persistentNoOverflowRegion.getAttributes().getEvictionAttributes()).isNotNull(); + assertThat(persistentNoOverflowRegion.getAttributes().getEvictionAttributes().getAction()).isEqualTo(EvictionAction.LOCAL_DESTROY); + assertThat(persistentNoOverflowRegion.getAttributes().getDiskStoreName()).isEqualTo("DiskStoreOne"); + } + + @Test + public void testPersistentOverflowRegion() { + + assertThat(persistentOverflowRegion) + .describedAs("The Persistent, Overflow Region was not properly configured and initialized!") + .isNotNull(); + + assertThat(persistentOverflowRegion.getAttributes()).isNotNull(); + assertThat(persistentOverflowRegion.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.PERSISTENT_PARTITION); + assertThat(persistentOverflowRegion.getAttributes().getEvictionAttributes()).isNotNull(); + assertThat(persistentOverflowRegion.getAttributes().getEvictionAttributes().getAction()).isEqualTo(EvictionAction.OVERFLOW_TO_DISK); + assertThat(persistentOverflowRegion.getAttributes().getDiskStoreName()).isEqualTo("DiskStoreOne"); + } +} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest.java deleted file mode 100644 index 9837e7b1..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.config.xml; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import javax.annotation.Resource; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.apache.geode.cache.DataPolicy; -import org.apache.geode.cache.EvictionAction; -import org.apache.geode.cache.Region; - -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * The RegionsWithDiskStoreAndPersistenceEvictionSettingsTest class is a test suite testing the functionality - * of GemFire Cache Regions when persistent/non-persistent with and without Eviction settings when specifying a - * Disk Store. - * - * @author John Blum - * @see org.junit.Test - * @see org.springframework.test.context.ContextConfiguration - * @since 1.4.0.RC1 - */ -@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class) -@RunWith(SpringJUnit4ClassRunner.class) -public class RegionsWithDiskStoreAndPersistenceEvictionSettingsTest { - - @Resource(name = "NotPersistentNoOverflowRegion") - private Region notPersistentNoOverflowRegion; - - @Resource(name = "NotPersistentOverflowRegion") - private Region notPersistentOverflowRegion; - - @Resource(name = "PersistentNoOverflowRegion") - private Region persistentNoOverflowRegion; - - @Resource(name = "PersistentOverflowRegion") - private Region persistentOverflowRegion; - - @Test - public void testNotPersistentNoOverflowRegion() { - assertNotNull("The Not Persistent, No Overflow Region was not properly configured and initialized!", - notPersistentNoOverflowRegion); - - assertNotNull(notPersistentNoOverflowRegion.getAttributes()); - assertEquals(DataPolicy.PARTITION, notPersistentNoOverflowRegion.getAttributes().getDataPolicy()); - assertNotNull(notPersistentNoOverflowRegion.getAttributes().getEvictionAttributes()); - assertEquals(EvictionAction.NONE, notPersistentNoOverflowRegion.getAttributes() - .getEvictionAttributes().getAction()); - assertNull(notPersistentNoOverflowRegion.getAttributes().getDiskStoreName()); - } - - @Test - public void testNotPersistentOverflowRegion() { - assertNotNull("The Not Persistent, Overflow Region was not properly configured and initialized!", - notPersistentOverflowRegion); - - assertNotNull(notPersistentOverflowRegion.getAttributes()); - assertEquals(DataPolicy.PARTITION, notPersistentOverflowRegion.getAttributes().getDataPolicy()); - assertNotNull(notPersistentOverflowRegion.getAttributes().getEvictionAttributes()); - assertEquals(EvictionAction.OVERFLOW_TO_DISK, notPersistentOverflowRegion.getAttributes() - .getEvictionAttributes().getAction()); - assertEquals("DiskStoreOne", notPersistentOverflowRegion.getAttributes().getDiskStoreName()); - } - - @Test - public void testPersistentNoOverflowRegion() { - assertNotNull("The Persistent, No Overflow Region was not properly configured and initialized!", - persistentNoOverflowRegion); - - assertNotNull(persistentNoOverflowRegion.getAttributes()); - assertEquals(DataPolicy.PERSISTENT_PARTITION, persistentNoOverflowRegion.getAttributes().getDataPolicy()); - assertNotNull(persistentNoOverflowRegion.getAttributes().getEvictionAttributes()); - assertEquals(EvictionAction.LOCAL_DESTROY, persistentNoOverflowRegion.getAttributes() - .getEvictionAttributes().getAction()); - assertEquals("DiskStoreOne", persistentNoOverflowRegion.getAttributes().getDiskStoreName()); - } - - @Test - public void testPersistentOverflowRegion() { - assertNotNull("The Persistent, Overflow Region was not properly configured and initialized!", - persistentOverflowRegion); - - assertNotNull(persistentOverflowRegion.getAttributes()); - assertEquals(DataPolicy.PERSISTENT_PARTITION, persistentOverflowRegion.getAttributes().getDataPolicy()); - assertNotNull(persistentOverflowRegion.getAttributes().getEvictionAttributes()); - assertEquals(EvictionAction.OVERFLOW_TO_DISK, persistentOverflowRegion.getAttributes() - .getEvictionAttributes().getAction()); - assertEquals("DiskStoreOne", persistentOverflowRegion.getAttributes().getDiskStoreName()); - } - -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ReplicatedRegionNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ReplicatedRegionNamespaceIntegrationTests.java similarity index 88% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ReplicatedRegionNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ReplicatedRegionNamespaceIntegrationTests.java index 00105bbe..f7e2084f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ReplicatedRegionNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ReplicatedRegionNamespaceIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; @@ -42,25 +41,32 @@ import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; import org.springframework.data.gemfire.ResolvableRegionFactoryBean; import org.springframework.data.gemfire.SimpleCacheListener; import org.springframework.data.gemfire.TestUtils; -import org.springframework.data.gemfire.test.mock.context.GemFireMockObjectsApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.ObjectUtils; /** - * Unit tests for the Replicated Region Namespace. + * Integration Tests for the Replicated Region XML namespace configuration metadata. * * @author Costin Leau * @author David Turanski * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.ReplicatedRegionFactoryBean * @see org.springframework.data.gemfire.config.xml.ReplicatedRegionParser + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) @ContextConfiguration(locations = "replicated-ns.xml", initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class ReplicatedRegionNamespaceTest { +public class ReplicatedRegionNamespaceIntegrationTests extends IntegrationTestsSupport { @Autowired private ApplicationContext applicationContext; @@ -70,14 +76,14 @@ public class ReplicatedRegionNamespaceTest { assertTrue(applicationContext.containsBean("simple")); - PeerRegionFactoryBean simpleRegionFactoryBean = + PeerRegionFactoryBean simpleRegionFactoryBean = applicationContext.getBean("&simple", PeerRegionFactoryBean.class); assertEquals("simple", TestUtils.readField("beanName", simpleRegionFactoryBean)); assertEquals(false, TestUtils.readField("close", simpleRegionFactoryBean)); assertNull(TestUtils.readField("scope", simpleRegionFactoryBean)); - RegionAttributes simpleRegionAttributes = TestUtils.readField("attributes", simpleRegionFactoryBean); + RegionAttributes simpleRegionAttributes = TestUtils.readField("attributes", simpleRegionFactoryBean); assertNotNull(simpleRegionAttributes); assertFalse(simpleRegionAttributes.getConcurrencyChecksEnabled()); @@ -129,7 +135,7 @@ public class ReplicatedRegionNamespaceTest { @Test @SuppressWarnings("rawtypes") - public void testReplicatedRegionWithAttributes() throws Exception { + public void testReplicatedRegionWithAttributes() { assertTrue(applicationContext.containsBean("replicated-with-attributes")); @@ -162,12 +168,12 @@ public class ReplicatedRegionNamespaceTest { assertTrue(applicationContext.containsBean("replicated-with-synchronous-index-updates")); - Region region = applicationContext.getBean("replicated-with-synchronous-index-updates", Region.class); + Region region = applicationContext.getBean("replicated-with-synchronous-index-updates", Region.class); assertNotNull(String.format("The '%1$s' Region was not properly configured and initialized!", "replicated-with-synchronous-index-updates"), region); - RegionAttributes regionAttributes = region.getAttributes(); + RegionAttributes regionAttributes = region.getAttributes(); assertNotNull(regionAttributes); assertTrue(regionAttributes.getIndexMaintenanceSynchronous()); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionNamespaceIntegrationTests.java new file mode 100644 index 00000000..2eedafaa --- /dev/null +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionNamespaceIntegrationTests.java @@ -0,0 +1,143 @@ +/* + * Copyright 2010-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.gemfire.config.xml; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.geode.cache.Cache; +import org.apache.geode.cache.CacheLoader; +import org.apache.geode.cache.Region; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; +import org.springframework.data.gemfire.TestUtils; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Integration Tests with test cases testing the contract and functionality of Region/SubRegion creation in a cache. + * + * @author David Turanski + * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner + */ +@RunWith(SpringRunner.class) +@ContextConfiguration(locations = "subregion-ns.xml", + initializers = GemFireMockObjectsApplicationContextInitializer.class) +@SuppressWarnings({ "rawtypes", "unused" }) +public class SubRegionNamespaceIntegrationTests extends IntegrationTestsSupport { + + @Autowired + private ApplicationContext applicationContext; + + @Test + public void testNestedRegionsCreated() { + + Cache cache = applicationContext.getBean(Cache.class); + + assertThat(cache.getRegion("parent")).isNotNull(); + assertThat(cache.getRegion("/parent/child")).isNotNull(); + assertThat(cache.getRegion("/parent/child/grandchild")).isNotNull(); + } + + @Test + @SuppressWarnings("unchecked") + public void testNestedReplicatedRegions() { + + Region parent = applicationContext.getBean("parent", Region.class); + Region child = applicationContext.getBean("/parent/child", Region.class); + Region grandchild = applicationContext.getBean("/parent/child/grandchild", Region.class); + + assertThat(child).isNotNull(); + assertThat(child.getName()).isEqualTo("child"); + assertThat(child.getFullPath()).isEqualTo("/parent/child"); + assertThat(parent.getSubregion("child")).isSameAs(child); + assertThat(grandchild).isNotNull(); + assertThat(grandchild.getName()).isEqualTo("grandchild"); + assertThat(grandchild.getFullPath()).isEqualTo("/parent/child/grandchild"); + assertThat(child.getSubregion("grandchild")).isSameAs(grandchild); + } + + @Test + @SuppressWarnings("unchecked") + public void testMixedNestedRegions() { + + Region parent = applicationContext.getBean("replicatedParent", Region.class); + Region child = applicationContext.getBean("/replicatedParent/replicatedChild", Region.class); + Region grandchild = applicationContext.getBean("/replicatedParent/replicatedChild/partitionedGrandchild", Region.class); + + assertThat(child).isNotNull(); + assertThat(child.getFullPath()).isEqualTo("/replicatedParent/replicatedChild"); + assertThat(parent.getSubregion("replicatedChild")).isEqualTo(child); + assertThat(grandchild).isNotNull(); + assertThat(grandchild.getFullPath()).isEqualTo("/replicatedParent/replicatedChild/partitionedGrandchild"); + assertThat(child.getSubregion("partitionedGrandchild")).isSameAs(grandchild); + } + + @Test + @SuppressWarnings("unchecked") + public void testNestedRegionsWithSiblings() { + + Region parent = applicationContext.getBean("parentWithSiblings", Region.class); + Region child1 = applicationContext.getBean("/parentWithSiblings/child1", Region.class); + + assertThat(child1.getFullPath()).isEqualTo("/parentWithSiblings/child1"); + + Region child2 = applicationContext.getBean("/parentWithSiblings/child2", Region.class); + + assertThat(child2.getFullPath()).isEqualTo("/parentWithSiblings/child2"); + assertThat(parent.getSubregion("child1")).isSameAs(child1); + assertThat(parent.getSubregion("child2")).isSameAs(child2); + + Region grandchild1 = applicationContext.getBean("/parentWithSiblings/child1/grandChild11", Region.class); + + assertThat(grandchild1.getFullPath()).isEqualTo("/parentWithSiblings/child1/grandChild11"); + } + + @Test + @SuppressWarnings("unused" ) + public void testComplexNestedRegions() throws Exception { + + Region parent = applicationContext.getBean("complexNested", Region.class); + Region child1 = applicationContext.getBean("/complexNested/child1", Region.class); + Region child2 = applicationContext.getBean("/complexNested/child2", Region.class); + Region grandchild11 = applicationContext.getBean("/complexNested/child1/grandChild11", Region.class); + + ReplicatedRegionFactoryBean grandchild11FactoryBean = + applicationContext.getBean("&/complexNested/child1/grandChild11", ReplicatedRegionFactoryBean.class); + + assertThat(grandchild11FactoryBean).isNotNull(); + + CacheLoader expectedCacheLoader = TestUtils.readField("cacheLoader", grandchild11FactoryBean); + + assertThat(expectedCacheLoader).isNotNull(); + + CacheLoader actualCacheLoader = grandchild11.getAttributes().getCacheLoader(); + + assertThat(actualCacheLoader).isSameAs(expectedCacheLoader); + } +} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionNamespaceTest.java deleted file mode 100644 index d8bf9c56..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionNamespaceTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.config.xml; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheLoader; -import org.apache.geode.cache.Region; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; -import org.springframework.data.gemfire.TestUtils; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * The SubRegionNamespaceTest class is a test suite of test cases testing the contract and functionality of - * Region/SubRegion creation in a GemFire Cache. - * - * @author David Turanski - * @author John Blum - * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "subregion-ns.xml", initializers = GemfireTestApplicationContextInitializer.class) -@SuppressWarnings({ "deprecation", "rawtypes", "unused" }) -public class SubRegionNamespaceTest { - - @Autowired - private ApplicationContext context; - - @Test - public void testNestedRegionsCreated() { - Cache cache = context.getBean(Cache.class); - - assertNotNull(cache.getRegion("parent")); - assertNotNull(cache.getRegion("/parent/child")); - assertNotNull(cache.getRegion("/parent/child/grandchild")); - } - - @Test - public void testNestedReplicatedRegions() { - Region parent = context.getBean("parent", Region.class); - Region child = context.getBean("/parent/child", Region.class); - Region grandchild = context.getBean("/parent/child/grandchild", Region.class); - - assertNotNull(child); - assertEquals("child", child.getName()); - assertEquals("/parent/child", child.getFullPath()); - assertSame(child, parent.getSubregion("child")); - assertNotNull(grandchild); - assertEquals("grandchild", grandchild.getName()); - assertEquals("/parent/child/grandchild", grandchild.getFullPath()); - assertSame(grandchild, child.getSubregion("grandchild")); - } - - @Test - @SuppressWarnings("unchecked") - public void testMixedNestedRegions() { - Region parent = context.getBean("replicatedParent", Region.class); - Region child = context.getBean("/replicatedParent/replicatedChild", Region.class); - Region grandchild = context.getBean("/replicatedParent/replicatedChild/partitionedGrandchild", Region.class); - - assertNotNull(child); - assertEquals("/replicatedParent/replicatedChild", child.getFullPath()); - assertEquals(child, parent.getSubregion("replicatedChild")); - assertNotNull(grandchild); - assertEquals("/replicatedParent/replicatedChild/partitionedGrandchild", grandchild.getFullPath()); - assertSame(grandchild, child.getSubregion("partitionedGrandchild")); - } - - @Test - public void testNestedRegionsWithSiblings() { - Region parent = context.getBean("parentWithSiblings", Region.class); - Region child1 = context.getBean("/parentWithSiblings/child1", Region.class); - assertEquals("/parentWithSiblings/child1", child1.getFullPath()); - Region child2 = context.getBean("/parentWithSiblings/child2", Region.class); - assertEquals("/parentWithSiblings/child2", child2.getFullPath()); - assertSame(child1, parent.getSubregion("child1")); - assertSame(child2, parent.getSubregion("child2")); - Region grandchild1 = context.getBean("/parentWithSiblings/child1/grandChild11", Region.class); - assertEquals("/parentWithSiblings/child1/grandChild11", grandchild1.getFullPath()); - } - - @Test - @SuppressWarnings("unused" ) - public void testComplexNestedRegions() throws Exception { - Region parent = context.getBean("complexNested", Region.class); - Region child1 = context.getBean("/complexNested/child1", Region.class); - Region child2 = context.getBean("/complexNested/child2", Region.class); - Region grandchild11 = context.getBean("/complexNested/child1/grandChild11", Region.class); - - ReplicatedRegionFactoryBean grandchild11FactoryBean = context.getBean("&/complexNested/child1/grandChild11", - ReplicatedRegionFactoryBean.class); - - assertNotNull(grandchild11FactoryBean); - - CacheLoader expectedCacheLoader = TestUtils.readField("cacheLoader", grandchild11FactoryBean); - - assertNotNull(expectedCacheLoader); - - CacheLoader actualCacheLoader = grandchild11.getAttributes().getCacheLoader(); - - assertSame(expectedCacheLoader, actualCacheLoader); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionSubElementNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionSubElementNamespaceIntegrationTests.java similarity index 76% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionSubElementNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionSubElementNamespaceIntegrationTests.java index d09241f6..f570d90f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionSubElementNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionSubElementNamespaceIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertNotNull; @@ -34,49 +33,51 @@ import org.apache.geode.cache.util.CacheListenerAdapter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - * The SubRegionSubElementNamespaceTest class... + * Integration Tests for {@link Region sub-Region}, sub-element SDG XML namespace configuration metadata. * * @author John Blum - * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner - * @see org.apache.geode.cache.Region * @link https://jira.springsource.org/browse/SGF-219 * @link https://jira.springsource.org/browse/SGF-220 * @link https://jira.springsource.org/browse/SGF-221 + * @see org.junit.Test + * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner * @since 1.3.3 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "subregionsubelement-ns.xml", - initializers = GemfireTestApplicationContextInitializer.class) + initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class SubRegionSubElementNamespaceTest { +public class SubRegionSubElementNamespaceIntegrationTests extends IntegrationTestsSupport { @Autowired private ApplicationContext applicationContext; @Resource(name = "/Customers/Accounts") - private Region customersAccountsRegion; + private Region customersAccountsRegion; @Resource(name = "/Parent/Child") - private Region parentChildRegion; + private Region parentChildRegion; @Test public void testCustomersAccountsSubRegionCacheListener() { + assertNotNull(customersAccountsRegion); assertNotNull(customersAccountsRegion.getAttributes()); assertNotNull(customersAccountsRegion.getAttributes().getCacheListeners()); boolean found = false; - for (CacheListener listener : customersAccountsRegion.getAttributes().getCacheListeners()) { + for (CacheListener listener : customersAccountsRegion.getAttributes().getCacheListeners()) { found |= (listener instanceof TestNoOpCacheListener); } @@ -86,7 +87,8 @@ public class SubRegionSubElementNamespaceTest { @Test public void testOrderItemsSubRegionGatewaySender() { - Region orderItemsRegion = applicationContext.getBean("/Orders/Items", Region.class); + + Region orderItemsRegion = applicationContext.getBean("/Orders/Items", Region.class); assertNotNull(orderItemsRegion); assertNotNull(orderItemsRegion.getAttributes()); @@ -96,14 +98,14 @@ public class SubRegionSubElementNamespaceTest { @Test public void testParentChildSubRegionAsyncEventQueue() { + assertNotNull(parentChildRegion); assertNotNull(parentChildRegion.getAttributes()); assertNotNull(parentChildRegion.getAttributes().getAsyncEventQueueIds()); assertTrue(parentChildRegion.getAttributes().getAsyncEventQueueIds().contains("testQueue")); } - public static final class TestNoOpCacheListener extends CacheListenerAdapter { - } + public static final class TestNoOpCacheListener extends CacheListenerAdapter { } public static final class TestNoOpAsyncEventListener implements AsyncEventListener { @@ -113,7 +115,7 @@ public class SubRegionSubElementNamespaceTest { } @Override - public void close() { - } + public void close() { } + } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplatePersistentPartitionRegionNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplatePersistentPartitionRegionNamespaceIntegrationTests.java similarity index 50% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplatePersistentPartitionRegionNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplatePersistentPartitionRegionNamespaceIntegrationTests.java index 9400c2bc..8ed89ff2 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplatePersistentPartitionRegionNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplatePersistentPartitionRegionNamespaceIntegrationTests.java @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; @@ -36,26 +34,31 @@ import org.apache.geode.cache.PartitionResolver; import org.apache.geode.cache.Region; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; -import org.springframework.data.gemfire.test.support.FileSystemUtils; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; +import org.springframework.data.gemfire.tests.util.FileSystemUtils; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** - * The PersistentPartitionRegionTemplateTest class is a test suite of test cases testing the functionality of - * Spring Data GemFire's Region templates with a 'persistent', PARTITION Region configuration. + * Integration Tests with test cases testing the functionality of {@link Region} templates + * with a persistent, {@literal PARTITION} {@link Region} configuration. * * @author John Blum * @see org.junit.Test - * @see org.springframework.data.gemfire.PartitionedRegionFactoryBean * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.PartitionedRegionFactoryBean + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner * @link https://jira.spring.io/browse/SGF-384 * @since 1.6.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class) +@RunWith(SpringRunner.class) +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class TemplatePersistentPartitionRegionNamespaceTest { +public class TemplatePersistentPartitionRegionNamespaceIntegrationTests extends IntegrationTestsSupport { @Autowired private DiskStore exampleDataStore; @@ -65,6 +68,7 @@ public class TemplatePersistentPartitionRegionNamespaceTest { @After public void tearDown() { + for (File diskDirectory : exampleDataStore.getDiskDirs()) { FileSystemUtils.deleteRecursive(FileSystemUtils.getRootRelativeToWorkingDirectoryOrPath( diskDirectory.getAbsoluteFile())); @@ -73,19 +77,21 @@ public class TemplatePersistentPartitionRegionNamespaceTest { @Test public void testExampleTemplatedPersistentPartitionRegion() { - assertNotNull("The '/Example' PARTITION Region was not properly configured and initialized!", example); - assertEquals("Example", example.getName()); - assertEquals("/Example", example.getFullPath()); - assertNotNull(example.getAttributes()); - assertEquals(DataPolicy.PERSISTENT_PARTITION, example.getAttributes().getDataPolicy()); - assertNotNull(example.getAttributes().getEvictionAttributes()); - assertEquals(EvictionAlgorithm.LRU_HEAP, example.getAttributes().getEvictionAttributes().getAlgorithm()); - assertEquals(EvictionAction.OVERFLOW_TO_DISK, example.getAttributes().getEvictionAttributes().getAction()); - assertNotNull(example.getAttributes().getPartitionAttributes()); - assertEquals(1, example.getAttributes().getPartitionAttributes().getRedundantCopies()); - assertEquals(163, example.getAttributes().getPartitionAttributes().getTotalNumBuckets()); - assertNotNull(example.getAttributes().getPartitionAttributes().getPartitionResolver()); - assertEquals("TestPartitionResolver", example.getAttributes().getPartitionAttributes().getPartitionResolver().getName()); + + assertThat(example).describedAs("The '/Example' PARTITION Region was not properly configured and initialized!").isNotNull(); + assertThat(example.getName()).isEqualTo("Example"); + assertThat(example.getFullPath()).isEqualTo("/Example"); + assertThat(example.getAttributes()).isNotNull(); + assertThat(example.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.PERSISTENT_PARTITION); + assertThat(example.getAttributes().getEvictionAttributes()).isNotNull(); + assertThat(example.getAttributes().getEvictionAttributes().getAlgorithm()).isEqualTo(EvictionAlgorithm.LRU_HEAP); + assertThat(example.getAttributes().getEvictionAttributes().getAction()).isEqualTo(EvictionAction.OVERFLOW_TO_DISK); + assertThat(example.getAttributes().getPartitionAttributes()).isNotNull(); + assertThat(example.getAttributes().getPartitionAttributes().getRedundantCopies()).isEqualTo(1); + assertThat(example.getAttributes().getPartitionAttributes().getTotalNumBuckets()).isEqualTo(163); + assertThat(example.getAttributes().getPartitionAttributes().getPartitionResolver()).isNotNull(); + assertThat(example.getAttributes().getPartitionAttributes().getPartitionResolver().getName()) + .isEqualTo("TestPartitionResolver"); } public static final class TestPartitionResolver implements PartitionResolver { @@ -110,5 +116,4 @@ public class TemplatePersistentPartitionRegionNamespaceTest { public void close() { } } - } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceIntegrationTests.java similarity index 97% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceTests.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceIntegrationTests.java index 8a2de3c8..7ecfc254 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; @@ -65,31 +64,30 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanIsAbstractException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; /** - * The TemplateRegionsNamespaceTests class is a test suite of test cases testing the functionality and support for - * Region Templating in Spring Data GemFire. + * Integration Tests for {@link Region} Templates. * * @author John Blum * @see org.junit.Test * @see org.junit.runner.RunWith - * @see org.springframework.context.ApplicationContext - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer + * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner - * @see org.apache.geode.cache.Cache - * @see org.apache.geode.cache.Region * @since 1.5.0 */ @RunWith(SpringRunner.class) -@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class) -@SuppressWarnings("unused") -public class TemplateRegionsNamespaceTests { +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) +@SuppressWarnings({ "rawtypes", "unused"}) +public class TemplateRegionsNamespaceIntegrationTests extends IntegrationTestsSupport { @Autowired private ApplicationContext applicationContext; @@ -310,9 +308,9 @@ public class TemplateRegionsNamespaceTests { fail(String.format("The abstract bean definition '%1$s' should not exist as a bean in the Spring context!", beanName)); } - catch (BeansException ignore) { - assertTrue(ignore instanceof BeanIsAbstractException); - assertTrue(ignore.getMessage().contains(beanName)); + catch (BeansException expected) { + assertTrue(expected instanceof BeanIsAbstractException); + assertTrue(expected.getMessage().contains(beanName)); } } } @@ -502,8 +500,8 @@ public class TemplateRegionsNamespaceTests { templateBasedPartitionRegion.getAttributes().getPartitionAttributes().getColocatedWith()); assertEquals(8192, templateBasedPartitionRegion.getAttributes().getPartitionAttributes().getLocalMaxMemory()); assertEquals(2, templateBasedPartitionRegion.getAttributes().getPartitionAttributes().getRedundantCopies()); - assertEquals(60000l, templateBasedPartitionRegion.getAttributes().getPartitionAttributes().getRecoveryDelay()); - assertEquals(15000l, templateBasedPartitionRegion.getAttributes().getPartitionAttributes().getStartupRecoveryDelay()); + assertEquals(60000L, templateBasedPartitionRegion.getAttributes().getPartitionAttributes().getRecoveryDelay()); + assertEquals(15000L, templateBasedPartitionRegion.getAttributes().getPartitionAttributes().getStartupRecoveryDelay()); assertEquals(16384, templateBasedPartitionRegion.getAttributes().getPartitionAttributes().getTotalMaxMemory()); assertEquals(91, templateBasedPartitionRegion.getAttributes().getPartitionAttributes().getTotalNumBuckets()); assertPartitionListener(templateBasedPartitionRegion, "testListener"); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxEventHandlersTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxEventHandlersIntegrationTests.java similarity index 72% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxEventHandlersTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxEventHandlersIntegrationTests.java index 7450773f..14a088f6 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxEventHandlersTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxEventHandlersIntegrationTests.java @@ -28,21 +28,34 @@ import org.apache.geode.cache.TransactionWriter; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * @author David Turanski + * Integration Tests for Apache Geode cache transaction event handling configuration declared in + * SDG XML namespace configuration metadata. * + * @author David Turanski + * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.Cache + * @see org.apache.geode.cache.TransactionEvent + * @see org.apache.geode.cache.TransactionListener + * @see org.apache.geode.cache.TransactionWriter + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) @ContextConfiguration( - locations="tx-listeners-and-writers.xml", - initializers = GemfireTestApplicationContextInitializer.class + locations = "tx-listeners-and-writers.xml", + initializers = GemFireMockObjectsApplicationContextInitializer.class ) @SuppressWarnings("unused") -public class TxEventHandlersTest { +public class TxEventHandlersIntegrationTests extends IntegrationTestsSupport { @Autowired TestTransactionListener txListener1; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceIntegrationTests.java new file mode 100644 index 00000000..86f60eba --- /dev/null +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceIntegrationTests.java @@ -0,0 +1,55 @@ +/* + * Copyright 2010-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.gemfire.config.xml; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; +import org.springframework.data.gemfire.transaction.GemfireTransactionManager; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author Costin Leau + * @author John Blum + */ +@RunWith(SpringRunner.class) +@ContextConfiguration(locations = "/org/springframework/data/gemfire/config/xml/tx-ns.xml", + initializers = GemFireMockObjectsApplicationContextInitializer.class) +@SuppressWarnings("unused") +public class TxManagerNamespaceIntegrationTests extends IntegrationTestsSupport { + + @Autowired + private ApplicationContext applicationContext; + + @Test + public void testBasicCache() { + + assertThat(applicationContext.containsBean("gemfireTransactionManager")).isTrue(); + assertThat(applicationContext.containsBean("gemfire-transaction-manager")).isTrue(); + + GemfireTransactionManager transactionManager = + applicationContext.getBean("gemfireTransactionManager", GemfireTransactionManager.class); + + assertThat(transactionManager.isCopyOnRead()).isFalse(); + } +} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceTest.java deleted file mode 100644 index 71a2dca7..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.config.xml; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; -import org.springframework.data.gemfire.transaction.GemfireTransactionManager; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * @author Costin Leau - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations= "/org/springframework/data/gemfire/config/xml/tx-ns.xml", - initializers=GemfireTestApplicationContextInitializer.class) -public class TxManagerNamespaceTest { - - @Autowired ApplicationContext ctx; - - @Test - public void testBasicCache() throws Exception { - assertTrue(ctx.containsBean("gemfireTransactionManager")); - //Check old style alias also registered - assertTrue(ctx.containsBean("gemfire-transaction-manager")); - - GemfireTransactionManager tx = ctx.getBean("gemfireTransactionManager", GemfireTransactionManager.class); - assertFalse(tx.isCopyOnRead()); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpirationConfigurationIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpirationConfigurationIntegrationTest.java index 5dc999cf..9fbf8ccf 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpirationConfigurationIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpirationConfigurationIntegrationTest.java @@ -14,66 +14,53 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.expiration; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.isA; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.CoreMatchers.sameInstance; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import javax.annotation.Resource; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + import org.apache.geode.cache.CustomExpiry; import org.apache.geode.cache.ExpirationAction; import org.apache.geode.cache.ExpirationAttributes; import org.apache.geode.cache.Region; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.expression.EvaluationException; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * The AnnotationBasedExpirationConfigurationIntegrationTest class is a test suite of test cases testing - * the configuration of Annotation-defined expiration policies on Region Entry TTL and TTI - * custom expiration settings. + * Integration Tests with test cases testing the configuration of Annotation-defined expiration policies + * on {@link Region} entry TTL and TTI custom expiration settings. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith * @see org.mockito.Mockito - * @see AnnotationBasedExpiration - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner * @see org.apache.geode.cache.CustomExpiry * @see org.apache.geode.cache.ExpirationAction * @see org.apache.geode.cache.ExpirationAttributes + * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.expiration.AnnotationBasedExpiration + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner * @since 1.7.0 */ @RunWith(SpringRunner.class) -@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class) +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") public class AnnotationBasedExpirationConfigurationIntegrationTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - @Autowired @Qualifier("genericExpiration") private AnnotationBasedExpiration genericExpiration; @@ -94,19 +81,20 @@ public class AnnotationBasedExpirationConfigurationIntegrationTest { @Before public void setup() { - assertThat(example, is(not(nullValue()))); - assertThat(example.getName(), is(equalTo("Example"))); - assertThat(example.getFullPath(), is(equalTo(String.format("%1$s%2$s", Region.SEPARATOR, "Example")))); - assertThat(example.getAttributes(), is(not(nullValue()))); - assertThat(defaultExpirationAttributes, is(not(nullValue()))); - assertThat(defaultExpirationAttributes.getTimeout(), is(equalTo(600))); - assertThat(defaultExpirationAttributes.getAction(), is(equalTo(ExpirationAction.DESTROY))); - assertThat(genericExpiration, is(instanceOf(CustomExpiry.class))); - assertThat(genericExpiration.getDefaultExpirationAttributes(), is(nullValue())); - assertThat(idleTimeoutExpiration, is(instanceOf(CustomExpiry.class))); - assertThat(idleTimeoutExpiration.getDefaultExpirationAttributes(), is(nullValue())); - assertThat(timeToLiveExpiration, is(instanceOf(CustomExpiry.class))); - assertThat(timeToLiveExpiration.getDefaultExpirationAttributes(), is(sameInstance(defaultExpirationAttributes))); + + assertThat(example).isNotNull(); + assertThat(example.getName()).isEqualTo("Example"); + assertThat(example.getFullPath()).isEqualTo(String.format("%1$s%2$s", Region.SEPARATOR, "Example")); + assertThat(example.getAttributes()).isNotNull(); + assertThat(defaultExpirationAttributes).isNotNull(); + assertThat(defaultExpirationAttributes.getTimeout()).isEqualTo(600); + assertThat(defaultExpirationAttributes.getAction()).isEqualTo(ExpirationAction.DESTROY); + assertThat(genericExpiration).isInstanceOf(CustomExpiry.class); + assertThat(genericExpiration.getDefaultExpirationAttributes()).isNull(); + assertThat(idleTimeoutExpiration).isInstanceOf(CustomExpiry.class); + assertThat(idleTimeoutExpiration.getDefaultExpirationAttributes()).isNull(); + assertThat(timeToLiveExpiration).isInstanceOf(CustomExpiry.class); + assertThat(timeToLiveExpiration.getDefaultExpirationAttributes()).isSameAs(defaultExpirationAttributes); } private void assertExpiration(ExpirationAttributes expected, ExpirationAttributes actual) { @@ -116,9 +104,9 @@ public class AnnotationBasedExpirationConfigurationIntegrationTest { private void assertExpiration(ExpirationAttributes expirationAttributes, int expectedTimeout, ExpirationAction expectedAction) { - assertThat(expirationAttributes, is(not(nullValue()))); - assertThat(expirationAttributes.getTimeout(), is(equalTo(expectedTimeout))); - assertThat(expirationAttributes.getAction(), is(equalTo(expectedAction))); + assertThat(expirationAttributes).isNotNull(); + assertThat(expirationAttributes.getTimeout()).isEqualTo(expectedTimeout); + assertThat(expirationAttributes.getAction()).isEqualTo(expectedAction); } @SuppressWarnings("unchecked") @@ -142,8 +130,8 @@ public class AnnotationBasedExpirationConfigurationIntegrationTest { 120, ExpirationAction.INVALIDATE); assertExpiration(expiration.getExpiry(mockRegionEntry(new ApplicationDomainObjectWithGenericExpirationPolicy())), 60, ExpirationAction.DESTROY); - assertThat(expiration.getExpiry(mockRegionEntry(new ApplicationDomainObjectWithNoExpirationPolicy())), is(nullValue())); - assertThat(expiration.getExpiry(mockRegionEntry(new RegionEntryTimeToLiveExpirationPolicy())), is(nullValue())); + assertThat(expiration.getExpiry(mockRegionEntry(new ApplicationDomainObjectWithNoExpirationPolicy()))).isNull(); + assertThat(expiration.getExpiry(mockRegionEntry(new RegionEntryTimeToLiveExpirationPolicy()))).isNull(); assertExpiration(expiration.getExpiry(mockRegionEntry(new RegionEntryIdleTimeoutExpirationPolicy())), 60, ExpirationAction.INVALIDATE); assertExpiration(expiration.getExpiry(mockRegionEntry(new RegionEntryGenericExpirationPolicy())), @@ -171,72 +159,75 @@ public class AnnotationBasedExpirationConfigurationIntegrationTest { @Test public void genericExpirationPolicy() { - assertExpiration(genericExpiration.getExpiry(mockRegionEntry( - new ApplicationDomainObjectWithTimeToLiveAndGenericExpirationPolicies())), 60, ExpirationAction.INVALIDATE); - assertThat(genericExpiration.getExpiry(mockRegionEntry( - new ApplicationDomainObjectWithIdleTimeoutExpirationPolicy())), is(nullValue())); - assertExpiration(genericExpiration.getExpiry(mockRegionEntry( - new ApplicationDomainObjectWithGenericExpirationPolicy())), 60, ExpirationAction.DESTROY); - assertThat(genericExpiration.getExpiry(mockRegionEntry( - new ApplicationDomainObjectWithNoExpirationPolicy())), is(nullValue())); - assertThat(genericExpiration.getExpiry(mockRegionEntry( - new RegionEntryTimeToLiveExpirationPolicy())), is(nullValue())); - assertThat(genericExpiration.getExpiry(mockRegionEntry( - new RegionEntryIdleTimeoutExpirationPolicy())), is(nullValue())); - assertExpiration(genericExpiration.getExpiry(mockRegionEntry( - new RegionEntryGenericExpirationPolicy())), 60, ExpirationAction.DESTROY); + assertExpiration(genericExpiration.getExpiry(mockRegionEntry(new ApplicationDomainObjectWithTimeToLiveAndGenericExpirationPolicies())), 60, ExpirationAction.INVALIDATE); + assertThat(genericExpiration.getExpiry(mockRegionEntry(new ApplicationDomainObjectWithIdleTimeoutExpirationPolicy()))).isNull(); + assertExpiration(genericExpiration.getExpiry(mockRegionEntry(new ApplicationDomainObjectWithGenericExpirationPolicy())), 60, ExpirationAction.DESTROY); + assertThat(genericExpiration.getExpiry(mockRegionEntry(new ApplicationDomainObjectWithNoExpirationPolicy()))).isNull(); + assertThat(genericExpiration.getExpiry(mockRegionEntry(new RegionEntryTimeToLiveExpirationPolicy()))).isNull(); + assertThat(genericExpiration.getExpiry(mockRegionEntry(new RegionEntryIdleTimeoutExpirationPolicy()))).isNull(); + assertExpiration(genericExpiration.getExpiry(mockRegionEntry(new RegionEntryGenericExpirationPolicy())), 60, ExpirationAction.DESTROY); } - @Test + @Test(expected = IllegalArgumentException.class) public void invalidExpirationAction() { - exception.expect(EvaluationException.class); - exception.expectCause(isA(IllegalArgumentException.class)); - exception.expectMessage(String.format("[%s] is not resolvable as an ExpirationAction(Type)", - "@expirationProperties['gemfire.region.entry.expiration.invalid.action.string']")); + try { + genericExpiration.getExpiry(mockRegionEntry(new RegionEntryWithInvalidExpirationAction())); + } + catch (EvaluationException expected) { - genericExpiration.getExpiry(mockRegionEntry(new RegionEntryWithInvalidExpirationAction())); + assertThat(expected).hasMessage("[%s] is not resolvable as an ExpirationAction(Type)", + "@expirationProperties['gemfire.region.entry.expiration.invalid.action.string']"); + assertThat(expected).hasCauseInstanceOf(IllegalArgumentException.class); + + throw expected; + } } - @Test + @Test(expected = IllegalArgumentException.class) public void invalidExpirationTimeout() { - exception.expect(IllegalArgumentException.class); - exception.expectCause(is(nullValue(Throwable.class))); + try { + genericExpiration.getExpiry(mockRegionEntry(new RegionEntryWithInvalidExpirationTimeout())); + } + catch (IllegalArgumentException expected) { - genericExpiration.getExpiry(mockRegionEntry(new RegionEntryWithInvalidExpirationTimeout())); + assertThat(expected).hasNoCause(); + + throw expected; + } } @Expiration(timeout = "60", action = "INVALIDATE") @TimeToLiveExpiration(timeout = "300", action = "DESTROY") - protected static class ApplicationDomainObjectWithTimeToLiveAndGenericExpirationPolicies { } + static class ApplicationDomainObjectWithTimeToLiveAndGenericExpirationPolicies { } @IdleTimeoutExpiration(timeout = "120", action = "INVALIDATE") - protected static class ApplicationDomainObjectWithIdleTimeoutExpirationPolicy { } + static class ApplicationDomainObjectWithIdleTimeoutExpirationPolicy { } @Expiration(timeout = "60", action = "DESTROY") - protected static class ApplicationDomainObjectWithGenericExpirationPolicy { } + static class ApplicationDomainObjectWithGenericExpirationPolicy { } - protected static class ApplicationDomainObjectWithNoExpirationPolicy { } + static class ApplicationDomainObjectWithNoExpirationPolicy { } @TimeToLiveExpiration(timeout = "${gemfire.region.entry.expiration.timeout}", action = "${gemfire.region.entry.expiration.action.string}") - protected static class RegionEntryTimeToLiveExpirationPolicy { } + static class RegionEntryTimeToLiveExpirationPolicy { } @IdleTimeoutExpiration(timeout = "@expirationProperties['gemfire.region.entry.expiration.timeout']", action = "@expirationProperties['gemfire.region.entry.expiration.action.gemfire.type']") - protected static class RegionEntryIdleTimeoutExpirationPolicy { } + static class RegionEntryIdleTimeoutExpirationPolicy { } @Expiration(timeout = "${gemfire.region.entry.expiration.timeout}", action = "@expirationProperties['gemfire.region.entry.expiration.action.spring.type']") - protected static class RegionEntryGenericExpirationPolicy { } + static class RegionEntryGenericExpirationPolicy { } @Expiration(timeout = "${gemfire.region.entry.expiration.timeout}", action = "@expirationProperties['gemfire.region.entry.expiration.invalid.action.string']") - protected static class RegionEntryWithInvalidExpirationAction { } + static class RegionEntryWithInvalidExpirationAction { } @Expiration(timeout = "${gemfire.region.entry.expiration.invalid.timeout}", action = "@expirationProperties['gemfire.region.entry.expiration.action.spring.type']") - protected static class RegionEntryWithInvalidExpirationTimeout { } + static class RegionEntryWithInvalidExpirationTimeout { } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/GemFireBasedServerProcess.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/GemFireBasedServerProcess.java index a1e77450..f06b6f27 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/GemFireBasedServerProcess.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/GemFireBasedServerProcess.java @@ -20,8 +20,8 @@ import java.io.File; import org.apache.geode.distributed.ServerLauncher; import org.springframework.data.gemfire.GemFireProperties; -import org.springframework.data.gemfire.process.support.ProcessUtils; -import org.springframework.data.gemfire.test.support.FileSystemUtils; +import org.springframework.data.gemfire.tests.process.ProcessUtils; +import org.springframework.data.gemfire.tests.util.FileSystemUtils; /** * The {@link GemFireBasedServerProcess} class is a main Java class used to launch a GemFire Server diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/LocatorProcess.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/LocatorProcess.java index 5000f02e..07394e91 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/LocatorProcess.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/LocatorProcess.java @@ -26,13 +26,13 @@ import org.apache.geode.distributed.internal.InternalLocator; import org.springframework.data.gemfire.GemFireProperties; import org.springframework.data.gemfire.GemfireUtils; -import org.springframework.data.gemfire.process.support.ProcessUtils; -import org.springframework.data.gemfire.test.support.FileSystemUtils; -import org.springframework.data.gemfire.test.support.ThreadUtils; +import org.springframework.data.gemfire.tests.process.ProcessUtils; +import org.springframework.data.gemfire.tests.util.FileSystemUtils; +import org.springframework.data.gemfire.tests.util.ThreadUtils; /** - * The {@link LocatorProcess} class is a main Java class that is used fork and launch a {@link Locator} process - * using the {@link LocatorLauncher} class. + * The {@link LocatorProcess} class is a main Java class that is used fork and launch an Apache Geode {@link Locator} + * process using the {@link LocatorLauncher} class. * * @author John Blum * @see org.apache.geode.distributed.Locator diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/ServerProcess.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/ServerProcess.java index 5d15bba8..1d3e9776 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/ServerProcess.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/ServerProcess.java @@ -20,8 +20,8 @@ import java.io.IOException; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.data.gemfire.process.support.ProcessUtils; -import org.springframework.data.gemfire.test.support.FileSystemUtils; +import org.springframework.data.gemfire.tests.process.ProcessUtils; +import org.springframework.data.gemfire.tests.util.FileSystemUtils; import org.springframework.util.Assert; import org.slf4j.Logger; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/ClientCacheFunctionExecutionWithPdxIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/ClientCacheFunctionExecutionWithPdxIntegrationTest.java index da4c93a6..1c3d8f83 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/ClientCacheFunctionExecutionWithPdxIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/ClientCacheFunctionExecutionWithPdxIntegrationTest.java @@ -23,7 +23,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -42,15 +41,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.gemfire.fork.ServerProcess; import org.springframework.data.gemfire.function.annotation.GemfireFunction; import org.springframework.data.gemfire.function.sample.ApplicationDomainFunctionExecutions; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; /** - * Integration Test for SDG's Function annotation support and interaction between an Apache Geode client + * Integration Tests for SDG's Function annotation support and interaction between an Apache Geode client * and server cache when PDX is configured and read-serialized is set to {@literal true}. * * @author John Blum @@ -64,8 +62,7 @@ import org.springframework.util.ObjectUtils; * @see org.apache.geode.pdx.internal.PdxInstanceEnum * @see org.springframework.data.gemfire.function.annotation.GemfireFunction * @see org.springframework.data.gemfire.function.sample.ApplicationDomainFunctionExecutions - * @see org.springframework.data.gemfire.process.ProcessWrapper - * @see org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 1.5.2 @@ -74,9 +71,7 @@ import org.springframework.util.ObjectUtils; @ContextConfiguration @SuppressWarnings("unused") // TODO: Convert to a ClientCache test. -public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientServerIntegrationTestsSupport { - - private static ProcessWrapper gemfireServer; +public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ForkingClientServerIntegrationTestsSupport { @Autowired private ClientCache gemfireClientCache; @@ -86,22 +81,8 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe @BeforeClass public static void startGemFireServer() throws Exception { - - int availablePort = findAvailablePort(); - - gemfireServer = run(ServerProcess.class, - String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort), + startGemFireServer(ServerProcess.class, getServerContextXmlFileLocation(ClientCacheFunctionExecutionWithPdxIntegrationTest.class)); - - waitForServerToStart(DEFAULT_HOSTNAME, availablePort); - - System.setProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY, String.valueOf(availablePort)); - } - - @AfterClass - public static void stopGemFireServer() { - System.clearProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY); - stop(gemfireServer); } private PdxInstance toPdxInstance(Map pdxData) { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTests.java similarity index 87% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTests.java index ab4a92cc..9677aded 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTests.java @@ -35,10 +35,11 @@ import org.apache.geode.cache.execute.FunctionException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.gemfire.fork.ServerProcess; import org.springframework.data.gemfire.function.sample.ExceptionThrowingFunctionExecution; -import org.springframework.data.gemfire.process.ProcessExecutor; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.FileSystemUtils; -import org.springframework.data.gemfire.test.support.ThreadUtils; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.process.ProcessExecutor; +import org.springframework.data.gemfire.tests.process.ProcessWrapper; +import org.springframework.data.gemfire.tests.util.FileSystemUtils; +import org.springframework.data.gemfire.tests.util.ThreadUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.Assert; @@ -64,7 +65,7 @@ import org.springframework.util.Assert; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class ExceptionThrowingFunctionExecutionIntegrationTest { +public class ExceptionThrowingFunctionExecutionIntegrationTests extends IntegrationTestsSupport { private static ProcessWrapper gemfireServer; @@ -74,7 +75,7 @@ public class ExceptionThrowingFunctionExecutionIntegrationTest { @BeforeClass public static void startGemFireServer() throws IOException { - String serverName = ExceptionThrowingFunctionExecutionIntegrationTest.class.getSimpleName().concat("Server"); + String serverName = ExceptionThrowingFunctionExecutionIntegrationTests.class.getSimpleName().concat("Server"); File serverWorkingDirectory = new File(FileSystemUtils.WORKING_DIRECTORY, serverName.toLowerCase()); @@ -85,7 +86,8 @@ public class ExceptionThrowingFunctionExecutionIntegrationTest { arguments.add("-Dgemfire.name=" + serverName); arguments.add("-Dgemfire.log-level=error"); - arguments.add(ExceptionThrowingFunctionExecutionIntegrationTest.class.getName().replace(".", "/") + arguments.add(ExceptionThrowingFunctionExecutionIntegrationTests.class.getName() + .replace(".", "/") .concat("-server-context.xml")); gemfireServer = ProcessExecutor.launch(serverWorkingDirectory, ServerProcess.class, @@ -96,13 +98,13 @@ public class ExceptionThrowingFunctionExecutionIntegrationTest { private static void waitForServerStart(final long milliseconds) { - ThreadUtils.timedWait(milliseconds, TimeUnit.MILLISECONDS.toMillis(500), new ThreadUtils.WaitCondition() { + ThreadUtils.timedWait(milliseconds, TimeUnit.MILLISECONDS.toMillis(500), new ThreadUtils.Condition() { - private File serverPidControlFile = new File(gemfireServer.getWorkingDirectory(), + private final File serverPidControlFile = new File(gemfireServer.getWorkingDirectory(), ServerProcess.getServerProcessControlFilename()); @Override - public boolean waiting() { + public boolean evaluate() { return !serverPidControlFile.isFile(); } }); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionExecutionIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionExecutionIntegrationTests.java index 41f4083d..531fefc1 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionExecutionIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionExecutionIntegrationTests.java @@ -12,14 +12,13 @@ */ package org.springframework.data.gemfire.function.config; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; - -import org.apache.geode.cache.Region; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.Region; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Configuration; @@ -28,39 +27,42 @@ import org.springframework.data.gemfire.TestUtils; import org.springframework.data.gemfire.function.config.two.TestOnRegionFunction; import org.springframework.data.gemfire.function.execution.GemfireOnRegionFunctionTemplate; import org.springframework.data.gemfire.function.execution.OnRegionFunctionProxyFactoryBean; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** * @author David Turanski - * + * @author John Blum */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { TestConfig.class }, initializers = GemfireTestApplicationContextInitializer.class) -public class FunctionExecutionIntegrationTests { +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = TestConfig.class, initializers = GemFireMockObjectsApplicationContextInitializer.class) +@SuppressWarnings("unused") +public class FunctionExecutionIntegrationTests extends IntegrationTestsSupport { + @Autowired - ApplicationContext context; + private ApplicationContext applicationContext; @Test public void testProxyFactoryBeanCreated() throws Exception { - OnRegionFunctionProxyFactoryBean factoryBean = (OnRegionFunctionProxyFactoryBean) context - .getBean("&testFunction"); - Class serviceInterface = TestUtils.readField("functionExecutionInterface", factoryBean); - assertEquals(serviceInterface, TestOnRegionFunction.class); - Region r1 = context.getBean("r1", Region.class); + OnRegionFunctionProxyFactoryBean factoryBean = + applicationContext.getBean("&testFunction", OnRegionFunctionProxyFactoryBean.class); + + Class serviceInterface = TestUtils.readField("functionExecutionInterface", factoryBean); + + assertThat(TestOnRegionFunction.class).isEqualTo(serviceInterface); + + Region regionOne = applicationContext.getBean("r1", Region.class); GemfireOnRegionFunctionTemplate template = TestUtils.readField("gemfireFunctionOperations", factoryBean); - assertSame(r1, TestUtils.readField("region", template)); + assertThat(TestUtils.>readField("region", template)).isSameAs(regionOne); } - } -@ImportResource("/org/springframework/data/gemfire/function/config/FunctionExecutionIntegrationTests-context.xml") -@EnableGemfireFunctionExecutions(basePackages = "org.springframework.data.gemfire.function.config.two") @Configuration -class TestConfig { - -} +@EnableGemfireFunctionExecutions(basePackages = "org.springframework.data.gemfire.function.config.two") +@ImportResource("/org/springframework/data/gemfire/function/config/FunctionExecutionIntegrationTests-context.xml") +class TestConfig { } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionsWithClientCacheTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionsWithClientCacheTests.java index 491c2049..4fe1fcc8 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionsWithClientCacheTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionsWithClientCacheTests.java @@ -15,21 +15,20 @@ package org.springframework.data.gemfire.function.config; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** * @author David Turanski * @author John Blum */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class) +@RunWith(SpringRunner.class) +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) public class FunctionsWithClientCacheTests { @Test public void doNothing() { // Just make sure this comes up for SGF-186. } - } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/XmlConfiguredFunctionExecutionIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/XmlConfiguredFunctionExecutionIntegrationTests.java index 1c6f5bf8..99d4f81c 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/XmlConfiguredFunctionExecutionIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/XmlConfiguredFunctionExecutionIntegrationTests.java @@ -12,46 +12,49 @@ */ package org.springframework.data.gemfire.function.config; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; - -import org.apache.geode.cache.Region; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.Region; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.TestUtils; import org.springframework.data.gemfire.function.config.two.TestOnRegionFunction; import org.springframework.data.gemfire.function.execution.GemfireOnRegionFunctionTemplate; import org.springframework.data.gemfire.function.execution.OnRegionFunctionProxyFactoryBean; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** * @author David Turanski - * + * @author John Blum */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class) +@RunWith(SpringRunner.class) +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) +@SuppressWarnings("unused") public class XmlConfiguredFunctionExecutionIntegrationTests { + @Autowired - ApplicationContext context; + private ApplicationContext applicationContext; @Test public void testProxyFactoryBeanCreated() throws Exception { - OnRegionFunctionProxyFactoryBean factoryBean = (OnRegionFunctionProxyFactoryBean) context - .getBean("&testFunction"); - Class serviceInterface = TestUtils.readField("functionExecutionInterface", factoryBean); - assertEquals(serviceInterface, TestOnRegionFunction.class); - Region r1 = context.getBean("r1", Region.class); + OnRegionFunctionProxyFactoryBean factoryBean = + applicationContext.getBean("&testFunction", OnRegionFunctionProxyFactoryBean.class); + + Class serviceInterface = TestUtils.readField("functionExecutionInterface", factoryBean); + + assertThat(TestOnRegionFunction.class).isEqualTo(serviceInterface); + + Region regionOne = applicationContext.getBean("r1", Region.class); GemfireOnRegionFunctionTemplate template = TestUtils.readField("gemfireFunctionOperations", factoryBean); - assertSame(r1, TestUtils.readField("region", template)); + assertThat(TestUtils.readField("region", template)).isSameAs(regionOne); } - } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/FunctionExecutionIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/FunctionExecutionIntegrationTests.java index 78f437fc..0a808f95 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/FunctionExecutionIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/FunctionExecutionIntegrationTests.java @@ -14,13 +14,13 @@ package org.springframework.data.gemfire.function.execution; import static org.assertj.core.api.Assertions.assertThat; +import java.util.Optional; + import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.apache.geode.cache.CacheClosedException; import org.apache.geode.cache.Region; import org.apache.geode.cache.client.ClientCache; import org.apache.geode.cache.client.ClientCacheFactory; @@ -30,44 +30,32 @@ import org.apache.geode.cache.client.Pool; import org.springframework.data.gemfire.client.PoolResolver; import org.springframework.data.gemfire.client.support.PoolManagerPoolResolver; import org.springframework.data.gemfire.fork.FunctionCacheServerProcess; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.util.SpringUtils; /** + * Integration Tests for SDG Function support. + * * @author David Turanski * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.Region + * @see org.apache.geode.cache.execute.Function + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport */ -public class FunctionExecutionIntegrationTests extends ClientServerIntegrationTestsSupport { - - private static int availablePort; - - private static ProcessWrapper gemfireServer; +public class FunctionExecutionIntegrationTests extends ForkingClientServerIntegrationTestsSupport { private ClientCache gemfireCache = null; private Pool gemfirePool = null; - private PoolResolver poolResolver = new PoolManagerPoolResolver(); + private final PoolResolver poolResolver = new PoolManagerPoolResolver(); private Region gemfireRegion = null; @BeforeClass public static void startGemFireServer() throws Exception { - - availablePort = findAvailablePort(); - - gemfireServer = run(FunctionCacheServerProcess.class, - String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort)); - - waitForServerToStart(DEFAULT_HOSTNAME, availablePort); - - System.setProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY, String.valueOf(availablePort)); - } - - @AfterClass - public static void stopGemFireServer() { - System.clearProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY); - stop(gemfireServer); + startGemFireServer(FunctionCacheServerProcess.class); } @Before @@ -77,7 +65,7 @@ public class FunctionExecutionIntegrationTests extends ClientServerIntegrationTe .set("name", FunctionExecutionIntegrationTests.class.getSimpleName()) .set("log-level", "error") .setPoolSubscriptionEnabled(true) - .addPoolServer("localhost", availablePort) + .addPoolServer("localhost", Integer.getInteger(GEMFIRE_POOL_SERVERS_PROPERTY)) .create(); assertThat(this.gemfireCache).isNotNull(); @@ -97,14 +85,7 @@ public class FunctionExecutionIntegrationTests extends ClientServerIntegrationTe @After public void tearDownGemFireClient() { - - if (this.gemfireCache != null) { - try { - this.gemfireCache.close(); - } - catch (CacheClosedException ignore) { - } - } + Optional.ofNullable(this.gemfireCache).ifPresent(cache -> SpringUtils.safeDoOperation(() -> cache.close())); } @Test diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/FunctionIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/FunctionIntegrationTests.java index 99d274f8..f109b46e 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/FunctionIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/FunctionIntegrationTests.java @@ -24,7 +24,6 @@ import java.util.Map; import javax.annotation.Resource; -import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -36,45 +35,37 @@ import org.apache.geode.cache.execute.Function; import org.springframework.data.gemfire.fork.ServerProcess; import org.springframework.data.gemfire.function.annotation.GemfireFunction; import org.springframework.data.gemfire.function.annotation.RegionData; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.stereotype.Component; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** + * Integration Tests for SDG Function support. + * * @author David Turanski * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.Region + * @see org.apache.geode.cache.execute.Function + * @see org.springframework.data.gemfire.function.annotation.GemfireFunction + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class FunctionIntegrationTests extends ClientServerIntegrationTestsSupport { - - private static ProcessWrapper gemfireServer; - - @Resource(name = "TestRegion") - private Region region; +public class FunctionIntegrationTests extends ForkingClientServerIntegrationTestsSupport { @BeforeClass public static void startGemFireServer() throws Exception { - - int availablePort = findAvailablePort(); - - gemfireServer = run(ServerProcess.class, - String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort), + startGemFireServer(ServerProcess.class, getServerContextXmlFileLocation(FunctionIntegrationTests.class)); - - waitForServerToStart(DEFAULT_HOSTNAME, availablePort); - - System.setProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY, String.valueOf(availablePort)); } - @AfterClass - public static void stopGemFireServer() { - System.clearProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY); - stop(gemfireServer); - } + @Resource(name = "TestRegion") + private Region region; @Before public void initializeRegion() { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/GemfireFunctionTemplateIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/GemfireFunctionTemplateIntegrationTests.java index 617f53f4..30e34405 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/GemfireFunctionTemplateIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/GemfireFunctionTemplateIntegrationTests.java @@ -12,10 +12,9 @@ */ package org.springframework.data.gemfire.function.execution; -import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -30,43 +29,32 @@ import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.client.PoolResolver; import org.springframework.data.gemfire.client.support.PoolManagerPoolResolver; import org.springframework.data.gemfire.fork.FunctionCacheServerProcess; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; /** + * Integration Tests for Apache Geode Function templates. + * * @author David Turanski + * @author John Blum + * @see org.apache.geode.cache.Region + * @see org.apache.geode.cache.client.ClientCache + * @see org.apache.geode.cache.client.ClientCacheFactory + * @see org.apache.geode.cache.client.Pool + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport */ -public class GemfireFunctionTemplateIntegrationTests extends ClientServerIntegrationTestsSupport { - - private static int availablePort; - - private static ProcessWrapper gemfireServer; +public class GemfireFunctionTemplateIntegrationTests extends ForkingClientServerIntegrationTestsSupport { private ClientCache gemfireCache = null; private Pool gemfirePool = null; - private PoolResolver poolResolver = new PoolManagerPoolResolver(); + private final PoolResolver poolResolver = new PoolManagerPoolResolver(); private Region gemfireRegion = null; @BeforeClass - public static void startGemFireServer() throws Exception { - - availablePort = findAvailablePort(); - - gemfireServer = run(FunctionCacheServerProcess.class, - String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort)); - - waitForServerToStart(DEFAULT_HOSTNAME, availablePort); - - System.setProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY, String.valueOf(availablePort)); - } - - @AfterClass - public static void stopGemFireServer() { - System.clearProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY); - stop(gemfireServer); + public static void startGeodeServer() throws Exception { + startGemFireServer(FunctionCacheServerProcess.class); } @Before @@ -76,7 +64,7 @@ public class GemfireFunctionTemplateIntegrationTests extends ClientServerIntegra .set("name", GemfireFunctionTemplateIntegrationTests.class.getSimpleName()) .set("log-level", "error") .setPoolSubscriptionEnabled(true) - .addPoolServer("localhost", availablePort) + .addPoolServer("localhost", Integer.getInteger(GEMFIRE_POOL_SERVERS_PROPERTY)) .create(); assertThat(this.gemfireCache).isNotNull(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/onservers/FunctionsReturnResultsFromAllServersIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/onservers/FunctionsReturnResultsFromAllServersIntegrationTests.java index 5cbee5fc..6c7364d2 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/onservers/FunctionsReturnResultsFromAllServersIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/onservers/FunctionsReturnResultsFromAllServersIntegrationTests.java @@ -36,19 +36,25 @@ import org.springframework.data.gemfire.function.config.EnableGemfireFunctions; import org.springframework.data.gemfire.function.sample.AllServersAdminFunctions; import org.springframework.data.gemfire.function.sample.Metric; import org.springframework.data.gemfire.function.sample.SingleServerAdminFunctions; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.process.ProcessWrapper; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.EnableTransactionManagement; /** * @author Patrick Johnson + * @author John Blum + * @see org.junit.Test + * @see org.springframework.data.gemfire.function.annotation.GemfireFunction + * @see org.springframework.data.gemfire.function.config.EnableGemfireFunctionExecutions + * @see org.springframework.data.gemfire.function.config.EnableGemfireFunctions + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport */ @SuppressWarnings("unused") @RunWith(SpringRunner.class) @ContextConfiguration(classes = FunctionsReturnResultsFromAllServersIntegrationTests.TestConfiguration.class) -public class FunctionsReturnResultsFromAllServersIntegrationTests extends ClientServerIntegrationTestsSupport { +public class FunctionsReturnResultsFromAllServersIntegrationTests extends ForkingClientServerIntegrationTestsSupport { private static final int NUMBER_OF_METRICS = 10; @@ -89,7 +95,9 @@ public class FunctionsReturnResultsFromAllServersIntegrationTests extends Client @Test public void executeFunctionOnAllServers() { + List> metrics = allServersAdminFunctions.getAllMetrics(); + assertThat(metrics.size()).isEqualTo(2); assertThat(metrics.get(0).size()).isEqualTo(NUMBER_OF_METRICS); assertThat(metrics.get(1).size()).isEqualTo(NUMBER_OF_METRICS); @@ -97,15 +105,16 @@ public class FunctionsReturnResultsFromAllServersIntegrationTests extends Client @Test public void executeFunctionOnSingleServer() { + List metrics = singleServerAdminFunctions.getAllMetrics(); + assertThat(metrics.size()).isEqualTo(NUMBER_OF_METRICS); } @ClientCacheApplication @EnableGemfireFunctionExecutions(basePackageClasses = AllServersAdminFunctions.class) @EnableTransactionManagement - static class TestConfiguration { - } + static class TestConfiguration { } @CacheServerApplication @EnableGemfireFunctions @@ -121,11 +130,14 @@ public class FunctionsReturnResultsFromAllServersIntegrationTests extends Client @GemfireFunction(id = "GetAllMetricsFunction", hasResult = true) public List getMetrics() { + List allMetrics = new ArrayList<>(); + for (int i = 0; i < NUMBER_OF_METRICS; i++) { Metric metric = new Metric("statName" + i, i, "statCat" + i, "statType" + i); allMetrics.add(metric); } + return allMetrics; } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/result/FunctionResultTypeIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/result/FunctionResultTypeIntegrationTests.java similarity index 93% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/function/result/FunctionResultTypeIntegrationTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/function/result/FunctionResultTypeIntegrationTests.java index a811b3db..ba4e771f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/result/FunctionResultTypeIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/result/FunctionResultTypeIntegrationTests.java @@ -32,7 +32,7 @@ import org.springframework.data.gemfire.function.annotation.GemfireFunction; import org.springframework.data.gemfire.function.annotation.OnRegion; import org.springframework.data.gemfire.function.config.EnableGemfireFunctionExecutions; import org.springframework.data.gemfire.function.config.EnableGemfireFunctions; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -48,14 +48,14 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.data.gemfire.function.annotation.OnRegion * @see org.springframework.data.gemfire.function.config.EnableGemfireFunctionExecutions * @see org.springframework.data.gemfire.function.config.EnableGemfireFunctions - * @see org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration(classes = FunctionResultTypeIntegrationTest.TestGeodeConfiguration.class) +@ContextConfiguration(classes = FunctionResultTypeIntegrationTests.TestGeodeConfiguration.class) @SuppressWarnings("unused") -public class FunctionResultTypeIntegrationTest extends ClientServerIntegrationTestsSupport { +public class FunctionResultTypeIntegrationTests extends IntegrationTestsSupport { @Autowired private FunctionExecutions functionExecutions; @@ -78,7 +78,7 @@ public class FunctionResultTypeIntegrationTest extends ClientServerIntegrationTe assertThat(num).isEqualTo(7); } - @PeerCacheApplication(name = "FunctionResultTypeIntegrationTest") + @PeerCacheApplication(name = "FunctionResultTypeIntegrationTests") @EnableGemfireFunctionExecutions(basePackageClasses = FunctionExecutions.class) @EnableGemfireFunctions public static class TestGeodeConfiguration { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/ListenerContainerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/ListenerContainerIntegrationTests.java index c5ccc604..bbe0b4c9 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/ListenerContainerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/ListenerContainerIntegrationTests.java @@ -13,44 +13,41 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.listener; import static org.assertj.core.api.Assertions.assertThat; import java.util.EventListener; import java.util.List; +import java.util.Optional; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; -import org.apache.geode.cache.CacheClosedException; -import org.apache.geode.cache.client.ClientCache; -import org.apache.geode.cache.client.ClientCacheFactory; -import org.apache.geode.cache.query.CqEvent; - import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.apache.geode.cache.client.ClientCache; +import org.apache.geode.cache.client.ClientCacheFactory; +import org.apache.geode.cache.query.CqEvent; + import org.springframework.data.gemfire.fork.CqCacheServerProcess; import org.springframework.data.gemfire.listener.adapter.ContinuousQueryListenerAdapter; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.util.SpringUtils; /** * @author Costin Leau + * @author John Blum */ -public class ListenerContainerIntegrationTests extends ClientServerIntegrationTestsSupport { - - private static int availablePort; - - private static ProcessWrapper gemfireServer; +public class ListenerContainerIntegrationTests extends ForkingClientServerIntegrationTestsSupport { private ClientCache gemfireCache = null; private final ContinuousQueryListenerAdapter adapter = new ContinuousQueryListenerAdapter(new EventListener() { + + @SuppressWarnings("unused") public void handleEvent(CqEvent event) { cqEvents.add(event); } @@ -62,29 +59,17 @@ public class ListenerContainerIntegrationTests extends ClientServerIntegrationTe @BeforeClass public static void startGemFireServer() throws Exception { - availablePort = findAvailablePort(); - - gemfireServer = run(CqCacheServerProcess.class, - String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort)); - - waitForServerToStart(DEFAULT_HOSTNAME, availablePort); - - System.setProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY, String.valueOf(availablePort)); - } - - @AfterClass - public static void stopGemFireServer() { - System.clearProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY); - stop(gemfireServer); + startGemFireServer(CqCacheServerProcess.class); } @Before - public void setupGemFireClient() throws Exception { + public void setupGemFireClient() { + gemfireCache = new ClientCacheFactory() .set("name", "ListenerContainerIntegrationTests") .set("log-level", "warning") .setPoolSubscriptionEnabled(true) - .addPoolServer(DEFAULT_HOSTNAME, availablePort) + .addPoolServer(DEFAULT_HOSTNAME, Integer.getInteger(GEMFIRE_POOL_SERVERS_PROPERTY)) .create(); String query = "SELECT * from /test-cq"; @@ -98,20 +83,17 @@ public class ListenerContainerIntegrationTests extends ClientServerIntegrationTe } @After - public void tearDownGemFireClient() { - if (gemfireCache != null) { - try { - gemfireCache.close(); - } - catch (CacheClosedException ignore) { - } - } + public void closeGemFireClient() { + + Optional.ofNullable(this.gemfireCache) + .ifPresent(cache -> SpringUtils.safeDoOperation(() -> cache.close())); } @Test - public void testContainer() throws Exception { - gemfireServer.signal(); - waitOn(() -> cqEvents.size() == 3, TimeUnit.SECONDS.toMillis(5)); - assertThat(cqEvents.size()).isEqualTo(3); + public void testContainer() { + + waitOn(() -> this.cqEvents.size() == 3, TimeUnit.SECONDS.toMillis(5)); + + assertThat(this.cqEvents.size()).isEqualTo(3); } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/adapter/ContainerXmlSetupIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/adapter/ContainerXmlSetupIntegrationTests.java index e6e12a8b..1e5e126f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/adapter/ContainerXmlSetupIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/adapter/ContainerXmlSetupIntegrationTests.java @@ -13,61 +13,51 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.listener.adapter; import static org.assertj.core.api.Assertions.assertThat; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + import org.apache.geode.cache.client.ClientCache; import org.apache.geode.cache.client.Pool; import org.apache.geode.cache.query.CqQuery; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.fork.CqCacheServerProcess; import org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** + * Integration Tests for CQ Listener Container + * * @author Costin Leau * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.client.ClientCache + * @see org.apache.geode.cache.query.CqQuery + * @see org.springframework.data.gemfire.fork.CqCacheServerProcess + * @see org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") // TODO change this test to use mocks!! -public class ContainerXmlSetupIntegrationTests extends ClientServerIntegrationTestsSupport { - - private static ProcessWrapper gemfireServer; +public class ContainerXmlSetupIntegrationTests extends ForkingClientServerIntegrationTestsSupport { @BeforeClass public static void startGemFireServer() throws Exception { - - int availablePort = findAvailablePort(); - - gemfireServer = run(CqCacheServerProcess.class, - String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort)); - - waitForServerToStart(DEFAULT_HOSTNAME, availablePort); - - System.setProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY, String.valueOf(availablePort)); + startGemFireServer(CqCacheServerProcess.class); } - @AfterClass - public static void stopGemFireServer() { - System.clearProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY); - stop(gemfireServer); - } - - @Autowired private ApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/ProcessConfiguration.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/ProcessConfiguration.java deleted file mode 100644 index 21775a49..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/ProcessConfiguration.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.process; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.springframework.data.gemfire.test.support.FileSystemUtils; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -/** - * The {@link ProcessConfiguration} class is a container encapsulating configuration and context meta-data - * for a running process. - * - * @author John Blum - * @see java.lang.ProcessBuilder - * @see org.springframework.data.gemfire.process.ProcessExecutor - * @since 1.5.0 - */ -@SuppressWarnings("unused") -public class ProcessConfiguration { - - private final boolean redirectingErrorStream; - - private final File workingDirectory; - - private final List command; - - private final Map environment; - - public static ProcessConfiguration create(ProcessBuilder processBuilder) { - Assert.notNull(processBuilder, "The ProcessBuilder used to configure and start the Process must not be null"); - - return new ProcessConfiguration(processBuilder.command(), processBuilder.directory(), - processBuilder.environment(), processBuilder.redirectErrorStream()); - } - - public ProcessConfiguration(List command, File workingDirectory, Map environment, - boolean redirectErrorStream) { - - Assert.notEmpty(command, "Process command must be specified"); - - Assert.isTrue(FileSystemUtils.isDirectory(workingDirectory), String.format( - "Process working directory [%s] is not valid", workingDirectory)); - - this.command = new ArrayList(command); - this.workingDirectory = workingDirectory; - this.redirectingErrorStream = redirectErrorStream; - - this.environment = (environment != null - ? Collections.unmodifiableMap(new HashMap(environment)) - : Collections.emptyMap()); - } - - public List getCommand() { - return Collections.unmodifiableList(command); - } - - public String getCommandString() { - return StringUtils.arrayToDelimitedString(getCommand().toArray(), " "); - } - - public Map getEnvironment() { - return environment; - } - - public boolean isRedirectingErrorStream() { - return redirectingErrorStream; - } - - public File getWorkingDirectory() { - return workingDirectory; - } - - @Override - public String toString() { - return "{ command = ".concat(getCommandString()) - .concat(", workingDirectory = ".concat(getWorkingDirectory().getAbsolutePath())) - .concat(", environment = ".concat(String.valueOf(getEnvironment()))) - .concat(", redirectingErrorStream = ".concat(String.valueOf(isRedirectingErrorStream()))) - .concat(" }"); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/ProcessExecutor.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/ProcessExecutor.java deleted file mode 100644 index eb54e489..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/ProcessExecutor.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.gemfire.process; - -import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -import org.springframework.data.gemfire.test.support.FileSystemUtils; -import org.springframework.data.gemfire.util.CollectionUtils; -import org.springframework.data.gemfire.util.JavaVersion; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -/** - * The {@link ProcessExecutor} class is a utility class for launching and running Java processes. - * - * @author John Blum - * @see java.io.File - * @see java.lang.Process - * @see java.lang.ProcessBuilder - * @see java.lang.System - * @see org.springframework.data.gemfire.process.ProcessConfiguration - * @see org.springframework.data.gemfire.process.ProcessWrapper - * @since 1.5.0 - */ -@SuppressWarnings("unused") -public abstract class ProcessExecutor { - - public static final File JAVA_EXE = new File(new File(FileSystemUtils.JAVA_HOME, "bin"), "java"); - - public static final String JAVA_CLASSPATH = System.getProperty("java.class.path"); - - protected static final String SPRING_GEMFIRE_SYSTEM_PROPERTY_PREFIX = "spring.gemfire."; - protected static final String SPRING_DATA_GEMFIRE_SYSTEM_PROPERTY_PREFIX = "spring.data.gemfire."; - - public static ProcessWrapper launch(Class type, String... args) throws IOException { - return launch(FileSystemUtils.WORKING_DIRECTORY, type, args); - } - - public static ProcessWrapper launch(File workingDirectory, Class type, String... args) throws IOException { - return launch(workingDirectory, JAVA_CLASSPATH, type, args); - } - - public static ProcessWrapper launch(File workingDirectory, String classpath, Class type, String... args) - throws IOException { - - ProcessBuilder processBuilder = new ProcessBuilder() - .command(buildCommand(classpath, type, args)) - .directory(validateDirectory(workingDirectory)) - .redirectErrorStream(true); - - Process process = processBuilder.start(); - - ProcessWrapper processWrapper = new ProcessWrapper(process, ProcessConfiguration.create(processBuilder)); - - //processWrapper.register((input) -> System.err.printf("[FORK] - %s%n", input)); - - return processWrapper; - } - - protected static String[] buildCommand(String classpath, Class type, String... args) { - - Assert.notNull(type, "The main Java class to launch must not be null"); - - List command = new ArrayList<>(); - List programArguments = new ArrayList<>(args.length); - - command.add(JAVA_EXE.getAbsolutePath()); - command.add("-server"); - command.add("-ea"); - configureJava16JvmOptions(command); - command.add("-classpath"); - command.add(StringUtils.hasText(classpath) ? classpath : JAVA_CLASSPATH); - command.addAll(getSpringGemFireSystemProperties()); - - for (String arg : nullSafeArray(args, String.class)) { - if (isJvmOption(arg)) { - command.add(arg); - } - else if (StringUtils.hasText(arg)) { - programArguments.add(arg); - } - } - - command.add(type.getName()); - command.addAll(programArguments); - - //System.err.printf("JAVA COMMAND (%s)%n", toExecutableCommandString(command)); - //System.err.flush(); - - return command.toArray(new String[0]); - } - - private static String toExecutableCommandString(Iterable command) { - - StringBuilder commandString = new StringBuilder(); - - for (String commandPart : CollectionUtils.nullSafeIterable(command)) { - commandString.append(" ").append(commandPart); - } - - return commandString.toString().trim(); - } - - protected static List configureJava16JvmOptions(List command) { - - if (JavaVersion.current().isNewerThanOrEqualTo(JavaVersion.SIXTEEN)) { - command.add("--add-opens"); - command.add("java.base/java.lang=ALL-UNNAMED"); - command.add("--add-opens"); - command.add("java.base/java.nio=ALL-UNNAMED"); - command.add("--add-opens"); - command.add("java.base/java.util=ALL-UNNAMED"); - } - - return command; - } - - protected static Collection getSpringGemFireSystemProperties() { - - return System.getProperties().stringPropertyNames().stream() - .filter(property -> property.startsWith(SPRING_DATA_GEMFIRE_SYSTEM_PROPERTY_PREFIX) - || property.startsWith(SPRING_GEMFIRE_SYSTEM_PROPERTY_PREFIX)) - .map(property -> String.format("-D%1$s=%2$s", property, System.getProperty(property))) - .collect(Collectors.toList()); - } - - protected static boolean isJvmOption(String option) { - return StringUtils.hasText(option) && (option.startsWith("-D") || option.startsWith("-X")); - } - - protected static File validateDirectory(File workingDirectory) { - - Assert.isTrue(workingDirectory != null && (workingDirectory.isDirectory() || workingDirectory.mkdirs()), - String.format("Failed to create working directory [%s]", workingDirectory)); - - return workingDirectory; - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/ProcessInputStreamListener.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/ProcessInputStreamListener.java deleted file mode 100644 index a41616dc..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/ProcessInputStreamListener.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.process; - -import java.util.EventListener; - -/** - * The {@link ProcessInputStreamListener} is a callback interface that gets called when input arrives from either a - * {@link Process process's} standard output steam or standard error stream. - * - * @author John Blum - * @see java.util.EventListener - * @since 1.5.0 - */ -public interface ProcessInputStreamListener extends EventListener { - - /** - * Callback method that gets called when the {@link Process} sends output from either its standard out - * or standard error streams. - * - * @param input {@link String} containing output from the {@link Process} that this listener is listening to. - * @see java.lang.Process#getErrorStream() - * @see java.lang.Process#getInputStream() - */ - void onInput(String input); - -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/ProcessWrapper.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/ProcessWrapper.java deleted file mode 100644 index e55c8963..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/ProcessWrapper.java +++ /dev/null @@ -1,337 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.process; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.springframework.data.gemfire.process.support.PidUnavailableException; -import org.springframework.data.gemfire.process.support.ProcessUtils; -import org.springframework.data.gemfire.test.support.FileSystemUtils; -import org.springframework.data.gemfire.test.support.FileUtils; -import org.springframework.data.gemfire.test.support.IOUtils; -import org.springframework.data.gemfire.test.support.ThreadUtils; -import org.springframework.data.gemfire.test.support.ThrowableUtils; -import org.springframework.util.Assert; - -/** - * The ProcessWrapper class is a wrapper for a Process object representing an OS process and the ProcessBuilder used - * to construct and start the process. - * - * @author John Blum - * @see java.lang.Process - * @see java.lang.ProcessBuilder - * @since 1.5.0 - */ -@SuppressWarnings("unused") -public class ProcessWrapper { - - protected static final boolean DEFAULT_DAEMON_THREAD = true; - - protected static final long DEFAULT_WAIT_TIME_MILLISECONDS = TimeUnit.SECONDS.toMillis(5); - - private final List listeners = new CopyOnWriteArrayList<>(); - - protected final Logger log = Logger.getLogger(getClass().getName()); - - private final Process process; - private final ProcessConfiguration processConfiguration; - - public ProcessWrapper(Process process, ProcessConfiguration processConfiguration) { - - Assert.notNull(process, "Process must not be null"); - - Assert.notNull(processConfiguration, "The context and configuration meta-data providing details" - + " about the environment in which the process is running and how the process was configured and executed" - + " must not be null"); - - this.process = process; - this.processConfiguration = processConfiguration; - - init(); - } - - private void init() { - - newThread("Process OUT Stream Reader Thread", - newProcessInputStreamReaderRunnable(process.getInputStream())).start(); - - if (!isRedirectingErrorStream()) { - newThread("Process ERR Stream Reader Thread", - newProcessInputStreamReaderRunnable(process.getErrorStream())).start(); - } - } - - protected Runnable newProcessInputStreamReaderRunnable(InputStream in) { - - return () -> { - - if (isRunning()) { - BufferedReader inputReader = new BufferedReader(new InputStreamReader(in)); - - try { - for (String input = inputReader.readLine(); input != null; input = inputReader.readLine()) { - for (ProcessInputStreamListener listener : listeners) { - listener.onInput(input); - } - } - } - catch (IOException ignore) { - // Ignore IO error and just stop reading from the process input stream - // An IO error occurred most likely because the process was terminated - } - finally { - IOUtils.close(inputReader); - } - } - }; - } - - protected Thread newThread(String name, Runnable task) { - - Assert.hasText(name, "Thread name must be specified"); - Assert.notNull(task, "Thread task must not be null"); - - Thread thread = new Thread(task, name); - - thread.setDaemon(DEFAULT_DAEMON_THREAD); - thread.setPriority(Thread.NORM_PRIORITY); - - return thread; - } - - public boolean isAlive() { - return ProcessUtils.isAlive(process); - } - - public boolean isNotAlive() { - return !isAlive(); - } - - public List getCommand() { - return processConfiguration.getCommand(); - } - - public String getCommandString() { - return processConfiguration.getCommandString(); - } - - public Map getEnvironment() { - return processConfiguration.getEnvironment(); - } - - public int getPid() { - return ProcessUtils.findAndReadPid(getWorkingDirectory()); - } - - public int safeGetPid() { - - try { - return getPid(); - } - catch (PidUnavailableException ignore) { - return -1; - } - } - - public boolean isRedirectingErrorStream() { - return processConfiguration.isRedirectingErrorStream(); - } - - public boolean isNotRunning() { - return !isRunning(); - } - - public boolean isRunning() { - return ProcessUtils.isRunning(process); - } - - public File getWorkingDirectory() { - return processConfiguration.getWorkingDirectory(); - } - - public int exitValue() { - return process.exitValue(); - } - - public int safeExitValue() { - - try { - return exitValue(); - } - catch (IllegalThreadStateException ignore) { - return -1; - } - } - - public String readLogFile() throws IOException { - - File[] logFiles = FileSystemUtils.listFiles(getWorkingDirectory(), - (path) -> path != null && (path.isDirectory() || path.getAbsolutePath().endsWith(".log"))); - - if (logFiles.length > 0) { - return readLogFile(logFiles[0]); - } - else { - throw new FileNotFoundException(String.format( - "No log files found in process's [%d] working directory [%s]", - safeGetPid(), getWorkingDirectory())); - } - } - - public String readLogFile(File log) throws IOException { - return FileUtils.read(log); - } - - public boolean register(ProcessInputStreamListener listener) { - return (listener != null && listeners.add(listener)); - } - - public void registerShutdownHook() { - Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown)); - } - - public void signal() { - - try { - OutputStream outputStream = process.getOutputStream(); - outputStream.write("\n".getBytes()); - outputStream.flush(); - } - catch (IOException cause) { - - log.warning("Failed to signal process"); - - if (log.isLoggable(Level.FINE)) { - log.fine(ThrowableUtils.toString(cause)); - } - } - } - - public void signalStop() { - - try { - ProcessUtils.signalStop(process); - } - catch (IOException cause) { - - log.warning("Failed to signal the process to stop"); - - if (log.isLoggable(Level.FINE)) { - log.fine(ThrowableUtils.toString(cause)); - } - } - } - - public int stop() { - return stop(DEFAULT_WAIT_TIME_MILLISECONDS); - } - - public int stop(long milliseconds) { - - if (isRunning()) { - - boolean interrupted = false; - int exitValue = -1; - int pid = safeGetPid(); - long timeout = System.currentTimeMillis() + milliseconds; - - AtomicBoolean exited = new AtomicBoolean(false); - - ExecutorService executorService = Executors.newSingleThreadExecutor(); - - try { - Future futureExitValue = executorService.submit(() -> { - process.destroy(); - int localExitValue = process.waitFor(); - exited.set(true); - return localExitValue; - }); - - while (!exited.get() && System.currentTimeMillis() < timeout) { - try { - exitValue = futureExitValue.get(milliseconds, TimeUnit.MILLISECONDS); - log.info(String.format("Process [%s] has stopped%n", pid)); - } - catch (InterruptedException ignore) { - interrupted = true; - } - } - } - catch (TimeoutException e) { - exitValue = -1; - log.warning(String.format("Process [%1$d] did not stop within the allotted timeout of %2$d seconds%n", - pid, TimeUnit.MILLISECONDS.toSeconds(milliseconds))); - } - catch (Exception ignore) { - // handles CancellationException, ExecutionException - } - finally { - - executorService.shutdownNow(); - - if (interrupted) { - Thread.currentThread().interrupt(); - } - } - - return exitValue; - } - else { - return exitValue(); - } - } - - public int shutdown() { - - if (isRunning()) { - log.info(String.format("Stopping process [%d]...%n", safeGetPid())); - signalStop(); - waitFor(); - } - - return stop(); - } - - public boolean unregister(ProcessInputStreamListener listener) { - return listeners.remove(listener); - } - - public void waitFor() { - waitFor(DEFAULT_WAIT_TIME_MILLISECONDS); - } - - public void waitFor(long milliseconds) { - ThreadUtils.timedWait(milliseconds, 500, this::isRunning); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/support/PidUnavailableException.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/support/PidUnavailableException.java deleted file mode 100644 index b1759588..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/support/PidUnavailableException.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.process.support; - -/** - * The PidUnavailableException class is a RuntimeException indicating that the process ID (PID) is unobtainable for - * the current process. - * - * @author John Blum - * @see java.lang.RuntimeException - * @since 1.5.0 - */ -@SuppressWarnings("unused") -public class PidUnavailableException extends RuntimeException { - - public PidUnavailableException() { - } - - public PidUnavailableException(final String message) { - super(message); - } - - public PidUnavailableException(final Throwable cause) { - super(cause); - } - - public PidUnavailableException(final String message, final Throwable cause) { - super(message, cause); - } - -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/support/ProcessUtils.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/support/ProcessUtils.java deleted file mode 100644 index 7d3895ea..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/process/support/ProcessUtils.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.process.support; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileFilter; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; -import java.util.Scanner; -import java.util.logging.Logger; - -import org.springframework.data.gemfire.test.support.FileSystemUtils; -import org.springframework.data.gemfire.test.support.IOUtils; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -/** - * The {@link ProcessUtils} class is a utility class for working with Operating System (OS) {@link Process processes}. - * - * @author John Blum - * @see java.io.File - * @see java.lang.Process - * @since 1.5.0 - */ -@SuppressWarnings("unused") -public abstract class ProcessUtils { - - protected static final Logger log = Logger.getLogger(ProcessUtils.class.getName()); - - protected static final String TERM_TOKEN = ""; - - public static int currentPid() { - RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); - String runtimeMXBeanName = runtimeMXBean.getName(); - - Exception cause = null; - - if (StringUtils.hasText(runtimeMXBeanName)) { - int atSignIndex = runtimeMXBeanName.indexOf('@'); - - if (atSignIndex > 0) { - try { - return Integer.parseInt(runtimeMXBeanName.substring(0, atSignIndex)); - } - catch (NumberFormatException e) { - cause = e; - } - } - } - - throw new PidUnavailableException(String.format("Process ID (PID) not available [%s]", runtimeMXBeanName), - cause); - } - - public static boolean isAlive(Process process) { - return process != null && process.isAlive(); - } - - public static boolean isRunning(int processId) { - - /* - for (VirtualMachineDescriptor vmDescriptor : VirtualMachine.list()) { - if (String.valueOf(processId).equals(vmDescriptor.id())) { - return true; - } - } - - return false; - */ - - throw new UnsupportedOperationException("operation not supported"); - } - - public static boolean isRunning(Process process) { - - try { - process.exitValue(); - return false; - } - catch (IllegalThreadStateException ignore) { - return true; - } - } - - public static void signalStop(Process process) throws IOException { - - if (isRunning(process)) { - OutputStream processOutputStream = process.getOutputStream(); - processOutputStream.write(TERM_TOKEN.concat("\n").getBytes()); - processOutputStream.flush(); - } - } - - @SuppressWarnings("all") - public static void waitForStopSignal() { - Scanner in = new Scanner(System.in); - while (!TERM_TOKEN.equals(in.next())); - } - - public static int findAndReadPid(File workingDirectory) { - File pidFile = findPidFile(workingDirectory); - - if (pidFile == null) { - throw new PidUnavailableException(String.format( - "No PID file was found in working directory [%s] or any of it's sub-directories", - workingDirectory)); - } - - return readPid(pidFile); - } - - @SuppressWarnings("all") - protected static File findPidFile(File workingDirectory) { - - Assert.isTrue(FileSystemUtils.isDirectory(workingDirectory), String.format( - "File [%s] is not a valid directory", workingDirectory)); - - for (File file : workingDirectory.listFiles(DirectoryPidFileFilter.INSTANCE)) { - if (file.isDirectory()) { - file = findPidFile(file); - } - - if (PidFileFilter.INSTANCE.accept(file)) { - return file; - } - } - - return null; - } - - @SuppressWarnings("all") - public static int readPid(File pidFile) { - - Assert.isTrue(pidFile != null && pidFile.isFile(), String.format( - "File [%s] is not a valid file", pidFile)); - - BufferedReader fileReader = null; - String pidValue = null; - - try { - fileReader = new BufferedReader(new FileReader(pidFile)); - pidValue = String.valueOf(fileReader.readLine()).trim(); - - return Integer.parseInt(pidValue); - } - catch (FileNotFoundException e) { - throw new PidUnavailableException(String.format("PID file [%s] not found", pidFile), e); - } - catch (IOException e) { - throw new PidUnavailableException(String.format("failed to read PID from file [%s]", pidFile), e); - } - catch (NumberFormatException e) { - throw new PidUnavailableException(String.format( - "value [%1$s] from PID file [%2$s] was not a valid numerical PID", pidValue, pidFile), e); - } - finally { - IOUtils.close(fileReader); - } - } - - @SuppressWarnings("all") - public static void writePid(File pidFile, int pid) throws IOException { - - Assert.isTrue(pidFile != null && (pidFile.isFile() || pidFile.createNewFile()), String.format( - "File [%s] is not a valid file", pidFile)); - - Assert.isTrue(pid > 0, String.format("PID [%d] must greater than 0", pid)); - - PrintWriter fileWriter = new PrintWriter(new BufferedWriter(new FileWriter(pidFile, false), 16), true); - - try { - fileWriter.println(pid); - } - finally { - pidFile.deleteOnExit(); - FileSystemUtils.close(fileWriter); - } - } - - protected static class DirectoryPidFileFilter extends PidFileFilter { - - protected static final DirectoryPidFileFilter INSTANCE = new DirectoryPidFileFilter(); - - /** - * @inheritDoc - */ - @Override - public boolean accept(File path) { - return path != null && (path.isDirectory() || super.accept(path)); - } - } - - protected static class PidFileFilter implements FileFilter { - - protected static final PidFileFilter INSTANCE = new PidFileFilter(); - - /** - * @inheritDoc - */ - @Override - public boolean accept(File path) { - return path != null && path.isFile() && path.getName().toLowerCase().endsWith(".pid"); - } - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/GemFireRepositoryFactoryInformationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/GemFireRepositoryFactoryInformationIntegrationTests.java index 82995d29..04fa9973 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/GemFireRepositoryFactoryInformationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/GemFireRepositoryFactoryInformationIntegrationTests.java @@ -29,7 +29,8 @@ import org.springframework.data.gemfire.config.annotation.ClientCacheApplication import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions; import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; import org.springframework.data.gemfire.repository.support.GemfireRepositoryFactoryBean; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.repository.Repository; import org.springframework.data.repository.core.support.RepositoryFactoryInformation; import org.springframework.test.context.ContextConfiguration; @@ -44,11 +45,13 @@ import example.app.repo.UserRepository; * in the Spring {@link ApplicationContext}. * * @author John Blum + * @see org.junit.Test * @see org.springframework.context.ApplicationContext * @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication - * @see org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions * @see org.springframework.data.gemfire.repository.config.EnableGemfireRepositories * @see org.springframework.data.gemfire.repository.support.GemfireRepositoryFactoryBean + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.data.repository.Repository * @see org.springframework.data.repository.core.support.RepositoryFactoryInformation * @see org.springframework.test.context.ContextConfiguration @@ -58,7 +61,7 @@ import example.app.repo.UserRepository; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class GemFireRepositoryFactoryInformationIntegrationTests { +public class GemFireRepositoryFactoryInformationIntegrationTests extends IntegrationTestsSupport { @Autowired private ApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/config/ClientRegionNamespaceRepositoryIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/config/ClientRegionNamespaceRepositoryIntegrationTests.java index 5fadeaf0..091d71cd 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/config/ClientRegionNamespaceRepositoryIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/config/ClientRegionNamespaceRepositoryIntegrationTests.java @@ -14,17 +14,15 @@ package org.springframework.data.gemfire.repository.config; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.gemfire.fork.ServerProcess; -import org.springframework.data.gemfire.process.ProcessWrapper; import org.springframework.data.gemfire.repository.GemfireRepository; import org.springframework.data.gemfire.repository.sample.PersonRepository; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -34,40 +32,25 @@ import org.springframework.test.context.junit4.SpringRunner; * * @author David Turanski * @author John Blum - * @see org.springframework.data.gemfire.process.ProcessWrapper + * @see org.junit.Test + * @see org.springframework.data.gemfire.fork.ServerProcess * @see org.springframework.data.gemfire.repository.GemfireRepository - * @see org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class ClientRegionNamespaceRepositoryIntegrationTests extends ClientServerIntegrationTestsSupport { - - private static ProcessWrapper gemfireServer; +public class ClientRegionNamespaceRepositoryIntegrationTests extends ForkingClientServerIntegrationTestsSupport { @Autowired private PersonRepository repository; @BeforeClass public static void startGemFireServer() throws Exception { - - int availablePort = findAvailablePort(); - - gemfireServer = run(ServerProcess.class, - String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort), + startGemFireServer(ServerProcess.class, getServerContextXmlFileLocation(ClientRegionNamespaceRepositoryIntegrationTests.class)); - - waitForServerToStart(DEFAULT_HOSTNAME, availablePort); - - System.setProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY, String.valueOf(availablePort)); - } - - @AfterClass - public static void stopGemFireServer() { - stop(gemfireServer); - System.clearProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY); } @Test diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/config/GemfireRepositoriesRegistrarIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/config/GemfireRepositoriesRegistrarIntegrationTests.java index 9f2add5f..481ec647 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/config/GemfireRepositoriesRegistrarIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/config/GemfireRepositoriesRegistrarIntegrationTests.java @@ -1,5 +1,4 @@ /* - /* * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,7 +23,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.gemfire.config.annotation.ClientCacheApplication; import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -40,14 +40,15 @@ import example.app.repo.UserRepository; * @author John Blum * @see org.junit.Test * @see org.springframework.data.gemfire.repository.config.GemfireRepositoriesRegistrar - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class GemfireRepositoriesRegistrarIntegrationTests { +public class GemfireRepositoriesRegistrarIntegrationTests extends IntegrationTestsSupport { @Autowired private UserRepository repository; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/config/IncompatibleRegionKeyRepositoryIdAndEntityIdRepositoryIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/config/IncompatibleRegionKeyRepositoryIdAndEntityIdRepositoryIntegrationTests.java index b95aed18..d709e3f5 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/config/IncompatibleRegionKeyRepositoryIdAndEntityIdRepositoryIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/config/IncompatibleRegionKeyRepositoryIdAndEntityIdRepositoryIntegrationTests.java @@ -38,7 +38,8 @@ import org.springframework.data.gemfire.repository.sample.Animal; import org.springframework.data.gemfire.repository.sample.Plant; import org.springframework.data.gemfire.repository.sample.PlantRepository; import org.springframework.data.gemfire.repository.sample.RabbitRepository; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.repository.Repository; @@ -51,16 +52,18 @@ import org.springframework.data.repository.Repository; * @see org.junit.Test * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.Region - * @see org.apache.geode.cache.RegionAttributes * @see org.springframework.context.ConfigurableApplicationContext * @see org.springframework.context.annotation.AnnotationConfigApplicationContext - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.context.annotation.Bean + * @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.data.repository.Repository * @see PR-55 * @since 1.4.0 */ @SuppressWarnings("unused") -public class IncompatibleRegionKeyRepositoryIdAndEntityIdRepositoryIntegrationTests { +public class IncompatibleRegionKeyRepositoryIdAndEntityIdRepositoryIntegrationTests extends IntegrationTestsSupport { private static ConfigurableApplicationContext newApplicationContext(Class testConfiguration) { return new AnnotationConfigApplicationContext(testConfiguration); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryRegionDeleteAllIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryRegionDeleteAllIntegrationTests.java index 2a18a207..b54eb454 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryRegionDeleteAllIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryRegionDeleteAllIntegrationTests.java @@ -22,7 +22,6 @@ import java.util.Collections; import javax.annotation.Resource; -import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -46,10 +45,9 @@ import org.springframework.data.gemfire.config.annotation.ClientCacheApplication import org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer; import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions; import org.springframework.data.gemfire.config.annotation.EnablePdx; -import org.springframework.data.gemfire.process.ProcessWrapper; import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; import org.springframework.data.gemfire.support.ConnectionEndpoint; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.data.repository.CrudRepository; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -63,11 +61,13 @@ import example.app.repo.UserRepository; * * @author John Blum * @see org.junit.Test + * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.config.annotation.CacheServerApplication * @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication * @see org.springframework.data.gemfire.repository.config.EnableGemfireRepositories * @see org.springframework.data.gemfire.repository.support.SimpleGemfireRepository + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @see org.springframework.data.repository.CrudRepository * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner @@ -77,27 +77,11 @@ import example.app.repo.UserRepository; @RunWith(SpringRunner.class) @ContextConfiguration(classes = SimpleGemfireRepositoryRegionDeleteAllIntegrationTests.GeodeClientTestConfiguration.class) @SuppressWarnings("unused") -public class SimpleGemfireRepositoryRegionDeleteAllIntegrationTests extends ClientServerIntegrationTestsSupport { - - private static ProcessWrapper gemfireServer; +public class SimpleGemfireRepositoryRegionDeleteAllIntegrationTests extends ForkingClientServerIntegrationTestsSupport { @BeforeClass public static void startGeodeServer() throws Exception { - - int availablePort = findAvailablePort(); - - gemfireServer = run(GeodeServerTestConfiguration.class, "-Dspring.profiles.active=partition", - String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort)); - - waitForServerToStart("localhost", availablePort); - - System.setProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY, String.valueOf(availablePort)); - } - - @AfterClass - public static void stopGemFireServer() { - System.clearProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY); - stop(gemfireServer); + startGemFireServer(GeodeServerTestConfiguration.class); } @Resource(name = "Users") diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTests.java similarity index 85% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTests.java index 724a7fac..b76a60a6 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTests.java @@ -16,10 +16,7 @@ package org.springframework.data.gemfire.snapshot; import static java.util.Arrays.stream; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray; import java.io.File; @@ -30,22 +27,24 @@ import java.util.concurrent.atomic.AtomicLong; import javax.annotation.Resource; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.snapshot.SnapshotFilter; - import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.snapshot.SnapshotFilter; + import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.data.gemfire.repository.sample.Person; import org.springframework.data.gemfire.snapshot.event.ExportSnapshotApplicationEvent; import org.springframework.data.gemfire.snapshot.event.ImportSnapshotApplicationEvent; import org.springframework.data.gemfire.snapshot.event.SnapshotApplicationEvent; -import org.springframework.data.gemfire.test.support.FileSystemUtils; -import org.springframework.data.gemfire.test.support.ThreadUtils; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.util.FileSystemUtils; +import org.springframework.data.gemfire.tests.util.ThreadUtils; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -53,27 +52,25 @@ import org.springframework.util.Assert; import org.springframework.util.StringUtils; /** - * The SnapshotApplicationEventTriggeredImportsExportsIntegrationTest class is a test suite of test cases testing - * the effects of the SnapshotServiceFactoryBean using Spring ApplicationEvents to trigger imports and exports - * of GemFire Cache Region data. + * Integration Tests with test cases testing the effects of the {@link SnapshotServiceFactoryBean} using Spring + * {@link ApplicationEvent ApplicationEvents} to trigger imports and exports of cache {@link Region} data. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner + * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBean * @see org.springframework.data.gemfire.snapshot.event.ExportSnapshotApplicationEvent * @see org.springframework.data.gemfire.snapshot.event.ImportSnapshotApplicationEvent * @see org.springframework.data.gemfire.snapshot.event.SnapshotApplicationEvent - * @see org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBean - * @see org.springframework.data.gemfire.repository.sample.Person - * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner * @since 1.7.0 */ @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTest { +public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTests extends IntegrationTestsSupport { protected static final AtomicLong ID_SEQUENCE = new AtomicLong(0L); @@ -99,13 +96,13 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTest { snapshotsDirectory = new File(new File(FileSystemUtils.WORKING_DIRECTORY, "gemfire"), "snapshots"); - assertThat(snapshotsDirectory.isDirectory() || snapshotsDirectory.mkdirs(), is(true)); + assertThat(snapshotsDirectory.isDirectory() || snapshotsDirectory.mkdirs()).isTrue(); File peopleSnapshotFile = new File(snapshotsDirectory, "people-snapshot.gfd"); File nonHandyNonDoeSnapshotFile = new File(snapshotsDirectory, "nonHandyNonDoePeople-snapshot.gfd"); - assertThat(peopleSnapshotFile.isFile() || peopleSnapshotFile.createNewFile(), is(true)); - assertThat(nonHandyNonDoeSnapshotFile.isFile() || nonHandyNonDoeSnapshotFile.createNewFile(), is(true)); + assertThat(peopleSnapshotFile.isFile() || peopleSnapshotFile.createNewFile()).isTrue(); + assertThat(nonHandyNonDoeSnapshotFile.isFile() || nonHandyNonDoeSnapshotFile.createNewFile()).isTrue(); } @AfterClass @@ -115,7 +112,7 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTest { protected void assertPeople(Region targetRegion, Person... people) { - assertThat(targetRegion.size(), is(equalTo(people.length))); + assertThat(targetRegion.size()).isEqualTo(people.length); stream(nullSafeArray(people, Person.class)) .forEach(person -> assertPerson(person, targetRegion.get(person.getId()))); @@ -123,11 +120,11 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTest { protected void assertPerson(Person expectedPerson, Person actualPerson) { - assertThat(String.format("Expected [%1$s]; but was [%2$s]", expectedPerson, actualPerson), - actualPerson, is(notNullValue())); - assertThat(actualPerson.getId(), is(equalTo(expectedPerson.getId()))); - assertThat(actualPerson.getFirstname(), is(equalTo(expectedPerson.getFirstname()))); - assertThat(actualPerson.getLastname(), is(equalTo(expectedPerson.getLastname()))); + assertThat(actualPerson).as(String.format("Expected [%1$s]; but was [%2$s]", expectedPerson, actualPerson)) + .isNotNull(); + assertThat(actualPerson.getId()).isEqualTo(expectedPerson.getId()); + assertThat(actualPerson.getFirstname()).isEqualTo(expectedPerson.getFirstname()); + assertThat(actualPerson.getLastname()).isEqualTo(expectedPerson.getLastname()); } protected Person newPerson(String firstName, String lastName) { @@ -159,8 +156,8 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTest { Person jackHandy = put(people, newPerson("Jack", "Handy")); Person joeDirt = put(people, newPerson("Joe", "Dirt")); - SnapshotApplicationEvent event = - new ExportSnapshotApplicationEvent(this, people.getFullPath()); + SnapshotApplicationEvent event = + new ExportSnapshotApplicationEvent<>(this, people.getFullPath()); eventPublisher.publishEvent(event); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanIntegrationTests.java similarity index 69% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanIntegrationTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanIntegrationTests.java index a645d94e..13a4d9f1 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanIntegrationTests.java @@ -13,13 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.snapshot; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBean.SnapshotServiceAdapterSupport; import java.io.File; @@ -30,23 +26,25 @@ import java.util.List; import org.junit.Test; import org.springframework.core.io.ClassPathResource; -import org.springframework.data.gemfire.test.support.FileSystemUtils; +import org.springframework.data.gemfire.tests.util.FileSystemUtils; /** - * The SnapshotServiceFactoryBeanIntegrationTest class is a test suite of test cases testing the file archive handling - * capabilities of the SnapshotServiceFactoryBean.SnapshotServiceAdpterSupport class. + * Integration Tests with test cases testing the file archive handling capabilities of + * the SnapshotServiceFactoryBean.SnapshotServiceAdpterSupport class. * * @author John Blum * @see org.junit.Test * @see org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBean.SnapshotServiceAdapterSupport * @since 1.7.0 */ -public class SnapshotServiceFactoryBeanIntegrationTest { +@SuppressWarnings("rawtypes") +public class SnapshotServiceFactoryBeanIntegrationTests { - SnapshotServiceAdapterSupport snapshotService = new TestSnapshotServiceAdapter(); + private final SnapshotServiceAdapterSupport snapshotService = new TestSnapshotServiceAdapter(); - protected List toFilenames(File... files) { - List filenames = new ArrayList(files.length); + private List toFilenames(File... files) { + + List filenames = new ArrayList<>(files.length); for (File file : files) { filenames.add(file.getName()); @@ -57,17 +55,19 @@ public class SnapshotServiceFactoryBeanIntegrationTest { @Test public void handleNonArchiveFileLocation() { + File expectedFile = new File("/path/to/non-existing/snapshot/file.gfd"); File[] files = snapshotService.handleFileLocation(expectedFile); - assertThat(files, is(notNullValue())); - assertThat(files.length, is(equalTo(1))); - assertThat(files[0], is(equalTo(expectedFile))); + assertThat(files).isNotNull(); + assertThat(files.length).isEqualTo(1); + assertThat(files[0]).isEqualTo(expectedFile); } @Test public void handleArchiveFileLocation() throws Exception { + File cacheSnapshotZipDirectory = null; try { @@ -75,17 +75,16 @@ public class SnapshotServiceFactoryBeanIntegrationTest { File[] actualSnapshots = snapshotService.handleFileLocation(cacheSnapshotZip); - assertThat(actualSnapshots, is(notNullValue())); - assertThat(actualSnapshots.length, is(equalTo(3))); + assertThat(actualSnapshots).isNotNull(); + assertThat(actualSnapshots.length).isEqualTo(3); assertThat(toFilenames(actualSnapshots).containsAll(Arrays.asList( - "accounts.snapshot", "address.snapshot", "people.snapshot")), is(true)); + "accounts.snapshot", "address.snapshot", "people.snapshot"))).isTrue(); cacheSnapshotZipDirectory = new File(System.getProperty("java.io.tmpdir"), cacheSnapshotZip.getName().replaceAll("\\.", "-")); - assertThat(cacheSnapshotZipDirectory.isDirectory(), is(true)); - assertThat(cacheSnapshotZipDirectory.listFiles(FileSystemUtils.FileOnlyFilter.INSTANCE), - is(equalTo(actualSnapshots))); + assertThat(cacheSnapshotZipDirectory.isDirectory()).isTrue(); + assertThat(cacheSnapshotZipDirectory.listFiles(FileSystemUtils.FileOnlyFilter.INSTANCE)).isEqualTo(actualSnapshots); } finally { if (cacheSnapshotZipDirectory != null && cacheSnapshotZipDirectory.isDirectory()) { @@ -101,5 +100,4 @@ public class SnapshotServiceFactoryBeanIntegrationTest { throw new UnsupportedOperationException("not implemented"); } } - } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanTest.java index 40db1d22..c247e88a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanTest.java @@ -16,16 +16,8 @@ package org.springframework.data.gemfire.snapshot; import static org.apache.geode.cache.snapshot.SnapshotOptions.SnapshotFormat; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.isA; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.CoreMatchers.sameInstance; -import static org.junit.Assert.assertThat; -import static org.junit.Assume.assumeThat; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assumptions.assumeThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; @@ -47,6 +39,11 @@ import java.io.File; import java.io.IOException; import java.util.Arrays; +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.ArgumentMatchers; + import org.apache.geode.cache.Cache; import org.apache.geode.cache.Region; import org.apache.geode.cache.snapshot.CacheSnapshotService; @@ -54,19 +51,13 @@ import org.apache.geode.cache.snapshot.RegionSnapshotService; import org.apache.geode.cache.snapshot.SnapshotFilter; import org.apache.geode.cache.snapshot.SnapshotOptions; -import org.junit.After; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.ArgumentMatchers; -import org.slf4j.Logger; - import org.springframework.core.io.ClassPathResource; import org.springframework.data.gemfire.snapshot.event.ExportSnapshotApplicationEvent; import org.springframework.data.gemfire.snapshot.event.ImportSnapshotApplicationEvent; import org.springframework.data.gemfire.snapshot.event.SnapshotApplicationEvent; -import org.springframework.data.gemfire.test.support.FileSystemUtils; +import org.springframework.data.gemfire.tests.util.FileSystemUtils; + +import org.slf4j.Logger; /** * The SnapshotServiceFactoryBeanTest class is a test suite of test cases testing the contract and functionality @@ -86,10 +77,7 @@ public class SnapshotServiceFactoryBeanTest { private static File snapshotDat; - @Rule - public ExpectedException exception = ExpectedException.none(); - - private SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean(); + private final SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean(); protected static File mockFile(String filename) { @@ -163,50 +151,60 @@ public class SnapshotServiceFactoryBeanTest { @Test public void nullSafeIsDirectoryWithDirectory() { - assertThat(SnapshotServiceFactoryBean.nullSafeIsDirectory(new File(System.getProperty("user.dir"))), is(true)); + assertThat(SnapshotServiceFactoryBean.nullSafeIsDirectory(new File(System.getProperty("user.dir")))).isTrue(); } @Test public void nullSafeIsDirectoryWithNonDirectories() { - assertThat(SnapshotServiceFactoryBean.nullSafeIsDirectory(new File("path/to/non-existing/directory")), - is(false)); + assertThat(SnapshotServiceFactoryBean.nullSafeIsDirectory(new File("path/to/non-existing/directory"))) + .isFalse(); - assertThat(SnapshotServiceFactoryBean.nullSafeIsDirectory(FileSystemUtils.JAVA_EXE), is(false)); + assertThat(SnapshotServiceFactoryBean.nullSafeIsDirectory(FileSystemUtils.JAVA_EXE)).isFalse(); } @Test public void nullSafeIsFileWithFile() { - assertThat(SnapshotServiceFactoryBean.nullSafeIsFile(FileSystemUtils.JAVA_EXE), - is(FileSystemUtils.JAVA_EXE.isFile())); + assertThat(SnapshotServiceFactoryBean.nullSafeIsFile(FileSystemUtils.JAVA_EXE)) + .isEqualTo(FileSystemUtils.JAVA_EXE.isFile()); } @Test public void nullSafeIsFileWithNonFiles() { - assertThat(SnapshotServiceFactoryBean.nullSafeIsFile(new File("/path/to/non-existing/file.ext")), is(false)); - assertThat(SnapshotServiceFactoryBean.nullSafeIsFile(new File(System.getProperty("user.dir"))), is(false)); + assertThat(SnapshotServiceFactoryBean.nullSafeIsFile(new File("/path/to/non-existing/file.ext"))).isFalse(); + assertThat(SnapshotServiceFactoryBean.nullSafeIsFile(new File(System.getProperty("user.dir")))).isFalse(); } - @Test + @Test(expected = IllegalArgumentException.class) public void setCacheToNull() { - exception.expect(IllegalArgumentException.class); - exception.expectCause(is(nullValue(Throwable.class))); - exception.expectMessage("The GemFire Cache must not be null"); + try { + factoryBean.setCache(null); + } + catch (IllegalArgumentException expected) { - factoryBean.setCache(null); + assertThat(expected).hasMessage("The GemFire Cache must not be null"); + assertThat(expected).hasNoCause(); + + throw expected; + } } - @Test + @Test(expected = IllegalStateException.class) public void getCacheWhenUninitialized() { - exception.expect(IllegalStateException.class); - exception.expectCause(is(nullValue(Throwable.class))); - exception.expectMessage("The GemFire Cache was not properly initialized"); + try { + factoryBean.getCache(); + } + catch (IllegalStateException expected) { - factoryBean.getCache(); + assertThat(expected).hasMessage("The GemFire Cache was not properly initialized"); + assertThat(expected).hasNoCause(); + + throw expected; + } } @Test @@ -218,7 +216,7 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.setCache(mockCache); - assertThat(factoryBean.getCache(), is(sameInstance(mockCache))); + assertThat(factoryBean.getCache()).isSameAs(mockCache); } @Test @@ -226,22 +224,22 @@ public class SnapshotServiceFactoryBeanTest { SnapshotMetadata[] actualExports = factoryBean.getExports(); - assertThat(actualExports, is(notNullValue())); - assertThat(actualExports.length, is(equalTo(0))); + assertThat(actualExports).isNotNull(); + assertThat(actualExports.length).isEqualTo(0); SnapshotMetadata[] expectedExports = toArray(newSnapshotMetadata()); factoryBean.setExports(expectedExports); actualExports = factoryBean.getExports(); - assertThat(actualExports, is(sameInstance(expectedExports))); + assertThat(actualExports).isSameAs(expectedExports); factoryBean.setExports(null); actualExports = factoryBean.getExports(); - assertThat(actualExports, is(not(sameInstance(expectedExports)))); - assertThat(actualExports, is(notNullValue())); - assertThat(actualExports.length, is(equalTo(0))); + assertThat(actualExports).isNotSameAs(expectedExports); + assertThat(actualExports).isNotNull(); + assertThat(actualExports.length).isEqualTo(0); } @Test @@ -249,61 +247,61 @@ public class SnapshotServiceFactoryBeanTest { SnapshotMetadata[] actualImports = factoryBean.getImports(); - assertThat(actualImports, is(notNullValue())); - assertThat(actualImports.length, is(equalTo(0))); + assertThat(actualImports).isNotNull(); + assertThat(actualImports.length).isEqualTo(0); SnapshotMetadata[] expectedImports = toArray(newSnapshotMetadata()); factoryBean.setImports(expectedImports); actualImports = factoryBean.getImports(); - assertThat(actualImports, is(sameInstance(expectedImports))); + assertThat(actualImports).isSameAs(expectedImports); factoryBean.setImports(null); actualImports = factoryBean.getImports(); - assertThat(actualImports, is(not(sameInstance(expectedImports)))); - assertThat(actualImports, is(notNullValue())); - assertThat(actualImports.length, is(equalTo(0))); + assertThat(actualImports).isNotSameAs(expectedImports); + assertThat(actualImports).isNotNull(); + assertThat(actualImports.length).isEqualTo(0); } @Test public void setAndGetRegionSuccessfully() { - assertThat(factoryBean.getRegion(), is(nullValue())); + assertThat(factoryBean.getRegion()).isNull(); Region mockRegion = mock(Region.class, "MockRegion"); factoryBean.setRegion(mockRegion); - assertThat(factoryBean.getRegion(), is(sameInstance(mockRegion))); + assertThat(factoryBean.getRegion()).isSameAs(mockRegion); factoryBean.setRegion(null); - assertThat(factoryBean.getRegion(), is(nullValue())); + assertThat(factoryBean.getRegion()).isNull(); } @Test public void setAndGetSuppressImportOnInitSuccessfully() { - assertThat(factoryBean.getSuppressImportOnInit(), is(false)); + assertThat(factoryBean.getSuppressImportOnInit()).isFalse(); factoryBean.setSuppressImportOnInit(true); - assertThat(factoryBean.getSuppressImportOnInit(), is(true)); + assertThat(factoryBean.getSuppressImportOnInit()).isTrue(); factoryBean.setSuppressImportOnInit(false); - assertThat(factoryBean.getSuppressImportOnInit(), is(false)); + assertThat(factoryBean.getSuppressImportOnInit()).isFalse(); factoryBean.setSuppressImportOnInit(null); - assertThat(factoryBean.getSuppressImportOnInit(), is(false)); + assertThat(factoryBean.getSuppressImportOnInit()).isFalse(); } @Test public void isSingletonIsTrue() { - assertThat(factoryBean.isSingleton(), is(true)); + assertThat(factoryBean.isSingleton()).isTrue(); } @Test @@ -325,7 +323,7 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.setImports(toArray(expectedSnapshotMetadata)); factoryBean.afterPropertiesSet(); - assertThat(factoryBean.getImports()[0], is(equalTo(expectedSnapshotMetadata))); + assertThat(factoryBean.getImports()[0]).isEqualTo(expectedSnapshotMetadata); verify(mockSnapshotService, times(1)).doImport(eq(expectedSnapshotMetadata)); } @@ -347,7 +345,7 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.setSuppressImportOnInit(true); factoryBean.afterPropertiesSet(); - assertThat(factoryBean.getSuppressImportOnInit(), is(true)); + assertThat(factoryBean.getSuppressImportOnInit()).isTrue(); verify(mockSnapshotService, never()).doImport(any(SnapshotMetadata[].class)); } @@ -367,7 +365,7 @@ public class SnapshotServiceFactoryBeanTest { SnapshotServiceAdapter adapter = factoryBean.create(); - assertThat(adapter, is(instanceOf(CacheSnapshotServiceAdapter.class))); + assertThat(adapter).isInstanceOf(CacheSnapshotServiceAdapter.class); verify(mockCache, times(1)).getSnapshotService(); } @@ -387,29 +385,39 @@ public class SnapshotServiceFactoryBeanTest { SnapshotServiceAdapter adapter = factoryBean.create(); - assertThat(adapter, is(instanceOf(RegionSnapshotServiceAdapter.class))); + assertThat(adapter).isInstanceOf(RegionSnapshotServiceAdapter.class); verify(mockRegion, times(1)).getSnapshotService(); } - @Test + @Test(expected = IllegalArgumentException.class) public void wrapNullCacheSnapshotService() { - exception.expect(IllegalArgumentException.class); - exception.expectCause(is(nullValue(Throwable.class))); - exception.expectMessage("The backing CacheSnapshotService must not be null"); + try { + factoryBean.wrap((CacheSnapshotService) null); + } + catch (IllegalArgumentException expected) { - factoryBean.wrap((CacheSnapshotService) null); + assertThat(expected).hasMessage("The backing CacheSnapshotService must not be null"); + assertThat(expected).hasNoCause(); + + throw expected; + } } - @Test + @Test(expected = IllegalArgumentException.class) public void wrapNullRegionSnapshotService() { - exception.expect(IllegalArgumentException.class); - exception.expectCause(is(nullValue(Throwable.class))); - exception.expectMessage("The backing RegionSnapshotService must not be null"); + try { + factoryBean.wrap((RegionSnapshotService) null); + } + catch (IllegalArgumentException expected) { - factoryBean.wrap((RegionSnapshotService) null); + assertThat(expected).hasMessage("The backing RegionSnapshotService must not be null"); + assertThat(expected).hasNoCause(); + + throw expected; + } } @Test @@ -431,7 +439,7 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.setExports(toArray(expectedSnapshotMetadata)); factoryBean.destroy(); - assertThat(factoryBean.getExports()[0], is(equalTo(expectedSnapshotMetadata))); + assertThat(factoryBean.getExports()[0]).isEqualTo(expectedSnapshotMetadata); verify(mockSnapshotService, times(1)).doExport(eq(expectedSnapshotMetadata)); } @@ -464,8 +472,8 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.setExports(toArray(newSnapshotMetadata())); factoryBean.setRegion(mockRegion); - assertThat(factoryBean.getExports()[0], is(not(sameInstance(eventSnapshotMetadata)))); - assertThat(factoryBean.getRegion(), is(sameInstance(mockRegion))); + assertThat(factoryBean.getExports()[0]).isNotSameAs(eventSnapshotMetadata); + assertThat(factoryBean.getRegion()).isSameAs(mockRegion); factoryBean.onApplicationEvent(mockSnapshotEvent); @@ -500,8 +508,8 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.setImports(toArray(factorySnapshotMetadata)); - assertThat(factoryBean.getImports()[0], is(equalTo(factorySnapshotMetadata))); - assertThat(factoryBean.getRegion(), is(nullValue())); + assertThat(factoryBean.getImports()[0]).isEqualTo(factorySnapshotMetadata); + assertThat(factoryBean.getRegion()).isNull(); factoryBean.onApplicationEvent(mockSnapshotEvent); @@ -534,8 +542,8 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.setExports(toArray(newSnapshotMetadata())); - assertThat(factoryBean.getExports()[0], isA(SnapshotMetadata.class)); - assertThat(factoryBean.getRegion(), is(nullValue())); + assertThat(factoryBean.getExports()[0]).isInstanceOf(SnapshotMetadata.class); + assertThat(factoryBean.getRegion()).isNull(); factoryBean.onApplicationEvent(mockSnapshotEvent); @@ -571,8 +579,8 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.setImports(toArray(newSnapshotMetadata())); factoryBean.setRegion(mockRegion); - assertThat(factoryBean.getImports()[0], isA(SnapshotMetadata.class)); - assertThat(factoryBean.getRegion(), is(equalTo(mockRegion))); + assertThat(factoryBean.getImports()[0]).isInstanceOf(SnapshotMetadata.class); + assertThat(factoryBean.getRegion()).isEqualTo(mockRegion); factoryBean.onApplicationEvent(mockSnapshotEvent); @@ -597,9 +605,9 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.setExports(toArray(factoryExportSnapshotMetadata)); factoryBean.setImports(toArray(factoryImportSnapshotMetadata)); - assertThat(factoryBean.getExports()[0], is(equalTo(factoryExportSnapshotMetadata))); - assertThat(factoryBean.getImports()[0], is(equalTo(factoryImportSnapshotMetadata))); - assertThat(factoryBean.resolveSnapshotMetadata(mockSnapshotEvent)[0], is(equalTo(eventSnapshotMetadata))); + assertThat(factoryBean.getExports()[0]).isEqualTo(factoryExportSnapshotMetadata); + assertThat(factoryBean.getImports()[0]).isEqualTo(factoryImportSnapshotMetadata); + assertThat(factoryBean.resolveSnapshotMetadata(mockSnapshotEvent)[0]).isEqualTo(eventSnapshotMetadata); verify(mockSnapshotEvent, times(1)).getSnapshotMetadata(); } @@ -618,9 +626,9 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.setExports(toArray(factoryExportSnapshotMetadata)); factoryBean.setImports(toArray(factoryImportSnapshotMetadata)); - assertThat(factoryBean.getExports()[0], is(equalTo(factoryExportSnapshotMetadata))); - assertThat(factoryBean.getImports()[0], is(equalTo(factoryImportSnapshotMetadata))); - assertThat(factoryBean.resolveSnapshotMetadata(mockSnapshotEvent)[0], is(equalTo(factoryExportSnapshotMetadata))); + assertThat(factoryBean.getExports()[0]).isEqualTo(factoryExportSnapshotMetadata); + assertThat(factoryBean.getImports()[0]).isEqualTo(factoryImportSnapshotMetadata); + assertThat(factoryBean.resolveSnapshotMetadata(mockSnapshotEvent)[0]).isEqualTo(factoryExportSnapshotMetadata); verify(mockSnapshotEvent, times(1)).getSnapshotMetadata(); } @@ -639,9 +647,9 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.setExports(toArray(factoryExportSnapshotMetadata)); factoryBean.setImports(toArray(factoryImportSnapshotMetadata)); - assertThat(factoryBean.getExports()[0], is(equalTo(factoryExportSnapshotMetadata))); - assertThat(factoryBean.getImports()[0], is(equalTo(factoryImportSnapshotMetadata))); - assertThat(factoryBean.resolveSnapshotMetadata(mockSnapshotEvent)[0], is(equalTo(factoryImportSnapshotMetadata))); + assertThat(factoryBean.getExports()[0]).isEqualTo(factoryExportSnapshotMetadata); + assertThat(factoryBean.getImports()[0]).isEqualTo(factoryImportSnapshotMetadata); + assertThat(factoryBean.resolveSnapshotMetadata(mockSnapshotEvent)[0]).isEqualTo(factoryImportSnapshotMetadata); verify(mockSnapshotEvent, times(1)).getSnapshotMetadata(); } @@ -654,8 +662,8 @@ public class SnapshotServiceFactoryBeanTest { when(mockSnapshotEvent.isCacheSnapshotEvent()).thenReturn(true); - assertThat(factoryBean.getRegion(), is(nullValue())); - assertThat(factoryBean.isMatch(mockSnapshotEvent), is(true)); + assertThat(factoryBean.getRegion()).isNull(); + assertThat(factoryBean.isMatch(mockSnapshotEvent)).isTrue(); verify(mockSnapshotEvent, times(1)).isCacheSnapshotEvent(); verify(mockSnapshotEvent, never()).matches(any(Region.class)); @@ -670,8 +678,8 @@ public class SnapshotServiceFactoryBeanTest { when(mockSnapshotEvent.isCacheSnapshotEvent()).thenReturn(false); when(mockSnapshotEvent.matches(any(Region.class))).thenReturn(false); - assertThat(factoryBean.getRegion(), is(nullValue())); - assertThat(factoryBean.isMatch(mockSnapshotEvent), is(false)); + assertThat(factoryBean.getRegion()).isNull(); + assertThat(factoryBean.isMatch(mockSnapshotEvent)).isFalse(); verify(mockSnapshotEvent, times(1)).isCacheSnapshotEvent(); verify(mockSnapshotEvent, times(1)).matches(ArgumentMatchers.isNull()); @@ -687,8 +695,8 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.setRegion(mock(Region.class, "MockRegion")); - assertThat(factoryBean.getRegion(), is(notNullValue())); - assertThat(factoryBean.isMatch(mockSnapshotEvent), is(true)); + assertThat(factoryBean.getRegion()).isNotNull(); + assertThat(factoryBean.isMatch(mockSnapshotEvent)).isTrue(); verify(mockSnapshotEvent, times(1)).isCacheSnapshotEvent(); verify(mockSnapshotEvent, never()).matches(any(Region.class)); @@ -707,8 +715,8 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.setRegion(mockRegion); - assertThat(factoryBean.getRegion(), is(sameInstance(mockRegion))); - assertThat(factoryBean.isMatch(mockSnapshotEvent), is(true)); + assertThat(factoryBean.getRegion()).isSameAs(mockRegion); + assertThat(factoryBean.isMatch(mockSnapshotEvent)).isTrue(); verify(mockSnapshotEvent, times(1)).isCacheSnapshotEvent(); verify(mockSnapshotEvent, times(1)).matches(eq(mockRegion)); @@ -749,15 +757,14 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.setImports(expectedImports); factoryBean.setRegion(null); - assertThat(factoryBean.getObject(), is(nullValue())); - assertThat((Class) factoryBean.getObjectType(), - is(equalTo(SnapshotServiceAdapter.class))); + assertThat(factoryBean.getObject()).isNull(); + assertThat((Class) factoryBean.getObjectType()).isEqualTo(SnapshotServiceAdapter.class); factoryBean.afterPropertiesSet(); - assertThat(factoryBean.getObject(), is(instanceOf(CacheSnapshotServiceAdapter.class))); - assertThat((Class) factoryBean.getObjectType(), - is(equalTo(CacheSnapshotServiceAdapter.class))); + assertThat(factoryBean.getObject()).isInstanceOf(CacheSnapshotServiceAdapter.class); + assertThat((Class) factoryBean.getObjectType()) + .isEqualTo(CacheSnapshotServiceAdapter.class); verify(mockCache, times(1)).getSnapshotService(); verify(mockCacheSnapshotService, times(2)).createOptions(); @@ -817,15 +824,14 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.setImports(expectedImports); factoryBean.setRegion(mockRegion); - assertThat(factoryBean.getObject(), is(nullValue())); - assertThat((Class) factoryBean.getObjectType(), - is(equalTo(SnapshotServiceAdapter.class))); + assertThat(factoryBean.getObject()).isNull(); + assertThat((Class) factoryBean.getObjectType()).isEqualTo(SnapshotServiceAdapter.class); factoryBean.afterPropertiesSet(); - assertThat(factoryBean.getObject(), is(instanceOf(RegionSnapshotServiceAdapter.class))); - assertThat((Class) factoryBean.getObjectType(), - is(equalTo(RegionSnapshotServiceAdapter.class))); + assertThat(factoryBean.getObject()).isInstanceOf(RegionSnapshotServiceAdapter.class); + assertThat((Class) factoryBean.getObjectType()) + .isEqualTo(RegionSnapshotServiceAdapter.class); verify(mockCache, never()).getSnapshotService(); verify(mockRegion, times(1)).getSnapshotService(); @@ -880,7 +886,7 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.afterPropertiesSet(); factoryBean.destroy(); - assertThat(factoryBean.getObject(), is(instanceOf(CacheSnapshotServiceAdapter.class))); + assertThat(factoryBean.getObject()).isInstanceOf(CacheSnapshotServiceAdapter.class); verify(mockCache, times(1)).getSnapshotService(); verify(mockCacheSnapshotService, times(2)).createOptions(); @@ -937,7 +943,7 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.afterPropertiesSet(); factoryBean.destroy(); - assertThat(factoryBean.getObject(), is(instanceOf(RegionSnapshotServiceAdapter.class))); + assertThat(factoryBean.getObject()).isInstanceOf(RegionSnapshotServiceAdapter.class); verify(mockCache, never()).getSnapshotService(); verify(mockRegion, times(1)).getSnapshotService(); @@ -980,7 +986,7 @@ public class SnapshotServiceFactoryBeanTest { snapshotMetadata.setInvokeCallbacks(true); snapshotMetadata.setParallel(true); - assertThat(snapshotService.createOptions(snapshotMetadata), is(equalTo(mockSnapshotOptions))); + assertThat(snapshotService.createOptions(snapshotMetadata)).isEqualTo(mockSnapshotOptions); verify(mockSnapshotOptions, times(1)).invokeCallbacks(eq(true)); verify(mockSnapshotOptions, times(1)).setFilter(eq(mockSnapshotFilter)); @@ -992,7 +998,7 @@ public class SnapshotServiceFactoryBeanTest { Closeable mockCloseable = mock(Closeable.class, "MockCloseable"); - assertThat(new TestSnapshotServiceAdapter().exceptionSuppressingClose(mockCloseable), is(true)); + assertThat(new TestSnapshotServiceAdapter().exceptionSuppressingClose(mockCloseable)).isTrue(); verify(mockCloseable, times(1)).close(); } @@ -1004,7 +1010,7 @@ public class SnapshotServiceFactoryBeanTest { doThrow(new IOException("TEST")).when(mockCloseable).close(); - assertThat(new TestSnapshotServiceAdapter().exceptionSuppressingClose(mockCloseable), is(false)); + assertThat(new TestSnapshotServiceAdapter().exceptionSuppressingClose(mockCloseable)).isFalse(); verify(mockCloseable, times(1)).close(); } @@ -1058,14 +1064,14 @@ public class SnapshotServiceFactoryBeanTest { TestSnapshotServiceAdapter snapshotService = new TestSnapshotServiceAdapter(); - assertThat(snapshotService.toSimpleFilename(toPathname("path", "to", "file.ext")), is(equalTo("file.ext"))); - assertThat(snapshotService.toSimpleFilename(toPathname("path", "to", "file ")), is(equalTo("file"))); - assertThat(snapshotService.toSimpleFilename(toPathname(" file.ext ")), is(equalTo("file.ext"))); - assertThat(snapshotService.toSimpleFilename(" file.ext "), is(equalTo("file.ext"))); - assertThat(snapshotService.toSimpleFilename(File.separator.concat(" ")), is(equalTo(""))); - assertThat(snapshotService.toSimpleFilename(" "), is(equalTo(""))); - assertThat(snapshotService.toSimpleFilename(""), is(equalTo(""))); - assertThat(snapshotService.toSimpleFilename(null), is(nullValue())); + assertThat(snapshotService.toSimpleFilename(toPathname("path", "to", "file.ext"))).isEqualTo("file.ext"); + assertThat(snapshotService.toSimpleFilename(toPathname("path", "to", "file "))).isEqualTo("file"); + assertThat(snapshotService.toSimpleFilename(toPathname(" file.ext "))).isEqualTo("file.ext"); + assertThat(snapshotService.toSimpleFilename(" file.ext ")).isEqualTo("file.ext"); + assertThat(snapshotService.toSimpleFilename(File.separator.concat(" "))).isEqualTo(""); + assertThat(snapshotService.toSimpleFilename(" ")).isEqualTo(""); + assertThat(snapshotService.toSimpleFilename("")).isEqualTo(""); + assertThat(snapshotService.toSimpleFilename(null)).isNull(); } @Test(expected = ImportSnapshotException.class) @@ -1078,18 +1084,18 @@ public class SnapshotServiceFactoryBeanTest { CacheSnapshotServiceAdapter adapter = new CacheSnapshotServiceAdapter(mockCacheSnapshotService); - assertThat(adapter.getSnapshotService(), is(equalTo(mockCacheSnapshotService))); + assertThat(adapter.getSnapshotService()).isEqualTo(mockCacheSnapshotService); try { adapter.load(FileSystemUtils.WORKING_DIRECTORY, SnapshotFormat.GEMFIRE); } catch (ImportSnapshotException expected) { - assertThat(expected.getMessage(), is(equalTo(String.format( + assertThat(expected.getMessage()).isEqualTo(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"))); + FileSystemUtils.WORKING_DIRECTORY)); + assertThat(expected.getCause()).isInstanceOf(IOException.class); + assertThat(expected.getCause().getMessage()).isEqualTo("TEST"); throw expected; } @@ -1112,18 +1118,18 @@ public class SnapshotServiceFactoryBeanTest { CacheSnapshotServiceAdapter adapter = new CacheSnapshotServiceAdapter(mockCacheSnapshotService); - assertThat(adapter.getSnapshotService(), is(equalTo(mockCacheSnapshotService))); + assertThat(adapter.getSnapshotService()).isEqualTo(mockCacheSnapshotService); try { adapter.load(SnapshotFormat.GEMFIRE, mockSnapshotOptions, snapshotDat); } catch (ImportSnapshotException expected) { - assertThat(expected.getMessage(), is(equalTo(String.format( + assertThat(expected.getMessage()).isEqualTo(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"))); + Arrays.toString(new File[] { snapshotDat }), mockSnapshotOptions)); + assertThat(expected.getCause()).isInstanceOf(ClassCastException.class); + assertThat(expected.getCause().getMessage()).isEqualTo("TEST"); throw expected; } @@ -1143,18 +1149,18 @@ public class SnapshotServiceFactoryBeanTest { CacheSnapshotServiceAdapter adapter = new CacheSnapshotServiceAdapter(mockCacheSnapshotService); - assertThat(adapter.getSnapshotService(), is(equalTo(mockCacheSnapshotService))); + assertThat(adapter.getSnapshotService()).isEqualTo(mockCacheSnapshotService); try { adapter.save(FileSystemUtils.WORKING_DIRECTORY, SnapshotFormat.GEMFIRE); } catch (ExportSnapshotException expected) { - assertThat(expected.getMessage(), is(equalTo(String.format( + assertThat(expected.getMessage()).isEqualTo(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"))); + FileSystemUtils.WORKING_DIRECTORY)); + assertThat(expected.getCause()).isInstanceOf(IOException.class); + assertThat(expected.getCause().getMessage()).isEqualTo("TEST"); throw expected; } @@ -1177,18 +1183,18 @@ public class SnapshotServiceFactoryBeanTest { CacheSnapshotServiceAdapter adapter = new CacheSnapshotServiceAdapter(mockCacheSnapshotService); - assertThat(adapter.getSnapshotService(), is(equalTo(mockCacheSnapshotService))); + assertThat(adapter.getSnapshotService()).isEqualTo(mockCacheSnapshotService); try { adapter.save(FileSystemUtils.USER_HOME, SnapshotFormat.GEMFIRE, mockSnapshotOptions); } catch (ExportSnapshotException expected) { - assertThat(expected.getMessage(), is(equalTo(String.format( + assertThat(expected.getMessage()).isEqualTo(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"))); + FileSystemUtils.USER_HOME, mockSnapshotOptions)); + assertThat(expected.getCause()).isInstanceOf(ClassCastException.class); + assertThat(expected.getCause().getMessage()).isEqualTo("TEST"); throw expected; } @@ -1209,17 +1215,17 @@ public class SnapshotServiceFactoryBeanTest { RegionSnapshotServiceAdapter adapter = new RegionSnapshotServiceAdapter(mockRegionSnapshotService); - assertThat(adapter.getSnapshotService(), is(equalTo(mockRegionSnapshotService))); + assertThat(adapter.getSnapshotService()).isEqualTo(mockRegionSnapshotService); try { 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"))); + assertThat(expected.getMessage()).isEqualTo(String.format( + "Failed to load snapshot from file [%1$s] in format [GEMFIRE]", snapshotDat)); + assertThat(expected.getCause()).isInstanceOf(IOException.class); + assertThat(expected.getCause().getMessage()).isEqualTo("TEST"); throw expected; } @@ -1241,18 +1247,18 @@ public class SnapshotServiceFactoryBeanTest { RegionSnapshotServiceAdapter adapter = new RegionSnapshotServiceAdapter(mockRegionSnapshotService); - assertThat(adapter.getSnapshotService(), is(equalTo(mockRegionSnapshotService))); + assertThat(adapter.getSnapshotService()).isEqualTo(mockRegionSnapshotService); try { adapter.load(SnapshotFormat.GEMFIRE, mockSnapshotOptions, snapshotDat); } catch (ImportSnapshotException expected) { - assertThat(expected.getMessage(), is(equalTo(String.format( + assertThat(expected.getMessage()).isEqualTo(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"))); + Arrays.toString(new File[] { snapshotDat }), mockSnapshotOptions)); + assertThat(expected.getCause()).isInstanceOf(ClassCastException.class); + assertThat(expected.getCause().getMessage()).isEqualTo("TEST"); throw expected; } @@ -1273,17 +1279,17 @@ public class SnapshotServiceFactoryBeanTest { RegionSnapshotServiceAdapter adapter = new RegionSnapshotServiceAdapter(mockRegionSnapshotService); - assertThat(adapter.getSnapshotService(), is(equalTo(mockRegionSnapshotService))); + assertThat(adapter.getSnapshotService()).isEqualTo(mockRegionSnapshotService); try { 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"))); + assertThat(expected.getMessage()).isEqualTo(String.format( + "Failed to save snapshot to file [%1$s] in format [GEMFIRE]", snapshotDat)); + assertThat(expected.getCause()).isInstanceOf(IOException.class); + assertThat(expected.getCause().getMessage()).isEqualTo("TEST"); throw expected; } @@ -1306,18 +1312,18 @@ public class SnapshotServiceFactoryBeanTest { RegionSnapshotServiceAdapter adapter = new RegionSnapshotServiceAdapter(mockRegionSnapshotService); - assertThat(adapter.getSnapshotService(), is(equalTo(mockRegionSnapshotService))); + assertThat(adapter.getSnapshotService()).isEqualTo(mockRegionSnapshotService); try { adapter.save(snapshotDat, SnapshotFormat.GEMFIRE, mockSnapshotOptions); } catch (ExportSnapshotException expected) { - assertThat(expected.getMessage(), is(equalTo(String.format( + assertThat(expected.getMessage()).isEqualTo(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"))); + snapshotDat, mockSnapshotOptions)); + assertThat(expected.getCause()).isInstanceOf(ClassCastException.class); + assertThat(expected.getCause().getMessage()).isEqualTo("TEST"); throw expected; } @@ -1327,14 +1333,19 @@ public class SnapshotServiceFactoryBeanTest { } } - @Test + @Test(expected = IllegalArgumentException.class) public void createSnapshotMetadataWithNullLocation() { - exception.expect(IllegalArgumentException.class); - exception.expectCause(is(nullValue(Throwable.class))); - exception.expectMessage("Location is required"); + try { + new SnapshotMetadata(null, SnapshotFormat.GEMFIRE, mock(SnapshotFilter.class)); + } + catch (IllegalArgumentException expected) { - new SnapshotMetadata(null, SnapshotFormat.GEMFIRE, mock(SnapshotFilter.class)); + assertThat(expected).hasMessage("Location is required"); + assertThat(expected).hasNoCause(); + + throw expected; + } } @Test @@ -1342,13 +1353,13 @@ public class SnapshotServiceFactoryBeanTest { SnapshotMetadata snapshotMetadata = new SnapshotMetadata(snapshotDat, SnapshotFormat.GEMFIRE, null); - assertThat(snapshotMetadata.getLocation(), is(equalTo(snapshotDat))); - assertThat(snapshotMetadata.isDirectory(), is(false)); - assertThat(snapshotMetadata.isFile(), is(true)); - assertThat(snapshotMetadata.getFormat(), is(equalTo(SnapshotFormat.GEMFIRE))); - assertThat(snapshotMetadata.isFilterPresent(), is(false)); - assertThat(snapshotMetadata.getFilter(), is(nullValue())); - assertThat(snapshotMetadata.isParallel(), is(false)); + assertThat(snapshotMetadata.getLocation()).isEqualTo(snapshotDat); + assertThat(snapshotMetadata.isDirectory()).isFalse(); + assertThat(snapshotMetadata.isFile()).isTrue(); + assertThat(snapshotMetadata.getFormat()).isEqualTo(SnapshotFormat.GEMFIRE); + assertThat(snapshotMetadata.isFilterPresent()).isFalse(); + assertThat(snapshotMetadata.getFilter()).isNull(); + assertThat(snapshotMetadata.isParallel()).isFalse(); } @Test @@ -1359,13 +1370,13 @@ public class SnapshotServiceFactoryBeanTest { SnapshotMetadata snapshotMetadata = new SnapshotMetadata(FileSystemUtils.WORKING_DIRECTORY, null, mockSnapshotFilter); - assertThat(snapshotMetadata.getLocation(), is(equalTo(FileSystemUtils.WORKING_DIRECTORY))); - assertThat(snapshotMetadata.isDirectory(), is(true)); - assertThat(snapshotMetadata.isFile(), is(false)); - assertThat(snapshotMetadata.getFormat(), is(equalTo(SnapshotFormat.GEMFIRE))); - assertThat(snapshotMetadata.isFilterPresent(), is(true)); - assertThat(snapshotMetadata.getFilter(), is(equalTo(mockSnapshotFilter))); - assertThat(snapshotMetadata.isParallel(), is(false)); + assertThat(snapshotMetadata.getLocation()).isEqualTo(FileSystemUtils.WORKING_DIRECTORY); + assertThat(snapshotMetadata.isDirectory()).isTrue(); + assertThat(snapshotMetadata.isFile()).isFalse(); + assertThat(snapshotMetadata.getFormat()).isEqualTo(SnapshotFormat.GEMFIRE); + assertThat(snapshotMetadata.isFilterPresent()).isTrue(); + assertThat(snapshotMetadata.getFilter()).isEqualTo(mockSnapshotFilter); + assertThat(snapshotMetadata.isParallel()).isFalse(); } @Test @@ -1377,44 +1388,44 @@ public class SnapshotServiceFactoryBeanTest { // JDK if (!runtimeDotJar.isFile()) { runtimeDotJar = new File(new File(new File(FileSystemUtils.JAVA_HOME, "jre"), "lib"), "rt.jar"); - assumeThat(runtimeDotJar.isFile(), is(true)); + assumeThat(runtimeDotJar.isFile()).isTrue(); } - assertThat(ArchiveFileFilter.INSTANCE.isJarFile(runtimeDotJar), is(true)); + assertThat(ArchiveFileFilter.INSTANCE.isJarFile(runtimeDotJar)).isTrue(); } @Test public void isJarFileIsFalse() throws Exception { - assertThat(ArchiveFileFilter.INSTANCE.isJarFile(new File("/path/to/non-existing/file.jar")), is(false)); - assertThat(ArchiveFileFilter.INSTANCE.isJarFile(new ClassPathResource("/cluster_config.zip").getFile()), is(false)); - assertThat(ArchiveFileFilter.INSTANCE.isJarFile(new File("to/file.tar")), is(false)); - assertThat(ArchiveFileFilter.INSTANCE.isJarFile(new File("jar.file")), is(false)); - assertThat(ArchiveFileFilter.INSTANCE.isJarFile(new File(" ")), is(false)); - assertThat(ArchiveFileFilter.INSTANCE.isJarFile(new File("")), is(false)); - assertThat(ArchiveFileFilter.INSTANCE.isJarFile(null), is(false)); + assertThat(ArchiveFileFilter.INSTANCE.isJarFile(new File("/path/to/non-existing/file.jar"))).isFalse(); + assertThat(ArchiveFileFilter.INSTANCE.isJarFile(new ClassPathResource("/cluster_config.zip").getFile())).isFalse(); + assertThat(ArchiveFileFilter.INSTANCE.isJarFile(new File("to/file.tar"))).isFalse(); + assertThat(ArchiveFileFilter.INSTANCE.isJarFile(new File("jar.file"))).isFalse(); + assertThat(ArchiveFileFilter.INSTANCE.isJarFile(new File(" "))).isFalse(); + assertThat(ArchiveFileFilter.INSTANCE.isJarFile(new File(""))).isFalse(); + assertThat(ArchiveFileFilter.INSTANCE.isJarFile(null)).isFalse(); } @Test public void getFileExtensionOfVariousFiles() throws Exception { - assertThat(ArchiveFileFilter.INSTANCE.getFileExtension(new ClassPathResource("/cluster_config.zip").getFile()), is(equalTo("zip"))); - assertThat(ArchiveFileFilter.INSTANCE.getFileExtension(new File("/path/to/non-existing/file.jar")), is(equalTo(""))); - assertThat(ArchiveFileFilter.INSTANCE.getFileExtension(new File("to/non-existing/file.tar")), is(equalTo(""))); - assertThat(ArchiveFileFilter.INSTANCE.getFileExtension(FileSystemUtils.WORKING_DIRECTORY), is(equalTo(""))); - assertThat(ArchiveFileFilter.INSTANCE.getFileExtension(new File(" ")), is(equalTo(""))); - assertThat(ArchiveFileFilter.INSTANCE.getFileExtension(new File("")), is(equalTo(""))); - assertThat(ArchiveFileFilter.INSTANCE.getFileExtension(null), is(equalTo(""))); + assertThat(ArchiveFileFilter.INSTANCE.getFileExtension(new ClassPathResource("/cluster_config.zip").getFile())).isEqualTo("zip"); + assertThat(ArchiveFileFilter.INSTANCE.getFileExtension(new File("/path/to/non-existing/file.jar"))).isEqualTo(""); + assertThat(ArchiveFileFilter.INSTANCE.getFileExtension(new File("to/non-existing/file.tar"))).isEqualTo(""); + assertThat(ArchiveFileFilter.INSTANCE.getFileExtension(FileSystemUtils.WORKING_DIRECTORY)).isEqualTo(""); + assertThat(ArchiveFileFilter.INSTANCE.getFileExtension(new File(" "))).isEqualTo(""); + assertThat(ArchiveFileFilter.INSTANCE.getFileExtension(new File(""))).isEqualTo(""); + assertThat(ArchiveFileFilter.INSTANCE.getFileExtension(null)).isEqualTo(""); } @Test public void archiveFileFilterAcceptsJarOrZipFile() throws Exception { - assertThat(ArchiveFileFilter.INSTANCE.accept(new ClassPathResource("/cluster_config.zip").getFile()), is(true)); + assertThat(ArchiveFileFilter.INSTANCE.accept(new ClassPathResource("/cluster_config.zip").getFile())).isTrue(); } @Test public void archiveFileFilterRejectsTarFile() { - assertThat(ArchiveFileFilter.INSTANCE.accept(new File("/path/to/file.tar")), is(false)); + assertThat(ArchiveFileFilter.INSTANCE.accept(new File("/path/to/file.tar"))).isFalse(); } protected static class TestSnapshotServiceAdapter extends SnapshotServiceAdapterSupport { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceImportExportIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceImportExportIntegrationTest.java index 0c8f8084..c7c1bf5f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceImportExportIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceImportExportIntegrationTest.java @@ -13,48 +13,43 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.snapshot; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; -import org.apache.geode.cache.Region; - import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.apache.geode.cache.Region; + import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.io.ClassPathResource; import org.springframework.data.gemfire.repository.sample.Person; -import org.springframework.data.gemfire.test.support.FileSystemUtils; -import org.springframework.data.gemfire.test.support.ThreadUtils; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.util.FileSystemUtils; +import org.springframework.data.gemfire.tests.util.ThreadUtils; import org.springframework.util.FileCopyUtils; /** - * The SnapshotServiceImportExportIntegrationTest class is a test suite of test cases testing the import and export - * of GemFire Cache Region data configured with SDG's Data Namespace >gfe-data:snapshot-service< (XML) element. + * Integration Tests with test cases testing the import and export of cache {@link Region} data configured with + * SDG's Data Namespace >gfe-data:snapshot-service< (XML) element. * * @author John Blum * @see org.junit.Test - * @see org.springframework.context.ConfigurableApplicationContext - * @see org.springframework.context.support.ClassPathXmlApplicationContext - * @see org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBean - * @see org.springframework.data.gemfire.repository.sample.Person * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBean + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport * @since 1.7.0 */ @SuppressWarnings("unused") -public class SnapshotServiceImportExportIntegrationTest { +public class SnapshotServiceImportExportIntegrationTest extends IntegrationTestsSupport { private static final AtomicLong ID_SEQUENCE = new AtomicLong(0L); @@ -65,27 +60,27 @@ public class SnapshotServiceImportExportIntegrationTest { private static Region people; - protected static void assertPerson(Person expectedPerson, Person actualPerson) { + private static void assertPerson(Person expectedPerson, Person actualPerson) { - assertThat(actualPerson, is(notNullValue())); - assertThat(actualPerson.getId(), is(equalTo(expectedPerson.getId()))); - assertThat(actualPerson.getFirstname(), is(equalTo(expectedPerson.getFirstname()))); - assertThat(actualPerson.getLastname(), is(equalTo(expectedPerson.getLastname()))); + assertThat(actualPerson).isNotNull(); + assertThat(actualPerson.getId()).isEqualTo(expectedPerson.getId()); + assertThat(actualPerson.getFirstname()).isEqualTo(expectedPerson.getFirstname()); + assertThat(actualPerson.getLastname()).isEqualTo(expectedPerson.getLastname()); } - protected static void assertRegion(Region actualRegion, String expectedName, int expectedSize) { + private static void assertRegion(Region actualRegion, String expectedName, int expectedSize) { - assertThat(actualRegion, is(notNullValue())); - assertThat(actualRegion.getName(), is(equalTo("People"))); - assertThat(actualRegion.getFullPath(), is(equalTo(String.format("%1$s%2$s", Region.SEPARATOR, expectedName)))); - assertThat(actualRegion.size(), is(expectedSize)); + assertThat(actualRegion).isNotNull(); + assertThat(actualRegion.getName()).isEqualTo("People"); + assertThat(actualRegion.getFullPath()).isEqualTo(String.format("%1$s%2$s", Region.SEPARATOR, expectedName)); + assertThat(actualRegion.size()).isEqualTo(expectedSize); } - protected static Person newPerson(String firstName, String lastName) { + private static Person newPerson(String firstName, String lastName) { return newPerson(ID_SEQUENCE.incrementAndGet(), firstName, lastName); } - protected static Person newPerson(Long id, String firstName, String lastName) { + private static Person newPerson(Long id, String firstName, String lastName) { return new Person(id, firstName, lastName); } @@ -98,15 +93,15 @@ public class SnapshotServiceImportExportIntegrationTest { File exportDirectory = new File(snapshotsDirectory, "export"); File importDirectory = new File(snapshotsDirectory, "import"); - assertThat(exportDirectory.isDirectory() || exportDirectory.mkdirs(), is(true)); - assertThat(importDirectory.isDirectory() || importDirectory.mkdirs(), is(true)); + assertThat(exportDirectory.isDirectory() || exportDirectory.mkdirs()).isTrue(); + assertThat(importDirectory.isDirectory() || importDirectory.mkdirs()).isTrue(); importPeopleSnapshot = new File(importDirectory, "people-snapshot.gfd"); FileCopyUtils.copy(new ClassPathResource("/people.snapshot").getFile(), importPeopleSnapshot); - assertThat(importPeopleSnapshot.isFile(), is(true)); - assertThat(importPeopleSnapshot.length() > 0, is(true)); + assertThat(importPeopleSnapshot.isFile()).isTrue(); + assertThat(importPeopleSnapshot.length() > 0).isTrue(); applicationContext = new ClassPathXmlApplicationContext( SnapshotServiceImportExportIntegrationTest.class.getName().replace(".", "/").concat("-context.xml")); @@ -123,8 +118,8 @@ public class SnapshotServiceImportExportIntegrationTest { File exportPeopleSnapshot = new File(new File(snapshotsDirectory, "export"), "people-snapshot.gfd"); - assertThat(exportPeopleSnapshot.isFile(), is(true)); - assertThat(exportPeopleSnapshot.length(), is(equalTo(importPeopleSnapshot.length()))); + assertThat(exportPeopleSnapshot.isFile()).isTrue(); + assertThat(exportPeopleSnapshot.length()).isEqualTo(importPeopleSnapshot.length()); FileSystemUtils.deleteRecursive(snapshotsDirectory.getParentFile()); } @@ -135,7 +130,8 @@ public class SnapshotServiceImportExportIntegrationTest { ThreadUtils.timedWait(TimeUnit.SECONDS.toMillis(5), 500, () -> !(people.size() > 0)); } - protected void setupPeople() { + private void setupPeople() { + put(newPerson("Jon", "Doe")); put(newPerson("Jane", "Doe")); put(newPerson("Cookie", "Doe")); @@ -147,13 +143,14 @@ public class SnapshotServiceImportExportIntegrationTest { put(newPerson("Sour", "Doe")); } - protected Person put(Person person) { + private Person put(Person person) { people.putIfAbsent(person.getId(), person); return person; } @Test public void peopleRegionIsLoaded() { + assertRegion(people, "People", 9); assertPerson(people.get(1L), newPerson(1L, "Jon", "Doe")); assertPerson(people.get(2L), newPerson(2L, "Jane", "Doe")); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/event/SnapshotApplicationEventTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/event/SnapshotApplicationEventTest.java index 27500184..8ff6a2da 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/event/SnapshotApplicationEventTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/event/SnapshotApplicationEventTest.java @@ -13,38 +13,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.snapshot.event; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.CoreMatchers.sameInstance; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBean.SnapshotMetadata; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.snapshot.SnapshotOptions; - import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.data.gemfire.test.support.FileSystemUtils; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.snapshot.SnapshotOptions; + +import org.springframework.data.gemfire.tests.util.FileSystemUtils; /** - * The SnapshotApplicationEventTest class is a test suite of test cases testing the contract and functionality - * of the SnapshotApplicationEvent class. + * Unit Tests testing the contract and functionality of the {@link SnapshotApplicationEvent} class. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith * @see org.mockito.Mock * @see org.mockito.Mockito * @see org.mockito.junit.MockitoJUnitRunner @@ -66,73 +58,75 @@ public class SnapshotApplicationEventTest { @Test public void constructSnapshotApplicationEventWithoutRegionOrSnapshotMetadata() { - SnapshotApplicationEvent event = new TestSnapshotApplicationEvent(this); + SnapshotApplicationEvent event = new TestSnapshotApplicationEvent<>(this); - assertThat(event.getSource(), is(equalTo(this))); - assertThat(event.getRegionPath(), is(nullValue())); - assertThat(event.getSnapshotMetadata(), is(notNullValue())); - assertThat(event.getSnapshotMetadata().length, is(equalTo(0))); - assertThat(event.isCacheSnapshotEvent(), is(true)); - assertThat(event.isRegionSnapshotEvent(), is(false)); + assertThat(event.getSource()).isEqualTo(this); + assertThat(event.getRegionPath()).isNull(); + assertThat(event.getSnapshotMetadata()).isNotNull(); + assertThat(event.getSnapshotMetadata().length).isEqualTo(0); + assertThat(event.isCacheSnapshotEvent()).isTrue(); + assertThat(event.isRegionSnapshotEvent()).isFalse(); } @Test public void constructSnapshotApplicationEventWithRegionAndSnapshotMetadata() { - SnapshotMetadata eventSnapshotMetadata = newSnapshotMetadata(); + SnapshotMetadata eventSnapshotMetadata = newSnapshotMetadata(); - SnapshotApplicationEvent event = new TestSnapshotApplicationEvent(this, "/Example", eventSnapshotMetadata); + SnapshotApplicationEvent event = + new TestSnapshotApplicationEvent<>(this, "/Example", eventSnapshotMetadata); - assertThat(event.getSource(), is(equalTo(this))); - assertThat(event.getRegionPath(), is(equalTo("/Example"))); - assertThat(event.getSnapshotMetadata()[0], is(sameInstance(eventSnapshotMetadata))); - assertThat(event.isCacheSnapshotEvent(), is(false)); - assertThat(event.isRegionSnapshotEvent(), is(true)); + assertThat(event.getSource()).isEqualTo(this); + assertThat(event.getRegionPath()).isEqualTo("/Example"); + assertThat(event.getSnapshotMetadata()[0]).isSameAs(eventSnapshotMetadata); + assertThat(event.isCacheSnapshotEvent()).isFalse(); + assertThat(event.isRegionSnapshotEvent()).isTrue(); } @Test public void constructSnapshotApplicationEventWithRegionButNoSnapshotMetadata() { - SnapshotApplicationEvent event = new TestSnapshotApplicationEvent(this, "/Example"); + SnapshotApplicationEvent event = new TestSnapshotApplicationEvent<>(this, "/Example"); - assertThat(event.getSource(), is(equalTo(this))); - assertThat(event.getRegionPath(), is(equalTo("/Example"))); - assertThat(event.getSnapshotMetadata(), is(notNullValue())); - assertThat(event.getSnapshotMetadata().length, is(equalTo(0))); - assertThat(event.isCacheSnapshotEvent(), is(false)); - assertThat(event.isRegionSnapshotEvent(), is(true)); + assertThat(event.getSource()).isEqualTo(this); + assertThat(event.getRegionPath()).isEqualTo("/Example"); + assertThat(event.getSnapshotMetadata()).isNotNull(); + assertThat(event.getSnapshotMetadata().length).isEqualTo(0); + assertThat(event.isCacheSnapshotEvent()).isFalse(); + assertThat(event.isRegionSnapshotEvent()).isTrue(); } @Test + @SuppressWarnings("rawtypes") public void constructSnapshotApplicationEventWithSnapshotMetadataButNoRegion() { - SnapshotMetadata eventSnapshotMetadataOne = newSnapshotMetadata(); - SnapshotMetadata eventSnapshotMetadataTwo = newSnapshotMetadata(); + SnapshotMetadata eventSnapshotMetadataOne = newSnapshotMetadata(); + SnapshotMetadata eventSnapshotMetadataTwo = newSnapshotMetadata(); SnapshotApplicationEvent event = new TestSnapshotApplicationEvent(this, eventSnapshotMetadataOne, eventSnapshotMetadataTwo); - assertThat(event.getSource(), is(equalTo(this))); - assertThat(event.getRegionPath(), is(nullValue())); - assertThat(event.getSnapshotMetadata()[0], is(equalTo(eventSnapshotMetadataOne))); - assertThat(event.getSnapshotMetadata()[1], is(equalTo(eventSnapshotMetadataTwo))); - assertThat(event.isCacheSnapshotEvent(), is(true)); - assertThat(event.isRegionSnapshotEvent(), is(false)); + assertThat(event.getSource()).isEqualTo(this); + assertThat(event.getRegionPath()).isNull(); + assertThat(event.getSnapshotMetadata()[0]).isEqualTo(eventSnapshotMetadataOne); + assertThat(event.getSnapshotMetadata()[1]).isEqualTo(eventSnapshotMetadataTwo); + assertThat(event.isCacheSnapshotEvent()).isTrue(); + assertThat(event.isRegionSnapshotEvent()).isFalse(); } @Test public void matchesNullRegionIsFalse() { - assertThat(new TestSnapshotApplicationEvent(this).matches((Region) null), is(false)); + assertThat(new TestSnapshotApplicationEvent<>(this).matches((Region) null)).isFalse(); } @Test public void matchesNonMatchingRegionIsFalse() { - Region mockRegion = mock(Region.class, "MockRegion"); + Region mockRegion = mock(Region.class, "MockRegion"); when(mockRegion.getFullPath()).thenReturn("/Example"); - assertThat(new TestSnapshotApplicationEvent(this, "/Prototype").matches(mockRegion), is(false)); + assertThat(new TestSnapshotApplicationEvent<>(this, "/Prototype").matches(mockRegion)).isFalse(); verify(mockRegion, times(1)).getFullPath(); } @@ -140,11 +134,11 @@ public class SnapshotApplicationEventTest { @Test public void matchesMatchingRegionIsTrue() { - Region mockRegion = mock(Region.class, "MockRegion"); + Region mockRegion = mock(Region.class, "MockRegion"); when(mockRegion.getFullPath()).thenReturn("/Example"); - assertThat(new TestSnapshotApplicationEvent(this, "/Example").matches(mockRegion), is(true)); + assertThat(new TestSnapshotApplicationEvent<>(this, "/Example").matches(mockRegion)).isTrue(); verify(mockRegion, times(1)).getFullPath(); } @@ -152,32 +146,32 @@ public class SnapshotApplicationEventTest { @Test public void matchesNonMatchingRegionPathsIsFalse() { - SnapshotApplicationEvent event = new TestSnapshotApplicationEvent(this, "/Example"); + SnapshotApplicationEvent event = new TestSnapshotApplicationEvent<>(this, "/Example"); - assertThat(event.getRegionPath(), is(equalTo("/Example"))); - assertThat(event.matches("Example"), is(false)); - assertThat(event.matches("/Sample"), is(false)); - assertThat(event.matches("/Prototype"), is(false)); - assertThat(event.matches("/example"), is(false)); - assertThat(event.matches("/Exam"), is(false)); - assertThat(event.matches("/Xmpl"), is(false)); - assertThat(event.matches("/Ex."), is(false)); - assertThat(event.matches("/E.g."), is(false)); - assertThat(event.matches("/"), is(false)); - assertThat(event.matches(" "), is(false)); - assertThat(event.matches(""), is(false)); - assertThat(event.matches((String) null), is(false)); + assertThat(event.getRegionPath()).isEqualTo("/Example"); + assertThat(event.matches("Example")).isFalse(); + assertThat(event.matches("/Sample")).isFalse(); + assertThat(event.matches("/Prototype")).isFalse(); + assertThat(event.matches("/example")).isFalse(); + assertThat(event.matches("/Exam")).isFalse(); + assertThat(event.matches("/Xmpl")).isFalse(); + assertThat(event.matches("/Ex.")).isFalse(); + assertThat(event.matches("/E.g.")).isFalse(); + assertThat(event.matches("/")).isFalse(); + assertThat(event.matches(" ")).isFalse(); + assertThat(event.matches("")).isFalse(); + assertThat(event.matches((String) null)).isFalse(); } @Test public void matchesMatchingRegionPathsIsTrue() { - assertThat(new TestSnapshotApplicationEvent(this, "/Example").matches("/Example"), is(true)); - assertThat(new TestSnapshotApplicationEvent(this, "/").matches("/"), is(true)); - assertThat(new TestSnapshotApplicationEvent(this, " ").matches(" "), is(true)); - assertThat(new TestSnapshotApplicationEvent(this, "").matches(" "), is(true)); - assertThat(new TestSnapshotApplicationEvent(this, "").matches(""), is(true)); - assertThat(new TestSnapshotApplicationEvent(this, (String) null).matches((String) null), is(true)); + assertThat(new TestSnapshotApplicationEvent<>(this, "/Example").matches("/Example")).isTrue(); + assertThat(new TestSnapshotApplicationEvent<>(this, "/").matches("/")).isTrue(); + assertThat(new TestSnapshotApplicationEvent<>(this, " ").matches(" ")).isTrue(); + assertThat(new TestSnapshotApplicationEvent<>(this, "").matches(" ")).isTrue(); + assertThat(new TestSnapshotApplicationEvent<>(this, "").matches("")).isTrue(); + assertThat(new TestSnapshotApplicationEvent<>(this, (String) null).matches((String) null)).isTrue(); } protected static final class TestSnapshotApplicationEvent extends SnapshotApplicationEvent { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/GemfireBeanFactoryLocatorAnnotationConfigIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/GemfireBeanFactoryLocatorAnnotationConfigIntegrationTests.java index d89f9ce5..1c65975d 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/GemfireBeanFactoryLocatorAnnotationConfigIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/GemfireBeanFactoryLocatorAnnotationConfigIntegrationTests.java @@ -14,7 +14,6 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.support; import static org.assertj.core.api.Assertions.assertThat; @@ -29,26 +28,28 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.config.annotation.PeerCacheApplication; -import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration tests using Java-based configuration for {@link GemfireBeanFactoryLocator}. + * Integration Tests using Java-based configuration for {@link GemfireBeanFactoryLocator}. * * @author John Blum * @see org.junit.Test * @see org.springframework.beans.factory.BeanFactory * @see org.springframework.data.gemfire.config.annotation.PeerCacheApplication * @see org.springframework.data.gemfire.support.GemfireBeanFactoryLocator - * @see org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.0.0 */ @RunWith(SpringRunner.class) @ContextConfiguration -public class GemfireBeanFactoryLocatorAnnotationConfigIntegrationTests { +public class GemfireBeanFactoryLocatorAnnotationConfigIntegrationTests extends IntegrationTestsSupport { @Autowired @SuppressWarnings("unused") @@ -87,8 +88,8 @@ public class GemfireBeanFactoryLocatorAnnotationConfigIntegrationTests { static class TestConfiguration { @Bean - GemfireTestBeanPostProcessor gemfireTestBeanPostProcessor() { - return new GemfireTestBeanPostProcessor(); + GemFireMockObjectsBeanPostProcessor gemfireTestBeanPostProcessor() { + return new GemFireMockObjectsBeanPostProcessor(); } @Bean(name = { "testBeanFactoryLocator", "aliasOne", "aliasTwo" }) diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/GemfireBeanFactoryLocatorJavaConfigIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/GemfireBeanFactoryLocatorJavaConfigIntegrationTests.java index 4c01b765..bf93dcb4 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/GemfireBeanFactoryLocatorJavaConfigIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/GemfireBeanFactoryLocatorJavaConfigIntegrationTests.java @@ -14,7 +14,6 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.support; import static org.assertj.core.api.Assertions.assertThat; @@ -30,26 +29,30 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.gemfire.CacheFactoryBean; -import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration tests using Java-based configuration for {@link GemfireBeanFactoryLocator}. + * Integration Tests using Java-based configuration for {@link GemfireBeanFactoryLocator}. * * @author John Blum * @see org.junit.Test * @see org.springframework.beans.factory.BeanFactory + * @see org.springframework.context.annotation.Bean + * @see org.springframework.context.annotation.Configuration * @see org.springframework.data.gemfire.CacheFactoryBean * @see org.springframework.data.gemfire.support.GemfireBeanFactoryLocator - * @see org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.0.0 */ @RunWith(SpringRunner.class) @ContextConfiguration -public class GemfireBeanFactoryLocatorJavaConfigIntegrationTests { +public class GemfireBeanFactoryLocatorJavaConfigIntegrationTests extends IntegrationTestsSupport { @Autowired @SuppressWarnings("unused") @@ -88,8 +91,8 @@ public class GemfireBeanFactoryLocatorJavaConfigIntegrationTests { static class TestConfiguration { @Bean - GemfireTestBeanPostProcessor gemfireTestBeanPostProcessor() { - return new GemfireTestBeanPostProcessor(); + GemFireMockObjectsBeanPostProcessor gemfireTestBeanPostProcessor() { + return new GemFireMockObjectsBeanPostProcessor(); } @Bean diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/LazyWiringDeclarableSupportIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/LazyWiringDeclarableSupportIntegrationTests.java index dbdab30e..f14b8c70 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/LazyWiringDeclarableSupportIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/LazyWiringDeclarableSupportIntegrationTests.java @@ -14,38 +14,36 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.support; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.Matchers.startsWith; import static org.springframework.data.gemfire.support.WiringDeclarableSupport.TEMPLATE_BEAN_NAME_PROPERTY; import java.util.Properties; import javax.sql.DataSource; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.data.gemfire.repository.sample.User; -import org.springframework.data.gemfire.test.support.DataSourceAdapter; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.support.DataSourceAdapter; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.Assert; /** - * Integration tests for {@link LazyWiringDeclarableSupport}. + * Integration Tests for {@link LazyWiringDeclarableSupport}. * * @author John Blum + * @see java.util.Properties * @see org.junit.Test + * @see org.springframework.context.ApplicationContext + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 1.3.4 @@ -53,10 +51,7 @@ import org.springframework.util.Assert; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class LazyWiringDeclarableSupportIntegrationTests { - - @Rule - public ExpectedException exception = ExpectedException.none(); +public class LazyWiringDeclarableSupportIntegrationTests extends IntegrationTestsSupport { @Autowired private ApplicationContext applicationContext; @@ -69,6 +64,7 @@ public class LazyWiringDeclarableSupportIntegrationTests { @Test public void autoWiringSuccessful() { + TestDeclarable declarable = new TestDeclarable(); declarable.init(createParameters("testParam", "testValue")); @@ -82,6 +78,7 @@ public class LazyWiringDeclarableSupportIntegrationTests { @Test public void autoWiringWithBeanTemplateSuccessful() { + TestDeclarable declarable = new TestDeclarable(); declarable.init(createParameters(TEMPLATE_BEAN_NAME_PROPERTY, "declarableTemplateBean")); @@ -93,21 +90,25 @@ public class LazyWiringDeclarableSupportIntegrationTests { assertThat(declarable.getUser().getUsername()).isEqualTo("supertool"); } - @Test + @Test(expected = IllegalArgumentException.class) public void autoWiringWithNonExistingBeanTemplateThrowsIllegalArgumentException() { - exception.expect(IllegalArgumentException.class); - exception.expectCause(is(nullValue(Throwable.class))); - exception.expectMessage(startsWith( - "Cannot find bean with name [nonExistingBeanTemplate]")); - TestDeclarable declarable = new TestDeclarable(); + try { + TestDeclarable declarable = new TestDeclarable(); - declarable.init(createParameters(TEMPLATE_BEAN_NAME_PROPERTY, "nonExistingBeanTemplate")); - declarable.onApplicationEvent(new ContextRefreshedEvent(applicationContext)); + declarable.init(createParameters(TEMPLATE_BEAN_NAME_PROPERTY, "nonExistingBeanTemplate")); + declarable.onApplicationEvent(new ContextRefreshedEvent(applicationContext)); + } + catch (IllegalStateException expected) { + + assertThat(expected).hasMessageStartingWith("Cannot find bean with name [nonExistingBeanTemplate]"); + assertThat(expected).hasNoCause(); + + throw expected; + } } - protected static final class TestDataSource extends DataSourceAdapter { - } + protected static final class TestDataSource extends DataSourceAdapter { } protected static final class TestDeclarable extends LazyWiringDeclarableSupport { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerIntegrationTests.java similarity index 95% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerIntegrationTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerIntegrationTests.java index 5c46a25c..25c41036 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerIntegrationTests.java @@ -52,27 +52,28 @@ import org.springframework.data.gemfire.config.xml.GemfireConstants; import org.springframework.data.gemfire.repository.sample.User; import org.springframework.data.gemfire.support.sample.TestUserDao; import org.springframework.data.gemfire.support.sample.TestUserService; -import org.springframework.data.gemfire.test.support.DataSourceAdapter; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.support.DataSourceAdapter; import org.springframework.data.gemfire.util.SpringUtils; import org.springframework.util.Assert; /** - * The SpringContextBootstrappingInitializerTest class is a test suite of test cases testing the integrated - * functionality of the SpringContextBootstrappingInitializer class. + * Integration Tests for the {@link SpringContextBootstrappingInitializer}. * * @author John Blum * @see org.junit.Test - * @see org.springframework.context.ConfigurableApplicationContext - * @see LazyWiringDeclarableSupport - * @see org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer * @see org.apache.geode.cache.Cache * @see org.apache.geode.cache.CacheFactory - * @see org.apache.geode.cache.CacheLoader * @see org.apache.geode.cache.Region + * @see org.springframework.context.ConfigurableApplicationContext + * @see org.springframework.context.annotation.Bean + * @see org.springframework.context.annotation.Configuration + * @see org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport * @since 1.4.0 */ @SuppressWarnings("unused") -public class SpringContextBootstrappingInitializerIntegrationTest { +public class SpringContextBootstrappingInitializerIntegrationTests extends IntegrationTestsSupport { private static final long CACHE_CLOSE_TIMEOUT = TimeUnit.SECONDS.toMillis(15); @@ -84,7 +85,7 @@ public class SpringContextBootstrappingInitializerIntegrationTest { protected static final String GEMFIRE_JMX_MANAGER_PORT = "1199"; protected static final String GEMFIRE_JMX_MANAGER_START = "true"; protected static final String GEMFIRE_MCAST_PORT = "0"; - protected static final String GEMFIRE_NAME = SpringContextBootstrappingInitializerIntegrationTest.class.getSimpleName(); + protected static final String GEMFIRE_NAME = SpringContextBootstrappingInitializerIntegrationTests.class.getSimpleName(); protected static final String GEMFIRE_START_LOCATORS = "localhost[11235]"; @Before diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerTest.java index 0444c516..486df52e 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerTest.java @@ -77,7 +77,7 @@ import org.springframework.util.ObjectUtils; * @see org.springframework.context.ApplicationContext * @see org.springframework.context.ConfigurableApplicationContext * @see org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer - * @see org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerIntegrationTest + * @see SpringContextBootstrappingInitializerIntegrationTests * @since 1.4.0 */ @SuppressWarnings("unused") diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/sample/UserApplicationConfiguration.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/sample/UserApplicationConfiguration.java index 089fdfd8..a5f92153 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/sample/UserApplicationConfiguration.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/sample/UserApplicationConfiguration.java @@ -21,7 +21,7 @@ import javax.sql.DataSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; -import org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerIntegrationTest; +import org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerIntegrationTests; /** * The UserApplicationConfiguration class is a configuration component for configuring the user's application. @@ -39,7 +39,7 @@ public class UserApplicationConfiguration { @Bean public DataSource userDataSource() { - return new SpringContextBootstrappingInitializerIntegrationTest.TestDataSource(); + return new SpringContextBootstrappingInitializerIntegrationTests.TestDataSource(); } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/GemfireTestApplicationContextInitializer.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/GemfireTestApplicationContextInitializer.java deleted file mode 100644 index 21dfa805..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/GemfireTestApplicationContextInitializer.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2002-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package org.springframework.data.gemfire.test; - -import org.springframework.context.ApplicationContextInitializer; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.util.StringUtils; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Spring {@link ApplicationContextInitializer} used to configure the Spring Data for Apache Geode test suite - * with mocking enabled or disabled. - * - * @author David Turanski - * @author John Blum - * @see org.springframework.context.ApplicationContextInitializer - * @see org.springframework.context.ConfigurableApplicationContext - */ -public class GemfireTestApplicationContextInitializer - implements ApplicationContextInitializer { - - public static final String GEMFIRE_TEST_RUNNER_DISABLED = - "org.springframework.data.gemfire.test.GemfireTestRunner.nomock"; - - protected final Logger logger = LoggerFactory.getLogger(getClass()); - - /** - * {@inheritDoc} - */ - @Override - public void initialize(ConfigurableApplicationContext applicationContext) { - - String gemfireTestRunnerDisabled = System.getProperty(GEMFIRE_TEST_RUNNER_DISABLED, Boolean.FALSE.toString()); - - if (isGemFireTestRunnerDisabled(gemfireTestRunnerDisabled)) { - logger.warn("WARNING - Mock objects disabled; Using real Apache Geode objects [{} = {}]", - GEMFIRE_TEST_RUNNER_DISABLED, gemfireTestRunnerDisabled); - } - else { - applicationContext.getBeanFactory().addBeanPostProcessor(new GemfireTestBeanPostProcessor()); - } - } - - private boolean isGemFireTestRunnerDisabled(String systemPropertyValue) { - - return Boolean.parseBoolean(StringUtils.trimAllWhitespace(systemPropertyValue)) - || "yes".equalsIgnoreCase(systemPropertyValue) - || "y".equalsIgnoreCase(systemPropertyValue); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/GemfireTestBeanPostProcessor.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/GemfireTestBeanPostProcessor.java deleted file mode 100644 index 38e153a0..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/GemfireTestBeanPostProcessor.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2002-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package org.springframework.data.gemfire.test; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.data.gemfire.AbstractBasicCacheFactoryBean; -import org.springframework.data.gemfire.CacheFactoryBean; -import org.springframework.data.gemfire.client.ClientCacheFactoryBean; -import org.springframework.data.gemfire.server.CacheServerFactoryBean; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Spring {@link BeanPostProcessor} to enable GemFire/Geode Mock Objects for testing. - * - * @author David Turanski - * @author John Blum - * @see org.springframework.beans.factory.config.BeanPostProcessor - * @see org.springframework.data.gemfire.CacheFactoryBean - * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean - * @see org.springframework.data.gemfire.server.CacheServerFactoryBean - */ -public class GemfireTestBeanPostProcessor implements BeanPostProcessor { - - private static final Logger logger = LoggerFactory.getLogger(GemfireTestBeanPostProcessor.class); - - @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - - if (bean instanceof AbstractBasicCacheFactoryBean) { - - String beanTypeName = bean.getClass().getName(); - - bean = bean instanceof ClientCacheFactoryBean - ? new MockClientCacheFactoryBean((ClientCacheFactoryBean) bean) - : new MockCacheFactoryBean((CacheFactoryBean) bean); - - logger.info("Replacing the [{}] bean definition of type [{}] with mock [{}]...", - beanName, beanTypeName, bean.getClass().getName()); - } - else if (bean instanceof CacheServerFactoryBean) { - ((CacheServerFactoryBean) bean).setCache(new StubCache()); - } - - return bean; - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockCacheFactoryBean.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockCacheFactoryBean.java deleted file mode 100644 index 2aef7f13..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockCacheFactoryBean.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2002-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package org.springframework.data.gemfire.test; - -import java.util.Optional; - -import org.apache.geode.cache.GemFireCache; - -import org.springframework.data.gemfire.CacheFactoryBean; - -/** - * Mock {@link CacheFactoryBean} used in tests. - * - * @author David Turanski - * @author John Blum - * @author Patrick Johnson - * @see org.springframework.data.gemfire.CacheFactoryBean - */ -public class MockCacheFactoryBean extends CacheFactoryBean { - - public MockCacheFactoryBean(CacheFactoryBean cacheFactoryBean) { - - setUseBeanFactoryLocator(false); - - Optional.ofNullable(cacheFactoryBean).ifPresent(it -> { - setBeanClassLoader(it.getBeanClassLoader()); - setBeanFactory(it.getBeanFactory()); - setBeanName(it.getBeanName()); - setCacheXml(it.getCacheXml()); - setPhase(it.getPhase()); - setProperties(it.getProperties()); - setClose(it.isClose()); - setCopyOnRead(it.getCopyOnRead()); - setCriticalHeapPercentage(it.getCriticalHeapPercentage()); - setCriticalOffHeapPercentage(it.getCriticalOffHeapPercentage()); - setEnableAutoReconnect(it.getEnableAutoReconnect()); - setEvictionHeapPercentage(it.getEvictionHeapPercentage()); - setEvictionOffHeapPercentage(it.getEvictionOffHeapPercentage()); - setGatewayConflictResolver(it.getGatewayConflictResolver()); - setJndiDataSources(it.getJndiDataSources()); - setLockLease(it.getLockLease()); - setLockTimeout(it.getLockTimeout()); - setMessageSyncInterval(it.getMessageSyncInterval()); - setPdxDiskStoreName(it.getPdxDiskStoreName()); - setPdxIgnoreUnreadFields(it.getPdxIgnoreUnreadFields()); - setPdxPersistent(it.getPdxPersistent()); - setPdxReadSerialized(it.getPdxReadSerialized()); - setPdxSerializer(it.getPdxSerializer()); - setSearchTimeout(it.getSearchTimeout()); - setTransactionListeners(it.getTransactionListeners()); - setTransactionWriter(it.getTransactionWriter()); - setUseBeanFactoryLocator(it.isUseBeanFactoryLocator()); - setUseClusterConfiguration(it.getUseClusterConfiguration()); - }); - - applyPeerCacheConfigurers(cacheFactoryBean.getCompositePeerCacheConfigurer()); - } - - @Override - @SuppressWarnings("unchecked") - protected T doFetchCache() { - StubCache stubCache = new StubCache(); - stubCache.setProperties(getProperties()); - return (T) stubCache; - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockClientCacheFactoryBean.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockClientCacheFactoryBean.java deleted file mode 100644 index 06562f3a..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockClientCacheFactoryBean.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2002-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package org.springframework.data.gemfire.test; - -import java.util.Optional; - -import org.apache.geode.cache.GemFireCache; - -import org.springframework.data.gemfire.client.ClientCacheFactoryBean; - -/** - * @author David Turanski - * @author John Blum - * @author Patrick Johnson - */ -public class MockClientCacheFactoryBean extends ClientCacheFactoryBean { - - public MockClientCacheFactoryBean(ClientCacheFactoryBean clientCacheFactoryBean) { - - setUseBeanFactoryLocator(false); - - Optional.ofNullable(clientCacheFactoryBean).ifPresent(it -> { - setBeanClassLoader(it.getBeanClassLoader()); - setBeanFactory(it.getBeanFactory()); - setBeanFactoryLocator(it.getBeanFactoryLocator()); - setBeanName(it.getBeanName()); - setCacheXml(it.getCacheXml()); - setCopyOnRead(it.getCopyOnRead()); - setCriticalHeapPercentage(it.getCriticalHeapPercentage()); - setDurableClientId(it.getDurableClientId()); - setDurableClientTimeout(it.getDurableClientTimeout()); - setEvictionHeapPercentage(it.getEvictionHeapPercentage()); - setGatewayConflictResolver(it.getGatewayConflictResolver()); - setJndiDataSources(it.getJndiDataSources()); - setKeepAlive(it.isKeepAlive()); - setLockLease(it.getLockLease()); - setLockTimeout(it.getLockTimeout()); - setMessageSyncInterval(it.getMessageSyncInterval()); - setPdxDiskStoreName(it.getPdxDiskStoreName()); - setPdxIgnoreUnreadFields(it.getPdxIgnoreUnreadFields()); - setPdxPersistent(it.getPdxPersistent()); - setPdxReadSerialized(it.getPdxReadSerialized()); - setPdxSerializer(it.getPdxSerializer()); - setPoolName(it.getPoolName()); - setProperties(it.getProperties()); - setReadyForEvents(it.getReadyForEvents()); - setSearchTimeout(it.getSearchTimeout()); - setTransactionListeners(it.getTransactionListeners()); - setTransactionWriter(it.getTransactionWriter()); - }); - - applyClientCacheConfigurers(clientCacheFactoryBean.getCompositeClientCacheConfigurer()); - } - - @SuppressWarnings("unchecked") - protected T fetchCache() { - StubCache stubCache = new StubCache(); - stubCache.setProperties(getProperties()); - return (T) stubCache; - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockClientRegionFactory.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockClientRegionFactory.java deleted file mode 100644 index 73afcccb..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockClientRegionFactory.java +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.test; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyFloat; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - -import org.apache.geode.cache.CacheListener; -import org.apache.geode.cache.CustomExpiry; -import org.apache.geode.cache.DataPolicy; -import org.apache.geode.cache.EvictionAttributes; -import org.apache.geode.cache.ExpirationAttributes; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.client.ClientRegionFactory; -import org.apache.geode.cache.client.ClientRegionShortcut; -import org.apache.geode.compression.Compressor; - -import org.springframework.util.StringUtils; - -/** - * The MockClientRegionFactory class... - * - * @author John Blum - * @since 1.8.0 - */ -@SuppressWarnings("unused") -public class MockClientRegionFactory extends MockRegionFactory { - - public MockClientRegionFactory(StubCache cache) { - super(cache); - } - - @SuppressWarnings({ "deprecation", "unchecked" }) - public ClientRegionFactory mockClientRegionFactory() { - return mockClientRegionFactory(ClientRegionShortcut.PROXY); - } - - @SuppressWarnings({ "deprecation", "unchecked" }) - public ClientRegionFactory mockClientRegionFactory(ClientRegionShortcut clientRegionShortcut) { - attributesFactory = new org.apache.geode.cache.AttributesFactory(); - attributesFactory.setDataPolicy(resolveDataPolicy(clientRegionShortcut)); - - final ClientRegionFactory mockClientRegionFactory = mock(ClientRegionFactory.class, "MockClientRegionFactory"); - - when(mockClientRegionFactory.create(anyString())).thenAnswer(new Answer() { - @Override public Region answer(InvocationOnMock invocation) throws Throwable { - String name = (String) invocation.getArguments()[0]; - Region region = mockRegion(name); - - when(region.getAttributesMutator()).thenReturn(mockAttributesMutator); - - cache.allRegions().put(name, region); - - return region; - } - }); - - when(mockClientRegionFactory.createSubregion(any(Region.class), anyString())).thenAnswer(new Answer() { - @Override public Region answer(InvocationOnMock invocation) throws Throwable { - Region parent = (Region) invocation.getArguments()[0]; - String name = (String) invocation.getArguments()[1]; - String parentRegionName = parent.getFullPath(); - - assert parentRegionName != null : "Parent Region name was null!"; - - String subRegionName = (parentRegionName.startsWith("/") ? parentRegionName+"/"+name - : "/"+parentRegionName+"/"+ name); - - Region subRegion = mockRegion(subRegionName); - - cache.allRegions().put(subRegionName, subRegion); - cache.allRegions().put(name, subRegion); - - return subRegion; - } - }); - - when(mockClientRegionFactory.setCloningEnabled(anyBoolean())).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - attributesFactory.setCloningEnabled(Boolean.TRUE.equals(invocation.getArgument(0))); - return mockClientRegionFactory; - } - } - ); - - when(mockClientRegionFactory.setCompressor(any(Compressor.class))).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - Compressor compressor = invocation.getArgument(0); - attributesFactory.setCompressor(compressor); - return mockClientRegionFactory; - } - } - ); - - doAnswer(new Answer() { - @Override public Void answer(final InvocationOnMock invocation) throws Throwable { - attributesFactory.setConcurrencyChecksEnabled(Boolean.TRUE.equals( - invocation.getArgument(0))); - return null; - } - }).when(mockClientRegionFactory).setConcurrencyChecksEnabled(anyBoolean()); - - when(mockClientRegionFactory.setConcurrencyLevel(anyInt())).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - int concurrencyLevel = invocation.getArgument(0); - attributesFactory.setConcurrencyLevel(concurrencyLevel); - return mockClientRegionFactory; - } - } - ); - - when(mockClientRegionFactory.setCustomEntryIdleTimeout(any(CustomExpiry.class))).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - CustomExpiry customEntryIdleTimeout = invocation.getArgument(0); - attributesFactory.setCustomEntryIdleTimeout(customEntryIdleTimeout); - return mockClientRegionFactory; - } - } - ); - - when(mockClientRegionFactory.setCustomEntryTimeToLive(any(CustomExpiry.class))).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - CustomExpiry customEntryTimeToLive = invocation.getArgument(0); - attributesFactory.setCustomEntryTimeToLive(customEntryTimeToLive); - return mockClientRegionFactory; - } - } - ); - - when(mockClientRegionFactory.setDiskStoreName(anyString())).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - String diskStoreName = invocation.getArgument(0); - attributesFactory.setDiskStoreName(diskStoreName); - return mockClientRegionFactory; - } - } - ); - - when(mockClientRegionFactory.setDiskSynchronous(anyBoolean())).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - attributesFactory.setDiskSynchronous(Boolean.TRUE.equals( - invocation.getArgument(0))); - return mockClientRegionFactory; - } - } - ); - - when(mockClientRegionFactory.setEntryIdleTimeout(any(ExpirationAttributes.class))).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - ExpirationAttributes entryIdleTimeout = invocation.getArgument(0); - attributesFactory.setEntryIdleTimeout(entryIdleTimeout); - return mockClientRegionFactory; - } - } - ); - - when(mockClientRegionFactory.setEntryTimeToLive(any(ExpirationAttributes.class))).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - ExpirationAttributes entryTimeToLive = invocation.getArgument(0); - attributesFactory.setEntryTimeToLive(entryTimeToLive); - return mockClientRegionFactory; - } - } - ); - - when(mockClientRegionFactory.setEvictionAttributes(any(EvictionAttributes.class))).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - EvictionAttributes evictionAttributes = invocation.getArgument(0); - attributesFactory.setEvictionAttributes(evictionAttributes); - return mockClientRegionFactory; - } - } - ); - - when(mockClientRegionFactory.setInitialCapacity(anyInt())).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - int initialCapacity = invocation.getArgument(0); - attributesFactory.setInitialCapacity(initialCapacity); - return mockClientRegionFactory; - } - } - ); - - when(mockClientRegionFactory.setKeyConstraint(any(Class.class))).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - Class keyConstraint = invocation.getArgument(0); - attributesFactory.setKeyConstraint(keyConstraint); - return mockClientRegionFactory; - } - } - ); - - when(mockClientRegionFactory.setLoadFactor(anyFloat())).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - float loadFactor = invocation.getArgument(0); - attributesFactory.setLoadFactor(loadFactor); - return mockClientRegionFactory; - } - } - ); - - when(mockClientRegionFactory.setPoolName(anyString())).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - String poolName = invocation.getArgument(0); - poolName = (StringUtils.hasText(poolName) ? poolName : null); - attributesFactory.setPoolName(poolName); - return mockClientRegionFactory; - } - } - ); - - when(mockClientRegionFactory.setRegionIdleTimeout(any(ExpirationAttributes.class))).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - ExpirationAttributes regionIdleTimeout = invocation.getArgument(0); - attributesFactory.setRegionIdleTimeout(regionIdleTimeout); - return mockClientRegionFactory; - } - } - ); - - when(mockClientRegionFactory.setRegionTimeToLive(any(ExpirationAttributes.class))).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - ExpirationAttributes regionTimeToLive = invocation.getArgument(0); - attributesFactory.setRegionTimeToLive(regionTimeToLive); - return mockClientRegionFactory; - } - } - ); - - when(mockClientRegionFactory.setStatisticsEnabled(anyBoolean())).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - attributesFactory.setStatisticsEnabled(Boolean.TRUE.equals( - invocation.getArgument(0))); - return mockClientRegionFactory; - } - } - ); - - when(mockClientRegionFactory.setValueConstraint(any(Class.class))).thenAnswer( - new Answer() { - @Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable { - Class valueConstraint = invocation.getArgument(0); - attributesFactory.setValueConstraint(valueConstraint); - return mockClientRegionFactory; - } - } - ); - - when(mockClientRegionFactory.addCacheListener(any(CacheListener.class))).thenAnswer(new Answer(){ - @Override public ClientRegionFactory answer(InvocationOnMock invocation) throws Throwable { - CacheListener cacheListener = (CacheListener) invocation.getArguments()[0]; - attributesFactory.addCacheListener(cacheListener); - return mockClientRegionFactory; - } - }); - - return mockClientRegionFactory; - } - - ClientRegionFactory createClientRegionFactory() { - return mockClientRegionFactory(); - } - - ClientRegionFactory createClientRegionFactory(ClientRegionShortcut shortcut) { - return mockClientRegionFactory(shortcut); - } - - DataPolicy resolveDataPolicy(ClientRegionShortcut clientRegionShortcut) { - clientRegionShortcut = (clientRegionShortcut != null ? clientRegionShortcut : ClientRegionShortcut.LOCAL); - - switch (clientRegionShortcut) { - case CACHING_PROXY: - case CACHING_PROXY_HEAP_LRU: - case CACHING_PROXY_OVERFLOW: - case LOCAL: - case LOCAL_HEAP_LRU: - case LOCAL_OVERFLOW: - return DataPolicy.NORMAL; - case LOCAL_PERSISTENT: - case LOCAL_PERSISTENT_OVERFLOW: - return DataPolicy.PERSISTENT_REPLICATE; - case PROXY: - return DataPolicy.EMPTY; - default: - return DataPolicy.NORMAL; - } - } - -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockRegionFactory.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockRegionFactory.java deleted file mode 100644 index d9bfcedc..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockRegionFactory.java +++ /dev/null @@ -1,484 +0,0 @@ -/* - * Copyright 2002-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package org.springframework.data.gemfire.test; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyFloat; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.File; -import java.lang.reflect.Field; - -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - -import org.apache.geode.cache.AttributesMutator; -import org.apache.geode.cache.CacheListener; -import org.apache.geode.cache.CacheLoader; -import org.apache.geode.cache.CacheWriter; -import org.apache.geode.cache.CustomExpiry; -import org.apache.geode.cache.DataPolicy; -import org.apache.geode.cache.EvictionAttributes; -import org.apache.geode.cache.ExpirationAttributes; -import org.apache.geode.cache.MembershipAttributes; -import org.apache.geode.cache.PartitionAttributes; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.RegionAttributes; -import org.apache.geode.cache.RegionFactory; -import org.apache.geode.cache.Scope; -import org.apache.geode.cache.SubscriptionAttributes; - -import org.springframework.util.ReflectionUtils; - -/** - * @author David Turanski - * @author John Blum - */ -@SuppressWarnings("deprecation") -public class MockRegionFactory { - - protected static AttributesMutator mockAttributesMutator = mock(AttributesMutator.class); - - protected org.apache.geode.cache.AttributesFactory attributesFactory; - - protected final StubCache cache; - - public MockRegionFactory(StubCache cache) { - this.cache = cache; - } - - public RegionFactory createMockRegionFactory() { - return createMockRegionFactory(null); - } - - @SuppressWarnings({ "deprecation", "rawtypes", "unchecked" }) - public RegionFactory createMockRegionFactory(RegionAttributes attributes) { - attributesFactory = (attributes != null ? new org.apache.geode.cache.AttributesFactory(attributes) - : new org.apache.geode.cache.AttributesFactory()); - - // Workaround for GemFire bug??? - if (attributes != null) { - attributesFactory.setLockGrantor(attributes.isLockGrantor()); - } - - final RegionFactory regionFactory = mock(RegionFactory.class); - - Field attrsFactory = ReflectionUtils.findField(RegionFactory.class, "attrsFactory"); - ReflectionUtils.makeAccessible(attrsFactory); - ReflectionUtils.setField(attrsFactory, regionFactory, attributesFactory); - - when(regionFactory.create(anyString())).thenAnswer(new Answer() { - @Override public Region answer(InvocationOnMock invocation) throws Throwable { - String name = (String) invocation.getArguments()[0]; - Region region = mockRegion(name); - - cache.allRegions().put(name, region); - - return region; - } - }); - - when(regionFactory.createSubregion(any(Region.class), anyString())).thenAnswer(new Answer() { - @Override public Region answer(InvocationOnMock invocation) throws Throwable { - Region parent = (Region) invocation.getArguments()[0]; - String name = (String) invocation.getArguments()[1]; - String parentRegionName = parent.getFullPath(); - - assert parentRegionName != null : "The parent Region name was null!"; - - String subRegionName = (parentRegionName.startsWith("/") ? parentRegionName+"/"+name - : "/"+parentRegionName+"/"+ name); - - Region subRegion = mockRegion(subRegionName); - - cache.allRegions().put(subRegionName, subRegion); - cache.allRegions().put(name, subRegion); - - return subRegion; - } - }); - - when(regionFactory.setCacheLoader(any(CacheLoader.class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - CacheLoader cacheLoader = (CacheLoader) invocation.getArguments()[0]; - attributesFactory.setCacheLoader(cacheLoader); - return regionFactory; - } - }); - - when(regionFactory.setCacheWriter(any(CacheWriter.class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - CacheWriter cacheWriter = (CacheWriter) invocation.getArguments()[0]; - attributesFactory.setCacheWriter(cacheWriter); - return regionFactory; - } - }); - - when(regionFactory.setCloningEnabled(anyBoolean())).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean cloningEnabled = (Boolean) invocation.getArguments()[0]; - attributesFactory.setCloningEnabled(cloningEnabled); - return regionFactory; - } - }); - - when(regionFactory.setConcurrencyChecksEnabled(anyBoolean())).thenAnswer(new Answer() { - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean concurrencyChecksEnabled = (Boolean) invocation.getArguments()[0]; - attributesFactory.setConcurrencyChecksEnabled(concurrencyChecksEnabled); - return regionFactory; - } - }); - - when(regionFactory.setConcurrencyLevel(anyInt())).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - int concurrencyLevel = (Integer) invocation.getArguments()[0]; - attributesFactory.setConcurrencyLevel(concurrencyLevel); - return regionFactory; - } - }); - - when(regionFactory.setDataPolicy(any(DataPolicy.class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - DataPolicy dataPolicy = (DataPolicy) invocation.getArguments()[0]; - attributesFactory.setDataPolicy(dataPolicy); - return regionFactory; - } - }); - - when(regionFactory.setDiskDirs(any(File[].class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - File[] diskDirectories = (File[]) invocation.getArguments()[0]; - attributesFactory.setDiskDirs(diskDirectories); - return regionFactory; - } - }); - - when(regionFactory.setDiskDirsAndSizes(any(File[].class), any(int[].class))).thenAnswer( - new Answer() { - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - File[] diskDirectories = (File[]) invocation.getArguments()[0]; - int[] diskSizes = (int[]) invocation.getArguments()[1]; - attributesFactory.setDiskDirsAndSizes(diskDirectories, diskSizes); - return regionFactory; - } - }); - - when(regionFactory.setDiskStoreName(anyString())).thenAnswer(new Answer() { - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - String diskStoreName = (String) invocation.getArguments()[0]; - attributesFactory.setDiskStoreName(diskStoreName); - return regionFactory; - } - }); - - when(regionFactory.setDiskWriteAttributes(any(org.apache.geode.cache.DiskWriteAttributes.class))) - .thenAnswer(new Answer() { - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - org.apache.geode.cache.DiskWriteAttributes diskWriteAttributes = - (org.apache.geode.cache.DiskWriteAttributes) invocation.getArguments()[0]; - attributesFactory.setDiskWriteAttributes(diskWriteAttributes); - return regionFactory; - } - }); - - when(regionFactory.setDiskSynchronous(anyBoolean())).thenAnswer(new Answer() { - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean diskSynchronous = (Boolean) invocation.getArguments()[0]; - attributesFactory.setDiskSynchronous(diskSynchronous); - return regionFactory; - } - }); - - when(regionFactory.setEarlyAck(anyBoolean())).thenAnswer(new Answer() { - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean earlyAck = (Boolean) invocation.getArguments()[0]; - attributesFactory.setEarlyAck(earlyAck); - return regionFactory; - } - }); - - when(regionFactory.setEnableAsyncConflation(anyBoolean())).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean enableAsyncConflation = (Boolean) invocation.getArguments()[0]; - attributesFactory.setEnableAsyncConflation(enableAsyncConflation); - return regionFactory; - } - }); - - when(regionFactory.setEnableSubscriptionConflation(anyBoolean())).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean enableSubscriptionConflation = (Boolean) invocation.getArguments()[0]; - attributesFactory.setEnableSubscriptionConflation(enableSubscriptionConflation); - return regionFactory; - } - }); - - when(regionFactory.setEntryIdleTimeout(any(ExpirationAttributes.class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - ExpirationAttributes entryIdleTimeout = (ExpirationAttributes) invocation.getArguments()[0]; - attributesFactory.setEntryIdleTimeout(entryIdleTimeout); - return regionFactory; - } - }); - - when(regionFactory.setCustomEntryIdleTimeout(any(CustomExpiry.class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - CustomExpiry customEntryIdleTimeout = (CustomExpiry) invocation.getArguments()[0]; - attributesFactory.setCustomEntryIdleTimeout(customEntryIdleTimeout); - return regionFactory; - } - }); - - when(regionFactory.setEntryTimeToLive(any(ExpirationAttributes.class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - ExpirationAttributes entryTimeToLive = (ExpirationAttributes) invocation.getArguments()[0]; - attributesFactory.setEntryTimeToLive(entryTimeToLive); - return regionFactory; - } - }); - - when(regionFactory.setCustomEntryTimeToLive(any(CustomExpiry.class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - CustomExpiry customEntryTimeToLive = (CustomExpiry) invocation.getArguments()[0]; - attributesFactory.setCustomEntryTimeToLive(customEntryTimeToLive); - return regionFactory; - } - }); - - when(regionFactory.setEvictionAttributes(any(EvictionAttributes.class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - EvictionAttributes evictionAttributes = (EvictionAttributes) invocation.getArguments()[0]; - attributesFactory.setEvictionAttributes(evictionAttributes); - return regionFactory; - } - }); - - when(regionFactory.setIgnoreJTA(anyBoolean())).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean ignoreJta = (Boolean) invocation.getArguments()[0]; - attributesFactory.setIgnoreJTA(ignoreJta); - return regionFactory; - } - }); - - when(regionFactory.setIndexMaintenanceSynchronous(anyBoolean())).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean indexMaintenanceSynchronous = (Boolean) invocation.getArguments()[0]; - attributesFactory.setIndexMaintenanceSynchronous(indexMaintenanceSynchronous); - return regionFactory; - } - }); - - when(regionFactory.setInitialCapacity(anyInt())).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - int initialCapacity = (Integer) invocation.getArguments()[0]; - attributesFactory.setInitialCapacity(initialCapacity); - return regionFactory; - } - }); - - when(regionFactory.setKeyConstraint(any(Class.class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - Class keyConstraint = (Class) invocation.getArguments()[0]; - attributesFactory.setKeyConstraint(keyConstraint); - return regionFactory; - } - }); - - when(regionFactory.setLoadFactor(anyFloat())).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - float loadFactor = (Float) invocation.getArguments()[0]; - attributesFactory.setLoadFactor(loadFactor); - return regionFactory; - } - }); - - when(regionFactory.setLockGrantor(anyBoolean())).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean lockGrantor = (Boolean) invocation.getArguments()[0]; - attributesFactory.setLockGrantor(lockGrantor); - return regionFactory; - } - }); - - when(regionFactory.setMembershipAttributes(any(MembershipAttributes.class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - MembershipAttributes membershipAttributes = (MembershipAttributes) invocation.getArguments()[0]; - attributesFactory.setMembershipAttributes(membershipAttributes); - return regionFactory; - } - }); - - when(regionFactory.setMulticastEnabled(anyBoolean())).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean multicastEnabled = (Boolean) invocation.getArguments()[0]; - attributesFactory.setMulticastEnabled(multicastEnabled); - return regionFactory; - } - }); - - when(regionFactory.setPartitionAttributes(any(PartitionAttributes.class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - PartitionAttributes partitionAttributes = (PartitionAttributes) invocation.getArguments()[0]; - attributesFactory.setPartitionAttributes(partitionAttributes); - return regionFactory; - } - }); - - when(regionFactory.setPoolName(anyString())).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - String poolName = (String) invocation.getArguments()[0]; - attributesFactory.setPoolName(poolName); - return regionFactory; - } - }); - - when(regionFactory.setRegionIdleTimeout(any(ExpirationAttributes.class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - ExpirationAttributes regionIdleTimeout = (ExpirationAttributes) invocation.getArguments()[0]; - attributesFactory.setRegionIdleTimeout(regionIdleTimeout); - return regionFactory; - } - }); - - when(regionFactory.setRegionTimeToLive(any(ExpirationAttributes.class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - ExpirationAttributes regionTimeToLive = (ExpirationAttributes) invocation.getArguments()[0]; - attributesFactory.setRegionTimeToLive(regionTimeToLive); - return regionFactory; - } - }); - - when(regionFactory.setScope(any(Scope.class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - Scope scope = (Scope) invocation.getArguments()[0]; - attributesFactory.setScope(scope); - return regionFactory; - } - }); - - when(regionFactory.setStatisticsEnabled(anyBoolean())).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - boolean statisticsEnabled = (Boolean) invocation.getArguments()[0]; - attributesFactory.setStatisticsEnabled(statisticsEnabled); - return regionFactory; - } - }); - - when(regionFactory.setSubscriptionAttributes(any(SubscriptionAttributes.class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - SubscriptionAttributes subscriptionAttributes = (SubscriptionAttributes) invocation.getArguments()[0]; - attributesFactory.setSubscriptionAttributes(subscriptionAttributes); - return regionFactory; - } - }); - - when(regionFactory.setValueConstraint(any(Class.class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - Class valueConstraint = (Class) invocation.getArguments()[0]; - attributesFactory.setValueConstraint(valueConstraint); - return regionFactory; - } - }); - - when(regionFactory.addAsyncEventQueueId(anyString())).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - String asyncEventQueueId = (String) invocation.getArguments()[0]; - attributesFactory.addAsyncEventQueueId(asyncEventQueueId); - return regionFactory; - } - }); - - when(regionFactory.addCacheListener(any(CacheListener.class))).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - CacheListener cacheListener = (CacheListener) invocation.getArguments()[0]; - attributesFactory.addCacheListener(cacheListener); - return regionFactory; - } - }); - - when(regionFactory.addGatewaySenderId(anyString())).thenAnswer(new Answer(){ - @Override public RegionFactory answer(InvocationOnMock invocation) throws Throwable { - String gatewaySenderId = (String) invocation.getArguments()[0]; - attributesFactory.addGatewaySenderId(gatewaySenderId); - return regionFactory; - } - }); - - return regionFactory; - } - - @SuppressWarnings("rawtypes") - RegionFactory createRegionFactory() { - return createMockRegionFactory(); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - public Region mockRegion(String name) { - RegionAttributes regionAttributes = attributesFactory.create(); - - Region region = mock(Region.class); - - when(region.getAttributes()).thenReturn(regionAttributes); - - String regionFullPath = (name.startsWith(Region.SEPARATOR) ? name : Region.SEPARATOR + name); - String regionName = (name.lastIndexOf(Region.SEPARATOR) > 0 ? - name.substring(name.lastIndexOf(Region.SEPARATOR) + Region.SEPARATOR.length()) : name); - - when(region.getFullPath()).thenReturn(regionFullPath); - when(region.getName()).thenReturn(regionName); - when(region.getRegionService()).thenReturn(cache); - - when(region.getSubregion(anyString())).thenAnswer(new Answer() { - @Override - public Region answer(InvocationOnMock invocation) throws Throwable { - Region parent = (Region) invocation.getMock(); - - String parentRegionName = parent.getFullPath(); - String subRegionName = (String) invocation.getArguments()[0]; - String subRegionPath = (parentRegionName.startsWith("/") ? parentRegionName+"/"+subRegionName - : "/"+parentRegionName+"/"+subRegionName); - - return cache.getRegion(subRegionPath); - } - }); - - when(region.createSubregion(anyString(), any(RegionAttributes.class))).thenAnswer(new Answer() { - @Override - public Region answer(InvocationOnMock invocation) throws Throwable { - String name = (String) invocation.getArguments()[0]; - RegionAttributes attributes = (RegionAttributes) invocation.getArguments()[1]; - - Region parent = (Region) invocation.getMock(); - String parentName = parent.getName(); - String regionName = parentName - .startsWith("/") ? parentName + "/" + name : "/" + parentName + "/" + name; - - Region subRegion = new MockRegionFactory(cache).createMockRegionFactory(attributes).create(regionName); - when(subRegion.getFullPath()).thenReturn(regionName); - - cache.allRegions().put(regionName, subRegion); - - return subRegion; - } - }); - - return region; - } - -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockRegionFactoryTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockRegionFactoryTest.java deleted file mode 100644 index 41854623..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/MockRegionFactoryTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2002-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package org.springframework.data.gemfire.test; - -/** - * @author David Turanski - * - */ - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import org.apache.geode.cache.Region; -import org.apache.geode.cache.RegionFactory; -import org.apache.geode.cache.Scope; -public class MockRegionFactoryTest { - @Test - public void testBasicAttributes() { - RegionFactory rf = new MockRegionFactory(new StubCache()).createMockRegionFactory(); - rf.setScope(Scope.LOCAL); - Region foo = rf.create("foo"); - assertEquals(Scope.LOCAL,foo.getAttributes().getScope()); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubAsyncEventQueueFactory.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubAsyncEventQueueFactory.java deleted file mode 100644 index 91c2e77e..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubAsyncEventQueueFactory.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright 2002-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package org.springframework.data.gemfire.test; - -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.apache.geode.cache.asyncqueue.AsyncEventListener; -import org.apache.geode.cache.asyncqueue.AsyncEventQueue; -import org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory; -import org.apache.geode.cache.wan.GatewayEventFilter; -import org.apache.geode.cache.wan.GatewayEventSubstitutionFilter; -import org.apache.geode.cache.wan.GatewaySender; -import org.apache.geode.cache.wan.GatewaySender.OrderPolicy; - -/** - * @author David Turanski - * @author John Blum - */ -@SuppressWarnings("deprecated") -public class StubAsyncEventQueueFactory implements AsyncEventQueueFactory { - - private AsyncEventQueue asyncEventQueue = mock(AsyncEventQueue.class); - - private boolean batchConflationEnabled; - private boolean diskSynchronous; - private boolean forwardExpirationDestroy; - private boolean parallel; - private boolean pauseEventDispatching; - private boolean persistent; - - private int batchSize; - private int batchTimeInterval; - private int dispatcherThreads = GatewaySender.DEFAULT_DISPATCHER_THREADS; - private int maxQueueMemory; - - private GatewayEventSubstitutionFilter gatewayEventSubstitutionFilter; - - private List gatewayEventFilters = new ArrayList<>(); - - private OrderPolicy orderPolicy; - - private String diskStoreName; - - @Override - public AsyncEventQueue create(String name, AsyncEventListener listener) { - - when(asyncEventQueue.getAsyncEventListener()).thenReturn(listener); - when(asyncEventQueue.isBatchConflationEnabled()).thenReturn(this.batchConflationEnabled); - when(asyncEventQueue.getBatchSize()).thenReturn(this.batchSize); - when(asyncEventQueue.getBatchTimeInterval()).thenReturn(this.batchTimeInterval); - when(asyncEventQueue.getDiskStoreName()).thenReturn(this.diskStoreName); - when(asyncEventQueue.isDiskSynchronous()).thenReturn(this.diskSynchronous); - when(asyncEventQueue.getDispatcherThreads()).thenReturn(this.dispatcherThreads); - when(asyncEventQueue.isDispatchingPaused()).thenAnswer(invocation -> this.pauseEventDispatching); - when(asyncEventQueue.getGatewayEventFilters()).thenReturn(Collections.unmodifiableList(gatewayEventFilters)); - when(asyncEventQueue.getGatewayEventSubstitutionFilter()).thenReturn(this.gatewayEventSubstitutionFilter); - when(asyncEventQueue.getId()).thenReturn(name); - when(asyncEventQueue.isForwardExpirationDestroy()).thenReturn(this.forwardExpirationDestroy); - when(asyncEventQueue.getMaximumQueueMemory()).thenReturn(this.maxQueueMemory); - when(asyncEventQueue.getOrderPolicy()).thenReturn(this.orderPolicy); - when(asyncEventQueue.isParallel()).thenReturn(this.parallel); - when(asyncEventQueue.isPersistent()).thenReturn(this.persistent); - - doAnswer(invocation -> { - this.pauseEventDispatching = false; - return null; - }).when(asyncEventQueue).resumeEventDispatching(); - - return this.asyncEventQueue; - } - - public AsyncEventQueueFactory setBatchConflationEnabled(boolean batchConflationEnabled) { - this.batchConflationEnabled = batchConflationEnabled; - return this; - } - - @Override - public AsyncEventQueueFactory setBatchSize(int batchSize) { - this.batchSize = batchSize; - return this; - } - - public AsyncEventQueueFactory setBatchTimeInterval(int batchTimeInterval) { - this.batchTimeInterval = batchTimeInterval; - return this; - } - - @Override - public AsyncEventQueueFactory setDiskStoreName(String diskStoreName) { - this.diskStoreName = diskStoreName; - return this; - } - - public AsyncEventQueueFactory setDispatcherThreads(int dispatchThreads) { - this.dispatcherThreads = dispatchThreads; - return this; - } - - public AsyncEventQueueFactory setDiskSynchronous(boolean diskSynchronous) { - this.diskSynchronous = diskSynchronous; - return this; - } - - public AsyncEventQueueFactory setForwardExpirationDestroy(boolean forwardExpirationDestroy) { - this.forwardExpirationDestroy = forwardExpirationDestroy; - return this; - } - - public AsyncEventQueueFactory setGatewayEventSubstitutionListener(final GatewayEventSubstitutionFilter gatewayEventSubstitutionFilter) { - this.gatewayEventSubstitutionFilter = gatewayEventSubstitutionFilter; - return this; - } - - public AsyncEventQueueFactory setMaximumQueueMemory(int maxQueueMemory) { - this.maxQueueMemory = maxQueueMemory; - return this; - } - - public AsyncEventQueueFactory setOrderPolicy(OrderPolicy orderPolicy) { - this.orderPolicy = orderPolicy; - return this; - } - - public AsyncEventQueueFactory setParallel(boolean parallel) { - this.parallel = parallel; - return this; - } - - public AsyncEventQueueFactory setPersistent(boolean persistent) { - this.persistent = persistent; - return this; - } - - public AsyncEventQueueFactory addGatewayEventFilter(final GatewayEventFilter gatewayEventFilter) { - gatewayEventFilters.add(gatewayEventFilter); - return this; - } - - public AsyncEventQueueFactory pauseEventDispatching() { - this.pauseEventDispatching = true; - return this; - } - - public AsyncEventQueueFactory removeGatewayEventFilter(final GatewayEventFilter gatewayEventFilter) { - gatewayEventFilters.remove(gatewayEventFilter); - return this; - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubCache.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubCache.java deleted file mode 100644 index 4d21072f..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubCache.java +++ /dev/null @@ -1,874 +0,0 @@ -package org.springframework.data.gemfire.test; - -import static org.mockito.Mockito.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.InputStream; -import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import javax.naming.Context; - -import org.apache.geode.CancelCriterion; -import org.apache.geode.LogWriter; -import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheTransactionManager; -import org.apache.geode.cache.CacheWriterException; -import org.apache.geode.cache.Declarable; -import org.apache.geode.cache.DiskStore; -import org.apache.geode.cache.DiskStoreFactory; -import org.apache.geode.cache.GatewayException; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.RegionAttributes; -import org.apache.geode.cache.RegionExistsException; -import org.apache.geode.cache.RegionFactory; -import org.apache.geode.cache.RegionService; -import org.apache.geode.cache.RegionShortcut; -import org.apache.geode.cache.TimeoutException; -import org.apache.geode.cache.asyncqueue.AsyncEventQueue; -import org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory; -import org.apache.geode.cache.client.ClientCache; -import org.apache.geode.cache.client.ClientRegionFactory; -import org.apache.geode.cache.client.ClientRegionShortcut; -import org.apache.geode.cache.client.Pool; -import org.apache.geode.cache.control.ResourceManager; -import org.apache.geode.cache.query.Index; -import org.apache.geode.cache.query.IndexExistsException; -import org.apache.geode.cache.query.IndexInvalidException; -import org.apache.geode.cache.query.IndexNameConflictException; -import org.apache.geode.cache.query.QueryService; -import org.apache.geode.cache.query.RegionNotFoundException; -import org.apache.geode.cache.server.CacheServer; -import org.apache.geode.cache.snapshot.CacheSnapshotService; -import org.apache.geode.cache.util.GatewayConflictResolver; -import org.apache.geode.cache.wan.GatewayReceiver; -import org.apache.geode.cache.wan.GatewayReceiverFactory; -import org.apache.geode.cache.wan.GatewaySender; -import org.apache.geode.cache.wan.GatewaySenderFactory; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.distributed.DistributedSystem; -import org.apache.geode.i18n.LogWriterI18n; -import org.apache.geode.pdx.JSONFormatter; -import org.apache.geode.pdx.PdxInstance; -import org.apache.geode.pdx.PdxInstanceFactory; -import org.apache.geode.pdx.PdxSerializer; - -@SuppressWarnings({ "deprecation", "unused" }) -public class StubCache implements Cache, ClientCache { - - private static final AtomicReference queryServiceReference = new AtomicReference<>(null); - - protected static final String NOT_IMPLEMENTED = "Not Implemented"; - - private boolean closed; - private boolean copyOnRead; - private boolean pdxIgnoreUnreadFields; - private boolean pdxPersistent; - private boolean pdxReadSerialized; - private boolean server; - - private int lockLease; - private int lockTimeout; - private int messageSyncInterval; - private int searchTimeout; - - private CacheTransactionManager cacheTransactionManager; - - private Context jndiContext; - - private Declarable initializer; - - private DistributedSystem distributedSystem; - - private GatewayConflictResolver gatewayConflictResolver; - - private Map rootRegions; - - private LogWriter logWriter; - private LogWriter securityLogWriter; - - private PdxSerializer pdxSerializer; - - private Properties properties; - - private ResourceManager resourceManager; - - private Set gatewayReceivers; - private Set gatewaySenders; - - private String pdxDiskStore; - private String name; - - public StubCache(){ - rootRegions = new HashMap<>(); - resourceManager = new StubResourceManager(); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#createDiskStoreFactory() - */ - @Override - public DiskStoreFactory createDiskStoreFactory() { - return new StubDiskStore(); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#findDiskStore(java.lang.String) - */ - @Override - public DiskStore findDiskStore(String name) { - return StubDiskStore.getDiskStore(name); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#getCacheTransactionManager() - */ - @Override - public CacheTransactionManager getCacheTransactionManager() { - if (cacheTransactionManager == null) { - cacheTransactionManager = new StubCacheTransactionManager(); - } - - return cacheTransactionManager; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#getCopyOnRead() - */ - @Override - public boolean getCopyOnRead() { - return this.copyOnRead; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#getDistributedSystem() - */ - @Override - public DistributedSystem getDistributedSystem() { - if (distributedSystem == null) { - distributedSystem = mockDistributedSystem(); - } - - return distributedSystem; - } - - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#getInitializer() - */ - @Override - public Declarable getInitializer() { - return this.initializer; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#getInitializerProps() - */ - @Override - public Properties getInitializerProps() { - return this.properties; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#getJNDIContext() - */ - @Override - public Context getJNDIContext() { - return this.jndiContext; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#getLogger() - */ - @Override - public LogWriter getLogger() { - return this.logWriter; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#getName() - */ - @Override - public String getName() { - return (this.properties != null ? this.properties.getProperty("name") : null); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#getPdxDiskStore() - */ - @Override - public String getPdxDiskStore() { - return this.pdxDiskStore; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#getPdxIgnoreUnreadFields() - */ - @Override - public boolean getPdxIgnoreUnreadFields() { - return this.pdxIgnoreUnreadFields; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#getPdxPersistent() - */ - @Override - public boolean getPdxPersistent() { - return this.pdxPersistent; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#getPdxReadSerialized() - */ - @Override - public boolean getPdxReadSerialized() { - return this.pdxReadSerialized; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#getPdxSerializer() - */ - @Override - public PdxSerializer getPdxSerializer() { - return this.pdxSerializer; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#getRegionAttributes(java.lang.String) - */ - @SuppressWarnings("unchecked") - @Override - public RegionAttributes getRegionAttributes(String region) { - return allRegions().get(region).getAttributes(); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#getResourceManager() - */ - @Override - public ResourceManager getResourceManager() { - return this.resourceManager; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#getSecurityLogger() - */ - @Override - public LogWriter getSecurityLogger() { - return this.securityLogWriter; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#listRegionAttributes() - */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public Map> listRegionAttributes() { - - Map> attributes = new HashMap<>(); - - for (Entry entry: allRegions().entrySet()) { - attributes.put(entry.getKey(), entry.getValue().getAttributes()); - } - - return attributes; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#loadCacheXml(java.io.InputStream) - */ - @Override - public void loadCacheXml(InputStream is) throws TimeoutException, CacheWriterException, GatewayException, RegionExistsException { - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#setCopyOnRead(boolean) - */ - @Override - public void setCopyOnRead(boolean arg0) { - this.copyOnRead = arg0; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.GemFireCache#setRegionAttributes(java.lang.String, org.apache.geode.cache.RegionAttributes) - */ - @Override - public void setRegionAttributes(String region, RegionAttributes attributes) { - RegionFactory rf = new MockRegionFactory(this).createMockRegionFactory(attributes); - rf.create(region); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.RegionService#close() - */ - @Override - public void close() { - this.closed = true; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.RegionService#createPdxEnum(java.lang.String, java.lang.String, int) - */ - @Override - public PdxInstance createPdxEnum(String arg0, String arg1, int arg2) { - throw new UnsupportedOperationException(NOT_IMPLEMENTED); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.RegionService#createPdxInstanceFactory(java.lang.String) - */ - @Override - public PdxInstanceFactory createPdxInstanceFactory(String arg0) { - throw new UnsupportedOperationException(NOT_IMPLEMENTED); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.RegionService#getCancelCriterion() - */ - @Override - public CancelCriterion getCancelCriterion() { - throw new UnsupportedOperationException(NOT_IMPLEMENTED); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.RegionService#getQueryService() - */ - @Override - public QueryService getQueryService() { - try { - queryServiceReference.compareAndSet(null, mockQueryService()); - return queryServiceReference.get(); - } - catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.RegionService#getRegion(java.lang.String) - */ - @SuppressWarnings("unchecked") - @Override - public Region getRegion(String name) { - return allRegions().get(name); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.RegionService#isClosed() - */ - @Override - public boolean isClosed() { - return this.closed; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.RegionService#rootRegions() - */ - @Override - public Set> rootRegions() { - - Set> rootRegions = new HashSet<>(); - - for (String key: allRegions().keySet()) { - if (!key.contains(Region.SEPARATOR)) { - rootRegions.add(allRegions().get(key)); - } - } - - return rootRegions; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#addCacheServer() - */ - @Override - public CacheServer addCacheServer() { - return mockCacheServer(); - } - - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#close(boolean) - */ - @Override - @Deprecated - public void close(boolean arg0) { - this.closed = true; - - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#createAsyncEventQueueFactory() - */ - @Override - public AsyncEventQueueFactory createAsyncEventQueueFactory() { - return new StubAsyncEventQueueFactory(); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#createGatewayReceiverFactory() - */ - @Override - public GatewayReceiverFactory createGatewayReceiverFactory() { - return new StubGatewayReceiverFactory(); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#createGatewaySenderFactory() - */ - @Override - public GatewaySenderFactory createGatewaySenderFactory() { - return new StubGatewaySenderFactory(); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#createRegion(java.lang.String, org.apache.geode.cache.RegionAttributes) - */ - @Override - @Deprecated - public Region createRegion(String arg0, RegionAttributes arg1) throws RegionExistsException, TimeoutException { - throw new UnsupportedOperationException(NOT_IMPLEMENTED); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#createRegionFactory() - */ - @Override - @SuppressWarnings("unchecked") - public RegionFactory createRegionFactory() { - return new MockRegionFactory(this).createRegionFactory(); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#createRegionFactory(org.apache.geode.cache.RegionAttributes) - */ - @Override - public RegionFactory createRegionFactory(RegionAttributes regionAttributes) { - return new MockRegionFactory(this).createMockRegionFactory(regionAttributes); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#createRegionFactory(org.apache.geode.cache.RegionShortcut) - */ - @Override - @SuppressWarnings("unchecked") - public RegionFactory createRegionFactory(RegionShortcut shortcut) { - return new MockRegionFactory(this).createRegionFactory(); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#createRegionFactory(java.lang.String) - */ - @Override - @SuppressWarnings("unchecked") - public RegionFactory createRegionFactory(String regionAttributesId) { - return new MockRegionFactory(this).createRegionFactory(); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#createVMRegion(java.lang.String, org.apache.geode.cache.RegionAttributes) - */ - @Override - @Deprecated - public Region createVMRegion(String arg0, RegionAttributes arg1) throws RegionExistsException, TimeoutException { - throw new UnsupportedOperationException(NOT_IMPLEMENTED); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#getAdminMembers() - */ - @Override - public Set getAdminMembers() { - throw new UnsupportedOperationException(NOT_IMPLEMENTED); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#getAsyncEventQueue(java.lang.String) - */ - @Override - public AsyncEventQueue getAsyncEventQueue(String name) { - throw new UnsupportedOperationException(NOT_IMPLEMENTED); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#getAsyncEventQueues() - */ - @Override - public Set getAsyncEventQueues() { - throw new UnsupportedOperationException(NOT_IMPLEMENTED); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#getCacheServers() - */ - @Override - public List getCacheServers() { - throw new UnsupportedOperationException(NOT_IMPLEMENTED); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#getGatewayConflictResolver() - */ - @Override - public GatewayConflictResolver getGatewayConflictResolver() { - return this.gatewayConflictResolver; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#getGatewayReceivers() - */ - @Override - public Set getGatewayReceivers() { - return this.gatewayReceivers; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#getGatewaySender(java.lang.String) - */ - @Override - public GatewaySender getGatewaySender(String name) { - throw new UnsupportedOperationException(NOT_IMPLEMENTED); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#getGatewaySenders() - */ - @Override - public Set getGatewaySenders() { - return this.gatewaySenders; - } - - @Override - public JSONFormatter getJsonFormatter() { - return new JSONFormatter(this); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#getLockLease() - */ - @Override - public int getLockLease() { - return this.lockLease; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#getLockTimeout() - */ - @Override - public int getLockTimeout() { - return this.lockTimeout; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#getLoggerI18n() - */ - @Override - @Deprecated - public LogWriterI18n getLoggerI18n() { - throw new UnsupportedOperationException(NOT_IMPLEMENTED); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#getMembers() - */ - @Override - public Set getMembers() { - throw new UnsupportedOperationException(NOT_IMPLEMENTED); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#getMembers(org.apache.geode.cache.Region) - */ - @SuppressWarnings({"rawtypes"}) - @Override - public Set getMembers(Region arg0) { - throw new UnsupportedOperationException(NOT_IMPLEMENTED); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#getMessageSyncInterval() - */ - @Override - public int getMessageSyncInterval() { - return this.messageSyncInterval; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#getSearchTimeout() - */ - @Override - public int getSearchTimeout() { - return this.searchTimeout; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#getSecurityLoggerI18n() - */ - @Override - @Deprecated - public LogWriterI18n getSecurityLoggerI18n() { - throw new UnsupportedOperationException(NOT_IMPLEMENTED); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#getSnapshotService() - */ - @Override - public CacheSnapshotService getSnapshotService() { - throw new UnsupportedOperationException(NOT_IMPLEMENTED); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#isServer() - */ - @Override - public boolean isServer() { - return this.server; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#readyForEvents() - */ - @Override - @Deprecated - public void readyForEvents() { - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#setGatewayConflictResolver(org.apache.geode.cache.util.GatewayConflictResolver) - */ - @Override - public void setGatewayConflictResolver(GatewayConflictResolver arg0) { - this.gatewayConflictResolver = arg0; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#setIsServer(boolean) - */ - @Override - public void setIsServer(boolean server) { - this.server = server; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#setLockLease(int) - */ - @Override - public void setLockLease(int arg0) { - this.lockLease = arg0; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#setLockTimeout(int) - */ - @Override - public void setLockTimeout(int arg0) { - this.lockTimeout = arg0; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#setMessageSyncInterval(int) - */ - @Override - public void setMessageSyncInterval(int arg0) { - this.messageSyncInterval = arg0; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.Cache#setSearchTimeout(int) - */ - @Override - public void setSearchTimeout(int arg0) { - this.searchTimeout = arg0; - } - - DistributedSystem mockDistributedSystem() { - - DistributedSystem mockDistributedSystem = mock(DistributedSystem.class); - - when(mockDistributedSystem.getName()).thenAnswer(invocation -> getName()); - - when(mockDistributedSystem.getProperties()).thenReturn(this.properties); - - DistributedMember mockDistributedMember = mockDistributedMember(); - - when(mockDistributedSystem.getDistributedMember()).thenReturn(mockDistributedMember); - - return mockDistributedSystem; - } - - DistributedMember mockDistributedMember() { - DistributedMember mockDistributedMember = mock(DistributedMember.class); - when(mockDistributedMember.getHost()).thenReturn("mockDistributedMember.host"); - when(mockDistributedMember.getName()).thenReturn("mockDistributedMember"); - return mockDistributedMember; - } - - CacheServer mockCacheServer() { - return new StubCacheServer(); - } - - QueryService mockQueryService() throws RegionNotFoundException, IndexInvalidException, IndexNameConflictException, - IndexExistsException, UnsupportedOperationException { - - QueryService queryService = mock(QueryService.class); - - when(queryService.getIndexes()).thenReturn(new ArrayList<>()); - - when(queryService.createIndex(anyString(), anyString(),anyString())).thenAnswer(invocation -> { - - String indexName = (String) invocation.getArguments()[0]; - String indexedExpression = (String) invocation.getArguments()[1]; - String fromClause = (String) invocation.getArguments()[2]; - - return mockIndex(indexName, org.apache.geode.cache.query.IndexType.FUNCTIONAL, indexedExpression, - fromClause, null); - }); - - when(queryService.createIndex(anyString(), anyString(),anyString(),anyString())).thenAnswer(invocation -> { - - String indexName = (String) invocation.getArguments()[0]; - String indexedExpression = (String) invocation.getArguments()[1]; - String fromClause = (String) invocation.getArguments()[2]; - String imports = (String) invocation.getArguments()[3]; - - return mockIndex(indexName, org.apache.geode.cache.query.IndexType.FUNCTIONAL, indexedExpression, - fromClause, imports); - }); - - when(queryService.createKeyIndex(anyString(), anyString(),anyString())).thenAnswer(invocation -> { - - String indexName = (String) invocation.getArguments()[0]; - String indexedExpression = (String) invocation.getArguments()[1]; - String fromClause = (String) invocation.getArguments()[2]; - - return mockIndex(indexName, org.apache.geode.cache.query.IndexType.PRIMARY_KEY, indexedExpression, - fromClause, null); - }); - - when(queryService.createHashIndex(anyString(), anyString(),anyString())).thenAnswer(invocation -> { - - String indexName = (String) invocation.getArguments()[0]; - String indexedExpression = (String) invocation.getArguments()[1]; - String fromClause = (String) invocation.getArguments()[2]; - - return mockIndex(indexName, org.apache.geode.cache.query.IndexType.HASH, indexedExpression, - fromClause, null); - }); - - when(queryService.createHashIndex(anyString(), anyString(),anyString(),anyString())).thenAnswer(invocation -> { - - String indexName = (String) invocation.getArguments()[0]; - String indexedExpression = (String) invocation.getArguments()[1]; - String fromClause = (String) invocation.getArguments()[2]; - String imports = (String) invocation.getArguments()[3]; - - return mockIndex(indexName, org.apache.geode.cache.query.IndexType.HASH, indexedExpression, - fromClause, imports); - }); - - return queryService; - } - - @SuppressWarnings({ "rawtypes", "unchecked", "unused" }) - Index mockIndex(String indexName, org.apache.geode.cache.query.IndexType indexType, String indexedExpression, - String fromClause, String imports){ - Index idx = mock(Index.class); - when(idx.getFromClause()).thenReturn(fromClause); - when(idx.getIndexedExpression()).thenReturn(indexedExpression); - when(idx.getName()).thenReturn(indexName); - when(idx.getType()).thenReturn(indexType); - - - if (fromClause != null && fromClause.length() >= 2) { - Region region = mock(Region.class); - String name = fromClause.substring(1).split(" ")[0]; - when(region.getName()).thenReturn(name); - when(idx.getRegion()).thenReturn(region); - } - return idx; - } - - @SuppressWarnings("rawtypes") - public Map allRegions() { - return this.rootRegions; - } - - public void setProperties(Properties gemfireProperties) { - this.properties = gemfireProperties; - } - - @Override - public boolean isReconnecting() { - return false; - } - - @Override - public Cache getReconnectedCache() { - return this; - } - - @Override - public void stopReconnecting() { - } - - @Override - public boolean waitUntilReconnected(final long l, final TimeUnit timeUnit) throws InterruptedException { - return false; - } - - public RegionService createAuthenticatedView(final Properties userSecurityProperties) { - return this; - } - - @Override - public RegionService createAuthenticatedView(final Properties userSecurityProperties, final String poolName) { - return this; - } - - @Override - public ClientRegionFactory createClientRegionFactory(ClientRegionShortcut shortcut) { - return new MockClientRegionFactory(this).createClientRegionFactory(shortcut); - } - - @Override - public ClientRegionFactory createClientRegionFactory(String regionAttributesId) { - return new MockClientRegionFactory(this).createClientRegionFactory(); - } - - @Override - public Set getCurrentServers() { - return Collections.emptySet(); - } - - @Override - public Pool getDefaultPool() { - return null; - } - - @Override - public QueryService getLocalQueryService() { - return getQueryService(); - } - - @Override - public QueryService getQueryService(final String poolName) { - return getQueryService(); - } - - @Override - public void registerPdxMetaData(Object objectToSerializeAndRegister) { } - -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubCacheServer.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubCacheServer.java deleted file mode 100644 index 5e33751a..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubCacheServer.java +++ /dev/null @@ -1,422 +0,0 @@ -/* - * Copyright 2002-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package org.springframework.data.gemfire.test; - -import java.io.IOException; -import java.util.Set; - -import org.apache.geode.cache.ClientSession; -import org.apache.geode.cache.InterestRegistrationListener; -import org.apache.geode.cache.server.CacheServer; -import org.apache.geode.cache.server.ClientSubscriptionConfig; -import org.apache.geode.cache.server.ServerLoadProbe; -import org.apache.geode.distributed.DistributedMember; - -/** - * @author David Turanski - * @author John Blum - */ -@SuppressWarnings("deprecation") -public class StubCacheServer implements CacheServer { - - private boolean isRunning; - private boolean notifyBySubscription; - private boolean tcpNoDelay; - - private int maxConnections; - private int maximumMessageCount; - private int maximumTimeBetweenPings; - private int maxThreads; - private int messageTimeToLive; - private int port; - private int socketBufferSize; - - private long loadPollInterval; - - private ClientSession clientSession; - - private ClientSubscriptionConfig clientSubscriptionConfig = mockClientSubscriptionConfig(); - - private Set clientSessions; - - private ServerLoadProbe serverLoadProbe; - - private String bindAddress; - private String hostNameForClients; - private String[] groups; - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getPort() - */ - @Override - public int getPort() { - return port; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#setPort(int) - */ - @Override - public void setPort(int port) { - this.port = port; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getBindAddress() - */ - @Override - public String getBindAddress() { - return bindAddress; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#setBindAddress(java.lang.String) - */ - @Override - public void setBindAddress(String address) { - this.bindAddress = address; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getHostnameForClients() - */ - @Override - public String getHostnameForClients() { - return this.hostNameForClients; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#setHostnameForClients(java.lang.String) - */ - @Override - public void setHostnameForClients(String name) { - this.hostNameForClients = name; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#setNotifyBySubscription(boolean) - */ - @Override - @Deprecated - public void setNotifyBySubscription(boolean b) { - this.notifyBySubscription = b; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getNotifyBySubscription() - */ - @Override - @Deprecated - public boolean getNotifyBySubscription() { - return this.notifyBySubscription; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#setSocketBufferSize(int) - */ - @Override - public void setSocketBufferSize(int socketBufferSize) { - this.socketBufferSize = socketBufferSize; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getSocketBufferSize() - */ - @Override - public int getSocketBufferSize() { - return this.socketBufferSize; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#setMaximumTimeBetweenPings(int) - */ - @Override - public void setMaximumTimeBetweenPings(int maximumTimeBetweenPings) { - this.maximumTimeBetweenPings = maximumTimeBetweenPings; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getMaximumTimeBetweenPings() - */ - @Override - public int getMaximumTimeBetweenPings() { - return this.maximumTimeBetweenPings; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#start() - */ - @Override - public void start() throws IOException { - isRunning = true; - - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#isRunning() - */ - @Override - public boolean isRunning() { - return isRunning; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#stop() - */ - @Override - public void stop() { - isRunning = false; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getMaxConnections() - */ - @Override - public int getMaxConnections() { - return this.maxConnections; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#setMaxConnections(int) - */ - @Override - public void setMaxConnections(int maxCons) { - this.maxConnections = maxCons; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getMaxThreads() - */ - @Override - public int getMaxThreads() { - return this.maxThreads; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#setMaxThreads(int) - */ - @Override - public void setMaxThreads(int maxThreads) { - this.maxThreads = maxThreads; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getMaximumMessageCount() - */ - @Override - public int getMaximumMessageCount() { - return this.maximumMessageCount; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#setMaximumMessageCount(int) - */ - @Override - public void setMaximumMessageCount(int maxMessageCount) { - this.maximumMessageCount = maxMessageCount; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getMessageTimeToLive() - */ - @Override - public int getMessageTimeToLive() { - return this.messageTimeToLive; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#setMessageTimeToLive(int) - */ - @Override - public void setMessageTimeToLive(int messageTimeToLive) { - this.messageTimeToLive = messageTimeToLive; - - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#setGroups(java.lang.String[]) - */ - @Override - public void setGroups(String[] groups) { - this.groups = groups; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getGroups() - */ - @Override - public String[] getGroups() { - return this.groups; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getLoadProbe() - */ - @Override - public ServerLoadProbe getLoadProbe() { - return this.serverLoadProbe; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#setLoadProbe(org.apache.geode.cache.server.ServerLoadProbe) - */ - @Override - public void setLoadProbe(ServerLoadProbe loadProbe) { - this.serverLoadProbe = loadProbe; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getLoadPollInterval() - */ - @Override - public long getLoadPollInterval() { - return this.loadPollInterval; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#setLoadPollInterval(long) - */ - @Override - public void setLoadPollInterval(long loadPollInterval) { - this.loadPollInterval = loadPollInterval; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getClientSubscriptionConfig() - */ - @Override - public ClientSubscriptionConfig getClientSubscriptionConfig() { - return this.clientSubscriptionConfig; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getClientSession(org.apache.geode.distributed.DistributedMember) - */ - @Override - public ClientSession getClientSession(DistributedMember member) { - return this.clientSession; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getClientSession(java.lang.String) - */ - @Override - public ClientSession getClientSession(String durableClientId) { - return this.clientSession; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getAllClientSessions() - */ - @Override - public Set getAllClientSessions() { - return this.clientSessions; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#registerInterestRegistrationListener(org.apache.geode.cache.InterestRegistrationListener) - */ - @Override - public void registerInterestRegistrationListener(InterestRegistrationListener listener) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#unregisterInterestRegistrationListener(org.apache.geode.cache.InterestRegistrationListener) - */ - @Override - public void unregisterInterestRegistrationListener(InterestRegistrationListener listener) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getInterestRegistrationListeners() - */ - @Override - public Set getInterestRegistrationListeners() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#getTcpNoDelay() - */ - @Override - public boolean getTcpNoDelay() { - return tcpNoDelay; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.server.CacheServer#setTcpNoDelay(boolean) - */ - @Override - public void setTcpNoDelay(final boolean tcpNoDelay) { - this.tcpNoDelay = tcpNoDelay; - } - - ClientSubscriptionConfig mockClientSubscriptionConfig() { - return new MockClientSubscriptionConfig(); - } - - protected static class MockClientSubscriptionConfig implements ClientSubscriptionConfig { - - private int capacity; - - private String diskStoreName; - private String evictionPolicy; - private String overflowDirectory; - - @Override - public int getCapacity() { - return capacity; - } - - @Override - public void setCapacity(final int capacity) { - this.capacity = capacity; - } - - @Override - public String getDiskStoreName() { - return diskStoreName; - } - - @Override - public void setDiskStoreName(final String diskStoreName) { - this.diskStoreName = diskStoreName; - } - - @Override - public String getEvictionPolicy() { - return evictionPolicy; - } - - @Override - public void setEvictionPolicy(final String policy) { - this.evictionPolicy = policy; - } - - @Override - public String getOverflowDirectory() { - return overflowDirectory; - } - - @Override - public void setOverflowDirectory(final String overflowDirectory) { - this.overflowDirectory = overflowDirectory; - } - } - -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubCacheTransactionManager.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubCacheTransactionManager.java deleted file mode 100644 index 65c4b31c..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubCacheTransactionManager.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright 2002-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package org.springframework.data.gemfire.test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import org.apache.geode.cache.CacheTransactionManager; -import org.apache.geode.cache.CommitConflictException; -import org.apache.geode.cache.TransactionId; -import org.apache.geode.cache.TransactionListener; -import org.apache.geode.cache.TransactionWriter; - - -/** - * @author David Turanski - * - */ -public class StubCacheTransactionManager implements CacheTransactionManager { - - private List listeners = new ArrayList(); - - private TransactionWriter writer; - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#begin() - */ - @Override - public void begin() { - throw new UnsupportedOperationException("Not Implemented!"); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#commit() - */ - @Override - public void commit() throws CommitConflictException { - throw new UnsupportedOperationException("Not Implemented!"); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#rollback() - */ - @Override - public void rollback() { - throw new UnsupportedOperationException("Not Implemented!"); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#suspend() - */ - @Override - public TransactionId suspend() { - throw new UnsupportedOperationException("Not Implemented!"); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#resume(org.apache.geode.cache.TransactionId) - */ - @Override - public void resume(TransactionId transactionId) { - throw new UnsupportedOperationException("Not Implemented!"); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#isSuspended(org.apache.geode.cache.TransactionId) - */ - @Override - public boolean isSuspended(TransactionId transactionId) { - return false; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#tryResume(org.apache.geode.cache.TransactionId) - */ - @Override - public boolean tryResume(TransactionId transactionId) { - return false; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#tryResume(org.apache.geode.cache.TransactionId, long, java.util.concurrent.TimeUnit) - */ - @Override - public boolean tryResume(TransactionId transactionId, long time, TimeUnit unit) { - return false; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#exists(org.apache.geode.cache.TransactionId) - */ - @Override - public boolean exists(TransactionId transactionId) { - return false; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#exists() - */ - @Override - public boolean exists() { - return false; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#getTransactionId() - */ - @Override - public TransactionId getTransactionId() { - return null; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#getListener() - */ - @Override - @Deprecated - public TransactionListener getListener() { - return null; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#getListeners() - */ - @Override - public TransactionListener[] getListeners() { - return listeners.toArray(new TransactionListener[listeners.size()]); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#setListener(org.apache.geode.cache.TransactionListener) - */ - @Override - @Deprecated - public TransactionListener setListener(TransactionListener newListener) { - throw new UnsupportedOperationException("Not Implemented!"); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#addListener(org.apache.geode.cache.TransactionListener) - */ - @Override - public void addListener(TransactionListener aListener) { - this.listeners.add(aListener); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#removeListener(org.apache.geode.cache.TransactionListener) - */ - @Override - public void removeListener(TransactionListener aListener) { - this.listeners.remove(aListener); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#initListeners(org.apache.geode.cache.TransactionListener[]) - */ - @Override - public void initListeners(TransactionListener[] newListeners) { - this.listeners = Arrays.asList(newListeners); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#setWriter(org.apache.geode.cache.TransactionWriter) - */ - @Override - public void setWriter(TransactionWriter writer) { - this.writer = writer; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.CacheTransactionManager#getWriter() - */ - @Override - public TransactionWriter getWriter() { - return this.writer; - } - - @Override - public void setDistributed(final boolean b) { - throw new UnsupportedOperationException("Not Implemented!"); - } - - @Override - public boolean isDistributed() { - return false; - } - -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubDiskStore.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubDiskStore.java deleted file mode 100644 index 8d11bfe1..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubDiskStore.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright 2002-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package org.springframework.data.gemfire.test; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -import org.apache.geode.cache.DiskStore; -import org.apache.geode.cache.DiskStoreFactory; - -/** - * @author David Turanski - * @author John Blum - */ -public class StubDiskStore implements DiskStoreFactory { - - private static Map diskStores = new HashMap(); - - private boolean allowForceCompaction; - private boolean autoCompact; - - private float diskUsageCriticalPercentage; - private float diskUsageWarningPercentage; - - private int compactionThreshold; - private int queueSize; - private int writeBufferSize; - - private int[] diskDirSizes; - - private long maxOpLogSize; - private long timeInterval; - - private File[] diskDirs; - - public static DiskStore getDiskStore(final String name) { - return diskStores.get(name); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.DiskStoreFactory#setAllowForceCompaction(boolean) - */ - @Override - public DiskStoreFactory setAllowForceCompaction(boolean allowForceCompaction) { - this.allowForceCompaction = allowForceCompaction; - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.DiskStoreFactory#setAutoCompact(boolean) - */ - @Override - public DiskStoreFactory setAutoCompact(boolean isAutoCompact) { - this.autoCompact = isAutoCompact; - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.DiskStoreFactory#setCompactionThreshold(int) - */ - @Override - public DiskStoreFactory setCompactionThreshold(int compactionThreshold) { - this.compactionThreshold = compactionThreshold; - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.DiskStoreFactory#setMaxOplogSize(long) - */ - @Override - public DiskStoreFactory setMaxOplogSize(long maxOplogSize) { - this.maxOpLogSize = maxOplogSize; - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.DiskStoreFactory#setTimeInterval(long) - */ - @Override - public DiskStoreFactory setTimeInterval(long timeInterval) { - this.timeInterval = timeInterval; - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.DiskStoreFactory#setWriteBufferSize(int) - */ - @Override - public DiskStoreFactory setWriteBufferSize(int writeBufferSize) { - this.writeBufferSize = writeBufferSize; - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.DiskStoreFactory#setQueueSize(int) - */ - @Override - public DiskStoreFactory setQueueSize(int queueSize) { - this.queueSize = queueSize; - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.DiskStoreFactory#setDiskDirs(java.io.File[]) - */ - @Override - public DiskStoreFactory setDiskDirs(File[] diskDirs) { - this.diskDirs = diskDirs; - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.DiskStoreFactory#setDiskDirsAndSizes(java.io.File[], int[]) - */ - @Override - public DiskStoreFactory setDiskDirsAndSizes(File[] diskDirs, int[] diskDirSizes) { - this.diskDirs = diskDirs; - this.diskDirSizes = diskDirSizes; - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.DiskStoreFactory#setDiskUsageCriticalPercentage(float) - */ - @Override - public DiskStoreFactory setDiskUsageCriticalPercentage(final float diskUsageCriticalPercentage) { - this.diskUsageCriticalPercentage = diskUsageCriticalPercentage; - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.DiskStoreFactory#setDiskUsageWarningPercentage(float) - */ - @Override - public DiskStoreFactory setDiskUsageWarningPercentage(final float diskUsageWarningPercentage) { - this.diskUsageWarningPercentage = diskUsageWarningPercentage; - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.DiskStoreFactory#create(java.lang.String) - */ - @Override - public DiskStore create(final String name) { - DiskStore mockDiskStore = mock(DiskStore.class, name); - - when(mockDiskStore.getName()).thenReturn(name); - when(mockDiskStore.getAllowForceCompaction()).thenReturn(allowForceCompaction); - when(mockDiskStore.getAutoCompact()).thenReturn(autoCompact); - when(mockDiskStore.getCompactionThreshold()).thenReturn(compactionThreshold); - when(mockDiskStore.getDiskUsageCriticalPercentage()).thenReturn(diskUsageCriticalPercentage); - when(mockDiskStore.getDiskUsageWarningPercentage()).thenReturn(diskUsageWarningPercentage); - when(mockDiskStore.getDiskDirs()).thenReturn(diskDirs); - when(mockDiskStore.getDiskDirSizes()).thenReturn(diskDirSizes); - when(mockDiskStore.getMaxOplogSize()).thenReturn(maxOpLogSize); - when(mockDiskStore.getQueueSize()).thenReturn(queueSize); - when(mockDiskStore.getTimeInterval()).thenReturn(timeInterval); - when(mockDiskStore.getWriteBufferSize()).thenReturn(writeBufferSize); - - diskStores.put(name, mockDiskStore); - - return mockDiskStore; - } - -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubGatewayReceiverFactory.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubGatewayReceiverFactory.java deleted file mode 100644 index 9f3805c1..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubGatewayReceiverFactory.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright 2002-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package org.springframework.data.gemfire.test; - -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - -import org.apache.geode.cache.wan.GatewayReceiver; -import org.apache.geode.cache.wan.GatewayReceiverFactory; -import org.apache.geode.cache.wan.GatewayTransportFilter; - -import org.springframework.util.StringUtils; - -/** - * @author David Turanski - * @author John Blum - * @see org.apache.geode.cache.wan.GatewayReceiverFactory - */ -@SuppressWarnings("unused") -public class StubGatewayReceiverFactory implements GatewayReceiverFactory { - - private volatile boolean running; - - private boolean manualStart; - - private int endPort; - private int maximumTimeBetweenPings; - private int socketBufferSize; - private int startPort; - - private List gatewayTransportFilters = new ArrayList(); - - private String bindAddress; - private String hostnameForClients; - private String hostnameForSenders; - - /* (non-Javadoc) - * @see org.apache.geode.cache.wan.GatewayReceiverFactory#setStartPort(int) - */ - @Override - public GatewayReceiverFactory setStartPort(int startPort) { - this.startPort = startPort; - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.wan.GatewayReceiverFactory#setEndPort(int) - */ - @Override - public GatewayReceiverFactory setEndPort(int endPort) { - this.endPort = endPort; - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.wan.GatewayReceiverFactory#setSocketBufferSize(int) - */ - @Override - public GatewayReceiverFactory setSocketBufferSize(int socketBufferSize) { - this.socketBufferSize = socketBufferSize; - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.wan.GatewayReceiverFactory#setBindAddress(java.lang.String) - */ - @Override - public GatewayReceiverFactory setBindAddress(String address) { - this.bindAddress = address; - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.wan.GatewayReceiverFactory#addGatewayTransportFilter(org.apache.geode.cache.wan.GatewayTransportFilter) - */ - @Override - public GatewayReceiverFactory addGatewayTransportFilter(GatewayTransportFilter filter) { - this.gatewayTransportFilters.add(filter); - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.wan.GatewayReceiverFactory#removeGatewayTransportFilter(org.apache.geode.cache.wan.GatewayTransportFilter) - */ - @Override - public GatewayReceiverFactory removeGatewayTransportFilter(GatewayTransportFilter filter) { - this.gatewayTransportFilters.remove(filter); - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.wan.GatewayReceiverFactory#setMaximumTimeBetweenPings(int) - */ - @Override - public GatewayReceiverFactory setMaximumTimeBetweenPings(int time) { - this.maximumTimeBetweenPings = time; - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.wan.GatewayReceiverFactory#setHostnameForClients(String) - * @see org.apache.geode.cache.wan.GatewayReceiver#getHost - */ - //@Override - public GatewayReceiverFactory setHostnameForClients(final String name) { - this.hostnameForClients = name; - return this; - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.wan.GatewayReceiverFactory#setHostnameForSenders(String) - */ - @Override - public GatewayReceiverFactory setHostnameForSenders(final String hostnameForSenders) { - this.hostnameForSenders = hostnameForSenders; - return this; - } - - /* - * (non-Javadoc) - * @see org.apache.geode.cache.wan.GatewayReceiverFactory#setManualStart(boolean) - */ - @Override - public GatewayReceiverFactory setManualStart(final boolean manualStart) { - this.manualStart = manualStart; - this.running = !manualStart; - return this; - } - - private int generatePort() { - final int portIncrement = new Random(System.currentTimeMillis()).nextInt(this.endPort - this.startPort); - return Math.min(this.startPort + portIncrement, this.endPort); - } - - /* (non-Javadoc) - * @see org.apache.geode.cache.wan.GatewayReceiverFactory#create() - */ - @Override - public GatewayReceiver create() { - GatewayReceiver gatewayReceiver = mock(GatewayReceiver.class); - - when(gatewayReceiver.getBindAddress()).thenReturn(this.bindAddress); - when(gatewayReceiver.getEndPort()).thenReturn(this.endPort); - when(gatewayReceiver.getGatewayTransportFilters()).thenReturn(this.gatewayTransportFilters); - when(gatewayReceiver.getHost()).thenReturn(StringUtils.hasText(this.hostnameForSenders) - ? this.hostnameForSenders : this.hostnameForClients); - when(gatewayReceiver.isManualStart()).thenReturn(this.manualStart); - when(gatewayReceiver.getMaximumTimeBetweenPings()).thenReturn(this.maximumTimeBetweenPings); - when(gatewayReceiver.getPort()).thenReturn(generatePort()); - when(gatewayReceiver.getSocketBufferSize()).thenReturn(this.socketBufferSize); - when(gatewayReceiver.getStartPort()).thenReturn(this.startPort); - - when(gatewayReceiver.isRunning()).thenAnswer(new Answer() { - @Override - public Boolean answer(InvocationOnMock invocation) throws Throwable { - return StubGatewayReceiverFactory.this.running; - } - }); - - try { - doAnswer(new Answer() { - public Void answer(InvocationOnMock invocation) { - StubGatewayReceiverFactory.this.running = true; - return null; - } - }).when(gatewayReceiver).start(); - } - catch (IOException e) { - throw new RuntimeException(e); - } - - doAnswer(new Answer() { - public Void answer(final InvocationOnMock invocation) throws Throwable { - StubGatewayReceiverFactory.this.running = false; - return null; - } - }).when(gatewayReceiver).stop(); - - return gatewayReceiver; - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubGatewaySenderFactory.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubGatewaySenderFactory.java deleted file mode 100644 index 8171dcd4..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubGatewaySenderFactory.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright 2002-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package org.springframework.data.gemfire.test; - -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.List; - -import org.mockito.stubbing.Answer; - -import org.apache.geode.cache.wan.GatewayEventFilter; -import org.apache.geode.cache.wan.GatewayEventSubstitutionFilter; -import org.apache.geode.cache.wan.GatewaySender; -import org.apache.geode.cache.wan.GatewaySender.OrderPolicy; -import org.apache.geode.cache.wan.GatewaySenderFactory; -import org.apache.geode.cache.wan.GatewayTransportFilter; - -/** - * {@link StubGatewaySenderFactory} class for testing purposes. - * - * @author David Turanski - * @author John Blum - * @see org.apache.geode.cache.wan.GatewaySenderFactory - */ -@SuppressWarnings({ "deprecation", "unused" }) -public class StubGatewaySenderFactory implements GatewaySenderFactory { - - private boolean batchConflationEnabled; - private boolean diskSynchronous; - private boolean groupTransactionEvents; - private boolean manualStart; - private boolean parallel; - private boolean persistenceEnabled; - private boolean running = false; - private boolean enforceThreadsConnectSameReceiver; - - private int alertThreshold; - private int batchSize; - private int batchTimeInterval; - private int dispatcherThreads; - private int maxQueueMemory; - private int parallelFactorForReplicatedRegion; - private int socketBufferSize; - private int socketReadTimeout; - - private GatewayEventSubstitutionFilter gatewayEventSubstitutionFilter; - - private final List eventFilters = new ArrayList<>(); - private final List transportFilters = new ArrayList<>(); - - private OrderPolicy orderPolicy; - - private String diskStoreName; - - @Override - public GatewaySenderFactory addGatewayEventFilter(GatewayEventFilter filter) { - eventFilters.add(filter); - return this; - } - - @Override - public GatewaySenderFactory addGatewayTransportFilter(GatewayTransportFilter filter) { - transportFilters.add(filter); - return this; - } - - @Override - public GatewaySender create(String name, int remoteSystemId) { - - GatewaySender gatewaySender = mock(GatewaySender.class); - - when(gatewaySender.getId()).thenReturn(name); - when(gatewaySender.getRemoteDSId()).thenReturn(remoteSystemId); - when(gatewaySender.getAlertThreshold()).thenReturn(this.alertThreshold); - when(gatewaySender.getGatewayEventFilters()).thenReturn(this.eventFilters); - when(gatewaySender.getGatewayEventSubstitutionFilter()).thenReturn(gatewayEventSubstitutionFilter); - when(gatewaySender.getGatewayTransportFilters()).thenReturn(this.transportFilters); - when(gatewaySender.isManualStart()).thenReturn(this.manualStart); - when(gatewaySender.getSocketBufferSize()).thenReturn(this.socketBufferSize); - when(gatewaySender.getSocketReadTimeout()).thenReturn(this.socketReadTimeout); - when(gatewaySender.isBatchConflationEnabled()).thenReturn(this.batchConflationEnabled); - when(gatewaySender.getBatchSize()).thenReturn(this.batchSize); - when(gatewaySender.getBatchTimeInterval()).thenReturn(this.batchTimeInterval); - when(gatewaySender.getDiskStoreName()).thenReturn(this.diskStoreName); - when(gatewaySender.isDiskSynchronous()).thenReturn(this.diskSynchronous); - when(gatewaySender.getDispatcherThreads()).thenReturn(this.dispatcherThreads); - when(gatewaySender.getMaximumQueueMemory()).thenReturn(this.maxQueueMemory); - when(gatewaySender.isParallel()).thenReturn(this.parallel); - when(gatewaySender.isPersistenceEnabled()).thenReturn(this.persistenceEnabled); - when(gatewaySender.getOrderPolicy()).thenReturn(this.orderPolicy); - when(gatewaySender.isRunning()).thenAnswer((Answer) invocation -> this.running); - doAnswer(invocation -> { - running = true; - return null; - }).when(gatewaySender).start(); - - return gatewaySender; - } - - @Override - public GatewaySenderFactory removeGatewayEventFilter(GatewayEventFilter filter) { - this.eventFilters.remove(filter); - return this; - } - - @Override - public GatewaySenderFactory setAlertThreshold(int alertThreshold) { - this.alertThreshold = alertThreshold; - return this; - } - - @Override - public GatewaySenderFactory setBatchConflationEnabled(boolean batchConflationEnabled) { - this.batchConflationEnabled = batchConflationEnabled; - return this; - } - - @Override - public GatewaySenderFactory setBatchSize(int batchSize) { - this.batchSize = batchSize; - return this; - } - - @Override - public GatewaySenderFactory setBatchTimeInterval(int batchTimeInterval) { - this.batchTimeInterval = batchTimeInterval; - return this; - } - - @Override - public GatewaySenderFactory setDiskStoreName(String diskStoreName) { - this.diskStoreName = diskStoreName; - return this; - } - - @Override - public GatewaySenderFactory setDiskSynchronous(boolean diskSynchronous) { - this.diskSynchronous = diskSynchronous; - return this; - } - - @Override - public GatewaySenderFactory setDispatcherThreads(int dispatcherThreads) { - this.dispatcherThreads = dispatcherThreads; - return this; - } - - @Override - public GatewaySenderFactory setEnforceThreadsConnectSameReceiver(boolean b) { - this.enforceThreadsConnectSameReceiver = b; - return this; - } - - @Override - public GatewaySenderFactory setGroupTransactionEvents(boolean groupTransactionEvents) { - this.groupTransactionEvents = groupTransactionEvents; - return this; - } - - @Override - public GatewaySenderFactory setManualStart(boolean manualStart) { - this.manualStart = manualStart; - return this; - } - - @Override - public GatewaySenderFactory setMaximumQueueMemory(int maxQueueMemory) { - this.maxQueueMemory = maxQueueMemory; - return this; - } - - @Override - public GatewaySenderFactory setOrderPolicy(OrderPolicy orderPolicy) { - this.orderPolicy = orderPolicy; - return this; - } - - @Override - public GatewaySenderFactory setParallel(boolean parallel) { - this.parallel = parallel; - return this; - } - - @Override - public GatewaySenderFactory setPersistenceEnabled(boolean persistenceEnabled) { - this.persistenceEnabled = persistenceEnabled; - return this; - } - - @Override - public GatewaySenderFactory setSocketBufferSize(int socketBufferSize) { - this.socketBufferSize = socketBufferSize; - return this; - } - - @Override - public GatewaySenderFactory setSocketReadTimeout(int socketReadTimeout) { - this.socketReadTimeout = socketReadTimeout; - return this; - } - - @Override - public GatewaySenderFactory removeGatewayTransportFilter(GatewayTransportFilter gatewayTransportFilter) { - return this; - } - - @Override - public GatewaySenderFactory setParallelFactorForReplicatedRegion(final int parallelFactorForReplicatedRegion) { - this.parallelFactorForReplicatedRegion = parallelFactorForReplicatedRegion; - return this; - } - - @Override - public GatewaySenderFactory setGatewayEventSubstitutionFilter( - final GatewayEventSubstitutionFilter gatewayEventSubstitutionFilter) { - this.gatewayEventSubstitutionFilter = gatewayEventSubstitutionFilter; - return this; - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubResourceManager.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubResourceManager.java deleted file mode 100644 index 17a6b661..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/StubResourceManager.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.springframework.data.gemfire.test; - -import static org.mockito.Mockito.mock; - -import java.util.Collections; -import java.util.Set; -import java.util.concurrent.CompletableFuture; - -import org.apache.geode.cache.control.RebalanceFactory; -import org.apache.geode.cache.control.RebalanceOperation; -import org.apache.geode.cache.control.ResourceManager; -import org.apache.geode.cache.control.RestoreRedundancyOperation; -import org.apache.geode.management.runtime.RestoreRedundancyResults; - -/** - * @author John Blum - * @deprecated - */ -@Deprecated -public class StubResourceManager implements ResourceManager { - - private float criticalHeapPercentage; - private float criticalOffHeapPercentage; - private float evictionHeapPercentage; - private float evictionOffHeapPercentage; - - @Override - public void setCriticalHeapPercentage(float heapPercentage) { - this.criticalHeapPercentage = heapPercentage; - } - - @Override - public float getCriticalHeapPercentage() { - return this.criticalHeapPercentage; - } - - @Override - public void setCriticalOffHeapPercentage(float offHeapPercentage) { - this.criticalOffHeapPercentage = offHeapPercentage; - } - - @Override - public float getCriticalOffHeapPercentage() { - return this.criticalOffHeapPercentage; - } - - @Override - public void setEvictionHeapPercentage(float heapPercentage) { - this.evictionHeapPercentage = heapPercentage; - } - - @Override - public float getEvictionHeapPercentage() { - return this.evictionHeapPercentage; - } - - @Override - public void setEvictionOffHeapPercentage(float offHeapPercentage) { - this.evictionOffHeapPercentage = offHeapPercentage; - } - - @Override - public float getEvictionOffHeapPercentage() { - return evictionOffHeapPercentage; - } - - @Override - public RebalanceFactory createRebalanceFactory() { - throw new UnsupportedOperationException("Not Implemented"); - } - - @Override - public Set getRebalanceOperations() { - return Collections.emptySet(); - } - - @Override - public RestoreRedundancyOperation createRestoreRedundancyOperation() { - return mock(RestoreRedundancyOperation.class); - } - - @Override - public Set> getRestoreRedundancyFutures() { - return Collections.emptySet(); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/logging/slf4j/logback/TestAppender.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/logging/slf4j/logback/TestAppender.java deleted file mode 100644 index 852560ce..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/logging/slf4j/logback/TestAppender.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2017-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.test.logging.slf4j.logback; - -import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException; - -import java.util.Optional; -import java.util.Stack; -import java.util.concurrent.atomic.AtomicReference; - -import org.springframework.util.StringUtils; - -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.Appender; -import ch.qos.logback.core.AppenderBase; - -/** - * The {@link TestAppender} class is a SLF4J, Logback {@link Appender} implementation used for testing purposes. - * - * @author John Blum - * @see ch.qos.logback.core.Appender - * @see ch.qos.logback.core.AppenderBase - * @since 2.0.2 - */ -@SuppressWarnings("unused") -public class TestAppender extends AppenderBase implements Appender { - - private static final AtomicReference INSTANCE = new AtomicReference<>(null); - - private static final Stack logMessages = new Stack<>(); - - public static TestAppender getInstance() { - - return Optional.ofNullable(INSTANCE.get()) - .orElseThrow(() -> newIllegalStateException("[%s] was not properly configured", - TestAppender.class.getName())); - } - - public TestAppender() { - INSTANCE.compareAndSet(null, this); - } - - @Override - protected void append(ILoggingEvent event) { - - Optional.ofNullable(event) - .map(ILoggingEvent::getFormattedMessage) - .filter(StringUtils::hasText) - .ifPresent(logMessages::push); - } - - public String lastLogMessage() { - synchronized (logMessages) { - return (logMessages.empty() ? null : logMessages.pop()); - } - } - - public void clear() { - logMessages.clear(); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/GemFireMockObjectsSupport.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/GemFireMockObjectsSupport.java deleted file mode 100644 index a8a9f51f..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/GemFireMockObjectsSupport.java +++ /dev/null @@ -1,2912 +0,0 @@ -/* - * Copyright 2017-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.gemfire.test.mock; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.ArgumentMatchers.anyFloat; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; -import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray; -import static org.springframework.data.gemfire.util.CollectionUtils.asSet; -import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeMap; -import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeSet; -import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.NOT_SUPPORTED; -import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException; -import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException; -import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newUnsupportedOperationException; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Properties; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Function; -import java.util.stream.Collectors; - -import org.mockito.ArgumentMatchers; -import org.mockito.stubbing.Answer; - -import org.apache.geode.cache.AttributesMutator; -import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheFactory; -import org.apache.geode.cache.CacheListener; -import org.apache.geode.cache.CacheLoader; -import org.apache.geode.cache.CacheWriter; -import org.apache.geode.cache.CustomExpiry; -import org.apache.geode.cache.DataPolicy; -import org.apache.geode.cache.DiskStore; -import org.apache.geode.cache.DiskStoreFactory; -import org.apache.geode.cache.EvictionAttributes; -import org.apache.geode.cache.EvictionAttributesMutator; -import org.apache.geode.cache.ExpirationAction; -import org.apache.geode.cache.ExpirationAttributes; -import org.apache.geode.cache.GemFireCache; -import org.apache.geode.cache.PartitionAttributes; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.RegionAttributes; -import org.apache.geode.cache.RegionExistsException; -import org.apache.geode.cache.RegionFactory; -import org.apache.geode.cache.RegionService; -import org.apache.geode.cache.RegionShortcut; -import org.apache.geode.cache.Scope; -import org.apache.geode.cache.SubscriptionAttributes; -import org.apache.geode.cache.asyncqueue.AsyncEventListener; -import org.apache.geode.cache.asyncqueue.AsyncEventQueue; -import org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory; -import org.apache.geode.cache.client.ClientCache; -import org.apache.geode.cache.client.ClientCacheFactory; -import org.apache.geode.cache.client.ClientRegionFactory; -import org.apache.geode.cache.client.ClientRegionShortcut; -import org.apache.geode.cache.client.Pool; -import org.apache.geode.cache.client.PoolFactory; -import org.apache.geode.cache.client.SocketFactory; -import org.apache.geode.cache.control.ResourceManager; -import org.apache.geode.cache.execute.RegionFunctionContext; -import org.apache.geode.cache.lucene.LuceneIndex; -import org.apache.geode.cache.lucene.LuceneIndexFactory; -import org.apache.geode.cache.lucene.LuceneQuery; -import org.apache.geode.cache.lucene.LuceneQueryFactory; -import org.apache.geode.cache.lucene.LuceneQueryProvider; -import org.apache.geode.cache.lucene.LuceneSerializer; -import org.apache.geode.cache.lucene.LuceneService; -import org.apache.geode.cache.query.CqAttributes; -import org.apache.geode.cache.query.CqQuery; -import org.apache.geode.cache.query.Index; -import org.apache.geode.cache.query.IndexStatistics; -import org.apache.geode.cache.query.Query; -import org.apache.geode.cache.query.QueryService; -import org.apache.geode.cache.query.QueryStatistics; -import org.apache.geode.cache.server.CacheServer; -import org.apache.geode.cache.server.ClientSubscriptionConfig; -import org.apache.geode.cache.wan.GatewayEventFilter; -import org.apache.geode.cache.wan.GatewayEventSubstitutionFilter; -import org.apache.geode.cache.wan.GatewayReceiver; -import org.apache.geode.cache.wan.GatewayReceiverFactory; -import org.apache.geode.cache.wan.GatewaySender; -import org.apache.geode.cache.wan.GatewaySenderFactory; -import org.apache.geode.cache.wan.GatewayTransportFilter; -import org.apache.geode.compression.Compressor; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.distributed.DistributedSystem; -import org.apache.geode.pdx.PdxSerializer; - -import org.apache.lucene.analysis.Analyzer; - -import org.springframework.data.gemfire.IndexType; -import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy; -import org.springframework.data.gemfire.test.mock.support.MockObjectInvocationException; -import org.springframework.data.gemfire.test.support.FileSystemUtils; -import org.springframework.util.Assert; - -/** - * The {@link GemFireMockObjectsSupport} class is an abstract base class encapsulating factory methods for creating - * Mock GemFire Objects (e.g. {@link Cache}, {@link ClientCache}, {@link Region}, etc). - * - * @author John Blum - * @see org.apache.geode.cache.Cache - * @see org.apache.geode.cache.CacheFactory - * @see org.apache.geode.cache.DiskStore - * @see org.apache.geode.cache.GemFireCache - * @see org.apache.geode.cache.Region - * @see org.apache.geode.cache.client.ClientCache - * @see org.apache.geode.cache.client.ClientCacheFactory - * @see org.apache.geode.cache.control.ResourceManager - * @see org.apache.geode.cache.server.CacheServer - * @see org.apache.geode.cache.server.ClientSubscriptionConfig - * @see org.apache.geode.distributed.DistributedSystem - * @see org.mockito.Mockito - * @see org.springframework.data.gemfire.test.mock.MockObjectsSupport - * @since 2.0.0 - */ -@SuppressWarnings("all") -public abstract class GemFireMockObjectsSupport extends MockObjectsSupport { - - private static final boolean DEFAULT_USE_SINGLETON_CACHE = false; - - private static final AtomicReference singletonCache = new AtomicReference<>(null); - - private static final Map diskStores = new ConcurrentHashMap<>(); - - private static final Map> regions = new ConcurrentHashMap<>(); - - private static final Map> regionAttributes = new ConcurrentHashMap<>(); - - private static final String FROM_KEYWORD = "FROM"; - private static final String WHERE_KEYWORD = "WHERE"; - - private static final String REPEATING_REGION_SEPARATOR = Region.SEPARATOR + "{2,}"; - - /** - * Destroys all mock object state. - */ - public static void destroy() { - singletonCache.set(null); - diskStores.clear(); - regions.clear(); - regionAttributes.clear(); - } - - /** - * Converts the given {@link ClientRegionShortcut} into a corresponding {@link DataPolicy}. - * - * @param clientRegionShortcut {@link ClientRegionShortcut} to convert. - * @return a {@link DataPolicy} from the {@link ClientRegionShortcut}. - * @see org.apache.geode.cache.client.ClientRegionShortcut - * @see org.apache.geode.cache.DataPolicy - */ - @SuppressWarnings("unchecked") - private static DataPolicy convert(ClientRegionShortcut clientRegionShortcut) { - - return Optional.ofNullable(clientRegionShortcut).map(shortcut -> { - - switch(shortcut) { - case CACHING_PROXY: - case CACHING_PROXY_HEAP_LRU: - case CACHING_PROXY_OVERFLOW: - case LOCAL: - case LOCAL_HEAP_LRU: - case LOCAL_OVERFLOW: - return DataPolicy.NORMAL; - case LOCAL_PERSISTENT: - case LOCAL_PERSISTENT_OVERFLOW: - return DataPolicy.PERSISTENT_REPLICATE; - case PROXY: - return DataPolicy.EMPTY; - default: - return null; - } - - }).orElse(DataPolicy.DEFAULT); - } - - /** - * Converts the given {@link RegionShortcut} into a corresponding {@link DataPolicy}. - * - * @param regionShortcut {@link RegionShortcut} to convert. - * @return a {@link DataPolicy} from the {@link RegionShortcut}. - * @see org.apache.geode.cache.RegionShortcut - * @see org.apache.geode.cache.DataPolicy - */ - @SuppressWarnings("unchecked") - private static DataPolicy convert(RegionShortcut regionShortcut) { - - return Optional.ofNullable(regionShortcut).map(shortcut -> { - - switch (shortcut) { - case LOCAL: - case LOCAL_HEAP_LRU: - case LOCAL_OVERFLOW: - return DataPolicy.NORMAL; - case PARTITION: - case PARTITION_HEAP_LRU: - case PARTITION_OVERFLOW: - case PARTITION_PROXY: - case PARTITION_PROXY_REDUNDANT: - case PARTITION_REDUNDANT: - case PARTITION_REDUNDANT_HEAP_LRU: - case PARTITION_REDUNDANT_OVERFLOW: - return DataPolicy.PARTITION; - case PARTITION_PERSISTENT: - case PARTITION_PERSISTENT_OVERFLOW: - case PARTITION_REDUNDANT_PERSISTENT: - case PARTITION_REDUNDANT_PERSISTENT_OVERFLOW: - return DataPolicy.PERSISTENT_PARTITION; - case REPLICATE: - case REPLICATE_HEAP_LRU: - case REPLICATE_OVERFLOW: - return DataPolicy.REPLICATE; - case LOCAL_PERSISTENT: - case LOCAL_PERSISTENT_OVERFLOW: - case REPLICATE_PERSISTENT: - case REPLICATE_PERSISTENT_OVERFLOW: - return DataPolicy.PERSISTENT_REPLICATE; - case REPLICATE_PROXY: - return DataPolicy.EMPTY; - default: - return null; - } - - }).orElse(DataPolicy.DEFAULT); - } - - /** - * Executes the given {@link IoExceptionThrowingOperation}, handling any {@link IOException IOExceptions} thrown - * during normal IO processing. - * - * @param operation {@link IoExceptionThrowingOperation} to execute. - * @return a boolean indicating whether the IO operation was successful, or {@literal false} if the IO operation - * threw an {@link IOException}. - * @see IOException - */ - private static boolean doSafeIo(IoExceptionThrowingOperation operation) { - - try { - operation.doIo(); - return true; - } - catch (IOException cause) { - return false; - } - } - - private static T doSafeOperation(ExceptionThrowingOperation operation) { - return doSafeOperation(operation, null); - } - - private static T doSafeOperation(ExceptionThrowingOperation operation, T defaultValue) { - - try { - return operation.doExceptionThrowingOperation(); - } - catch (Exception ignore) { - return defaultValue; - } - } - - /** - * Determines whether the given {@link Region} is a root {@link Region}. - * - * @param region {@link Region} to evaluate. - * @return a boolean value indicating whether the {@link Region} is a root {@link Region}. - * @see org.apache.geode.cache.Region - * @see #isRootRegion(String) - */ - private static boolean isRootRegion(Region region) { - return isRootRegion(region.getFullPath()); - } - - /** - * Determines whether the {@link Region} identified by the given {@link String path} is a root {@link Region}. - * - * @param regionPath {@link String path} identifying the {@link Region} to evaluate. - * @return a boolean value indicating whether the {@link Region} identified by the given {@link String path} - * is a root {@link Region}. - */ - private static boolean isRootRegion(String regionPath) { - return regionPath.lastIndexOf(Region.SEPARATOR) <= 0; - } - - /** - * Normalizes the given {@link Region#getFullPath() Regon path} by removing all duplicate, repeating - * {@link Region#SEPARATOR} characters between path segments as well as removing the trailing - * {@link Region#SEPARATOR}. - * - * @param regionPath {@link Region#getFullPath()} to normalize. - * @return a normalized version of the given {@link Region#getFullPath()}. - */ - private static String normalizeRegionPath(String regionPath) { - - regionPath = regionPath.replaceAll(REPEATING_REGION_SEPARATOR, Region.SEPARATOR); - - regionPath = regionPath.endsWith(Region.SEPARATOR) - ? regionPath.substring(0, regionPath.length() - 1) - : regionPath; - - return regionPath; - } - - /** - * Remembers the given mock {@link GemFireCache} object, which may be a {@link ClientCache} or a peer {@link Cache}. - * - * @param {@link Class sub-type} of the {@link GemFireCache} instance. - * @param mockedGemFireCache {@link GemFireCache} to remember. - * @param useSingletonCache boolean value indicating whether the {@link GemFireCache} is a Singleton. - * @return the given {@link GemFireCache}. - * @throws IllegalArgumentException if {@link GemFireCache} is {@literal null}. - * @see org.apache.geode.cache.GemFireCache - */ - private static T rememberMockedGemFireCache(T mockedGemFireCache, - boolean useSingletonCache) { - - return Optional.ofNullable(mockedGemFireCache) - .map(it -> { - - if (useSingletonCache) { - singletonCache.compareAndSet(null, it); - } - - return it; - }) - .orElseThrow(() -> newIllegalArgumentException("GemFireCache is required")); - } - - /** - * Remembers the given mock {@link Region}. - * - * @param {@link Class type} of the {@link Region} key. - * @param {@link Class type} of the {@link Region} value. - * @param mockRegion {@link Region} to remember. - * @throws IllegalArgumentException if the given {@link Region} is {@literal null}. - * @throws RegionExistsException if the given {@link Region} already exists. - * @return the given {@link Region}. - * @see org.apache.geode.cache.Region - */ - @SuppressWarnings("unchecked") - private static Region rememberMockedRegion(Region mockRegion) { - - String mockRegionPath = Optional.ofNullable(mockRegion).map(Region::getFullPath) - .orElseThrow(() -> newIllegalArgumentException("Region is required")); - - if (regions.putIfAbsent(mockRegionPath, (Region) mockRegion) != null) { - throw new RegionExistsException(mockRegion); - } - - assertThat(regions).containsValue((Region) mockRegion); - - return mockRegion; - } - - /** - * Resolves the single, remembered {@link GemFireCache} if using GemFire in Singleton-mode. - * - * @param {@link Class sub-type} of the {@link GemFireCache} instance. - * @param useSingletonCache boolean value indicating if mock infrastructure is using GemFire Singletons. - * @return an {@link Optional}, single remembered instance of the {@link GemFireCache}. - * @see org.apache.geode.cache.GemFireCache - */ - @SuppressWarnings("unchecked") - private static Optional resolveMockedGemFireCache(boolean useSingletonCache) { - return Optional.ofNullable((T) singletonCache.get()).filter(it -> useSingletonCache); - } - - /** - * Resolves the {@link RegionAttributes} identified by the given {@link String id}. - * - * @param {@link Class type} of the {@link Region} key. - * @param {@link Class type} of the {@link Region} value. - * @param regionAttributesId {@link String id} identifying the {@link RegionAttributes} to resolve. - * @return the resolved {@link RegionAttributes} identified by the given {@link String id}. - * @throws IllegalStateException if {@link RegionAttributes} could not be resolved from the given {@link String id}. - * @see org.apache.geode.cache.RegionAttributes - */ - @SuppressWarnings("unchecked") - private static RegionAttributes resolveRegionAttributes(String regionAttributesId) { - - return (RegionAttributes) Optional.ofNullable(regionAttributes.get(regionAttributesId)).orElseThrow(() -> - newIllegalStateException("RegionAttributes with ID [%s] cannot be found", regionAttributesId)); - } - - private static T rethrowAsRuntimeException(ExceptionThrowingOperation operation) { - - try { - return operation.doExceptionThrowingOperation(); - } - catch (RuntimeException cause) { - throw cause; - } - catch (Exception cause) { - throw new RuntimeException(cause); - } - } - - /** - * Converts the given {@link String Region name} into a proper {@link Region#getName() Region name}. - * - * @param regionName {@link String Region name} to evaluate. - * @return a proper {@link Region#getName() Region name} from the given {@link String Region name}. - * @throws IllegalArgumentException if {@link String Region name} is {@literal null} - * or {@link String#isEmpty() empty}. - * @see String - */ - private static String toRegionName(String regionName) { - - return Optional.ofNullable(regionName) - .map(String::trim) - .map(it -> { - int lastIndexOfRegionSeparator = it.lastIndexOf(Region.SEPARATOR); - return lastIndexOfRegionSeparator < 0 ? it : it.substring(lastIndexOfRegionSeparator); - }) - .filter(it -> !it.isEmpty()) - .orElseThrow(() -> newIllegalArgumentException("Region name [%s] is required", regionName)); - } - - /** - * Converts the given {@link String Region path} into a proper {@link Region#getFullPath() Region path}. - * - * @param regionPath {@link String Region path} to evaluate. - * @return a proper {@link Region#getFullPath() Region path} from the given {@link String Region path}. - * @throws IllegalArgumentException if {@link String Region path} is {@literal null} - * or {@link String#isEmpty() empty}. - * @see String - */ - private static String toRegionPath(String regionPath) { - - return Optional.ofNullable(regionPath) - .map(String::trim) - .map(it -> it.startsWith(Region.SEPARATOR) ? it : String.format("%1$s%2$s", Region.SEPARATOR, it)) - .map(GemFireMockObjectsSupport::normalizeRegionPath) - .filter(it -> !it.isEmpty()) - .orElseThrow(() -> newIllegalArgumentException("Region path [%s] is required", regionPath)); - } - - /* (non-Javadoc) */ - @SuppressWarnings("unchecked") - private static T mockCacheApi(T mockGemFireCache) { - - AtomicBoolean copyOnRead = new AtomicBoolean(false); - - DistributedSystem mockDistributedSystem = mockDistributedSystem(); - - ResourceManager mockResourceManager = mockResourceManager(); - - doAnswer(newSetter(copyOnRead, null)).when(mockGemFireCache).setCopyOnRead(anyBoolean()); - - doAnswer(newSetter(regionAttributes, null)) - .when(mockGemFireCache).setRegionAttributes(anyString(), any(RegionAttributes.class)); - - when(mockGemFireCache.getCopyOnRead()).thenAnswer(newGetter(copyOnRead)); - - when(mockGemFireCache.getDistributedSystem()).thenReturn(mockDistributedSystem); - - when(mockGemFireCache.getRegionAttributes(anyString())) - .thenAnswer(invocation -> regionAttributes.get(invocation.getArgument(0))); - - when(mockGemFireCache.getResourceManager()).thenReturn(mockResourceManager); - - when(mockGemFireCache.createDiskStoreFactory()).thenAnswer(invocation -> mockDiskStoreFactory()); - - when(mockGemFireCache.findDiskStore(anyString())) - .thenAnswer(invocation -> diskStores.get(invocation.getArgument(0))); - - when(mockGemFireCache.listRegionAttributes()).thenReturn(Collections.unmodifiableMap(regionAttributes)); - - doThrow(newUnsupportedOperationException(NOT_SUPPORTED)) - .when(mockGemFireCache).loadCacheXml(any(InputStream.class)); - - return mockRegionServiceApi(mockGemFireCache); - } - - /* (non-Javadoc) */ - private static T mockRegionServiceApi(T mockRegionService) { - - AtomicBoolean closed = new AtomicBoolean(false); - - doAnswer(newSetter(closed, true, null)).when(mockRegionService).close(); - - when(mockRegionService.isClosed()).thenAnswer(newGetter(closed)); - - when(mockRegionService.getCancelCriterion()).thenThrow(newUnsupportedOperationException(NOT_SUPPORTED)); - - when(mockRegionService.getRegion(anyString())).thenAnswer(invocation -> { - - String regionPath = invocation.getArgument(0); - - String resolvedRegionPath = Optional.ofNullable(regionPath) - .map(String::trim) - .filter(it -> !it.isEmpty()) - .map(GemFireMockObjectsSupport::toRegionPath) - .orElseThrow(() -> newIllegalArgumentException("Region path [%s] is not valid", regionPath)); - - return regions.get(resolvedRegionPath); - }); - - when(mockRegionService.createPdxEnum(anyString(), anyString(), anyInt())) - .thenThrow(newUnsupportedOperationException(NOT_SUPPORTED)); - - when(mockRegionService.createPdxInstanceFactory(anyString())) - .thenThrow(newUnsupportedOperationException(NOT_SUPPORTED)); - - when(mockRegionService.rootRegions()).thenAnswer(invocation -> - regions.values().stream().filter(GemFireMockObjectsSupport::isRootRegion).collect(Collectors.toSet())); - - return mockRegionService; - } - - public static ClientCache mockClientCache() { - - ClientCache mockClientCache = mock(ClientCache.class); - - doAnswer(newVoidAnswer(invocation -> mockClientCache.close())).when(mockClientCache).close(anyBoolean()); - - when(mockClientCache.createClientRegionFactory(any(ClientRegionShortcut.class))).thenAnswer(invocation -> - mockClientRegionFactory(mockClientCache, invocation.getArgument(0))); - - when(mockClientCache.createClientRegionFactory(anyString())).thenAnswer(invocation -> - mockClientRegionFactory(mockClientCache, invocation.getArgument(0))); - - return mockQueryService(mockCacheApi(mockClientCache)); - } - - public static GemFireCache mockGemFireCache() { - - GemFireCache mockGemFireCache = mock(GemFireCache.class); - - return mockQueryService(mockCacheApi(mockGemFireCache)); - } - - @SuppressWarnings("unchecked") - public static Cache mockPeerCache() { - - Cache mockCache = mock(Cache.class); - - AtomicInteger lockLease = new AtomicInteger(); - AtomicInteger lockTimeout = new AtomicInteger(); - AtomicInteger messageSyncInterval = new AtomicInteger(); - AtomicInteger searchTimeout = new AtomicInteger(); - - List cacheServers = new ArrayList<>(); - - when(mockCache.addCacheServer()).thenAnswer(invocation -> { - - CacheServer mockCacheServer = mockCacheServer(); - - cacheServers.add(mockCacheServer); - - return mockCacheServer; - }); - - doAnswer(newSetter(lockLease, null)).when(mockCache).setLockLease(anyInt()); - doAnswer(newSetter(lockTimeout, null)).when(mockCache).setLockTimeout(anyInt()); - doAnswer(newSetter(messageSyncInterval, null)).when(mockCache).setMessageSyncInterval(anyInt()); - doAnswer(newSetter(searchTimeout, null)).when(mockCache).setSearchTimeout(anyInt()); - - when(mockCache.isServer()).thenReturn(true); - when(mockCache.getCacheServers()).thenAnswer(invocation -> Collections.unmodifiableList(cacheServers)); - when(mockCache.getLockLease()).thenAnswer(newGetter(lockLease)); - when(mockCache.getLockTimeout()).thenAnswer(newGetter(lockTimeout)); - when(mockCache.getMessageSyncInterval()).thenAnswer(newGetter(messageSyncInterval)); - when(mockCache.getReconnectedCache()).thenAnswer(invocation -> mockPeerCache()); - when(mockCache.getSearchTimeout()).thenAnswer(newGetter(searchTimeout)); - - when(mockCache.createRegionFactory()).thenAnswer(invocation -> mockRegionFactory(mockCache)); - - when(mockCache.createRegionFactory(any(RegionAttributes.class))).thenAnswer(invocation -> - mockRegionFactory(mockCache, invocation.>getArgument(0))); - - when(mockCache.createRegionFactory(any(RegionShortcut.class))).thenAnswer(invocation -> - mockRegionFactory(mockCache, invocation.getArgument(0))); - - when(mockCache.createRegionFactory(anyString())).thenAnswer(invocation -> - mockRegionFactory(mockCache, invocation.getArgument(0))); - - return mockQueryService( - mockGatewaySenderFactory( - mockGatewayReceiverFactory( - mockAsyncEventQueueFactory( - mockCacheApi(mockCache))))); - } - - public static Cache mockAsyncEventQueueFactory(Cache mockCache) { - - when(mockCache.createAsyncEventQueueFactory()).thenAnswer(invocation -> mockAsyncEventQueueFactory()); - - return mockCache; - } - - public static AsyncEventQueueFactory mockAsyncEventQueueFactory() { - - AsyncEventQueueFactory mockAsyncEventQueueFactory = mock(AsyncEventQueueFactory.class); - - AtomicBoolean batchConflationEnabled = new AtomicBoolean(false); - AtomicBoolean diskSynchronous = new AtomicBoolean(true); - AtomicBoolean forwardExpirationDestroy = new AtomicBoolean(false); - AtomicBoolean parallel = new AtomicBoolean(false); - AtomicBoolean pauseEventDispatching = new AtomicBoolean(false); - AtomicBoolean persistent = new AtomicBoolean(false); - - AtomicInteger batchSize = new AtomicInteger(100); - AtomicInteger batchTimeInterval = new AtomicInteger(5); - AtomicInteger dispatcherThreads = new AtomicInteger(5); - AtomicInteger maximumQueueMemory = new AtomicInteger(100); - - AtomicReference diskStoreName = new AtomicReference<>(null); - AtomicReference gatewayEventSubstitutionFilter = - new AtomicReference<>(null); - AtomicReference orderPolicy = new AtomicReference<>(GatewaySender.OrderPolicy.KEY); - - CopyOnWriteArrayList gatewayEventFilters = new CopyOnWriteArrayList<>(); - - when(mockAsyncEventQueueFactory.setBatchConflationEnabled(anyBoolean())) - .thenAnswer(newSetter(batchConflationEnabled, mockAsyncEventQueueFactory)); - - when(mockAsyncEventQueueFactory.setBatchSize(anyInt())) - .thenAnswer(newSetter(batchSize, mockAsyncEventQueueFactory)); - - when(mockAsyncEventQueueFactory.setBatchTimeInterval(anyInt())) - .thenAnswer(newSetter(batchTimeInterval, mockAsyncEventQueueFactory)); - - when(mockAsyncEventQueueFactory.setDiskStoreName(anyString())) - .thenAnswer(newSetter(diskStoreName, mockAsyncEventQueueFactory)); - - when(mockAsyncEventQueueFactory.setDiskSynchronous(anyBoolean())) - .thenAnswer(newSetter(diskSynchronous, mockAsyncEventQueueFactory)); - - when(mockAsyncEventQueueFactory.setDispatcherThreads(anyInt())) - .thenAnswer(newSetter(dispatcherThreads, mockAsyncEventQueueFactory)); - - when(mockAsyncEventQueueFactory.setForwardExpirationDestroy(anyBoolean())) - .thenAnswer(newSetter(forwardExpirationDestroy, mockAsyncEventQueueFactory)); - - when(mockAsyncEventQueueFactory.setGatewayEventSubstitutionListener(any(GatewayEventSubstitutionFilter.class))) - .thenAnswer(newSetter(gatewayEventSubstitutionFilter, mockAsyncEventQueueFactory)); - - when(mockAsyncEventQueueFactory.setMaximumQueueMemory(anyInt())) - .thenAnswer(newSetter(maximumQueueMemory, mockAsyncEventQueueFactory)); - - when(mockAsyncEventQueueFactory.setOrderPolicy(any(GatewaySender.OrderPolicy.class))) - .thenAnswer(newSetter(orderPolicy, mockAsyncEventQueueFactory)); - - when(mockAsyncEventQueueFactory.setParallel(anyBoolean())) - .thenAnswer(newSetter(parallel, mockAsyncEventQueueFactory)); - - when(mockAsyncEventQueueFactory.setPersistent(anyBoolean())) - .thenAnswer(newSetter(persistent, mockAsyncEventQueueFactory)); - - when(mockAsyncEventQueueFactory.addGatewayEventFilter(any(GatewayEventFilter.class))).thenAnswer(invocation -> { - - gatewayEventFilters.add(invocation.getArgument(0)); - - return mockAsyncEventQueueFactory; - }); - - doAnswer(newSetter(pauseEventDispatching, true, mockAsyncEventQueueFactory)) - .when(mockAsyncEventQueueFactory).pauseEventDispatching(); - - when(mockAsyncEventQueueFactory.removeGatewayEventFilter(any(GatewayEventFilter.class))).thenAnswer(invocation -> { - - gatewayEventFilters.remove(invocation.getArgument(0)); - - return mockAsyncEventQueueFactory; - }); - - when(mockAsyncEventQueueFactory.create(anyString(), any(AsyncEventListener.class))).thenAnswer(invocation -> { - - String asyncEventQueueId = invocation.getArgument(0); - - AsyncEventListener listener = invocation.getArgument(1); - - AsyncEventQueue mockAsyncEventQueue = mock(AsyncEventQueue.class); - - when(mockAsyncEventQueue.isBatchConflationEnabled()).thenAnswer(newGetter(batchConflationEnabled)); - when(mockAsyncEventQueue.isDiskSynchronous()).thenAnswer(newGetter(diskSynchronous)); - when(mockAsyncEventQueue.isDispatchingPaused()).thenAnswer(newGetter(pauseEventDispatching)); - when(mockAsyncEventQueue.isForwardExpirationDestroy()).thenAnswer(newGetter(forwardExpirationDestroy)); - when(mockAsyncEventQueue.isParallel()).thenAnswer(newGetter(parallel)); - when(mockAsyncEventQueue.isPersistent()).thenAnswer(newGetter(persistent)); - when(mockAsyncEventQueue.isPrimary()).thenReturn(false); - - when(mockAsyncEventQueue.getAsyncEventListener()).thenReturn(listener); - when(mockAsyncEventQueue.getBatchSize()).thenAnswer(newGetter(batchSize)); - when(mockAsyncEventQueue.getBatchTimeInterval()).thenAnswer(newGetter(batchTimeInterval)); - when(mockAsyncEventQueue.getDiskStoreName()).thenAnswer(newGetter(diskStoreName)); - when(mockAsyncEventQueue.getDispatcherThreads()).thenAnswer(newGetter(dispatcherThreads)); - when(mockAsyncEventQueue.getGatewayEventFilters()).thenReturn(gatewayEventFilters); - when(mockAsyncEventQueue.getGatewayEventSubstitutionFilter()).thenAnswer(newGetter(gatewayEventSubstitutionFilter)); - when(mockAsyncEventQueue.getId()).thenReturn(asyncEventQueueId); - when(mockAsyncEventQueue.getMaximumQueueMemory()).thenAnswer(newGetter(maximumQueueMemory)); - when(mockAsyncEventQueue.getOrderPolicy()).thenAnswer(newGetter(orderPolicy)); - - doAnswer(resumeEventDispatchingInvocation -> { - pauseEventDispatching.set(false); - return null; - }).when(mockAsyncEventQueue).resumeEventDispatching(); - - when(mockAsyncEventQueue.size()).thenReturn(0); - - return mockAsyncEventQueue; - }); - - return mockAsyncEventQueueFactory; - } - - public static CacheServer mockCacheServer() { - - CacheServer mockCacheServer = mock(CacheServer.class); - - AtomicBoolean running = new AtomicBoolean(false); - AtomicBoolean tcpNoDelay = new AtomicBoolean(CacheServer.DEFAULT_TCP_NO_DELAY); - - AtomicInteger maxConnections = new AtomicInteger(CacheServer.DEFAULT_MAX_CONNECTIONS); - AtomicInteger maxMessageCount = new AtomicInteger(CacheServer.DEFAULT_MAXIMUM_MESSAGE_COUNT); - AtomicInteger maxThreads = new AtomicInteger(CacheServer.DEFAULT_MAX_THREADS); - AtomicInteger maxTimeBetweenPings = new AtomicInteger(CacheServer.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS); - AtomicInteger messageTimeToLive = new AtomicInteger(CacheServer.DEFAULT_MESSAGE_TIME_TO_LIVE); - AtomicInteger port = new AtomicInteger(CacheServer.DEFAULT_PORT); - AtomicInteger socketBufferSize = new AtomicInteger(CacheServer.DEFAULT_SOCKET_BUFFER_SIZE); - - AtomicLong loadPollInterval = new AtomicLong(CacheServer.DEFAULT_LOAD_POLL_INTERVAL); - - AtomicReference bindAddress = new AtomicReference<>(CacheServer.DEFAULT_BIND_ADDRESS); - AtomicReference hostnameForClients = new AtomicReference<>(CacheServer.DEFAULT_HOSTNAME_FOR_CLIENTS); - - doAnswer(newSetter(bindAddress, null)) - .when(mockCacheServer).setBindAddress(anyString()); - - doAnswer(newSetter(hostnameForClients, null)) - .when(mockCacheServer).setHostnameForClients(anyString()); - - doAnswer(newSetter(loadPollInterval, null)) - .when(mockCacheServer).setLoadPollInterval(anyLong()); - - doAnswer(newSetter(maxConnections, null)) - .when(mockCacheServer).setMaxConnections(anyInt()); - - doAnswer(newSetter(maxMessageCount, null)) - .when(mockCacheServer).setMaximumMessageCount(anyInt()); - - doAnswer(newSetter(maxThreads, null)) - .when(mockCacheServer).setMaxThreads(anyInt()); - - doAnswer(newSetter(maxTimeBetweenPings, null)) - .when(mockCacheServer).setMaximumTimeBetweenPings(anyInt()); - - doAnswer(newSetter(messageTimeToLive, null)) - .when(mockCacheServer).setMessageTimeToLive(anyInt()); - - doAnswer(newSetter(port, null)) - .when(mockCacheServer).setPort(anyInt()); - - doAnswer(newSetter(socketBufferSize, null)) - .when(mockCacheServer).setSocketBufferSize(anyInt()); - - doAnswer(newSetter(tcpNoDelay, null)) - .when(mockCacheServer).setTcpNoDelay(anyBoolean()); - - when(mockCacheServer.isRunning()).thenAnswer(newGetter(running)); - when(mockCacheServer.getAllClientSessions()).thenReturn(Collections.emptySet()); - when(mockCacheServer.getBindAddress()).thenAnswer(newGetter(bindAddress)); - when(mockCacheServer.getClientSession(any(DistributedMember.class))) - .thenThrow(newUnsupportedOperationException(NOT_SUPPORTED)); - when(mockCacheServer.getClientSession(anyString())).thenThrow(newUnsupportedOperationException(NOT_SUPPORTED)); - when(mockCacheServer.getHostnameForClients()).thenAnswer(newGetter(hostnameForClients)); - when(mockCacheServer.getInterestRegistrationListeners()).thenReturn(Collections.emptySet()); - when(mockCacheServer.getLoadPollInterval()).thenAnswer(newGetter(loadPollInterval)); - when(mockCacheServer.getLoadProbe()).thenThrow(newUnsupportedOperationException(NOT_SUPPORTED)); - when(mockCacheServer.getMaxConnections()).thenAnswer(newGetter(maxConnections)); - when(mockCacheServer.getMaximumMessageCount()).thenAnswer(newGetter(maxMessageCount)); - when(mockCacheServer.getMaximumTimeBetweenPings()).thenAnswer(newGetter(maxTimeBetweenPings)); - when(mockCacheServer.getMaxThreads()).thenAnswer(newGetter(maxThreads)); - when(mockCacheServer.getMessageTimeToLive()).thenAnswer(newGetter(messageTimeToLive)); - when(mockCacheServer.getPort()).thenAnswer(newGetter(port)); - when(mockCacheServer.getSocketBufferSize()).thenAnswer(newGetter(socketBufferSize)); - when(mockCacheServer.getTcpNoDelay()).thenAnswer(newGetter(tcpNoDelay)); - - ClientSubscriptionConfig mockClientSubscriptionConfig = mockClientSubscriptionConfig(); - - when(mockCacheServer.getClientSubscriptionConfig()).thenReturn(mockClientSubscriptionConfig); - - doSafeIo(() -> doAnswer(newSetter(running, true, null)).when(mockCacheServer).start()); - doAnswer(newSetter(running, false, null)).when(mockCacheServer).stop(); - - return mockCacheServer; - } - - public static ClientRegionFactory mockClientRegionFactory(ClientCache mockClientCache, - ClientRegionShortcut clientRegionShortcut) { - - return mockClientRegionFactory(mockClientCache, clientRegionShortcut, null); - } - - public static ClientRegionFactory mockClientRegionFactory(ClientCache mockClientCache, - String regionAttributesId) { - - return mockClientRegionFactory(mockClientCache, null, - resolveRegionAttributes(regionAttributesId)); - } - - @SuppressWarnings("unchecked") - public static ClientRegionFactory mockClientRegionFactory(ClientCache mockClientCache, - ClientRegionShortcut clientRegionShortcut, RegionAttributes regionAttributes) { - - ClientRegionFactory mockClientRegionFactory = - mock(ClientRegionFactory.class, mockObjectIdentifier("MockClientRegionFactory")); - - ExpirationAttributes DEFAULT_EXPIRATION_ATTRIBUTES = - new ExpirationAttributes(0, ExpirationAction.INVALIDATE); - - Optional> optionalRegionAttributes = Optional.ofNullable(regionAttributes); - - AtomicBoolean cloningEnabled = new AtomicBoolean(optionalRegionAttributes - .map(RegionAttributes::getCloningEnabled).orElse(false)); - - AtomicBoolean concurrencyChecksEnabled = new AtomicBoolean(optionalRegionAttributes - .map(RegionAttributes::getConcurrencyChecksEnabled).orElse(false)); - - AtomicBoolean diskSynchronous = new AtomicBoolean(optionalRegionAttributes - .map(RegionAttributes::isDiskSynchronous).orElse(true)); - - AtomicBoolean statisticsEnabled = new AtomicBoolean(optionalRegionAttributes - .map(RegionAttributes::getStatisticsEnabled).orElse(false)); - - AtomicInteger concurrencyLevel = new AtomicInteger(optionalRegionAttributes - .map(RegionAttributes::getConcurrencyLevel).orElse(16)); - - AtomicInteger initialCapacity = new AtomicInteger(optionalRegionAttributes - .map(RegionAttributes::getInitialCapacity).orElse(16)); - - AtomicReference compressor = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getCompressor).orElse(null)); - - AtomicReference> customEntryIdleTimeout = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getCustomEntryIdleTimeout).orElse(null)); - - AtomicReference> customEntryTimeToLive = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getCustomEntryTimeToLive).orElse(null)); - - AtomicReference dataPolicy = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getDataPolicy).orElseGet(() -> convert(clientRegionShortcut))); - - AtomicReference diskStoreName = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getDiskStoreName).orElse(null)); - - AtomicReference entryIdleTimeout = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getEntryIdleTimeout).orElse(DEFAULT_EXPIRATION_ATTRIBUTES)); - - AtomicReference entryTimeToLive = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getEntryTimeToLive).orElse(DEFAULT_EXPIRATION_ATTRIBUTES)); - - AtomicReference evictionAttributes = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getEvictionAttributes).orElseGet(EvictionAttributes::createLRUEntryAttributes)); - - AtomicReference> keyConstraint = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getKeyConstraint).orElse(null)); - - AtomicReference loadFactor = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getLoadFactor).orElse(0.75f)); - - AtomicReference poolName = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getPoolName).orElse(null)); - - AtomicReference regionIdleTimeout = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getRegionIdleTimeout).orElse(DEFAULT_EXPIRATION_ATTRIBUTES)); - - AtomicReference regionTimeToLive = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getRegionTimeToLive).orElse(DEFAULT_EXPIRATION_ATTRIBUTES)); - - AtomicReference> valueConstraint = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getValueConstraint).orElse(null)); - - List cacheListeners = new ArrayList<>(Arrays.asList(nullSafeArray(optionalRegionAttributes - .map(RegionAttributes::getCacheListeners).orElse(null), CacheListener.class))); - - when(mockClientRegionFactory.addCacheListener(any(CacheListener.class))) - .thenAnswer(newAdder(cacheListeners, mockClientRegionFactory)); - - when(mockClientRegionFactory.initCacheListeners(any(CacheListener[].class))).thenAnswer(invocation -> { - cacheListeners.clear(); - Collections.addAll(cacheListeners, invocation.getArgument(0)); - return mockClientRegionFactory; - }); - - when(mockClientRegionFactory.setCloningEnabled(anyBoolean())) - .thenAnswer(newSetter(cloningEnabled, mockClientRegionFactory)); - - when(mockClientRegionFactory.setCompressor(any(Compressor.class))) - .thenAnswer(newSetter(compressor, mockClientRegionFactory)); - - doAnswer(newSetter(concurrencyChecksEnabled, mockClientRegionFactory)) - .when(mockClientRegionFactory).setConcurrencyChecksEnabled(anyBoolean()); - - when(mockClientRegionFactory.setConcurrencyLevel(anyInt())) - .thenAnswer(newSetter(concurrencyLevel, mockClientRegionFactory)); - - when(mockClientRegionFactory.setCustomEntryIdleTimeout(any(CustomExpiry.class))) - .thenAnswer(newSetter(customEntryIdleTimeout, mockClientRegionFactory)); - - when(mockClientRegionFactory.setCustomEntryTimeToLive(any(CustomExpiry.class))) - .thenAnswer(newSetter(customEntryTimeToLive, mockClientRegionFactory)); - - when(mockClientRegionFactory.setDiskStoreName(anyString())) - .thenAnswer(newSetter(diskStoreName, mockClientRegionFactory)); - - when(mockClientRegionFactory.setDiskSynchronous(anyBoolean())) - .thenAnswer(newSetter(diskSynchronous, mockClientRegionFactory)); - - when(mockClientRegionFactory.setEntryIdleTimeout(any(ExpirationAttributes.class))) - .thenAnswer(newSetter(entryIdleTimeout, mockClientRegionFactory)); - - when(mockClientRegionFactory.setEntryTimeToLive(any(ExpirationAttributes.class))) - .thenAnswer(newSetter(entryTimeToLive, mockClientRegionFactory)); - - when(mockClientRegionFactory.setEvictionAttributes(any(EvictionAttributes.class))) - .thenAnswer(newSetter(evictionAttributes, mockClientRegionFactory)); - - when(mockClientRegionFactory.setInitialCapacity(anyInt())) - .thenAnswer(newSetter(initialCapacity, mockClientRegionFactory)); - - when(mockClientRegionFactory.setKeyConstraint(any(Class.class))) - .thenAnswer(newSetter(keyConstraint, mockClientRegionFactory)); - - when(mockClientRegionFactory.setLoadFactor(anyFloat())) - .thenAnswer(newSetter(loadFactor, mockClientRegionFactory)); - - when(mockClientRegionFactory.setPoolName(anyString())) - .thenAnswer(newSetter(poolName, mockClientRegionFactory)); - - when(mockClientRegionFactory.setRegionIdleTimeout(any(ExpirationAttributes.class))) - .thenAnswer(newSetter(regionIdleTimeout, mockClientRegionFactory)); - - when(mockClientRegionFactory.setRegionTimeToLive(any(ExpirationAttributes.class))) - .thenAnswer(newSetter(regionTimeToLive, mockClientRegionFactory)); - - when(mockClientRegionFactory.setStatisticsEnabled(anyBoolean())) - .thenAnswer(newSetter(statisticsEnabled, mockClientRegionFactory)); - - when(mockClientRegionFactory.setValueConstraint(any(Class.class))) - .thenAnswer(newSetter(valueConstraint, mockClientRegionFactory)); - - RegionAttributes mockRegionAttributes = - mock(RegionAttributes.class, mockObjectIdentifier("MockRegionAttributes")); - - when(mockRegionAttributes.getCacheListeners()) - .thenAnswer(newGetter(() -> cacheListeners.toArray(new CacheListener[cacheListeners.size()]))); - - when(mockRegionAttributes.getCloningEnabled()).thenAnswer(newGetter(cloningEnabled)); - when(mockRegionAttributes.getCompressor()).thenAnswer(newGetter(compressor)); - when(mockRegionAttributes.getConcurrencyChecksEnabled()).thenAnswer(newGetter(concurrencyChecksEnabled)); - when(mockRegionAttributes.getConcurrencyLevel()).thenAnswer(newGetter(concurrencyLevel)); - when(mockRegionAttributes.getCustomEntryIdleTimeout()).thenAnswer(newGetter(customEntryIdleTimeout)); - when(mockRegionAttributes.getCustomEntryTimeToLive()).thenAnswer(newGetter(customEntryTimeToLive)); - when(mockRegionAttributes.getDataPolicy()).thenAnswer(newGetter(dataPolicy)); - when(mockRegionAttributes.getDiskStoreName()).thenAnswer(newGetter(diskStoreName)); - when(mockRegionAttributes.isDiskSynchronous()).thenAnswer(newGetter(diskSynchronous)); - when(mockRegionAttributes.getEntryIdleTimeout()).thenAnswer(newGetter(entryIdleTimeout)); - when(mockRegionAttributes.getEntryTimeToLive()).thenAnswer(newGetter(entryTimeToLive)); - when(mockRegionAttributes.getEvictionAttributes()).thenAnswer(newGetter(evictionAttributes)); - when(mockRegionAttributes.getInitialCapacity()).thenAnswer(newGetter(initialCapacity)); - when(mockRegionAttributes.getKeyConstraint()).thenAnswer(newGetter(keyConstraint)); - when(mockRegionAttributes.getLoadFactor()).thenAnswer(newGetter(loadFactor)); - when(mockRegionAttributes.getPoolName()).thenAnswer(newGetter(poolName)); - when(mockRegionAttributes.getRegionIdleTimeout()).thenAnswer(newGetter(regionIdleTimeout)); - when(mockRegionAttributes.getRegionTimeToLive()).thenAnswer(newGetter(regionTimeToLive)); - when(mockRegionAttributes.getStatisticsEnabled()).thenAnswer(newGetter(statisticsEnabled)); - when(mockRegionAttributes.getValueConstraint()).thenAnswer(newGetter(valueConstraint)); - - when(mockClientRegionFactory.create(anyString())).thenAnswer(invocation -> - mockRegion(mockClientCache, invocation.getArgument(0), mockRegionAttributes)); - - when(mockClientRegionFactory.createSubregion(any(Region.class), anyString())).thenAnswer(invocation -> - mockSubRegion(invocation.getArgument(0), invocation.getArgument(1), mockRegionAttributes)); - - return mockClientRegionFactory; - } - - public static ClientSubscriptionConfig mockClientSubscriptionConfig() { - - ClientSubscriptionConfig mockClientSubscriptionConfig = mock(ClientSubscriptionConfig.class); - - AtomicInteger subscriptionCapacity = new AtomicInteger(ClientSubscriptionConfig.DEFAULT_CAPACITY); - - AtomicReference subscriptionDiskStoreName = new AtomicReference<>(""); - - AtomicReference subscriptionEvictionPolicy = - new AtomicReference<>(SubscriptionEvictionPolicy.DEFAULT); - - Function stringToSubscriptionEvictionPolicyConverter = - arg -> SubscriptionEvictionPolicy.valueOfIgnoreCase(String.valueOf(arg)); - - Function subscriptionEvictionPolicyToStringConverter = - arg -> Optional.ofNullable(arg).map(Object::toString).map(String::toLowerCase).orElse(null); - - doAnswer(newSetter(subscriptionCapacity, null)) - .when(mockClientSubscriptionConfig).setCapacity(anyInt()); - - doAnswer(newSetter(subscriptionDiskStoreName, null)) - .when(mockClientSubscriptionConfig).setDiskStoreName(anyString()); - - doAnswer(newSetter(subscriptionEvictionPolicy, stringToSubscriptionEvictionPolicyConverter, null)) - .when(mockClientSubscriptionConfig).setEvictionPolicy(anyString()); - - when(mockClientSubscriptionConfig.getCapacity()).thenAnswer(newGetter(subscriptionCapacity)); - when(mockClientSubscriptionConfig.getDiskStoreName()).thenAnswer(newGetter(subscriptionDiskStoreName)); - when(mockClientSubscriptionConfig.getEvictionPolicy()).thenAnswer(newGetter(subscriptionEvictionPolicy, - subscriptionEvictionPolicyToStringConverter)); - - return mockClientSubscriptionConfig; - } - - public static DiskStoreFactory mockDiskStoreFactory() { - - DiskStoreFactory mockDiskStoreFactory = mock(DiskStoreFactory.class); - - AtomicBoolean allowForceCompaction = new AtomicBoolean(DiskStoreFactory.DEFAULT_ALLOW_FORCE_COMPACTION); - AtomicBoolean autoCompact = new AtomicBoolean(DiskStoreFactory.DEFAULT_AUTO_COMPACT); - - AtomicInteger compactionThreshold = new AtomicInteger(DiskStoreFactory.DEFAULT_COMPACTION_THRESHOLD); - AtomicInteger queueSize = new AtomicInteger(DiskStoreFactory.DEFAULT_QUEUE_SIZE); - AtomicInteger writeBufferSize = new AtomicInteger(DiskStoreFactory.DEFAULT_WRITE_BUFFER_SIZE); - - AtomicLong maxOplogSize = new AtomicLong(DiskStoreFactory.DEFAULT_MAX_OPLOG_SIZE); - AtomicLong timeInterval = new AtomicLong(DiskStoreFactory.DEFAULT_TIME_INTERVAL); - - AtomicReference diskDirectories = - new AtomicReference<>(new File[] { FileSystemUtils.WORKING_DIRECTORY }); - - AtomicReference diskDiretorySizes = new AtomicReference<>(new int[0]); - - AtomicReference diskUsageCriticalPercentage = - new AtomicReference<>(DiskStoreFactory.DEFAULT_DISK_USAGE_CRITICAL_PERCENTAGE); - - AtomicReference diskUsageWarningPercentage = - new AtomicReference<>(DiskStoreFactory.DEFAULT_DISK_USAGE_WARNING_PERCENTAGE); - - when(mockDiskStoreFactory.setAllowForceCompaction(anyBoolean())) - .thenAnswer(newSetter(allowForceCompaction, mockDiskStoreFactory)); - - when(mockDiskStoreFactory.setAutoCompact(anyBoolean())) - .thenAnswer(newSetter(autoCompact, mockDiskStoreFactory)); - - when(mockDiskStoreFactory.setCompactionThreshold(anyInt())) - .thenAnswer(newSetter(compactionThreshold, mockDiskStoreFactory)); - - when(mockDiskStoreFactory.setDiskDirs(any(File[].class))).thenAnswer(invocation -> { - - File[] resolveDiskDirectories = nullSafeArray(invocation.getArgument(0), File.class); - - int[] resolvedDiskDirectorySizes = new int[resolveDiskDirectories.length]; - - Arrays.fill(resolvedDiskDirectorySizes, DiskStoreFactory.DEFAULT_DISK_DIR_SIZE); - - diskDirectories.set(resolveDiskDirectories); - diskDiretorySizes.set(resolvedDiskDirectorySizes); - - return mockDiskStoreFactory; - }); - - when(mockDiskStoreFactory.setDiskDirsAndSizes(any(File[].class), any(int[].class))).thenAnswer(invocation -> { - - diskDirectories.set(invocation.getArgument(0)); - diskDiretorySizes.set(invocation.getArgument(1)); - - return mockDiskStoreFactory; - }); - - when(mockDiskStoreFactory.setDiskUsageCriticalPercentage(anyFloat())) - .thenAnswer(newSetter(diskUsageCriticalPercentage, mockDiskStoreFactory)); - - when(mockDiskStoreFactory.setDiskUsageWarningPercentage(anyFloat())) - .thenAnswer(newSetter(diskUsageWarningPercentage, mockDiskStoreFactory)); - - when(mockDiskStoreFactory.setMaxOplogSize(anyLong())) - .thenAnswer(newSetter(maxOplogSize, mockDiskStoreFactory)); - - when(mockDiskStoreFactory.setQueueSize(anyInt())) - .thenAnswer(newSetter(queueSize, mockDiskStoreFactory)); - - when(mockDiskStoreFactory.setTimeInterval(anyLong())) - .thenAnswer(newSetter(timeInterval, mockDiskStoreFactory)); - - when(mockDiskStoreFactory.setWriteBufferSize(anyInt())) - .thenAnswer(newSetter(writeBufferSize, mockDiskStoreFactory)); - - when(mockDiskStoreFactory.create(anyString())).thenAnswer(invocation -> { - - String name = invocation.getArgument(0); - - DiskStore mockDiskStore = mock(DiskStore.class, name); - - when(mockDiskStore.getAllowForceCompaction()).thenReturn(allowForceCompaction.get()); - when(mockDiskStore.getAutoCompact()).thenReturn(autoCompact.get()); - when(mockDiskStore.getCompactionThreshold()).thenReturn(compactionThreshold.get()); - when(mockDiskStore.getDiskDirs()).thenReturn(diskDirectories.get()); - when(mockDiskStore.getDiskDirSizes()).thenReturn(diskDiretorySizes.get()); - when(mockDiskStore.getDiskUsageCriticalPercentage()).thenReturn(diskUsageCriticalPercentage.get()); - when(mockDiskStore.getDiskUsageWarningPercentage()).thenReturn(diskUsageWarningPercentage.get()); - when(mockDiskStore.getDiskStoreUUID()).thenReturn(UUID.randomUUID()); - when(mockDiskStore.getMaxOplogSize()).thenReturn(maxOplogSize.get()); - when(mockDiskStore.getName()).thenReturn(name); - when(mockDiskStore.getQueueSize()).thenReturn(queueSize.get()); - when(mockDiskStore.getTimeInterval()).thenReturn(timeInterval.get()); - when(mockDiskStore.getWriteBufferSize()).thenReturn(writeBufferSize.get()); - - diskStores.put(name, mockDiskStore); - - return mockDiskStore; - }); - - return mockDiskStoreFactory; - } - - public static DistributedSystem mockDistributedSystem() { - - DistributedSystem mockDistributedSystem = mock(DistributedSystem.class); - - when(mockDistributedSystem.getProperties()).thenReturn(new Properties()); - when(mockDistributedSystem.getReconnectedSystem()).thenAnswer(invocation -> mockDistributedSystem()); - - return mockDistributedSystem; - } - - public static Cache mockGatewayReceiverFactory(Cache mockCache) { - - when(mockCache.createGatewayReceiverFactory()).thenAnswer(invocation -> mockGatewayReceiverFactory()); - - return mockCache; - } - - public static GatewayReceiverFactory mockGatewayReceiverFactory() { - - GatewayReceiverFactory mockGatewayReceiverFactory = mock(GatewayReceiverFactory.class); - - AtomicBoolean manualStart = new AtomicBoolean(GatewayReceiver.DEFAULT_MANUAL_START); - - AtomicInteger endPort = new AtomicInteger(GatewayReceiver.DEFAULT_END_PORT); - AtomicInteger maximumTimeBetweenPings = new AtomicInteger(GatewayReceiver.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS); - AtomicInteger socketBufferSize = new AtomicInteger(GatewayReceiver.DEFAULT_SOCKET_BUFFER_SIZE); - AtomicInteger startPort = new AtomicInteger(GatewayReceiver.DEFAULT_START_PORT); - - AtomicReference bindAddress = new AtomicReference<>(GatewayReceiver.DEFAULT_BIND_ADDRESS); - AtomicReference hostnameForSenders = new AtomicReference<>(GatewayReceiver.DEFAULT_HOSTNAME_FOR_SENDERS); - - CopyOnWriteArrayList gatewayTransportFilters = new CopyOnWriteArrayList<>(); - - when(mockGatewayReceiverFactory.setBindAddress(anyString())) - .thenAnswer(newSetter(bindAddress, mockGatewayReceiverFactory)); - - when(mockGatewayReceiverFactory.setEndPort(anyInt())) - .thenAnswer(newSetter(endPort, mockGatewayReceiverFactory)); - - when(mockGatewayReceiverFactory.setHostnameForSenders(anyString())) - .thenAnswer(newSetter(hostnameForSenders, mockGatewayReceiverFactory)); - - when(mockGatewayReceiverFactory.setManualStart(anyBoolean())) - .thenAnswer(newSetter(manualStart, mockGatewayReceiverFactory)); - - when(mockGatewayReceiverFactory.setMaximumTimeBetweenPings(anyInt())) - .thenAnswer(newSetter(maximumTimeBetweenPings, mockGatewayReceiverFactory)); - - when(mockGatewayReceiverFactory.setSocketBufferSize(anyInt())) - .thenAnswer(newSetter(socketBufferSize, mockGatewayReceiverFactory)); - - when(mockGatewayReceiverFactory.setStartPort(anyInt())) - .thenAnswer(newSetter(startPort, mockGatewayReceiverFactory)); - - when(mockGatewayReceiverFactory.addGatewayTransportFilter(any(GatewayTransportFilter.class))).thenAnswer(invocation -> { - - gatewayTransportFilters.add(invocation.getArgument(0)); - - return mockGatewayReceiverFactory; - }); - - when(mockGatewayReceiverFactory.removeGatewayTransportFilter(any(GatewayTransportFilter.class))).thenAnswer(invocation -> { - - gatewayTransportFilters.remove(invocation.getArgument(0)); - - return mockGatewayReceiverFactory; - }); - - when(mockGatewayReceiverFactory.create()).thenAnswer(invocation -> { - - AtomicBoolean running = new AtomicBoolean(false); - - GatewayReceiver mockGatewayReceiver = mock(GatewayReceiver.class); - - when(mockGatewayReceiver.isManualStart()).thenAnswer(newGetter(manualStart)); - when(mockGatewayReceiver.isRunning()).thenAnswer(newGetter(running)); - - when(mockGatewayReceiver.getBindAddress()).thenAnswer(newGetter(bindAddress)); - when(mockGatewayReceiver.getEndPort()).thenAnswer(newGetter(endPort)); - when(mockGatewayReceiver.getGatewayTransportFilters()).thenReturn(gatewayTransportFilters); - when(mockGatewayReceiver.getHost()).thenAnswer(newGetter(hostnameForSenders)); - //when(mockGatewayReceiver.getHostnameForSenders()).thenAnswer(newGetter(hostnameForSenders)); - when(mockGatewayReceiver.getMaximumTimeBetweenPings()).thenAnswer(newGetter(maximumTimeBetweenPings)); - when(mockGatewayReceiver.getPort()).thenReturn(0); - when(mockGatewayReceiver.getSocketBufferSize()).thenAnswer(newGetter(socketBufferSize)); - when(mockGatewayReceiver.getStartPort()).thenAnswer(newGetter(startPort)); - - doAnswer(newSetter(running, true, null)).when(mockGatewayReceiver).start(); - doAnswer(newSetter(running, false, null)).when(mockGatewayReceiver).stop(); - - return mockGatewayReceiver; - }); - - return mockGatewayReceiverFactory; - } - - public static Cache mockGatewaySenderFactory(Cache mockCache) { - - when(mockCache.createGatewaySenderFactory()).thenAnswer(invocation -> mockGatewaySenderFactory()); - - return mockCache; - } - - public static GatewaySenderFactory mockGatewaySenderFactory() { - - GatewaySenderFactory mockGatewaySenderFactory = mock(GatewaySenderFactory.class); - - AtomicBoolean batchConflationEnabled = new AtomicBoolean(GatewaySender.DEFAULT_BATCH_CONFLATION); - AtomicBoolean diskSynchronous = new AtomicBoolean(GatewaySender.DEFAULT_DISK_SYNCHRONOUS); - AtomicBoolean parallel = new AtomicBoolean(GatewaySender.DEFAULT_IS_PARALLEL); - AtomicBoolean persistenceEnabled = new AtomicBoolean(GatewaySender.DEFAULT_PERSISTENCE_ENABLED); - - AtomicInteger alertThreshold = new AtomicInteger(GatewaySender.DEFAULT_ALERT_THRESHOLD); - AtomicInteger batchSize = new AtomicInteger(GatewaySender.DEFAULT_BATCH_SIZE); - AtomicInteger batchTimeInterval = new AtomicInteger(GatewaySender.DEFAULT_BATCH_TIME_INTERVAL); - AtomicInteger dispatcherThreads = new AtomicInteger(GatewaySender.DEFAULT_DISPATCHER_THREADS); - AtomicInteger maximumQueueMemory = new AtomicInteger(GatewaySender.DEFAULT_MAXIMUM_QUEUE_MEMORY); - AtomicInteger parallelFactorForReplicatedRegion = - new AtomicInteger(GatewaySender.DEFAULT_PARALLELISM_REPLICATED_REGION); - AtomicInteger socketBufferSize = new AtomicInteger(GatewaySender.DEFAULT_SOCKET_BUFFER_SIZE); - AtomicInteger socketReadTimeout = new AtomicInteger(GatewaySender.DEFAULT_SOCKET_READ_TIMEOUT); - - AtomicReference diskStoreName = new AtomicReference<>(null); - AtomicReference gatewayEventSubstitutionFilter = - new AtomicReference<>(null); - AtomicReference orderPolicy = new AtomicReference<>(GatewaySender.DEFAULT_ORDER_POLICY); - - CopyOnWriteArrayList gatewayEventFilters = new CopyOnWriteArrayList<>(); - CopyOnWriteArrayList gatewayTransportFilters = new CopyOnWriteArrayList<>(); - - when(mockGatewaySenderFactory.setAlertThreshold(anyInt())) - .thenAnswer(newSetter(alertThreshold, mockGatewaySenderFactory)); - - when(mockGatewaySenderFactory.setBatchConflationEnabled(anyBoolean())) - .thenAnswer(newSetter(batchConflationEnabled, mockGatewaySenderFactory)); - - when(mockGatewaySenderFactory.setBatchSize(anyInt())).thenAnswer(newSetter(batchSize, mockGatewaySenderFactory)); - - when(mockGatewaySenderFactory.setBatchTimeInterval(anyInt())) - .thenAnswer(newSetter(batchTimeInterval, mockGatewaySenderFactory)); - - when(mockGatewaySenderFactory.setDiskStoreName(anyString())) - .thenAnswer(newSetter(diskStoreName, mockGatewaySenderFactory)); - - when(mockGatewaySenderFactory.setDiskSynchronous(anyBoolean())) - .thenAnswer(newSetter(diskSynchronous, mockGatewaySenderFactory)); - - when(mockGatewaySenderFactory.setDispatcherThreads(anyInt())) - .thenAnswer(newSetter(dispatcherThreads, mockGatewaySenderFactory)); - - when(mockGatewaySenderFactory.setGatewayEventSubstitutionFilter(any(GatewayEventSubstitutionFilter.class))) - .thenAnswer(newSetter(gatewayEventSubstitutionFilter, mockGatewaySenderFactory)); - - when(mockGatewaySenderFactory.setMaximumQueueMemory(anyInt())) - .thenAnswer(newSetter(maximumQueueMemory, mockGatewaySenderFactory)); - - when(mockGatewaySenderFactory.setOrderPolicy(any(GatewaySender.OrderPolicy.class))) - .thenAnswer(newSetter(orderPolicy, mockGatewaySenderFactory)); - - when(mockGatewaySenderFactory.setParallel(anyBoolean())).thenAnswer(newSetter(parallel, mockGatewaySenderFactory)); - - when(mockGatewaySenderFactory.setParallelFactorForReplicatedRegion(anyInt())) - .thenAnswer(newSetter(parallelFactorForReplicatedRegion, mockGatewaySenderFactory)); - - when(mockGatewaySenderFactory.setPersistenceEnabled(anyBoolean())) - .thenAnswer(newSetter(persistenceEnabled, mockGatewaySenderFactory)); - - when(mockGatewaySenderFactory.setSocketBufferSize(anyInt())) - .thenAnswer(newSetter(socketBufferSize, mockGatewaySenderFactory)); - - when(mockGatewaySenderFactory.setSocketReadTimeout(anyInt())) - .thenAnswer(newSetter(socketReadTimeout, mockGatewaySenderFactory)); - - when(mockGatewaySenderFactory.addGatewayEventFilter(any(GatewayEventFilter.class))).thenAnswer(invocation -> { - - gatewayEventFilters.add(invocation.getArgument(0)); - - return mockGatewaySenderFactory; - }); - - when(mockGatewaySenderFactory.addGatewayTransportFilter(any(GatewayTransportFilter.class))).thenAnswer(invocation -> { - - gatewayTransportFilters.add(invocation.getArgument(0)); - - return mockGatewaySenderFactory; - }); - - when(mockGatewaySenderFactory.removeGatewayEventFilter(any(GatewayEventFilter.class))).thenAnswer(invocation -> { - - gatewayEventFilters.remove(invocation.getArgument(0)); - - return mockGatewaySenderFactory; - }); - - when(mockGatewaySenderFactory.removeGatewayTransportFilter(any(GatewayTransportFilter.class))).thenAnswer(invocation -> { - - gatewayTransportFilters.remove(invocation.getArgument(0)); - - return mockGatewaySenderFactory; - }); - - when(mockGatewaySenderFactory.create(anyString(), anyInt())).thenAnswer(invocation -> { - - GatewaySender mockGatewaySender = mock(GatewaySender.class); - - AtomicBoolean destroyed = new AtomicBoolean(false); - AtomicBoolean running = new AtomicBoolean(false); - - Integer remoteDistributedSystemId = invocation.getArgument(1); - - String gatewaySenderId = invocation.getArgument(0); - - when(mockGatewaySender.isBatchConflationEnabled()).thenAnswer(newGetter(batchConflationEnabled)); - when(mockGatewaySender.isDiskSynchronous()).thenAnswer(newGetter(diskSynchronous)); - when(mockGatewaySender.isParallel()).thenAnswer(newGetter(parallel)); - when(mockGatewaySender.isPaused()).thenAnswer(newGetter(running)); - when(mockGatewaySender.isPersistenceEnabled()).thenAnswer(newGetter(persistenceEnabled)); - when(mockGatewaySender.isRunning()).thenAnswer(newGetter(running)); - - when(mockGatewaySender.getAlertThreshold()).thenAnswer(newGetter(alertThreshold)); - when(mockGatewaySender.getBatchSize()).thenAnswer(newGetter(batchSize)); - when(mockGatewaySender.getBatchTimeInterval()).thenAnswer(newGetter(batchTimeInterval)); - when(mockGatewaySender.getDiskStoreName()).thenAnswer(newGetter(diskStoreName)); - when(mockGatewaySender.getDispatcherThreads()).thenAnswer(newGetter(dispatcherThreads)); - when(mockGatewaySender.getGatewayEventFilters()).thenReturn(gatewayEventFilters); - when(mockGatewaySender.getGatewayEventSubstitutionFilter()).thenAnswer(newGetter(gatewayEventSubstitutionFilter)); - when(mockGatewaySender.getGatewayTransportFilters()).thenReturn(gatewayTransportFilters); - when(mockGatewaySender.getId()).thenReturn(gatewaySenderId); - when(mockGatewaySender.getMaximumQueueMemory()).thenAnswer(newGetter(maximumQueueMemory)); - when(mockGatewaySender.getMaxParallelismForReplicatedRegion()).thenAnswer(newGetter(parallelFactorForReplicatedRegion)); - when(mockGatewaySender.getOrderPolicy()).thenAnswer(newGetter(orderPolicy)); - when(mockGatewaySender.getRemoteDSId()).thenReturn(remoteDistributedSystemId); - when(mockGatewaySender.getSocketBufferSize()).thenAnswer(newGetter(socketBufferSize)); - when(mockGatewaySender.getSocketReadTimeout()).thenAnswer(newGetter(socketReadTimeout)); - - doAnswer(it -> { - - gatewayEventFilters.add(it.getArgument(0)); - - return null; - - }).when(mockGatewaySender).addGatewayEventFilter(any(GatewayEventFilter.class)); - - doAnswer(newSetter(destroyed, null)).when(mockGatewaySender).destroy(); - doAnswer(newSetter(running, false, null)).when(mockGatewaySender).pause(); - doAnswer(newSetter(running, true, null)).when(mockGatewaySender).resume(); - doAnswer(newSetter(running, true, null)).when(mockGatewaySender).start(); - doAnswer(newSetter(running, false, null)).when(mockGatewaySender).stop(); - - doAnswer(it -> { - - gatewayEventFilters.remove(it.getArgument(0)); - - return null; - - }).when(mockGatewaySender).removeGatewayEventFilter(any(GatewayEventFilter.class)); - - return mockGatewaySender; - }); - - return mockGatewaySenderFactory; - } - - public static PoolFactory mockPoolFactory() { - - PoolFactory mockPoolFactory = mock(PoolFactory.class); - - AtomicBoolean multiuserAuthentication = new AtomicBoolean(PoolFactory.DEFAULT_MULTIUSER_AUTHENTICATION); - AtomicBoolean prSingleHopEnabled = new AtomicBoolean(PoolFactory.DEFAULT_PR_SINGLE_HOP_ENABLED); - AtomicBoolean subscriptionEnabled = new AtomicBoolean(PoolFactory.DEFAULT_SUBSCRIPTION_ENABLED); - AtomicBoolean threadLocalConnections = new AtomicBoolean(PoolFactory.DEFAULT_THREAD_LOCAL_CONNECTIONS); - - AtomicInteger freeConnectionTimeout = new AtomicInteger(PoolFactory.DEFAULT_FREE_CONNECTION_TIMEOUT); - AtomicInteger loadConditioningInterval = new AtomicInteger(PoolFactory.DEFAULT_LOAD_CONDITIONING_INTERVAL); - AtomicInteger maxConnections = new AtomicInteger(PoolFactory.DEFAULT_MAX_CONNECTIONS); - AtomicInteger minConnections = new AtomicInteger(PoolFactory.DEFAULT_MIN_CONNECTIONS); - AtomicInteger readTimeout = new AtomicInteger(PoolFactory.DEFAULT_READ_TIMEOUT); - AtomicInteger retryAttempts = new AtomicInteger(PoolFactory.DEFAULT_RETRY_ATTEMPTS); - AtomicInteger serverConnectionTimeout = new AtomicInteger(PoolFactory.DEFAULT_SOCKET_CONNECT_TIMEOUT); - AtomicInteger socketBufferSize = new AtomicInteger(PoolFactory.DEFAULT_SOCKET_BUFFER_SIZE); - AtomicInteger socketConnectTimeout = new AtomicInteger(PoolFactory.DEFAULT_SOCKET_CONNECT_TIMEOUT); - AtomicInteger statisticInterval = new AtomicInteger(PoolFactory.DEFAULT_STATISTIC_INTERVAL); - AtomicInteger subscriptionAckInterval = new AtomicInteger(PoolFactory.DEFAULT_SUBSCRIPTION_ACK_INTERVAL); - AtomicInteger subscriptionMessageTrackingTimeout = new AtomicInteger(PoolFactory.DEFAULT_SUBSCRIPTION_MESSAGE_TRACKING_TIMEOUT); - AtomicInteger subscriptionRedundancy = new AtomicInteger(PoolFactory.DEFAULT_SUBSCRIPTION_REDUNDANCY); - - AtomicLong idleTimeout = new AtomicLong(PoolFactory.DEFAULT_IDLE_TIMEOUT); - AtomicLong pingInterval = new AtomicLong(PoolFactory.DEFAULT_PING_INTERVAL); - - AtomicReference serverGroup = new AtomicReference<>(PoolFactory.DEFAULT_SERVER_GROUP); - AtomicReference socketFactory = new AtomicReference<>(PoolFactory.DEFAULT_SOCKET_FACTORY); - - List locators = new ArrayList<>(); - List servers = new ArrayList<>(); - - when(mockPoolFactory.addLocator(anyString(), anyInt())).thenAnswer(invocation -> { - locators.add(new InetSocketAddress(invocation.getArgument(0), invocation.getArgument(1))); - return mockPoolFactory; - }); - - when(mockPoolFactory.addServer(anyString(), anyInt())).thenAnswer(invocation -> { - servers.add(new InetSocketAddress(invocation.getArgument(0), invocation.getArgument(1))); - return mockPoolFactory; - }); - - when(mockPoolFactory.setFreeConnectionTimeout(anyInt())) - .thenAnswer(newSetter(freeConnectionTimeout, mockPoolFactory)); - - when(mockPoolFactory.setIdleTimeout(anyLong())) - .thenAnswer(newSetter(idleTimeout, mockPoolFactory)); - - when(mockPoolFactory.setLoadConditioningInterval(anyInt())) - .thenAnswer(newSetter(loadConditioningInterval, mockPoolFactory)); - - when(mockPoolFactory.setMaxConnections(anyInt())) - .thenAnswer(newSetter(maxConnections, mockPoolFactory)); - - when(mockPoolFactory.setMinConnections(anyInt())) - .thenAnswer(newSetter(minConnections, mockPoolFactory)); - - when(mockPoolFactory.setMultiuserAuthentication(anyBoolean())) - .thenAnswer(newSetter(multiuserAuthentication, mockPoolFactory)); - - when(mockPoolFactory.setPingInterval(anyLong())) - .thenAnswer(newSetter(pingInterval, mockPoolFactory)); - - when(mockPoolFactory.setPRSingleHopEnabled(anyBoolean())) - .thenAnswer(newSetter(prSingleHopEnabled, mockPoolFactory)); - - when(mockPoolFactory.setReadTimeout(anyInt())) - .thenAnswer(newSetter(readTimeout, mockPoolFactory)); - - when(mockPoolFactory.setRetryAttempts(anyInt())) - .thenAnswer(newSetter(retryAttempts, mockPoolFactory)); - - when(mockPoolFactory.setServerConnectionTimeout(anyInt())) - .thenAnswer(newSetter(serverConnectionTimeout, mockPoolFactory)); - - when(mockPoolFactory.setServerGroup(anyString())) - .thenAnswer(newSetter(serverGroup, mockPoolFactory)); - - when(mockPoolFactory.setSocketBufferSize(anyInt())) - .thenAnswer(newSetter(socketBufferSize, mockPoolFactory)); - - when(mockPoolFactory.setSocketFactory(any())) - .thenAnswer(newSetter(socketFactory, mockPoolFactory)); - - when(mockPoolFactory.setSocketConnectTimeout(anyInt())) - .thenAnswer(newSetter(socketConnectTimeout, mockPoolFactory)); - - when(mockPoolFactory.setStatisticInterval(anyInt())) - .thenAnswer(newSetter(statisticInterval, mockPoolFactory)); - - when(mockPoolFactory.setSubscriptionAckInterval(anyInt())) - .thenAnswer(newSetter(subscriptionAckInterval, mockPoolFactory)); - - when(mockPoolFactory.setSubscriptionEnabled(anyBoolean())) - .thenAnswer(newSetter(subscriptionEnabled, mockPoolFactory)); - - when(mockPoolFactory.setSubscriptionMessageTrackingTimeout(anyInt())) - .thenAnswer(newSetter(subscriptionMessageTrackingTimeout, mockPoolFactory)); - - when(mockPoolFactory.setSubscriptionRedundancy(anyInt())) - .thenAnswer(newSetter(subscriptionRedundancy, mockPoolFactory)); - - when(mockPoolFactory.setThreadLocalConnections(anyBoolean())) - .thenAnswer(newSetter(threadLocalConnections, mockPoolFactory)); - - when(mockPoolFactory.create(anyString())).thenAnswer(invocation -> { - - String name = invocation.getArgument(0); - - Pool mockPool = mock(Pool.class, name); - - AtomicBoolean destroyed = new AtomicBoolean(false); - - doAnswer(invocationOnMock -> { - destroyed.set(true); - return null; - }).when(mockPool).destroy(); - - doAnswer(invocationOnMock -> { - destroyed.set(true); - return null; - }).when(mockPool).destroy(anyBoolean()); - - when(mockPool.isDestroyed()).thenAnswer(newGetter(destroyed)); - when(mockPool.getFreeConnectionTimeout()).thenReturn(freeConnectionTimeout.get()); - when(mockPool.getIdleTimeout()).thenReturn(idleTimeout.get()); - when(mockPool.getLoadConditioningInterval()).thenReturn(loadConditioningInterval.get()); - when(mockPool.getLocators()).thenReturn(locators); - when(mockPool.getMaxConnections()).thenReturn(maxConnections.get()); - when(mockPool.getMinConnections()).thenReturn(minConnections.get()); - when(mockPool.getMultiuserAuthentication()).thenReturn(multiuserAuthentication.get()); - when(mockPool.getName()).thenReturn(name); - when(mockPool.getPingInterval()).thenReturn(pingInterval.get()); - when(mockPool.getPRSingleHopEnabled()).thenReturn(prSingleHopEnabled.get()); - when(mockPool.getReadTimeout()).thenReturn(readTimeout.get()); - when(mockPool.getRetryAttempts()).thenReturn(retryAttempts.get()); - when(mockPool.getServerConnectionTimeout()).thenReturn(serverConnectionTimeout.get()); - when(mockPool.getServerGroup()).thenReturn(serverGroup.get()); - when(mockPool.getServers()).thenReturn(servers); - when(mockPool.getSocketBufferSize()).thenReturn(socketBufferSize.get()); - when(mockPool.getSocketConnectTimeout()).thenReturn(socketConnectTimeout.get()); - when(mockPool.getSocketFactory()).thenReturn(socketFactory.get()); - when(mockPool.getStatisticInterval()).thenReturn(statisticInterval.get()); - when(mockPool.getSubscriptionAckInterval()).thenReturn(subscriptionAckInterval.get()); - when(mockPool.getSubscriptionEnabled()).thenReturn(subscriptionEnabled.get()); - when(mockPool.getSubscriptionMessageTrackingTimeout()).thenReturn(subscriptionMessageTrackingTimeout.get()); - when(mockPool.getSubscriptionRedundancy()).thenReturn(subscriptionRedundancy.get()); - when(mockPool.getThreadLocalConnections()).thenReturn(threadLocalConnections.get()); - - return mockPool; - }); - - return mockPoolFactory; - } - - public static Pool mockQueryService(Pool pool) { - - QueryService mockQueryService = mockQueryService(); - - when(pool.getQueryService()).thenReturn(mockQueryService); - - return pool; - } - - public static T mockQueryService(T regionService) { - - QueryService mockQueryService = mockQueryService(); - - when(regionService.getQueryService()).thenReturn(mockQueryService); - - if (regionService instanceof ClientCache) { - when(((ClientCache) regionService).getLocalQueryService()).thenReturn(mockQueryService); - } - - return regionService; - } - - // TODO write more mocking logic for the QueryService interface - public static QueryService mockQueryService() { - - QueryService mockQueryService = mock(QueryService.class); - - Set cqQueries = Collections.synchronizedSet(new HashSet<>()); - Set indexes = Collections.synchronizedSet(new HashSet<>()); - - try { - when(mockQueryService.getCqs()).thenAnswer(invocation -> cqQueries.toArray(new CqQuery[cqQueries.size()])); - - when(mockQueryService.getCq(anyString())).thenAnswer(invocation -> - cqQueries.stream().filter(cqQuery -> invocation.getArgument(0).equals(cqQuery.getName())) - .findFirst().orElse(null)); - - when(mockQueryService.getCqs(anyString())).thenAnswer(invocation -> { - - List cqQueriesByRegion = cqQueries.stream().filter(cqQuery -> { - - String queryString = cqQuery.getQueryString(); - - int indexOfFromClause = queryString.indexOf(FROM_KEYWORD); - int indexOfWhereClause = queryString.indexOf(WHERE_KEYWORD); - - queryString = (indexOfFromClause > -1 - ? queryString.substring(indexOfFromClause + FROM_KEYWORD.length()) : queryString); - - queryString = (indexOfWhereClause > 0 ? queryString.substring(0, indexOfWhereClause) : queryString); - - queryString = (queryString.startsWith(Region.SEPARATOR) ? queryString.substring(1) : queryString); - - return invocation.getArgument(0).equals(queryString.trim()); - - }).collect(Collectors.toList()); - - return cqQueriesByRegion.toArray(new CqQuery[cqQueriesByRegion.size()]); - }); - - when(mockQueryService.getIndexes()).thenReturn(indexes); - - when(mockQueryService.getIndexes(any(Region.class))).thenAnswer(invocation -> { - - Region region = invocation.getArgument(0); - - return indexes.stream() - .filter(index -> index.getRegion().equals(region)) - .collect(Collectors.toList()); - - }); - - when(mockQueryService.getIndex(any(Region.class), anyString())).thenAnswer(invocation -> { - - Region region = invocation.getArgument(0); - - String indexName = invocation.getArgument(1); - - Collection indexesForRegion = mockQueryService.getIndexes(region); - - return indexesForRegion.stream() - .filter(index -> index.getName().equals(indexName)) - .findFirst().orElse(null); - - }); - - when(mockQueryService.createIndex(anyString(), anyString(), anyString())) - .thenAnswer(createIndexAnswer(indexes, IndexType.FUNCTIONAL)); - - when(mockQueryService.createIndex(anyString(), anyString(), anyString(), anyString())) - .thenAnswer(createIndexAnswer(indexes, IndexType.FUNCTIONAL)); - - when(mockQueryService.createHashIndex(anyString(), anyString(), anyString())) - .thenAnswer(createIndexAnswer(indexes, IndexType.HASH)); - - when(mockQueryService.createHashIndex(anyString(), anyString(), anyString(), anyString())) - .thenAnswer(createIndexAnswer(indexes, IndexType.HASH)); - - when(mockQueryService.createKeyIndex(anyString(), anyString(), anyString())) - .thenAnswer(createIndexAnswer(indexes, IndexType.KEY)); - - when(mockQueryService.newCq(anyString(), any(CqAttributes.class))).thenAnswer(invocation -> - add(cqQueries, mockCqQuery(null, invocation.getArgument(0), invocation.getArgument(1), - false))); - - when(mockQueryService.newCq(anyString(), any(CqAttributes.class), anyBoolean())).thenAnswer(invocation -> - add(cqQueries, mockCqQuery(null, invocation.getArgument(0), invocation.getArgument(1), - invocation.getArgument(2)))); - - when(mockQueryService.newCq(anyString(), anyString(), any(CqAttributes.class))).thenAnswer(invocation -> - add(cqQueries, mockCqQuery(invocation.getArgument(0), invocation.getArgument(1), - invocation.getArgument(2), false))); - - when(mockQueryService.newCq(anyString(), anyString(), any(CqAttributes.class), anyBoolean())) - .thenAnswer(invocation -> add(cqQueries, mockCqQuery(invocation.getArgument(0), - invocation.getArgument(1), invocation.getArgument(2), invocation.getArgument(3)))); - } - catch (Exception cause) { - throw new MockObjectInvocationException(cause); - } - - return mockQueryService; - } - - private static CqQuery add(Collection cqQueries, CqQuery cqQuery) { - - cqQueries.add(cqQuery); - - return cqQuery; - } - - private static Index add(Collection indexes, Index index) { - - indexes.add(index); - - return index; - } - - private static Answer createIndexAnswer(Collection indexes, IndexType indexType) { - - return invocation -> { - - String indexName = invocation.getArgument(0); - String indexedExpression = invocation.getArgument(1); - String regionPath = invocation.getArgument(2); - - return add(indexes, mockIndex(indexName, indexedExpression, regionPath, indexType)); - }; - } - - private static CqQuery mockCqQuery(String name, String queryString, CqAttributes cqAttributes, boolean durable) { - - CqQuery mockCqQuery = mock(CqQuery.class); - - Query mockQuery = mockQuery(queryString); - - AtomicBoolean closed = new AtomicBoolean(false); - AtomicBoolean running = new AtomicBoolean(false); - AtomicBoolean stopped = new AtomicBoolean(true); - - when(mockCqQuery.getCqAttributes()).thenReturn(cqAttributes); - when(mockCqQuery.getName()).thenReturn(name); - when(mockCqQuery.getQuery()).thenReturn(mockQuery); - when(mockCqQuery.getQueryString()).thenReturn(queryString); - - try { - doAnswer(newSetter(closed, true, null)).when(mockCqQuery).close(); - - doAnswer(invocation -> { - - running.set(true); - stopped.set(false); - - return null; - - }).when(mockCqQuery).execute(); - - doAnswer(invocation -> { - - running.set(false); - stopped.set(true); - - return null; - - }).when(mockCqQuery).stop(); - } - catch (Exception cause) { - throw new MockObjectInvocationException(cause); - } - - when(mockCqQuery.isClosed()).thenAnswer(newGetter(closed)); - when(mockCqQuery.isDurable()).thenReturn(durable); - when(mockCqQuery.isRunning()).thenAnswer(newGetter(running)); - when(mockCqQuery.isStopped()).thenAnswer(newGetter(stopped)); - - return mockCqQuery; - } - - private static Query mockQuery(String queryString) { - - Query mockQuery = mock(Query.class); - - QueryStatistics mockQueryStatistics = mockQueryStatistics(mockQuery); - - when(mockQuery.getQueryString()).thenReturn(queryString); - when(mockQuery.getStatistics()).thenReturn(mockQueryStatistics); - - return mockQuery; - } - - private static QueryStatistics mockQueryStatistics(Query query) { - - QueryStatistics mockQueryStatistics = mock(QueryStatistics.class); - - AtomicLong numberOfExecutions = new AtomicLong(0L); - - Answer executeAnswer = invocation -> { - numberOfExecutions.incrementAndGet(); - return null; - }; - - try { - when(query.execute()).thenAnswer(executeAnswer); - when(query.execute(any(Object[].class))).thenAnswer(executeAnswer); - when(query.execute(any(RegionFunctionContext.class))).thenAnswer(executeAnswer); - when(query.execute(any(RegionFunctionContext.class), any(Object[].class))).thenAnswer(executeAnswer); - } - catch (Exception cause) { - throw new MockObjectInvocationException(cause); - } - - when(mockQueryStatistics.getNumExecutions()).thenAnswer(newGetter(numberOfExecutions)); - when(mockQueryStatistics.getTotalExecutionTime()).thenReturn(0L); - - return mockQueryStatistics; - } - - public static Index mockIndex(String name, String expression, String fromClause, IndexType indexType) { - - Index mockIndex = mock(Index.class, name); - - IndexStatistics mockIndexStaticts = mockIndexStatistics(name); - - when(mockIndex.getName()).thenReturn(name); - when(mockIndex.getCanonicalizedFromClause()).thenReturn(fromClause); - when(mockIndex.getCanonicalizedIndexedExpression()).thenReturn(expression); - when(mockIndex.getCanonicalizedProjectionAttributes()).thenReturn(expression); - when(mockIndex.getFromClause()).thenReturn(fromClause); - when(mockIndex.getIndexedExpression()).thenReturn(expression); - when(mockIndex.getProjectionAttributes()).thenReturn(expression); - when(mockIndex.getRegion()).thenAnswer(invocation -> regions.get(fromClause)); - when(mockIndex.getStatistics()).thenReturn(mockIndexStaticts); - when(mockIndex.getType()).thenReturn(indexType.getGemfireIndexType()); - - return mockIndex; - } - - private static IndexStatistics mockIndexStatistics(String name) { - return mock(IndexStatistics.class, mockObjectIdentifier(name)); - } - - public static LuceneIndexFactory mockLuceneIndexFactory() { - return mockLuceneIndexFactory(null); - } - - private static LuceneIndexFactory mockLuceneIndexFactory(Map luceneIndexes) { - - LuceneIndexFactory mockLuceneIndexFactory = mock(LuceneIndexFactory.class); - - AtomicReference luceneSerializerReference = new AtomicReference<>(null); - - Map fieldAnalyzers = new ConcurrentHashMap<>(); - - Set fields = new CopyOnWriteArraySet<>(); - - when(mockLuceneIndexFactory.addField(anyString())).thenAnswer(invocation -> { - - String fieldName = invocation.getArgument(0); - - fields.add(fieldName); - - return mockLuceneIndexFactory; - }); - - when(mockLuceneIndexFactory.addField(anyString(), any(Analyzer.class))).thenAnswer(invocation -> { - - String fieldName = invocation.getArgument(0); - Analyzer analyzer = invocation.getArgument(1); - - fieldAnalyzers.put(fieldName, analyzer); - - return mockLuceneIndexFactory; - }); - - when(mockLuceneIndexFactory.setFields(ArgumentMatchers.any())).thenAnswer(invocation -> { - - Object[] fieldsArgument = invocation.getArguments(); - - fields.clear(); - - Arrays.stream(nullSafeArray(fieldsArgument, Object.class)) - .filter(field -> field instanceof String) - .map(String::valueOf) - .forEach(fields::add); - - return mockLuceneIndexFactory; - }); - - when(mockLuceneIndexFactory.setFields(any(Map.class))).thenAnswer(invocation -> { - - Map fieldAnalyzersArgument = invocation.getArgument(0); - - fieldAnalyzers.clear(); - fieldAnalyzers.putAll(nullSafeMap(fieldAnalyzers)); - - return mockLuceneIndexFactory; - }); - - when(mockLuceneIndexFactory.setLuceneSerializer(any(LuceneSerializer.class))).thenAnswer(invocation -> { - - Optional.ofNullable(invocation.getArgument(0)) - .map(luceneSerializer -> { - luceneSerializerReference.set(luceneSerializer); - return luceneSerializer; - }) - .orElseGet(() -> { - luceneSerializerReference.set(null); - return null; - }); - - return mockLuceneIndexFactory; - }); - - doAnswer(invocation -> { - - String indexName = invocation.getArgument(0); - String regionPath = invocation.getArgument(1); - - LuceneIndexKey key = LuceneIndexKey.of(indexName, regionPath); - - LuceneIndex mockLuceneIndex = mock(LuceneIndex.class, key.toString()); - - when(mockLuceneIndex.getFieldAnalyzers()).thenReturn(Collections.unmodifiableMap(fieldAnalyzers)); - when(mockLuceneIndex.getFieldNames()).thenAnswer(in -> fields.toArray(new String[fields.size()])); - when(mockLuceneIndex.getLuceneSerializer()).thenAnswer(in -> luceneSerializerReference.get()); - when(mockLuceneIndex.getName()).thenReturn(indexName); - when(mockLuceneIndex.getRegionPath()).thenReturn(regionPath); - - Optional.ofNullable(luceneIndexes).ifPresent(it -> it.put(key, mockLuceneIndex)); - - return null; - - }).when(mockLuceneIndexFactory).create(anyString(), anyString()); - - return mockLuceneIndexFactory; - } - - public static LuceneQueryFactory mockLuceneQueryFactory() { - - LuceneQueryFactory mockLuceneQueryFactory = mock(LuceneQueryFactory.class); - - AtomicInteger limit = new AtomicInteger(LuceneQueryFactory.DEFAULT_LIMIT); - AtomicInteger pageSize = new AtomicInteger(LuceneQueryFactory.DEFAULT_PAGESIZE); - - when(mockLuceneQueryFactory.setLimit(anyInt())).thenAnswer(invocation -> { - limit.set(invocation.getArgument(0)); - return mockLuceneQueryFactory; - }); - - when(mockLuceneQueryFactory.setPageSize(anyInt())).thenAnswer(invocation -> { - pageSize.set(invocation.getArgument(0)); - return mockLuceneQueryFactory; - }); - - when(mockLuceneQueryFactory.create(anyString(), anyString(), any(LuceneQueryProvider.class))) - .thenAnswer(invocation -> mockLuceneQuery(limit.get(), pageSize.get())); - - when(mockLuceneQueryFactory.create(anyString(), anyString(), anyString(), anyString())) - .thenAnswer(invocation -> mockLuceneQuery(limit.get(), pageSize.get())); - - return mockLuceneQueryFactory; - } - - private static LuceneQuery mockLuceneQuery(int limit, int pageSize) { - - LuceneQuery mockLuceneQuery = mock(LuceneQuery.class); - - when(mockLuceneQuery.getLimit()).thenReturn(limit); - when(mockLuceneQuery.getPageSize()).thenReturn(pageSize); - - doSafeOperation(() -> when(mockLuceneQuery.findKeys()) - .thenReturn(Collections.emptySet()), Collections.emptySet()); - - rethrowAsRuntimeException(() -> when(mockLuceneQuery.findPages()) - .thenThrow(newUnsupportedOperationException("Operation Not Supported!"))); - - doSafeOperation(() -> when(mockLuceneQuery.findResults()) - .thenReturn(Collections.emptyList()), Collections.emptyList()); - - doSafeOperation(() -> when(mockLuceneQuery.findValues()) - .thenReturn(Collections.emptyList()), Collections.emptyList()); - - return mockLuceneQuery; - } - - public static LuceneService mockLuceneService(Cache mockCache) { - - LuceneService mockLuceneService = mock(LuceneService.class); - - Map luceneIndexes = new ConcurrentHashMap<>(); - - when(mockLuceneService.createIndexFactory()) - .thenAnswer(invocation -> mockLuceneIndexFactory(luceneIndexes)); - - when(mockLuceneService.createLuceneQueryFactory()) - .thenAnswer(invocation -> mockLuceneQueryFactory()); - - doAnswer(invocation -> { - - String indexName = invocation.getArgument(0); - String regionName = invocation .getArgument(1); - - luceneIndexes.remove(LuceneIndexKey.of(indexName, regionName)); - - return null; - - }).when(mockLuceneService).destroyIndex(anyString(), anyString()); - - doAnswer(invocation -> { - - String regionPath = invocation.getArgument(0); - - luceneIndexes.keySet().stream().filter(key -> key.getRegionPath().equals(regionPath)) - .collect(Collectors.toSet()).forEach(key -> luceneIndexes.remove(key)); - - return null; - - }).when(mockLuceneService).destroyIndexes(anyString()); - - when(mockLuceneService.getAllIndexes()).thenAnswer(invocation -> - Collections.unmodifiableCollection(luceneIndexes.values())); - - when(mockLuceneService.getCache()).thenReturn(mockCache); - - when(mockLuceneService.getIndex(anyString(), anyString())).thenAnswer(invocation -> { - - String indexName = invocation.getArgument(0); - String regionPath = invocation.getArgument(1); - - return luceneIndexes.get(LuceneIndexKey.of(indexName, regionPath)); - }); - - doSafeOperation(() -> - when(mockLuceneService.waitUntilFlushed(anyString(), anyString(), anyLong(), any(TimeUnit.class))) - .thenReturn(true)); - - return mockLuceneService; - } - - @SuppressWarnings("unchecked") - public static Region mockRegion(RegionService regionService, String name, - RegionAttributes regionAttributes) { - - Map data = new ConcurrentHashMap<>(); - - Region mockRegion = mock(Region.class, name); - - RegionAttributes mockRegionAttributes = mockRegionAttributes(mockRegion, regionAttributes); - - Set> subRegions = new CopyOnWriteArraySet<>(); - - when(mockRegion.getAttributes()).thenReturn(mockRegionAttributes); - when(mockRegion.getFullPath()).thenReturn(toRegionPath(name)); - when(mockRegion.getName()).thenReturn(toRegionName(name)); - when(mockRegion.getRegionService()).thenReturn(regionService); - - when(mockRegion.getSubregion(anyString())).thenAnswer(invocation -> { - - String subRegionPath = toRegionPath(invocation.getArgument(0)); - String subRegionFullPath = String.format("%1$s%2$s", mockRegion.getFullPath(), subRegionPath); - - return regions.get(subRegionFullPath); - }); - - when(mockRegion.get(ArgumentMatchers.any())).thenAnswer(invocation -> - data.get(invocation.getArgument(0))); - - when(mockRegion.getEntry(ArgumentMatchers.any())).thenAnswer(invocation -> - data.entrySet().stream().filter(entry -> entry.getKey().equals(invocation.getArgument(0))).findFirst() - .orElse(null)); - - when(mockRegion.put(any(), any())).thenAnswer(invocation -> - data.put(invocation.getArgument(0), invocation.getArgument(1))); - - when(mockRegion.size()).thenAnswer(invocation -> data.size()); - - when(mockRegion.subregions(anyBoolean())).thenAnswer(invocation -> { - - boolean recursive = invocation.getArgument(0); - - return recursive - ? subRegions.stream() - .flatMap(subRegion -> subRegion.subregions(true).stream()) - .collect(Collectors.toSet()) - : subRegions; - }); - - return rememberMockedRegion(mockRegion); - } - - @SuppressWarnings("all") - private static RegionAttributes mockRegionAttributes(Region mockRegion, - RegionAttributes baseRegionAttributes) { - - AttributesMutator mockAttributesMutator = mock(AttributesMutator.class); - - EvictionAttributesMutator mockEvictionAttributesMutator = mock(EvictionAttributesMutator.class); - - RegionAttributes mockRegionAttributes = mock(RegionAttributes.class); - - when(mockRegion.getAttributesMutator()).thenReturn(mockAttributesMutator); - when(mockAttributesMutator.getEvictionAttributesMutator()).thenReturn(mockEvictionAttributesMutator); - when(mockAttributesMutator.getRegion()).thenReturn(mockRegion); - - AtomicInteger evictionMaximum = - new AtomicInteger(Optional.ofNullable(baseRegionAttributes.getEvictionAttributes()) - .map(EvictionAttributes::getMaximum) - .orElse(EvictionAttributes.DEFAULT_ENTRIES_MAXIMUM)); - - AtomicReference cloningEnabled = new AtomicReference<>(null); - - AtomicReference> cacheLoader = new AtomicReference<>(baseRegionAttributes.getCacheLoader()); - - AtomicReference> cacheWriter = new AtomicReference<>(baseRegionAttributes.getCacheWriter()); - - AtomicReference> customEntryIdleTimeout = - new AtomicReference<>(baseRegionAttributes.getCustomEntryIdleTimeout()); - - AtomicReference> customEntryTimeToLive = - new AtomicReference<>(baseRegionAttributes.getCustomEntryTimeToLive()); - - AtomicReference entryIdleTimeout = - new AtomicReference<>(baseRegionAttributes.getEntryIdleTimeout()); - - AtomicReference entryTimeToLive = - new AtomicReference<>(baseRegionAttributes.getEntryTimeToLive()); - - AtomicReference regionIdleTimeout = - new AtomicReference<>(baseRegionAttributes.getRegionIdleTimeout()); - - AtomicReference regionTimeToLive = - new AtomicReference<>(baseRegionAttributes.getRegionTimeToLive()); - - List asyncEventQueueIds = - new CopyOnWriteArrayList<>(nullSafeSet(baseRegionAttributes.getAsyncEventQueueIds())); - - List> cacheListeners = - new CopyOnWriteArrayList<>(nullSafeArray(baseRegionAttributes.getCacheListeners(), CacheListener.class)); - - List gatewaySenderIds = - new CopyOnWriteArrayList<>(nullSafeSet(baseRegionAttributes.getGatewaySenderIds())); - - // Mock AttributesMutator - doAnswer(newAdder(asyncEventQueueIds, null)) - .when(mockAttributesMutator).addAsyncEventQueueId(anyString()); - - doAnswer(newAdder(cacheListeners, null)) - .when(mockAttributesMutator).addCacheListener(any(CacheListener.class)); - - doAnswer(newAdder(gatewaySenderIds, null)). - when(mockAttributesMutator).addGatewaySenderId(anyString()); - - when(mockAttributesMutator.getCloningEnabled()).thenAnswer(newGetter(() -> - Optional.ofNullable(cloningEnabled.get()).orElseGet(baseRegionAttributes::getCloningEnabled))); - - doAnswer(invocation -> { - - CacheListener[] cacheListenersArgument = - nullSafeArray(invocation.getArgument(0), CacheListener.class); - - Arrays.stream(cacheListenersArgument).forEach(it -> - Assert.notNull(it, "The CacheListener[] must not contain null elements")); - - cacheListeners.forEach(CacheListener::close); - cacheListeners.addAll(Arrays.asList(cacheListenersArgument)); - - return null; - - }).when(mockAttributesMutator).initCacheListeners(any(CacheListener[].class)); - - - doAnswer(invocation -> asyncEventQueueIds.remove(invocation.getArgument(0))) - .when(mockAttributesMutator).removeAsyncEventQueueId(anyString()); - - doAnswer(invocation -> cacheListeners.remove(invocation.getArgument(0))) - .when(mockAttributesMutator).removeCacheListener(any(CacheListener.class)); - - doAnswer(invocation -> gatewaySenderIds.remove(invocation.getArgument(0))) - .when(mockAttributesMutator).removeGatewaySenderId(anyString()); - - doAnswer(newSetter(cacheLoader, baseRegionAttributes.getCacheLoader())) - .when(mockAttributesMutator).setCacheLoader(any(CacheLoader.class)); - - doAnswer(newSetter(cacheWriter, baseRegionAttributes.getCacheWriter())) - .when(mockAttributesMutator).setCacheWriter(any(CacheWriter.class)); - - doAnswer(newSetter(cloningEnabled, null)) - .when(mockAttributesMutator).setCloningEnabled(anyBoolean()); - - doAnswer(newSetter(customEntryIdleTimeout, baseRegionAttributes.getCustomEntryIdleTimeout())) - .when(mockAttributesMutator).setCustomEntryIdleTimeout(any(CustomExpiry.class)); - - doAnswer(newSetter(customEntryTimeToLive, baseRegionAttributes.getCustomEntryTimeToLive())) - .when(mockAttributesMutator).setCustomEntryTimeToLive(any(CustomExpiry.class)); - - doAnswer(newSetter(entryIdleTimeout, baseRegionAttributes.getEntryIdleTimeout())) - .when(mockAttributesMutator).setEntryIdleTimeout(any(ExpirationAttributes.class)); - - doAnswer(newSetter(entryTimeToLive, baseRegionAttributes.getEntryTimeToLive())) - .when(mockAttributesMutator).setEntryTimeToLive(any(ExpirationAttributes.class)); - - doAnswer(newSetter(regionIdleTimeout, baseRegionAttributes.getRegionIdleTimeout())) - .when(mockAttributesMutator).setRegionIdleTimeout(any(ExpirationAttributes.class)); - - doAnswer(newSetter(regionTimeToLive, baseRegionAttributes.getRegionTimeToLive())) - .when(mockAttributesMutator).setRegionTimeToLive(any(ExpirationAttributes.class)); - - // Mock EvictionAttributesMutator - doAnswer(newSetter(evictionMaximum, null)).when(mockEvictionAttributesMutator).setMaximum(anyInt()); - - // Mock RegionAttributes - when(mockRegionAttributes.getAsyncEventQueueIds()) - .thenAnswer(invocation -> asSet(asyncEventQueueIds.toArray(new String[asyncEventQueueIds.size()]))); - - when(mockRegionAttributes.getCacheListeners()) - .thenAnswer(invocation -> cacheListeners.toArray(new CacheListener[cacheListeners.size()])); - - when(mockRegionAttributes.getCacheLoader()).thenAnswer(newGetter(cacheLoader::get)); - when(mockRegionAttributes.getCacheWriter()).thenAnswer(newGetter(cacheWriter::get)); - when(mockRegionAttributes.getCloningEnabled()).thenAnswer(newGetter(cloningEnabled::get)); - when(mockRegionAttributes.getCompressor()).thenAnswer(newGetter(baseRegionAttributes::getCompressor)); - when(mockRegionAttributes.getConcurrencyChecksEnabled()).thenAnswer(newGetter(baseRegionAttributes::getConcurrencyChecksEnabled)); - when(mockRegionAttributes.getConcurrencyLevel()).thenAnswer(newGetter(baseRegionAttributes::getConcurrencyLevel)); - when(mockRegionAttributes.getCustomEntryIdleTimeout()).thenAnswer(newGetter(customEntryIdleTimeout::get)); - when(mockRegionAttributes.getCustomEntryTimeToLive()).thenAnswer(newGetter(customEntryTimeToLive::get)); - when(mockRegionAttributes.getDataPolicy()).thenAnswer(newGetter(baseRegionAttributes::getDataPolicy)); - when(mockRegionAttributes.getDiskStoreName()).thenAnswer(newGetter(baseRegionAttributes::getDiskStoreName)); - when(mockRegionAttributes.getEnableAsyncConflation()).thenAnswer(newGetter(baseRegionAttributes::getEnableAsyncConflation)); - when(mockRegionAttributes.getEnableSubscriptionConflation()).thenAnswer(newGetter(baseRegionAttributes::getEnableSubscriptionConflation)); - when(mockRegionAttributes.getEntryIdleTimeout()).thenAnswer(newGetter(entryIdleTimeout::get)); - when(mockRegionAttributes.getEntryTimeToLive()).thenAnswer(newGetter(entryTimeToLive::get)); - - when(mockRegionAttributes.getEvictionAttributes()).thenAnswer(invocation -> { - - EvictionAttributes mockEvictionAttibutes = mock(EvictionAttributes.class); - EvictionAttributes regionEvictionAttributes = baseRegionAttributes.getEvictionAttributes(); - - when(mockEvictionAttibutes.getAction()).thenAnswer(newGetter(regionEvictionAttributes::getAction)); - when(mockEvictionAttibutes.getAlgorithm()).thenAnswer(newGetter(regionEvictionAttributes::getAlgorithm)); - when(mockEvictionAttibutes.getMaximum()).thenAnswer(newGetter(evictionMaximum)); - when(mockEvictionAttibutes.getObjectSizer()).thenAnswer(newGetter(regionEvictionAttributes::getObjectSizer)); - - return mockEvictionAttibutes; - }); - - when(mockRegionAttributes.getGatewaySenderIds()) - .thenAnswer(invocation -> asSet(gatewaySenderIds.toArray(new String[gatewaySenderIds.size()]))); - - when(mockRegionAttributes.getIgnoreJTA()).thenAnswer(newGetter(baseRegionAttributes::getIgnoreJTA)); - when(mockRegionAttributes.getIndexMaintenanceSynchronous()).thenAnswer(newGetter(baseRegionAttributes::getIndexMaintenanceSynchronous)); - when(mockRegionAttributes.getInitialCapacity()).thenAnswer(newGetter(baseRegionAttributes::getInitialCapacity)); - when(mockRegionAttributes.getKeyConstraint()).thenAnswer(newGetter(baseRegionAttributes::getKeyConstraint)); - when(mockRegionAttributes.getLoadFactor()).thenAnswer(newGetter(baseRegionAttributes::getLoadFactor)); - when(mockRegionAttributes.getMulticastEnabled()).thenAnswer(newGetter(baseRegionAttributes::getMulticastEnabled)); - when(mockRegionAttributes.getOffHeap()).thenAnswer(newGetter(baseRegionAttributes::getOffHeap)); - when(mockRegionAttributes.getPartitionAttributes()).thenAnswer(newGetter(baseRegionAttributes::getPartitionAttributes)); - when(mockRegionAttributes.getPoolName()).thenAnswer(newGetter(baseRegionAttributes::getPoolName)); - when(mockRegionAttributes.getRegionIdleTimeout()).thenAnswer(newGetter(regionIdleTimeout::get)); - when(mockRegionAttributes.getRegionTimeToLive()).thenAnswer(newGetter(regionTimeToLive::get)); - when(mockRegionAttributes.getScope()).thenAnswer(newGetter(baseRegionAttributes::getScope)); - when(mockRegionAttributes.getStatisticsEnabled()).thenAnswer(newGetter(baseRegionAttributes::getStatisticsEnabled)); - when(mockRegionAttributes.getSubscriptionAttributes()).thenAnswer(newGetter(baseRegionAttributes::getSubscriptionAttributes)); - when(mockRegionAttributes.getValueConstraint()).thenAnswer(newGetter(baseRegionAttributes::getValueConstraint)); - when(mockRegionAttributes.isDiskSynchronous()).thenAnswer(newGetter(baseRegionAttributes::isDiskSynchronous)); - when(mockRegionAttributes.isLockGrantor()).thenAnswer(newGetter(baseRegionAttributes::isLockGrantor)); - - return mockRegionAttributes; - } - - public static Region mockSubRegion(Region parent, String name, - RegionAttributes regionAttributes) { - - String subRegionName = String.format("%1$s%2$s", parent.getFullPath(), toRegionPath(name)); - - Region mockSubRegion = mockRegion(parent.getRegionService(), subRegionName, regionAttributes); - - parent.subregions(false).add(mockSubRegion); - - return mockSubRegion; - } - - public static RegionFactory mockRegionFactory(Cache mockCache) { - return mockRegionFactory(mockCache, null, null); - } - - public static RegionFactory mockRegionFactory(Cache mockCache, - RegionAttributes regionAttributes) { - - return mockRegionFactory(mockCache, null, regionAttributes); - } - - public static RegionFactory mockRegionFactory(Cache mockCache, RegionShortcut regionShortcut) { - return mockRegionFactory(mockCache, regionShortcut, null); - } - - public static RegionFactory mockRegionFactory(Cache mockCache, String regionAttributesId) { - return mockRegionFactory(mockCache, null, resolveRegionAttributes(regionAttributesId)); - } - - @SuppressWarnings("unchecked") - public static RegionFactory mockRegionFactory(Cache mockCache, RegionShortcut regionShortcut, - RegionAttributes regionAttributes) { - - RegionFactory mockRegionFactory = mock(RegionFactory.class, - mockObjectIdentifier("MockRegionFactory")); - - Optional> optionalRegionAttributes = Optional.ofNullable(regionAttributes); - - ExpirationAttributes DEFAULT_EXPIRATION_ATTRIBUTES = - new ExpirationAttributes(0, ExpirationAction.INVALIDATE); - - AtomicBoolean cloningEnabled = new AtomicBoolean(optionalRegionAttributes - .map(RegionAttributes::getCloningEnabled).orElse(false)); - - AtomicBoolean concurrencyChecksEnabled = new AtomicBoolean(optionalRegionAttributes - .map(RegionAttributes::getConcurrencyChecksEnabled).orElse(true)); - - AtomicBoolean diskSynchronous = new AtomicBoolean(optionalRegionAttributes - .map(RegionAttributes::isDiskSynchronous).orElse(true)); - - AtomicBoolean enableAsyncConflation = new AtomicBoolean(optionalRegionAttributes - .map(RegionAttributes::getEnableAsyncConflation).orElse(false)); - - AtomicBoolean enableSubscriptionConflation = new AtomicBoolean(optionalRegionAttributes - .map(RegionAttributes::getEnableSubscriptionConflation).orElse(false)); - - AtomicBoolean ignoreJta = new AtomicBoolean(optionalRegionAttributes - .map(RegionAttributes::getIgnoreJTA).orElse(false)); - - AtomicBoolean indexMaintenanceSynchronous = new AtomicBoolean(optionalRegionAttributes - .map(RegionAttributes::getIndexMaintenanceSynchronous).orElse(true)); - - AtomicBoolean lockGrantor = new AtomicBoolean(optionalRegionAttributes - .map(RegionAttributes::isLockGrantor).orElse(false)); - - AtomicBoolean multicastEnabled = new AtomicBoolean(optionalRegionAttributes - .map(RegionAttributes::getMulticastEnabled).orElse(false)); - - AtomicBoolean offHeap = new AtomicBoolean(optionalRegionAttributes - .map(RegionAttributes::getOffHeap).orElse(false)); - - AtomicBoolean statisticsEnabled = new AtomicBoolean(optionalRegionAttributes - .map(RegionAttributes::getStatisticsEnabled).orElse(false)); - - AtomicInteger concurrencyLevel = new AtomicInteger(optionalRegionAttributes - .map(RegionAttributes::getConcurrencyLevel).orElse(16)); - - AtomicInteger initialCapacity = new AtomicInteger(optionalRegionAttributes - .map(RegionAttributes::getInitialCapacity).orElse(16)); - - AtomicReference cacheLoader = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getCacheLoader).orElse(null)); - - AtomicReference cacheWriter = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getCacheWriter).orElse(null)); - - AtomicReference compressor = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getCompressor).orElse(null)); - - AtomicReference> customEntryIdleTimeout = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getCustomEntryIdleTimeout).orElse(null)); - - AtomicReference> customEntryTimeToLive = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getCustomEntryTimeToLive).orElse(null)); - - AtomicReference dataPolicy = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getDataPolicy).orElseGet(() -> convert(regionShortcut))); - - AtomicReference diskStoreName = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getDiskStoreName).orElse(null)); - - AtomicReference entryIdleTimeout = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getEntryIdleTimeout).orElse(DEFAULT_EXPIRATION_ATTRIBUTES)); - - AtomicReference entryTimeToLive = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getEntryTimeToLive).orElse(DEFAULT_EXPIRATION_ATTRIBUTES)); - - AtomicReference evictionAttributes = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getEvictionAttributes).orElseGet(EvictionAttributes::createLRUEntryAttributes)); - - AtomicReference> keyConstraint = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getKeyConstraint).orElse(null)); - - AtomicReference loadFactor = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getLoadFactor).orElse(0.75f)); - - AtomicReference> partitionAttributes = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getPartitionAttributes).orElse(null)); - - AtomicReference poolName = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getPoolName).orElse(null)); - - AtomicReference regionIdleTimeout = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getRegionIdleTimeout).orElse(DEFAULT_EXPIRATION_ATTRIBUTES)); - - AtomicReference regionTimeToLive = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getRegionTimeToLive).orElse(DEFAULT_EXPIRATION_ATTRIBUTES)); - - AtomicReference scope = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getScope).orElse(Scope.DISTRIBUTED_NO_ACK)); - - AtomicReference subscriptionAttributes = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getSubscriptionAttributes).orElseGet(SubscriptionAttributes::new)); - - AtomicReference> valueConstraint = new AtomicReference<>(optionalRegionAttributes - .map(RegionAttributes::getValueConstraint).orElse(null)); - - List cacheListeners = new ArrayList<>(Arrays.asList(nullSafeArray(optionalRegionAttributes - .map(RegionAttributes::getCacheListeners).orElse(null), CacheListener.class))); - - Set asyncEventQueueIds = new HashSet<>(nullSafeSet(optionalRegionAttributes - .map(RegionAttributes::getAsyncEventQueueIds).orElse(null))); - - Set gatewaySenderIds = new HashSet<>(nullSafeSet(optionalRegionAttributes - .map(RegionAttributes::getGatewaySenderIds).orElse(null))); - - when(mockRegionFactory.addAsyncEventQueueId(anyString())) - .thenAnswer(newAdder(asyncEventQueueIds, mockRegionFactory)); - - when(mockRegionFactory.addCacheListener(any(CacheListener.class))) - .thenAnswer(newAdder(cacheListeners, mockRegionFactory)); - - when(mockRegionFactory.addGatewaySenderId(anyString())) - .thenAnswer(newAdder(gatewaySenderIds, mockRegionFactory)); - - when(mockRegionFactory.initCacheListeners(any(CacheListener[].class))).thenAnswer(invocation -> { - cacheListeners.clear(); - Collections.addAll(cacheListeners, invocation.getArgument(0)); - return mockRegionFactory; - }); - - when(mockRegionFactory.setCacheLoader(any(CacheLoader.class))) - .thenAnswer(newSetter(cacheLoader, mockRegionFactory)); - - when(mockRegionFactory.setCacheWriter(any(CacheWriter.class))) - .thenAnswer(newSetter(cacheWriter, mockRegionFactory)); - - when(mockRegionFactory.setCloningEnabled(anyBoolean())) - .thenAnswer(newSetter(cloningEnabled, mockRegionFactory)); - - when(mockRegionFactory.setCompressor(any(Compressor.class))) - .thenAnswer(newSetter(compressor, mockRegionFactory)); - - when(mockRegionFactory.setConcurrencyChecksEnabled(anyBoolean())) - .then(newSetter(concurrencyChecksEnabled, mockRegionFactory)); - - when(mockRegionFactory.setConcurrencyLevel(anyInt())) - .thenAnswer(newSetter(concurrencyLevel, mockRegionFactory)); - - when(mockRegionFactory.setCustomEntryIdleTimeout(any(CustomExpiry.class))) - .thenAnswer(newSetter(customEntryIdleTimeout, mockRegionFactory)); - - when(mockRegionFactory.setCustomEntryTimeToLive(any(CustomExpiry.class))) - .thenAnswer(newSetter(customEntryTimeToLive, mockRegionFactory)); - - when(mockRegionFactory.setDataPolicy(any(DataPolicy.class))) - .thenAnswer(newSetter(dataPolicy, mockRegionFactory)); - - when(mockRegionFactory.setDiskStoreName(anyString())).thenAnswer(newSetter(diskStoreName, mockRegionFactory)); - - when(mockRegionFactory.setDiskSynchronous(anyBoolean())) - .thenAnswer(newSetter(diskSynchronous, mockRegionFactory)); - - when(mockRegionFactory.setEnableAsyncConflation(anyBoolean())) - .thenAnswer(newSetter(enableAsyncConflation, mockRegionFactory)); - - when(mockRegionFactory.setEnableSubscriptionConflation(anyBoolean())) - .thenAnswer(newSetter(enableSubscriptionConflation, mockRegionFactory)); - - when(mockRegionFactory.setEntryIdleTimeout(any(ExpirationAttributes.class))) - .thenAnswer(newSetter(entryIdleTimeout, mockRegionFactory)); - - when(mockRegionFactory.setEntryTimeToLive(any(ExpirationAttributes.class))) - .thenAnswer(newSetter(entryTimeToLive, mockRegionFactory)); - - when(mockRegionFactory.setEvictionAttributes(any(EvictionAttributes.class))) - .thenAnswer(newSetter(evictionAttributes, mockRegionFactory)); - - when(mockRegionFactory.setIgnoreJTA(anyBoolean())).thenAnswer(newSetter(ignoreJta, mockRegionFactory)); - - when(mockRegionFactory.setIndexMaintenanceSynchronous(anyBoolean())) - .thenAnswer(newSetter(indexMaintenanceSynchronous, mockRegionFactory)); - - when(mockRegionFactory.setInitialCapacity(anyInt())).thenAnswer(newSetter(initialCapacity, mockRegionFactory)); - - when(mockRegionFactory.setKeyConstraint(any(Class.class))) - .thenAnswer(newSetter(keyConstraint, mockRegionFactory)); - - when(mockRegionFactory.setLoadFactor(anyFloat())).thenAnswer(newSetter(loadFactor, mockRegionFactory)); - - when(mockRegionFactory.setLockGrantor(anyBoolean())).thenAnswer(newSetter(lockGrantor, mockRegionFactory)); - - when(mockRegionFactory.setMulticastEnabled(anyBoolean())) - .thenAnswer(newSetter(multicastEnabled, mockRegionFactory)); - - //when(mockRegionFactory.setOffHeap(anyBoolean())).thenAnswer(newSetter(offHeap, mockRegionFactory)); - - when(mockRegionFactory.setOffHeap(anyBoolean())).thenAnswer(invocation -> { - Boolean value = invocation.getArgument(0); - offHeap.set(value); - return mockRegionFactory; - }); - - when(mockRegionFactory.setPartitionAttributes(any(PartitionAttributes.class))) - .thenAnswer(newSetter(partitionAttributes, mockRegionFactory)); - - when(mockRegionFactory.setPoolName(anyString())).thenAnswer(newSetter(poolName, mockRegionFactory)); - - when(mockRegionFactory.setRegionIdleTimeout(any(ExpirationAttributes.class))) - .thenAnswer(newSetter(regionIdleTimeout, mockRegionFactory)); - - when(mockRegionFactory.setRegionTimeToLive(any(ExpirationAttributes.class))) - .thenAnswer(newSetter(regionTimeToLive, mockRegionFactory)); - - when(mockRegionFactory.setScope(any(Scope.class))).thenAnswer(newSetter(scope, mockRegionFactory)); - - when(mockRegionFactory.setStatisticsEnabled(anyBoolean())) - .thenAnswer(newSetter(statisticsEnabled, mockRegionFactory)); - - when(mockRegionFactory.setSubscriptionAttributes(any(SubscriptionAttributes.class))) - .thenAnswer(newSetter(subscriptionAttributes, mockRegionFactory)); - - when(mockRegionFactory.setValueConstraint(any(Class.class))) - .thenAnswer(newSetter(valueConstraint, mockRegionFactory)); - - RegionAttributes mockRegionAttributes = - mock(RegionAttributes.class, mockObjectIdentifier("MockRegionAttributes")); - - when(mockRegionAttributes.getAsyncEventQueueIds()).thenReturn(asyncEventQueueIds); - - when(mockRegionAttributes.getCacheListeners()) - .thenAnswer(newGetter(() -> cacheListeners.toArray(new CacheListener[cacheListeners.size()]))); - - when(mockRegionAttributes.getCacheLoader()).thenAnswer(newGetter(cacheLoader)); - when(mockRegionAttributes.getCacheWriter()).thenAnswer(newGetter(cacheWriter)); - when(mockRegionAttributes.getCloningEnabled()).thenAnswer(newGetter(cloningEnabled)); - when(mockRegionAttributes.getCompressor()).thenAnswer(newGetter(compressor)); - when(mockRegionAttributes.getConcurrencyChecksEnabled()).thenAnswer(newGetter(concurrencyChecksEnabled)); - when(mockRegionAttributes.getConcurrencyLevel()).thenAnswer(newGetter(concurrencyLevel)); - when(mockRegionAttributes.getCustomEntryIdleTimeout()).thenAnswer(newGetter(customEntryIdleTimeout)); - when(mockRegionAttributes.getCustomEntryTimeToLive()).thenAnswer(newGetter(customEntryTimeToLive)); - when(mockRegionAttributes.getDataPolicy()).thenAnswer(newGetter(dataPolicy)); - when(mockRegionAttributes.getDiskStoreName()).thenAnswer(newGetter(diskStoreName)); - when(mockRegionAttributes.isDiskSynchronous()).thenAnswer(newGetter(diskSynchronous)); - when(mockRegionAttributes.getEnableAsyncConflation()).thenAnswer(newGetter(enableAsyncConflation)); - when(mockRegionAttributes.getEnableSubscriptionConflation()).thenAnswer(newGetter(enableSubscriptionConflation)); - when(mockRegionAttributes.getEntryIdleTimeout()).thenAnswer(newGetter(entryIdleTimeout)); - when(mockRegionAttributes.getEntryTimeToLive()).thenAnswer(newGetter(entryTimeToLive)); - when(mockRegionAttributes.getEvictionAttributes()).thenAnswer(newGetter(evictionAttributes)); - when(mockRegionAttributes.getGatewaySenderIds()).thenReturn(gatewaySenderIds); - when(mockRegionAttributes.getIgnoreJTA()).thenAnswer(newGetter(ignoreJta)); - when(mockRegionAttributes.getIndexMaintenanceSynchronous()).thenAnswer(newGetter(indexMaintenanceSynchronous)); - when(mockRegionAttributes.getInitialCapacity()).thenAnswer(newGetter(initialCapacity)); - when(mockRegionAttributes.getKeyConstraint()).thenAnswer(newGetter(keyConstraint)); - when(mockRegionAttributes.getLoadFactor()).thenAnswer(newGetter(loadFactor)); - when(mockRegionAttributes.isLockGrantor()).thenAnswer(newGetter(lockGrantor)); - when(mockRegionAttributes.getMulticastEnabled()).thenAnswer(newGetter(multicastEnabled)); - when(mockRegionAttributes.getOffHeap()).thenAnswer(newGetter(offHeap)); - when(mockRegionAttributes.getPartitionAttributes()).thenAnswer(newGetter(partitionAttributes)); - when(mockRegionAttributes.getPoolName()).thenAnswer(newGetter(poolName)); - when(mockRegionAttributes.getRegionIdleTimeout()).thenAnswer(newGetter(regionIdleTimeout)); - when(mockRegionAttributes.getRegionTimeToLive()).thenAnswer(newGetter(regionTimeToLive)); - when(mockRegionAttributes.getScope()).thenAnswer(newGetter(scope)); - when(mockRegionAttributes.getStatisticsEnabled()).thenAnswer(newGetter(statisticsEnabled)); - when(mockRegionAttributes.getSubscriptionAttributes()).thenAnswer(newGetter(subscriptionAttributes)); - when(mockRegionAttributes.getValueConstraint()).thenAnswer(newGetter(valueConstraint)); - - when(mockRegionFactory.create(anyString())).thenAnswer(invocation -> - mockRegion(mockCache, invocation.getArgument(0), mockRegionAttributes)); - - when(mockRegionFactory.createSubregion(any(Region.class), anyString())).thenAnswer(invocation -> - mockSubRegion(invocation.getArgument(0), invocation.getArgument(1), mockRegionAttributes)); - - return mockRegionFactory; - } - - public static ResourceManager mockResourceManager() { - - ResourceManager mockResourceManager = mock(ResourceManager.class); - - AtomicReference criticalHeapPercentage = - new AtomicReference<>(ResourceManager.DEFAULT_CRITICAL_PERCENTAGE); - - AtomicReference criticalOffHeapPercentage = new AtomicReference<>(0.0f); - - AtomicReference evictionHeapPercentage = - new AtomicReference<>(ResourceManager.DEFAULT_EVICTION_PERCENTAGE); - - AtomicReference evictionOffHeapPercentage = new AtomicReference<>(0.0f); - - doAnswer(newSetter(criticalHeapPercentage, null)) - .when(mockResourceManager).setCriticalHeapPercentage(anyFloat()); - - doAnswer(newSetter(criticalOffHeapPercentage, null)) - .when(mockResourceManager).setCriticalOffHeapPercentage(anyFloat()); - - doAnswer(newSetter(evictionHeapPercentage, null)) - .when(mockResourceManager).setEvictionHeapPercentage(anyFloat()); - - doAnswer(newSetter(evictionOffHeapPercentage, null)) - .when(mockResourceManager).setEvictionOffHeapPercentage(anyFloat()); - - when(mockResourceManager.getCriticalHeapPercentage()).thenAnswer(newGetter(criticalHeapPercentage)); - when(mockResourceManager.getCriticalOffHeapPercentage()).thenAnswer(newGetter(criticalOffHeapPercentage)); - when(mockResourceManager.getEvictionHeapPercentage()).thenAnswer(newGetter(evictionHeapPercentage)); - when(mockResourceManager.getEvictionOffHeapPercentage()).thenAnswer(newGetter(evictionOffHeapPercentage)); - when(mockResourceManager.getRebalanceOperations()).thenReturn(Collections.emptySet()); - - return mockResourceManager; - } - - public static CacheFactory spyOn(CacheFactory cacheFactory) { - return spyOn(cacheFactory, DEFAULT_USE_SINGLETON_CACHE); - } - - public static CacheFactory spyOn(CacheFactory cacheFactory, boolean useSingletonCache) { - - CacheFactory cacheFactorySpy = spy(cacheFactory); - - Cache resolvedMockCache = GemFireMockObjectsSupport.resolveMockedGemFireCache(useSingletonCache) - .orElseGet(() -> { - - Cache mockCache = mockPeerCache(); - - AtomicBoolean pdxIgnoreUnreadFields = new AtomicBoolean(false); - AtomicBoolean pdxPersistent = new AtomicBoolean(false); - AtomicBoolean pdxReadSerialized = new AtomicBoolean(false); - - AtomicReference pdxDiskStoreName = new AtomicReference<>(null); - AtomicReference pdxSerializer = new AtomicReference<>(null); - - doAnswer(newSetter(pdxDiskStoreName, cacheFactorySpy)) - .when(cacheFactorySpy).setPdxDiskStore(anyString()); - - doAnswer(newSetter(pdxIgnoreUnreadFields, cacheFactorySpy)) - .when(cacheFactorySpy).setPdxIgnoreUnreadFields(anyBoolean()); - - doAnswer(newSetter(pdxPersistent, cacheFactorySpy)) - .when(cacheFactorySpy).setPdxPersistent(anyBoolean()); - - doAnswer(newSetter(pdxReadSerialized, cacheFactorySpy)) - .when(cacheFactorySpy).setPdxReadSerialized(anyBoolean()); - - doAnswer(newSetter(pdxSerializer, cacheFactorySpy)) - .when(cacheFactorySpy).setPdxSerializer(any(PdxSerializer.class)); - - when(mockCache.getPdxDiskStore()).thenAnswer(newGetter(pdxDiskStoreName)); - when(mockCache.getPdxIgnoreUnreadFields()).thenAnswer(newGetter(pdxIgnoreUnreadFields)); - when(mockCache.getPdxPersistent()).thenAnswer(newGetter(pdxPersistent)); - when(mockCache.getPdxReadSerialized()).thenAnswer(newGetter(pdxReadSerialized)); - when(mockCache.getPdxSerializer()).thenAnswer(newGetter(pdxSerializer)); - - return mockCache; - }); - - doReturn(rememberMockedGemFireCache(resolvedMockCache, useSingletonCache)).when(cacheFactorySpy).create(); - - return cacheFactorySpy; - } - - public static ClientCacheFactory spyOn(ClientCacheFactory clientCacheFactory) { - return spyOn(clientCacheFactory, DEFAULT_USE_SINGLETON_CACHE); - } - - public static ClientCacheFactory spyOn(ClientCacheFactory clientCacheFactory, boolean useSingletonCache) { - - ClientCacheFactory clientCacheFactorySpy = spy(clientCacheFactory); - - ClientCache resolvedMockedClientCache = - GemFireMockObjectsSupport.resolveMockedGemFireCache(useSingletonCache).orElseGet(() -> { - - ClientCache mockClientCache = mockClientCache(); - - AtomicBoolean pdxIgnoreUnreadFields = new AtomicBoolean(false); - AtomicBoolean pdxPersistent = new AtomicBoolean(false); - AtomicBoolean pdxReadSerialized = new AtomicBoolean(false); - - AtomicReference pdxDiskStoreName = new AtomicReference<>(null); - AtomicReference pdxSerializer = new AtomicReference<>(null); - AtomicReference defaultPool = new AtomicReference<>(null); - - doAnswer(newSetter(pdxDiskStoreName, clientCacheFactorySpy)) - .when(clientCacheFactorySpy).setPdxDiskStore(anyString()); - - doAnswer(newSetter(pdxIgnoreUnreadFields, clientCacheFactorySpy)) - .when(clientCacheFactorySpy).setPdxIgnoreUnreadFields(anyBoolean()); - - doAnswer(newSetter(pdxPersistent, clientCacheFactorySpy)) - .when(clientCacheFactorySpy).setPdxPersistent(anyBoolean()); - - doAnswer(newSetter(pdxReadSerialized, clientCacheFactorySpy)) - .when(clientCacheFactorySpy).setPdxReadSerialized(anyBoolean()); - - doAnswer(newSetter(pdxSerializer, clientCacheFactorySpy)) - .when(clientCacheFactorySpy).setPdxSerializer(any(PdxSerializer.class)); - - PoolFactory mockPoolFactory = mockPoolFactory(); - - doAnswer(invocation -> { - mockPoolFactory.addLocator(invocation.getArgument(0), invocation.getArgument(1)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).addPoolLocator(anyString(), anyInt()); - - doAnswer(invocation -> { - mockPoolFactory.addServer(invocation.getArgument(0), invocation.getArgument(1)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).addPoolServer(anyString(), anyInt()); - - doAnswer(invocation -> { - mockPoolFactory.setFreeConnectionTimeout(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolFreeConnectionTimeout(anyInt()); - - doAnswer(invocation -> { - mockPoolFactory.setIdleTimeout(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolIdleTimeout(anyLong()); - - doAnswer(invocation -> { - mockPoolFactory.setLoadConditioningInterval(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolLoadConditioningInterval(anyInt()); - - doAnswer(invocation -> { - mockPoolFactory.setMaxConnections(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolMaxConnections(anyInt()); - - doAnswer(invocation -> { - mockPoolFactory.setMinConnections(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolMinConnections(anyInt()); - - doAnswer(invocation -> { - mockPoolFactory.setMultiuserAuthentication(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolMultiuserAuthentication(anyBoolean()); - - doAnswer(invocation -> { - mockPoolFactory.setPingInterval(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolPingInterval(anyLong()); - - doAnswer(invocation -> { - mockPoolFactory.setPRSingleHopEnabled(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolPRSingleHopEnabled(anyBoolean()); - - doAnswer(invocation -> { - mockPoolFactory.setReadTimeout(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolReadTimeout(anyInt()); - - doAnswer(invocation -> { - mockPoolFactory.setRetryAttempts(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolRetryAttempts(anyInt()); - - doAnswer(invocation -> { - mockPoolFactory.setServerConnectionTimeout(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolServerConnectionTimeout(anyInt()); - - doAnswer(invocation -> { - mockPoolFactory.setServerGroup(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolServerGroup(anyString()); - - doAnswer(invocation -> { - mockPoolFactory.setSocketBufferSize(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolSocketBufferSize(anyInt()); - - doAnswer(invocation -> { - mockPoolFactory.setSocketConnectTimeout(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolSocketConnectTimeout(anyInt()); - - doAnswer(invocation -> { - mockPoolFactory.setSocketFactory(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolSocketFactory(any()); - - doAnswer(invocation -> { - mockPoolFactory.setStatisticInterval(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolStatisticInterval(anyInt()); - - doAnswer(invocation -> { - mockPoolFactory.setSubscriptionAckInterval(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolSubscriptionAckInterval(anyInt()); - - doAnswer(invocation -> { - mockPoolFactory.setSubscriptionEnabled(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolSubscriptionEnabled(anyBoolean()); - - doAnswer(invocation -> { - mockPoolFactory.setSubscriptionMessageTrackingTimeout(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolSubscriptionMessageTrackingTimeout(anyInt()); - - doAnswer(invocation -> { - mockPoolFactory.setSubscriptionRedundancy(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolSubscriptionRedundancy(anyInt()); - - doAnswer(invocation -> { - mockPoolFactory.setThreadLocalConnections(invocation.getArgument(0)); - return clientCacheFactorySpy; - }).when(clientCacheFactorySpy).setPoolThreadLocalConnections(anyBoolean()); - - when(mockClientCache.getCurrentServers()).thenAnswer(invocation -> - Collections.unmodifiableSet(new HashSet<>(defaultPool.get().getServers()))); - - when(mockClientCache.getDefaultPool()).thenAnswer(invocation -> { - - if (defaultPool.get() == null) { - defaultPool.set(mockPoolFactory.create("DEFAULT")); - } - - return defaultPool.get(); - }); - - when(mockClientCache.getPdxDiskStore()).thenAnswer(newGetter(pdxDiskStoreName)); - when(mockClientCache.getPdxIgnoreUnreadFields()).thenAnswer(newGetter(pdxIgnoreUnreadFields)); - when(mockClientCache.getPdxPersistent()).thenAnswer(newGetter(pdxPersistent)); - when(mockClientCache.getPdxReadSerialized()).thenAnswer(newGetter(pdxReadSerialized)); - when(mockClientCache.getPdxSerializer()).thenAnswer(newGetter(pdxSerializer)); - - return mockClientCache; - }); - - doReturn(rememberMockedGemFireCache(resolvedMockedClientCache, useSingletonCache)) - .when(clientCacheFactorySpy).create(); - - return clientCacheFactorySpy; - } - - protected interface ExceptionThrowingOperation { - T doExceptionThrowingOperation() throws Exception; - } - - protected interface IoExceptionThrowingOperation { - void doIo() throws IOException; - } - - public static class LuceneIndexKey { - - private final String indexName; - private final String regionPath; - - public static LuceneIndexKey of(String indexName, Region region) { - - Assert.notNull(region, "Region is required"); - - return of(indexName, region.getFullPath()); - } - - public static LuceneIndexKey of(String indexName, String regionPath) { - return new LuceneIndexKey(indexName, regionPath); - } - - private LuceneIndexKey(String indexName, String regionPath) { - - Assert.hasText(indexName, String.format("LuceneIndex name [%s] is required", indexName)); - Assert.hasText(regionPath, String.format("Region path [%s] is required", regionPath)); - - this.indexName = indexName; - this.regionPath = regionPath; - } - - protected String getIndexName() { - return this.indexName; - } - - protected String getRegionPath() { - return this.regionPath; - } - - @Override - public boolean equals(Object obj) { - - if (obj == this) { - return true; - } - - if (!(obj instanceof LuceneIndexKey)) { - return false; - } - - LuceneIndexKey that = (LuceneIndexKey) obj; - - return this.getIndexName().equals(that.getIndexName()) - && this.getRegionPath().equals(that.getRegionPath()); - } - - @Override - public int hashCode() { - - int hashValue = 17; - - hashValue = 37 * hashValue + getIndexName().hashCode(); - hashValue = 37 * hashValue + getRegionPath().hashCode(); - - return hashValue; - } - - @Override - public String toString() { - return String.format("%1$s.%2$s", getRegionPath(), getIndexName()); - } - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/MockObjectsSupport.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/MockObjectsSupport.java deleted file mode 100644 index 6cd3ca0b..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/MockObjectsSupport.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright 2017-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.gemfire.test.mock; - -import java.util.Collection; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Supplier; - -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - -import org.springframework.util.StringUtils; - -/** - * The {@link MockObjectsSupport} class is an abstract base class encapsulating common operations and utilities - * used in mocking using Mockito. - * - * @author John Blum - * @see org.mockito.invocation.InvocationOnMock - * @see org.mockito.stubbing.Answer - * @since 2.0.0 - */ -@SuppressWarnings("unused") -public abstract class MockObjectsSupport { - - private static final AtomicLong mockObjectIdentifier = new AtomicLong(0L); - - private static final String DEFAULT_MOCK_OBJECT_NAME = "MockObject"; - - public static String mockObjectIdentifier() { - return mockObjectIdentifier(DEFAULT_MOCK_OBJECT_NAME); - } - - public static String mockObjectIdentifier(String mockObjectName) { - return String.format("%s%d", Optional.ofNullable(mockObjectName).filter(StringUtils::hasText) - .orElse(DEFAULT_MOCK_OBJECT_NAME), mockObjectIdentifier.incrementAndGet()); - } - - /* (non-Javadoc) */ - protected static Answer newGetter(AtomicBoolean returnValue) { - return invocation -> returnValue.get(); - } - - /* (non-Javadoc) */ - protected static Answer newGetter(AtomicInteger returnValue) { - return invocation -> returnValue.get(); - } - - /* (non-Javadoc) */ - protected static Answer newGetter(AtomicLong returnValue) { - return invocation -> returnValue.get(); - } - - /* (non-Javadoc) */ - protected static Answer newGetter(AtomicReference returnValue) { - return invocation -> returnValue.get(); - } - - /* (non-Javadoc) */ - protected static Answer newGetter(AtomicReference returnValue, Function converter) { - return invocation -> converter.apply(returnValue.get()); - } - - /* (non-Javadoc) */ - protected static Answer newGetter(Supplier returnValue) { - return invocation -> returnValue.get(); - } - - /* (non-Javadoc) */ - protected static Answer newGetter(Supplier returnValue, Function converter) { - return invocation -> converter.apply(returnValue.get()); - } - - /* (non-Javadoc) */ - protected static , R> Answer newAdder(C collection, R returnValue) { - return invocation -> { - collection.add(invocation.getArgument(0)); - return returnValue; - }; - } - - /* (non-Javadoc) */ - protected static Answer newSetter(AtomicBoolean argument, R returnValue) { - return invocation -> { - argument.set(invocation.getArgument(0)); - return returnValue; - }; - } - - /* (non-Javadoc) */ - protected static Answer newSetter(AtomicBoolean argument, Boolean value, R returnValue) { - return invocation -> { - argument.set(value); - return returnValue; - }; - } - - /* (non-Javadoc) */ - protected static Answer newSetter(AtomicInteger argument, R returnValue) { - return invocation -> { - argument.set(invocation.getArgument(0)); - return returnValue; - }; - } - - /* (non-Javadoc) */ - protected static Answer newSetter(AtomicInteger argument, Integer value, R returnValue) { - return invocation -> { - argument.set(value); - return returnValue; - }; - } - - /* (non-Javadoc) */ - protected static Answer newSetter(AtomicLong argument, R returnValue) { - return invocation -> { - argument.set(invocation.getArgument(0)); - return returnValue; - }; - } - - /* (non-Javadoc) */ - protected static Answer newSetter(AtomicLong argument, Long value, R returnValue) { - return invocation -> { - argument.set(value); - return returnValue; - }; - } - - /* (non-Javadoc) */ - protected static Answer newSetter(AtomicReference argument, R returnValue) { - return invocation -> { - argument.set(invocation.getArgument(0)); - return returnValue; - }; - } - - /* (non-Javadoc) */ - protected static Answer newSetter(AtomicReference argument, T value, R returnValue) { - return invocation -> { - argument.set(value); - return returnValue; - }; - } - - /* (non-Javadoc) */ - protected static Answer newSetter(AtomicReference argument, Function converter, R returnValue) { - return invocation -> { - argument.set(converter.apply(invocation.getArgument(0))); - return returnValue; - }; - } - - /* (non-Javadoc) */ - protected static Answer newSetter(Map argument, R returnValue) { - return invocation -> { - argument.put(invocation.getArgument(0), invocation.getArgument(1)); - return returnValue; - }; - } - - /* (non-Javadoc) */ - protected static Answer newVoidAnswer(Consumer methodInvocation) { - return invocation -> { - methodInvocation.accept(invocation); - return null; - }; - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/annotation/EnableGemFireMockObjects.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/annotation/EnableGemFireMockObjects.java deleted file mode 100644 index f92df097..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/annotation/EnableGemFireMockObjects.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2017-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.test.mock.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.apache.geode.cache.GemFireCache; - -import org.springframework.context.annotation.Import; - -/** - * The {@link EnableGemFireMockObjects} annotation enables mocking of GemFire Objects in Unit Tests. - * - * @author John Blum - * @see java.lang.annotation.Documented - * @see java.lang.annotation.Inherited - * @see java.lang.annotation.Retention - * @see java.lang.annotation.Target - * @see org.apache.geode.cache.GemFireCache - * @see org.springframework.context.annotation.Import - * @since 2.0.0 - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -@Inherited -@Documented -@Import(GemFireMockObjectsConfiguration.class) -@SuppressWarnings("unused") -public @interface EnableGemFireMockObjects { - - /** - * Determines whether the mock {@link GemFireCache} created for Unit Tests is a Singleton. - * - * Defaults to {@literal false}. - * - * @return a boolean value indicating whether the mock {@link GemFireCache} created for Unit Tests is a Singleton. - */ - boolean useSingletonCache() default false; - -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/annotation/GemFireMockObjectsConfiguration.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/annotation/GemFireMockObjectsConfiguration.java deleted file mode 100644 index c7d6012c..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/annotation/GemFireMockObjectsConfiguration.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2017-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.test.mock.annotation; - -import java.lang.annotation.Annotation; - -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.context.ApplicationListener; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportAware; -import org.springframework.context.event.ContextClosedEvent; -import org.springframework.context.event.EventListener; -import org.springframework.core.annotation.AnnotationAttributes; -import org.springframework.core.type.AnnotationMetadata; -import org.springframework.data.gemfire.test.mock.GemFireMockObjectsSupport; -import org.springframework.data.gemfire.test.mock.config.GemFireMockObjectsBeanPostProcessor; - -/** - * The {@link GemFireMockObjectsConfiguration} class is a Spring {@link Configuration @Configuration} class - * containing bean definitions to configure GemFire Object mocking. - * - * @author John Blum - * @see java.lang.annotation.Annotation - * @see org.springframework.beans.factory.config.BeanPostProcessor - * @see org.springframework.context.annotation.Bean - * @see org.springframework.context.annotation.Configuration - * @see org.springframework.context.annotation.ImportAware - * @see org.springframework.core.annotation.AnnotationAttributes - * @see org.springframework.core.type.AnnotationMetadata - * @see GemFireMockObjectsBeanPostProcessor - * @since 2.0.0 - */ -@SuppressWarnings("unused") -@Configuration -public class GemFireMockObjectsConfiguration implements ApplicationListener, ImportAware { - - private boolean useSingletonCache = false; - - @Override - public void setImportMetadata(AnnotationMetadata importingClassMetadata) { - - if (isAnnotationPresent(importingClassMetadata)) { - - AnnotationAttributes enableGemFireMockingAttributes = getAnnotationAttributes(importingClassMetadata); - - this.useSingletonCache = enableGemFireMockingAttributes.getBoolean("useSingletonCache"); - } - } - - private Class getAnnotationType() { - return EnableGemFireMockObjects.class; - } - - private boolean isAnnotationPresent(AnnotationMetadata importingClassMetadata) { - return isAnnotationPresent(importingClassMetadata, getAnnotationType()); - } - - private boolean isAnnotationPresent(AnnotationMetadata importingClassMetadata, - Class annotationType) { - - return importingClassMetadata.hasAnnotation(annotationType.getName()); - } - - private AnnotationAttributes getAnnotationAttributes(AnnotationMetadata importingClassMetadata) { - return getAnnotationAttributes(importingClassMetadata, getAnnotationType()); - } - - private AnnotationAttributes getAnnotationAttributes(AnnotationMetadata importingClassMetadata, - Class annotationType) { - - return AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(annotationType.getName())); - } - - @Bean - public BeanPostProcessor mockGemFireObjectsBeanPostProcessor() { - return GemFireMockObjectsBeanPostProcessor.newInstance(this.useSingletonCache); - } - - @EventListener - public void releaseMockObjectResources(ContextClosedEvent event) { - GemFireMockObjectsSupport.destroy(); - } - - @Override - public void onApplicationEvent(ContextClosedEvent event) { - releaseMockObjectResources(event); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/annotation/GemFireUnitTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/annotation/GemFireUnitTest.java deleted file mode 100644 index 2c401f61..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/annotation/GemFireUnitTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2017-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.test.mock.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.junit.runner.RunWith; - -import org.springframework.data.gemfire.test.mock.context.GemFireMockObjectsApplicationContextInitializer; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * The {@link GemFireUnitTest} annotation marks a test class as a GemFire Unit Test - * with GemFire Object mocking enabled. - * - * Additionally, this annotation enables Spring's {@link SpringRunner} JUnit Runner implementation - * using JUnit's {@link RunWith} annotation. - * - * @author John Blum - * @see java.lang.annotation.Documented - * @see java.lang.annotation.Inherited - * @see java.lang.annotation.Retention - * @see java.lang.annotation.Target - * @see org.junit.runner.RunWith - * @see GemFireMockObjectsApplicationContextInitializer - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringRunner - * @since 2.0.0 - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -@Inherited -@Documented -@RunWith(SpringRunner.class) -@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) -@SuppressWarnings("unused") -public @interface GemFireUnitTest { - -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/config/GemFireMockObjectsBeanPostProcessor.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/config/GemFireMockObjectsBeanPostProcessor.java deleted file mode 100644 index edf66b8a..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/config/GemFireMockObjectsBeanPostProcessor.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright 2017-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.test.mock.config; - -import static org.mockito.Mockito.when; - -import java.util.Properties; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.geode.cache.CacheFactory; -import org.apache.geode.cache.GemFireCache; -import org.apache.geode.cache.client.ClientCacheFactory; -import org.apache.geode.cache.client.PoolFactory; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.data.gemfire.CacheFactoryBean; -import org.springframework.data.gemfire.client.ClientCacheFactoryBean; -import org.springframework.data.gemfire.client.PoolFactoryBean; -import org.springframework.data.gemfire.test.mock.GemFireMockObjectsSupport; -import org.springframework.lang.Nullable; - -/** - * The {@link GemFireMockObjectsBeanPostProcessor} class is a Spring {@link BeanPostProcessor} that applies - * mocks and spies to Spring Data GemFire / Spring Data Geode and Pivotal GemFire / Apache Geode objects - * and components. - * - * @author John Blum - * @see org.apache.geode.cache.CacheFactory - * @see org.apache.geode.cache.client.ClientCacheFactory - * @see org.apache.geode.cache.client.PoolFactory - * @see org.springframework.beans.factory.config.BeanPostProcessor - * @see org.springframework.data.gemfire.CacheFactoryBean - * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean - * @see org.springframework.data.gemfire.client.PoolFactoryBean - * @see GemFireMockObjectsSupport - * @since 2.0.0 - */ -public class GemFireMockObjectsBeanPostProcessor implements BeanPostProcessor { - - private static final boolean DEFAULT_USE_SINGLETON_CACHE = false; - - private static final String GEMFIRE_PROPERTIES_BEAN_NAME = "gemfireProperties"; - - private volatile boolean useSingletonCache; - - private final AtomicReference gemfireProperties = new AtomicReference<>(new Properties()); - - public static GemFireMockObjectsBeanPostProcessor newInstance() { - return newInstance(DEFAULT_USE_SINGLETON_CACHE); - } - - public static GemFireMockObjectsBeanPostProcessor newInstance(boolean useSingletonCache) { - - GemFireMockObjectsBeanPostProcessor beanPostProcessor = new GemFireMockObjectsBeanPostProcessor(); - - beanPostProcessor.useSingletonCache = useSingletonCache; - - return beanPostProcessor; - } - - @Nullable @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - - return (isGemFireProperties(bean, beanName) ? set((Properties) bean) - : (bean instanceof CacheFactoryBean ? spyOnCacheFactoryBean((CacheFactoryBean) bean, this.useSingletonCache) - : (bean instanceof PoolFactoryBean ? mockThePoolFactoryBean((PoolFactoryBean) bean) - : bean))); - } - - @Nullable @Override - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - - if (bean instanceof GemFireCache) { - - GemFireCache gemfireCache = (GemFireCache) bean; - - when(gemfireCache.getDistributedSystem().getProperties()).thenReturn(this.gemfireProperties.get()); - } - - return bean; - } - - private boolean isGemFireProperties(Object bean, String beanName) { - return (bean instanceof Properties && GEMFIRE_PROPERTIES_BEAN_NAME.equals(beanName)); - } - - private Object set(Properties gemfireProperties) { - this.gemfireProperties.set(gemfireProperties); - return gemfireProperties; - } - - private Object spyOnCacheFactoryBean(CacheFactoryBean bean, boolean useSingletonCache) { - - return (bean instanceof ClientCacheFactoryBean - ? SpyingClientCacheFactoryInitializer.spyOn((ClientCacheFactoryBean) bean, useSingletonCache) - : SpyingCacheFactoryInitializer.spyOn(bean, useSingletonCache)); - } - - private Object mockThePoolFactoryBean(PoolFactoryBean bean) { - return MockingPoolFactoryInitializer.mock(bean); - } - - protected static class SpyingCacheFactoryInitializer - implements CacheFactoryBean.CacheFactoryInitializer { - - public static CacheFactoryBean spyOn(CacheFactoryBean cacheFactoryBean, boolean useSingletonCache) { - cacheFactoryBean.setCacheFactoryInitializer(new SpyingCacheFactoryInitializer(useSingletonCache)); - return cacheFactoryBean; - } - - private final boolean useSingletonCache; - - protected SpyingCacheFactoryInitializer(boolean useSingletonCache) { - this.useSingletonCache = useSingletonCache; - } - - @Override - public CacheFactory initialize(CacheFactory cacheFactory) { - return GemFireMockObjectsSupport.spyOn(cacheFactory, useSingletonCache); - } - } - - protected static class SpyingClientCacheFactoryInitializer - implements CacheFactoryBean.CacheFactoryInitializer { - - public static ClientCacheFactoryBean spyOn(ClientCacheFactoryBean clientCacheFactoryBean, - boolean useSingletonCache) { - - clientCacheFactoryBean.setCacheFactoryInitializer( - new SpyingClientCacheFactoryInitializer(useSingletonCache)); - - return clientCacheFactoryBean; - } - - private final boolean useSingletonCache; - - protected SpyingClientCacheFactoryInitializer(boolean useSingletonCache) { - this.useSingletonCache = useSingletonCache; - } - - @Override - public ClientCacheFactory initialize(ClientCacheFactory clientCacheFactory) { - return GemFireMockObjectsSupport.spyOn(clientCacheFactory, this.useSingletonCache); - } - } - - protected static class MockingPoolFactoryInitializer implements PoolFactoryBean.PoolFactoryInitializer { - - public static PoolFactoryBean mock(PoolFactoryBean poolFactoryBean) { - poolFactoryBean.setPoolFactoryInitializer(new MockingPoolFactoryInitializer()); - return poolFactoryBean; - } - - @Override - public PoolFactory initialize(PoolFactory poolFactory) { - return GemFireMockObjectsSupport.mockPoolFactory(); - } - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/context/GemFireMockObjectsApplicationContextInitializer.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/context/GemFireMockObjectsApplicationContextInitializer.java deleted file mode 100644 index 6eae0bda..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/context/GemFireMockObjectsApplicationContextInitializer.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2017-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.test.mock.context; - -import org.springframework.context.ApplicationContextInitializer; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.data.gemfire.test.mock.config.GemFireMockObjectsBeanPostProcessor; - -/** - * The {@link GemFireMockObjectsApplicationContextInitializer} class is a Spring {@link ApplicationContextInitializer} - * used to initialize the Spring {@link ConfigurableApplicationContext} with GemFire Object mocking. - * - * @author John Blum - * @see org.springframework.context.ApplicationContextInitializer - * @see org.springframework.context.ConfigurableApplicationContext - * @see GemFireMockObjectsBeanPostProcessor - * @since 2.0.0 - */ -public class GemFireMockObjectsApplicationContextInitializer - implements ApplicationContextInitializer { - - @Override - @SuppressWarnings("all") - public void initialize(ConfigurableApplicationContext applicationContext) { - applicationContext.getBeanFactory().addBeanPostProcessor(GemFireMockObjectsBeanPostProcessor.newInstance()); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/support/MockObjectInvocationException.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/support/MockObjectInvocationException.java deleted file mode 100644 index 4f15f477..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/support/MockObjectInvocationException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2017-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.test.mock.support; - -import java.lang.reflect.Method; - -/** - * The {@link MockObjectInvocationException} class is an extension of {@link MockObjectsException} to categorize - * problems with {@link Method method} invocations on {@link Object Mock Objects}. - * - * @author John Blum - * @see org.springframework.data.gemfire.test.mock.support.MockObjectsException - * @since 2.0.1 - */ -@SuppressWarnings("unused") -public class MockObjectInvocationException extends MockObjectsException { - - /** - * Constructs a new instance of the {@link MockObjectInvocationException} class with no message or underlying cause. - */ - public MockObjectInvocationException() { - } - - /** - * Constructs a new instance of the {@link MockObjectInvocationException} class initialized with - * the given {@link String message} describing the problem. - * - * @param message {@link String} describing the problem. - * @see java.lang.String - */ - public MockObjectInvocationException(String message) { - super(message); - } - - /** - * Constructs a new instance of the {@link MockObjectInvocationException} class initialized with - * the given {@link Throwable cause} of the underlying problem. - * - * @param cause {@link Throwable} object containing the cause of this exception. - * @see java.lang.Throwable - */ - public MockObjectInvocationException(Throwable cause) { - super(cause); - } - - /** - * Constructs a new instance of the {@link MockObjectInvocationException} class initialized with - * the given {@link String message} describing the underlying problem as well as the {@link Throwable cause} - * of the underlying problem. - * - * @param message {@link String} describing the problem. - * @param cause {@link Throwable} object containing the cause of this exception. - * @see java.lang.Throwable - * @see java.lang.String - */ - public MockObjectInvocationException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/support/MockObjectsException.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/support/MockObjectsException.java deleted file mode 100644 index a8804ae1..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/mock/support/MockObjectsException.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2017-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.test.mock.support; - -/** - * The {@link MockObjectsException} class is a {@link RuntimeException} indicating a general problem - * with the Mock Objects infrastructure. - * - * @author John Blum - * @see java.lang.RuntimeException - * @since 2.0.1 - */ -@SuppressWarnings("unused") -public class MockObjectsException extends RuntimeException { - - /** - * Constructs a new instance of the {@link MockObjectsException} class with no message or underlying cause. - */ - public MockObjectsException() { - } - - /** - * Constructs a new instance of the {@link MockObjectsException} class initialized with - * the given {@link String message} describing the problem. - * - * @param message {@link String} describing the problem. - * @see java.lang.String - */ - public MockObjectsException(String message) { - super(message); - } - - /** - * Constructs a new instance of the {@link MockObjectsException} class initialized with - * the given {@link Throwable cause} of the underlying problem. - * - * @param cause {@link Throwable} object containing the cause of this exception. - * @see java.lang.Throwable - */ - public MockObjectsException(Throwable cause) { - super(cause); - } - - /** - * Constructs a new instance of the {@link MockObjectsException} class initialized with - * the given {@link String message} describing the underlying problem as well as the {@link Throwable cause} - * of the underlying problem. - * - * @param message {@link String} describing the problem. - * @param cause {@link Throwable} object containing the cause of this exception. - * @see java.lang.Throwable - * @see java.lang.String - */ - public MockObjectsException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/model/Person.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/model/Person.java index f6ef6db3..42ac985e 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/model/Person.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/model/Person.java @@ -27,7 +27,7 @@ import org.springframework.data.annotation.Id; import org.springframework.data.annotation.PersistenceConstructor; import org.springframework.data.gemfire.mapping.annotation.Indexed; import org.springframework.data.gemfire.mapping.annotation.Region; -import org.springframework.data.gemfire.test.support.IdentifierSequence; +import org.springframework.data.gemfire.tests.support.IdentifierSequence; import org.springframework.data.gemfire.util.SpringUtils; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractGemFireClientServerIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractGemFireClientServerIntegrationTest.java deleted file mode 100644 index 1566eeda..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractGemFireClientServerIntegrationTest.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2016-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.springframework.data.gemfire.test.support; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import org.springframework.data.gemfire.fork.ServerProcess; -import org.springframework.data.gemfire.process.ProcessExecutor; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.util.Assert; - -/** - * The {@link AbstractGemFireClientServerIntegrationTest} class is an abstract test suite base class - * encapsulating functionality common to all test classes implementing client/server test cases. - * - * @author John Blum - * @see org.springframework.data.gemfire.fork.ServerProcess - * @see org.springframework.data.gemfire.process.ProcessExecutor - * @see org.springframework.data.gemfire.process.ProcessWrapper - * @since 1.8.0 - */ -@Deprecated -@SuppressWarnings("unused") -public abstract class AbstractGemFireClientServerIntegrationTest { - - protected static final long DEFAULT_TIME_TO_WAIT_FOR_SERVER_TO_START = TimeUnit.SECONDS.toMillis(20); - protected static final long FIVE_HUNDRED_MILLISECONDS = TimeUnit.MILLISECONDS.toMillis(500); - protected static final long ONE_SECOND_IN_MILLISECONDS = TimeUnit.SECONDS.toMillis(1); - - protected static String CLEAN_PROCESS_WORKING_DIRECTORY_SYSTEM_PROPERTY = "spring.data.gemfire.force.clean"; - - protected static void pause(final long duration) { - ThreadUtils.timedWait(Math.max(duration, ONE_SECOND_IN_MILLISECONDS), ONE_SECOND_IN_MILLISECONDS, () -> true); - } - - protected static T setSystemProperty(String propertyName, T propertyValue) { - - System.setProperty(propertyName, String.valueOf(propertyValue)); - - return propertyValue; - } - - protected static ProcessWrapper startGemFireServer(Class testClass) throws IOException { - return startGemFireServer(testClass, DEFAULT_TIME_TO_WAIT_FOR_SERVER_TO_START); - } - - protected static ProcessWrapper startGemFireServer(Class testClass, long waitTimeInMilliseconds) - throws IOException { - - Assert.notNull(testClass, "testClass must not be null"); - - String serverName = testClass.getSimpleName() + "Server"; - - File serverWorkingDirectory = new File(FileSystemUtils.WORKING_DIRECTORY, serverName.toLowerCase()); - - Assert.isTrue(serverWorkingDirectory.isDirectory() || serverWorkingDirectory.mkdirs()); - - List arguments = new ArrayList<>(); - - addTestClassSystemProperties(testClass, arguments) - .add(String.format("-Dgemfire.name=%1$s", serverName)); - - arguments.add("/".concat(testClass.getName().replace(".", "/").concat("-server-context.xml"))); - - ProcessWrapper gemfireServerProcess = - ProcessExecutor.launch(serverWorkingDirectory, ServerProcess.class, arguments.toArray(new String[0])); - - waitForServerToStart(gemfireServerProcess, waitTimeInMilliseconds); - - return gemfireServerProcess; - } - - static List addTestClassSystemProperties(Class testClass, List arguments) { - - String testClassName = testClass.getName(); - - System.getProperties().stringPropertyNames().stream() - .filter(propertyName -> propertyName.startsWith(testClassName)) - .forEach(propertyName -> { - - String argument = String.format("-D%1$s=%2$s", propertyName, System.getProperty(propertyName)); - - arguments.add(argument); - }); - - return arguments; - } - - static void waitForServerToStart(final ProcessWrapper process, long duration) { - - ThreadUtils.timedWait(Math.max(duration, FIVE_HUNDRED_MILLISECONDS), FIVE_HUNDRED_MILLISECONDS, - - new ThreadUtils.WaitCondition() { - - private File processPidFile = - new File(process.getWorkingDirectory(), ServerProcess.getServerProcessControlFilename()); - - @Override - public boolean waiting() { - return !processPidFile.isFile(); - } - } - ); - } - - protected static ProcessWrapper stopGemFireServer(ProcessWrapper process) { - - try { - - process.shutdown(); - - boolean springGemFireForceClean = - Boolean.valueOf(System.getProperty(CLEAN_PROCESS_WORKING_DIRECTORY_SYSTEM_PROPERTY, - String.valueOf(true))); - - if (springGemFireForceClean) { - org.springframework.util.FileSystemUtils.deleteRecursively(process.getWorkingDirectory()); - } - - return null; - } - catch (Exception ignore) { - return process; - } - } - - protected static void clearTestClassSystemProperties(Class testClass) { - - String testClassName = testClass.getName(); - - System.getProperties().stringPropertyNames().stream() - .filter(propertyName -> propertyName.startsWith(testClassName)) - .forEach(propertyName -> System.clearProperty(propertyName)); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractNativeCacheTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractNativeCacheTests.java index ec766803..2af2dfd6 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractNativeCacheTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractNativeCacheTests.java @@ -14,7 +14,6 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.test.support; import static org.assertj.core.api.Assertions.assertThat; @@ -37,13 +36,15 @@ public abstract class AbstractNativeCacheTests { protected static final String CACHE_NAME = "Example"; private T nativeCache; + private Cache cache; @Before public void setUp() throws Exception { - nativeCache = newNativeCache(); - cache = newCache(nativeCache); - cache.clear(); + + this.nativeCache = newNativeCache(); + this.cache = newCache(nativeCache); + this.cache.clear(); } @SuppressWarnings("unchecked") @@ -56,50 +57,53 @@ public abstract class AbstractNativeCacheTests { protected abstract T newNativeCache() throws Exception; @Test - public void cacheNameIsEqualToExpected() throws Exception { + public void cacheNameIsEqualToExpected() { assertThat(cache.getName()).isEqualTo(CACHE_NAME); } @Test - public void nativeCacheIsSameAsExpected() throws Exception { - assertThat(cache.getNativeCache()).isSameAs(nativeCache); + public void nativeCacheIsSameAsExpected() { + assertThat(this.cache.getNativeCache()).isSameAs(this.nativeCache); } @Test - public void cachePutIsSuccessful() throws Exception { - assertThat(cache.get("enescu")).isNull(); + public void cachePutIsSuccessful() { - cache.put("enescu", "george"); + assertThat(this.cache.get("enescu")).isNull(); - assertThat(cache.get("enescu").get()).isEqualTo("george"); + this.cache.put("enescu", "george"); + + assertThat(this.cache.get("enescu").get()).isEqualTo("george"); } @Test - public void cachePutThenClearIsSuccessful() throws Exception { - cache.put("enescu", "george"); - cache.put("vlaicu", "aurel"); + public void cachePutThenClearIsSuccessful() { - assertThat(cache.get("enescu", String.class)).isEqualTo("george"); - assertThat(cache.get("vlaicu", String.class)).isEqualTo("aurel"); + this.cache.put("enescu", "george"); + this.cache.put("vlaicu", "aurel"); - cache.clear(); + assertThat(this.cache.get("enescu", String.class)).isEqualTo("george"); + assertThat(this.cache.get("vlaicu", String.class)).isEqualTo("aurel"); - assertThat(cache.get("vlaicu")).isNull(); - assertThat(cache.get("enescu")).isNull(); + this.cache.clear(); + + assertThat(this.cache.get("vlaicu")).isNull(); + assertThat(this.cache.get("enescu")).isNull(); } @Test public void cachePutThenGetForClassTypeIsSuccessful() { - cache.put("one", Boolean.TRUE); - cache.put("two", 'X'); - cache.put("three", 101); - cache.put("four", Math.PI); - cache.put("five", "TEST"); - assertThat(cache.get("one", Boolean.class)).isTrue(); - assertThat(cache.get("two", Character.class)).isEqualTo('X'); - assertThat(cache.get("three", Integer.class)).isEqualTo(101); - assertThat(cache.get("four", Double.class)).isEqualTo(Math.PI); - assertThat(cache.get("five", String.class)).isEqualTo("TEST"); + this.cache.put("one", Boolean.TRUE); + this.cache.put("two", 'X'); + this.cache.put("three", 101); + this.cache.put("four", Math.PI); + this.cache.put("five", "TEST"); + + assertThat(this.cache.get("one", Boolean.class)).isTrue(); + assertThat(this.cache.get("two", Character.class)).isEqualTo('X'); + assertThat(this.cache.get("three", Integer.class)).isEqualTo(101); + assertThat(this.cache.get("four", Double.class)).isEqualTo(Math.PI); + assertThat(this.cache.get("five", String.class)).isEqualTo("TEST"); } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractRegionFactoryBeanTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractRegionFactoryBeanTests.java index cee3e53e..5ee2a947 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractRegionFactoryBeanTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractRegionFactoryBeanTests.java @@ -14,7 +14,6 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.test.support; import java.io.File; @@ -29,7 +28,7 @@ import org.junit.Test; import org.apache.geode.cache.GemFireCache; import org.springframework.data.gemfire.PeerRegionFactoryBean; -import org.springframework.data.gemfire.test.StubCache; +import org.springframework.data.gemfire.tests.mock.GemFireMockObjectsSupport; /** * @author David Turanski @@ -39,41 +38,46 @@ public abstract class AbstractRegionFactoryBeanTests { private GemFireCache cache; - private Map regionFactoryBeanConfigs = new HashMap<>(); + private final Map regionFactoryBeanConfigs = new HashMap<>(); @AfterClass - public static void cleanUp() { + public static void cleanup() { + for (String name : new File(".").list((dir, name1) -> name1.startsWith("BACKUP"))) { new File(name).delete(); } + + GemFireMockObjectsSupport.destroy(); } @Before public void setUp() throws Exception { - cache = new StubCache(); + this.cache = GemFireMockObjectsSupport.mockPeerCache(); } @After public void tearDown() { - cache.close(); - cache = null; + this.cache.close(); + this.cache = null; } @Test - public void testAll() throws Exception { + public void testAll() { + createRegionFactoryBeanConfigs(); - for (RegionFactoryBeanConfig regionFactoryBeanConfig : regionFactoryBeanConfigs.values()) { + for (RegionFactoryBeanConfig regionFactoryBeanConfig : this.regionFactoryBeanConfigs.values()) { regionFactoryBeanConfig.test(); } } protected void add(RegionFactoryBeanConfig regionFactoryBeanConfig) { - if (regionFactoryBeanConfigs.containsKey(regionFactoryBeanConfig.regionName)) { + + if (this.regionFactoryBeanConfigs.containsKey(regionFactoryBeanConfig.regionName)) { throw new RuntimeException("duplicate region name " + regionFactoryBeanConfig.regionName); } - regionFactoryBeanConfigs.put(regionFactoryBeanConfig.regionName, regionFactoryBeanConfig); + this.regionFactoryBeanConfigs.put(regionFactoryBeanConfig.regionName, regionFactoryBeanConfig); } protected abstract void createRegionFactoryBeanConfigs(); @@ -89,6 +93,7 @@ public abstract class AbstractRegionFactoryBeanTests { @SuppressWarnings("rawtypes") public RegionFactoryBeanConfig(PeerRegionFactoryBean regionFactoryBean, String regionName) { + this.regionFactoryBean = regionFactoryBean; this.regionName = regionName; regionFactoryBean.setBeanName(regionName); @@ -98,6 +103,7 @@ public abstract class AbstractRegionFactoryBeanTests { public abstract void configureRegionFactoryBean(); public void test() { + configureRegionFactoryBean(); try { @@ -111,5 +117,6 @@ public abstract class AbstractRegionFactoryBeanTests { } public abstract void verify(); + } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractUnitAndIntegrationTestsWithMockSupport.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractUnitAndIntegrationTestsWithMockSupport.java deleted file mode 100644 index c0d3eff2..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractUnitAndIntegrationTestsWithMockSupport.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.test.support; - -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; -import org.springframework.util.StringUtils; - -/** - * {@link AbstractUnitAndIntegrationTestsWithMockSupport} is an abstract base class for test classes - * having support for the creation and use of mock objects in test cases, but that may also be ran - * as integration tests using actual GemFire components (e.g. Regions, etc). - * - * @author John Blum - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer - * @since 1.5.3 - */ -@SuppressWarnings("unused") -public abstract class AbstractUnitAndIntegrationTestsWithMockSupport { - - protected static final String GEMFIRE_TEST_RUNNER_NO_MOCK = - System.getProperty(GemfireTestApplicationContextInitializer.GEMFIRE_TEST_RUNNER_DISABLED, "false"); - - protected static final String NOT_IMPLEMENTED = "Not Implemented"; - - /* (non-Javadoc) */ - protected boolean isMocking() { - String gemfireTestRunnerNoMock = StringUtils.trimWhitespace(GEMFIRE_TEST_RUNNER_NO_MOCK); - - return !(Boolean.parseBoolean(gemfireTestRunnerNoMock) - || "yes".equalsIgnoreCase(gemfireTestRunnerNoMock) - || "y".equalsIgnoreCase(gemfireTestRunnerNoMock)); - } - - /* (non-Javadoc) */ - protected boolean isNotMocking() { - return !isMocking(); - } - - /* (non-Javadoc) */ - protected Object getMockId() { - StackTraceElement element = StackTraceUtils.getTestCaller(); - return (element != null ? StackTraceUtils.getCallerSimpleName(element) : IdentifierSequence.nextId()); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/ClientServerIntegrationTestsSupport.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/ClientServerIntegrationTestsSupport.java deleted file mode 100644 index 57e3eb79..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/ClientServerIntegrationTestsSupport.java +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Copyright 2016-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.springframework.data.gemfire.test.support; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.data.gemfire.process.ProcessExecutor.launch; -import static org.springframework.data.gemfire.util.ArrayUtils.asArray; - -import java.io.File; -import java.io.IOException; -import java.net.ServerSocket; -import java.net.Socket; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Optional; -import java.util.Scanner; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.apache.geode.cache.server.CacheServer; - -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.util.CollectionUtils; - -/** - * The {@link ClientServerIntegrationTestsSupport} class is a abstract base class encapsulating common functionality - * to support the implementation of GemFire client/server tests. - * - * @author John Blum - * @see java.io.File - * @see java.net.ServerSocket - * @see java.net.Socket - * @see java.time.LocalDateTime - * @see org.apache.geode.cache.server.CacheServer - * @see org.springframework.context.annotation.AnnotationConfigApplicationContext - * @see org.springframework.data.gemfire.process.ProcessExecutor - * @see org.springframework.data.gemfire.process.ProcessWrapper - * @see org.springframework.data.gemfire.test.support.SocketUtils - * @see org.springframework.data.gemfire.test.support.ThreadUtils - * @since 1.9.0 - */ -@SuppressWarnings("unused") -public class ClientServerIntegrationTestsSupport { - - protected static final long DEFAULT_WAIT_DURATION = TimeUnit.SECONDS.toMillis(30); - protected static final long DEFAULT_WAIT_INTERVAL = 500L; // milliseconds - - protected static final String DEBUG_ENDPOINT = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"; - protected static final String DEBUGGING_ENABLED_PROPERTY = "spring.data.gemfire.debugging.enabled"; - protected static final String DEFAULT_HOSTNAME = "localhost"; - protected static final String DIRECTORY_DELETE_ON_EXIT_PROPERTY = "spring.data.gemfire.directory.delete-on-exit"; - protected static final String GEMFIRE_CACHE_SERVER_PORT_PROPERTY = "spring.data.gemfire.cache.server.port"; - protected static final String GEMFIRE_POOL_LOCATORS_PROPERTY = "spring.data.gemfire.pool.locators"; - protected static final String GEMFIRE_POOL_SERVERS_PROPERTY = "spring.data.gemfire.pool.servers"; - protected static final String GEMFIRE_LOG_FILE = "gemfire-server.log"; - protected static final String GEMFIRE_LOG_FILE_PROPERTY = "spring.data.gemfire.log.file"; - protected static final String GEMFIRE_LOG_LEVEL = "error"; - protected static final String GEMFIRE_LOG_LEVEL_PROPERTY = "spring.data.gemfire.log.level"; - protected static final String PROCESS_RUN_MANUAL_PROPERTY = "spring.data.gemfire.process.run-manual"; - protected static final String SYSTEM_PROPERTIES_LOG_FILE = "system-properties.log"; - protected static final String TEST_GEMFIRE_LOG_LEVEL = "error"; - - protected static String asApplicationName(Class type) { - return type.getSimpleName(); - } - - protected static String asDirectoryName(Class type) { - return String.format("%1$s-%2$s", asApplicationName(type), - LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-hh-mm-ss"))); - } - - protected static String block() { - return new Scanner(System.in).nextLine(); - } - - protected static File createDirectory(String pathname) { - return createDirectory(new File(pathname)); - } - - protected static File createDirectory(File directory) { - - assertThat(directory.isDirectory() || directory.mkdirs()) - .as(String.format("Failed to create directory [%s]", directory)).isTrue(); - - if (isDeleteDirectoryOnExit()) { - directory.deleteOnExit(); - } - - return directory; - } - - protected static int findAvailablePort() throws IOException { - - ServerSocket serverSocket = null; - - try { - serverSocket = new ServerSocket(0); - return serverSocket.getLocalPort(); - } - finally { - SocketUtils.close(serverSocket); - } - } - - protected static String getClassNameAsPath(Class type) { - return type.getName().replaceAll("\\.", "/"); - } - - protected static String getClassNameAsPath(Object obj) { - return getClassNameAsPath(obj.getClass()); - } - - protected static String getPackageNameAsPath(Class type) { - return type.getPackage().getName().replaceAll("\\.", "/"); - } - - protected static String getPackageNameAsPath(Object obj) { - return getPackageNameAsPath(obj.getClass()); - } - - protected static String getContextXmlFileLocation(Class type) { - return getClassNameAsPath(type).concat("-context.xml"); - } - - protected static String getServerContextXmlFileLocation(Class type) { - return getClassNameAsPath(type).concat("-server-context.xml"); - } - - protected static boolean isDeleteDirectoryOnExit() { - return Boolean.valueOf(System.getProperty(DIRECTORY_DELETE_ON_EXIT_PROPERTY, Boolean.TRUE.toString())); - } - - protected static int intValue(Number number) { - return number != null ? number.intValue() : 0; - } - - protected static String logFile() { - return logFile(GEMFIRE_LOG_FILE); - } - - protected static String logFile(String defaultLogFilePathname) { - return System.getProperty(GEMFIRE_LOG_FILE_PROPERTY, defaultLogFilePathname); - } - - protected static String logLevel() { - return logLevel(GEMFIRE_LOG_LEVEL); - } - - protected static String logLevel(String defaultLogLevel) { - return System.getProperty(GEMFIRE_LOG_LEVEL_PROPERTY, defaultLogLevel); - } - - protected static void logSystemProperties() throws IOException { - FileUtils.write(new File(SYSTEM_PROPERTIES_LOG_FILE), - String.format("%s", CollectionUtils.toString(System.getProperties()))); - } - - protected static ProcessWrapper run(Class type, String... arguments) throws IOException { - return run(createDirectory(asDirectoryName(type)), type, arguments); - } - - protected static ProcessWrapper run(File workingDirectory, Class type, String... arguments) throws IOException { - return isProcessRunAuto() ? launch(createDirectory(workingDirectory), type, arguments) : null; - } - - protected static ProcessWrapper run(String classpath, Class type, String... arguments) throws IOException { - return run(createDirectory(asDirectoryName(type)), classpath, type, arguments); - } - - protected static ProcessWrapper run(File workingDirectory, String classpath, Class type, String... arguments) - throws IOException { - - return isProcessRunAuto() ? launch(createDirectory(workingDirectory), classpath, type, arguments) : null; - } - - protected static boolean isProcessRunAuto() { - return !isProcessRunManual(); - } - - protected static boolean isProcessRunManual() { - return Boolean.getBoolean(PROCESS_RUN_MANUAL_PROPERTY); - } - - protected static AnnotationConfigApplicationContext runSpringApplication(Class annotatedClass, String... args) { - return runSpringApplication(asArray(annotatedClass), args); - } - - protected static AnnotationConfigApplicationContext runSpringApplication(Class[] annotatedClasses, - String... args) { - - AnnotationConfigApplicationContext applicationContext = - new AnnotationConfigApplicationContext(annotatedClasses); - - applicationContext.registerShutdownHook(); - - return applicationContext; - } - - protected static boolean stop(ProcessWrapper process) { - return stop(process, DEFAULT_WAIT_DURATION); - } - - protected static boolean stop(ProcessWrapper process, long duration) { - - return Optional.ofNullable(process) - .map(it -> { - - it.stop(duration); - - if (it.isNotRunning() && isDeleteDirectoryOnExit()) { - FileSystemUtils.deleteRecursive(it.getWorkingDirectory()); - } - - return it.isRunning(); - }) - .orElse(true); - } - - protected static boolean waitForCacheServerToStart(CacheServer cacheServer) { - return waitForServerToStart(cacheServer.getBindAddress(), cacheServer.getPort(), DEFAULT_WAIT_DURATION); - } - - protected static boolean waitForCacheServerToStart(CacheServer cacheServer, long duration) { - return waitForServerToStart(cacheServer.getBindAddress(), cacheServer.getPort(), duration); - } - - protected static boolean waitForServerToStart(String host, int port) { - return waitForServerToStart(host, port, DEFAULT_WAIT_DURATION); - } - - protected static boolean waitForServerToStart(final String host, final int port, long duration) { - - return ThreadUtils.timedWait(duration, DEFAULT_WAIT_INTERVAL, new ThreadUtils.WaitCondition() { - - AtomicBoolean connected = new AtomicBoolean(false); - - public boolean waiting() { - - Socket socket = null; - - try { - if (!connected.get()) { - socket = new Socket(host, port); - connected.set(true); - } - } - catch (IOException ignore) { - } - finally { - SocketUtils.close(socket); - } - - return !connected.get(); - } - }); - } - - protected static boolean waitOn(Condition condition) { - return waitOn(condition, DEFAULT_WAIT_DURATION); - } - - @SuppressWarnings("all") - protected static boolean waitOn(Condition condition, long duration) { - - long timeout = (System.currentTimeMillis() + duration); - - try { - while (!condition.evaluate() && System.currentTimeMillis() < timeout) { - synchronized (condition) { - TimeUnit.MILLISECONDS.timedWait(condition, DEFAULT_WAIT_INTERVAL); - } - } - } - catch (InterruptedException cause) { - Thread.currentThread().interrupt(); - } - - return condition.evaluate(); - } - - @FunctionalInterface - protected interface Condition { - boolean evaluate(); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/DataSourceAdapter.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/DataSourceAdapter.java deleted file mode 100644 index 1443b631..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/DataSourceAdapter.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.test.support; - -import java.io.PrintWriter; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.util.logging.Logger; - -import javax.sql.DataSource; - -/** - * The DataSourceAdapter class is an implementation of the DataSource interface with unsupported operations by default. - * - * @author John Blum - * @see java.sql.Connection - * @see javax.sql.DataSource - * @since 1.3.4 - */ -@SuppressWarnings("unused") -public abstract class DataSourceAdapter implements DataSource { - - private static final String UNSUPPORTED_OPERATION_EXCEPTION_MESSAGE = "Not Implemented"; - - @Override - public Connection getConnection() throws SQLException { - throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_EXCEPTION_MESSAGE); - } - - @Override - public Connection getConnection(final String username, final String password) throws SQLException { - throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_EXCEPTION_MESSAGE); - } - - @Override - public PrintWriter getLogWriter() throws SQLException { - throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_EXCEPTION_MESSAGE); - } - - @Override - public void setLogWriter(final PrintWriter out) throws SQLException { - throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_EXCEPTION_MESSAGE); - } - - @Override - public int getLoginTimeout() throws SQLException { - throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_EXCEPTION_MESSAGE); - } - - @Override - public void setLoginTimeout(final int seconds) throws SQLException { - throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_EXCEPTION_MESSAGE); - } - - //@Override - public Logger getParentLogger() throws SQLFeatureNotSupportedException { - throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_EXCEPTION_MESSAGE); - } - - @Override - public boolean isWrapperFor(final Class iface) throws SQLException { - throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_EXCEPTION_MESSAGE); - } - - @Override - public T unwrap(final Class iface) throws SQLException { - throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_EXCEPTION_MESSAGE); - } - -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/FileSystemUtils.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/FileSystemUtils.java deleted file mode 100644 index 36a8e60e..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/FileSystemUtils.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.gemfire.test.support; - -import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray; -import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeIterable; - -import java.io.File; -import java.io.FileFilter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.springframework.util.Assert; - -/** - * The {@link FileSystemUtils} class is a utility class encapsulating functionality to process - * file system directories and files collectively. - * - * @author John Blum - * @see java.io.File - * @see java.io.FileFilter - * @see org.springframework.data.gemfire.test.support.FileUtils - * @see org.springframework.data.gemfire.test.support.IOUtils - * @since 1.5.0 - */ -@SuppressWarnings("unused") -public abstract class FileSystemUtils extends FileUtils { - - public static final File JAVA_HOME = new File(System.getProperty("java.home")); - public static final File JAVA_EXE = new File(new File(JAVA_HOME, "bin"), "java"); - public static final File TEMPORARY_DIRECTORY = new File(System.getProperty("java.io.tmpdir")); - public static final File USER_HOME = new File(System.getProperty("user.home")); - public static final File WORKING_DIRECTORY = new File(System.getProperty("user.dir")); - - public static final File[] NO_FILES = new File[0]; - - /* (non-Javadoc) */ - public static boolean deleteRecursive(File path) { - return deleteRecursive(path, AllFilesFilter.INSTANCE); - } - - /* (non-Javadoc) */ - public static boolean deleteRecursive(File path, FileFilter fileFilter) { - boolean success = true; - - if (isDirectory(path)) { - for (File file : safeListFiles(path, fileFilter)) { - success &= deleteRecursive(file); - } - } - - return ((!exists(path) || path.delete()) && success); - } - - public static boolean exists(File path) { - return (path != null && path.exists()); - } - - // returns sub-directory just below working directory - public static File getRootRelativeToWorkingDirectoryOrPath(File path) { - File localPath = path; - - if (isDirectory(localPath)) { - while (localPath != null && !WORKING_DIRECTORY.equals(localPath.getParentFile())) { - localPath = localPath.getParentFile(); - } - } - - return (localPath != null ? localPath : path); - } - - /* (non-Javadoc) */ - public static File[] listFiles(File directory, FileFilter fileFilter) { - Assert.isTrue(isDirectory(directory), String.format( - "File [%s] does not refer to a valid directory", directory)); - - List results = new ArrayList<>(); - - for (File file : safeListFiles(directory, fileFilter)) { - if (isDirectory(file)) { - results.addAll(Arrays.asList(listFiles(file, fileFilter))); - } - else { - results.add(file); - } - } - - return results.toArray(new File[0]); - } - - public static File[] safeListFiles(File directory) { - return safeListFiles(directory, AllFilesFilter.INSTANCE); - } - - public static File[] safeListFiles(File directory, FileFilter fileFilter) { - FileFilter resolvedFileFilter = (fileFilter != null ? fileFilter : AllFilesFilter.INSTANCE); - File[] files = (isDirectory(directory) ? directory.listFiles(resolvedFileFilter) : null); - return (files != null ? files : NO_FILES); - } - - public static class AllFilesFilter implements FileFilter { - - public static final AllFilesFilter INSTANCE = new AllFilesFilter(); - - @Override - public boolean accept(File pathname) { - return true; - } - } - - public static class CompositeFileFilter implements FileFilter { - - private final FileFilter fileFilterOne; - private final FileFilter fileFilterTwo; - - private final LogicalOperator logicalOperator; - - private CompositeFileFilter(FileFilter fileFilterOne, LogicalOperator operator, FileFilter fileFilterTwo) { - this.fileFilterOne = fileFilterOne; - this.logicalOperator = operator; - this.fileFilterTwo = fileFilterTwo; - } - - protected static FileFilter compose(FileFilter fileFilterOne, LogicalOperator operator, FileFilter fileFilterTwo) { - return (fileFilterOne == null ? fileFilterTwo : (fileFilterTwo == null ? fileFilterOne - : new CompositeFileFilter(fileFilterOne, operator, fileFilterTwo))); - } - - public static FileFilter and(FileFilter... fileFilters) { - return and(Arrays.asList(nullSafeArray(fileFilters, FileFilter.class))); - } - - public static FileFilter and(Iterable fileFilters) { - FileFilter current = null; - - for (FileFilter fileFilter : nullSafeIterable(fileFilters)) { - current = compose(current, LogicalOperator.AND, fileFilter); - } - - return current; - } - - public static FileFilter or(FileFilter... fileFilters) { - return or(Arrays.asList(nullSafeArray(fileFilters, FileFilter.class))); - } - - public static FileFilter or(Iterable fileFilters) { - FileFilter current = null; - - for (FileFilter fileFilter : nullSafeIterable(fileFilters)) { - current = compose(current, LogicalOperator.OR, fileFilter); - } - - return current; - } - - @Override - public boolean accept(File pathname) { - switch (this.logicalOperator) { - case AND: - return (fileFilterOne.accept(pathname) && fileFilterTwo.accept(pathname)); - case OR: - return (fileFilterOne.accept(pathname) || fileFilterTwo.accept(pathname)); - default: - throw new UnsupportedOperationException(String.format( - "Logical operator [%s] is unsupported", this.logicalOperator)); - } - } - - enum LogicalOperator { - AND, - OR - } - } - - public static class DirectoryOnlyFilter implements FileFilter { - - public static final DirectoryOnlyFilter INSTANCE = new DirectoryOnlyFilter(); - - @Override - public boolean accept(File pathname) { - return isDirectory(pathname); - } - } - - public static final class FileExtensionFilter extends FileOnlyFilter { - - private final String fileExtension; - - public static FileExtensionFilter newFileExtensionFilter(String fileExtension) { - return new FileExtensionFilter(fileExtension); - } - - public FileExtensionFilter(String fileExtension) { - Assert.hasText(fileExtension, String.format("File extension [%s] must be specified", fileExtension)); - this.fileExtension = fileExtension; - } - - @Override - public boolean accept(File pathname) { - return (super.accept(pathname) && pathname.getAbsolutePath().toLowerCase().endsWith(this.fileExtension)); - } - } - - public static class FileOnlyFilter implements FileFilter { - - public static final FileOnlyFilter INSTANCE = new FileOnlyFilter(); - - @Override - public boolean accept(File pathname) { - return isFile(pathname); - } - } - - public static class NegatingFileFilter implements FileFilter { - - private final FileFilter delegate; - - public static NegatingFileFilter newNegatingFileFilter(FileFilter delegate) { - return new NegatingFileFilter(delegate); - } - - public NegatingFileFilter(FileFilter delegate) { - Assert.notNull(delegate, "FileFilter must not be null"); - this.delegate = delegate; - } - - @Override - public boolean accept(File pathname) { - return !this.delegate.accept(pathname); - } - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/FileUtils.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/FileUtils.java deleted file mode 100644 index eeeebf8e..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/FileUtils.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.test.support; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; - -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -/** - * The {@link FileUtils} class is an abstract utility class for processing file system files - * by working with {@link File} objects. - * - * @author John Blum - * @see java.io.File - * @see java.io.FileReader - * @see java.io.FileWriter - * @see org.springframework.data.gemfire.test.support.IOUtils - * @since 1.5.0 - */ -@SuppressWarnings("unused") -public abstract class FileUtils extends IOUtils { - - public static final String FILE_SEPARATOR = System.getProperty("file.separator"); - public static final String LINE_SEPARATOR = System.getProperty("line.separator"); - - /* (non-Javadoc) */ - public static boolean isDirectory(File path) { - return (path != null && path.isDirectory()); - } - - /* (non-Javadoc) */ - public static boolean isFile(File path) { - return (path != null && path.isFile()); - } - - /* (non-Javadoc) */ - public static File newFile(String pathname) { - return new File(pathname); - } - - /* (non-Javadoc) */ - public static File newFile(File parent, String pathname) { - return new File(parent, pathname); - } - - /* (non-Javadoc) */ - @SuppressWarnings("all") - public static String read(File file) throws IOException { - Assert.isTrue(isFile(file), String.format("The file [%s] to read the contents from is not a valid file", file)); - - BufferedReader fileReader = new BufferedReader(new FileReader(file)); - - try { - StringBuilder buffer = new StringBuilder(); - - for (String line = fileReader.readLine(); line != null; line = fileReader.readLine()) { - buffer.append(line); - buffer.append(LINE_SEPARATOR); - } - - return buffer.toString().trim(); - } - finally { - close(fileReader); - } - } - - /* (non-Javadoc) */ - public static void write(File file, String contents) throws IOException { - Assert.notNull(file, "File must not be null"); - - Assert.isTrue(StringUtils.hasText(contents), String.format( - "The contents for File [%1$s] cannot be null or empty", file)); - - BufferedWriter fileWriter = null; - - try { - fileWriter = new BufferedWriter(new FileWriter(file)); - fileWriter.write(contents); - fileWriter.flush(); - } - finally { - IOUtils.close(fileWriter); - } - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/IOUtils.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/IOUtils.java deleted file mode 100644 index b4474e00..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/IOUtils.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.test.support; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.Closeable; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * The {@link IOUtils} class is an abstract utility class for working with IO operations. - * - * @author John Blum - * @see java.io.Closeable - * @since 1.5.0 - */ -@SuppressWarnings("unused") -public abstract class IOUtils { - - protected static final Logger log = Logger.getLogger(IOUtils.class.getName()); - - /* (non-Javadoc) */ - public static boolean close(Closeable closeable) { - - if (closeable != null) { - try { - closeable.close(); - return true; - } - catch (IOException cause) { - if (log.isLoggable(Level.FINE)) { - log.fine(String.format("Failed to close the Closeable object (%1$s) due to an I/O error:%n%2$s", - closeable, ThrowableUtils.toString(cause))); - } - } - } - - return false; - } - - /* (non-Javadoc) */ - @SuppressWarnings("unchecked") - public static T deserializeObject(byte[] objectBytes) throws IOException, ClassNotFoundException { - - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(objectBytes); - - ObjectInputStream objectInputStream = null; - - try { - objectInputStream = new ObjectInputStream(byteArrayInputStream); - - return (T) objectInputStream.readObject(); - } - finally { - IOUtils.close(objectInputStream); - } - } - - /* (non-Javadoc) */ - public static byte[] serializeObject(Serializable obj) throws IOException { - - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - - ObjectOutputStream objectOutputStream = null; - - try { - objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); - objectOutputStream.writeObject(obj); - objectOutputStream.flush(); - - return byteArrayOutputStream.toByteArray(); - } - finally { - IOUtils.close(objectOutputStream); - } - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/IdentifierSequence.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/IdentifierSequence.java deleted file mode 100644 index d2b3fc1f..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/IdentifierSequence.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.test.support; - -import java.util.concurrent.atomic.AtomicLong; - -/** - * The IdentifierSequence class is an Identifier (ID) generator generating unique IDs in sequence. - * - * @author John Blum - * @see java.lang.System#currentTimeMillis() - * @see java.util.concurrent.atomic.AtomicLong - * @since 1.5.3 - */ -@SuppressWarnings("unused") -public abstract class IdentifierSequence { - - private static final AtomicLong ID_SEQUENCE = new AtomicLong(System.currentTimeMillis()); - - public static long nextId() { - return ID_SEQUENCE.incrementAndGet(); - } - -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/MapBuilder.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/MapBuilder.java index 0429472b..ea80a727 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/MapBuilder.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/MapBuilder.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.test.support; import java.util.HashMap; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/SocketUtils.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/SocketUtils.java deleted file mode 100644 index 5d1a1d4d..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/SocketUtils.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2016-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.springframework.data.gemfire.test.support; - -import java.io.IOException; -import java.net.ServerSocket; -import java.net.Socket; -import java.util.logging.Logger; - -/** - * {@link SocketUtils} is a utility class for managing {@link Socket} and {@link ServerSocket} objects. - * - * @author John Blum - * @see java.net.ServerSocket - * @see java.net.Socket - * @since 1.9.0 - */ -@SuppressWarnings("unused") -public abstract class SocketUtils { - - private static final Logger log = Logger.getLogger(SocketUtils.class.getName()); - - /* (non-Javadoc) */ - public static boolean close(Socket socket) { - try { - if (socket != null) { - socket.close(); - return true; - } - } - catch (IOException ignore) { - log.warning(String.format("Failed to close Socket [%s]", socket)); - log.warning(ThrowableUtils.toString(ignore)); - } - - return false; - } - - /* (non-Javadoc) */ - public static boolean close(ServerSocket serverSocket) { - try { - if (serverSocket != null) { - serverSocket.close(); - return true; - } - } - catch (IOException ignore) { - log.warning(String.format("Failed to close ServerSocket [%s]", serverSocket)); - log.warning(ThrowableUtils.toString(ignore)); - } - - return false; - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/StackTraceUtils.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/StackTraceUtils.java deleted file mode 100644 index 456af693..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/StackTraceUtils.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.gemfire.test.support; - -/** - * The StackTraceUtils class is a utility class for working with stack trace frames (elements) of the current Thread. - * - * @author John Blum - * @see java.lang.StackTraceElement - * @see java.lang.Thread - * @see org.springframework.data.gemfire.test.support.ThreadUtils - * @since 1.5.3 - */ -@SuppressWarnings("unused") -public abstract class StackTraceUtils extends ThreadUtils { - - public static StackTraceElement getCaller() { - return getCaller(Thread.currentThread()); - } - - public static StackTraceElement getCaller(final Thread thread) { - return thread.getStackTrace()[2]; - } - - public static String getCallerName(final StackTraceElement element) { - return String.format("%1$%s.%2$s", element.getClass().getName(), element.getMethodName()); - } - - public static String getCallerSimpleName(final StackTraceElement element) { - return String.format("%1$%s.%2$s", element.getClass().getSimpleName(), element.getMethodName()); - } - - public static StackTraceElement getTestCaller() { - return getTestCaller(Thread.currentThread()); - } - - public static StackTraceElement getTestCaller(final Thread thread) { - - for (StackTraceElement stackTraceElement : thread.getStackTrace()) { - if (isTestSuiteClass(stackTraceElement) && isTestCaseMethod(stackTraceElement)) { - return stackTraceElement; - } - } - - return null; - } - - private static boolean isTestCaseMethod(final StackTraceElement element) { - - boolean result = element.getMethodName().toLowerCase().startsWith("test"); - - try { - result |= element.getClass().getMethod(element.getMethodName()).isAnnotationPresent(org.junit.Test.class); - } - catch (NoSuchMethodException ignore) { - } - - return result; - } - - private static boolean isTestSuiteClass(final StackTraceElement element) { - - boolean result = element.getClass().getSimpleName().toLowerCase().endsWith("test"); - - result |= element.getClass().isAssignableFrom(junit.framework.TestCase.class); - - return result; - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/ThreadUtils.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/ThreadUtils.java deleted file mode 100644 index ab94a9ca..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/ThreadUtils.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.gemfire.test.support; - -import java.util.concurrent.TimeUnit; - -/** - * {@link ThreadUtils} is an abstract utility class for managing Java {@link Thread Threads}. - * - * @author John Blum - * @see java.lang.Thread - * @since 1.5.0 - */ -@SuppressWarnings("unused") -public abstract class ThreadUtils { - - public static boolean sleep(long milliseconds) { - - try { - Thread.sleep(milliseconds); - return true; - } - catch (InterruptedException ignore) { - Thread.currentThread().interrupt(); - return false; - } - } - - public static boolean timedWait(long duration) { - return timedWait(duration, duration); - } - - public static boolean timedWait(long duration, long interval) { - return timedWait(duration, interval, () -> true); - } - - @SuppressWarnings("all") - public static boolean timedWait(long duration, long interval, WaitCondition waitCondition) { - - final long timeout = System.currentTimeMillis() + duration; - - interval = Math.min(interval, duration); - - try { - while (waitCondition.waiting() && System.currentTimeMillis() < timeout) { - synchronized (waitCondition) { - TimeUnit.MILLISECONDS.timedWait(waitCondition, interval); - } - } - } - catch (InterruptedException cause) { - Thread.currentThread().interrupt(); - } - - return !waitCondition.waiting(); - } - - // TODO rename interface to Condition and waiting() method to evaluate() - @FunctionalInterface - public interface WaitCondition { - boolean waiting(); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/ThrowableUtils.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/ThrowableUtils.java deleted file mode 100644 index 088060aa..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/ThrowableUtils.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.gemfire.test.support; - -import java.io.PrintWriter; -import java.io.StringWriter; - -/** - * The ThrowableUtils class is a utility class for working with Throwable, Exception and Error objects. - * - * @author John Blum - * @see java.lang.Error - * @see java.lang.Exception - * @see java.lang.Throwable - * @since 1.5.0 - */ -@SuppressWarnings("unused") -public abstract class ThrowableUtils { - - public static String toString(Throwable cause) { - - StringWriter writer = new StringWriter(); - - cause.printStackTrace(new PrintWriter(writer)); - - return writer.toString(); - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/ZipUtils.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/ZipUtils.java deleted file mode 100644 index 32bae461..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/ZipUtils.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.test.support; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -import org.springframework.core.io.Resource; -import org.springframework.data.gemfire.util.CollectionUtils; -import org.springframework.util.Assert; -import org.springframework.util.FileCopyUtils; - -/** - * The ZipUtils class is an abstract utility class for working with JAR and ZIP archives. - * - * @author John Blum - * @see java.io.File - * @see java.util.zip.ZipFile - * @since 1.5.0 - */ -public abstract class ZipUtils { - - public static void unzip(final Resource zipResource, final File directory) throws IOException { - Assert.notNull(zipResource, "The ZIP Resource must not be null!"); - - Assert.isTrue(directory != null && directory.isDirectory(), String.format( - "The file system pathname (%1$s) is not a valid directory!", directory)); - - ZipFile zipFile = new ZipFile(zipResource.getFile(), ZipFile.OPEN_READ); - - for (ZipEntry entry : CollectionUtils.iterable(zipFile.entries())) { - if (entry.isDirectory()) { - new File(directory, entry.getName()).mkdirs(); - } - else { - DataInputStream entryInputStream = new DataInputStream(zipFile.getInputStream(entry)); - - DataOutputStream entryOutputStream = new DataOutputStream(new FileOutputStream( - new File(directory, entry.getName()))); - - try { - FileCopyUtils.copy(entryInputStream, entryOutputStream); - } - finally { - IOUtils.close(entryInputStream); - IOUtils.close(entryOutputStream); - } - } - } - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/ConcurrentClientDataAccessTransactionsWithRollbackIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/ConcurrentClientTransactionalDataAccessWithRollbackIntegrationTests.java similarity index 86% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/ConcurrentClientDataAccessTransactionsWithRollbackIntegrationTests.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/ConcurrentClientTransactionalDataAccessWithRollbackIntegrationTests.java index 80439114..650e44b4 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/ConcurrentClientDataAccessTransactionsWithRollbackIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/ConcurrentClientTransactionalDataAccessWithRollbackIntegrationTests.java @@ -24,7 +24,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import edu.umd.cs.mtc.MultithreadedTestCase; import edu.umd.cs.mtc.TestFramework; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -43,10 +42,9 @@ import org.springframework.data.gemfire.config.annotation.ClientCacheApplication import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions; import org.springframework.data.gemfire.config.annotation.EnablePdx; import org.springframework.data.gemfire.mapping.GemfireMappingContext; -import org.springframework.data.gemfire.process.ProcessWrapper; import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; import org.springframework.data.gemfire.repository.support.GemfireRepositoryFactoryBean; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.data.gemfire.transaction.config.EnableGemfireCacheTransactions; import org.springframework.lang.NonNull; import org.springframework.stereotype.Service; @@ -72,10 +70,7 @@ import lombok.Setter; * @see org.apache.geode.cache.client.ClientCache * @see org.springframework.data.gemfire.config.annotation.CacheServerApplication * @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication - * @see org.springframework.data.gemfire.mapping.annotation.Region - * @see org.springframework.data.gemfire.repository.GemfireRepository - * @see org.springframework.data.gemfire.repository.config.EnableGemfireRepositories - * @see org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @see org.springframework.data.gemfire.transaction.config.EnableGemfireCacheTransactions * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner @@ -83,30 +78,14 @@ import lombok.Setter; * @since 2.5.0 */ @RunWith(SpringRunner.class) -@ContextConfiguration(classes = ConcurrentClientDataAccessTransactionsWithRollbackIntegrationTests.TestGeodeClientConfiguration.class) +@ContextConfiguration(classes = ConcurrentClientTransactionalDataAccessWithRollbackIntegrationTests.TestGeodeClientConfiguration.class) @SuppressWarnings("unused") -public class ConcurrentClientDataAccessTransactionsWithRollbackIntegrationTests - extends ClientServerIntegrationTestsSupport { - - private static ProcessWrapper geodeServer; +public class ConcurrentClientTransactionalDataAccessWithRollbackIntegrationTests + extends ForkingClientServerIntegrationTestsSupport { @BeforeClass public static void startGeodeServer() throws IOException { - - int availablePort = findAvailablePort(); - - geodeServer = run(TestGeodeServerConfiguration.class, - String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort)); - - waitForServerToStart("localhost", availablePort); - - System.setProperty(GEMFIRE_POOL_SERVERS_PROPERTY, String.format("localhost[%d]", availablePort)); - } - - @AfterClass - public static void stopGeodeServer() { - stop(geodeServer); - System.clearProperty(GEMFIRE_POOL_SERVERS_PROPERTY); + startGemFireServer(TestGeodeServerConfiguration.class); } @Autowired @@ -117,7 +96,7 @@ public class ConcurrentClientDataAccessTransactionsWithRollbackIntegrationTests TestFramework.runOnce(new TwoConcurrentThreadsTransactionalDataAccessOperationsMultithreadedTestCase(this.userService)); } - @ClientCacheApplication(name = "ConcurrentClientDataAccessTransactionsWithRollbackIntegrationTests") + @ClientCacheApplication(name = "ConcurrentClientTransactionalDataAccessWithRollbackIntegrationTests") @EnableEntityDefinedRegions(basePackageClasses = User.class) @EnableGemfireRepositories(basePackageClasses = UserRepository.class) @EnableGemfireCacheTransactions diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueByIdXmlConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueByIdXmlConfigurationIntegrationTests.java index 7fc549bc..86c880c1 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueByIdXmlConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueByIdXmlConfigurationIntegrationTests.java @@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import java.io.IOException; +import java.util.Scanner; import javax.annotation.Resource; @@ -40,8 +41,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.config.annotation.EnableLocator; import org.springframework.data.gemfire.config.annotation.PeerCacheApplication; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.process.ProcessWrapper; import org.springframework.data.gemfire.util.ArrayUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -58,7 +59,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.apache.geode.cache.asyncqueue.AsyncEventQueue * @see org.springframework.data.gemfire.config.annotation.EnableLocator * @see org.springframework.data.gemfire.config.annotation.PeerCacheApplication - * @see org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.2.0 @@ -66,9 +67,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration(locations = "AsyncEventQueueByIdXmlConfigurationIntegrationTests-context.xml") @SuppressWarnings("unused") -public class AsyncEventQueueByIdXmlConfigurationIntegrationTests extends ClientServerIntegrationTestsSupport { - - private static final String GEMFIRE_LOG_LEVEL = "error"; +public class AsyncEventQueueByIdXmlConfigurationIntegrationTests extends ForkingClientServerIntegrationTestsSupport { private static ProcessWrapper geodeServer; @@ -80,17 +79,13 @@ public class AsyncEventQueueByIdXmlConfigurationIntegrationTests extends ClientS System.setProperty("spring.data.gemfire.locator.port", String.valueOf(port)); geodeServer = run(GeodeServerConfiguration.class, "-Dspring.data.gemfire.locator.port=" + port); + waitForServerToStart("localhost", port); } @AfterClass public static void stopGeodeServer() { - stop(geodeServer); - - System.getProperties().stringPropertyNames().stream() - .filter(propertyName -> propertyName.startsWith("spring.data.gemfire")) - .forEach(System::clearProperty); } @Resource(name = "Example") @@ -111,15 +106,14 @@ public class AsyncEventQueueByIdXmlConfigurationIntegrationTests extends ClientS } @EnableLocator - @PeerCacheApplication(logLevel = GEMFIRE_LOG_LEVEL) + @PeerCacheApplication static class GeodeServerConfiguration { public static void main(String[] args) { - //System.err.printf("Locator Port [%s]%n", System.getProperty("spring.data.gemfire.locator.port")); - runSpringApplication(GeodeServerConfiguration.class, args); - block(); + + new Scanner(System.in).nextLine(); } @Bean("TestAsyncEventQueueOne") diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTests.java similarity index 52% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTests.java index 952ca783..309e2e48 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTests.java @@ -13,14 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.wan; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.util.List; @@ -34,29 +29,34 @@ import org.apache.geode.cache.asyncqueue.AsyncEventListener; import org.apache.geode.cache.asyncqueue.AsyncEventQueue; import org.apache.geode.cache.wan.GatewaySender; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.Assert; import org.springframework.util.StringUtils; /** - * The AsyncEventQueueWithListenerIntegrationTest class is a test suite of test cases testing the circular references - * between an Async Event Queue and a registered AsyncEventListener that refers back to the Async Event Queue - * on which the listener is registered. + * Integration Tests with test cases testing the circular references between an {@link AsyncEventQueue} + * and a registered {@link AsyncEventListener} that refers back to the {@link AsyncEventQueue} on which + * the listener is registered. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner + * @see org.apache.geode.cache.asyncqueue.AsyncEventListener * @see org.apache.geode.cache.asyncqueue.AsyncEventQueue + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.data.gemfire.wan.AsyncEventQueueFactoryBean + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner * @since 1.0.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(value = "asyncEventQueueWithListener.xml", initializers = GemfireTestApplicationContextInitializer.class) +@RunWith(SpringRunner.class) +@ContextConfiguration(locations = "asyncEventQueueWithListener.xml", + initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class AsyncEventQueueWithListenerIntegrationTest { +public class AsyncEventQueueWithListenerIntegrationTests extends IntegrationTestsSupport { @Resource(name = "Q1") private AsyncEventQueue queueOne; @@ -69,37 +69,40 @@ public class AsyncEventQueueWithListenerIntegrationTest { @Test public void testAsyncEventQueueOneAndListenerConfiguration() { - assertNotNull(queueOne); - assertEquals("QueueOne", queueOne.getId()); - assertFalse(queueOne.isPersistent()); - assertFalse(queueOne.isParallel()); - assertEquals(50, queueOne.getMaximumQueueMemory()); - assertEquals(4, queueOne.getDispatcherThreads()); - assertTrue(queueOne.getAsyncEventListener() instanceof TestAsyncEventListener); - assertSame(queueOne, ((TestAsyncEventListener) queueOne.getAsyncEventListener()).getQueue()); + + assertThat(queueOne).isNotNull(); + assertThat(queueOne.getId()).isEqualTo("QueueOne"); + assertThat(queueOne.isPersistent()).isFalse(); + assertThat(queueOne.isParallel()).isFalse(); + assertThat(queueOne.getMaximumQueueMemory()).isEqualTo(50); + assertThat(queueOne.getDispatcherThreads()).isEqualTo(4); + assertThat(queueOne.getAsyncEventListener() instanceof TestAsyncEventListener).isTrue(); + assertThat(((TestAsyncEventListener) queueOne.getAsyncEventListener()).getQueue()).isSameAs(queueOne); } @Test public void testAsyncEventQueueTwoAndListenerConfiguration() { - assertNotNull(queueTwo); - assertEquals("QueueTwo", queueTwo.getId()); - assertFalse(queueTwo.isPersistent()); - assertTrue(queueTwo.isParallel()); - assertEquals(150, queueTwo.getMaximumQueueMemory()); - assertEquals(GatewaySender.DEFAULT_DISPATCHER_THREADS, queueTwo.getDispatcherThreads()); - assertTrue(queueTwo.getAsyncEventListener() instanceof TestAsyncEventListener); - assertEquals("ListenerTwo", ((TestAsyncEventListener) queueTwo.getAsyncEventListener()).getName()); + + assertThat(queueTwo).isNotNull(); + assertThat(queueTwo.getId()).isEqualTo("QueueTwo"); + assertThat(queueTwo.isPersistent()).isFalse(); + assertThat(queueTwo.isParallel()).isTrue(); + assertThat(queueTwo.getMaximumQueueMemory()).isEqualTo(150); + assertThat(queueTwo.getDispatcherThreads()).isEqualTo(GatewaySender.DEFAULT_DISPATCHER_THREADS); + assertThat(queueTwo.getAsyncEventListener() instanceof TestAsyncEventListener).isTrue(); + assertThat(((TestAsyncEventListener) queueTwo.getAsyncEventListener()).getName()).isEqualTo("ListenerTwo"); } @Test public void testAsyncEventQueueThreeAndListenerConfiguration() { - assertNotNull(queueThree); - assertEquals("QueueThree", queueThree.getId()); - assertFalse(queueThree.isPersistent()); - assertFalse(queueThree.isParallel()); - assertEquals(25, queueThree.getMaximumQueueMemory()); - assertEquals(2, queueThree.getDispatcherThreads()); - assertTrue(queueThree.getAsyncEventListener() instanceof TestAsyncEventListener); - assertSame(queueThree, ((TestAsyncEventListener) queueThree.getAsyncEventListener()).getQueue()); + + assertThat(queueThree).isNotNull(); + assertThat(queueThree.getId()).isEqualTo("QueueThree"); + assertThat(queueThree.isPersistent()).isFalse(); + assertThat(queueThree.isParallel()).isFalse(); + assertThat(queueThree.getMaximumQueueMemory()).isEqualTo(25); + assertThat(queueThree.getDispatcherThreads()).isEqualTo(2); + assertThat(queueThree.getAsyncEventListener() instanceof TestAsyncEventListener).isTrue(); + assertThat(((TestAsyncEventListener) queueThree.getAsyncEventListener()).getQueue()).isSameAs(queueThree); } /** @@ -121,7 +124,7 @@ public class AsyncEventQueueWithListenerIntegrationTest { this.queue = null; } - public TestAsyncEventListener(final AsyncEventQueue queue) { + public TestAsyncEventListener(AsyncEventQueue queue) { this.queue = queue; } @@ -155,8 +158,7 @@ public class AsyncEventQueueWithListenerIntegrationTest { } @Override - public void close() { - } + public void close() { } @Override public String toString() { @@ -164,5 +166,4 @@ public class AsyncEventQueueWithListenerIntegrationTest { } } - } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/GatewaySenderByIdXmlConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/GatewaySenderByIdXmlConfigurationIntegrationTests.java index c6e1d48d..596f8739 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/GatewaySenderByIdXmlConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/GatewaySenderByIdXmlConfigurationIntegrationTests.java @@ -18,6 +18,7 @@ package org.springframework.data.gemfire.wan; import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; +import java.util.Scanner; import javax.annotation.Resource; @@ -38,8 +39,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; import org.springframework.data.gemfire.config.annotation.EnableLocator; import org.springframework.data.gemfire.config.annotation.PeerCacheApplication; -import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.process.ProcessWrapper; import org.springframework.data.gemfire.util.ArrayUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -56,7 +57,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.apache.geode.cache.wan.GatewaySender * @see org.springframework.data.gemfire.config.annotation.EnableLocator * @see org.springframework.data.gemfire.config.annotation.PeerCacheApplication - * @see org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.2.0 @@ -64,12 +65,10 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration(locations = "GatewaySenderByIdXmlConfigurationIntegrationTests-context.xml") @SuppressWarnings("unused") -public class GatewaySenderByIdXmlConfigurationIntegrationTests extends ClientServerIntegrationTestsSupport { +public class GatewaySenderByIdXmlConfigurationIntegrationTests extends ForkingClientServerIntegrationTestsSupport { private static ProcessWrapper geodeServer; - private static final String GEMFIRE_LOG_LEVEL = "error"; - @BeforeClass public static void startGeodeServer() throws IOException { @@ -78,17 +77,13 @@ public class GatewaySenderByIdXmlConfigurationIntegrationTests extends ClientSer System.setProperty("spring.data.gemfire.locator.port", String.valueOf(port)); geodeServer = run(GeodeServerConfiguration.class, "-Dspring.data.gemfire.locator.port=" + port); + waitForServerToStart("localhost", port); } @AfterClass public static void stopGeodeServer() { - stop(geodeServer); - - System.getProperties().stringPropertyNames().stream() - .filter(propertyName -> propertyName.startsWith("spring.data.gemfire")) - .forEach(System::clearProperty); } @Resource(name = "Example") @@ -109,15 +104,14 @@ public class GatewaySenderByIdXmlConfigurationIntegrationTests extends ClientSer } @EnableLocator - @PeerCacheApplication(logLevel = GEMFIRE_LOG_LEVEL) + @PeerCacheApplication static class GeodeServerConfiguration { public static void main(String[] args) { - //System.err.printf("Locator Port [%s]%n", System.getProperty("spring.data.gemfire.locator.port")); - runSpringApplication(GeodeServerConfiguration.class, args); - block(); + + new Scanner(System.in).nextLine(); } @Bean("TestGatewaySenderOne") diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/ManualGatewayReceiverStartIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/ManualGatewayReceiverStartIntegrationTest.java index b6425c11..105ee0af 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/ManualGatewayReceiverStartIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/ManualGatewayReceiverStartIntegrationTest.java @@ -15,10 +15,7 @@ */ package org.springframework.data.gemfire.wan; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; @@ -29,24 +26,26 @@ import org.junit.runner.RunWith; import org.apache.geode.cache.wan.GatewayReceiver; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * The ManualGatewayReceiverStartIntegrationTest class is a test suite of test cases testing the manual start capability - * of Gateway Receivers when configured with the Spring Data GemFire XML namespace. + * Integration Tests with test cases testing the manual start capability of {@link GatewayReceiver GatewayReceivers} + * when configured with SDG XML namespace configuration metadata. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer + * @see org.apache.geode.cache.wan.GatewayReceiver + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner + * @see org.springframework.test.context.junit4.SpringRunner * @since 1.5.0 */ @RunWith(SpringRunner.class) -@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class) +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") public class ManualGatewayReceiverStartIntegrationTest { @@ -56,19 +55,22 @@ public class ManualGatewayReceiverStartIntegrationTest { @Resource(name = "Manual") private GatewayReceiver manualGatewayReceiver; - protected void assertGreaterThanEqualToLessThanEqualTo(String message, + private void assertGreaterThanEqualToLessThanEqualTo(String message, int actualValue, int lowerBound, int upperBound) { - assertTrue(message, actualValue >= lowerBound && actualValue <= upperBound); + assertThat(actualValue >= lowerBound && actualValue <= upperBound).as(message).isTrue(); } @Test public void testAutoGatewayReceiver() { - assertNotNull("The 'Auto' GatewayReceiver was not properly configured or initialized!", autoGatewayReceiver); - assertTrue(autoGatewayReceiver.isRunning()); - assertEquals(7070, autoGatewayReceiver.getStartPort()); - assertEquals(7700, autoGatewayReceiver.getEndPort()); + assertThat(autoGatewayReceiver) + .describedAs("The 'Auto' GatewayReceiver was not properly configured or initialized!") + .isNotNull(); + + assertThat(autoGatewayReceiver.isRunning()).isTrue(); + assertThat(autoGatewayReceiver.getStartPort()).isEqualTo(7070); + assertThat(autoGatewayReceiver.getEndPort()).isEqualTo(7700); int gatewayReceiverPort = autoGatewayReceiver.getPort(); @@ -79,20 +81,23 @@ public class ManualGatewayReceiverStartIntegrationTest { autoGatewayReceiver.stop(); - assertFalse(autoGatewayReceiver.isRunning()); + assertThat(autoGatewayReceiver.isRunning()).isFalse(); } @Test public void testManualGatewayReceiverConfiguration() throws IOException { - assertNotNull("The 'Manual' GatewayReceiver was not properly configured or initialized!", manualGatewayReceiver); - assertFalse(manualGatewayReceiver.isRunning()); - assertEquals(6060, manualGatewayReceiver.getStartPort()); - assertEquals(6600, manualGatewayReceiver.getEndPort()); + assertThat(manualGatewayReceiver) + .describedAs("The 'Manual' GatewayReceiver was not properly configured or initialized!") + .isNotNull(); + + assertThat(manualGatewayReceiver.isRunning()).isFalse(); + assertThat(manualGatewayReceiver.getStartPort()).isEqualTo(6060); + assertThat(manualGatewayReceiver.getEndPort()).isEqualTo(6600); manualGatewayReceiver.start(); - assertTrue(manualGatewayReceiver.isRunning()); + assertThat(manualGatewayReceiver.isRunning()).isTrue(); int gatewayReceiverPort = manualGatewayReceiver.getPort(); @@ -103,6 +108,6 @@ public class ManualGatewayReceiverStartIntegrationTest { manualGatewayReceiver.stop(); - assertFalse(manualGatewayReceiver.isRunning()); + assertThat(manualGatewayReceiver.isRunning()).isFalse(); } } diff --git a/spring-data-geode/src/test/resources/cache-with-spring-context-bootstrap-initializer-using-base-packages.xml b/spring-data-geode/src/test/resources/cache-with-spring-context-bootstrap-initializer-using-base-packages.xml index 4bc04122..6382b849 100644 --- a/spring-data-geode/src/test/resources/cache-with-spring-context-bootstrap-initializer-using-base-packages.xml +++ b/spring-data-geode/src/test/resources/cache-with-spring-context-bootstrap-initializer-using-base-packages.xml @@ -10,7 +10,7 @@ org.springframework.data.gemfire.repository.sample.User - org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerIntegrationTest$UserDataStoreCacheLoader + org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerIntegrationTests$UserDataStoreCacheLoader diff --git a/spring-data-geode/src/test/resources/cache-with-spring-context-bootstrap-initializer.xml b/spring-data-geode/src/test/resources/cache-with-spring-context-bootstrap-initializer.xml index a45f7099..16ce3daa 100644 --- a/spring-data-geode/src/test/resources/cache-with-spring-context-bootstrap-initializer.xml +++ b/spring-data-geode/src/test/resources/cache-with-spring-context-bootstrap-initializer.xml @@ -10,7 +10,7 @@ org.springframework.data.gemfire.repository.sample.User - org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerIntegrationTest$UserDataStoreCacheLoader + org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerIntegrationTests$UserDataStoreCacheLoader diff --git a/spring-data-geode/src/test/resources/logback.xml b/spring-data-geode/src/test/resources/logback.xml index 6606bd1b..2a82f0d3 100644 --- a/spring-data-geode/src/test/resources/logback.xml +++ b/spring-data-geode/src/test/resources/logback.xml @@ -11,7 +11,7 @@ - + TEST - %m%n diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCachePoolTests-server-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCachePoolTests-server-context.xml index 4d10174f..0059ae5c 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCachePoolTests-server-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCachePoolTests-server-context.xml @@ -22,7 +22,7 @@ - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheSecurityTest-server-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheSecurityTest-server-context.xml index 42793cb5..41651039 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheSecurityTest-server-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheSecurityTest-server-context.xml @@ -46,7 +46,7 @@ - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheVariableLocatorsTest-server-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheVariableLocatorsTest-server-context.xml index 3287c37f..202831a0 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheVariableLocatorsTest-server-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheVariableLocatorsTest-server-context.xml @@ -32,7 +32,7 @@ - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheVariableServersTest-server-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheVariableServersTest-server-context.xml index 01cf035b..699d2b1a 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheVariableServersTest-server-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheVariableServersTest-server-context.xml @@ -40,7 +40,7 @@ - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceTest-context.xml index 97d70b94..875a40bd 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceTest-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceTest-context.xml @@ -19,9 +19,9 @@ - - diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceTest-context.xml index 62723262..46ee852e 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceTest-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceTest-context.xml @@ -17,7 +17,7 @@ - - diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceTest-context.xml index 7b353239..5e2f6aa0 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceTest-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceTest-context.xml @@ -41,20 +41,20 @@ - - - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplatePersistentPartitionRegionNamespaceTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplatePersistentPartitionRegionNamespaceTest-context.xml index 41a6cdb8..292a911f 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplatePersistentPartitionRegionNamespaceTest-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplatePersistentPartitionRegionNamespaceTest-context.xml @@ -24,7 +24,7 @@ - diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceTests-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceTests-context.xml index 30399ad7..418cc959 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceTests-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceTests-context.xml @@ -19,7 +19,7 @@ - @@ -29,9 +29,9 @@ disk-synchronous="false" ignore-jta="true" initial-capacity="51" key-constraint="java.lang.Long" load-factor="0.85" persistent="false" statistics="true" value-constraint="java.lang.String"> - - - + + + @@ -41,10 +41,10 @@ index-update-type="asynchronous" key-constraint="java.lang.Integer" load-factor="0.55" template="BaseRegionTemplate"> - + - + @@ -56,7 +56,7 @@ key-constraint="java.lang.String" persistent="true" scope="distributed-ack" value-constraint="java.lang.Object" template="BaseRegionTemplate"> - + @@ -65,25 +65,25 @@ - + - + - + - + - + @@ -112,7 +112,7 @@ - + @@ -121,11 +121,11 @@ total-buckets="91" disk-synchronous="true" enable-async-conflation="true" ignore-jta="false" key-constraint="java.util.Date" persistent="true" template="PartitionRegionTemplate"> - + - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/client-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/client-ns.xml index 314222e2..1cd982e0 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/client-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/client-ns.xml @@ -56,10 +56,10 @@ - + - + @@ -92,6 +92,6 @@ - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/diskstore-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/diskstore-ns.xml index 1c72e906..7a2aedc0 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/diskstore-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/diskstore-ns.xml @@ -80,10 +80,10 @@ - + - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/function-service-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/function-service-ns.xml index 9c543eab..4c00fed3 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/function-service-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/function-service-ns.xml @@ -9,11 +9,11 @@ - + - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/gateway-v8-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/gateway-v8-ns.xml index cf26934f..5889ba34 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/gateway-v8-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/gateway-v8-ns.xml @@ -20,7 +20,7 @@ - + @@ -29,6 +29,6 @@ - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/local-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/local-ns.xml index 31a66499..79004061 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/local-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/local-ns.xml @@ -47,7 +47,7 @@ - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/partitioned-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/partitioned-ns.xml index b4a793d2..39381c5b 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/partitioned-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/partitioned-ns.xml @@ -45,13 +45,13 @@ - + - + @@ -63,9 +63,9 @@ - - - + + + @@ -75,7 +75,7 @@ - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/replicated-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/replicated-ns.xml index 3f7def38..2c19739b 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/replicated-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/replicated-ns.xml @@ -67,7 +67,7 @@ - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/subregionsubelement-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/subregionsubelement-ns.xml index a635a7be..f13a8744 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/subregionsubelement-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/subregionsubelement-ns.xml @@ -21,7 +21,7 @@ - + @@ -30,7 +30,7 @@ - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/tx-listeners-and-writers.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/tx-listeners-and-writers.xml index b4897575..dd70fddc 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/tx-listeners-and-writers.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/tx-listeners-and-writers.xml @@ -26,8 +26,8 @@ - - - + + + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTest-server-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTest-server-context.xml index 9ee648e2..6ff1b922 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTest-server-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTest-server-context.xml @@ -31,7 +31,7 @@ - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTest-context.xml index f40d50e0..6a4a3d9b 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTest-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTest-context.xml @@ -31,9 +31,9 @@ - - @@ -42,7 +42,7 @@ + class="org.springframework.data.gemfire.snapshot.SnapshotApplicationEventTriggeredImportsExportsIntegrationTests.SnapshotImportsMonitor"/> @@ -57,7 +57,7 @@ @@ -68,7 +68,7 @@ - diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/support/sample/initializer-dao-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/support/sample/initializer-dao-context.xml index 5e44a11a..0229272d 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/support/sample/initializer-dao-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/support/sample/initializer-dao-context.xml @@ -9,7 +9,7 @@ - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/asyncEventQueueWithListener.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/asyncEventQueueWithListener.xml index 018f8913..3747dd38 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/asyncEventQueueWithListener.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/asyncEventQueueWithListener.xml @@ -22,19 +22,19 @@ - - - diff --git a/src/main/asciidoc/reference/gemfire-bootstrap.adoc b/src/main/asciidoc/reference/gemfire-bootstrap.adoc index 21231525..e1f1785b 100644 --- a/src/main/asciidoc/reference/gemfire-bootstrap.adoc +++ b/src/main/asciidoc/reference/gemfire-bootstrap.adoc @@ -160,7 +160,7 @@ the following (which comes from {sdg-acronym}'s test suite): org.springframework.data.gemfire.repository.sample.User - org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerIntegrationTest$UserDataStoreCacheLoader + org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerIntegrationTests$UserDataStoreCacheLoader