Repository: jclouds-labs-google Updated Branches: refs/heads/master 7348f0117 -> 81b4351b3
Added ForwardingRule to AggregatedListApi. Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/commit/81b4351b Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/tree/81b4351b Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/diff/81b4351b Branch: refs/heads/master Commit: 81b4351b362564b0392ba409f563b016a668198d Parents: 7348f01 Author: Daniel Broudy <[email protected]> Authored: Mon Nov 24 15:39:07 2014 -0800 Committer: Adrian Cole <[email protected]> Committed: Tue Nov 25 10:52:49 2014 -0800 ---------------------------------------------------------------------- .../features/AggregatedListApi.java | 51 +++++++++++++++++ .../features/AggregatedListApiLiveTest.java | 18 ++++++ .../features/AggregatedListApiMockTest.java | 20 +++++++ .../aggregated_forwarding_rule_list.json | 60 ++++++++++++++++++++ .../aggregated_forwarding_rule_list_empty.json | 55 ++++++++++++++++++ 5 files changed, 204 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/81b4351b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/AggregatedListApi.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/AggregatedListApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/AggregatedListApi.java index ae56592..de12f51 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/AggregatedListApi.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/AggregatedListApi.java @@ -32,6 +32,7 @@ import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; import org.jclouds.googlecomputeengine.domain.Address; import org.jclouds.googlecomputeengine.domain.Disk; import org.jclouds.googlecomputeengine.domain.DiskType; +import org.jclouds.googlecomputeengine.domain.ForwardingRule; import org.jclouds.googlecomputeengine.domain.Instance; import org.jclouds.googlecomputeengine.domain.MachineType; import org.jclouds.googlecomputeengine.domain.Operation; @@ -345,4 +346,54 @@ public interface AggregatedListApi { }; } } + + /** + * Retrieves the list of forwarding rule resources available to the + * specified project. By default the list as a maximum size of 100, if no + * options are provided or ListOptions#getMaxResults() has not been set. + * + * @param pageToken + * marks the beginning of the next list page + * @param listOptions + * listing options + * @return a page of the list + */ + @Named("ForwardingRules:aggregatedList") + @GET + @Path("/forwardingRules") + ListPage<ForwardingRule> pageOfForwardingRules(@Nullable @QueryParam("pageToken") String pageToken, + ListOptions listOptions); + + /** @see #pageOfForwardingRules(String, ListOptions) */ + @Named("ForwardingRules:aggregatedList") + @GET + @Path("/forwardingRules") + @Transform(ForwardingRulePages.class) + Iterator<ListPage<ForwardingRule>> forwardingRules(); + + /** @see #pageOfForwardingRules(String, ListOptions) */ + @Named("ForwardingRule:aggregatedList") + @GET + @Path("/forwardingRules") + @Transform(ForwardingRulePages.class) + Iterator<ListPage<ForwardingRule>> forwardingRules(ListOptions options); + + static final class ForwardingRulePages extends BaseToIteratorOfListPage<ForwardingRule, ForwardingRulePages> { + private final GoogleComputeEngineApi api; + + @Inject + ForwardingRulePages(GoogleComputeEngineApi api) { + this.api = api; + } + + @Override + protected Function<String, ListPage<ForwardingRule>> fetchNextPage(final ListOptions options) { + return new Function<String, ListPage<ForwardingRule>>() { + @Override + public ListPage<ForwardingRule> apply(String pageToken) { + return api.aggregatedList().pageOfForwardingRules(pageToken, options); + } + }; + } + } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/81b4351b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AggregatedListApiLiveTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AggregatedListApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AggregatedListApiLiveTest.java index 349a9ac..e119872 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AggregatedListApiLiveTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AggregatedListApiLiveTest.java @@ -27,6 +27,7 @@ import org.jclouds.googlecloud.domain.ListPage; import org.jclouds.googlecomputeengine.domain.Address; import org.jclouds.googlecomputeengine.domain.Disk; import org.jclouds.googlecomputeengine.domain.DiskType; +import org.jclouds.googlecomputeengine.domain.ForwardingRule; import org.jclouds.googlecomputeengine.domain.MachineType; import org.jclouds.googlecomputeengine.domain.Operation; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; @@ -111,4 +112,21 @@ public class AggregatedListApiLiveTest extends BaseGoogleComputeEngineApiLiveTes } assertEquals(count, 2); } + + public void forwardingRules() { + Iterator<ListPage<ForwardingRule>> pageIterator = api().forwardingRules(maxResults(1)); + // make sure that in spite of having only one result per page we get at + // least two results + int count = 0; + for (; count < 2 && pageIterator.hasNext();) { + ListPage<ForwardingRule> result = pageIterator.next(); + if (!result.isEmpty()) { + count++; + } + } + if (count < 2) { + throw new SkipException("Not enough forwarding rules"); + } + assertEquals(count, 2); + } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/81b4351b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AggregatedListApiMockTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AggregatedListApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AggregatedListApiMockTest.java index f6f1c3a..ea39619 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AggregatedListApiMockTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AggregatedListApiMockTest.java @@ -144,4 +144,24 @@ public class AggregatedListApiMockTest extends BaseGoogleComputeEngineApiMockTes assertSent(server, "GET", "/projects/party/aggregated/operations"); } + + public void forwardingRules() throws Exception { + server.enqueue(jsonResponse("/aggregated_forwarding_rule_list.json")); + + AggregatedListApi aggregatedList = api().aggregatedList(); + + assertTrue(aggregatedList.forwardingRules().hasNext()); + + assertSent(server, "GET", "/projects/party/aggregated/forwardingRules"); + } + + public void forwardingRules_4xx() throws Exception { + server.enqueue(jsonResponse("/aggregated_forwarding_rule_list_empty.json")); + + AggregatedListApi aggregatedList = api().aggregatedList(); + + assertFalse(aggregatedList.forwardingRules().hasNext()); + + assertSent(server, "GET", "/projects/party/aggregated/forwardingRules"); + } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/81b4351b/google-compute-engine/src/test/resources/aggregated_forwarding_rule_list.json ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/resources/aggregated_forwarding_rule_list.json b/google-compute-engine/src/test/resources/aggregated_forwarding_rule_list.json new file mode 100644 index 0000000..2beb18b --- /dev/null +++ b/google-compute-engine/src/test/resources/aggregated_forwarding_rule_list.json @@ -0,0 +1,60 @@ +{ + "kind": "compute#forwardingRuleAggregatedList", + "id": "projects/party/aggregated/forwardingRules", + "items": { + "regions/asia-east1": { + "warning": { + "code": "NO_RESULTS_ON_PAGE", + "message": "There are no results for scope 'regions/asia-east1' on this page.", + "data": [ + { + "key": "scope", + "value": "regions/asia-east1" + } + ] + } + }, + "regions/europe-west1": { + "warning": { + "code": "NO_RESULTS_ON_PAGE", + "message": "There are no results for scope 'regions/europe-west1' on this page.", + "data": [ + { + "key": "scope", + "value": "regions/europe-west1" + } + ] + } + }, + "regions/us-central1": { + "forwardingRules": [ + { + + "kind": "compute#forwardingRule", + "id": "943206052144235641", + "creationTimestamp": "2014-11-24T15:33:26.664-08:00", + "name": "test-forwarding-rule", + "region": "https://www.googleapis.com/compute/v1/projects/party/regions/us-central1", + "IPAddress": "130.211.140.61", + "IPProtocol": "TCP", + "portRange": "1-65535", + "target": "https://www.googleapis.com/compute/v1/projects/party/regions/us-central1/targetPools/test", + "selfLink": "https://www.googleapis.com/compute/v1/projects/party/regions/us-central1/forwardingRules/test-forwarding-rule" + } + ] + }, + "global": { + "warning": { + "code": "NO_RESULTS_ON_PAGE", + "message": "There are no results for scope 'global' on this page.", + "data": [ + { + "key": "scope", + "value": "global" + } + ] + } + } + }, + "selfLink": "https://www.googleapis.com/compute/v1/projects/party/aggregated/forwardingRules" +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/81b4351b/google-compute-engine/src/test/resources/aggregated_forwarding_rule_list_empty.json ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/resources/aggregated_forwarding_rule_list_empty.json b/google-compute-engine/src/test/resources/aggregated_forwarding_rule_list_empty.json new file mode 100644 index 0000000..c924b99 --- /dev/null +++ b/google-compute-engine/src/test/resources/aggregated_forwarding_rule_list_empty.json @@ -0,0 +1,55 @@ +{ + "kind": "compute#forwardingRuleAggregatedList", + "id": "projects/party/aggregated/forwardingRules", + "items": { + "regions/asia-east1": { + "warning": { + "code": "NO_RESULTS_ON_PAGE", + "message": "There are no results for scope 'regions/asia-east1' on this page.", + "data": [ + { + "key": "scope", + "value": "regions/asia-east1" + } + ] + } + }, + "regions/europe-west1": { + "warning": { + "code": "NO_RESULTS_ON_PAGE", + "message": "There are no results for scope 'regions/europe-west1' on this page.", + "data": [ + { + "key": "scope", + "value": "regions/europe-west1" + } + ] + } + }, + "regions/us-central1": { + "warning": { + "code": "NO_RESULTS_ON_PAGE", + "message": "There are no results for scope 'regions/us-central1' on this page.", + "data": [ + { + "key": "scope", + "value": "regions/us-central1" + } + ] + } + }, + "global": { + "warning": { + "code": "NO_RESULTS_ON_PAGE", + "message": "There are no results for scope 'global' on this page.", + "data": [ + { + "key": "scope", + "value": "global" + } + ] + } + } + }, + "selfLink": "https://www.googleapis.com/compute/v1/projects/party/aggregated/forwardingRules" +} \ No newline at end of file
