Use JsonPath to test Json responses

parent 7ee2f509
......@@ -302,6 +302,12 @@
<artifactId>connector-client</artifactId>
<version>0.40.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path-assert</artifactId>
<version>0.9.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
......
......@@ -56,7 +56,7 @@ public class FeedbackService implements IFeedbackService {
@Autowired
private IUserService userService;
private FeedbackStorage feedbackStorage;
public final void setDatabaseDao(final IDatabaseDao newDatabaseDao) {
......@@ -67,7 +67,7 @@ public class FeedbackService implements IFeedbackService {
public void init() {
this.feedbackStorage = new FeedbackStorage(databaseDao);
}
@Override
@Scheduled(fixedDelay = DEFAULT_SCHEDULER_DELAY)
public final void cleanFeedbackVotes() {
......@@ -129,7 +129,7 @@ public class FeedbackService implements IFeedbackService {
public final void broadcastFeedbackChanges(
final Map<String, Set<String>> affectedUsers,
final Set<String> allAffectedSessions
) {
) {
for (Map.Entry<String, Set<String>> e : affectedUsers.entrySet()) {
// Is this user registered with a socket connection?
String connectedSocket = userService.getSessionForUser(e.getKey());
......
......@@ -3,6 +3,7 @@ package de.thm.arsnova.controller;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.junit.Before;
......@@ -70,7 +71,7 @@ public class FeedbackControllerTest {
userService.setUserAuthenticated(true);
mockMvc.perform(get("/session/87654321/feedback").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().string("{\"values\":[0,0,0,0]}"));
.andExpect(jsonPath("$.values").isArray());
}
@Test
......
......@@ -3,6 +3,7 @@ package de.thm.arsnova.controller;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.junit.Before;
......@@ -72,7 +73,11 @@ public class StatisticsControllerTest {
public final void testShouldGetStatistics() throws Exception {
mockMvc.perform(get("/statistics"))
.andExpect(status().isOk())
.andExpect(content().string("{\"answers\":0,\"questions\":0,\"openSessions\":3,\"closedSessions\":0,\"activeUsers\":0}"));
.andExpect(jsonPath("$.answers").value(0))
.andExpect(jsonPath("$.questions").value(0))
.andExpect(jsonPath("$.openSessions").value(3))
.andExpect(jsonPath("$.closedSessions").value(0))
.andExpect(jsonPath("$.activeUsers").value(0));
}
@Test
......
Markdown is supported
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