-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
throw retry/non retry errors on api status response error
- Loading branch information
1 parent
5c7182c
commit 5269fcb
Showing
7 changed files
with
105 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
...ain/java/uk/gov/companieshouse/disqualifiedofficers/delta/handler/ApiResponseHandler.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 0 additions & 64 deletions
64
...java/uk/gov/companieshouse/disqualifiedofficers/delta/handler/ApiResponseHandlerTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...v/companieshouse/disqualifiedofficers/delta/service/api/BaseApiClientServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package uk.gov.companieshouse.disqualifiedofficers.delta.service.api; | ||
|
||
import com.google.api.client.http.HttpHeaders; | ||
import com.google.api.client.http.HttpResponseException.Builder; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import uk.gov.companieshouse.api.error.ApiErrorResponseException; | ||
import uk.gov.companieshouse.api.handler.Executor; | ||
import uk.gov.companieshouse.api.handler.exception.URIValidationException; | ||
import uk.gov.companieshouse.api.model.ApiResponse; | ||
import uk.gov.companieshouse.disqualifiedofficers.delta.exception.NonRetryableErrorException; | ||
import uk.gov.companieshouse.disqualifiedofficers.delta.exception.RetryableErrorException; | ||
import uk.gov.companieshouse.logging.Logger; | ||
|
||
import java.util.HashMap; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.Assert.assertThrows; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class BaseApiClientServiceImplTest { | ||
|
||
private BaseApiClientServiceImpl service; | ||
|
||
@Mock | ||
private Logger logger; | ||
@Mock | ||
private Executor executor; | ||
|
||
@BeforeEach | ||
void setup() { | ||
service = new BaseApiClientServiceImpl(logger) {}; | ||
} | ||
|
||
@Test | ||
void returnsApiResponse() throws Exception { | ||
ApiResponse expectedResponse = new ApiResponse(200, new HashMap<>()); | ||
when(executor.execute()).thenReturn(expectedResponse); | ||
|
||
ApiResponse actualResponse = service.executeOp(null, null, null, executor); | ||
|
||
assertThat(actualResponse).isEqualTo(expectedResponse); | ||
} | ||
|
||
@Test | ||
void throwsRetryableErrorOn404() throws Exception { | ||
when(executor.execute()).thenThrow(new URIValidationException("Not Found")); | ||
|
||
RetryableErrorException thrown = assertThrows(RetryableErrorException.class, | ||
() -> service.executeOp(null, null, null, executor)); | ||
|
||
assertThat(thrown.getMessage()).isEqualTo("404 NOT_FOUND response received from disqualified-officers-data-api"); | ||
} | ||
|
||
@Test | ||
void throwsRetryableErrorOn500() throws Exception { | ||
when(executor.execute()).thenThrow( | ||
new ApiErrorResponseException(new Builder(500, "500", new HttpHeaders()))); | ||
|
||
RetryableErrorException thrown = assertThrows(RetryableErrorException.class, | ||
() -> service.executeOp(null, null, null, executor)); | ||
|
||
assertThat(thrown.getMessage()).isEqualTo("Non-Successful response received from disqualified-officers-data-api"); | ||
} | ||
|
||
@Test | ||
void throwsNonRetryableErrorOn400() throws Exception { | ||
when(executor.execute()).thenThrow( | ||
new ApiErrorResponseException(new Builder(400, "400", new HttpHeaders()))); | ||
|
||
NonRetryableErrorException thrown = assertThrows(NonRetryableErrorException.class, | ||
() -> service.executeOp(null, null, null, executor)); | ||
|
||
assertThat(thrown.getMessage()).isEqualTo("400 BAD_REQUEST response received from disqualified-officers-data-api"); | ||
} | ||
} |