use of com.azure.core.http.rest.PagedIterable in project bulk-scan-processor by hmcts.
the class BlobContainerInfoContributorTest method should_return_info_about_application.
@Test
@SuppressWarnings("unchecked")
public void should_return_info_about_application() throws Exception {
PagedIterable pagedIterable = mock(PagedIterable.class);
given(blobServiceClient.listBlobContainers()).willReturn(pagedIterable);
given(pagedIterable.stream()).willReturn(Stream.of(new BlobContainerItem().setName("sscs"), new BlobContainerItem().setName("bulkscan"), new BlobContainerItem().setName("sscs-rejected")));
this.mockMvc.perform(get("/info")).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.containers[0]").value("sscs")).andExpect(jsonPath("$.containers[1]").value("bulkscan")).andExpect(jsonPath("$.containers[2]").value("sscs-rejected"));
}
use of com.azure.core.http.rest.PagedIterable in project bulk-scan-processor by hmcts.
the class BlobManagerTest method listInputContainers_retrieves_input_containers_from_client.
@Test
void listInputContainers_retrieves_input_containers_from_client() {
List<BlobContainerItem> allContainers = Arrays.asList(mockBlobContainerItem("test1"), mockBlobContainerItem("test1-rejected"), mockBlobContainerItem("test2"));
PagedIterable pagedIterable = mock(PagedIterable.class);
given(blobServiceClient.listBlobContainers()).willReturn(pagedIterable);
given(pagedIterable.stream()).willReturn(allContainers.stream());
given(blobManagementProperties.getBlobSelectedContainer()).willReturn("all");
BlobContainerClient test1ContainerClient = mock(BlobContainerClient.class);
BlobContainerClient test2ContainerClient = mock(BlobContainerClient.class);
given(blobServiceClient.getBlobContainerClient("test1")).willReturn(test1ContainerClient);
given(blobServiceClient.getBlobContainerClient("test2")).willReturn(test2ContainerClient);
List<BlobContainerClient> containers = blobManager.listInputContainerClients();
assertThat(containers).hasSameElementsAs(Arrays.asList(test1ContainerClient, test2ContainerClient));
verify(blobServiceClient, times(2)).getBlobContainerClient(anyString());
verifyNoMoreInteractions(blobServiceClient);
}
use of com.azure.core.http.rest.PagedIterable in project bulk-scan-processor by hmcts.
the class BlobManagerTest method listRejectedContainers_retrieves_rejected_containers_only.
@Test
void listRejectedContainers_retrieves_rejected_containers_only() {
// given
List<BlobContainerItem> allContainers = Arrays.asList(mockBlobContainerItem("test1"), mockBlobContainerItem("test1-rejected"), mockBlobContainerItem("test2"), mockBlobContainerItem("test2-rejected"));
PagedIterable pagedIterable = mock(PagedIterable.class);
given(blobServiceClient.listBlobContainers()).willReturn(pagedIterable);
given(pagedIterable.stream()).willReturn(allContainers.stream());
given(blobServiceClient.getBlobContainerClient(anyString())).willReturn(mock(BlobContainerClient.class));
// when
List<BlobContainerClient> rejectedContainers = blobManager.listRejectedContainers();
// then
assertThat(rejectedContainers.size()).isEqualTo(2);
var conditionCapturer = ArgumentCaptor.forClass(String.class);
verify(blobServiceClient, times(2)).getBlobContainerClient(conditionCapturer.capture());
assertThat(conditionCapturer.getAllValues()).hasSameElementsAs(Arrays.asList("test1-rejected", "test2-rejected"));
}
use of com.azure.core.http.rest.PagedIterable in project bulk-scan-processor by hmcts.
the class RejectedFilesReportServiceTest method setUpContainer.
@SuppressWarnings("unchecked")
private void setUpContainer(BlobContainerClient container, List<BlobItem> listBlobItems) {
PagedIterable pagedIterable = mock(PagedIterable.class);
given(pagedIterable.stream()).willReturn(listBlobItems.stream());
given(container.listBlobs(any(), eq(null))).willReturn(pagedIterable);
}
use of com.azure.core.http.rest.PagedIterable in project vividus by vividus-framework.
the class BlobStorageSteps method findBlobs.
/**
* Finds blobs with names filtered by the specified rules in the container.
*
* @param filter Filter to apply to blob names.
* <div>Example:</div>
* <code>
* <br>When I filter blobs by:
* <br>|blobNamePrefix|blobNameFilterRule|blobNameFilterValue|resultsLimit|
* <br>|data/ |contains |file-key.txt |10 |
* <br>in container `global` of storage account `storage`
* <br> and save result to story variable `blobs`
* </code>
* <br>
* <br>where all filters are optional, but at least one rule is required.
* <ul>
* <li><code>blobNameFilterRule</code> The blob name comparison rule: "is equal to",
* "contains", "does not contain" or "matches".
* Should be specified along with <i>blobNameFilterValue</i>.</li>
* <li><code>blobNameFilterValue</code> The full or partial blob name to be matched.
* Should be specified along with <i>blobNameFilterRule</i>.</li>
* <li><code>blobNamePrefix</code> The prefix which blob names should start with.</li>
* <li><code>resultsLimit</code> Maximum number of blob names to return.</li>
* </ul>
* @param containerName The name of the container to point to.
* @param storageAccountKey The key to Storage Account endpoint.
* @param scopes The set (comma separated list of scopes e.g.: STORY, NEXT_BATCHES) of the variable
* scopes.<br>
* <i>Available scopes:</i>
* <ul>
* <li><b>STEP</b> - the variable will be available only within the step,
* <li><b>SCENARIO</b> - the variable will be available only within the scenario,
* <li><b>STORY</b> - the variable will be available within the whole story,
* <li><b>NEXT_BATCHES</b> - the variable will be available starting from next batch
* </ul>
* @param variableName The variable name to store the list of found blob names.
*/
@When("I filter blobs by:$filter in container `$containerName` of storage account `$storageAccountKey`" + " and save result to $scopes variable `$variableName`")
public void findBlobs(BlobFilter filter, String containerName, String storageAccountKey, Set<VariableScope> scopes, String variableName) {
BlobContainerClient blobContainerClient = createBlobContainerClient(containerName, storageAccountKey);
ListBlobsOptions options = new ListBlobsOptions();
filter.getBlobNamePrefix().ifPresent(options::setPrefix);
options.setMaxResultsPerPage(filter.getResultsLimit().map(limit -> Math.min(limit, DEFAULT_MAX_RESULTS_PER_PAGE)).orElse(DEFAULT_MAX_RESULTS_PER_PAGE));
PagedIterable<BlobItem> blobItems = blobContainerClient.listBlobs(options, null);
Stream<String> blobNames = StreamSupport.stream(blobItems.iterableByPage().spliterator(), false).map(PagedResponse::getValue).flatMap(List::stream).map(BlobItem::getName);
Stream<String> filteredBlobNames = filter.getBlobNameMatcher().map(matcher -> blobNames.filter(matcher::matches)).orElse(blobNames);
List<String> result = filter.getResultsLimit().map(filteredBlobNames::limit).orElse(filteredBlobNames).collect(Collectors.toList());
variableContext.putVariable(scopes, variableName, result);
}
Aggregations