use of io.r2dbc.spi.Statement 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.Statement in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method executeShouldBindNamedValuesFromIndexes.
@Test
void executeShouldBindNamedValuesFromIndexes() {
Statement statement = mockStatementFor("SELECT id, name, manual FROM legoset WHERE name IN ($1, $2, $3)");
DatabaseClient databaseClient = databaseClientBuilder.build();
databaseClient.sql("SELECT id, name, manual FROM legoset WHERE name IN (:name)").bind(0, Arrays.asList("unknown", "dunno", "other")).then().as(StepVerifier::create).verifyComplete();
verify(statement).bind(0, "unknown");
verify(statement).bind(1, "dunno");
verify(statement).bind(2, "other");
verify(statement).execute();
verifyNoMoreInteractions(statement);
}
use of io.r2dbc.spi.Statement 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.Statement in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method mockStatementFor.
private Statement mockStatementFor(@Nullable String sql, @Nullable Result result) {
Statement statement = mock(Statement.class);
when(connection.createStatement(sql == null ? anyString() : eq(sql))).thenReturn(statement);
when(statement.returnGeneratedValues(anyString())).thenReturn(statement);
when(statement.returnGeneratedValues()).thenReturn(statement);
doReturn(result == null ? Mono.empty() : Flux.just(result)).when(statement).execute();
return statement;
}
use of io.r2dbc.spi.Statement in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method executeShouldBindNamedValuesByIndex.
@Test
void executeShouldBindNamedValuesByIndex() {
Statement statement = mockStatementFor("SELECT * FROM table WHERE key = $1");
DatabaseClient databaseClient = databaseClientBuilder.build();
databaseClient.sql("SELECT * FROM table WHERE key = :key").bind("key", "foo").then().as(StepVerifier::create).verifyComplete();
verify(statement).bind(0, "foo");
}
Aggregations