Example usage for org.springframework.data.gemfire IndexFactoryBean getIndex

List of usage examples for org.springframework.data.gemfire IndexFactoryBean getIndex

Introduction

In this page you can find the example usage for org.springframework.data.gemfire IndexFactoryBean getIndex.

Prototype

public Index getIndex() 

Source Link

Document

Returns a reference to the Index created by this IndexFactoryBean .

Usage

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);// www  .  ja  v a2s  .co 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
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"));
}