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 ;
55
58
* @author Mark Paluch
56
59
* @author Christoph Strobl
57
60
* @author Ruben J Garcia
61
+ * @author Clément Petit
58
62
*/
59
63
@ RunWith (SpringRunner .class )
60
64
@ ContextConfiguration ("classpath:reactive-infrastructure.xml" )
@@ -65,9 +69,11 @@ public class SimpleReactiveMongoRepositoryTests implements BeanClassLoaderAware,
65
69
ReactiveMongoRepositoryFactory factory ;
66
70
ClassLoader classLoader ;
67
71
BeanFactory beanFactory ;
68
- ReactivePersonRepostitory repository ;
72
+ ReactivePersonRepository repository ;
73
+ ReactiveImmutablePersonRepository immutableRepository ;
69
74
70
75
private ReactivePerson dave , oliver , carter , boyd , stefan , leroi , alicia ;
76
+ private ImmutableReactivePerson keith , james , mariah ;
71
77
72
78
@ Override
73
79
public void setBeanClassLoader (ClassLoader classLoader ) {
@@ -88,9 +94,11 @@ public void setUp() {
88
94
factory .setBeanFactory (beanFactory );
89
95
factory .setEvaluationContextProvider (QueryMethodEvaluationContextProvider .DEFAULT );
90
96
91
- repository = factory .getRepository (ReactivePersonRepostitory .class );
97
+ repository = factory .getRepository (ReactivePersonRepository .class );
98
+ immutableRepository = factory .getRepository (ReactiveImmutablePersonRepository .class );
92
99
93
100
repository .deleteAll ().as (StepVerifier ::create ).verifyComplete ();
101
+ immutableRepository .deleteAll ().as (StepVerifier ::create ).verifyComplete ();
94
102
95
103
dave = new ReactivePerson ("Dave" , "Matthews" , 42 );
96
104
oliver = new ReactivePerson ("Oliver August" , "Matthews" , 4 );
@@ -99,6 +107,9 @@ public void setUp() {
99
107
stefan = new ReactivePerson ("Stefan" , "Lessard" , 34 );
100
108
leroi = new ReactivePerson ("Leroi" , "Moore" , 41 );
101
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 );
102
113
103
114
repository .saveAll (Arrays .asList (oliver , dave , carter , boyd , stefan , leroi , alicia )).as (StepVerifier ::create ) //
104
115
.expectNextCount (7 ) //
@@ -324,6 +335,20 @@ public void savePublisherOfEntitiesShouldInsertEntity() {
324
335
assertThat (boyd .getId ()).isNotNull ();
325
336
}
326
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 ).consumeNextWith (e -> james = e ).consumeNextWith (e -> mariah = e )
345
+ .verifyComplete ();
346
+
347
+ assertThat (keith .getId ()).isNotNull ();
348
+ assertThat (james .getId ()).isNotNull ();
349
+ assertThat (mariah .getId ()).isNotNull ();
350
+ }
351
+
327
352
@ Test // DATAMONGO-1444
328
353
public void deleteAllShouldRemoveEntities () {
329
354
@@ -452,12 +477,16 @@ public void findOneByExampleWithoutResultShouldCompleteEmpty() {
452
477
repository .findOne (example ).as (StepVerifier ::create ).verifyComplete ();
453
478
}
454
479
455
- interface ReactivePersonRepostitory extends ReactiveMongoRepository <ReactivePerson , String > {
480
+ interface ReactivePersonRepository extends ReactiveMongoRepository <ReactivePerson , String > {
456
481
457
482
Flux <ReactivePerson > findByLastname (String lastname );
458
483
459
484
}
460
485
486
+ interface ReactiveImmutablePersonRepository extends ReactiveMongoRepository <ImmutableReactivePerson , String > {
487
+
488
+ }
489
+
461
490
@ Data
462
491
@ NoArgsConstructor
463
492
static class ReactivePerson {
@@ -475,4 +504,23 @@ public ReactivePerson(String firstname, String lastname, int age) {
475
504
this .age = age ;
476
505
}
477
506
}
507
+
508
+ @ With
509
+ @ Value
510
+ static class ImmutableReactivePerson {
511
+
512
+ @ Id String id ;
513
+
514
+ String firstname ;
515
+ String lastname ;
516
+ int age ;
517
+
518
+ public ImmutableReactivePerson (@ Nullable String id , String firstname , String lastname , int age ) {
519
+ this .id = id ;
520
+ this .firstname = firstname ;
521
+ this .lastname = lastname ;
522
+ this .age = age ;
523
+ }
524
+ }
525
+
478
526
}
0 commit comments