mirror of https://github.com/apache/jclouds.git
Cleanup ListPage in google apis.
This commit is contained in:
parent
1772ea896b
commit
a5ac88f1d7
|
@ -37,7 +37,7 @@ public final class GoogleComputeEngineFallbacks {
|
|||
}
|
||||
public static final class EmptyListPageOnNotFoundOr404 implements Fallback<Object> {
|
||||
@Override public ListPage<Object> createOrPropagate(Throwable t) throws Exception {
|
||||
return valOnNotFoundOr404(ListPage.create(null, null, null), t);
|
||||
return valOnNotFoundOr404(ListPage.create(null, null), t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,34 +25,26 @@ import org.jclouds.javax.annotation.Nullable;
|
|||
|
||||
import com.google.common.collect.ForwardingList;
|
||||
|
||||
/**
|
||||
* The collection returned from any <code>listFirstPage()</code> method.
|
||||
*/
|
||||
/** An immutable list that includes a token, if there is another page available. */
|
||||
public final class ListPage<T> extends ForwardingList<T> {
|
||||
|
||||
private final List<T> items;
|
||||
private final String nextPageToken;
|
||||
private final List<String> prefixes;
|
||||
|
||||
public static <T> ListPage<T> create(List<T> items, String nextPageToken, List<String> prefixes) {
|
||||
return new ListPage<T>(items, nextPageToken, prefixes);
|
||||
public static <T> ListPage<T> create(List<T> items, String nextPageToken) {
|
||||
return new ListPage<T>(items, nextPageToken);
|
||||
}
|
||||
|
||||
@ConstructorProperties({ "items", "nextPageToken", "prefixes" })
|
||||
ListPage(List<T> items, String nextPageToken, List<String> prefixes) {
|
||||
@ConstructorProperties({ "items", "nextPageToken" })
|
||||
ListPage(List<T> items, String nextPageToken) {
|
||||
this.items = copyOf(items);
|
||||
this.nextPageToken = nextPageToken;
|
||||
this.prefixes = copyOf(prefixes);
|
||||
}
|
||||
|
||||
@Nullable public String nextPageToken() {
|
||||
return nextPageToken;
|
||||
}
|
||||
|
||||
public List<String> prefixes() {
|
||||
return prefixes;
|
||||
}
|
||||
|
||||
@Override protected List<T> delegate() {
|
||||
return items;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ import org.jclouds.googlecomputeengine.options.HttpHealthCheckCreationOptions;
|
|||
import org.jclouds.googlecomputeengine.options.ListOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
public class HttpHealthCheckApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
|
||||
|
||||
private static final String HTTP_HEALTH_CHECK_NAME = "http-health-check-api-live-test";
|
||||
|
@ -69,7 +71,7 @@ public class HttpHealthCheckApiLiveTest extends BaseGoogleComputeEngineApiLiveTe
|
|||
public void testListHttpHealthCheck() {
|
||||
ListPage<HttpHealthCheck> httpHealthCheck = api().list(new ListOptions.Builder()
|
||||
.filter("name eq " + HTTP_HEALTH_CHECK_NAME));
|
||||
assertEquals(httpHealthCheck.size(), 1);
|
||||
assertEquals(Iterables.size(httpHealthCheck), 1);
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = "testGetHttpHealthCheck")
|
||||
|
|
|
@ -53,8 +53,7 @@ public class RegionOperationApiExpectTest extends BaseGoogleComputeEngineApiExpe
|
|||
private ListPage<Operation> expectedList() {
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(new ParseRegionOperationTest().expected()), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.testng.annotations.AfterClass;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
|
||||
|
||||
|
@ -205,10 +206,9 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
|
|||
|
||||
@Test(groups = "live", dependsOnMethods = "testInsertTargetPool")
|
||||
public void testListTargetPool() {
|
||||
|
||||
ListPage<TargetPool> targetPool = api().list(new ListOptions.Builder()
|
||||
.filter("name eq " + BACKUP_TARGETPOOL_NAME));
|
||||
assertEquals(targetPool.size(), 1);
|
||||
assertEquals(Iterables.size(targetPool), 1);
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = {"testInsertTargetPool2"})
|
||||
|
|
|
@ -100,8 +100,7 @@ public class ZoneOperationApiExpectTest extends BaseGoogleComputeEngineApiExpect
|
|||
private static ListPage<Operation> expectedList() {
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(new ParseZoneOperationTest().expected()), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,8 +52,7 @@ public class ParseAddressListTest extends BaseGoogleComputeEngineParseTest<ListP
|
|||
);
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(address1, address2), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,8 +39,7 @@ public class ParseDiskListTest extends BaseGoogleComputeEngineParseTest<ListPage
|
|||
public ListPage<Disk> expected() {
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(new ParseDiskTest().expected()), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,8 +52,7 @@ public class ParseDiskTypeListTest extends BaseGoogleComputeEngineParseTest<List
|
|||
DiskType diskType2 = new ParseDiskTypeTest().expected();
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(diskType1, diskType2), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,8 +53,7 @@ public class ParseFirewallListTest extends BaseGoogleComputeEngineParseTest<List
|
|||
);
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(firewall1, firewall2), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,8 +39,7 @@ public class ParseForwardingRuleListTest extends BaseGoogleComputeEngineParseTes
|
|||
public ListPage<ForwardingRule> expected() {
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(new ParseForwardingRuleTest().expected()), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,8 +39,7 @@ public class ParseGlobalOperationListTest extends BaseGoogleComputeEngineParseTe
|
|||
public ListPage<Operation> expected() {
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(new ParseGlobalOperationTest().expected()), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,8 +70,7 @@ public class ParseHttpHealthCheckListTest extends BaseGoogleComputeEngineParseTe
|
|||
);
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(healthCheck1, healthCheck2, healthCheck3), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,8 +38,7 @@ public class ParseImageListTest extends BaseGoogleComputeEngineParseTest<ListPag
|
|||
public ListPage<Image> expected() {
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(new ParseImageTest().expected()), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,8 +39,7 @@ public class ParseInstanceListTest extends BaseGoogleComputeEngineParseTest<List
|
|||
public ListPage<Instance> expected() {
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(new ParseInstanceTest().expected()), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,8 +80,7 @@ public class ParseMachineTypeListTest extends BaseGoogleComputeEngineParseTest<L
|
|||
);
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(machineType1, machineType2, machineType3), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,8 +39,7 @@ public class ParseNetworkListTest extends BaseGoogleComputeEngineParseTest<ListP
|
|||
public ListPage<Network> expected() {
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(new ParseNetworkTest().expected()), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,8 +61,7 @@ public class ParseRegionListTest extends BaseGoogleComputeEngineParseTest<ListPa
|
|||
);
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(region1, region2), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,8 +56,7 @@ public class ParseRouteListTest extends BaseGoogleComputeEngineParseTest<ListPag
|
|||
);
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(route1, route2), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,8 +52,7 @@ public class ParseSnapshotListTest extends BaseGoogleComputeEngineParseTest<List
|
|||
);
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(snapshot1, snapshot2), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,8 +39,7 @@ public class ParseTargetPoolListTest extends BaseGoogleComputeEngineParseTest<Li
|
|||
public ListPage<TargetPool> expected() {
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(new ParseTargetPoolTest().expected()), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,8 +57,7 @@ public class ParseZoneListTest extends BaseGoogleComputeEngineParseTest<ListPage
|
|||
);
|
||||
return ListPage.create( //
|
||||
ImmutableList.of(zone1, zone2), // items
|
||||
null, // nextPageToken
|
||||
null // prefixes
|
||||
null // nextPageToken
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue