Skip to content
This repository has been archived by the owner on Jul 25, 2020. It is now read-only.

Commit

Permalink
Implements VirtualMachineAPI deallocate operation
Browse files Browse the repository at this point in the history
https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/deallocate

Adds missing mock test
Fixes returning codes from API methods to 202
  • Loading branch information
danielestevez committed Jul 9, 2018
1 parent 00b6697 commit 7003cee
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.net.URI;
import java.util.List;
import java.util.Map;

import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
Expand Down Expand Up @@ -114,6 +113,11 @@ VirtualMachine createOrUpdate(@PathParam("vmname") String vmname,
@Path("/{name}/powerOff")
void stop(@PathParam("name") String name);

@Named("DeallocateVirtualMachine")
@POST
@Path("/{name}/deallocate")
void deallocate(@PathParam("name") String name);

@Named("generalize")
@POST
@Path("/{name}/generalize")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,20 @@ public void testUpdate() {
assertEquals(vm.properties().storageProfile().dataDisks().size(), oldDataDisks.size() + 1);
}

@Test(dependsOnMethods = "testUpdate")
@Test(dependsOnMethods = "testRestart")
public void testStop() {
api().stop(vmName);
assertTrue(stateReached(vmName, PowerState.STOPPED), "stop operation did not complete in the configured timeout");
}

@Test(dependsOnMethods = "testStop")
@Test(dependsOnMethods = "testUpdate")
public void testDeallocate() {
api().deallocate(vmName);
assertTrue(stateReached(vmName, PowerState.DEALLOCATED),
"deallocate operation did not complete in the configured timeout");
}

@Test(dependsOnMethods = "testDeallocate")
public void testRestart() {
api().start(vmName);
assertTrue(stateReached(vmName, PowerState.RUNNING), "start operation did not complete in the configured timeout");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
*/
package org.jclouds.azurecompute.arm.features;

import static com.google.common.collect.Iterables.isEmpty;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;

import java.net.URI;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -53,12 +59,6 @@
import com.google.common.collect.ImmutableMap;
import com.squareup.okhttp.mockwebserver.MockResponse;

import static com.google.common.collect.Iterables.isEmpty;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;

@Test(groups = "unit", testName = "VirtualMachineApiMockTest", singleThreaded = true)
public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest {

Expand Down Expand Up @@ -213,7 +213,7 @@ public void testDelete() throws Exception {
}

public void testStart() throws Exception {
server.enqueue(new MockResponse().setResponseCode(204));
server.enqueue(response202WithHeader());

final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname");

Expand All @@ -224,7 +224,7 @@ public void testStart() throws Exception {
}

public void testRestart() throws Exception {
server.enqueue(new MockResponse().setResponseCode(204));
server.enqueue(response202WithHeader());

final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname");

Expand All @@ -235,7 +235,7 @@ public void testRestart() throws Exception {
}

public void testStop() throws Exception {
server.enqueue(new MockResponse().setResponseCode(204));
server.enqueue(response202WithHeader());

final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname");

Expand All @@ -245,6 +245,17 @@ public void testStop() throws Exception {
+ "/virtualMachines/windowsmachine/powerOff?api-version=2016-04-30-preview");
}

public void testDeallocate() throws Exception {
server.enqueue(response202WithHeader());

final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname");

vmAPI.deallocate("windowsmachine");

assertSent(server, "POST", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute"
+ "/virtualMachines/windowsmachine/deallocate?api-version=2016-04-30-preview");
}

public void testGeneralize() throws Exception {
server.enqueue(new MockResponse().setResponseCode(200));
final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname");
Expand Down

0 comments on commit 7003cee

Please sign in to comment.