Fixed issue related to nested objects
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package org.springframework.data.elasticsearch;
|
||||
|
||||
public class Author {
|
||||
private String name;
|
||||
private String id;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.springframework.data.elasticsearch;
|
||||
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
|
||||
@Document(indexName = "book",type = "book")
|
||||
public class Book {
|
||||
private String id;
|
||||
private String name;
|
||||
private Author author;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Author getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(Author author) {
|
||||
this.author = author;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.springframework.data.elasticsearch;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.elasticsearch.repositories.SampleElasticSearchBookRepository;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
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;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/repository-test-nested-object.xml")
|
||||
public class NestedObjectTest{
|
||||
|
||||
@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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package org.springframework.data.elasticsearch;
|
||||
|
||||
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
@Document(indexName = "Foo")
|
||||
public class NonDocumentEntity {
|
||||
|
||||
@Id
|
||||
private String someId;
|
||||
private String someField1;
|
||||
private String someField2;
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.springframework.data.elasticsearch;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.elasticsearch.repositories.NonDocumentEntityRepository;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/repository-non-document-entity.xml")
|
||||
public class NonDocumentEntityTest {
|
||||
|
||||
@Resource
|
||||
private NonDocumentEntityRepository nonDocumentEntityRepository;
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldNotIndexEntitiesWhichAreNotADocument(){
|
||||
//when
|
||||
nonDocumentEntityRepository.save(new NonDocumentEntity());
|
||||
}
|
||||
}
|
||||
@@ -333,6 +333,4 @@ public class ElasticsearchTemplateTest {
|
||||
assertThat(sampleEntity1, is(notNullValue()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.springframework.data.elasticsearch.repositories;
|
||||
|
||||
import org.springframework.data.elasticsearch.NonDocumentEntity;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
|
||||
public interface NonDocumentEntityRepository extends ElasticsearchRepository<NonDocumentEntity,String> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.springframework.data.elasticsearch.repositories;
|
||||
|
||||
import org.springframework.data.elasticsearch.Book;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
public interface SampleElasticSearchBookRepository extends ElasticsearchRepository<Book,String> {
|
||||
}
|
||||
Reference in New Issue
Block a user