use of org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion in project spring-data-mongodb by spring-projects.
the class MongoTemplateUpdateTests method aggregateUpdateWithSetToValue.
// DATAMONGO-2331
@Test
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.2")
void aggregateUpdateWithSetToValue() {
Book one = new Book();
one.id = 1;
one.author = new Author("John", "Backus");
template.insertAll(Arrays.asList(one));
AggregationUpdate update = AggregationUpdate.update().set("author").toValue(new Author("Ada", "Lovelace"));
template.update(Book.class).matching(Query.query(Criteria.where("id").is(one.id))).apply(update).all();
assertThat(all(Book.class)).containsExactlyInAnyOrder(org.bson.Document.parse("{\"_id\" : 1, \"author\" : {\"first\" : \"Ada\", \"last\" : \"Lovelace\"}, \"_class\" : \"org.springframework.data.mongodb.core.MongoTemplateUpdateTests$Book\"}"));
}
use of org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion in project spring-data-mongodb by spring-projects.
the class MongoTemplateUpdateTests method versionedAggregateUpdateTouchingVersionProperty.
// DATAMONGO-2331
@Test
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.2")
void versionedAggregateUpdateTouchingVersionProperty() {
Versioned source = template.insert(Versioned.class).one(new Versioned("id-1", "value-0"));
AggregationUpdate update = AggregationUpdate.update().set(SetOperation.builder().set("value").toValue("changed").and().set("version").toValue(10L));
template.update(Versioned.class).matching(Query.query(Criteria.where("id").is(source.id))).apply(update).first();
assertThat(collection(Versioned.class).find(new org.bson.Document("_id", source.id)).limit(1).into(new ArrayList<>())).containsExactly(new org.bson.Document("_id", source.id).append("version", 10L).append("value", "changed").append("_class", "org.springframework.data.mongodb.core.MongoTemplateUpdateTests$Versioned"));
}
use of org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion in project spring-data-mongodb by spring-projects.
the class MongoTemplateUpdateTests method aggregateUpdateWithReplaceWith.
// DATAMONGO-2331
@Test
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.2")
void aggregateUpdateWithReplaceWith() {
Book one = new Book();
one.id = 1;
one.author = new Author("John", "Backus");
Book two = new Book();
two.id = 2;
two.author = new Author("Grace", "Hopper");
template.insertAll(Arrays.asList(one, two));
AggregationUpdate update = AggregationUpdate.update().replaceWith(ReplaceWithOperation.replaceWithValueOf("author"));
template.update(Book.class).apply(update).all();
assertThat(all(Book.class)).containsExactlyInAnyOrder(org.bson.Document.parse("{\"_id\" : 1, \"first\" : \"John\", \"last\" : \"Backus\"}"), org.bson.Document.parse("{\"_id\" : 2, \"first\" : \"Grace\", \"last\" : \"Hopper\"}"));
}
use of org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion in project spring-data-mongodb by spring-projects.
the class MongoTemplateUpdateTests method aggregateUpdateWithReplaceWithNewObject.
// DATAMONGO-2331
@Test
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.2")
void aggregateUpdateWithReplaceWithNewObject() {
Book one = new Book();
one.id = 1;
one.author = new Author("John", "Backus");
Book two = new Book();
two.id = 2;
two.author = new Author("Grace", "Hopper");
template.insertAll(Arrays.asList(one, two));
AggregationUpdate update = AggregationUpdate.update().replaceWith(new Author("Ada", "Lovelace"));
template.update(Book.class).matching(Query.query(Criteria.where("id").is(one.id))).apply(update).all();
assertThat(all(Book.class)).containsExactlyInAnyOrder(org.bson.Document.parse("{\"_id\" : 1, \"first\" : \"Ada\", \"last\" : \"Lovelace\", \"_class\" : \"org.springframework.data.mongodb.core.MongoTemplateUpdateTests$Author\"}"), org.bson.Document.parse("{\"_id\" : 2, \"author\" : {\"first\" : \"Grace\", \"last\" : \"Hopper\"}, \"_class\" : \"org.springframework.data.mongodb.core.MongoTemplateUpdateTests$Book\"}"));
}
use of org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion in project spring-data-mongodb by spring-projects.
the class SimpleMongoRepositoryTests method existsShouldBePossibleInTransaction.
// DATAMONGO-2130
@Test
@EnableIfReplicaSetAvailable
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.0")
void existsShouldBePossibleInTransaction() {
MongoTransactionManager txmgr = new MongoTransactionManager(template.getMongoDbFactory());
TransactionTemplate tt = new TransactionTemplate(txmgr);
tt.afterPropertiesSet();
boolean exists = tt.execute(status -> {
Person sample = new Person();
sample.setLastname("Matthews");
repository.save(sample);
return repository.existsById(sample.getId());
});
assertThat(exists).isTrue();
}
Aggregations