use of io.r2dbc.spi.test.MockResult in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method mockSingleColumnResult.
/**
* Mocks a {@link Result} with a single column "name" and a single row if a non null
* row is provided.
*/
private MockResult mockSingleColumnResult(@Nullable MockRow.Builder row) {
MockResult.Builder resultBuilder = MockResult.builder();
if (row != null) {
MockRowMetadata metadata = MockRowMetadata.builder().columnMetadata(MockColumnMetadata.builder().name("name").javaType(String.class).build()).build();
resultBuilder = resultBuilder.row(row.metadata(metadata).build());
}
return resultBuilder.build();
}
use of io.r2dbc.spi.test.MockResult 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 io.r2dbc.spi.test.MockResult 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);
}
Aggregations