From adf1ebb7c5df717f560d8e8d97424e22ef3b426e Mon Sep 17 00:00:00 2001 From: andreisavu Date: Sun, 11 Dec 2011 11:36:57 +0200 Subject: [PATCH] Completed ListHostsOptions with unit tests --- .../cloudstack/options/ListHostsOptions.java | 198 +++++++++++++++++- .../options/ListHostsOptionsTest.java | 166 +++++++++++++++ 2 files changed, 353 insertions(+), 11 deletions(-) create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListHostsOptionsTest.java diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListHostsOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListHostsOptions.java index 342d9d2328..6550ffed21 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListHostsOptions.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListHostsOptions.java @@ -24,22 +24,110 @@ import org.jclouds.cloudstack.domain.TrafficType; /** * Options used to control what hosts information is returned - * + * + * @author Andrei Savu * @see - * @author Andrei Savu */ public class ListHostsOptions extends AccountInDomainOptions { public static final ListHostsOptions NONE = new ListHostsOptions(); /** - * @param isDefault - * true if network is default, false otherwise + * @param id the id of the host */ - public ListHostsOptions isDefault(boolean isDefault) { - this.queryParameters.replaceValues("isdefault", ImmutableSet.of(isDefault + "")); + public ListHostsOptions id(long id) { + this.queryParameters.replaceValues("id", ImmutableSet.of(id + "")); + return this; + } + + /** + * @param allocationState list hosts by allocation state + */ + public ListHostsOptions allocationState(String allocationState) { + this.queryParameters.replaceValues("allocationstate", ImmutableSet.of(allocationState)); + return this; + } + + /** + * @param clusterId lists hosts existing in particular cluster + */ + public ListHostsOptions clusterId(long clusterId) { + this.queryParameters.replaceValues("clusterid", ImmutableSet.of(clusterId + "")); + return this; + } + + /** + * @param keyword List by keyword + */ + public ListHostsOptions keyword(String keyword) { + this.queryParameters.replaceValues("keyword", ImmutableSet.of(keyword)); + return this; + } + + /** + * @param name List by name + */ + public ListHostsOptions name(String name) { + this.queryParameters.replaceValues("name", ImmutableSet.of(name)); + return this; + } + + /** + * @param page + */ + public ListHostsOptions page(long page) { + this.queryParameters.replaceValues("page", ImmutableSet.of(page + "")); + return this; + } + + /** + * @param pageSize the page size + */ + public ListHostsOptions pageSize(long pageSize) { + this.queryParameters.replaceValues("pagesize", ImmutableSet.of(pageSize + "")); + return this; + } + + /** + * @param podId the Pod ID for the host + */ + public ListHostsOptions podId(long podId) { + this.queryParameters.replaceValues("podid", ImmutableSet.of(podId + "")); + return this; + } + + /** + * @param state the state of the host + */ + public ListHostsOptions state(String state) { + this.queryParameters.replaceValues("state", ImmutableSet.of(state)); + return this; + } + + /** + * @param type the type of the host + */ + public ListHostsOptions type(String type) { + this.queryParameters.replaceValues("type", ImmutableSet.of(type)); + return this; + } + + /** + * @param virtualMachineId lists hosts in the same cluster as this VM and flag hosts with + * enough CPU/RAm to host this VM + */ + public ListHostsOptions virtualMachineId(long virtualMachineId) { + this.queryParameters.replaceValues("virtualmachineid", ImmutableSet.of(virtualMachineId + "")); + return this; + } + + /** + * @param zoneId the Zone ID for the host + */ + public ListHostsOptions zoneId(long zoneId) { + this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId + "")); return this; } @@ -61,15 +149,103 @@ public class ListHostsOptions extends AccountInDomainOptions { public static class Builder { /** - * @see org.jclouds.cloudstack.options.ListHostsOptions#isDefault + * @see ListHostsOptions#id */ - public static ListHostsOptions isDefault(boolean isDefault) { + public static ListHostsOptions id(long id) { ListHostsOptions options = new ListHostsOptions(); - return options.isDefault(isDefault); + return options.id(id); } /** - * @see org.jclouds.cloudstack.options.ListHostsOptions#accountInDomain + * @see ListHostsOptions#allocationState + */ + public static ListHostsOptions allocationState(String allocationState) { + ListHostsOptions options = new ListHostsOptions(); + return options.allocationState(allocationState); + } + + /** + * @see ListHostsOptions#clusterId + */ + public static ListHostsOptions clusterId(long clusterId) { + ListHostsOptions options = new ListHostsOptions(); + return options.clusterId(clusterId); + } + + /** + * @see ListHostsOptions#keyword(String) + */ + public static ListHostsOptions keyword(String keyword) { + ListHostsOptions options = new ListHostsOptions(); + return options.keyword(keyword); + } + + /** + * @see ListHostsOptions#name(String) + */ + public static ListHostsOptions name(String name) { + ListHostsOptions options = new ListHostsOptions(); + return options.name(name); + } + + /** + * @see ListHostsOptions#page + */ + public static ListHostsOptions page(long page) { + ListHostsOptions options = new ListHostsOptions(); + return options.page(page); + } + + /** + * @see ListHostsOptions#pageSize + */ + public static ListHostsOptions pageSize(long pageSize) { + ListHostsOptions options = new ListHostsOptions(); + return options.pageSize(pageSize); + } + + /** + * @see ListHostsOptions#podId + */ + public static ListHostsOptions podId(long podId) { + ListHostsOptions options = new ListHostsOptions(); + return options.podId(podId); + } + + /** + * @see ListHostsOptions#state + */ + public static ListHostsOptions state(String state) { + ListHostsOptions options = new ListHostsOptions(); + return options.state(state); + } + + /** + * @see ListHostsOptions#type + */ + public static ListHostsOptions type(String type) { + ListHostsOptions options = new ListHostsOptions(); + return options.type(type); + } + + /** + * @see ListHostsOptions#virtualMachineId + */ + public static ListHostsOptions virtualMachineId(long virtualMachineId) { + ListHostsOptions options = new ListHostsOptions(); + return options.virtualMachineId(virtualMachineId); + } + + /** + * @see ListHostsOptions#zoneId + */ + public static ListHostsOptions zoneId(long zoneId) { + ListHostsOptions options = new ListHostsOptions(); + return options.zoneId(zoneId); + } + + /** + * @see ListHostsOptions#accountInDomain */ public static ListHostsOptions accountInDomain(String account, long domain) { ListHostsOptions options = new ListHostsOptions(); @@ -77,7 +253,7 @@ public class ListHostsOptions extends AccountInDomainOptions { } /** - * @see org.jclouds.cloudstack.options.ListHostsOptions#domainId + * @see ListHostsOptions#domainId */ public static ListHostsOptions domainId(long domainId) { ListHostsOptions options = new ListHostsOptions(); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListHostsOptionsTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListHostsOptionsTest.java new file mode 100644 index 0000000000..77f934162e --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListHostsOptionsTest.java @@ -0,0 +1,166 @@ +/** + * 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.ListHostsOptions.Builder.allocationState; +import static org.jclouds.cloudstack.options.ListHostsOptions.Builder.clusterId; +import static org.jclouds.cloudstack.options.ListHostsOptions.Builder.id; +import static org.jclouds.cloudstack.options.ListHostsOptions.Builder.keyword; +import static org.jclouds.cloudstack.options.ListHostsOptions.Builder.name; +import static org.jclouds.cloudstack.options.ListHostsOptions.Builder.page; +import static org.jclouds.cloudstack.options.ListHostsOptions.Builder.pageSize; +import static org.jclouds.cloudstack.options.ListHostsOptions.Builder.podId; +import static org.jclouds.cloudstack.options.ListHostsOptions.Builder.state; +import static org.jclouds.cloudstack.options.ListHostsOptions.Builder.type; +import static org.jclouds.cloudstack.options.ListHostsOptions.Builder.virtualMachineId; +import static org.jclouds.cloudstack.options.ListHostsOptions.Builder.zoneId; +import static org.testng.Assert.assertEquals; + +/** + * Tests behavior of {@code ListHostsOptions} + * + * @author Andrei Savu + */ +@Test(groups = "unit") +public class ListHostsOptionsTest { + + public void testId() { + ListHostsOptions options = new ListHostsOptions().id(42L); + assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("id")); + } + + public void testIdStatic() { + ListHostsOptions options = id(42L); + assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("id")); + } + + public void testAllocationState() { + ListHostsOptions options = new ListHostsOptions().allocationState("Enabled"); + assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("allocationstate")); + } + + public void testAllocationStateStatic() { + ListHostsOptions options = allocationState("Enabled"); + assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("allocationstate")); + } + + public void testClusterId() { + ListHostsOptions options = new ListHostsOptions().clusterId(42L); + assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("clusterid")); + } + + public void testClusterIdStatic() { + ListHostsOptions options = clusterId(42L); + assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("clusterid")); + } + + public void testKeyword() { + ListHostsOptions options = new ListHostsOptions().keyword("Enabled"); + assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("keyword")); + } + + public void testKeywordStatic() { + ListHostsOptions options = keyword("Enabled"); + assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("keyword")); + } + + public void testName() { + ListHostsOptions options = new ListHostsOptions().name("Host Name"); + assertEquals(ImmutableList.of("Host Name"), options.buildQueryParameters().get("name")); + } + + public void testNameStatic() { + ListHostsOptions options = name("Host Name"); + assertEquals(ImmutableList.of("Host Name"), options.buildQueryParameters().get("name")); + } + + public void testPage() { + ListHostsOptions options = new ListHostsOptions().page(42L); + assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("page")); + } + + public void testPageStatic() { + ListHostsOptions options = page(42L); + assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("page")); + } + + public void testPageSize() { + ListHostsOptions options = new ListHostsOptions().pageSize(42L); + assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("pagesize")); + } + + public void testPageSizeStatic() { + ListHostsOptions options = pageSize(42L); + assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("pagesize")); + } + + public void testPodId() { + ListHostsOptions options = new ListHostsOptions().podId(42L); + assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("podid")); + } + + public void testPodIdStatic() { + ListHostsOptions options = podId(42L); + assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("podid")); + } + + public void testState() { + ListHostsOptions options = new ListHostsOptions().state("Up"); + assertEquals(ImmutableList.of("Up"), options.buildQueryParameters().get("state")); + } + + public void testStateStatic() { + ListHostsOptions options = state("Up"); + assertEquals(ImmutableList.of("Up"), options.buildQueryParameters().get("state")); + } + + public void testType() { + ListHostsOptions options = new ListHostsOptions().type("Routing"); + assertEquals(ImmutableList.of("Routing"), options.buildQueryParameters().get("type")); + } + + public void testTypeStatic() { + ListHostsOptions options = type("Routing"); + assertEquals(ImmutableList.of("Routing"), options.buildQueryParameters().get("type")); + } + + public void testVirtualMachineId() { + ListHostsOptions options = new ListHostsOptions().virtualMachineId(42L); + assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("virtualmachineid")); + } + + public void testVirtualMachineIdStatic() { + ListHostsOptions options = virtualMachineId(42L); + assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("virtualmachineid")); + } + + public void testZoneId() { + ListHostsOptions options = new ListHostsOptions().zoneId(42L); + assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("zoneid")); + } + + public void testZoneIdStatic() { + ListHostsOptions options = zoneId(42L); + assertEquals(ImmutableList.of("42"), options.buildQueryParameters().get("zoneid")); + } + +}