From 7d494715703f9cc1b0dc91ebd3ed6feddde851db Mon Sep 17 00:00:00 2001
From: Paul-Christian Volkmer <paul-christian.volkmer@mni.thm.de>
Date: Tue, 12 Feb 2013 12:23:21 +0100
Subject: [PATCH] Modified test environment to match new spring configuration

---
 .../arsnova/controller/LoginController.java   |  6 +-
 .../arsnova/controller/WelcomeController.java |  2 +-
 .../WEB-INF/{ => spring}/arsnova-servlet.xml  |  3 +
 src/main/webapp/WEB-INF/web.xml               |  6 ++
 .../AbstractSpringContextTestBase.java        | 80 -------------------
 .../java/de/thm/arsnova/Selenium2Test.java    |  1 -
 src/test/java/de/thm/arsnova/WiringTest.java  | 35 --------
 .../controller/FeedbackControllerTest.java    |  4 +-
 .../controller/LoginControllerTest.java       |  2 +-
 .../QuestionByLecturerControllerTest.java     |  2 +-
 .../controller/SessionControllerTest.java     |  2 +-
 .../controller/StatisticsControllerTest.java  |  2 +-
 .../controller/WelcomeControllerTest.java     | 30 ++++++-
 .../arsnova/services/FeedbackServiceTest.java |  2 +-
 .../arsnova/services/QuestionServiceTest.java |  2 +-
 .../arsnova/services/SessionServiceTest.java  |  2 +-
 .../services/StatisticsServiceTest.java       |  2 +-
 17 files changed, 49 insertions(+), 134 deletions(-)
 rename src/main/webapp/WEB-INF/{ => spring}/arsnova-servlet.xml (98%)
 delete mode 100644 src/test/java/de/thm/arsnova/AbstractSpringContextTestBase.java
 delete mode 100644 src/test/java/de/thm/arsnova/WiringTest.java

diff --git a/src/main/java/de/thm/arsnova/controller/LoginController.java b/src/main/java/de/thm/arsnova/controller/LoginController.java
index dd025d368..5fe73f1e3 100644
--- a/src/main/java/de/thm/arsnova/controller/LoginController.java
+++ b/src/main/java/de/thm/arsnova/controller/LoginController.java
@@ -76,7 +76,7 @@ public class LoginController extends AbstractController {
 
 	public static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class);
 
-	@RequestMapping(method = RequestMethod.GET, value = "/doLogin")
+	@RequestMapping(value = "/doLogin", method = RequestMethod.GET)
 	public final View doLogin(
 			@RequestParam("type") final String type,
 			@RequestParam(value = "user", required = false) final String guestName,
@@ -127,13 +127,13 @@ public class LoginController extends AbstractController {
 		return null;
 	}
 
-	@RequestMapping(method = RequestMethod.GET, value = "/whoami")
+	@RequestMapping(value = "/whoami", method = RequestMethod.GET)
 	@ResponseBody
 	public final User whoami() {
 		return userService.getCurrentUser();
 	}
 
-	@RequestMapping(method = RequestMethod.GET, value = "/logout")
+	@RequestMapping(value = "/logout", method = RequestMethod.GET)
 	public final View doLogout(final HttpServletRequest request) {
 		Authentication auth = SecurityContextHolder.getContext().getAuthentication();
 		request.getSession().invalidate();
diff --git a/src/main/java/de/thm/arsnova/controller/WelcomeController.java b/src/main/java/de/thm/arsnova/controller/WelcomeController.java
index 55796f95c..588dad75e 100644
--- a/src/main/java/de/thm/arsnova/controller/WelcomeController.java
+++ b/src/main/java/de/thm/arsnova/controller/WelcomeController.java
@@ -27,7 +27,7 @@ import org.springframework.web.servlet.ModelAndView;
 
 @Controller
 public class WelcomeController extends AbstractController {
-	@RequestMapping(method = RequestMethod.GET, value = "/")
+	@RequestMapping(value = "/", method = RequestMethod.GET)
 	public final ModelAndView home(final HttpServletRequest request) {
 		String referer = request.getHeader("referer");
 		String target = "index.html";
diff --git a/src/main/webapp/WEB-INF/arsnova-servlet.xml b/src/main/webapp/WEB-INF/spring/arsnova-servlet.xml
similarity index 98%
rename from src/main/webapp/WEB-INF/arsnova-servlet.xml
rename to src/main/webapp/WEB-INF/spring/arsnova-servlet.xml
index e255a8190..0026ff247 100644
--- a/src/main/webapp/WEB-INF/arsnova-servlet.xml
+++ b/src/main/webapp/WEB-INF/spring/arsnova-servlet.xml
@@ -19,6 +19,7 @@
 	    <property name="favorParameter" value="true" />
 	    <property name="mediaTypes" >
 	        <value>
+	        	html=text/html
 	          	json=application/json
 	        </value>
 	    </property>
@@ -31,6 +32,7 @@
 	<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">
@@ -42,6 +44,7 @@
 			</list>
 		</property>
 	</bean>
+	<!-- -->
 
 	<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
 		<property name="viewResolvers">  
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index 5128d8dc1..ae5e104f8 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -16,6 +16,12 @@
 	<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>
 	</servlet>
 	<servlet-mapping>
diff --git a/src/test/java/de/thm/arsnova/AbstractSpringContextTestBase.java b/src/test/java/de/thm/arsnova/AbstractSpringContextTestBase.java
deleted file mode 100644
index 02fe1ace2..000000000
--- a/src/test/java/de/thm/arsnova/AbstractSpringContextTestBase.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2012 THM webMedia
- * 
- * This file is part of ARSnova.
- *
- * ARSnova is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * ARSnova is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package de.thm.arsnova;
-
-import static org.junit.Assert.assertNotNull;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.junit.runner.RunWith;
-import org.springframework.mock.web.MockHttpServletRequest;
-import org.springframework.mock.web.MockHttpServletResponse;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.springframework.web.servlet.HandlerAdapter;
-import org.springframework.web.servlet.HandlerExecutionChain;
-import org.springframework.web.servlet.HandlerInterceptor;
-import org.springframework.web.servlet.HandlerMapping;
-import org.springframework.web.servlet.ModelAndView;
-import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
-import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = {
-		"file:src/main/webapp/WEB-INF/arsnova-servlet.xml",
-		"file:src/main/webapp/WEB-INF/spring/spring-main.xml",
-		"file:src/test/resources/test-config.xml" })
-public class AbstractSpringContextTestBase extends
-		AbstractJUnit4SpringContextTests {
-
-	protected MockHttpServletRequest request;
-	protected MockHttpServletResponse response;
-
-	protected ModelAndView handle(HttpServletRequest request,
-			HttpServletResponse response) throws Exception {
-		final HandlerMapping handlerMapping = applicationContext
-				.getBean(RequestMappingHandlerMapping.class);
-		final HandlerExecutionChain handler = handlerMapping
-				.getHandler(request);
-		assertNotNull(
-				"No handler found for request, check you request mapping",
-				handler);
-
-		final Object controller = handler.getHandler();
-		// if you want to override any injected attributes do it here
-
-		final HandlerInterceptor[] interceptors = handlerMapping.getHandler(
-				request).getInterceptors();
-		for (HandlerInterceptor interceptor : interceptors) {
-			final boolean carryOn = interceptor.preHandle(request, response,
-					controller);
-			if (!carryOn) {
-				return null;
-			}
-		}
-		HandlerAdapter handlerAdapter = applicationContext
-				.getBean(RequestMappingHandlerAdapter.class);
-		;
-		final ModelAndView mav = handlerAdapter.handle(request, response,
-				controller);
-		return mav;
-	}
-}
diff --git a/src/test/java/de/thm/arsnova/Selenium2Test.java b/src/test/java/de/thm/arsnova/Selenium2Test.java
index 76a602a80..98a5211c1 100644
--- a/src/test/java/de/thm/arsnova/Selenium2Test.java
+++ b/src/test/java/de/thm/arsnova/Selenium2Test.java
@@ -7,7 +7,6 @@ import java.util.Properties;
 
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.openqa.selenium.By;
 import org.openqa.selenium.WebDriver;
diff --git a/src/test/java/de/thm/arsnova/WiringTest.java b/src/test/java/de/thm/arsnova/WiringTest.java
deleted file mode 100644
index 5f8590492..000000000
--- a/src/test/java/de/thm/arsnova/WiringTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2012 THM webMedia
- * 
- * This file is part of ARSnova.
- *
- * ARSnova is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * ARSnova is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package de.thm.arsnova;
-
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-/**
- * Unit test to verify Spring context wiring.
- * 
- */
-public class WiringTest extends AbstractSpringContextTestBase {
-
-	@Test
-	public void testWiring() throws Exception {
-		assertTrue(applicationContext.getBeanDefinitionCount() > 0);
-	}
-}
\ No newline at end of file
diff --git a/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java b/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java
index 18034a387..d0b8997bc 100644
--- a/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java
+++ b/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java
@@ -1,8 +1,8 @@
 package de.thm.arsnova.controller;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertEquals;
 
 import javax.inject.Inject;
 
@@ -27,7 +27,7 @@ import de.thm.arsnova.services.StubUserService;
 
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations = {
-		"file:src/main/webapp/WEB-INF/arsnova-servlet.xml",
+		"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"
 })
diff --git a/src/test/java/de/thm/arsnova/controller/LoginControllerTest.java b/src/test/java/de/thm/arsnova/controller/LoginControllerTest.java
index 73824157e..f10539f3e 100644
--- a/src/test/java/de/thm/arsnova/controller/LoginControllerTest.java
+++ b/src/test/java/de/thm/arsnova/controller/LoginControllerTest.java
@@ -46,7 +46,7 @@ import de.thm.arsnova.services.StubUserService;
 
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations = {
-		"file:src/main/webapp/WEB-INF/arsnova-servlet.xml",
+		"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" })
 public class LoginControllerTest {
diff --git a/src/test/java/de/thm/arsnova/controller/QuestionByLecturerControllerTest.java b/src/test/java/de/thm/arsnova/controller/QuestionByLecturerControllerTest.java
index c78854e3d..46a02e3de 100644
--- a/src/test/java/de/thm/arsnova/controller/QuestionByLecturerControllerTest.java
+++ b/src/test/java/de/thm/arsnova/controller/QuestionByLecturerControllerTest.java
@@ -26,7 +26,7 @@ import de.thm.arsnova.services.StubUserService;
 
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations = {
-		"file:src/main/webapp/WEB-INF/arsnova-servlet.xml",
+		"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" })
 public class QuestionByLecturerControllerTest {
diff --git a/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java b/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java
index ee422e592..75bb88a9b 100644
--- a/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java
+++ b/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java
@@ -27,7 +27,7 @@ import de.thm.arsnova.services.StubUserService;
 
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations = {
-		"file:src/main/webapp/WEB-INF/arsnova-servlet.xml",
+		"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"
 })
diff --git a/src/test/java/de/thm/arsnova/controller/StatisticsControllerTest.java b/src/test/java/de/thm/arsnova/controller/StatisticsControllerTest.java
index 0a342bd9d..2882e4b3c 100644
--- a/src/test/java/de/thm/arsnova/controller/StatisticsControllerTest.java
+++ b/src/test/java/de/thm/arsnova/controller/StatisticsControllerTest.java
@@ -18,7 +18,7 @@ import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAda
 
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations = {
-		"file:src/main/webapp/WEB-INF/arsnova-servlet.xml",
+		"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"
 })
diff --git a/src/test/java/de/thm/arsnova/controller/WelcomeControllerTest.java b/src/test/java/de/thm/arsnova/controller/WelcomeControllerTest.java
index 18717546b..35d3287b3 100644
--- a/src/test/java/de/thm/arsnova/controller/WelcomeControllerTest.java
+++ b/src/test/java/de/thm/arsnova/controller/WelcomeControllerTest.java
@@ -21,20 +21,42 @@ package de.thm.arsnova.controller;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
+import javax.inject.Inject;
+
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
 import org.springframework.mock.web.MockHttpServletRequest;
 import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.web.servlet.HandlerAdapter;
 import org.springframework.web.servlet.ModelAndView;
+import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@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" })
+public class WelcomeControllerTest {
 
-import de.thm.arsnova.AbstractSpringContextTestBase;
+	@Inject
+	private ApplicationContext applicationContext;
+	private MockHttpServletRequest request;
+	private MockHttpServletResponse response;
+	private HandlerAdapter handlerAdapter;
 
-public class WelcomeControllerTest extends AbstractSpringContextTestBase {
+	@Autowired
+	private WelcomeController welcomeController;
 
 	@Before
-	public void setUp() throws Exception {
+	public final void setUp() {
 		this.request = new MockHttpServletRequest();
 		this.response = new MockHttpServletResponse();
+		handlerAdapter = applicationContext.getBean(AnnotationMethodHandlerAdapter.class);
 	}
 
 	@Test
@@ -42,7 +64,7 @@ public class WelcomeControllerTest extends AbstractSpringContextTestBase {
 		request.setMethod("GET");
 		request.setRequestURI("/");
 
-		final ModelAndView mav = handle(request, response);
+		final ModelAndView mav = handlerAdapter.handle(request, response, welcomeController);
 		assertNotNull(mav);
 		assertEquals("redirect:/index.html", mav.getViewName());
 	}
diff --git a/src/test/java/de/thm/arsnova/services/FeedbackServiceTest.java b/src/test/java/de/thm/arsnova/services/FeedbackServiceTest.java
index 5cb9beec7..4f8fc000c 100644
--- a/src/test/java/de/thm/arsnova/services/FeedbackServiceTest.java
+++ b/src/test/java/de/thm/arsnova/services/FeedbackServiceTest.java
@@ -34,7 +34,7 @@ import de.thm.arsnova.exceptions.NotFoundException;
 
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations = {
-		"file:src/main/webapp/WEB-INF/arsnova-servlet.xml",
+		"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"
 })
diff --git a/src/test/java/de/thm/arsnova/services/QuestionServiceTest.java b/src/test/java/de/thm/arsnova/services/QuestionServiceTest.java
index ce8dddb35..731fb23ae 100644
--- a/src/test/java/de/thm/arsnova/services/QuestionServiceTest.java
+++ b/src/test/java/de/thm/arsnova/services/QuestionServiceTest.java
@@ -34,7 +34,7 @@ import de.thm.arsnova.exceptions.UnauthorizedException;
 
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations = {
-		"file:src/main/webapp/WEB-INF/arsnova-servlet.xml",
+		"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"
 })
diff --git a/src/test/java/de/thm/arsnova/services/SessionServiceTest.java b/src/test/java/de/thm/arsnova/services/SessionServiceTest.java
index 520265553..ef51a2c5e 100644
--- a/src/test/java/de/thm/arsnova/services/SessionServiceTest.java
+++ b/src/test/java/de/thm/arsnova/services/SessionServiceTest.java
@@ -36,7 +36,7 @@ import de.thm.arsnova.exceptions.UnauthorizedException;
 
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations = {
-		"file:src/main/webapp/WEB-INF/arsnova-servlet.xml",
+		"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" })
 public class SessionServiceTest {
diff --git a/src/test/java/de/thm/arsnova/services/StatisticsServiceTest.java b/src/test/java/de/thm/arsnova/services/StatisticsServiceTest.java
index 140e6c769..1d76572e8 100644
--- a/src/test/java/de/thm/arsnova/services/StatisticsServiceTest.java
+++ b/src/test/java/de/thm/arsnova/services/StatisticsServiceTest.java
@@ -16,7 +16,7 @@ import de.thm.arsnova.entities.Statistics;
 
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations = {
-		"file:src/main/webapp/WEB-INF/arsnova-servlet.xml",
+		"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"
 })
-- 
GitLab