Translated xml configuration to java configuration

Signed-off-by: Andrew DeMaria <lostonamountain@gmail.com>
master
Andrew DeMaria 5 years ago
parent bdcfc78b85
commit fa1a700ebd
No known key found for this signature in database
GPG Key ID: 0A3F5E91F8364EDF
  1. 6
      airsonic-main/pom.xml
  2. 14
      airsonic-main/src/main/java/org/airsonic/player/Application.java
  3. 1
      airsonic-main/src/main/java/org/airsonic/player/controller/ReloadFrame.java
  4. 2
      airsonic-main/src/main/java/org/airsonic/player/service/metadata/DefaultMetaDataParser.java
  5. 2
      airsonic-main/src/main/java/org/airsonic/player/service/metadata/FFmpegParser.java
  6. 2
      airsonic-main/src/main/java/org/airsonic/player/service/metadata/JaudiotaggerParser.java
  7. 7
      airsonic-main/src/main/java/org/airsonic/player/service/metadata/MetaDataParserFactory.java
  8. 2
      airsonic-main/src/main/java/org/airsonic/player/service/sonos/SonosFaultInterceptor.java
  9. 105
      airsonic-main/src/main/java/org/airsonic/player/spring/DatabaseConfiguration.java
  10. 33
      airsonic-main/src/main/java/org/airsonic/player/spring/EhcacheConfiguration.java
  11. 2
      airsonic-main/src/main/java/org/airsonic/player/spring/LoggingExceptionResolver.java
  12. 34
      airsonic-main/src/main/java/org/airsonic/player/spring/ServletConfiguration.java
  13. 26
      airsonic-main/src/main/java/org/airsonic/player/spring/SonosConfiguration.java
  14. 5
      airsonic-main/src/main/java/org/airsonic/player/theme/CustomThemeResolver.java
  15. 8
      airsonic-main/src/main/java/org/airsonic/player/theme/CustomThemeSource.java
  16. 7
      airsonic-main/src/main/resources/application.properties
  17. 17
      airsonic-main/src/main/resources/applicationContext-cache.xml
  18. 14
      airsonic-main/src/main/resources/applicationContext-db-embed.xml
  19. 12
      airsonic-main/src/main/resources/applicationContext-db-jndi.xml
  20. 22
      airsonic-main/src/main/resources/applicationContext-db-legacy.xml
  21. 41
      airsonic-main/src/main/resources/applicationContext-db.xml
  22. 34
      airsonic-main/src/main/resources/applicationContext-service.xml
  23. 30
      airsonic-main/src/main/resources/applicationContext-sonos.xml
  24. 52
      airsonic-main/src/main/resources/servlet.xml
  25. 13
      airsonic-main/src/test/java/org/airsonic/player/TestCaseUtils.java
  26. 8
      airsonic-main/src/test/java/org/airsonic/player/dao/DaoTestCaseBean2.java
  27. 8
      airsonic-main/src/test/java/org/airsonic/player/service/LegacyDatabaseStartupTestCase.java
  28. 21
      airsonic-main/src/test/java/org/airsonic/player/service/MediaScannerServiceTestCase.java
  29. 75
      airsonic-main/src/test/java/org/airsonic/player/service/metadata/MetaDataFactoryTestCase.java
  30. 9
      airsonic-main/src/test/java/org/airsonic/player/service/search/AbstractAirsonicHomeTest.java
  31. 10
      airsonic-main/src/test/java/org/airsonic/player/service/search/QueryFactoryTestCase.java
  32. 11
      airsonic-main/src/test/resources/applicationContext-mockSonos.xml
  33. 15
      airsonic-main/src/test/resources/applicationContext-testdb.xml

@ -149,7 +149,6 @@
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId> <artifactId>commons-dbcp2</artifactId>
<version>2.5.0</version> <version>2.5.0</version>
<scope>runtime</scope>
<!-- this wants to pull in commons-logging v1.2 which conflicts with other dependencies --> <!-- this wants to pull in commons-logging v1.2 which conflicts with other dependencies -->
<exclusions> <exclusions>
<exclusion> <exclusion>
@ -568,6 +567,11 @@
<version>2.1.2</version> <version>2.1.2</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -1,6 +1,5 @@
package org.airsonic.player; package org.airsonic.player;
import net.sf.ehcache.constructs.web.ShutdownListener;
import org.airsonic.player.filter.*; import org.airsonic.player.filter.*;
import org.directwebremoting.servlet.DwrServlet; import org.directwebremoting.servlet.DwrServlet;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -19,12 +18,9 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
import javax.servlet.Filter; import javax.servlet.Filter;
import javax.servlet.ServletContextListener;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -35,11 +31,6 @@ import java.lang.reflect.Method;
DataSourceTransactionManagerAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class,
MultipartAutoConfiguration.class, // TODO: update to use spring boot builtin multipart support MultipartAutoConfiguration.class, // TODO: update to use spring boot builtin multipart support
LiquibaseAutoConfiguration.class}) LiquibaseAutoConfiguration.class})
@Configuration
@ImportResource({"classpath:/applicationContext-service.xml",
"classpath:/applicationContext-cache.xml",
"classpath:/applicationContext-sonos.xml",
"classpath:/servlet.xml"})
public class Application extends SpringBootServletInitializer implements EmbeddedServletContainerCustomizer { public class Application extends SpringBootServletInitializer implements EmbeddedServletContainerCustomizer {
private static final Logger LOG = LoggerFactory.getLogger(Application.class); private static final Logger LOG = LoggerFactory.getLogger(Application.class);
@ -61,11 +52,6 @@ public class Application extends SpringBootServletInitializer implements Embedde
return new ServletRegistrationBean(new org.apache.cxf.transport.servlet.CXFServlet(), "/ws/*"); return new ServletRegistrationBean(new org.apache.cxf.transport.servlet.CXFServlet(), "/ws/*");
} }
@Bean
public ServletContextListener ehCacheShutdownListener() {
return new ShutdownListener();
}
@Bean @Bean
public FilterRegistrationBean bootstrapVerificationFilterRegistration() { public FilterRegistrationBean bootstrapVerificationFilterRegistration() {
FilterRegistrationBean registration = new FilterRegistrationBean(); FilterRegistrationBean registration = new FilterRegistrationBean();

@ -20,7 +20,6 @@
package org.airsonic.player.controller; package org.airsonic.player.controller;
/** /**
* Used in servlet.xml to specify frame reloading.
* *
* @author Sindre Mehus * @author Sindre Mehus
*/ */

@ -22,6 +22,7 @@ package org.airsonic.player.service.metadata;
import org.airsonic.player.domain.MediaFile; import org.airsonic.player.domain.MediaFile;
import org.airsonic.player.service.SettingsService; import org.airsonic.player.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.File; import java.io.File;
@ -32,6 +33,7 @@ import java.io.File;
* @author Sindre Mehus * @author Sindre Mehus
*/ */
@Service @Service
@Order(200)
public class DefaultMetaDataParser extends MetaDataParser { public class DefaultMetaDataParser extends MetaDataParser {
@Autowired @Autowired

@ -28,6 +28,7 @@ import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.File; import java.io.File;
@ -43,6 +44,7 @@ import java.util.List;
* @author Sindre Mehus * @author Sindre Mehus
*/ */
@Service("ffmpegParser") @Service("ffmpegParser")
@Order(100)
public class FFmpegParser extends MetaDataParser { public class FFmpegParser extends MetaDataParser {
private static final Logger LOG = LoggerFactory.getLogger(FFmpegParser.class); private static final Logger LOG = LoggerFactory.getLogger(FFmpegParser.class);

@ -36,6 +36,7 @@ import org.jaudiotagger.tag.reference.GenreTypes;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
@ -53,6 +54,7 @@ import java.util.regex.Pattern;
* @author Sindre Mehus * @author Sindre Mehus
*/ */
@Service @Service
@Order(0)
public class JaudiotaggerParser extends MetaDataParser { public class JaudiotaggerParser extends MetaDataParser {
private static final Logger LOG = LoggerFactory.getLogger(JaudiotaggerParser.class); private static final Logger LOG = LoggerFactory.getLogger(JaudiotaggerParser.class);

@ -19,6 +19,9 @@
*/ */
package org.airsonic.player.service.metadata; package org.airsonic.player.service.metadata;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
@ -27,11 +30,13 @@ import java.util.List;
* *
* @author Sindre Mehus * @author Sindre Mehus
*/ */
@Component
public class MetaDataParserFactory { public class MetaDataParserFactory {
private List<MetaDataParser> parsers; private List<MetaDataParser> parsers;
public void setParsers(List<MetaDataParser> parsers) { @Autowired
public MetaDataParserFactory(List<MetaDataParser> parsers) {
this.parsers = parsers; this.parsers = parsers;
} }

@ -26,6 +26,7 @@ import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.phase.Phase; import org.apache.cxf.phase.Phase;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
@ -37,6 +38,7 @@ import javax.xml.namespace.QName;
* @author Sindre Mehus * @author Sindre Mehus
* @version $Id$ * @version $Id$
*/ */
@Component
public class SonosFaultInterceptor extends AbstractSoapInterceptor { public class SonosFaultInterceptor extends AbstractSoapInterceptor {
private static final Logger LOG = LoggerFactory.getLogger(SonosFaultInterceptor.class); private static final Logger LOG = LoggerFactory.getLogger(SonosFaultInterceptor.class);

@ -0,0 +1,105 @@
package org.airsonic.player.spring;
import org.airsonic.player.dao.DaoHelper;
import org.airsonic.player.dao.GenericDaoHelper;
import org.airsonic.player.dao.LegacyHsqlDaoHelper;
import org.airsonic.player.service.SettingsService;
import org.airsonic.player.util.Util;
import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
@Configuration
@EnableTransactionManagement
public class DatabaseConfiguration {
@Bean
public DataSourceTransactionManager transactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean
@Profile("legacy")
public DaoHelper legacyDaoHelper(DataSource dataSource) {
return new LegacyHsqlDaoHelper(dataSource);
}
@Bean
@ConditionalOnMissingBean
public DaoHelper daoHelper(DataSource dataSource) {
return new GenericDaoHelper(dataSource);
}
@Bean
@Profile("legacy")
public DataSource legacyDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
dataSource.setUrl(SettingsService.getDefaultJDBCUrl());
dataSource.setUsername("sa");
dataSource.setPassword("");
return dataSource;
}
@Bean
@Profile("embed")
public DataSource embedDataSource(@Value("${DatabaseConfigEmbedDriver}") String driver,
@Value("${DatabaseConfigEmbedUrl}") String url,
@Value("${DatabaseConfigEmbedUsername}") String username,
@Value("${DatabaseConfigEmbedPassword}") String password) {
BasicDataSource basicDataSource = new BasicDataSource();
basicDataSource.setDriverClassName(driver);
basicDataSource.setUrl(url);
basicDataSource.setUsername(username);
basicDataSource.setPassword(password);
return basicDataSource;
}
@Bean
@Profile("jndi")
public DataSource jndiDataSource(@Value("${DatabaseConfigJNDIName}") String jndiName) {
JndiDataSourceLookup jndiLookup = new JndiDataSourceLookup();
return jndiLookup.getDataSource(jndiName);
}
@Bean
public File rollbackFile() {
return new File(SettingsService.getAirsonicHome(), "rollback.sql");
}
@Bean
public String userTableQuote(@Value("${DatabaseUsertableQuote:}") String value) {
return value;
}
@Bean
public SpringLiquibase liquibase(DataSource dataSource,
@Value("${DatabaseMysqlMaxlength:512}")
String mysqlVarcharLimit,
String userTableQuote) {
SpringLiquibase springLiquibase = new SpringLiquibase();
springLiquibase.setDataSource(dataSource);
springLiquibase.setChangeLog("classpath:liquibase/db-changelog.xml");
springLiquibase.setRollbackFile(rollbackFile());
Map<String, String> parameters = new HashMap<>();
parameters.put("defaultMusicFolder", Util.getDefaultMusicFolder());
parameters.put("mysqlVarcharLimit", mysqlVarcharLimit);
parameters.put("userTableQuote", userTableQuote);
springLiquibase.setChangeLogParameters(parameters);
return springLiquibase;
}
}

@ -0,0 +1,33 @@
package org.airsonic.player.spring;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.constructs.web.ShutdownListener;
import org.airsonic.player.cache.CacheFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletContextListener;
@Configuration
public class EhcacheConfiguration {
@Bean
public ServletContextListener ehCacheShutdownListener() {
return new ShutdownListener();
}
@Bean
public Ehcache userCache(CacheFactory cacheFactory) {
return cacheFactory.getCache("userCache");
}
@Bean
public Ehcache mediaFileMemoryCache(CacheFactory cacheFactory) {
return cacheFactory.getCache("mediaFileMemoryCache");
}
@Bean
public CacheFactory cacheFactory() {
return new CacheFactory();
}
}

@ -4,12 +4,14 @@ import org.airsonic.player.util.Util;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver; import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@Component
public class LoggingExceptionResolver implements HandlerExceptionResolver, Ordered { public class LoggingExceptionResolver implements HandlerExceptionResolver, Ordered {
private static final Logger LOG = LoggerFactory.getLogger(LoggingExceptionResolver.class); private static final Logger LOG = LoggerFactory.getLogger(LoggingExceptionResolver.class);

@ -0,0 +1,34 @@
package org.airsonic.player.spring;
import org.airsonic.player.controller.PodcastController;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
import java.util.Properties;
@Configuration
public class ServletConfiguration {
@Bean
public SimpleUrlHandlerMapping podcastUrlMapping(PodcastController podcastController) {
SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
handlerMapping.setAlwaysUseFullPath(true);
Properties properties = new Properties();
properties.put("/podcast/**", podcastController);
handlerMapping.setMappings(properties);
return handlerMapping;
}
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setViewClass(JstlView.class);
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
return resolver;
}
}

@ -0,0 +1,26 @@
package org.airsonic.player.spring;
import org.airsonic.player.service.SonosService;
import org.airsonic.player.service.sonos.SonosFaultInterceptor;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import javax.xml.ws.Endpoint;
import java.util.Collections;
@Configuration
@ImportResource({"classpath:META-INF/cxf/cxf.xml", "classpath:META-INF/cxf/cxf-servlet.xml"})
public class SonosConfiguration {
@Bean
public Endpoint sonosEndpoint(SonosService sonosService, SonosFaultInterceptor sonosFaultInterceptor) {
EndpointImpl endpoint = new EndpointImpl(sonosService);
endpoint.publish("/Sonos");
endpoint.setOutFaultInterceptors(Collections.singletonList(sonosFaultInterceptor));
return endpoint;
}
}

@ -23,6 +23,8 @@ import org.airsonic.player.domain.Theme;
import org.airsonic.player.domain.UserSettings; import org.airsonic.player.domain.UserSettings;
import org.airsonic.player.service.SecurityService; import org.airsonic.player.service.SecurityService;
import org.airsonic.player.service.SettingsService; import org.airsonic.player.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ThemeResolver; import org.springframework.web.servlet.ThemeResolver;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -36,6 +38,7 @@ import java.util.Set;
* *
* @author Sindre Mehus * @author Sindre Mehus
*/ */
@Component("themeResolver")
public class CustomThemeResolver implements ThemeResolver { public class CustomThemeResolver implements ThemeResolver {
private SecurityService securityService; private SecurityService securityService;
@ -113,10 +116,12 @@ public class CustomThemeResolver implements ThemeResolver {
throw new UnsupportedOperationException("Cannot change theme - use a different theme resolution strategy"); throw new UnsupportedOperationException("Cannot change theme - use a different theme resolution strategy");
} }
@Autowired
public void setSecurityService(SecurityService securityService) { public void setSecurityService(SecurityService securityService) {
this.securityService = securityService; this.securityService = securityService;
} }
@Autowired
public void setSettingsService(SettingsService settingsService) { public void setSettingsService(SettingsService settingsService) {
this.settingsService = settingsService; this.settingsService = settingsService;
} }

@ -21,9 +21,13 @@ package org.airsonic.player.theme;
import org.airsonic.player.domain.Theme; import org.airsonic.player.domain.Theme;
import org.airsonic.player.service.SettingsService; import org.airsonic.player.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.support.ResourceBundleMessageSource; import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.stereotype.Component;
import org.springframework.ui.context.support.ResourceBundleThemeSource; import org.springframework.ui.context.support.ResourceBundleThemeSource;
import org.springframework.ui.context.support.UiApplicationContextUtils;
/** /**
* Theme source implementation which uses two resource bundles: the * Theme source implementation which uses two resource bundles: the
@ -31,6 +35,7 @@ import org.springframework.ui.context.support.ResourceBundleThemeSource;
* *
* @author Sindre Mehus * @author Sindre Mehus
*/ */
@Component(UiApplicationContextUtils.THEME_SOURCE_BEAN_NAME)
public class CustomThemeSource extends ResourceBundleThemeSource { public class CustomThemeSource extends ResourceBundleThemeSource {
private SettingsService settingsService; private SettingsService settingsService;
@ -51,12 +56,15 @@ public class CustomThemeSource extends ResourceBundleThemeSource {
return messageSource; return messageSource;
} }
@Autowired
@Value("org.airsonic.player.theme.")
@Override @Override
public void setBasenamePrefix(String basenamePrefix) { public void setBasenamePrefix(String basenamePrefix) {
this.basenamePrefix = basenamePrefix; this.basenamePrefix = basenamePrefix;
super.setBasenamePrefix(basenamePrefix); super.setBasenamePrefix(basenamePrefix);
} }
@Autowired
public void setSettingsService(SettingsService settingsService) { public void setSettingsService(SettingsService settingsService) {
this.settingsService = settingsService; this.settingsService = settingsService;
} }

@ -1,6 +1,7 @@
spring.mvc.view.prefix: /WEB-INF/jsp/ spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix: .jsp spring.mvc.view.suffix=.jsp
server.error.includeStacktrace: ALWAYS spring.messages.basename=org.airsonic.player.i18n.ResourceBundle
server.error.includeStacktrace=ALWAYS
logging.level.root=WARN logging.level.root=WARN
logging.level.org.airsonic=INFO logging.level.org.airsonic=INFO
logging.level.liquibase=INFO logging.level.liquibase=INFO

@ -1,17 +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="cacheFactory" class="org.airsonic.player.cache.CacheFactory"/>
<bean id="userCache" factory-bean="cacheFactory" factory-method="getCache">
<constructor-arg value="userCache"/>
</bean>
<bean id="mediaFileMemoryCache" factory-bean="cacheFactory" factory-method="getCache">
<constructor-arg value="mediaFileMemoryCache"/>
</bean>
</beans>

@ -1,14 +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"
profile="embed">
<bean id="dataSource"
class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="${DatabaseConfigEmbedDriver}" />
<property name="url" value="${DatabaseConfigEmbedUrl}" />
<property name="username" value="${DatabaseConfigEmbedUsername}" />
<property name="password" value="${DatabaseConfigEmbedPassword}" />
</bean>
</beans>

@ -1,12 +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:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd"
profile="jndi">
<jee:jndi-lookup id="dataSource"
jndi-name="${DatabaseConfigJNDIName}"
expected-type="javax.sql.DataSource" />
</beans>

@ -1,22 +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"
profile="legacy">
<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>
<!-- Overwrite the GenericDaoHelper bean defined in applicationContext-db.xml -->
<!-- This bean is specific to the legacy embedded HSQLDB database -->
<bean id="daoHelper" class="org.airsonic.player.dao.LegacyHsqlDaoHelper">
<constructor-arg name="dataSource" ref="dataSource" />
</bean>
</beans>

@ -1,41 +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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<constructor-arg ref="dataSource"/>
</bean>
<bean id="daoHelper" class="org.airsonic.player.dao.GenericDaoHelper">
<constructor-arg name="dataSource" ref="dataSource" />
</bean>
<import resource="applicationContext-db-jndi.xml" />
<import resource="applicationContext-db-embed.xml" />
<import resource="applicationContext-db-legacy.xml" />
<tx:annotation-driven/>
<bean id="rollbackFile" class="java.io.File">
<constructor-arg type="java.io.File" index="0" value="#{T(org.airsonic.player.service.SettingsService).airsonicHome}" />
<constructor-arg type="java.lang.String" index="1" value="rollback.sql" />
</bean>
<bean id="userTableQuote" class="java.lang.String">
<constructor-arg value="${DatabaseUsertableQuote:}" />
</bean>
<bean id="liquibase" class="org.airsonic.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.airsonic.player.util.Util).getDefaultMusicFolder()}" />
<entry key="mysqlVarcharLimit" value="${DatabaseMysqlMaxlength:512}" />
<entry key="userTableQuote" value-ref="userTableQuote" />
</map>
</property>
</bean>
</beans>

@ -1,34 +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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder />
<import resource="applicationContext-db.xml" />
<!-- DAO's -->
<context:component-scan base-package="org.airsonic.player.dao,
org.airsonic.player.service,
org.airsonic.player.monitor,
org.airsonic.player.ajax,
org.airsonic.player.i18n." />
<!-- Services -->
<bean id="metaDataParserFactory" class="org.airsonic.player.service.metadata.MetaDataParserFactory">
<property name="parsers">
<list>
<ref bean="jaudiotaggerParser" />
<ref bean="ffmpegParser" />
<ref bean="defaultMetaDataParser" />
</list>
</property>
</bean>
<!-- AJAX services -->
</beans>

@ -1,30 +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">
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<jaxws:endpoint id="sonosEndpoint" implementor="#sonosService" address="/Sonos">
<jaxws:outFaultInterceptors>
<bean class="org.airsonic.player.service.sonos.SonosFaultInterceptor"/>
</jaxws:outFaultInterceptors>
</jaxws:endpoint>
<bean id="sonosHelper" class="org.airsonic.player.service.sonos.SonosHelper">
<property name="mediaFileService" ref="mediaFileService"/>
<property name="settingsService" ref="settingsService"/>
<property name="playlistService" ref="playlistService"/>
<property name="playerService" ref="playerService"/>
<property name="transcodingService" ref="transcodingService"/>
<property name="musicIndexService" ref="musicIndexService"/>
<property name="searchService" ref="searchServiceImpl"/>
<property name="ratingService" ref="ratingService"/>
<property name="lastFmService" ref="lastFmService"/>
<property name="podcastService" ref="podcastService"/>
<property name="mediaFileDao" ref="mediaFileDao"/>
</bean>
</beans>

@ -1,52 +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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="org.airsonic.player.controller,
org.airsonic.player.validator,
org.airsonic.player.security"/>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="alwaysUseFullPath" value="true"/>
<property name="mappings">
<props>
<prop key="/podcast/**">podcastController</prop>
</props>
</property>
</bean>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="org.airsonic.player.i18n.ResourceBundle"/>
</bean>
<bean id="themeSource" class="org.airsonic.player.theme.CustomThemeSource">
<property name="basenamePrefix" value="org.airsonic.player.theme."/>
<property name="settingsService" ref="settingsService"/>
</bean>
<bean id="themeResolver" class="org.airsonic.player.theme.CustomThemeResolver">
<property name="securityService" ref="securityService"/>
<property name="settingsService" ref="settingsService"/>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean class="org.airsonic.player.spring.LoggingExceptionResolver" />
</beans>

@ -6,8 +6,6 @@ import org.airsonic.player.service.MediaScannerService;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -91,17 +89,6 @@ public class TestCaseUtils {
return daoHelper.getJdbcTemplate().queryForObject("select count(1) from " + tableName,Integer.class); 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 * Scans the music library * @param mediaScannerService
*/ */

@ -6,16 +6,12 @@ import org.junit.Rule;
import org.junit.runner.Description; import org.junit.runner.Description;
import org.junit.runners.model.Statement; import org.junit.runners.model.Statement;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate; 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.SpringClassRule;
import org.springframework.test.context.junit4.rules.SpringMethodRule; import org.springframework.test.context.junit4.rules.SpringMethodRule;
@ContextConfiguration(locations = { @SpringBootTest
"/applicationContext-service.xml",
"/applicationContext-cache.xml",
"/applicationContext-testdb.xml",
"/applicationContext-mockSonos.xml"})
public class DaoTestCaseBean2 { public class DaoTestCaseBean2 {
@ClassRule @ClassRule
public static final SpringClassRule classRule = new SpringClassRule() { public static final SpringClassRule classRule = new SpringClassRule() {

@ -8,17 +8,13 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.Description; import org.junit.runner.Description;
import org.junit.runners.model.Statement; 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.SpringClassRule;
import org.springframework.test.context.junit4.rules.SpringMethodRule; import org.springframework.test.context.junit4.rules.SpringMethodRule;
import java.io.File; import java.io.File;
@ContextConfiguration(locations = { @SpringBootTest
"/applicationContext-service.xml",
"/applicationContext-cache.xml",
"/applicationContext-testdb.xml",
"/applicationContext-mockSonos.xml"})
public class LegacyDatabaseStartupTestCase { public class LegacyDatabaseStartupTestCase {
@ClassRule @ClassRule

@ -20,15 +20,14 @@ import org.junit.rules.TemporaryFolder;
import org.junit.runner.Description; import org.junit.runner.Description;
import org.junit.runners.model.Statement; import org.junit.runners.model.Statement;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.ResourceLoader;
import org.springframework.test.annotation.DirtiesContext; 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.SpringClassRule;
import org.springframework.test.context.junit4.rules.SpringMethodRule; import org.springframework.test.context.junit4.rules.SpringMethodRule;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; 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. * 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. * An empty database is created on the fly.
*/ */
@ContextConfiguration(locations = { @SpringBootTest
"/applicationContext-service.xml",
"/applicationContext-cache.xml",
"/applicationContext-testdb.xml",
"/applicationContext-mockSonos.xml"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class MediaScannerServiceTestCase { public class MediaScannerServiceTestCase {
@ -101,9 +96,6 @@ public class MediaScannerServiceTestCase {
@Rule @Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder(); public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Autowired
ResourceLoader resourceLoader;
/** /**
* Tests the MediaScannerService by scanning the test media library into an empty database. * Tests the MediaScannerService by scanning the test media library into an empty database.
@ -161,12 +153,15 @@ public class MediaScannerServiceTestCase {
@Test @Test
public void testSpecialCharactersInFilename() throws Exception { 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 directoryName = "Muff1nman\u2019s \uFF0FMusic";
String fileName = "Muff1nman\u2019s\uFF0FPiano.mp3"; String fileName = "Muff1nman\u2019s\uFF0FPiano.mp3";
File artistDir = temporaryFolder.newFolder(directoryName); File artistDir = temporaryFolder.newFolder(directoryName);
File musicFile = artistDir.toPath().resolve(fileName).toFile(); 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()); MusicFolder musicFolder = new MusicFolder(1, temporaryFolder.getRoot(), "Music", true, new Date());
musicFolderDao.createMusicFolder(musicFolder); musicFolderDao.createMusicFolder(musicFolder);

@ -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));
}
}

@ -13,9 +13,8 @@ import org.junit.rules.TemporaryFolder;
import org.junit.runner.Description; import org.junit.runner.Description;
import org.junit.runners.model.Statement; import org.junit.runners.model.Statement;
import org.springframework.beans.factory.annotation.Autowired; 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.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.rules.SpringClassRule; import org.springframework.test.context.junit4.rules.SpringClassRule;
import org.springframework.test.context.junit4.rules.SpringMethodRule; 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.concurrent.atomic.AtomicBoolean;
import java.util.function.Function; import java.util.function.Function;
@ContextConfiguration(locations = { @SpringBootTest
"/applicationContext-service.xml",
"/applicationContext-cache.xml",
"/applicationContext-testdb.xml"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@Component
/* /*
* Abstract class for scanning MusicFolder. * Abstract class for scanning MusicFolder.
*/ */

@ -13,8 +13,8 @@ import org.junit.Test;
import org.junit.runner.Description; import org.junit.runner.Description;
import org.junit.runners.model.Statement; import org.junit.runners.model.Statement;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext; 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.SpringClassRule;
import org.springframework.test.context.junit4.rules.SpringMethodRule; 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 * These cases have the purpose of observing the current situation
* and observing the impact of upgrading Lucene. * and observing the impact of upgrading Lucene.
*/ */
@ContextConfiguration(
locations = { @SpringBootTest
"/applicationContext-service.xml",
"/applicationContext-cache.xml",
"/applicationContext-testdb.xml",
"/applicationContext-mockSonos.xml" })
@DirtiesContext( @DirtiesContext(
classMode = DirtiesContext.ClassMode.AFTER_CLASS) classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class QueryFactoryTestCase { 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>
Loading…
Cancel
Save