1010package org .opensearch .data .client .core .index ;
1111
1212
13+ import static org .assertj .core .api .Assertions .assertThat ;
14+
1315import java .util .HashMap ;
1416import java .util .Map ;
1517import org .junit .jupiter .api .AfterEach ;
2426import org .springframework .data .elasticsearch .core .ElasticsearchOperations ;
2527import org .springframework .data .elasticsearch .core .IndexOperations ;
2628import org .springframework .data .elasticsearch .core .mapping .IndexCoordinates ;
29+ import org .springframework .data .elasticsearch .core .query .Query ;
2730import org .springframework .data .elasticsearch .junit .jupiter .SpringIntegrationTest ;
2831import org .springframework .data .elasticsearch .utils .IndexNameProvider ;
2932import org .springframework .lang .Nullable ;
@@ -46,14 +49,20 @@ void cleanup() {
4649 @ Test
4750 void shouldCreateDynamicTemplateOne () {
4851 IndexOperations indexOperations = operations .indexOps (SampleDynamicTemplatesEntity .class );
49- indexOperations .createWithMapping ();
52+ assertThat (indexOperations .createWithMapping ()).isTrue ();
53+
54+ operations .save (new SampleDynamicTemplatesEntity (Map .of ("John" , "Smith" )));
55+ assertThat (operations .search (Query .findAll (), SampleDynamicTemplatesEntity .class ).get ().count ()).isEqualTo (1L );
5056 }
5157
5258
5359 @ Test
5460 void shouldCreateDynamicTemplateTwo () {
5561 IndexOperations indexOperations = operations .indexOps (SampleDynamicTemplatesEntityTwo .class );
56- indexOperations .createWithMapping ();
62+ assertThat (indexOperations .createWithMapping ()).isTrue ();
63+
64+ operations .save (new SampleDynamicTemplatesEntityTwo ("Other string" ));
65+ assertThat (operations .search (Query .findAll (), SampleDynamicTemplatesEntityTwo .class ).get ().count ()).isEqualTo (1L );
5766 }
5867
5968 /**
@@ -67,7 +76,15 @@ static class SampleDynamicTemplatesEntity {
6776 @ Id private String id ;
6877
6978 @ Nullable
70- @ Field (type = FieldType .Object ) private final Map <String , String > names = new HashMap <>();
79+ @ Field (type = FieldType .Object ) private final Map <String , String > names ;
80+
81+ public SampleDynamicTemplatesEntity () {
82+ this (new HashMap <>());
83+ }
84+
85+ public SampleDynamicTemplatesEntity (final Map <String , String > names ) {
86+ this .names = names ;
87+ }
7188 }
7289
7390 /**
@@ -81,6 +98,13 @@ static class SampleDynamicTemplatesEntityTwo {
8198 @ Id private String id ;
8299
83100 @ Nullable
84- @ Field (type = FieldType .Object ) private final Map <String , String > names = new HashMap <>();
101+ @ Field (type = FieldType .Text ) private String others ;
102+
103+ public SampleDynamicTemplatesEntityTwo () {
104+ }
105+
106+ public SampleDynamicTemplatesEntityTwo (final String others ) {
107+ this .others = others ;
108+ }
85109 }
86110}
0 commit comments