From 98f00a81dde423a0133daa0fe46dcacc3c3eb861 Mon Sep 17 00:00:00 2001 From: Everett Toews Date: Thu, 17 Jan 2013 13:03:44 -0600 Subject: [PATCH] Changed return types on remove methods and minor naming fixes. --- .../features/AccessRuleApi.java | 18 ++++++++++----- .../features/AccessRuleAsyncApi.java | 18 +++++++-------- .../features/AccessRuleApiExpectTest.java | 23 ++++++++++--------- .../features/AccessRuleApiLiveTest.java | 8 +++---- 4 files changed, 37 insertions(+), 30 deletions(-) diff --git a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/AccessRuleApi.java b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/AccessRuleApi.java index 9f3947e8b8..fd020adbe7 100644 --- a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/AccessRuleApi.java +++ b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/AccessRuleApi.java @@ -31,14 +31,14 @@ import org.jclouds.rackspace.cloudloadbalancers.domain.AccessRuleWithId; */ public interface AccessRuleApi { /** - * Create a new access list or append to an existing access list. + * Create new access rules or append to existing access rules. * - * When creating an access list, one or more AccessRules are required. If a populated access list already exists + * When creating access rules, one or more AccessRules are required. If populated access rules already exist * for the load balancer, it will be appended to with subsequent creates. One access list may include up to 100 * AccessRules. A single address or subnet definition is considered unique and cannot be duplicated between rules * in an access list. */ - void create(Iterable accessList); + void create(Iterable accessRules); /** * List the AccessRules @@ -47,16 +47,22 @@ public interface AccessRuleApi { /** * Remove an access rule from the access list. + * + * @return true on a successful removal, false if the access rule was not found */ - void remove(int id); + boolean remove(int id); /** * Batch delete the access rules given the specified ids. + * + * @return true on a successful removal, false if the access rule was not found */ - void remove(Iterable ids); + boolean remove(Iterable ids); /** * Remove the entire access list. + * + * @return true on a successful removal, false if the access rule was not found */ - void removeAll(); + boolean removeAll(); } \ No newline at end of file diff --git a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/AccessRuleAsyncApi.java b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/AccessRuleAsyncApi.java index 7285173483..6a04de594f 100644 --- a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/AccessRuleAsyncApi.java +++ b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/AccessRuleAsyncApi.java @@ -28,7 +28,7 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404; -import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.Fallbacks.FalseOnNotFoundOr404; import org.jclouds.Fallbacks.VoidOnNotFoundOr404; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; import org.jclouds.rackspace.cloudloadbalancers.domain.AccessRule; @@ -55,9 +55,9 @@ public interface AccessRuleAsyncApi { */ @POST @Consumes(MediaType.APPLICATION_JSON) - @Fallback(NullOnNotFoundOr404.class) + @Fallback(VoidOnNotFoundOr404.class) @Path("/accesslist") - ListenableFuture create(@WrapWith("accessList") Iterable accessList); + ListenableFuture create(@WrapWith("accessList") Iterable accessRules); /** * @see AccessRuleApi#list() @@ -73,26 +73,26 @@ public interface AccessRuleAsyncApi { * @see AccessRuleApi#remove(int) */ @DELETE - @Fallback(VoidOnNotFoundOr404.class) + @Fallback(FalseOnNotFoundOr404.class) @Path("/accesslist/{id}") @Consumes("*/*") - ListenableFuture remove(@PathParam("id") int id); + ListenableFuture remove(@PathParam("id") int id); /** * @see AccessRuleApi#remove(Iterable) */ @DELETE - @Fallback(VoidOnNotFoundOr404.class) + @Fallback(FalseOnNotFoundOr404.class) @Path("/accesslist") @Consumes("*/*") - ListenableFuture remove(@QueryParam("id") Iterable ids); + ListenableFuture remove(@QueryParam("id") Iterable ids); /** * @see AccessRuleApi#removeAll() */ @DELETE - @Fallback(VoidOnNotFoundOr404.class) + @Fallback(FalseOnNotFoundOr404.class) @Path("/accesslist") @Consumes("*/*") - ListenableFuture removeAll(); + ListenableFuture removeAll(); } diff --git a/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/AccessRuleApiExpectTest.java b/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/AccessRuleApiExpectTest.java index f665b58da1..bb01c24855 100644 --- a/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/AccessRuleApiExpectTest.java +++ b/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/AccessRuleApiExpectTest.java @@ -19,6 +19,7 @@ package org.jclouds.rackspace.cloudloadbalancers.features; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; import java.net.URI; import java.util.List; @@ -39,7 +40,7 @@ import com.google.common.collect.ImmutableList; */ @Test(groups = "unit") public class AccessRuleApiExpectTest extends BaseCloudLoadBalancerApiExpectTest { - public void testListAccessList() { + public void testListAccessRules() { URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/accesslist"); AccessRuleApi api = requestsSendResponses( rackspaceAuthWithUsernameAndApiKey, @@ -49,10 +50,10 @@ public class AccessRuleApiExpectTest extends BaseCloudLoadBalancerApiExpectTest< ).getAccessRuleApiForZoneAndLoadBalancer("DFW", 2000); Iterable accessList = api.list(); - assertEquals(accessList, getAccessList()); + assertEquals(accessList, getAccessRules()); } - public void testCreateAccessList() { + public void testCreateAccessRules() { URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/accesslist"); AccessRuleApi api = requestsSendResponses( rackspaceAuthWithUsernameAndApiKey, @@ -78,7 +79,7 @@ public class AccessRuleApiExpectTest extends BaseCloudLoadBalancerApiExpectTest< HttpResponse.builder().statusCode(200).build() ).getAccessRuleApiForZoneAndLoadBalancer("DFW", 2000); - api.remove(23); + assertTrue(api.remove(23)); } public void testRemoveManyAccessRules() { @@ -91,7 +92,7 @@ public class AccessRuleApiExpectTest extends BaseCloudLoadBalancerApiExpectTest< ).getAccessRuleApiForZoneAndLoadBalancer("DFW", 2000); List accessRuleIds = ImmutableList. of(23, 24); - api.remove(accessRuleIds); + assertTrue(api.remove(accessRuleIds)); } public void testRemoveAllAccessRules() { @@ -103,14 +104,14 @@ public class AccessRuleApiExpectTest extends BaseCloudLoadBalancerApiExpectTest< HttpResponse.builder().statusCode(200).build() ).getAccessRuleApiForZoneAndLoadBalancer("DFW", 2000); - api.removeAll(); + assertTrue(api.removeAll()); } - private Iterable getAccessList() { - AccessRule accessRule1 = new AccessRuleWithId(23, "206.160.163.21", AccessRule.Type.DENY); - AccessRule accessRule2 = new AccessRuleWithId(24, "206.160.165.11", AccessRule.Type.DENY); - AccessRule accessRule3 = new AccessRuleWithId(25, "206.160.163.22", AccessRule.Type.DENY); + private Iterable getAccessRules() { + AccessRuleWithId accessRule1 = new AccessRuleWithId(23, "206.160.163.21", AccessRule.Type.DENY); + AccessRuleWithId accessRule2 = new AccessRuleWithId(24, "206.160.165.11", AccessRule.Type.DENY); + AccessRuleWithId accessRule3 = new AccessRuleWithId(25, "206.160.163.22", AccessRule.Type.DENY); - return ImmutableList. of(accessRule1, accessRule2, accessRule3); + return ImmutableList. of(accessRule1, accessRule2, accessRule3); } } diff --git a/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/AccessRuleApiLiveTest.java b/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/AccessRuleApiLiveTest.java index 10543e09af..9815bf70b7 100644 --- a/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/AccessRuleApiLiveTest.java +++ b/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/AccessRuleApiLiveTest.java @@ -76,7 +76,7 @@ public class AccessRuleApiLiveTest extends BaseCloudLoadBalancersApiLiveTest { LoadBalancerRequest lbRequest = LoadBalancerRequest.builder() .name(prefix+"-jclouds").protocol("HTTP").port(80).virtualIPType(Type.PUBLIC).node(nodeRequest).build(); - zone = Iterables.getFirst(clbApi.getConfiguredZones(), null); + zone = "ORD";//Iterables.getFirst(clbApi.getConfiguredZones(), null); lb = clbApi.getLoadBalancerApiForZone(zone).create(lbRequest); assertTrue(awaitAvailable(clbApi.getLoadBalancerApiForZone(zone)).apply(lb)); @@ -96,7 +96,7 @@ public class AccessRuleApiLiveTest extends BaseCloudLoadBalancersApiLiveTest { AccessRuleWithId removedAccessRule = Iterables.getFirst(actualAccessList, null); accessRules.remove(removedAccessRule.getAddress()); - clbApi.getAccessRuleApiForZoneAndLoadBalancer(zone, lb.getId()).remove(removedAccessRule.getId()); + assertTrue(clbApi.getAccessRuleApiForZoneAndLoadBalancer(zone, lb.getId()).remove(removedAccessRule.getId())); assertTrue(awaitAvailable(clbApi.getLoadBalancerApiForZone(zone)).apply(lb)); assertExpectedAccessRules(accessRules); @@ -111,7 +111,7 @@ public class AccessRuleApiLiveTest extends BaseCloudLoadBalancersApiLiveTest { accessRules.remove(removedAccessRule1.getAddress()); accessRules.remove(removedAccessRule2.getAddress()); - clbApi.getAccessRuleApiForZoneAndLoadBalancer(zone, lb.getId()).remove(removedAccessRuleIds); + assertTrue(clbApi.getAccessRuleApiForZoneAndLoadBalancer(zone, lb.getId()).remove(removedAccessRuleIds)); assertTrue(awaitAvailable(clbApi.getLoadBalancerApiForZone(zone)).apply(lb)); assertExpectedAccessRules(accessRules); @@ -119,7 +119,7 @@ public class AccessRuleApiLiveTest extends BaseCloudLoadBalancersApiLiveTest { @Test(dependsOnMethods = "testRemoveManyAccessRules") public void testRemoveAllAccessRules() throws Exception { - clbApi.getAccessRuleApiForZoneAndLoadBalancer(zone, lb.getId()).removeAll(); + assertTrue(clbApi.getAccessRuleApiForZoneAndLoadBalancer(zone, lb.getId()).removeAll()); assertTrue(awaitAvailable(clbApi.getLoadBalancerApiForZone(zone)).apply(lb)); assertExpectedAccessRules(new HashMap());