Convert to liquibase from handrolled migration tool
Signed-off-by: Andrew DeMaria <lostonamountain@gmail.com>
This commit is contained in:
@@ -1,11 +1,21 @@
|
||||
package org.libresonic.player.dao;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import junit.framework.TestCase;
|
||||
import liquibase.exception.LiquibaseException;
|
||||
import org.libresonic.player.TestCaseUtils;
|
||||
import org.libresonic.player.service.SettingsService;
|
||||
import org.libresonic.player.spring.SpringLiquibase;
|
||||
import org.libresonic.player.util.FileUtil;
|
||||
import org.libresonic.player.util.Util;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Superclass for all DAO test cases.
|
||||
@@ -32,7 +42,10 @@ public abstract class DaoTestCaseBase extends TestCase {
|
||||
protected PodcastDao podcastDao;
|
||||
|
||||
protected DaoTestCaseBase() {
|
||||
daoHelper = new HsqlDaoHelper();
|
||||
DataSource dataSource = createDataSource();
|
||||
daoHelper = new GenericDaoHelper(new JdbcTemplate(dataSource), new NamedParameterJdbcTemplate(dataSource));
|
||||
|
||||
runDatabaseMigration(dataSource);
|
||||
|
||||
playerDao = new PlayerDao();
|
||||
internetRadioDao = new InternetRadioDao();
|
||||
@@ -57,6 +70,34 @@ public abstract class DaoTestCaseBase extends TestCase {
|
||||
getJdbcTemplate().execute("shutdown");
|
||||
}
|
||||
|
||||
private void runDatabaseMigration(DataSource dataSource) {
|
||||
SpringLiquibase springLiquibase = new SpringLiquibase();
|
||||
springLiquibase.setDataSource(dataSource);
|
||||
springLiquibase.setChangeLog("classpath:liquibase/db-changelog.xml");
|
||||
springLiquibase.setResourceLoader(new DefaultResourceLoader());
|
||||
Map<String,String> parameters = new HashMap<>();
|
||||
parameters.put("defaultMusicFolder", Util.getDefaultMusicFolder());
|
||||
parameters.put("varcharLimit", "512");
|
||||
parameters.put("userTableQuote", "");
|
||||
springLiquibase.setChangeLogParameters(parameters);
|
||||
try {
|
||||
springLiquibase.afterPropertiesSet();
|
||||
} catch (LiquibaseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private DataSource createDataSource() {
|
||||
File libresonicHome = SettingsService.getLibresonicHome();
|
||||
DriverManagerDataSource ds = new DriverManagerDataSource();
|
||||
ds.setDriverClassName("org.hsqldb.jdbcDriver");
|
||||
ds.setUrl("jdbc:hsqldb:file:" + libresonicHome.getPath() + "/db/libresonic");
|
||||
ds.setUsername("sa");
|
||||
ds.setPassword("");
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
protected JdbcTemplate getJdbcTemplate() {
|
||||
return daoHelper.getJdbcTemplate();
|
||||
}
|
||||
|
||||
+8
-2
@@ -41,7 +41,13 @@ public class SettingsServiceTestCase extends TestCase {
|
||||
String libresonicHome = TestCaseUtils.libresonicHomePathForTest();
|
||||
System.setProperty("libresonic.home", libresonicHome);
|
||||
new File(libresonicHome, "libresonic.properties").delete();
|
||||
settingsService = new SettingsService();
|
||||
settingsService = newSettingsService();
|
||||
}
|
||||
|
||||
private SettingsService newSettingsService() {
|
||||
SettingsService settingsService = new SettingsService();
|
||||
settingsService.setConfigurationService(new ApacheCommonsConfigurationService());
|
||||
return settingsService;
|
||||
}
|
||||
|
||||
public void testLibresonicHome() {
|
||||
@@ -97,7 +103,7 @@ public class SettingsServiceTestCase extends TestCase {
|
||||
settingsService.save();
|
||||
verifySettings(settingsService);
|
||||
|
||||
verifySettings(new SettingsService());
|
||||
verifySettings(newSettingsService());
|
||||
}
|
||||
|
||||
private void verifySettings(SettingsService ss) {
|
||||
|
||||
+43
-3
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
|
||||
<!-- DAO's -->
|
||||
@@ -67,8 +67,45 @@
|
||||
<property name="daoHelper" ref="daoHelper"/>
|
||||
</bean>
|
||||
|
||||
<bean id="daoHelper" class="org.libresonic.player.dao.DaoHelperFactory" factory-method="create"/>
|
||||
<bean id="daoHelper" class="org.libresonic.player.dao.GenericDaoHelper">
|
||||
<constructor-arg name="jdbcTemplate" ref="jdbcTemplate" />
|
||||
<constructor-arg name="namedParameterJdbcTemplate" ref="namedJdbcTemplate" />
|
||||
</bean>
|
||||
|
||||
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
|
||||
<constructor-arg name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="namedJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate" >
|
||||
<constructor-arg name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="rollbackFile" class="java.io.File">
|
||||
<constructor-arg name="parent" value="#{T(org.libresonic.player.service.SettingsService).libresonicHome}" />
|
||||
<constructor-arg name="child" value="rollback.sql" />
|
||||
</bean>
|
||||
|
||||
<bean id="dataSource"
|
||||
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||
|
||||
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
|
||||
<property name="url" value="jdbc:hsqldb:file:#{systemProperties['libresonic.home']}/db/libresonic" />
|
||||
<property name="username" value="sa" />
|
||||
<property name="password" value="" />
|
||||
</bean>
|
||||
|
||||
<bean id="liquibase" class="org.libresonic.player.spring.SpringLiquibase">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="changeLog" value="classpath:liquibase/db-changelog.xml" />
|
||||
<property name="rollbackFile" ref="rollbackFile" />
|
||||
<property name="changeLogParameters">
|
||||
<map>
|
||||
<entry key="defaultMusicFolder" value="#{T(org.libresonic.player.util.Util).getDefaultMusicFolder()}" />
|
||||
<entry key="varcharLimit" value="${database.varchar.maxlength:512}" />
|
||||
<entry key="userTableQuote" value="" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- Services -->
|
||||
|
||||
@@ -87,12 +124,15 @@
|
||||
<property name="userCache" ref="userCache"/>
|
||||
</bean>
|
||||
|
||||
<bean id="configurationService" class="org.libresonic.player.service.ApacheCommonsConfigurationService" />
|
||||
|
||||
<bean id="settingsService" class="org.libresonic.player.service.SettingsService" init-method="init">
|
||||
<property name="internetRadioDao" ref="internetRadioDao"/>
|
||||
<property name="musicFolderDao" ref="musicFolderDao"/>
|
||||
<property name="userDao" ref="userDao"/>
|
||||
<property name="avatarDao" ref="avatarDao"/>
|
||||
<property name="versionService" ref="versionService"/>
|
||||
<property name="configurationService" ref="configurationService" />
|
||||
</bean>
|
||||
|
||||
<bean id="mediaScannerService" class="org.libresonic.player.service.MediaScannerService" init-method="initNoSchedule" depends-on="metaDataParserFactory">
|
||||
|
||||
Reference in New Issue
Block a user