From 470259f9e7137b3827cd4c028c9e3aa7804ce258 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer <paul-christian.volkmer@mni.thm.de> Date: Sun, 28 Oct 2012 14:01:48 +0100 Subject: [PATCH] Fixed internal server error occuring for exaption handling reasons --- .../controller/AbstractController.java | 3 +- .../controller/FeedbackControllerTest.java | 35 ++++++++++++++++--- .../arsnova/services/SessionServiceTest.java | 5 ++- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/thm/arsnova/controller/AbstractController.java b/src/main/java/de/thm/arsnova/controller/AbstractController.java index 0e6d2b526..b8f04da0a 100644 --- a/src/main/java/de/thm/arsnova/controller/AbstractController.java +++ b/src/main/java/de/thm/arsnova/controller/AbstractController.java @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseStatus; import de.thm.arsnova.exceptions.ForbiddenException; +import de.thm.arsnova.exceptions.NoContentException; import de.thm.arsnova.exceptions.NotFoundException; import de.thm.arsnova.exceptions.UnauthorizedException; @@ -27,7 +28,7 @@ public class AbstractController { } @ResponseStatus(HttpStatus.NO_CONTENT) - @ExceptionHandler(UnauthorizedException.class) + @ExceptionHandler(NoContentException.class) public void handleNoContentException(final Exception e, HttpServletRequest request) { } } diff --git a/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java b/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java index cea87b5a7..8cf20ed56 100644 --- a/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java +++ b/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java @@ -2,6 +2,7 @@ package de.thm.arsnova.controller; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; import javax.inject.Inject; @@ -18,6 +19,7 @@ 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.NoContentException; import de.thm.arsnova.exceptions.NotFoundException; import de.thm.arsnova.services.StubUserService; @@ -25,7 +27,8 @@ import de.thm.arsnova.services.StubUserService; @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" }) + "file:src/test/resources/test-config.xml" +}) public class FeedbackControllerTest { @Inject @@ -44,8 +47,7 @@ public class FeedbackControllerTest { public void setUp() { this.request = new MockHttpServletRequest(); this.response = new MockHttpServletResponse(); - handlerAdapter = applicationContext - .getBean(AnnotationMethodHandlerAdapter.class); + handlerAdapter = applicationContext.getBean(AnnotationMethodHandlerAdapter.class); } @Test(expected = NotFoundException.class) @@ -54,10 +56,33 @@ public class FeedbackControllerTest { request.setMethod("GET"); request.setRequestURI("/session/00000000/feedback"); - final ModelAndView mav = handlerAdapter.handle(request, response, - feedbackController); + final ModelAndView mav = handlerAdapter.handle(request, response, feedbackController); assertNull(mav); assertTrue(response.getStatus() == 404); } + + @Test(expected = NoContentException.class) + public void testShouldNotGetAverageFeedbackContentForSessionWithoutFeedback() throws Exception { + userService.setUserAuthenticated(true); + + request.setMethod("GET"); + request.setRequestURI("/session/12345678/averagefeedback"); + final ModelAndView mav = handlerAdapter.handle(request, response, feedbackController); + + assertNull(mav); + assertTrue(response.getStatus() == 204); + } + + @Test + public void testShouldNotGetCorrectFeedbackCountForSessionWithoutFeedback() throws Exception { + userService.setUserAuthenticated(true); + + request.setMethod("GET"); + request.setRequestURI("/session/12345678/feedbackcount"); + handlerAdapter.handle(request, response, feedbackController); + + assertTrue(response.getStatus() == 200); + assertEquals("0", response.getContentAsString()); + } } diff --git a/src/test/java/de/thm/arsnova/services/SessionServiceTest.java b/src/test/java/de/thm/arsnova/services/SessionServiceTest.java index e70816ce1..f32454747 100644 --- a/src/test/java/de/thm/arsnova/services/SessionServiceTest.java +++ b/src/test/java/de/thm/arsnova/services/SessionServiceTest.java @@ -18,10 +18,9 @@ */ package de.thm.arsnova.services; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import org.junit.Test; import org.junit.runner.RunWith; -- GitLab