-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2250 from liquibase/DAT-8640
Fix issue with ConfiguredValue.wasDefaultValueUsed method DAT-8640
- Loading branch information
Showing
10 changed files
with
145 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 47 additions & 18 deletions
65
...sion-testing/src/main/groovy/liquibase/extension/testing/setup/SetupCleanResources.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,71 @@ | ||
package liquibase.extension.testing.setup | ||
|
||
import liquibase.Contexts | ||
import liquibase.LabelExpression | ||
import liquibase.Liquibase | ||
import liquibase.changelog.ChangeLogHistoryService | ||
import liquibase.changelog.ChangeLogHistoryServiceFactory | ||
import liquibase.database.Database | ||
import liquibase.database.DatabaseFactory | ||
import liquibase.database.jvm.JdbcConnection | ||
|
||
import liquibase.extension.testing.TestDatabaseConnections | ||
import liquibase.integration.commandline.CommandLineResourceAccessor | ||
import liquibase.resource.CompositeResourceAccessor | ||
import liquibase.resource.FileSystemResourceAccessor | ||
|
||
import java.nio.file.Paths | ||
import java.nio.file.FileSystems | ||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
|
||
class SetupCleanResources extends TestSetup { | ||
|
||
private final List<String> resourcesToDelete = new ArrayList<>() | ||
public enum CleanupMode { CLEAN_ON_SETUP, CLEAN_ON_CLEANUP, CLEAN_ON_BOTH} | ||
private CleanupMode cleanupMode | ||
|
||
SetupCleanResources(String[] resourcesToDelete) { | ||
this(CleanupMode.CLEAN_ON_CLEANUP, resourcesToDelete) | ||
} | ||
|
||
SetupCleanResources(CleanupMode cleanupMode, String[] resourcesToDelete) { | ||
this.cleanupMode = cleanupMode | ||
this.resourcesToDelete.addAll(resourcesToDelete as Set) | ||
} | ||
|
||
@Override | ||
void setup(TestDatabaseConnections.ConnectionStatus connectionStatus) throws Exception { | ||
if (cleanupMode == CleanupMode.CLEAN_ON_CLEANUP) { | ||
return | ||
} | ||
deleteFiles(resourcesToDelete) | ||
} | ||
|
||
@Override | ||
void cleanup() { | ||
if (cleanupMode == CleanupMode.CLEAN_ON_SETUP) { | ||
return | ||
} | ||
deleteFiles(resourcesToDelete) | ||
} | ||
|
||
private void deleteFiles(List<String> resourcesToDelete) { | ||
for (String fileToDelete : resourcesToDelete) { | ||
File f = null | ||
URL url = Thread.currentThread().getContextClassLoader().getResource(fileToDelete) | ||
if (url == null) { | ||
return | ||
f = new File(fileToDelete) | ||
} else { | ||
f = new File(url.toURI()) | ||
} | ||
File f = new File(url.toURI()) | ||
|
||
if (f.isFile()) { | ||
f.delete() | ||
} else { | ||
f.deleteDir() | ||
} | ||
|
||
// | ||
// This will handle files and directories | ||
// | ||
/* | ||
if (f.exists()) { | ||
boolean b = f.delete() | ||
if (b) { | ||
assert !f.exists(): "The file '$f' was not deleted" | ||
} | ||
Path path = FileSystems.getDefault().getPath(f.getAbsolutePath()); | ||
Files.walk(path) | ||
.sorted(Comparator.reverseOrder()) | ||
.map({ p -> p.toFile() }) | ||
.forEach({ file -> file.delete() }) | ||
} | ||
*/ | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ng/src/main/groovy/liquibase/extension/testing/setup/SetupCreateDirectoryResources.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package liquibase.extension.testing.setup | ||
|
||
import liquibase.extension.testing.TestDatabaseConnections | ||
|
||
class SetupCreateDirectoryResources extends TestSetup { | ||
|
||
private String directory | ||
|
||
SetupCreateDirectoryResources(String directory) { | ||
this.directory = directory | ||
} | ||
|
||
@Override | ||
void setup(TestDatabaseConnections.ConnectionStatus connectionStatus) throws Exception { | ||
File f = new File(directory) | ||
boolean b = f.mkdirs() | ||
if (! b) { | ||
if (! f.exists()) { | ||
throw new RuntimeException("Unable to create directory '" + directory + "'") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters