Skip to content

Commit

Permalink
JDBC - Add action and isolation validation for Transaction component
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelborn committed Mar 11, 2024
1 parent 4184f23 commit e176f65
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Transaction() {
"setsavepoint"
)
) ),
new Attribute( Key.isolation, "isolation", Set.of(
new Attribute( Key.isolation, "string", Set.of(
Validator.valueOneOf(
"read_uncommitted",
"read_committed",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -42,6 +44,7 @@
import ortus.boxlang.runtime.types.IStruct;
import ortus.boxlang.runtime.types.Query;
import ortus.boxlang.runtime.types.Struct;
import ortus.boxlang.runtime.types.exceptions.BoxRuntimeException;

public class TransactionTest {

Expand Down Expand Up @@ -220,6 +223,33 @@ public void testRollbackAllSavepoints() {
);
}

@DisplayName( "Throws on bad action level" )
@Test
public void testActionValidation() {
assertDoesNotThrow( () -> instance.executeStatement( "transaction action='commit';" ) );

BoxRuntimeException e = assertThrows( BoxRuntimeException.class, () -> instance.executeStatement( "transaction action='foo'{}" ) );

assertTrue( e.getMessage().startsWith( "Record [action] for component [Transaction] must be one of the following values:" ) );
}

@DisplayName( "Throws on bad isolation level" )
@Test
public void testIsolationValidation() {
assertDoesNotThrow( () -> instance.executeStatement( "transaction isolation='read_committed'{}" ) );

BoxRuntimeException e = assertThrows( BoxRuntimeException.class, () -> instance.executeStatement( "transaction isolation='foo'{}" ) );

assertTrue( e.getMessage().startsWith( "Record [isolation] for component [Transaction] must be one of the following values:" ) );
}

@Disabled( "Not implemented" )
@DisplayName( "Can set isolation levels" )
@Test
public void testIsolationLevels() {
// @TODO: Implement
}

@Disabled( "Not implemented" )
@DisplayName( "Can handle nested transactions" )
@Test
Expand Down

0 comments on commit e176f65

Please sign in to comment.