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 ;
4447import org .springframework .data .mongodb .core .ReactiveMongoTemplate ;
4548import org .springframework .data .mongodb .repository .support .ReactiveMongoRepositoryFactory ;
4649import org .springframework .data .mongodb .repository .support .SimpleReactiveMongoRepository ;
47- import org .springframework .data .repository .query .QueryMethodEvaluationContextProvider ;
4850import org .springframework .data .repository .query .ReactiveQueryMethodEvaluationContextProvider ;
4951import org .springframework .test .context .ContextConfiguration ;
5052import org .springframework .test .context .junit4 .SpringRunner ;
5658 * @author Mark Paluch
5759 * @author Christoph Strobl
5860 * @author Ruben J Garcia
61+ * @author Clément Petit
5962 */
6063@ RunWith (SpringRunner .class )
6164@ ContextConfiguration ("classpath:reactive-infrastructure.xml" )
@@ -66,9 +69,11 @@ public class SimpleReactiveMongoRepositoryTests implements BeanClassLoaderAware,
6669 ReactiveMongoRepositoryFactory factory ;
6770 ClassLoader classLoader ;
6871 BeanFactory beanFactory ;
69- ReactivePersonRepostitory repository ;
72+ ReactivePersonRepository repository ;
73+ ReactiveImmutablePersonRepository immutableRepository ;
7074
7175 private ReactivePerson dave , oliver , carter , boyd , stefan , leroi , alicia ;
76+ private ImmutableReactivePerson keith , james , mariah ;
7277
7378 @ Override
7479 public void setBeanClassLoader (ClassLoader classLoader ) {
@@ -89,9 +94,11 @@ public void setUp() {
8994 factory .setBeanFactory (beanFactory );
9095 factory .setEvaluationContextProvider (ReactiveQueryMethodEvaluationContextProvider .DEFAULT );
9196
92- repository = factory .getRepository (ReactivePersonRepostitory .class );
97+ repository = factory .getRepository (ReactivePersonRepository .class );
98+ immutableRepository = factory .getRepository (ReactiveImmutablePersonRepository .class );
9399
94100 repository .deleteAll ().as (StepVerifier ::create ).verifyComplete ();
101+ immutableRepository .deleteAll ().as (StepVerifier ::create ).verifyComplete ();
95102
96103 dave = new ReactivePerson ("Dave" , "Matthews" , 42 );
97104 oliver = new ReactivePerson ("Oliver August" , "Matthews" , 4 );
@@ -100,6 +107,9 @@ public void setUp() {
100107 stefan = new ReactivePerson ("Stefan" , "Lessard" , 34 );
101108 leroi = new ReactivePerson ("Leroi" , "Moore" , 41 );
102109 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 );
103113
104114 repository .saveAll (Arrays .asList (oliver , dave , carter , boyd , stefan , leroi , alicia )).as (StepVerifier ::create ) //
105115 .expectNextCount (7 ) //
@@ -325,6 +335,22 @@ public void savePublisherOfEntitiesShouldInsertEntity() {
325335 assertThat (boyd .getId ()).isNotNull ();
326336 }
327337
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+
328354 @ Test // DATAMONGO-1444
329355 public void deleteAllShouldRemoveEntities () {
330356
@@ -453,12 +479,16 @@ public void findOneByExampleWithoutResultShouldCompleteEmpty() {
453479 repository .findOne (example ).as (StepVerifier ::create ).verifyComplete ();
454480 }
455481
456- interface ReactivePersonRepostitory extends ReactiveMongoRepository <ReactivePerson , String > {
482+ interface ReactivePersonRepository extends ReactiveMongoRepository <ReactivePerson , String > {
457483
458484 Flux <ReactivePerson > findByLastname (String lastname );
459485
460486 }
461487
488+ interface ReactiveImmutablePersonRepository extends ReactiveMongoRepository <ImmutableReactivePerson , String > {
489+
490+ }
491+
462492 @ Data
463493 @ NoArgsConstructor
464494 static class ReactivePerson {
@@ -476,4 +506,23 @@ public ReactivePerson(String firstname, String lastname, int age) {
476506 this .age = age ;
477507 }
478508 }
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+
479528}
0 commit comments