Skip to content

Commit

Permalink
#434 - Replace deprecated MockBeans
Browse files Browse the repository at this point in the history
- replace @MockBean with @MockitoBean
  • Loading branch information
michael-82 committed Jan 24, 2025
1 parent 3878f77 commit 80a630a
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;

Expand Down Expand Up @@ -43,10 +43,10 @@ class DseRestControllerIT {
@Autowired
private ObjectMapper jsonUtil;

@MockBean
@MockitoBean
private DseService dseService;

@MockBean
@MockitoBean
private RateLimitingInterceptor rateLimitingInterceptor;

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.testcontainers.junit.jupiter.Testcontainers;

import static de.numcodex.feasibility_gui_backend.query.QueryHandlerService.ResultDetail.DETAILED;
Expand Down Expand Up @@ -101,7 +101,7 @@ public class QueryHandlerServiceIT {
@Autowired
private QueryHashCalculator queryHashCalculator;

@MockBean
@MockitoBean
private StructuredQueryValidation structuredQueryValidation;

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import org.junit.jupiter.params.provider.EnumSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.security.core.Authentication;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;

Expand All @@ -61,16 +61,16 @@ public class RateLimitingInterceptorIT {
@Autowired
private MockMvc mockMvc;

@MockBean
@MockitoBean
private QueryHandlerService queryHandlerService;

@MockBean
@MockitoBean
private StructuredQueryValidation structuredQueryValidation;

@MockBean
@MockitoBean
AuthenticationHelper authenticationHelper;

@MockBean
@MockitoBean
private UserBlacklistRepository userBlacklistRepository;

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -77,19 +77,19 @@ public class QueryHandlerRestControllerIT {
@Autowired
private ObjectMapper jsonUtil;

@MockBean
@MockitoBean
private QueryHandlerService queryHandlerService;

@MockBean
@MockitoBean
private StructuredQueryValidation structuredQueryValidation;

@MockBean
@MockitoBean
private RateLimitingInterceptor rateLimitingInterceptor;

@MockBean
@MockitoBean
private UserBlacklistRepository userBlacklistRepository;

@MockBean
@MockitoBean
private AuthenticationHelper authenticationHelper;

@Value("${app.privacy.quota.soft.create.amount}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;

Expand Down Expand Up @@ -63,13 +63,13 @@ public class QueryTemplateHandlerRestControllerIT {
@Autowired
private ObjectMapper jsonUtil;

@MockBean
@MockitoBean
private QueryHandlerService queryHandlerService;

@MockBean
@MockitoBean
private StructuredQueryValidation structuredQueryValidation;

@MockBean
@MockitoBean
private AuthenticationHelper authenticationHelper;

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.IOException;
import java.util.List;

import static java.lang.Thread.sleep;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
Expand Down Expand Up @@ -61,7 +62,7 @@ public class TerminologyEsServiceIT {
.waitingFor(Wait.forHttp("/health").forStatusCodeMatching(c -> c >= 200 && c <= 500));

@BeforeAll
static void setUp() throws IOException {
static void setUp() throws IOException, InterruptedException {
ELASTICSEARCH_CONTAINER.start();
System.out.println(ELASTICSEARCH_CONTAINER.getHttpHostAddress());
WebClient webClient = WebClient.builder().baseUrl("http://" + ELASTICSEARCH_CONTAINER.getHttpHostAddress()).build();
Expand All @@ -78,6 +79,10 @@ static void setUp() throws IOException {
.retrieve()
.toBodilessEntity()
.block();

// There may be a timing issue when there is no short sleep here, leading to tests failing because the data is not fully loaded
// Although the commands to upload the data are blocking
sleep(1000);
}

@AfterAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;

Expand Down Expand Up @@ -47,10 +47,10 @@ class CodeableConceptRestControllerIT {
@Autowired
private ObjectMapper jsonUtil;

@MockBean
@MockitoBean
private CodeableConceptService codeableConceptService;

@MockBean
@MockitoBean
private RateLimitingInterceptor rateLimitingInterceptor;

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
Expand Down Expand Up @@ -53,16 +53,16 @@ public class TerminologyRestControllerIT {
@Autowired
private ObjectMapper jsonUtil;

@MockBean
@MockitoBean
private StructuredQueryValidation structuredQueryValidation;

@MockBean
@MockitoBean
private TerminologyService terminologyService;

@MockBean
@MockitoBean
private TerminologyEsService terminologyEsService;

@MockBean
@MockitoBean
private RateLimitingInterceptor rateLimitingInterceptor;

@Test
Expand Down

0 comments on commit 80a630a

Please sign in to comment.