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/parse/ListPodsResponseTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListPodsResponseTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListPodsResponseTest.java new file mode 100644 index 0000000..5f8944f --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListPodsResponseTest.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.parse; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.AllocationState; +import org.jclouds.cloudstack.domain.Pod; +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ListPodsResponseTest extends BaseSetParserTest<Pod> { + + @Override + public String resource() { + return "/listpodsresponse.json"; + } + + @Override + @SelectJson("pod") + public Set<Pod> expected() { + Pod pod1 = Pod.builder() + .id("1") + .name("Dev Pod 1") + .zoneId("1") + .zoneName("Dev Zone 1") + .gateway("10.26.26.254") + .netmask("255.255.255.0") + .startIp("10.26.26.50") + .endIp("10.26.26.100") + .allocationState(AllocationState.ENABLED) + .build(); + Pod pod2 = Pod.builder() + .id("2") + .name("Dev Pod 2") + .zoneId("2") + .zoneName("Dev Zone 2") + .gateway("10.22.22.254") + .netmask("255.255.255.0") + .startIp("10.22.22.25") + .endIp("10.22.22.50") + .allocationState(AllocationState.ENABLED) + .build(); + return ImmutableSet.of(pod1, pod2); + } +}
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/parse/ListPortForwardingRulesResponseTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListPortForwardingRulesResponseTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListPortForwardingRulesResponseTest.java new file mode 100644 index 0000000..6356c7d --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListPortForwardingRulesResponseTest.java @@ -0,0 +1,65 @@ +/* + * 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.parse; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.PortForwardingRule; +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; + +@Test(groups = "unit") +public class ListPortForwardingRulesResponseTest extends BaseSetParserTest<PortForwardingRule> { + + @Override + protected Injector injector() { + return Guice.createInjector(new GsonModule() { + + @Override + protected void configure() { + bind(DateAdapter.class).to(Iso8601DateAdapter.class); + super.configure(); + } + + }); + } + + @Override + public String resource() { + return "/listportforwardingrulesresponse.json"; + } + + @Override + @SelectJson("portforwardingrule") + public Set<PortForwardingRule> expected() { + Set<String> cidrs = ImmutableSet.of("0.0.0.0/1", "128.0.0.0/1"); + return ImmutableSet.<PortForwardingRule> of( + PortForwardingRule.builder().id("15").privatePort(22).protocol(PortForwardingRule.Protocol.TCP) + .publicPort(2022).virtualMachineId("3").virtualMachineName("i-3-3-VM").IPAddressId("3") + .IPAddress("72.52.126.32").state(PortForwardingRule.State.ACTIVE).CIDRs(cidrs).build(), + PortForwardingRule.builder().id("18").privatePort(22).protocol(PortForwardingRule.Protocol.TCP) + .publicPort(22).virtualMachineId("89").virtualMachineName("i-3-89-VM").IPAddressId("34") + .IPAddress("72.52.126.63").state(PortForwardingRule.State.ACTIVE).build()); + } + +} 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/parse/ListPublicIPAddressesResponseTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListPublicIPAddressesResponseTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListPublicIPAddressesResponseTest.java new file mode 100644 index 0000000..a9547d4 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListPublicIPAddressesResponseTest.java @@ -0,0 +1,47 @@ +/* + * 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.parse; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.PublicIPAddress; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ListPublicIPAddressesResponseTest extends BaseSetParserTest<PublicIPAddress> { + + @Override + public String resource() { + return "/listpublicipaddressesresponse.json"; + } + + @Override + @SelectJson("publicipaddress") + public Set<PublicIPAddress> expected() { + return ImmutableSet.of(PublicIPAddress.builder().id("30").IPAddress("72.52.126.59") + .allocated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-02-19T21:15:01-0800")).zoneId("1") + .zoneName("San Jose 1").isSourceNAT(false).account("adrian").domainId("1").domain("ROOT") + .usesVirtualNetwork(true).isStaticNAT(false).associatedNetworkId("204").networkId("200") + .state(PublicIPAddress.State.ALLOCATED).build()); + } + +} 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/parse/ListSSHKeyPairsResponseTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListSSHKeyPairsResponseTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListSSHKeyPairsResponseTest.java new file mode 100644 index 0000000..c509a34 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListSSHKeyPairsResponseTest.java @@ -0,0 +1,60 @@ +/* + * 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.parse; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.SshKeyPair; +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; + +@Test(groups = "unit") +public class ListSSHKeyPairsResponseTest extends BaseSetParserTest<SshKeyPair> { + + @Override + protected Injector injector() { + return Guice.createInjector(new GsonModule() { + + @Override + protected void configure() { + bind(DateAdapter.class).to(Iso8601DateAdapter.class); + super.configure(); + } + + }); + + } + + @Override + public String resource() { + return "/listsshkeypairsresponse.json"; + } + + @Override + @SelectJson("sshkeypair") + public Set<SshKeyPair> expected() { + return ImmutableSet.<SshKeyPair> of(SshKeyPair.builder().name("jclouds-keypair") + .fingerprint("1c:06:74:52:3b:99:1c:95:5c:04:c2:f4:ba:77:6e:7b").build()); + } + +} 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/parse/ListSecurityGroupsResponseTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListSecurityGroupsResponseTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListSecurityGroupsResponseTest.java new file mode 100644 index 0000000..54d06b9 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListSecurityGroupsResponseTest.java @@ -0,0 +1,89 @@ +/* + * 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.parse; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.IngressRule; +import org.jclouds.cloudstack.domain.SecurityGroup; +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ListSecurityGroupsResponseTest extends BaseSetParserTest<SecurityGroup> { + + @Override + public String resource() { + return "/listsecuritygroupsresponse.json"; + } + + @Override + @SelectJson("securitygroup") + public Set<SecurityGroup> expected() { + return ImmutableSet + .<SecurityGroup> builder() + .add(SecurityGroup + .builder() + .id("13") + .name("default") + .description("description") + .account("adrian") + .domainId("1") + .domain("ROOT") + .ingressRules( + ImmutableSet.of( + + IngressRule.builder().id("5").protocol("tcp").startPort(22).endPort(22) + .securityGroupName("adriancole").account("adrian").build(), + + IngressRule.builder().id("6").protocol("udp").startPort(11).endPort(11).CIDR("1.1.1.1/24") + .build())).build()) + .add(SecurityGroup.builder().id("12").name("adriancole").account("adrian").domainId("1").domain("ROOT").build()) + .add(SecurityGroup.builder().id("15").name("2").description("description").account("adrian").domainId("1") + .domain("ROOT").build()) + + .add(SecurityGroup.builder().id("14").name("1").description("description").account("adrian").domainId("1") + .domain("ROOT").ingressRules(ImmutableSet.of( + + IngressRule.builder().id("7").protocol("tcp").startPort(10).endPort(10).CIDR("1.1.1.1/24").build(), + + IngressRule.builder().id("8").protocol("tcp").startPort(10).endPort(10).CIDR("2.2.2.2/16").build())) + .build()) + .add(SecurityGroup + .builder() + .id("16") + .name("with1and2") + .description("description") + .account("adrian") + .domainId("1") + .domain("ROOT") + .ingressRules( + ImmutableSet.of(IngressRule.builder().id("9").protocol("icmp").ICMPType(-1).ICMPCode(-1) + .securityGroupName("1").account("adrian").build(), + + IngressRule.builder().id("10").protocol("tcp").startPort(22).endPort(22).securityGroupName("1") + .account("adrian").build(), + + IngressRule.builder().id("11").protocol("tcp").startPort(22).endPort(22).securityGroupName("2") + .account("adrian").build())).build()).build(); + + } + +} 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/parse/ListServiceOfferingsResponseTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListServiceOfferingsResponseTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListServiceOfferingsResponseTest.java new file mode 100644 index 0000000..0318d19 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListServiceOfferingsResponseTest.java @@ -0,0 +1,54 @@ +/* + * 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.parse; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.ServiceOffering; +import org.jclouds.cloudstack.domain.StorageType; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ListServiceOfferingsResponseTest extends BaseSetParserTest<ServiceOffering> { + + @Override + public String resource() { + return "/listserviceofferingsresponse.json"; + } + + @Override + @SelectJson("serviceoffering") + public Set<ServiceOffering> expected() { + return ImmutableSet.<ServiceOffering> of( + ServiceOffering.builder().id("1").name("Small Instance") + .displayText("Small Instance - 500 MhZ CPU, 512 MB RAM - $0.05 per hour").cpuNumber(1).cpuSpeed(500) + .memory(512) + .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-02-11T15:22:32-0800")) + .storageType(StorageType.SHARED).supportsHA(false).build(), + ServiceOffering.builder().id("2").name("Medium Instance") + .displayText("Medium Instance, 1 GhZ CPU, 1 GB RAM - $0.10 per hour").cpuNumber(1).cpuSpeed(1000) + .memory(1024) + .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-02-11T15:22:32-0800")) + .storageType(StorageType.SHARED).supportsHA(false).build()); + } + +} 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/parse/ListStoragePoolsResponseTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java new file mode 100644 index 0000000..6993d72 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.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.parse; + +import java.util.Calendar; +import java.util.Date; +import java.util.Set; +import java.util.TimeZone; + +import org.jclouds.cloudstack.config.CloudStackParserModule; +import org.jclouds.cloudstack.domain.StoragePool; +import org.jclouds.json.BaseItemParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; + +@Test(groups = "unit", testName = "ListStoragePoolsResponseTest") +public class ListStoragePoolsResponseTest extends BaseItemParserTest<Set<StoragePool>> { + + @Override + public String resource() { + return "/liststoragepoolsresponse.json"; + } + + @Override + @SelectJson("storagepool") + public Set<StoragePool> expected() { + Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT+02:00")); + c.set(Calendar.YEAR, 2011); + c.set(Calendar.MONTH, Calendar.NOVEMBER); + c.set(Calendar.DAY_OF_MONTH, 26); + c.set(Calendar.HOUR_OF_DAY, 23); + c.set(Calendar.MINUTE, 33); + c.set(Calendar.SECOND, 6); + Date created = c.getTime(); + + StoragePool storagePool = StoragePool.builder().id("201").zoneId("1").zoneName("Dev Zone 1").podId("1") + .podName("Dev Pod 1").name("NFS Pri 1").ipAddress("10.26.26.165").path("/mnt/nfs/cs_pri") + .created(created).type(StoragePool.Type.NETWORK_FILESYSTEM).clusterId("1").clusterName("Xen Clust 1") + .diskSizeTotal(898356445184L).diskSizeAllocated(18276679680L).tag("tag1").state(StoragePool.State.UP) + .build(); + return ImmutableSet.of(storagePool); + } + + @Override + protected Injector injector() { + return Guice.createInjector(new GsonModule(), new CloudStackParserModule()); + } +} 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/parse/ListTemplatesResponseTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListTemplatesResponseTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListTemplatesResponseTest.java new file mode 100644 index 0000000..bd5980e --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListTemplatesResponseTest.java @@ -0,0 +1,77 @@ +/* + * 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.parse; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.Template; +import org.jclouds.cloudstack.domain.Template.Format; +import org.jclouds.cloudstack.domain.Template.Type; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ListTemplatesResponseTest extends BaseSetParserTest<Template> { + + @Override + public String resource() { + // grep listtemplatesresponse ./target/test-data/jclouds-wire.log|tail + // -1|sed -e 's/.*<< "//g' -e 's/"$//g' + return "/listtemplatesresponse.json"; + } + + @Override + @SelectJson("template") + public Set<Template> expected() { + return ImmutableSet.of( + Template.builder().id("2").name("CentOS 5.3(64-bit) no GUI (XenServer)") + .displayText("CentOS 5.3(64-bit) no GUI (XenServer)").isPublic(true) + .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-03-20T19:17:48-0700")) + .ready(false).passwordEnabled(false).format(Format.VHD).featured(true).crossZones(true).OSTypeId("11") + .OSType("CentOS 5.3 (32-bit)").account("system").zoneId("2").zone("Chicago").type(Type.BUILTIN) + .hypervisor("XenServer").domain("ROOT").domainId("1").extractable(true).build(), + Template.builder().id("4").name("CentOS 5.5(64-bit) no GUI (KVM)") + .displayText("CentOS 5.5(64-bit) no GUI (KVM)").isPublic(true) + .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-03-20T19:17:48-0700")) + .ready(true).passwordEnabled(false).format(Format.QCOW2).featured(true).crossZones(true) + .OSTypeId("112").OSType("CentOS 5.5 (64-bit)").account("system").zoneId("2").zone("Chicago") + .size(8589934592l).type(Type.BUILTIN).hypervisor("KVM").domain("ROOT").domainId("1").extractable(true) + .build(), + Template.builder().id("203").name("Windows 7 KVM").displayText("Windows 7 KVM").isPublic(true) + .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-03-20T22:02:18-0700")) + .ready(true).passwordEnabled(false).format(Format.QCOW2).featured(true).crossZones(false) + .OSTypeId("48").OSType("Windows 7 (32-bit)").account("admin").zoneId("2").zone("Chicago") + .size(17179869184l).type(Type.USER).hypervisor("KVM").domain("ROOT").domainId("1").extractable(false) + .build(), + Template.builder().id("7").name("CentOS 5.3(64-bit) no GUI (vSphere)") + .displayText("CentOS 5.3(64-bit) no GUI (vSphere)").isPublic(true) + .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-03-20T19:17:48-0700")) + .ready(false).passwordEnabled(false).format(Format.OVA).featured(true).crossZones(true).OSTypeId("12") + .OSType("CentOS 5.3 (64-bit)").account("system").zoneId("2").zone("Chicago").type(Type.BUILTIN) + .hypervisor("VMware").domain("ROOT").domainId("1").extractable(true).build(), + Template.builder().id("241").name("kvmdev4").displayText("v5.6.28_Dev4").isPublic(true) + .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-04-21T09:43:25-0700")) + .ready(true).passwordEnabled(false).format(Format.QCOW2).featured(false).crossZones(false) + .OSTypeId("14").OSType("CentOS 5.4 (64-bit)").account("rs3").zoneId("2").zone("Chicago") + .size(10737418240l).type(Type.USER).hypervisor("KVM").domain("ROOT").domainId("1").extractable(false) + .build()); + } +} 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/parse/ListUsageRecordsResponseTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListUsageRecordsResponseTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListUsageRecordsResponseTest.java new file mode 100644 index 0000000..9ecd895 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListUsageRecordsResponseTest.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.parse; + +import java.util.Calendar; +import java.util.Date; +import java.util.Set; +import java.util.TimeZone; + +import org.jclouds.cloudstack.config.CloudStackParserModule; +import org.jclouds.cloudstack.domain.UsageRecord; +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; + +@Test(groups = "unit") +public class ListUsageRecordsResponseTest extends BaseSetParserTest<UsageRecord> { + + @Override + public String resource() { + return "/listusagerecordsresponse.json"; + } + + @Override + @SelectJson("usagerecord") + public Set<UsageRecord> expected() { + Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + c.set(Calendar.YEAR, 2011); + c.set(Calendar.MONTH, Calendar.DECEMBER); + c.set(Calendar.DAY_OF_MONTH, 15); + c.set(Calendar.HOUR_OF_DAY, 0); + c.set(Calendar.MINUTE, 0); + c.set(Calendar.SECOND, 0); + c.set(Calendar.MILLISECOND, 0); + Date start = c.getTime(); + c.add(Calendar.DAY_OF_MONTH, 1); + c.add(Calendar.SECOND, -1); + Date end = c.getTime(); + + return ImmutableSet.of(UsageRecord.builder() + .accountName("admin").accountId("2").domainId("1").zoneId("1") + .description("Template Id:203 Size:3117171712") + .usage("24 Hrs").usageType(UsageRecord.UsageType.TEMPLATE).rawUsageHours(24) + .templateId("0").id("203").startDate(start).endDate(end).build()); + + } + + @Override + protected Injector injector() { + return Guice.createInjector(new GsonModule(), new CloudStackParserModule()); + } + +} 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/parse/ListVirtualMachinesResponse3xTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListVirtualMachinesResponse3xTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListVirtualMachinesResponse3xTest.java new file mode 100644 index 0000000..a891f4c --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListVirtualMachinesResponse3xTest.java @@ -0,0 +1,76 @@ +/* + * 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.parse; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.GuestIPType; +import org.jclouds.cloudstack.domain.NIC; +import org.jclouds.cloudstack.domain.TrafficType; +import org.jclouds.cloudstack.domain.VirtualMachine; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ListVirtualMachinesResponse3xTest extends BaseSetParserTest<VirtualMachine> { + + @Override + public String resource() { + return "/listvirtualmachinesresponse3x.json"; + } + + @Override + @SelectJson("virtualmachine") + public Set<VirtualMachine> expected() { + return ImmutableSet.of(VirtualMachine + .builder() + .id("fee2ccb3-c1f2-4e7b-8465-42b390e10dff") + .name("cloudstack-r-611") + .displayName("cloudstack-r-611") + .account("jcloud2") + .domainId("ea66e3a5-d007-42e8-a0de-ec5ce778a1d7") + .domain("jCloud") + .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-05-22T09:18:28-0700")) + .state(VirtualMachine.State.RUNNING) + .isHAEnabled(false) + .zoneId("1") + .zoneName("Santa Clara Zone") + .templateId("5c65f152-a4bc-4405-a756-fd10841a9aa7") + .templateName("jclouds-6d4bdc29") + .templateDisplayText("jclouds live testCreateTemplate") + .passwordEnabled(false) + .serviceOfferingId("5305750d-df71-4da9-8cd0-e23c2236a6e2") + .serviceOfferingName("Micro Instance") + .cpuCount(1) + .cpuSpeed(500) + .memory(256) + .guestOSId("6dcd58ce-1ec6-432c-af0b-9ab4ca9207d9") + .rootDeviceId("0") + .rootDeviceType("IscsiLUN") + .publicIP("72.52.126.110") + .publicIPId("e202aafb-ab41-4dc0-80e9-9fcd64fbf45c") + .nics(ImmutableSet.of(NIC.builder().id("48640c5e-90f3-45bd-abd2-a108ca8957ac"). + networkId("c0d5db5b-f7d5-44e1-b854-21ecd1a09dbf").netmask("255.255.255.0").gateway("10.1.1.1") + .IPAddress("10.1.1.227").trafficType(TrafficType.GUEST).guestIPType(GuestIPType.ISOLATED) + .isDefault(true).build())).build()); + } + +} 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/parse/ListVirtualMachinesResponseTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListVirtualMachinesResponseTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListVirtualMachinesResponseTest.java new file mode 100644 index 0000000..d6b737b --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListVirtualMachinesResponseTest.java @@ -0,0 +1,75 @@ +/* + * 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.parse; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.GuestIPType; +import org.jclouds.cloudstack.domain.NIC; +import org.jclouds.cloudstack.domain.TrafficType; +import org.jclouds.cloudstack.domain.VirtualMachine; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ListVirtualMachinesResponseTest extends BaseSetParserTest<VirtualMachine> { + + @Override + public String resource() { + return "/listvirtualmachinesresponse.json"; + } + + @Override + @SelectJson("virtualmachine") + public Set<VirtualMachine> expected() { + return ImmutableSet.of(VirtualMachine + .builder() + .id("54") + .name("i-3-54-VM") + .displayName("i-3-54-VM") + .account("adrian") + .domainId("1") + .domain("ROOT") + .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-02-16T14:28:37-0800")) + .state(VirtualMachine.State.STARTING) + .isHAEnabled(false) + .zoneId("1") + .zoneName("San Jose 1") + .templateId("2") + .templateName("CentOS 5.3(64-bit) no GUI (XenServer)") + .templateDisplayText("CentOS 5.3(64-bit) no GUI (XenServer)") + .passwordEnabled(false) + .serviceOfferingId("1") + .serviceOfferingName("Small Instance") + .cpuCount(1) + .cpuSpeed(500) + .memory(512) + .guestOSId("11") + .rootDeviceId("0") + .rootDeviceType("NetworkFilesystem") + .jobId("63") + .jobStatus(0) + .nics(ImmutableSet.of(NIC.builder().id("72").networkId("204").netmask("255.255.255.0").gateway("10.1.1.1") + .IPAddress("10.1.1.18").trafficType(TrafficType.GUEST).guestIPType(GuestIPType.VIRTUAL) + .isDefault(true).build())).hypervisor("XenServer").build()); + } + +} 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/parse/ListVlanIPRangesResponseTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListVlanIPRangesResponseTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListVlanIPRangesResponseTest.java new file mode 100644 index 0000000..fdbaa68 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListVlanIPRangesResponseTest.java @@ -0,0 +1,71 @@ +/* + * 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.parse; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.VlanIPRange; +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ListVlanIPRangesResponseTest extends BaseSetParserTest<VlanIPRange> { + + @Override + public String resource() { + return "/listvlaniprangesresponse.json"; + } + + @Override + @SelectJson("vlaniprange") + public Set<VlanIPRange> expected() { + VlanIPRange range1 = VlanIPRange.builder() + .id("1") + .forVirtualNetwork(true) + .zoneId("1") + .vlan("127") + .account("system") + .domainId("1") + .domain("ROOT") + .gateway("10.27.27.254") + .netmask("255.255.255.0") + .startIP("10.27.27.50") + .endIP("10.27.27.100") + .networkId("200") + .build(); + VlanIPRange range2 = VlanIPRange.builder() + .id("2") + .forVirtualNetwork(false) + .zoneId("2") + .vlan("untagged") + .account("system") + .domainId("1") + .domain("ROOT") + .podId("2") + .podName("Dev Pod 2") + .gateway("10.22.22.254") + .netmask("255.255.255.0") + .startIP("10.22.22.51") + .endIP("10.22.22.100") + .networkId("209") + .build(); + return ImmutableSet.of(range1, range2); + } +} 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/parse/ListZonesResponseTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListZonesResponseTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListZonesResponseTest.java new file mode 100644 index 0000000..f69213d --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/ListZonesResponseTest.java @@ -0,0 +1,44 @@ +/* + * 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.parse; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.NetworkType; +import org.jclouds.cloudstack.domain.Zone; +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ListZonesResponseTest extends BaseSetParserTest<Zone> { + + @Override + public String resource() { + return "/listzonesresponse.json"; + } + + @Override + @SelectJson("zone") + public Set<Zone> expected() { + return ImmutableSet.of(Zone.builder().id("1").name("San Jose 1").networkType(NetworkType.ADVANCED) + .securityGroupsEnabled(false).build(), + Zone.builder().id("2").name("Chicago").networkType(NetworkType.ADVANCED).securityGroupsEnabled(true).build()); + } +} 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/parse/RegisterUserKeysResponseTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/RegisterUserKeysResponseTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/RegisterUserKeysResponseTest.java new file mode 100644 index 0000000..08cd959 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/parse/RegisterUserKeysResponseTest.java @@ -0,0 +1,40 @@ +/* + * 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.parse; + +import org.jclouds.cloudstack.domain.ApiKeyPair; +import org.jclouds.json.BaseParserTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class RegisterUserKeysResponseTest extends BaseParserTest<ApiKeyPair, Object> { + + @Override + public String resource() { + return "/registeruserkeysresponse.json"; + } + + @Override + @SelectJson("userkeys") + public ApiKeyPair expected() { + return ApiKeyPair.builder() + .apiKey("5nn6IAQ-0BYuAKTu45rf49VsyX0rg9t48TpY8NKsduE5t-_1_g_AU8ZjP3OJvVdlzWKL3Lgfa6_nkC9hU6NyQQ") + .secretKey("GSCDYzj65CiSkxzCJxlFvcF52qglM7HbuG6QL7zYVeWVhVO8GnW85wGTBBuZ3xpzEN_UfKnsORvrNszYQ1ofAw").build(); + } + +} 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/predicates/JobCompleteTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/JobCompleteTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/JobCompleteTest.java new file mode 100644 index 0000000..581e373 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/JobCompleteTest.java @@ -0,0 +1,79 @@ +/* + * 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.predicates; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + +import org.jclouds.cloudstack.AsyncJobException; +import org.jclouds.cloudstack.CloudStackApi; +import org.jclouds.cloudstack.domain.AsyncJob; +import org.jclouds.cloudstack.domain.AsyncJobError; +import org.jclouds.cloudstack.domain.AsyncJob.ResultCode; +import org.jclouds.cloudstack.domain.AsyncJob.Status; +import org.jclouds.cloudstack.domain.AsyncJobError.ErrorCode; +import org.jclouds.cloudstack.features.AsyncJobApi; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +@Test(groups = "unit", singleThreaded = true) +public class JobCompleteTest { + + CloudStackApi client; + AsyncJobApi asyncJobClient; + + @BeforeMethod + public void setUp() { + client = createMock(CloudStackApi.class); + asyncJobClient = createMock(AsyncJobApi.class); + + expect(client.getAsyncJobApi()).andReturn(asyncJobClient); + } + + @Test + public void testJobComplete() { + AsyncJob<?> job = AsyncJob.builder().id("100") + .status(Status.SUCCEEDED).resultCode(ResultCode.SUCCESS).build(); + expect((Object) asyncJobClient.getAsyncJob(job.getId())).andReturn(job); + + replay(client, asyncJobClient); + assertTrue(new JobComplete(client).apply(job.getId())); + verify(client, asyncJobClient); + } + + @Test + public void testFailedJobComplete() { + AsyncJob<?> job = AsyncJob.builder().id("100") + .status(Status.FAILED).resultCode(ResultCode.FAIL) + .error(AsyncJobError.builder().errorCode(ErrorCode.INTERNAL_ERROR).errorText("Dummy test error").build()).build(); + expect((Object) asyncJobClient.getAsyncJob(job.getId())).andReturn(job); + + replay(client, asyncJobClient); + try { + new JobComplete(client).apply(job.getId()); + fail("No exception thrown"); + + } catch (AsyncJobException e) { + assertTrue(e.toString().contains("Dummy test error")); + } + verify(client, asyncJobClient); + } +} 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/predicates/NetworkPredicatesTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/NetworkPredicatesTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/NetworkPredicatesTest.java new file mode 100644 index 0000000..c7fc117 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/NetworkPredicatesTest.java @@ -0,0 +1,109 @@ +/* + * 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.predicates; + +import static org.jclouds.cloudstack.predicates.NetworkPredicates.defaultNetworkInZone; +import static org.jclouds.cloudstack.predicates.NetworkPredicates.hasLoadBalancerService; +import static org.jclouds.cloudstack.predicates.NetworkPredicates.supportsPortForwarding; +import static org.jclouds.cloudstack.predicates.NetworkPredicates.supportsStaticNAT; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import org.jclouds.cloudstack.domain.Network; +import org.jclouds.cloudstack.domain.NetworkService; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class NetworkPredicatesTest { + + public void testHasLoadBalancerService() { + Network network = Network.builder().id("204").services(ImmutableSet.of(NetworkService.builder().name("Lb").build())).build(); + + assert hasLoadBalancerService().apply(network); + assert !supportsStaticNAT().apply(network); + assert !supportsPortForwarding().apply(network); + + } + + public void testSupportsStaticNATFindsWhenFirewallHasStaticNatFeature() { + Network network = Network + .builder() + .id("204") + .services( + ImmutableSet.of(NetworkService.builder().name("Firewall").capabilities( + ImmutableMap.<String, String> of("StaticNat", "true")).build())) + .build(); + + assert !hasLoadBalancerService().apply(network); + assert supportsStaticNAT().apply(network); + assert !supportsPortForwarding().apply(network); + } + + public void testNoSupport() { + Network network = Network.builder().id("204") + .services(ImmutableSet.of(NetworkService.builder().name("Firewall").capabilities( + ImmutableMap.<String, String> of()).build())).build(); + + assert !hasLoadBalancerService().apply(network); + assert !supportsStaticNAT().apply(network); + assert !supportsPortForwarding().apply(network); + } + + public void testSupportsPortForwardingFindsWhenFirewallHasPortForwardingFeature() { + Network network = Network + .builder() + .id("204") + .services( + ImmutableSet.of(NetworkService.builder().name("Firewall").capabilities( + ImmutableMap.<String, String> of("PortForwarding", "true")).build())).build(); + + assert !hasLoadBalancerService().apply(network); + assert !supportsStaticNAT().apply(network); + assert supportsPortForwarding().apply(network); + } + + public void testSupportsPortForwardingAndStaticNATWhenFirewallHasFeatures() { + Network network = Network + .builder() + .id("204") + .services( + ImmutableSet.of(NetworkService.builder().name("Firewall").capabilities( + ImmutableMap.<String, String> of("StaticNat", "true", "PortForwarding", "true")).build())).build(); + + assert Predicates.and(supportsPortForwarding(), supportsStaticNAT()).apply(network); + assert !hasLoadBalancerService().apply(network); + + } + + public void testDefaultNetworkInZone() { + Network defaultInZone = Network.builder().id("42-1").isDefault(true).zoneId("42").build(); + Network defaultNotInZone = Network.builder().id("200-1").isDefault(true).zoneId("200").build(); + Network notDefaultInZone = Network.builder().id("42-2").isDefault(false).zoneId("42").build(); + Network notDefaultNotInZone = Network.builder().id("200-2").isDefault(false).zoneId("200").build(); + + Predicate<Network> predicate = defaultNetworkInZone("42"); + assertTrue(predicate.apply(defaultInZone)); + assertFalse(predicate.apply(defaultNotInZone)); + assertFalse(predicate.apply(notDefaultInZone)); + assertFalse(predicate.apply(notDefaultNotInZone)); + } +} 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/predicates/OSCategoryInTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/OSCategoryInTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/OSCategoryInTest.java new file mode 100644 index 0000000..0722a73 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/OSCategoryInTest.java @@ -0,0 +1,85 @@ +/* + * 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.predicates; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import java.util.Map; +import java.util.Set; + +import org.jclouds.cloudstack.CloudStackApi; +import org.jclouds.cloudstack.domain.OSType; +import org.jclouds.cloudstack.domain.Template; +import org.jclouds.cloudstack.features.GuestOSApi; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; + +@Test(groups = "unit", singleThreaded = true) +public class OSCategoryInTest { + + private CloudStackApi client; + private GuestOSApi guestOSClient; + private Set<String> acceptableCategories = ImmutableSet.<String>of("Ubuntu"); + + @BeforeMethod + public void setUp() { + client = createMock(CloudStackApi.class); + guestOSClient = createMock(GuestOSApi.class); + + expect(client.getGuestOSApi()).andReturn(guestOSClient).times(2); + + Map<String, String> osCategories = Maps.newHashMap(); + osCategories.put("1", "Ubuntu"); + osCategories.put("2", "CentOS"); + osCategories.put("3", "RHEL"); + + expect(guestOSClient.listOSCategories()).andReturn(osCategories); + + Set<OSType> osTypes = ImmutableSet.of( + OSType.builder().id("10").OSCategoryId("1").description("Ubuntu 10.04 LTS").build(), + OSType.builder().id("20").OSCategoryId("2").description("CentOS 5.4").build(), + OSType.builder().id("30").OSCategoryId("3").description("RHEL 6").build() + ); + + expect(guestOSClient.listOSTypes()).andReturn(osTypes); + replay(client, guestOSClient); + } + + @Test + public void testTemplateInAcceptableCategory() { + assertTrue(new OSCategoryIn(client).apply(acceptableCategories).apply( + Template.builder().id("1").OSTypeId("10").build() + )); + verify(client, guestOSClient); + } + + @Test + public void testTemplateNotInAcceptableCategory() { + assertFalse(new OSCategoryIn(client).apply(acceptableCategories).apply( + Template.builder().id("2").OSTypeId("30").build() + )); + verify(client, guestOSClient); + } +} 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/predicates/PublicIPAddressPredicatesTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/PublicIPAddressPredicatesTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/PublicIPAddressPredicatesTest.java new file mode 100644 index 0000000..8b05cf6 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/PublicIPAddressPredicatesTest.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.predicates; + +import static org.jclouds.cloudstack.predicates.PublicIPAddressPredicates.available; + +import org.jclouds.cloudstack.domain.PublicIPAddress; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class PublicIPAddressPredicatesTest { + + public void testIsAvailableWhenAllocated() { + PublicIPAddress address = PublicIPAddress.builder().state(PublicIPAddress.State.ALLOCATED).id("204").build(); + + assert available().apply(address); + + } + + public void testIsNotAvailableWhenNotAllocated() { + PublicIPAddress address = PublicIPAddress.builder().state(PublicIPAddress.State.ALLOCATING).id("204").build(); + + assert !available().apply(address); + + } + + public void testIsNotAvailableWhenAssignedToVM() { + PublicIPAddress address = PublicIPAddress.builder().state(PublicIPAddress.State.ALLOCATED).virtualMachineId("1") + .id("204").build(); + + assert !available().apply(address); + + } + + public void testIsNotAvailableWhenSourceNAT() { + PublicIPAddress address = PublicIPAddress.builder().state(PublicIPAddress.State.ALLOCATED).isSourceNAT(true) + .id("204").build(); + + assert !available().apply(address); + + } + + public void testIsNotAvailableWhenStaticNAT() { + PublicIPAddress address = PublicIPAddress.builder().state(PublicIPAddress.State.ALLOCATED).isStaticNAT(true) + .id("204").build(); + + assert !available().apply(address); + + } +} 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/predicates/SecurityGroupPredicatesTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/SecurityGroupPredicatesTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/SecurityGroupPredicatesTest.java new file mode 100644 index 0000000..cccb558 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/SecurityGroupPredicatesTest.java @@ -0,0 +1,107 @@ +/* + * 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.predicates; + +import static org.jclouds.cloudstack.predicates.SecurityGroupPredicates.hasCidr; +import static org.jclouds.cloudstack.predicates.SecurityGroupPredicates.nameEquals; +import static org.jclouds.cloudstack.predicates.SecurityGroupPredicates.portInRange; +import static org.jclouds.cloudstack.predicates.SecurityGroupPredicates.portInRangeForCidr; +import static org.jclouds.cloudstack.predicates.SecurityGroupPredicates.ruleCidrMatches; +import static org.jclouds.cloudstack.predicates.SecurityGroupPredicates.ruleGroupMatches; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import org.jclouds.cloudstack.domain.IngressRule; +import org.jclouds.cloudstack.domain.SecurityGroup; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; + +@Test(groups = "unit") +public class SecurityGroupPredicatesTest { + + public SecurityGroup group() { + return SecurityGroup + .builder() + .id("13") + .name("default") + .description("description") + .account("adrian") + .domainId("1") + .domain("ROOT") + .ingressRules( + ImmutableSet.of( + + IngressRule.builder().id("5").protocol("tcp").startPort(22).endPort(22) + .securityGroupName("adriancole").account("adrian").build(), + IngressRule.builder().id("6").protocol("udp").startPort(11).endPort(11).CIDR("1.1.1.1/24").build(), + IngressRule.builder().id("7").protocol("tcp").startPort(40).endPort(50).CIDR("1.1.1.1/24").build(), + IngressRule.builder().id("8").protocol("tcp").startPort(60).endPort(60).CIDR("2.2.2.2/16").build() + )).build(); + } + + @Test + public void testPortInRange() { + assertTrue(portInRange(22).apply(group())); + assertTrue(portInRange(45).apply(group())); + assertFalse(portInRange(100).apply(group())); + } + + @Test + public void testHasCidr() { + assertTrue(hasCidr("1.1.1.1/24").apply(group())); + assertFalse(hasCidr("3.3.3.3/25").apply(group())); + } + + @Test + public void testPortInRangeForCidr() { + assertTrue(portInRangeForCidr(11, "1.1.1.1/24").apply(group())); + assertTrue(portInRangeForCidr(45, "1.1.1.1/24").apply(group())); + assertFalse(portInRangeForCidr(45, "2.2.2.2/16").apply(group())); + assertFalse(portInRangeForCidr(11, "2.2.2.2/16").apply(group())); + assertFalse(portInRangeForCidr(11, "3.3.3.3/25").apply(group())); + } + + @Test + public void testNameEquals() { + assertTrue(nameEquals("default").apply(group())); + assertFalse(nameEquals("not-default").apply(group())); + } + + @Test + public void testRuleCidrMatches() { + assertTrue(Iterables.any(group().getIngressRules(), + ruleCidrMatches("tcp", 40, 50, ImmutableSet.of("1.1.1.1/24")))); + assertFalse(Iterables.any(group().getIngressRules(), + ruleCidrMatches("tcp", 40, 50, ImmutableSet.of("2.2.2.2/24")))); + } + + @Test + public void testRuleGroupMatches() { + assertTrue(Iterables.any(group().getIngressRules(), + ruleGroupMatches("tcp", 22, 22, + ImmutableMultimap.<String, String>builder().put("adrian", "adriancole").build()))); + assertFalse(Iterables.any(group().getIngressRules(), + ruleGroupMatches("tcp", 22, 22, + ImmutableMultimap.<String, String>builder().put("adrian", "somegroup").build()))); + assertFalse(Iterables.any(group().getIngressRules(), + ruleGroupMatches("tcp", 22, 22, + ImmutableMultimap.<String, String>builder().put("someuser", "adriancole").build()))); + } +} 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/predicates/TemplatePredicatesTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/TemplatePredicatesTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/TemplatePredicatesTest.java new file mode 100644 index 0000000..c514af1 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/TemplatePredicatesTest.java @@ -0,0 +1,49 @@ +/* + * 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.predicates; + +import static org.jclouds.cloudstack.predicates.TemplatePredicates.isPasswordEnabled; +import static org.jclouds.cloudstack.predicates.TemplatePredicates.isReady; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import org.jclouds.cloudstack.domain.Template; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class TemplatePredicatesTest { + + @Test + public void testTemplateIsReady() { + assertTrue(isReady().apply( + Template.builder().id("a").ready(true).build() + )); + assertFalse(isReady().apply( + Template.builder().id("b").ready(false).build() + )); + } + + @Test + public void testTemplateIsPasswordEnabled() { + assertTrue(isPasswordEnabled().apply( + Template.builder().id("anid").passwordEnabled(true).build() + )); + assertFalse(isPasswordEnabled().apply( + Template.builder().id("someid").passwordEnabled(false).build() + )); + } +} 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/predicates/UserPredicatesTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/UserPredicatesTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/UserPredicatesTest.java new file mode 100644 index 0000000..ac2ecb1 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/UserPredicatesTest.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.predicates; + +import static org.jclouds.cloudstack.predicates.UserPredicates.apiKeyEquals; +import static org.jclouds.cloudstack.predicates.UserPredicates.isAdminAccount; +import static org.jclouds.cloudstack.predicates.UserPredicates.isDomainAdminAccount; +import static org.jclouds.cloudstack.predicates.UserPredicates.isUserAccount; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import org.jclouds.cloudstack.domain.Account; +import org.jclouds.cloudstack.domain.User; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class UserPredicatesTest { + + @Test + public void testMatchApiKey() { + assertTrue(apiKeyEquals("random-text").apply( + User.builder().id("random-id").apiKey("random-text").build() + )); + assertFalse(apiKeyEquals("something-different").apply( + User.builder().id("random-id").apiKey("random-text").build() + )); + } + + @DataProvider(name = "accountType") + public Object[][] getAccountTypes() { + return new Object[][] { + /* Type ID, isUser, isDomainAdmin, isAdmin */ + {Account.Type.USER, true, false, false}, + {Account.Type.DOMAIN_ADMIN, false, true, false}, + {Account.Type.ADMIN, false, false, true}, + {Account.Type.UNRECOGNIZED, false, false, false} + }; + } + + @Test(dataProvider = "accountType") + public void testAccountType(Account.Type type, boolean isUser, boolean isDomainAdmin, boolean isAdmin) { + User testUser = User.builder().id("someid").accountType(type).build(); + assertEquals(isUserAccount().apply(testUser), isUser); + assertEquals(isDomainAdminAccount().apply(testUser), isDomainAdmin); + assertEquals(isAdminAccount().apply(testUser), isAdmin); + } + +} 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/predicates/VirtualMachineDestroyedTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/VirtualMachineDestroyedTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/VirtualMachineDestroyedTest.java new file mode 100644 index 0000000..2c5f99b --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/VirtualMachineDestroyedTest.java @@ -0,0 +1,68 @@ +/* + * 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.predicates; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import org.jclouds.cloudstack.CloudStackApi; +import org.jclouds.cloudstack.domain.VirtualMachine; +import org.jclouds.cloudstack.features.VirtualMachineApi; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +@Test(groups = "unit", singleThreaded = true, testName = "VirtualMachineDestroyedTest") +public class VirtualMachineDestroyedTest { + + CloudStackApi client; + VirtualMachineApi virtualMachineClient; + + @BeforeMethod + public void setUp() { + client = createMock(CloudStackApi.class); + virtualMachineClient = createMock(VirtualMachineApi.class); + expect(client.getVirtualMachineApi()).andReturn(virtualMachineClient); + } + + @Test + public void testIsDestroyed() { + VirtualMachine virtualMachine = VirtualMachine.builder(). + id("229").state(VirtualMachine.State.DESTROYED).build(); + + expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(virtualMachine); + + replay(client, virtualMachineClient); + assertTrue(new VirtualMachineDestroyed(client).apply(virtualMachine)); + verify(client, virtualMachineClient); + } + + @Test + public void testStillRunning() { + VirtualMachine virtualMachine = VirtualMachine.builder(). + id("229").state(VirtualMachine.State.RUNNING).build(); + + expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(virtualMachine); + + replay(client, virtualMachineClient); + assertFalse(new VirtualMachineDestroyed(client).apply(virtualMachine)); + verify(client, virtualMachineClient); + } +} 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/predicates/VirtualMachineExpungedTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/VirtualMachineExpungedTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/VirtualMachineExpungedTest.java new file mode 100644 index 0000000..11f2790 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/VirtualMachineExpungedTest.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.predicates; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import org.jclouds.cloudstack.CloudStackApi; +import org.jclouds.cloudstack.domain.VirtualMachine; +import org.jclouds.cloudstack.features.VirtualMachineApi; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +@Test(groups = "unit", singleThreaded = true, testName = "VirtualMachineExpungedTest") +public class VirtualMachineExpungedTest { + + CloudStackApi client; + VirtualMachineApi virtualMachineClient; + + @BeforeMethod + public void setUp() { + client = createMock(CloudStackApi.class); + virtualMachineClient = createMock(VirtualMachineApi.class); + expect(client.getVirtualMachineApi()).andReturn(virtualMachineClient); + } + + @Test + public void testWaitForVirtualMachineToBeExpunged() { + VirtualMachine virtualMachine = VirtualMachine.builder().id("229").build(); + expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(null); + + replay(client, virtualMachineClient); + assertTrue(new VirtualMachineExpunged(client).apply(virtualMachine)); + verify(client, virtualMachineClient); + } + + @Test + public void testNoRemovedYet() { + VirtualMachine virtualMachine = VirtualMachine.builder().id("229").build(); + expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(virtualMachine); + + replay(client, virtualMachineClient); + assertFalse(new VirtualMachineExpunged(client).apply(virtualMachine)); + verify(client, virtualMachineClient); + } +} 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/predicates/VirtualMachineRunningTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/VirtualMachineRunningTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/VirtualMachineRunningTest.java new file mode 100644 index 0000000..269fa32 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/VirtualMachineRunningTest.java @@ -0,0 +1,82 @@ +/* + * 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.predicates; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.testng.Assert.assertEquals; + +import org.jclouds.cloudstack.CloudStackApi; +import org.jclouds.cloudstack.domain.VirtualMachine; +import org.jclouds.cloudstack.domain.VirtualMachine.State; +import org.jclouds.cloudstack.features.VirtualMachineApi; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +@Test(groups = "unit", singleThreaded = true, testName = "VirtualMachineRunningTest") +public class VirtualMachineRunningTest { + + CloudStackApi client; + VirtualMachineApi virtualMachineClient; + + @BeforeMethod + public void setUp() { + client = createMock(CloudStackApi.class); + virtualMachineClient = createMock(VirtualMachineApi.class); + + expect(client.getVirtualMachineApi()).andReturn(virtualMachineClient); + } + + @DataProvider(name = "virtualMachineStates") + public Object[][] virtualMachineStates() { + return new Object[][] { + {State.RUNNING, true}, + {State.STARTING, false}, + {State.STOPPING, false}, + {State.STOPPED, false}, + {State.SHUTDOWNED, false}, + {State.DESTROYED, false}, + {State.EXPUNGING, false}, + {State.MIGRATING, false} + }; + } + + @Test(dataProvider = "virtualMachineStates") + public void testWaitForVirtualMachineToBeRunning(State state, boolean expected) { + assertPredicateResult(state, expected); + } + + @Test(expectedExceptions = IllegalStateException.class) + public void testThrowExceptionOnErrorState() { + assertPredicateResult(State.ERROR, true); + } + + private void assertPredicateResult(State state, boolean expected) { + String virtualMachineId = "229"; + VirtualMachine virtualMachine = VirtualMachine.builder(). + id(virtualMachineId).state(state).build(); + + expect(virtualMachineClient.getVirtualMachine(virtualMachineId)).andReturn(virtualMachine); + replay(client, virtualMachineClient); + + assertEquals(new VirtualMachineRunning(client).apply(virtualMachine), expected); + verify(client, virtualMachineClient); + } +} 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/predicates/ZonePredicatesTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/ZonePredicatesTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/ZonePredicatesTest.java new file mode 100644 index 0000000..8dfeb24 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/predicates/ZonePredicatesTest.java @@ -0,0 +1,51 @@ +/* + * 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.predicates; + +import static org.jclouds.cloudstack.predicates.ZonePredicates.supportsAdvancedNetworks; +import static org.jclouds.cloudstack.predicates.ZonePredicates.supportsSecurityGroups; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import org.jclouds.cloudstack.domain.NetworkType; +import org.jclouds.cloudstack.domain.Zone; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class ZonePredicatesTest { + + @Test + public void testSupportsAdvancedNetworks() { + assertTrue(supportsAdvancedNetworks().apply( + Zone.builder().id("41").networkType(NetworkType.ADVANCED).build() + )); + assertFalse(supportsAdvancedNetworks().apply( + Zone.builder().id("42").networkType(NetworkType.BASIC).build() + )); + } + + @Test + public void testSupportsSecurityGroups() { + assertTrue(supportsSecurityGroups().apply( + Zone.builder().id("43").securityGroupsEnabled(true).build() + )); + assertFalse(supportsSecurityGroups().apply( + Zone.builder().id("44").securityGroupsEnabled(false).build() + )); + } + +}
