15
15
*/
16
16
package org .springframework .data .elasticsearch .repository .support ;
17
17
18
- import static org .elasticsearch .index .query .QueryBuilders .matchAllQuery ;
19
- import static org .elasticsearch .index .query .QueryBuilders .termQuery ;
20
- import static org .hamcrest .Matchers .equalTo ;
21
- import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
22
- import static org .hamcrest .Matchers .is ;
23
- import static org .hamcrest .Matchers .notNullValue ;
24
- import static org .hamcrest .Matchers .nullValue ;
25
- import static org .junit .Assert .assertEquals ;
26
- import static org .junit .Assert .assertNotNull ;
27
- import static org .junit .Assert .assertThat ;
28
-
29
- import java .util .ArrayList ;
30
- import java .util .Arrays ;
31
- import java .util .List ;
32
- import java .util .UUID ;
33
-
34
- import org .elasticsearch .common .collect .Lists ;
18
+ import static org .elasticsearch .index .query .QueryBuilders .*;
19
+ import static org .hamcrest .Matchers .*;
20
+ import static org .junit .Assert .*;
21
+
22
+ import java .util .*;
23
+
35
24
import org .junit .Before ;
36
25
import org .junit .Test ;
37
26
import org .junit .runner .RunWith ;
@@ -68,8 +57,8 @@ public class UUIDElasticsearchRepositoryTests {
68
57
public void before () {
69
58
elasticsearchTemplate .deleteIndex (SampleEntityUUIDKeyed .class );
70
59
elasticsearchTemplate .createIndex (SampleEntityUUIDKeyed .class );
71
- elasticsearchTemplate .putMapping (SampleEntityUUIDKeyed .class );
72
- elasticsearchTemplate .refresh (SampleEntityUUIDKeyed .class , true );
60
+ elasticsearchTemplate .putMapping (SampleEntityUUIDKeyed .class );
61
+ elasticsearchTemplate .refresh (SampleEntityUUIDKeyed .class );
73
62
}
74
63
75
64
@ Test
@@ -222,12 +211,13 @@ public void shouldFindAllByIdQuery() {
222
211
repository .save (sampleEntityUUIDKeyed2 );
223
212
224
213
// when
225
- Iterable <SampleEntityUUIDKeyed > sampleEntities = repository .findAll (Arrays .asList (documentId , documentId2 ));
214
+ LinkedList <SampleEntityUUIDKeyed > sampleEntities = ( LinkedList < SampleEntityUUIDKeyed >) repository .findAll (Arrays .asList (documentId , documentId2 ));
226
215
227
216
// then
228
217
assertNotNull ("sample entities cant be null.." , sampleEntities );
229
- List <SampleEntityUUIDKeyed > entities = Lists .newArrayList (sampleEntities );
230
- assertThat (entities .size (), is (2 ));
218
+ assertThat (sampleEntities .size (), is (2 ));
219
+ assertThat (sampleEntities .get (0 ).getId (), isIn (Arrays .asList (documentId , documentId2 )));
220
+ assertThat (sampleEntities .get (1 ).getId (), isIn (Arrays .asList (documentId , documentId2 )));
231
221
}
232
222
233
223
@ Test
@@ -324,6 +314,7 @@ public void shouldDeleteByMessageAndReturnList() {
324
314
repository .save (Arrays .asList (sampleEntityUUIDKeyed1 , sampleEntityUUIDKeyed2 , sampleEntityUUIDKeyed3 ));
325
315
// when
326
316
List <SampleEntityUUIDKeyed > result = repository .deleteByAvailable (true );
317
+ repository .refresh ();
327
318
// then
328
319
assertThat (result .size (), equalTo (2 ));
329
320
SearchQuery searchQuery = new NativeSearchQueryBuilder ().withQuery (matchAllQuery ()).build ();
@@ -354,6 +345,7 @@ public void shouldDeleteByListForMessage() {
354
345
repository .save (Arrays .asList (sampleEntityUUIDKeyed1 , sampleEntityUUIDKeyed2 , sampleEntityUUIDKeyed3 ));
355
346
// when
356
347
List <SampleEntityUUIDKeyed > result = repository .deleteByMessage ("hello world 3" );
348
+ repository .refresh ();
357
349
// then
358
350
assertThat (result .size (), equalTo (1 ));
359
351
SearchQuery searchQuery = new NativeSearchQueryBuilder ().withQuery (matchAllQuery ()).build ();
@@ -384,14 +376,14 @@ public void shouldDeleteByType() {
384
376
repository .save (Arrays .asList (sampleEntityUUIDKeyed1 , sampleEntityUUIDKeyed2 , sampleEntityUUIDKeyed3 ));
385
377
// when
386
378
repository .deleteByType ("article" );
379
+ repository .refresh ();
387
380
// then
388
381
SearchQuery searchQuery = new NativeSearchQueryBuilder ().withQuery (matchAllQuery ()).build ();
389
382
Page <SampleEntityUUIDKeyed > sampleEntities = repository .search (searchQuery );
390
383
assertThat (sampleEntities .getTotalElements (), equalTo (2L ));
391
384
}
392
385
393
386
394
-
395
387
@ Test
396
388
public void shouldDeleteEntity () {
397
389
// given
@@ -403,6 +395,7 @@ public void shouldDeleteEntity() {
403
395
repository .save (sampleEntityUUIDKeyed );
404
396
// when
405
397
repository .delete (sampleEntityUUIDKeyed );
398
+ repository .refresh ();
406
399
// then
407
400
SearchQuery searchQuery = new NativeSearchQueryBuilder ().withQuery (termQuery ("id" , documentId )).build ();
408
401
Page <SampleEntityUUIDKeyed > sampleEntities = repository .search (searchQuery );
0 commit comments