Skip to content

Commit e753b98

Browse files
committed
added test case for simple object type
1 parent 6d299aa commit e753b98

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/test/java/org/springframework/data/elasticsearch/repositories/NestedObjectTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@
1616
package org.springframework.data.elasticsearch.repositories;
1717

1818
import org.junit.Before;
19+
import org.junit.Test;
1920
import org.junit.runner.RunWith;
2021
import org.springframework.beans.factory.annotation.Autowired;
2122
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
23+
import org.springframework.data.elasticsearch.entities.Author;
2224
import org.springframework.data.elasticsearch.entities.Book;
2325
import org.springframework.data.elasticsearch.entities.Person;
2426
import org.springframework.test.context.ContextConfiguration;
2527
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2628

29+
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
30+
import static org.hamcrest.core.Is.is;
31+
import static org.hamcrest.core.IsNull.notNullValue;
32+
import static org.junit.Assert.assertThat;
33+
2734
/**
2835
* @author Rizwan Idrees
2936
* @author Mohsin Husen
@@ -36,6 +43,8 @@ public class NestedObjectTests {
3643
@Autowired
3744
private ElasticsearchTemplate elasticsearchTemplate;
3845

46+
@Autowired
47+
private SampleBookRepository bookRepository;
3948

4049
@Before
4150
public void before() {
@@ -47,4 +56,20 @@ public void before() {
4756
elasticsearchTemplate.putMapping(Person.class);
4857
elasticsearchTemplate.refresh(Person.class, true);
4958
}
59+
60+
@Test
61+
public void shouldIndexInnerObject() {
62+
// given
63+
String id = randomAlphanumeric(5);
64+
Book book = new Book();
65+
book.setId(id);
66+
book.setName("xyz");
67+
Author author = new Author();
68+
author.setId("1");
69+
author.setName("ABC");
70+
// when
71+
bookRepository.save(book);
72+
// then
73+
assertThat(bookRepository.findOne(id), is(notNullValue()));
74+
}
5075
}

0 commit comments

Comments
 (0)