1919
2020import java .text .ParseException ;
2121import java .text .SimpleDateFormat ;
22+ import java .util .ArrayList ;
2223
2324import org .junit .jupiter .api .Test ;
2425import org .springframework .beans .factory .annotation .Autowired ;
2526import org .springframework .boot .test .context .SpringBootTest ;
2627import org .springframework .context .annotation .Configuration ;
2728import org .springframework .data .elasticsearch .client .ClientConfiguration ;
2829import org .springframework .data .elasticsearch .client .elc .ElasticsearchConfiguration ;
30+ import org .springframework .data .elasticsearch .client .elc .ElasticsearchTemplate ;
2931import org .springframework .data .elasticsearch .core .ElasticsearchOperations ;
32+ import org .springframework .data .elasticsearch .core .SearchHit ;
3033import org .springframework .data .elasticsearch .core .geo .GeoPoint ;
3134import org .springframework .data .elasticsearch .core .mapping .IndexCoordinates ;
3235import org .springframework .data .elasticsearch .core .query .Criteria ;
4346 * @author Artur Konczak
4447 * @author Oliver Gierke
4548 * @author Christoph Strobl
49+ * @author omniCoder77
4650 * @author Prakhar Gupta
4751 * @author Peter-Josef Meisch
4852 */
@@ -73,6 +77,8 @@ public ClientConfiguration clientConfiguration() {
7377 }
7478
7579 @ Autowired ElasticsearchOperations operations ;
80+ @ Autowired
81+ ElasticsearchTemplate template ;
7682
7783 @ Test
7884 void textSearch () throws ParseException {
@@ -103,4 +109,29 @@ void geoSpatialSearch() {
103109
104110 assertThat (result ).hasSize (2 );
105111 }
106- }
112+
113+ @ Test
114+ void shouldUpdateConferenceKeywords () {
115+ var conferenceName = "JDD14 - Cracow" ;
116+ var newKeyword = "java-ee" ;
117+
118+ var initialQuery = new CriteriaQuery (new Criteria ("name" ).is (conferenceName ));
119+ SearchHit <Conference > searchHit = template .searchOne (initialQuery , Conference .class );
120+ assertThat (searchHit ).isNotNull ();
121+
122+ Conference conference = searchHit .getContent ();
123+ String conferenceId = searchHit .getId ();
124+
125+ int originalKeywordsCount = conference .getKeywords ().size ();
126+ assertThat (conference .getKeywords ()).doesNotContain (newKeyword );
127+
128+ conference .getKeywords ().add (newKeyword );
129+
130+ template .save (conference );
131+
132+ Conference updatedConference = template .get (conferenceId , Conference .class );
133+ assertThat (updatedConference ).isNotNull ();
134+ assertThat (updatedConference .getKeywords ()).contains (newKeyword );
135+ assertThat (updatedConference .getKeywords ()).hasSize (originalKeywordsCount + 1 );
136+ }
137+ }
0 commit comments