Skip to content

Commit ae0e240

Browse files
Move and add tests to UpdateMapper.
Also update author information. Original Pull Request: #3815
1 parent 852a461 commit ae0e240

File tree

2 files changed

+55
-24
lines changed

2 files changed

+55
-24
lines changed

Diff for: spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java

-24
Original file line numberDiff line numberDiff line change
@@ -1327,25 +1327,6 @@ void mapStringIdFieldProjection() {
13271327
org.bson.Document mappedFields = mapper.getMappedFields(new org.bson.Document("id", 1), context.getPersistentEntity(WithStringId.class));
13281328
assertThat(mappedFields).containsEntry("_id", 1);
13291329
}
1330-
1331-
@Test
1332-
void mapNestedStringFieldCorrectly() {
1333-
Update update = new Update();
1334-
update.set("levelOne.a.b.d", "e");
1335-
org.bson.Document document = mapper.getMappedObject(update.getUpdateObject(),
1336-
context.getPersistentEntity(EntityWithNestedMap.class));
1337-
assertThat(document).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.a.b.d","e")));
1338-
}
1339-
1340-
@Test
1341-
void mapNestedIntegerFieldCorrectly() {
1342-
Update update = new Update();
1343-
update.set("levelOne.0.1.3", "4");
1344-
org.bson.Document document = mapper.getMappedObject(update.getUpdateObject(),
1345-
context.getPersistentEntity(EntityWithNestedMap.class));
1346-
assertThat(document).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.0.1.3","4")));
1347-
}
1348-
13491330

13501331
@Test // GH-3783
13511332
void retainsId$InWithStringArray() {
@@ -1534,11 +1515,6 @@ static class EntityWithIntKeyedMapOfMap{
15341515
static class EntityWithComplexValueTypeList {
15351516
List<SimpleEntityWithoutId> list;
15361517
}
1537-
1538-
static class EntityWithNestedMap {
1539-
Map<String, Map<String, Map<String, Object>>> levelOne;
1540-
}
1541-
15421518

15431519
static class WithExplicitTargetTypes {
15441520

Diff for: spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/UpdateMapperUnitTests.java

+55
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
* @author Mark Paluch
6868
* @author Pavel Vodrazka
6969
* @author David Julia
70+
* @author Divya Srivastava
7071
*/
7172
@ExtendWith(MockitoExtension.class)
7273
class UpdateMapperUnitTests {
@@ -1200,6 +1201,56 @@ void mapsObjectClassPropertyFieldInMapValueTypeAsKey() {
12001201
assertThat(mappedUpdate).isEqualTo("{\"$set\": {\"map.class\": \"value\"}}");
12011202
}
12021203

1204+
@Test // GH-3775
1205+
void mapNestedStringFieldCorrectly() {
1206+
1207+
Update update = new Update().set("levelOne.a.b.d", "e");
1208+
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
1209+
context.getPersistentEntity(EntityWithNestedMap.class));
1210+
1211+
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.a.b.d","e")));
1212+
}
1213+
1214+
@Test // GH-3775
1215+
void mapNestedIntegerFieldCorrectly() {
1216+
1217+
Update update = new Update().set("levelOne.0.1.3", "4");
1218+
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
1219+
context.getPersistentEntity(EntityWithNestedMap.class));
1220+
1221+
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.0.1.3","4")));
1222+
}
1223+
1224+
@Test // GH-3775
1225+
void mapNestedMixedStringIntegerFieldCorrectly() {
1226+
1227+
Update update = new Update().set("levelOne.0.1.c", "4");
1228+
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
1229+
context.getPersistentEntity(EntityWithNestedMap.class));
1230+
1231+
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.0.1.c","4")));
1232+
}
1233+
1234+
@Test // GH-3775
1235+
void mapNestedMixedStringIntegerWithStartNumberFieldCorrectly() {
1236+
1237+
Update update = new Update().set("levelOne.0a.1b.3c", "4");
1238+
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
1239+
context.getPersistentEntity(EntityWithNestedMap.class));
1240+
1241+
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.0a.1b.3c","4")));
1242+
}
1243+
1244+
@Test // GH-3688
1245+
void multipleKeysStartingWithANumberInNestedPath() {
1246+
1247+
Update update = new Update().set("intKeyedMap.1a.map.0b", "testing");
1248+
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
1249+
context.getPersistentEntity(EntityWithIntKeyedMap.class));
1250+
1251+
assertThat(mappedUpdate).isEqualTo("{\"$set\": {\"intKeyedMap.1a.map.0b\": \"testing\"}}");
1252+
}
1253+
12031254
static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes {
12041255
ListModelWrapper concreteTypeWithListAttributeOfInterfaceType;
12051256
}
@@ -1566,4 +1617,8 @@ static class UnwrappableType {
15661617
String transientValue;
15671618
}
15681619

1620+
static class EntityWithNestedMap {
1621+
Map<String, Map<String, Map<String, Object>>> levelOne;
1622+
}
1623+
15691624
}

0 commit comments

Comments
 (0)