1
0

ReplaceCustomChange: assume auto commit off during Liquibase-Changeset

This commit is contained in:
Michael Hoennig
2019-05-06 18:20:10 +02:00
parent 1284c2acaa
commit 295e45e8b8
2 changed files with 20 additions and 2 deletions

View File

@ -13,6 +13,8 @@ import liquibase.exception.CustomChangeException;
import liquibase.exception.DatabaseException;
import liquibase.exception.SetupException;
import com.google.common.base.VerifyException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@ -43,6 +45,7 @@ public class ReplaceCustomChangeUnitTest {
@Before
public void initMocks() throws DatabaseException {
given(database.getConnection()).willReturn(connection);
given(connection.getAutoCommit()).willReturn(false);
given(connection.createStatement()).willReturn(statement);
}
@ -86,6 +89,20 @@ public class ReplaceCustomChangeUnitTest {
assertThat(actual).isEqualTo("in table some_table / columns address,remark: replaced all '|' to '\\n'");
}
@Test
public void throwsValidationErrorIfAutoCommitIsOff() throws Exception {
// given
given(database.getDatabaseProductName()).willReturn(POSTGRES_DATABASE_PRODUCT_NAME);
final ReplaceCustomChange replaceCustomChange = givenReplaceCustomChange("some_table", "address,remark", "|", "\\n");
given(connection.getAutoCommit()).willReturn(true);
// when
final Throwable actual = catchThrowable(() -> replaceCustomChange.execute(database));
// then
assertThat(actual).isInstanceOf(VerifyException.class);
}
@Test
public void onDatabaseExceptionThrowsCustomChangeException() throws Exception {
// given