Java Code Examples for com.microsoft.azure.PagedList#add()

The following examples show how to use com.microsoft.azure.PagedList#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AzureIDBrokerObjectStorageValidatorTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void testValidateObjectStorageNonExistingMapperIdentity() {
    SpiFileSystem fileSystem = setupSpiFileSystem(true);
    PagedList<Identity> identityPagedList = Mockito.spy(PagedList.class);
    identityPagedList.add(assumer);
    identityPagedList.add(logger);
    when(client.listIdentities()).thenReturn(identityPagedList);

    new RoleASsignmentBuilder(client)
            .withAssignment(ASSUMER_IDENTITY_PRINCIPAL_ID, SUBSCRIPTION_FULL_ID)
            .withAssignment(LOG_IDENTITY_PRINCIPAL_ID, STORAGE_RESOURCE_GROUP_NAME);
    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();

    underTest.validateObjectStorage(client, fileSystem, resultBuilder);

    ValidationResult validationResult = resultBuilder.build();
    assertTrue(validationResult.hasError());
    assertEquals(2, validationResult.getErrors().size());
    List<String> actual = validationResult.getErrors();
    assertTrue(actual.stream().anyMatch(item ->
            item.equals(String.format("Identity with id %s does not exist in the given Azure subscription.", USER_IDENTITY_1))));
    assertTrue(actual.stream().anyMatch(item ->
            item.equals(String.format("Identity with id %s does not exist in the given Azure subscription.", GROUP_IDENTITY_1))));
}
 
Example 2
Source File: AzureCloudResourceServiceTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void getListWithKnownSuccededCloudResource() {
    TargetResource t = new TargetResource();
    t.withResourceType(MICROSOFT_COMPUTE_VIRTUAL_MACHINES);
    t.withResourceName(VM_NAME);
    PagedList<DeploymentOperation> operationList = Mockito.spy(PagedList.class);
    DeploymentOperations operations = Mockito.mock(DeploymentOperations.class);
    DeploymentOperation operation = Mockito.mock(DeploymentOperation.class);
    operationList.add(operation);

    when(deployment.deploymentOperations()).thenReturn(operations);
    when(deployment.deploymentOperations().list()).thenReturn(operationList);
    when(operation.targetResource()).thenReturn(t);
    when(operation.provisioningState()).thenReturn("succeeded");

    List<CloudResource> cloudResourceList = underTest.getDeploymentCloudResources(deployment);

    assertEquals(1, cloudResourceList.size());
    CloudResource cloudResource = cloudResourceList.get(0);
    assertEquals(VM_NAME, cloudResource.getName());
    assertEquals(CommonStatus.CREATED, cloudResource.getStatus());
}
 
Example 3
Source File: AzureCloudResourceServiceTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void getListWithKnownFailedCloudResource() {
    TargetResource t = new TargetResource();
    t.withResourceType(MICROSOFT_COMPUTE_VIRTUAL_MACHINES);
    t.withResourceName(VM_NAME);
    PagedList<DeploymentOperation> operationList = Mockito.spy(PagedList.class);
    DeploymentOperations operations = Mockito.mock(DeploymentOperations.class);
    DeploymentOperation operation = Mockito.mock(DeploymentOperation.class);
    operationList.add(operation);

    when(deployment.deploymentOperations()).thenReturn(operations);
    when(deployment.deploymentOperations().list()).thenReturn(operationList);
    when(operation.targetResource()).thenReturn(t);
    when(operation.provisioningState()).thenReturn("failed");

    List<CloudResource> cloudResourceList = underTest.getDeploymentCloudResources(deployment);

    assertEquals(1, cloudResourceList.size());
    CloudResource cloudResource = cloudResourceList.get(0);
    assertEquals(VM_NAME, cloudResource.getName());
    assertEquals(CommonStatus.FAILED, cloudResource.getStatus());
}
 
Example 4
Source File: AzureCloudResourceServiceTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void getListWithUnknownCloudResource() {
    TargetResource t = new TargetResource();
    t.withResourceType("unknown");
    t.withResourceName(VM_NAME);
    PagedList<DeploymentOperation> operationList = Mockito.spy(PagedList.class);
    DeploymentOperations operations = Mockito.mock(DeploymentOperations.class);
    DeploymentOperation operation = Mockito.mock(DeploymentOperation.class);
    operationList.add(operation);

    when(deployment.deploymentOperations()).thenReturn(operations);
    when(deployment.deploymentOperations().list()).thenReturn(operationList);
    when(operation.targetResource()).thenReturn(t);
    when(operation.provisioningState()).thenReturn("succeeded");

    List<CloudResource> cloudResourceList = underTest.getDeploymentCloudResources(deployment);

    assertEquals(0, cloudResourceList.size());
}
 
Example 5
Source File: AzureVirtualMachineServiceTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private PagedList<VirtualMachine> createPagedListWithOnePage() {
    PagedList<VirtualMachine> pagedList = new PagedList<>() {
        @Override
        public Page<VirtualMachine> nextPage(String nextPageLink) throws RestException {
            return null;
        }

        @Override
        public void loadNextPage() {
        }

        @Override
        public boolean hasNextPage() {
            return false;
        }
    };
    pagedList.add(createVirtualMachine(INSTANCE_1));
    return pagedList;
}
 
Example 6
Source File: AzureIDBrokerObjectStorageValidatorTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidateObjectStorageNoMappedRoles() {
    SpiFileSystem fileSystem = setupSpiFileSystem(true);
    PagedList<Identity> identityPagedList = Mockito.spy(PagedList.class);
    when(assumer.id()).thenReturn(USER_IDENTITY_1);
    when(logger.id()).thenReturn(GROUP_IDENTITY_1);
    identityPagedList.add(assumer);
    identityPagedList.add(logger);
    when(client.listIdentities()).thenReturn(identityPagedList);

    final String wrongAssumerIdentityPrincipalid = "489e3729-aed1-4d54-a95b-b231b70d383f";
    final String wrongLoggerIdentityPrincipalid = "61a70b9b-7331-4fa3-8717-2652fc70434e";

    new RoleASsignmentBuilder(client)
            .withAssignment(wrongAssumerIdentityPrincipalid, SUBSCRIPTION_FULL_ID)
            .withAssignment(wrongLoggerIdentityPrincipalid, STORAGE_RESOURCE_GROUP_NAME);

    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();

    underTest.validateObjectStorage(client, fileSystem, resultBuilder);

    ValidationResult validationResult = resultBuilder.build();
    assertTrue(validationResult.hasError());
    assertEquals(4, validationResult.getErrors().size());
    List<String> actual = validationResult.getErrors();
    assertTrue(actual.stream().anyMatch(item ->
            item.equals(String.format("Identity with id %s has no role assignment.", USER_IDENTITY_1))));
    assertTrue(actual.stream().anyMatch(item ->
            item.equals(String.format("Identity with id %s has no role assignment.", GROUP_IDENTITY_1))));

}
 
Example 7
Source File: AzureCloudResourceServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void getAttachedOsDiskResourcesFound() {
    CloudResource vm1 = createCloudResource(INSTANCE_1, ResourceType.AZURE_INSTANCE);
    CloudResource vm2 = createCloudResource(INSTANCE_2, ResourceType.AZURE_INSTANCE);
    CloudResource vm3 = createCloudResource(INSTANCE_3, ResourceType.AZURE_INSTANCE);
    PagedList<VirtualMachine> virtualMachines = Mockito.spy(PagedList.class);
    VirtualMachine vm = Mockito.mock(VirtualMachine.class);
    StorageProfile storageProfile = Mockito.mock(StorageProfile.class);
    OSDisk osDisk = Mockito.mock(OSDisk.class);
    ManagedDiskParameters managedDiskParameters = Mockito.mock(ManagedDiskParameters.class);
    virtualMachines.add(vm);

    when(vm.name()).thenReturn(INSTANCE_1);
    when(vm.storageProfile()).thenReturn(storageProfile);
    when(vm.storageProfile().osDisk()).thenReturn(osDisk);
    when(osDisk.managedDisk()).thenReturn(managedDiskParameters);
    when(managedDiskParameters.id()).thenReturn("diskId1");
    when(osDisk.name()).thenReturn("diskName1");
    when(ac.getParameter(AzureClient.class)).thenReturn(azureClient);

    when(azureClient.getVirtualMachines("resourceGroupName")).thenReturn(virtualMachines);

    List<CloudResource> osDiskResources = underTest.getAttachedOsDiskResources(ac, List.of(vm1, vm2, vm3), "resourceGroupName");

    assertEquals(1, osDiskResources.size());
    CloudResource diskResource = osDiskResources.get(0);
    assertEquals("diskName1", diskResource.getName());
    assertEquals("diskId1", diskResource.getReference());
}
 
Example 8
Source File: AzureVirtualMachineServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private PagedList<VirtualMachine> createPagedList() {
    PagedList<VirtualMachine> pagedList = new PagedList<>() {
        @Override
        public Page<VirtualMachine> nextPage(String nextPageLink) throws RestException {
            return null;
        }
    };
    pagedList.add(createVirtualMachine(INSTANCE_1));
    pagedList.add(createVirtualMachine(INSTANCE_2));
    pagedList.add(createVirtualMachine(INSTANCE_3));
    return pagedList;
}
 
Example 9
Source File: AzureStorageTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private void setupSubscriptions(AzureClient client) {
    PagedList<Subscription> subscriptionPagedList = Mockito.spy(PagedList.class);

    Subscription subscriptionOne = mock(Subscription.class);
    when(subscriptionOne.subscriptionId()).thenReturn(SUBSCRIPTION_ONE);
    subscriptionPagedList.add(subscriptionOne);

    Subscription subscriptionTwo = mock(Subscription.class);
    when(subscriptionTwo.subscriptionId()).thenReturn(SUBSCRIPTION_ANOTHER);
    subscriptionPagedList.add(subscriptionTwo);

    when(client.listSubscriptions()).thenReturn(subscriptionPagedList);
}