use of io.r2dbc.spi.test.MockRowMetadata in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method selectShouldEmitAllValues.
@Test
void selectShouldEmitAllValues() {
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)).all().as(StepVerifier::create).expectNext("Walter").expectNext("White").verifyComplete();
}
use of io.r2dbc.spi.test.MockRowMetadata in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method selectOneShouldFailWithException.
@Test
void selectOneShouldFailWithException() {
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)).one().as(StepVerifier::create).verifyError(IncorrectResultSizeDataAccessException.class);
}
use of io.r2dbc.spi.test.MockRowMetadata 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.MockRowMetadata 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();
}
Aggregations