Skip to content
Snippets Groups Projects
Commit 7d494715 authored by Paul-Christian Volkmer's avatar Paul-Christian Volkmer
Browse files

Modified test environment to match new spring configuration

parent a002d534
No related merge requests found
Showing
with 49 additions and 134 deletions
...@@ -76,7 +76,7 @@ public class LoginController extends AbstractController { ...@@ -76,7 +76,7 @@ public class LoginController extends AbstractController {
public static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class); 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( public final View doLogin(
@RequestParam("type") final String type, @RequestParam("type") final String type,
@RequestParam(value = "user", required = false) final String guestName, @RequestParam(value = "user", required = false) final String guestName,
...@@ -127,13 +127,13 @@ public class LoginController extends AbstractController { ...@@ -127,13 +127,13 @@ public class LoginController extends AbstractController {
return null; return null;
} }
@RequestMapping(method = RequestMethod.GET, value = "/whoami") @RequestMapping(value = "/whoami", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public final User whoami() { public final User whoami() {
return userService.getCurrentUser(); return userService.getCurrentUser();
} }
@RequestMapping(method = RequestMethod.GET, value = "/logout") @RequestMapping(value = "/logout", method = RequestMethod.GET)
public final View doLogout(final HttpServletRequest request) { public final View doLogout(final HttpServletRequest request) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication(); Authentication auth = SecurityContextHolder.getContext().getAuthentication();
request.getSession().invalidate(); request.getSession().invalidate();
......
...@@ -27,7 +27,7 @@ import org.springframework.web.servlet.ModelAndView; ...@@ -27,7 +27,7 @@ import org.springframework.web.servlet.ModelAndView;
@Controller @Controller
public class WelcomeController extends AbstractController { public class WelcomeController extends AbstractController {
@RequestMapping(method = RequestMethod.GET, value = "/") @RequestMapping(value = "/", method = RequestMethod.GET)
public final ModelAndView home(final HttpServletRequest request) { public final ModelAndView home(final HttpServletRequest request) {
String referer = request.getHeader("referer"); String referer = request.getHeader("referer");
String target = "index.html"; String target = "index.html";
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
<property name="favorParameter" value="true" /> <property name="favorParameter" value="true" />
<property name="mediaTypes" > <property name="mediaTypes" >
<value> <value>
html=text/html
json=application/json json=application/json
</value> </value>
</property> </property>
...@@ -31,6 +32,7 @@ ...@@ -31,6 +32,7 @@
<mvc:annotation-driven /> <mvc:annotation-driven />
<mvc:resources mapping="/**" location="/" /> <mvc:resources mapping="/**" location="/" />
<!-- -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters"> <property name="messageConverters">
...@@ -42,6 +44,7 @@ ...@@ -42,6 +44,7 @@
</list> </list>
</property> </property>
</bean> </bean>
<!-- -->
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="viewResolvers"> <property name="viewResolvers">
......
...@@ -16,6 +16,12 @@ ...@@ -16,6 +16,12 @@
<servlet> <servlet>
<servlet-name>arsnova</servlet-name> <servlet-name>arsnova</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <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> <load-on-startup>1</load-on-startup>
</servlet> </servlet>
<servlet-mapping> <servlet-mapping>
......
/*
* 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;
}
}
...@@ -7,7 +7,6 @@ import java.util.Properties; ...@@ -7,7 +7,6 @@ import java.util.Properties;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
......
/*
* 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
package de.thm.arsnova.controller; package de.thm.arsnova.controller;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import javax.inject.Inject; import javax.inject.Inject;
...@@ -27,7 +27,7 @@ import de.thm.arsnova.services.StubUserService; ...@@ -27,7 +27,7 @@ import de.thm.arsnova.services.StubUserService;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { @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/main/webapp/WEB-INF/spring/spring-main.xml",
"file:src/test/resources/test-config.xml" "file:src/test/resources/test-config.xml"
}) })
......
...@@ -46,7 +46,7 @@ import de.thm.arsnova.services.StubUserService; ...@@ -46,7 +46,7 @@ import de.thm.arsnova.services.StubUserService;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { @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/main/webapp/WEB-INF/spring/spring-main.xml",
"file:src/test/resources/test-config.xml" }) "file:src/test/resources/test-config.xml" })
public class LoginControllerTest { public class LoginControllerTest {
......
...@@ -26,7 +26,7 @@ import de.thm.arsnova.services.StubUserService; ...@@ -26,7 +26,7 @@ import de.thm.arsnova.services.StubUserService;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { @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/main/webapp/WEB-INF/spring/spring-main.xml",
"file:src/test/resources/test-config.xml" }) "file:src/test/resources/test-config.xml" })
public class QuestionByLecturerControllerTest { public class QuestionByLecturerControllerTest {
......
...@@ -27,7 +27,7 @@ import de.thm.arsnova.services.StubUserService; ...@@ -27,7 +27,7 @@ import de.thm.arsnova.services.StubUserService;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { @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/main/webapp/WEB-INF/spring/spring-main.xml",
"file:src/test/resources/test-config.xml" "file:src/test/resources/test-config.xml"
}) })
......
...@@ -18,7 +18,7 @@ import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAda ...@@ -18,7 +18,7 @@ import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAda
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { @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/main/webapp/WEB-INF/spring/spring-main.xml",
"file:src/test/resources/test-config.xml" "file:src/test/resources/test-config.xml"
}) })
......
...@@ -21,20 +21,42 @@ package de.thm.arsnova.controller; ...@@ -21,20 +21,42 @@ package de.thm.arsnova.controller;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import javax.inject.Inject;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; 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.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse; 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.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 @Before
public void setUp() throws Exception { public final void setUp() {
this.request = new MockHttpServletRequest(); this.request = new MockHttpServletRequest();
this.response = new MockHttpServletResponse(); this.response = new MockHttpServletResponse();
handlerAdapter = applicationContext.getBean(AnnotationMethodHandlerAdapter.class);
} }
@Test @Test
...@@ -42,7 +64,7 @@ public class WelcomeControllerTest extends AbstractSpringContextTestBase { ...@@ -42,7 +64,7 @@ public class WelcomeControllerTest extends AbstractSpringContextTestBase {
request.setMethod("GET"); request.setMethod("GET");
request.setRequestURI("/"); request.setRequestURI("/");
final ModelAndView mav = handle(request, response); final ModelAndView mav = handlerAdapter.handle(request, response, welcomeController);
assertNotNull(mav); assertNotNull(mav);
assertEquals("redirect:/index.html", mav.getViewName()); assertEquals("redirect:/index.html", mav.getViewName());
} }
......
...@@ -34,7 +34,7 @@ import de.thm.arsnova.exceptions.NotFoundException; ...@@ -34,7 +34,7 @@ import de.thm.arsnova.exceptions.NotFoundException;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { @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/main/webapp/WEB-INF/spring/spring-main.xml",
"file:src/test/resources/test-config.xml" "file:src/test/resources/test-config.xml"
}) })
......
...@@ -34,7 +34,7 @@ import de.thm.arsnova.exceptions.UnauthorizedException; ...@@ -34,7 +34,7 @@ import de.thm.arsnova.exceptions.UnauthorizedException;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { @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/main/webapp/WEB-INF/spring/spring-main.xml",
"file:src/test/resources/test-config.xml" "file:src/test/resources/test-config.xml"
}) })
......
...@@ -36,7 +36,7 @@ import de.thm.arsnova.exceptions.UnauthorizedException; ...@@ -36,7 +36,7 @@ import de.thm.arsnova.exceptions.UnauthorizedException;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { @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/main/webapp/WEB-INF/spring/spring-main.xml",
"file:src/test/resources/test-config.xml" }) "file:src/test/resources/test-config.xml" })
public class SessionServiceTest { public class SessionServiceTest {
......
...@@ -16,7 +16,7 @@ import de.thm.arsnova.entities.Statistics; ...@@ -16,7 +16,7 @@ import de.thm.arsnova.entities.Statistics;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { @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/main/webapp/WEB-INF/spring/spring-main.xml",
"file:src/test/resources/test-config.xml" "file:src/test/resources/test-config.xml"
}) })
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment