use of io.r2dbc.spi.Statement in project spring-framework by spring-projects.
the class R2dbcTransactionManagerUnitTests method appliesReadOnly.
@Test
void appliesReadOnly() {
when(connectionMock.commitTransaction()).thenReturn(Mono.empty());
when(connectionMock.setTransactionIsolationLevel(any())).thenReturn(Mono.empty());
Statement statement = mock(Statement.class);
when(connectionMock.createStatement(anyString())).thenReturn(statement);
when(statement.execute()).thenReturn(Mono.empty());
tm.setEnforceReadOnly(true);
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setReadOnly(true);
TransactionalOperator operator = TransactionalOperator.create(tm, definition);
ConnectionFactoryUtils.getConnection(connectionFactoryMock).as(operator::transactional).as(StepVerifier::create).expectNextCount(1).verifyComplete();
verify(connectionMock).isAutoCommit();
verify(connectionMock).beginTransaction();
verify(connectionMock).createStatement("SET TRANSACTION READ ONLY");
verify(connectionMock).commitTransaction();
verify(connectionMock).close();
verifyNoMoreInteractions(connectionMock);
}
use of io.r2dbc.spi.Statement 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.Statement in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method executeShouldBindNamedNullValues.
@Test
void executeShouldBindNamedNullValues() {
Statement statement = mockStatementFor("SELECT * FROM table WHERE key = $1");
DatabaseClient databaseClient = databaseClientBuilder.build();
databaseClient.sql("SELECT * FROM table WHERE key = :key").bindNull("key", String.class).then().as(StepVerifier::create).verifyComplete();
verify(statement).bindNull(0, String.class);
}
use of io.r2dbc.spi.Statement in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method executeShouldBindSettableValues.
@Test
void executeShouldBindSettableValues() {
Statement statement = mockStatementFor("SELECT * FROM table WHERE key = $1");
DatabaseClient databaseClient = databaseClientBuilder.namedParameters(false).build();
databaseClient.sql("SELECT * FROM table WHERE key = $1").bind(0, Parameter.empty(String.class)).then().as(StepVerifier::create).verifyComplete();
verify(statement).bindNull(0, String.class);
databaseClient.sql("SELECT * FROM table WHERE key = $1").bind("$1", Parameter.empty(String.class)).then().as(StepVerifier::create).verifyComplete();
verify(statement).bindNull("$1", String.class);
}
use of io.r2dbc.spi.Statement in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method executeShouldBindValues.
@Test
void executeShouldBindValues() {
Statement statement = mockStatementFor("SELECT * FROM table WHERE key = $1");
DatabaseClient databaseClient = databaseClientBuilder.build();
databaseClient.sql("SELECT * FROM table WHERE key = $1").bind(0, Parameter.from("foo")).then().as(StepVerifier::create).verifyComplete();
verify(statement).bind(0, "foo");
databaseClient.sql("SELECT * FROM table WHERE key = $1").bind("$1", "foo").then().as(StepVerifier::create).verifyComplete();
verify(statement).bind("$1", "foo");
}
Aggregations