mirror of https://github.com/apache/jclouds.git
Implements listAll operation for VirtualNetworkAPI (#33)
* Implements listAll operation for VirtualNetworkAPI Fixes test with proper method call * Fixes resourcegroup param is now nullable
This commit is contained in:
parent
757d288ae0
commit
cbe683db13
|
@ -106,7 +106,7 @@ public interface AzureComputeApi extends Closeable {
|
|||
* @see <a href="https://msdn.microsoft.com/en-us/library/azure/mt163661.aspx">docs</a>
|
||||
*/
|
||||
@Delegate
|
||||
VirtualNetworkApi getVirtualNetworkApi(@PathParam("resourcegroup") String resourcegroup);
|
||||
VirtualNetworkApi getVirtualNetworkApi(@Nullable @PathParam("resourcegroup") String resourcegroup);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,40 +44,51 @@ import org.jclouds.rest.annotations.ResponseParser;
|
|||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.binders.BindToJsonPayload;
|
||||
|
||||
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/virtualNetworks")
|
||||
/**
|
||||
* The Virtual Networks API includes operations for managing Azure virtual networks in your subscription.
|
||||
*
|
||||
* @see <a href="https://docs.microsoft.com/en-us/rest/api/virtualnetwork/virtualnetworks">docs</a>
|
||||
*/
|
||||
@Path("")
|
||||
@RequestFilters({ OAuthFilter.class, ApiVersionFilter.class })
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public interface VirtualNetworkApi {
|
||||
|
||||
@Named("virtualnetwork:list")
|
||||
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/virtualNetworks")
|
||||
@SelectJson("value")
|
||||
@GET
|
||||
@Fallback(EmptyListOnNotFoundOr404.class)
|
||||
List<VirtualNetwork> list();
|
||||
|
||||
@Named("loadbalancer:listall")
|
||||
@GET
|
||||
@Path("/providers/Microsoft.Network/virtualNetworks")
|
||||
@SelectJson("value")
|
||||
@Fallback(EmptyListOnNotFoundOr404.class)
|
||||
List<VirtualNetwork> listAll();
|
||||
|
||||
@Named("virtualnetwork:create_or_update")
|
||||
@Path("/{virtualnetworkname}")
|
||||
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/virtualNetworks/{virtualnetworkname}")
|
||||
@MapBinder(BindToJsonPayload.class)
|
||||
@PUT
|
||||
VirtualNetwork createOrUpdate(@PathParam("virtualnetworkname") String virtualnetworkname,
|
||||
@PayloadParam("location") String location, @Nullable @PayloadParam("tags") Map<String, String> tags,
|
||||
VirtualNetwork createOrUpdate(@PathParam("virtualnetworkname") String virtualnetworkname, @PayloadParam("location") String location, @Nullable @PayloadParam("tags") Map<String, String> tags,
|
||||
@PayloadParam("properties") VirtualNetwork.VirtualNetworkProperties properties);
|
||||
|
||||
@Named("virtualnetwork:get")
|
||||
@Path("/{virtualnetworkname}")
|
||||
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/virtualNetworks/{virtualnetworkname}")
|
||||
@GET
|
||||
@Fallback(NullOnNotFoundOr404.class)
|
||||
VirtualNetwork get(@PathParam("virtualnetworkname") String virtualnetworkname);
|
||||
|
||||
@Named("virtualnetwork:delete")
|
||||
@Path("/{virtualnetworkname}")
|
||||
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/virtualNetworks/{virtualnetworkname}")
|
||||
@DELETE
|
||||
@ResponseParser(FalseOn204.class)
|
||||
boolean delete(@PathParam("virtualnetworkname") String virtualnetworkname);
|
||||
|
||||
@Named("virtualnetwork:check_ip_address_availability")
|
||||
@Path("/{virtualnetworkname}/CheckIPAddressAvailability")
|
||||
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/virtualNetworks/{virtualnetworkname}/CheckIPAddressAvailability")
|
||||
@GET
|
||||
IpAddressAvailabilityResult checkIPAddressAvailability(@PathParam("virtualnetworkname") String virtualnetworkname,
|
||||
@QueryParam("ipAddress") String ipAddress);
|
||||
IpAddressAvailabilityResult checkIPAddressAvailability(@PathParam("virtualnetworkname") String virtualnetworkname, @QueryParam("ipAddress") String ipAddress);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.jclouds.azurecompute.arm.features;
|
||||
|
||||
import static com.google.common.collect.Iterables.any;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
@ -39,6 +40,7 @@ import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest;
|
|||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
@Test(groups = "live", singleThreaded = true)
|
||||
|
@ -49,7 +51,7 @@ public class VirtualNetworkApiLiveTest extends BaseAzureComputeApiLiveTest {
|
|||
private static final String TEST_IP_ADDRESS_USED_IN_PROVIDER = "10.20.0.7";
|
||||
|
||||
private String virtualNetworkName;
|
||||
|
||||
private VirtualNetwork vn;
|
||||
|
||||
@BeforeClass
|
||||
@Override
|
||||
|
@ -75,7 +77,7 @@ public class VirtualNetworkApiLiveTest extends BaseAzureComputeApiLiveTest {
|
|||
.builder().subnets(ImmutableList.<Subnet> of(subnet))
|
||||
.addressSpace(AddressSpace.create(Arrays.asList(TEST_VIRTUALNETWORK_ADDRESS_PREFIX))).build();
|
||||
|
||||
VirtualNetwork vn = api().createOrUpdate(virtualNetworkName, LOCATION, null, virtualNetworkProperties);
|
||||
vn = api().createOrUpdate(virtualNetworkName, LOCATION, null, virtualNetworkProperties);
|
||||
|
||||
networkAvailablePredicate.create(resourceGroupName).apply(virtualNetworkName);
|
||||
|
||||
|
@ -95,7 +97,31 @@ public class VirtualNetworkApiLiveTest extends BaseAzureComputeApiLiveTest {
|
|||
@Test(dependsOnMethods = "createVirtualNetwork")
|
||||
public void listVirtualNetworks() {
|
||||
List<VirtualNetwork> vnList = api().list();
|
||||
|
||||
assertNotNull(vnList);
|
||||
assertTrue(vnList.size() > 0);
|
||||
|
||||
assertTrue(any(vnList, new Predicate<VirtualNetwork>() {
|
||||
@Override
|
||||
public boolean apply(VirtualNetwork input) {
|
||||
return vn.name().equals(input.name());
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "createVirtualNetwork")
|
||||
public void listAllVirtualNetworks() {
|
||||
List<VirtualNetwork> vnList = api.getVirtualNetworkApi(null).listAll();
|
||||
|
||||
assertNotNull(vnList);
|
||||
assertTrue(vnList.size() > 0);
|
||||
|
||||
assertTrue(any(vnList, new Predicate<VirtualNetwork>() {
|
||||
@Override
|
||||
public boolean apply(VirtualNetwork input) {
|
||||
return vn.name().equals(input.name());
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "getVirtualNetwork")
|
||||
|
@ -115,7 +141,7 @@ public class VirtualNetworkApiLiveTest extends BaseAzureComputeApiLiveTest {
|
|||
deleteLoadBalancer(lbCreated);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "listVirtualNetworks", "getVirtualNetwork", "checkIpAvailability" }, alwaysRun = true)
|
||||
@Test(dependsOnMethods = { "listVirtualNetworks", "listAllVirtualNetworks", "getVirtualNetwork", "checkIpAvailability" }, alwaysRun = true)
|
||||
public void deleteVirtualNetwork() {
|
||||
boolean status = api().delete(virtualNetworkName);
|
||||
assertTrue(status);
|
||||
|
|
|
@ -94,6 +94,17 @@ public class VirtualNetworkApiMockTest extends BaseAzureComputeApiMockTest {
|
|||
assertEquals(vnList.size(), 3);
|
||||
}
|
||||
|
||||
public void listAllVirtualNetworks() throws InterruptedException {
|
||||
server.enqueue(jsonResponse("/listvirtualnetworksall.json"));
|
||||
|
||||
final VirtualNetworkApi vnApi = api.getVirtualNetworkApi(null);
|
||||
List<VirtualNetwork> vnList = vnApi.listAll();
|
||||
String path = String.format("/subscriptions/%s/providers/Microsoft.Network/virtualNetworks?%s", subscriptionid, apiVersion);
|
||||
|
||||
assertSent(server, "GET", path);
|
||||
assertEquals(vnList.size(), 4);
|
||||
}
|
||||
|
||||
public void listVirtualNetworkReturns404() throws InterruptedException {
|
||||
server.enqueue(response404());
|
||||
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
{
|
||||
"value": [
|
||||
{
|
||||
"name": "mockvirtualnetwork",
|
||||
"id": "/subscriptions/6b6748c8-3e69-4e27-9b71-df97a81c0bbc/resourceGroups/azurearmtesting/providers/Microsoft.Network/virtualNetworks/mockvirtualnetwork",
|
||||
"etag": "W/\"0dcd223f-670c-49ca-abe7-5978d127c131\"",
|
||||
"type": "Microsoft.Network/virtualNetworks",
|
||||
"location": "westeurope",
|
||||
"tags": {
|
||||
"key": "value"
|
||||
},
|
||||
"properties": {
|
||||
"provisioningState": "Succeeded",
|
||||
"resourceGuid": "1568c76a-73a4-4a60-8dfb-53b823197ccb",
|
||||
"addressSpace": {
|
||||
"addressPrefixes": [
|
||||
"10.2.0.0/16"
|
||||
]
|
||||
},
|
||||
"subnets": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "anothervirtualnetworks",
|
||||
"id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/azurearmtesting/providers/Microsoft.Network/virtualNetworks/anothervirtualnetworks",
|
||||
"etag": "W/\"7604d8fe-f3b8-4fd4-ae52-ab503cc29097\"",
|
||||
"type": "Microsoft.Network/virtualNetworks",
|
||||
"location": "westeurope",
|
||||
"tags": {
|
||||
"key": "value"
|
||||
},
|
||||
"properties": {
|
||||
"provisioningState": "Succeeded",
|
||||
"resourceGuid": "5192bdb3-f6ed-44ad-bf4c-059cff905791",
|
||||
"addressSpace": {
|
||||
"addressPrefixes": [
|
||||
"10.2.0.0/16"
|
||||
]
|
||||
},
|
||||
"subnets": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "myvirtualnetwork",
|
||||
"id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/azurearmtesting/providers/Microsoft.Network/virtualNetworks/myvirtualnetwork",
|
||||
"etag": "W/\"bc7e1d77-eec0-4b91-ae80-afc33cf3c867\"",
|
||||
"type": "Microsoft.Network/virtualNetworks",
|
||||
"location": "westeurope",
|
||||
"tags": {
|
||||
"key": "value"
|
||||
},
|
||||
"properties": {
|
||||
"provisioningState": "Succeeded",
|
||||
"resourceGuid": "8da85637-833c-4445-a681-81ca3fb90044",
|
||||
"addressSpace": {
|
||||
"addressPrefixes": [
|
||||
"10.2.0.0/16"
|
||||
]
|
||||
},
|
||||
"subnets": [
|
||||
{
|
||||
"name": "mysubnet",
|
||||
"id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/azurearmtesting/providers/Microsoft.Network/virtualNetworks/myvirtualnetwork/subnets/mysubnet",
|
||||
"etag": "W/\"bc7e1d77-eec0-4b91-ae80-afc33cf3c867\"",
|
||||
"properties": {
|
||||
"provisioningState": "Succeeded",
|
||||
"addressPrefix": "10.2.0.0/24",
|
||||
"ipConfigurations": [
|
||||
{
|
||||
"id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/azurearmtesting/providers/Microsoft.Network/networkInterfaces/myNic/ipConfigurations/myip1"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "mockvirtualnetworkextra",
|
||||
"id": "/subscriptions/6b6748c8-3e69-4e27-9b71-df97a81c0bbc/resourceGroups/other-rg/providers/Microsoft.Network/virtualNetworks/mockvirtualnetwork",
|
||||
"etag": "W/\"0dcd223f-670c-49ca-abe7-5978d127c131\"",
|
||||
"type": "Microsoft.Network/virtualNetworks",
|
||||
"location": "westeurope",
|
||||
"tags": {
|
||||
"key": "value"
|
||||
},
|
||||
"properties": {
|
||||
"provisioningState": "Succeeded",
|
||||
"resourceGuid": "1568c76a-73a4-4a60-8dfb-53b823197ccb",
|
||||
"addressSpace": {
|
||||
"addressPrefixes": [
|
||||
"10.2.0.0/16"
|
||||
]
|
||||
},
|
||||
"subnets": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue