use of org.springframework.data.mongodb.core.ReactiveMongoTemplate in project spring-data-mongodb by spring-projects.
the class ReactiveQuerydslMongoPredicateExecutorTests method translatesExceptionsCorrectly.
// DATAMONGO-2182, DATAMONGO-2265
@Test
public void translatesExceptionsCorrectly() {
ReactiveMongoOperations ops = new ReactiveMongoTemplate(dbFactory) {
@Override
protected Mono<MongoDatabase> doGetDatabase() {
return Mono.error(new MongoException(18, "Authentication Failed"));
}
};
ReactiveMongoRepositoryFactory factory = new ReactiveMongoRepositoryFactory(ops);
MongoEntityInformation<Person, String> entityInformation = factory.getEntityInformation(Person.class);
repository = new ReactiveQuerydslMongoPredicateExecutor<>(entityInformation, ops);
//
repository.findOne(person.firstname.contains("batman")).as(//
StepVerifier::create).expectError(//
PermissionDeniedDataAccessException.class).verify();
}
use of org.springframework.data.mongodb.core.ReactiveMongoTemplate in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTransactionManagerUnitTests method readonlyShouldInitiateASessionStartAndCommitTransaction.
// DATAMONGO-2265
@Test
void readonlyShouldInitiateASessionStartAndCommitTransaction() {
ReactiveMongoTransactionManager txManager = new ReactiveMongoTransactionManager(databaseFactory);
ReactiveMongoTemplate template = new ReactiveMongoTemplate(databaseFactory);
when(session.commitTransaction()).thenReturn(Mono.empty());
DefaultTransactionDefinition readonlyTxDefinition = new DefaultTransactionDefinition();
readonlyTxDefinition.setReadOnly(true);
TransactionalOperator operator = TransactionalOperator.create(txManager, readonlyTxDefinition);
template.execute(db -> {
db.drop();
return Mono.empty();
}).as(//
operator::transactional).as(//
StepVerifier::create).verifyComplete();
verify(databaseFactory).withSession(eq(session));
verify(session).startTransaction();
verify(session).commitTransaction();
verify(session).close();
}
use of org.springframework.data.mongodb.core.ReactiveMongoTemplate in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTransactionManagerUnitTests method triggerCommitCorrectly.
// DATAMONGO-2265
@Test
void triggerCommitCorrectly() {
ReactiveMongoTransactionManager txManager = new ReactiveMongoTransactionManager(databaseFactory);
ReactiveMongoTemplate template = new ReactiveMongoTemplate(databaseFactory);
when(session.commitTransaction()).thenReturn(Mono.empty());
TransactionalOperator operator = TransactionalOperator.create(txManager, new DefaultTransactionDefinition());
template.execute(db -> {
db.drop();
return Mono.empty();
}).as(//
operator::transactional).as(//
StepVerifier::create).verifyComplete();
verify(databaseFactory).withSession(eq(session));
verify(session).startTransaction();
verify(session).commitTransaction();
verify(session).close();
}
use of org.springframework.data.mongodb.core.ReactiveMongoTemplate in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTransactionManagerUnitTests method participateInOnGoingTransactionWithRollbackOnly.
// DATAMONGO-2265
@Test
void participateInOnGoingTransactionWithRollbackOnly() {
ReactiveMongoTransactionManager txManager = new ReactiveMongoTransactionManager(databaseFactory);
ReactiveMongoTemplate template = new ReactiveMongoTemplate(databaseFactory);
when(session.abortTransaction()).thenReturn(Mono.empty());
TransactionalOperator operator = TransactionalOperator.create(txManager, new DefaultTransactionDefinition());
operator.execute(tx -> {
return template.execute(db -> {
db.drop();
tx.setRollbackOnly();
return Mono.empty();
});
}).as(StepVerifier::create).verifyComplete();
verify(databaseFactory, times(1)).withSession(eq(session));
verify(session).startTransaction();
verify(session).abortTransaction();
verify(session).close();
}
use of org.springframework.data.mongodb.core.ReactiveMongoTemplate in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTransactionManagerUnitTests method participateInOnGoingTransactionWithCommit.
// DATAMONGO-2265
@Test
void participateInOnGoingTransactionWithCommit() {
ReactiveMongoTransactionManager txManager = new ReactiveMongoTransactionManager(databaseFactory);
ReactiveMongoTemplate template = new ReactiveMongoTemplate(databaseFactory);
when(session.commitTransaction()).thenReturn(Mono.empty());
TransactionalOperator operator = TransactionalOperator.create(txManager, new DefaultTransactionDefinition());
template.execute(db -> {
db.drop();
return Mono.empty();
}).as(StepVerifier::create).verifyComplete();
template.execute(db -> {
db.drop();
return Mono.empty();
}).as(//
operator::transactional).as(//
StepVerifier::create).verifyComplete();
verify(databaseFactory, times(1)).withSession(eq(session));
verify(session).startTransaction();
verify(session).commitTransaction();
verify(session).close();
}
Aggregations