Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding unit test for VirtualMachineSizes, adding VirtualMachines.avai… #848

Merged
merged 2 commits into from
Jun 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.microsoft.azure.CloudException;
import com.microsoft.azure.PagedList;
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup;
Expand Down Expand Up @@ -31,6 +32,16 @@ public interface VirtualMachines extends
*/
PagedList<VirtualMachineSize> availableSizesByRegion(String region) throws CloudException, IOException;

/**
* Lists all available virtual machine sizes in a region.
*
* @param region The {@link Region} upon which virtual-machine-sizes is queried.
* @return the List&lt;VirtualMachineSize&gt; if successful.
* @throws CloudException thrown for an invalid response from the service.
* @throws IOException thrown for IO exception.
*/
PagedList<VirtualMachineSize> availableSizesByRegion(Region region) throws CloudException, IOException;

/**
* Shuts down the Virtual Machine and releases the compute resources.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.microsoft.azure.management.compute.implementation.api.VirtualMachineCaptureParametersInner;
import com.microsoft.azure.management.compute.implementation.api.VirtualMachineCaptureResultInner;
import com.microsoft.azure.management.network.implementation.NetworkManager;
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter;
import com.microsoft.azure.management.resources.implementation.ResourceManager;
Expand Down Expand Up @@ -123,6 +124,11 @@ public Page<VirtualMachineSizeInner> nextPage(String nextPageLink) throws RestEx
});
}

@Override
public PagedList<VirtualMachineSize> availableSizesByRegion(Region region) throws CloudException, IOException {
return this.availableSizesByRegion(region.toString());
}

@Override
public void deallocate(String groupName, String name) throws CloudException, IOException, InterruptedException {
this.client.deallocate(groupName, name);
Expand Down
5 changes: 5 additions & 0 deletions azure/src/test/java/com/microsoft/azure/AzureTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ public void setup() throws Exception {
.runTest(azure.virtualMachines(), azure.resourceGroups());
}

@Test public void testVirtualMachineSizes() throws Exception {
new TestVirtualMachineSizes()
.runTest(azure.virtualMachines(), azure.resourceGroups());
}

@Test
public void listSubscriptions() throws Exception {
Assert.assertTrue(0 < subscriptions.list().size());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.microsoft.azure;

import com.microsoft.azure.management.compute.KnownWindowsVirtualMachineImage;
import com.microsoft.azure.management.compute.VirtualMachine;
import com.microsoft.azure.management.compute.VirtualMachineSize;
import com.microsoft.azure.management.compute.VirtualMachines;
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import org.junit.Assert;

import java.util.List;

public class TestVirtualMachineSizes extends TestTemplate<VirtualMachine, VirtualMachines> {
@Override
public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exception {
List<VirtualMachineSize> availableSizes = virtualMachines.availableSizesByRegion(Region.US_EAST);
Assert.assertTrue(availableSizes.size() > 0);

final String vmName = "vm" + this.testId;
VirtualMachine vm = virtualMachines.define(vmName)
.withRegion(Region.US_EAST)
.withNewGroup()
.withNewPrimaryNetwork("10.0.0.0/28")
.withPrimaryPrivateIpAddressDynamic()
.withoutPrimaryPublicIpAddress()
.withPopularWindowsImage(KnownWindowsVirtualMachineImage.WINDOWS_SERVER_2012_R2_DATACENTER)
.withAdminUserName("testuser")
.withPassword("12NewPA$$w0rd!")
.withSize(availableSizes.get(0).name()) // Use the first size
.create();

Assert.assertTrue(vm.size().equalsIgnoreCase(availableSizes.get(0).name()));
return vm;
}

@Override
public VirtualMachine updateResource(VirtualMachine virtualMachine) throws Exception {
List<VirtualMachineSize> resizableSizes = virtualMachine.availableSizes();
Assert.assertTrue(resizableSizes.size() > 1);
VirtualMachineSize newSize = null;
for (VirtualMachineSize resizableSize : resizableSizes) {
if (!resizableSize.name().equalsIgnoreCase(virtualMachine.size())) {
newSize = resizableSize;
break;
}
}
Assert.assertNotNull(newSize);
virtualMachine = virtualMachine.update()
.withSize(newSize.name())
.apply();

Assert.assertTrue(virtualMachine.size().equalsIgnoreCase(newSize.name()));
return virtualMachine;
}

@Override
public void print(VirtualMachine virtualMachine) {

}
}