use of io.r2dbc.spi.test.MockResult 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.MockResult in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method shouldApplyStatementFilterFunctions.
@Test
void shouldApplyStatementFilterFunctions() {
MockResult result = MockResult.builder().build();
Statement statement = mockStatement(result);
DatabaseClient databaseClient = databaseClientBuilder.build();
databaseClient.sql("SELECT").filter((s, next) -> next.execute(s.returnGeneratedValues("foo"))).filter((s, next) -> next.execute(s.returnGeneratedValues("bar"))).fetch().all().as(StepVerifier::create).verifyComplete();
InOrder inOrder = inOrder(statement);
inOrder.verify(statement).returnGeneratedValues("foo");
inOrder.verify(statement).returnGeneratedValues("bar");
inOrder.verify(statement).execute();
inOrder.verifyNoMoreInteractions();
}
use of io.r2dbc.spi.test.MockResult in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method shouldApplySimpleStatementFilterFunctions.
@Test
void shouldApplySimpleStatementFilterFunctions() {
MockResult result = mockSingleColumnEmptyResult();
Statement statement = mockStatement(result);
DatabaseClient databaseClient = databaseClientBuilder.build();
databaseClient.sql("SELECT").filter(s -> s.returnGeneratedValues("foo")).filter(s -> s.returnGeneratedValues("bar")).fetch().all().as(StepVerifier::create).verifyComplete();
InOrder inOrder = inOrder(statement);
inOrder.verify(statement).returnGeneratedValues("foo");
inOrder.verify(statement).returnGeneratedValues("bar");
inOrder.verify(statement).execute();
inOrder.verifyNoMoreInteractions();
}
use of io.r2dbc.spi.test.MockResult in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method shouldApplyPreparedOperation.
@Test
void shouldApplyPreparedOperation() {
MockResult result = mockSingleColumnResult(MockRow.builder().identified(0, Object.class, "Walter"));
Statement statement = mockStatementFor("SELECT * FROM person", result);
DatabaseClient databaseClient = databaseClientBuilder.build();
databaseClient.sql(new PreparedOperation<String>() {
@Override
public String toQuery() {
return "SELECT * FROM person";
}
@Override
public String getSource() {
return "SELECT";
}
@Override
public void bindTo(BindTarget target) {
target.bind("index", "value");
}
}).fetch().all().as(StepVerifier::create).expectNextCount(1).verifyComplete();
verify(statement).bind("index", "value");
}
use of io.r2dbc.spi.test.MockResult 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);
}
Aggregations