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/GlobalUserApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalUserApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalUserApiLiveTest.java new file mode 100644 index 0000000..cccfa62 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalUserApiLiveTest.java @@ -0,0 +1,104 @@ +/* + * 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.Charsets.UTF_8; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.hash.Hashing.md5; +import static com.google.common.io.BaseEncoding.base16; +import static org.jclouds.cloudstack.features.GlobalAccountApiLiveTest.createTestAccount; +import static org.jclouds.cloudstack.options.UpdateUserOptions.Builder.userName; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.util.Properties; +import java.util.Set; + +import org.jclouds.cloudstack.CloudStackApi; +import org.jclouds.cloudstack.CloudStackContext; +import org.jclouds.cloudstack.CloudStackGlobalApi; +import org.jclouds.cloudstack.domain.Account; +import org.jclouds.cloudstack.domain.ApiKeyPair; +import org.jclouds.cloudstack.domain.User; +import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code GlobaUserClient} + */ +@Test(groups = "live", singleThreaded = true, testName = "GlobalUserApiLiveTest") +public class GlobalUserApiLiveTest extends BaseCloudStackApiLiveTest { + + public static User createTestUser(CloudStackGlobalApi client, Account account, String prefix) { + return client.getUserClient().createUser(prefix + "-user", account.getName(), "[email protected]", + base16().lowerCase().encode(md5().hashString("password", UTF_8).asBytes()), "First", "Last"); + } + + @Test + public void testCreateUser() { + skipIfNotGlobalAdmin(); + + Account testAccount = createTestAccount(globalAdminClient, prefix); + User testUser = null; + try { + testUser = createTestUser(globalAdminClient, testAccount, prefix); + + assertNotNull(testUser); + assertEquals(testUser.getName(), prefix + "-user"); + assertEquals(testUser.getAccount(), prefix + "-account"); + + User updatedUser = globalAdminClient.getUserClient() + .updateUser(testUser.getId(), userName(prefix + "-user-2")); + + assertNotNull(updatedUser); + assertEquals(updatedUser.getName(), prefix + "-user-2"); + + ApiKeyPair apiKeys = globalAdminClient.getUserClient() + .registerUserKeys(updatedUser.getId()); + + assertNotNull(apiKeys.getApiKey()); + assertNotNull(apiKeys.getSecretKey()); + + checkAuthAsUser(apiKeys); + + } finally { + if (testUser != null) { + globalAdminClient.getUserClient().deleteUser(testUser.getId()); + } + globalAdminClient.getAccountApi().deleteAccount(testAccount.getId()); + } + } + + private void checkAuthAsUser(ApiKeyPair keyPair) { + CloudStackContext context = createView(credentialsAsProperties(keyPair), setupModules()); + + CloudStackApi client = context.getApi(); + Set<Account> accounts = client.getAccountApi().listAccounts(); + + assert !accounts.isEmpty(); + + context.close(); + } + + private Properties credentialsAsProperties(ApiKeyPair keyPair) { + Properties overrides = setupProperties(); + overrides.put(provider + ".identity", checkNotNull(keyPair.getApiKey())); + overrides.put(provider + ".credential", checkNotNull(keyPair.getSecretKey())); + return overrides; + } + +}
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/GlobalUserApiTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalUserApiTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalUserApiTest.java new file mode 100644 index 0000000..4c8f76a --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalUserApiTest.java @@ -0,0 +1,98 @@ +/* + * 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.cloudstack.options.CreateUserOptions; +import org.jclouds.cloudstack.options.UpdateUserOptions; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.functions.ParseFirstJsonValueNamed; +import org.jclouds.http.functions.ReleasePayloadAndReturn; +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 GlobalUserApi} + */ +@Test(groups = "unit", testName = "GlobalUserApiTest") +public class GlobalUserApiTest extends BaseCloudStackApiTest<GlobalUserApi> { + + HttpRequest createUser = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "createUser") + .addQueryParam("username", "user") + .addQueryParam("account", "account") + .addQueryParam("email", "email%40example.com") + .addQueryParam("password", "hashed-password") + .addQueryParam("firstname", "FirstName") + .addQueryParam("lastname", "LastName").build(); + + public void testCreateAccount() throws Exception { + Invokable<?, ?> method = method(GlobalUserApi.class, "createUser", String.class, String.class, + String.class, String.class, String.class, String.class, CreateUserOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("user", "account", "[email protected]", + "hashed-password", "FirstName", "LastName")); + + assertRequestLineEquals(httpRequest, createUser.getRequestLine()); + 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 testUpdateUser() throws Exception { + Invokable<?, ?> method = method(GlobalUserApi.class, "updateUser", String.class, UpdateUserOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(42L)); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=updateUser&id=42 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 testDeleteUser() throws Exception { + Invokable<?, ?> method = method(GlobalUserApi.class, "deleteUser", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(42L)); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=deleteUser&id=42 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.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/GlobalVlanApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalVlanApiExpectTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalVlanApiExpectTest.java new file mode 100644 index 0000000..6b9a2c7 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalVlanApiExpectTest.java @@ -0,0 +1,169 @@ +/* + * 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.net.URI; + +import org.jclouds.cloudstack.CloudStackContext; +import org.jclouds.cloudstack.domain.VlanIPRange; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; +import org.jclouds.cloudstack.options.CreateVlanIPRangeOptions; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Test the CloudStack VlanClient + */ +@Test(groups = "unit", testName = "GlobalVlanApiExpectTest") +public class GlobalVlanApiExpectTest extends BaseCloudStackExpectTest<GlobalVlanApi> { + + public void testListVlanIpRangesWhenResponseIs2xx() { + GlobalVlanApi client = requestSendsResponse( + HttpRequest.builder() + .method("GET") + .endpoint( + URI.create("http://localhost:8080/client/api?response=json&" + + "command=listVlanIpRanges&listAll=true&apiKey=identity&signature=xPwCeAcMp9kDGbD5oPgztLtSdnU%3D")) + .addHeader("Accept", "application/json") + .build(), + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/listvlaniprangesresponse.json")) + .build()); + + 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(); + + assertEquals(client.listVlanIPRanges(), ImmutableSet.of(range1, range2)); + } + + public void testListVlanIpRangesWhenResponseIs404() { + GlobalVlanApi client = requestSendsResponse( + HttpRequest.builder() + .method("GET") + .endpoint( + URI.create("http://localhost:8080/client/api?response=json&" + + "command=listVlanIpRanges&listAll=true&apiKey=identity&signature=xPwCeAcMp9kDGbD5oPgztLtSdnU%3D")) + .addHeader("Accept", "application/json") + .build(), + HttpResponse.builder() + .statusCode(404) + .build()); + + assertEquals(client.listVlanIPRanges(), ImmutableSet.of()); + } + + public void testCreateVlanIpRangeWhenResponseIs2xx() { + GlobalVlanApi client = requestSendsResponse( + HttpRequest.builder() + .method("GET") + .endpoint( + URI.create("http://localhost:8080/client/api?response=json&" + + "command=createVlanIpRange&startip=10.22.22.51&endip=10.22.22.100&forvirtualnetwork=false&zoneid=2&vlan=untagged&account=system&domainid=1&podid=2&gateway=10.22.22.254&netmask=255.255.255.0&networkid=209&apiKey=identity&signature=XgDjPYAQNLMVCuSMGRA6QjV8mOY%3D")) + .addHeader("Accept", "application/json") + .build(), + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/createvlaniprangeresponse.json")) + .build()); + + VlanIPRange actual = client.createVlanIPRange("10.22.22.51", "10.22.22.100", new CreateVlanIPRangeOptions() + .forVirtualNetwork(false) + .zoneId("2") + .vlan("untagged") + .accountInDomain("system", "1") + .podId("2") + .gateway("10.22.22.254") + .netmask("255.255.255.0") + .networkId("209")); + + VlanIPRange expected = 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(); + + assertEquals(actual, expected); + } + + public void testDeleteVlanIpRangeWhenResponseIs2xx() { + GlobalVlanApi client = requestSendsResponse( + HttpRequest.builder() + .method("GET") + .endpoint( + URI.create("http://localhost:8080/client/api?response=json&" + + "command=deleteVlanIpRange&id=1&apiKey=identity&signature=tTBbpdCndgHXdR397fbbJaN1RZU%3D")) + .addHeader("Accept", "application/json") + .build(), + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/createvlaniprangeresponse.json")) + .build()); + + client.deleteVlanIPRange("1"); + } + + @Override + protected GlobalVlanApi clientFrom(CloudStackContext context) { + return context.getGlobalApi().getVlanClient(); + } +} 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/GlobalVlanApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalVlanApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalVlanApiLiveTest.java new file mode 100644 index 0000000..34fe5be --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalVlanApiLiveTest.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.cloudstack.options.ListNetworksOptions.Builder.zoneId; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.Network; +import org.jclouds.cloudstack.domain.NetworkOffering; +import org.jclouds.cloudstack.domain.TrafficType; +import org.jclouds.cloudstack.domain.VlanIPRange; +import org.jclouds.cloudstack.domain.Zone; +import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest; +import org.jclouds.cloudstack.options.CreateVlanIPRangeOptions; +import org.jclouds.cloudstack.options.ListVlanIPRangesOptions; +import org.jclouds.cloudstack.predicates.NetworkOfferingPredicates; +import org.jclouds.cloudstack.predicates.ZonePredicates; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.base.Strings; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; + +/** + * Tests behavior of {@code GlobalVlanApi} + */ +@Test(groups = "live", singleThreaded = true, testName = "GlobalVlanApiLiveTest") +public class GlobalVlanApiLiveTest extends BaseCloudStackApiLiveTest { + + private Network network; + private boolean usingExistingNetwork; + + private VlanIPRange range; + + @Test + public void testListVlanIPRanges() throws Exception { + skipIfNotGlobalAdmin(); + + Set<VlanIPRange> response = globalAdminClient.getVlanClient().listVlanIPRanges(); + assert null != response; + long rangeCount = response.size(); + assertTrue(rangeCount >= 0); + + for (VlanIPRange range : response) { + VlanIPRange newDetails = Iterables.getOnlyElement(globalAdminClient.getVlanClient().listVlanIPRanges( + ListVlanIPRangesOptions.Builder.id(range.getId()))); + assertEquals(range, newDetails); + assertEquals(range, globalAdminClient.getVlanClient().getVlanIPRange(range.getId())); + assertNull(range.getId()); + assertNull(range.getZoneId()); + assertFalse(Strings.isNullOrEmpty(range.getVlan())); + assertFalse(Strings.isNullOrEmpty(range.getAccount())); + assertNull(range.getDomainId()); + assertFalse(Strings.isNullOrEmpty(range.getDomain())); + assertFalse(Strings.isNullOrEmpty(range.getGateway())); + assertFalse(Strings.isNullOrEmpty(range.getNetmask())); + assertFalse(Strings.isNullOrEmpty(range.getStartIP())); + assertFalse(Strings.isNullOrEmpty(range.getEndIP())); + assertNull(range.getNetworkId()); + } + } + + @Test + public void testCreateVlanIPRange() { + skipIfNotGlobalAdmin(); + + final Zone zone = Iterables.find(client.getZoneApi().listZones(), ZonePredicates.supportsAdvancedNetworks()); + final NetworkOffering offering = Iterables.tryFind(client.getOfferingApi().listNetworkOfferings(), + NetworkOfferingPredicates.supportsGuestVirtualNetworks()).orNull(); + + if (offering != null) { + Set<Network> suitableNetworks = Sets.filter(client.getNetworkApi().listNetworks( + zoneId(zone.getId()).isSystem(false).trafficType(TrafficType.GUEST)), + new Predicate<Network>() { + @Override + public boolean apply(Network network) { + return network.getNetworkOfferingId().equals(offering.getId()); + } + }); + + if (!suitableNetworks.isEmpty()) { + network = Iterables.get(suitableNetworks, 0); + usingExistingNetwork = true; + + } else if (network == null) { + network = client.getNetworkApi().createNetworkInZone(zone.getId(), + offering.getId(), "net-" + prefix, "jclouds test " + prefix); + usingExistingNetwork = false; + } + + range = globalAdminClient.getVlanClient().createVlanIPRange("172.19.1.1", "172.19.1.199", CreateVlanIPRangeOptions.Builder + .accountInDomain(user.getAccount(), user.getDomainId()) + .forVirtualNetwork(true) + .vlan(1001) + .networkId(network.getId()) + ); + } + } + + @AfterGroups(groups = "live") + @Override + protected void tearDownContext() { + if (range != null) { + globalAdminClient.getVlanClient().deleteVlanIPRange(range.getId()); + range = null; + } + if (network != null && !usingExistingNetwork) { + client.getNetworkApi().deleteNetwork(network.getId()); + network = null; + } + super.tearDownContext(); + } + +} 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/GlobalZoneApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalZoneApiExpectTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalZoneApiExpectTest.java new file mode 100644 index 0000000..80364d5 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalZoneApiExpectTest.java @@ -0,0 +1,133 @@ +/* + * 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.UpdateZoneOptions.Builder.name; +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.AllocationState; +import org.jclouds.cloudstack.domain.NetworkType; +import org.jclouds.cloudstack.domain.Zone; +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.ImmutableList; +import com.google.common.collect.ImmutableMultimap; + +/** + * Test the CloudStack GlobalZoneApi + */ +@Test(groups = "unit", testName = "GlobalZoneApiExpectTest") +public class GlobalZoneApiExpectTest extends BaseCloudStackExpectTest<GlobalZoneApi> { + + HttpRequest createZone = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "createZone") + .addQueryParam("name", "test-zone") + .addQueryParam("networktype", "Basic") + .addQueryParam("dns1", "8.8.8.8") + .addQueryParam("internaldns1", "10.10.10.10") + .addQueryParam("apiKey", "identity") + .addQueryParam("signature", "hWNmM2%2BTsfb5DelQa/GJLN5DVWE=") + .addHeader("Accept", "application/json").build(); + + public void testCreateZoneWhenResponseIs2xxAnd404() { + GlobalZoneApi client = requestSendsResponse(createZone, + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/createzoneresponse.json")) + .build()); + + assertEquals(client.createZone("test-zone", NetworkType.BASIC, "8.8.8.8", "10.10.10.10"), + Zone.builder() + .id("6") + .name("test-zone") + .DNS(ImmutableList.of("8.8.8.8")) + .internalDNS(ImmutableList.of("10.10.10.10")) + .networkType(NetworkType.BASIC) + .securityGroupsEnabled(true) + .allocationState(AllocationState.ENABLED) + .zoneToken("7b6e27df-30a6-3024-9d8b-7971a3127f64") + .dhcpProvider("DhcpServer").build()); + + client = requestSendsResponse(createZone, HttpResponse.builder().statusCode(404).build()); + assertNull(client.createZone("test-zone", NetworkType.BASIC, "8.8.8.8", "10.10.10.10")); + } + + public void testUpdateZoneWhenResponseIs2xxAnd404() { + HttpRequest request = HttpRequest.builder() + .method("GET") + .endpoint( + URI.create("http://localhost:8080/client/api?response=json&command=updateZone&" + + "id=6&name=test-zone&dns1=8.8.8.8&apiKey=identity&signature=v19FdHKHztdT0IRloYFFn0eNbWM%3D")) + .headers( + ImmutableMultimap.<String, String>builder() + .put("Accept", "application/json") + .build()) + .build(); + + GlobalZoneApi client = requestSendsResponse(request, + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/updatezoneresponse.json")) + .build()); + + assertEquals(client.updateZone("6", name("test-zone").externalDns(ImmutableList.of("8.8.8.8"))), + Zone.builder() + .id("6") + .name("test-zone") + .DNS(ImmutableList.of("8.8.8.8")) + .internalDNS(ImmutableList.of("10.10.10.10")) + .networkType(NetworkType.BASIC) + .securityGroupsEnabled(true) + .allocationState(AllocationState.ENABLED) + .zoneToken("7b6e27df-30a6-3024-9d8b-7971a3127f64") + .dhcpProvider("DhcpServer").build()); + + client = requestSendsResponse(request, HttpResponse.builder().statusCode(404).build()); + assertNull(client.updateZone("6", name("test-zone").externalDns(ImmutableList.of("8.8.8.8")))); + } + + public void testDeleteZone() { + GlobalZoneApi client = requestSendsResponse( + HttpRequest.builder() + .method("GET") + .endpoint( + URI.create("http://localhost:8080/client/api?response=json&" + + "command=deleteZone&id=6&apiKey=identity&signature=TfkzSIK8kzGJnIYo3DofECyuOII%3D")) + .addHeader("Accept", "application/json") + .build(), + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/deletezoneresponse.json")) + .build()); + + client.deleteZone("6"); + } + + @Override + protected GlobalZoneApi clientFrom(CloudStackContext context) { + return context.getGlobalApi().getZoneApi(); + } +} 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/GlobalZoneApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalZoneApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalZoneApiLiveTest.java new file mode 100644 index 0000000..8e83343 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GlobalZoneApiLiveTest.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.features; + +import static org.jclouds.cloudstack.options.UpdateZoneOptions.Builder.name; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import org.jclouds.cloudstack.domain.NetworkType; +import org.jclouds.cloudstack.domain.Zone; +import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; + +/** + * Tests behavior of {@code GlobalZoneApi} + */ +@Test(groups = "live", singleThreaded = true, testName = "GlobalZoneApiLiveTest") +public class GlobalZoneApiLiveTest extends BaseCloudStackApiLiveTest { + + @Test + public void testCreateUpdateDeleteZone() { + skipIfNotGlobalAdmin(); + + Zone zone = null; + String zoneName = prefix + "-zone"; + try { + zone = globalAdminClient.getZoneApi().createZone(zoneName, + NetworkType.BASIC, "8.8.8.8", "10.10.10.10"); + + assertNotNull(zone); + assertEquals(zone, globalAdminClient.getZoneApi().getZone(zone.getId())); + assertEquals(zone.getNetworkType(), NetworkType.BASIC); + assertEquals(zone.getDNS(), ImmutableList.of("8.8.8.8")); + assertEquals(zone.getInternalDNS(), ImmutableList.of("10.10.10.10")); + + Zone updated = globalAdminClient.getZoneApi().updateZone(zone.getId(), + name(zoneName + "-2").externalDns(ImmutableList.of("8.8.4.4"))); + assertEquals(updated.getId(), zone.getId()); + assertEquals(updated.getDNS(), ImmutableList.of("8.8.4.4")); + + } finally { + if (zone != null) { + globalAdminClient.getZoneApi().deleteZone(zone.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/GuestOSApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GuestOSApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GuestOSApiLiveTest.java new file mode 100644 index 0000000..43c0d3a --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GuestOSApiLiveTest.java @@ -0,0 +1,73 @@ +/* + * 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.Iterables.getOnlyElement; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.jclouds.cloudstack.domain.OSType; +import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest; +import org.jclouds.cloudstack.options.ListOSTypesOptions; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code GuestOSApiLiveTest} + */ +@Test(groups = "live", singleThreaded = true, testName = "GuestOSApiLiveTest") +public class GuestOSApiLiveTest extends BaseCloudStackApiLiveTest { + + public void testListOSTypes() throws Exception { + Set<OSType> response = client.getGuestOSApi().listOSTypes(); + assert null != response; + assertTrue(response.size() >= 0); + for (OSType type : response) { + OSType newDetails = getOnlyElement(client.getGuestOSApi().listOSTypes( + ListOSTypesOptions.Builder.id(type.getId()))); + assertEquals(type.getId(), newDetails.getId()); + checkOSType(type); + } + } + + public void testListOSCategories() throws Exception { + Map<String, String> response = client.getGuestOSApi().listOSCategories(); + assert null != response; + assertTrue(response.size() >= 0); + for (Entry<String, String> category : response.entrySet()) { + checkOSCategory(category); + } + } + + protected void checkOSCategory(Entry<String, String> category) { + assertEquals(category, client.getGuestOSApi().getOSCategory(category.getKey())); + assert category.getKey() != null : category; + assert category.getValue() != null : category; + } + + protected void checkOSType(OSType type) { + assertEquals(type.getId(), client.getGuestOSApi().getOSType(type.getId()).getId()); + assert type.getId() != null : type; + assert type.getOSCategoryId() != null : type; + assert type.getDescription() != null : type; + + } + +} 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/GuestOSApiTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GuestOSApiTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GuestOSApiTest.java new file mode 100644 index 0000000..5f3e657 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/GuestOSApiTest.java @@ -0,0 +1,130 @@ +/* + * 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.ParseIdToNameEntryFromHttpResponse; +import org.jclouds.cloudstack.functions.ParseIdToNameFromHttpResponse; +import org.jclouds.cloudstack.internal.BaseCloudStackApiTest; +import org.jclouds.cloudstack.options.ListOSTypesOptions; +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 GuestOSApi} + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "GuestOSApiTest") +public class GuestOSApiTest extends BaseCloudStackApiTest<GuestOSApi> { + + public void testGetOSCategory() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(GuestOSApi.class, "getOSCategory", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(11l)); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listOsCategories&listAll=true&id=11 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseIdToNameEntryFromHttpResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testListOSCategories() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(GuestOSApi.class, "listOSCategories"); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listOsCategories&listAll=true HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseIdToNameFromHttpResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testGetOSType() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(GuestOSApi.class, "getOSType", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(11l)); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listOsTypes&listAll=true&id=11 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 testListOSTypes() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(GuestOSApi.class, "listOSTypes", ListOSTypesOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listOsTypes&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 testListOSTypesOptions() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(GuestOSApi.class, "listOSTypes", ListOSTypesOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(ListOSTypesOptions.Builder.OSCategoryId("11"))); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listOsTypes&listAll=true&oscategoryid=11 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); + + } +} 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/HypervisorApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/HypervisorApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/HypervisorApiLiveTest.java new file mode 100644 index 0000000..13400fe --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/HypervisorApiLiveTest.java @@ -0,0 +1,43 @@ +/* + * 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.assertTrue; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.Zone; +import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code HypervisorApiLiveTest} + */ +@Test(groups = "live", singleThreaded = true, testName = "HypervisorApiLiveTest") +public class HypervisorApiLiveTest extends BaseCloudStackApiLiveTest { + + public void testListHypervisors() throws Exception { + Set<String> response = client.getHypervisorApi().listHypervisors(); + assert null != response; + assertTrue(response.size() >= 0); + for (Zone zone : client.getZoneApi().listZones()) { + Set<String> zoneHype = client.getHypervisorApi().listHypervisorsInZone(zone.getId()); + assert response.containsAll(zoneHype); + } + } + +} 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/HypervisorApiTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/HypervisorApiTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/HypervisorApiTest.java new file mode 100644 index 0000000..0cc1303 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/HypervisorApiTest.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.jclouds.reflect.Reflection2.method; + +import java.io.IOException; + +import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404; +import org.jclouds.cloudstack.functions.ParseNamesFromHttpResponse; +import org.jclouds.cloudstack.internal.BaseCloudStackApiTest; +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 HypervisorApi} + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "HypervisorApiTest") +public class HypervisorApiTest extends BaseCloudStackApiTest<HypervisorApi> { + + public void testListHypervisors() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(HypervisorApi.class, "listHypervisors"); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listHypervisors&listAll=true HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseNamesFromHttpResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testListHypervisorsInZon() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(HypervisorApi.class, "listHypervisorsInZone", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(11)); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listHypervisors&listAll=true&zoneid=11 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseNamesFromHttpResponse.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/ISOApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ISOApiExpectTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ISOApiExpectTest.java new file mode 100644 index 0000000..ce564a1 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ISOApiExpectTest.java @@ -0,0 +1,221 @@ +/* + * 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.ListISOsOptions.Builder.accountInDomain; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import org.jclouds.cloudstack.CloudStackContext; +import org.jclouds.cloudstack.domain.ISO; +import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; +import org.jclouds.cloudstack.options.RegisterISOOptions; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.rest.ResourceNotFoundException; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Test the CloudStack ISOApi + */ +@Test(groups = "unit", testName = "ISOApiExpectTest") +public class ISOApiExpectTest extends BaseCloudStackExpectTest<ISOApi> { + + private static final ISO iso1 = ISO.builder() + .id("018e0928-8205-4d8e-9329-f731a9ccd488") + .name("xs-tools.iso") + .displayText("xen-pv-drv-iso") + .isPublic(true) + .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-08-21T15:45:01+0530")) + .isReady(true) + .passwordEnabled(false) + .bootable(false) + .isFeatured(true) + .crossZones(false) + .account("system") + .domain("ROOT") + .domainid("9d189ea2-097e-4b2b-9bae-d885f5430d69") + .isExtractable(false).build(); + + private static final ISO iso2 = ISO.builder() + .id("1e29244b-9cf0-4ff2-9978-677eb83f6bfb") + .name("vmware-tools.iso") + .displayText("VMware Tools Installer ISO") + .isPublic(true) + .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-08-21T15:45:01+0530")) + .isReady(true) + .passwordEnabled(false) + .bootable(false) + .isFeatured(true) + .crossZones(false) + .account("system") + .domain("ROOT") + .domainid("9d189ea2-097e-4b2b-9bae-d885f5430d69") + .isExtractable(false).build(); + + HttpRequest listIsos = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "listIsos") + .addQueryParam("listAll", "true") + .addQueryParam("apiKey", "identity") + .addQueryParam("signature", "qUUF6hCDc57Bc/nHriS9umbZBKA%3D") + .addHeader("Accept", "application/json") + .build(); + + public void testListISOsWhenResponseIs2xx() { + ISOApi client = requestSendsResponse(listIsos, + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/listisosresponse.json")) + .build()); + + assertEquals(client.listISOs().toString(), ImmutableSet.of(iso1, iso2).toString()); + } + + public void testListISOsWhenResponseIs404() { + ISOApi client = requestSendsResponse(listIsos, + HttpResponse.builder() + .statusCode(404) + .build()); + + assertEquals(client.listISOs(), ImmutableSet.of()); + } + + HttpRequest listIsosOptions = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "listIsos") + .addQueryParam("listAll", "true") + .addQueryParam("account", "fred") + .addQueryParam("domainid", "5") + .addQueryParam("bootable", "true") + .addQueryParam("hypervisor", "xen") + .addQueryParam("id", "3") + .addQueryParam("isofilter", "featured") + .addQueryParam("ispublic", "true") + .addQueryParam("isready", "true") + .addQueryParam("keyword", "bob") + .addQueryParam("name", "bob%27s%20iso") + .addQueryParam("zoneid", "7") + .addQueryParam("apiKey", "identity") + .addQueryParam("signature", "4S5ustbaBErEnpymWLSj1rEJ/nk%3D") + .addHeader("Accept", "application/json") + .build(); + + public void testListISOsOptionsWhenResponseIs2xx() { + ISOApi client = requestSendsResponse(listIsosOptions, + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/listisosresponse.json")) + .build()); + + assertEquals(client.listISOs(accountInDomain("fred", "5").bootable().hypervisor("xen").id("3").isoFilter(ISO.ISOFilter.featured).isPublic().isReady().keyword("bob").name("bob's iso").zoneId("7")).toString(), ImmutableSet.of(iso1, iso2).toString()); + } + + HttpRequest getIso = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "listIsos") + .addQueryParam("listAll", "true") + .addQueryParam("id", "018e0928-8205-4d8e-9329-f731a9ccd488") + .addQueryParam("apiKey", "identity") + .addQueryParam("signature", "uZyPUJt6ThMDcQSDa%2BEv5LMs%2B2U%3D") + .addHeader("Accept", "application/json") + .build(); + + public void testGetISOWhenResponseIs2xx() { + ISOApi client = requestSendsResponse(getIso, + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/getisoresponse.json")) + .build()); + + assertEquals(client.getISO("018e0928-8205-4d8e-9329-f731a9ccd488").toString(), iso1.toString()); + } + + public void testGetISOWhenResponseIs404() { + ISOApi client = requestSendsResponse(getIso, + HttpResponse.builder() + .statusCode(404) + .build()); + + assertNull(client.getISO("018e0928-8205-4d8e-9329-f731a9ccd488")); + } + + HttpRequest registerIso = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "registerIso") + .addQueryParam("name", "ubuntu10.10") + .addQueryParam("displaytext", "ubuntu 10.10 (32 bit)") + .addQueryParam("url", "http://ubuntu/ubuntu-10.10.iso") + .addQueryParam("zoneid", "1e0335d9-b6cc-4805-bddf-0828e66a0d01") + .addQueryParam("account", "root") + .addQueryParam("domainid", "99f4159b-c698-4bd9-b8c5-5ac462f101eb") + .addQueryParam("bootable", "true") + .addQueryParam("isextractable", "true") + .addQueryParam("isfeatured", "true") + .addQueryParam("ispublic", "true") + .addQueryParam("ostypeid", "1234-abcd") + .addQueryParam("apiKey", "identity") + .addQueryParam("signature", "YpFMYUUu0daLgwxNFubVfkV0Nw8%3D") + .addHeader("Accept", "application/json") + .build(); + + RegisterISOOptions registerISOOptions = RegisterISOOptions.Builder + .accountInDomain("root", "99f4159b-c698-4bd9-b8c5-5ac462f101eb") + .bootable(true).isExtractable(true).isFeatured(true).isPublic(true).osTypeId("1234-abcd"); + + @Test + public void testRegisterISOsWhenResponseIs2xx() { + ISOApi client = requestSendsResponse( + registerIso, + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/registerisoresponse.json")) + .build()); + + assertEquals(client.registerISO("ubuntu10.10", "ubuntu 10.10 (32 bit)", "http://ubuntu/ubuntu-10.10.iso", "1e0335d9-b6cc-4805-bddf-0828e66a0d01", + registerISOOptions), + ISO.builder().id("b52c509d-c6e2-452c-b6ec-aa00720ed6cd").name("ubuntu10.10").displayText("ubuntu 10.10 (32 bit)").isPublic(true) + .isReady(false).bootable(true).isFeatured(false).crossZones(false).osTypeId("0e0335d9-b6cc-4808-bddf-0828e66a0d03") + .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-08-21T15:45:01+0530")) + .osTypeName("Ubuntu 10.10 (32-bit)").account("root").domain("ROOT").domainid("99f4159b-c698-4bd9-b8c5-5ac462f101eb").status("") + .account("admin").zoneId("6f9a2921-b22a-4149-8b71-6ffc275a2177").zoneName("Basic1") + .isExtractable(false).build()); + } + + @Test(expectedExceptions = ResourceNotFoundException.class) + public void testRegisterISOWhenResponseIs404() { + ISOApi client = requestSendsResponse(registerIso, + HttpResponse.builder() + .statusCode(404) + .build()); + + assertNull(client.registerISO("ubuntu10.10", "ubuntu 10.10 (32 bit)", "http://ubuntu/ubuntu-10.10.iso", "1e0335d9-b6cc-4805-bddf-0828e66a0d01", + registerISOOptions)); + } + + @Override + protected ISOApi clientFrom(CloudStackContext context) { + return context.getApi().getISOApi(); + } +} 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/ISOApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ISOApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ISOApiLiveTest.java new file mode 100644 index 0000000..93e6c01 --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ISOApiLiveTest.java @@ -0,0 +1,108 @@ +/* + * 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.ListZonesOptions.Builder.available; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.ISO; +import org.jclouds.cloudstack.domain.ISOPermissions; +import org.jclouds.cloudstack.domain.OSType; +import org.jclouds.cloudstack.domain.Zone; +import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest; +import org.jclouds.cloudstack.options.DeleteISOOptions; +import org.jclouds.cloudstack.options.ListISOsOptions; +import org.jclouds.cloudstack.options.RegisterISOOptions; +import org.testng.SkipException; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +import com.google.common.base.Optional; +import com.google.common.base.Predicates; +import com.google.common.collect.Iterables; + +/** + * Tests behavior of {@link ISOApi} and {@link ISOApi} + */ +@Test(groups = "live", singleThreaded = true, testName = "ISOApiLiveTest") +public class ISOApiLiveTest extends BaseCloudStackApiLiveTest { + + private static final String isoName = "jcloudsTestISO"; + private static final String url = System.getProperty("test.cloudstack.iso-url", "http://archive.ubuntu.com/ubuntu/dists/maverick/main/installer-i386/current/images/netboot/mini.iso"); + + public void testListPublicISOs() throws Exception { + Set<ISO> response = client.getISOApi().listISOs(ListISOsOptions.Builder.isPublic()); + assertNotNull(response); + assertFalse(response.isEmpty()); + long isoCount = response.size(); + assertTrue(isoCount >= 0); + + for (ISO iso : response) { + ISO query = client.getISOApi().getISO(iso.getId()); + assertEquals(query.getId(), iso.getId()); + } + } + + public void testListISOPermissions() throws Exception { + Set<ISO> response = client.getISOApi().listISOs(ListISOsOptions.Builder.isPublic()); + assertNotNull(response); + assertFalse(response.isEmpty()); + long isoCount = response.size(); + assertTrue(isoCount >= 0); + + for (ISO iso : response) { + ISOPermissions perms = client.getISOApi().listISOPermissions(iso.getId()); + assertNotNull(perms); + } + } + + public void testRegisterISO() throws Exception { + Optional<OSType> guestOSTypeOptional = Iterables.tryFind(client.getGuestOSApi().listOSTypes(), Predicates.notNull()); + Optional<Zone> zoneOptional = Iterables.tryFind(client.getZoneApi().listZones(available(true)), Predicates.notNull()); + if (guestOSTypeOptional.isPresent() && zoneOptional.isPresent()) { + String osTypeId = guestOSTypeOptional.get().getId(); + String zoneId = zoneOptional.get().getId(); + ISO iso = client.getISOApi().registerISO(isoName, "", url, zoneId, RegisterISOOptions.Builder.isPublic(true).osTypeId(osTypeId)); + assertNotNull(iso); + assertNotNull(iso.getId()); + assertEquals(iso.getName(), isoName); + } else { + String skipMessage = String.format("Cannot register the iso with url: %s", url); + if (zoneOptional.isPresent()) + skipMessage += " without a valid zone"; + else + skipMessage += " without a valid guest OS type"; + throw new SkipException(skipMessage); + } + } + + @AfterClass + @Override + protected void tearDownContext() { + Set<ISO> isos = client.getISOApi().listISOs(ListISOsOptions.Builder.name(isoName)); + for (ISO iso : isos) { + client.getISOApi().deleteISO(iso.getId(), DeleteISOOptions.NONE); + } + super.tearDownContext(); + } + +} 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/ISOApiTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ISOApiTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ISOApiTest.java new file mode 100644 index 0000000..ef5cf8c --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/ISOApiTest.java @@ -0,0 +1,279 @@ +/* + * 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.cloudstack.domain.ExtractMode; +import org.jclouds.cloudstack.domain.PermissionOperation; +import org.jclouds.cloudstack.internal.BaseCloudStackApiTest; +import org.jclouds.cloudstack.options.AccountInDomainOptions; +import org.jclouds.cloudstack.options.DeleteISOOptions; +import org.jclouds.cloudstack.options.ExtractISOOptions; +import org.jclouds.cloudstack.options.UpdateISOOptions; +import org.jclouds.cloudstack.options.UpdateISOPermissionsOptions; +import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions; +import org.jclouds.http.HttpRequest; +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.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.Invokable; +/** + * Tests the behaviour of ISOApi. + * + * @see ISOApi + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +@Test(groups = "unit", testName = "ISOApiTest") +public class ISOApiTest extends BaseCloudStackApiTest<ISOApi> { + + public void testAttachISO() throws NoSuchMethodException { + Invokable<?, ?> method = method(ISOApi.class, "attachISO", String.class, String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("3", "5")); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=attachIso&id=3&virtualmachineid=5 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 testDetachISO() throws NoSuchMethodException { + Invokable<?, ?> method = method(ISOApi.class, "detachISO", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(3)); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=detachIso&virtualmachineid=3 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 testUpdateISO() throws NoSuchMethodException { + Invokable<?, ?> method = method(ISOApi.class, "updateISO", String.class, UpdateISOOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(3)); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=updateIso&id=3 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 testUpdateISOOptions() throws NoSuchMethodException { + Invokable<?, ?> method = method(ISOApi.class, "updateISO", String.class, UpdateISOOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(3, UpdateISOOptions.Builder.bootable(true).displayText("robert").format("format").name("bob").osTypeId("9").passwordEnabled(true))); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=updateIso&id=3&bootable=true&displaytext=robert&format=format&name=bob&ostypeid=9&passwordenabled=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, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + } + + public void testDeleteISO() throws NoSuchMethodException { + Invokable<?, ?> method = method(ISOApi.class, "deleteISO", String.class, DeleteISOOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(3)); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=deleteIso&id=3 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 testDeleteISOOptions() throws NoSuchMethodException { + Invokable<?, ?> method = method(ISOApi.class, "deleteISO", String.class, DeleteISOOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(3, DeleteISOOptions.Builder.zoneId("5"))); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=deleteIso&id=3&zoneid=5 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); + } + + HttpRequest copyIso = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "copyIso") + .addQueryParam("id", "3") + .addQueryParam("sourcezoneid", "5") + .addQueryParam("destzoneid", "7") + .build(); + + public void testCopyISO() throws NoSuchMethodException { + Invokable<?, ?> method = method(ISOApi.class, "copyISO", String.class, String.class, String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(3, 5, 7)); + + assertRequestLineEquals(httpRequest, copyIso.getRequestLine()); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + } + + public void testUpdateISOPermissions() throws NoSuchMethodException { + Invokable<?, ?> method = method(ISOApi.class, "updateISOPermissions", String.class, UpdateISOPermissionsOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(3)); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=updateIsoPermissions&id=3 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + } + + public void testUpdateISOPermissionsOptions() throws NoSuchMethodException { + Invokable<?, ?> method = method(ISOApi.class, "updateISOPermissions", String.class, UpdateISOPermissionsOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(3, UpdateISOPermissionsOptions.Builder.accounts(ImmutableSet.<String>of("fred", "bob")).isExtractable(true).isFeatured(true).isPublic(true).operation(PermissionOperation.add))); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=updateIsoPermissions&id=3&accounts=fred,bob&isextractable=true&isfeatured=true&ispublic=true&op=add HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + } + + public void testListISOPermissions() throws NoSuchMethodException { + Invokable<?, ?> method = method(ISOApi.class, "listISOPermissions", String.class, AccountInDomainOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(3)); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listIsoPermissions&listAll=true&id=3 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); + } + + public void testListISOPermissionsOptions() throws NoSuchMethodException { + Invokable<?, ?> method = method(ISOApi.class, "listISOPermissions", String.class, AccountInDomainOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(3, AccountInDomainOptions.Builder.accountInDomain("fred", "5"))); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listIsoPermissions&listAll=true&id=3&account=fred&domainid=5 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); + } + + HttpRequest extractIso = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "extractIso") + .addQueryParam("id", "3") + .addQueryParam("mode", "HTTP_DOWNLOAD") + .addQueryParam("zoneid", "5") + .build(); + + public void testExtractISO() throws NoSuchMethodException { + Invokable<?, ?> method = method(ISOApi.class, "extractISO", String.class, ExtractMode.class, String.class, ExtractISOOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(3, ExtractMode.HTTP_DOWNLOAD, 5)); + + assertRequestLineEquals(httpRequest, extractIso.getRequestLine()); + 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); + } + + HttpRequest extractIsoOptions = HttpRequest.builder().method("GET") + .endpoint("http://localhost:8080/client/api") + .addQueryParam("response", "json") + .addQueryParam("command", "extractIso") + .addQueryParam("id", "3") + .addQueryParam("mode", "HTTP_DOWNLOAD") + .addQueryParam("zoneid", "5") + .addQueryParam("url", "http://example.com/") + .build(); + + public void testExtractISOOptions() throws NoSuchMethodException { + Invokable<?, ?> method = method(ISOApi.class, "extractISO", String.class, ExtractMode.class, String.class, ExtractISOOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(3, ExtractMode.HTTP_DOWNLOAD, 5, ExtractISOOptions.Builder.url("http://example.com/"))); + + assertRequestLineEquals(httpRequest, extractIsoOptions.getRequestLine()); + 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); + } +} 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/LimitApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/LimitApiLiveTest.java b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/LimitApiLiveTest.java new file mode 100644 index 0000000..06749cc --- /dev/null +++ b/dependencies/jclouds/apis/cloudstack/1.8.0-stratos/src/test/java/org/jclouds/cloudstack/features/LimitApiLiveTest.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.features; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.ResourceLimit; +import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code LimitApi} + */ +@Test(groups = "live", singleThreaded = true, testName = "LimitApiLiveTest") +public class LimitApiLiveTest extends BaseCloudStackApiLiveTest { + + public void testListResourceLimits() { + final Set<ResourceLimit> resourceLimits = client.getLimitApi().listResourceLimits(); + + for (ResourceLimit resourceLimit : resourceLimits) { + checkResourceLimit(resourceLimit); + } + } + + private void checkResourceLimit(ResourceLimit resourceLimit) { + assert resourceLimit.getAccount() != null : resourceLimit; + assert resourceLimit.getDomain() != null : resourceLimit; + assert resourceLimit.getResourceType() != ResourceLimit.ResourceType.UNRECOGNIZED : resourceLimit; + } +}
