spring-projects / spring-projects/spring-data-mongodb
Update Mapper test failed with object nested integer field
Open
@christophstrobl is already working on this.
Since Sep 25, 2023.
type: bug
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
when add following test code in UpdateMapperUnitTests.java, test would fail for parameter "levelOne.levelTwo.1.0" and "levelOne.levelTwo.2.0".
@ParameterizedTest
@ValueSource(strings = {"levelOne.levelTwo.1", "levelOne.levelTwo.1.0", "levelOne.levelTwo.2.0"})
void objectNestedIntegerFieldCorrectly(String path) {
Update update = new Update().set(path, "4");
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
context.getPersistentEntity(EntityWithNestedObject1.class));
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set", new org.bson.Document(path, "4")));
}
static class EntityWithNestedObject1 {
EntityWithNestedObject2 levelOne;
}
static class EntityWithNestedObject2 {
Integer levelTwo;
}
test result:
expected: {"$set"={"levelOne.levelTwo.1.0"="4"}}
but was: {"$set"={"levelOne.levelTwo.1"="4"}}
expected: {"$set"={"levelOne.levelTwo.2.0"="4"}}
but was: {"$set"={"levelOne.levelTwo.2"="4"}}
yes, the last ".0" was lost, but parameter "levelOne.levelTwo.1" will test success.
the test code was pushed to my repository: https://github.com/juzq/spring-data-mongodb
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.