1
1
/*
2
- * Copyright 2011-2016 the original author or authors.
2
+ * Copyright 2011-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -138,8 +138,10 @@ public class MongoTemplateTests {
138
138
139
139
@ Autowired
140
140
public void setApplicationContext (ConfigurableApplicationContext context ) {
141
- context . addApplicationListener ( new PersonWithIdPropertyOfTypeUUIDListener ());
141
+
142
142
this .context = context ;
143
+
144
+ context .addApplicationListener (new PersonWithIdPropertyOfTypeUUIDListener ());
143
145
}
144
146
145
147
@ Autowired
@@ -149,12 +151,12 @@ public void setMongo(Mongo mongo) throws Exception {
149
151
Arrays .asList (DateToDateTimeConverter .INSTANCE , DateTimeToDateConverter .INSTANCE ));
150
152
151
153
MongoMappingContext mappingContext = new MongoMappingContext ();
152
- mappingContext .setInitialEntitySet (new HashSet <Class <?>>(Arrays . asList ( PersonWith_idPropertyOfTypeObjectId . class ,
153
- PersonWith_idPropertyOfTypeString . class , PersonWithIdPropertyOfTypeObjectId .class ,
154
- PersonWithIdPropertyOfTypeString .class , PersonWithIdPropertyOfTypeInteger .class ,
155
- PersonWithIdPropertyOfTypeBigInteger .class , PersonWithIdPropertyOfPrimitiveInt .class ,
156
- PersonWithIdPropertyOfTypeLong .class , PersonWithIdPropertyOfPrimitiveLong .class ,
157
- PersonWithIdPropertyOfTypeUUID .class )));
154
+ mappingContext .setInitialEntitySet (new HashSet <Class <?>>(
155
+ Arrays . asList ( PersonWith_idPropertyOfTypeObjectId . class , PersonWith_idPropertyOfTypeString .class ,
156
+ PersonWithIdPropertyOfTypeObjectId .class , PersonWithIdPropertyOfTypeString .class ,
157
+ PersonWithIdPropertyOfTypeInteger .class , PersonWithIdPropertyOfTypeBigInteger .class ,
158
+ PersonWithIdPropertyOfPrimitiveInt .class , PersonWithIdPropertyOfTypeLong .class ,
159
+ PersonWithIdPropertyOfPrimitiveLong . class , PersonWithIdPropertyOfTypeUUID .class )));
158
160
mappingContext .setSimpleTypeHolder (conversions .getSimpleTypeHolder ());
159
161
mappingContext .initialize ();
160
162
@@ -168,8 +170,11 @@ public void setMongo(Mongo mongo) throws Exception {
168
170
169
171
@ Before
170
172
public void setUp () {
173
+
171
174
cleanDb ();
172
175
queryMongoVersionIfNecessary ();
176
+
177
+ this .mappingTemplate .setApplicationContext (context );
173
178
}
174
179
175
180
@ After
@@ -659,7 +664,6 @@ private void testProperHandlingOfDifferentIdTypes(MongoTemplate mongoTemplate) t
659
664
PersonWithIdPropertyOfTypeUUID p13 = new PersonWithIdPropertyOfTypeUUID ();
660
665
p13 .setFirstName ("Sven_10" );
661
666
p13 .setAge (22 );
662
- p13 .setId (UUID .randomUUID ());
663
667
// insert
664
668
mongoTemplate .insert (p13 );
665
669
// also try save
@@ -3629,10 +3633,12 @@ static class WithObjectTypeProperty {
3629
3633
Object value ;
3630
3634
}
3631
3635
3632
- static class PersonWithIdPropertyOfTypeUUIDListener extends AbstractMongoEventListener <PersonWithIdPropertyOfTypeUUID > {
3636
+ static class PersonWithIdPropertyOfTypeUUIDListener
3637
+ extends AbstractMongoEventListener <PersonWithIdPropertyOfTypeUUID > {
3633
3638
3634
3639
@ Override
3635
3640
public void onBeforeConvert (BeforeConvertEvent <PersonWithIdPropertyOfTypeUUID > event ) {
3641
+
3636
3642
PersonWithIdPropertyOfTypeUUID person = event .getSource ();
3637
3643
3638
3644
if (person .getId () != null ) {
@@ -3641,6 +3647,5 @@ public void onBeforeConvert(BeforeConvertEvent<PersonWithIdPropertyOfTypeUUID> e
3641
3647
3642
3648
person .setId (UUID .randomUUID ());
3643
3649
}
3644
-
3645
3650
}
3646
3651
}
0 commit comments