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,10 +107,16 @@ 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 ) //
106
116
.verifyComplete ();
117
+ immutableRepository .saveAll (Arrays .asList (keith , james , mariah )).as (StepVerifier ::create ) //
118
+ .expectNextCount (3 ) //
119
+ .verifyComplete ();
107
120
}
108
121
109
122
@ Test // DATAMONGO-1444
@@ -325,6 +338,23 @@ public void savePublisherOfEntitiesShouldInsertEntity() {
325
338
assertThat (boyd .getId ()).isNotNull ();
326
339
}
327
340
341
+ @ Test // GH-3609
342
+ public void savePublisherOfImmutableEntitiesShouldInsertEntity () {
343
+
344
+ immutableRepository .deleteAll ().as (StepVerifier ::create ).verifyComplete ();
345
+
346
+ keith = keith .withId (null );
347
+ james = james .withId (null );
348
+ mariah = mariah .withId (null );
349
+
350
+ immutableRepository .saveAll (Flux .just (keith , james , mariah )).as (StepVerifier ::create ).expectNextCount (3 )
351
+ .verifyComplete ();
352
+
353
+ assertThat (keith .getId ()).isNotNull ();
354
+ assertThat (james .getId ()).isNotNull ();
355
+ assertThat (mariah .getId ()).isNotNull ();
356
+ }
357
+
328
358
@ Test // DATAMONGO-1444
329
359
public void deleteAllShouldRemoveEntities () {
330
360
@@ -453,12 +483,16 @@ public void findOneByExampleWithoutResultShouldCompleteEmpty() {
453
483
repository .findOne (example ).as (StepVerifier ::create ).verifyComplete ();
454
484
}
455
485
456
- interface ReactivePersonRepostitory extends ReactiveMongoRepository <ReactivePerson , String > {
486
+ interface ReactivePersonRepository extends ReactiveMongoRepository <ReactivePerson , String > {
457
487
458
488
Flux <ReactivePerson > findByLastname (String lastname );
459
489
460
490
}
461
491
492
+ interface ReactiveImmutablePersonRepository extends ReactiveMongoRepository <ImmutableReactivePerson , String > {
493
+
494
+ }
495
+
462
496
@ Data
463
497
@ NoArgsConstructor
464
498
static class ReactivePerson {
@@ -476,4 +510,23 @@ public ReactivePerson(String firstname, String lastname, int age) {
476
510
this .age = age ;
477
511
}
478
512
}
513
+
514
+ @ With
515
+ @ Value
516
+ static class ImmutableReactivePerson {
517
+
518
+ @ Id String id ;
519
+
520
+ String firstname ;
521
+ String lastname ;
522
+ int age ;
523
+
524
+ public ImmutableReactivePerson (@ Nullable String id , String firstname , String lastname , int age ) {
525
+ this .id = id ;
526
+ this .firstname = firstname ;
527
+ this .lastname = lastname ;
528
+ this .age = age ;
529
+ }
530
+ }
531
+
479
532
}
0 commit comments