From 7a60ce579b03f272f99990041ac406c9aa388ec4 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Wed, 21 Dec 2011 18:10:41 +0000 Subject: [PATCH] Added stub ISO live test and ListISOsOptions minor refactoring --- .../cloudstack/options/ListISOsOptions.java | 101 ++++++++--- .../features/ISOAsyncClientTest.java | 2 +- .../features/ISOClientLiveTest.java | 42 +++++ .../options/ListISOsOptionsTest.java | 161 ++++++++++++++++++ 4 files changed, 278 insertions(+), 28 deletions(-) create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ISOClientLiveTest.java create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListISOsOptionsTest.java diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListISOsOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListISOsOptions.java index 9ec41646c7..f3fdef4633 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListISOsOptions.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListISOsOptions.java @@ -22,6 +22,8 @@ import org.jclouds.cloudstack.domain.ISO; import com.google.common.collect.ImmutableSet; +import java.util.Set; + /** * Options for the ISO listISOs method. * @@ -30,14 +32,24 @@ import com.google.common.collect.ImmutableSet; * @author Richard Downer */ public class ListISOsOptions extends AccountInDomainOptions { - public static final ListISOsOptions NONE = new ListISOsOptions(); + private static final Set TRUE = ImmutableSet.of(Boolean.toString(true)); + private static final Set FALSE = ImmutableSet.of(Boolean.toString(false)); + /** - * @param bootable true if the ISO is bootable, false otherwise + * the ISO is bootable */ - public ListISOsOptions bootable(boolean bootable) { - this.queryParameters.replaceValues("bootable", ImmutableSet.of(bootable + "")); + public ListISOsOptions bootable() { + this.queryParameters.replaceValues("bootable", TRUE); + return this; + } + + /** + * the ISO is bootable + */ + public ListISOsOptions notBootable() { + this.queryParameters.replaceValues("bootable", FALSE); return this; } @@ -45,7 +57,7 @@ public class ListISOsOptions extends AccountInDomainOptions { * @param hypervisor the hypervisor for which to restrict the search */ public ListISOsOptions hypervisor(String hypervisor) { - this.queryParameters.replaceValues("hypervisor", ImmutableSet.of(hypervisor + "")); + this.queryParameters.replaceValues("hypervisor", ImmutableSet.of(hypervisor)); return this; } @@ -53,7 +65,7 @@ public class ListISOsOptions extends AccountInDomainOptions { * @param id list all isos by id */ public ListISOsOptions id(long id) { - this.queryParameters.replaceValues("id", ImmutableSet.of(id + "")); + this.queryParameters.replaceValues("id", ImmutableSet.of(Long.toString(id))); return this; } @@ -61,23 +73,39 @@ public class ListISOsOptions extends AccountInDomainOptions { * @param isoFilter possible values are "featured", "self", "self-executable","executable", and "community". */ public ListISOsOptions isoFilter(ISO.ISOFilter isoFilter) { - this.queryParameters.replaceValues("isofilter", ImmutableSet.of(isoFilter + "")); + this.queryParameters.replaceValues("isofilter", ImmutableSet.of(isoFilter.name())); return this; } /** - * @param isPublic true if the ISO is publicly available to all users, false otherwise. + * the ISO is publicly available to all users */ - public ListISOsOptions isPublic(boolean isPublic) { - this.queryParameters.replaceValues("ispublic", ImmutableSet.of(isPublic + "")); + public ListISOsOptions isPublic() { + this.queryParameters.replaceValues("ispublic", TRUE); return this; } /** - * @param isReady true if this ISO is ready to be deployed + * the ISO is not publicly available to all users */ - public ListISOsOptions isReady(boolean isReady) { - this.queryParameters.replaceValues("isready", ImmutableSet.of(isReady + "")); + public ListISOsOptions isPrivate() { + this.queryParameters.replaceValues("ispublic", FALSE); + return this; + } + + /** + * this ISO is ready to be deployed + */ + public ListISOsOptions isReady() { + this.queryParameters.replaceValues("isready", TRUE); + return this; + } + + /** + * this ISO is not ready to be deployed + */ + public ListISOsOptions isNotReady() { + this.queryParameters.replaceValues("isready", FALSE); return this; } @@ -85,7 +113,7 @@ public class ListISOsOptions extends AccountInDomainOptions { * @param keyword List by keyword */ public ListISOsOptions keyword(String keyword) { - this.queryParameters.replaceValues("keyword", ImmutableSet.of(keyword + "")); + this.queryParameters.replaceValues("keyword", ImmutableSet.of(keyword)); return this; } @@ -93,7 +121,7 @@ public class ListISOsOptions extends AccountInDomainOptions { * @param name list all isos by name */ public ListISOsOptions name(String name) { - this.queryParameters.replaceValues("name", ImmutableSet.of(name + "")); + this.queryParameters.replaceValues("name", ImmutableSet.of(name)); return this; } @@ -101,12 +129,11 @@ public class ListISOsOptions extends AccountInDomainOptions { * @param zoneId the ID of the zone */ public ListISOsOptions zoneId(long zoneId) { - this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId + "")); + this.queryParameters.replaceValues("zoneid", ImmutableSet.of(Long.toString(zoneId))); return this; } public static class Builder { - /** * @param account the account of the ISO file. Must be used with the domainId parameter. */ @@ -115,10 +142,17 @@ public class ListISOsOptions extends AccountInDomainOptions { } /** - * @param bootable true if the ISO is bootable, false otherwise + * the ISO is bootable */ - public static ListISOsOptions bootable(boolean bootable) { - return new ListISOsOptions().bootable(bootable); + public static ListISOsOptions bootable() { + return new ListISOsOptions().bootable(); + } + + /** + * the ISO is bootable + */ + public static ListISOsOptions notBootable() { + return new ListISOsOptions().notBootable(); } /** @@ -150,17 +184,31 @@ public class ListISOsOptions extends AccountInDomainOptions { } /** - * @param isPublic true if the ISO is publicly available to all users, false otherwise. + * the ISO is publicly available to all users */ - public static ListISOsOptions isPublic(boolean isPublic) { - return new ListISOsOptions().isPublic(isPublic); + public static ListISOsOptions isPublic() { + return new ListISOsOptions().isPublic(); } /** - * @param isReady true if this ISO is ready to be deployed + * the ISO is not publicly available to all users */ - public static ListISOsOptions isReady(boolean isReady) { - return new ListISOsOptions().isReady(isReady); + public static ListISOsOptions isPrivate() { + return new ListISOsOptions().isPrivate(); + } + + /** + * this ISO is ready to be deployed + */ + public static ListISOsOptions isReady() { + return new ListISOsOptions().isReady(); + } + + /** + * this ISO is not ready to be deployed + */ + public static ListISOsOptions isNotReady() { + return new ListISOsOptions().isNotReady(); } /** @@ -184,5 +232,4 @@ public class ListISOsOptions extends AccountInDomainOptions { return new ListISOsOptions().zoneId(zoneId); } } - } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ISOAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ISOAsyncClientTest.java index 0a987dac12..a617baff7a 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ISOAsyncClientTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/ISOAsyncClientTest.java @@ -115,7 +115,7 @@ public class ISOAsyncClientTest extends BaseCloudStackAsyncClientTest response = client.getISOClient().listISOs(ListISOsOptions.Builder.isPublic()); + assertNotNull(response); + assertFalse(response.isEmpty()); + } +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListISOsOptionsTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListISOsOptionsTest.java new file mode 100644 index 0000000000..530052749b --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListISOsOptionsTest.java @@ -0,0 +1,161 @@ +/** + * 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 com.google.common.collect.ImmutableSet; +import org.jclouds.cloudstack.domain.ISO; +import org.jclouds.cloudstack.domain.TemplateFilter; +import org.testng.annotations.Test; + +import java.util.Set; + +import static org.jclouds.cloudstack.options.ListISOsOptions.Builder.*; +import static org.testng.Assert.assertEquals; + +/** + * Tests behavior of {@link ListISOsOptions} + * + * @author grkvlt@apache.org + */ +@Test(groups = "unit") +public class ListISOsOptionsTest { + private static final Set TRUE = ImmutableSet.of(Boolean.toString(true)); + private static final Set FALSE = ImmutableSet.of(Boolean.toString(false)); + + public void testBootable() { + ListISOsOptions options = new ListISOsOptions().bootable(); + assertEquals(options.buildQueryParameters().get("bootable"), TRUE); + } + + public void testBootableStatic() { + ListISOsOptions options = bootable(); + assertEquals(options.buildQueryParameters().get("bootable"), TRUE); + } + + public void testNotBootable() { + ListISOsOptions options = new ListISOsOptions().notBootable(); + assertEquals(options.buildQueryParameters().get("bootable"), FALSE); + } + + public void testNotBootableStatic() { + ListISOsOptions options = notBootable(); + assertEquals(options.buildQueryParameters().get("bootable"), FALSE); + } + + public void testHypervisor() { + ListISOsOptions options = new ListISOsOptions().hypervisor("KVM"); + assertEquals(options.buildQueryParameters().get("hypervisor"), ImmutableSet.of("KVM")); + } + + public void testHypervisorStatic() { + ListISOsOptions options = hypervisor("KVM"); + assertEquals(options.buildQueryParameters().get("hypervisor"), ImmutableSet.of("KVM")); + } + + public void testId() { + ListISOsOptions options = new ListISOsOptions().id(6); + assertEquals(options.buildQueryParameters().get("id"), ImmutableSet.of("6")); + } + + public void testIdStatic() { + ListISOsOptions options = id(6); + assertEquals(options.buildQueryParameters().get("id"), ImmutableSet.of("6")); + } + + public void testISOFilter() { + ListISOsOptions options = new ListISOsOptions().isoFilter(ISO.ISOFilter.community); + assertEquals(options.buildQueryParameters().get("isofilter"), ImmutableSet.of(ISO.ISOFilter.community.name())); + } + + public void testISOFilterStatic() { + ListISOsOptions options = isoFilter(ISO.ISOFilter.community); + assertEquals(options.buildQueryParameters().get("isofilter"), ImmutableSet.of(ISO.ISOFilter.community.name())); + } + + public void testIsPublic() { + ListISOsOptions options = new ListISOsOptions().isPublic(); + assertEquals(options.buildQueryParameters().get("ispublic"), TRUE); + } + + public void testIsPublicStatic() { + ListISOsOptions options = isPublic(); + assertEquals(options.buildQueryParameters().get("ispublic"), TRUE); + } + + public void testIsPrivate() { + ListISOsOptions options = new ListISOsOptions().isPrivate(); + assertEquals(options.buildQueryParameters().get("ispublic"), FALSE); + } + + public void testIsPrivateStatic() { + ListISOsOptions options = isPrivate(); + assertEquals(options.buildQueryParameters().get("ispublic"), FALSE); + } + + public void testIsReady() { + ListISOsOptions options = new ListISOsOptions().isReady(); + assertEquals(options.buildQueryParameters().get("isready"), TRUE); + } + + public void testIsReadyStatic() { + ListISOsOptions options = isReady(); + assertEquals(options.buildQueryParameters().get("isready"), TRUE); + } + + public void testIsNotReady() { + ListISOsOptions options = new ListISOsOptions().isNotReady(); + assertEquals(options.buildQueryParameters().get("isready"), FALSE); + } + + public void testIsNotReadyStatic() { + ListISOsOptions options = isNotReady(); + assertEquals(options.buildQueryParameters().get("isready"), FALSE); + } + + public void testKeyword() { + ListISOsOptions options = new ListISOsOptions().keyword("text"); + assertEquals(options.buildQueryParameters().get("keyword"), ImmutableSet.of("text")); + } + + public void testKeywordStatic() { + ListISOsOptions options = keyword("text"); + assertEquals(options.buildQueryParameters().get("keyword"), ImmutableSet.of("text")); + } + + public void testName() { + ListISOsOptions options = new ListISOsOptions().name("text"); + assertEquals(options.buildQueryParameters().get("name"), ImmutableSet.of("text")); + } + + public void testNameStatic() { + ListISOsOptions options = name("text"); + assertEquals(options.buildQueryParameters().get("name"), ImmutableSet.of("text")); + } + + public void testZoneId() { + ListISOsOptions options = new ListISOsOptions().zoneId(6); + assertEquals(ImmutableSet.of("6"), options.buildQueryParameters().get("zoneid")); + } + + public void testZoneIdStatic() { + ListISOsOptions options = zoneId(6); + assertEquals(ImmutableSet.of("6"), options.buildQueryParameters().get("zoneid")); + } +}