http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/test/java/org/jclouds/azurecompute/features/VMImageApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/VMImageApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/VMImageApiLiveTest.java deleted file mode 100644 index 556e73f..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/VMImageApiLiveTest.java +++ /dev/null @@ -1,218 +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.jclouds.azurecompute.domain.Deployment.InstanceStatus.READY_ROLE; -import static org.jclouds.util.Predicates2.retry; -import static org.testng.Assert.assertNotEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; -import java.net.URI; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; - -import org.jclouds.azurecompute.compute.AzureComputeServiceAdapter; -import org.jclouds.azurecompute.domain.CaptureVMImageParams; -import org.jclouds.azurecompute.domain.CloudService; -import org.jclouds.azurecompute.domain.Deployment; -import org.jclouds.azurecompute.domain.DeploymentParams; -import org.jclouds.azurecompute.domain.OSImage; -import org.jclouds.azurecompute.domain.RoleSize; -import org.jclouds.azurecompute.domain.VMImage; -import org.jclouds.azurecompute.domain.VMImageParams; -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; -import com.google.common.collect.Iterables; - -@Test(groups = "live", testName = "VMImageApiLiveTest") -public class VMImageApiLiveTest extends BaseAzureComputeApiLiveTest { - - private static final String CLOUD_SERVICE = String.format("%s%d-%s", - System.getProperty("user.name"), RAND, VMImageApiLiveTest.class.getSimpleName()).toLowerCase(); - - private static final String DEPLOYMENT = String.format("%s%d-%s", - System.getProperty("user.name"), RAND, VMImageApiLiveTest.class.getSimpleName()).toLowerCase(); - - private static final String CAPTURED_IMAGE_NAME = "captured-image"; - - private static final String CREATE_IMAGE_NAME = "create-image"; - - private String roleName; - - private String diskName; - - private Predicate<String> roleInstanceReady; - - private CloudService cloudService; - - @BeforeClass(groups = {"integration", "live"}) - @Override - public void setup() { - super.setup(); - cloudService = getOrCreateCloudService(CLOUD_SERVICE, LOCATION); - - roleInstanceReady = retry(new Predicate<String>() { - - @Override - public boolean apply(String input) { - Deployment.RoleInstance roleInstance = getFirstRoleInstanceInDeployment(input); - return roleInstance != null && roleInstance.instanceStatus() == READY_ROLE; - } - }, 600, 5, 5, SECONDS); - - final DeploymentParams params = DeploymentParams.builder() - .name(DEPLOYMENT) - .os(OSImage.Type.LINUX) - .sourceImageName(BaseAzureComputeApiLiveTest.IMAGE_NAME) - .mediaLink(AzureComputeServiceAdapter.createMediaLink(storageService.serviceName(), DEPLOYMENT)) - .username("test") - .password("supersecurePassword1!") - .size(RoleSize.Type.BASIC_A2) - .externalEndpoints(ImmutableSet.of(DeploymentParams.ExternalEndpoint.inboundTcpToLocalPort(22, 22))) - .build(); - Deployment deployment = getOrCreateDeployment(cloudService.name(), params); - Deployment.RoleInstance roleInstance = getFirstRoleInstanceInDeployment(DEPLOYMENT); - assertTrue(roleInstanceReady.apply(DEPLOYMENT), roleInstance.toString()); - roleName = roleInstance.roleName(); - diskName = deployment.roleList().get(0).osVirtualHardDisk().diskName(); - } - - @Test(dependsOnMethods = "testCaptureVMImage") - public void testCreate() { - Date date = new Date(); - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - VMImage image = api().list().get(5); - VMImageParams.OSDiskConfigurationParams osParams = VMImageParams.OSDiskConfigurationParams - .OSDiskConfiguration(CREATE_IMAGE_NAME + "osdisk", - VMImageParams.OSDiskConfigurationParams.Caching.READ_ONLY, - VMImageParams.OSDiskConfigurationParams.OSState.SPECIALIZED, - image.osDiskConfiguration().os(), - URI.create( - "https://" + storageService.serviceName() - + ".blob.core.windows.net/vhds/" + CAPTURED_IMAGE_NAME + "-os-" + dateFormat.format(date) + ".vhd"), - 30, - "Standard"); - VMImageParams params = VMImageParams.builder().name(CREATE_IMAGE_NAME).label(CREATE_IMAGE_NAME) - .description(image.description()).recommendedVMSize(image.recommendedVMSize()) - .osDiskConfiguration(osParams).imageFamily(image.imageFamily()) - .build(); - - String requestId = api().create(params); - assertNotNull(requestId); - operationSucceeded.apply(requestId); - } - - @Test - public void testCaptureVMImage() { - String shutdownRequest = api.getVirtualMachineApiForDeploymentInService(DEPLOYMENT, CLOUD_SERVICE).shutdown(roleName); - assertTrue(operationSucceeded.apply(shutdownRequest), shutdownRequest); - - CaptureVMImageParams captureParams = CaptureVMImageParams.builder() - .osState(VMImage.OSDiskConfiguration.OSState.GENERALIZED).name(CAPTURED_IMAGE_NAME) - .label(CAPTURED_IMAGE_NAME).recommendedVMSize(RoleSize.Type.MEDIUM).build(); - - String requestId = api.getVirtualMachineApiForDeploymentInService(DEPLOYMENT, CLOUD_SERVICE) - .capture(roleName, captureParams); - assertNotNull(requestId); - operationSucceeded.apply(requestId); - } - - @Test(dependsOnMethods = "testCreate") - public void testUpdateVMImage() { - VMImage image = api().list().get(5); - VMImageParams params = VMImageParams.builder() - .label("UpdatedLabel") - .description(image.description()).recommendedVMSize(RoleSize.Type.A7) - .build(); - - String requestId = api().update(CAPTURED_IMAGE_NAME, params); - assertNotNull(requestId); - operationSucceeded.apply(requestId); - } - - @Test - public void testList() { - List<VMImage> vmImageList = api().list(); - assertTrue(vmImageList.size() > 0); - for (VMImage VMImage : vmImageList) { - checkVMImage(VMImage); - } - } - - @Test(dependsOnMethods = {"testList", "testUpdateVMImage"}) - public void testDelete() { - String requestId = api().delete(CAPTURED_IMAGE_NAME); - assertNotNull(requestId); - assertTrue(operationSucceeded.apply(requestId), requestId); - } - - private void checkVMImage(VMImage image) { - assertNotNull(image.label(), "Label cannot be null for " + image); - assertNotNull(image.name(), "Name cannot be null for " + image); - assertNotNull(image.location(), "Location cannot be null for " + image); - - //OSImage - VMImage.OSDiskConfiguration osDiskConfiguration = image.osDiskConfiguration(); - assertNotNull(osDiskConfiguration); - assertNotNull(osDiskConfiguration.name()); - assertTrue(osDiskConfiguration.logicalSizeInGB() > 0); - - if (osDiskConfiguration.mediaLink() != null) { - assertTrue(ImmutableSet.of("http", "https").contains(osDiskConfiguration.mediaLink().getScheme()), - "MediaLink should be an http(s) url" + image); - } - - if (image.category() != null) { - assertNotEquals("", image.category().trim(), "Invalid Category for " + image); - } - } - - @AfterClass - @Override - protected void tearDown() { - assertTrue(new ConflictManagementPredicate(api) { - @Override - protected String operation() { - return api.getDiskApi().delete(diskName); - } - }.apply(diskName)); - assertTrue(new ConflictManagementPredicate(api) { - @Override - protected String operation() { - return api.getCloudServiceApi().delete(cloudService.name()); - } - }.apply(cloudService.name())); - super.tearDown(); - } - - private VMImageApi api() { - return api.getVMImageApi(); - } - - private Deployment.RoleInstance getFirstRoleInstanceInDeployment(String deployment) { - return Iterables.getOnlyElement(api.getDeploymentApiForService(cloudService.name()).get(deployment). - roleInstanceList()); - } -}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/test/java/org/jclouds/azurecompute/features/VMImageApiMockTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/VMImageApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/VMImageApiMockTest.java deleted file mode 100644 index 2396bb0..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/VMImageApiMockTest.java +++ /dev/null @@ -1,198 +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.assertNull; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.assertEquals; - -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import org.jclouds.azurecompute.domain.OSImage; -import org.jclouds.azurecompute.domain.RoleSize; -import org.jclouds.azurecompute.domain.VMImageParams; -import org.jclouds.azurecompute.domain.CaptureVMImageParams; -import org.jclouds.azurecompute.domain.VMImage; -import org.jclouds.azurecompute.internal.BaseAzureComputeApiMockTest; -import org.jclouds.azurecompute.xml.ListVMImagesHandlerTest; -import org.testng.annotations.Test; - -import java.net.URI; - -@Test(groups = "unit", testName = "VMImageApiMockTest") -public class VMImageApiMockTest extends BaseAzureComputeApiMockTest { - - public void listWhenFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(xmlResponse("/vmimages.xml")); - - try { - VMImageApi api = api(server.getUrl("/")).getVMImageApi(); - - assertEquals(api.list(), ListVMImagesHandlerTest.expected()); - - assertSent(server, "GET", "/services/vmimages"); - } finally { - server.shutdown(); - } - } - - public void listWhenNotFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - try { - VMImageApi api = api(server.getUrl("/")).getVMImageApi(); - - assertTrue(api.list().isEmpty()); - - assertSent(server, "GET", "/services/vmimages"); - } finally { - server.shutdown(); - } - } - - public void create() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - VMImageApi api = api(server.getUrl("/")).getVMImageApi(); - - VMImageParams.OSDiskConfigurationParams osParams = VMImageParams.OSDiskConfigurationParams - .OSDiskConfiguration("ClouderaGolden-os_disk", - VMImageParams.OSDiskConfigurationParams.Caching.READ_ONLY, - VMImageParams.OSDiskConfigurationParams.OSState.SPECIALIZED, - OSImage.Type.LINUX, - URI.create("http://blobs/disks/neotysss/MSFT__Win2K8R2SP1-ABCD-en-us-30GB.vhd"), - 30, - "Standard"); - VMImageParams params = VMImageParams.builder() - .name("ClouderaGolden") - .label("CDH 5.1 Evaluation") - .description("Single click deployment") - .recommendedVMSize(RoleSize.Type.LARGE) - .osDiskConfiguration(osParams) - .imageFamily("Ubuntu") - .language("en") - .eula("http://www.gnu.org/copyleft/gpl.html") - .iconUri(URI.create("http://www.cloudera.com/content/cloudera/en/privacy-policy.html")) - .smallIconUri(URI.create("http://www.cloudera.com/content/cloudera/en/privacy-policy.html")) - .privacyUri(URI.create("http://www.cloudera.com/content/cloudera/en/privacy-policy.html")) - .showGui(Boolean.TRUE) - .build(); - - assertEquals(api.create(params), "request-1"); - - assertSent(server, "POST", "/services/vmimages", "/vmimageparams.xml"); - } finally { - server.shutdown(); - } - } - - public void testUpdate() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - VMImageApi api = api(server.getUrl("/")).getVMImageApi(); - - VMImageParams.OSDiskConfigurationParams osParams = VMImageParams.OSDiskConfigurationParams - .OSDiskConfiguration("ClouderaGolden-os_disk", - VMImageParams.OSDiskConfigurationParams.Caching.READ_ONLY, - VMImageParams.OSDiskConfigurationParams.OSState.SPECIALIZED, - OSImage.Type.LINUX, - URI.create("http://blobs/disks/neotysss/MSFT__Win2K8R2SP1-ABCD-en-us-30GB.vhd"), - 30, - "Standard"); - VMImageParams params = VMImageParams.builder() - .name("ClouderaGolden") - .label("CDH 5.1 Evaluation") - .description("Single click deployment") - .recommendedVMSize(RoleSize.Type.LARGE) - .osDiskConfiguration(osParams) - .imageFamily("Ubuntu") - .language("en") - .eula("http://www.gnu.org/copyleft/gpl.html") - .iconUri(URI.create("http://www.cloudera.com/content/cloudera/en/privacy-policy.html")) - .smallIconUri(URI.create("http://www.cloudera.com/content/cloudera/en/privacy-policy.html")) - .privacyUri(URI.create("http://www.cloudera.com/content/cloudera/en/privacy-policy.html")) - .showGui(Boolean.TRUE) - .build(); - - assertEquals(api.update("myvmimage", params), "request-1"); - - assertSent(server, "PUT", "/services/vmimages/myvmimage", "/vmimageparams.xml"); - } finally { - server.shutdown(); - } - } - - public void deleteWhenFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - VMImageApi api = api(server.getUrl("/")).getVMImageApi(); - - assertEquals(api.delete("myvmimage"), "request-1"); - - assertSent(server, "DELETE", "/services/vmimages/myvmimage"); - } finally { - server.shutdown(); - } - } - - public void deleteWhenNotFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - try { - VMImageApi api = api(server.getUrl("/")).getVMImageApi(); - - assertNull(api.delete("myvmimage")); - - assertSent(server, "DELETE", "/services/vmimages/myvmimage"); - } finally { - server.shutdown(); - } - } - - @Test - public void testCaptureVMImage() throws Exception { - - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - CaptureVMImageParams captureParams = CaptureVMImageParams.builder() - .osState(VMImage.OSDiskConfiguration.OSState.GENERALIZED).name("capturedimage") - .label("CapturedImage").recommendedVMSize(RoleSize.Type.MEDIUM).build(); - - VirtualMachineApi api = api(server.getUrl("/")). - getVirtualMachineApiForDeploymentInService("mydeployment", "myservice"); - - assertEquals(api.capture("myvirtualmachine", captureParams), "request-1"); - assertSent(server, "POST", - "/services/hostedservices/myservice/deployments/mydeployment/roleinstances/" + - "myvirtualmachine/Operations", - "/vmimageparams_mock.xml"); - } finally { - server.shutdown(); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/test/java/org/jclouds/azurecompute/features/VirtualMachineApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/VirtualMachineApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/VirtualMachineApiLiveTest.java deleted file mode 100644 index 22d50e6..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/VirtualMachineApiLiveTest.java +++ /dev/null @@ -1,222 +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.jclouds.azurecompute.domain.Deployment.InstanceStatus.READY_ROLE; -import static org.jclouds.util.Predicates2.retry; -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.Deployment; -import org.jclouds.azurecompute.domain.Deployment.RoleInstance; -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; -import com.google.common.collect.Iterables; - -/* - * Note: Live test for CaptureVMImage method is in VMImageApiLiveTest class - */ -@Test(groups = "live", testName = "VirtualMachineApiLiveTest", singleThreaded = true) -public class VirtualMachineApiLiveTest extends BaseAzureComputeApiLiveTest { - - private static final String CLOUD_SERVICE = String.format("%s%d-%s", - System.getProperty("user.name"), RAND, VirtualMachineApiLiveTest.class.getSimpleName()).toLowerCase(); - - private static final String DEPLOYMENT = String.format("%s%d-%s", - System.getProperty("user.name"), RAND, VirtualMachineApiLiveTest.class.getSimpleName()).toLowerCase(); - - private String roleName; - - private Predicate<String> roleInstanceReady; - - private Predicate<String> roleInstanceStopped; - - private CloudService cloudService; - - @BeforeClass(groups = {"integration", "live"}) - @Override - public void setup() { - super.setup(); - cloudService = getOrCreateCloudService(CLOUD_SERVICE, LOCATION); - - roleInstanceReady = retry(new Predicate<String>() { - - @Override - public boolean apply(String input) { - RoleInstance roleInstance = getFirstRoleInstanceInDeployment(input); - return roleInstance != null && roleInstance.instanceStatus() == READY_ROLE; - } - }, 600, 5, 15, SECONDS); - - roleInstanceStopped = retry(new Predicate<String>() { - - @Override - public boolean apply(String input) { - RoleInstance roleInstance = getFirstRoleInstanceInDeployment(input); - return roleInstance != null && roleInstance.instanceStatus() == Deployment.InstanceStatus.STOPPED_VM; - } - }, 600, 5, 15, SECONDS); - - final DeploymentParams params = DeploymentParams.builder() - .name(DEPLOYMENT) - .os(OSImage.Type.LINUX) - .sourceImageName(BaseAzureComputeApiLiveTest.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(); - getOrCreateDeployment(cloudService.name(), params); - RoleInstance roleInstance = getFirstRoleInstanceInDeployment(DEPLOYMENT); - assertTrue(roleInstanceReady.apply(DEPLOYMENT), roleInstance.toString()); - roleName = roleInstance.roleName(); - } - - public void testUpdate() { - final Role role = api().getRole(roleName); - assertTrue(new ConflictManagementPredicate(api) { - - @Override - protected String operation() { - return api().updateRole(roleName, - Role.create( - role.roleName(), - role.roleType(), - role.vmImage(), - role.mediaLocation(), - role.configurationSets(), - role.resourceExtensionReferences(), - role.availabilitySetName(), - role.dataVirtualHardDisks(), - role.osVirtualHardDisk(), - role.roleSize(), - role.provisionGuestAgent(), - role.defaultWinRmCertificateThumbprint())); - } - }.apply(role.roleName())); - } - - @Test(dependsOnMethods = "testUpdate") - public void testShutdown() { - assertTrue(new ConflictManagementPredicate(api) { - - @Override - protected String operation() { - return api().shutdown(roleName); - } - }.apply(roleName)); - - RoleInstance roleInstance = getFirstRoleInstanceInDeployment(DEPLOYMENT); - assertTrue(roleInstanceStopped.apply(DEPLOYMENT), roleInstance.toString()); - Logger.getAnonymousLogger().log(Level.INFO, "roleInstance stopped: {0}", roleInstance); - } - - @Test(dependsOnMethods = "testShutdown") - public void testStart() { - assertTrue(new ConflictManagementPredicate(api) { - - @Override - protected String operation() { - return api().start(roleName); - } - }.apply(roleName)); - - RoleInstance roleInstance = getFirstRoleInstanceInDeployment(DEPLOYMENT); - assertTrue(roleInstanceReady.apply(DEPLOYMENT), roleInstance.toString()); - Logger.getAnonymousLogger().log(Level.INFO, "roleInstance started: {0}", roleInstance); - } - - @Test(dependsOnMethods = "testStart") - public void testRestart() { - assertTrue(new ConflictManagementPredicate(api) { - - @Override - protected String operation() { - return api().restart(roleName); - } - }.apply(roleName)); - - final RoleInstance roleInstance = getFirstRoleInstanceInDeployment(DEPLOYMENT); - assertTrue(roleInstanceReady.apply(DEPLOYMENT), roleInstance.toString()); - Logger.getAnonymousLogger().log(Level.INFO, "roleInstance restarted: {0}", roleInstance); - } - - @AfterClass - @Override - protected void tearDown() { - if (cloudService != null && api.getDeploymentApiForService(cloudService.name()).get(DEPLOYMENT) != null) { - final List<Role> roles = api.getDeploymentApiForService(cloudService.name()).get(DEPLOYMENT).roleList(); - - assertTrue(new ConflictManagementPredicate(api) { - - @Override - protected String operation() { - return api.getDeploymentApiForService(cloudService.name()).delete(DEPLOYMENT); - } - }.apply(DEPLOYMENT)); - - 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())); - } - } - - assertTrue(new ConflictManagementPredicate(api) { - - @Override - protected String operation() { - return api.getCloudServiceApi().delete(cloudService.name()); - } - }.apply(cloudService.name())); - - super.tearDown(); - } - } - - private VirtualMachineApi api() { - return api.getVirtualMachineApiForDeploymentInService(DEPLOYMENT, cloudService.name()); - } - - private RoleInstance getFirstRoleInstanceInDeployment(String deployment) { - return Iterables.getOnlyElement(api.getDeploymentApiForService(cloudService.name()).get(deployment). - roleInstanceList()); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/test/java/org/jclouds/azurecompute/features/VirtualMachineApiMockTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/VirtualMachineApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/VirtualMachineApiMockTest.java deleted file mode 100644 index 2272c70..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/VirtualMachineApiMockTest.java +++ /dev/null @@ -1,133 +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 java.io.InputStream; -import java.nio.charset.Charset; - -import org.jclouds.azurecompute.domain.Role; -import org.jclouds.azurecompute.internal.BaseAzureComputeApiMockTest; -import org.jclouds.azurecompute.xml.RoleHandlerTest; -import org.testng.annotations.Test; - -import com.google.common.io.ByteStreams; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; - -/* - * Note: Mock test for CaptureVMImage method is in VMImageApiMockTest class - */ -@Test(groups = "unit", testName = "VirtualMachineApiMockTest") -public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { - - public void testStart() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - VirtualMachineApi api = vmApi(server); - - assertThat(api.start("myvm")).isEqualTo("request-1"); - - assertSent(server, "POST", - "/services/hostedservices/my-service/deployments/mydeployment/roleinstances/myvm/Operations", - "/startrolepayload.xml"); - } finally { - server.shutdown(); - } - } - - public void testRestart() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - VirtualMachineApi api = vmApi(server); - - assertThat(api.restart("myvm")).isEqualTo("request-1"); - - assertSent(server, "POST", - "/services/hostedservices/my-service/deployments/mydeployment/roleinstances/myvm/Operations", - "/restartrolepayload.xml"); - } finally { - server.shutdown(); - } - } - - public void testShutdown() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - VirtualMachineApi api = vmApi(server); - - assertThat(api.shutdown("myvm")).isEqualTo("request-1"); - - assertSent(server, "POST", - "/services/hostedservices/my-service/deployments/mydeployment/roleinstances/myvm/Operations", - "/shutdownrolepayload.xml"); - } finally { - server.shutdown(); - } - } - - public void testCapture() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - VirtualMachineApi api = vmApi(server); - - assertThat(api.capture("myvm", "myImageName", "myImageLabel")).isEqualTo("request-1"); - - assertSent(server, "POST", - "/services/hostedservices/my-service/deployments/mydeployment/roleinstances/myvm/Operations", - "/capturerolepayload.xml"); - } finally { - server.shutdown(); - } - } - - public void testUpdate() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - VirtualMachineApi api = vmApi(server); - - Role role = RoleHandlerTest.expected(); - assertThat(api.updateRole("testvnetsg02", role)).isEqualTo("request-1"); - - RecordedRequest request = assertSent(server, "PUT", "/services/hostedservices/my-service/deployments/mydeployment/roles/testvnetsg02"); - - final InputStream is = getClass().getResourceAsStream("/role-update-body.xml"); - try { - assertThat(request.getUtf8Body()).isXmlEqualTo(new String(ByteStreams.toByteArray(is), Charset.forName("UTF-8"))); - } finally { - is.close(); - } - } finally { - server.shutdown(); - } - } - - private VirtualMachineApi vmApi(MockWebServer server) { - return api(server.getUrl("/")).getVirtualMachineApiForDeploymentInService("mydeployment", "my-service"); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/test/java/org/jclouds/azurecompute/features/VirtualNetworkApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/VirtualNetworkApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/VirtualNetworkApiLiveTest.java deleted file mode 100644 index 705a377..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/VirtualNetworkApiLiveTest.java +++ /dev/null @@ -1,114 +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 static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; -import java.util.List; - -import org.jclouds.azurecompute.AzureTestUtils; -import org.jclouds.azurecompute.domain.NetworkConfiguration; -import org.jclouds.azurecompute.domain.NetworkConfiguration.VirtualNetworkSite; -import org.jclouds.azurecompute.internal.BaseAzureComputeApiLiveTest; -import org.jclouds.azurecompute.util.ConflictManagementPredicate; -import org.testng.annotations.AfterSuite; -import org.testng.annotations.BeforeSuite; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -@Test(groups = "live", testName = "VirtualNetworkApiLiveTest", singleThreaded = true) -public class VirtualNetworkApiLiveTest extends BaseAzureComputeApiLiveTest { - - private static final String DEFAULT_ADDRESS_SPACE = "10.0.0.0/20"; - private static final String DEFAULT_SUBNET_ADDRESS_SPACE = "10.0.0.0/23"; - private List<VirtualNetworkSite> initialVirtualNetworkSite; - - @BeforeSuite - @Override - public void setup() { - super.setup(); - - initialVirtualNetworkSite = AzureTestUtils.getVirtualNetworkSite(api); - - virtualNetworkSite = getOrCreateVirtualNetworkSite(VIRTUAL_NETWORK_NAME, LOCATION); - - final List<VirtualNetworkSite> virtualNetworkSites = Lists.newArrayList(Iterables.filter( - AzureTestUtils.getVirtualNetworkSite(api), - new AzureTestUtils.SameVirtualNetworkSiteNamePredicate(VIRTUAL_NETWORK_NAME))); - - final NetworkConfiguration.AddressSpace addressSpace = NetworkConfiguration.AddressSpace.create( - DEFAULT_ADDRESS_SPACE); - - final ImmutableList<NetworkConfiguration.Subnet> subnets = ImmutableList.of(NetworkConfiguration.Subnet.create( - DEFAULT_SUBNET_NAME, DEFAULT_SUBNET_ADDRESS_SPACE, null)); - - final NetworkConfiguration networkConfiguration = api().getNetworkConfiguration(); - assertThat(networkConfiguration.virtualNetworkConfiguration().dns()).isEqualTo( - networkConfiguration.virtualNetworkConfiguration().dns()); - - assertThat(virtualNetworkSites.size()).isEqualTo(1); - assertThat(virtualNetworkSites.get(0).name()).isEqualTo(VIRTUAL_NETWORK_NAME); - assertThat(virtualNetworkSites.get(0).location()).isEqualTo(LOCATION); - assertThat(virtualNetworkSites.get(0).addressSpace()).isEqualTo(addressSpace); - assertThat(virtualNetworkSites.get(0).subnets()).isEqualTo(subnets); - } - - @AfterSuite - @Override - protected void tearDown() { - super.tearDown(); - - final NetworkConfiguration networkConfiguration = NetworkConfiguration.create(NetworkConfiguration.VirtualNetworkConfiguration.create(null, initialVirtualNetworkSite)); - assertTrue(new ConflictManagementPredicate(api) { - @Override - protected String operation() { - return api.getVirtualNetworkApi().set(networkConfiguration); - } - }.apply("Revert VirtualNetworkConfiguration")); - } - - @Test - public void testList() { - for (VirtualNetworkSite vns : api().list()) { - checkVirtualNetworkSite(vns); - } - } - - private void checkVirtualNetworkSite(VirtualNetworkSite virtualNetworkSite) { - assertNotNull(virtualNetworkSite.name(), "Name cannot be null for a VirtualNetworkSite."); - assertNotNull(virtualNetworkSite.addressSpace(), "AddressSpace cannot be null for: " + virtualNetworkSite); - assertNotNull(virtualNetworkSite.subnets(), "Subnets cannot be null for: " + virtualNetworkSite); - } - - @Test - public void testGetNetworkConfiguration() { - final NetworkConfiguration networkConfiguration = api().getNetworkConfiguration(); - assertThat(networkConfiguration).isNotNull(); - for (VirtualNetworkSite vns : networkConfiguration.virtualNetworkConfiguration().virtualNetworkSites()) { - assertThat(vns.name()).isNotEqualTo("not-existing"); - } - } - - private VirtualNetworkApi api() { - return api.getVirtualNetworkApi(); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/test/java/org/jclouds/azurecompute/features/VirtualNetworkApiMockTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/VirtualNetworkApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/VirtualNetworkApiMockTest.java deleted file mode 100644 index 85f13af..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/VirtualNetworkApiMockTest.java +++ /dev/null @@ -1,94 +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 static org.testng.Assert.assertEquals; -import java.util.UUID; - -import org.jclouds.azurecompute.domain.NetworkConfiguration; -import org.jclouds.azurecompute.domain.NetworkConfiguration.VirtualNetworkConfiguration; -import org.jclouds.azurecompute.internal.BaseAzureComputeApiMockTest; -import org.jclouds.azurecompute.xml.ListVirtualNetworkSitesHandlerTest; -import org.jclouds.azurecompute.xml.NetworkConfigurationHandlerTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.mockwebserver.MockWebServer; - -@Test(groups = "unit", testName = "VirtualNetworkApiMockTest") -public class VirtualNetworkApiMockTest extends BaseAzureComputeApiMockTest { - - public void testGetNetworkConfiguration() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(xmlResponse("/networkconfiguration.xml")); - - try { - VirtualNetworkApi api = virtualNetworkApi(server); - - assertEquals(api.getNetworkConfiguration(), NetworkConfigurationHandlerTest.expected()); - - assertSent(server, "GET", "/services/networking/media"); - } finally { - server.shutdown(); - } - } - - public void testSet() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - VirtualNetworkApi api = virtualNetworkApi(server); - - assertThat(api.set(NetworkConfiguration.create( - VirtualNetworkConfiguration.create(null, - ImmutableList.of(NetworkConfiguration.VirtualNetworkSite.create( - UUID.randomUUID().toString(), - "jclouds-virtual-network", - "West Europe", - NetworkConfiguration.AddressSpace.create("10.0.0.0/20"), - ImmutableList.of(NetworkConfiguration.Subnet.create("jclouds-1", "10.0.0.0/23", - null))))))) - ).isEqualTo("request-1"); - - assertSent(server, "PUT", "/services/networking/media"); - } finally { - server.shutdown(); - } - } - - public void testList() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(xmlResponse("/virtualnetworksites.xml")); - - try { - VirtualNetworkApi api = virtualNetworkApi(server); - - assertThat(api.list()).containsExactlyElementsOf(ListVirtualNetworkSitesHandlerTest.expected()); - - assertSent(server, "GET", - "/services/networking/virtualnetwork"); - } finally { - server.shutdown(); - } - } - - private VirtualNetworkApi virtualNetworkApi(MockWebServer server) { - return api(server.getUrl("/")).getVirtualNetworkApi(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/test/java/org/jclouds/azurecompute/internal/AbstractAzureComputeApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/internal/AbstractAzureComputeApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/internal/AbstractAzureComputeApiLiveTest.java deleted file mode 100644 index 47bfb5a..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/internal/AbstractAzureComputeApiLiveTest.java +++ /dev/null @@ -1,64 +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.internal; - -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.jclouds.azurecompute.config.AzureComputeProperties.OPERATION_POLL_INITIAL_PERIOD; -import static org.jclouds.azurecompute.config.AzureComputeProperties.OPERATION_POLL_MAX_PERIOD; -import static org.jclouds.azurecompute.config.AzureComputeProperties.OPERATION_TIMEOUT; -import static org.jclouds.azurecompute.config.AzureComputeProperties.TCP_RULE_FORMAT; -import static org.jclouds.azurecompute.config.AzureComputeProperties.TCP_RULE_REGEXP; -import java.util.Properties; -import java.util.Random; - -import org.jclouds.apis.BaseApiLiveTest; -import org.jclouds.azurecompute.AzureComputeApi; -import org.jclouds.azurecompute.util.ConflictManagementPredicate; -import org.jclouds.compute.config.ComputeServiceProperties; -import org.testng.annotations.BeforeClass; - -import com.google.common.base.Predicate; - -public abstract class AbstractAzureComputeApiLiveTest extends BaseApiLiveTest<AzureComputeApi> { - - protected static final int RAND = new Random().nextInt(999); - - protected Predicate<String> operationSucceeded; - - public AbstractAzureComputeApiLiveTest() { - provider = "azurecompute"; - } - - @Override protected Properties setupProperties() { - Properties properties = super.setupProperties(); - properties.put(ComputeServiceProperties.POLL_INITIAL_PERIOD, 1000); - properties.put(ComputeServiceProperties.POLL_MAX_PERIOD, 10000); - properties.setProperty(OPERATION_TIMEOUT, "60000"); - properties.setProperty(OPERATION_POLL_INITIAL_PERIOD, "5"); - properties.setProperty(OPERATION_POLL_MAX_PERIOD, "15"); - properties.setProperty(TCP_RULE_FORMAT, "tcp_%s-%s"); - properties.setProperty(TCP_RULE_REGEXP, "tcp_\\d{1,5}-\\d{1,5}"); - return properties; - } - - @BeforeClass - @Override - public void setup() { - super.setup(); - operationSucceeded = new ConflictManagementPredicate(api, 600, 5, 5, SECONDS); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/test/java/org/jclouds/azurecompute/internal/BaseAzureComputeApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/internal/BaseAzureComputeApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/internal/BaseAzureComputeApiLiveTest.java deleted file mode 100644 index 220b592..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/internal/BaseAzureComputeApiLiveTest.java +++ /dev/null @@ -1,203 +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.internal; - -import static com.google.common.collect.Iterables.find; -import static com.google.common.collect.Iterables.tryFind; -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.testng.Assert.assertTrue; - -import java.util.List; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.jclouds.azurecompute.AzureTestUtils; -import org.jclouds.azurecompute.AzureTestUtils.SameVirtualNetworkSiteNamePredicate; -import org.jclouds.azurecompute.domain.CloudService; -import org.jclouds.azurecompute.domain.CreateStorageServiceParams; -import org.jclouds.azurecompute.domain.Deployment; -import org.jclouds.azurecompute.domain.DeploymentParams; -import org.jclouds.azurecompute.domain.NetworkConfiguration; -import org.jclouds.azurecompute.domain.NetworkConfiguration.AddressSpace; -import org.jclouds.azurecompute.domain.NetworkConfiguration.Subnet; -import org.jclouds.azurecompute.domain.NetworkConfiguration.VirtualNetworkConfiguration; -import org.jclouds.azurecompute.domain.NetworkConfiguration.VirtualNetworkSite; -import org.jclouds.azurecompute.domain.StorageService; -import org.jclouds.azurecompute.util.ConflictManagementPredicate; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; - -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; - -public class BaseAzureComputeApiLiveTest extends AbstractAzureComputeApiLiveTest { - - public static final String DEFAULT_ADDRESS_SPACE = "10.0.0.0/20"; - - public static final String DEFAULT_SUBNET_ADDRESS_SPACE = "10.0.0.0/23"; - - public static final String VIRTUAL_NETWORK_NAME = "jclouds-virtual-network-live-test"; - - public static final String DEFAULT_SUBNET_NAME = "jclouds-1"; - - public static final String LOCATION = "West Europe"; - - public static final String IMAGE_NAME - = "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04_1-LTS-amd64-server-20150123-en-us-30GB"; - - protected StorageService storageService; - - protected VirtualNetworkSite virtualNetworkSite; - - private String storageServiceName = null; - - protected String getStorageServiceName() { - if (storageServiceName == null) { - storageServiceName = String.format("%3.24s", - System.getProperty("user.name") + RAND + this.getClass().getSimpleName()).toLowerCase(); - } - return storageServiceName; - } - - @BeforeClass - @Override - public void setup() { - super.setup(); - - operationSucceeded = new ConflictManagementPredicate(api, 600, 5, 5, SECONDS); - - final CreateStorageServiceParams params = CreateStorageServiceParams.builder(). - serviceName(getStorageServiceName()). - label(getStorageServiceName()). - location(LOCATION). - accountType(StorageService.AccountType.Standard_LRS). - build(); - storageService = getOrCreateStorageService(getStorageServiceName(), params); - } - - @AfterClass(alwaysRun = true) - @Override - protected void tearDown() { - super.tearDown(); - - assertTrue(new ConflictManagementPredicate(api) { - @Override - protected String operation() { - return api.getStorageAccountApi().delete(getStorageServiceName()); - } - }.apply(getStorageServiceName())); - - - - } - - protected CloudService getOrCreateCloudService(final String cloudServiceName, final String location) { - CloudService cloudService = api.getCloudServiceApi().get(cloudServiceName); - if (cloudService != null) { - return cloudService; - } - - String requestId = api.getCloudServiceApi().createWithLabelInLocation( - cloudServiceName, cloudServiceName, location); - - assertTrue(operationSucceeded.apply(requestId), requestId); - Logger.getAnonymousLogger().log(Level.INFO, "operation succeeded: {0}", requestId); - cloudService = api.getCloudServiceApi().get(cloudServiceName); - Logger.getAnonymousLogger().log(Level.INFO, "created cloudService: {0}", cloudService); - return cloudService; - } - - protected Deployment getOrCreateDeployment(final String serviceName, final DeploymentParams params) { - Deployment deployment = api.getDeploymentApiForService(serviceName).get(params.name()); - if (deployment != null) { - return deployment; - } - - assertTrue(new ConflictManagementPredicate(api) { - - @Override - protected String operation() { - return api.getDeploymentApiForService(serviceName).create(params); - } - }.apply(getStorageServiceName())); - - deployment = api.getDeploymentApiForService(serviceName).get(params.name()); - - Logger.getAnonymousLogger().log(Level.INFO, "created deployment: {0}", deployment); - return deployment; - } - - protected StorageService getOrCreateStorageService(String storageServiceName, CreateStorageServiceParams params) { - StorageService ss = api.getStorageAccountApi().get(storageServiceName); - if (ss != null) { - return ss; - } - String requestId = api.getStorageAccountApi().create(params); - assertTrue(operationSucceeded.apply(requestId), requestId); - Logger.getAnonymousLogger().log(Level.INFO, "operation succeeded: {0}", requestId); - ss = api.getStorageAccountApi().get(storageServiceName); - - Logger.getAnonymousLogger().log(Level.INFO, "created storageService: {0}", ss); - return ss; - } - - protected VirtualNetworkSite getOrCreateVirtualNetworkSite(final String virtualNetworkSiteName, String location) { - final List<VirtualNetworkSite> current = AzureTestUtils.getVirtualNetworkSite(api); - - final Optional<VirtualNetworkSite> optionalVirtualNetworkSite = tryFind( - current, - new SameVirtualNetworkSiteNamePredicate(virtualNetworkSiteName)); - - if (optionalVirtualNetworkSite.isPresent()) { - return optionalVirtualNetworkSite.get(); - } - - current.add(VirtualNetworkSite.create(UUID.randomUUID().toString(), - virtualNetworkSiteName, - location, - AddressSpace.create(DEFAULT_ADDRESS_SPACE), - ImmutableList.of(Subnet.create(DEFAULT_SUBNET_NAME, DEFAULT_SUBNET_ADDRESS_SPACE, null)))); - - final NetworkConfiguration networkConfiguration - = NetworkConfiguration.create(VirtualNetworkConfiguration.create(null, current)); - - VirtualNetworkSite vns; - try { - vns = find( - api.getVirtualNetworkApi().getNetworkConfiguration().virtualNetworkConfiguration(). - virtualNetworkSites(), - new SameVirtualNetworkSiteNamePredicate(virtualNetworkSiteName)); - } catch (Exception e) { - assertTrue(new ConflictManagementPredicate(api) { - - @Override - protected String operation() { - return api.getVirtualNetworkApi().set(networkConfiguration); - } - }.apply(virtualNetworkSiteName)); - - vns = find( - api.getVirtualNetworkApi().getNetworkConfiguration().virtualNetworkConfiguration(). - virtualNetworkSites(), - new SameVirtualNetworkSiteNamePredicate(virtualNetworkSiteName)); - - Logger.getAnonymousLogger().log(Level.INFO, "created virtualNetworkSite: {0}", vns); - } - return vns; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/test/java/org/jclouds/azurecompute/internal/BaseAzureComputeApiMockTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/internal/BaseAzureComputeApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/internal/BaseAzureComputeApiMockTest.java deleted file mode 100644 index ced04f8..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/internal/BaseAzureComputeApiMockTest.java +++ /dev/null @@ -1,102 +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.internal; - -import static com.google.common.base.Charsets.UTF_8; -import static com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService; -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.IOException; -import java.net.URL; -import java.util.Properties; -import java.util.Set; - -import org.jclouds.ContextBuilder; -import org.jclouds.azurecompute.AzureComputeApi; -import org.jclouds.concurrent.config.ExecutorServiceModule; -import org.jclouds.util.Strings2; - -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; - -public class BaseAzureComputeApiMockTest { - - private final Set<Module> modules = ImmutableSet.<Module>of(new ExecutorServiceModule(newDirectExecutorService())); - - protected String provider; - - private final String identity; - - private final String credential; - - public BaseAzureComputeApiMockTest() { - provider = "azurecompute"; - // self-signed dummy cert: - // keytool -genkey -alias test -keyalg RSA -keysize 1024 -validity 5475 -dname "CN=localhost" -keystore azure-test.p12 -storepass azurepass -storetype pkcs12 - identity = this.getClass().getResource("/azure-test.p12").getFile(); - credential = "azurepass"; - } - - public AzureComputeApi api(URL url) { - Properties properties = new Properties(); - //properties.setProperty(SUBSCRIPTION_ID, "1234-1234-1234"); - return ContextBuilder.newBuilder(provider).credentials(identity, credential).endpoint(url.toString()) - .modules(modules).overrides(properties).buildApi(AzureComputeApi.class); - } - - protected static MockWebServer mockAzureManagementServer() throws IOException { - MockWebServer server = new MockWebServer(); - server.play(); - return server; - } - - protected MockResponse xmlResponse(String resource) { - return new MockResponse().addHeader("Content-Type", "application/xml").setBody(stringFromResource(resource)); - } - - protected MockResponse requestIdResponse(String requestId) { - return new MockResponse().addHeader("x-ms-request-id", requestId); - } - - protected String stringFromResource(String resourceName) { - try { - return Strings2.toStringAndClose(getClass().getResourceAsStream(resourceName)); - } catch (IOException e) { - throw Throwables.propagate(e); - } - } - - protected RecordedRequest assertSent(MockWebServer server, String method, String path) throws InterruptedException { - RecordedRequest request = server.takeRequest(); - assertThat(request.getMethod()).isEqualTo(method); - assertThat(request.getPath()).isEqualTo(path); - assertThat(request.getHeader("x-ms-version")).isEqualTo("2014-10-01"); - assertThat(request.getHeader("Accept")).isEqualTo("application/xml"); - return request; - } - - protected RecordedRequest assertSent(MockWebServer server, String method, String path, String resource) - throws InterruptedException { - RecordedRequest request = assertSent(server, method, path); - assertThat(new String(request.getBody(), UTF_8)).isEqualTo(stringFromResource(resource).trim()); - return request; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/test/java/org/jclouds/azurecompute/xml/CloudServiceHandlerTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/CloudServiceHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/CloudServiceHandlerTest.java deleted file mode 100644 index b11ae0e..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/CloudServiceHandlerTest.java +++ /dev/null @@ -1,56 +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.xml; - -import static org.testng.Assert.assertEquals; - -import java.io.InputStream; -import java.util.Collections; - -import org.jclouds.azurecompute.domain.CloudService; -import org.jclouds.azurecompute.domain.CloudService.Status; -import org.jclouds.date.DateService; -import org.jclouds.date.internal.SimpleDateFormatDateService; -import org.jclouds.http.functions.BaseHandlerTest; -import org.testng.annotations.Test; - -@Test(groups = "unit", testName = "HostedServiceHandlerTest") -public class CloudServiceHandlerTest extends BaseHandlerTest { - - private static final DateService DATE_SERVICE = new SimpleDateFormatDateService(); - - public void test() { - InputStream is = getClass().getResourceAsStream("/hostedservice.xml"); - CloudService result = factory.create(new CloudServiceHandler(DATE_SERVICE)).parse(is); - - assertEquals(result, expected()); - } - - public static CloudService expected() { - return CloudService.create( // - "neotys", // name - "West Europe", // location - null, // affinityGroup - "neotys", // label - "Implicitly created cloud service2012-08-06 14:55", // description - Status.CREATED, // status - DATE_SERVICE.iso8601SecondsDateParse("2012-08-06T14:55:17Z"), // created - DATE_SERVICE.iso8601SecondsDateParse("2012-08-06T15:50:34Z"), // lastModified - Collections.<String, String>emptyMap() // extendedProperties - ); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/test/java/org/jclouds/azurecompute/xml/CloudServicePropertiesHandlerTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/CloudServicePropertiesHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/CloudServicePropertiesHandlerTest.java deleted file mode 100644 index 6390442..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/CloudServicePropertiesHandlerTest.java +++ /dev/null @@ -1,147 +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.xml; - -import static org.testng.Assert.assertEquals; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import org.jclouds.azurecompute.domain.Deployment; -import org.jclouds.azurecompute.domain.CloudServiceProperties; -import org.jclouds.azurecompute.domain.RoleSize; -import org.jclouds.azurecompute.domain.Role; -import org.jclouds.azurecompute.domain.DataVirtualHardDisk; -import org.jclouds.azurecompute.domain.OSImage; -import org.jclouds.azurecompute.domain.Deployment.InstanceStatus; -import org.jclouds.azurecompute.domain.Deployment.Slot; -import org.jclouds.azurecompute.domain.Deployment.Status; -import org.jclouds.azurecompute.domain.Role.ConfigurationSet; -import org.jclouds.azurecompute.domain.Role.ConfigurationSet.InputEndpoint; -import org.jclouds.azurecompute.domain.Role.OSVirtualHardDisk; -import org.jclouds.date.DateService; -import org.jclouds.date.internal.SimpleDateFormatDateService; -import org.jclouds.http.functions.BaseHandlerTest; -import org.testng.annotations.Test; - -import java.io.InputStream; -import java.net.URI; -import java.util.List; - -@Test(groups = "unit", testName = "CloudServicePropertiesHandlerTest") -public class CloudServicePropertiesHandlerTest extends BaseHandlerTest { - - private static final DateService DATE_SERVICE = new SimpleDateFormatDateService(); - - public void test() { - InputStream is = getClass().getResourceAsStream("/cloudserviceproperties.xml"); - CloudServiceProperties result = factory.create( - new CloudServicePropertiesHandler(DATE_SERVICE, new DeploymentHandler( - new VirtualIPHandler(), - new RoleInstanceHandler(), - new RoleHandler( - new ConfigurationSetHandler(new InputEndpointHandler(), new SubnetNameHandler()), - new OSVirtualHardDiskHandler(), - new DataVirtualHardDiskHandler(), - new ResourceExtensionReferenceHandler(new ResourceExtensionParameterValueHandler()))))) - .parse(is); - assertEquals(result, expected()); - } - - public static CloudServiceProperties expected() { - return CloudServiceProperties.create("neotys", - URI.create("https://api/services/hostedservices/neotys"), - "West Europe", - null, - "bmVvdHlz", - "Implicitly created cloud service2012-08-06 14:55", - CloudServiceProperties.Status.CREATED, - DATE_SERVICE.iso8601SecondsDateParse("2012-08-06T14:55:17Z"), // created - DATE_SERVICE.iso8601SecondsDateParse("2012-08-06T15:50:34Z"), - ImmutableMap.<String, String>builder().build(), - deploymentList() - ); - } - - private static List<Deployment> deploymentList() { - return ImmutableList.of( - Deployment.create( // - "node1855162607153993262-b26", // name - Slot.PRODUCTION, // slot - Status.RUNNING, // status - "node1855162607153993262-b26", // label - null, // instanceStateDetails - null, // instanceErrorCode - ImmutableList.of(Deployment.VirtualIP.create("191.233.85.49", true, - "node1855162607153993262-b26ContractContract")), //virtualIPs - ImmutableList.of(Deployment.RoleInstance.create( - "node1855162607153993262-b26", // roleName - "node1855162607153993262-b26", // instanceName - InstanceStatus.READY_ROLE, //instanceStatus - Deployment.PowerState.STARTED, - 0, - 0, - RoleSize.Type.BASIC_A0, - "10.0.2.6", - "node1855162607153993262-b26", // hostname - ImmutableList.of( - Deployment.InstanceEndpoint.create( - "tcp_22-22", // name - "191.233.85.49", // vip - 22, // publicPort - 22, // localPort - "tcp" // protocol - ) - ) - )), - ImmutableList.of(Role.create( - "node1855162607153993262-b26", - "PersistentVMRole", - null, - null, - ImmutableList.of(ConfigurationSet.create( - "NetworkConfiguration", - ImmutableList.of( - InputEndpoint.create("tcp_22-22", "tcp", 22, 22, "191.233.85.49", - false, null, null, null), - InputEndpoint.create("tcp_2375-2375", "tcp", 2375, 2375, - "191.233.85.49", false, null, null, null) - ), - ImmutableList.of(ConfigurationSet.SubnetName.create("Subnet-1")), - null, - ImmutableList.<ConfigurationSet.PublicIP>of(), - null)), - ImmutableList.<Role.ResourceExtensionReference>of(), - null, - ImmutableList.<DataVirtualHardDisk>of(), - OSVirtualHardDisk.create( - "ReadWrite", - "node1855162607153993262-b26-node1855162607153993262-b26-0-201412221704390597", - null, - null, - URI.create( - "https://test.blob.core.windows.net/clockerblob/container-node1855162607153993262-b26.vhd"), - "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu_DAILY_BUILD-trusty-14_04_1-LTS-amd64-server-20141212-en-us-30GB", - OSImage.Type.LINUX), - RoleSize.Type.BASIC_A0, - null, - null - )), - "jclouds" // virtualNetworkName - ) - ); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/test/java/org/jclouds/azurecompute/xml/DeploymentHandlerTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/DeploymentHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/DeploymentHandlerTest.java deleted file mode 100644 index 0b24069..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/DeploymentHandlerTest.java +++ /dev/null @@ -1,153 +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.xml; - -import static org.testng.Assert.assertEquals; - -import java.io.InputStream; -import java.net.URI; - -import org.jclouds.azurecompute.domain.DataVirtualHardDisk; -import org.jclouds.azurecompute.domain.Deployment; -import org.jclouds.azurecompute.domain.Deployment.InstanceStatus; -import org.jclouds.azurecompute.domain.Deployment.Slot; -import org.jclouds.azurecompute.domain.Deployment.Status; -import org.jclouds.azurecompute.domain.OSImage; -import org.jclouds.azurecompute.domain.Role; -import org.jclouds.azurecompute.domain.Role.ConfigurationSet; -import org.jclouds.azurecompute.domain.Role.ConfigurationSet.InputEndpoint; -import org.jclouds.azurecompute.domain.Role.OSVirtualHardDisk; -import org.jclouds.azurecompute.domain.RoleSize; -import org.jclouds.http.functions.BaseHandlerTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; - -@Test(groups = "unit", testName = "DeploymentHandlerTest") -public class DeploymentHandlerTest extends BaseHandlerTest { - - private InstanceStatus parseInstanceStatus(final String instanceStatus) { - return InstanceStatus.fromString(instanceStatus); - } - - /** - * Covers values listed - * <a href="http://msdn.microsoft.com/en-us/library/azure/ee460804.aspx#RoleInstanceList">here</a>. - */ - public void parseInstanceStatus_Recognized() { - assertEquals(parseInstanceStatus("RoleStateUnknown"), InstanceStatus.ROLE_STATE_UNKNOWN); - assertEquals(parseInstanceStatus("CreatingVM"), InstanceStatus.CREATING_VM); - assertEquals(parseInstanceStatus("StartingVM"), InstanceStatus.STARTING_VM); - assertEquals(parseInstanceStatus("CreatingRole"), InstanceStatus.CREATING_ROLE); - assertEquals(parseInstanceStatus("StartingRole"), InstanceStatus.STARTING_ROLE); - assertEquals(parseInstanceStatus("ReadyRole"), InstanceStatus.READY_ROLE); - assertEquals(parseInstanceStatus("BusyRole"), InstanceStatus.BUSY_ROLE); - assertEquals(parseInstanceStatus("StoppingRole"), InstanceStatus.STOPPING_ROLE); - assertEquals(parseInstanceStatus("StoppingVM"), InstanceStatus.STOPPING_VM); - assertEquals(parseInstanceStatus("DeletingVM"), InstanceStatus.DELETING_VM); - assertEquals(parseInstanceStatus("StoppedVM"), InstanceStatus.STOPPED_VM); - assertEquals(parseInstanceStatus("RestartingRole"), InstanceStatus.RESTARTING_ROLE); - assertEquals(parseInstanceStatus("CyclingRole"), InstanceStatus.CYCLING_ROLE); - assertEquals(parseInstanceStatus("FailedStartingRole"), InstanceStatus.FAILED_STARTING_ROLE); - assertEquals(parseInstanceStatus("FailedStartingVM"), InstanceStatus.FAILED_STARTING_VM); - assertEquals(parseInstanceStatus("UnresponsiveRole"), InstanceStatus.UNRESPONSIVE_ROLE); - assertEquals(parseInstanceStatus("StoppedDeallocated"), InstanceStatus.STOPPED_DEALLOCATED); - assertEquals(parseInstanceStatus("Preparing"), InstanceStatus.PREPARING); - } - - public void parseInstanceStatus_Unrecognized() { - assertEquals(parseInstanceStatus("FooAddedToday"), InstanceStatus.UNRECOGNIZED); - } - - public void test() { - InputStream is = getClass().getResourceAsStream("/deployment.xml"); - Deployment result = factory.create(new DeploymentHandler( - new VirtualIPHandler(), - new RoleInstanceHandler(), - new RoleHandler( - new ConfigurationSetHandler(new InputEndpointHandler(), new SubnetNameHandler()), - new OSVirtualHardDiskHandler(), - new DataVirtualHardDiskHandler(), - new ResourceExtensionReferenceHandler(new ResourceExtensionParameterValueHandler())))) - .parse(is); - - assertEquals(result, expected()); - } - - public static Deployment expected() { - return Deployment.create( // - "node1855162607153993262-b26", // name - Slot.PRODUCTION, // slot - Status.RUNNING, // status - "node1855162607153993262-b26", // label - null, // instanceStateDetails - null, // instanceErrorCode - ImmutableList.of(Deployment.VirtualIP.create("191.233.85.49", true, "node1855162607153993262-b26ContractContract")), //virtualIPs - ImmutableList.of(Deployment.RoleInstance.create( - "node1855162607153993262-b26", // roleName - "node1855162607153993262-b26", // instanceName - InstanceStatus.READY_ROLE, //instanceStatus - Deployment.PowerState.STARTED, - 0, - 0, - RoleSize.Type.BASIC_A0, - "10.0.2.6", - "node1855162607153993262-b26", // hostname - ImmutableList.of( - Deployment.InstanceEndpoint.create( - "tcp_22-22", // name - "191.233.85.49", // vip - 22, // publicPort - 22, // localPort - "tcp" // protocol - ) - ) - )), - ImmutableList.of(Role.create( - "node1855162607153993262-b26", - "PersistentVMRole", - null, - null, - ImmutableList.of(ConfigurationSet.create( - "NetworkConfiguration", - ImmutableList.of( - InputEndpoint.create("tcp_22-22", "tcp", 22, 22, "191.233.85.49", false, null, null, null), - InputEndpoint.create("tcp_2375-2375", "tcp", 2375, 2375, "191.233.85.49", false, null, null, null) - ), - ImmutableList.of(ConfigurationSet.SubnetName.create("Subnet-1")), - null, - ImmutableList.<ConfigurationSet.PublicIP>of(), - null)), - ImmutableList.<Role.ResourceExtensionReference>of(), - null, - ImmutableList.<DataVirtualHardDisk>of(), - OSVirtualHardDisk.create( - "ReadWrite", - "node1855162607153993262-b26-node1855162607153993262-b26-0-201412221704390597", - null, - null, - URI.create("https://test.blob.core.windows.net/clockerblob/container-node1855162607153993262-b26.vhd"), - "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu_DAILY_BUILD-trusty-14_04_1-LTS-amd64-server-20141212-en-us-30GB", - OSImage.Type.LINUX), - RoleSize.Type.BASIC_A0, - null, - null - )), - "jclouds" // virtualNetworkName - ); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ErrorHandlerTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ErrorHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ErrorHandlerTest.java deleted file mode 100644 index d627c23..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ErrorHandlerTest.java +++ /dev/null @@ -1,42 +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.xml; - -import static org.testng.Assert.assertEquals; - -import java.io.InputStream; - -import org.jclouds.azurecompute.domain.Error; -import org.jclouds.azurecompute.domain.Error.Code; -import org.jclouds.http.functions.BaseHandlerTest; -import org.testng.annotations.Test; - -@Test(groups = "unit", testName = "ErrorHandlerTest") -public class ErrorHandlerTest extends BaseHandlerTest { - - public void test() { - InputStream is = getClass().getResourceAsStream("/error.xml"); - Error result = factory.create(new ErrorHandler()).parse(is); - - assertEquals(result, expected()); - } - - public static Error expected() { - return Error.create(Code.MISSING_OR_INVALID_REQUIRED_QUERY_PARAMETER, - "A required query parameter was not specified for this request or was specified incorrectly."); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/b8ab3758/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListAffinityGroupsHandlerTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListAffinityGroupsHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListAffinityGroupsHandlerTest.java deleted file mode 100644 index 747b0d2..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListAffinityGroupsHandlerTest.java +++ /dev/null @@ -1,90 +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.xml; - -import static org.testng.Assert.assertEquals; - -import java.io.InputStream; -import java.util.List; - -import org.jclouds.azurecompute.domain.AffinityGroup; -import org.jclouds.azurecompute.domain.ComputeCapabilities; -import org.jclouds.azurecompute.domain.RoleSize; -import org.jclouds.date.internal.SimpleDateFormatDateService; -import org.jclouds.http.functions.BaseHandlerTest; - -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; - -@Test(groups = "unit", testName = "ListAffinityGroupsHandlerTest") -public class ListAffinityGroupsHandlerTest extends BaseHandlerTest { - - public void test() { - final InputStream input = getClass().getResourceAsStream("/affinityGroups.xml"); - final List<AffinityGroup> result = factory.create(new ListAffinityGroupsHandler( - new AffinityGroupHandler(new ComputeCapabilitiesHandler()))).parse(input); - - assertEquals(result, expected()); - } - - public static List<AffinityGroup> expected() { - return ImmutableList.of( - AffinityGroup.create( - "Test1", - "Test1", - "Test 1 description", - "West Europe", - ImmutableList.of( - AffinityGroup.Capability.PersistentVMRole, - AffinityGroup.Capability.HighMemory - ), - new SimpleDateFormatDateService().iso8601DateOrSecondsDateParse("2015-03-09T15:15:29Z"), - ComputeCapabilities.create( - ImmutableList.of( - RoleSize.Type.A10, - RoleSize.Type.A11 - ), - ImmutableList.of( - RoleSize.Type.A10, - RoleSize.Type.A11) - ) - ), - AffinityGroup.create( - "Test2", - "Test2", - null, - "Southeast Asia", - ImmutableList.of( - AffinityGroup.Capability.PersistentVMRole, - AffinityGroup.Capability.HighMemory - ), - new SimpleDateFormatDateService().iso8601DateOrSecondsDateParse("2015-03-09T15:16:10Z"), - ComputeCapabilities.create( - ImmutableList.of( - RoleSize.Type.EXTRALARGE, - RoleSize.Type.EXTRASMALL - ), - ImmutableList.of( - RoleSize.Type.EXTRALARGE, - RoleSize.Type.EXTRASMALL - ) - ) - ) - ); - } -}
