Search in sources :

Example 1 with SyncPoller

use of com.azure.core.util.polling.SyncPoller in project bulk-scan-processor by hmcts.

the class BlobManagerTest method mockBeginCopy.

private void mockBeginCopy(String url, String sasToken) {
    given(inputBlobClient.getBlobUrl()).willReturn(url);
    given(inputBlobClient.generateSas(any())).willReturn(sasToken);
    SyncPoller syncPoller = mock(SyncPoller.class);
    given(rejectedBlobClient.beginCopy(url + "?" + sasToken, BlobManager.META_DATA_MAP, null, null, null, null, Duration.ofSeconds(2))).willReturn(syncPoller);
    var pollResponse = mock(PollResponse.class);
    var blobCopyInfo = mock(BlobCopyInfo.class);
    given(syncPoller.waitForCompletion(Duration.ofMinutes(5))).willReturn(pollResponse);
    given(pollResponse.getValue()).willReturn(mock(BlobCopyInfo.class));
    given(pollResponse.getValue()).willReturn(blobCopyInfo);
}
Also used : SyncPoller(com.azure.core.util.polling.SyncPoller) BlobCopyInfo(com.azure.storage.blob.models.BlobCopyInfo)

Example 2 with SyncPoller

use of com.azure.core.util.polling.SyncPoller in project bulk-scan-processor by hmcts.

the class BlobManagerTest method tryMoveFileToRejectedContainer_should_abort_copy_when_begincopy_fails.

@Test
void tryMoveFileToRejectedContainer_should_abort_copy_when_begincopy_fails() {
    given(inputContainerClient.getBlobClient(INPUT_FILE_NAME)).willReturn(inputBlobClient);
    given(rejectedContainerClient.getBlobClient(INPUT_FILE_NAME)).willReturn(rejectedBlobClient);
    given(blobServiceClient.getBlobContainerClient(INPUT_CONTAINER_NAME)).willReturn(inputContainerClient);
    given(blobServiceClient.getBlobContainerClient(REJECTED_CONTAINER_NAME)).willReturn(rejectedContainerClient);
    SyncPoller syncPoller = mock(SyncPoller.class);
    given(rejectedBlobClient.beginCopy(any(), any(), any(), any(), any(), any(), any())).willReturn(syncPoller);
    var pollResponse = mock(PollResponse.class);
    willThrow(new RuntimeException("Copy Failed")).given(syncPoller).waitForCompletion(Duration.ofMinutes(5));
    var blobCopyInfo = mock(BlobCopyInfo.class);
    given(syncPoller.poll()).willReturn(pollResponse);
    given(pollResponse.getValue()).willReturn(blobCopyInfo);
    String copyId = UUID.randomUUID().toString();
    given(blobCopyInfo.getCopyId()).willReturn(copyId);
    // whenc
    blobManager.tryMoveFileToRejectedContainer(INPUT_FILE_NAME, INPUT_CONTAINER_NAME);
    // then
    verify(rejectedBlobClient).beginCopy(any(), any(), any(), any(), any(), any(), any());
    verify(rejectedBlobClient).abortCopyFromUrl(copyId);
    verify(inputBlobClient, never()).deleteWithResponse(any(), any(), any(), any());
}
Also used : SyncPoller(com.azure.core.util.polling.SyncPoller) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

SyncPoller (com.azure.core.util.polling.SyncPoller)2 BlobCopyInfo (com.azure.storage.blob.models.BlobCopyInfo)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1