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

Added some comtroller tests

parent e019796d
Branches
Tags
No related merge requests found
......@@ -54,7 +54,7 @@ public class AudienceQuestionController extends AbstractController {
@RequestParam final String sessionkey,
final HttpServletResponse response
) {
response.addHeader("X-Deprecated-API", "1");
response.addHeader(X_DEPRECATED_API, "1");
return questionService.getInterposedCount(sessionkey);
}
......@@ -64,7 +64,7 @@ public class AudienceQuestionController extends AbstractController {
@RequestParam("sessionkey") final String sessionkey,
final HttpServletResponse response
) {
response.addHeader("X-Deprecated-API", "1");
response.addHeader(X_DEPRECATED_API, "1");
return questionService.getInterposedReadingCount(sessionkey);
}
......
......@@ -2,6 +2,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.status;
import org.junit.Before;
......@@ -68,6 +69,15 @@ public class FeedbackControllerTest {
public void testShouldReturnFeedback() throws Exception {
userService.setUserAuthenticated(true);
mockMvc.perform(get("/session/87654321/feedback").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
.andExpect(status().isOk())
.andExpect(content().string("{\"values\":[0,0,0,0]}"));
}
@Test
public void testShouldReturnXDeprecatedApiHeaderForFeedback() throws Exception {
userService.setUserAuthenticated(true);
mockMvc.perform(get("/session/87654321/feedback").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(header().string(AbstractController.X_DEPRECATED_API, "1"));
}
}
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.status;
import java.util.ArrayList;
......@@ -83,4 +85,22 @@ public class LecturerQuestionControllerTest {
mockMvc.perform(get("/lecturerquestion/").param("sessionkey", "12345678").param("preparationquestionsonly", "true"))
.andExpect(status().isUnauthorized());
}
@Test
public void testShouldReturnQuestionCount() throws Exception {
setAuthenticated(true, "somebody");
mockMvc.perform(get("/lecturerquestion/count").param("sessionkey", "12345678").param("lecturequestionsonly", "true"))
.andExpect(status().isOk())
.andExpect(content().string("0"));
}
@Test
public void testShouldReturnXDeprecatedApiHeaderForQuestionCount() throws Exception {
setAuthenticated(true, "somebody");
mockMvc.perform(get("/lecturerquestion/count").param("sessionkey", "12345678").param("lecturequestionsonly", "true"))
.andExpect(status().isOk())
.andExpect(header().string(AbstractController.X_DEPRECATED_API, "1"));
}
}
......@@ -2,6 +2,8 @@ package de.thm.arsnova.controller;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
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.status;
import java.util.ArrayList;
......@@ -117,4 +119,22 @@ public class SessionControllerTest {
mockMvc.perform(get("/session/"))
.andExpect(status().isNotImplemented());
}
@Test
public void testShouldReturnActiveUserCount() throws Exception {
setAuthenticated(false, "ptsr00");
mockMvc.perform(get("/session/12345678/activeusercount"))
.andExpect(status().isOk())
.andExpect(content().string("0"));
}
@Test
public void testShouldReturnXDeprecatedApiHeaderForActiveUserCount() throws Exception {
setAuthenticated(false, "ptsr00");
mockMvc.perform(get("/session/12345678/activeusercount"))
.andExpect(status().isOk())
.andExpect(header().string(AbstractController.X_DEPRECATED_API, "1"));
}
}
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