diff --git a/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java b/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java index 7b19d5f8c8efc0b047b9ba781a22ccf81ed09422..18034a38724b1fe9137dea6a7db0e87513fba67f 100644 --- a/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java +++ b/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java @@ -6,6 +6,7 @@ import static org.junit.Assert.assertEquals; import javax.inject.Inject; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -19,6 +20,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.dao.StubDatabaseDao; import de.thm.arsnova.exceptions.NoContentException; import de.thm.arsnova.exceptions.NotFoundException; import de.thm.arsnova.services.StubUserService; @@ -42,6 +44,14 @@ public class FeedbackControllerTest { @Autowired private StubUserService userService; + + @Autowired + private StubDatabaseDao databaseDao; + + @After + public final void cleanup() { + databaseDao.cleanupTestData(); + } @Before public void setUp() { diff --git a/src/test/java/de/thm/arsnova/controller/LoginControllerTest.java b/src/test/java/de/thm/arsnova/controller/LoginControllerTest.java index c6f2256fe76f2179c5da7838de9af5f5327d1240..73824157ea13eef7c597564d366c75a68f8b42cd 100644 --- a/src/test/java/de/thm/arsnova/controller/LoginControllerTest.java +++ b/src/test/java/de/thm/arsnova/controller/LoginControllerTest.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotNull; import javax.inject.Inject; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -40,6 +41,7 @@ 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.dao.StubDatabaseDao; import de.thm.arsnova.services.StubUserService; @RunWith(SpringJUnit4ClassRunner.class) @@ -60,6 +62,14 @@ public class LoginControllerTest { @Autowired private StubUserService userService; + + @Autowired + private StubDatabaseDao databaseDao; + + @After + public final void cleanup() { + databaseDao.cleanupTestData(); + } @Before public void setUp() throws Exception { diff --git a/src/test/java/de/thm/arsnova/controller/QuestionControllerTest.java b/src/test/java/de/thm/arsnova/controller/QuestionControllerTest.java index 624f63c9b4a48881c81bd754c9216b5186a52866..e798061fbc99bb9350831688f26e7a409605bb6a 100644 --- a/src/test/java/de/thm/arsnova/controller/QuestionControllerTest.java +++ b/src/test/java/de/thm/arsnova/controller/QuestionControllerTest.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertTrue; import javax.inject.Inject; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -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.dao.StubDatabaseDao; import de.thm.arsnova.exceptions.NotFoundException; import de.thm.arsnova.exceptions.UnauthorizedException; import de.thm.arsnova.services.StubUserService; @@ -40,6 +42,14 @@ public class QuestionControllerTest { @Autowired private StubUserService userService; + + @Autowired + private StubDatabaseDao databaseDao; + + @After + public final void cleanup() { + databaseDao.cleanupTestData(); + } @Before public void setUp() { diff --git a/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java b/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java index 8e2c33587cdc3b01663562fc9765c18cfb206693..ee422e59202231a1b8fac08cdfb90433a48de524 100644 --- a/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java +++ b/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertTrue; import javax.inject.Inject; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -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.dao.StubDatabaseDao; import de.thm.arsnova.exceptions.ForbiddenException; import de.thm.arsnova.exceptions.NotFoundException; import de.thm.arsnova.exceptions.UnauthorizedException; @@ -42,6 +44,14 @@ public class SessionControllerTest { @Autowired private StubUserService userService; + + @Autowired + private StubDatabaseDao databaseDao; + + @After + public final void cleanup() { + databaseDao.cleanupTestData(); + } @Before public void setUp() { diff --git a/src/test/java/de/thm/arsnova/controller/StatisticsControllerTest.java b/src/test/java/de/thm/arsnova/controller/StatisticsControllerTest.java index d0b4f25a21cdf7d4f39cb9008527df3b503793d4..3ce074a36f7f6bd465887e91f16f1ab71b6e87a6 100644 --- a/src/test/java/de/thm/arsnova/controller/StatisticsControllerTest.java +++ b/src/test/java/de/thm/arsnova/controller/StatisticsControllerTest.java @@ -16,8 +16,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.servlet.HandlerAdapter; import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter; -import de.thm.arsnova.services.StubUserService; - @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/arsnova-servlet.xml", @@ -35,9 +33,6 @@ public class StatisticsControllerTest { @Autowired private StatisticsController statisticsController; - @Autowired - private StubUserService userService; - @Before public final void setUp() { this.request = new MockHttpServletRequest(); @@ -47,12 +42,10 @@ public class StatisticsControllerTest { @Test public final void testShouldGetCurrentOnlineUsers() throws Exception { - userService.setUserAuthenticated(true); - request.setMethod("GET"); request.setRequestURI("/statistics/activeusercount"); handlerAdapter.handle(request, response, statisticsController); - assertEquals("1", response.getContentAsString()); + assertEquals("0", response.getContentAsString()); } } diff --git a/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java b/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java index ac2264591672a4b66233c16285f7e4386576050a..76b4f2b39b149536bec98667ff332588eefd2e02 100644 --- a/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java +++ b/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java @@ -33,6 +33,17 @@ public class StubDatabaseDao implements IDatabaseDao { fillWithDummyQuestions(); } + public void cleanupTestData() { + stubSessions.clear(); + stubFeedbacks.clear(); + stubQuestions.clear(); + stubUsers.clear(); + + fillWithDummySessions(); + fillWithDummyFeedbacks(); + fillWithDummyQuestions(); + } + private void fillWithDummySessions() { Session session = new Session(); session.setActive(true); @@ -121,7 +132,6 @@ public class StubDatabaseDao implements IDatabaseDao { @Override public boolean sessionKeyAvailable(String keyword) { - System.out.println(stubSessions.get(keyword)); return (stubSessions.get(keyword) == null); } @@ -168,7 +178,6 @@ public class StubDatabaseDao implements IDatabaseDao { @Override public LoggedIn registerAsOnlineUser(User u, Session s) { stubUsers.put(s.getKeyword(), u); - System.out.println("X"); return new LoggedIn(); } diff --git a/src/test/java/de/thm/arsnova/services/FeedbackServiceTest.java b/src/test/java/de/thm/arsnova/services/FeedbackServiceTest.java index 8332d19183dc8158b6025ae3289f504875dea33c..5cb9beec7e11fe32a7adb4af737976b44660d6c3 100644 --- a/src/test/java/de/thm/arsnova/services/FeedbackServiceTest.java +++ b/src/test/java/de/thm/arsnova/services/FeedbackServiceTest.java @@ -21,12 +21,14 @@ package de.thm.arsnova.services; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import de.thm.arsnova.dao.StubDatabaseDao; import de.thm.arsnova.exceptions.NoContentException; import de.thm.arsnova.exceptions.NotFoundException; @@ -43,6 +45,14 @@ public class FeedbackServiceTest { @Autowired StubUserService userService; + + @Autowired + private StubDatabaseDao databaseDao; + + @After + public final void cleanup() { + databaseDao.cleanupTestData(); + } @Test(expected = NotFoundException.class) public void testShouldFindFeedbackForNonExistantSession() { diff --git a/src/test/java/de/thm/arsnova/services/QuestionServiceTest.java b/src/test/java/de/thm/arsnova/services/QuestionServiceTest.java index 607f65476d93cd1e7f8cd819fb5b158069406e68..a224b94610857d152367d946a2d12c1de22b2983 100644 --- a/src/test/java/de/thm/arsnova/services/QuestionServiceTest.java +++ b/src/test/java/de/thm/arsnova/services/QuestionServiceTest.java @@ -20,12 +20,14 @@ package de.thm.arsnova.services; import static org.junit.Assert.assertEquals; +import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import de.thm.arsnova.dao.StubDatabaseDao; import de.thm.arsnova.exceptions.NotFoundException; import de.thm.arsnova.exceptions.UnauthorizedException; @@ -42,6 +44,14 @@ public class QuestionServiceTest { @Autowired StubUserService userService; + + @Autowired + private StubDatabaseDao databaseDao; + + @After + public final void cleanup() { + databaseDao.cleanupTestData(); + } @Test(expected = UnauthorizedException.class) public void testShouldNotReturnQuestionsIfNotAuthenticated() { diff --git a/src/test/java/de/thm/arsnova/services/SessionServiceTest.java b/src/test/java/de/thm/arsnova/services/SessionServiceTest.java index 6159c06017cef4f15df1b236cfb38850f22276bb..52026555375defd92a00421d39eaf44cc5997e28 100644 --- a/src/test/java/de/thm/arsnova/services/SessionServiceTest.java +++ b/src/test/java/de/thm/arsnova/services/SessionServiceTest.java @@ -22,12 +22,14 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import de.thm.arsnova.dao.StubDatabaseDao; import de.thm.arsnova.entities.Session; import de.thm.arsnova.exceptions.NotFoundException; import de.thm.arsnova.exceptions.UnauthorizedException; @@ -44,6 +46,14 @@ public class SessionServiceTest { @Autowired private StubUserService userService; + + @Autowired + private StubDatabaseDao databaseDao; + + @After + public final void cleanup() { + databaseDao.cleanupTestData(); + } @Test public void testShouldGenerateSessionKeyword() { diff --git a/src/test/java/de/thm/arsnova/services/StatisticsServiceTest.java b/src/test/java/de/thm/arsnova/services/StatisticsServiceTest.java index 077ad2db11c858ee58819403a08254c899a41a05..f2530c954d642d30d590e7ae94c81bd6846c9d3a 100644 --- a/src/test/java/de/thm/arsnova/services/StatisticsServiceTest.java +++ b/src/test/java/de/thm/arsnova/services/StatisticsServiceTest.java @@ -2,6 +2,7 @@ package de.thm.arsnova.services; import static org.junit.Assert.assertEquals; +import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -28,6 +29,11 @@ public class StatisticsServiceTest { @Autowired private StubDatabaseDao databaseDao; + @After + public final void cleanup() { + databaseDao.cleanupTestData(); + } + @Test public final void testShouldReturnNoActiveUsers() { int actual = statisticsService.countActiveUsers(); diff --git a/src/test/java/de/thm/arsnova/services/StubUserService.java b/src/test/java/de/thm/arsnova/services/StubUserService.java index 169058a110f264220884fbade47e78ec91741587..7454485faa3dc33d0ea17c5115e0183e5eaff64b 100644 --- a/src/test/java/de/thm/arsnova/services/StubUserService.java +++ b/src/test/java/de/thm/arsnova/services/StubUserService.java @@ -1,19 +1,18 @@ package de.thm.arsnova.services; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import de.thm.arsnova.dao.StubDatabaseDao; import de.thm.arsnova.entities.User; public class StubUserService extends UserService { private User stubUser = null; - + public void setUserAuthenticated(boolean isAuthenticated) { if (isAuthenticated) { - stubUser = new User(new UsernamePasswordAuthenticationToken( - "ptsr00", "testpassword")); + stubUser = new User( + new UsernamePasswordAuthenticationToken("ptsr00", "testpassword") + ); return; } stubUser = null;