From dea284fbb3ab1bda3148ea4db806e3b9157b0753 Mon Sep 17 00:00:00 2001 From: Richard Downer Date: Wed, 18 Jan 2012 11:17:55 +0000 Subject: [PATCH] Add listPods API call, with supporting Pod domain object and unit tests. --- .../org/jclouds/cloudstack/domain/Pod.java | 270 ++++++++++++++++++ .../features/GlobalPodAsyncClient.java | 39 ++- .../cloudstack/features/GlobalPodClient.java | 21 ++ .../cloudstack/options/ListPodsOptions.java | 83 ++++++ .../features/GlobalPodClientExpectTest.java | 72 +++++ .../features/GlobalPodClientLiveTest.java | 31 ++ .../options/ListPodsOptionsTest.java | 86 ++++++ .../parse/ListPodsResponseTest.java | 72 +++++ .../src/test/resources/listpodsresponse.json | 1 + 9 files changed, 673 insertions(+), 2 deletions(-) create mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Pod.java create mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListPodsOptions.java create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListPodsOptionsTest.java create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPodsResponseTest.java create mode 100644 apis/cloudstack/src/test/resources/listpodsresponse.json diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Pod.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Pod.java new file mode 100644 index 0000000000..2b46bbc8ac --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Pod.java @@ -0,0 +1,270 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.cloudstack.domain; + +import com.google.gson.annotations.SerializedName; + +/** + * Represents a Pod in CloudStack. + * + * @author Richard Downer + */ +public class Pod implements Comparable { + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private long id; + private String name; + private long zoneId; + private String zoneName; + private String gateway; + private String netmask; + private String startIp; + private String endIp; + private AllocationState allocationState; + + private Builder() {} + + /** + * @param id the ID of the Pod + */ + public Builder id(long id) { + this.id = id; + return this; + } + + /** + * @param name the name of the Pod + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @param zoneId the Zone ID of the Pod + */ + public Builder zoneId(long zoneId) { + this.zoneId = zoneId; + return this; + } + + /** + * @param zoneName the Zone name of the Pod + */ + public Builder zoneName(String zoneName) { + this.zoneName = zoneName; + return this; + } + + /** + * @param gateway the gateway of the Pod + */ + public Builder gateway(String gateway) { + this.gateway = gateway; + return this; + } + + /** + * @param netmask the netmask of the Pod + */ + public Builder netmask(String netmask) { + this.netmask = netmask; + return this; + } + + /** + * @param startIp the starting IP for the Pod + */ + public Builder startIp(String startIp) { + this.startIp = startIp; + return this; + } + + /** + * @param endIp the ending IP for the Pod + */ + public Builder endIp(String endIp) { + this.endIp = endIp; + return this; + } + + /** + * @param allocationState the allocation state of the cluster + */ + public Builder allocationState(AllocationState allocationState) { + this.allocationState = allocationState; + return this; + } + + /** + * Build the Pod object + * @return the Pod object + */ + public Pod build() { + return new Pod(id, name, zoneId, zoneName, gateway, netmask, startIp, endIp, allocationState); + } + } + + private long id; + private String name; + @SerializedName("zoneid") private long zoneId; + @SerializedName("zonename") private String zoneName; + private String gateway; + private String netmask; + @SerializedName("startip") private String startIp; + @SerializedName("endip") private String endIp; + @SerializedName("allocationstate") private AllocationState allocationState; + + /* Just for the serializer */ + Pod() {} + + public Pod(long id, String name, long zoneId, String zoneName, String gateway, String netmask, String startIp, String endIp, AllocationState allocationState) { + this.id = id; + this.name = name; + this.zoneId = zoneId; + this.zoneName = zoneName; + this.gateway = gateway; + this.netmask = netmask; + this.startIp = startIp; + this.endIp = endIp; + this.allocationState = allocationState; + } + + /** + * @return id the ID of the Pod + */ + public long getId() { + return id; + } + + /** + * @return name the name of the Pod + */ + public String getName() { + return name; + } + + /** + * @return zoneId the Zone ID of the Pod + */ + public long getZoneId() { + return zoneId; + } + + /** + * @return zoneName the Zone name of the Pod + */ + public String getZoneName() { + return zoneName; + } + + /** + * @return gateway the gateway of the Pod + */ + public String getGateway() { + return gateway; + } + + /** + * @return netmask the netmask of the Pod + */ + public String getNetmask() { + return netmask; + } + + /** + * @return startIp the starting IP for the Pod + */ + public String getStartIp() { + return startIp; + } + + /** + * @return endIp the ending IP for the Pod + */ + public String getEndIp() { + return endIp; + } + + /** + * @param allocationState the allocation state of the cluster + */ + public AllocationState getAllocationState() { + return allocationState; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Pod pod = (Pod) o; + + if (id != pod.id) return false; + if (zoneId != pod.zoneId) return false; + if (allocationState != pod.allocationState) return false; + if (endIp != null ? !endIp.equals(pod.endIp) : pod.endIp != null) return false; + if (gateway != null ? !gateway.equals(pod.gateway) : pod.gateway != null) return false; + if (name != null ? !name.equals(pod.name) : pod.name != null) return false; + if (netmask != null ? !netmask.equals(pod.netmask) : pod.netmask != null) return false; + if (startIp != null ? !startIp.equals(pod.startIp) : pod.startIp != null) return false; + if (zoneName != null ? !zoneName.equals(pod.zoneName) : pod.zoneName != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + result = 31 * result + (int) (zoneId ^ (zoneId >>> 32)); + result = 31 * result + (zoneName != null ? zoneName.hashCode() : 0); + result = 31 * result + (gateway != null ? gateway.hashCode() : 0); + result = 31 * result + (netmask != null ? netmask.hashCode() : 0); + result = 31 * result + (startIp != null ? startIp.hashCode() : 0); + result = 31 * result + (endIp != null ? endIp.hashCode() : 0); + result = 31 * result + (allocationState != null ? allocationState.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "Pod{" + + "id=" + id + + ", name='" + name + '\'' + + ", zoneId=" + zoneId + + ", zoneName='" + zoneName + '\'' + + ", gateway='" + gateway + '\'' + + ", netmask='" + netmask + '\'' + + ", startIp='" + startIp + '\'' + + ", endIp='" + endIp + '\'' + + ", allocationState=" + allocationState + + '}'; + } + + @Override + public int compareTo(Pod other) { + return Long.valueOf(this.id).compareTo(other.id); + } +} diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalPodAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalPodAsyncClient.java index 6a36eb7b2f..6fe4d09b25 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalPodAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalPodAsyncClient.java @@ -18,15 +18,29 @@ */ package org.jclouds.cloudstack.features; +import com.google.common.util.concurrent.ListenableFuture; +import org.jclouds.cloudstack.domain.Pod; import org.jclouds.cloudstack.filters.QuerySigner; +import org.jclouds.cloudstack.options.ListPodsOptions; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.OnlyElement; import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SelectJson; +import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import java.util.Set; /** - * Provides asynchronous access to CloudStack Account features available to Global + * Provides asynchronous access to CloudStack Pod features available to Global * Admin users. * - * @author Adrian Cole, Andrei Savu + * @author Richard Downer * @see @@ -35,4 +49,25 @@ import org.jclouds.rest.annotations.RequestFilters; @QueryParams(keys = "response", values = "json") public interface GlobalPodAsyncClient { + /** + * @see PodClient#listPods + */ + @GET + @QueryParams(keys = "command", values = "listPods") + @SelectJson("pod") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + ListenableFuture> listPods(ListPodsOptions... options); + + /** + * @see PodClient#getPod + */ + @GET + @QueryParams(keys = "command", values = "listPods") + @SelectJson("pod") + @OnlyElement + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getPod(@QueryParam("id") long id); + } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalPodClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalPodClient.java index 864994b66f..eed13f0da7 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalPodClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalPodClient.java @@ -18,8 +18,11 @@ */ package org.jclouds.cloudstack.features; +import org.jclouds.cloudstack.domain.Pod; +import org.jclouds.cloudstack.options.ListPodsOptions; import org.jclouds.concurrent.Timeout; +import java.util.Set; import java.util.concurrent.TimeUnit; /** @@ -34,4 +37,22 @@ import java.util.concurrent.TimeUnit; @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface GlobalPodClient { + /** + * Lists pods + * + * @param options + * if present, how to constrain the list. + * @return pods matching query, or empty set, if no pods are found + */ + Set listPods(ListPodsOptions... options); + + /** + * get a specific pod by id + * + * @param id + * pod to get + * @return pod or null if not found + */ + Pod getPod(long id); + } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListPodsOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListPodsOptions.java new file mode 100644 index 0000000000..4bd746f1a7 --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListPodsOptions.java @@ -0,0 +1,83 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.options; + +import com.google.common.collect.ImmutableSet; +import org.jclouds.cloudstack.domain.AllocationState; +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Options to the GlobalPodClient.listPods API call. + * + * @author Richard Downer + */ +public class ListPodsOptions extends BaseHttpRequestOptions { + + public static final ListPodsOptions NONE = new ListPodsOptions(); + + public static class Builder { + + public static ListPodsOptions allocationState(AllocationState allocationState) { + return new ListPodsOptions().allocationState(allocationState); + } + + public static ListPodsOptions id(long id) { + return new ListPodsOptions().id(id); + } + + public static ListPodsOptions keyword(String keyword) { + return new ListPodsOptions().keyword(keyword); + } + + public static ListPodsOptions name(String name) { + return new ListPodsOptions().name(name); + } + + public static ListPodsOptions zoneId(long zoneId) { + return new ListPodsOptions().zoneId(zoneId); + } + + } + + public ListPodsOptions allocationState(AllocationState allocationState) { + this.queryParameters.replaceValues("allocationstate", ImmutableSet.of(allocationState.toString())); + return this; + } + + public ListPodsOptions id(long id) { + this.queryParameters.replaceValues("id", ImmutableSet.of(id + "")); + return this; + } + + public ListPodsOptions keyword(String keyword) { + this.queryParameters.replaceValues("keyword", ImmutableSet.of(keyword)); + return this; + } + + public ListPodsOptions name(String name) { + this.queryParameters.replaceValues("name", ImmutableSet.of(name)); + return this; + } + + public ListPodsOptions zoneId(long zoneId) { + this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId + "")); + return this; + } + +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalPodClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalPodClientExpectTest.java index 508f3f5768..230d41bc4e 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalPodClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalPodClientExpectTest.java @@ -18,9 +18,19 @@ */ package org.jclouds.cloudstack.features; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; import org.jclouds.cloudstack.CloudStackContext; +import org.jclouds.cloudstack.domain.AllocationState; +import org.jclouds.cloudstack.domain.Pod; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; import org.testng.annotations.Test; +import java.net.URI; + +import static org.testng.Assert.assertEquals; + /** * Test the CloudStack PodClient * @@ -29,6 +39,68 @@ import org.testng.annotations.Test; @Test(groups = "unit", testName = "GlobalPodClientExpectTest") public class GlobalPodClientExpectTest extends BaseCloudStackRestClientExpectTest { + public void testListPodsWhenResponseIs2xx() { + GlobalPodClient client = requestSendsResponse( + HttpRequest.builder() + .method("GET") + .endpoint( + URI.create("http://localhost:8080/client/api?response=json&" + + "command=listPods&apiKey=identity&signature=asx1px2NQkW4R44%2FDgdozuu9wQg%3D")) + .headers( + ImmutableMultimap.builder() + .put("Accept", "application/json") + .build()) + .build(), + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/listpodsresponse.json")) + .build()); + + 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(); + + assertEquals(client.listPods(), ImmutableSet.of(pod1, pod2)); + } + + public void testListPodsWhenResponseIs404() { + GlobalPodClient client = requestSendsResponse( + HttpRequest.builder() + .method("GET") + .endpoint( + URI.create("http://localhost:8080/client/api?response=json&" + + "command=listPods&apiKey=identity&signature=asx1px2NQkW4R44%2FDgdozuu9wQg%3D")) + .headers( + ImmutableMultimap.builder() + .put("Accept", "application/json") + .build()) + .build(), + HttpResponse.builder() + .statusCode(404) + .build()); + + assertEquals(client.listPods(), ImmutableSet.of()); + } + @Override protected GlobalPodClient clientFrom(CloudStackContext context) { return context.getGlobalContext().getApi().getPodClient(); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalPodClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalPodClientLiveTest.java index 8b28dc42c9..a4200fe899 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalPodClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalPodClientLiveTest.java @@ -18,8 +18,17 @@ */ package org.jclouds.cloudstack.features; +import com.google.common.base.Strings; +import com.google.common.collect.Iterables; +import org.jclouds.cloudstack.domain.AllocationState; +import org.jclouds.cloudstack.domain.Pod; +import org.jclouds.cloudstack.options.ListPodsOptions; import org.testng.annotations.Test; +import java.util.Set; + +import static org.testng.Assert.*; + /** * Tests behavior of {@code GlobalPodClient} * @@ -28,4 +37,26 @@ import org.testng.annotations.Test; @Test(groups = "live", singleThreaded = true, testName = "GlobalPodClientLiveTest") public class GlobalPodClientLiveTest extends BaseCloudStackClientLiveTest { + public void testListPods() throws Exception { + Set response = globalAdminClient.getPodClient().listPods(); + assert null != response; + long podCount = response.size(); + assertTrue(podCount >= 0); + for (Pod pod : response) { + Pod newDetails = Iterables.getOnlyElement(globalAdminClient.getPodClient().listPods( + ListPodsOptions.Builder.id(pod.getId()))); + assertEquals(pod, newDetails); + assertEquals(pod, globalAdminClient.getPodClient().getPod(pod.getId())); + assertFalse(pod.getId() <= 0); + assertFalse(Strings.isNullOrEmpty(pod.getName())); + assertFalse(pod.getZoneId() <= 0); + assertFalse(Strings.isNullOrEmpty(pod.getZoneName())); + assertFalse(Strings.isNullOrEmpty(pod.getGateway())); + assertFalse(Strings.isNullOrEmpty(pod.getNetmask())); + assertFalse(Strings.isNullOrEmpty(pod.getStartIp())); + assertFalse(Strings.isNullOrEmpty(pod.getEndIp())); + assertNotEquals(pod.getAllocationState(), AllocationState.UNKNOWN); + } + } + } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListPodsOptionsTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListPodsOptionsTest.java new file mode 100644 index 0000000000..eedab15236 --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListPodsOptionsTest.java @@ -0,0 +1,86 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.options; + +import com.google.common.collect.ImmutableList; +import org.jclouds.cloudstack.domain.AllocationState; +import org.testng.annotations.Test; + +import static org.jclouds.cloudstack.options.ListPodsOptions.Builder.*; +import static org.testng.Assert.assertEquals; + +/** + * Tests behavior of {@code ListPodsOptions} + * + * @author Richard Downer + */ +@Test(groups = "unit") +public class ListPodsOptionsTest { + + public void testId() { + ListPodsOptions options = new ListPodsOptions().id(6); + assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("id")); + } + + public void testIdStatic() { + ListPodsOptions options = id(6); + assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("id")); + } + + public void testAllocationState() { + ListPodsOptions options = new ListPodsOptions().allocationState(AllocationState.ENABLED); + assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("allocationstate")); + } + + public void testAllocationStateStatic() { + ListPodsOptions options = allocationState(AllocationState.ENABLED); + assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("allocationstate")); + } + + public void testKeyword() { + ListPodsOptions options = new ListPodsOptions().keyword("fred"); + assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("keyword")); + } + + public void testKeywordStatic() { + ListPodsOptions options = keyword("fred"); + assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("keyword")); + } + + public void testName() { + ListPodsOptions options = new ListPodsOptions().name("bob"); + assertEquals(ImmutableList.of("bob"), options.buildQueryParameters().get("name")); + } + + public void testNameStatic() { + ListPodsOptions options = name("bob"); + assertEquals(ImmutableList.of("bob"), options.buildQueryParameters().get("name")); + } + + public void testZoneId() { + ListPodsOptions options = new ListPodsOptions().zoneId(6); + assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("zoneid")); + } + + public void testZoneIdStatic() { + ListPodsOptions options = zoneId(6); + assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("zoneid")); + } + +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPodsResponseTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPodsResponseTest.java new file mode 100644 index 0000000000..31696db210 --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPodsResponseTest.java @@ -0,0 +1,72 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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 com.google.common.collect.ImmutableSet; +import org.jclouds.cloudstack.domain.AllocationState; +import org.jclouds.cloudstack.domain.Host; +import org.jclouds.cloudstack.domain.NetworkType; +import org.jclouds.cloudstack.domain.Pod; +import org.jclouds.cloudstack.domain.Zone; +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import java.util.Set; + +/** + * + * @author Richard Downer + */ +@Test(groups = "unit") +public class ListPodsResponseTest extends BaseSetParserTest { + + @Override + public String resource() { + return "/listpodsresponse.json"; + } + + @Override + @SelectJson("pod") + public Set 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); + } +} diff --git a/apis/cloudstack/src/test/resources/listpodsresponse.json b/apis/cloudstack/src/test/resources/listpodsresponse.json new file mode 100644 index 0000000000..9b63799f7b --- /dev/null +++ b/apis/cloudstack/src/test/resources/listpodsresponse.json @@ -0,0 +1 @@ +{ "listpodsresponse" : { "count":2 ,"pod" : [ {"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":"Enabled"}, {"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":"Enabled"} ] } } \ No newline at end of file