-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #848 from anuchandy/vmsize
Adding unit test for VirtualMachineSizes, adding VirtualMachines.avai…
- Loading branch information
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
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
59 changes: 59 additions & 0 deletions
59
azure/src/test/java/com/microsoft/azure/TestVirtualMachineSizes.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,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) { | ||
|
||
} | ||
} |