1616package org .springframework .data .elasticsearch .repositories ;
1717
1818import org .junit .Before ;
19+ import org .junit .Test ;
1920import org .junit .runner .RunWith ;
2021import org .springframework .beans .factory .annotation .Autowired ;
2122import org .springframework .data .elasticsearch .core .ElasticsearchTemplate ;
23+ import org .springframework .data .elasticsearch .entities .Author ;
2224import org .springframework .data .elasticsearch .entities .Book ;
2325import org .springframework .data .elasticsearch .entities .Person ;
2426import org .springframework .test .context .ContextConfiguration ;
2527import 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