http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/compute/options/CloudStackTemplateOptionsTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/compute/options/CloudStackTemplateOptionsTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/compute/options/CloudStackTemplateOptionsTest.java new file mode 100644 index 0000000..6c29f83 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/compute/options/CloudStackTemplateOptionsTest.java @@ -0,0 +1,261 @@ +/* + * 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.cloudstack.compute.options; + +import com.google.common.collect.ImmutableSet; +import org.jclouds.compute.options.TemplateOptions; +import org.testng.annotations.Test; +import org.testng.collections.Maps; + +import java.util.Map; + +import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.account; +import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.dataDiskSize; +import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.diskOfferingId; +import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.domainId; +import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.generateKeyPair; +import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.generateSecurityGroup; +import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.ipOnDefaultNetwork; +import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.ipsToNetworks; +import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.keyPair; +import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.networks; +import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.securityGroupId; +import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.securityGroupIds; +import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.setupStaticNat; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + +/** + * Tests possible uses of {@code CloudStackTemplateOptions} and + * {@code CloudStackTemplateOptions.Builder.*}. + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "CloudStackTemplateOptionsTest") +public class CloudStackTemplateOptionsTest { + //TODO: test clone(); + + @Test + public void testAs() { + TemplateOptions options = new CloudStackTemplateOptions(); + assertEquals(options.as(CloudStackTemplateOptions.class), options); + } + + @Test + public void testDefaultSecurityGroupIds() { + TemplateOptions options = new CloudStackTemplateOptions(); + assertEquals(options.as(CloudStackTemplateOptions.class).getSecurityGroupIds(), ImmutableSet.of()); + } + + @Test + public void testSecurityGroupId() { + TemplateOptions options = new CloudStackTemplateOptions().securityGroupId("3"); + assertEquals(options.as(CloudStackTemplateOptions.class).getSecurityGroupIds(), ImmutableSet.of("3")); + } + + @Test + public void testSecurityGroupIdStatic() { + TemplateOptions options = securityGroupId("3"); + assertEquals(options.as(CloudStackTemplateOptions.class).getSecurityGroupIds(), ImmutableSet.of("3")); + } + + @Test + public void testSecurityGroupIds() { + TemplateOptions options = new CloudStackTemplateOptions().securityGroupIds(ImmutableSet.of("3")); + assertEquals(options.as(CloudStackTemplateOptions.class).getSecurityGroupIds(), ImmutableSet.of("3")); + } + + @Test + public void testSecurityGroupIdsStatic() { + TemplateOptions options = securityGroupIds(ImmutableSet.of("3")); + assertEquals(options.as(CloudStackTemplateOptions.class).getSecurityGroupIds(), ImmutableSet.of("3")); + } + + @Test + public void testGenerateSecurityGroupDefaultsFalse() { + TemplateOptions options = new CloudStackTemplateOptions(); + assertFalse(options.as(CloudStackTemplateOptions.class) + .shouldGenerateSecurityGroup()); + } + + @Test + public void testGenerateSecurityGroup() { + TemplateOptions options = new CloudStackTemplateOptions().generateSecurityGroup(true); + assertTrue(options.as(CloudStackTemplateOptions.class) + .shouldGenerateSecurityGroup()); + } + + @Test + public void testGenerateSecurityGroupStatic() { + TemplateOptions options = generateSecurityGroup(true); + assertTrue(options.as(CloudStackTemplateOptions.class) + .shouldGenerateSecurityGroup()); + } + + @Test + public void testDefaultNetworkIds() { + TemplateOptions options = new CloudStackTemplateOptions(); + assertEquals(options.as(CloudStackTemplateOptions.class).getNetworks(), ImmutableSet.of()); + } + + @Test + public void testNetworkId() { + TemplateOptions options = new CloudStackTemplateOptions().networks("3"); + assertEquals(options.as(CloudStackTemplateOptions.class).getNetworks(), ImmutableSet.of("3")); + } + + @Test + public void testNetworkIdStatic() { + TemplateOptions options = networks(ImmutableSet.of("3")); + assertEquals(options.as(CloudStackTemplateOptions.class).getNetworks(), ImmutableSet.of("3")); + } + + @Test + public void testNetworkIds() { + TemplateOptions options = new CloudStackTemplateOptions().networks(ImmutableSet.of("3")); + assertEquals(options.as(CloudStackTemplateOptions.class).getNetworks(), ImmutableSet.of("3")); + } + + @Test + public void testNetworkIdsStatic() { + TemplateOptions options = networks(ImmutableSet.of("3")); + assertEquals(options.as(CloudStackTemplateOptions.class).getNetworks(), ImmutableSet.of("3")); + } + + @Test + public void testIpOnDefaultNetwork() { + TemplateOptions options = new CloudStackTemplateOptions().ipOnDefaultNetwork("10.0.0.1"); + assertEquals(options.as(CloudStackTemplateOptions.class).getIpOnDefaultNetwork(), "10.0.0.1"); + } + + @Test + public void testIpOnDefaultNetworkStatic() { + TemplateOptions options = ipOnDefaultNetwork("10.0.0.1"); + assertEquals(options.as(CloudStackTemplateOptions.class).getIpOnDefaultNetwork(), "10.0.0.1"); + } + + @Test + public void testIpsToNetwork() { + Map<String, String> ipsToNetworks = Maps.newHashMap(); + ipsToNetworks.put("10.0.0.1", "5"); + + TemplateOptions options = new CloudStackTemplateOptions().ipsToNetworks(ipsToNetworks); + assertEquals(options.as(CloudStackTemplateOptions.class) + .getIpsToNetworks().get("10.0.0.1"), "5"); + } + + @Test + public void testIpsToNetworkStatic() { + Map<String, String> ipsToNetworks = Maps.newHashMap(); + ipsToNetworks.put("10.0.0.1", "5"); + + TemplateOptions options = ipsToNetworks(ipsToNetworks); + assertEquals(options.as(CloudStackTemplateOptions.class) + .getIpsToNetworks().get("10.0.0.1"), "5"); + } + + @Test + public void testSetupStaticNatDefaultsTrue() { + TemplateOptions options = new CloudStackTemplateOptions(); + assertTrue(options.as(CloudStackTemplateOptions.class) + .shouldSetupStaticNat()); + } + + @Test + public void testSetupStaticNat() { + TemplateOptions options = new CloudStackTemplateOptions().setupStaticNat(false); + assertFalse(options.as(CloudStackTemplateOptions.class) + .shouldSetupStaticNat()); + } + + @Test + public void testSetupStaticNatStatic() { + TemplateOptions options = setupStaticNat(false); + assertFalse(options.as(CloudStackTemplateOptions.class) + .shouldSetupStaticNat()); + } + + @Test + public void testGenerateKeyPairDefaultsFalse() { + TemplateOptions options = new CloudStackTemplateOptions(); + assertFalse(options.as(CloudStackTemplateOptions.class) + .shouldGenerateKeyPair()); + } + + @Test + public void testGenerateKeyPair() { + TemplateOptions options = new CloudStackTemplateOptions().generateKeyPair(true); + assertTrue(options.as(CloudStackTemplateOptions.class) + .shouldGenerateKeyPair()); + } + + @Test + public void testGenerateKeyPairStatic() { + TemplateOptions options = generateKeyPair(true); + assertTrue(options.as(CloudStackTemplateOptions.class) + .shouldGenerateKeyPair()); + } + + @Test + public void testKeyPair() { + TemplateOptions options = keyPair("test"); + assertEquals(options.as(CloudStackTemplateOptions.class).getKeyPair(), "test"); + } + + @Test + public void testDiskOfferingId() { + TemplateOptions options = diskOfferingId("test"); + assertEquals(options.as(CloudStackTemplateOptions.class).getDiskOfferingId(), "test"); + } + + @Test + public void testDataDiskSizeDefault() { + TemplateOptions options = new CloudStackTemplateOptions(); + assertEquals(options.as(CloudStackTemplateOptions.class).getDataDiskSize(), 0); + } + + @Test + public void testDataDiskSize() { + TemplateOptions options = dataDiskSize(10); + assertEquals(options.as(CloudStackTemplateOptions.class).getDataDiskSize(), 10); + } + + @Test + public void testAccount() { + TemplateOptions options = account("test"); + assertEquals(options.as(CloudStackTemplateOptions.class).getAccount(), "test"); + } + + @Test + public void testDomainId() { + TemplateOptions options = domainId("test"); + assertEquals(options.as(CloudStackTemplateOptions.class).getDomainId(), "test"); + } + + @Test + public void testSecurityGroupIdsNullHasDecentMessage() { + try { + new CloudStackTemplateOptions().securityGroupIds(null); + fail("should NPE"); + } catch (NullPointerException e) { + assertEquals(e.getMessage(), "securityGroupIds was null"); + } + } + +}
http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/compute/strategy/OptionsConverterTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/compute/strategy/OptionsConverterTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/compute/strategy/OptionsConverterTest.java new file mode 100644 index 0000000..d44ba77 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/compute/strategy/OptionsConverterTest.java @@ -0,0 +1,118 @@ +/* + * 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.cloudstack.compute.strategy; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions; +import org.jclouds.cloudstack.domain.Network; +import org.jclouds.cloudstack.domain.NetworkService; +import org.jclouds.cloudstack.options.DeployVirtualMachineOptions; +import org.testng.annotations.Test; + +import java.util.Map; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +@Test(singleThreaded = true, testName = "OptionsConverterTest") +public class OptionsConverterTest { + + private static final Map<String, Network> EMPTY_NETWORKS_MAP = ImmutableMap.<String, Network>of(); + private static final String ZONE_ID = "2"; + private final NetworkService firewallServiceWithStaticNat + = NetworkService.builder().name("Firewall").capabilities(ImmutableMap.of("StaticNat", "true")).build(); + + @Test + public void testBasicNetworkOptionsConverter() { + BasicNetworkOptionsConverter converter = new BasicNetworkOptionsConverter(); + + CloudStackTemplateOptions optionsIn = CloudStackTemplateOptions.Builder.securityGroupId("42").networks("46"); + DeployVirtualMachineOptions optionsOut = new DeployVirtualMachineOptions(); + + DeployVirtualMachineOptions optionsOut2 = converter.apply(optionsIn, EMPTY_NETWORKS_MAP, ZONE_ID, optionsOut); + assertEquals(optionsOut, optionsOut2); + + DeployVirtualMachineOptions optionsExpected = DeployVirtualMachineOptions.Builder.securityGroupId("42").networkId("46"); + assertEquals(optionsOut, optionsExpected); + } + + @Test + public void testAdvancedSecurityGroupsNotAllowed() { + boolean exceptionThrown = false; + AdvancedNetworkOptionsConverter converter = new AdvancedNetworkOptionsConverter(); + CloudStackTemplateOptions optionsIn = CloudStackTemplateOptions.Builder.securityGroupId("42"); + + try { + converter.apply(optionsIn, EMPTY_NETWORKS_MAP, ZONE_ID, DeployVirtualMachineOptions.NONE); + } catch (IllegalArgumentException e) { + exceptionThrown = true; + } + + assertTrue(exceptionThrown, "IllegalArgumentException should have been thrown"); + } + + @Test + public void testAdvancedExplicitNetworkSelection() { + AdvancedNetworkOptionsConverter converter = new AdvancedNetworkOptionsConverter(); + DeployVirtualMachineOptions optionsActual = converter.apply(CloudStackTemplateOptions.Builder.networks("42"), + EMPTY_NETWORKS_MAP, ZONE_ID, DeployVirtualMachineOptions.NONE); + DeployVirtualMachineOptions optionsExpected = DeployVirtualMachineOptions.Builder.networkId("42"); + assertEquals(optionsActual, optionsExpected); + } + + @Test + public void testAdvancedAutoDetectNetwork() { + AdvancedNetworkOptionsConverter converter = new AdvancedNetworkOptionsConverter(); + + Network eligibleNetwork = Network.builder() + .id("25").zoneId(ZONE_ID).isDefault(true).services(ImmutableSet.of(firewallServiceWithStaticNat)) + .build(); + DeployVirtualMachineOptions optionsActual = converter.apply(CloudStackTemplateOptions.NONE, + ImmutableMap.of(eligibleNetwork.getId(), eligibleNetwork), ZONE_ID, DeployVirtualMachineOptions.NONE); + DeployVirtualMachineOptions optionsExpected = DeployVirtualMachineOptions.Builder.networkId("25"); + assertEquals(optionsActual, optionsExpected); + } + + @Test + public void testAdvancedWhenNoNetworkGiven() { + AdvancedNetworkOptionsConverter converter = new AdvancedNetworkOptionsConverter(); + boolean exceptionThrown = false; + try { + converter.apply(CloudStackTemplateOptions.NONE, EMPTY_NETWORKS_MAP, ZONE_ID, DeployVirtualMachineOptions.NONE); + } catch (IllegalArgumentException e) { + exceptionThrown = true; + } + assertTrue(exceptionThrown); + } + + @Test + public void testAdvancedWhenNoNetworkEligible() { + AdvancedNetworkOptionsConverter converter = new AdvancedNetworkOptionsConverter(); + Network unsuitableNetwork = Network.builder() + .id("25").zoneId(ZONE_ID) + .build(); + + boolean exceptionThrown = false; + try { + converter.apply(CloudStackTemplateOptions.NONE, ImmutableMap.of(unsuitableNetwork.getId(), unsuitableNetwork), ZONE_ID, DeployVirtualMachineOptions.NONE); + } catch (IllegalArgumentException e) { + exceptionThrown = true; + } + assertTrue(exceptionThrown); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/domain/VirtualMachineTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/domain/VirtualMachineTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/domain/VirtualMachineTest.java new file mode 100644 index 0000000..8276b03 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/domain/VirtualMachineTest.java @@ -0,0 +1,52 @@ +/* + * 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.cloudstack.domain; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.fail; + +import org.testng.annotations.Test; + +/** + * Tests for the VirtualMachine class. + */ +@Test(groups = "unit", testName = "VirtualMachineTest") +public class VirtualMachineTest { + + @Test(groups = "unit", enabled = true) + public void testCpuUsed() { + // Class under test should detect if the % is missing off the end + try { + VirtualMachine.builder().id("1").cpuUsed("23.4").build(); + fail("Should have thrown an exception due to % being missing!"); + } catch (Exception e) { + } + + // If CpuUsed is not specified at all, that's OK + VirtualMachine vm = VirtualMachine.builder().id("2").build(); + assertEquals(vm.getCpuUsed(), 0.0f); + + // Retrieving CpuUsed should just give us a straightforward float + vm = VirtualMachine.builder().id("3").cpuUsed("23.4%").build(); + assertEquals(vm.getCpuUsed(), 23.4, 0.01); + + //Allow ',' as decimal separator + vm = VirtualMachine.builder().id("4").cpuUsed("23,4%").build(); + assertEquals(vm.getCpuUsed(), 23.4, 0.01); + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AccountApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AccountApiExpectTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AccountApiExpectTest.java new file mode 100644 index 0000000..385f221 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AccountApiExpectTest.java @@ -0,0 +1,105 @@ +/* + * 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.cloudstack.features; + +import static org.testng.Assert.assertEquals; + +import java.util.Set; + +import org.jclouds.cloudstack.CloudStackContext; +import org.jclouds.cloudstack.domain.Account; +import org.jclouds.cloudstack.domain.User; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Test the CloudStack AccountApi + */ +@Test(groups = "unit", testName = "AccountApiExpectTest") +public class AccountApiExpectTest extends BaseCloudStackExpectTest<AccountApi> { + + + public void testListAccountsWhenResponseIs2xx() { + + AccountApi client = requestSendsResponse( + HttpRequest.builder() + .method("GET") + .endpoint("http://localhost:8080/client/api?response=json&command=listAccounts&listAll=true&apiKey=identity&signature=yMZYMZxzFlaUsbfxtuppMwNhpXI%3D") + .addHeader("Accept", "application/json") + .build(), + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/listaccountsresponse.json")) + .build()); + + Set<User> users = ImmutableSet.of( + User.builder() + .id("505") + .name("jclouds") + .firstName("Adrian") + .lastName("Cole") + .email("[email protected]") + .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-04-19T01:57:24+0000")) + .state(User.State.ENABLED) + .account("jclouds") + .accountType(Account.Type.USER) + .domainId("457") + .domain("AA000062-jclouds-dev") + .apiKey("APIKEY") + .secretKey("SECRETKEY").build()); + + assertEquals(client.listAccounts(), + ImmutableSet.of(Account.builder() + .id("505") + .name("jclouds") + .type(Account.Type.USER) + .domainId("457") + .domain("AA000062-jclouds-dev") + .receivedBytes(318900216) + .sentBytes(23189677) + .VMLimit(15l) + .VMs(1) + .IPsAvailable(14l) + .IPLimit(15l) + .IPs(0) + .IPsAvailable(15l) + .volumeLimit(90l) + .volumes(2) + .volumesAvailable(88l) + .snapshotLimit(250l) + .snapshots(0) + .snapshotsAvailable(250l) + .templateLimit(15l) + .templates(0) + .templatesAvailable(15l) + .VMsAvailable(14l) + .VMsStopped(0) + .VMsRunning(1) + .state(Account.State.ENABLED) + .users(users).build())); + } + + @Override + protected AccountApi clientFrom(CloudStackContext context) { + return context.getApi().getAccountApi(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AccountApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AccountApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AccountApiLiveTest.java new file mode 100644 index 0000000..b394ce0 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AccountApiLiveTest.java @@ -0,0 +1,80 @@ +/* + * 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.cloudstack.features; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.cloudstack.domain.Account; +import org.jclouds.cloudstack.domain.User; +import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code AccountApi} + */ +@Test(groups = "live", singleThreaded = true, testName = "AccountApiLiveTest") +public class AccountApiLiveTest extends BaseCloudStackApiLiveTest { + + @Test + public void testListAccounts() throws Exception { + for (Account securityAccount : client.getAccountApi().listAccounts()) + checkAccount(securityAccount); + } + + protected void checkAccount(Account account) { + assert account.getId() != null : account; + assertEquals(account.toString(), client.getAccountApi().getAccount(account.getId()).toString()); + assert account.getName() != null : account; + assert account.getType() != null && account.getType() != Account.Type.UNRECOGNIZED : account; + assert account.getDomain() != null : account; + assert account.getDomainId() != null : account; + assert account.getUsers() != null : account; + for (User user : account.getUsers()) { + assert user.getName() != null : user; + assert user.getAccountType().equals(account.getType()) : user; + assert user.getDomain().equals(account.getDomain()) : user; + assert user.getDomainId().equals(account.getDomainId()) : user; + assert user.getCreated() != null : user; + assert user.getEmail() != null : user; + assert user.getLastName() != null : user; + assert user.getFirstName() != null : user; + assert user.getId() != null : user; + assert user.getState() != null : user; + } + assert account.getIPsAvailable() == null || account.getIPsAvailable() >= 0 : account; + assert account.getIPLimit() == null || account.getIPLimit() >= 0 : account; + assert account.getIPs() >= 0 : account; + assert account.getReceivedBytes() >= 0 : account; + assert account.getSentBytes() >= 0 : account; + assert account.getSnapshotsAvailable() == null || account.getSnapshotsAvailable() >= 0 : account; + assert account.getSnapshotLimit() == null || account.getSnapshotLimit() >= 0 : account; + assert account.getSnapshots() >= 0 : account; + assert account.getState() != null && account.getState() != Account.State.UNRECOGNIZED : account; + assert account.getTemplatesAvailable() == null || account.getTemplatesAvailable() >= 0 : account; + assert account.getTemplateLimit() == null || account.getTemplateLimit() >= 0 : account; + assert account.getTemplates() >= 0 : account; + assert account.getVMsAvailable() == null || account.getVMsAvailable() >= 0 : account; + assert account.getVMLimit() == null || account.getVMLimit() >= 0 : account; + assert account.getVMsRunning() >= 0 : account; + assert account.getVMsStopped() >= 0 : account; + assert account.getVMs() >= 0 : account; + assert account.getVolumesAvailable() == null || account.getVolumesAvailable() >= 0 : account; + assert account.getVolumeLimit() == null || account.getVolumeLimit() >= 0 : account; + assert account.getVolumes() >= 0 : account; + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AccountApiTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AccountApiTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AccountApiTest.java new file mode 100644 index 0000000..ffaec22 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AccountApiTest.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.cloudstack.features; +import static org.jclouds.reflect.Reflection2.method; + +import java.io.IOException; + +import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404; +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.cloudstack.internal.BaseCloudStackApiTest; +import org.jclouds.cloudstack.options.ListAccountsOptions; +import org.jclouds.functions.IdentityFunction; +import org.jclouds.http.functions.ParseFirstJsonValueNamed; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.testng.annotations.Test; + +import com.google.common.base.Functions; +import com.google.common.collect.ImmutableList; +import com.google.common.reflect.Invokable; + +/** + * Tests behavior of {@code AccountApi} + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "AccountApiTest") +public class AccountApiTest extends BaseCloudStackApiTest<AccountApi> { + + public void testListAccounts() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(AccountApi.class, "listAccounts", ListAccountsOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listAccounts&listAll=true HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testListAccountsOptions() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(AccountApi.class, "listAccounts", ListAccountsOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of( + ListAccountsOptions.Builder.accountInDomain("jclouds", "123"))); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listAccounts&listAll=true&account=jclouds&domainid=123 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testGetAccount() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(AccountApi.class, "getAccount", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("3")); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listAccounts&listAll=true&id=3 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, + Functions.compose(IdentityFunction.INSTANCE, IdentityFunction.INSTANCE).getClass()); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AddressApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AddressApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AddressApiLiveTest.java new file mode 100644 index 0000000..dc685a6 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AddressApiLiveTest.java @@ -0,0 +1,94 @@ +/* + * 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.cloudstack.features; + +import static com.google.common.base.Preconditions.checkState; +import static com.google.common.collect.Iterables.getOnlyElement; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.AsyncCreateResponse; +import org.jclouds.cloudstack.domain.PublicIPAddress; +import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest; +import org.jclouds.cloudstack.options.ListPublicIPAddressesOptions; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +/** + * Tests behavior of {@code AddressApi} + */ +@Test(groups = "live", singleThreaded = true, testName = "AddressApiLiveTest") +public class AddressApiLiveTest extends BaseCloudStackApiLiveTest { + private boolean networksEnabled; + + @BeforeGroups(groups = "live") + void networksEnabled() { + networksEnabled = !client.getNetworkApi().listNetworks().isEmpty(); + } + + private PublicIPAddress ip = null; + + public void testAssociateDisassociatePublicIPAddress() throws Exception { + if (!networksEnabled) + return; + AsyncCreateResponse job = client.getAddressApi().associateIPAddressInZone( + Iterables.get(client.getNetworkApi().listNetworks(), 0).getZoneId()); + checkState(jobComplete.apply(job.getJobId()), "job %s failed to complete", job.getJobId()); + ip = client.getAsyncJobApi().<PublicIPAddress> getAsyncJob(job.getJobId()).getResult(); + checkIP(ip); + } + + @AfterGroups(groups = "live") + @Override + protected void tearDownContext() { + if (ip != null) { + client.getAddressApi().disassociateIPAddress(ip.getId()); + } + super.tearDownContext(); + } + + public void testListPublicIPAddresss() throws Exception { + if (!networksEnabled) + return; + Set<PublicIPAddress> response = client.getAddressApi().listPublicIPAddresses(); + assert null != response; + assertTrue(response.size() >= 0); + for (PublicIPAddress ip : response) { + PublicIPAddress newDetails = getOnlyElement(client.getAddressApi().listPublicIPAddresses( + ListPublicIPAddressesOptions.Builder.id(ip.getId()))); + assertEquals(ip.getId(), newDetails.getId()); + checkIP(ip); + } + } + + protected void checkIP(PublicIPAddress ip) { + assertEquals(ip.getId(), client.getAddressApi().getPublicIPAddress(ip.getId()).getId()); + assert ip.getId() != null : ip; + assert ip.getAccount() != null : ip; + assert ip.getDomain() != null : ip; + assert ip.getDomainId() != null : ip; + assert ip.getState() != null : ip; + assert ip.getZoneId() != null : ip; + assert ip.getZoneName() != null : ip; + + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AddressApiTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AddressApiTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AddressApiTest.java new file mode 100644 index 0000000..fdff2cb --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AddressApiTest.java @@ -0,0 +1,135 @@ +/* + * 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.cloudstack.features; + +import static org.jclouds.reflect.Reflection2.method; + +import java.io.IOException; + +import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404; +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.cloudstack.functions.CloudStackFallbacks.VoidOnNotFoundOr404OrUnableToFindAccountOwner; +import org.jclouds.cloudstack.internal.BaseCloudStackApiTest; +import org.jclouds.cloudstack.options.AssociateIPAddressOptions; +import org.jclouds.cloudstack.options.ListPublicIPAddressesOptions; +import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions; +import org.jclouds.functions.IdentityFunction; +import org.jclouds.http.functions.ParseFirstJsonValueNamed; +import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.http.functions.UnwrapOnlyJsonValue; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.testng.annotations.Test; + +import com.google.common.base.Functions; +import com.google.common.collect.ImmutableList; +import com.google.common.reflect.Invokable; +/** + * Tests behavior of {@code AddressApi} + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "AddressApiTest") +public class AddressApiTest extends BaseCloudStackApiTest<AddressApi> { + public void testListPublicIPAddresses() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(AddressApi.class, "listPublicIPAddresses", ListPublicIPAddressesOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listPublicIpAddresses&listAll=true HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testListPublicIPAddressesOptions() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(AddressApi.class, "listPublicIPAddresses", ListPublicIPAddressesOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of( + ListPublicIPAddressesOptions.Builder.accountInDomain("adrian", "6").usesVirtualNetwork(true))); + + assertRequestLineEquals( + httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listPublicIpAddresses&listAll=true&account=adrian&domainid=6&forvirtualnetwork=true HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testGetPublicIPAddress() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(AddressApi.class, "getPublicIPAddress", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(5)); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listPublicIpAddresses&listAll=true&id=5 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, + Functions.compose(IdentityFunction.INSTANCE, IdentityFunction.INSTANCE).getClass()); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testAssociateIPAddressInZone() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(AddressApi.class, "associateIPAddressInZone", String.class, + AssociateIPAddressOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(6)); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=associateIpAddress&zoneid=6 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } + + public void testDisassociateIPAddress() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(AddressApi.class, "disassociateIPAddress", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(5)); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=disassociateIpAddress&id=5 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, VoidOnNotFoundOr404OrUnableToFindAccountOwner.class); + + checkFilters(httpRequest); + + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AsyncJobApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AsyncJobApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AsyncJobApiLiveTest.java new file mode 100644 index 0000000..5cb6011 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AsyncJobApiLiveTest.java @@ -0,0 +1,72 @@ +/* + * 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.cloudstack.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.AsyncJob; +import org.jclouds.cloudstack.domain.AsyncJob.ResultCode; +import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code AsyncJobApiLiveTest} + */ +@Test(groups = "live", singleThreaded = true, testName = "AsyncJobApiLiveTest") +public class AsyncJobApiLiveTest extends BaseCloudStackApiLiveTest { + + @Test(enabled = true) + public void testListAsyncJobs() throws Exception { + Set<AsyncJob<?>> response = client.getAsyncJobApi().listAsyncJobs(); + assert null != response; + + long asyncJobCount = response.size(); + assertTrue(asyncJobCount >= 0); + + for (AsyncJob<?> asyncJob : response) { + assert asyncJob.getCmd() != null : asyncJob; + assert asyncJob.getUserId() != null : asyncJob; + checkJob(asyncJob); + + AsyncJob<?> query = client.getAsyncJobApi().getAsyncJob(asyncJob.getId()); + assertEquals(query.getId(), asyncJob.getId()); + + assert query.getResultType() != null : query; + checkJob(query); + } + } + + private void checkJob(AsyncJob<?> query) { + assert query.getStatus().code() >= 0 : query; + assert query.getResultCode().code() >= 0 : query; + assert query.getProgress() >= 0 : query; + if (query.getResultCode() == ResultCode.SUCCESS) { + if (query.getResult() != null) { + assertEquals(query.getResult().getClass().getPackage(), AsyncJob.class.getPackage()); + } + } else if (query.getResultCode() == ResultCode.FAIL) { + assert query.getResult() == null : query; + assert query.getError() != null : query; + } else { + assert query.getResult() == null : query; + } + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AsyncJobApiTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AsyncJobApiTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AsyncJobApiTest.java new file mode 100644 index 0000000..a61d4e0 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/AsyncJobApiTest.java @@ -0,0 +1,94 @@ +/* + * 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.cloudstack.features; + +import static org.jclouds.reflect.Reflection2.method; + +import java.io.IOException; + +import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404; +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.cloudstack.functions.ParseAsyncJobFromHttpResponse; +import org.jclouds.cloudstack.functions.ParseAsyncJobsFromHttpResponse; +import org.jclouds.cloudstack.internal.BaseCloudStackApiTest; +import org.jclouds.cloudstack.options.ListAsyncJobsOptions; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.reflect.Invokable; + +/** + * Tests behavior of {@code AsyncJobApi} + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "AsyncJobApiTest") +public class AsyncJobApiTest extends BaseCloudStackApiTest<AsyncJobApi> { + + public void testGetAsyncJob() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(AsyncJobApi.class, "getAsyncJob", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(11l)); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=queryAsyncJobResult&jobid=11 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseAsyncJobFromHttpResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testListAsyncJobs() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(AsyncJobApi.class, "listAsyncJobs", ListAsyncJobsOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listAsyncJobs&listAll=true HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseAsyncJobsFromHttpResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testListAsyncJobsOptions() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(AsyncJobApi.class, "listAsyncJobs", ListAsyncJobsOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of( + ListAsyncJobsOptions.Builder.accountInDomain("adrian", "5"))); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listAsyncJobs&listAll=true&account=adrian&domainid=5 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseAsyncJobsFromHttpResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ConfigurationApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ConfigurationApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ConfigurationApiLiveTest.java new file mode 100644 index 0000000..b072571 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ConfigurationApiLiveTest.java @@ -0,0 +1,35 @@ +/* + * 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.cloudstack.features; + +import org.jclouds.cloudstack.domain.Capabilities; +import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code ConfigurationApiLiveTest} + */ +@Test(groups = "live", singleThreaded = true, testName = "ConfigurationApiLiveTest") +public class ConfigurationApiLiveTest extends BaseCloudStackApiLiveTest { + + public void testListCapabilities() throws Exception { + Capabilities response = client.getConfigurationApi().listCapabilities(); + assert null != response; + assert null != response.getCloudStackVersion(); + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ConfigurationApiTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ConfigurationApiTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ConfigurationApiTest.java new file mode 100644 index 0000000..0d169b2 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ConfigurationApiTest.java @@ -0,0 +1,55 @@ +/* + * 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.cloudstack.features; + +import static org.jclouds.reflect.Reflection2.method; + +import java.io.IOException; + +import org.jclouds.cloudstack.internal.BaseCloudStackApiTest; +import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions; +import org.jclouds.http.functions.ParseFirstJsonValueNamed; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.reflect.Invokable; +/** + * Tests behavior of {@code ConfigurationApi} + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "ConfigurationApiTest") +public class ConfigurationApiTest extends BaseCloudStackApiTest<ConfigurationApi> { + + public void testListCapabilities() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(ConfigurationApi.class, "listCapabilities"); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&listAll=true&command=listCapabilities HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainAccountApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainAccountApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainAccountApiLiveTest.java new file mode 100644 index 0000000..7f2cee0 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainAccountApiLiveTest.java @@ -0,0 +1,64 @@ +/* + * 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.cloudstack.features; + +import static org.jclouds.cloudstack.features.GlobalAccountApiLiveTest.createTestAccount; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.cloudstack.domain.Account; +import org.jclouds.cloudstack.domain.AsyncCreateResponse; +import org.jclouds.cloudstack.domain.AsyncJob; +import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code DomainAccountApi} + */ +@Test(groups = "live", singleThreaded = true, testName = "DomainAccountApiLiveTest") +public class DomainAccountApiLiveTest extends BaseCloudStackApiLiveTest { + + @Test + public void testEnableDisableAccount() { + skipIfNotGlobalAdmin(); + + Account testAccount = null; + try { + testAccount = createTestAccount(globalAdminClient, prefix); + + AsyncCreateResponse response = domainAdminClient.getAccountApi() + .disableAccount(testAccount.getName(), testAccount.getDomainId(), false); + assertNotNull(response); + assertTrue(adminJobComplete.apply(response.getJobId())); + + AsyncJob<Account> job = domainAdminClient.getAsyncJobApi().getAsyncJob(response.getJobId()); + assertEquals(job.getResult().getState(), Account.State.DISABLED); + + Account updated = domainAdminClient.getAccountApi() + .enableAccount(testAccount.getName(), testAccount.getDomainId()); + assertNotNull(updated); + assertEquals(updated.getState(), Account.State.ENABLED); + + } finally { + if (testAccount != null) { + globalAdminClient.getAccountApi().deleteAccount(testAccount.getId()); + } + } + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainAccountApiTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainAccountApiTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainAccountApiTest.java new file mode 100644 index 0000000..afab941 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainAccountApiTest.java @@ -0,0 +1,67 @@ +/* + * 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.cloudstack.features; + +import static org.jclouds.reflect.Reflection2.method; + +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.cloudstack.internal.BaseCloudStackApiTest; +import org.jclouds.http.functions.ParseFirstJsonValueNamed; +import org.jclouds.http.functions.UnwrapOnlyJsonValue; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.reflect.Invokable; +/** + * Tests behavior of {@code DomainAccountApi} + */ +@Test(groups = "unit", testName = "DomainAccountApiTest") +public class DomainAccountApiTest extends BaseCloudStackApiTest<DomainAccountApi> { + + public void testEnableAccount() throws Exception { + Invokable<?, ?> method = method(DomainAccountApi.class, "enableAccount", String.class, String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("goo", "2")); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=enableAccount&account=goo&domainid=2 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(httpRequest); + } + + public void testDisableAccount() throws Exception { + Invokable<?, ?> method = method(DomainAccountApi.class, "disableAccount", String.class, String.class, boolean.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("1", "2", true)); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=disableAccount&account=1&domainid=2&lock=true HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(httpRequest); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainDomainApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainDomainApiExpectTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainDomainApiExpectTest.java new file mode 100644 index 0000000..23d6824 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainDomainApiExpectTest.java @@ -0,0 +1,156 @@ +/* + * 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.cloudstack.features; + +import static org.jclouds.cloudstack.options.ListDomainChildrenOptions.Builder.parentDomainId; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import java.net.URI; + +import org.jclouds.cloudstack.CloudStackContext; +import org.jclouds.cloudstack.domain.Domain; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Test the CloudStack DomainDomainApi + */ +@Test(groups = "unit", testName = "DomainDomainApiExpectTest") +public class DomainDomainApiExpectTest extends BaseCloudStackExpectTest<DomainDomainApi> { + + public void testListDomainsWhenResponseIs2xx() { + DomainDomainApi client = requestSendsResponse( + HttpRequest.builder() + .method("GET") + .endpoint( + URI.create("http://localhost:8080/client/api?response=json&" + + "command=listDomains&listAll=true&apiKey=identity&signature=sVFaGTu0DNSTVtWy3wtRt7KTx0w%3D")) + .addHeader("Accept", "application/json") + .build(), + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/listdomainsresponse.json")) + .build()); + + assertEquals(client.listDomains(), + ImmutableSet.of( + Domain.builder().id("1").name("ROOT").level(0).hasChild(true).build(), + Domain.builder().id("2").name("jclouds1").level(1).parentDomainId("1") + .parentDomainName("ROOT").hasChild(false).build() + )); + } + + public void testListDomainsWhenResponseIs404() { + DomainDomainApi client = requestSendsResponse( + HttpRequest.builder() + .method("GET") + .endpoint( + URI.create("http://localhost:8080/client/api?response=json&" + + "command=listDomains&listAll=true&apiKey=identity&signature=sVFaGTu0DNSTVtWy3wtRt7KTx0w%3D")) + .addHeader("Accept", "application/json") + .build(), + HttpResponse.builder() + .statusCode(404) + .build()); + + assertEquals(client.listDomains(), ImmutableSet.of()); + } + + public void testGetDomainWhenResponseIs2xx() { + DomainDomainApi client = requestSendsResponse( + HttpRequest.builder() + .method("GET") + .endpoint( + URI.create("http://localhost:8080/client/api?response=json&" + + "command=listDomains&listAll=true&id=1&apiKey=identity&signature=M16YxHWKST/cIRUHvWhfWovJugU%3D")) + .addHeader("Accept", "application/json") + .build(), + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/getdomainresponse.json")) + .build()); + + assertEquals(client.getDomainById("1"), + Domain.builder().id("1").name("ROOT").level(0).hasChild(true).build()); + } + + public void testGetDomainWhenResponseIs404() { + DomainDomainApi client = requestSendsResponse( + HttpRequest.builder() + .method("GET") + .endpoint( + URI.create("http://localhost:8080/client/api?response=json&" + + "command=listDomains&listAll=true&id=1&apiKey=identity&signature=M16YxHWKST/cIRUHvWhfWovJugU%3D")) + .addHeader("Accept", "application/json") + .build(), + HttpResponse.builder() + .statusCode(404) + .build()); + + assertNull(client.getDomainById("1")); + } + + public void testListDomainChildrenWhenResponseIs2xx() { + DomainDomainApi client = requestSendsResponse( + HttpRequest.builder() + .method("GET") + .endpoint( + URI.create("http://localhost:8080/client/api?response=json&" + + "command=listDomainChildren&listAll=true&id=1&isrecursive=true&apiKey=identity&signature=Jn6kFkloRvfaaivlJiHd0F5J3Jk%3D")) + .addHeader("Accept", "application/json") + .build(), + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/listdomainchildrenresponse.json")) + .build()); + + assertEquals(client.listDomainChildren(parentDomainId("1").isRecursive(true)), + ImmutableSet.of( + Domain.builder().id("2").name("jclouds1").level(1).parentDomainId("1") + .parentDomainName("ROOT").hasChild(false).build(), + Domain.builder().id("3").name("jclouds2").level(1).parentDomainId("1") + .parentDomainName("ROOT").hasChild(false).build() + )); + } + + public void testListDomainChildrenWhenResponseIs404() { + DomainDomainApi client = requestSendsResponse( + HttpRequest.builder() + .method("GET") + .endpoint( + URI.create("http://localhost:8080/client/api?response=json&" + + "command=listDomainChildren&listAll=true&id=1&isrecursive=true&apiKey=identity&" + + "signature=Jn6kFkloRvfaaivlJiHd0F5J3Jk%3D")) + .addHeader("Accept", "application/json") + .build(), + HttpResponse.builder() + .statusCode(404) + .build()); + + assertEquals(client.listDomainChildren(parentDomainId("1").isRecursive(true)), ImmutableSet.of()); + } + + @Override + protected DomainDomainApi clientFrom(CloudStackContext context) { + return context.getDomainApi().getDomainClient(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainDomainApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainDomainApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainDomainApiLiveTest.java new file mode 100644 index 0000000..aa9ed44 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainDomainApiLiveTest.java @@ -0,0 +1,97 @@ +/* + * 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.cloudstack.features; + +import static com.google.common.collect.Sets.newHashSet; +import static org.jclouds.cloudstack.options.ListDomainChildrenOptions.Builder.parentDomainId; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.util.NoSuchElementException; +import java.util.Set; + +import org.jclouds.cloudstack.domain.Domain; +import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest; +import org.testng.annotations.Test; + +import com.google.common.base.Function; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; + +/** + * Tests behavior of {@code DomainDomainApi} + */ +@Test(groups = "live", singleThreaded = true, testName = "DomainDomainApiLiveTest") +public class DomainDomainApiLiveTest extends BaseCloudStackApiLiveTest { + + @Test + public void testListDomains() { + skipIfNotDomainAdmin(); + + Set<Domain> domains = domainAdminClient.getDomainClient().listDomains(); + for (Domain candidate : domains) { + checkDomain(candidate); + } + } + + private void checkDomain(Domain domain) { + assertNotNull(domain.getId()); + if (domain.getLevel() == 0 /* global ROOT */) { + assertNull(domain.getParentDomainName()); + assertNull(domain.getParentDomainId()); + } else { + assertNotNull(domain.getParentDomainName()); + assertNotNull(domain.getParentDomainId()); + } + } + + @Test + public void testListDomainChildren() { + skipIfNotDomainAdmin(); + + Set<Domain> domains = domainAdminClient.getDomainClient().listDomains(); + Domain root = findRootOfVisibleTree(domains); + if (domains.size() > 1) { + assertTrue(root.hasChild()); + } + + Set<Domain> children = domainAdminClient.getDomainClient() + .listDomainChildren(parentDomainId(root.getId()).isRecursive(true)); + assertEquals(domains.size() - 1, children.size()); + assertTrue(Sets.difference(domains, children).contains(root)); + } + + private Domain findRootOfVisibleTree(Set<Domain> domains) { + final Set<String> names = newHashSet(Iterables.transform(domains, + new Function<Domain, String>() { + @Override + public String apply(Domain domain) { + return domain.getName(); + } + })); + + for (Domain candidate : domains) { + if (candidate.getParentDomainId() == null || + !names.contains(candidate.getParentDomainName())) { + return candidate; + } + } + throw new NoSuchElementException("No root node found in this tree"); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainLimitApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainLimitApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainLimitApiLiveTest.java new file mode 100644 index 0000000..e616a88 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainLimitApiLiveTest.java @@ -0,0 +1,28 @@ +/* + * 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.cloudstack.features; + +import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code DomainLimitApi} + */ +@Test(groups = "live", singleThreaded = true, testName = "DomainLimitApiLiveTest") +public class DomainLimitApiLiveTest extends BaseCloudStackApiLiveTest { + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainLimitApiTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainLimitApiTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainLimitApiTest.java new file mode 100644 index 0000000..26cba6f --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainLimitApiTest.java @@ -0,0 +1,57 @@ +/* + * 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.cloudstack.features; + +import static org.jclouds.reflect.Reflection2.method; + +import java.io.IOException; + +import org.jclouds.cloudstack.domain.ResourceLimit; +import org.jclouds.cloudstack.domain.ResourceLimit.ResourceType; +import org.jclouds.cloudstack.internal.BaseCloudStackApiTest; +import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions; +import org.jclouds.http.functions.ParseFirstJsonValueNamed; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.reflect.Invokable; +/** + * Tests behavior of {@code DomainLimitApi} + */ +@Test(groups = "unit", testName = "DomainLimitApiTest") +public class DomainLimitApiTest extends BaseCloudStackApiTest<DomainLimitApi> { + + public void testUpdateResourceLimit() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(DomainLimitApi.class, "updateResourceLimit", ResourceLimit.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of( + ResourceLimit.builder().resourceType(ResourceType.SNAPSHOT).account("foo").domainId("100").max(101).build())); + + assertRequestLineEquals( + httpRequest, + "GET http://localhost:8080/client/api?response=json&command=updateResourceLimit&resourcetype=3&account=foo&domainid=100&max=101 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/86fd5cf2/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainUserApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainUserApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainUserApiLiveTest.java new file mode 100644 index 0000000..2deb76c --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/DomainUserApiLiveTest.java @@ -0,0 +1,91 @@ +/* + * 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.cloudstack.features; + +import static org.jclouds.cloudstack.features.GlobalAccountApiLiveTest.createTestAccount; +import static org.jclouds.cloudstack.features.GlobalUserApiLiveTest.createTestUser; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.Account; +import org.jclouds.cloudstack.domain.AsyncCreateResponse; +import org.jclouds.cloudstack.domain.AsyncJob; +import org.jclouds.cloudstack.domain.User; +import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code DomainUserApi} + */ +@Test(groups = "live", singleThreaded = true, testName = "DomainUserApiLiveTest") +public class DomainUserApiLiveTest extends BaseCloudStackApiLiveTest { + + @Test + public void testListUsers() { + skipIfNotDomainAdmin(); + + Set<User> users = domainAdminClient.getUserClient().listUsers(); + + assert !users.isEmpty(); + assert users.contains(user); // contains the current user + + for (User user : users) { + checkUser(user); + } + } + + private void checkUser(User user) { + assert user.getId() != null; + assert user.getAccount() != null; + assert user.getDomain() != null; + } + + @Test + public void testEnableDisableUser() { + skipIfNotGlobalAdmin(); + + Account testAccount = null; + User testUser = null; + try { + testAccount = createTestAccount(globalAdminClient, prefix); + testUser = createTestUser(globalAdminClient, testAccount, prefix); + + AsyncCreateResponse response = domainAdminClient.getUserClient().disableUser(testUser.getId()); + assertNotNull(response); + assertTrue(adminJobComplete.apply(response.getJobId())); + + AsyncJob<User> job = domainAdminClient.getAsyncJobApi().getAsyncJob(response.getJobId()); + assertNotNull(job); + assertEquals(job.getResult().getState(), User.State.DISABLED); + + User updated = domainAdminClient.getUserClient().enableUser(testUser.getId()); + assertNotNull(updated); + assertEquals(updated.getState(), User.State.ENABLED); + + } finally { + if (testUser != null) { + globalAdminClient.getUserClient().deleteUser(testUser.getId()); + } + if (testAccount != null) { + globalAdminClient.getAccountApi().deleteAccount(testAccount.getId()); + } + } + } +}
