@@ -130,10 +130,9 @@ public class MongoTemplateTests {
130
130
.parse ("2.4" );
131
131
private static final org .springframework .data .util .Version TWO_DOT_EIGHT = org .springframework .data .util .Version
132
132
.parse ("2.8" );
133
- private static final org .springframework .data .util .Version THREE_DOT_FOUR = org .springframework .data .util .Version
133
+ private static final org .springframework .data .util .Version THREE_DOT_FOUR = org .springframework .data .util .Version
134
134
.parse ("3.4" );
135
135
136
-
137
136
@ Autowired MongoTemplate template ;
138
137
@ Autowired MongoDbFactory factory ;
139
138
@@ -145,23 +144,25 @@ public class MongoTemplateTests {
145
144
146
145
@ Autowired
147
146
public void setApplicationContext (ConfigurableApplicationContext context ) {
148
- context . addApplicationListener ( new PersonWithIdPropertyOfTypeUUIDListener ());
147
+
149
148
this .context = context ;
149
+
150
+ context .addApplicationListener (new PersonWithIdPropertyOfTypeUUIDListener ());
150
151
}
151
152
152
153
@ Autowired
153
154
public void setMongo (Mongo mongo ) throws Exception {
154
155
155
- CustomConversions conversions = new CustomConversions (Arrays . asList ( DateToDateTimeConverter . INSTANCE ,
156
- DateTimeToDateConverter .INSTANCE ));
156
+ CustomConversions conversions = new CustomConversions (
157
+ Arrays . asList ( DateToDateTimeConverter . INSTANCE , DateTimeToDateConverter .INSTANCE ));
157
158
158
159
MongoMappingContext mappingContext = new MongoMappingContext ();
159
- mappingContext .setInitialEntitySet (new HashSet <Class <?>>(Arrays . asList ( PersonWith_idPropertyOfTypeObjectId . class ,
160
- PersonWith_idPropertyOfTypeString . class , PersonWithIdPropertyOfTypeObjectId .class ,
161
- PersonWithIdPropertyOfTypeString .class , PersonWithIdPropertyOfTypeInteger .class ,
162
- PersonWithIdPropertyOfTypeBigInteger .class , PersonWithIdPropertyOfPrimitiveInt .class ,
163
- PersonWithIdPropertyOfTypeLong .class , PersonWithIdPropertyOfPrimitiveLong .class ,
164
- PersonWithIdPropertyOfTypeUUID .class )));
160
+ mappingContext .setInitialEntitySet (new HashSet <Class <?>>(
161
+ Arrays . asList ( PersonWith_idPropertyOfTypeObjectId . class , PersonWith_idPropertyOfTypeString .class ,
162
+ PersonWithIdPropertyOfTypeObjectId .class , PersonWithIdPropertyOfTypeString .class ,
163
+ PersonWithIdPropertyOfTypeInteger .class , PersonWithIdPropertyOfTypeBigInteger .class ,
164
+ PersonWithIdPropertyOfPrimitiveInt .class , PersonWithIdPropertyOfTypeLong .class ,
165
+ PersonWithIdPropertyOfPrimitiveLong . class , PersonWithIdPropertyOfTypeUUID .class )));
165
166
mappingContext .setSimpleTypeHolder (conversions .getSimpleTypeHolder ());
166
167
mappingContext .initialize ();
167
168
@@ -175,8 +176,11 @@ public void setMongo(Mongo mongo) throws Exception {
175
176
176
177
@ Before
177
178
public void setUp () {
179
+
178
180
cleanDb ();
179
181
queryMongoVersionIfNecessary ();
182
+
183
+ this .mappingTemplate .setApplicationContext (context );
180
184
}
181
185
182
186
@ After
@@ -648,7 +652,6 @@ private void testProperHandlingOfDifferentIdTypes(MongoTemplate mongoTemplate) t
648
652
PersonWithIdPropertyOfTypeUUID p13 = new PersonWithIdPropertyOfTypeUUID ();
649
653
p13 .setFirstName ("Sven_10" );
650
654
p13 .setAge (22 );
651
- p13 .setId (UUID .randomUUID ());
652
655
// insert
653
656
mongoTemplate .insert (p13 );
654
657
// also try save
@@ -2406,7 +2409,7 @@ public void updateWithPullShouldRemoveNestedItemFromDbRefAnnotatedCollection() {
2406
2409
doc .dbRefAnnotatedList = Arrays .asList ( //
2407
2410
sample1 , //
2408
2411
sample2 //
2409
- );
2412
+ );
2410
2413
template .save (doc );
2411
2414
2412
2415
Update update = new Update ().pull ("dbRefAnnotatedList" , doc .dbRefAnnotatedList .get (1 ));
@@ -2435,7 +2438,7 @@ public void updateWithPullShouldRemoveNestedItemFromDbRefAnnotatedCollectionWhen
2435
2438
doc .dbRefAnnotatedList = Arrays .asList ( //
2436
2439
sample1 , //
2437
2440
sample2 //
2438
- );
2441
+ );
2439
2442
template .save (doc );
2440
2443
2441
2444
Update update = new Update ().pull ("dbRefAnnotatedList.id" , "2" );
@@ -2500,8 +2503,8 @@ public void shouldBeAbleToUpdateDbRefPropertyWithDomainObject() {
2500
2503
@ Test // DATAMONGO-862
2501
2504
public void testUpdateShouldWorkForPathsOnInterfaceMethods () {
2502
2505
2503
- DocumentWithCollection document = new DocumentWithCollection (Arrays .< Model > asList ( new ModelA ( "spring" ),
2504
- new ModelA ("data" )));
2506
+ DocumentWithCollection document = new DocumentWithCollection (
2507
+ Arrays .< Model > asList ( new ModelA ( "spring" ), new ModelA ("data" )));
2505
2508
2506
2509
template .save (document );
2507
2510
@@ -2967,7 +2970,7 @@ public void updatesNumericValueCorrectlyWhenUsingMinOperator() {
2967
2970
.min ("longVal" , 490 ) //
2968
2971
.min ("bigIntegerVal" , new BigInteger ("590" )) //
2969
2972
.min ("bigDeciamVal" , new BigDecimal ("690" )) //
2970
- ;
2973
+ ;
2971
2974
2972
2975
template .updateFirst (query (where ("id" ).is (twn .id )), update , TypeWithNumbers .class );
2973
2976
@@ -3023,7 +3026,7 @@ public void updatesNumericValueCorrectlyWhenUsingMaxOperator() {
3023
3026
.max ("longVal" , 590 ) //
3024
3027
.max ("bigIntegerVal" , new BigInteger ("690" )) //
3025
3028
.max ("bigDeciamVal" , new BigDecimal ("790" )) //
3026
- ;
3029
+ ;
3027
3030
3028
3031
template .updateFirst (query (where ("id" ).is (twn .id )), update , TypeWithNumbers .class );
3029
3032
@@ -3052,7 +3055,7 @@ public void updatesBigNumberValueUsingStringComparisonWhenUsingMaxOperator() {
3052
3055
Update update = new Update ()//
3053
3056
.max ("bigIntegerVal" , new BigInteger ("70" )) //
3054
3057
.max ("bigDeciamVal" , new BigDecimal ("80" )) //
3055
- ;
3058
+ ;
3056
3059
3057
3060
template .updateFirst (query (where ("id" ).is (twn .id )), update , TypeWithNumbers .class );
3058
3061
@@ -3076,7 +3079,7 @@ public void updatesBigNumberValueUsingStringComparisonWhenUsingMinOperator() {
3076
3079
Update update = new Update ()//
3077
3080
.min ("bigIntegerVal" , new BigInteger ("700" )) //
3078
3081
.min ("bigDeciamVal" , new BigDecimal ("800" )) //
3079
- ;
3082
+ ;
3080
3083
3081
3084
template .updateFirst (query (where ("id" ).is (twn .id )), update , TypeWithNumbers .class );
3082
3085
@@ -3584,10 +3587,12 @@ static class WithObjectTypeProperty {
3584
3587
Object value ;
3585
3588
}
3586
3589
3587
- static class PersonWithIdPropertyOfTypeUUIDListener extends AbstractMongoEventListener <PersonWithIdPropertyOfTypeUUID > {
3590
+ static class PersonWithIdPropertyOfTypeUUIDListener
3591
+ extends AbstractMongoEventListener <PersonWithIdPropertyOfTypeUUID > {
3588
3592
3589
3593
@ Override
3590
3594
public void onBeforeConvert (BeforeConvertEvent <PersonWithIdPropertyOfTypeUUID > event ) {
3595
+
3591
3596
PersonWithIdPropertyOfTypeUUID person = event .getSource ();
3592
3597
3593
3598
if (person .getId () != null ) {
@@ -3596,6 +3601,5 @@ public void onBeforeConvert(BeforeConvertEvent<PersonWithIdPropertyOfTypeUUID> e
3596
3601
3597
3602
person .setId (UUID .randomUUID ());
3598
3603
}
3599
-
3600
3604
}
3601
3605
}
0 commit comments