package com.mattrixwv.cipherstream.controller; import static org.mockito.Mockito.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.slf4j.Logger; import org.slf4j.spi.MDCAdapter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.context.annotation.Import; import org.springframework.test.web.servlet.MockMvc; import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect; import com.mattrixwv.cipherstream.config.FullFilter; @Tag("integration-test") @WebMvcTest(controllers = HealthCheckController.class) @Import({AopAutoConfiguration.class, FullFilter.class, CipherStreamLoggingAspect.class}) public class HealthCheckControllerIntegrationTest{ @Autowired private MockMvc mockMvc; //MDC @Mock private MDCAdapter mdc; //Logging @Mock(name = "com.mattrixwv.cipherstream.controller.HealthCheckController") private Logger healthLogger; @Mock(name = "com.mattrixwv.cipherstream.config.FullFilter") private Logger filterLogger; @Mock(name = "com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect") protected Logger aspectLogger; @Test public void testHealthCheck() throws Exception{ mockMvc.perform(options("/health")) .andExpect(status().isOk()); //Verify results verify(healthLogger, times(1)).debug("Health check"); verifyNoInteractions(filterLogger); verifyNoInteractions(aspectLogger); verify(mdc, times(1)).clear(); verifyNoMoreInteractions(mdc); } }