@Test(expected = InternalException.class) public void lauchShouldThrowExceptionIfVlanIsNotExist() throws CloudException, InternalException { VMLaunchOptions vmLaunchOptions = VMLaunchOptions.getInstance(HWP_1_ID, VHD_1_ID, VM_1_NAME, VM_1_DESCRIPTION); vmLaunchOptions.inVlan(null, DATACENTER_ID, "not-exist-vlan-id"); azurePackVirtualMachineSupport.launch(vmLaunchOptions); }
@Test public void lauchTemplateVMShouldSendCorrectRequest() throws CloudException, InternalException { final AtomicInteger postCount = new AtomicInteger(0); new StartOrStopVirtualMachinesRequestExecutorMockUp("Start") { @Mock public void $init( CloudProvider provider, HttpClientBuilder clientBuilder, HttpUriRequest request, ResponseHandler handler) { String requestUri = request.getURI().toString(); if (request.getMethod().equals("POST") && requestUri.equals(String.format(LIST_VM_RESOURCES, ENDPOINT, ACCOUNT_NO))) { requestResourceType = 21; WAPVirtualMachineModel wapVirtualMachineModel = new WAPVirtualMachineModel(); wapVirtualMachineModel.setName(VM_1_NAME); wapVirtualMachineModel.setCloudId(REGION); wapVirtualMachineModel.setStampId(DATACENTER_ID); wapVirtualMachineModel.setVmTemplateId(TPL_1_ID); wapVirtualMachineModel.setProductKey(VM_1_WINDOWS_SERIAL_NUMBER); wapVirtualMachineModel.setLocalAdminUserName(VM_1_BOOTSTRAP_USER); wapVirtualMachineModel.setLocalAdminPassword(VM_1_BOOTSTRAP_PASSWORD); List<WAPNewAdapterModel> adapters = new ArrayList<>(); WAPNewAdapterModel newAdapterModel = new WAPNewAdapterModel(); newAdapterModel.setVmNetworkName(VM_1_NETWORK_NAME); adapters.add(newAdapterModel); wapVirtualMachineModel.setNewVirtualNetworkAdapterInput(adapters); assertPost( request, String.format(LIST_VM_RESOURCES, ENDPOINT, ACCOUNT_NO), new Header[0], wapVirtualMachineModel); } else { super.$init(provider, clientBuilder, request, handler); } responseHandler = handler; } @Mock public Object execute() { if (requestResourceType == 21) { postCount.incrementAndGet(); return mapFromModel(this.responseHandler, createWAPVirtualMachineModel()); } else { return super.execute(); } } }; VMLaunchOptions vmLaunchOptions = VMLaunchOptions.getInstance(HWP_1_ID, TPL_1_ID, VM_1_NAME, VM_1_DESCRIPTION); vmLaunchOptions.inVlan(null, DATACENTER_ID, VM_1_NETWORK_ID); vmLaunchOptions.withWinProductSerialNum(VM_1_WINDOWS_SERIAL_NUMBER); vmLaunchOptions.withBootstrapUser("dummy-user-name-to-be-replaced", VM_1_BOOTSTRAP_PASSWORD); VirtualMachine virtualMachine = azurePackVirtualMachineSupport.launch(vmLaunchOptions); assertEquals("terminate doesn't send DELETE request", 1, postCount.get()); assertVirtualMachine(virtualMachine); }
@Test(expected = InternalException.class) public void lauchShouldThrowExceptionIfLaunchFromVHDWithDefaultProduct() throws CloudException, InternalException { final AtomicInteger postCount = new AtomicInteger(0); new StartOrStopVirtualMachinesRequestExecutorMockUp("Start") { @Mock public void $init( CloudProvider provider, HttpClientBuilder clientBuilder, HttpUriRequest request, ResponseHandler handler) { String requestUri = request.getURI().toString(); if (request.getMethod().equals("POST") && requestUri.equals(String.format(LIST_VM_RESOURCES, ENDPOINT, ACCOUNT_NO))) { requestResourceType = 21; WAPVirtualMachineModel wapVirtualMachineModel = new WAPVirtualMachineModel(); wapVirtualMachineModel.setName(VM_1_NAME); wapVirtualMachineModel.setCloudId(REGION); wapVirtualMachineModel.setStampId(DATACENTER_ID); wapVirtualMachineModel.setVirtualHardDiskId(VHD_1_ID); wapVirtualMachineModel.setHardwareProfileId(HWP_1_ID); List<WAPNewAdapterModel> adapters = new ArrayList<>(); WAPNewAdapterModel newAdapterModel = new WAPNewAdapterModel(); newAdapterModel.setVmNetworkName(VM_1_NETWORK_NAME); adapters.add(newAdapterModel); wapVirtualMachineModel.setNewVirtualNetworkAdapterInput(adapters); } else { super.$init(provider, clientBuilder, request, handler); } responseHandler = handler; } @Mock public Object execute() { if (requestResourceType == 21) { postCount.incrementAndGet(); return mapFromModel(this.responseHandler, createWAPVirtualMachineModel()); } else { return super.execute(); } } }; VMLaunchOptions vmLaunchOptions = VMLaunchOptions.getInstance("default", VHD_1_ID, VM_1_NAME, VM_1_DESCRIPTION); vmLaunchOptions.inVlan(null, DATACENTER_ID, VM_1_NETWORK_ID); azurePackVirtualMachineSupport.launch(vmLaunchOptions); }
@Test(expected = InternalException.class) public void lauchShouldThrowExceptionIfImageIsNotExist() throws CloudException, InternalException { VMLaunchOptions vmLaunchOptions = VMLaunchOptions.getInstance(HWP_1_ID, "not-exist-image-id", VM_1_NAME, VM_1_DESCRIPTION); azurePackVirtualMachineSupport.launch(vmLaunchOptions); }