use of org.springframework.data.mongodb.core.query.Update in project spring-data-mongodb by spring-projects.
the class UpdateMapperUnitTests method testUpdateShouldAllowMultiplePushEachForDifferentFields.
// DATAMONGO-812
@Test
void testUpdateShouldAllowMultiplePushEachForDifferentFields() {
Update update = new Update().push("category").each("spring", "data").push("type").each("mongodb");
Document mappedObject = mapper.getMappedObject(update.getUpdateObject(), context.getPersistentEntity(Object.class));
Document push = getAsDocument(mappedObject, "$push");
assertThat(getAsDocument(push, "category")).containsKey("$each");
assertThat(getAsDocument(push, "type")).containsKey("$each");
}
use of org.springframework.data.mongodb.core.query.Update in project spring-data-mongodb by spring-projects.
the class UpdateMapperUnitTests method mappingShouldNotRetainTypeInformationForConcreteValues.
// DATAMONGO-1236
@Test
void mappingShouldNotRetainTypeInformationForConcreteValues() {
Update update = new Update().set("concreteValue", new NestedDocument("shallan"));
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), context.getPersistentEntity(EntityWithObject.class));
assertThat(mappedUpdate).containsEntry("$set.concreteValue.name", "shallan");
assertThat(mappedUpdate).doesNotContainKey("$set.concreteValue._class");
}
use of org.springframework.data.mongodb.core.query.Update in project spring-data-mongodb by spring-projects.
the class UpdateMapperUnitTests method updatePushEachWithSliceShouldRenderCorrectly.
// DATAMONGO-832
@Test
void updatePushEachWithSliceShouldRenderCorrectly() {
Update update = new Update().push("key").slice(5).each(Arrays.asList("Arya", "Arry", "Weasel"));
Document mappedObject = mapper.getMappedObject(update.getUpdateObject(), context.getPersistentEntity(Object.class));
Document push = getAsDocument(mappedObject, "$push");
Document key = getAsDocument(push, "key");
assertThat(key).containsKey("$slice").containsEntry("$slice", 5);
assertThat(key).containsKey("$each");
}
use of org.springframework.data.mongodb.core.query.Update in project spring-data-mongodb by spring-projects.
the class UpdateMapperUnitTests method mappingShouldAllowPositionParameterWithIdentifier.
// DATAMONGO-2215
@Test
void mappingShouldAllowPositionParameterWithIdentifier() {
Update update = //
new Update().set("grades.$[element]", 10).filterArray(Criteria.where("element").gte(100));
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), context.getPersistentEntity(EntityWithListOfIntegers.class));
assertThat(mappedUpdate).isEqualTo(new Document("$set", new Document("grades.$[element]", 10)));
}
use of org.springframework.data.mongodb.core.query.Update in project spring-data-mongodb by spring-projects.
the class UpdateMapperUnitTests method pathShouldIdentifyPositionalParameterWithMoreThanOneDigit.
// DATAMONGO-1809
@Test
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).isEqualTo(new Document("$addToSet", new Document("concreteInnerList.10.concreteTypeList", new Document("value", "szeth"))));
assertThat(at3digitPosition).isEqualTo(new Document("$addToSet", new Document("concreteInnerList.123.concreteTypeList", new Document("value", "lopen"))));
}
Aggregations