2020
2121import lombok .Data ;
2222import lombok .NoArgsConstructor ;
23+ import lombok .Value ;
24+ import lombok .With ;
2325import reactor .core .publisher .Flux ;
2426import reactor .core .publisher .Mono ;
2527import reactor .test .StepVerifier ;
2628
2729import java .util .Arrays ;
2830
31+ import javax .annotation .Nullable ;
32+
2933import org .junit .Before ;
3034import org .junit .Test ;
3135import org .junit .runner .RunWith ;
32-
3336import org .springframework .beans .BeansException ;
3437import org .springframework .beans .factory .BeanClassLoaderAware ;
3538import org .springframework .beans .factory .BeanFactory ;
5558 * @author Mark Paluch
5659 * @author Christoph Strobl
5760 * @author Ruben J Garcia
61+ * @author Clément Petit
5862 */
5963@ RunWith (SpringRunner .class )
6064@ ContextConfiguration ("classpath:reactive-infrastructure.xml" )
@@ -65,9 +69,11 @@ public class SimpleReactiveMongoRepositoryTests implements BeanClassLoaderAware,
6569 ReactiveMongoRepositoryFactory factory ;
6670 ClassLoader classLoader ;
6771 BeanFactory beanFactory ;
68- ReactivePersonRepostitory repository ;
72+ ReactivePersonRepository repository ;
73+ ReactiveImmutablePersonRepository immutableRepository ;
6974
7075 private ReactivePerson dave , oliver , carter , boyd , stefan , leroi , alicia ;
76+ private ImmutableReactivePerson keith , james , mariah ;
7177
7278 @ Override
7379 public void setBeanClassLoader (ClassLoader classLoader ) {
@@ -88,9 +94,11 @@ public void setUp() {
8894 factory .setBeanFactory (beanFactory );
8995 factory .setEvaluationContextProvider (QueryMethodEvaluationContextProvider .DEFAULT );
9096
91- repository = factory .getRepository (ReactivePersonRepostitory .class );
97+ repository = factory .getRepository (ReactivePersonRepository .class );
98+ immutableRepository = factory .getRepository (ReactiveImmutablePersonRepository .class );
9299
93100 repository .deleteAll ().as (StepVerifier ::create ).verifyComplete ();
101+ immutableRepository .deleteAll ().as (StepVerifier ::create ).verifyComplete ();
94102
95103 dave = new ReactivePerson ("Dave" , "Matthews" , 42 );
96104 oliver = new ReactivePerson ("Oliver August" , "Matthews" , 4 );
@@ -99,6 +107,9 @@ public void setUp() {
99107 stefan = new ReactivePerson ("Stefan" , "Lessard" , 34 );
100108 leroi = new ReactivePerson ("Leroi" , "Moore" , 41 );
101109 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 );
102113
103114 repository .saveAll (Arrays .asList (oliver , dave , carter , boyd , stefan , leroi , alicia )).as (StepVerifier ::create ) //
104115 .expectNextCount (7 ) //
@@ -324,6 +335,20 @@ public void savePublisherOfEntitiesShouldInsertEntity() {
324335 assertThat (boyd .getId ()).isNotNull ();
325336 }
326337
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+
327352 @ Test // DATAMONGO-1444
328353 public void deleteAllShouldRemoveEntities () {
329354
@@ -452,12 +477,16 @@ public void findOneByExampleWithoutResultShouldCompleteEmpty() {
452477 repository .findOne (example ).as (StepVerifier ::create ).verifyComplete ();
453478 }
454479
455- interface ReactivePersonRepostitory extends ReactiveMongoRepository <ReactivePerson , String > {
480+ interface ReactivePersonRepository extends ReactiveMongoRepository <ReactivePerson , String > {
456481
457482 Flux <ReactivePerson > findByLastname (String lastname );
458483
459484 }
460485
486+ interface ReactiveImmutablePersonRepository extends ReactiveMongoRepository <ImmutableReactivePerson , String > {
487+
488+ }
489+
461490 @ Data
462491 @ NoArgsConstructor
463492 static class ReactivePerson {
@@ -475,4 +504,23 @@ public ReactivePerson(String firstname, String lastname, int age) {
475504 this .age = age ;
476505 }
477506 }
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+
478526}
0 commit comments