46 lines
1.8 KiB
Java
46 lines
1.8 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 pl.edu.amu.wmi.bookapi.api.dto.MessageDto;
|
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
|
|
|
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 userId) throws Exception {
|
|
return mvc.perform(get("/api/messages"));
|
|
}
|
|
|
|
public ResultActions getMessages(String userId, String threadId) throws Exception {
|
|
return mvc.perform(get("/api/messages" + threadId));
|
|
}
|
|
|
|
public ResultActions postMessage(String content, String author, String recipient) throws Exception {
|
|
System.out.println("Content");
|
|
System.out.println("{\n" +
|
|
"\"content\": " + objectMapper.writeValueAsString(content) + ",\n" +
|
|
"\"author\": " + objectMapper.writeValueAsString(author) + ",\n" +
|
|
"\"recipient\": " + objectMapper.writeValueAsString(recipient) + "\n" +
|
|
"}");
|
|
|
|
return mvc.perform(post("/api/messages")
|
|
.contentType(MediaType.APPLICATION_JSON)
|
|
.content("{\n" +
|
|
"\"content\": " + objectMapper.writeValueAsString(content) + ",\n" +
|
|
"\"author\": " + objectMapper.writeValueAsString(author) + ",\n" +
|
|
"\"recipient\": " + objectMapper.writeValueAsString(recipient) + "\n" +
|
|
"}")
|
|
);
|
|
}
|
|
}
|