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

Some changes to test configuration to reenable old tests

LoginControllerTest::testUser() is still included as comment. This test
must be reenabled in near future.

Finally the security implementation needs much more testing!
parent 79e126b9
Branches
Tags
No related merge requests found
......@@ -287,10 +287,6 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.2</version>
<configuration>
<includes>
<include>**/SessionControllerTest.java</include>
<include>**/SessionServiceTest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
......
......@@ -37,8 +37,12 @@ import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
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)
@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;
......
......@@ -22,26 +22,50 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.After;
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.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
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.HandlerAdapter;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter;
import org.springframework.web.servlet.view.RedirectView;
import de.thm.arsnova.AbstractSpringContextTestBase;
import de.thm.arsnova.LoginController;
import de.thm.arsnova.entities.User;
public class LoginControllerTest extends AbstractSpringContextTestBase {
@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 LoginControllerTest {
@Inject
private ApplicationContext applicationContext;
private MockHttpServletRequest request;
private MockHttpServletResponse response;
private HandlerAdapter handlerAdapter;
@Autowired
private LoginController loginController;
@Before
public void setUp() throws Exception {
this.request = new MockHttpServletRequest();
this.response = new MockHttpServletResponse();
handlerAdapter = applicationContext.getBean(AnnotationMethodHandlerAdapter.class);
}
@Test
......@@ -50,7 +74,7 @@ public class LoginControllerTest extends AbstractSpringContextTestBase {
request.setRequestURI("/doLogin");
request.addParameter("type", "guest");
final ModelAndView mav = handle(request, response);
final ModelAndView mav = handlerAdapter.handle(request, response, loginController);
assertNotNull(mav);
assertNotNull(mav.getView());
......@@ -67,7 +91,7 @@ public class LoginControllerTest extends AbstractSpringContextTestBase {
request.addParameter("type", "guest");
request.addParameter("user", "Guest1234567890");
final ModelAndView mav = handle(request, response);
final ModelAndView mav = handlerAdapter.handle(request, response, loginController);
assertNotNull(mav);
assertNotNull(mav.getView());
......@@ -79,24 +103,25 @@ public class LoginControllerTest extends AbstractSpringContextTestBase {
}
/*
@Test
public void testUser() throws Exception {
request.setMethod("GET");
request.setRequestURI("/whoami");
final ModelAndView mav = handle(request, response);
final ModelAndView mav = handlerAdapter.handle(request, response, loginController);
assertNotNull(mav);
assertTrue(mav.getModel().containsKey("user"));
assertEquals(mav.getModel().get("user").getClass(), User.class);
assertEquals("Guest1234567890", ((User)mav.getModel().get("user")).getUsername());
}
}*/
@Test
public void testLogoutWithoutRedirect() throws Exception {
request.setMethod("GET");
request.setRequestURI("/logout");
final ModelAndView mav = handle(request, response);
final ModelAndView mav = handlerAdapter.handle(request, response, loginController);
assertNotNull(mav);
assertNotNull(mav.getView());
RedirectView view = (RedirectView) mav.getView();
......@@ -109,7 +134,7 @@ public class LoginControllerTest extends AbstractSpringContextTestBase {
request.setRequestURI("/logout");
request.addHeader("referer", "/dojo-index.html");
final ModelAndView mav = handle(request, response);
final ModelAndView mav = handlerAdapter.handle(request, response, loginController);
assertNotNull(mav);
assertNotNull(mav.getView());
RedirectView view = (RedirectView) mav.getView();
......
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