@Override public Tuple<String, Iterable<com.google.api.services.compute.model.Snapshot>> call() { return serviceOptions.getComputeRpcV1().listSnapshots(optionsMap); } },
@Test public void testListEmptySnapshots() { compute = options.getService(); ImmutableList<com.google.api.services.compute.model.Snapshot> snapshots = ImmutableList.of(); Tuple<String, Iterable<com.google.api.services.compute.model.Snapshot>> result = Tuple.<String, Iterable<com.google.api.services.compute.model.Snapshot>>of(null, snapshots); EasyMock.expect(computeRpcMock.listSnapshots(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.replay(computeRpcMock); Page<Snapshot> page = compute.listSnapshots(); assertNull(page.getNextPageToken()); assertArrayEquals(snapshots.toArray(), Iterables.toArray(page.getValues(), Snapshot.class)); }
@Test public void testListSnapshots() { String cursor = "cursor"; compute = options.getService(); ImmutableList<Snapshot> snapshotList = ImmutableList.of( new Snapshot(compute, new SnapshotInfo.BuilderImpl(SNAPSHOT)), new Snapshot(compute, new SnapshotInfo.BuilderImpl(SNAPSHOT))); Tuple<String, Iterable<com.google.api.services.compute.model.Snapshot>> result = Tuple.of(cursor, Iterables.transform(snapshotList, SnapshotInfo.TO_PB_FUNCTION)); EasyMock.expect(computeRpcMock.listSnapshots(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.replay(computeRpcMock); Page<Snapshot> page = compute.listSnapshots(); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(snapshotList.toArray(), Iterables.toArray(page.getValues(), Snapshot.class)); }
@Test public void testListSnapshotsWithOptions() { String cursor = "cursor"; compute = options.getService(); ImmutableList<Snapshot> snapshotList = ImmutableList.of( new Snapshot(compute, new SnapshotInfo.BuilderImpl(SNAPSHOT)), new Snapshot(compute, new SnapshotInfo.BuilderImpl(SNAPSHOT))); Tuple<String, Iterable<com.google.api.services.compute.model.Snapshot>> result = Tuple.of(cursor, Iterables.transform(snapshotList, SnapshotInfo.TO_PB_FUNCTION)); EasyMock.expect(computeRpcMock.listSnapshots(SNAPSHOT_LIST_OPTIONS)).andReturn(result); EasyMock.replay(computeRpcMock); Page<Snapshot> page = compute.listSnapshots( SNAPSHOT_LIST_PAGE_SIZE, SNAPSHOT_LIST_PAGE_TOKEN, SNAPSHOT_LIST_FILTER); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(snapshotList.toArray(), Iterables.toArray(page.getValues(), Snapshot.class)); }
@Test public void testListSnapshotsNextPage() { String cursor = "cursor"; String nextCursor = "nextCursor"; compute = options.getService(); ImmutableList<Snapshot> snapshotList = ImmutableList.of( new Snapshot(compute, new SnapshotInfo.BuilderImpl(SNAPSHOT)), new Snapshot(compute, new SnapshotInfo.BuilderImpl(SNAPSHOT))); ImmutableList<Snapshot> nextSnapshotList = ImmutableList.of(new Snapshot(compute, new SnapshotInfo.BuilderImpl(SNAPSHOT))); Tuple<String, Iterable<com.google.api.services.compute.model.Snapshot>> result = Tuple.of(cursor, Iterables.transform(snapshotList, SnapshotInfo.TO_PB_FUNCTION)); Tuple<String, Iterable<com.google.api.services.compute.model.Snapshot>> nextResult = Tuple.of(nextCursor, Iterables.transform(nextSnapshotList, SnapshotInfo.TO_PB_FUNCTION)); Map<ComputeRpc.Option, ?> nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); EasyMock.expect(computeRpcMock.listSnapshots(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.expect(computeRpcMock.listSnapshots(nextOptions)).andReturn(nextResult); EasyMock.replay(computeRpcMock); Page<Snapshot> page = compute.listSnapshots(); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(snapshotList.toArray(), Iterables.toArray(page.getValues(), Snapshot.class)); page = page.getNextPage(); assertEquals(nextCursor, page.getNextPageToken()); assertArrayEquals( nextSnapshotList.toArray(), Iterables.toArray(page.getValues(), Snapshot.class)); }