|
126 | 126 | * @author Laszlo Csontos
|
127 | 127 | * @author duozhilin
|
128 | 128 | * @author Jakub Zurawa
|
| 129 | + * @author Florian Lüdiger |
129 | 130 | */
|
130 | 131 | @ExtendWith(MongoClientExtension.class)
|
131 | 132 | public class MongoTemplateTests {
|
@@ -4065,6 +4066,64 @@ void readsMapWithDotInKey() {
|
4065 | 4066 | assertThat(loaded.mapValue).isEqualTo(sourceMap);
|
4066 | 4067 | }
|
4067 | 4068 |
|
| 4069 | + @Test // GH-4797 |
| 4070 | + public void updateFirstWithSortingAscendingShouldUpdateCorrectEntities() { |
| 4071 | + |
| 4072 | + PersonWithIdPropertyOfTypeObjectId youngPerson = new PersonWithIdPropertyOfTypeObjectId(); |
| 4073 | + youngPerson.setId(new ObjectId()); |
| 4074 | + youngPerson.setAge(27); |
| 4075 | + youngPerson.setFirstName("Dave"); |
| 4076 | + template.save(youngPerson); |
| 4077 | + |
| 4078 | + PersonWithIdPropertyOfTypeObjectId oldPerson = new PersonWithIdPropertyOfTypeObjectId(); |
| 4079 | + oldPerson.setId(new ObjectId()); |
| 4080 | + oldPerson.setAge(34); |
| 4081 | + oldPerson.setFirstName("Dave"); |
| 4082 | + template.save(oldPerson); |
| 4083 | + |
| 4084 | + template.updateFirst(query(where("firstName").is("Dave")).with(Sort.by(Direction.ASC, "age")), |
| 4085 | + update("firstName", "Mike"), PersonWithIdPropertyOfTypeObjectId.class); |
| 4086 | + |
| 4087 | + PersonWithIdPropertyOfTypeObjectId oldPersonResult = template.findById(oldPerson.getId(), |
| 4088 | + PersonWithIdPropertyOfTypeObjectId.class); |
| 4089 | + assertThat(oldPersonResult).isNotNull(); |
| 4090 | + assertThat(oldPersonResult.getFirstName()).isEqualTo("Dave"); |
| 4091 | + |
| 4092 | + PersonWithIdPropertyOfTypeObjectId youngPersonResult = template.findById(youngPerson.getId(), |
| 4093 | + PersonWithIdPropertyOfTypeObjectId.class); |
| 4094 | + assertThat(youngPersonResult).isNotNull(); |
| 4095 | + assertThat(youngPersonResult.getFirstName()).isEqualTo("Mike"); |
| 4096 | + } |
| 4097 | + |
| 4098 | + @Test // GH-4797 |
| 4099 | + public void updateFirstWithSortingDescendingShouldUpdateCorrectEntities() { |
| 4100 | + |
| 4101 | + PersonWithIdPropertyOfTypeObjectId youngPerson = new PersonWithIdPropertyOfTypeObjectId(); |
| 4102 | + youngPerson.setId(new ObjectId()); |
| 4103 | + youngPerson.setAge(27); |
| 4104 | + youngPerson.setFirstName("Dave"); |
| 4105 | + template.save(youngPerson); |
| 4106 | + |
| 4107 | + PersonWithIdPropertyOfTypeObjectId oldPerson = new PersonWithIdPropertyOfTypeObjectId(); |
| 4108 | + oldPerson.setId(new ObjectId()); |
| 4109 | + oldPerson.setAge(34); |
| 4110 | + oldPerson.setFirstName("Dave"); |
| 4111 | + template.save(oldPerson); |
| 4112 | + |
| 4113 | + template.updateFirst(query(where("firstName").is("Dave")).with(Sort.by(Direction.DESC, "age")), |
| 4114 | + update("firstName", "Mike"), PersonWithIdPropertyOfTypeObjectId.class); |
| 4115 | + |
| 4116 | + PersonWithIdPropertyOfTypeObjectId oldPersonResult = template.findById(oldPerson.getId(), |
| 4117 | + PersonWithIdPropertyOfTypeObjectId.class); |
| 4118 | + assertThat(oldPersonResult).isNotNull(); |
| 4119 | + assertThat(oldPersonResult.getFirstName()).isEqualTo("Mike"); |
| 4120 | + |
| 4121 | + PersonWithIdPropertyOfTypeObjectId youngPersonResult = template.findById(youngPerson.getId(), |
| 4122 | + PersonWithIdPropertyOfTypeObjectId.class); |
| 4123 | + assertThat(youngPersonResult).isNotNull(); |
| 4124 | + assertThat(youngPersonResult.getFirstName()).isEqualTo("Dave"); |
| 4125 | + } |
| 4126 | + |
4068 | 4127 | private AtomicReference<ImmutableVersioned> createAfterSaveReference() {
|
4069 | 4128 |
|
4070 | 4129 | AtomicReference<ImmutableVersioned> saved = new AtomicReference<>();
|
|
0 commit comments