use of reactor.test.StepVerifier in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method selectShouldEmitFirstValue.
@Test
void selectShouldEmitFirstValue() {
MockRowMetadata metadata = MockRowMetadata.builder().columnMetadata(MockColumnMetadata.builder().name("name").javaType(String.class).build()).build();
MockResult result = MockResult.builder().row(MockRow.builder().identified(0, Object.class, "Walter").metadata(metadata).build(), MockRow.builder().identified(0, Object.class, "White").metadata(metadata).build()).build();
mockStatementFor("SELECT * FROM person", result);
DatabaseClient databaseClient = databaseClientBuilder.build();
databaseClient.sql("SELECT * FROM person").map(row -> row.get(0)).first().as(StepVerifier::create).expectNext("Walter").verifyComplete();
}
use of reactor.test.StepVerifier in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method rowsUpdatedShouldEmitSingleValue.
@Test
@SuppressWarnings("unchecked")
void rowsUpdatedShouldEmitSingleValue() {
Result result = mock(Result.class);
when(result.getRowsUpdated()).thenReturn(Mono.empty(), Mono.just(2), Flux.just(1, 2, 3));
mockStatementFor("DROP TABLE tab;", result);
DatabaseClient databaseClient = databaseClientBuilder.build();
databaseClient.sql("DROP TABLE tab;").fetch().rowsUpdated().as(StepVerifier::create).expectNextCount(1).verifyComplete();
databaseClient.sql("DROP TABLE tab;").fetch().rowsUpdated().as(StepVerifier::create).expectNextCount(1).verifyComplete();
databaseClient.sql("DROP TABLE tab;").fetch().rowsUpdated().as(StepVerifier::create).expectNextCount(1).verifyComplete();
}
use of reactor.test.StepVerifier in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method shouldApplyExecuteFunction.
@Test
void shouldApplyExecuteFunction() {
Statement statement = mockStatement();
MockResult result = mockSingleColumnResult(MockRow.builder().identified(0, Object.class, "Walter"));
DatabaseClient databaseClient = databaseClientBuilder.executeFunction(stmnt -> Mono.just(result)).build();
databaseClient.sql("SELECT").fetch().all().as(StepVerifier::create).expectNextCount(1).verifyComplete();
verifyNoInteractions(statement);
}
use of reactor.test.StepVerifier in project spring-framework by spring-projects.
the class AbstractReactiveTransactionAspectTests method cannotCreateTransaction.
/**
* Simulate a transaction infrastructure failure.
* Shouldn't invoke target method.
*/
@Test
public void cannotCreateTransaction() throws Exception {
TransactionAttribute txatt = new DefaultTransactionAttribute();
Method m = getNameMethod;
MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
tas.register(m, txatt);
ReactiveTransactionManager rtm = mock(ReactiveTransactionManager.class);
// Expect a transaction
CannotCreateTransactionException ex = new CannotCreateTransactionException("foobar", null);
given(rtm.getReactiveTransaction(txatt)).willThrow(ex);
DefaultTestBean tb = new DefaultTestBean() {
@Override
public Mono<String> getName() {
throw new UnsupportedOperationException("Shouldn't have invoked target method when couldn't create transaction for transactional method");
}
};
TestBean itb = (TestBean) advised(tb, rtm, tas);
itb.getName().as(StepVerifier::create).expectError(CannotCreateTransactionException.class).verify();
}
use of reactor.test.StepVerifier in project spring-framework by spring-projects.
the class AbstractReactiveTransactionAspectTests method cannotCommitTransaction.
/**
* Simulate failure of the underlying transaction infrastructure to commit.
* Check that the target method was invoked, but that the transaction
* infrastructure exception was thrown to the client
*/
@Test
public void cannotCommitTransaction() throws Exception {
TransactionAttribute txatt = new DefaultTransactionAttribute();
Method m = setNameMethod;
MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
tas.register(m, txatt);
// Method m2 = getNameMethod;
// No attributes for m2
ReactiveTransactionManager rtm = mock(ReactiveTransactionManager.class);
ReactiveTransaction status = mock(ReactiveTransaction.class);
given(rtm.getReactiveTransaction(txatt)).willReturn(Mono.just(status));
UnexpectedRollbackException ex = new UnexpectedRollbackException("foobar", null);
given(rtm.commit(status)).willReturn(Mono.error(ex));
given(rtm.rollback(status)).willReturn(Mono.empty());
DefaultTestBean tb = new DefaultTestBean();
TestBean itb = (TestBean) advised(tb, rtm, tas);
String name = "new name";
Mono.from(itb.setName(name)).as(StepVerifier::create).consumeErrorWith(throwable -> {
assertThat(throwable.getClass()).isEqualTo(RuntimeException.class);
assertThat(throwable.getCause()).isEqualTo(ex);
}).verify();
// Should have invoked target and changed name
itb.getName().as(StepVerifier::create).expectNext(name).verifyComplete();
}
Aggregations