Skip to content

Commit

Permalink
Remove RestClientRetry mock
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmarete committed Feb 13, 2025
1 parent 41a20e2 commit 8355b22
Showing 1 changed file with 3 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -13,7 +11,6 @@
import java.util.List;
import java.util.Map;
import org.databiosphere.workspacedataservice.common.ControlPlaneTestBase;
import org.databiosphere.workspacedataservice.retry.RestClientRetry;
import org.databiosphere.workspacedataservice.service.model.exception.RestException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -32,7 +29,6 @@
class DrsHubClientTest extends ControlPlaneTestBase {

@MockitoBean DrsHubApi mockDrsHubApi;
@MockitoBean RestClientRetry restClientRetry;

@Autowired DrsHubClient drsHubClient;

Expand All @@ -54,13 +50,6 @@ void resolveDrs_ReturnsExpectedResponse() {
ResolveDrsRequest resolveDrsRequest = new ResolveDrsRequest(drsUri, List.of("accessUrl"));

when(mockDrsHubApi.resolveDrs(resolveDrsRequestCaptor.capture())).thenReturn(expectedResponse);
when(restClientRetry.withRetryAndErrorHandling(
any(RestClientRetry.RestCall.class), anyString()))
.thenAnswer(
invocation -> {
RestClientRetry.RestCall<?> restCall = invocation.getArgument(0);
return restCall.run();
});

// ACT
ResourceMetadataResponse response = drsHubClient.resolveDrs(resolveDrsRequest);
Expand All @@ -80,17 +69,9 @@ void resolveDrs_ThrowsNotFound() {

when(mockDrsHubApi.resolveDrs(resolveDrsRequest)).thenThrow(exception);

when(restClientRetry.withRetryAndErrorHandling(
any(RestClientRetry.RestCall.class), anyString()))
.thenThrow(new RestException(HttpStatus.NOT_FOUND, "Not Found"));

// ACT
RestException thrown =
assertThrows(
RestException.class,
() -> {
drsHubClient.resolveDrs(resolveDrsRequest);
});
assertThrows(RestException.class, () -> drsHubClient.resolveDrs(resolveDrsRequest));

// ASSERT
assertEquals(HttpStatus.NOT_FOUND, thrown.getStatusCode());
Expand All @@ -106,17 +87,9 @@ void resolveDrs_ThrowsTimeout() {

when(mockDrsHubApi.resolveDrs(resolveDrsRequest)).thenThrow(exception);

when(restClientRetry.withRetryAndErrorHandling(
any(RestClientRetry.RestCall.class), anyString()))
.thenThrow(new RestException(HttpStatus.GATEWAY_TIMEOUT, "Gateway Timeout"));

// ACT
RestException thrown =
assertThrows(
RestException.class,
() -> {
drsHubClient.resolveDrs(resolveDrsRequest);
});
assertThrows(RestException.class, () -> drsHubClient.resolveDrs(resolveDrsRequest));

// ASSERT
assertEquals(HttpStatus.GATEWAY_TIMEOUT, thrown.getStatusCode());
Expand All @@ -133,17 +106,9 @@ void resolveDrs_ThrowsInternalServerError() {

when(mockDrsHubApi.resolveDrs(resolveDrsRequest)).thenThrow(exception);

when(restClientRetry.withRetryAndErrorHandling(
any(RestClientRetry.RestCall.class), anyString()))
.thenThrow(new RestException(HttpStatus.INTERNAL_SERVER_ERROR, "Internal Server Error"));

// ACT
RestException thrown =
assertThrows(
RestException.class,
() -> {
drsHubClient.resolveDrs(resolveDrsRequest);
});
assertThrows(RestException.class, () -> drsHubClient.resolveDrs(resolveDrsRequest));

// ASSERT
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, thrown.getStatusCode());
Expand Down

0 comments on commit 8355b22

Please sign in to comment.