diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/handlers/CloudStackErrorHandler.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/handlers/CloudStackErrorHandler.java index d9cfcd64b5..7c051ec7af 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/handlers/CloudStackErrorHandler.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/handlers/CloudStackErrorHandler.java @@ -71,8 +71,7 @@ public class CloudStackErrorHandler implements HttpErrorHandler { break; case 409: case 431: - if (command.getCurrentRequest().getRequestLine().indexOf("delete") != -1 - && message.indexOf("does not exist") != -1) { + if (message.contains("does not exist")) { exception = new ResourceNotFoundException(message, exception); } else { exception = new IllegalStateException(message, exception); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientLiveTest.java index 5bf6d2d3c4..fda2d9a8d4 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientLiveTest.java @@ -49,7 +49,7 @@ public class AccountClientLiveTest extends BaseCloudStackClientLiveTest { assert user.getName() != null : user; assert user.getAccountType().equals(account.getType()) : user; assert user.getDomain().equals(account.getDomain()) : user; - assert user.getDomainId() == account.getDomainId() : user; + assert user.getDomainId().equals(account.getDomainId()) : user; assert user.getApiKey() != null : user; assert user.getCreated() != null : user; assert user.getEmail() != null : user; diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java index d153c0719d..16218b0617 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java @@ -57,6 +57,7 @@ import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; import org.jclouds.ssh.SshClient; import org.jclouds.sshj.config.SshjSshClientModule; +import org.testng.SkipException; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; @@ -270,6 +271,18 @@ public class BaseCloudStackClientLiveTest extends BaseGenericComputeServiceConte return currentUser; } + protected void skipIfNotDomainAdmin() { + if (!domainAdminEnabled) { + throw new SkipException("Test cannot run without domain admin identity and credentials"); + } + } + + protected void skipIfNotGlobalAdmin() { + if (!globalAdminEnabled) { + throw new SkipException("Test cannot run without global admin identity and credentials"); + } + } + @AfterGroups(groups = "live") protected void tearDown() { if (cloudStackContext != null) diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountClientLiveTest.java index 81b954ddf9..7d433392a2 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainAccountClientLiveTest.java @@ -38,7 +38,7 @@ public class DomainAccountClientLiveTest extends BaseCloudStackClientLiveTest { @Test public void testEnableDisableAccount() { - assert globalAdminEnabled; + skipIfNotGlobalAdmin(); Account testAccount = null; try { diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainDomainClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainDomainClientLiveTest.java index 0d84f24764..2a06bcb13e 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainDomainClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainDomainClientLiveTest.java @@ -43,7 +43,7 @@ public class DomainDomainClientLiveTest extends BaseCloudStackClientLiveTest { @Test public void testListDomains() { - assert domainAdminEnabled; + skipIfNotDomainAdmin(); Set allDomains = domainAdminClient.getDomainClient().listDomains(); @@ -63,7 +63,7 @@ public class DomainDomainClientLiveTest extends BaseCloudStackClientLiveTest { @Test public void testListDomainChildren() { - assert domainAdminEnabled; + skipIfNotDomainAdmin(); Set allDomains = domainAdminClient.getDomainClient().listDomains(); Domain root = find(allDomains, withName("ROOT")); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainUserClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainUserClientLiveTest.java index 42e846565d..fb6837b205 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainUserClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/DomainUserClientLiveTest.java @@ -40,7 +40,7 @@ public class DomainUserClientLiveTest extends BaseCloudStackClientLiveTest { @Test public void testListUsers() { - assert domainAdminEnabled; + skipIfNotDomainAdmin(); Set users = domainAdminClient.getUserClient().listUsers(); @@ -60,7 +60,8 @@ public class DomainUserClientLiveTest extends BaseCloudStackClientLiveTest { @Test public void testEnableDisableUser() { - assert globalAdminEnabled && domainAdminEnabled; + skipIfNotDomainAdmin(); + skipIfNotDomainAdmin(); Account testAccount = null; User testUser = null; diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalAccountClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalAccountClientLiveTest.java index 8f1302420f..fca83acc72 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalAccountClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalAccountClientLiveTest.java @@ -42,7 +42,7 @@ public class GlobalAccountClientLiveTest extends BaseCloudStackClientLiveTest { @Test public void testCreateAndRemoveAccount() { - assert globalAdminEnabled; + skipIfNotGlobalAdmin(); Account account = null; try { diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalAlertClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalAlertClientLiveTest.java index 65c0b94811..a51d98394c 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalAlertClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalAlertClientLiveTest.java @@ -38,7 +38,7 @@ public class GlobalAlertClientLiveTest extends BaseCloudStackClientLiveTest { @Test(groups = "live", enabled = true) public void testListAlerts() throws Exception { - assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials"); + skipIfNotGlobalAdmin(); final Set response = globalAdminClient.getAlertClient().listAlerts(ListAlertsOptions.Builder.id("20")); assert null != response; diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalCapacityClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalCapacityClientLiveTest.java index 590b5d35aa..3b72681e07 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalCapacityClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalCapacityClientLiveTest.java @@ -36,7 +36,7 @@ public class GlobalCapacityClientLiveTest extends BaseCloudStackClientLiveTest { @Test(groups = "live", enabled = true) public void testListCapacity() throws Exception { - assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials"); + skipIfNotGlobalAdmin(); final Set response = globalAdminClient.getCapacityClient().listCapacity(); assert null != response; diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalConfigurationClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalConfigurationClientLiveTest.java index eb46e3cfaa..64b578d8fa 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalConfigurationClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalConfigurationClientLiveTest.java @@ -45,7 +45,7 @@ public class GlobalConfigurationClientLiveTest extends BaseCloudStackClientLiveT @Test public void testListConfigurationEntries() { - assert globalAdminEnabled; + skipIfNotGlobalAdmin(); Set entries = globalAdminClient .getConfigurationClient().listConfigurationEntries(); @@ -62,7 +62,7 @@ public class GlobalConfigurationClientLiveTest extends BaseCloudStackClientLiveT @Test public void testUpdateConfigurationEntry() { - assert globalAdminEnabled; + skipIfNotGlobalAdmin(); Set entries = globalAdminClient .getConfigurationClient().listConfigurationEntries(); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainClientLiveTest.java index 7e7558a88e..ae848345c4 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainClientLiveTest.java @@ -55,7 +55,7 @@ public class GlobalDomainClientLiveTest extends BaseCloudStackClientLiveTest { @Test public void testCreateUpdateDeleteDomain() { - assert globalAdminEnabled; + skipIfNotDomainAdmin(); Domain domain = null; try { diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientLiveTest.java index 937dd80904..6db852473c 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientLiveTest.java @@ -40,7 +40,7 @@ public class GlobalHostClientLiveTest extends BaseCloudStackClientLiveTest { @Test(groups = "live", enabled = true) public void testListHosts() throws Exception { - assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials"); + skipIfNotGlobalAdmin(); Set hosts = globalAdminClient.getHostClient().listHosts(); assert hosts.size() > 0 : hosts; @@ -68,7 +68,7 @@ public class GlobalHostClientLiveTest extends BaseCloudStackClientLiveTest { @Test(groups = "live", enabled = true) public void testListClusters() throws Exception { - assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials"); + skipIfNotGlobalAdmin(); Set clusters = globalAdminClient.getHostClient().listClusters(); assert clusters.size() > 0 : clusters; diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingClientLiveTest.java index 76c6a25b42..f3eb1b5db2 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingClientLiveTest.java @@ -50,7 +50,7 @@ public class GlobalOfferingClientLiveTest extends BaseCloudStackClientLiveTest { @Test(groups = "live", enabled = true) public void testCreateServiceOffering() throws Exception { - assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials"); + skipIfNotGlobalAdmin(); String name = prefix + "-test-create-service-offering"; String displayText = name + "-display"; @@ -90,7 +90,7 @@ public class GlobalOfferingClientLiveTest extends BaseCloudStackClientLiveTest { @Test(groups = "live", enabled = true) public void testCreateDiskOffering() throws Exception { - assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials"); + skipIfNotGlobalAdmin(); String name = prefix + "-test-create-disk-offering"; String displayText = name + "-display"; @@ -127,7 +127,7 @@ public class GlobalOfferingClientLiveTest extends BaseCloudStackClientLiveTest { @Test(groups = "live", enabled = true) public void testUpdateNetworkOffering() throws Exception { - assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials"); + skipIfNotGlobalAdmin(); NetworkOffering offering = getFirst(globalAdminClient.getOfferingClient().listNetworkOfferings(), null); assertNotNull(offering, "Unable to test, no network offering found."); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalPodClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalPodClientLiveTest.java index 282db7bdad..9cf1cdf425 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalPodClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalPodClientLiveTest.java @@ -51,10 +51,13 @@ public class GlobalPodClientLiveTest extends BaseCloudStackClientLiveTest { private Pod pod; public void testListPods() throws Exception { + skipIfNotGlobalAdmin(); + Set response = globalAdminClient.getPodClient().listPods(); assert null != response; long podCount = response.size(); assertTrue(podCount >= 0); + for (Pod pod : response) { Pod newDetails = Iterables.getOnlyElement(globalAdminClient.getPodClient().listPods( ListPodsOptions.Builder.id(pod.getId()))); @@ -74,7 +77,7 @@ public class GlobalPodClientLiveTest extends BaseCloudStackClientLiveTest { @Test public void testCreatePod() { - assertTrue(globalAdminEnabled, "Global admin credentials must be given"); + skipIfNotGlobalAdmin(); zone = globalAdminClient.getZoneClient().createZone(prefix + "-zone", NetworkType.BASIC, "8.8.8.8", "10.10.10.10"); pod = globalAdminClient.getPodClient().createPod(prefix + "-pod", zone.getId(), "172.20.0.1", "172.20.0.250", "172.20.0.254", "255.255.255.0", diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolClientLiveTest.java index 35e1baf2b3..c1ba2c0185 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalStoragePoolClientLiveTest.java @@ -39,7 +39,7 @@ public class GlobalStoragePoolClientLiveTest extends BaseCloudStackClientLiveTes @Test(groups = "live", enabled = true) public void testListStoragePools() throws Exception { - assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials"); + skipIfNotGlobalAdmin(); Set result = globalAdminClient.getStoragePoolClient().listStoragePools(); assertNotNull(result); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUsageClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUsageClientLiveTest.java index 1557fa95f9..c28364628a 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUsageClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUsageClientLiveTest.java @@ -42,6 +42,8 @@ public class GlobalUsageClientLiveTest extends BaseCloudStackClientLiveTest { @Test(groups = "live", enabled = true) public void testListUsage() { + skipIfNotGlobalAdmin(); + Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); Date end = c.getTime(); c.add(Calendar.MONTH, -1); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUserClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUserClientLiveTest.java index 87f4aab4f1..988d0d18c9 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUserClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUserClientLiveTest.java @@ -50,7 +50,7 @@ public class GlobalUserClientLiveTest extends BaseCloudStackClientLiveTest { @Test public void testCreateUser() { - assert globalAdminEnabled; + skipIfNotGlobalAdmin(); Account testAccount = createTestAccount(globalAdminClient, prefix); User testUser = null; diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalVlanClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalVlanClientLiveTest.java index ee2a4ddc6e..bd221df998 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalVlanClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalVlanClientLiveTest.java @@ -57,10 +57,13 @@ public class GlobalVlanClientLiveTest extends BaseCloudStackClientLiveTest { private VlanIPRange range; public void testListVlanIPRanges() throws Exception { + skipIfNotGlobalAdmin(); + Set response = globalAdminClient.getVlanClient().listVlanIPRanges(); assert null != response; long rangeCount = response.size(); assertTrue(rangeCount >= 0); + for (VlanIPRange range : response) { VlanIPRange newDetails = Iterables.getOnlyElement(globalAdminClient.getVlanClient().listVlanIPRanges( ListVlanIPRangesOptions.Builder.id(range.getId()))); @@ -90,7 +93,7 @@ public class GlobalVlanClientLiveTest extends BaseCloudStackClientLiveTest { new Predicate() { @Override public boolean apply(Network network) { - return network.getNetworkOfferingId() == offering.getId(); + return network.getNetworkOfferingId().equals(offering.getId()); } }); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalZoneClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalZoneClientLiveTest.java index 9309bb3d14..c5a1438f82 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalZoneClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalZoneClientLiveTest.java @@ -38,7 +38,7 @@ public class GlobalZoneClientLiveTest extends BaseCloudStackClientLiveTest { @Test public void testCreateUpdateDeleteZone() { - assert globalAdminEnabled; + skipIfNotGlobalAdmin(); Zone zone = null; String zoneName = prefix + "-zone"; diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SessionClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SessionClientLiveTest.java index aa703839b8..0ffc155469 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SessionClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SessionClientLiveTest.java @@ -44,11 +44,12 @@ public class SessionClientLiveTest extends BaseCloudStackClientLiveTest { @Test public void testCreateContextUsingUserAndPasswordAuthentication() { - String endpoint = cloudStackContext.getProviderMetadata().getEndpoint(); - assert globalAdminEnabled; + skipIfNotGlobalAdmin(); + String endpoint = cloudStackContext.getProviderMetadata().getEndpoint(); Account testAccount = null; User testUser = null; + String prefix = this.prefix + "-session"; try { testAccount = createTestAccount(globalAdminClient, prefix); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SnapshotClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SnapshotClientLiveTest.java index 7bfde2e5a8..5a3d427a57 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SnapshotClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SnapshotClientLiveTest.java @@ -147,7 +147,7 @@ public class SnapshotClientLiveTest extends BaseCloudStackClientLiveTest { return find(client.getSnapshotClient().listSnapshots(), new Predicate() { @Override public boolean apply(Snapshot arg0) { - return arg0.getId() == id; + return arg0.getId().equals(id); } }); } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VolumeClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VolumeClientLiveTest.java index a6e9d42007..1e422618b3 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VolumeClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VolumeClientLiveTest.java @@ -246,7 +246,7 @@ public class VolumeClientLiveTest extends BaseCloudStackClientLiveTest { static Volume findVolumeWithId(final CloudStackClient client, final String id) { for (Volume v: client.getVolumeClient().listVolumes()) - if (v.getId()==id) return v; + if (v.getId().equals(id)) return v; throw new NoSuchElementException("no volume with id "+id); }