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 ;
@@ -66,9 +68,11 @@ public class SimpleReactiveMongoRepositoryTests implements BeanClassLoaderAware,
66
68
ReactiveMongoRepositoryFactory factory ;
67
69
ClassLoader classLoader ;
68
70
BeanFactory beanFactory ;
69
- ReactivePersonRepostitory repository ;
71
+ ReactivePersonRepository repository ;
72
+ ReactiveImmutablePersonRepository immutableRepository ;
70
73
71
74
private ReactivePerson dave , oliver , carter , boyd , stefan , leroi , alicia ;
75
+ private ImmutableReactivePerson keith , james , mariah ;
72
76
73
77
@ Override
74
78
public void setBeanClassLoader (ClassLoader classLoader ) {
@@ -89,9 +93,11 @@ public void setUp() {
89
93
factory .setBeanFactory (beanFactory );
90
94
factory .setEvaluationContextProvider (ReactiveQueryMethodEvaluationContextProvider .DEFAULT );
91
95
92
- repository = factory .getRepository (ReactivePersonRepostitory .class );
96
+ repository = factory .getRepository (ReactivePersonRepository .class );
97
+ immutableRepository = factory .getRepository (ReactiveImmutablePersonRepository .class );
93
98
94
99
repository .deleteAll ().as (StepVerifier ::create ).verifyComplete ();
100
+ immutableRepository .deleteAll ().as (StepVerifier ::create ).verifyComplete ();
95
101
96
102
dave = new ReactivePerson ("Dave" , "Matthews" , 42 );
97
103
oliver = new ReactivePerson ("Oliver August" , "Matthews" , 4 );
@@ -100,10 +106,16 @@ public void setUp() {
100
106
stefan = new ReactivePerson ("Stefan" , "Lessard" , 34 );
101
107
leroi = new ReactivePerson ("Leroi" , "Moore" , 41 );
102
108
alicia = new ReactivePerson ("Alicia" , "Keys" , 30 );
109
+ keith = new ImmutableReactivePerson (null , "Keith" , "Urban" , 53 );
110
+ james = new ImmutableReactivePerson (null , "James" , "Arthur" , 33 );
111
+ mariah = new ImmutableReactivePerson (null , "Mariah" , "Carey" , 51 );
103
112
104
113
repository .saveAll (Arrays .asList (oliver , dave , carter , boyd , stefan , leroi , alicia )).as (StepVerifier ::create ) //
105
114
.expectNextCount (7 ) //
106
115
.verifyComplete ();
116
+ immutableRepository .saveAll (Arrays .asList (keith , james , mariah )).as (StepVerifier ::create ) //
117
+ .expectNextCount (3 ) //
118
+ .verifyComplete ();
107
119
}
108
120
109
121
@ Test // DATAMONGO-1444
@@ -325,6 +337,23 @@ public void savePublisherOfEntitiesShouldInsertEntity() {
325
337
assertThat (boyd .getId ()).isNotNull ();
326
338
}
327
339
340
+ @ Test // GH-3609
341
+ public void savePublisherOfImmutableEntitiesShouldInsertEntity () {
342
+
343
+ immutableRepository .deleteAll ().as (StepVerifier ::create ).verifyComplete ();
344
+
345
+ keith = keith .withId (null );
346
+ james = james .withId (null );
347
+ mariah = mariah .withId (null );
348
+
349
+ immutableRepository .saveAll (Flux .just (keith , james , mariah )).as (StepVerifier ::create ).expectNextCount (3 )
350
+ .verifyComplete ();
351
+
352
+ assertThat (keith .getId ()).isNotNull ();
353
+ assertThat (james .getId ()).isNotNull ();
354
+ assertThat (mariah .getId ()).isNotNull ();
355
+ }
356
+
328
357
@ Test // DATAMONGO-1444
329
358
public void deleteAllShouldRemoveEntities () {
330
359
@@ -453,12 +482,16 @@ public void findOneByExampleWithoutResultShouldCompleteEmpty() {
453
482
repository .findOne (example ).as (StepVerifier ::create ).verifyComplete ();
454
483
}
455
484
456
- interface ReactivePersonRepostitory extends ReactiveMongoRepository <ReactivePerson , String > {
485
+ interface ReactivePersonRepository extends ReactiveMongoRepository <ReactivePerson , String > {
457
486
458
487
Flux <ReactivePerson > findByLastname (String lastname );
459
488
460
489
}
461
490
491
+ interface ReactiveImmutablePersonRepository extends ReactiveMongoRepository <ImmutableReactivePerson , String > {
492
+
493
+ }
494
+
462
495
@ Data
463
496
@ NoArgsConstructor
464
497
static class ReactivePerson {
@@ -476,4 +509,23 @@ public ReactivePerson(String firstname, String lastname, int age) {
476
509
this .age = age ;
477
510
}
478
511
}
512
+
513
+ @ With
514
+ @ Value
515
+ static class ImmutableReactivePerson {
516
+
517
+ @ Id String id ;
518
+
519
+ String firstname ;
520
+ String lastname ;
521
+ int age ;
522
+
523
+ public ImmutableReactivePerson (@ Nullable String id , String firstname , String lastname , int age ) {
524
+ this .id = id ;
525
+ this .firstname = firstname ;
526
+ this .lastname = lastname ;
527
+ this .age = age ;
528
+ }
529
+ }
530
+
479
531
}
0 commit comments