DATAMONGO-1809 - Fix positional parameter detection for PropertyPaths.

We now make sure to capture all digits for positional parameters.

Original pull request: #508.
This commit is contained in:
Christoph Strobl
2017-10-23 08:51:55 +02:00
committed by Mark Paluch
parent 49dd03311a
commit fdbb305b8e
2 changed files with 25 additions and 1 deletions

View File

@@ -930,7 +930,7 @@ public class QueryMapper {
try {
PropertyPath path = PropertyPath.from(pathExpression.replaceAll("\\.\\d", ""), entity.getTypeInformation());
PropertyPath path = PropertyPath.from(pathExpression.replaceAll("\\.\\d+", ""), entity.getTypeInformation());
PersistentPropertyPath<MongoPersistentProperty> propertyPath = mappingContext.getPersistentPropertyPath(path);
Iterator<MongoPersistentProperty> iterator = propertyPath.iterator();

View File

@@ -21,6 +21,9 @@ import static org.mockito.Mockito.*;
import static org.springframework.data.mongodb.core.DocumentTestUtils.*;
import static org.springframework.data.mongodb.test.util.IsBsonObject.*;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collections;
@@ -677,6 +680,23 @@ public class UpdateMapperUnitTests {
.containing("$set.concreteTypeWithListAttributeOfInterfaceType.models.[0]._class", ModelImpl.class.getName()));
}
@Test // DATAMONGO-1809
public void pathShouldIdentifyPositionalParameterWithMoreThanOneDigit() {
Document at2digitPosition = mapper.getMappedObject(new Update()
.addToSet("concreteInnerList.10.concreteTypeList", new SomeInterfaceImpl("szeth")).getUpdateObject(),
context.getPersistentEntity(Outer.class));
Document at3digitPosition = mapper.getMappedObject(new Update()
.addToSet("concreteInnerList.123.concreteTypeList", new SomeInterfaceImpl("lopen")).getUpdateObject(),
context.getPersistentEntity(Outer.class));
assertThat(at2digitPosition, is(equalTo(new Document("$addToSet",
new Document("concreteInnerList.10.concreteTypeList", new Document("value", "szeth"))))));
assertThat(at3digitPosition, is(equalTo(new Document("$addToSet",
new Document("concreteInnerList.123.concreteTypeList", new Document("value", "lopen"))))));
}
@Test // DATAMONGO-1236
public void mappingShouldRetainTypeInformationForObjectValues() {
@@ -1254,6 +1274,7 @@ public class UpdateMapperUnitTests {
static class ConcreteInner {
List<SomeInterfaceType> interfaceTypeList;
List<SomeAbstractType> abstractTypeList;
List<SomeInterfaceImpl> concreteTypeList;
}
interface SomeInterfaceType {
@@ -1264,8 +1285,11 @@ public class UpdateMapperUnitTests {
}
@AllArgsConstructor
@NoArgsConstructor
static class SomeInterfaceImpl extends SomeAbstractType implements SomeInterfaceType {
String value;
}
}