Repository: jclouds Updated Branches: refs/heads/2.1.x 8d2808e30 -> 2a957193c
Added Local Network Gateway API Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/2a957193 Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/2a957193 Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/2a957193 Branch: refs/heads/2.1.x Commit: 2a957193cc30bae868a16354b00a906cdc8a3f61 Parents: 8d2808e Author: Ignasi Barrera <[email protected]> Authored: Mon Jun 11 15:25:25 2018 +0200 Committer: Ignasi Barrera <[email protected]> Committed: Wed Jun 13 14:22:56 2018 +0200 ---------------------------------------------------------------------- .../azurecompute/arm/AzureComputeApi.java | 9 ++ .../arm/AzureComputeProviderMetadata.java | 2 + .../arm/domain/LocalNetworkGateway.java | 75 ++++++++++ .../domain/LocalNetworkGatewayProperties.java | 96 ++++++++++++ .../arm/features/LocalNetworkGatewayApi.java | 81 ++++++++++ .../features/AvailabilitySetApiMockTest.java | 2 +- .../LocalNetworkGatewayApiLiveTest.java | 122 +++++++++++++++ .../LocalNetworkGatewayApiMockTest.java | 148 +++++++++++++++++++ .../resources/localnetworkgatewaycreate.json | 18 +++ .../test/resources/localnetworkgatewayget.json | 18 +++ .../test/resources/localnetworkgatewaylist.json | 22 +++ 11 files changed, 592 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a957193/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeApi.java ---------------------------------------------------------------------- diff --git a/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeApi.java b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeApi.java index d62a5b7..a4b6282 100644 --- a/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeApi.java +++ b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeApi.java @@ -28,6 +28,7 @@ import org.jclouds.azurecompute.arm.features.GraphRBACApi; import org.jclouds.azurecompute.arm.features.ImageApi; import org.jclouds.azurecompute.arm.features.JobApi; import org.jclouds.azurecompute.arm.features.LoadBalancerApi; +import org.jclouds.azurecompute.arm.features.LocalNetworkGatewayApi; import org.jclouds.azurecompute.arm.features.LocationApi; import org.jclouds.azurecompute.arm.features.MetricDefinitionsApi; import org.jclouds.azurecompute.arm.features.MetricsApi; @@ -263,6 +264,14 @@ public interface AzureComputeApi extends Closeable { VaultApi getVaultApi(@PathParam("resourcegroup") String resourcegroup); /** + * Management features for Local Network Gateways. + * + * @see <a href="https://docs.microsoft.com/en-us/rest/api/network-gateway/localnetworkgateways">docs</a> + */ + @Delegate + LocalNetworkGatewayApi getLocalNetworkGatewayApi(@PathParam("resourcegroup") String resourcegroup); + + /** * Returns the information about the current service principal. */ @Provides http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a957193/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeProviderMetadata.java ---------------------------------------------------------------------- diff --git a/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeProviderMetadata.java b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeProviderMetadata.java index 2e51e69..3038f8e 100644 --- a/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeProviderMetadata.java +++ b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeProviderMetadata.java @@ -45,6 +45,7 @@ import org.jclouds.azurecompute.arm.features.DiskApi; import org.jclouds.azurecompute.arm.features.GraphRBACApi; import org.jclouds.azurecompute.arm.features.ImageApi; import org.jclouds.azurecompute.arm.features.LoadBalancerApi; +import org.jclouds.azurecompute.arm.features.LocalNetworkGatewayApi; import org.jclouds.azurecompute.arm.features.LocationApi; import org.jclouds.azurecompute.arm.features.MetricDefinitionsApi; import org.jclouds.azurecompute.arm.features.MetricsApi; @@ -130,6 +131,7 @@ public class AzureComputeProviderMetadata extends BaseProviderMetadata { properties.put(API_VERSION_PREFIX + VirtualMachineScaleSetApi.class.getSimpleName(), "2017-03-30"); properties.put(API_VERSION_PREFIX + GraphRBACApi.class.getSimpleName(), "1.6"); properties.put(API_VERSION_PREFIX + VaultApi.class.getSimpleName(), "2016-10-01"); + properties.put(API_VERSION_PREFIX + LocalNetworkGatewayApi.class.getSimpleName(), "2018-02-01"); return properties; } http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a957193/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/domain/LocalNetworkGateway.java ---------------------------------------------------------------------- diff --git a/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/domain/LocalNetworkGateway.java b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/domain/LocalNetworkGateway.java new file mode 100644 index 0000000..b8e95ab --- /dev/null +++ b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/domain/LocalNetworkGateway.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.domain; + +import java.util.Map; + +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; + +import com.google.auto.value.AutoValue; +import com.google.common.collect.ImmutableMap; + +@AutoValue +public abstract class LocalNetworkGateway { + + @Nullable public abstract String id(); + public abstract String name(); + public abstract String location(); + @Nullable public abstract String type(); + @Nullable public abstract Map<String, String> tags(); + @Nullable public abstract String etag(); + public abstract LocalNetworkGatewayProperties properties(); + + LocalNetworkGateway() { + + } + + @SerializedNames({ "id", "name", "location", "type", "tags", "etag", "properties" }) + public static LocalNetworkGateway create(String id, String name, String location, String type, + Map<String, String> tags, String etag, LocalNetworkGatewayProperties properties) { + return builder().id(id).name(name).location(location).type(type).tags(tags).etag(etag).properties(properties) + .build(); + } + + public abstract Builder toBuilder(); + + public static Builder builder() { + return new AutoValue_LocalNetworkGateway.Builder(); + } + + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder id(String id); + public abstract Builder name(String name); + public abstract Builder location(String location); + public abstract Builder type(String type); + public abstract Builder tags(Map<String, String> tags); + public abstract Builder etag(String etag); + public abstract Builder properties(LocalNetworkGatewayProperties properties); + + abstract String location(); + abstract Map<String, String> tags(); + abstract LocalNetworkGateway autoBuild(); + + public LocalNetworkGateway build() { + tags(tags() != null ? ImmutableMap.copyOf(tags()) : null); + location(location().toLowerCase()); // Avoid issues in regions such as CanadaEast + return autoBuild(); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a957193/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/domain/LocalNetworkGatewayProperties.java ---------------------------------------------------------------------- diff --git a/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/domain/LocalNetworkGatewayProperties.java b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/domain/LocalNetworkGatewayProperties.java new file mode 100644 index 0000000..56b773f --- /dev/null +++ b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/domain/LocalNetworkGatewayProperties.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.domain; + +import java.util.List; + +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; + +import com.google.auto.value.AutoValue; +import com.google.common.collect.ImmutableList; + +@AutoValue +public abstract class LocalNetworkGatewayProperties implements Provisionable { + + @Nullable public abstract BGPSettings bgpSettings(); + public abstract String gatewayIpAddress(); + @Nullable public abstract AddressSpace localNetworkAddressSpace(); + @Nullable public abstract String provisioningState(); + @Nullable public abstract String resourceGuid(); + + @SerializedNames({ "bgpSettings", "gatewayIpAddress", "localNetworkAddressSpace", "provisioningState", + "resourceGuid" }) + public static LocalNetworkGatewayProperties create(BGPSettings bgpSettings, String gatewayIpAddress, + AddressSpace localNetworkAddressSpace, String provisioningState, String resourceGuid) { + return builder().bgpSettings(bgpSettings).gatewayIpAddress(gatewayIpAddress) + .localNetworkAddressSpace(localNetworkAddressSpace).provisioningState(provisioningState) + .resourceGuid(resourceGuid).build(); + } + + LocalNetworkGatewayProperties() { + + } + + public abstract LocalNetworkGatewayProperties.Builder toBuilder(); + + public static LocalNetworkGatewayProperties.Builder builder() { + return new AutoValue_LocalNetworkGatewayProperties.Builder(); + } + + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder bgpSettings(BGPSettings bgpSettings); + public abstract Builder gatewayIpAddress(String gatewayIpAddress); + public abstract Builder localNetworkAddressSpace(AddressSpace localNetworkAddressSpace); + public abstract Builder provisioningState(String provisioningState); + public abstract Builder resourceGuid(String resourceGuid); + + public abstract LocalNetworkGatewayProperties build(); + } + + @AutoValue + public abstract static class BGPSettings { + public abstract int asn(); + public abstract String bgpPeeringAddress(); + public abstract int peerWeight(); + + @SerializedNames({ "asn", "bgpPeeringAddress", "peerWeight" }) + public static LocalNetworkGatewayProperties.BGPSettings create(int asn, String bgpPeeringAddress, int peerWeight) { + return new AutoValue_LocalNetworkGatewayProperties_BGPSettings(asn, bgpPeeringAddress, peerWeight); + } + + BGPSettings() { + + } + } + + @AutoValue + public abstract static class AddressSpace { + public abstract List<String> addressPrefixes(); + + @SerializedNames({ "addressPrefixes" }) + public static LocalNetworkGatewayProperties.AddressSpace create(List<String> addressPrefixes) { + return new AutoValue_LocalNetworkGatewayProperties_AddressSpace( + addressPrefixes == null ? ImmutableList.<String> of() : ImmutableList.copyOf(addressPrefixes)); + } + + AddressSpace() { + + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a957193/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/LocalNetworkGatewayApi.java ---------------------------------------------------------------------- diff --git a/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/LocalNetworkGatewayApi.java b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/LocalNetworkGatewayApi.java new file mode 100644 index 0000000..a868e40 --- /dev/null +++ b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/LocalNetworkGatewayApi.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import java.io.Closeable; +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; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.MediaType; + +import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404; +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.azurecompute.arm.domain.LocalNetworkGateway; +import org.jclouds.azurecompute.arm.domain.LocalNetworkGatewayProperties; +import org.jclouds.azurecompute.arm.filters.ApiVersionFilter; +import org.jclouds.azurecompute.arm.functions.URIParser; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.oauth.v2.filters.OAuthFilter; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.MapBinder; +import org.jclouds.rest.annotations.PayloadParam; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.SelectJson; +import org.jclouds.rest.binders.BindToJsonPayload; + +@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/localNetworkGateways") +@RequestFilters({ OAuthFilter.class, ApiVersionFilter.class }) +@Consumes(MediaType.APPLICATION_JSON) +public interface LocalNetworkGatewayApi extends Closeable { + + @Named("localnetworkgateway:list") + @GET + @SelectJson("value") + @Fallback(EmptyListOnNotFoundOr404.class) + List<LocalNetworkGateway> list(); + + @Named("localnetworkgateway:get") + @Path("/{name}") + @GET + @Fallback(NullOnNotFoundOr404.class) + LocalNetworkGateway get(@PathParam("name") String name); + + @Named("localnetworkgateway:createOrUpdate") + @MapBinder(BindToJsonPayload.class) + @Path("/{name}") + @PUT + LocalNetworkGateway createOrUpdate(@PathParam("name") String name, @PayloadParam("location") String location, + @Nullable @PayloadParam("tags") Map<String, String> tags, + @PayloadParam("properties") LocalNetworkGatewayProperties properties); + + @Named("localnetworkgateway:delete") + @Path("/{name}") + @DELETE + @ResponseParser(URIParser.class) + @Fallback(NullOnNotFoundOr404.class) + URI delete(@PathParam("name") String name); + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a957193/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AvailabilitySetApiMockTest.java ---------------------------------------------------------------------- diff --git a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AvailabilitySetApiMockTest.java b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AvailabilitySetApiMockTest.java index 430c32f..a20407b 100644 --- a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AvailabilitySetApiMockTest.java +++ b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AvailabilitySetApiMockTest.java @@ -138,7 +138,7 @@ public class AvailabilitySetApiMockTest extends BaseAzureComputeApiMockTest { assertSent(server, "DELETE", path); } - public void deleteSubnetResourceDoesNotExist() throws InterruptedException { + public void deleteAvailabilitySetDoesNotExist() throws InterruptedException { server.enqueue(response204()); http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a957193/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocalNetworkGatewayApiLiveTest.java ---------------------------------------------------------------------- diff --git a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocalNetworkGatewayApiLiveTest.java b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocalNetworkGatewayApiLiveTest.java new file mode 100644 index 0000000..301df03 --- /dev/null +++ b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocalNetworkGatewayApiLiveTest.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +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.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.net.URI; + +import org.jclouds.azurecompute.arm.domain.LocalNetworkGateway; +import org.jclouds.azurecompute.arm.domain.LocalNetworkGatewayProperties; +import org.jclouds.azurecompute.arm.domain.LocalNetworkGatewayProperties.AddressSpace; +import org.jclouds.azurecompute.arm.domain.Provisionable; +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.base.Supplier; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +@Test(groups = "live", testName = "LocalNetworkGatewayApiLiveTest", singleThreaded = true) +public class LocalNetworkGatewayApiLiveTest extends BaseAzureComputeApiLiveTest { + + private String name; + + @BeforeClass + @Override + public void setup() { + super.setup(); + createTestResourceGroup(); + name = "jclouds-" + RAND; + } + + @Test + public void createLocalNetworkGateway() { + AddressSpace localAddresses = AddressSpace.create(ImmutableList.of("192.168.0.0/24")); + LocalNetworkGatewayProperties props = LocalNetworkGatewayProperties.builder().gatewayIpAddress("1.2.3.4") + .localNetworkAddressSpace(localAddresses).build(); + + LocalNetworkGateway gw = api().createOrUpdate(name, LOCATION, null, props); + + assertNotNull(gw); + assertEquals(gw.name(), name); + assertNotNull(gw.properties()); + assertNotNull(gw.properties().gatewayIpAddress()); + assertEquals(gw.properties().gatewayIpAddress(), "1.2.3.4"); + assertNotNull(gw.properties().localNetworkAddressSpace()); + assertTrue(gw.properties().localNetworkAddressSpace().addressPrefixes().contains("192.168.0.0/24")); + } + + @Test(dependsOnMethods = "createLocalNetworkGateway") + public void getLocalNetworkGateway() { + assertNotNull(api().get(name)); + } + + @Test(dependsOnMethods = "createLocalNetworkGateway") + public void listLocalNetworkGateways() { + assertTrue(any(api().list(), new Predicate<LocalNetworkGateway>() { + @Override + public boolean apply(LocalNetworkGateway input) { + return name.equals(input.name()); + } + })); + } + + @Test(dependsOnMethods = "createLocalNetworkGateway") + public void updateLocalNetworkGateway() { + // Make sure the resource is fully provisioned before modifying it + waitUntilAvailable(name); + + LocalNetworkGateway gw = api().get(name); + AddressSpace localAddresses = AddressSpace.create(ImmutableList.of("192.168.0.0/24", "192.168.1.0/24")); + gw = api().createOrUpdate(name, LOCATION, ImmutableMap.of("foo", "bar"), + gw.properties().toBuilder().localNetworkAddressSpace(localAddresses).build()); + + assertNotNull(gw); + assertTrue(gw.tags().containsKey("foo")); + assertEquals(gw.tags().get("foo"), "bar"); + assertTrue(gw.properties().localNetworkAddressSpace().addressPrefixes().contains("192.168.0.0/24")); + assertTrue(gw.properties().localNetworkAddressSpace().addressPrefixes().contains("192.168.1.0/24")); + } + + @Test(dependsOnMethods = { "getLocalNetworkGateway", "listLocalNetworkGateways", "updateLocalNetworkGateway" }, alwaysRun = true) + public void deleteLocalNetworkGateway() { + // Make sure the resource is fully provisioned before deleting it + waitUntilAvailable(name); + URI uri = api().delete(name); + assertResourceDeleted(uri); + } + + private LocalNetworkGatewayApi api() { + return api.getLocalNetworkGatewayApi(resourceGroupName); + } + + private boolean waitUntilAvailable(final String name) { + return resourceAvailable.apply(new Supplier<Provisionable>() { + @Override + public Provisionable get() { + LocalNetworkGateway gw = api().get(name); + return gw == null ? null : gw.properties(); + } + }); + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a957193/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocalNetworkGatewayApiMockTest.java ---------------------------------------------------------------------- diff --git a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocalNetworkGatewayApiMockTest.java b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocalNetworkGatewayApiMockTest.java new file mode 100644 index 0000000..840c872 --- /dev/null +++ b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocalNetworkGatewayApiMockTest.java @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +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.util.List; + +import org.jclouds.azurecompute.arm.domain.LocalNetworkGateway; +import org.jclouds.azurecompute.arm.domain.LocalNetworkGatewayProperties; +import org.jclouds.azurecompute.arm.domain.LocalNetworkGatewayProperties.AddressSpace; +import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; + +@Test(groups = "unit", testName = "LocalNetworkGatewayApiMockTest", singleThreaded = true) +public class LocalNetworkGatewayApiMockTest extends BaseAzureComputeApiMockTest { + + private final String subscriptionid = "SUBSCRIPTIONID"; + private final String resourcegroup = "myresourcegroup"; + private final String name = "mylocalgw"; + private final String apiVersion = "api-version=2018-02-01"; + + public void createOrUpdateLocalNetworkGateway() throws InterruptedException { + server.enqueue(jsonResponse("/localnetworkgatewaycreate.json").setResponseCode(200)); + LocalNetworkGatewayApi gwapi = api.getLocalNetworkGatewayApi(resourcegroup); + + AddressSpace localAddresses = AddressSpace.create(ImmutableList.of("192.168.0.0/24")); + LocalNetworkGatewayProperties props = LocalNetworkGatewayProperties.builder().gatewayIpAddress("1.2.3.4") + .localNetworkAddressSpace(localAddresses).build(); + LocalNetworkGateway gw = gwapi.createOrUpdate(name, "westeurope", null, props); + + String path = String.format( + "/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/localNetworkGateways/%s?%s", + subscriptionid, resourcegroup, name, apiVersion); + String json = "{\"location\":\"westeurope\",\"properties\":{\"gatewayIpAddress\":\"1.2.3.4\",\"localNetworkAddressSpace\":{\"addressPrefixes\":[\"192.168.0.0/24\"]}}}"; + assertSent(server, "PUT", path, json); + + assertEquals(gw.name(), name); + assertNotNull(gw.properties()); + assertNotNull(gw.properties().gatewayIpAddress()); + assertEquals(gw.properties().gatewayIpAddress(), "1.2.3.4"); + assertNotNull(gw.properties().localNetworkAddressSpace()); + assertTrue(gw.properties().localNetworkAddressSpace().addressPrefixes().contains("192.168.0.0/24")); + } + + public void getLocalNetworkGateway() throws InterruptedException { + server.enqueue(jsonResponse("/localnetworkgatewayget.json").setResponseCode(200)); + LocalNetworkGatewayApi gwapi = api.getLocalNetworkGatewayApi(resourcegroup); + + LocalNetworkGateway gw = gwapi.get(name); + + String path = String.format( + "/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/localNetworkGateways/%s?%s", + subscriptionid, resourcegroup, name, apiVersion); + assertSent(server, "GET", path); + + assertEquals(gw.name(), name); + } + + public void getLocalNetworkGatewayReturns404() throws InterruptedException { + server.enqueue(response404()); + LocalNetworkGatewayApi gwapi = api.getLocalNetworkGatewayApi(resourcegroup); + + LocalNetworkGateway gw = gwapi.get(name); + + String path = String.format( + "/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/localNetworkGateways/%s?%s", + subscriptionid, resourcegroup, name, apiVersion); + assertSent(server, "GET", path); + + assertNull(gw); + } + + public void listLocalNetworkGateways() throws InterruptedException { + server.enqueue(jsonResponse("/localnetworkgatewaylist.json").setResponseCode(200)); + LocalNetworkGatewayApi gwapi = api.getLocalNetworkGatewayApi(resourcegroup); + + List<LocalNetworkGateway> gws = gwapi.list(); + + String path = String.format( + "/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/localNetworkGateways?%s", + subscriptionid, resourcegroup, apiVersion); + assertSent(server, "GET", path); + + assertTrue(gws.size() > 0); + } + + public void listLocalNetworkGatewaysReturns404() throws InterruptedException { + server.enqueue(response404()); + LocalNetworkGatewayApi gwapi = api.getLocalNetworkGatewayApi(resourcegroup); + + List<LocalNetworkGateway> gws = gwapi.list(); + + String path = String.format( + "/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/localNetworkGateways?%s", + subscriptionid, resourcegroup, apiVersion); + assertSent(server, "GET", path); + + assertTrue(isEmpty(gws)); + } + + public void deleteLocalNetworkGateway() throws InterruptedException { + server.enqueue(response202WithHeader()); + LocalNetworkGatewayApi gwapi = api.getLocalNetworkGatewayApi(resourcegroup); + + URI uri = gwapi.delete(name); + assertNotNull(uri); + + String path = String.format( + "/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/localNetworkGateways/%s?%s", + subscriptionid, resourcegroup, name, apiVersion); + assertSent(server, "DELETE", path); + } + + public void deleteLocalNetworkGatewayDoesNotExist() throws InterruptedException { + server.enqueue(response204()); + LocalNetworkGatewayApi gwapi = api.getLocalNetworkGatewayApi(resourcegroup); + + URI uri = gwapi.delete(name); + assertNull(uri); + + String path = String.format( + "/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/localNetworkGateways/%s?%s", + subscriptionid, resourcegroup, name, apiVersion); + assertSent(server, "DELETE", path); + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a957193/providers/azurecompute-arm/src/test/resources/localnetworkgatewaycreate.json ---------------------------------------------------------------------- diff --git a/providers/azurecompute-arm/src/test/resources/localnetworkgatewaycreate.json b/providers/azurecompute-arm/src/test/resources/localnetworkgatewaycreate.json new file mode 100644 index 0000000..99efd0e --- /dev/null +++ b/providers/azurecompute-arm/src/test/resources/localnetworkgatewaycreate.json @@ -0,0 +1,18 @@ +{ + "name": "mylocalgw", + "id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/myresourcegroup/providers/Microsoft.Network/localNetworkGateways/mylocalgw", + "etag": "W/\"e76a6517-260a-4424-811b-b4d518109424\"", + "type": "Microsoft.Network/localNetworkGateways", + "location": "westeurope", + "properties": { + "provisioningState": "Updating", + "resourceGuid": "cd00ef09-fec6-4d6e-aa15-77cf06d14915", + "localNetworkAddressSpace": { + "addressPrefixes": [ + "192.168.0.0/24" + ] + }, + "gatewayIpAddress": "1.2.3.4" + } +} + http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a957193/providers/azurecompute-arm/src/test/resources/localnetworkgatewayget.json ---------------------------------------------------------------------- diff --git a/providers/azurecompute-arm/src/test/resources/localnetworkgatewayget.json b/providers/azurecompute-arm/src/test/resources/localnetworkgatewayget.json new file mode 100644 index 0000000..99efd0e --- /dev/null +++ b/providers/azurecompute-arm/src/test/resources/localnetworkgatewayget.json @@ -0,0 +1,18 @@ +{ + "name": "mylocalgw", + "id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/myresourcegroup/providers/Microsoft.Network/localNetworkGateways/mylocalgw", + "etag": "W/\"e76a6517-260a-4424-811b-b4d518109424\"", + "type": "Microsoft.Network/localNetworkGateways", + "location": "westeurope", + "properties": { + "provisioningState": "Updating", + "resourceGuid": "cd00ef09-fec6-4d6e-aa15-77cf06d14915", + "localNetworkAddressSpace": { + "addressPrefixes": [ + "192.168.0.0/24" + ] + }, + "gatewayIpAddress": "1.2.3.4" + } +} + http://git-wip-us.apache.org/repos/asf/jclouds/blob/2a957193/providers/azurecompute-arm/src/test/resources/localnetworkgatewaylist.json ---------------------------------------------------------------------- diff --git a/providers/azurecompute-arm/src/test/resources/localnetworkgatewaylist.json b/providers/azurecompute-arm/src/test/resources/localnetworkgatewaylist.json new file mode 100644 index 0000000..d1c32ad --- /dev/null +++ b/providers/azurecompute-arm/src/test/resources/localnetworkgatewaylist.json @@ -0,0 +1,22 @@ +{ + "value": [ + { + "name": "mylocalgw", + "id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/myresourcegroup/providers/Microsoft.Network/localNetworkGateways/mylocalgw", + "etag": "W/\"e76a6517-260a-4424-811b-b4d518109424\"", + "type": "Microsoft.Network/localNetworkGateways", + "location": "westeurope", + "properties": { + "provisioningState": "Updating", + "resourceGuid": "cd00ef09-fec6-4d6e-aa15-77cf06d14915", + "localNetworkAddressSpace": { + "addressPrefixes": [ + "192.168.0.0/24" + ] + }, + "gatewayIpAddress": "1.2.3.4" + } + } + ] +} +
