From ec46da8b594f37855eab3c686baf448b842d43f2 Mon Sep 17 00:00:00 2001 From: Richard Downer Date: Wed, 14 Dec 2011 15:13:10 +0000 Subject: [PATCH] Add ListStoragePoolsOptions + test --- .../options/ListStoragePoolsOptions.java | 119 ++++++++++++++++++ .../options/ListStoragePoolsOptionsTest.java | 115 +++++++++++++++++ 2 files changed, 234 insertions(+) create mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListStoragePoolsOptions.java create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListStoragePoolsOptionsTest.java diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListStoragePoolsOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListStoragePoolsOptions.java new file mode 100644 index 0000000000..a8657e10e7 --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListStoragePoolsOptions.java @@ -0,0 +1,119 @@ +/** + * 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.http.options.BaseHttpRequestOptions; + +/** + * Options to the GlobalStoragePools[Async]Client.listStoragePools API call + * + * @author Richard Downer + */ +public class ListStoragePoolsOptions extends BaseHttpRequestOptions { + + public static ListStoragePoolsOptions NONE = new ListStoragePoolsOptions(); + + public static class Builder { + + private Builder() {} + + public static ListStoragePoolsOptions clusterId(long clusterId) { + ListStoragePoolsOptions options = new ListStoragePoolsOptions(); + return options.clusterId(clusterId); + } + + public static ListStoragePoolsOptions id(long id) { + ListStoragePoolsOptions options = new ListStoragePoolsOptions(); + return options.id(id); + } + + public static ListStoragePoolsOptions ipAddress(String ipAddress) { + ListStoragePoolsOptions options = new ListStoragePoolsOptions(); + return options.ipAddress(ipAddress); + } + + public static ListStoragePoolsOptions keyword(String keyword) { + ListStoragePoolsOptions options = new ListStoragePoolsOptions(); + return options.keyword(keyword); + } + + public static ListStoragePoolsOptions name(String name) { + ListStoragePoolsOptions options = new ListStoragePoolsOptions(); + return options.name(name); + } + + public static ListStoragePoolsOptions path(String path) { + ListStoragePoolsOptions options = new ListStoragePoolsOptions(); + return options.path(path); + } + + public static ListStoragePoolsOptions podId(long podId) { + ListStoragePoolsOptions options = new ListStoragePoolsOptions(); + return options.podId(podId); + } + + public static ListStoragePoolsOptions zoneId(long zoneId) { + ListStoragePoolsOptions options = new ListStoragePoolsOptions(); + return options.zoneId(zoneId); + } + } + + ListStoragePoolsOptions() {} + + public ListStoragePoolsOptions clusterId(long clusterId) { + this.queryParameters.replaceValues("clusterid", ImmutableSet.of(clusterId + "")); + return this; + } + + public ListStoragePoolsOptions id(long id) { + this.queryParameters.replaceValues("id", ImmutableSet.of(id + "")); + return this; + } + + public ListStoragePoolsOptions ipAddress(String ipAddress) { + this.queryParameters.replaceValues("ipaddress", ImmutableSet.of(ipAddress)); + return this; + } + + public ListStoragePoolsOptions keyword(String keyword) { + this.queryParameters.replaceValues("keyword", ImmutableSet.of(keyword)); + return this; + } + + public ListStoragePoolsOptions name(String name) { + this.queryParameters.replaceValues("name", ImmutableSet.of(name)); + return this; + } + public ListStoragePoolsOptions path(String path) { + this.queryParameters.replaceValues("path", ImmutableSet.of(path)); + return this; + } + + public ListStoragePoolsOptions podId(long podId) { + this.queryParameters.replaceValues("podid", ImmutableSet.of(podId + "")); + return this; + } + + public ListStoragePoolsOptions zoneId(long zoneId) { + this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId + "")); + return this; + } + +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListStoragePoolsOptionsTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListStoragePoolsOptionsTest.java new file mode 100644 index 0000000000..38eb811bbf --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListStoragePoolsOptionsTest.java @@ -0,0 +1,115 @@ +/** + * 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.testng.annotations.Test; + +import static org.jclouds.cloudstack.options.ListStoragePoolsOptions.Builder.*; +import static org.testng.Assert.assertEquals; + +/** + * Test for the ListStoragePoolsOptions class. + * + * @author Richard Downer + */ +@Test(groups = "unit") +public class ListStoragePoolsOptionsTest { + + public void testClusterId() { + ListStoragePoolsOptions options = new ListStoragePoolsOptions().clusterId(14); + assertEquals(ImmutableList.of(14 + ""), options.buildQueryParameters().get("clusterid")); + } + + public void testClusterIdStatic() { + ListStoragePoolsOptions options = clusterId(14); + assertEquals(ImmutableList.of(14 + ""), options.buildQueryParameters().get("clusterid")); + } + + public void testId() { + ListStoragePoolsOptions options = new ListStoragePoolsOptions().id(15); + assertEquals(ImmutableList.of(15 + ""), options.buildQueryParameters().get("id")); + } + + public void testIdStatic() { + ListStoragePoolsOptions options = id(15); + assertEquals(ImmutableList.of(15 + ""), options.buildQueryParameters().get("id")); + } + + public void testIpAddress() { + ListStoragePoolsOptions options = new ListStoragePoolsOptions().ipAddress("192.168.42.42"); + assertEquals(ImmutableList.of("192.168.42.42"), options.buildQueryParameters().get("ipaddress")); + } + + public void testIpAddressStatic() { + ListStoragePoolsOptions options = ipAddress("192.168.42.42"); + assertEquals(ImmutableList.of("192.168.42.42"), options.buildQueryParameters().get("ipaddress")); + } + + public void testKeyword() { + ListStoragePoolsOptions options = new ListStoragePoolsOptions().keyword("fred"); + assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("keyword")); + } + + public void testKeywordStatic() { + ListStoragePoolsOptions options = keyword("fred"); + assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("keyword")); + } + + public void testName() { + ListStoragePoolsOptions options = new ListStoragePoolsOptions().name("bob"); + assertEquals(ImmutableList.of("bob"), options.buildQueryParameters().get("name")); + } + + public void testNameStatic() { + ListStoragePoolsOptions options = name("bob"); + assertEquals(ImmutableList.of("bob"), options.buildQueryParameters().get("name")); + } + + public void testPath() { + ListStoragePoolsOptions options = new ListStoragePoolsOptions().path("/foo/bar"); + assertEquals(ImmutableList.of("/foo/bar"), options.buildQueryParameters().get("path")); + } + + public void testPathStatic() { + ListStoragePoolsOptions options = path("/foo/bar"); + assertEquals(ImmutableList.of("/foo/bar"), options.buildQueryParameters().get("path")); + } + + public void testPodId() { + ListStoragePoolsOptions options = new ListStoragePoolsOptions().podId(16); + assertEquals(ImmutableList.of(16 + ""), options.buildQueryParameters().get("podid")); + } + + public void testPodIdStatic() { + ListStoragePoolsOptions options = podId(16); + assertEquals(ImmutableList.of(16 + ""), options.buildQueryParameters().get("podid")); + } + + public void testZoneId() { + ListStoragePoolsOptions options = new ListStoragePoolsOptions().zoneId(17); + assertEquals(ImmutableList.of(17 + ""), options.buildQueryParameters().get("zoneid")); + } + + public void testZoneIdStatic() { + ListStoragePoolsOptions options = zoneId(17); + assertEquals(ImmutableList.of(17 + ""), options.buildQueryParameters().get("zoneid")); + } + +}