Added testcase to reproduce liquibase failure
Signed-off-by: Andrew DeMaria <lostonamountain@gmail.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package org.libresonic.player.service;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.libresonic.player.TestCaseUtils;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class StartupTestCase extends TestCase {
|
||||
|
||||
private static String baseResources = "/org/libresonic/player/service/mediaScannerServiceTestCase/";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public void testStartup() throws Exception {
|
||||
String homeParent = TestCaseUtils.libresonicHomePathForTest();
|
||||
System.setProperty("libresonic.home", TestCaseUtils.libresonicHomePathForTest());
|
||||
TestCaseUtils.cleanLibresonicHomeForTest();
|
||||
File dbDirectory = new File(homeParent, "/db");
|
||||
FileUtils.forceMkdir(dbDirectory);
|
||||
org.libresonic.player.util.FileUtils.copyResourcesRecursively(getClass().getResource("/db/pre-liquibase/db"), new File(homeParent));
|
||||
|
||||
// load spring context
|
||||
ApplicationContext context = TestCaseUtils.loadSpringApplicationContext(baseResources);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package org.libresonic.player.util;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
public class FileUtils {
|
||||
public static boolean copyFile(final File toCopy, final File destFile) {
|
||||
try {
|
||||
return FileUtils.copyStream(new FileInputStream(toCopy), new FileOutputStream(destFile));
|
||||
} catch (final FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean copyFilesRecusively(
|
||||
final File toCopy, final File destDir
|
||||
) {
|
||||
assert destDir.isDirectory();
|
||||
|
||||
if (!toCopy.isDirectory()) {
|
||||
return FileUtils.copyFile(toCopy, new File(destDir, toCopy.getName()));
|
||||
} else {
|
||||
final File newDestDir = new File(destDir, toCopy.getName());
|
||||
if (!newDestDir.exists() && !newDestDir.mkdir()) {
|
||||
return false;
|
||||
}
|
||||
for (final File child : toCopy.listFiles()) {
|
||||
if (!FileUtils.copyFilesRecusively(child, newDestDir)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean copyJarResourcesRecursively(
|
||||
final File destDir, final JarURLConnection jarConnection
|
||||
) throws IOException {
|
||||
|
||||
final JarFile jarFile = jarConnection.getJarFile();
|
||||
|
||||
for (final Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements(); ) {
|
||||
final JarEntry entry = e.nextElement();
|
||||
if (entry.getName().startsWith(jarConnection.getEntryName())) {
|
||||
final String filename = StringUtils.removeStart(
|
||||
entry.getName(), //
|
||||
jarConnection.getEntryName());
|
||||
|
||||
final File f = new File(destDir, filename);
|
||||
if (!entry.isDirectory()) {
|
||||
final InputStream entryInputStream = jarFile.getInputStream(entry);
|
||||
if (!FileUtils.copyStream(entryInputStream, f)) {
|
||||
return false;
|
||||
}
|
||||
entryInputStream.close();
|
||||
} else {
|
||||
if (!FileUtils.ensureDirectoryExists(f)) {
|
||||
throw new IOException("Could not create directory: " + f.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean copyResourcesRecursively(final URL originUrl, final File destination) {
|
||||
try {
|
||||
final URLConnection urlConnection = originUrl.openConnection();
|
||||
if (urlConnection instanceof JarURLConnection) {
|
||||
return FileUtils.copyJarResourcesRecursively(destination, (JarURLConnection) urlConnection);
|
||||
} else {
|
||||
return FileUtils.copyFilesRecusively(new File(originUrl.getPath()), destination);
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean copyStream(final InputStream is, final File f) {
|
||||
try {
|
||||
return FileUtils.copyStream(is, new FileOutputStream(f));
|
||||
} catch (final FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean copyStream(final InputStream is, final OutputStream os) {
|
||||
try {
|
||||
final byte[] buf = new byte[1024];
|
||||
|
||||
int len = 0;
|
||||
while ((len = is.read(buf)) > 0) {
|
||||
os.write(buf, 0, len);
|
||||
}
|
||||
is.close();
|
||||
os.close();
|
||||
return true;
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean ensureDirectoryExists(final File f) {
|
||||
return f.exists() || f.mkdir();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
@@ -0,0 +1,17 @@
|
||||
#HSQL Database Engine 1.8.0.5
|
||||
#Sun Dec 18 21:11:59 MST 2016
|
||||
hsqldb.script_format=0
|
||||
runtime.gc_interval=0
|
||||
sql.enforce_strict_size=false
|
||||
hsqldb.cache_size_scale=8
|
||||
readonly=false
|
||||
hsqldb.nio_data_file=true
|
||||
hsqldb.cache_scale=14
|
||||
version=1.8.0
|
||||
hsqldb.default_table_type=memory
|
||||
hsqldb.cache_file_scale=1
|
||||
hsqldb.log_size=200
|
||||
modified=yes
|
||||
hsqldb.cache_version=1.7.0
|
||||
hsqldb.original_version=1.8.0
|
||||
hsqldb.compatible_version=1.8.0
|
||||
Reference in New Issue
Block a user