diff --git a/src/main/java/de/thm/arsnova/controller/FeedbackController.java b/src/main/java/de/thm/arsnova/controller/FeedbackController.java index 9b60626c4a7d3544fd2fa23427f95cdf3f483bc3..b91cec4859999a684c3411ef6d106c1238de47b1 100644 --- a/src/main/java/de/thm/arsnova/controller/FeedbackController.java +++ b/src/main/java/de/thm/arsnova/controller/FeedbackController.java @@ -65,7 +65,7 @@ public class FeedbackController extends AbstractController { @RequestMapping(value="/session/{sessionkey}/averagefeedback", method=RequestMethod.GET) @ResponseBody - public int getAverageFeedback(@PathVariable String sessionkey) { + public long getAverageFeedback(@PathVariable String sessionkey) { return feedbackService.getAverageFeedback(sessionkey); } diff --git a/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java b/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java index 13fd216408fdf2dde05295ac414498bdde5ca485..16e5bf59eff12be3e0e1b2787b4163ff125ff1cc 100644 --- a/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java +++ b/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java @@ -21,9 +21,9 @@ import de.thm.arsnova.exceptions.NotFoundException; @Scope("singleton") public class StubDatabaseDao implements IDatabaseDao { - private Map<String, Session> stubSessions = new ConcurrentHashMap<String, Session>(); - private Map<String, Feedback> stubFeedbacks = new ConcurrentHashMap<String, Feedback>(); - private Map<Session, Question> stubQuestions = new ConcurrentHashMap<Session, Question>(); + private static Map<String, Session> stubSessions = new ConcurrentHashMap<String, Session>(); + private static Map<String, Feedback> stubFeedbacks = new ConcurrentHashMap<String, Feedback>(); + private static Map<Session, Question> stubQuestions = new ConcurrentHashMap<Session, Question>(); private final Logger logger = LoggerFactory.getLogger(getClass()); @@ -40,7 +40,7 @@ public class StubDatabaseDao implements IDatabaseDao { session.setName("TestSession1"); session.setShortName("TS1"); - this.stubSessions.put("12345678", session); + stubSessions.put("12345678", session); session.setActive(true); session.setCreator("ptsr00"); @@ -48,7 +48,7 @@ public class StubDatabaseDao implements IDatabaseDao { session.setName("TestSession2"); session.setShortName("TS2"); - this.stubSessions.put("87654321", session); + stubSessions.put("87654321", session); } private void fillWithDummyFeedbacks() { diff --git a/src/test/java/de/thm/arsnova/services/SessionServiceTest.java b/src/test/java/de/thm/arsnova/services/SessionServiceTest.java index be16be5fe817d8f2d4f0ca916d44b81f993ae97d..3ad94fdc68830216c34d8f03ccff2a78a475e251 100644 --- a/src/test/java/de/thm/arsnova/services/SessionServiceTest.java +++ b/src/test/java/de/thm/arsnova/services/SessionServiceTest.java @@ -19,6 +19,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 org.junit.Test; import org.junit.runner.RunWith; @@ -26,6 +29,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import de.thm.arsnova.entities.Session; +import de.thm.arsnova.exceptions.NotFoundException; +import de.thm.arsnova.exceptions.UnauthorizedException; + @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={ "file:src/main/webapp/WEB-INF/arsnova-servlet.xml", @@ -45,4 +52,47 @@ public class SessionServiceTest { System.out.println(sessionService.generateKeyword()); assertTrue(sessionService.generateKeyword().matches("^[0-9]{8}$")); } + + @Test(expected=NotFoundException.class) + public void testShouldFindNonExistantSession() { + userService.setUserAuthenticated(true); + sessionService.joinSession("00000000"); + } + + @Test(expected=UnauthorizedException.class) + public void testShouldNotReturnSessionIfUnauthorized() { + userService.setUserAuthenticated(false); + sessionService.joinSession("12345678"); + } + + @Test(expected=UnauthorizedException.class) + public void testShouldNotSaveSessionIfUnauthorized() { + userService.setUserAuthenticated(false); + + Session session = new Session(); + session.setActive(true); + session.setCreator("ptsr00"); + session.setKeyword("11111111"); + session.setName("TestSessionX"); + session.setShortName("TSX"); + sessionService.saveSession(session); + + userService.setUserAuthenticated(true); + + assertNull(sessionService.joinSession("11111111")); + } + + @Test + public void testShouldSaveSession() { + userService.setUserAuthenticated(true); + + Session session = new Session(); + session.setActive(true); + session.setCreator("ptsr00"); + session.setKeyword("11111111"); + session.setName("TestSessionX"); + session.setShortName("TSX"); + sessionService.saveSession(session); + assertNotNull(sessionService.joinSession("11111111")); + } } \ No newline at end of file