I was earlier using the management.port in the application yaml for the management endpoint port. However, changed it to using as in the below application yaml file. It has been failing my actuator test for the health endpoint. The endpoint works as normal when i run the application.
application.yaml
spring:
profiles.active: development
management:
endpoints:
web:
exposure:
include: "*"
server:
port: 9000
server:
port: 8000
---
spring:
profiles: development
logging:
level:
root: INFO
org.springframework.web: INFO
---
spring:
profiles: staging
logging:
level:
root: ERROR
org.springframework.web: ERROR
Integration Test Class
package com.rps;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import com.rps.infrastructure.repository.PlayersInMemoryRepository;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
/**
* Integration testing the actual API Check the guide here: https://spring.io/guides/gs/testing-web/
*/
@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)
public class RPSApplicationIT {
@Autowired
private WebApplicationContext context;
@Autowired
private PlayersInMemoryRepository playersInMemoryRepository;
private MockMvc mockMvc;
@Before
public void setupMockMvc() {
mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
}
@Test
public void shouldReturnActuatorHealthResponse() throws Exception {
this.mockMvc.perform(get("/actuator/health"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(content().json("{\"status\":\"UP\"}"));
}
}