List of usage examples for org.springframework.data.gemfire IndexFactoryBean afterPropertiesSet
@Override public void afterPropertiesSet() throws Exception
From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java
@Test @SuppressWarnings("all") public void afterPropertiesSetIsSuccessful() throws Exception { ConfigurableBeanFactory mockConfigurableBeanFactory = mock(ConfigurableBeanFactory.class); Index mockIndex = mock(Index.class, "testAfterPropertiesSetIsSuccessful.MockIndex"); when(mockQueryService.createKeyIndex(eq("TestKeyIndex"), eq("id"), eq("/Example"))).thenReturn(mockIndex); IndexFactoryBean indexFactoryBean = newIndexFactoryBean(); indexFactoryBean.setBeanFactory(mockConfigurableBeanFactory); indexFactoryBean.setBeanName("KeyIndexBean"); indexFactoryBean.setDefine(false);//from ww w . j a v a 2s. c o m indexFactoryBean.setExpression("id"); indexFactoryBean.setFrom("/Example"); indexFactoryBean.setName("TestKeyIndex"); indexFactoryBean.setType("key"); indexFactoryBean.afterPropertiesSet(); assertThat(indexFactoryBean.getIndex()).isEqualTo(mockIndex); Index actualIndex = indexFactoryBean.getObject(); assertThat(actualIndex).isEqualTo(mockIndex); assertThat(indexFactoryBean.getObject()).isSameAs(actualIndex); assertThat(Index.class).isAssignableFrom(indexFactoryBean.getObjectType()); assertThat(indexFactoryBean.isSingleton()).isTrue(); verify(indexFactoryBean, times(1)).getBeanName(); verify(indexFactoryBean, never()).lookupQueryService(); verify(mockConfigurableBeanFactory, times(1)).registerAlias(eq("KeyIndexBean"), eq("TestKeyIndex")); verify(mockQueryService, times(1)).createKeyIndex(eq("TestKeyIndex"), eq("id"), eq("/Example")); verifyZeroInteractions(mockCache); }
From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java
@Test(expected = IllegalStateException.class) public void afterPropertiesSetWithNullCache() throws Exception { try {/*w w w . j av a 2s .c o m*/ IndexFactoryBean indexFactoryBean = new IndexFactoryBean(); indexFactoryBean.setName("TestIndex"); indexFactoryBean.afterPropertiesSet(); } catch (IllegalStateException expected) { assertThat(expected).hasMessage("Cache is required"); assertThat(expected).hasNoCause(); throw expected; } }
From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java
@Test(expected = IllegalStateException.class) public void afterPropertiesSetWithNullQueryService() throws Exception { IndexFactoryBean indexFactoryBean = spy(new IndexFactoryBean()); doReturn(null).when(indexFactoryBean).lookupQueryService(); try {// w w w .j a v a2 s. c o m indexFactoryBean.setCache(mockCache); indexFactoryBean.setName("TestIndex"); indexFactoryBean.afterPropertiesSet(); } catch (IllegalStateException expected) { assertThat(expected).hasMessage("QueryService is required to create an Index"); assertThat(expected).hasNoCause(); throw expected; } finally { verify(indexFactoryBean, times(1)).lookupQueryService(); } }
From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java
@Test(expected = IllegalArgumentException.class) public void afterPropertiesSetWithUnspecifiedExpression() throws Exception { try {/* w ww . j a v a 2s .co m*/ IndexFactoryBean indexFactoryBean = newIndexFactoryBean(); indexFactoryBean.setName("TestIndex"); indexFactoryBean.afterPropertiesSet(); } catch (IllegalArgumentException expected) { assertThat(expected).hasMessage("Index expression is required"); assertThat(expected).hasNoCause(); throw expected; } }
From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java
@Test(expected = IllegalArgumentException.class) public void afterPropertiesSetWithUnspecifiedFromClause() throws Exception { try {/*ww w .j av a2 s. co m*/ IndexFactoryBean indexFactoryBean = newIndexFactoryBean(); indexFactoryBean.setName("TestIndex"); indexFactoryBean.setExpression("id"); indexFactoryBean.afterPropertiesSet(); } catch (Exception expected) { assertThat(expected).hasMessage("Index from clause is required"); assertThat(expected).hasNoCause(); throw expected; } }
From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java
@Test(expected = IllegalArgumentException.class) public void afterPropertiesSetUsingImportsWithInvalidIndexKeyType() throws Exception { try {/*from w w w .jav a 2s .c o m*/ IndexFactoryBean indexFactoryBean = newIndexFactoryBean(); indexFactoryBean.setName("TestIndex"); indexFactoryBean.setExpression("id"); indexFactoryBean.setFrom("/Example"); indexFactoryBean.setImports("org.example.DomainType"); indexFactoryBean.setType("PriMary_Key"); indexFactoryBean.afterPropertiesSet(); } catch (IllegalArgumentException expected) { assertThat(expected).hasMessage("Imports are not supported with a KEY Index"); assertThat(expected).hasNoCause(); throw expected; } }
From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java
@Test public void getObjectReturnsFactoryIndex() throws Exception { Index mockIndex = mockIndex("testGetObjectReturnsFactoryIndex.MockIndex"); IndexFactoryBean indexFactoryBean = newIndexFactoryBean(); doReturn(mockIndex).when(indexFactoryBean).createIndex(eq(mockQueryService), eq("testGetObjectReturnsFactoryIndex.MockIndex")); indexFactoryBean.setName("testGetObjectReturnsFactoryIndex.MockIndex"); indexFactoryBean.setExpression("id"); indexFactoryBean.setFrom("/Mock"); indexFactoryBean.afterPropertiesSet(); assertThat(indexFactoryBean.getIndex()).isEqualTo(mockIndex); assertThat(indexFactoryBean.getObject()).isEqualTo(mockIndex); assertThat(indexFactoryBean.getObject()).isEqualTo(mockIndex); verify(indexFactoryBean, times(1)).createIndex(eq(mockQueryService), eq("testGetObjectReturnsFactoryIndex.MockIndex")); }
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 -> {//w ww. j av a 2 s.c om 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")); }