Browse Source

Move and add tests to UpdateMapper.

Also update author information.

Original Pull Request: #3815
pull/3801/head
Christoph Strobl 4 years ago
parent
commit
eda1c79315
  1. 24
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java
  2. 55
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/UpdateMapperUnitTests.java

24
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java

@ -1356,25 +1356,6 @@ public class QueryMapperUnitTests {
assertThat(mappedFields).containsEntry("_id", 1); assertThat(mappedFields).containsEntry("_id", 1);
} }
@Test
void mapNestedStringFieldCorrectly() {
Update update = new Update();
update.set("levelOne.a.b.d", "e");
org.bson.Document document = mapper.getMappedObject(update.getUpdateObject(),
context.getPersistentEntity(EntityWithNestedMap.class));
assertThat(document).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.a.b.d","e")));
}
@Test
void mapNestedIntegerFieldCorrectly() {
Update update = new Update();
update.set("levelOne.0.1.3", "4");
org.bson.Document document = mapper.getMappedObject(update.getUpdateObject(),
context.getPersistentEntity(EntityWithNestedMap.class));
assertThat(document).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.0.1.3","4")));
}
@Test // GH-3783 @Test // GH-3783
void retainsId$InWithStringArray() { void retainsId$InWithStringArray() {
@ -1563,11 +1544,6 @@ public class QueryMapperUnitTests {
List<SimpleEntityWithoutId> list; List<SimpleEntityWithoutId> list;
} }
static class EntityWithNestedMap {
Map<String, Map<String, Map<String, Object>>> levelOne;
}
static class WithExplicitTargetTypes { static class WithExplicitTargetTypes {
@Field(targetType = FieldType.SCRIPT) // @Field(targetType = FieldType.SCRIPT) //

55
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/UpdateMapperUnitTests.java

@ -68,6 +68,7 @@ import com.mongodb.DBRef;
* @author Mark Paluch * @author Mark Paluch
* @author Pavel Vodrazka * @author Pavel Vodrazka
* @author David Julia * @author David Julia
* @author Divya Srivastava
*/ */
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
class UpdateMapperUnitTests { class UpdateMapperUnitTests {
@ -1200,6 +1201,56 @@ class UpdateMapperUnitTests {
assertThat(mappedUpdate).isEqualTo("{\"$set\": {\"map.class\": \"value\"}}"); assertThat(mappedUpdate).isEqualTo("{\"$set\": {\"map.class\": \"value\"}}");
} }
@Test // GH-3775
void mapNestedStringFieldCorrectly() {
Update update = new Update().set("levelOne.a.b.d", "e");
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
context.getPersistentEntity(EntityWithNestedMap.class));
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.a.b.d","e")));
}
@Test // GH-3775
void mapNestedIntegerFieldCorrectly() {
Update update = new Update().set("levelOne.0.1.3", "4");
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
context.getPersistentEntity(EntityWithNestedMap.class));
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.0.1.3","4")));
}
@Test // GH-3775
void mapNestedMixedStringIntegerFieldCorrectly() {
Update update = new Update().set("levelOne.0.1.c", "4");
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
context.getPersistentEntity(EntityWithNestedMap.class));
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.0.1.c","4")));
}
@Test // GH-3775
void mapNestedMixedStringIntegerWithStartNumberFieldCorrectly() {
Update update = new Update().set("levelOne.0a.1b.3c", "4");
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
context.getPersistentEntity(EntityWithNestedMap.class));
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set",new org.bson.Document("levelOne.0a.1b.3c","4")));
}
@Test // GH-3688
void multipleKeysStartingWithANumberInNestedPath() {
Update update = new Update().set("intKeyedMap.1a.map.0b", "testing");
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
context.getPersistentEntity(EntityWithIntKeyedMap.class));
assertThat(mappedUpdate).isEqualTo("{\"$set\": {\"intKeyedMap.1a.map.0b\": \"testing\"}}");
}
static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes { static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes {
ListModelWrapper concreteTypeWithListAttributeOfInterfaceType; ListModelWrapper concreteTypeWithListAttributeOfInterfaceType;
} }
@ -1566,4 +1617,8 @@ class UpdateMapperUnitTests {
String transientValue; String transientValue;
} }
static class EntityWithNestedMap {
Map<String, Map<String, Map<String, Object>>> levelOne;
}
} }

Loading…
Cancel
Save