20
20
21
21
import lombok .Data ;
22
22
import lombok .NoArgsConstructor ;
23
+ import lombok .Value ;
24
+ import lombok .With ;
23
25
import reactor .core .publisher .Flux ;
24
26
import reactor .core .publisher .Mono ;
25
27
import reactor .test .StepVerifier ;
26
28
27
29
import java .util .Arrays ;
28
30
31
+ import javax .annotation .Nullable ;
32
+
29
33
import org .junit .Before ;
30
34
import org .junit .Test ;
31
35
import org .junit .runner .RunWith ;
32
-
33
36
import org .springframework .beans .BeansException ;
34
37
import org .springframework .beans .factory .BeanClassLoaderAware ;
35
38
import org .springframework .beans .factory .BeanFactory ;
44
47
import org .springframework .data .mongodb .core .ReactiveMongoTemplate ;
45
48
import org .springframework .data .mongodb .repository .support .ReactiveMongoRepositoryFactory ;
46
49
import org .springframework .data .mongodb .repository .support .SimpleReactiveMongoRepository ;
47
- import org .springframework .data .repository .query .QueryMethodEvaluationContextProvider ;
48
50
import org .springframework .data .repository .query .ReactiveQueryMethodEvaluationContextProvider ;
49
51
import org .springframework .test .context .ContextConfiguration ;
50
52
import org .springframework .test .context .junit4 .SpringRunner ;
56
58
* @author Mark Paluch
57
59
* @author Christoph Strobl
58
60
* @author Ruben J Garcia
61
+ * @author Clément Petit
59
62
*/
60
63
@ RunWith (SpringRunner .class )
61
64
@ ContextConfiguration ("classpath:reactive-infrastructure.xml" )
@@ -66,9 +69,11 @@ public class SimpleReactiveMongoRepositoryTests implements BeanClassLoaderAware,
66
69
ReactiveMongoRepositoryFactory factory ;
67
70
ClassLoader classLoader ;
68
71
BeanFactory beanFactory ;
69
- ReactivePersonRepostitory repository ;
72
+ ReactivePersonRepository repository ;
73
+ ReactiveImmutablePersonRepository immutableRepository ;
70
74
71
75
private ReactivePerson dave , oliver , carter , boyd , stefan , leroi , alicia ;
76
+ private ImmutableReactivePerson keith , james , mariah ;
72
77
73
78
@ Override
74
79
public void setBeanClassLoader (ClassLoader classLoader ) {
@@ -89,9 +94,11 @@ public void setUp() {
89
94
factory .setBeanFactory (beanFactory );
90
95
factory .setEvaluationContextProvider (ReactiveQueryMethodEvaluationContextProvider .DEFAULT );
91
96
92
- repository = factory .getRepository (ReactivePersonRepostitory .class );
97
+ repository = factory .getRepository (ReactivePersonRepository .class );
98
+ immutableRepository = factory .getRepository (ReactiveImmutablePersonRepository .class );
93
99
94
100
repository .deleteAll ().as (StepVerifier ::create ).verifyComplete ();
101
+ immutableRepository .deleteAll ().as (StepVerifier ::create ).verifyComplete ();
95
102
96
103
dave = new ReactivePerson ("Dave" , "Matthews" , 42 );
97
104
oliver = new ReactivePerson ("Oliver August" , "Matthews" , 4 );
@@ -100,6 +107,9 @@ public void setUp() {
100
107
stefan = new ReactivePerson ("Stefan" , "Lessard" , 34 );
101
108
leroi = new ReactivePerson ("Leroi" , "Moore" , 41 );
102
109
alicia = new ReactivePerson ("Alicia" , "Keys" , 30 );
110
+ keith = new ImmutableReactivePerson (null , "Keith" , "Urban" , 53 );
111
+ james = new ImmutableReactivePerson (null , "James" , "Arthur" , 33 );
112
+ mariah = new ImmutableReactivePerson (null , "Mariah" , "Carey" , 51 );
103
113
104
114
repository .saveAll (Arrays .asList (oliver , dave , carter , boyd , stefan , leroi , alicia )).as (StepVerifier ::create ) //
105
115
.expectNextCount (7 ) //
@@ -325,6 +335,22 @@ public void savePublisherOfEntitiesShouldInsertEntity() {
325
335
assertThat (boyd .getId ()).isNotNull ();
326
336
}
327
337
338
+ @ Test // GH-3609
339
+ public void savePublisherOfImmutableEntitiesShouldInsertEntity () {
340
+
341
+ immutableRepository .deleteAll ().as (StepVerifier ::create ).verifyComplete ();
342
+
343
+ immutableRepository .saveAll (Flux .just (keith , james , mariah )).as (StepVerifier ::create )
344
+ .consumeNextWith (e -> keith = e )
345
+ .consumeNextWith (e -> james = e )
346
+ .consumeNextWith (e -> mariah = e )
347
+ .verifyComplete ();
348
+
349
+ assertThat (keith .getId ()).isNotNull ();
350
+ assertThat (james .getId ()).isNotNull ();
351
+ assertThat (mariah .getId ()).isNotNull ();
352
+ }
353
+
328
354
@ Test // DATAMONGO-1444
329
355
public void deleteAllShouldRemoveEntities () {
330
356
@@ -453,12 +479,16 @@ public void findOneByExampleWithoutResultShouldCompleteEmpty() {
453
479
repository .findOne (example ).as (StepVerifier ::create ).verifyComplete ();
454
480
}
455
481
456
- interface ReactivePersonRepostitory extends ReactiveMongoRepository <ReactivePerson , String > {
482
+ interface ReactivePersonRepository extends ReactiveMongoRepository <ReactivePerson , String > {
457
483
458
484
Flux <ReactivePerson > findByLastname (String lastname );
459
485
460
486
}
461
487
488
+ interface ReactiveImmutablePersonRepository extends ReactiveMongoRepository <ImmutableReactivePerson , String > {
489
+
490
+ }
491
+
462
492
@ Data
463
493
@ NoArgsConstructor
464
494
static class ReactivePerson {
@@ -476,4 +506,23 @@ public ReactivePerson(String firstname, String lastname, int age) {
476
506
this .age = age ;
477
507
}
478
508
}
509
+
510
+ @ With
511
+ @ Value
512
+ static class ImmutableReactivePerson {
513
+
514
+ @ Id String id ;
515
+
516
+ String firstname ;
517
+ String lastname ;
518
+ int age ;
519
+
520
+ public ImmutableReactivePerson (@ Nullable String id , String firstname , String lastname , int age ) {
521
+ this .id = id ;
522
+ this .firstname = firstname ;
523
+ this .lastname = lastname ;
524
+ this .age = age ;
525
+ }
526
+ }
527
+
479
528
}
0 commit comments