You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2018/01/08 14:55:51 UTC
[10/21] jclouds-labs git commit: Promoted Azure ARM to the main repo
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ac03bac4/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LoadBalancerApiLiveTest.java
----------------------------------------------------------------------
diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LoadBalancerApiLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LoadBalancerApiLiveTest.java
deleted file mode 100644
index adcde2b..0000000
--- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LoadBalancerApiLiveTest.java
+++ /dev/null
@@ -1,449 +0,0 @@
-/*
- * 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.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-import static com.google.common.collect.Iterables.any;
-import static com.google.common.collect.Iterables.transform;
-import static com.google.common.collect.Lists.newArrayList;
-import static org.jclouds.azurecompute.arm.compute.options.AzureTemplateOptions.Builder.availabilitySet;
-import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.TIMEOUT_RESOURCE_DELETED;
-import static org.jclouds.azurecompute.arm.domain.IdReference.extractName;
-import static org.jclouds.azurecompute.arm.domain.InboundNatRuleProperties.Protocol.Tcp;
-import static org.jclouds.compute.predicates.NodePredicates.inGroup;
-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.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import org.jclouds.azurecompute.arm.AzureComputeApi;
-import org.jclouds.azurecompute.arm.compute.config.AzurePredicatesModule.PublicIpAvailablePredicateFactory;
-import org.jclouds.azurecompute.arm.compute.domain.ResourceGroupAndName;
-import org.jclouds.azurecompute.arm.domain.AvailabilitySet;
-import org.jclouds.azurecompute.arm.domain.AvailabilitySet.AvailabilitySetProperties;
-import org.jclouds.azurecompute.arm.domain.BackendAddressPool;
-import org.jclouds.azurecompute.arm.domain.BackendAddressPoolProperties;
-import org.jclouds.azurecompute.arm.domain.FrontendIPConfigurations;
-import org.jclouds.azurecompute.arm.domain.FrontendIPConfigurationsProperties;
-import org.jclouds.azurecompute.arm.domain.IdReference;
-import org.jclouds.azurecompute.arm.domain.InboundNatRule;
-import org.jclouds.azurecompute.arm.domain.InboundNatRuleProperties;
-import org.jclouds.azurecompute.arm.domain.IpConfiguration;
-import org.jclouds.azurecompute.arm.domain.IpConfigurationProperties;
-import org.jclouds.azurecompute.arm.domain.LoadBalancer;
-import org.jclouds.azurecompute.arm.domain.LoadBalancerProperties;
-import org.jclouds.azurecompute.arm.domain.LoadBalancingRule;
-import org.jclouds.azurecompute.arm.domain.LoadBalancingRuleProperties;
-import org.jclouds.azurecompute.arm.domain.LoadBalancingRuleProperties.Protocol;
-import org.jclouds.azurecompute.arm.domain.NetworkInterfaceCard;
-import org.jclouds.azurecompute.arm.domain.NetworkInterfaceCardProperties;
-import org.jclouds.azurecompute.arm.domain.Probe;
-import org.jclouds.azurecompute.arm.domain.ProbeProperties;
-import org.jclouds.azurecompute.arm.domain.Provisionable;
-import org.jclouds.azurecompute.arm.domain.PublicIPAddress;
-import org.jclouds.azurecompute.arm.domain.PublicIPAddressProperties;
-import org.jclouds.azurecompute.arm.domain.VirtualMachine;
-import org.jclouds.azurecompute.arm.internal.AzureLiveTestUtils;
-import org.jclouds.compute.RunNodesException;
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.base.Supplier;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.inject.Key;
-import com.google.inject.TypeLiteral;
-import com.google.inject.name.Names;
-
-// We extend the BaseComputeServiceContextLiveTest to create nodes using the abstraction, which is much easier
-@Test(groups = "live", singleThreaded = true)
-public class LoadBalancerApiLiveTest extends BaseComputeServiceContextLiveTest {
-
- private static final String lbName = String.format("lb-%s-%s", LoadBalancerApiLiveTest.class.getSimpleName()
- .toLowerCase(), System.getProperty("user.name"));
-
- private Predicate<URI> resourceDeleted;
- private PublicIpAvailablePredicateFactory publicIpAvailable;
- private Predicate<Supplier<Provisionable>> resourceAvailable;
- private AzureComputeApi api;
-
- private String location;
- private LoadBalancerApi lbApi;
- private NetworkInterfaceCardApi nicApi;
-
- private LoadBalancer lb;
- private String group;
- private List<String> nicNames;
-
- public LoadBalancerApiLiveTest() {
- provider = "azurecompute-arm";
- group = getClass().getSimpleName().toLowerCase();
- }
-
- @Override
- protected Properties setupProperties() {
- Properties properties = super.setupProperties();
- AzureLiveTestUtils.defaultProperties(properties);
- checkNotNull(setIfTestSystemPropertyPresent(properties, "oauth.endpoint"), "test.oauth.endpoint");
- return properties;
- }
-
- @Override
- protected void initializeContext() {
- super.initializeContext();
- resourceDeleted = context.utils().injector().getInstance(Key.get(new TypeLiteral<Predicate<URI>>() {
- }, Names.named(TIMEOUT_RESOURCE_DELETED)));
- publicIpAvailable = context.utils().injector().getInstance(PublicIpAvailablePredicateFactory.class);
- resourceAvailable = context.utils().injector()
- .getInstance(Key.get(new TypeLiteral<Predicate<Supplier<Provisionable>>>() {
- }));
- api = view.unwrapApi(AzureComputeApi.class);
- }
-
- @Override
- @BeforeClass
- public void setupContext() {
- super.setupContext();
- // Use the resource name conventions used in the abstraction so the nodes
- // can see the load balancer
- location = view.getComputeService().templateBuilder().build().getLocation().getId();
- view.unwrapApi(AzureComputeApi.class).getResourceGroupApi().create(group, location, null);
- lbApi = api.getLoadBalancerApi(group);
- nicApi = api.getNetworkInterfaceCardApi(group);
- }
-
- @Override
- @AfterClass(alwaysRun = true)
- protected void tearDownContext() {
- try {
- view.getComputeService().destroyNodesMatching(inGroup(group));
- } finally {
- try {
- URI uri = api.getResourceGroupApi().delete(group);
- assertResourceDeleted(uri);
- } finally {
- super.tearDownContext();
- }
- }
- }
-
- @Test
- public void testDeleteLoadBalancerDoesNotExist() {
- URI uri = lbApi.delete(lbName);
- assertNull(uri);
- }
-
- @Test(dependsOnMethods = "testDeleteLoadBalancerDoesNotExist")
- public void testCreateLoadBalancer() {
- LoadBalancer createLB = newLoadBalancer(lbName, location);
-
- PublicIPAddress publicIP = createPublicIPAddress("Ip4LoadBalancer");
- FrontendIPConfigurationsProperties fronendProps = FrontendIPConfigurationsProperties.builder()
- .publicIPAddress(IdReference.create(publicIP.id())).build();
- FrontendIPConfigurations frontendIps = FrontendIPConfigurations.create("ipConfigs", null, fronendProps, null);
- LoadBalancerProperties props = LoadBalancerProperties.builder()
- .frontendIPConfigurations(ImmutableList.of(frontendIps)).build();
-
- lb = lbApi.createOrUpdate(lbName, createLB.location(), createLB.tags(), props);
- assertNotNull(lb);
- }
-
- @Test(dependsOnMethods = "testCreateLoadBalancer")
- public void testListLoadBalancers() {
- List<LoadBalancer> result = lbApi.list();
-
- // Verify we have something
- assertNotNull(result);
- assertTrue(result.size() > 0);
-
- // Check that the load balancer matches the one we originally passed in
- assertTrue(any(result, new Predicate<LoadBalancer>() {
- @Override
- public boolean apply(LoadBalancer input) {
- return lb.name().equals(input.name());
- }
- }));
- }
-
- @Test(dependsOnMethods = "testCreateLoadBalancer")
- public void testGetLoadBalancer() {
- lb = lbApi.get(lbName);
- assertNotNull(lb);
- }
-
- @Test(dependsOnMethods = "testGetLoadBalancer")
- public void testAddProbe() {
- ProbeProperties probeProps = ProbeProperties.builder().protocol(ProbeProperties.Protocol.Http).port(80)
- .requestPath("/").intervalInSeconds(5).numberOfProbes(2).build();
-
- Probe probe = Probe.create("probetest", null, probeProps, null);
- LoadBalancerProperties props = lb.properties().toBuilder().probes(ImmutableList.of(probe)).build();
-
- lb = updateLoadBalancer(lbName, props);
-
- assertEquals(lb.properties().probes().size(), 1);
- assertEquals(lb.properties().probes().get(0).name(), probe.name());
- }
-
- @Test(dependsOnMethods = "testGetLoadBalancer")
- public void testAddBackendPool() throws Exception {
- List<IdReference> rules = newArrayList(transform(lb.properties().loadBalancingRules(), ToIdReference));
- BackendAddressPool pool = BackendAddressPool.create("backpools", null, BackendAddressPoolProperties.builder()
- .loadBalancingRules(rules).build(), null);
-
- LoadBalancerProperties props = lb.properties().toBuilder().backendAddressPools(ImmutableList.of(pool)).build();
-
- lb = updateLoadBalancer(lbName, props);
-
- assertEquals(lb.properties().backendAddressPools().size(), 1);
- assertEquals(lb.properties().backendAddressPools().get(0).name(), pool.name());
- }
-
- @Test(dependsOnMethods = { "testAddProbe", "testAddBackendPool" })
- public void testAddLoadBalancingRule() {
- IdReference frontendIp = IdReference.create(lb.properties().frontendIPConfigurations().get(0).id());
- IdReference probe = IdReference.create(lb.properties().probes().get(0).id());
- IdReference backendPool = IdReference.create(lb.properties().backendAddressPools().get(0).id());
-
- LoadBalancingRuleProperties ruleProperties = LoadBalancingRuleProperties.builder()
- .frontendIPConfiguration(frontendIp).backendAddressPool(backendPool).frontendPort(80).backendPort(80)
- .protocol(Protocol.Tcp).probe(probe).build();
-
- LoadBalancingRule rule = LoadBalancingRule.create("lbRule1", null, ruleProperties, null);
- LoadBalancerProperties props = lb.properties().toBuilder().loadBalancingRules(ImmutableList.of(rule)).build();
-
- lb = updateLoadBalancer(lbName, props);
-
- assertEquals(lb.properties().loadBalancingRules().size(), 1);
- assertEquals(lb.properties().loadBalancingRules().get(0).name(), rule.name());
- }
-
- @Test(dependsOnMethods = { "testAddBackendPool", "testAddProbe", "testAddLoadBalancingRule" })
- public void testAttachNodesToBackendPool() throws Exception {
- nicNames = createVirtualMachinesInGroupAndGetNicRefs(group, 2);
-
- // Add the first IP of each node to the pool
- List<NetworkInterfaceCard> attachedNics = new ArrayList<NetworkInterfaceCard>();
- BackendAddressPool targetPool = lb.properties().backendAddressPools().get(0);
- for (String nicName : nicNames) {
- attachedNics.add(attachNicToBackendPool(nicName, targetPool));
- }
-
- // Refresh the LB after having attached NICs to the pool
- lb = lbApi.get(lbName);
- List<BackendAddressPool> pools = lb.properties().backendAddressPools();
- assertEquals(pools.size(), 1);
-
- List<IdReference> backendIps = pools.get(0).properties().backendIPConfigurations();
- assertEquals(backendIps.size(), attachedNics.size());
- assertTrue(backendIps.containsAll(newArrayList(transform(attachedNics, ToFirstIpReference))));
- }
-
- @Test(dependsOnMethods = "testAttachNodesToBackendPool")
- public void testAddInboundNatRule() {
- IdReference frontendIp = IdReference.create(lb.properties().frontendIPConfigurations().get(0).id());
-
- InboundNatRuleProperties natProps = InboundNatRuleProperties.builder().frontendIPConfiguration(frontendIp)
- .frontendPort(5679).backendPort(56710).protocol(Tcp).build();
-
- InboundNatRule natRule = InboundNatRule.create("inboundnat", null, natProps, null);
- LoadBalancerProperties props = lb.properties().toBuilder().inboundNatRules(ImmutableList.of(natRule)).build();
-
- lb = updateLoadBalancer(lbName, props);
-
- assertEquals(lb.properties().inboundNatRules().size(), 1);
- assertEquals(lb.properties().inboundNatRules().get(0).name(), natRule.name());
-
- InboundNatRule createdRule = lb.properties().inboundNatRules().get(0);
- NetworkInterfaceCard updatedNic = attachNicToNatRule(nicNames.get(0), createdRule);
- List<IdReference> natRulesInNic = updatedNic.properties().ipConfigurations().get(0).properties()
- .loadBalancerInboundNatRules();
-
- assertEquals(natRulesInNic.size(), 1);
- assertEquals(natRulesInNic.get(0), IdReference.create(createdRule.id()));
-
- // Refresh the LB after having attached NICs to the pool
- lb = lbApi.get(lbName);
-
- IdReference backendIpRef = IdReference.create(updatedNic.properties().ipConfigurations().get(0).id());
- assertEquals(lb.properties().inboundNatRules().size(), 1);
- assertEquals(lb.properties().inboundNatRules().get(0).properties().backendIPConfiguration(), backendIpRef);
-
- }
-
- @Test(dependsOnMethods = { "testCreateLoadBalancer", "testListLoadBalancers", "testGetLoadBalancer", "testAddProbe",
- "testAddLoadBalancingRule", "testAddBackendPool", "testAttachNodesToBackendPool", "testAddInboundNatRule" }, alwaysRun = true)
- public void deleteLoadBalancer() {
- URI uri = lbApi.delete(lbName);
- assertResourceDeleted(uri);
- }
-
- private PublicIPAddress createPublicIPAddress(final String publicIpAddressName) {
- final PublicIPAddressApi ipApi = view.unwrapApi(AzureComputeApi.class).getPublicIPAddressApi(group);
- PublicIPAddress publicIPAddress = ipApi.get(publicIpAddressName);
-
- if (publicIPAddress == null) {
- final Map<String, String> tags = ImmutableMap.of("testkey", "testvalue");
- PublicIPAddressProperties properties = PublicIPAddressProperties.builder().publicIPAllocationMethod("Static")
- .idleTimeoutInMinutes(4).build();
- publicIPAddress = ipApi.createOrUpdate(publicIpAddressName, location, tags, properties);
-
- checkState(publicIpAvailable.create(group).apply(publicIpAddressName),
- "Public IP was not provisioned in the configured timeout");
- }
-
- return publicIPAddress;
- }
-
- private LoadBalancer newLoadBalancer(final String lbName, final String locationName) {
- FrontendIPConfigurationsProperties frontendIPConfigurationsProperties = FrontendIPConfigurationsProperties
- .builder().build();
- FrontendIPConfigurations frontendIPConfigurations = FrontendIPConfigurations.create("ipConfigs", null,
- frontendIPConfigurationsProperties, null);
- return LoadBalancer
- .builder()
- .name(lbName)
- .location(locationName)
- .properties(
- LoadBalancerProperties.builder().frontendIPConfigurations(ImmutableList.of(frontendIPConfigurations))
- .build()).build();
- }
-
- private void assertResourceDeleted(final URI uri) {
- if (uri != null) {
- assertTrue(resourceDeleted.apply(uri),
- String.format("Resource %s was not terminated in the configured timeout", uri));
- }
- }
-
- private List<String> createVirtualMachinesInGroupAndGetNicRefs(final String group, final int count)
- throws RunNodesException {
-
- // To add multiple nodes in a LB they must belong to the same availability
- // set
- AvailabilitySetProperties props = AvailabilitySetProperties.builder().platformUpdateDomainCount(count)
- .platformFaultDomainCount(count).build();
- AvailabilitySet as = AvailabilitySet.managed().name(group).properties(props).build();
-
- Set<? extends NodeMetadata> nodes = view.getComputeService().createNodesInGroup(group, count,
- availabilitySet(as).resourceGroup(this.group));
-
- List<String> nicNames = new ArrayList<String>();
- for (NodeMetadata node : nodes) {
- ResourceGroupAndName resourceGroupAndName = ResourceGroupAndName.fromSlashEncoded(node.getId());
- VirtualMachine vm = api.getVirtualMachineApi(resourceGroupAndName.resourceGroup()).get(
- resourceGroupAndName.name());
-
- String nicName = extractName(vm.properties().networkProfile().networkInterfaces().get(0).id());
- nicNames.add(nicName);
- }
-
- return nicNames;
- }
-
- private NetworkInterfaceCard attachNicToBackendPool(final String nicName, BackendAddressPool pool) {
- List<IdReference> poolRefs = ImmutableList.of(IdReference.create(pool.id()));
-
- // Assume we are attaching the first IP to the Load Balancer
- NetworkInterfaceCard nic = nicApi.get(nicName);
-
- IpConfigurationProperties ipProps = nic.properties().ipConfigurations().get(0).properties().toBuilder()
- .loadBalancerBackendAddressPools(poolRefs).build();
- List<IpConfiguration> ips = ImmutableList.of(nic.properties().ipConfigurations().get(0).toBuilder()
- .properties(ipProps).build());
-
- NetworkInterfaceCardProperties nicProps = nic.properties().toBuilder().ipConfigurations(ips).build();
-
- nicApi.createOrUpdate(nicName, location, nicProps, null);
-
- resourceAvailable.apply(new Supplier<Provisionable>() {
- @Override
- public Provisionable get() {
- NetworkInterfaceCard updated = nicApi.get(nicName);
- return updated == null ? null : updated.properties();
- }
- });
-
- return nicApi.get(nicName);
- }
-
- private NetworkInterfaceCard attachNicToNatRule(final String nicName, InboundNatRule rule) {
- List<IdReference> natRuleRefs = ImmutableList.of(IdReference.create(rule.id()));
-
- // Assume we are attaching the first IP to the NAT rule
- NetworkInterfaceCard nic = nicApi.get(nicName);
-
- IpConfigurationProperties ipProps = nic.properties().ipConfigurations().get(0).properties().toBuilder()
- .loadBalancerInboundNatRules(natRuleRefs).build();
- List<IpConfiguration> ips = ImmutableList.of(nic.properties().ipConfigurations().get(0).toBuilder()
- .properties(ipProps).build());
-
- NetworkInterfaceCardProperties nicProps = nic.properties().toBuilder().ipConfigurations(ips).build();
-
- nicApi.createOrUpdate(nicName, location, nicProps, null);
-
- resourceAvailable.apply(new Supplier<Provisionable>() {
- @Override
- public Provisionable get() {
- NetworkInterfaceCard updated = nicApi.get(nicName);
- return updated == null ? null : updated.properties();
- }
- });
-
- return nicApi.get(nicName);
- }
-
- private LoadBalancer updateLoadBalancer(final String name, LoadBalancerProperties props) {
- lbApi.createOrUpdate(name, location, null, props);
- resourceAvailable.apply(new Supplier<Provisionable>() {
- @Override
- public Provisionable get() {
- LoadBalancer updated = lbApi.get(name);
- return updated == null ? null : updated.properties();
- }
- });
- return lbApi.get(name);
- }
-
- private static final Function<LoadBalancingRule, IdReference> ToIdReference = new Function<LoadBalancingRule, IdReference>() {
- @Override
- public IdReference apply(LoadBalancingRule input) {
- return IdReference.create(input.id());
- }
- };
-
- private static final Function<NetworkInterfaceCard, IdReference> ToFirstIpReference = new Function<NetworkInterfaceCard, IdReference>() {
- @Override
- public IdReference apply(NetworkInterfaceCard input) {
- return IdReference.create(input.properties().ipConfigurations().get(0).id());
- }
- };
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ac03bac4/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LoadBalancerApiMockTest.java
----------------------------------------------------------------------
diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LoadBalancerApiMockTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LoadBalancerApiMockTest.java
deleted file mode 100644
index 45663ea..0000000
--- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LoadBalancerApiMockTest.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * 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.FrontendIPConfigurations;
-import org.jclouds.azurecompute.arm.domain.FrontendIPConfigurationsProperties;
-import org.jclouds.azurecompute.arm.domain.LoadBalancer;
-import org.jclouds.azurecompute.arm.domain.LoadBalancerProperties;
-import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-
-@Test(groups = "unit", testName = "LoadBalancerApiMockTest", singleThreaded = true)
-public class LoadBalancerApiMockTest extends BaseAzureComputeApiMockTest {
- private final String subscriptionid = "SUBSCRIPTIONID";
- private final String resourcegroup = "myresourcegroup";
- private final String apiVersion = "api-version=2016-03-30";
- private final String lbName = "testLoadBalancer";
-
- public void createLoadBalancer() throws InterruptedException {
- LoadBalancer nsg = newLoadBalancer();
-
- server.enqueue(jsonResponse("/loadbalancercreate.json").setResponseCode(200));
- final LoadBalancerApi nsgApi = api.getLoadBalancerApi(resourcegroup);
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/loadBalancers/%s?%s",
- subscriptionid, resourcegroup, lbName, apiVersion);
-
- String json = "{\"location\":\"westeurope\",\"properties\":{\"frontendIPConfigurations\":[{\"name\":\"ipConfigs\",\"properties\":{}}]}}";
-
- LoadBalancer result = nsgApi.createOrUpdate(lbName, "westeurope", null, nsg.properties());
- assertSent(server, "PUT", path, json);
-
- assertEquals(result.name(), lbName);
- assertEquals(result.location(), "westeurope");
- }
-
- public void getLoadBalancer() throws InterruptedException {
- server.enqueue(jsonResponse("/loadbalancerget.json").setResponseCode(200));
-
- final LoadBalancerApi nsgApi = api.getLoadBalancerApi(resourcegroup);
- LoadBalancer result = nsgApi.get(lbName);
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/loadBalancers/%s?%s",
- subscriptionid, resourcegroup, lbName, apiVersion);
- assertSent(server, "GET", path);
-
- assertEquals(result.name(), lbName);
- assertEquals(result.location(), "westeurope");
- assertEquals(result.properties().loadBalancingRules().size(), 1);
- assertEquals(result.properties().loadBalancingRules().get(0).name(), "lbRule1");
- }
-
- public void getLoadBalancerReturns404() throws InterruptedException {
- server.enqueue(response404());
-
- final LoadBalancerApi nsgApi = api.getLoadBalancerApi(resourcegroup);
- LoadBalancer result = nsgApi.get(lbName);
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/loadBalancers/%s?%s",
- subscriptionid, resourcegroup, lbName, apiVersion);
- assertSent(server, "GET", path);
-
- assertNull(result);
- }
-
- public void listLoadBalancers() throws InterruptedException {
- server.enqueue(jsonResponse("/loadbalancerlist.json").setResponseCode(200));
-
- final LoadBalancerApi nsgApi = api.getLoadBalancerApi(resourcegroup);
- List<LoadBalancer> result = nsgApi.list();
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/loadBalancers?%s",
- subscriptionid, resourcegroup, apiVersion);
- assertSent(server, "GET", path);
-
- assertNotNull(result);
- assertTrue(result.size() > 0);
- }
-
- public void listLoadBalancersReturns404() throws InterruptedException {
- server.enqueue(response404());
-
- final LoadBalancerApi nsgApi = api.getLoadBalancerApi(resourcegroup);
- List<LoadBalancer> result = nsgApi.list();
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/loadBalancers?%s",
- subscriptionid, resourcegroup, apiVersion);
- assertSent(server, "GET", path);
-
- assertTrue(isEmpty(result));
- }
-
- public void deleteLoadBalancer() throws InterruptedException {
- server.enqueue(response202WithHeader());
-
- final LoadBalancerApi nsgApi = api.getLoadBalancerApi(resourcegroup);
- URI uri = nsgApi.delete(lbName);
-
- assertEquals(server.getRequestCount(), 1);
- assertNotNull(uri);
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/loadBalancers/%s?%s",
- subscriptionid, resourcegroup, lbName, apiVersion);
- assertSent(server, "DELETE", path);
-
- assertTrue(uri.toString().contains("api-version"));
- assertTrue(uri.toString().contains("operationresults"));
- }
-
- public void deleteLoadBalancerDoesNotExist() throws InterruptedException {
- server.enqueue(response404());
-
- final LoadBalancerApi nsgApi = api.getLoadBalancerApi(resourcegroup);
- URI uri = nsgApi.delete(lbName);
- assertNull(uri);
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/loadBalancers/%s?%s",
- subscriptionid, resourcegroup, lbName, apiVersion);
- assertSent(server, "DELETE", path);
- }
-
- private LoadBalancer newLoadBalancer() {
- FrontendIPConfigurationsProperties frontendIPConfigurationsProperties = FrontendIPConfigurationsProperties
- .builder().build();
- FrontendIPConfigurations frontendIPConfigurations = FrontendIPConfigurations.create("ipConfigs", null,
- frontendIPConfigurationsProperties, null);
- return LoadBalancer
- .builder()
- .name(lbName)
- .location("westus")
- .properties(
- LoadBalancerProperties.builder().frontendIPConfigurations(ImmutableList.of(frontendIPConfigurations))
- .build()).build();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ac03bac4/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocationApiLiveTest.java
----------------------------------------------------------------------
diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocationApiLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocationApiLiveTest.java
deleted file mode 100644
index 4e37294..0000000
--- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocationApiLiveTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.util.List;
-
-import org.jclouds.azurecompute.arm.domain.Location;
-import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-
-@Test(groups = "live", testName = "LocationApiLiveTest")
-public class LocationApiLiveTest extends BaseAzureComputeApiLiveTest {
-
- @Test
- public void testList() {
- List<Location> locations = api().list();
- assertTrue(!locations.isEmpty());
- for (Location location : locations) {
- checkLocation(location);
- }
- }
-
- private LocationApi api() {
- return api.getLocationApi();
- }
-
- private void checkLocation(final Location location) {
- assertNotNull(location.name(), "Name cannot be null for a Location.");
- assertNotNull(location.displayName(), "DisplayName cannot be null for: " + location.name());
- assertNotNull(location.id(), "Id cannot be null for: " + location.name());
- assertNotNull(location.latitude(), "Latitude cannot be null for: " + location.name());
- assertNotNull(location.longitude(), "Longitude cannot be null for: " + location.name());
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ac03bac4/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocationApiMockTest.java
----------------------------------------------------------------------
diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocationApiMockTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocationApiMockTest.java
deleted file mode 100644
index 5ea60d4..0000000
--- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocationApiMockTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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 com.google.common.collect.ImmutableList;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import org.jclouds.azurecompute.arm.domain.Location;
-import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-@Test(groups = "unit", testName = "LocationApiMockTest", singleThreaded = true)
-public class LocationApiMockTest extends BaseAzureComputeApiMockTest {
-
- public void testList() throws Exception {
- server.enqueue(jsonResponse("/locations.json"));
- final LocationApi locationAPI = api.getLocationApi();
- assertEquals(locationAPI.list(), ImmutableList.of(
- Location.create("/subscriptions/SUBSCRIPTIONID/locations/eastasia",
- "eastasia", "East Asia", 114.188, 22.267)
- ));
- assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/locations?api-version=2015-11-01");
- }
-
- public void testEmptyList() throws Exception {
- server.enqueue(new MockResponse().setResponseCode(404));
-
- final LocationApi locationAPI = api.getLocationApi();
-
- assertTrue(locationAPI.list().isEmpty());
-
- assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/locations?api-version=2015-11-01");
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ac03bac4/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricDefinitionsApiLiveTest.java
----------------------------------------------------------------------
diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricDefinitionsApiLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricDefinitionsApiLiveTest.java
deleted file mode 100644
index cb8027f..0000000
--- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricDefinitionsApiLiveTest.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * 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.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Iterables.getOnlyElement;
-import static org.jclouds.azurecompute.arm.compute.options.AzureTemplateOptions.Builder.resourceGroup;
-import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.TIMEOUT_RESOURCE_DELETED;
-import static org.jclouds.compute.predicates.NodePredicates.inGroup;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
-import java.net.URI;
-import java.util.List;
-import java.util.Properties;
-
-import org.jclouds.azurecompute.arm.AzureComputeApi;
-import org.jclouds.azurecompute.arm.domain.IdReference;
-import org.jclouds.azurecompute.arm.domain.MetricDefinition;
-import org.jclouds.azurecompute.arm.internal.AzureLiveTestUtils;
-import org.jclouds.compute.RunNodesException;
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Predicate;
-import com.google.inject.Key;
-import com.google.inject.TypeLiteral;
-import com.google.inject.name.Names;
-
-@Test(groups = "live", singleThreaded = true)
-public class MetricDefinitionsApiLiveTest extends BaseComputeServiceContextLiveTest {
-
- private Predicate<URI> resourceDeleted;
- private AzureComputeApi api;
-
- private String location;
- private MetricDefinitionsApi metricDefinitionsApi;
-
- private String group;
-
- public MetricDefinitionsApiLiveTest() {
- provider = "azurecompute-arm";
- group = getClass().getSimpleName().toLowerCase();
- }
-
- @Override
- protected Properties setupProperties() {
- Properties properties = super.setupProperties();
- AzureLiveTestUtils.defaultProperties(properties);
- checkNotNull(setIfTestSystemPropertyPresent(properties, "oauth.endpoint"), "test.oauth.endpoint");
- return properties;
- }
-
- @Override
- protected void initializeContext() {
- super.initializeContext();
- resourceDeleted = context.utils().injector().getInstance(Key.get(new TypeLiteral<Predicate<URI>>() {
- }, Names.named(TIMEOUT_RESOURCE_DELETED)));
- api = view.unwrapApi(AzureComputeApi.class);
- }
-
- @Override
- @BeforeClass
- public void setupContext() {
- super.setupContext();
- NodeMetadata node = null;
- try {
- node = getOnlyElement(view.getComputeService().createNodesInGroup(group, 1, resourceGroup(group)));
- } catch (RunNodesException e) {
- fail();
- }
- String resourceId = String.format("/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s",
- IdReference.extractResourceGroup(node.getProviderId()), IdReference.extractName(node.getProviderId()));
-
- location = view.getComputeService().templateBuilder().build().getLocation().getId();
- view.unwrapApi(AzureComputeApi.class).getResourceGroupApi().create(group, location, null);
- metricDefinitionsApi = api.getMetricsDefinitionsApi(resourceId);
- }
-
- @Override
- @AfterClass(alwaysRun = true)
- protected void tearDownContext() {
- try {
- view.getComputeService().destroyNodesMatching(inGroup(group));
- } finally {
- try {
- URI uri = api.getResourceGroupApi().delete(group);
- assertResourceDeleted(uri);
- } finally {
- super.tearDownContext();
- }
- }
- }
-
- public void listVirtualMachineMetricDefinitions() {
- List<MetricDefinition> result = metricDefinitionsApi.list("name.value eq 'Percentage CPU'");
-
- // verify we have something
- assertNotNull(result);
- assertTrue(result.size() > 1);
- assertEquals(result.get(0).name().value(), "Percentage CPU");
- }
-
- private void assertResourceDeleted(final URI uri) {
- if (uri != null) {
- assertTrue(resourceDeleted.apply(uri),
- String.format("Resource %s was not deleted in the configured timeout", uri));
- }
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ac03bac4/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricDefinitionsApiMockTest.java
----------------------------------------------------------------------
diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricDefinitionsApiMockTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricDefinitionsApiMockTest.java
deleted file mode 100644
index 8fd06b8..0000000
--- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricDefinitionsApiMockTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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 org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import org.jclouds.azurecompute.arm.domain.MetricDefinition;
-import org.jclouds.azurecompute.arm.domain.MetricName;
-import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-
-@Test(groups = "unit", testName = "MetricDefinitionsApiMockTest", singleThreaded = true)
-public class MetricDefinitionsApiMockTest extends BaseAzureComputeApiMockTest {
-
- private final String resourceId = "resourceGroups/myresourceGroup/providers/Microsoft.Compute/virtualMachines/myvm";
- private final String filter = "(name.value eq 'Percentage CPU')";
-
- public void testList() throws Exception {
- server.enqueue(jsonResponse("/metricdefinitions.json"));
- final MetricDefinitionsApi metricDefinitionsApi = api.getMetricsDefinitionsApi(resourceId);
- assertEquals(metricDefinitionsApi.list(filter), ImmutableList.of(MetricDefinition.create(
- "/subscriptions/SUBSCRIPTIONID/resourceGroups/myresourcegroup/providers/Microsoft"
- + ".Compute/virtualMachines/myvm", MetricName.create("Percentage CPU", "Percentage CPU"),
- Boolean.FALSE, "Percent", MetricDefinition.AggregationType.Average,
- ImmutableList.<MetricDefinition.MetricAvailability> of(
- MetricDefinition.MetricAvailability.create("PT1M", "P30D"),
- MetricDefinition.MetricAvailability.create("PT1H", "P30D")),
- "/subscriptions/SUBSCRIPTIONID/resourceGroups/myresourcegroup/providers"
- + "/Microsoft.Compute/virtualMachines/myvm/providers/microsoft"
- + ".insights/metricdefinitions/Percentage " + "CPU")));
- assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/resourceGroups/myresourceGroup/providers/Microsoft"
- + ".Compute/virtualMachines/myvm/providers/microsoft.insights/metricdefinitions?$filter=%28name"
- + ".value%20eq%20%27Percentage%20CPU%27%29&api-version=2017-05-01-preview");
- }
-
- public void testEmptyList() throws Exception {
- server.enqueue(new MockResponse().setResponseCode(404));
-
- final MetricDefinitionsApi metricDefinitionsApi = api.getMetricsDefinitionsApi(resourceId);
-
- assertTrue(metricDefinitionsApi.list(filter).isEmpty());
-
- assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/resourceGroups/myresourceGroup/providers/Microsoft"
- + ".Compute/virtualMachines/myvm/providers/microsoft.insights/metricdefinitions?$filter=%28name"
- + ".value%20eq%20%27Percentage%20CPU%27%29&api-version=2017-05-01-preview");
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ac03bac4/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricsApiLiveTest.java
----------------------------------------------------------------------
diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricsApiLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricsApiLiveTest.java
deleted file mode 100644
index 5fe19db..0000000
--- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricsApiLiveTest.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * 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.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Iterables.getOnlyElement;
-import static org.jclouds.azurecompute.arm.compute.options.AzureTemplateOptions.Builder.resourceGroup;
-import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.TIMEOUT_RESOURCE_DELETED;
-import static org.jclouds.compute.predicates.NodePredicates.inGroup;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
-import java.net.URI;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.Properties;
-
-import org.jclouds.azurecompute.arm.AzureComputeApi;
-import org.jclouds.azurecompute.arm.domain.IdReference;
-import org.jclouds.azurecompute.arm.domain.Metric;
-import org.jclouds.azurecompute.arm.internal.AzureLiveTestUtils;
-import org.jclouds.compute.RunNodesException;
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Predicate;
-import com.google.inject.Key;
-import com.google.inject.TypeLiteral;
-import com.google.inject.name.Names;
-
-@Test(groups = "live", singleThreaded = true)
-public class MetricsApiLiveTest extends BaseComputeServiceContextLiveTest {
-
- private Predicate<URI> resourceDeleted;
- private AzureComputeApi api;
-
- private String location;
- private MetricsApi metricsApi;
-
- private String group;
-
- private String startTime;
- private SimpleDateFormat dateFormat;
-
- public MetricsApiLiveTest() {
- provider = "azurecompute-arm";
- group = getClass().getSimpleName().toLowerCase();
- }
-
- @Override
- protected Properties setupProperties() {
- Properties properties = super.setupProperties();
- AzureLiveTestUtils.defaultProperties(properties);
- checkNotNull(setIfTestSystemPropertyPresent(properties, "oauth.endpoint"), "test.oauth.endpoint");
- return properties;
- }
-
- @Override
- protected void initializeContext() {
- super.initializeContext();
- resourceDeleted = context.utils().injector().getInstance(Key.get(new TypeLiteral<Predicate<URI>>() {
- }, Names.named(TIMEOUT_RESOURCE_DELETED)));
- api = view.unwrapApi(AzureComputeApi.class);
- }
-
- @Override
- @BeforeClass
- public void setupContext() {
- super.setupContext();
-
- dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
- startTime = dateFormat.format(new Date());
-
- NodeMetadata node = null;
- try {
- node = getOnlyElement(view.getComputeService().createNodesInGroup(group, 1, resourceGroup(group)));
- } catch (RunNodesException e) {
- fail();
- }
- String resourceId = String.format("/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s",
- IdReference.extractResourceGroup(node.getProviderId()), IdReference.extractName(node.getProviderId()));
-
- location = view.getComputeService().templateBuilder().build().getLocation().getId();
- view.unwrapApi(AzureComputeApi.class).getResourceGroupApi().create(group, location, null);
- metricsApi = api.getMetricsApi(resourceId);
- }
-
- @Override
- @AfterClass(alwaysRun = true)
- protected void tearDownContext() {
- try {
- view.getComputeService().destroyNodesMatching(inGroup(group));
- } finally {
- try {
- URI uri = api.getResourceGroupApi().delete(group);
- assertResourceDeleted(uri);
- } finally {
- super.tearDownContext();
- }
- }
- }
-
- public void listVirtualMachineMetrics() throws RunNodesException {
- List<Metric> result = metricsApi
- .list("(name.value eq 'Percentage CPU') and startTime eq " + startTime + " and endTime eq " + dateFormat
- .format(new Date()) + " and timeGrain eq duration'PT1M'");
-
- // verify we have something
- assertNotNull(result);
- assertEquals(result.size(), 1);
- assertEquals(result.get(0).name().value(), "Percentage CPU");
- assertTrue(result.get(0).data().size() > 1);
- }
-
- private void assertResourceDeleted(final URI uri) {
- if (uri != null) {
- assertTrue(resourceDeleted.apply(uri),
- String.format("Resource %s was not deleted in the configured timeout", uri));
- }
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ac03bac4/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricsApiMockTest.java
----------------------------------------------------------------------
diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricsApiMockTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricsApiMockTest.java
deleted file mode 100644
index 2001d19..0000000
--- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricsApiMockTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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 org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Date;
-
-import org.jclouds.azurecompute.arm.domain.Metric;
-import org.jclouds.azurecompute.arm.domain.MetricData;
-import org.jclouds.azurecompute.arm.domain.MetricName;
-import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-
-@Test(groups = "unit", testName = "MetricsApiMockTest", singleThreaded = true)
-public class MetricsApiMockTest extends BaseAzureComputeApiMockTest {
-
- private final String resourceId = "resourceGroups/myresourceGroup/providers/Microsoft.Compute/virtualMachines/myvm";
- private final String filter = "(name.value eq 'Percentage CPU') and startTime eq 2017-06-01T11:14:00Z and "
- + "endTime eq 2017-06-01T11:23:00Z and timeGrain eq duration'PT1M'";
-
- public void testList() throws Exception {
- server.enqueue(jsonResponse("/metrics.json"));
- final MetricsApi metricsApi = api.getMetricsApi(resourceId);
- Date timestamp = dateService.iso8601DateOrSecondsDateParse("2017-06-01T11:14:00Z");
- assertEquals(metricsApi.list(filter), ImmutableList.of(Metric.create(
- ImmutableList.of(MetricData.create(timestamp, null, Double.valueOf(0.295), null, null, null)),
- "/subscriptions/SUBSCRIPTIONID/resourceGroups/myresourcegroup/providers"
- + "/Microsoft.Compute/virtualMachines/myvm/providers/Microsoft.Insights/metrics/Percentage CPU",
- MetricName.create("Percentage CPU", "Percentage CPU"), "Microsoft.Insights/metrics", "Percent")));
- assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/resourceGroups/myresourceGroup/providers/Microsoft"
- + ".Compute/virtualMachines/myvm/providers/microsoft.insights/metrics?$filter=%28name"
- + ".value%20eq%20%27Percentage%20CPU%27%29%20and%20startTime%20eq%202017-06-01T11%3A14%3A00Z%20and"
- + "%20endTime%20eq%202017-06-01T11%3A23%3A00Z%20and%20timeGrain%20eq%20duration%27PT1M%27&api-version"
- + "=2016-09-01");
- }
-
- public void testEmptyList() throws Exception {
- server.enqueue(new MockResponse().setResponseCode(404));
-
- final MetricsApi metricsAPI = api.getMetricsApi(resourceId);
-
- assertTrue(metricsAPI.list(filter).isEmpty());
-
- assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/resourceGroups/myresourceGroup/providers/Microsoft"
- + ".Compute/virtualMachines/myvm/providers/microsoft.insights/metrics?$filter=%28name"
- + ".value%20eq%20%27Percentage%20CPU%27%29%20and%20startTime%20eq%202017-06-01T11%3A14%3A00Z%20and"
- + "%20endTime%20eq%202017-06-01T11%3A23%3A00Z%20and%20timeGrain%20eq%20duration%27PT1M%27&api-version"
- + "=2016-09-01");
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ac03bac4/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiLiveTest.java
----------------------------------------------------------------------
diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiLiveTest.java
deleted file mode 100644
index cd95a2c..0000000
--- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiLiveTest.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * 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 org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-
-import java.net.URI;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import org.jclouds.azurecompute.arm.domain.IdReference;
-import org.jclouds.azurecompute.arm.domain.IpConfiguration;
-import org.jclouds.azurecompute.arm.domain.IpConfigurationProperties;
-import org.jclouds.azurecompute.arm.domain.NetworkInterfaceCard;
-import org.jclouds.azurecompute.arm.domain.NetworkInterfaceCardProperties;
-import org.jclouds.azurecompute.arm.domain.Subnet;
-import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableMap;
-
-@Test(groups = "live", singleThreaded = true)
-public class NetworkInterfaceCardApiLiveTest extends BaseAzureComputeApiLiveTest {
-
- private String subnetId;
- private String nicName;
-
- @BeforeClass
- @Override
- public void setup() {
- super.setup();
- createTestResourceGroup();
- assertNotNull(api.getResourceGroupApi().create(resourceGroupName, LOCATION, ImmutableMap.<String, String>of()));
- String virtualNetworkName = String.format("vn-%s-%s", this.getClass().getSimpleName().toLowerCase(), System.getProperty("user.name"));
- nicName = String.format("nic-%s-%s", this.getClass().getSimpleName().toLowerCase(), System.getProperty("user.name"));
- String subnetName = String.format("s-%s-%s", this.getClass().getSimpleName().toLowerCase(), System.getProperty("user.name"));
-
- //Subnets belong to a virtual network so that needs to be created first
- assertNotNull(createDefaultVirtualNetwork(resourceGroupName, virtualNetworkName, "10.2.0.0/16", LOCATION));
-
- //Subnet needs to be up & running before NIC can be created
- Subnet subnet = createDefaultSubnet(resourceGroupName, subnetName, virtualNetworkName, "10.2.0.0/23");
- assertNotNull(subnet);
- assertNotNull(subnet.id());
- subnetId = subnet.id();
- }
-
- @Test
- public void createNetworkInterfaceCard() {
- //Create properties object
- final NetworkInterfaceCardProperties networkInterfaceCardProperties =
- NetworkInterfaceCardProperties.builder().ipConfigurations(
- Arrays.asList(IpConfiguration.builder()
- .name("myipconfig")
- .properties(IpConfigurationProperties.builder()
- .privateIPAllocationMethod("Dynamic")
- .subnet(IdReference.create(subnetId)).build()
- ).build()
- )).build();
-
- final Map<String, String> tags = ImmutableMap.of("jclouds", "livetest");
- NetworkInterfaceCard nic = api().createOrUpdate(nicName, LOCATION, networkInterfaceCardProperties, tags);
-
- assertEquals(nic.name(), nicName);
- assertEquals(nic.location(), LOCATION);
- assertTrue(nic.properties().ipConfigurations().size() > 0);
- assertEquals(nic.properties().ipConfigurations().get(0).name(), "myipconfig");
- assertEquals(nic.properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(), "Dynamic");
- assertEquals(nic.properties().ipConfigurations().get(0).properties().subnet().id(), subnetId);
- assertEquals(nic.tags().get("jclouds"), "livetest");
- }
-
- @Test(dependsOnMethods = "createNetworkInterfaceCard")
- public void getNetworkInterfaceCard() {
- NetworkInterfaceCard nic = api().get(nicName);
-
- assertEquals(nic.name(), nicName);
- assertEquals(nic.location(), LOCATION);
- assertTrue(nic.properties().ipConfigurations().size() > 0);
- assertEquals(nic.properties().ipConfigurations().get(0).name(), "myipconfig");
- assertEquals(nic.properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(), "Dynamic");
- assertEquals(nic.properties().ipConfigurations().get(0).properties().subnet().id(), subnetId);
- }
-
- @Test(dependsOnMethods = "createNetworkInterfaceCard")
- public void listNetworkInterfaceCards() {
- List<NetworkInterfaceCard> nicList = api().list();
- assertTrue(nicList.contains(api().get(nicName)));
- }
-
- @Test(dependsOnMethods = {"listNetworkInterfaceCards", "getNetworkInterfaceCard"})
- public void deleteNetworkInterfaceCard() {
- URI uri = api().delete(nicName);
- assertResourceDeleted(uri);
- }
-
- private NetworkInterfaceCardApi api() {
- return api.getNetworkInterfaceCardApi(resourceGroupName);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ac03bac4/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiMockTest.java
----------------------------------------------------------------------
diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiMockTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiMockTest.java
deleted file mode 100644
index dd10046..0000000
--- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiMockTest.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * 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 com.google.common.collect.ImmutableMap;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import org.jclouds.azurecompute.arm.domain.IdReference;
-import org.jclouds.azurecompute.arm.domain.IpConfiguration;
-import org.jclouds.azurecompute.arm.domain.IpConfigurationProperties;
-import org.jclouds.azurecompute.arm.domain.NetworkInterfaceCard;
-import org.jclouds.azurecompute.arm.domain.NetworkInterfaceCardProperties;
-import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest;
-import org.testng.annotations.Test;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.assertEquals;
-
-@Test(groups = "unit", testName = "NetworkInterfaceCardApiMockTest", singleThreaded = true)
-public class NetworkInterfaceCardApiMockTest extends BaseAzureComputeApiMockTest {
-
- private final String subscriptionid = "SUBSCRIPTIONID";
- private final String resourcegroup = "myresourcegroup";
- private final String apiVersion = "api-version=2017-03-01";
- private final String location = "northeurope";
- private final String nicName = "myNic";
-
- public void getNetworkInterfaceCard() throws InterruptedException {
- server.enqueue(jsonResponse("/getnetworkinterfacecard.json"));
-
- final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup);
- NetworkInterfaceCard nic = nicApi.get(nicName);
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces/%s?%s", subscriptionid, resourcegroup, nicName, apiVersion);
- assertSent(server, "GET", path);
- assertNotNull(nic);
- assertEquals(nic.name(), nicName);
- assertEquals(nic.properties().ipConfigurations().get(0).name(), "myip1");
- assertEquals(nic.tags().get("mycustomtag"), "foobar");
- }
-
- public void getNetworkInterfaceCardEmpty() throws Exception {
- server.enqueue(new MockResponse().setResponseCode(404));
-
- final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup);
-
- assertNull(nicApi.get(nicName));
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces/%s?%s", subscriptionid, resourcegroup, nicName, apiVersion);
- assertSent(server, "GET", path);
- }
-
- public void listNetworkInterfaceCards() throws InterruptedException {
- server.enqueue(jsonResponse("/listnetworkinterfaces.json"));
-
- final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup);
- List<NetworkInterfaceCard> nicList = nicApi.list();
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces?%s", subscriptionid, resourcegroup, apiVersion);
-
- assertSent(server, "GET", path);
- assertTrue(nicList.size() == 2);
- assertTrue(nicList.get(0).properties().ipConfigurations().size() > 0);
- assertEquals(nicList.get(0).properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(), "Dynamic");
- assertTrue(nicList.get(1).properties().ipConfigurations().size() > 0);
- assertEquals(nicList.get(1).properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(), "Static");
- }
-
- public void listNetworkInterfaceCardsEmpty() throws Exception {
- server.enqueue(new MockResponse().setResponseCode(404));
-
- final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup);
-
- assertTrue(nicApi.list().isEmpty());
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces?%s", subscriptionid, resourcegroup, apiVersion);
-
- assertSent(server, "GET", path);
- }
-
- public void createNetworkInterfaceCard() throws InterruptedException {
-
- server.enqueue(jsonResponse("/createnetworkinterfacecard.json").setStatus("HTTP/1.1 201 Created"));
-
- final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup);
-
-
- final String SubnetID = "/subscriptions/" + subscriptionid + "/resourceGroups/azurearmtesting/providers/Microsoft.Network/virtualNetworks/myvirtualnetwork/subnets/mysubnet";
- //Create properties object
- final NetworkInterfaceCardProperties networkInterfaceCardProperties = NetworkInterfaceCardProperties.create(null,
- null, null, Arrays.asList(IpConfiguration.create("myipconfig", null, null, null, IpConfigurationProperties
- .create(null, null, "Dynamic", IdReference.create(SubnetID), null, null, null))), null);
-
- final Map<String, String> tags = ImmutableMap.of("mycustomtag", "foobar");
-
- NetworkInterfaceCard nic = nicApi.createOrUpdate(nicName, location, networkInterfaceCardProperties, tags);
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces/%s?%s", subscriptionid, resourcegroup, nicName, apiVersion);
- String json = String.format("{ \"location\":\"%s\", \"tags\": { \"mycustomtag\": \"foobar\" }, \"properties\":{ \"ipConfigurations\":[ { \"name\":\"%s\", \"properties\":{ \"subnet\":{ \"id\": \"%s\" }, \"privateIPAllocationMethod\":\"%s\" } } ] } }", location, "myipconfig", SubnetID, "Dynamic");
- assertSent(server, "PUT", path, json);
- assertEquals(nic.tags().get("mycustomtag"), "foobar");
- }
-
- public void deleteNetworkInterfaceCard() throws InterruptedException {
-
- server.enqueue(response202WithHeader());
-
- final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup);
-
- nicApi.delete(nicName);
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces/%s?%s", subscriptionid, resourcegroup, nicName, apiVersion);
- assertSent(server, "DELETE", path);
-
- }
-
- public void deleteNetworkInterfaceCardResourceDoesNotExist() throws InterruptedException {
-
- server.enqueue(response404());
-
- final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup);
-
- nicApi.delete(nicName);
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces/%s?%s", subscriptionid, resourcegroup, nicName, apiVersion);
- assertSent(server, "DELETE", path);
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ac03bac4/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkSecurityGroupApiLiveTest.java
----------------------------------------------------------------------
diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkSecurityGroupApiLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkSecurityGroupApiLiveTest.java
deleted file mode 100644
index 3a2f4eb..0000000
--- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkSecurityGroupApiLiveTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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 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.NetworkSecurityGroup;
-import org.jclouds.azurecompute.arm.domain.NetworkSecurityRule;
-import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-@Test(groups = "live", singleThreaded = true)
-public class NetworkSecurityGroupApiLiveTest extends BaseAzureComputeApiLiveTest {
-
- private static String nsgName = "testNetworkSecurityGroup";
-
- @BeforeClass
- @Override
- public void setup() {
- super.setup();
- createTestResourceGroup();
- nsgName = String.format("nsg-%s-%s", this.getClass().getSimpleName().toLowerCase(), System.getProperty("user.name"));
- }
-
- @Test
- public void deleteNetworkSecurityGroupDoesNotExist() {
- URI uri = api().delete(nsgName);
- assertNull(uri);
- }
-
- @Test(dependsOnMethods = "deleteNetworkSecurityGroupDoesNotExist")
- public void createNetworkSecurityGroup() {
- final NetworkSecurityGroup nsg = newNetworkSecurityGroup(nsgName, LOCATION);
- assertNotNull(nsg);
-
- NetworkSecurityGroup result = api().createOrUpdate(nsgName,
- nsg.location(),
- nsg.tags(),
- nsg.properties());
- assertNotNull(result);
- }
-
- @Test(dependsOnMethods = "createNetworkSecurityGroup")
- public void listNetworkSecurityGroups() {
- List<NetworkSecurityGroup> result = api().list();
-
- // verify we have something
- assertNotNull(result);
- assertEquals(result.size(), 1);
-
- // check that the nework security group matches the one we originally passed in
- NetworkSecurityGroup original = newNetworkSecurityGroup(nsgName, LOCATION);
- NetworkSecurityGroup nsg = result.get(0);
- assertEquals(original.name(), nsg.name());
- assertEquals(original.location(), nsg.location());
- assertEquals(original.tags(), nsg.tags());
-
- // check the network security rule in the group
- assertEquals(nsg.properties().securityRules().size(), 1);
- NetworkSecurityRule originalRule = original.properties().securityRules().get(0);
- NetworkSecurityRule nsgRule = nsg.properties().securityRules().get(0);
- assertEquals(originalRule.name(), nsgRule.name());
- assertTrue(originalRule.properties().equals(nsgRule.properties()));
- }
-
- @Test(dependsOnMethods = {"listNetworkSecurityGroups", "getNetworkSecurityGroup"}, alwaysRun = true)
- public void deleteNetworkSecurityGroup() {
- URI uri = api().delete(nsgName);
- assertResourceDeleted(uri);
- }
-
- @Test(dependsOnMethods = "createNetworkSecurityGroup")
- public void getNetworkSecurityGroup() {
- NetworkSecurityGroup nsg = api().get(nsgName);
- assertNotNull(nsg);
- assertNotNull(nsg.etag());
- assertEquals(nsg.name(), nsgName);
- }
-
- private NetworkSecurityGroupApi api() {
- return api.getNetworkSecurityGroupApi(resourceGroupName);
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ac03bac4/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkSecurityGroupApiMockTest.java
----------------------------------------------------------------------
diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkSecurityGroupApiMockTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkSecurityGroupApiMockTest.java
deleted file mode 100644
index 3dc0e4a..0000000
--- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkSecurityGroupApiMockTest.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * 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 com.google.gson.Gson;
-import org.jclouds.azurecompute.arm.domain.NetworkSecurityGroup;
-import org.jclouds.azurecompute.arm.domain.NetworkSecurityGroupProperties;
-import org.jclouds.azurecompute.arm.domain.NetworkSecurityRule;
-import org.jclouds.azurecompute.arm.domain.NetworkSecurityRuleProperties;
-import org.jclouds.azurecompute.arm.domain.NetworkSecurityRuleProperties.Protocol;
-import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest;
-import org.testng.annotations.Test;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-
-import static com.google.common.collect.Iterables.isEmpty;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-
-@Test(groups = "unit", testName = "NetworkSecurityGroupApiMockTest", singleThreaded = true)
-public class NetworkSecurityGroupApiMockTest extends BaseAzureComputeApiMockTest {
- private final String subscriptionid = "SUBSCRIPTIONID";
- private final String resourcegroup = "myresourcegroup";
- private final String apiVersion = "api-version=2016-03-30";
- private static String DEFAULT_NSG_NAME = "testNetworkSecurityGroup";
-
- private NetworkSecurityGroup createGroup() {
- NetworkSecurityRule rule = NetworkSecurityRule.create("denyallout", null, null,
- NetworkSecurityRuleProperties.builder()
- .description("deny all out")
- .protocol(Protocol.Tcp)
- .sourcePortRange("*")
- .destinationPortRange("*")
- .sourceAddressPrefix("*")
- .destinationAddressPrefix("*")
- .access(NetworkSecurityRuleProperties.Access.Deny)
- .priority(4095)
- .direction(NetworkSecurityRuleProperties.Direction.Outbound)
- .build());
- ArrayList<NetworkSecurityRule> ruleList = new ArrayList<NetworkSecurityRule>();
- ruleList.add(rule);
- NetworkSecurityGroup nsg = NetworkSecurityGroup.create("id", "samplensg", "westus", null,
- NetworkSecurityGroupProperties.builder()
- .securityRules(ruleList)
- .build(),
- null);
- return nsg;
- }
-
- public void createNetworkSecurityGroup() throws InterruptedException {
- NetworkSecurityGroup nsg = createGroup();
-
- server.enqueue(jsonResponse("/networksecuritygroupcreate.json").setResponseCode(200));
- final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, apiVersion);
- String json = String.format("{\"location\":\"%s\",\"properties\":%s}", "westus", new Gson().toJson(nsg.properties()));
- NetworkSecurityGroup result = nsgApi.createOrUpdate(DEFAULT_NSG_NAME, "westus", null, nsg.properties());
- assertSent(server, "PUT", path, json);
-
- assertEquals(result.name(), DEFAULT_NSG_NAME);
- assertEquals(result.location(), "westus");
- assertEquals(result.properties().securityRules().size(), 1);
- assertEquals(result.properties().securityRules().get(0).properties().protocol(), Protocol.Tcp);
- }
-
- public void getNetworkSecurityGroup() throws InterruptedException {
- server.enqueue(jsonResponse("/networksecuritygroupget.json").setResponseCode(200));
-
- final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
- NetworkSecurityGroup result = nsgApi.get(DEFAULT_NSG_NAME);
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, apiVersion);
- assertSent(server, "GET", path);
-
- assertEquals(result.name(), DEFAULT_NSG_NAME);
- assertEquals(result.location(), "westus");
- assertEquals(result.properties().securityRules().size(), 1);
- assertEquals(result.properties().securityRules().get(0).properties().protocol(), Protocol.Tcp);
- }
-
- public void getNetworkSecurityGroupReturns404() throws InterruptedException {
- server.enqueue(response404());
-
- final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
- NetworkSecurityGroup result = nsgApi.get(DEFAULT_NSG_NAME);
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, apiVersion);
- assertSent(server, "GET", path);
-
- assertNull(result);
- }
-
- public void listNetworkSecurityGroups() throws InterruptedException {
- server.enqueue(jsonResponse("/networksecuritygrouplist.json").setResponseCode(200));
-
- final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
- List<NetworkSecurityGroup> result = nsgApi.list();
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups?%s", subscriptionid, resourcegroup, apiVersion);
- assertSent(server, "GET", path);
-
- assertNotNull(result);
- assertTrue(result.size() > 0);
- }
-
- public void listNetworkSecurityGroupsReturns404() throws InterruptedException {
- server.enqueue(response404());
-
- final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
- List<NetworkSecurityGroup> result = nsgApi.list();
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups?%s", subscriptionid, resourcegroup, apiVersion);
- assertSent(server, "GET", path);
-
- assertTrue(isEmpty(result));
- }
-
- public void deleteNetworkSecurityGroup() throws InterruptedException {
- server.enqueue(response202WithHeader());
-
- final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
- URI uri = nsgApi.delete(DEFAULT_NSG_NAME);
-
- assertEquals(server.getRequestCount(), 1);
- assertNotNull(uri);
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, apiVersion);
- assertSent(server, "DELETE", path);
-
- assertTrue(uri.toString().contains("api-version"));
- assertTrue(uri.toString().contains("operationresults"));
- }
-
- public void deleteNetworkSecurityGroupDoesNotExist() throws InterruptedException {
- server.enqueue(response404());
-
- final NetworkSecurityGroupApi nsgApi = api.getNetworkSecurityGroupApi(resourcegroup);
- URI uri = nsgApi.delete(DEFAULT_NSG_NAME);
- assertNull(uri);
-
- String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s?%s", subscriptionid, resourcegroup, DEFAULT_NSG_NAME, apiVersion);
- assertSent(server, "DELETE", path);
- }
-}