Fix tests for Spring Boot 4 and test config
This commit is contained in:
@@ -3,7 +3,12 @@ package de.dev089.eventproducer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
@SpringBootTest(properties = {
|
||||
"RABBITMQ_HOST=localhost",
|
||||
"RABBITMQ_PORT=5672",
|
||||
"RABBITMQ_USERNAME=guest",
|
||||
"RABBITMQ_PASSWORD=guest"
|
||||
})
|
||||
class EventProducerApplicationTests {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
package de.dev089.eventproducer.web;
|
||||
|
||||
import de.dev089.eventproducer.producer.HealthRequestProducer;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
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.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -20,14 +25,29 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
"RABBITMQ_USERNAME=guest",
|
||||
"RABBITMQ_PASSWORD=guest"
|
||||
})
|
||||
@AutoConfigureMockMvc
|
||||
class RequestProducerControllerIT {
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext context;
|
||||
|
||||
@Autowired
|
||||
private HealthRequestProducer healthRequestProducer;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@MockBean
|
||||
private HealthRequestProducer healthRequestProducer;
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
|
||||
}
|
||||
|
||||
@TestConfiguration
|
||||
static class TestConfig {
|
||||
@Bean
|
||||
@Primary
|
||||
HealthRequestProducer healthRequestProducer() {
|
||||
return Mockito.mock(HealthRequestProducer.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void postPopulate_acceptsValidRequest() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user