Skip to content

Commit

Permalink
Use RestoreSystemPropertiesExtension, assert RawSQLChange class
Browse files Browse the repository at this point in the history
  • Loading branch information
adangel committed Sep 28, 2024
1 parent 4a02df0 commit f72f70d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParame
String sql = perconaChange.getSql();
Matcher usePerconaMatcher = USE_PERCONA_PATTERN.matcher(sql);
if (usePerconaMatcher.find()) {
Boolean usePercona = Boolean.valueOf(usePerconaMatcher.group(1));
boolean usePercona = Boolean.parseBoolean(usePerconaMatcher.group(1));
perconaChange.setUsePercona(usePercona);
usePerconaChangeSet = usePerconaChangeSet || usePercona;
}
Expand Down
75 changes: 40 additions & 35 deletions src/test/java/liquibase/ext/percona/ChangeLogParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import liquibase.change.Change;
import liquibase.change.core.RawSQLChange;
import liquibase.changelog.ChangeLogParameters;
import liquibase.changelog.ChangeSet;
import liquibase.changelog.DatabaseChangeLog;
Expand All @@ -30,6 +32,7 @@
import liquibase.resource.DirectoryResourceAccessor;
import liquibase.resource.ResourceAccessor;

@ExtendWith(RestoreSystemPropertiesExtension.class)
public class ChangeLogParserTest {

private ResourceAccessor resourceAccessor;
Expand Down Expand Up @@ -113,40 +116,42 @@ public void testReadLiquibaseUsePerconaFlagSQL() throws Exception {
@Test
public void testReadLiquibaseUsePerconaFlagSQL_defaultOff() throws Exception {
System.setProperty(Configuration.DEFAULT_ON, "false");
try {
DatabaseChangeLog changelog = loadChangeLog("test-changelog.sql");
Assertions.assertEquals(4, changelog.getChangeSets().size());

// changeset 1
ChangeSet changeSet = changelog.getChangeSets().get(0);
Change change = changeSet.getChanges().get(0);
Assertions.assertFalse(change instanceof PerconaRawSQLChange);
Assertions.assertEquals(1, changeSet.getRollback().getChanges().size());
Change rollback = changeSet.getRollback().getChanges().get(0);
Assertions.assertFalse(rollback instanceof PerconaRawSQLChange);

// changeset 2
changeSet = changelog.getChangeSets().get(1);
change = changeSet.getChanges().get(0);
Assertions.assertFalse(change instanceof PerconaRawSQLChange);
rollback = changeSet.getRollback().getChanges().get(0);
Assertions.assertFalse(rollback instanceof PerconaRawSQLChange);

// changeset 3
changeSet = changelog.getChangeSets().get(2);
change = changeSet.getChanges().get(0);
Assertions.assertFalse(change instanceof PerconaRawSQLChange);
rollback = changeSet.getRollback().getChanges().get(0);
Assertions.assertFalse(rollback instanceof PerconaRawSQLChange);

// changeset 4
changeSet = changelog.getChangeSets().get(3);
change = changeSet.getChanges().get(0);
assertChange(change, PerconaRawSQLChange.class, Boolean.TRUE, null);
rollback = changeSet.getRollback().getChanges().get(0);
assertChange(rollback, PerconaRawSQLChange.class, Boolean.TRUE, null);
} finally {
System.clearProperty(Configuration.DEFAULT_ON);
}
DatabaseChangeLog changelog = loadChangeLog("test-changelog.sql");
Assertions.assertEquals(4, changelog.getChangeSets().size());

// changeset 1
ChangeSet changeSet = changelog.getChangeSets().get(0);
Change change = changeSet.getChanges().get(0);
Assertions.assertSame(RawSQLChange.class, change.getClass());
Assertions.assertFalse(change instanceof PerconaRawSQLChange);
Assertions.assertEquals(1, changeSet.getRollback().getChanges().size());
Change rollback = changeSet.getRollback().getChanges().get(0);
Assertions.assertSame(RawSQLChange.class, rollback.getClass());
Assertions.assertFalse(rollback instanceof PerconaRawSQLChange);

// changeset 2
changeSet = changelog.getChangeSets().get(1);
change = changeSet.getChanges().get(0);
Assertions.assertSame(RawSQLChange.class, change.getClass());
Assertions.assertFalse(change instanceof PerconaRawSQLChange);
rollback = changeSet.getRollback().getChanges().get(0);
Assertions.assertSame(RawSQLChange.class, rollback.getClass());
Assertions.assertFalse(rollback instanceof PerconaRawSQLChange);

// changeset 3
changeSet = changelog.getChangeSets().get(2);
change = changeSet.getChanges().get(0);
Assertions.assertSame(RawSQLChange.class, change.getClass());
Assertions.assertFalse(change instanceof PerconaRawSQLChange);
rollback = changeSet.getRollback().getChanges().get(0);
Assertions.assertSame(RawSQLChange.class, rollback.getClass());
Assertions.assertFalse(rollback instanceof PerconaRawSQLChange);

// changeset 4 - the only one, that explicitly uses percona
changeSet = changelog.getChangeSets().get(3);
change = changeSet.getChanges().get(0);
assertChange(change, PerconaRawSQLChange.class, Boolean.TRUE, null);
rollback = changeSet.getRollback().getChanges().get(0);
assertChange(rollback, PerconaRawSQLChange.class, Boolean.TRUE, null);
}
}

0 comments on commit f72f70d

Please sign in to comment.