Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
ARSnova Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Paul-Christian Volkmer
ARSnova Backend
Commits
2ecbfec8
Commit
2ecbfec8
authored
Apr 20, 2017
by
Daniel Gerhardt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate remaining Spring XML config to Java
parent
acf18781
Changes
25
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
420 additions
and
384 deletions
+420
-384
src/main/java/de/thm/arsnova/aop/UserSessionAspect.java
src/main/java/de/thm/arsnova/aop/UserSessionAspect.java
+2
-0
src/main/java/de/thm/arsnova/config/AppConfig.java
src/main/java/de/thm/arsnova/config/AppConfig.java
+257
-0
src/main/java/de/thm/arsnova/dao/CouchDBDao.java
src/main/java/de/thm/arsnova/dao/CouchDBDao.java
+4
-2
src/main/java/de/thm/arsnova/socket/ARSnovaSocketListener.java
...ain/java/de/thm/arsnova/socket/ARSnovaSocketListener.java
+2
-2
src/main/webapp/WEB-INF/arsnova-servlet.xml
src/main/webapp/WEB-INF/arsnova-servlet.xml
+5
-0
src/main/webapp/WEB-INF/spring/arsnova-servlet.xml
src/main/webapp/WEB-INF/spring/arsnova-servlet.xml
+0
-103
src/main/webapp/WEB-INF/spring/spring-main.xml
src/main/webapp/WEB-INF/spring/spring-main.xml
+0
-50
src/main/webapp/WEB-INF/web.xml
src/main/webapp/WEB-INF/web.xml
+6
-7
src/test/java/de/thm/arsnova/ImageUtilsTest.java
src/test/java/de/thm/arsnova/ImageUtilsTest.java
+4
-6
src/test/java/de/thm/arsnova/config/AppConfigTest.java
src/test/java/de/thm/arsnova/config/AppConfigTest.java
+3
-7
src/test/java/de/thm/arsnova/config/TestAppConfig.java
src/test/java/de/thm/arsnova/config/TestAppConfig.java
+81
-0
src/test/java/de/thm/arsnova/controller/AbstractControllerTest.java
...ava/de/thm/arsnova/controller/AbstractControllerTest.java
+14
-1
src/test/java/de/thm/arsnova/controller/CourseControllerTest.java
.../java/de/thm/arsnova/controller/CourseControllerTest.java
+1
-33
src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java
...ava/de/thm/arsnova/controller/FeedbackControllerTest.java
+1
-15
src/test/java/de/thm/arsnova/controller/LecturerQuestionControllerTest.java
...hm/arsnova/controller/LecturerQuestionControllerTest.java
+1
-31
src/test/java/de/thm/arsnova/controller/LoginControllerTest.java
...t/java/de/thm/arsnova/controller/LoginControllerTest.java
+3
-15
src/test/java/de/thm/arsnova/controller/SessionControllerTest.java
...java/de/thm/arsnova/controller/SessionControllerTest.java
+1
-31
src/test/java/de/thm/arsnova/controller/StatisticsControllerTest.java
...a/de/thm/arsnova/controller/StatisticsControllerTest.java
+7
-20
src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java
src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java
+4
-2
src/test/java/de/thm/arsnova/services/FeedbackServiceTest.java
...est/java/de/thm/arsnova/services/FeedbackServiceTest.java
+5
-6
src/test/java/de/thm/arsnova/services/QuestionServiceTest.java
...est/java/de/thm/arsnova/services/QuestionServiceTest.java
+5
-6
src/test/java/de/thm/arsnova/services/SessionServiceTest.java
...test/java/de/thm/arsnova/services/SessionServiceTest.java
+5
-6
src/test/java/de/thm/arsnova/services/UserServiceTest.java
src/test/java/de/thm/arsnova/services/UserServiceTest.java
+9
-2
src/test/resources/test-config.xml
src/test/resources/test-config.xml
+0
-28
src/test/resources/test-socketioconfig.xml
src/test/resources/test-socketioconfig.xml
+0
-11
No files found.
src/main/java/de/thm/arsnova/aop/UserSessionAspect.java
View file @
2ecbfec8
...
...
@@ -23,12 +23,14 @@ import org.aspectj.lang.JoinPoint;
import
org.aspectj.lang.annotation.AfterReturning
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
/**
* Assigns a session to the {@link de.thm.arsnova.services.UserSessionService} whenever a user joins a
* session.
*/
@Aspect
@Service
public
class
UserSessionAspect
{
@Autowired
...
...
src/main/java/de/thm/arsnova/config/
Extra
Config.java
→
src/main/java/de/thm/arsnova/config/
App
Config.java
View file @
2ecbfec8
...
...
@@ -17,12 +17,16 @@
*/
package
de.thm.arsnova.config
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
de.thm.arsnova.ImageUtils
;
import
de.thm.arsnova.connector.client.ConnectorClient
;
import
de.thm.arsnova.connector.client.ConnectorClientImpl
;
import
de.thm.arsnova.socket.ARSnovaSocket
;
import
de.thm.arsnova.socket.ARSnovaSocketIOServer
;
import
de.thm.arsnova.web.CacheControlInterceptorHandler
;
import
de.thm.arsnova.web.CorsFilter
;
import
de.thm.arsnova.web.DeprecatedApiInterceptorHandler
;
import
de.thm.arsnova.web.ResponseInterceptorHandler
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.config.PropertiesFactoryBean
;
...
...
@@ -30,24 +34,58 @@ import org.springframework.cache.CacheManager;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.cache.concurrent.ConcurrentMapCacheManager
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.EnableAspectJAutoProxy
;
import
org.springframework.context.annotation.Profile
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.context.support.PropertySourcesPlaceholderConfigurer
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.core.io.FileSystemResource
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.StringHttpMessageConverter
;
import
org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
org.springframework.mail.javamail.JavaMailSenderImpl
;
import
org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.ViewResolverRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
org.springframework.web.servlet.view.InternalResourceViewResolver
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
/**
* Loads property file and configures non-security related beans and components.
*
* expose-proxy for AspectJ is needed to access the proxy object via AopContext.currentProxy() in CouchDBDao. It might
* have a negative impact on performance but is needed for caching until a better solution is implemented (e.g. use of
* AspectJ's weaving).
*/
@EnableWebMvc
@ComponentScan
({
"de.thm.arsnova.aop"
,
"de.thm.arsnova.cache"
,
"de.thm.arsnova.controller"
,
"de.thm.arsnova.domain"
,
"de.thm.arsnova.dao"
,
"de.thm.arsnova.events"
,
"de.thm.arsnova.security"
,
"de.thm.arsnova.services"
,
"de.thm.arsnova.web"
})
@Configuration
@EnableAspectJAutoProxy
(
exposeProxy
=
true
)
@EnableCaching
public
class
ExtraConfig
extends
WebMvcConfigurerAdapter
{
@EnableWebMvc
@PropertySource
(
value
=
{
"classpath:arsnova.properties.example"
,
"file:/etc/arsnova/arsnova.properties"
},
ignoreResourceNotFound
=
true
)
public
class
AppConfig
extends
WebMvcConfigurerAdapter
{
@Autowired
private
Environment
env
;
...
...
@@ -62,18 +100,102 @@ public class ExtraConfig extends WebMvcConfigurerAdapter {
@Value
(
value
=
"${socketio.ssl.jks-file:}"
)
private
String
socketKeystore
;
@Value
(
value
=
"${socketio.ssl.jks-password:}"
)
private
String
socketKeystorePassword
;
@Value
(
value
=
"${security.cors.origins:}"
)
private
String
[]
corsOrigins
;
@Value
(
value
=
"${mail.host}"
)
private
String
mailHost
;
@Override
public
void
configureMessageConverters
(
List
<
HttpMessageConverter
<?>>
converters
)
{
converters
.
add
(
stringMessageConverter
());
converters
.
add
(
jsonMessageConverter
());
//converters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
}
@Override
public
void
configureContentNegotiation
(
ContentNegotiationConfigurer
configurer
)
{
configurer
.
mediaType
(
"json"
,
MediaType
.
APPLICATION_JSON_UTF8
);
configurer
.
mediaType
(
"xml"
,
MediaType
.
APPLICATION_XML
);
configurer
.
mediaType
(
"html"
,
MediaType
.
TEXT_HTML
);
configurer
.
defaultContentType
(
MediaType
.
APPLICATION_JSON_UTF8
);
configurer
.
favorParameter
(
true
);
configurer
.
favorPathExtension
(
false
);
}
@Override
public
void
configureViewResolvers
(
ViewResolverRegistry
registry
)
{
registry
.
viewResolver
(
new
InternalResourceViewResolver
());
}
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
registry
.
addInterceptor
(
cacheControlInterceptorHandler
());
registry
.
addInterceptor
(
deprecatedApiInterceptorHandler
());
registry
.
addInterceptor
(
responseInterceptorHandler
());
}
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
registry
.
addResourceHandler
(
"swagger.json"
).
addResourceLocations
(
"classpath:/"
);
registry
.
addResourceHandler
(
"/**"
).
addResourceLocations
(
"/"
);
}
@Bean
public
CacheControlInterceptorHandler
cacheControlInterceptorHandler
()
{
return
new
CacheControlInterceptorHandler
();
}
@Bean
public
DeprecatedApiInterceptorHandler
deprecatedApiInterceptorHandler
()
{
return
new
DeprecatedApiInterceptorHandler
();
}
@Bean
public
ResponseInterceptorHandler
responseInterceptorHandler
()
{
return
new
ResponseInterceptorHandler
();
}
private
static
int
testPortOffset
=
0
;
@Bean
public
StringHttpMessageConverter
stringMessageConverter
()
{
StringHttpMessageConverter
messageConverter
=
new
StringHttpMessageConverter
();
List
<
MediaType
>
mediaTypes
=
new
ArrayList
<>();
mediaTypes
.
add
(
MediaType
.
TEXT_PLAIN
);
messageConverter
.
setSupportedMediaTypes
(
mediaTypes
);
return
messageConverter
;
}
@Bean
public
MappingJackson2HttpMessageConverter
jsonMessageConverter
()
{
Jackson2ObjectMapperBuilder
builder
=
new
Jackson2ObjectMapperBuilder
();
builder
.
serializationInclusion
(
JsonInclude
.
Include
.
NON_NULL
);
builder
.
serializationInclusion
(
JsonInclude
.
Include
.
NON_EMPTY
);
builder
.
defaultViewInclusion
(
false
);
builder
.
indentOutput
(
true
).
simpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ssZ"
);
return
new
MappingJackson2HttpMessageConverter
(
builder
.
build
());
}
// @Bean
// public PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
// final PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
// configurer.setLocations(
// new ClassPathResource("arsnova.properties.example"),
// new FileSystemResource("/etc/arsnova/arsnova.properties")
// );
// configurer.setIgnoreResourceNotFound(true);
// configurer.setIgnoreUnresolvablePlaceholders(false);
//
// return configurer;
// }
@Bean
public
static
PropertySourcesPlaceholderConfigurer
propertySourcesPlaceholderConfigurer
()
{
final
PropertySourcesPlaceholderConfigurer
configurer
=
new
PropertySourcesPlaceholderConfigurer
();
configurer
.
setLocations
(
new
ClassPathResource
(
"arsnova.properties.example"
),
new
FileSystemResource
(
"/etc/arsnova/arsnova.properties"
)
);
configurer
.
setIgnoreResourceNotFound
(
true
);
//
configurer.setLocations(
//
new ClassPathResource("arsnova.properties.example"),
//
new FileSystemResource("/etc/arsnova/arsnova.properties")
//
);
//
configurer.setIgnoreResourceNotFound(true);
configurer
.
setIgnoreUnresolvablePlaceholders
(
false
);
return
configurer
;
}
...
...
@@ -115,24 +237,19 @@ public class ExtraConfig extends WebMvcConfigurerAdapter {
return
socketServer
;
}
@Profile
(
"test"
)
@Bean
(
name
=
"socketServer"
,
initMethod
=
"startServer"
,
destroyMethod
=
"stopServer"
)
public
ARSnovaSocket
socketTestServer
()
{
final
int
testSocketPort
=
1234
+
testPortOffset
++
%
10
;
final
ARSnovaSocketIOServer
socketServer
=
new
ARSnovaSocketIOServer
();
socketServer
.
setHostIp
(
socketAddress
);
socketServer
.
setPortNumber
(
socketPort
+
testSocketPort
);
socketServer
.
setUseSSL
(!
socketKeystore
.
isEmpty
());
socketServer
.
setKeystore
(
socketKeystore
);
socketServer
.
setStorepass
(
socketKeystorePassword
);
return
socketServer
;
}
@Bean
public
CacheManager
cacheManager
()
{
return
new
ConcurrentMapCacheManager
();
}
@Bean
public
JavaMailSenderImpl
mailSender
()
{
final
JavaMailSenderImpl
mailSender
=
new
JavaMailSenderImpl
();
mailSender
.
setHost
(
mailHost
);
return
mailSender
;
}
@Bean
public
ImageUtils
imageUtils
()
{
return
new
ImageUtils
();
...
...
src/main/java/de/thm/arsnova/dao/CouchDBDao.java
View file @
2ecbfec8
...
...
@@ -51,8 +51,9 @@ import org.springframework.cache.annotation.Cacheable;
import
org.springframework.cache.annotation.Caching
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.context.ApplicationEventPublisherAware
;
import
org.springframework.context.annotation.Profile
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.
Component
;
import
org.springframework.stereotype.
Service
;
import
org.springframework.transaction.annotation.Isolation
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -79,7 +80,8 @@ import java.util.concurrent.ConcurrentLinkedQueue;
* @see <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html/cache.html">Spring Framework's Cache Abstraction</a>
* @see <a href="https://github.com/thm-projects/arsnova-backend/wiki/Caching">Caching in ARSnova explained</a>
*/
@Component
(
"databaseDao"
)
@Profile
(
"!test"
)
@Service
(
"databaseDao"
)
public
class
CouchDBDao
implements
IDatabaseDao
,
ApplicationEventPublisherAware
{
private
static
final
int
BULK_PARTITION_SIZE
=
500
;
...
...
src/main/java/de/thm/arsnova/socket/ARSnovaSocketListener.java
View file @
2ecbfec8
...
...
@@ -21,13 +21,13 @@ import de.thm.arsnova.events.NovaEvent;
import
de.thm.arsnova.events.NovaEventVisitor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.stereotype.
Component
;
import
org.springframework.stereotype.
Service
;
/**
* An external Listener is required because otherwise the event methods are not called through a Spring proxy.
* This would result in Spring method annotations not working.
*/
@
Component
@
Service
public
class
ARSnovaSocketListener
implements
ApplicationListener
<
NovaEvent
>
{
@Autowired
...
...
src/main/webapp/WEB-INF/arsnova-servlet.xml
0 → 100644
View file @
2ecbfec8
<?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-4.3.xsd"
>
</beans>
src/main/webapp/WEB-INF/spring/arsnova-servlet.xml
deleted
100644 → 0
View file @
acf18781
<?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:aop=
"http://www.springframework.org/schema/aop"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:mvc=
"http://www.springframework.org/schema/mvc"
xmlns:p=
"http://www.springframework.org/schema/p"
xsi:schemaLocation=
"
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd"
>
<!-- ARSnova Servlet Context -->
<context:component-scan
base-package=
"de.thm.arsnova.aop,de.thm.arsnova.controller,de.thm.arsnova.web"
/>
<mvc:annotation-driven
content-negotiation-manager=
"mvcContentNegotiationManager"
/>
<mvc:interceptors>
<bean
class=
"de.thm.arsnova.web.CacheControlInterceptorHandler"
/>
<bean
class=
"de.thm.arsnova.web.DeprecatedApiInterceptorHandler"
/>
<bean
class=
"de.thm.arsnova.web.ResponseInterceptorHandler"
/>
</mvc:interceptors>
<bean
id=
"requestMappingHandlerMapping"
class=
"org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"
primary=
"true"
></bean>
<aop:aspectj-autoproxy
/>
<!-- Enables swgger ui-->
<mvc:resources
mapping=
"swagger.json"
location=
"classpath:/"
/>
<bean
id=
"propertyPlaceholderConfigurer"
class=
"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:ignoreUnresolvablePlaceholders=
"false"
p:ignoreResourceNotFound=
"true"
>
<property
name=
"locations"
>
<list>
<value>
classpath:arsnova.properties.example
</value>
<value>
file:///etc/arsnova/arsnova.properties
</value>
</list>
</property>
<property
name=
"fileEncoding"
value=
"UTF-8"
/>
</bean>
<bean
id=
"mvcContentNegotiationManager"
class=
"org.springframework.web.accept.ContentNegotiationManagerFactoryBean"
>
<property
name=
"favorPathExtension"
value=
"false"
/>
<property
name=
"favorParameter"
value=
"true"
/>
<property
name=
"defaultContentType"
value=
"application/json"
/>
<property
name=
"mediaTypes"
>
<value>
html=text/html
json=application/json
xml=application/xml
</value>
</property>
</bean>
<mvc:annotation-driven
/>
<mvc:resources
mapping=
"/**"
location=
"/"
/>
<!-- -->
<bean
class=
"org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"
/>
<bean
class=
"org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"
>
<property
name=
"messageConverters"
>
<list>
<bean
class=
"org.springframework.http.converter.StringHttpMessageConverter"
>
<property
name=
"supportedMediaTypes"
value=
"text/plain;charset=UTF-8"
/>
</bean>
<bean
class=
"org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"
/>
</list>
</property>
</bean>
<!-- -->
<bean
class=
"org.springframework.web.servlet.view.ContentNegotiatingViewResolver"
>
<property
name=
"viewResolvers"
>
<list>
<bean
class=
"org.springframework.web.servlet.view.UrlBasedViewResolver"
>
<property
name=
"viewClass"
value=
"org.springframework.web.servlet.view.JstlView"
/>
<property
name=
"prefix"
value=
"/WEB-INF/jsp/"
/>
<property
name=
"suffix"
value=
".jsp"
/>
</bean>
</list>
</property>
<property
name=
"defaultViews"
>
<list>
<bean
class=
"org.springframework.web.servlet.view.json.MappingJackson2JsonView"
>
<property
name=
"prefixJson"
value=
"false"
/>
</bean>
</list>
</property>
</bean>
</beans>
src/main/webapp/WEB-INF/spring/spring-main.xml
deleted
100644 → 0
View file @
acf18781
<?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:aop=
"http://www.springframework.org/schema/aop"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:task=
"http://www.springframework.org/schema/task"
xmlns:p=
"http://www.springframework.org/schema/p"
xsi:schemaLocation=
"
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.3.xsd"
>
<bean
id=
"propertyPlaceholderConfigurer"
class=
"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:ignoreUnresolvablePlaceholders=
"false"
p:ignoreResourceNotFound=
"true"
>
<property
name=
"locations"
>
<list>
<value>
classpath:arsnova.properties.example
</value>
<value>
file:///etc/arsnova/arsnova.properties
</value>
</list>
</property>
<property
name=
"fileEncoding"
value=
"UTF-8"
/>
</bean>
<context:component-scan
base-package=
"de.thm.arsnova.dao,de.thm.arsnova.cache,de.thm.arsnova.events,de.thm.arsnova.security,de.thm.arsnova.services,de.thm.arsnova.config,de.thm.arsnova.domain"
/>
<context:annotation-config
/>
<task:annotation-driven
/>
<!--
expose-proxy is needed to access the proxy object via AopContext.currentProxy() in CouchDBDao. It might have a
negative impact on performance but is needed for caching until a better solution is implemented (e.g. use of
AspectJ's weaving).
-->
<aop:aspectj-autoproxy
expose-proxy=
"true"
>
<aop:include
name=
"userSessionAspect"
/>
</aop:aspectj-autoproxy>
<bean
id=
"userSessionAspect"
class=
"de.thm.arsnova.aop.UserSessionAspect"
/>
<bean
id=
"mailSender"
class=
"org.springframework.mail.javamail.JavaMailSenderImpl"
>
<property
name=
"host"
value=
"${mail.host}"
/>
</bean>
<bean
id=
"databaseDao"
class=
"de.thm.arsnova.dao.CouchDBDao"
/>
<bean
id=
"socketListener"
class=
"de.thm.arsnova.socket.ARSnovaSocketListener"
/>
</beans>
src/main/webapp/WEB-INF/web.xml
View file @
2ecbfec8
...
...
@@ -3,10 +3,15 @@
xmlns=
"http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation=
"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id=
"WebApp_ID"
version=
"3.0"
>
<context-param>
<param-name>
contextClass
</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>
<context-param>
<param-name>
contextConfigLocation
</param-name>
<param-value>
/WEB-INF/spring/spring-main.xml
de.thm.arsnova.config.AppConfig
de.thm.arsnova.config.SecurityConfig
</param-value>
</context-param>
<context-param>
...
...
@@ -16,12 +21,6 @@
<servlet>
<servlet-name>
arsnova
</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>
contextConfigLocation
</param-name>
<param-value>
/WEB-INF/spring/arsnova-servlet.xml
</param-value>
</init-param>
<load-on-startup>
1
</load-on-startup>
<async-supported>
true
</async-supported>
</servlet>
...
...
src/test/java/de/thm/arsnova/ImageUtilsTest.java
View file @
2ecbfec8
...
...
@@ -17,6 +17,9 @@
*/
package
de.thm.arsnova
;
import
de.thm.arsnova.config.AppConfig
;
import
de.thm.arsnova.config.TestAppConfig
;
import
de.thm.arsnova.config.TestSecurityConfig
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.test.context.ActiveProfiles
;
...
...
@@ -30,12 +33,7 @@ import static org.junit.Assert.*;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@WebAppConfiguration
@ContextConfiguration
(
locations
=
{
"file:src/main/webapp/WEB-INF/spring/arsnova-servlet.xml"
,
"file:src/main/webapp/WEB-INF/spring/spring-main.xml"
,
"file:src/test/resources/test-config.xml"
,
"file:src/test/resources/test-socketioconfig.xml"
})
@ContextConfiguration
(
classes
=
{
AppConfig
.
class
,
TestAppConfig
.
class
,
TestSecurityConfig
.
class
})
@ActiveProfiles
(
"test"
)
public
class
ImageUtilsTest
{
...
...
src/test/java/de/thm/arsnova/config/
Extra
ConfigTest.java
→
src/test/java/de/thm/arsnova/config/
App
ConfigTest.java
View file @
2ecbfec8
...
...
@@ -23,6 +23,7 @@ import org.junit.runner.RunWith;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
...
...
@@ -30,14 +31,9 @@ import static org.junit.Assert.assertNull;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@WebAppConfiguration
@ContextConfiguration
(
locations
=
{
"file:src/main/webapp/WEB-INF/spring/arsnova-servlet.xml"
,
"file:src/main/webapp/WEB-INF/spring/spring-main.xml"
,
"file:src/test/resources/test-config.xml"
,
"file:src/test/resources/test-socketioconfig.xml"
})
@ContextConfiguration
(
classes
=
{
AppConfig
.
class
,
TestAppConfig
.
class
,
TestSecurityConfig
.
class
})
@ActiveProfiles
(
"test"
)
public
class
ExtraConfigTest
{
public
class
AppConfigTest
extends
AbstractJUnit4SpringContextTests
{
@Autowired
(
required
=
false
)
private
ConnectorClient
connectorClient
;
...
...
src/test/java/de/thm/arsnova/config/TestAppConfig.java
0 → 100644
View file @
2ecbfec8
package
de.thm.arsnova.config
;
import
de.thm.arsnova.dao.IDatabaseDao
;
import
de.thm.arsnova.dao.StubDatabaseDao
;
import
de.thm.arsnova.services.StubUserService
;
import
de.thm.arsnova.socket.ARSnovaSocket
;
import
de.thm.arsnova.socket.ARSnovaSocketIOServer
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.config.CustomScopeConfigurer
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.EnableAspectJAutoProxy
;
import
org.springframework.context.annotation.Profile
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.context.support.SimpleThreadScope
;
import
org.springframework.mock.web.MockServletContext
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.support.AnnotationConfigContextLoader
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
@ComponentScan
({
"de.thm.arsnova.aop"
,
"de.thm.arsnova.cache"
,
"de.thm.arsnova.controller"
,
"de.thm.arsnova.domain"
,
"de.thm.arsnova.dao"
,
"de.thm.arsnova.events"
,
"de.thm.arsnova.security"
,
"de.thm.arsnova.services"
,
"de.thm.arsnova.web"
})
@Configuration
@ContextConfiguration
(
loader
=
AnnotationConfigContextLoader
.
class
)
@EnableAspectJAutoProxy
(
exposeProxy
=
true
)
@EnableCaching
@EnableWebMvc
@PropertySource
(
value
=
{
"classpath:arsnova.properties.example"
,
"file:/etc/arsnova/arsnova.properties"
},
ignoreResourceNotFound
=
true
)
@Profile
(
"test"
)
public
class
TestAppConfig
{
private
static
int
testPortOffset
=
0
;
@Value
(
"${socketio.bind-address}"
)
private
String
socketAddress
;
@Value
(
"${socketio.port}"
)
private
int
socketPort
;
@Bean
public
MockServletContext
servletContext
()
{
return
new
MockServletContext
();
}
@Bean
public
CustomScopeConfigurer
customScopeConfigurer
()
{
final
CustomScopeConfigurer
configurer
=
new
CustomScopeConfigurer
();
configurer
.
addScope
(
"session"
,
new
SimpleThreadScope
());
return
configurer
;
}
@Bean
public
IDatabaseDao
databaseDao
()
{
return
new
StubDatabaseDao
();
}
@Bean
(
name
=
"socketServer"
,
initMethod
=
"startServer"
,
destroyMethod
=
"stopServer"
)
public
ARSnovaSocket
socketTestServer
()
{
final
int
testSocketPort
=
1234
+
testPortOffset
++
%
10
;
final
ARSnovaSocketIOServer
socketServer
=
new
ARSnovaSocketIOServer
();
socketServer
.
setHostIp
(
socketAddress
);
socketServer
.
setPortNumber
(
socketPort
+
testSocketPort
);
return
socketServer
;
}
@Bean
public
StubUserService
stubUserService
()
{
return
new
StubUserService
();
}
}
src/test/java/de/thm/arsnova/controller/AbstractControllerTest.java
View file @
2ecbfec8
...
...
@@ -17,17 +17,30 @@
*/
package
de.thm.arsnova.controller
;
import
de.thm.arsnova.config.AppConfig
;
import
de.thm.arsnova.config.TestAppConfig
;
import
de.thm.arsnova.config.TestSecurityConfig
;
import
de.thm.arsnova.services.StubUserService
;
import
org.junit.After
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
java.util.ArrayList
;
import
java.util.List
;
public
abstract
class
AbstractControllerTest
{
@RunWith
(
SpringJUnit4ClassRunner
.
class
)