DATAES-143 added support for turning off auto index creation based on Document annotation.

This commit is contained in:
Mason Chan
2014-12-30 20:13:30 -06:00
committed by Artur Konczak
parent 485f0e7252
commit 751302d6f0
11 changed files with 120 additions and 23 deletions

View File

@@ -48,6 +48,7 @@ import org.springframework.data.elasticsearch.ElasticsearchException;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.core.query.*;
import org.springframework.data.elasticsearch.entities.*;
import org.springframework.data.elasticsearch.repositories.existing.index.CreateIndexFalseEntity;
import org.springframework.data.util.CloseableIterator;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -58,6 +59,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Franck Marchand
* @author Abdul Mohammed
* @author Kevin Leturc
* @author Mason Chan
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:elasticsearch-template-test.xml")

View File

@@ -0,0 +1,17 @@
package org.springframework.data.elasticsearch.repositories.existing.index;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
/**
* CreateIndexFalseEntity
*
* @author Mason Chan
*/
@Document(indexName = "test-index", type = "test-type", createIndex = false)
public class CreateIndexFalseEntity {
@Id
private String id;
}

View File

@@ -0,0 +1,10 @@
package org.springframework.data.elasticsearch.repositories.existing.index;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
/**
* Created by akonczak on 16/12/2015.
*/
public interface CreateIndexFalseRepository extends ElasticsearchRepository<CreateIndexFalseEntity, String> {
}

View File

@@ -0,0 +1,34 @@
package org.springframework.data.elasticsearch.repositories.existing.index;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/existing-index-repository-test.xml")
public class CreateIndexFalseRepositoryTest {
@Autowired
private CreateIndexFalseRepository repository;
@Autowired
private ElasticsearchTemplate elasticsearchTemplate;
/*
DATAES-143
*/
@Test
public void shouldNotCreateIndex() {
//given
//when
//then
assertFalse(elasticsearchTemplate.indexExists(CreateIndexFalseEntity.class));
}
}