http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRoutes.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRoutes.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRoutes.java index 4f46dc6..59053e5 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRoutes.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRoutes.java @@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal; import javax.inject.Inject; -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.IterableWithMarkers; import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; import org.jclouds.googlecomputeengine.domain.ListPage; import org.jclouds.googlecomputeengine.domain.Route; @@ -37,21 +35,20 @@ public final class ParseRoutes extends ParseJson<ListPage<Route>> { }); } - public static final class ToPagedIterable extends BaseToPagedIterable<Route, ToPagedIterable> { + public static final class ToIteratorOfListPage extends BaseToIteratorOfListPage<Route, ToIteratorOfListPage> { private final GoogleComputeEngineApi api; - @Inject ToPagedIterable(GoogleComputeEngineApi api) { + @Inject ToIteratorOfListPage(GoogleComputeEngineApi api) { this.api = api; } @Override - protected Function<Object, IterableWithMarker<Route>> fetchNextPage(final String projectName, + protected Function<String, ListPage<Route>> fetchNextPage(final String projectName, final ListOptions options) { - return new Function<Object, IterableWithMarker<Route>>() { - @Override public IterableWithMarker<Route> apply(Object input) { - ListPage<Route> result = api.getRouteApi(projectName).listAtMarker(input.toString(), options); - return IterableWithMarkers.from(result, result.nextPageToken()); + return new Function<String, ListPage<Route>>() { + @Override public ListPage<Route> apply(String input) { + return api.getRouteApi(projectName).listAtMarker(input, options); } }; }
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseSnapshots.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseSnapshots.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseSnapshots.java index ab7309d..a5df763 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseSnapshots.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseSnapshots.java @@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal; import javax.inject.Inject; -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.IterableWithMarkers; import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; import org.jclouds.googlecomputeengine.domain.ListPage; import org.jclouds.googlecomputeengine.domain.Snapshot; @@ -37,20 +35,19 @@ public final class ParseSnapshots extends ParseJson<ListPage<Snapshot>> { }); } - public static final class ToPagedIterable extends BaseToPagedIterable<Snapshot, ToPagedIterable> { + public static final class ToIteratorOfListPage extends BaseToIteratorOfListPage<Snapshot, ToIteratorOfListPage> { private final GoogleComputeEngineApi api; - @Inject ToPagedIterable(GoogleComputeEngineApi api) { + @Inject ToIteratorOfListPage(GoogleComputeEngineApi api) { this.api = api; } - @Override protected Function<Object, IterableWithMarker<Snapshot>> fetchNextPage(final String projectName, + @Override protected Function<String, ListPage<Snapshot>> fetchNextPage(final String projectName, final ListOptions options) { - return new Function<Object, IterableWithMarker<Snapshot>>() { - @Override public IterableWithMarker<Snapshot> apply(Object input) { - ListPage<Snapshot> result = api.getSnapshotApi(projectName).listAtMarker(input.toString(), options); - return IterableWithMarkers.from(result, result.nextPageToken()); + return new Function<String, ListPage<Snapshot>>() { + @Override public ListPage<Snapshot> apply(String input) { + return api.getSnapshotApi(projectName).listAtMarker(input, options); } }; } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseTargetPools.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseTargetPools.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseTargetPools.java index 80e4194..466a859 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseTargetPools.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseTargetPools.java @@ -20,8 +20,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import javax.inject.Inject; -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.IterableWithMarkers; import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; import org.jclouds.googlecomputeengine.domain.ListPage; import org.jclouds.googlecomputeengine.domain.TargetPool; @@ -39,23 +37,22 @@ public final class ParseTargetPools extends ParseJson<ListPage<TargetPool>> { }); } - public static class ToPagedIterable extends BaseWithZoneToPagedIterable<TargetPool, ToPagedIterable> { + public static class ToIteratorOfListPage extends BaseWithZoneToIteratorOfListPage<TargetPool, ToIteratorOfListPage> { private final GoogleComputeEngineApi api; - @Inject ToPagedIterable(GoogleComputeEngineApi api) { + @Inject ToIteratorOfListPage(GoogleComputeEngineApi api) { this.api = checkNotNull(api, "api"); } - @Override protected Function<Object, IterableWithMarker<TargetPool>> fetchNextPage(final String projectName, + @Override protected Function<String, ListPage<TargetPool>> fetchNextPage(final String projectName, final String regionName, final ListOptions options) { - return new Function<Object, IterableWithMarker<TargetPool>>() { + return new Function<String, ListPage<TargetPool>>() { @Override - public IterableWithMarker<TargetPool> apply(Object input) { - ListPage<TargetPool> result = api.getTargetPoolApi(projectName, regionName).list(options); - return IterableWithMarkers.from(result, result.nextPageToken()); + public ListPage<TargetPool> apply(String input) { + return api.getTargetPoolApi(projectName, regionName).list(options); } }; } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneOperations.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneOperations.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneOperations.java index 3019f7d..5bad3df 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneOperations.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneOperations.java @@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal; import javax.inject.Inject; -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.IterableWithMarkers; import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; import org.jclouds.googlecomputeengine.domain.ListPage; import org.jclouds.googlecomputeengine.domain.Operation; @@ -37,22 +35,20 @@ public final class ParseZoneOperations extends ParseJson<ListPage<Operation>> { }); } - public static class ToPagedIterable extends BaseWithZoneToPagedIterable<Operation, ToPagedIterable> { + public static class ToIteratorOfListPage extends BaseWithZoneToIteratorOfListPage<Operation, ToIteratorOfListPage> { private final GoogleComputeEngineApi api; - @Inject ToPagedIterable(GoogleComputeEngineApi api) { + @Inject ToIteratorOfListPage(GoogleComputeEngineApi api) { this.api = api; } - @Override protected Function<Object, IterableWithMarker<Operation>> fetchNextPage(final String projectName, + @Override protected Function<String, ListPage<Operation>> fetchNextPage(final String projectName, final String zoneName, final ListOptions options) { - return new Function<Object, IterableWithMarker<Operation>>() { + return new Function<String, ListPage<Operation>>() { - @Override public IterableWithMarker<Operation> apply(Object input) { - ListPage<Operation> result = api.getZoneOperationApi(projectName) - .listAtMarkerInZone(zoneName, input.toString(), options); - return IterableWithMarkers.from(result, result.nextPageToken()); + @Override public ListPage<Operation> apply(String input) { + return api.getZoneOperationApi(projectName).listAtMarkerInZone(zoneName, input, options); } }; } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZones.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZones.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZones.java index 24e925e..0253f9e 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZones.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZones.java @@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal; import javax.inject.Inject; -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.IterableWithMarkers; import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; import org.jclouds.googlecomputeengine.domain.ListPage; import org.jclouds.googlecomputeengine.domain.Zone; @@ -37,21 +35,20 @@ public final class ParseZones extends ParseJson<ListPage<Zone>> { }); } - public static final class ToPagedIterable extends BaseToPagedIterable<Zone, ToPagedIterable> { + public static final class ToIteratorOfListPage extends BaseToIteratorOfListPage<Zone, ToIteratorOfListPage> { private final GoogleComputeEngineApi api; - @Inject ToPagedIterable(GoogleComputeEngineApi api) { + @Inject ToIteratorOfListPage(GoogleComputeEngineApi api) { this.api = api; } @Override - protected Function<Object, IterableWithMarker<Zone>> fetchNextPage(final String projectName, + protected Function<String, ListPage<Zone>> fetchNextPage(final String projectName, final ListOptions options) { - return new Function<Object, IterableWithMarker<Zone>>() { - @Override public IterableWithMarker<Zone> apply(Object input) { - ListPage<Zone> result = api.getZoneApi(projectName).listAtMarker(input.toString(), options); - return IterableWithMarkers.from(result, result.nextPageToken()); + return new Function<String, ListPage<Zone>>() { + @Override public ListPage<Zone> apply(String input) { + return api.getZoneApi(projectName).listAtMarker(input, options); } }; } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/internal/ListPages.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/internal/ListPages.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/internal/ListPages.java new file mode 100644 index 0000000..5ab2420 --- /dev/null +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/internal/ListPages.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.googlecomputeengine.internal; + +import java.util.Iterator; + +import org.jclouds.googlecomputeengine.domain.ListPage; + +import com.google.common.collect.AbstractIterator; +import com.google.common.collect.Iterators; + +public final class ListPages { + + public static <T> Iterable<T> concat(final Iterator<ListPage<T>> input) { + return new Iterable<T>() { + @Override public Iterator<T> iterator() { + return Iterators.concat(new AbstractIterator<Iterator<T>>() { + @Override protected Iterator<T> computeNext() { + return input.hasNext() ? input.next().iterator() : endOfData(); + } + }); + } + }; + } + + private ListPages() { + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/PageSystemExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/PageSystemExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/PageSystemExpectTest.java index e437ffe..7f2ed9d 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/PageSystemExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/PageSystemExpectTest.java @@ -17,11 +17,13 @@ package org.jclouds.googlecomputeengine; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; +import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertSame; -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.PagedIterable; +import java.util.Iterator; + import org.jclouds.googlecomputeengine.domain.Image; +import org.jclouds.googlecomputeengine.domain.ListPage; import org.jclouds.googlecomputeengine.features.ImageApi; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; import org.jclouds.googlecomputeengine.options.ListOptions; @@ -51,12 +53,9 @@ public class PageSystemExpectTest extends BaseGoogleComputeEngineApiExpectTest { ImageApi imageApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, list, operationResponse).getImageApi("myproject"); - PagedIterable<Image> images = imageApi.list(); + Iterator<ListPage<Image>> images = imageApi.list(); - // expect one page - assertSame(images.size(), 1); - // with three images - assertSame(images.concat().size(), 3); + assertEquals(images.next().size(), 3); } public void testGetMultiplePages() { @@ -100,13 +99,11 @@ public class PageSystemExpectTest extends BaseGoogleComputeEngineApiExpectTest { TOKEN_RESPONSE, list1, list1response, list2, list2Response, list3, list3Response) .getImageApi("myproject"); - PagedIterable<Image> images = imageApi.list(new ListOptions.Builder().maxResults(3)); + Iterator<ListPage<Image>> images = imageApi.list(new ListOptions.Builder().maxResults(3)); int imageCounter = 0; - for (IterableWithMarker<Image> page : images) { - for (Image image : page) { - imageCounter++; - } + while (images.hasNext()) { + imageCounter += images.next().size(); } assertSame(imageCounter, 9); } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java index eef70c9..c765a81 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java @@ -415,8 +415,6 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin @Test(dependsOnMethods = "testListLocationsWhenResponseIs2xx") public void testCreateNodeWhenNetworkNorFirewallExistDoesNotExist() throws RunNodesException, IOException { - - String payload = Strings2.toStringAndClose(InstanceApiExpectTest.class.getResourceAsStream("/instance_get.json")); payload = payload.replace("test-0", "test-1"); http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java index 3d29f08..e7470e7 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java @@ -67,7 +67,7 @@ public class GoogleComputeEngineServiceLiveTest extends BaseComputeServiceLiveTe }, UserProject.class)); ImmutableSet.Builder<String> deprecatedMachineTypes = ImmutableSet.builder(); for (MachineType machine : api.getMachineTypeApi(userProject.get()) - .listInZone(DEFAULT_ZONE_NAME).concat()) { + .listInZone(DEFAULT_ZONE_NAME).next()) { if (machine.deprecated() != null) { deprecatedMachineTypes.add(machine.id()); } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroupTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroupTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroupTest.java index a3f3319..76454d4 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroupTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroupTest.java @@ -16,6 +16,7 @@ */ package org.jclouds.googlecomputeengine.compute.functions; +import static com.google.common.collect.Iterators.singletonIterator; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; @@ -26,10 +27,9 @@ import static org.testng.Assert.assertTrue; import java.net.URI; -import org.jclouds.collect.IterableWithMarkers; -import org.jclouds.collect.PagedIterables; import org.jclouds.compute.domain.SecurityGroup; import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; +import org.jclouds.googlecomputeengine.domain.ListPage; import org.jclouds.googlecomputeengine.domain.Network; import org.jclouds.googlecomputeengine.features.FirewallApi; import org.jclouds.googlecomputeengine.options.ListOptions; @@ -39,7 +39,7 @@ import org.testng.annotations.Test; import com.google.common.base.Predicates; import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; public class NetworkToSecurityGroupTest { @@ -62,7 +62,7 @@ public class NetworkToSecurityGroupTest { expect(api.getFirewallApi(projectSupplier.get())) .andReturn(fwApi); expect(fwApi.list(options)).andReturn( - PagedIterables.onlyPage(IterableWithMarkers.from(ImmutableSet.of(FirewallToIpPermissionTest.fwForTest())))); + singletonIterator(ListPage.create(ImmutableList.of(FirewallToIpPermissionTest.fwForTest()), null))); replay(api, fwApi); http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java index e6e0c02..09e9057 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java @@ -19,7 +19,7 @@ package org.jclouds.googlecomputeengine.features; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertFalse; import static org.testng.AssertJUnit.assertNull; import javax.ws.rs.core.MediaType; @@ -137,8 +137,7 @@ public class AddressApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, list, operationResponse).getAddressApi("myproject"); - assertEquals(api.listFirstPageInRegion("us-central1").toString(), - new ParseAddressListTest().expected().toString()); + assertEquals(api.listInRegion("us-central1").next().toString(), new ParseAddressListTest().expected().toString()); } public void testListAddresssResponseIs4xx() { @@ -154,6 +153,6 @@ public class AddressApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, list, operationResponse).getAddressApi("myproject"); - assertTrue(api.listInRegion("us-central1").concat().isEmpty()); + assertFalse(api.listInRegion("us-central1").hasNext()); } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiLiveTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiLiveTest.java index 20b4f81..cbd707c 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiLiveTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiLiveTest.java @@ -19,16 +19,14 @@ package org.jclouds.googlecomputeengine.features; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import java.util.List; +import java.util.Iterator; -import org.jclouds.collect.PagedIterable; import org.jclouds.googlecomputeengine.domain.Address; +import org.jclouds.googlecomputeengine.domain.ListPage; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; import org.jclouds.googlecomputeengine.options.ListOptions; import org.testng.annotations.Test; -import com.google.common.collect.Lists; - public class AddressApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { private static final String ADDRESS_NAME = "address-api-live-test-address"; @@ -54,13 +52,10 @@ public class AddressApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live", dependsOnMethods = "testGetAddress") public void testListAddress() { - PagedIterable<Address> addresss = api().listInRegion(DEFAULT_REGION_NAME, new ListOptions.Builder() + Iterator<ListPage<Address>> addresses = api().listInRegion(DEFAULT_REGION_NAME, new ListOptions.Builder() .filter("name eq " + ADDRESS_NAME)); - List<Address> addresssAsList = Lists.newArrayList(addresss.concat()); - - assertEquals(addresssAsList.size(), 1); - + assertEquals(addresses.next().size(), 1); } @Test(groups = "live", dependsOnMethods = "testListAddress") http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiExpectTest.java index 226815e..d11f26d 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiExpectTest.java @@ -19,7 +19,7 @@ package org.jclouds.googlecomputeengine.features; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertFalse; import static org.testng.AssertJUnit.assertNull; import java.net.URI; @@ -228,8 +228,7 @@ public class DiskApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, list, operationResponse).getDiskApi("myproject"); - assertEquals(api.listFirstPageInZone("us-central1-a").toString(), - new ParseDiskListTest().expected().toString()); + assertEquals(api.listInZone("us-central1-a").next().toString(), new ParseDiskListTest().expected().toString()); } public void testListDisksResponseIs4xx() { @@ -245,6 +244,6 @@ public class DiskApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, list, operationResponse).getDiskApi("myproject"); - assertTrue(api.listInZone("us-central1-a").concat().isEmpty()); + assertFalse(api.listInZone("us-central1-a").hasNext()); } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java index 625b820..d05454a 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java @@ -20,18 +20,16 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import java.net.URI; +import java.util.Iterator; import java.util.List; -import org.jclouds.collect.PagedIterable; import org.jclouds.googlecomputeengine.domain.Disk; +import org.jclouds.googlecomputeengine.domain.ListPage; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; import org.jclouds.googlecomputeengine.options.DiskCreationOptions; import org.jclouds.googlecomputeengine.options.ListOptions; import org.testng.annotations.Test; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - public class DiskApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { public static final String DISK_NAME = "disk-api-live-test-disk"; @@ -45,7 +43,7 @@ public class DiskApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live") public void testInsertDisk() { - assertZoneOperationDoneSucessfully(api().createInZone(DISK_NAME, sizeGb, DEFAULT_ZONE_NAME), TIME_WAIT); + assertZoneOperationDoneSuccessfully(api().createInZone(DISK_NAME, sizeGb, DEFAULT_ZONE_NAME), TIME_WAIT); } @Test(groups = "live", dependsOnMethods = "testInsertDisk") @@ -59,21 +57,21 @@ public class DiskApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live", dependsOnMethods = "testGetDisk") public void testListDisk() { - PagedIterable<Disk> disks = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder() + Iterator<ListPage<Disk>> disks = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder() .filter("name eq " + DISK_NAME)); - List<Disk> disksAsList = Lists.newArrayList(disks.concat()); + List<Disk> disksAsList = disks.next(); assertEquals(disksAsList.size(), 1); - assertDiskEquals(Iterables.getOnlyElement(disksAsList)); + assertDiskEquals(disksAsList.get(0)); } @Test(groups = "live", dependsOnMethods = "testListDisk") public void testDeleteDisk() { - assertZoneOperationDoneSucessfully(api().deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT); + assertZoneOperationDoneSuccessfully(api().deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT); } private void assertDiskEquals(Disk result) { @@ -86,7 +84,8 @@ public class DiskApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { public void testInsertSSDDisk() { URI diskType = getDiskTypeUrl(userProject.get(), DEFAULT_ZONE_NAME, "pd-ssd"); DiskCreationOptions diskCreationOptions = new DiskCreationOptions().type(diskType); - assertZoneOperationDoneSucessfully(api().createInZone(SSD_DISK_NAME, sizeGb, DEFAULT_ZONE_NAME, diskCreationOptions), TIME_WAIT); + assertZoneOperationDoneSuccessfully( + api().createInZone(SSD_DISK_NAME, sizeGb, DEFAULT_ZONE_NAME, diskCreationOptions), TIME_WAIT); } @Test(groups = "live", dependsOnMethods = "testInsertSSDDisk") @@ -100,7 +99,7 @@ public class DiskApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live", dependsOnMethods = "testGetSSDDisk") public void testDeleteSSDDisk() { - assertZoneOperationDoneSucessfully(api().deleteInZone(DEFAULT_ZONE_NAME, SSD_DISK_NAME), TIME_WAIT); + assertZoneOperationDoneSuccessfully(api().deleteInZone(DEFAULT_ZONE_NAME, SSD_DISK_NAME), TIME_WAIT); } private void assertSSDDiskEquals(Disk result) { http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiExpectTest.java index 5f8f648..b62a251 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiExpectTest.java @@ -18,8 +18,8 @@ package org.jclouds.googlecomputeengine.features; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; import org.jclouds.googlecomputeengine.parse.ParseDiskTypeListTest; @@ -95,7 +95,7 @@ public class DiskTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTest TOKEN_RESPONSE, LIST_DISK_TYPES_REQUEST, LIST_DISK_TYPES_RESPONSE).getDiskTypeApi ("myproject"); - assertEquals(diskTypeApi.listFirstPageInZone("us-central1-a").toString(), + assertEquals(diskTypeApi.listInZone("us-central1-a").next().toString(), new ParseDiskTypeListTest().expected().toString()); } @@ -106,6 +106,6 @@ public class DiskTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTest DiskTypeApi diskTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, LIST_DISK_TYPES_REQUEST, operationResponse).getDiskTypeApi("myproject"); - assertTrue(diskTypeApi.listInZone("us-central1-a").concat().isEmpty()); + assertFalse(diskTypeApi.listInZone("us-central1-a").hasNext()); } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiLiveTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiLiveTest.java index b97f34e..03c7b36 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiLiveTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiLiveTest.java @@ -18,21 +18,16 @@ package org.jclouds.googlecomputeengine.features; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertSame; import static org.testng.Assert.assertTrue; import java.util.Iterator; -import java.util.List; -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.PagedIterable; import org.jclouds.googlecomputeengine.domain.DiskType; +import org.jclouds.googlecomputeengine.domain.ListPage; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; import org.jclouds.googlecomputeengine.options.ListOptions; import org.testng.annotations.Test; -import com.google.common.collect.Iterables; - public class DiskTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { private DiskType diskType; @@ -44,18 +39,15 @@ public class DiskTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live") public void testDiskType() { - PagedIterable<DiskType> diskTypes = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder() - .maxResults(1)); - - Iterator<IterableWithMarker<DiskType>> pageIterator = diskTypes.iterator(); + Iterator<ListPage<DiskType>> pageIterator = api().listInZone(DEFAULT_ZONE_NAME, + new ListOptions.Builder().maxResults(1)); assertTrue(pageIterator.hasNext()); - IterableWithMarker<DiskType> singlePageIterator = pageIterator.next(); - List<DiskType> diskTypeAsList = singlePageIterator.toList(); + ListPage<DiskType> page = pageIterator.next(); - assertSame(diskTypeAsList.size(), 1); + assertEquals(page.size(), 1); - this.diskType = Iterables.getOnlyElement(diskTypeAsList); + this.diskType = page.get(0); } @Test(groups = "live", dependsOnMethods = "testDiskType") http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java index 1222f58..1fc0497 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java @@ -24,7 +24,7 @@ import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPU import static org.jclouds.io.Payloads.newStringPayload; import static org.jclouds.util.Strings2.toStringAndClose; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertFalse; import static org.testng.AssertJUnit.assertNull; import java.io.IOException; @@ -259,8 +259,7 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, list, operationResponse).getFirewallApi("myproject"); - assertEquals(api.listFirstPage().toString(), - new ParseFirewallListTest().expected().toString()); + assertEquals(api.list().next().toString(), new ParseFirewallListTest().expected().toString()); } public void testListFirewallsResponseIs4xx() { @@ -276,6 +275,6 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, list, operationResponse).getFirewallApi("myproject"); - assertTrue(api.list().concat().isEmpty()); + assertFalse(api.list().hasNext()); } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiLiveTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiLiveTest.java index 652d47a..f17c69e 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiLiveTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiLiveTest.java @@ -20,17 +20,17 @@ import static com.google.common.collect.Iterables.getOnlyElement; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; +import java.util.Iterator; import java.util.List; -import org.jclouds.collect.PagedIterable; import org.jclouds.googlecomputeengine.domain.Firewall; +import org.jclouds.googlecomputeengine.domain.ListPage; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; import org.jclouds.googlecomputeengine.options.FirewallOptions; import org.jclouds.googlecomputeengine.options.ListOptions; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; @Test(groups = "live", testName = "FirewallApiLiveTest") public class FirewallApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @@ -110,13 +110,12 @@ public class FirewallApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live", dependsOnMethods = "testGetFirewall") public void testListFirewall() { - PagedIterable<Firewall> firewalls = api().list(new ListOptions.Builder() + Iterator<ListPage<Firewall>> firewalls = api().list(new ListOptions.Builder() .filter("name eq " + FIREWALL_NAME)); - List<Firewall> firewallsAsList = Lists.newArrayList(firewalls.concat()); + List<Firewall> firewallsAsList = firewalls.next(); assertEquals(firewallsAsList.size(), 1); - } @Test(groups = "live", dependsOnMethods = "testListFirewall") http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiExpectTest.java index 866eadd..161d27d 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiExpectTest.java @@ -19,7 +19,7 @@ package org.jclouds.googlecomputeengine.features; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertFalse; import static org.testng.AssertJUnit.assertNull; import java.net.URI; @@ -28,7 +28,6 @@ import javax.ws.rs.core.MediaType; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions; -import org.jclouds.googlecomputeengine.options.ListOptions; import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleListTest; import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleTest; import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest; @@ -142,8 +141,7 @@ public class ForwardingRuleApiExpectTest extends BaseGoogleComputeEngineApiExpec ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, list, operationResponse).getForwardingRuleApi("myproject", "us-central1"); - ListOptions options = new ListOptions(); - assertEquals(api.list(options).toString(), new ParseForwardingRuleListTest().expected().toString()); + assertEquals(api.list().next().toString(), new ParseForwardingRuleListTest().expected().toString()); } public void testListForwardingRulesResponseIs4xx() { @@ -159,7 +157,7 @@ public class ForwardingRuleApiExpectTest extends BaseGoogleComputeEngineApiExpec ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, list, operationResponse).getForwardingRuleApi("myproject", "us-central1"); - assertTrue(api.list().concat().isEmpty()); + assertFalse(api.list().hasNext()); } public void testSetTargetForwardingRuleResponseIs2xx(){ http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiExpectTest.java index a7c6731..d66532a 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiExpectTest.java @@ -19,8 +19,8 @@ package org.jclouds.googlecomputeengine.features; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; import org.jclouds.googlecomputeengine.options.ListOptions; @@ -108,7 +108,7 @@ public class GlobalOperationApiExpectTest extends BaseGoogleComputeEngineApiExpe GlobalOperationApi globalOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, get, operationResponse).getGlobalOperationApi("myproject"); - assertEquals(globalOperationApi.listFirstPage().toString(), + assertEquals(globalOperationApi.list().next().toString(), new ParseGlobalOperationListTest().expected().toString()); } @@ -150,6 +150,6 @@ public class GlobalOperationApiExpectTest extends BaseGoogleComputeEngineApiExpe GlobalOperationApi globalOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, get, operationResponse).getGlobalOperationApi("myproject"); - assertTrue(globalOperationApi.list().concat().isEmpty()); + assertFalse(globalOperationApi.list().hasNext()); } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiLiveTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiLiveTest.java index 526bc26..0d40738 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiLiveTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiLiveTest.java @@ -16,74 +16,51 @@ */ package org.jclouds.googlecomputeengine.features; -import static org.jclouds.googlecomputeengine.features.ProjectApiLiveTest.addItemToMetadata; -import static org.jclouds.googlecomputeengine.features.ProjectApiLiveTest.deleteItemFromMetadata; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import java.util.concurrent.atomic.AtomicInteger; +import java.util.Iterator; -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.PagedIterable; +import org.jclouds.googlecomputeengine.domain.ListPage; import org.jclouds.googlecomputeengine.domain.Operation; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; import org.jclouds.googlecomputeengine.options.ListOptions; +import org.testng.SkipException; import org.testng.annotations.Test; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; - +@Test(groups = "live", testName = "GlobalOperationApiLiveTest") public class GlobalOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { - private static final String METADATA_ITEM_KEY = "operationLiveTestTestProp"; - private static final String METADATA_ITEM_VALUE = "operationLiveTestTestValue"; - private Operation addOperation; - private Operation deleteOperation; + private Operation operation; private GlobalOperationApi api() { return api.getGlobalOperationApi(userProject.get()); } - - @Test(groups = "live") - public void testCreateOperations() { - //insert some operations by adding and deleting metadata items - // this will make sure there is stuff to listFirstPage - addOperation = assertGlobalOperationDoneSucessfully(addItemToMetadata(api.getProjectApi(), - userProject.get(), METADATA_ITEM_KEY, METADATA_ITEM_VALUE), 20); - deleteOperation = assertGlobalOperationDoneSucessfully(deleteItemFromMetadata(api - .getProjectApi(), userProject.get(), METADATA_ITEM_KEY), 20); - - assertNotNull(addOperation); - assertNotNull(deleteOperation); - } - - @Test(groups = "live", dependsOnMethods = "testCreateOperations") - public void testGetOperation() { - Operation operation = api().get(addOperation.name()); - assertNotNull(operation); - assertOperationEquals(operation, this.addOperation); - } - - @Test(groups = "live", dependsOnMethods = "testCreateOperations") public void testListOperationsWithFiltersAndPagination() { - PagedIterable<Operation> operations = api().list(new ListOptions.Builder() - .filter("operationType eq setMetadata") - .maxResults(1)); + Iterator<ListPage<Operation>> operations = api().list(new ListOptions.Builder() + // .filter("operationType eq insert") + .maxResults(1)); // make sure that in spite of having only one result per page we get at least two results - final AtomicInteger counter = new AtomicInteger(); - operations.firstMatch(new Predicate<IterableWithMarker<Operation>>() { - @Override public boolean apply(IterableWithMarker<Operation> input) { - counter.addAndGet(Iterables.size(input)); - return counter.get() == 2; + int count = 0; + for (; count < 2 && operations.hasNext(); ) { + ListPage<Operation> result = operations.next(); + if (result.isEmpty()) { + operation = result.get(0); + count++; } - }); + } + if (count < 2) { + throw new SkipException("Not enough global operations"); + } + assertEquals(count, 2); } - private void assertOperationEquals(Operation result, Operation expected) { - assertEquals(result.name(), expected.name()); + @Test(groups = "live", dependsOnMethods = "testListOperationsWithFiltersAndPagination") + public void testGetOperation() { + Operation result = api().get(operation.name()); + assertNotNull(result); + assertEquals(result.name(), operation.name()); // Checking state besides name can lead to flaky test. } - - } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiExpectTest.java index 5c165fd..24a2011 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiExpectTest.java @@ -19,14 +19,13 @@ package org.jclouds.googlecomputeengine.features; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertFalse; import static org.testng.AssertJUnit.assertNull; import javax.ws.rs.core.MediaType; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; import org.jclouds.googlecomputeengine.options.HttpHealthCheckCreationOptions; -import org.jclouds.googlecomputeengine.options.ListOptions; import org.jclouds.googlecomputeengine.parse.ParseGlobalOperationTest; import org.jclouds.googlecomputeengine.parse.ParseHttpHealthCheckListTest; import org.jclouds.googlecomputeengine.parse.ParseHttpHealthCheckTest; @@ -161,9 +160,7 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, list, operationResponse).getHttpHealthCheckApi("myproject"); - ListOptions options = new ListOptions(); - assertEquals(api.list(options).toString(), - new ParseHttpHealthCheckListTest().expected().toString()); + assertEquals(api.list().next().toString(), new ParseHttpHealthCheckListTest().expected().toString()); } public void testListHttpHealthChecksResponseIs4xx() { @@ -179,7 +176,7 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, list, operationResponse).getHttpHealthCheckApi("myproject"); - assertTrue(api.list().concat().isEmpty()); + assertFalse(api.list().hasNext()); } public void testPatchHttpHealthChecksResponseIs2xx() { http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiExpectTest.java index 5f8ed31..039adec 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiExpectTest.java @@ -19,7 +19,7 @@ package org.jclouds.googlecomputeengine.features; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertFalse; import static org.testng.AssertJUnit.assertNull; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; @@ -139,8 +139,7 @@ public class ImageApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { TOKEN_RESPONSE, LIST_PROJECT_IMAGES_REQUEST, LIST_PROJECT_IMAGES_RESPONSE).getImageApi ("myproject"); - assertEquals(imageApi.listFirstPage().toString(), - new ParseImageListTest().expected().toString()); + assertEquals(imageApi.list().next().toString(), new ParseImageListTest().expected().toString()); } public void testListImagesResponseIs4xx() { @@ -150,7 +149,7 @@ public class ImageApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { ImageApi imageApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, LIST_PROJECT_IMAGES_REQUEST, operationResponse).getImageApi("myproject"); - assertTrue(imageApi.list().concat().isEmpty()); + assertFalse(imageApi.list().hasNext()); } public void testCreateImageFromPdResponseIs2xx(){ http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java index 8c3f0bf..c9e34c9 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java @@ -18,23 +18,18 @@ package org.jclouds.googlecomputeengine.features; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; import java.net.URI; import java.util.Iterator; import java.util.List; -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.PagedIterable; import org.jclouds.googlecomputeengine.domain.Disk; import org.jclouds.googlecomputeengine.domain.Image; +import org.jclouds.googlecomputeengine.domain.ListPage; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; import org.jclouds.googlecomputeengine.options.ListOptions; import org.testng.annotations.Test; -import com.google.common.collect.Iterables; - public class ImageApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { public static final String DISK_NAME = "image-api-live-test-disk"; @@ -60,17 +55,13 @@ public class ImageApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live") public void testListImage() { - PagedIterable<Image> images = api().list(new ListOptions.Builder().maxResults(1)); - - Iterator<IterableWithMarker<Image>> pageIterator = images.iterator(); - assertTrue(pageIterator.hasNext()); + Iterator<ListPage<Image>> images = api().list(new ListOptions.Builder().maxResults(1)); - IterableWithMarker<Image> singlePageIterator = pageIterator.next(); - List<Image> imageAsList = singlePageIterator.toList(); + List<Image> imageAsList = images.next(); - assertSame(imageAsList.size(), 1); + assertEquals(imageAsList.size(), 1); - this.image = Iterables.getOnlyElement(imageAsList); + this.image = imageAsList.get(0); } @@ -87,7 +78,7 @@ public class ImageApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live") public void testInsertDisk() { - assertZoneOperationDoneSucessfully(diskApi().createInZone(DISK_NAME, sizeGb, DEFAULT_ZONE_NAME), TIME_WAIT); + assertZoneOperationDoneSuccessfully(diskApi().createInZone(DISK_NAME, sizeGb, DEFAULT_ZONE_NAME), TIME_WAIT); Disk disk = diskApi().getInZone(DEFAULT_ZONE_NAME, DISK_NAME); diskURI = disk.selfLink(); } @@ -106,7 +97,7 @@ public class ImageApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live", dependsOnMethods = "testGetCreatedImage") public void testCleanup(){ assertGlobalOperationDoneSucessfully(imageApi().delete(IMAGE_NAME), TIME_WAIT); - assertZoneOperationDoneSucessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT); + assertZoneOperationDoneSuccessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT); } private void assertImageEquals(Image result) { http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java index 4515233..17d7d92 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java @@ -22,7 +22,7 @@ import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPU import static org.jclouds.googlecomputeengine.features.ProjectApiExpectTest.GET_PROJECT_REQUEST; import static org.jclouds.googlecomputeengine.features.ProjectApiExpectTest.GET_PROJECT_RESPONSE; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertFalse; import static org.testng.AssertJUnit.assertNull; import java.net.URI; @@ -216,7 +216,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, LIST_INSTANCES_REQUEST, LIST_INSTANCES_RESPONSE).getInstanceApi("myproject"); - assertEquals(api.listFirstPageInZone("us-central1-a").toString(), + assertEquals(api.listInZone("us-central1-a").next().toString(), new ParseInstanceListTest().expected().toString()); } @@ -233,7 +233,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, list, operationResponse).getInstanceApi("myproject"); - assertTrue(api.listInZone("us-central1-a").concat().isEmpty()); + assertFalse(api.listInZone("us-central1-a").hasNext()); } public void testSetInstanceMetadataResponseIs2xx() { http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java index f799948..11f4915 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java @@ -21,14 +21,15 @@ import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; import java.net.URI; +import java.util.Iterator; import java.util.List; import java.util.Properties; -import org.jclouds.collect.PagedIterable; import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; import org.jclouds.googlecomputeengine.domain.Image; import org.jclouds.googlecomputeengine.domain.Instance; import org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk; +import org.jclouds.googlecomputeengine.domain.ListPage; import org.jclouds.googlecomputeengine.domain.templates.InstanceTemplate; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; import org.jclouds.googlecomputeengine.options.AttachDiskOptions; @@ -40,10 +41,10 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import com.google.common.base.Predicate; +import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.google.inject.Module; @Test(groups = "live", testName = "InstanceApiLiveTest") @@ -68,9 +69,9 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Override protected GoogleComputeEngineApi create(Properties props, Iterable<Module> modules) { GoogleComputeEngineApi api = super.create(props, modules); - URI imageUri = api.getImageApi("centos-cloud") - .list(new ListOptions.Builder().filter("name eq centos.*")) - .concat() + List<Image> list = api.getImageApi("centos-cloud") + .list(new ListOptions.Builder().filter("name eq centos.*")).next(); + URI imageUri = FluentIterable.from(list) .filter(new Predicate<Image>() { @Override public boolean apply(Image input) { @@ -111,15 +112,15 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { (INSTANCE_NETWORK_NAME, IPV4_RANGE), TIME_WAIT); DiskCreationOptions diskCreationOptions = new DiskCreationOptions().sourceImage(instance.image()); - assertZoneOperationDoneSucessfully(api.getDiskApi(userProject.get()) - .createInZone(BOOT_DISK_NAME, DEFAULT_DISK_SIZE_GB, DEFAULT_ZONE_NAME, diskCreationOptions), - TIME_WAIT); + assertZoneOperationDoneSuccessfully(api.getDiskApi(userProject.get()) + .createInZone(BOOT_DISK_NAME, DEFAULT_DISK_SIZE_GB, DEFAULT_ZONE_NAME, diskCreationOptions), + TIME_WAIT); - assertZoneOperationDoneSucessfully(diskApi().createInZone - ("instance-live-test-disk", DEFAULT_DISK_SIZE_GB, DEFAULT_ZONE_NAME), TIME_WAIT); + assertZoneOperationDoneSuccessfully( + diskApi().createInZone("instance-live-test-disk", DEFAULT_DISK_SIZE_GB, DEFAULT_ZONE_NAME), TIME_WAIT); - assertZoneOperationDoneSucessfully(api().createInZone(INSTANCE_NAME, DEFAULT_ZONE_NAME, instance), TIME_WAIT); + assertZoneOperationDoneSuccessfully(api().createInZone(INSTANCE_NAME, DEFAULT_ZONE_NAME, instance), TIME_WAIT); } @@ -134,10 +135,9 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live", dependsOnMethods = "testListInstance") public void testSetMetadataForInstance() { Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); - assertZoneOperationDoneSucessfully(api().setMetadataInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, - ImmutableMap.of(METADATA_ITEM_KEY, METADATA_ITEM_VALUE), - originalInstance.metadata().fingerprint()), - TIME_WAIT); + assertZoneOperationDoneSuccessfully(api().setMetadataInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, + ImmutableMap.of(METADATA_ITEM_KEY, METADATA_ITEM_VALUE), originalInstance.metadata().fingerprint()), + TIME_WAIT); Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); @@ -150,9 +150,9 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live", dependsOnMethods = "testListInstance") public void testSetTagsForInstance() { Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); - assertZoneOperationDoneSucessfully(api().setTagsInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, TAGS, - originalInstance.tags().fingerprint()), - TIME_WAIT); + assertZoneOperationDoneSuccessfully( + api().setTagsInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, TAGS, originalInstance.tags().fingerprint()), + TIME_WAIT); Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); @@ -162,15 +162,13 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live", dependsOnMethods = "testSetMetadataForInstance") public void testAttachDiskToInstance() { - assertZoneOperationDoneSucessfully(diskApi().createInZone(ATTACH_DISK_NAME, 1, DEFAULT_ZONE_NAME), TIME_WAIT); + assertZoneOperationDoneSuccessfully(diskApi().createInZone(ATTACH_DISK_NAME, 1, DEFAULT_ZONE_NAME), TIME_WAIT); Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); - assertZoneOperationDoneSucessfully(api().attachDiskInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, - new AttachDiskOptions().type(DiskType.PERSISTENT) - .source(getDiskUrl(userProject.get(), ATTACH_DISK_NAME)) - .mode(DiskMode.READ_ONLY) - .deviceName(ATTACH_DISK_DEVICE_NAME)), - TIME_WAIT); + assertZoneOperationDoneSuccessfully(api().attachDiskInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, + new AttachDiskOptions().type(DiskType.PERSISTENT) + .source(getDiskUrl(userProject.get(), ATTACH_DISK_NAME)).mode(DiskMode.READ_ONLY) + .deviceName(ATTACH_DISK_DEVICE_NAME)), TIME_WAIT); Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); @@ -188,44 +186,42 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live", dependsOnMethods = "testAttachDiskToInstance") public void testDetachDiskFromInstance() { Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); - assertZoneOperationDoneSucessfully(api().detachDiskInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, - ATTACH_DISK_DEVICE_NAME), TIME_WAIT); + assertZoneOperationDoneSuccessfully( + api().detachDiskInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, ATTACH_DISK_DEVICE_NAME), TIME_WAIT); Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); assertTrue(modifiedInstance.disks().size() < originalInstance.disks().size()); - assertZoneOperationDoneSucessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, ATTACH_DISK_NAME), TIME_WAIT); + assertZoneOperationDoneSuccessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, ATTACH_DISK_NAME), TIME_WAIT); } @Test(groups = "live", dependsOnMethods = "testInsertInstance") public void testListInstance() { - PagedIterable<Instance> instances = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder() + Iterator<ListPage<Instance>> instances = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder() .filter("name eq " + INSTANCE_NAME)); - List<Instance> instancesAsList = Lists.newArrayList(instances.concat()); + List<Instance> instancesAsList = instances.next(); assertEquals(instancesAsList.size(), 1); - assertInstanceEquals(Iterables.getOnlyElement(instancesAsList), instance); + assertInstanceEquals(instancesAsList.get(0), instance); } @Test(groups = "live", dependsOnMethods = "testDetachDiskFromInstance") public void testResetInstance() { - assertZoneOperationDoneSucessfully(api().resetInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME), - TIME_WAIT); + assertZoneOperationDoneSuccessfully(api().resetInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME), TIME_WAIT); } @Test(groups = "live", dependsOnMethods = "testResetInstance") public void testDeleteInstance() { - - assertZoneOperationDoneSucessfully(api().deleteInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME), TIME_WAIT); - assertZoneOperationDoneSucessfully(api.getDiskApi(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), - TIME_WAIT); - assertZoneOperationDoneSucessfully(api.getDiskApi(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, BOOT_DISK_NAME), - TIME_WAIT); + assertZoneOperationDoneSuccessfully(api().deleteInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME), TIME_WAIT); + assertZoneOperationDoneSuccessfully(api.getDiskApi(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), + TIME_WAIT); + assertZoneOperationDoneSuccessfully( + api.getDiskApi(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, BOOT_DISK_NAME), TIME_WAIT); assertGlobalOperationDoneSucessfully(api.getNetworkApi(userProject.get()).delete (INSTANCE_NETWORK_NAME), TIME_WAIT); } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java index dc829b2..1400232 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java @@ -18,8 +18,8 @@ package org.jclouds.googlecomputeengine.features; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; import org.jclouds.googlecomputeengine.parse.ParseMachineTypeListTest; @@ -95,7 +95,7 @@ public class MachineTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTe TOKEN_RESPONSE, LIST_MACHINE_TYPES_REQUEST, LIST_MACHINE_TYPES_RESPONSE).getMachineTypeApi ("myproject"); - assertEquals(machineTypeApi.listFirstPageInZone("us-central1-a").toString(), + assertEquals(machineTypeApi.listInZone("us-central1-a").next().toString(), new ParseMachineTypeListTest().expected().toString()); } @@ -106,6 +106,6 @@ public class MachineTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTe MachineTypeApi machineTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, LIST_MACHINE_TYPES_REQUEST, operationResponse).getMachineTypeApi("myproject"); - assertTrue(machineTypeApi.listInZone("us-central1-a").concat().isEmpty()); + assertFalse(machineTypeApi.listInZone("us-central1-a").hasNext()); } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java index 00f3acb..89c7257 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java @@ -18,21 +18,17 @@ package org.jclouds.googlecomputeengine.features; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertSame; import static org.testng.Assert.assertTrue; import java.util.Iterator; import java.util.List; -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.PagedIterable; +import org.jclouds.googlecomputeengine.domain.ListPage; import org.jclouds.googlecomputeengine.domain.MachineType; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; import org.jclouds.googlecomputeengine.options.ListOptions; import org.testng.annotations.Test; -import com.google.common.collect.Iterables; - public class MachineTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { private MachineType machineType; @@ -43,19 +39,15 @@ public class MachineTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live") public void testListMachineType() { - - PagedIterable<MachineType> machineTypes = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder() - .maxResults(1)); - - Iterator<IterableWithMarker<MachineType>> pageIterator = machineTypes.iterator(); + Iterator<ListPage<MachineType>> pageIterator = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder() + .maxResults(1)); assertTrue(pageIterator.hasNext()); - IterableWithMarker<MachineType> singlePageIterator = pageIterator.next(); - List<MachineType> machineTypeAsList = singlePageIterator.toList(); + List<MachineType> machineTypeAsList = pageIterator.next(); - assertSame(machineTypeAsList.size(), 1); + assertEquals(machineTypeAsList.size(), 1); - this.machineType = Iterables.getOnlyElement(machineTypeAsList); + this.machineType = machineTypeAsList.get(0); } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java index 2f0d7a0..61f319b 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java @@ -19,7 +19,7 @@ package org.jclouds.googlecomputeengine.features; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertFalse; import static org.testng.AssertJUnit.assertNull; import javax.ws.rs.core.MediaType; @@ -138,7 +138,7 @@ public class NetworkApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, list, operationResponse).getNetworkApi("myproject"); - assertEquals(api.listFirstPage().toString(), + assertEquals(api.list().next().toString(), new ParseNetworkListTest().expected().toString()); } @@ -152,9 +152,9 @@ public class NetworkApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, list, operationResponse).getNetworkApi("myproject"); + NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, list, + operationResponse).getNetworkApi("myproject"); - assertTrue(api.list().concat().isEmpty()); + assertFalse(api.list().hasNext()); } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java index 2a336ee..9363370 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java @@ -19,17 +19,15 @@ package org.jclouds.googlecomputeengine.features; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; +import java.util.Iterator; import java.util.List; -import org.jclouds.collect.PagedIterable; +import org.jclouds.googlecomputeengine.domain.ListPage; import org.jclouds.googlecomputeengine.domain.Network; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; import org.jclouds.googlecomputeengine.options.ListOptions; import org.testng.annotations.Test; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - @Test(groups = "live", testName = "NetworkApiLiveTest") public class NetworkApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @@ -43,14 +41,11 @@ public class NetworkApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live") public void testInsertNetwork() { - assertGlobalOperationDoneSucessfully(api().createInIPv4Range(NETWORK_NAME, IPV4_RANGE), TIME_WAIT); - } @Test(groups = "live", dependsOnMethods = "testInsertNetwork") public void testGetNetwork() { - Network network = api().get(NETWORK_NAME); assertNotNull(network); assertNetworkEquals(network); @@ -59,14 +54,14 @@ public class NetworkApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live", dependsOnMethods = "testGetNetwork") public void testListNetwork() { - PagedIterable<Network> networks = api().list(new ListOptions.Builder() + Iterator<ListPage<Network>> networks = api().list(new ListOptions.Builder() .filter("name eq " + NETWORK_NAME)); - List<Network> networksAsList = Lists.newArrayList(networks.concat()); + List<Network> networksAsList = networks.next(); assertEquals(networksAsList.size(), 1); - assertNetworkEquals(Iterables.getOnlyElement(networksAsList)); + assertNetworkEquals(networksAsList.get(0)); } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java index b041647..4ede7f6 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java @@ -18,8 +18,8 @@ package org.jclouds.googlecomputeengine.features; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; import org.jclouds.googlecomputeengine.parse.ParseRegionListTest; @@ -78,8 +78,7 @@ public class RegionApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { RegionApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, LIST_REGIONS_REQ, LIST_REGIONS_RESPONSE).getRegionApi("myproject"); - assertEquals(api.listFirstPage().toString(), - new ParseRegionListTest().expected().toString()); + assertEquals(api.list().next().toString(), new ParseRegionListTest().expected().toString()); } public void testListRegionWithPaginationOptionsResponseIs4xx() { @@ -89,6 +88,6 @@ public class RegionApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { RegionApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, LIST_REGIONS_REQ, operationResponse).getRegionApi("myproject"); - assertTrue(api.list().concat().isEmpty()); + assertFalse(api.list().hasNext()); } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/7427ba23/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.java index 6c47e4b..e360863 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.java @@ -18,21 +18,17 @@ package org.jclouds.googlecomputeengine.features; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertSame; import static org.testng.Assert.assertTrue; import java.util.Iterator; import java.util.List; -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.PagedIterable; +import org.jclouds.googlecomputeengine.domain.ListPage; import org.jclouds.googlecomputeengine.domain.Region; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; import org.jclouds.googlecomputeengine.options.ListOptions; import org.testng.annotations.Test; -import com.google.common.collect.Iterables; - public class RegionApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { private Region region; @@ -43,19 +39,14 @@ public class RegionApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live") public void testListRegion() { - - PagedIterable<Region> regions = api().list(new ListOptions.Builder() - .maxResults(1)); - - Iterator<IterableWithMarker<Region>> pageIterator = regions.iterator(); + Iterator<ListPage<Region>> pageIterator = api().list(new ListOptions.Builder().maxResults(1)); assertTrue(pageIterator.hasNext()); - IterableWithMarker<Region> singlePageIterator = pageIterator.next(); - List<Region> regionAsList = singlePageIterator.toList(); + List<Region> regionAsList = pageIterator.next(); - assertSame(regionAsList.size(), 1); + assertEquals(regionAsList.size(), 1); - this.region = Iterables.getOnlyElement(regionAsList); + this.region = regionAsList.get(0); } @Test(groups = "live", dependsOnMethods = "testListRegion")
