From 4077539f3e4c0aa36b83ecb051135648deef5f68 Mon Sep 17 00:00:00 2001
From: Paul-Christian Volkmer <paul-christian.volkmer@mni.thm.de>
Date: Wed, 24 Oct 2012 09:29:56 +0200
Subject: [PATCH] Moved tests for FeedbackController

---
 .../controller/FeedbackControllerTest.java    | 89 +++++++++++++++++++
 .../controller/SessionControllerTest.java     | 38 --------
 2 files changed, 89 insertions(+), 38 deletions(-)
 create mode 100644 src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java

diff --git a/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java b/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java
new file mode 100644
index 00000000..17e3b11a
--- /dev/null
+++ b/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java
@@ -0,0 +1,89 @@
+package de.thm.arsnova.controller;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+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;
+
+import de.thm.arsnova.exceptions.NotFoundException;
+import de.thm.arsnova.exceptions.UnauthorizedException;
+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/spring-main.xml",
+		"file:src/test/resources/test-config.xml" })
+public class FeedbackControllerTest {
+
+	@Inject
+	private ApplicationContext applicationContext;
+	private MockHttpServletRequest request;
+	private MockHttpServletResponse response;
+	private HandlerAdapter handlerAdapter;
+
+	@Autowired
+	private FeedbackController feedbackController;
+	
+	@Autowired
+	private StubUserService userService;
+
+	@Before
+	public void setUp() {
+		this.request = new MockHttpServletRequest();
+		this.response = new MockHttpServletResponse();
+		handlerAdapter = applicationContext
+				.getBean(AnnotationMethodHandlerAdapter.class);
+	}
+
+	@Test(expected=NotFoundException.class)
+	public void testShouldNotGetFeedbackForUnknownSession() throws Exception {
+		userService.setUserAuthenticated(true);
+		
+		request.setMethod("GET");
+		request.setRequestURI("/session/00000000/feedback");
+		final ModelAndView mav = handlerAdapter.handle(request, response, feedbackController);
+		
+		assertNull(mav);
+		assertTrue(response.getStatus() == 404);
+	}
+	
+	@Test(expected=UnauthorizedException.class)
+	public void testShouldNotGetFeedbackIfUnauthorized() throws Exception {
+		userService.setUserAuthenticated(false);
+		
+		request.setMethod("GET");
+		request.setRequestURI("/session/00000000/feedback");
+		final ModelAndView mav = handlerAdapter.handle(request, response, feedbackController);
+		
+		assertNull(mav);
+		assertTrue(response.getStatus() == 401);
+	}
+	
+	@Test(expected=UnauthorizedException.class)
+	public void testShouldNotSaveFeedbackIfUnauthorized() throws Exception {
+		userService.setUserAuthenticated(false);
+		
+		request.setMethod("POST");
+		request.setRequestURI("/session/00000000/feedback");
+		request.setContentType("application/json");
+		request.setContent("0".getBytes());
+		final ModelAndView mav = handlerAdapter.handle(request, response, feedbackController);
+		
+		assertNull(mav);
+		assertTrue(response.getStatus() == 401);
+	}
+}
diff --git a/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java b/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java
index df4c2530..56418baf 100644
--- a/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java
+++ b/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java
@@ -100,42 +100,4 @@ public class SessionControllerTest {
 		assertNull(mav);
 		assertTrue(response.getStatus() == 401);
 	}
-
-	@Test(expected=NotFoundException.class)
-	public void testShouldNotGetFeedbackForUnknownSession() throws Exception {
-		userService.setUserAuthenticated(true);
-		
-		request.setMethod("GET");
-		request.setRequestURI("/session/00000000/feedback");
-		final ModelAndView mav = handlerAdapter.handle(request, response, sessionController);
-		
-		assertNull(mav);
-		assertTrue(response.getStatus() == 404);
-	}
-	
-	@Test(expected=UnauthorizedException.class)
-	public void testShouldNotGetFeedbackIfUnauthorized() throws Exception {
-		userService.setUserAuthenticated(false);
-		
-		request.setMethod("GET");
-		request.setRequestURI("/session/00000000/feedback");
-		final ModelAndView mav = handlerAdapter.handle(request, response, sessionController);
-		
-		assertNull(mav);
-		assertTrue(response.getStatus() == 401);
-	}
-	
-	@Test(expected=UnauthorizedException.class)
-	public void testShouldNotSaveFeedbackIfUnauthorized() throws Exception {
-		userService.setUserAuthenticated(false);
-		
-		request.setMethod("POST");
-		request.setRequestURI("/session/00000000/feedback");
-		request.setContentType("application/json");
-		request.setContent("0".getBytes());
-		final ModelAndView mav = handlerAdapter.handle(request, response, sessionController);
-		
-		assertNull(mav);
-		assertTrue(response.getStatus() == 401);
-	}
 }
-- 
GitLab