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

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

Introduction

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

Prototype

@Override
public Index getObject() 

Source Link

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);//from   w w  w  . j  a va  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
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 getObjectReturnsLookedUpIndex() throws Exception {

    Index mockIndexOne = mockIndex("MockIndexOne");
    Index mockIndexTwo = mockIndex("MockIndexTwo");

    when(mockQueryService.getIndexes()).thenReturn(Arrays.asList(mockIndexOne, mockIndexTwo));

    IndexFactoryBean indexFactoryBean = newIndexFactoryBean();

    indexFactoryBean.setName("MockIndexTwo");

    assertThat(indexFactoryBean.getObject()).isEqualTo(mockIndexTwo);
}

From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java

@Test
public void getObjectReturnsNull() {

    IndexFactoryBean indexFactoryBean = newIndexFactoryBean();

    indexFactoryBean.setName("TestIndex");

    assertThat(indexFactoryBean.getObject()).isNull();
}