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

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

Introduction

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

Prototype

public void setName(String name) 

Source Link

Document

Sets the name of the Index .

Usage

From source file:org.spring.data.gemfire.app.context.config.PeerCacheConfiguration.java

@Bean
public IndexFactoryBean exampleIndex(Cache gemfireCache) {
    IndexFactoryBean customerId = new IndexFactoryBean();

    customerId.setCache(gemfireCache);/*from ww w  .j av a2s.  c  o  m*/
    customerId.setName("CustomerIdIdx");
    customerId.setExpression("id");
    customerId.setFrom("/Customers");
    customerId.setType(IndexType.PRIMARY_KEY);

    return customerId;
}

From source file:example.app.config.gemfire.GemFireConfiguration.java

@Bean
@DependsOn("Contacts")
public IndexFactoryBean emailIndex(GemFireCache gemfireCache) {
    IndexFactoryBean lastNameIndex = new IndexFactoryBean();

    lastNameIndex.setCache(gemfireCache);
    lastNameIndex.setExpression("email");
    lastNameIndex.setFrom("/Contacts");
    lastNameIndex.setName("EmailIdx");
    lastNameIndex.setType(IndexType.HASH);

    return lastNameIndex;
}

From source file:example.app.config.gemfire.GemFireConfiguration.java

@Bean
@DependsOn("Contacts")
public IndexFactoryBean lastNameIndex(GemFireCache gemfireCache) {
    IndexFactoryBean lastNameIndex = new IndexFactoryBean();

    lastNameIndex.setCache(gemfireCache);
    lastNameIndex.setExpression("person.lastName");
    lastNameIndex.setFrom("/Contacts");
    lastNameIndex.setName("PersonLastNameIdx");
    lastNameIndex.setType(IndexType.HASH);

    return lastNameIndex;
}

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   www. ja  v  a 2  s  .  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 {/*from  w ww  .j a v a2 s  .  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 {/*  www .j  a  v a2s.c om*/
        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 {/*  ww w .ja  va  2 s  . com*/
        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 {//www .  j  a  v a  2 s . com
        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 {// w ww  .  j ava  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 resolveIndexNameFromBeanNameProperty() {

    IndexFactoryBean indexFactoryBean = newIndexFactoryBean();

    indexFactoryBean.setBeanName("TestIndexBeanName");
    indexFactoryBean.setName(null);

    assertThat(indexFactoryBean.resolveIndexName()).isEqualTo("TestIndexBeanName");
}