DATAES-2 Applied spring-data formatting to all sources
This commit is contained in:
@@ -14,28 +14,29 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class Author {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,39 +17,40 @@ package org.springframework.data.elasticsearch;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Document(indexName = "book",type = "book", indexStoreType = "memory", shards = 1 , replicas = 0, refreshInterval = "-1" )
|
||||
@Document(indexName = "book", type = "book", indexStoreType = "memory", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class Book {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
private Author author;
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
private Author author;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Author getAuthor() {
|
||||
return author;
|
||||
}
|
||||
public Author getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(Author author) {
|
||||
this.author = author;
|
||||
}
|
||||
public void setAuthor(Author author) {
|
||||
this.author = author;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,48 +24,46 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
|
||||
@Document(indexName = "double-keyed-entity", type = "double-keyed-entity", indexStoreType = "memory", shards = 1 , replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "double-keyed-entity", type = "double-keyed-entity", indexStoreType = "memory", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class DoubleIDEntity {
|
||||
|
||||
@Id
|
||||
private Double id;
|
||||
private String type;
|
||||
private String message;
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
public Double getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Double id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
@Id
|
||||
private Double id;
|
||||
private String type;
|
||||
private String message;
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
public Double getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Double id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -24,49 +24,46 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
|
||||
@Document(indexName = "integer-keyed-entity", type = "integer-keyed-entity", indexStoreType = "memory", shards = 1 , replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "integer-keyed-entity", type = "integer-keyed-entity", indexStoreType = "memory", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class IntegerIDEntity {
|
||||
|
||||
@Id
|
||||
private Integer id;
|
||||
private String type;
|
||||
private String message;
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
@Id
|
||||
private Integer id;
|
||||
private String type;
|
||||
private String message;
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.elasticsearch.repositories.SampleElasticSearchBookRepository;
|
||||
@@ -24,38 +23,36 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
||||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/repository-test-nested-object.xml")
|
||||
public class NestedObjectTests{
|
||||
public class NestedObjectTests {
|
||||
|
||||
@Resource
|
||||
private SampleElasticSearchBookRepository repository;
|
||||
@Resource
|
||||
private SampleElasticSearchBookRepository repository;
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldIndexNestedObject(){
|
||||
//given
|
||||
String id = randomAlphanumeric(5);
|
||||
Book book = new Book();
|
||||
book.setId(id);
|
||||
book.setName("xyz");
|
||||
Author author = new Author();
|
||||
author.setId("1");
|
||||
author.setName("ABC");
|
||||
book.setAuthor(author);
|
||||
//when
|
||||
repository.save(book);
|
||||
//then
|
||||
assertThat(repository.findOne(id), is(notNullValue()));
|
||||
}
|
||||
@Test
|
||||
public void shouldIndexNestedObject() {
|
||||
// given
|
||||
String id = randomAlphanumeric(5);
|
||||
Book book = new Book();
|
||||
book.setId(id);
|
||||
book.setName("xyz");
|
||||
Author author = new Author();
|
||||
author.setId("1");
|
||||
author.setName("ABC");
|
||||
book.setAuthor(author);
|
||||
// when
|
||||
repository.save(book);
|
||||
// then
|
||||
assertThat(repository.findOne(id), is(notNullValue()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,32 +15,32 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch;
|
||||
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class NonDocumentEntity {
|
||||
|
||||
@Id
|
||||
private String someId;
|
||||
private String someField1;
|
||||
private String someField2;
|
||||
@Id
|
||||
private String someId;
|
||||
private String someField1;
|
||||
private String someField2;
|
||||
|
||||
public String getSomeField1() {
|
||||
return someField1;
|
||||
}
|
||||
public String getSomeField1() {
|
||||
return someField1;
|
||||
}
|
||||
|
||||
public void setSomeField1(String someField1) {
|
||||
this.someField1 = someField1;
|
||||
}
|
||||
public void setSomeField1(String someField1) {
|
||||
this.someField1 = someField1;
|
||||
}
|
||||
|
||||
public String getSomeField2() {
|
||||
return someField2;
|
||||
}
|
||||
public String getSomeField2() {
|
||||
return someField2;
|
||||
}
|
||||
|
||||
public void setSomeField2(String someField2) {
|
||||
this.someField2 = someField2;
|
||||
}
|
||||
public void setSomeField2(String someField2) {
|
||||
this.someField2 = someField2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,23 +15,21 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.data.elasticsearch.repositories.NonDocumentEntityRepository;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class NonDocumentEntityTests {
|
||||
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void shouldNotInitialiseRepositoryWithNonDocument(){
|
||||
//when
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext("/repository-non-document-entity.xml");
|
||||
ctx.getBean(NonDocumentEntityRepository.class);
|
||||
}
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void shouldNotInitialiseRepositoryWithNonDocument() {
|
||||
// when
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/repository-non-document-entity.xml");
|
||||
ctx.getBean(NonDocumentEntityRepository.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,93 +25,82 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Document(indexName = "test-index", type = "test-type", indexStoreType = "memory", shards = 1 , replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index", type = "test-type", indexStoreType = "memory", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class SampleEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String type;
|
||||
private String message;
|
||||
private int rate;
|
||||
private boolean available;
|
||||
@Version
|
||||
private Long version;
|
||||
@Id
|
||||
private String id;
|
||||
private String type;
|
||||
private String message;
|
||||
private int rate;
|
||||
private boolean available;
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getRate() {
|
||||
return rate;
|
||||
}
|
||||
public int getRate() {
|
||||
return rate;
|
||||
}
|
||||
|
||||
public void setRate(int rate) {
|
||||
this.rate = rate;
|
||||
}
|
||||
public void setRate(int rate) {
|
||||
this.rate = rate;
|
||||
}
|
||||
|
||||
public boolean isAvailable() {
|
||||
return available;
|
||||
}
|
||||
public boolean isAvailable() {
|
||||
return available;
|
||||
}
|
||||
|
||||
public void setAvailable(boolean available) {
|
||||
this.available = available;
|
||||
}
|
||||
public void setAvailable(boolean available) {
|
||||
this.available = available;
|
||||
}
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof SampleEntity)) {
|
||||
return false;
|
||||
}
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
SampleEntity rhs = (SampleEntity) obj;
|
||||
return new EqualsBuilder().append(this.id, rhs.id)
|
||||
.append(this.type, rhs.type)
|
||||
.append(this.message, rhs.message)
|
||||
.append(this.rate,rhs.rate)
|
||||
.append(this.available,rhs.available)
|
||||
.append(this.version,rhs.version)
|
||||
.isEquals();
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof SampleEntity)) {
|
||||
return false;
|
||||
}
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
SampleEntity rhs = (SampleEntity) obj;
|
||||
return new EqualsBuilder().append(this.id, rhs.id).append(this.type, rhs.type).append(this.message, rhs.message)
|
||||
.append(this.rate, rhs.rate).append(this.available, rhs.available).append(this.version, rhs.version).isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder()
|
||||
.append(id)
|
||||
.append(type)
|
||||
.append(message)
|
||||
.append(rate)
|
||||
.append(available)
|
||||
.append(version)
|
||||
.toHashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder().append(id).append(type).append(message).append(rate).append(available).append(version)
|
||||
.toHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch;
|
||||
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
@@ -24,47 +23,43 @@ import org.springframework.data.elasticsearch.annotations.Field;
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Document(indexName = "test-mapping", type = "mapping", indexStoreType = "memory", shards = 1 , replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-mapping", type = "mapping", indexStoreType = "memory", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class SampleMappingEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
@Field(type = "string", index = "not_analyzed", store = true, searchAnalyzer = "standard", indexAnalyzer = "standard")
|
||||
private String message;
|
||||
@Id
|
||||
private String id;
|
||||
@Field(type = "string", index = "not_analyzed", store = true, searchAnalyzer = "standard", indexAnalyzer = "standard")
|
||||
private String message;
|
||||
|
||||
private NestedEntity nested;
|
||||
private NestedEntity nested;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
static class NestedEntity {
|
||||
@Field(type = "string")
|
||||
private String someField;
|
||||
|
||||
static class NestedEntity{
|
||||
@Field(type = "string")
|
||||
private String someField;
|
||||
public String getSomeField() {
|
||||
return someField;
|
||||
}
|
||||
|
||||
public String getSomeField() {
|
||||
return someField;
|
||||
}
|
||||
|
||||
public void setSomeField(String someField) {
|
||||
this.someField = someField;
|
||||
}
|
||||
}
|
||||
public void setSomeField(String someField) {
|
||||
this.someField = someField;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -39,25 +39,26 @@ import static org.junit.Assert.assertThat;
|
||||
@ContextConfiguration("namespace.xml")
|
||||
public class ElasticsearchNamespaceHandlerTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void shouldCreatesNodeClient() {
|
||||
assertThat(context.getBean(NodeClientFactoryBean.class), is(notNullValue()));
|
||||
assertThat(context.getBean(NodeClientFactoryBean.class), is(instanceOf(NodeClientFactoryBean.class)));
|
||||
}
|
||||
@Test
|
||||
public void shouldCreatesNodeClient() {
|
||||
assertThat(context.getBean(NodeClientFactoryBean.class), is(notNullValue()));
|
||||
assertThat(context.getBean(NodeClientFactoryBean.class), is(instanceOf(NodeClientFactoryBean.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateTransportClient() {
|
||||
assertThat(context.getBean(TransportClientFactoryBean.class), is(notNullValue()));
|
||||
assertThat(context.getBean(TransportClientFactoryBean.class), is(instanceOf(TransportClientFactoryBean.class)));
|
||||
}
|
||||
@Test
|
||||
public void shouldCreateTransportClient() {
|
||||
assertThat(context.getBean(TransportClientFactoryBean.class), is(notNullValue()));
|
||||
assertThat(context.getBean(TransportClientFactoryBean.class), is(instanceOf(TransportClientFactoryBean.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateRepository(){
|
||||
assertThat(context.getBean(TransportClientFactoryBean.class), is(notNullValue()));
|
||||
assertThat(context.getBean(SampleElasticsearchRepository.class), is(instanceOf(SampleElasticsearchRepository.class)));
|
||||
}
|
||||
@Test
|
||||
public void shouldCreateRepository() {
|
||||
assertThat(context.getBean(TransportClientFactoryBean.class), is(notNullValue()));
|
||||
assertThat(context.getBean(SampleElasticsearchRepository.class),
|
||||
is(instanceOf(SampleElasticsearchRepository.class)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.config;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -41,22 +40,22 @@ import static org.junit.Assert.assertThat;
|
||||
@ContextConfiguration
|
||||
public class EnableElasticsearchRepositoriesTests {
|
||||
|
||||
@Configuration
|
||||
@EnableElasticsearchRepositories(basePackages = "org.springframework.data.elasticsearch.repositories")
|
||||
static class Config {
|
||||
@Configuration
|
||||
@EnableElasticsearchRepositories(basePackages = "org.springframework.data.elasticsearch.repositories")
|
||||
static class Config {
|
||||
|
||||
@Bean
|
||||
public ElasticsearchOperations elasticsearchTemplate() {
|
||||
return new ElasticsearchTemplate(nodeBuilder().local(true).clusterName("testCluster").node().client());
|
||||
}
|
||||
}
|
||||
@Bean
|
||||
public ElasticsearchOperations elasticsearchTemplate() {
|
||||
return new ElasticsearchTemplate(nodeBuilder().local(true).clusterName("testCluster").node().client());
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private SampleElasticsearchRepository repository;
|
||||
@Autowired
|
||||
private SampleElasticsearchRepository repository;
|
||||
|
||||
@Test
|
||||
public void bootstrapsRepository() {
|
||||
assertThat(repository, is(notNullValue()));
|
||||
}
|
||||
@Test
|
||||
public void bootstrapsRepository() {
|
||||
assertThat(repository, is(notNullValue()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -31,44 +31,44 @@ import java.util.TimeZone;
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class DateTimeConvertersTests {
|
||||
@Test
|
||||
public void testJodaDateTimeConverterWithNullValue() {
|
||||
Assert.assertNull(DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(null));
|
||||
}
|
||||
@Test
|
||||
public void testJodaDateTimeConverterWithNullValue() {
|
||||
Assert.assertNull(DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJodaDateTimeConverter() {
|
||||
DateTime dateTime = new DateTime(2013, 1,24 , 6, 35, 0, DateTimeZone.UTC);
|
||||
Assert.assertEquals("2013-01-24T06:35:00.000Z",
|
||||
DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(dateTime));
|
||||
}
|
||||
@Test
|
||||
public void testJodaDateTimeConverter() {
|
||||
DateTime dateTime = new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC);
|
||||
Assert
|
||||
.assertEquals("2013-01-24T06:35:00.000Z", DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(dateTime));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJodaLocalDateTimeConverterWithNullValue() {
|
||||
Assert.assertNull(DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE.convert(null));
|
||||
}
|
||||
@Test
|
||||
public void testJodaLocalDateTimeConverterWithNullValue() {
|
||||
Assert.assertNull(DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE.convert(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJodaLocalDateTimeConverter() {
|
||||
LocalDateTime dateTime = new LocalDateTime(new DateTime(2013, 1,24, 6, 35, 0, DateTimeZone.UTC).getMillis(),
|
||||
DateTimeZone.UTC);
|
||||
Assert.assertEquals("2013-01-24T06:35:00.000Z",
|
||||
DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE.convert(dateTime));
|
||||
}
|
||||
@Test
|
||||
public void testJodaLocalDateTimeConverter() {
|
||||
LocalDateTime dateTime = new LocalDateTime(new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC).getMillis(),
|
||||
DateTimeZone.UTC);
|
||||
Assert.assertEquals("2013-01-24T06:35:00.000Z",
|
||||
DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE.convert(dateTime));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJavaDateConverterWithNullValue() {
|
||||
Assert.assertNull(DateTimeConverters.JavaDateConverter.INSTANCE.convert(null));
|
||||
}
|
||||
@Test
|
||||
public void testJavaDateConverterWithNullValue() {
|
||||
Assert.assertNull(DateTimeConverters.JavaDateConverter.INSTANCE.convert(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJavaDateConverter() {
|
||||
DateTime dateTime = new DateTime(2013, 1,24, 6, 35, 0, DateTimeZone.UTC);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
calendar.setTimeInMillis(dateTime.getMillis());
|
||||
@Test
|
||||
public void testJavaDateConverter() {
|
||||
DateTime dateTime = new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
calendar.setTimeInMillis(dateTime.getMillis());
|
||||
|
||||
Assert.assertEquals("2013-01-24T06:35:00.000Z",
|
||||
DateTimeConverters.JavaDateConverter.INSTANCE.convert(calendar.getTime()));
|
||||
}
|
||||
Assert.assertEquals("2013-01-24T06:35:00.000Z",
|
||||
DateTimeConverters.JavaDateConverter.INSTANCE.convert(calendar.getTime()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.convert;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||
@@ -23,36 +22,37 @@ import org.springframework.data.mapping.context.MappingContext;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class MappingElasticsearchConverterTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldFailToInitializeGivenMappingContextIsNull(){
|
||||
//given
|
||||
new MappingElasticsearchConverter(null);
|
||||
}
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldFailToInitializeGivenMappingContextIsNull() {
|
||||
// given
|
||||
new MappingElasticsearchConverter(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnMappingContextWithWhichItWasInitialized(){
|
||||
//given
|
||||
MappingContext mappingContext = new SimpleElasticsearchMappingContext();
|
||||
MappingElasticsearchConverter converter = new MappingElasticsearchConverter(mappingContext);
|
||||
//then
|
||||
assertThat(converter.getMappingContext(), is(notNullValue()));
|
||||
assertThat(converter.getMappingContext(), is(sameInstance(mappingContext)));
|
||||
}
|
||||
@Test
|
||||
public void shouldReturnMappingContextWithWhichItWasInitialized() {
|
||||
// given
|
||||
MappingContext mappingContext = new SimpleElasticsearchMappingContext();
|
||||
MappingElasticsearchConverter converter = new MappingElasticsearchConverter(mappingContext);
|
||||
// then
|
||||
assertThat(converter.getMappingContext(), is(notNullValue()));
|
||||
assertThat(converter.getMappingContext(), is(sameInstance(mappingContext)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnDefaultConversionService(){
|
||||
//given
|
||||
MappingElasticsearchConverter converter = new MappingElasticsearchConverter(new SimpleElasticsearchMappingContext());
|
||||
//when
|
||||
ConversionService conversionService = converter.getConversionService();
|
||||
//then
|
||||
assertThat(conversionService, is(notNullValue()));
|
||||
}
|
||||
@Test
|
||||
public void shouldReturnDefaultConversionService() {
|
||||
// given
|
||||
MappingElasticsearchConverter converter = new MappingElasticsearchConverter(new SimpleElasticsearchMappingContext());
|
||||
// when
|
||||
ConversionService conversionService = converter.getConversionService();
|
||||
// then
|
||||
assertThat(conversionService, is(notNullValue()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,85 +24,85 @@ import org.springframework.data.util.TypeInformation;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class SimpleElasticsearchPersistentEntityTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionGivenVersionPropertyIsNotLong() throws NoSuchFieldException, IntrospectionException {
|
||||
//given
|
||||
TypeInformation typeInformation = ClassTypeInformation.from(EntityWithWrongVersionType.class);
|
||||
SimpleElasticsearchPersistentProperty persistentProperty =
|
||||
new SimpleElasticsearchPersistentProperty(EntityWithWrongVersionType.class.getDeclaredField("version"),
|
||||
new PropertyDescriptor("version", EntityWithWrongVersionType.class),
|
||||
new SimpleElasticsearchPersistentEntity<EntityWithWrongVersionType>(typeInformation),
|
||||
new SimpleTypeHolder());
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionGivenVersionPropertyIsNotLong() throws NoSuchFieldException, IntrospectionException {
|
||||
// given
|
||||
TypeInformation typeInformation = ClassTypeInformation.from(EntityWithWrongVersionType.class);
|
||||
SimpleElasticsearchPersistentProperty persistentProperty = new SimpleElasticsearchPersistentProperty(
|
||||
EntityWithWrongVersionType.class.getDeclaredField("version"), new PropertyDescriptor("version",
|
||||
EntityWithWrongVersionType.class), new SimpleElasticsearchPersistentEntity<EntityWithWrongVersionType>(
|
||||
typeInformation), new SimpleTypeHolder());
|
||||
|
||||
//when
|
||||
new SimpleElasticsearchPersistentEntity(typeInformation).addPersistentProperty(persistentProperty);
|
||||
}
|
||||
// when
|
||||
new SimpleElasticsearchPersistentEntity(typeInformation).addPersistentProperty(persistentProperty);
|
||||
}
|
||||
|
||||
@Test(expected = MappingException.class)
|
||||
public void shouldThrowExceptionGivenMultipleVersionPropertiesArePresent() throws NoSuchFieldException,
|
||||
IntrospectionException {
|
||||
// given
|
||||
TypeInformation typeInformation = ClassTypeInformation.from(EntityWithMultipleVersionField.class);
|
||||
SimpleElasticsearchPersistentProperty persistentProperty1 = new SimpleElasticsearchPersistentProperty(
|
||||
EntityWithMultipleVersionField.class.getDeclaredField("version1"), new PropertyDescriptor("version1",
|
||||
EntityWithMultipleVersionField.class),
|
||||
new SimpleElasticsearchPersistentEntity<EntityWithMultipleVersionField>(typeInformation),
|
||||
new SimpleTypeHolder());
|
||||
|
||||
@Test(expected = MappingException.class)
|
||||
public void shouldThrowExceptionGivenMultipleVersionPropertiesArePresent() throws NoSuchFieldException, IntrospectionException {
|
||||
//given
|
||||
TypeInformation typeInformation = ClassTypeInformation.from(EntityWithMultipleVersionField.class);
|
||||
SimpleElasticsearchPersistentProperty persistentProperty1 =
|
||||
new SimpleElasticsearchPersistentProperty(EntityWithMultipleVersionField.class.getDeclaredField("version1"),
|
||||
new PropertyDescriptor("version1", EntityWithMultipleVersionField.class),
|
||||
new SimpleElasticsearchPersistentEntity<EntityWithMultipleVersionField>(typeInformation),
|
||||
new SimpleTypeHolder());
|
||||
SimpleElasticsearchPersistentProperty persistentProperty2 = new SimpleElasticsearchPersistentProperty(
|
||||
EntityWithMultipleVersionField.class.getDeclaredField("version2"), new PropertyDescriptor("version2",
|
||||
EntityWithMultipleVersionField.class),
|
||||
new SimpleElasticsearchPersistentEntity<EntityWithMultipleVersionField>(typeInformation),
|
||||
new SimpleTypeHolder());
|
||||
|
||||
SimpleElasticsearchPersistentProperty persistentProperty2 =
|
||||
new SimpleElasticsearchPersistentProperty(EntityWithMultipleVersionField.class.getDeclaredField("version2"),
|
||||
new PropertyDescriptor("version2", EntityWithMultipleVersionField.class),
|
||||
new SimpleElasticsearchPersistentEntity<EntityWithMultipleVersionField>(typeInformation),
|
||||
new SimpleTypeHolder());
|
||||
SimpleElasticsearchPersistentEntity simpleElasticsearchPersistentEntity = new SimpleElasticsearchPersistentEntity(
|
||||
typeInformation);
|
||||
simpleElasticsearchPersistentEntity.addPersistentProperty(persistentProperty1);
|
||||
// when
|
||||
simpleElasticsearchPersistentEntity.addPersistentProperty(persistentProperty2);
|
||||
}
|
||||
|
||||
SimpleElasticsearchPersistentEntity simpleElasticsearchPersistentEntity = new SimpleElasticsearchPersistentEntity(typeInformation);
|
||||
simpleElasticsearchPersistentEntity.addPersistentProperty(persistentProperty1);
|
||||
//when
|
||||
simpleElasticsearchPersistentEntity.addPersistentProperty(persistentProperty2);
|
||||
}
|
||||
private class EntityWithWrongVersionType {
|
||||
@Version
|
||||
private String version;
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
private class EntityWithWrongVersionType {
|
||||
@Version
|
||||
private String version;
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
private class EntityWithMultipleVersionField {
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
@Version
|
||||
private Long version1;
|
||||
@Version
|
||||
private Long version2;
|
||||
|
||||
private class EntityWithMultipleVersionField{
|
||||
public Long getVersion1() {
|
||||
return version1;
|
||||
}
|
||||
|
||||
@Version
|
||||
private Long version1;
|
||||
@Version
|
||||
private Long version2;
|
||||
public void setVersion1(Long version1) {
|
||||
this.version1 = version1;
|
||||
}
|
||||
|
||||
public Long getVersion1() {
|
||||
return version1;
|
||||
}
|
||||
public Long getVersion2() {
|
||||
return version2;
|
||||
}
|
||||
|
||||
public void setVersion1(Long version1) {
|
||||
this.version1 = version1;
|
||||
}
|
||||
|
||||
public Long getVersion2() {
|
||||
return version2;
|
||||
}
|
||||
|
||||
public void setVersion2(Long version2) {
|
||||
this.version2 = version2;
|
||||
}
|
||||
}
|
||||
public void setVersion2(Long version2) {
|
||||
this.version2 = version2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.repositories;
|
||||
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -38,6 +37,7 @@ import static org.apache.commons.lang.RandomStringUtils.randomNumeric;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
@@ -46,454 +46,450 @@ import static org.junit.Assert.assertThat;
|
||||
@ContextConfiguration("classpath:custom-method-repository-test.xml")
|
||||
public class CustomMethodRepositoryTests {
|
||||
|
||||
@Resource
|
||||
private SampleCustomMethodRepository repository;
|
||||
@Resource
|
||||
private SampleCustomMethodRepository repository;
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Before
|
||||
public void before(){
|
||||
elasticsearchTemplate.createIndex(SampleEntity.class);
|
||||
DeleteQuery deleteQuery = new DeleteQuery();
|
||||
deleteQuery.setQuery(matchAllQuery());
|
||||
elasticsearchTemplate.delete(deleteQuery,SampleEntity.class);
|
||||
elasticsearchTemplate.refresh(SampleEntity.class, true);
|
||||
}
|
||||
@Before
|
||||
public void before() {
|
||||
elasticsearchTemplate.createIndex(SampleEntity.class);
|
||||
DeleteQuery deleteQuery = new DeleteQuery();
|
||||
deleteQuery.setQuery(matchAllQuery());
|
||||
elasticsearchTemplate.delete(deleteQuery, SampleEntity.class);
|
||||
elasticsearchTemplate.refresh(SampleEntity.class, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethod(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setMessage("some message");
|
||||
repository.save(sampleEntity);
|
||||
//when
|
||||
Page<SampleEntity> page = repository.findByType("test", new PageRequest(0, 10));
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(greaterThanOrEqualTo(1L)));
|
||||
}
|
||||
@Test
|
||||
public void shouldExecuteCustomMethod() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setMessage("some message");
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByType("test", new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(greaterThanOrEqualTo(1L)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForNot(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("some");
|
||||
sampleEntity.setMessage("some message");
|
||||
repository.save(sampleEntity);
|
||||
//when
|
||||
Page<SampleEntity> page = repository.findByTypeNot("test", new PageRequest(0, 10));
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForNot() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("some");
|
||||
sampleEntity.setMessage("some message");
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByTypeNot("test", new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodWithQuery(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setMessage("customQuery");
|
||||
repository.save(sampleEntity);
|
||||
//when
|
||||
Page<SampleEntity> page = repository.findByMessage("customQuery", new PageRequest(0, 10));
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(greaterThanOrEqualTo(1L)));
|
||||
}
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodWithQuery() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setMessage("customQuery");
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByMessage("customQuery", new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(greaterThanOrEqualTo(1L)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodWithLessThan() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setRate(10);
|
||||
sampleEntity.setMessage("some message");
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodWithLessThan(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setRate(10);
|
||||
sampleEntity.setMessage("some message");
|
||||
repository.save(sampleEntity);
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setType("test");
|
||||
sampleEntity2.setRate(20);
|
||||
sampleEntity2.setMessage("some message");
|
||||
repository.save(sampleEntity2);
|
||||
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setType("test");
|
||||
sampleEntity2.setRate(20);
|
||||
sampleEntity2.setMessage("some message");
|
||||
repository.save(sampleEntity2);
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByRateLessThan(10, new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
|
||||
//when
|
||||
Page<SampleEntity> page = repository.findByRateLessThan(10, new PageRequest(0, 10));
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodWithBefore() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setRate(10);
|
||||
sampleEntity.setMessage("some message");
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodWithBefore(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setRate(10);
|
||||
sampleEntity.setMessage("some message");
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByRateBefore(10, new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
|
||||
//when
|
||||
Page<SampleEntity> page = repository.findByRateBefore(10, new PageRequest(0, 10));
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodWithAfter() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setRate(10);
|
||||
sampleEntity.setMessage("some message");
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodWithAfter(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setRate(10);
|
||||
sampleEntity.setMessage("some message");
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByRateAfter(10, new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
|
||||
//when
|
||||
Page<SampleEntity> page = repository.findByRateAfter(10, new PageRequest(0, 10));
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodWithLike() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setRate(10);
|
||||
sampleEntity.setMessage("foo");
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodWithLike(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setRate(10);
|
||||
sampleEntity.setMessage("foo");
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByMessageLike("fo", new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
|
||||
//when
|
||||
Page<SampleEntity> page = repository.findByMessageLike("fo", new PageRequest(0, 10));
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForStartingWith() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setRate(10);
|
||||
sampleEntity.setMessage("foo");
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForStartingWith(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setRate(10);
|
||||
sampleEntity.setMessage("foo");
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByMessageStartingWith("fo", new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
|
||||
//when
|
||||
Page<SampleEntity> page = repository.findByMessageStartingWith("fo", new PageRequest(0, 10));
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForEndingWith() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setRate(10);
|
||||
sampleEntity.setMessage("foo");
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForEndingWith(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setRate(10);
|
||||
sampleEntity.setMessage("foo");
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByMessageEndingWith("o", new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
|
||||
//when
|
||||
Page<SampleEntity> page = repository.findByMessageEndingWith("o", new PageRequest(0, 10));
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForContains() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setRate(10);
|
||||
sampleEntity.setMessage("foo");
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForContains(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setRate(10);
|
||||
sampleEntity.setMessage("foo");
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByMessageContaining("fo", new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
|
||||
//when
|
||||
Page<SampleEntity> page = repository.findByMessageContaining("fo", new PageRequest(0, 10));
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForIn() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setMessage("foo");
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForIn(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setMessage("foo");
|
||||
repository.save(sampleEntity);
|
||||
// given
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setType("test");
|
||||
sampleEntity2.setMessage("bar");
|
||||
repository.save(sampleEntity2);
|
||||
|
||||
//given
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setType("test");
|
||||
sampleEntity2.setMessage("bar");
|
||||
repository.save(sampleEntity2);
|
||||
List<String> ids = Arrays.asList(documentId, documentId2);
|
||||
|
||||
List<String> ids = Arrays.asList(documentId,documentId2);
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByIdIn(ids, new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(2L)));
|
||||
}
|
||||
|
||||
//when
|
||||
Page<SampleEntity> page = repository.findByIdIn(ids, new PageRequest(0, 10));
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(2L)));
|
||||
}
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForNotIn() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setMessage("foo");
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForNotIn(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setMessage("foo");
|
||||
repository.save(sampleEntity);
|
||||
// given
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setType("test");
|
||||
sampleEntity2.setMessage("bar");
|
||||
repository.save(sampleEntity2);
|
||||
|
||||
//given
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setType("test");
|
||||
sampleEntity2.setMessage("bar");
|
||||
repository.save(sampleEntity2);
|
||||
List<String> ids = Arrays.asList(documentId);
|
||||
|
||||
List<String> ids = Arrays.asList(documentId);
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByIdNotIn(ids, new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
assertThat(page.getContent().get(0).getId(), is(documentId2));
|
||||
}
|
||||
|
||||
//when
|
||||
Page<SampleEntity> page = repository.findByIdNotIn(ids, new PageRequest(0, 10));
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
assertThat(page.getContent().get(0).getId(),is(documentId2));
|
||||
}
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForTrue() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setMessage("foo");
|
||||
sampleEntity.setAvailable(true);
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForTrue(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setMessage("foo");
|
||||
sampleEntity.setAvailable(true);
|
||||
repository.save(sampleEntity);
|
||||
// given
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setType("test");
|
||||
sampleEntity2.setMessage("bar");
|
||||
sampleEntity2.setAvailable(false);
|
||||
repository.save(sampleEntity2);
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByAvailableTrue(new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
|
||||
//given
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setType("test");
|
||||
sampleEntity2.setMessage("bar");
|
||||
sampleEntity2.setAvailable(false);
|
||||
repository.save(sampleEntity2);
|
||||
//when
|
||||
Page<SampleEntity> page = repository.findByAvailableTrue(new PageRequest(0, 10));
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForFalse() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setMessage("foo");
|
||||
sampleEntity.setAvailable(true);
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForFalse(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setMessage("foo");
|
||||
sampleEntity.setAvailable(true);
|
||||
repository.save(sampleEntity);
|
||||
// given
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setType("test");
|
||||
sampleEntity2.setMessage("bar");
|
||||
sampleEntity2.setAvailable(false);
|
||||
repository.save(sampleEntity2);
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByAvailableFalse(new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
|
||||
//given
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setType("test");
|
||||
sampleEntity2.setMessage("bar");
|
||||
sampleEntity2.setAvailable(false);
|
||||
repository.save(sampleEntity2);
|
||||
//when
|
||||
Page<SampleEntity> page = repository.findByAvailableFalse(new PageRequest(0, 10));
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForOrderBy() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("abc");
|
||||
sampleEntity.setMessage("test");
|
||||
sampleEntity.setAvailable(true);
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForOrderBy(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("abc");
|
||||
sampleEntity.setMessage("test");
|
||||
sampleEntity.setAvailable(true);
|
||||
repository.save(sampleEntity);
|
||||
// document 2
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setType("xyz");
|
||||
sampleEntity2.setMessage("bar");
|
||||
sampleEntity2.setAvailable(false);
|
||||
repository.save(sampleEntity2);
|
||||
|
||||
//document 2
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setType("xyz");
|
||||
sampleEntity2.setMessage("bar");
|
||||
sampleEntity2.setAvailable(false);
|
||||
repository.save(sampleEntity2);
|
||||
// document 3
|
||||
String documentId3 = randomNumeric(5);
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setId(documentId3);
|
||||
sampleEntity3.setType("def");
|
||||
sampleEntity3.setMessage("foo");
|
||||
sampleEntity3.setAvailable(false);
|
||||
repository.save(sampleEntity3);
|
||||
|
||||
//document 3
|
||||
String documentId3 = randomNumeric(5);
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setId(documentId3);
|
||||
sampleEntity3.setType("def");
|
||||
sampleEntity3.setMessage("foo");
|
||||
sampleEntity3.setAvailable(false);
|
||||
repository.save(sampleEntity3);
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByMessageOrderByTypeAsc("foo", new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
|
||||
//when
|
||||
Page<SampleEntity> page = repository.findByMessageOrderByTypeAsc("foo",new PageRequest(0, 10));
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodWithBooleanParameter() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setMessage("foo");
|
||||
sampleEntity.setAvailable(true);
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodWithBooleanParameter(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setType("test");
|
||||
sampleEntity.setMessage("foo");
|
||||
sampleEntity.setAvailable(true);
|
||||
repository.save(sampleEntity);
|
||||
// given
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setType("test");
|
||||
sampleEntity2.setMessage("bar");
|
||||
sampleEntity2.setAvailable(false);
|
||||
repository.save(sampleEntity2);
|
||||
// when
|
||||
Page<SampleEntity> page = repository.findByAvailable(false, new PageRequest(0, 10));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
|
||||
//given
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setType("test");
|
||||
sampleEntity2.setMessage("bar");
|
||||
sampleEntity2.setAvailable(false);
|
||||
repository.save(sampleEntity2);
|
||||
//when
|
||||
Page<SampleEntity> page = repository.findByAvailable(false, new PageRequest(0, 10));
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getTotalElements(), is(equalTo(1L)));
|
||||
}
|
||||
@Test
|
||||
public void shouldReturnPageableResultsWithQueryAnnotationExpectedPageSize() {
|
||||
// given
|
||||
for (int i = 0; i < 30; i++) {
|
||||
String documentId = String.valueOf(i);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
}
|
||||
// when
|
||||
Page<SampleEntity> pageResult = repository.findByMessage("message", new PageRequest(0, 23, new Sort(new Sort.Order(
|
||||
Sort.Direction.ASC, "message"))));
|
||||
// then
|
||||
assertThat(pageResult.getTotalElements(), is(equalTo(30L)));
|
||||
assertThat(pageResult.getContent().size(), is(equalTo(23)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnPageableResultsWithQueryAnnotationExpectedPageSize() {
|
||||
// given
|
||||
for (int i = 0; i < 30; i++) {
|
||||
String documentId = String.valueOf(i);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
}
|
||||
// when
|
||||
Page<SampleEntity> pageResult = repository.findByMessage("message", new PageRequest(0, 23, new Sort(new Sort.Order(Sort.Direction.ASC,"message"))));
|
||||
// then
|
||||
assertThat(pageResult.getTotalElements(), is(equalTo(30L)));
|
||||
assertThat(pageResult.getContent().size(), is(equalTo(23)));
|
||||
}
|
||||
@Test
|
||||
public void shouldReturnPageableResultsWithGivenSortingOrder() {
|
||||
// given
|
||||
String documentId = random(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("abc");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
public void shouldReturnPageableResultsWithGivenSortingOrder(){
|
||||
//given
|
||||
String documentId = random(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("abc");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("abd");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity2);
|
||||
|
||||
String documentId3 = randomNumeric(5);
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setId(documentId3);
|
||||
sampleEntity3.setMessage("abe");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity3);
|
||||
//when
|
||||
Page<SampleEntity> pageResult = repository.findByMessageContaining("a", new PageRequest(0, 23, new Sort(new Sort.Order(Sort.Direction.DESC,"message"))));
|
||||
//then
|
||||
assertThat(pageResult.getContent().isEmpty(),is(false));
|
||||
assertThat(pageResult.getContent().get(0).getMessage(),is(sampleEntity3.getMessage()));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldReturnListForMessage(){
|
||||
//given
|
||||
String documentId = random(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("abc");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("abd");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity2);
|
||||
|
||||
String documentId3 = randomNumeric(5);
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setId(documentId3);
|
||||
sampleEntity3.setMessage("abe");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity3);
|
||||
//when
|
||||
List<SampleEntity> sampleEntities = repository.findByMessage("abc");
|
||||
//then
|
||||
assertThat(sampleEntities.isEmpty(),is(false));
|
||||
assertThat(sampleEntities.size(),is(1));
|
||||
}
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("abd");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity2);
|
||||
|
||||
String documentId3 = randomNumeric(5);
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setId(documentId3);
|
||||
sampleEntity3.setMessage("abe");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity3);
|
||||
// when
|
||||
Page<SampleEntity> pageResult = repository.findByMessageContaining("a", new PageRequest(0, 23, new Sort(
|
||||
new Sort.Order(Sort.Direction.DESC, "message"))));
|
||||
// then
|
||||
assertThat(pageResult.getContent().isEmpty(), is(false));
|
||||
assertThat(pageResult.getContent().get(0).getMessage(), is(sampleEntity3.getMessage()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnListForMessage() {
|
||||
// given
|
||||
String documentId = random(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("abc");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("abd");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity2);
|
||||
|
||||
String documentId3 = randomNumeric(5);
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setId(documentId3);
|
||||
sampleEntity3.setMessage("abe");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity3);
|
||||
// when
|
||||
List<SampleEntity> sampleEntities = repository.findByMessage("abc");
|
||||
// then
|
||||
assertThat(sampleEntities.isEmpty(), is(false));
|
||||
assertThat(sampleEntities.size(), is(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.springframework.data.elasticsearch.repositories;
|
||||
import org.springframework.data.elasticsearch.DoubleIDEntity;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
public interface DoubleIDRepository extends ElasticsearchRepository<DoubleIDEntity,Double> {
|
||||
|
||||
|
||||
public interface DoubleIDRepository extends ElasticsearchRepository<DoubleIDEntity, Double> {
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,6 @@ package org.springframework.data.elasticsearch.repositories;
|
||||
import org.springframework.data.elasticsearch.IntegerIDEntity;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
public interface IntegerIDRepository extends ElasticsearchRepository<IntegerIDEntity,Integer> {
|
||||
public interface IntegerIDRepository extends ElasticsearchRepository<IntegerIDEntity, Integer> {
|
||||
|
||||
}
|
||||
|
||||
@@ -22,5 +22,5 @@ import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public interface NonDocumentEntityRepository extends ElasticsearchRepository<NonDocumentEntity,String> {
|
||||
public interface NonDocumentEntityRepository extends ElasticsearchRepository<NonDocumentEntity, String> {
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.repositories;
|
||||
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.SampleEntity;
|
||||
@@ -23,46 +22,47 @@ import org.springframework.data.elasticsearch.annotations.Query;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public interface SampleCustomMethodRepository extends ElasticsearchRepository<SampleEntity,String> {
|
||||
public interface SampleCustomMethodRepository extends ElasticsearchRepository<SampleEntity, String> {
|
||||
|
||||
Page<SampleEntity> findByType(String type, Pageable pageable);
|
||||
Page<SampleEntity> findByType(String type, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByTypeNot(String type, Pageable pageable);
|
||||
Page<SampleEntity> findByTypeNot(String type, Pageable pageable);
|
||||
|
||||
@Query("{\"bool\" : {\"must\" : {\"field\" : {\"message\" : \"?0\"}}}}")
|
||||
Page<SampleEntity> findByMessage(String message, Pageable pageable);
|
||||
@Query("{\"bool\" : {\"must\" : {\"field\" : {\"message\" : \"?0\"}}}}")
|
||||
Page<SampleEntity> findByMessage(String message, Pageable pageable);
|
||||
|
||||
@Query("{\"bool\" : {\"must\" : {\"field\" : {\"message\" : \"?0\"}}}}")
|
||||
List<SampleEntity> findByMessage(String message);
|
||||
@Query("{\"bool\" : {\"must\" : {\"field\" : {\"message\" : \"?0\"}}}}")
|
||||
List<SampleEntity> findByMessage(String message);
|
||||
|
||||
Page<SampleEntity> findByAvailable(boolean available, Pageable pageable);
|
||||
Page<SampleEntity> findByAvailable(boolean available, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByRateLessThan(int rate, Pageable pageable);
|
||||
Page<SampleEntity> findByRateLessThan(int rate, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByRateBefore(int rate, Pageable pageable);
|
||||
Page<SampleEntity> findByRateBefore(int rate, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByRateAfter(int rate, Pageable pageable);
|
||||
Page<SampleEntity> findByRateAfter(int rate, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByMessageLike(String message, Pageable pageable);
|
||||
Page<SampleEntity> findByMessageLike(String message, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByMessageStartingWith(String message, Pageable pageable);
|
||||
Page<SampleEntity> findByMessageStartingWith(String message, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByMessageEndingWith(String message, Pageable pageable);
|
||||
Page<SampleEntity> findByMessageEndingWith(String message, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByMessageContaining(String message, Pageable pageable);
|
||||
Page<SampleEntity> findByMessageContaining(String message, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByIdIn(List<String> ids, Pageable pageable);
|
||||
Page<SampleEntity> findByIdIn(List<String> ids, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByIdNotIn(List<String> messages, Pageable pageable);
|
||||
Page<SampleEntity> findByIdNotIn(List<String> messages, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByAvailableTrue(Pageable pageable);
|
||||
Page<SampleEntity> findByAvailableTrue(Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByAvailableFalse(Pageable pageable);
|
||||
Page<SampleEntity> findByAvailableFalse(Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByMessageOrderByTypeAsc(String message,Pageable pageable);
|
||||
Page<SampleEntity> findByMessageOrderByTypeAsc(String message, Pageable pageable);
|
||||
|
||||
}
|
||||
|
||||
@@ -24,5 +24,5 @@ import java.util.List;
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public interface SampleElasticSearchBookRepository extends ElasticsearchRepository<Book,String> {
|
||||
public interface SampleElasticSearchBookRepository extends ElasticsearchRepository<Book, String> {
|
||||
}
|
||||
|
||||
@@ -17,10 +17,11 @@ package org.springframework.data.elasticsearch.repositories;
|
||||
|
||||
import org.springframework.data.elasticsearch.SampleEntity;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public interface SampleElasticsearchRepository extends ElasticsearchRepository<SampleEntity,String> {
|
||||
public interface SampleElasticsearchRepository extends ElasticsearchRepository<SampleEntity, String> {
|
||||
|
||||
}
|
||||
|
||||
@@ -38,51 +38,51 @@ import static org.junit.Assert.assertThat;
|
||||
@ContextConfiguration("classpath:/simple-repository-test.xml")
|
||||
public class DoubleIDRepositoryTests {
|
||||
|
||||
@Resource
|
||||
private DoubleIDRepository repository;
|
||||
@Resource
|
||||
private DoubleIDRepository repository;
|
||||
|
||||
@Before
|
||||
public void before(){
|
||||
repository.deleteAll();
|
||||
}
|
||||
@Before
|
||||
public void before() {
|
||||
repository.deleteAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDoBulkIndexDocument(){
|
||||
//given
|
||||
Double documentId1 = RandomUtils.nextDouble();
|
||||
DoubleIDEntity sampleEntity1 = new DoubleIDEntity();
|
||||
sampleEntity1.setId(documentId1);
|
||||
sampleEntity1.setMessage("some message");
|
||||
sampleEntity1.setVersion(System.currentTimeMillis());
|
||||
@Test
|
||||
public void shouldDoBulkIndexDocument() {
|
||||
// given
|
||||
Double documentId1 = RandomUtils.nextDouble();
|
||||
DoubleIDEntity sampleEntity1 = new DoubleIDEntity();
|
||||
sampleEntity1.setId(documentId1);
|
||||
sampleEntity1.setMessage("some message");
|
||||
sampleEntity1.setVersion(System.currentTimeMillis());
|
||||
|
||||
Double documentId2 = RandomUtils.nextDouble();
|
||||
DoubleIDEntity sampleEntity2 = new DoubleIDEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
Double documentId2 = RandomUtils.nextDouble();
|
||||
DoubleIDEntity sampleEntity2 = new DoubleIDEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
//when
|
||||
repository.save(Arrays.asList(sampleEntity1, sampleEntity2));
|
||||
//then
|
||||
DoubleIDEntity entity1FromElasticSearch = repository.findOne(documentId1);
|
||||
assertThat(entity1FromElasticSearch, is(notNullValue()));
|
||||
// when
|
||||
repository.save(Arrays.asList(sampleEntity1, sampleEntity2));
|
||||
// then
|
||||
DoubleIDEntity entity1FromElasticSearch = repository.findOne(documentId1);
|
||||
assertThat(entity1FromElasticSearch, is(notNullValue()));
|
||||
|
||||
DoubleIDEntity entity2FromElasticSearch = repository.findOne(documentId2);
|
||||
assertThat(entity2FromElasticSearch, is(notNullValue()));
|
||||
}
|
||||
DoubleIDEntity entity2FromElasticSearch = repository.findOne(documentId2);
|
||||
assertThat(entity2FromElasticSearch, is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSaveDocument(){
|
||||
//given
|
||||
Double documentId = RandomUtils.nextDouble();
|
||||
DoubleIDEntity sampleEntity = new DoubleIDEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
//when
|
||||
repository.save(sampleEntity);
|
||||
//then
|
||||
DoubleIDEntity entityFromElasticSearch = repository.findOne(documentId);
|
||||
assertThat(entityFromElasticSearch, is(notNullValue()));
|
||||
}
|
||||
@Test
|
||||
public void shouldSaveDocument() {
|
||||
// given
|
||||
Double documentId = RandomUtils.nextDouble();
|
||||
DoubleIDEntity sampleEntity = new DoubleIDEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
// when
|
||||
repository.save(sampleEntity);
|
||||
// then
|
||||
DoubleIDEntity entityFromElasticSearch = repository.findOne(documentId);
|
||||
assertThat(entityFromElasticSearch, is(notNullValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.repository.support;
|
||||
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -33,6 +32,7 @@ import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
@@ -40,27 +40,25 @@ import static org.mockito.Mockito.when;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ElasticsearchRepositoryFactoryTests {
|
||||
|
||||
@Mock
|
||||
private ElasticsearchOperations operations;
|
||||
private ElasticsearchConverter converter;
|
||||
private ElasticsearchRepositoryFactory factory;
|
||||
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext= new SimpleElasticsearchMappingContext();
|
||||
@Mock
|
||||
private ElasticsearchOperations operations;
|
||||
private ElasticsearchConverter converter;
|
||||
private ElasticsearchRepositoryFactory factory;
|
||||
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext = new SimpleElasticsearchMappingContext();
|
||||
|
||||
@Before
|
||||
public void before(){
|
||||
converter = new MappingElasticsearchConverter(mappingContext);
|
||||
when(operations.getElasticsearchConverter()).thenReturn(converter);
|
||||
factory = new ElasticsearchRepositoryFactory(operations);
|
||||
}
|
||||
@Before
|
||||
public void before() {
|
||||
converter = new MappingElasticsearchConverter(mappingContext);
|
||||
when(operations.getElasticsearchConverter()).thenReturn(converter);
|
||||
factory = new ElasticsearchRepositoryFactory(operations);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionGivenQueryDslRepository(){
|
||||
//given
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(QueryDslPredicateExecutor.class);
|
||||
//when
|
||||
factory.getRepositoryBaseClass(metadata);
|
||||
}
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionGivenQueryDslRepository() {
|
||||
// given
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(QueryDslPredicateExecutor.class);
|
||||
// when
|
||||
factory.getRepositoryBaseClass(metadata);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,51 +38,51 @@ import static org.junit.Assert.assertThat;
|
||||
@ContextConfiguration("classpath:/simple-repository-test.xml")
|
||||
public class IntegerIDRepositoryTests {
|
||||
|
||||
@Resource
|
||||
private IntegerIDRepository repository;
|
||||
@Resource
|
||||
private IntegerIDRepository repository;
|
||||
|
||||
@Before
|
||||
public void before(){
|
||||
repository.deleteAll();
|
||||
}
|
||||
@Before
|
||||
public void before() {
|
||||
repository.deleteAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDoBulkIndexDocument(){
|
||||
//given
|
||||
Integer documentId1 = RandomUtils.nextInt();
|
||||
IntegerIDEntity sampleEntity1 = new IntegerIDEntity();
|
||||
sampleEntity1.setId(documentId1);
|
||||
sampleEntity1.setMessage("some message");
|
||||
sampleEntity1.setVersion(System.currentTimeMillis());
|
||||
@Test
|
||||
public void shouldDoBulkIndexDocument() {
|
||||
// given
|
||||
Integer documentId1 = RandomUtils.nextInt();
|
||||
IntegerIDEntity sampleEntity1 = new IntegerIDEntity();
|
||||
sampleEntity1.setId(documentId1);
|
||||
sampleEntity1.setMessage("some message");
|
||||
sampleEntity1.setVersion(System.currentTimeMillis());
|
||||
|
||||
Integer documentId2 = RandomUtils.nextInt();
|
||||
IntegerIDEntity sampleEntity2 = new IntegerIDEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
Integer documentId2 = RandomUtils.nextInt();
|
||||
IntegerIDEntity sampleEntity2 = new IntegerIDEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
//when
|
||||
repository.save(Arrays.asList(sampleEntity1, sampleEntity2));
|
||||
//then
|
||||
IntegerIDEntity entity1FromElasticSearch = repository.findOne(documentId1);
|
||||
assertThat(entity1FromElasticSearch, is(notNullValue()));
|
||||
// when
|
||||
repository.save(Arrays.asList(sampleEntity1, sampleEntity2));
|
||||
// then
|
||||
IntegerIDEntity entity1FromElasticSearch = repository.findOne(documentId1);
|
||||
assertThat(entity1FromElasticSearch, is(notNullValue()));
|
||||
|
||||
IntegerIDEntity entity2FromElasticSearch = repository.findOne(documentId2);
|
||||
assertThat(entity2FromElasticSearch, is(notNullValue()));
|
||||
}
|
||||
IntegerIDEntity entity2FromElasticSearch = repository.findOne(documentId2);
|
||||
assertThat(entity2FromElasticSearch, is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSaveDocument(){
|
||||
//given
|
||||
Integer documentId = RandomUtils.nextInt();
|
||||
IntegerIDEntity sampleEntity = new IntegerIDEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
//when
|
||||
repository.save(sampleEntity);
|
||||
//then
|
||||
IntegerIDEntity entityFromElasticSearch = repository.findOne(documentId);
|
||||
assertThat(entityFromElasticSearch, is(notNullValue()));
|
||||
}
|
||||
@Test
|
||||
public void shouldSaveDocument() {
|
||||
// given
|
||||
Integer documentId = RandomUtils.nextInt();
|
||||
IntegerIDEntity sampleEntity = new IntegerIDEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
// when
|
||||
repository.save(sampleEntity);
|
||||
// then
|
||||
IntegerIDEntity entityFromElasticSearch = repository.findOne(documentId);
|
||||
assertThat(entityFromElasticSearch, is(notNullValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.repository.support;
|
||||
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@@ -49,380 +48,367 @@ import static org.junit.Assert.*;
|
||||
@ContextConfiguration("classpath:/simple-repository-test.xml")
|
||||
public class SimpleElasticsearchRepositoryTests {
|
||||
|
||||
@Resource
|
||||
private SampleElasticsearchRepository repository;
|
||||
@Resource
|
||||
private SampleElasticsearchRepository repository;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
repository.deleteAll();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before(){
|
||||
repository.deleteAll();
|
||||
}
|
||||
@Test
|
||||
public void shouldDoBulkIndexDocument() {
|
||||
// given
|
||||
String documentId1 = randomNumeric(5);
|
||||
SampleEntity sampleEntity1 = new SampleEntity();
|
||||
sampleEntity1.setId(documentId1);
|
||||
sampleEntity1.setMessage("some message");
|
||||
sampleEntity1.setVersion(System.currentTimeMillis());
|
||||
|
||||
@Test
|
||||
public void shouldDoBulkIndexDocument(){
|
||||
//given
|
||||
String documentId1 = randomNumeric(5);
|
||||
SampleEntity sampleEntity1 = new SampleEntity();
|
||||
sampleEntity1.setId(documentId1);
|
||||
sampleEntity1.setMessage("some message");
|
||||
sampleEntity1.setVersion(System.currentTimeMillis());
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
// when
|
||||
repository.save(Arrays.asList(sampleEntity1, sampleEntity2));
|
||||
// then
|
||||
SampleEntity entity1FromElasticSearch = repository.findOne(documentId1);
|
||||
assertThat(entity1FromElasticSearch, is(notNullValue()));
|
||||
|
||||
//when
|
||||
repository.save(Arrays.asList(sampleEntity1, sampleEntity2));
|
||||
//then
|
||||
SampleEntity entity1FromElasticSearch = repository.findOne(documentId1);
|
||||
assertThat(entity1FromElasticSearch, is(notNullValue()));
|
||||
SampleEntity entity2FromElasticSearch = repository.findOne(documentId2);
|
||||
assertThat(entity2FromElasticSearch, is(notNullValue()));
|
||||
}
|
||||
|
||||
SampleEntity entity2FromElasticSearch = repository.findOne(documentId2);
|
||||
assertThat(entity2FromElasticSearch, is(notNullValue()));
|
||||
}
|
||||
@Test
|
||||
public void shouldSaveDocument() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
// when
|
||||
repository.save(sampleEntity);
|
||||
// then
|
||||
SampleEntity entityFromElasticSearch = repository.findOne(documentId);
|
||||
assertThat(entityFromElasticSearch, is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSaveDocument(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
//when
|
||||
repository.save(sampleEntity);
|
||||
//then
|
||||
SampleEntity entityFromElasticSearch = repository.findOne(documentId);
|
||||
assertThat(entityFromElasticSearch, is(notNullValue()));
|
||||
}
|
||||
@Test
|
||||
public void shouldFindDocumentById() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
SampleEntity entityFromElasticSearch = repository.findOne(documentId);
|
||||
// then
|
||||
assertThat(entityFromElasticSearch, is(notNullValue()));
|
||||
assertThat(sampleEntity, is((equalTo(sampleEntity))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindDocumentById(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
//when
|
||||
SampleEntity entityFromElasticSearch = repository.findOne(documentId);
|
||||
//then
|
||||
assertThat(entityFromElasticSearch, is(notNullValue()));
|
||||
assertThat(sampleEntity, is((equalTo(sampleEntity))));
|
||||
}
|
||||
@Test
|
||||
public void shouldReturnCountOfDocuments() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
Long count = repository.count();
|
||||
// then
|
||||
assertThat(count, is(greaterThanOrEqualTo(1L)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnCountOfDocuments(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
//when
|
||||
Long count = repository.count();
|
||||
//then
|
||||
assertThat(count, is(greaterThanOrEqualTo(1L)));
|
||||
}
|
||||
@Test
|
||||
public void shouldFindAllDocuments() {
|
||||
// when
|
||||
Iterable<SampleEntity> results = repository.findAll();
|
||||
// then
|
||||
assertThat(results, is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindAllDocuments(){
|
||||
//when
|
||||
Iterable<SampleEntity> results = repository.findAll();
|
||||
//then
|
||||
assertThat(results, is(notNullValue()));
|
||||
}
|
||||
@Test
|
||||
public void shouldDeleteDocument() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
repository.delete(documentId);
|
||||
// then
|
||||
SampleEntity entityFromElasticSearch = repository.findOne(documentId);
|
||||
assertThat(entityFromElasticSearch, is(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeleteDocument(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
//when
|
||||
repository.delete(documentId);
|
||||
//then
|
||||
SampleEntity entityFromElasticSearch = repository.findOne(documentId);
|
||||
assertThat(entityFromElasticSearch, is(nullValue()));
|
||||
}
|
||||
@Test
|
||||
public void shouldSearchDocumentsGivenSearchQuery() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("some test message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
public void shouldSearchDocumentsGivenSearchQuery(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("some test message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
SearchQuery query = new NativeSearchQueryBuilder().withQuery(termQuery("message", "test")).build();
|
||||
// when
|
||||
Page<SampleEntity> page = repository.search(query);
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getNumberOfElements(), is(greaterThanOrEqualTo(1)));
|
||||
}
|
||||
|
||||
SearchQuery query = new NativeSearchQueryBuilder()
|
||||
.withQuery(termQuery("message", "test"))
|
||||
.build();
|
||||
//when
|
||||
Page<SampleEntity> page = repository.search(query);
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getNumberOfElements(), is(greaterThanOrEqualTo(1)));
|
||||
}
|
||||
@Test
|
||||
public void shouldSearchDocumentsGivenElasticsearchQuery() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("hello world.");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
Page<SampleEntity> page = repository.search(termQuery("message", "world"), new PageRequest(0, 50));
|
||||
// then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getNumberOfElements(), is(greaterThanOrEqualTo(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSearchDocumentsGivenElasticsearchQuery(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("hello world.");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
//when
|
||||
Page<SampleEntity> page = repository.search(termQuery("message", "world"), new PageRequest(0,50));
|
||||
//then
|
||||
assertThat(page, is(notNullValue()));
|
||||
assertThat(page.getNumberOfElements(), is(greaterThanOrEqualTo(1)));
|
||||
}
|
||||
@Test
|
||||
@Ignore
|
||||
public void shouldFindAllByIdQuery() {
|
||||
// todo : find solution for findAll(Iterable<Ids> ids)
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("hello world.");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void shouldFindAllByIdQuery(){
|
||||
//todo : find solution for findAll(Iterable<Ids> ids)
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("hello world.");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("hello world.");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity2);
|
||||
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("hello world.");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity2);
|
||||
// when
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(Arrays.asList(documentId, documentId2));
|
||||
|
||||
//when
|
||||
Iterable<SampleEntity> sampleEntities=repository.findAll(Arrays.asList(documentId,documentId2));
|
||||
// then
|
||||
assertNotNull("sample entities cant be null..", sampleEntities);
|
||||
}
|
||||
|
||||
//then
|
||||
assertNotNull("sample entities cant be null..", sampleEntities);
|
||||
}
|
||||
@Test
|
||||
public void shouldSaveIterableEntities() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity1 = new SampleEntity();
|
||||
sampleEntity1.setId(documentId);
|
||||
sampleEntity1.setMessage("hello world.");
|
||||
sampleEntity1.setVersion(System.currentTimeMillis());
|
||||
|
||||
@Test
|
||||
public void shouldSaveIterableEntities(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity1 = new SampleEntity();
|
||||
sampleEntity1.setId(documentId);
|
||||
sampleEntity1.setMessage("hello world.");
|
||||
sampleEntity1.setVersion(System.currentTimeMillis());
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("hello world.");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("hello world.");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
Iterable<SampleEntity> sampleEntities = Arrays.asList(sampleEntity1, sampleEntity2);
|
||||
// when
|
||||
repository.save(sampleEntities);
|
||||
// then
|
||||
Page<SampleEntity> entities = repository.search(fieldQuery("id", documentId), new PageRequest(0, 50));
|
||||
assertNotNull(entities);
|
||||
}
|
||||
|
||||
Iterable<SampleEntity> sampleEntities = Arrays.asList(sampleEntity1,sampleEntity2);
|
||||
//when
|
||||
repository.save(sampleEntities);
|
||||
//then
|
||||
Page<SampleEntity> entities = repository.search(fieldQuery("id", documentId), new PageRequest(0, 50));
|
||||
assertNotNull(entities);
|
||||
}
|
||||
@Test
|
||||
public void shouldReturnTrueGivenDocumentWithIdExists() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("hello world.");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
public void shouldReturnTrueGivenDocumentWithIdExists(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("hello world.");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
boolean exist = repository.exists(documentId);
|
||||
|
||||
//when
|
||||
boolean exist = repository.exists(documentId);
|
||||
// then
|
||||
assertEquals(exist, true);
|
||||
}
|
||||
|
||||
//then
|
||||
assertEquals(exist, true);
|
||||
}
|
||||
@Test
|
||||
public void shouldReturnResultsForGivenSearchQuery() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("hello world.");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(fieldQuery("id", documentId)).build();
|
||||
Page<SampleEntity> sampleEntities = repository.search(searchQuery);
|
||||
// then
|
||||
assertThat(sampleEntities.getTotalElements(), equalTo(1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnResultsForGivenSearchQuery(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("hello world.");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
//when
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(fieldQuery("id",documentId))
|
||||
.build();
|
||||
Page<SampleEntity> sampleEntities= repository.search(searchQuery);
|
||||
//then
|
||||
assertThat(sampleEntities.getTotalElements(), equalTo(1L));
|
||||
}
|
||||
@Test
|
||||
public void shouldDeleteAll() {
|
||||
// when
|
||||
repository.deleteAll();
|
||||
// then
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||
Page<SampleEntity> sampleEntities = repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements(), equalTo(0L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeleteAll(){
|
||||
//when
|
||||
repository.deleteAll();
|
||||
//then
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(matchAllQuery())
|
||||
.build();
|
||||
Page<SampleEntity> sampleEntities= repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements(), equalTo(0L));
|
||||
}
|
||||
@Test
|
||||
public void shouldDeleteEntity() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("hello world.");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
// when
|
||||
repository.delete(sampleEntity);
|
||||
// then
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(fieldQuery("id", documentId)).build();
|
||||
Page<SampleEntity> sampleEntities = repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements(), equalTo(0L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeleteEntity(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("hello world.");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity);
|
||||
//when
|
||||
repository.delete(sampleEntity);
|
||||
//then
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(fieldQuery("id", documentId))
|
||||
.build();
|
||||
Page<SampleEntity> sampleEntities= repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements(),equalTo(0L));
|
||||
}
|
||||
@Test
|
||||
public void shouldReturnIterableEntities() {
|
||||
// given
|
||||
String documentId1 = randomNumeric(5);
|
||||
SampleEntity sampleEntity1 = new SampleEntity();
|
||||
sampleEntity1.setId(documentId1);
|
||||
sampleEntity1.setMessage("hello world.");
|
||||
sampleEntity1.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity1);
|
||||
|
||||
@Test
|
||||
public void shouldReturnIterableEntities(){
|
||||
//given
|
||||
String documentId1 = randomNumeric(5);
|
||||
SampleEntity sampleEntity1 = new SampleEntity();
|
||||
sampleEntity1.setId(documentId1);
|
||||
sampleEntity1.setMessage("hello world.");
|
||||
sampleEntity1.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity1);
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("hello world.");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity2);
|
||||
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("hello world.");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity2);
|
||||
// when
|
||||
Iterable<SampleEntity> sampleEntities = repository.search(fieldQuery("id", documentId1));
|
||||
// then
|
||||
assertNotNull("sample entities cant be null..", sampleEntities);
|
||||
}
|
||||
|
||||
//when
|
||||
Iterable<SampleEntity> sampleEntities = repository.search(fieldQuery("id",documentId1));
|
||||
//then
|
||||
assertNotNull("sample entities cant be null..", sampleEntities);
|
||||
}
|
||||
@Test
|
||||
public void shouldDeleteIterableEntities() {
|
||||
// given
|
||||
String documentId1 = randomNumeric(5);
|
||||
SampleEntity sampleEntity1 = new SampleEntity();
|
||||
sampleEntity1.setId(documentId1);
|
||||
sampleEntity1.setMessage("hello world.");
|
||||
sampleEntity1.setVersion(System.currentTimeMillis());
|
||||
|
||||
@Test
|
||||
public void shouldDeleteIterableEntities(){
|
||||
//given
|
||||
String documentId1 = randomNumeric(5);
|
||||
SampleEntity sampleEntity1 = new SampleEntity();
|
||||
sampleEntity1.setId(documentId1);
|
||||
sampleEntity1.setMessage("hello world.");
|
||||
sampleEntity1.setVersion(System.currentTimeMillis());
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("hello world.");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity2);
|
||||
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("hello world.");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
repository.save(sampleEntity2);
|
||||
Iterable<SampleEntity> sampleEntities = Arrays.asList(sampleEntity2, sampleEntity2);
|
||||
// when
|
||||
repository.delete(sampleEntities);
|
||||
// then
|
||||
assertThat(repository.findOne(documentId1), is(nullValue()));
|
||||
assertThat(repository.findOne(documentId2), is(nullValue()));
|
||||
}
|
||||
|
||||
Iterable<SampleEntity> sampleEntities = Arrays.asList(sampleEntity2,sampleEntity2);
|
||||
//when
|
||||
repository.delete(sampleEntities);
|
||||
//then
|
||||
assertThat(repository.findOne(documentId1),is(nullValue()));
|
||||
assertThat(repository.findOne(documentId2),is(nullValue()));
|
||||
}
|
||||
@Test
|
||||
public void shouldIndexEntity() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
sampleEntity.setMessage("some message");
|
||||
// when
|
||||
repository.index(sampleEntity);
|
||||
// then
|
||||
Page<SampleEntity> entities = repository.search(fieldQuery("id", documentId), new PageRequest(0, 50));
|
||||
assertThat(entities.getTotalElements(), equalTo(1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldIndexEntity(){
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
sampleEntity.setMessage("some message");
|
||||
//when
|
||||
repository.index(sampleEntity);
|
||||
//then
|
||||
Page<SampleEntity> entities = repository.search(fieldQuery("id", documentId), new PageRequest(0,50));
|
||||
assertThat(entities.getTotalElements(),equalTo(1L));
|
||||
}
|
||||
@Test
|
||||
public void shouldSortByGivenField() {
|
||||
// todo
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("world");
|
||||
repository.save(sampleEntity);
|
||||
|
||||
@Test
|
||||
public void shouldSortByGivenField(){
|
||||
//todo
|
||||
//given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("world");
|
||||
repository.save(sampleEntity);
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("hello");
|
||||
repository.save(sampleEntity2);
|
||||
// when
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(new Sort(new Sort.Order(Sort.Direction.ASC, "message")));
|
||||
// then
|
||||
assertThat(sampleEntities, is(notNullValue()));
|
||||
}
|
||||
|
||||
String documentId2 = randomNumeric(5);
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("hello");
|
||||
repository.save(sampleEntity2);
|
||||
//when
|
||||
Iterable<SampleEntity> sampleEntities=repository.findAll(new Sort(new Sort.Order(Sort.Direction.ASC,"message")));
|
||||
//then
|
||||
assertThat(sampleEntities,is(notNullValue()));
|
||||
}
|
||||
@Test
|
||||
public void shouldReturnSimilarEntities() {
|
||||
// given
|
||||
String sampleMessage = "So we build a web site or an application and want to add search to it, "
|
||||
+ "and then it hits us: getting search working is hard. We want our search solution to be fast,"
|
||||
+ " we want a painless setup and a completely free search schema, we want to be able to index data simply using JSON over HTTP, "
|
||||
+ "we want our search server to be always available, we want to be able to start with one machine and scale to hundreds, "
|
||||
+ "we want real-time search, we want simple multi-tenancy, and we want a solution that is built for the cloud.";
|
||||
|
||||
@Test
|
||||
public void shouldReturnSimilarEntities(){
|
||||
//given
|
||||
String sampleMessage = "So we build a web site or an application and want to add search to it, " +
|
||||
"and then it hits us: getting search working is hard. We want our search solution to be fast," +
|
||||
" we want a painless setup and a completely free search schema, we want to be able to index data simply using JSON over HTTP, " +
|
||||
"we want our search server to be always available, we want to be able to start with one machine and scale to hundreds, " +
|
||||
"we want real-time search, we want simple multi-tenancy, and we want a solution that is built for the cloud.";
|
||||
List<SampleEntity> sampleEntities = createSampleEntitiesWithMessage(sampleMessage, 30);
|
||||
repository.save(sampleEntities);
|
||||
|
||||
// when
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withPageable(new PageRequest(0, 5)).withFields("message")
|
||||
.build();
|
||||
Page<SampleEntity> results = repository.searchSimilar(sampleEntities.get(0), searchQuery);
|
||||
|
||||
// then
|
||||
assertThat(results.getTotalElements(), is(greaterThanOrEqualTo(1L)));
|
||||
}
|
||||
|
||||
List<SampleEntity> sampleEntities = createSampleEntitiesWithMessage(sampleMessage, 30);
|
||||
repository.save(sampleEntities);
|
||||
|
||||
//when
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withPageable(new PageRequest(0, 5))
|
||||
.withFields("message")
|
||||
.build();
|
||||
Page<SampleEntity> results = repository.searchSimilar(sampleEntities.get(0), searchQuery);
|
||||
|
||||
//then
|
||||
assertThat(results.getTotalElements(), is(greaterThanOrEqualTo(1L)));
|
||||
}
|
||||
|
||||
private static List<SampleEntity> createSampleEntitiesWithMessage(String message, int numberOfEntities){
|
||||
List<SampleEntity> sampleEntities = new ArrayList<SampleEntity>();
|
||||
for(int i = 0; i < numberOfEntities; i++){
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage(message);
|
||||
sampleEntity.setRate(2);
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
sampleEntities.add(sampleEntity);
|
||||
}
|
||||
return sampleEntities;
|
||||
}
|
||||
private static List<SampleEntity> createSampleEntitiesWithMessage(String message, int numberOfEntities) {
|
||||
List<SampleEntity> sampleEntities = new ArrayList<SampleEntity>();
|
||||
for (int i = 0; i < numberOfEntities; i++) {
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage(message);
|
||||
sampleEntity.setRate(2);
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
sampleEntities.add(sampleEntity);
|
||||
}
|
||||
return sampleEntities;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user