Skip to content
Snippets Groups Projects
Commit bc754804 authored by Julian Hochstetter's avatar Julian Hochstetter
Browse files

adjust tests

parent 24ce741d
No related merge requests found
...@@ -3,5 +3,7 @@ log4j.rootCategory=INFO, stdout ...@@ -3,5 +3,7 @@ log4j.rootCategory=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n
log4j.category.org.springframework.beans.factory=DEBUG #log4j.category.org.springframework.beans.factory=DEBUG
log4j.category.de.thm.arsnova=DEBUG
\ No newline at end of file
...@@ -23,17 +23,22 @@ import static org.junit.Assert.assertNotNull; ...@@ -23,17 +23,22 @@ import static org.junit.Assert.assertNotNull;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.junit.runner.RunWith;
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.AbstractJUnit4SpringContextTests; 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.HandlerAdapter;
import org.springframework.web.servlet.HandlerExecutionChain; import org.springframework.web.servlet.HandlerExecutionChain;
import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
@ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/arsnova-servlet.xml", "file:src/main/webapp/WEB-INF/spring/spring-main.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class AbstractSpringContextTestBase extends AbstractJUnit4SpringContextTests { public class AbstractSpringContextTestBase extends AbstractJUnit4SpringContextTests {
protected MockHttpServletRequest request; protected MockHttpServletRequest request;
...@@ -41,7 +46,7 @@ public class AbstractSpringContextTestBase extends AbstractJUnit4SpringContextTe ...@@ -41,7 +46,7 @@ public class AbstractSpringContextTestBase extends AbstractJUnit4SpringContextTe
protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response) protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response)
throws Exception { throws Exception {
final HandlerMapping handlerMapping = applicationContext.getBean(DefaultAnnotationHandlerMapping.class); final HandlerMapping handlerMapping = applicationContext.getBean(RequestMappingHandlerMapping.class);
final HandlerExecutionChain handler = handlerMapping.getHandler(request); final HandlerExecutionChain handler = handlerMapping.getHandler(request);
assertNotNull("No handler found for request, check you request mapping", handler); assertNotNull("No handler found for request, check you request mapping", handler);
...@@ -56,7 +61,7 @@ public class AbstractSpringContextTestBase extends AbstractJUnit4SpringContextTe ...@@ -56,7 +61,7 @@ public class AbstractSpringContextTestBase extends AbstractJUnit4SpringContextTe
return null; return null;
} }
} }
HandlerAdapter handlerAdapter = applicationContext.getBean(AnnotationMethodHandlerAdapter.class);; HandlerAdapter handlerAdapter = applicationContext.getBean(RequestMappingHandlerAdapter.class);;
final ModelAndView mav = handlerAdapter.handle(request, response, controller); final ModelAndView mav = handlerAdapter.handle(request, response, controller);
return mav; return mav;
} }
......
...@@ -22,18 +22,12 @@ package de.thm.arsnova; ...@@ -22,18 +22,12 @@ package de.thm.arsnova;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/** /**
* Unit test to verify Spring context wiring. * Unit test to verify Spring context wiring.
* *
*/ */
@ContextConfiguration(locations="file:src/main/webapp/WEB-INF/arsnova-servlet.xml") public class WiringTest extends AbstractSpringContextTestBase {
@RunWith(SpringJUnit4ClassRunner.class)
public class WiringTest extends AbstractJUnit4SpringContextTests {
@Test @Test
public void testWiring() throws Exception { public void testWiring() throws Exception {
......
...@@ -19,54 +19,44 @@ ...@@ -19,54 +19,44 @@
package de.thm.arsnova.controller; 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.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import javax.servlet.Filter;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
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.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import de.thm.arsnova.AbstractSpringContextTestBase; import de.thm.arsnova.AbstractSpringContextTestBase;
@ContextConfiguration(locations = "file:src/main/webapp/WEB-INF/arsnova-servlet.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class LoginControllerTest extends AbstractSpringContextTestBase { public class LoginControllerTest extends AbstractSpringContextTestBase {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
this.request = new MockHttpServletRequest(); this.request = new MockHttpServletRequest();
this.response = new MockHttpServletResponse(); this.response = new MockHttpServletResponse();
} }
@Test
public void testCasLogin() throws Exception {
request.setMethod("GET");
request.setRequestURI("/doCasLogin");
final ModelAndView mav = handle(request, response);
assertEquals(null, mav.getViewName());
}
@Test @Test
public void testGuestLogin() throws Exception { public void testGuestLogin() throws Exception {
request.setMethod("GET"); request.setMethod("GET");
request.setRequestURI("/doGuestLogin"); request.setRequestURI("/doLogin");
request.addParameter("type", "guest");
final ModelAndView mav = handle(request, response);
final ModelAndView mav = handle(request, response); assertNotNull(mav);
assertTrue(mav.getViewName().startsWith("redirect:/"));
assertTrue(mav.getViewName().startsWith("redirect:/")); Authentication auth = SecurityContextHolder.getContext()
Authentication auth = SecurityContextHolder.getContext().getAuthentication(); .getAuthentication();
assertEquals(auth.getClass(), UsernamePasswordAuthenticationToken.class); assertEquals(auth.getClass(), UsernamePasswordAuthenticationToken.class);
} }
} }
...@@ -19,27 +19,22 @@ ...@@ -19,27 +19,22 @@
package de.thm.arsnova.controller; package de.thm.arsnova.controller;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
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.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import de.thm.arsnova.AbstractSpringContextTestBase; import de.thm.arsnova.AbstractSpringContextTestBase;
@ContextConfiguration(locations = "file:src/main/webapp/WEB-INF/arsnova-servlet.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class WelcomeControllerTest extends AbstractSpringContextTestBase { public class WelcomeControllerTest extends AbstractSpringContextTestBase {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
this.request = new MockHttpServletRequest(); this.request = new MockHttpServletRequest();
this.response = new MockHttpServletResponse(); this.response = new MockHttpServletResponse();
} }
@Test @Test
...@@ -48,8 +43,8 @@ public class WelcomeControllerTest extends AbstractSpringContextTestBase { ...@@ -48,8 +43,8 @@ public class WelcomeControllerTest extends AbstractSpringContextTestBase {
request.setRequestURI("/"); request.setRequestURI("/");
final ModelAndView mav = handle(request, response); final ModelAndView mav = handle(request, response);
assertNotNull(mav);
assertEquals("redirect:/index.html", mav.getViewName()); assertEquals("redirect:/index.html", mav.getViewName());
} }
} }
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