List of usage examples for org.springframework.data.gemfire IndexFactoryBean setType
public void setType(IndexType type)
From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java
@Test public void defineMultipleIndexesWithSeparateIndexFactoryBeansSameSpringContext() throws Exception { ConfigurableBeanFactory mockBeanFactory = mock(ConfigurableBeanFactory.class, "testDefineMultipleIndexesWithSeparateIndexFactoryBeansSameSpringContext.MockBeanFactory"); Cache mockCacheOne = mock(Cache.class, "testDefineMultipleIndexesWithSeparateIndexFactoryBeansSameSpringContext.MockCacheOne"); Cache mockCacheTwo = mock(Cache.class, "testDefineMultipleIndexesWithSeparateIndexFactoryBeansSameSpringContext.MockCacheTwo"); AtomicReference<QueryService> queryServiceReference = new AtomicReference<>(null); doAnswer(invocation -> (queryServiceReference.get() != null)).when(mockBeanFactory) .containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE)); doAnswer(invocation -> queryServiceReference.get()).when(mockBeanFactory).getBean( eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE), eq(QueryService.class)); doAnswer(invocation -> {/* www . j a v a 2s.c o m*/ assertEquals(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE, invocation.getArgument(0)); queryServiceReference.compareAndSet(null, invocation.getArgument(1)); return null; }).when(mockBeanFactory).registerSingleton( eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE), any(QueryService.class)); when(mockCacheOne.getQueryService()).thenReturn(mockQueryService); IndexFactoryBean indexFactoryBeanOne = new IndexFactoryBean(); indexFactoryBeanOne.setBeanFactory(mockBeanFactory); indexFactoryBeanOne.setCache(mockCacheOne); indexFactoryBeanOne.setDefine(true); indexFactoryBeanOne.setExpression("id"); indexFactoryBeanOne.setFrom("/People"); indexFactoryBeanOne.setName("PersonIdIndex"); indexFactoryBeanOne.setType("Key"); indexFactoryBeanOne.afterPropertiesSet(); IndexFactoryBean indexFactoryBeanTwo = new IndexFactoryBean(); indexFactoryBeanTwo.setBeanFactory(mockBeanFactory); indexFactoryBeanTwo.setCache(mockCacheTwo); indexFactoryBeanTwo.setDefine(true); indexFactoryBeanTwo.setExpression("purchaseDate"); indexFactoryBeanTwo.setFrom("/Orders"); indexFactoryBeanTwo.setImports("org.example.Order"); indexFactoryBeanTwo.setName("PurchaseDateIndex"); indexFactoryBeanTwo.setType("HASH"); indexFactoryBeanTwo.afterPropertiesSet(); verify(mockBeanFactory, times(2)) .containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE)); verify(mockBeanFactory, times(1)).getBean( eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE), eq(QueryService.class)); verify(mockBeanFactory, times(1)).registerSingleton( eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE), same(mockQueryService)); verify(mockCacheOne, times(1)).getQueryService(); verify(mockCacheTwo, never()).getQueryService(); verify(mockQueryService, times(1)).defineKeyIndex(eq("PersonIdIndex"), eq("id"), eq("/People")); verify(mockQueryService, times(1)).defineHashIndex(eq("PurchaseDateIndex"), eq("purchaseDate"), eq("/Orders"), eq("org.example.Order")); }