19
19
20
20
import java .text .ParseException ;
21
21
import java .text .SimpleDateFormat ;
22
+ import java .util .ArrayList ;
22
23
23
24
import org .junit .jupiter .api .Test ;
24
25
import org .springframework .beans .factory .annotation .Autowired ;
25
26
import org .springframework .boot .test .context .SpringBootTest ;
26
27
import org .springframework .context .annotation .Configuration ;
27
28
import org .springframework .data .elasticsearch .client .ClientConfiguration ;
28
29
import org .springframework .data .elasticsearch .client .elc .ElasticsearchConfiguration ;
30
+ import org .springframework .data .elasticsearch .client .elc .ElasticsearchTemplate ;
29
31
import org .springframework .data .elasticsearch .core .ElasticsearchOperations ;
32
+ import org .springframework .data .elasticsearch .core .SearchHit ;
30
33
import org .springframework .data .elasticsearch .core .geo .GeoPoint ;
31
34
import org .springframework .data .elasticsearch .core .mapping .IndexCoordinates ;
32
35
import org .springframework .data .elasticsearch .core .query .Criteria ;
43
46
* @author Artur Konczak
44
47
* @author Oliver Gierke
45
48
* @author Christoph Strobl
49
+ * @author omniCoder77
46
50
* @author Prakhar Gupta
47
51
* @author Peter-Josef Meisch
48
52
*/
@@ -73,6 +77,8 @@ public ClientConfiguration clientConfiguration() {
73
77
}
74
78
75
79
@ Autowired ElasticsearchOperations operations ;
80
+ @ Autowired
81
+ ElasticsearchTemplate template ;
76
82
77
83
@ Test
78
84
void textSearch () throws ParseException {
@@ -103,4 +109,29 @@ void geoSpatialSearch() {
103
109
104
110
assertThat (result ).hasSize (2 );
105
111
}
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