http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/test/java/org/jclouds/azurecompute/compute/AzureComputeServiceContextLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/compute/AzureComputeServiceContextLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/compute/AzureComputeServiceContextLiveTest.java deleted file mode 100644 index dbcfd38..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/compute/AzureComputeServiceContextLiveTest.java +++ /dev/null @@ -1,127 +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.compute; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.jclouds.compute.predicates.NodePredicates.inGroup; -import static org.jclouds.compute.predicates.NodePredicates.runningInGroup; -import java.util.Map; -import java.util.Random; -import java.util.Set; - -import org.jclouds.azurecompute.compute.options.AzureComputeTemplateOptions; -import org.jclouds.azurecompute.internal.BaseAzureComputeApiLiveTest; -import org.jclouds.compute.RunNodesException; -import org.jclouds.compute.RunScriptOnNodesException; -import org.jclouds.compute.domain.ExecResponse; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.Template; -import org.jclouds.compute.domain.TemplateBuilder; -import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.google.inject.Module; - -@Test(groups = "live", testName = "AzureComputeServiceContextLiveTest") -public class AzureComputeServiceContextLiveTest extends BaseComputeServiceContextLiveTest { - - private static final int COUNT = 2; - - @Override - protected Module getSshModule() { - return new SshjSshClientModule(); - } - - public AzureComputeServiceContextLiveTest() { - provider = "azurecompute"; - } - - - @Test - public void testWindowsNode() throws RunNodesException { - final String groupName = String.format("win-%s", System.getProperty("user.name")); - - final TemplateBuilder templateBuilder = view.getComputeService().templateBuilder(); - //templateBuilder.imageId("3a50f22b388a4ff7ab41029918570fa6__Windows-Server-2012-Essentials-20141204-enus"); - templateBuilder.imageId("a699494373c04fc0bc8f2bb1389d6106__Nano_TP4_Azure_20151118_8GB.vhd"); - templateBuilder.hardwareId("BASIC_A2"); - templateBuilder.locationId(BaseAzureComputeApiLiveTest.LOCATION); - final Template template = templateBuilder.build(); - - // test passing custom options - final AzureComputeTemplateOptions options = template.getOptions().as(AzureComputeTemplateOptions.class); - options.inboundPorts(5985); - - try { - Set<? extends NodeMetadata> nodes = view.getComputeService().createNodesInGroup(groupName, 1, template); - assertThat(nodes).hasSize(1); - } finally { - view.getComputeService().destroyNodesMatching(inGroup(groupName)); - } - } - - @Test - public void testLaunchNodes() throws RunNodesException { - final int rand = new Random().nextInt(999); - final String groupName = String.format("%s%d-group-acsclt", System.getProperty("user.name"), rand); - - final TemplateBuilder templateBuilder = view.getComputeService().templateBuilder(); - templateBuilder.imageId(BaseAzureComputeApiLiveTest.IMAGE_NAME); - templateBuilder.hardwareId("BASIC_A0"); - templateBuilder.locationId(BaseAzureComputeApiLiveTest.LOCATION); - final Template template = templateBuilder.build(); - - // test passing custom options - final AzureComputeTemplateOptions options = template.getOptions().as(AzureComputeTemplateOptions.class); - options.inboundPorts(22); - - try { - Set<? extends NodeMetadata> nodes = view.getComputeService().createNodesInGroup(groupName, COUNT, template); - assertThat(nodes).hasSize(COUNT); - - Map<? extends NodeMetadata, ExecResponse> responses = view.getComputeService().runScriptOnNodesMatching(runningInGroup(groupName), "echo hello"); - assertThat(responses).hasSize(COUNT); - - for (ExecResponse execResponse : responses.values()) { - assertThat(execResponse.getOutput().trim()).isEqualTo("hello"); - } - } catch (RunScriptOnNodesException e) { - Assert.fail(); - } finally { - view.getComputeService().destroyNodesMatching(inGroup(groupName)); - } - } - - @Test(expectedExceptions = { IllegalStateException.class }) - public void testNotExistingStorageAccount() throws RunNodesException { - final int rand = new Random().nextInt(999); - final String groupName = String.format("%s%d-group-acsclt", System.getProperty("user.name"), rand); - - final String storageServiceName = "not3x1st1ng"; - - final Template template = view.getComputeService().templateBuilder().build(); - - // test passing custom options - final AzureComputeTemplateOptions options = template.getOptions().as(AzureComputeTemplateOptions.class); - options.storageAccountName(storageServiceName); - - Set<? extends NodeMetadata> nodes = view.getComputeService().createNodesInGroup(groupName, 1, template); - } - -}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/test/java/org/jclouds/azurecompute/compute/AzureComputeServiceLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/compute/AzureComputeServiceLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/compute/AzureComputeServiceLiveTest.java deleted file mode 100644 index 6eb0220..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/compute/AzureComputeServiceLiveTest.java +++ /dev/null @@ -1,63 +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.compute; - -import org.jclouds.azurecompute.internal.BaseAzureComputeApiLiveTest; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.Template; -import org.jclouds.compute.domain.TemplateBuilder; -import org.jclouds.compute.internal.BaseComputeServiceLiveTest; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -@Test(groups = {"integration", "live"}, singleThreaded = true, testName = "AzureComputeServiceLiveTest", alwaysRun = false) -public class AzureComputeServiceLiveTest extends BaseComputeServiceLiveTest { - - public AzureComputeServiceLiveTest() { - super(); - provider = "azurecompute"; - // this is 30 seconds by default, but Azure will take anyway longer because we need to wait for a non-null - // Deployment object to be returned: see the end of AzureComputeServiceAdapter#createNodeWithGroupEncodedIntoName - nonBlockDurationSeconds = 600; - } - - @Override - protected void checkUserMetadataContains(final NodeMetadata node, final ImmutableMap<String, String> userMetadata) { - // Azure doe not support user metadata - } - - @Override - protected void checkTagsInNodeEquals(final NodeMetadata node, final ImmutableSet<String> tags) { - // Azure does not support tags - } - - @Override - protected Module getSshModule() { - return new SshjSshClientModule(); - } - - protected Template buildTemplate(TemplateBuilder templateBuilder) { - return templateBuilder.imageId(BaseAzureComputeApiLiveTest.IMAGE_NAME) - .hardwareId("BASIC_A1") - .locationId(BaseAzureComputeApiLiveTest.LOCATION) - .build(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/test/java/org/jclouds/azurecompute/compute/AzureTemplateBuilderLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/compute/AzureTemplateBuilderLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/compute/AzureTemplateBuilderLiveTest.java deleted file mode 100644 index f900c34..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/compute/AzureTemplateBuilderLiveTest.java +++ /dev/null @@ -1,49 +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.compute; - -import java.util.Set; -import org.jclouds.azurecompute.AzureComputeProviderMetadata; -import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; -import org.jclouds.providers.ProviderMetadata; -import org.testng.annotations.Test; - -@Test(groups = "live", testName = "AzureTemplateBuilderLiveTest") -public class AzureTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { - - private AzureComputeProviderMetadata providerMeta; - - public AzureTemplateBuilderLiveTest() { - super(); - - provider = "azurecompute"; - } - - @Override - protected ProviderMetadata createProviderMetadata() { - if (providerMeta == null) { - providerMeta = new AzureComputeProviderMetadata(); - } - return providerMeta; - } - - @Override - protected Set<String> getIso3166Codes() { - return createProviderMetadata().getIso3166Codes(); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/test/java/org/jclouds/azurecompute/compute/extensions/AzureComputeSecurityGroupExtensionLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/compute/extensions/AzureComputeSecurityGroupExtensionLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/compute/extensions/AzureComputeSecurityGroupExtensionLiveTest.java deleted file mode 100644 index 50a88c0..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/compute/extensions/AzureComputeSecurityGroupExtensionLiveTest.java +++ /dev/null @@ -1,82 +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.compute.extensions; - -import com.google.common.base.Optional; -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.inject.Module; - -import org.jclouds.compute.extensions.internal.BaseSecurityGroupExtensionLiveTest; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.jclouds.compute.ComputeService; -import org.jclouds.compute.domain.SecurityGroup; -import org.jclouds.compute.extensions.SecurityGroupExtension; - -import org.testng.annotations.Test; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; - -/** - * Live test for AzureCompute {@link org.jclouds.compute.extensions.SecurityGroupExtension} implementation. - */ -@Test(groups = "live", singleThreaded = true, testName = "AzureComputeSecurityGroupExtensionLiveTest") -public class AzureComputeSecurityGroupExtensionLiveTest extends BaseSecurityGroupExtensionLiveTest { - - public AzureComputeSecurityGroupExtensionLiveTest() { - super(); - provider = "azurecompute"; - } - - @Override - protected Iterable<Module> setupModules() { - return ImmutableSet.of(getLoggingModule(), credentialStoreModule, getSshModule()); - } - - @Override - protected Module getSshModule() { - return new SshjSshClientModule(); - } - - @BeforeClass(groups = {"integration", "live"}) - public void setup() { - final ComputeService computeService = view.getComputeService(); - - final Optional<SecurityGroupExtension> securityGroupExtension = computeService.getSecurityGroupExtension(); - if (securityGroupExtension.isPresent()) { - final Optional<SecurityGroup> group = Iterables.tryFind(securityGroupExtension.get().listSecurityGroups(), - new Predicate<SecurityGroup>() { - @Override - public boolean apply(final SecurityGroup input) { - return input.getId().equals(secGroupName); - } - }); - - if (group.isPresent()) { - securityGroupExtension.get().removeSecurityGroup(group.get().getId()); - } - } - } - - @AfterClass(groups = {"integration", "live"}, alwaysRun = true) - @Override - protected void tearDownContext() { - super.tearDownContext(); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/test/java/org/jclouds/azurecompute/compute/functions/OSImageToImageTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/compute/functions/OSImageToImageTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/compute/functions/OSImageToImageTest.java deleted file mode 100644 index c4ae3dd..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/compute/functions/OSImageToImageTest.java +++ /dev/null @@ -1,266 +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.compute.functions; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -import java.net.URI; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; - -import org.jclouds.azurecompute.domain.OSImage; -import org.jclouds.azurecompute.domain.Region; -import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.compute.domain.OsFamily; -import org.jclouds.domain.Location; -import org.jclouds.domain.LocationBuilder; -import org.jclouds.domain.LocationScope; - -import org.testng.annotations.Test; - -@Test(groups = "unit", testName = "OSImageToImageTest") -public class OSImageToImageTest { - - public void testImageTransform() { - final OSImageToImage imageToImage = new OSImageToImage(new Supplier<Set<? extends Location>>() { - - private Location getLocation(final String input) { - final LocationBuilder builder = new LocationBuilder(); - builder.id(input); - builder.description(input); - - builder.scope(LocationScope.REGION); - final Region region = Region.byName(input); - if (region != null) { - builder.iso3166Codes(ImmutableSet.of(region.iso3166Code())); - } - - return builder.build(); - } - - @Override - public Set<? extends Location> get() { - return ImmutableSet.of(getLocation("Central US"), getLocation("North Europe")); - } - }); - - for (OSImage osImage : createOSImage()) { - final org.jclouds.compute.domain.Image transformed = imageToImage.apply(osImage); - final OperatingSystem os = OSImageToImage.osFamily().apply(osImage).build(); - assertNotNull(osImage.label()); - assertNotNull(transformed.getId()); - assertEquals(transformed.getId(), osImage.name()); - assertEquals(transformed.getName(), osImage.label()); - assertEquals(transformed.getOperatingSystem().getFamily(), os.getFamily()); - assertEquals(transformed.getOperatingSystem().getVersion(), os.getVersion()); - assertEquals(transformed.getProviderId(), osImage.name()); - final Location location = transformed.getLocation(); - assertEquals(location.getId(), osImage.location()); - } - } - - public void testOperatingSystem() { - ImmutableList<String> version = ImmutableList.of( - "13.1", - "12.04 LTS", - "Windows Server 2008 R2 SP1, June 2012", - "Microsoft SQL Server 2012 Evaluation Edition", - "Windows Server 2012 Release Candidate, July 2012", - "Windows Server 2008 R2 SP1, July 2012", - "OpenLogic CentOS 6.2", - "12.1", - "Linux Enterprise Server", - "RightImage-CentOS-6.4-x64-v13.4" - ); - ImmutableList<OsFamily> osFamily = ImmutableList.of( - OsFamily.SUSE, - OsFamily.UBUNTU, - OsFamily.WINDOWS, - OsFamily.WINDOWS, - OsFamily.WINDOWS, - OsFamily.WINDOWS, - OsFamily.CENTOS, - OsFamily.SUSE, - OsFamily.SUSE, - OsFamily.CENTOS - ); - - List<OSImage> images = createOSImage(); - for (int i = 0; i < images.size(); i++) { - OSImage osImage = images.get(i); - OperatingSystem os = OSImageToImage.osFamily().apply(osImage).build(); - assertEquals(os.getFamily(), osFamily.get(i)); - assertEquals(os.getVersion(), version.get(i)); - } - } - - private static ImmutableList<OSImage> createOSImage() { - return ImmutableList.of( - OSImage.create( - "SUSE__openSUSE-12-1-20120603-en-us-30GB.vhd", // name - "Central US", // location - null, // affinityGroup - "openSUSE 13.1", // label - "openSUSE 13.1 brings updated desktop environments and software, lot of polishing, a brand new KDE theme, " - + "complete systemd integration and many other features.", // description - null, // imageFamily - "MSDN", // category - OSImage.Type.WINDOWS, // os - "SUSE", // publisherName - URI.create("http://example.blob.core.windows.net/disks/myimage.vhd"), // mediaLink - 30, // logicalSizeInGB - Arrays.asList("http://www.ubuntu.com/project/about-ubuntu/licensing")// eula - ), - OSImage.create( - "CANONICAL__Canonical-Ubuntu-12-04-amd64-server-20120528.1.3-en-us-30GB.vhd", // name - "North Europe", // locations - null, // affinityGroup - "Ubuntu Server 12.04 LTS", // label - "Ubuntu Server 12.04 LTS amd64 20120528 Cloud Image", //description - null, // imageFamily - "Canonical", // category - OSImage.Type.LINUX, // os - "Canonical", // publisherName - null, // mediaLink - 30, // logicalSizeInGB - Arrays.asList("http://www.ubuntu.com/project/about-ubuntu/licensing") // eula - ), - OSImage.create( // - "MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd", // name - "North Europe", // locations - null, // affinityGroup - "Windows Server 2008 R2 SP1, June 2012", // label - "Windows Server 2008 R2 is a multi-purpose server.", //description - null, // imageFamily - "Microsoft", // category - OSImage.Type.WINDOWS, // os - "Microsoft", //publisherName - URI.create("http://blobs/disks/mydeployment/MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd"), - // mediaLink - 30, // logicalSizeInGB - Collections.<String>emptyList() // eula - ), - OSImage.create( // - "MSFT__Sql-Server-11EVAL-11.0.2215.0-05152012-en-us-30GB.vhd", // name - "North Europe", // locations - null, // affinityGroup - "Microsoft SQL Server 2012 Evaluation Edition", // label - "SQL Server 2012 Evaluation Edition (64-bit).", //description - null, // imageFamily - "Microsoft", // category - OSImage.Type.WINDOWS, // os - "Microsoft", //publisherName - null, // mediaLink - 30, // logicalSizeInGB - Arrays.asList("http://go.microsoft.com/fwlink/?LinkID=251820", - "http://go.microsoft.com/fwlink/?LinkID=131004") // eula - ), - OSImage.create( // - "MSFT__Win2K12RC-Datacenter-201207.02-en.us-30GB.vhd", // name - "North Europe", // locations - null, // affinityGroup - "Windows Server 2012 Release Candidate, July 2012", // label - "Windows Server 2012 incorporates Microsoft's experience building.", //description - null, // imageFamily - "Microsoft", // category - OSImage.Type.WINDOWS, // os - "Microsoft", //publisherName - null, // mediaLink - 30, // logicalSizeInGB - Collections.<String>emptyList() // eula - ), - OSImage.create( // - "MSFT__Win2K8R2SP1-Datacenter-201207.01-en.us-30GB.vhd", // name - "North Europe", // locations - null, // affinityGroup - "Windows Server 2008 R2 SP1, July 2012", // label - "Windows Server 2008 R2 is a multi-purpose server.", //description - null, // imageFamily - "Microsoft", // category - OSImage.Type.WINDOWS, // os - "Microsoft", //publisherName - null, // mediaLink - 30, // logicalSizeInGB - Collections.<String>emptyList() // eula - ), - OSImage.create( // - "OpenLogic__OpenLogic-CentOS-62-20120531-en-us-30GB.vhd", // name - "North Europe", // locations - null, // affinityGroup - "OpenLogic CentOS 6.2", // label - "This distribution of Linux is based on CentOS.", //description - null, // imageFamily - "OpenLogic", // category - OSImage.Type.LINUX, // os - "openLogic", //publisherName - URI.create("http://blobs/disks/mydeployment/OpenLogic__OpenLogic-CentOS-62-20120531-en-us-30GB.vhd"), - // mediaLink - 30, //logicalSizeInGB - Arrays.asList("http://www.openlogic.com/azure/service-agreement/") // eula - ), - OSImage.create( // - "SUSE__openSUSE-12-1-20120603-en-us-30GB.vhd", // name - "North Europe", // locations - null, // affinityGroup - "openSUSE 12.1", // label - "openSUSE is a free and Linux-based operating system!", //description - null, // imageFamily - "SUSE", // category - OSImage.Type.LINUX, // os - "SUSE", //publisherName - null, // mediaLink - 30, // logicalSizeInGB - Arrays.asList("http://opensuse.org/") // eula - ), - OSImage.create( // - "SUSE__SUSE-Linux-Enterprise-Server-11SP2-20120601-en-us-30GB.vhd", // name - "North Europe", // locations - null, // affinityGroup - "SUSE Linux Enterprise Server", // label - "SUSE Linux Enterprise Server is a highly reliable value.", //description - null, // imageFamily - "SUSE", // category - OSImage.Type.LINUX, // os - "SUSE", //publisherName - null, // mediaLink - 30, // logicalSizeInGB - Arrays.asList("http://www.novell.com/licensing/eula/") // eula - ), - OSImage.create( // - "0b11de9248dd4d87b18621318e037d37__RightImage-CentOS-6.4-x64-v13.4", // name - "North Europe", // locations - null, // affinityGroup - "RightImage-CentOS-6.4-x64-v13.4", // label - null, //description - null, // imageFamily - "RightScale with Linux", // category - OSImage.Type.LINUX, // os - "RightScale with Linux", - null, // mediaLink - 10, // logicalSizeInGB - Collections.<String>emptyList() // No EULA, as RightScale stuffed ';' into the field. - ) - ); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/test/java/org/jclouds/azurecompute/features/AffinityGroupApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/AffinityGroupApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/AffinityGroupApiLiveTest.java deleted file mode 100644 index 62bab24..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/AffinityGroupApiLiveTest.java +++ /dev/null @@ -1,97 +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.features; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.assertNotNull; - -import static org.jclouds.azurecompute.internal.BaseAzureComputeApiLiveTest.LOCATION; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; - -import java.util.List; - -import org.jclouds.azurecompute.domain.AffinityGroup; -import org.jclouds.azurecompute.domain.CreateAffinityGroupParams; -import org.jclouds.azurecompute.domain.UpdateAffinityGroupParams; -import org.jclouds.azurecompute.internal.AbstractAzureComputeApiLiveTest; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; - -@Test(groups = "live", testName = "AffinityGroupApiLiveTest") -public class AffinityGroupApiLiveTest extends AbstractAzureComputeApiLiveTest { - - private static final String GROUP_NAME = String.format("%3.24s", - System.getProperty("user.name") + RAND + "-securityGroup"); - - private AffinityGroupApi api() { - return api.getAffinityGroupApi(); - } - - @Test(dependsOnMethods = "testCreate") - public void testList() { - final List<AffinityGroup> groups = api().list(); - assertFalse(groups.isEmpty()); - - final AffinityGroup matching = Iterables.find(groups, new Predicate<AffinityGroup>() { - - @Override - public boolean apply(final AffinityGroup group) { - return GROUP_NAME.equals(group.name()); - } - }); - assertNotNull(matching); - } - - @Test(dependsOnMethods = "testCreate") - public void testRead() { - final AffinityGroup group = api().get(GROUP_NAME); - assertNotNull(group); - assertEquals(group.name(), GROUP_NAME); - } - - public void testCreate() { - final CreateAffinityGroupParams params = CreateAffinityGroupParams.builder(). - name(GROUP_NAME). - label(GROUP_NAME). - location(LOCATION). - build(); - - final String requestId = api().add(params); - assertTrue(operationSucceeded.apply(requestId), requestId); - } - - @Test(dependsOnMethods = "testCreate") - public void testUpdate() { - final UpdateAffinityGroupParams params = UpdateAffinityGroupParams.builder(). - description(GROUP_NAME + " description"). - build(); - - final String requestId = api().update(GROUP_NAME, params); - assertTrue(operationSucceeded.apply(requestId), requestId); - } - - @AfterClass(alwaysRun = true) - public void testDelete() throws Exception { - final String requestId = api().delete(GROUP_NAME); - assertTrue(operationSucceeded.apply(requestId), requestId); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/test/java/org/jclouds/azurecompute/features/AffinityGroupApiMockTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/AffinityGroupApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/AffinityGroupApiMockTest.java deleted file mode 100644 index 65960c2..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/AffinityGroupApiMockTest.java +++ /dev/null @@ -1,161 +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.features; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.assertNull; - -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; - -import org.jclouds.azurecompute.internal.BaseAzureComputeApiMockTest; -import org.jclouds.azurecompute.xml.ListAffinityGroupsHandlerTest; -import org.jclouds.azurecompute.domain.CreateAffinityGroupParams; -import org.jclouds.azurecompute.domain.UpdateAffinityGroupParams; - -import org.testng.annotations.Test; - -@Test(groups = "unit", testName = "AffinityGroupApiMockTest") -public class AffinityGroupApiMockTest extends BaseAzureComputeApiMockTest { - - public void testList() throws Exception { - final MockWebServer server = mockAzureManagementServer(); - server.enqueue(xmlResponse("/affinityGroups.xml")); - - try { - final AffinityGroupApi api = api(server.getUrl("/")).getAffinityGroupApi(); - - assertEquals(api.list(), ListAffinityGroupsHandlerTest.expected()); - - assertSent(server, "GET", "/affinitygroups"); - } finally { - server.shutdown(); - } - } - - public void testEmptyList() throws Exception { - final MockWebServer server = mockAzureManagementServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - try { - final AffinityGroupApi api = api(server.getUrl("/")).getAffinityGroupApi(); - - assertTrue(api.list().isEmpty()); - - assertSent(server, "GET", "/affinitygroups"); - } finally { - server.shutdown(); - } - } - - public void testRead() throws Exception { - final MockWebServer server = mockAzureManagementServer(); - server.enqueue(xmlResponse("/affinityGroup.xml")); - - try { - final AffinityGroupApi api = api(server.getUrl("/")).getAffinityGroupApi(); - - assertEquals(api.get("Test1"), ListAffinityGroupsHandlerTest.expected().get(0)); - - assertSent(server, "GET", "/affinitygroups/Test1"); - } finally { - server.shutdown(); - } - } - - public void testNullRead() throws Exception { - final MockWebServer server = mockAzureManagementServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - try { - final AffinityGroupApi api = api(server.getUrl("/")).getAffinityGroupApi(); - - assertNull(api.get("Test1")); - - assertSent(server, "GET", "/affinitygroups/Test1"); - } finally { - server.shutdown(); - } - } - - public void testAdd() throws Exception { - final MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - final AffinityGroupApi api = api(server.getUrl("/")).getAffinityGroupApi(); - - final CreateAffinityGroupParams params = CreateAffinityGroupParams.builder().name("mygroup").label("foo"). - location("West Europe").build(); - - assertEquals(api.add(params), "request-1"); - - assertSent(server, "POST", "/affinitygroups", "/createaffinitygroupparams.xml"); - } finally { - server.shutdown(); - } - } - - public void testUpdate() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-2")); - - try { - final AffinityGroupApi api = api(server.getUrl("/")).getAffinityGroupApi(); - - final UpdateAffinityGroupParams params = UpdateAffinityGroupParams.builder().label("foo"). - description("mygroup description").build(); - - assertEquals(api.update("mygroup", params), "request-2"); - - assertSent(server, "PUT", "/affinitygroups/mygroup", "/updateaffinitygroupparams.xml"); - } finally { - server.shutdown(); - } - } - - public void testDelete() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-3")); - - try { - final AffinityGroupApi api = api(server.getUrl("/")).getAffinityGroupApi(); - - assertEquals(api.delete("mygroup"), "request-3"); - - assertSent(server, "DELETE", "/affinitygroups/mygroup"); - } finally { - server.shutdown(); - } - } - - public void testNullDelete() throws Exception { - final MockWebServer server = mockAzureManagementServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - try { - final AffinityGroupApi api = api(server.getUrl("/")).getAffinityGroupApi(); - - assertNull(api.delete("mygroup")); - - assertSent(server, "DELETE", "/affinitygroups/mygroup"); - } finally { - server.shutdown(); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/test/java/org/jclouds/azurecompute/features/CloudServiceApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/CloudServiceApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/CloudServiceApiLiveTest.java deleted file mode 100644 index b0dcbd8..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/CloudServiceApiLiveTest.java +++ /dev/null @@ -1,146 +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.features; - -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.assertj.core.api.Assertions.assertThat; -import static org.jclouds.azurecompute.domain.CloudService.Status.UNRECOGNIZED; -import static org.jclouds.util.Predicates2.retry; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.util.List; -import java.util.logging.Logger; - -import org.jclouds.azurecompute.domain.CloudService; -import org.jclouds.azurecompute.domain.CloudService.Status; -import org.jclouds.azurecompute.internal.BaseAzureComputeApiLiveTest; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import java.util.logging.Level; - -@Test(groups = "live", testName = "CloudServiceApiLiveTest", singleThreaded = true) -public class CloudServiceApiLiveTest extends BaseAzureComputeApiLiveTest { - - private static final String CLOUD_SERVICE = String.format("%s%d-%s", - System.getProperty("user.name"), RAND, CloudServiceApiLiveTest.class.getSimpleName()).toLowerCase(); - - private Predicate<CloudService> cloudServiceCreated; - - private Predicate<CloudService> cloudServiceGone; - - @BeforeClass(groups = {"integration", "live"}) - @Override - public void setup() { - super.setup(); - cloudServiceCreated = retry(new Predicate<CloudService>() { - - @Override - public boolean apply(CloudService input) { - return api().get(input.name()).status() == Status.CREATED; - } - }, 600, 5, 5, SECONDS); - cloudServiceGone = retry(new Predicate<CloudService>() { - - @Override - public boolean apply(CloudService input) { - return api().get(input.name()) == null; - } - }, 600, 5, 5, SECONDS); - } - - private CloudService cloudService; - - public void testCreate() { - String requestId = api().createWithLabelInLocation(CLOUD_SERVICE, CLOUD_SERVICE, LOCATION); - assertTrue(operationSucceeded.apply(requestId), requestId); - Logger.getAnonymousLogger().log(Level.INFO, "operation succeeded: {0}", requestId); - - cloudService = api().get(CLOUD_SERVICE); - Logger.getAnonymousLogger().log(Level.INFO, "created cloudService: {0}", cloudService); - - assertEquals(cloudService.name(), CLOUD_SERVICE); - - checkHostedService(cloudService); - - assertTrue(cloudServiceCreated.apply(cloudService), cloudService.toString()); - cloudService = api().get(cloudService.name()); - Logger.getAnonymousLogger().log(Level.INFO, "cloudService available: {0}", cloudService); - - } - - @Test(dependsOnMethods = "testCreate") - public void testGet() { - CloudService foundCloudService = api().get(cloudService.name()); - assertThat(foundCloudService).isEqualToComparingFieldByField(cloudService); - } - - @Test(dependsOnMethods = "testGet") - public void testDelete() { - String requestId = api().delete(cloudService.name()); - assertTrue(operationSucceeded.apply(requestId), requestId); - Logger.getAnonymousLogger().log(Level.INFO, "operation succeeded: {0}", requestId); - - assertTrue(cloudServiceGone.apply(cloudService), cloudService.toString()); - Logger.getAnonymousLogger().log(Level.INFO, "cloudService deleted: {0}", cloudService); - } - - @Override - @AfterClass(groups = "live", alwaysRun = true) - protected void tearDown() { - String requestId = api().delete(CLOUD_SERVICE); - if (requestId != null) { - operationSucceeded.apply(requestId); - } - - super.tearDown(); - } - - public void testList() { - List<CloudService> response = api().list(); - - for (CloudService cs : response) { - checkHostedService(cs); - } - - if (!response.isEmpty()) { - CloudService cs = response.iterator().next(); - assertEquals(api().get(cs.name()), cs); - } - } - - private void checkHostedService(CloudService cloudService) { - assertNotNull(cloudService.name(), "ServiceName cannot be null for " + cloudService); - assertTrue(cloudService.location() != null || cloudService.affinityGroup() != null, - "Location or AffinityGroup must be present for " + cloudService); - assertNotNull(cloudService.label(), "Label cannot be null for " + cloudService); - assertNotNull(cloudService.status(), "Status cannot be null for " + cloudService); - assertNotEquals(cloudService.status(), UNRECOGNIZED, "Status cannot be UNRECOGNIZED for " + cloudService); - assertNotNull(cloudService.created(), "Created cannot be null for " + cloudService); - assertNotNull(cloudService.lastModified(), "LastModified cannot be null for " + cloudService); - assertNotNull(cloudService.extendedProperties(), "ExtendedProperties cannot be null for " + cloudService); - } - - private CloudServiceApi api() { - return api.getCloudServiceApi(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/test/java/org/jclouds/azurecompute/features/CloudServiceApiMockTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/CloudServiceApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/CloudServiceApiMockTest.java deleted file mode 100644 index c321d5d..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/CloudServiceApiMockTest.java +++ /dev/null @@ -1,169 +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.features; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -import org.jclouds.azurecompute.internal.BaseAzureComputeApiMockTest; -import org.jclouds.azurecompute.xml.CloudServiceHandlerTest; -import org.jclouds.azurecompute.xml.CloudServicePropertiesHandlerTest; -import org.jclouds.azurecompute.xml.ListCloudServicesHandlerTest; -import org.testng.annotations.Test; - -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; - -@Test(groups = "unit", testName = "CloudServiceApiMockTest") -public class CloudServiceApiMockTest extends BaseAzureComputeApiMockTest { - - public void listWhenFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(xmlResponse("/hostedservices.xml")); - - try { - CloudServiceApi api = api(server.getUrl("/")).getCloudServiceApi(); - - assertEquals(api.list(), ListCloudServicesHandlerTest.expected()); - - assertSent(server, "GET", "/services/hostedservices?embed-detail=true"); - } finally { - server.shutdown(); - } - } - - public void listWhenNotFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - try { - CloudServiceApi api = api(server.getUrl("/")).getCloudServiceApi(); - - assertTrue(api.list().isEmpty()); - - assertSent(server, "GET", "/services/hostedservices?embed-detail=true"); - } finally { - server.shutdown(); - } - } - - public void getWhenFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(xmlResponse("/hostedservice.xml")); - - try { - CloudServiceApi api = api(server.getUrl("/")).getCloudServiceApi(); - - assertEquals(api.get("myservice"), CloudServiceHandlerTest.expected()); - - assertSent(server, "GET", "/services/hostedservices/myservice?embed-detail=true"); - } finally { - server.shutdown(); - } - } - - public void getWhenNotFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - try { - CloudServiceApi api = api(server.getUrl("/")).getCloudServiceApi(); - - assertNull(api.get("myservice")); - - assertSent(server, "GET", "/services/hostedservices/myservice?embed-detail=true"); - } finally { - server.shutdown(); - } - } - - public void getPropertiesWhenFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(xmlResponse("/cloudserviceproperties.xml")); - - try { - CloudServiceApi api = api(server.getUrl("/")).getCloudServiceApi(); - - assertEquals(api.getProperties("myservice"), CloudServicePropertiesHandlerTest.expected()); - - assertSent(server, "GET", "/services/hostedservices/myservice?embed-detail=true"); - } finally { - server.shutdown(); - } - } - - public void getPropertiesWhenNotFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - try { - CloudServiceApi api = api(server.getUrl("/")).getCloudServiceApi(); - - assertNull(api.getProperties("myservice")); - - assertSent(server, "GET", "/services/hostedservices/myservice?embed-detail=true"); - } finally { - server.shutdown(); - } - } - - public void createWithLabelInLocation() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - CloudServiceApi api = api(server.getUrl("/")).getCloudServiceApi(); - - assertEquals(api.createWithLabelInLocation("myservice", "service mine", "West US"), "request-1"); - - assertSent(server, "POST", "/services/hostedservices", "/create_hostedservice_location.xml"); - } finally { - server.shutdown(); - } - } - - public void deleteWhenFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - CloudServiceApi api = api(server.getUrl("/")).getCloudServiceApi(); - - assertEquals(api.delete("myservice"), "request-1"); - - assertSent(server, "DELETE", "/services/hostedservices/myservice"); - } finally { - server.shutdown(); - } - } - - public void deleteWhenNotFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - try { - CloudServiceApi api = api(server.getUrl("/")).getCloudServiceApi(); - - assertNull(api.delete("myservice")); - - assertSent(server, "DELETE", "/services/hostedservices/myservice"); - } finally { - server.shutdown(); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/test/java/org/jclouds/azurecompute/features/DeploymentApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DeploymentApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/DeploymentApiLiveTest.java deleted file mode 100644 index 6982300..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DeploymentApiLiveTest.java +++ /dev/null @@ -1,187 +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.features; - -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.assertj.core.api.Assertions.assertThat; -import static org.jclouds.util.Predicates2.retry; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.jclouds.azurecompute.compute.AzureComputeServiceAdapter; -import org.jclouds.azurecompute.domain.CloudService; -import org.jclouds.azurecompute.domain.CloudServiceProperties; -import org.jclouds.azurecompute.domain.Deployment; -import org.jclouds.azurecompute.domain.DeploymentParams; -import org.jclouds.azurecompute.domain.OSImage; -import org.jclouds.azurecompute.domain.Role; -import org.jclouds.azurecompute.domain.RoleSize; -import org.jclouds.azurecompute.internal.BaseAzureComputeApiLiveTest; -import org.jclouds.azurecompute.util.ConflictManagementPredicate; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableSet; - -@Test(groups = "live", testName = "DeploymentApiLiveTest", singleThreaded = true) -public class DeploymentApiLiveTest extends BaseAzureComputeApiLiveTest { - - private static final String CLOUD_SERVICE = String.format("%s%d-%s", - System.getProperty("user.name"), RAND, DeploymentApiLiveTest.class.getSimpleName()).toLowerCase(); - - private static final String DEPLOYMENT = String.format("%s%d-%s", - System.getProperty("user.name"), RAND, DeploymentApiLiveTest.class.getSimpleName()).toLowerCase(); - - private Predicate<Deployment> deploymentCreated; - - private Predicate<Deployment> deploymentGone; - - private Deployment deployment; - - private CloudService cloudService; - - @BeforeClass(groups = {"integration", "live"}) - @Override - public void setup() { - super.setup(); - - cloudService = getOrCreateCloudService(CLOUD_SERVICE, LOCATION); - - deploymentCreated = retry(new Predicate<Deployment>() { - - @Override - public boolean apply(final Deployment input) { - return api().get(input.name()).status() == Deployment.Status.RUNNING; - } - }, 600, 5, 5, SECONDS); - - deploymentGone = retry(new Predicate<Deployment>() { - - @Override - public boolean apply(final Deployment input) { - return api().get(input.name()) == null; - } - }, 600, 5, 5, SECONDS); - } - - public void testCreate() { - final DeploymentParams params = DeploymentParams.builder() - .name(DEPLOYMENT) - .os(OSImage.Type.LINUX) - .sourceImageName(DeploymentApiLiveTest.IMAGE_NAME) - .mediaLink(AzureComputeServiceAdapter.createMediaLink(storageService.serviceName(), DEPLOYMENT)) - .username("test") - .password("supersecurePassword1!") - .size(RoleSize.Type.BASIC_A0) - .externalEndpoints(ImmutableSet.of(DeploymentParams.ExternalEndpoint.inboundTcpToLocalPort(22, 22))) - .build(); - final String requestId = api().create(params); - assertTrue(operationSucceeded.apply(requestId), requestId); - - deployment = api().get(DEPLOYMENT); - assertNotNull(deployment); - assertTrue(deploymentCreated.apply(deployment), deployment.toString()); - assertThat(deployment.name()).isEqualTo(DEPLOYMENT); - assertThat(deployment.status()).isEqualTo(Deployment.Status.RUNNING); - assertThat(deployment.label()).isEqualTo(DEPLOYMENT); - assertThat(deployment.slot()).isEqualTo(Deployment.Slot.PRODUCTION); - assertThat(deployment.roleList().size()).isEqualTo(1); - assertThat(deployment.roleInstanceList().size()).isEqualTo(1); - - } - - @Test(dependsOnMethods = "testCreate") - public void testGet() { - Deployment foundDeployment = api().get(deployment.name()); - assertThat(foundDeployment).isEqualToComparingFieldByField(deployment); - } - - // Test CloudServiceProperties with a deployment - @Test(dependsOnMethods = "testCreate") - public void testGetProperties() { - CloudServiceProperties cloudServiceProperties = api.getCloudServiceApi().getProperties(cloudService.name()); - assertNotNull(cloudServiceProperties); - assertEquals(cloudServiceProperties.serviceName(), CLOUD_SERVICE); - - Deployment deployment = cloudServiceProperties.deployments().get(0); - checkDeployment(deployment); - } - - @Test(dependsOnMethods = "testGet") - public void testDelete() { - final List<Role> roles = api.getDeploymentApiForService(cloudService.name()).get(DEPLOYMENT).roleList(); - - assertTrue(new ConflictManagementPredicate(api) { - - @Override - protected String operation() { - return api().delete(deployment.name()); - } - }.apply(deployment.name())); - - assertTrue(deploymentGone.apply(deployment), deployment.toString()); - Logger.getAnonymousLogger().log(Level.INFO, "deployment deleted: {0}", deployment); - - assertTrue(new ConflictManagementPredicate(api) { - - @Override - protected String operation() { - return api.getCloudServiceApi().delete(cloudService.name()); - } - }.apply(cloudService.name())); - - for (Role r : roles) { - final Role.OSVirtualHardDisk disk = r.osVirtualHardDisk(); - if (disk != null) { - assertTrue(new ConflictManagementPredicate(api) { - - @Override - protected String operation() { - return api.getDiskApi().delete(disk.diskName()); - } - }.apply(disk.diskName())); - } - } - } - - private void checkDeployment(Deployment deployment) { - assertNotNull(deployment); - assertNotNull(deployment.name(), "Name cannot be Null for Deployment" + deployment); - assertTrue(deployment.roleList().size() > 0, "There should be atleast 1 Virtual machine for a deployment "); - assertNotNull(deployment.label(), "Label cannot be Null for Deployment" + deployment); - - Deployment.Slot slot = deployment.slot(); - assertTrue((slot == Deployment.Slot.PRODUCTION) || (slot == Deployment.Slot.STAGING)); - assertEquals(deployment.name(), DEPLOYMENT); - } - - @Override - @AfterClass(groups = "live", alwaysRun = true) - protected void tearDown() { - super.tearDown(); - } - - private DeploymentApi api() { - return api.getDeploymentApiForService(cloudService.name()); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/test/java/org/jclouds/azurecompute/features/DeploymentApiMockTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DeploymentApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/DeploymentApiMockTest.java deleted file mode 100644 index d41901d..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DeploymentApiMockTest.java +++ /dev/null @@ -1,121 +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.features; - -import static org.jclouds.azurecompute.domain.DeploymentParams.ExternalEndpoint.inboundTcpToLocalPort; -import static org.jclouds.azurecompute.domain.DeploymentParams.ExternalEndpoint.inboundUdpToLocalPort; -import static org.testng.Assert.assertEquals; -import java.net.URI; - -import org.jclouds.azurecompute.domain.DeploymentParams; -import org.jclouds.azurecompute.domain.OSImage; -import org.jclouds.azurecompute.domain.RoleSize; -import org.jclouds.azurecompute.internal.BaseAzureComputeApiMockTest; -import org.jclouds.azurecompute.xml.DeploymentHandlerTest; -import org.jclouds.azurecompute.xml.ListOSImagesHandlerTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.squareup.okhttp.mockwebserver.MockWebServer; - -@Test(groups = "unit", testName = "DeploymentApiMockTest") -public class DeploymentApiMockTest extends BaseAzureComputeApiMockTest { - - public void testCreateLinux() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - DeploymentApi api = api(server.getUrl("/")).getDeploymentApiForService("myservice"); - - OSImage osImage = ListOSImagesHandlerTest.expected().get(5); // Centos - - DeploymentParams params = DeploymentParams.builder() - .name("mydeployment") - .size(RoleSize.Type.MEDIUM) - .sourceImageName(osImage.name()).mediaLink(URI.create("https://mydeployment.blob.core.windows.net/vhds/disk-mydeployment.vhd")).os(osImage.os()) - .username("username").password("testpwd") - .virtualNetworkName("my-virtualNetworkName") - .reservedIPName("myreservedip") - .externalEndpoints(ImmutableSet.of(inboundTcpToLocalPort(80, 8080), inboundUdpToLocalPort(53, 53))) - .build(); - - assertEquals(api.create(params), "request-1"); - - assertSent(server, "POST", "/services/hostedservices/myservice/deployments", "/deploymentparams.xml"); - } finally { - server.shutdown(); - } - } - - public void testCreateWindows() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - DeploymentApi api = api(server.getUrl("/")).getDeploymentApiForService("myservice"); - - OSImage osImage = ListOSImagesHandlerTest.expected().get(1); // Windows - - DeploymentParams params = DeploymentParams.builder() - .name("mydeployment") - .size(RoleSize.Type.MEDIUM) - .sourceImageName(osImage.name()).mediaLink(osImage.mediaLink()).os(osImage.os()) - .username("username").password("testpwd") - .virtualNetworkName("my-virtualNetworkName") - .externalEndpoints(ImmutableSet.of(inboundTcpToLocalPort(80, 8080), inboundUdpToLocalPort(53, 53))) - .build(); - - assertEquals(api.create(params), "request-1"); - - assertSent(server, "POST", "/services/hostedservices/myservice/deployments", "/deploymentparams-windows.xml"); - } finally { - server.shutdown(); - } - } - - public void testGet() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(xmlResponse("/deployment.xml")); - - try { - DeploymentApi api = api(server.getUrl("/")).getDeploymentApiForService("myservice"); - - assertEquals(api.get("mydeployment"), DeploymentHandlerTest.expected()); - - assertSent(server, "GET", "/services/hostedservices/myservice/deployments/mydeployment"); - } finally { - server.shutdown(); - } - } - - public void testDelete() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - DeploymentApi api = api(server.getUrl("/")).getDeploymentApiForService("myservice"); - - assertEquals(api.delete("mydeployment"), "request-1"); - - assertSent(server, "DELETE", "/services/hostedservices/myservice/deployments/mydeployment"); - } finally { - server.shutdown(); - } - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java deleted file mode 100644 index 1847f1f..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java +++ /dev/null @@ -1,113 +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.features; - -import static com.google.common.collect.Iterables.transform; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import org.jclouds.azurecompute.domain.AffinityGroup; -import org.jclouds.azurecompute.domain.Disk; -import org.jclouds.azurecompute.domain.Location; -import org.jclouds.azurecompute.domain.OSImage; -import org.jclouds.azurecompute.internal.AbstractAzureComputeApiLiveTest; - -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; - -@Test(groups = "live", testName = "DiskApiLiveTest") -public class DiskApiLiveTest extends AbstractAzureComputeApiLiveTest { - - private ImmutableSet<String> locations; - - private ImmutableSet<String> images; - - private ImmutableSet<String> groups; - - @BeforeClass(groups = {"integration", "live"}) - @Override - public void setup() { - super.setup(); - - locations = ImmutableSet.copyOf(transform(api.getLocationApi().list(), - new Function<Location, String>() { - - @Override - public String apply(final Location location) { - return location.name(); - } - })); - images = ImmutableSet.copyOf(transform(api.getOSImageApi().list(), new Function<OSImage, String>() { - - @Override - public String apply(final OSImage image) { - return image.name(); - } - })); - groups = ImmutableSet.copyOf(transform(api.getAffinityGroupApi().list(), new Function<AffinityGroup, String>() { - - @Override - public String apply(final AffinityGroup group) { - return group.name(); - } - })); - } - - public void testList() { - for (Disk disk : api().list()) { - checkDisk(disk); - } - } - - // TODO testDeleteDisk, if we will need testCreateDisk - private void checkDisk(Disk disk) { - assertNotNull(disk.name(), "Name cannot be null for: " + disk); - - if (disk.attachedTo() != null) { - // TODO: verify you can lookup the role - } - - if (disk.logicalSizeInGB() != null) { - assertTrue(disk.logicalSizeInGB() > 0, "LogicalSizeInGB should be positive, if set" + disk); - } - - if (disk.mediaLink() != null) { - assertTrue(ImmutableSet.of("http", "https").contains(disk.mediaLink().getScheme()), - "MediaLink should be an http(s) url" + disk); - } - - if (disk.location() != null) { - assertTrue(locations.contains(disk.location()), "Location not in " + locations + " :" + disk); - } - - if (disk.sourceImage() != null) { - //TODO disk can be generated from a `VM Image` that listDisk doesn't consider - // assertTrue(images.contains(disk.sourceImage()), "SourceImage not in " + images + " :" + disk); - } - - if (disk.affinityGroup() != null) { - assertTrue(groups.contains(disk.affinityGroup()), "AffinityGroup not in " + groups + " :" + disk); - } - } - - private DiskApi api() { - return api.getDiskApi(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiMockTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiMockTest.java deleted file mode 100644 index a9b6900..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiMockTest.java +++ /dev/null @@ -1,60 +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.features; - -import static org.testng.Assert.assertEquals; - -import org.jclouds.azurecompute.internal.BaseAzureComputeApiMockTest; -import org.jclouds.azurecompute.xml.ListDisksHandlerTest; -import org.testng.annotations.Test; - -import com.squareup.okhttp.mockwebserver.MockWebServer; - -@Test(groups = "unit", testName = "DiskApiMockTest") -public class DiskApiMockTest extends BaseAzureComputeApiMockTest { - - public void testList() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(xmlResponse("/disks.xml")); - - try { - DiskApi api = api(server.getUrl("/")).getDiskApi(); - - assertEquals(api.list(), ListDisksHandlerTest.expected()); - - assertSent(server, "GET", "/services/disks"); - } finally { - server.shutdown(); - } - } - - public void testDelete() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - DiskApi api = api(server.getUrl("/")).getDiskApi(); - - assertEquals(api.delete("my-disk"), "request-1"); - - assertSent(server, "DELETE", "/services/disks/my-disk?comp=media"); - } finally { - server.shutdown(); - } - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiLiveTest.java deleted file mode 100644 index 8b43292..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiLiveTest.java +++ /dev/null @@ -1,54 +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.features; - -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.util.Arrays; -import java.util.List; - -import org.jclouds.azurecompute.domain.Location; -import org.jclouds.azurecompute.internal.AbstractAzureComputeApiLiveTest; - -import org.testng.annotations.Test; - -@Test(groups = "live", testName = "LocationApiLiveTest") -public class LocationApiLiveTest extends AbstractAzureComputeApiLiveTest { - - private static final List<String> KNOWN_SERVICES = Arrays - .asList("Compute", "Storage", "PersistentVMRole", "HighMemory"); - - @Test - public void testList() { - for (Location location : api().list()) { - checkLocation(location); - } - } - - 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); - assertNotNull(location.availableServices(), "AvailableServices cannot be null for: " + location.name()); - assertTrue(KNOWN_SERVICES.containsAll(location.availableServices()), - "AvailableServices in " + location + " didn't match: " + KNOWN_SERVICES); - } - - private LocationApi api() { - return api.getLocationApi(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiMockTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiMockTest.java deleted file mode 100644 index c6f1924..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiMockTest.java +++ /dev/null @@ -1,45 +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.features; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.jclouds.azurecompute.internal.BaseAzureComputeApiMockTest; -import org.jclouds.azurecompute.xml.ListLocationsHandlerTest; -import org.testng.annotations.Test; - -import com.squareup.okhttp.mockwebserver.MockWebServer; - -@Test(groups = "unit", testName = "LocationApiMockTest") -public class LocationApiMockTest extends BaseAzureComputeApiMockTest { - - public void testList() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(xmlResponse("/locations.xml")); - - try { - LocationApi api = api(server.getUrl("/")).getLocationApi(); - - assertThat(api.list()).containsExactlyElementsOf(ListLocationsHandlerTest.expected()); - - assertSent(server, "GET", "/locations"); - } finally { - server.shutdown(); - } - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/test/java/org/jclouds/azurecompute/features/NetworkSecurityGroupApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/NetworkSecurityGroupApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/NetworkSecurityGroupApiLiveTest.java deleted file mode 100644 index 7e41eb7..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/NetworkSecurityGroupApiLiveTest.java +++ /dev/null @@ -1,215 +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.features; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -import java.util.List; - -import org.jclouds.azurecompute.domain.NetworkSecurityGroup; -import org.jclouds.azurecompute.domain.Rule; -import org.jclouds.azurecompute.internal.BaseAzureComputeApiLiveTest; - -import org.jclouds.azurecompute.util.ConflictManagementPredicate; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -@Test(groups = "live", testName = "NetworkSecurityGroupApiLiveTest", singleThreaded = true) -public class NetworkSecurityGroupApiLiveTest extends BaseAzureComputeApiLiveTest { - - private static final String GROUP1 = System.getProperty("user.name") + RAND + "-1"; - - private static final String GROUP2 = System.getProperty("user.name") + RAND + "-2"; - - @BeforeClass - public void groupSetup() { - // ---------------------------- - // Clean before start - // ---------------------------- - try { - final NetworkSecurityGroup group = api(). - getNetworkSecurityGroupAppliedToSubnet(VIRTUAL_NETWORK_NAME, DEFAULT_SUBNET_NAME); - - if (group != null && (group.name().equals(GROUP1) || group.name().equals(GROUP2))) { - api().removeFromSubnet(VIRTUAL_NETWORK_NAME, DEFAULT_SUBNET_NAME, group.name()); - } - } catch (Exception e) { - // ignore - } - - try { - if (api().get(GROUP1) != null) { - operationSucceeded.apply(api.getNetworkSecurityGroupApi().delete(GROUP1)); - } - } catch (Exception e) { - // ignore - } - - try { - if (api().get(GROUP2) != null) { - operationSucceeded.apply(api.getNetworkSecurityGroupApi().delete(GROUP2)); - } - } catch (Exception e) { - // ignore - } - // ---------------------------- - - String requestId = api().create( - NetworkSecurityGroup.create(GROUP1, GROUP1 + " security group", LOCATION, null, null)); - - assertTrue(operationSucceeded.apply(requestId), GROUP1); - - requestId = api().create( - NetworkSecurityGroup.create(GROUP2, GROUP2 + " security group", LOCATION, null, null)); - - assertTrue(operationSucceeded.apply(requestId), GROUP2); - } - - @Test - public void list() { - final List<NetworkSecurityGroup> groups = api().list(); - assertFalse(groups.isEmpty()); - } - - @Test - public void get() { - final NetworkSecurityGroup group = api().get(GROUP1); - assertEquals(group.name(), GROUP1); - assertEquals(group.label(), GROUP1 + " security group"); - assertEquals(group.location(), LOCATION); - assertTrue(group.state() == NetworkSecurityGroup.State.CREATED); - assertTrue(group.rules().isEmpty()); - } - - @Test - public void getFullDetails() { - final NetworkSecurityGroup group = api().getFullDetails(GROUP2); - assertEquals(group.name(), GROUP2); - assertEquals(group.label(), GROUP2 + " security group"); - assertEquals(group.location(), LOCATION); - assertTrue(group.state() == NetworkSecurityGroup.State.CREATED); - assertFalse(group.rules().isEmpty()); - } - - @Test - public void setRule() { - final String ruleName = "newrule"; - - final String requestId = api().setRule(GROUP1, ruleName, Rule.create( - ruleName, - Rule.Type.Inbound, - "100", - Rule.Action.Allow, - "INTERNET", - "*", - "10.0.0.0/0", - "*", - Rule.Protocol.ALL)); - - assertTrue(operationSucceeded.apply(requestId), ruleName); - - Rule newrule = null; - - for (Rule rule : api().getFullDetails(GROUP1).rules()) { - if (ruleName.equals(rule.name())) { - newrule = rule; - } - } - - assertNotNull(newrule); - - assertNull(newrule.isDefault()); - assertEquals(newrule.action(), Rule.Action.Allow); - assertEquals(newrule.type(), Rule.Type.Inbound); - assertEquals(newrule.protocol(), Rule.Protocol.ALL); - assertEquals(newrule.state(), "Active"); - } - - @Test(dependsOnMethods = {"setRule"}) - public void removeRule() { - final String ruleName = "newrule"; - - final String requestId = api().deleteRule(GROUP1, ruleName); - assertTrue(operationSucceeded.apply(requestId), ruleName); - - Rule newrule = null; - - for (Rule rule : api().getFullDetails(GROUP1).rules()) { - if (ruleName.equals(rule.name())) { - newrule = rule; - } - } - - assertNull(newrule); - } - - @Test(dependsOnMethods = {"removeRule"}) - public void addToSubnet() { - assertTrue(new ConflictManagementPredicate(api) { - - @Override - protected String operation() { - return api().addToSubnet(VIRTUAL_NETWORK_NAME, DEFAULT_SUBNET_NAME, GROUP1); - } - }.apply(GROUP1)); - } - - @Test(dependsOnMethods = {"addToSubnet"}) - public void getForSubnet() { - final NetworkSecurityGroup group = api(). - getNetworkSecurityGroupAppliedToSubnet(VIRTUAL_NETWORK_NAME, DEFAULT_SUBNET_NAME); - assertEquals(group.state(), NetworkSecurityGroup.State.CREATED); - } - - @Test(dependsOnMethods = {"getForSubnet"}) - public void removeFromSubnet() { - assertTrue(new ConflictManagementPredicate(api) { - - @Override - protected String operation() { - return api().removeFromSubnet(VIRTUAL_NETWORK_NAME, DEFAULT_SUBNET_NAME, GROUP1); - } - }.apply(GROUP1)); - } - - @AfterClass - public void cleanup() { - // no assertion is required: just to be sure to remove for subnet - final NetworkSecurityGroup group = api(). - getNetworkSecurityGroupAppliedToSubnet(VIRTUAL_NETWORK_NAME, DEFAULT_SUBNET_NAME); - - if (group != null) { - api().removeFromSubnet(VIRTUAL_NETWORK_NAME, DEFAULT_SUBNET_NAME, group.name()); - } - - String requestId = api.getNetworkSecurityGroupApi().delete(GROUP1); - assertTrue(operationSucceeded.apply(requestId), GROUP1); - - requestId = api.getNetworkSecurityGroupApi().delete(GROUP2); - assertTrue(operationSucceeded.apply(requestId), GROUP2); - } - - private NetworkSecurityGroupApi api() { - return api.getNetworkSecurityGroupApi(); - } -}
