57 lines
2.1 KiB
Java
57 lines
2.1 KiB
Java
package de.nclazz.service.mailrelay;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import de.nclazz.service.mailrelay.adapter.web.MessageForm;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.context.TestConfiguration;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.test.context.ActiveProfiles;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
|
|
import java.time.Clock;
|
|
import java.time.LocalDateTime;
|
|
|
|
import static org.springframework.http.MediaType.APPLICATION_JSON;
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
|
|
|
@SpringBootTest
|
|
@ActiveProfiles("integration")
|
|
@AutoConfigureMockMvc
|
|
public class ForwardMessageRestTest {
|
|
|
|
@Autowired
|
|
private MockMvc mockMvc;
|
|
|
|
@Autowired
|
|
private ObjectMapper mapper;
|
|
|
|
private static final LocalDateTime FIXED_TIME = LocalDateTime.of(2019, 4, 25, 13, 12);
|
|
|
|
@TestConfiguration
|
|
static class TestConfig {
|
|
@Bean
|
|
public Clock clock() {
|
|
return FakeClock.fixed(FIXED_TIME);
|
|
}
|
|
}
|
|
|
|
@Test
|
|
void forwardMessageReturnsForwardedMessageAndIsAlwaysOK() throws Exception {
|
|
MessageForm form = MessageForm.of("my-token", "subject", "message", "sender@company.com");
|
|
|
|
mockMvc.perform(post("/").contentType(APPLICATION_JSON)
|
|
.content(mapper.writeValueAsString(form)))
|
|
.andExpect(status().isOk())
|
|
.andExpect(content().contentType(APPLICATION_JSON))
|
|
.andExpect(jsonPath("$.subject").value("subject"))
|
|
.andExpect(jsonPath("$.content").value("message"))
|
|
.andExpect(jsonPath("$.from").value("sender@company.com"))
|
|
.andExpect(jsonPath("$.timestamp").value("2019-04-25T13:12:00"));
|
|
|
|
}
|
|
}
|