Translated xml configuration to java configuration
Signed-off-by: Andrew DeMaria <lostonamountain@gmail.com>
This commit is contained in:
@@ -6,8 +6,6 @@ import org.airsonic.player.service.MediaScannerService;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -91,17 +89,6 @@ public class TestCaseUtils {
|
||||
return daoHelper.getJdbcTemplate().queryForObject("select count(1) from " + tableName,Integer.class);
|
||||
}
|
||||
|
||||
public static ApplicationContext loadSpringApplicationContext(String baseResources) {
|
||||
String applicationContextService = baseResources + "applicationContext-service.xml";
|
||||
String applicationContextCache = baseResources + "applicationContext-cache.xml";
|
||||
|
||||
String[] configLocations = new String[]{
|
||||
TestCaseUtils.class.getClass().getResource(applicationContextCache).toString(),
|
||||
TestCaseUtils.class.getClass().getResource(applicationContextService).toString()
|
||||
};
|
||||
return new ClassPathXmlApplicationContext(configLocations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans the music library * @param mediaScannerService
|
||||
*/
|
||||
|
||||
@@ -6,16 +6,12 @@ import org.junit.Rule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.rules.SpringClassRule;
|
||||
import org.springframework.test.context.junit4.rules.SpringMethodRule;
|
||||
|
||||
@ContextConfiguration(locations = {
|
||||
"/applicationContext-service.xml",
|
||||
"/applicationContext-cache.xml",
|
||||
"/applicationContext-testdb.xml",
|
||||
"/applicationContext-mockSonos.xml"})
|
||||
@SpringBootTest
|
||||
public class DaoTestCaseBean2 {
|
||||
@ClassRule
|
||||
public static final SpringClassRule classRule = new SpringClassRule() {
|
||||
|
||||
+2
-6
@@ -8,17 +8,13 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.rules.SpringClassRule;
|
||||
import org.springframework.test.context.junit4.rules.SpringMethodRule;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@ContextConfiguration(locations = {
|
||||
"/applicationContext-service.xml",
|
||||
"/applicationContext-cache.xml",
|
||||
"/applicationContext-testdb.xml",
|
||||
"/applicationContext-mockSonos.xml"})
|
||||
@SpringBootTest
|
||||
public class LegacyDatabaseStartupTestCase {
|
||||
|
||||
@ClassRule
|
||||
|
||||
+8
-13
@@ -20,15 +20,14 @@ import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.rules.SpringClassRule;
|
||||
import org.springframework.test.context.junit4.rules.SpringMethodRule;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -50,11 +49,7 @@ import static org.junit.Assert.assertNotNull;
|
||||
* At runtime, the subsonic_home dir is set to target/test-classes/org/airsonic/player/service/mediaScannerServiceTestCase.
|
||||
* An empty database is created on the fly.
|
||||
*/
|
||||
@ContextConfiguration(locations = {
|
||||
"/applicationContext-service.xml",
|
||||
"/applicationContext-cache.xml",
|
||||
"/applicationContext-testdb.xml",
|
||||
"/applicationContext-mockSonos.xml"})
|
||||
@SpringBootTest
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class MediaScannerServiceTestCase {
|
||||
|
||||
@@ -101,9 +96,6 @@ public class MediaScannerServiceTestCase {
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Autowired
|
||||
ResourceLoader resourceLoader;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the MediaScannerService by scanning the test media library into an empty database.
|
||||
@@ -161,12 +153,15 @@ public class MediaScannerServiceTestCase {
|
||||
|
||||
@Test
|
||||
public void testSpecialCharactersInFilename() throws Exception {
|
||||
Resource resource = resourceLoader.getResource("MEDIAS/piano.mp3");
|
||||
InputStream resource = MediaScannerServiceTestCase.class
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("MEDIAS/piano.mp3");
|
||||
assert resource != null;
|
||||
String directoryName = "Muff1nman\u2019s \uFF0FMusic";
|
||||
String fileName = "Muff1nman\u2019s\uFF0FPiano.mp3";
|
||||
File artistDir = temporaryFolder.newFolder(directoryName);
|
||||
File musicFile = artistDir.toPath().resolve(fileName).toFile();
|
||||
IOUtils.copy(resource.getInputStream(), new FileOutputStream(musicFile));
|
||||
IOUtils.copy(resource, new FileOutputStream(musicFile));
|
||||
|
||||
MusicFolder musicFolder = new MusicFolder(1, temporaryFolder.getRoot(), "Music", true, new Date());
|
||||
musicFolderDao.createMusicFolder(musicFolder);
|
||||
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package org.airsonic.player.service.metadata;
|
||||
|
||||
import org.airsonic.player.service.SettingsService;
|
||||
import org.airsonic.player.util.HomeRule;
|
||||
import org.junit.*;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.rules.SpringClassRule;
|
||||
import org.springframework.test.context.junit4.rules.SpringMethodRule;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@SpringBootTest
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class MetaDataFactoryTestCase {
|
||||
|
||||
@ClassRule
|
||||
public static final SpringClassRule classRule = new SpringClassRule() {
|
||||
HomeRule homeRule = new HomeRule();
|
||||
|
||||
@Override
|
||||
public Statement apply(Statement base, Description description) {
|
||||
Statement spring = super.apply(base, description);
|
||||
return homeRule.apply(spring, description);
|
||||
}
|
||||
};
|
||||
|
||||
@ClassRule
|
||||
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
private static File someMp3;
|
||||
private static File someFlv;
|
||||
private static File someJunk;
|
||||
|
||||
@BeforeClass
|
||||
public static void createTestFiles() throws IOException {
|
||||
someMp3 = temporaryFolder.newFile("some.mp3");
|
||||
someFlv = temporaryFolder.newFile("some.flv");
|
||||
someJunk = temporaryFolder.newFile("some.junk");
|
||||
}
|
||||
|
||||
@Rule
|
||||
public final SpringMethodRule springMethodRule = new SpringMethodRule();
|
||||
|
||||
@Autowired
|
||||
MetaDataParserFactory metaDataParserFactory;
|
||||
|
||||
@Autowired
|
||||
SettingsService settingsService;
|
||||
|
||||
@Test
|
||||
public void testorder() {
|
||||
MetaDataParser parser;
|
||||
|
||||
settingsService.setVideoFileTypes("mp3 flv");
|
||||
|
||||
parser = metaDataParserFactory.getParser(someMp3);
|
||||
assertThat(parser, instanceOf(JaudiotaggerParser.class));
|
||||
|
||||
parser = metaDataParserFactory.getParser(someFlv);
|
||||
assertThat(parser, instanceOf(FFmpegParser.class));
|
||||
|
||||
parser = metaDataParserFactory.getParser(someJunk);
|
||||
assertThat(parser, instanceOf(DefaultMetaDataParser.class));
|
||||
}
|
||||
|
||||
}
|
||||
+2
-7
@@ -13,9 +13,8 @@ import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.rules.SpringClassRule;
|
||||
import org.springframework.test.context.junit4.rules.SpringMethodRule;
|
||||
|
||||
@@ -23,12 +22,8 @@ import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Function;
|
||||
|
||||
@ContextConfiguration(locations = {
|
||||
"/applicationContext-service.xml",
|
||||
"/applicationContext-cache.xml",
|
||||
"/applicationContext-testdb.xml"})
|
||||
@SpringBootTest
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
|
||||
@Component
|
||||
/*
|
||||
* Abstract class for scanning MusicFolder.
|
||||
*/
|
||||
|
||||
+3
-7
@@ -13,8 +13,8 @@ import org.junit.Test;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.rules.SpringClassRule;
|
||||
import org.springframework.test.context.junit4.rules.SpringMethodRule;
|
||||
|
||||
@@ -30,12 +30,8 @@ import static org.junit.Assert.assertEquals;
|
||||
* These cases have the purpose of observing the current situation
|
||||
* and observing the impact of upgrading Lucene.
|
||||
*/
|
||||
@ContextConfiguration(
|
||||
locations = {
|
||||
"/applicationContext-service.xml",
|
||||
"/applicationContext-cache.xml",
|
||||
"/applicationContext-testdb.xml",
|
||||
"/applicationContext-mockSonos.xml" })
|
||||
|
||||
@SpringBootTest
|
||||
@DirtiesContext(
|
||||
classMode = DirtiesContext.ClassMode.AFTER_CLASS)
|
||||
public class QueryFactoryTestCase {
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:jaxws="http://cxf.apache.org/jaxws"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
|
||||
|
||||
<bean id="sonosHelper" class="org.mockito.Mockito" factory-method="mock">
|
||||
<constructor-arg value="org.airsonic.player.service.sonos.SonosHelper" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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.xsd">
|
||||
|
||||
<bean id="dataSource"
|
||||
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||
|
||||
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
|
||||
<property name="url"
|
||||
value="#{T(org.airsonic.player.service.SettingsService).defaultJDBCUrl}" />
|
||||
<property name="username" value="sa" />
|
||||
<property name="password" value="" />
|
||||
</bean>
|
||||
</beans>
|
||||
Reference in New Issue
Block a user