@@ -84,7 +84,7 @@ public void setUp() {
84
84
template .flushDatabase ();
85
85
}
86
86
87
- @ Test
87
+ @ Test // GH-3602
88
88
void writeSimpleTypeReference () {
89
89
90
90
String rootCollectionName = template .getCollectionName (SingleRefRoot .class );
@@ -102,7 +102,7 @@ void writeSimpleTypeReference() {
102
102
assertThat (target .get ("simpleValueRef" )).isEqualTo ("ref-1" );
103
103
}
104
104
105
- @ Test
105
+ @ Test // GH-3602
106
106
void writeMapTypeReference () {
107
107
108
108
String rootCollectionName = template .getCollectionName (CollectionRefRoot .class );
@@ -122,7 +122,7 @@ void writeMapTypeReference() {
122
122
assertThat (target .get ("mapValueRef" , Map .class )).containsEntry ("frodo" , "ref-1" ).containsEntry ("bilbo" , "ref-2" );
123
123
}
124
124
125
- @ Test
125
+ @ Test // GH-3602
126
126
void writeCollectionOfSimpleTypeReference () {
127
127
128
128
String rootCollectionName = template .getCollectionName (CollectionRefRoot .class );
@@ -141,7 +141,7 @@ void writeCollectionOfSimpleTypeReference() {
141
141
assertThat (target .get ("simpleValueRef" , List .class )).containsExactly ("ref-1" , "ref-2" );
142
142
}
143
143
144
- @ Test
144
+ @ Test // GH-3602
145
145
void writeObjectTypeReference () {
146
146
147
147
String rootCollectionName = template .getCollectionName (SingleRefRoot .class );
@@ -159,7 +159,7 @@ void writeObjectTypeReference() {
159
159
assertThat (target .get ("objectValueRef" )).isEqualTo (source .getObjectValueRef ().toReference ());
160
160
}
161
161
162
- @ Test
162
+ @ Test // GH-3602
163
163
void writeCollectionOfObjectTypeReference () {
164
164
165
165
String rootCollectionName = template .getCollectionName (CollectionRefRoot .class );
@@ -179,7 +179,7 @@ void writeCollectionOfObjectTypeReference() {
179
179
source .getObjectValueRef ().get (0 ).toReference (), source .getObjectValueRef ().get (1 ).toReference ());
180
180
}
181
181
182
- @ Test
182
+ @ Test // GH-3602
183
183
void readSimpleTypeObjectReference () {
184
184
185
185
String rootCollectionName = template .getCollectionName (SingleRefRoot .class );
@@ -198,7 +198,7 @@ void readSimpleTypeObjectReference() {
198
198
assertThat (result .getSimpleValueRef ()).isEqualTo (new SimpleObjectRef ("ref-1" , "me-the-referenced-object" ));
199
199
}
200
200
201
- @ Test
201
+ @ Test // GH-3602
202
202
void readCollectionOfSimpleTypeObjectReference () {
203
203
204
204
String rootCollectionName = template .getCollectionName (CollectionRefRoot .class );
@@ -218,7 +218,7 @@ void readCollectionOfSimpleTypeObjectReference() {
218
218
assertThat (result .getSimpleValueRef ()).containsExactly (new SimpleObjectRef ("ref-1" , "me-the-referenced-object" ));
219
219
}
220
220
221
- @ Test
221
+ @ Test // GH-3602
222
222
void readLazySimpleTypeObjectReference () {
223
223
224
224
String rootCollectionName = template .getCollectionName (SingleRefRoot .class );
@@ -243,7 +243,7 @@ void readLazySimpleTypeObjectReference() {
243
243
assertThat (result .getSimpleLazyValueRef ()).isEqualTo (new SimpleObjectRef ("ref-1" , "me-the-referenced-object" ));
244
244
}
245
245
246
- @ Test
246
+ @ Test // GH-3602
247
247
void readSimpleTypeObjectReferenceFromFieldWithCustomName () {
248
248
249
249
String rootCollectionName = template .getCollectionName (SingleRefRoot .class );
@@ -264,7 +264,7 @@ void readSimpleTypeObjectReferenceFromFieldWithCustomName() {
264
264
.isEqualTo (new SimpleObjectRef ("ref-1" , "me-the-referenced-object" ));
265
265
}
266
266
267
- @ Test
267
+ @ Test // GH-3602
268
268
void readCollectionTypeObjectReferenceFromFieldWithCustomName () {
269
269
270
270
String rootCollectionName = template .getCollectionName (CollectionRefRoot .class );
@@ -285,7 +285,7 @@ void readCollectionTypeObjectReferenceFromFieldWithCustomName() {
285
285
.containsExactly (new SimpleObjectRef ("ref-1" , "me-the-referenced-object" ));
286
286
}
287
287
288
- @ Test
288
+ @ Test // GH-3602
289
289
void readObjectReferenceFromDocumentType () {
290
290
291
291
String rootCollectionName = template .getCollectionName (SingleRefRoot .class );
@@ -305,7 +305,7 @@ void readObjectReferenceFromDocumentType() {
305
305
assertThat (result .getObjectValueRef ()).isEqualTo (new ObjectRefOfDocument ("ref-1" , "me-the-referenced-object" ));
306
306
}
307
307
308
- @ Test
308
+ @ Test // GH-3602
309
309
void readCollectionObjectReferenceFromDocumentType () {
310
310
311
311
String rootCollectionName = template .getCollectionName (CollectionRefRoot .class );
@@ -326,7 +326,7 @@ void readCollectionObjectReferenceFromDocumentType() {
326
326
.containsExactly (new ObjectRefOfDocument ("ref-1" , "me-the-referenced-object" ));
327
327
}
328
328
329
- @ Test
329
+ @ Test // GH-3602
330
330
void readObjectReferenceFromDocumentDeclaringCollectionName () {
331
331
332
332
String rootCollectionName = template .getCollectionName (SingleRefRoot .class );
@@ -349,7 +349,7 @@ void readObjectReferenceFromDocumentDeclaringCollectionName() {
349
349
.isEqualTo (new ObjectRefOfDocumentWithEmbeddedCollectionName ("ref-1" , "me-the-referenced-object" ));
350
350
}
351
351
352
- @ Test
352
+ @ Test // GH-3602
353
353
void readCollectionObjectReferenceFromDocumentDeclaringCollectionName () {
354
354
355
355
String rootCollectionName = template .getCollectionName (CollectionRefRoot .class );
@@ -377,7 +377,7 @@ void readCollectionObjectReferenceFromDocumentDeclaringCollectionName() {
377
377
new ObjectRefOfDocumentWithEmbeddedCollectionName ("ref-1" , "me-the-1-referenced-object" ));
378
378
}
379
379
380
- @ Test
380
+ @ Test // GH-3602
381
381
void readObjectReferenceFromDocumentNotRelatingToTheIdProperty () {
382
382
383
383
String rootCollectionName = template .getCollectionName (SingleRefRoot .class );
@@ -399,7 +399,7 @@ void readObjectReferenceFromDocumentNotRelatingToTheIdProperty() {
399
399
.isEqualTo (new ObjectRefOnNonIdField ("ref-1" , "me-the-referenced-object" , "ref-key-1" , "ref-key-2" ));
400
400
}
401
401
402
- @ Test
402
+ @ Test // GH-3602
403
403
void readLazyObjectReferenceFromDocumentNotRelatingToTheIdProperty () {
404
404
405
405
String rootCollectionName = template .getCollectionName (SingleRefRoot .class );
@@ -427,7 +427,7 @@ void readLazyObjectReferenceFromDocumentNotRelatingToTheIdProperty() {
427
427
.isEqualTo (new ObjectRefOnNonIdField ("ref-1" , "me-the-referenced-object" , "ref-key-1" , "ref-key-2" ));
428
428
}
429
429
430
- @ Test
430
+ @ Test // GH-3602
431
431
void readCollectionObjectReferenceFromDocumentNotRelatingToTheIdProperty () {
432
432
433
433
String rootCollectionName = template .getCollectionName (CollectionRefRoot .class );
@@ -450,7 +450,7 @@ void readCollectionObjectReferenceFromDocumentNotRelatingToTheIdProperty() {
450
450
.containsExactly (new ObjectRefOnNonIdField ("ref-1" , "me-the-referenced-object" , "ref-key-1" , "ref-key-2" ));
451
451
}
452
452
453
- @ Test
453
+ @ Test // GH-3602
454
454
void readMapOfReferences () {
455
455
456
456
String rootCollectionName = template .getCollectionName (CollectionRefRoot .class );
@@ -483,8 +483,8 @@ void readMapOfReferences() {
483
483
.containsEntry ("bilbo" , new SimpleObjectRef ("ref-2" , "me-the-2-referenced-object" ));
484
484
}
485
485
486
- @ Test
487
- void testLazyCyclic () {
486
+ @ Test // GH-3602
487
+ void loadLazyCyclicReference () {
488
488
489
489
WithRefA a = new WithRefA ();
490
490
a .id = "a" ;
@@ -508,8 +508,8 @@ void testLazyCyclic() {
508
508
});
509
509
}
510
510
511
- @ Test
512
- void testEagerCyclic () {
511
+ @ Test // GH-3602
512
+ void loadEagerCyclicReference () {
513
513
514
514
WithRefA a = new WithRefA ();
515
515
a .id = "a" ;
@@ -530,6 +530,60 @@ void testEagerCyclic() {
530
530
assertThat (loadedA .getToB ().eagerToA ).isSameAs (loadedA );
531
531
}
532
532
533
+ @ Test // GH-3602
534
+ void loadAndStoreUnresolvedLazyDoesNotResolveTheProxy () {
535
+
536
+ String collectionB = template .getCollectionName (WithRefB .class );
537
+
538
+ WithRefA a = new WithRefA ();
539
+ a .id = "a" ;
540
+
541
+ WithRefB b = new WithRefB ();
542
+ b .id = "b" ;
543
+
544
+ a .toB = b ;
545
+ b .lazyToA = a ;
546
+
547
+ template .save (a );
548
+ template .save (b );
549
+
550
+ WithRefA loadedA = template .query (WithRefA .class ).matching (where ("id" ).is (a .id )).firstValue ();
551
+ template .save (loadedA .getToB ());
552
+
553
+ LazyLoadingTestUtils .assertProxy (loadedA .getToB ().lazyToA , (proxy ) -> {
554
+
555
+ assertThat (proxy .isResolved ()).isFalse ();
556
+ assertThat (proxy .currentValue ()).isNull ();
557
+ });
558
+
559
+ Document target = template .execute (db -> {
560
+ return db .getCollection (collectionB ).find (Filters .eq ("_id" , "b" )).first ();
561
+ });
562
+ assertThat (target .get ("lazyToA" , Object .class )).isEqualTo ("a" );
563
+ }
564
+
565
+ @ Test // GH-3602
566
+ void loadCollectionReferenceWithMissingRefs () {
567
+
568
+ String rootCollectionName = template .getCollectionName (CollectionRefRoot .class );
569
+ String refCollectionName = template .getCollectionName (SimpleObjectRef .class );
570
+
571
+ // ref-1 is missing.
572
+ Document refSource = new Document ("_id" , "ref-2" ).append ("value" , "me-the-2-referenced-object" );
573
+ Document source = new Document ("_id" , "id-1" ).append ("value" , "v1" ).append ("simpleValueRef" ,
574
+ Arrays .asList ("ref-1" , "ref-2" ));
575
+
576
+ template .execute (db -> {
577
+
578
+ db .getCollection (refCollectionName ).insertOne (refSource );
579
+ db .getCollection (rootCollectionName ).insertOne (source );
580
+ return null ;
581
+ });
582
+
583
+ CollectionRefRoot result = template .findOne (query (where ("id" ).is ("id-1" )), CollectionRefRoot .class );
584
+ assertThat (result .getSimpleValueRef ()).containsExactly (new SimpleObjectRef ("ref-2" , "me-the-2-referenced-object" ));
585
+ }
586
+
533
587
@ Data
534
588
static class SingleRefRoot {
535
589
0 commit comments