Add unit and integration tests

This commit is contained in:
root
2026-02-02 15:34:37 +01:00
parent 2774ce0793
commit 9259fa6ca9
5 changed files with 170 additions and 0 deletions
@@ -0,0 +1,49 @@
package de.dev089.eventproducer.web;
import de.dev089.eventproducer.producer.HealthRequestProducer;
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.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest(properties = {
"RABBITMQ_HOST=localhost",
"RABBITMQ_PORT=5672",
"RABBITMQ_USERNAME=guest",
"RABBITMQ_PASSWORD=guest"
})
@AutoConfigureMockMvc
class RequestProducerControllerIT {
@Autowired
private MockMvc mockMvc;
@MockBean
private HealthRequestProducer healthRequestProducer;
@Test
void postPopulate_acceptsValidRequest() throws Exception {
mockMvc.perform(post("/api/events/populate")
.contentType(MediaType.APPLICATION_JSON)
.content("{\"message\":\"hello\"}"))
.andExpect(status().isAccepted());
verify(healthRequestProducer).publishToDefaultQueue(any());
}
@Test
void postPopulate_rejectsInvalidRequest() throws Exception {
mockMvc.perform(post("/api/events/populate")
.contentType(MediaType.APPLICATION_JSON)
.content("{\"message\":\"\"}"))
.andExpect(status().isBadRequest());
}
}