Skip to content

Commit

Permalink
Assert LazyConnectionDataSourceProxy.setDefaultTransactionIsolation()…
Browse files Browse the repository at this point in the history
… values

See gh-30851
  • Loading branch information
sbrannen committed Jul 31, 2023
1 parent c43d2e2 commit 48eb477
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ public void setDefaultTransactionIsolationName(String constantName) {
* @see java.sql.Connection#setTransactionIsolation
*/
public void setDefaultTransactionIsolation(int defaultTransactionIsolation) {
Assert.isTrue(constants.containsValue(defaultTransactionIsolation),
"Only values of transaction isolation constants allowed");
this.defaultTransactionIsolation = defaultTransactionIsolation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

import static java.sql.Connection.TRANSACTION_NONE;
import static java.sql.Connection.TRANSACTION_READ_COMMITTED;
import static java.sql.Connection.TRANSACTION_READ_UNCOMMITTED;
import static java.sql.Connection.TRANSACTION_REPEATABLE_READ;
import static java.sql.Connection.TRANSACTION_SERIALIZABLE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

Expand Down Expand Up @@ -75,16 +78,20 @@ void setDefaultTransactionIsolationNameToAllSupportedValues() {

@Test
void setDefaultTransactionIsolation() {
// unsupported values are not checked:
proxy.setDefaultTransactionIsolation(-999);
assertThat(proxy.defaultTransactionIsolation()).isEqualTo(-999);

// TRANSACTION_NONE should not be supported, but we currently do not check that.
proxy.setDefaultTransactionIsolation(TRANSACTION_NONE);
assertThat(proxy.defaultTransactionIsolation()).isEqualTo(TRANSACTION_NONE);
assertThatIllegalArgumentException().isThrownBy(() -> proxy.setDefaultTransactionIsolation(-999));
assertThatIllegalArgumentException().isThrownBy(() -> proxy.setDefaultTransactionIsolation(TRANSACTION_NONE));

proxy.setDefaultTransactionIsolation(TRANSACTION_READ_COMMITTED);
assertThat(proxy.defaultTransactionIsolation()).isEqualTo(TRANSACTION_READ_COMMITTED);

proxy.setDefaultTransactionIsolation(TRANSACTION_READ_UNCOMMITTED);
assertThat(proxy.defaultTransactionIsolation()).isEqualTo(TRANSACTION_READ_UNCOMMITTED);

proxy.setDefaultTransactionIsolation(TRANSACTION_REPEATABLE_READ);
assertThat(proxy.defaultTransactionIsolation()).isEqualTo(TRANSACTION_REPEATABLE_READ);

proxy.setDefaultTransactionIsolation(TRANSACTION_SERIALIZABLE);
assertThat(proxy.defaultTransactionIsolation()).isEqualTo(TRANSACTION_SERIALIZABLE);
}


Expand Down

0 comments on commit 48eb477

Please sign in to comment.