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

Added some more tests to service classes

parent 0489302f
Branches
Tags
No related merge requests found
...@@ -65,7 +65,7 @@ public class FeedbackController extends AbstractController { ...@@ -65,7 +65,7 @@ public class FeedbackController extends AbstractController {
@RequestMapping(value="/session/{sessionkey}/averagefeedback", method=RequestMethod.GET) @RequestMapping(value="/session/{sessionkey}/averagefeedback", method=RequestMethod.GET)
@ResponseBody @ResponseBody
public int getAverageFeedback(@PathVariable String sessionkey) { public long getAverageFeedback(@PathVariable String sessionkey) {
return feedbackService.getAverageFeedback(sessionkey); return feedbackService.getAverageFeedback(sessionkey);
} }
......
...@@ -21,9 +21,9 @@ import de.thm.arsnova.exceptions.NotFoundException; ...@@ -21,9 +21,9 @@ import de.thm.arsnova.exceptions.NotFoundException;
@Scope("singleton") @Scope("singleton")
public class StubDatabaseDao implements IDatabaseDao { public class StubDatabaseDao implements IDatabaseDao {
private Map<String, Session> stubSessions = new ConcurrentHashMap<String, Session>(); private static Map<String, Session> stubSessions = new ConcurrentHashMap<String, Session>();
private Map<String, Feedback> stubFeedbacks = new ConcurrentHashMap<String, Feedback>(); private static Map<String, Feedback> stubFeedbacks = new ConcurrentHashMap<String, Feedback>();
private Map<Session, Question> stubQuestions = new ConcurrentHashMap<Session, Question>(); private static Map<Session, Question> stubQuestions = new ConcurrentHashMap<Session, Question>();
private final Logger logger = LoggerFactory.getLogger(getClass()); private final Logger logger = LoggerFactory.getLogger(getClass());
...@@ -40,7 +40,7 @@ public class StubDatabaseDao implements IDatabaseDao { ...@@ -40,7 +40,7 @@ public class StubDatabaseDao implements IDatabaseDao {
session.setName("TestSession1"); session.setName("TestSession1");
session.setShortName("TS1"); session.setShortName("TS1");
this.stubSessions.put("12345678", session); stubSessions.put("12345678", session);
session.setActive(true); session.setActive(true);
session.setCreator("ptsr00"); session.setCreator("ptsr00");
...@@ -48,7 +48,7 @@ public class StubDatabaseDao implements IDatabaseDao { ...@@ -48,7 +48,7 @@ public class StubDatabaseDao implements IDatabaseDao {
session.setName("TestSession2"); session.setName("TestSession2");
session.setShortName("TS2"); session.setShortName("TS2");
this.stubSessions.put("87654321", session); stubSessions.put("87654321", session);
} }
private void fillWithDummyFeedbacks() { private void fillWithDummyFeedbacks() {
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
package de.thm.arsnova.services; package de.thm.arsnova.services;
import static org.junit.Assert.assertTrue; 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.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -26,6 +29,10 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -26,6 +29,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 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) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={ @ContextConfiguration(locations={
"file:src/main/webapp/WEB-INF/arsnova-servlet.xml", "file:src/main/webapp/WEB-INF/arsnova-servlet.xml",
...@@ -45,4 +52,47 @@ public class SessionServiceTest { ...@@ -45,4 +52,47 @@ public class SessionServiceTest {
System.out.println(sessionService.generateKeyword()); System.out.println(sessionService.generateKeyword());
assertTrue(sessionService.generateKeyword().matches("^[0-9]{8}$")); 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
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