18
18
19
19
import static org .hamcrest .Matchers .*;
20
20
import static org .junit .Assert .*;
21
+ import static org .springframework .data .domain .ExampleMatcher .*;
22
+
23
+ import lombok .Data ;
24
+ import lombok .NoArgsConstructor ;
25
+ import reactor .core .publisher .Flux ;
26
+ import reactor .core .publisher .Mono ;
27
+ import reactor .test .TestSubscriber ;
21
28
22
29
import java .util .Arrays ;
23
30
import java .util .List ;
24
- import java .util .stream .Collectors ;
25
31
26
32
import org .junit .Before ;
27
33
import org .junit .Test ;
32
38
import org .springframework .beans .factory .BeanFactoryAware ;
33
39
import org .springframework .beans .factory .annotation .Autowired ;
34
40
import org .springframework .data .annotation .Id ;
35
- import org .springframework .data .domain .Page ;
36
- import org .springframework .data .domain .PageRequest ;
41
+ import org .springframework .data .domain .Example ;
37
42
import org .springframework .data .domain .Sort ;
38
43
import org .springframework .data .domain .Sort .Direction ;
39
44
import org .springframework .data .domain .Sort .Order ;
45
50
import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
46
51
import org .springframework .util .ClassUtils ;
47
52
48
- import lombok .Data ;
49
- import lombok .NoArgsConstructor ;
50
- import reactor .core .publisher .Flux ;
51
- import reactor .core .publisher .Mono ;
52
- import reactor .test .TestSubscriber ;
53
-
54
53
/**
55
54
* Test for {@link ReactiveMongoRepository}.
56
55
*
@@ -422,7 +421,6 @@ public void deleteIterableOfEntitiesShouldRemoveEntities() {
422
421
List <ReactivePerson > matthews = repository .findByLastname ("Matthews" ).collectList ().block ();
423
422
assertThat (matthews , hasSize (1 ));
424
423
assertThat (matthews , contains (oliver ));
425
-
426
424
}
427
425
428
426
@ Test // DATAMONGO-1444
@@ -438,7 +436,67 @@ public void deletePublisherOfEntitiesShouldRemoveEntities() {
438
436
List <ReactivePerson > matthews = repository .findByLastname ("Matthews" ).collectList ().block ();
439
437
assertThat (matthews , hasSize (1 ));
440
438
assertThat (matthews , contains (oliver ));
439
+ }
440
+
441
+ @ Test // DATAMONGO-1619
442
+ public void findOneByExampleShouldReturnObject () {
443
+
444
+ Example <ReactivePerson > example = Example .of (dave );
445
+
446
+ TestSubscriber <ReactivePerson > testSubscriber = TestSubscriber .subscribe (repository .findOne (example ));
447
+
448
+ testSubscriber .await ().assertComplete ().assertValues (dave );
449
+ }
450
+
451
+ @ Test // DATAMONGO-1619
452
+ public void findAllByExampleShouldReturnObjects () {
453
+
454
+ Example <ReactivePerson > example = Example .of (dave , matching ().withIgnorePaths ("id" , "age" , "firstname" ));
455
+
456
+ TestSubscriber <ReactivePerson > testSubscriber = TestSubscriber .subscribe (repository .findAll (example ));
457
+
458
+ testSubscriber .await ().assertComplete ().assertValueCount (2 );
459
+ }
460
+
461
+ @ Test // DATAMONGO-1619
462
+ public void findAllByExampleAndSortShouldReturnObjects () {
463
+
464
+ Example <ReactivePerson > example = Example .of (dave , matching ().withIgnorePaths ("id" , "age" , "firstname" ));
465
+
466
+ TestSubscriber <ReactivePerson > testSubscriber = TestSubscriber
467
+ .subscribe (repository .findAll (example , new Sort ("firstname" )));
468
+
469
+ testSubscriber .await ().assertComplete ().assertValues (dave , oliver );
470
+ }
471
+
472
+ @ Test // DATAMONGO-1619
473
+ public void countByExampleShouldCountObjects () {
474
+
475
+ Example <ReactivePerson > example = Example .of (dave , matching ().withIgnorePaths ("id" , "age" , "firstname" ));
476
+
477
+ TestSubscriber <Long > testSubscriber = TestSubscriber .subscribe (repository .count (example ));
478
+
479
+ testSubscriber .await ().assertComplete ().assertValues (2L );
480
+ }
481
+
482
+ @ Test // DATAMONGO-1619
483
+ public void existsByExampleShouldReturnExisting () {
484
+
485
+ Example <ReactivePerson > example = Example .of (dave , matching ().withIgnorePaths ("id" , "age" , "firstname" ));
486
+
487
+ TestSubscriber <Boolean > testSubscriber = TestSubscriber .subscribe (repository .exists (example ));
488
+
489
+ testSubscriber .await ().assertComplete ().assertValues (true );
490
+ }
491
+
492
+ @ Test // DATAMONGO-1619
493
+ public void existsByExampleShouldReturnNonExisting () {
494
+
495
+ Example <ReactivePerson > example = Example .of (new ReactivePerson ("foo" , "bar" , -1 ));
496
+
497
+ TestSubscriber <Boolean > testSubscriber = TestSubscriber .subscribe (repository .exists (example ));
441
498
499
+ testSubscriber .await ().assertComplete ().assertValues (false );
442
500
}
443
501
444
502
interface ReactivePersonRepostitory extends ReactiveMongoRepository <ReactivePerson , String > {
0 commit comments