I'm trying to test a customized actuator endpoint in springboot.
The endpoint is:
@Component
@RestControllerEndpoint(id = "test")
public class TestController {
@PostMapping("/1")
public ResponseEntity<?> testEndpoint(Request request) {
}
}
Then I use MockMvc,
@SpringBootTest
@ActiveProfiles("test")
public class MyControllerTest {
@Autowired
private MyController myController;
@BeforeEach
public void setup() {
this.mock =
MockMvcBuilders.standaloneSetup(myController)
.build();
}
@Test
public void test_1() throws Exception {
Request request = new Request();
request.setStatus("ok");
mock.perform(
post("/1")
.contentType(MediaType.APPLICATION_JSON)
.content(mapper.writeValueAsString(request))
.andExpect(status().isOk())
.andReturn();
}
}
Both post("/test/1") and post("/1") get 404 error. This MockMvc test works for normal controllers.
java.lang.AssertionError: Status expected:<200> but was:<404>
Expected :200
Actual :404
And .yml file is
management:
server.port: 8081
endpoints:
web:
base-path: /api/v1/mycontext
Thanks in advance.