generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DMP-4141 (Dev Only) ARM RPO - Integrate downloadProduction (#2253)
- Loading branch information
1 parent
5c0f772
commit a05f8ef
Showing
7 changed files
with
321 additions
and
55 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
src/integrationTest/java/uk/gov/hmcts/darts/arm/rpo/ArmRpoApiDownloadProductionIntTest.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,94 @@ | ||
package uk.gov.hmcts.darts.arm.rpo; | ||
|
||
import feign.FeignException; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import uk.gov.hmcts.darts.arm.client.ArmRpoClient; | ||
import uk.gov.hmcts.darts.arm.exception.ArmRpoException; | ||
import uk.gov.hmcts.darts.common.entity.ArmRpoExecutionDetailEntity; | ||
import uk.gov.hmcts.darts.common.entity.UserAccountEntity; | ||
import uk.gov.hmcts.darts.common.enums.ArmRpoStateEnum; | ||
import uk.gov.hmcts.darts.common.enums.ArmRpoStatusEnum; | ||
import uk.gov.hmcts.darts.testutils.IntegrationBase; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.junit.Assert.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
@SuppressWarnings("PMD.CloseResource") | ||
class ArmRpoApiDownloadProductionIntTest extends IntegrationBase { | ||
|
||
@MockBean | ||
private ArmRpoClient armRpoClient; | ||
|
||
@Autowired | ||
private ArmRpoApi armRpoApi; | ||
|
||
|
||
@Test | ||
void downloadProductionSuccess() throws IOException { | ||
// given | ||
feign.Response response = mock(feign.Response.class); | ||
when(response.status()).thenReturn(200); | ||
InputStream inputStream = mock(InputStream.class); | ||
feign.Response.Body body = mock(feign.Response.Body.class); | ||
when(response.body()).thenReturn(body); | ||
when(body.asInputStream()).thenReturn(inputStream); | ||
when(armRpoClient.downloadProduction(anyString(), anyString())).thenReturn(response); | ||
|
||
UserAccountEntity userAccount = dartsDatabase.getUserAccountStub().getIntegrationTestUserAccountEntity(); | ||
ArmRpoExecutionDetailEntity armRpoExecutionDetailEntity = new ArmRpoExecutionDetailEntity(); | ||
armRpoExecutionDetailEntity.setCreatedBy(userAccount); | ||
armRpoExecutionDetailEntity.setLastModifiedBy(userAccount); | ||
var armRpoExecutionDetail = dartsPersistence.save(armRpoExecutionDetailEntity); | ||
|
||
|
||
// when | ||
try (InputStream result = | ||
armRpoApi.downloadProduction("token", armRpoExecutionDetailEntity.getId(), "productionExportId", userAccount)) { | ||
// then | ||
assertNotNull(result); | ||
} | ||
|
||
// then | ||
var armRpoExecutionDetailEntityUpdated = dartsPersistence.getArmRpoExecutionDetailRepository().findById(armRpoExecutionDetail.getId()).get(); | ||
assertEquals(ArmRpoStateEnum.DOWNLOAD_PRODUCTION.getId(), armRpoExecutionDetailEntityUpdated.getArmRpoState().getId()); | ||
assertEquals(ArmRpoStatusEnum.COMPLETED.getId(), armRpoExecutionDetailEntityUpdated.getArmRpoStatus().getId()); | ||
|
||
} | ||
|
||
@Test | ||
void downloadProductionThrowsFeignException() { | ||
// given | ||
when(armRpoClient.downloadProduction(anyString(), anyString())).thenThrow(FeignException.class); | ||
|
||
UserAccountEntity userAccount = dartsDatabase.getUserAccountStub().getIntegrationTestUserAccountEntity(); | ||
ArmRpoExecutionDetailEntity armRpoExecutionDetailEntity = new ArmRpoExecutionDetailEntity(); | ||
armRpoExecutionDetailEntity.setCreatedBy(userAccount); | ||
armRpoExecutionDetailEntity.setLastModifiedBy(userAccount); | ||
var armRpoExecutionDetail = dartsPersistence.save(armRpoExecutionDetailEntity); | ||
|
||
// when | ||
ArmRpoException armRpoException = assertThrows(ArmRpoException.class, () -> | ||
armRpoApi.downloadProduction("token", armRpoExecutionDetailEntity.getId(), "productionExportId", userAccount)); | ||
|
||
|
||
// then | ||
assertThat(armRpoException.getMessage(), containsString( | ||
"Failure during download production: Error during ARM RPO download production id: productionExportId")); | ||
|
||
var armRpoExecutionDetailEntityUpdated = dartsPersistence.getArmRpoExecutionDetailRepository().findById(armRpoExecutionDetail.getId()).get(); | ||
assertEquals(ArmRpoStateEnum.DOWNLOAD_PRODUCTION.getId(), armRpoExecutionDetailEntityUpdated.getArmRpoState().getId()); | ||
assertEquals(ArmRpoStatusEnum.FAILED.getId(), armRpoExecutionDetailEntityUpdated.getArmRpoStatus().getId()); | ||
|
||
} | ||
} |
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
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
Oops, something went wrong.