4242 * Testing the querying and parsing of inner_hits.
4343 *
4444 * @author Peter-Josef Meisch
45+ * @author Jakob Hoeper
4546 */
4647@ SpringIntegrationTest
4748public abstract class InnerHitsIntegrationTests {
@@ -58,8 +59,9 @@ void setUp() {
5859 indexOps .createWithMapping ();
5960
6061 Inhabitant john = new Inhabitant ("John" , "Smith" );
61- Inhabitant carla = new Inhabitant ("Carla" , "Miller" );
62- House cornerHouse = new House ("Round the corner" , "7" , Arrays .asList (john , carla ));
62+ Inhabitant carla1 = new Inhabitant ("Carla" , "Miller" );
63+ Inhabitant carla2 = new Inhabitant ("Carla" , "Nguyen" );
64+ House cornerHouse = new House ("Round the corner" , "7" , Arrays .asList (john , carla1 , carla2 ));
6365 City metropole = new City ("Metropole" , Arrays .asList (cornerHouse ));
6466
6567 Inhabitant jack = new Inhabitant ("Jack" , "Wayne" );
@@ -76,7 +78,7 @@ void cleanup() {
7678 operations .indexOps (IndexCoordinates .of (indexNameProvider .getPrefix () + "*" )).delete ();
7779 }
7880
79- @ Test
81+ @ Test // #2521
8082 void shouldReturnInnerHits () {
8183
8284 Query query = buildQueryForInnerHits ("inner_hit_name" , "hou-ses.in-habi-tants" , "hou-ses.in-habi-tants.first-name" ,
@@ -91,7 +93,7 @@ void shouldReturnInnerHits() {
9193 softly .assertThat (searchHit .getInnerHits ()).hasSize (1 );
9294
9395 SearchHits <?> innerHits = searchHit .getInnerHits ("inner_hit_name" );
94- softly .assertThat (innerHits ).hasSize (1 );
96+ softly .assertThat (innerHits ).hasSize (2 );
9597
9698 SearchHit <?> innerHit = innerHits .getSearchHit (0 );
9799 Object content = innerHit .getContent ();
@@ -106,6 +108,10 @@ void shouldReturnInnerHits() {
106108 softly .assertThat (nestedMetaData .getChild ().getField ()).isEqualTo ("inhabitants" );
107109 softly .assertThat (nestedMetaData .getChild ().getOffset ()).isEqualTo (1 );
108110
111+ innerHit = innerHits .getSearchHit (1 );
112+ softly .assertThat (((Inhabitant ) innerHit .getContent ()).getLastName ()).isEqualTo ("Nguyen" );
113+ softly .assertThat (innerHit .getNestedMetaData ().getChild ().getOffset ()).isEqualTo (2 );
114+
109115 softly .assertAll ();
110116 }
111117
0 commit comments