19
19
import static org .junit .Assume .*;
20
20
import static org .mockito .Mockito .*;
21
21
22
+ import lombok .RequiredArgsConstructor ;
23
+
22
24
import java .lang .annotation .Annotation ;
23
25
import java .lang .annotation .Retention ;
24
26
import java .lang .annotation .RetentionPolicy ;
27
29
import java .util .List ;
28
30
import java .util .concurrent .CountDownLatch ;
29
31
import java .util .concurrent .atomic .AtomicBoolean ;
32
+ import java .util .stream .Stream ;
30
33
31
34
import org .hamcrest .CoreMatchers ;
32
35
import org .junit .Rule ;
44
47
import org .springframework .data .annotation .Immutable ;
45
48
import org .springframework .data .annotation .LastModifiedBy ;
46
49
import org .springframework .data .annotation .Persistent ;
50
+ import org .springframework .data .annotation .Transient ;
47
51
import org .springframework .data .annotation .TypeAlias ;
48
52
import org .springframework .data .domain .Persistable ;
49
53
import org .springframework .data .mapping .Alias ;
@@ -355,6 +359,19 @@ public void detectsImmutableEntity() {
355
359
assertThat (createEntity (Entity .class ).isImmutable ()).isFalse ();
356
360
}
357
361
362
+ @ Test // DATACMNS-1366
363
+ public void exposesPropertyPopulationRequired () {
364
+
365
+ assertThat (createPopulatedPersistentEntity (PropertyPopulationRequired .class ).requiresPropertyPopulation ()).isTrue ();
366
+ }
367
+
368
+ @ Test // DATACMNS-1366
369
+ public void exposesPropertyPopulationNotRequired () {
370
+
371
+ Stream .of (PropertyPopulationNotRequired .class , PropertyPopulationNotRequiredWithTransient .class ) //
372
+ .forEach (it -> assertThat (createPopulatedPersistentEntity (it ).requiresPropertyPopulation ()).isFalse ());
373
+ }
374
+
358
375
private <S > BasicPersistentEntity <S , T > createEntity (Class <S > type ) {
359
376
return createEntity (type , null );
360
377
}
@@ -363,6 +380,12 @@ private <S> BasicPersistentEntity<S, T> createEntity(Class<S> type, Comparator<T
363
380
return new BasicPersistentEntity <>(ClassTypeInformation .from (type ), comparator );
364
381
}
365
382
383
+ private static PersistentEntity <Object , ?> createPopulatedPersistentEntity (Class <?> type ) {
384
+
385
+ SampleMappingContext context = new SampleMappingContext ();
386
+ return context .getRequiredPersistentEntity (type );
387
+ }
388
+
366
389
@ TypeAlias ("foo" )
367
390
static class AliasedEntity {
368
391
@@ -427,4 +450,26 @@ public boolean isNew() {
427
450
428
451
@ Immutable
429
452
static class SomeValue {}
453
+
454
+ // DATACMNS-1366
455
+
456
+ @ RequiredArgsConstructor
457
+ static class PropertyPopulationRequired {
458
+
459
+ private final String firstname , lastname ;
460
+ private String email ;
461
+ }
462
+
463
+ @ RequiredArgsConstructor
464
+ static class PropertyPopulationNotRequired {
465
+
466
+ private final String firstname , lastname ;
467
+ }
468
+
469
+ @ RequiredArgsConstructor
470
+ static class PropertyPopulationNotRequiredWithTransient {
471
+
472
+ private final String firstname , lastname ;
473
+ private @ Transient String email ;
474
+ }
430
475
}
0 commit comments