41 lines
1.6 KiB
Java
41 lines
1.6 KiB
Java
package pl.edu.amu.wmi.bookapi.fixtures.api;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
import org.springframework.test.web.servlet.ResultActions;
|
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
|
|
|
public class MessageControllerRequests {
|
|
private final MockMvc mvc;
|
|
private final ObjectMapper objectMapper;
|
|
|
|
public MessageControllerRequests(MockMvc mvc, ObjectMapper objectMapper) {
|
|
this.mvc = mvc;
|
|
this.objectMapper = objectMapper;
|
|
}
|
|
|
|
public ResultActions getThreads(String bearer) throws Exception {
|
|
return mvc.perform(get("/api/messages")
|
|
.header("Authorization", bearer));
|
|
}
|
|
|
|
public ResultActions getMessages(String bearer, String threadId) throws Exception {
|
|
return mvc.perform(get("/api/messages/" + threadId)
|
|
.header("Authorization", bearer));
|
|
}
|
|
|
|
public ResultActions postMessage(String content, String recipient, String bearer) throws Exception {
|
|
return mvc.perform(post("/api/messages")
|
|
.header("Authorization", bearer)
|
|
.contentType(MediaType.APPLICATION_JSON)
|
|
.content("{\n" +
|
|
"\"content\": " + objectMapper.writeValueAsString(content) + ",\n" +
|
|
"\"recipient\": " + objectMapper.writeValueAsString(recipient) + "\n" +
|
|
"}")
|
|
);
|
|
}
|
|
}
|