@Override public Tuple<String, Iterable<com.google.api.services.compute.model.Region>> call() { return serviceOptions.getComputeRpcV1().listRegions(optionsMap); } },
@Test public void testListRegions() { String cursor = "cursor"; compute = options.getService(); ImmutableList<Region> regionList = ImmutableList.of(REGION, REGION); Tuple<String, Iterable<com.google.api.services.compute.model.Region>> result = Tuple.of(cursor, Iterables.transform(regionList, Region.TO_PB_FUNCTION)); EasyMock.expect(computeRpcMock.listRegions(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.replay(computeRpcMock); Page<Region> page = compute.listRegions(); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(regionList.toArray(), Iterables.toArray(page.getValues(), Region.class)); }
@Test public void testListRegionsWithOptions() { String cursor = "cursor"; compute = options.getService(); ImmutableList<Region> regionList = ImmutableList.of(REGION, REGION); Tuple<String, Iterable<com.google.api.services.compute.model.Region>> result = Tuple.of(cursor, Iterables.transform(regionList, Region.TO_PB_FUNCTION)); EasyMock.expect(computeRpcMock.listRegions(REGION_LIST_OPTIONS)).andReturn(result); EasyMock.replay(computeRpcMock); Page<Region> page = compute.listRegions(REGION_LIST_PAGE_SIZE, REGION_LIST_PAGE_TOKEN, REGION_LIST_FILTER); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(regionList.toArray(), Iterables.toArray(page.getValues(), Region.class)); }
@Test public void testListEmptyRegions() { ImmutableList<com.google.api.services.compute.model.Region> regions = ImmutableList.of(); Tuple<String, Iterable<com.google.api.services.compute.model.Region>> result = Tuple.<String, Iterable<com.google.api.services.compute.model.Region>>of(null, regions); EasyMock.expect(computeRpcMock.listRegions(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.replay(computeRpcMock); compute = options.getService(); Page<Region> page = compute.listRegions(); assertNull(page.getNextPageToken()); assertArrayEquals(regions.toArray(), Iterables.toArray(page.getValues(), Region.class)); }
@Test public void testListRegionsNextPage() { String cursor = "cursor"; String nextCursor = "nextCursor"; compute = options.getService(); ImmutableList<Region> regionList = ImmutableList.of(REGION, REGION); ImmutableList<Region> nextRegionList = ImmutableList.of(REGION); Tuple<String, Iterable<com.google.api.services.compute.model.Region>> result = Tuple.of(cursor, Iterables.transform(regionList, Region.TO_PB_FUNCTION)); Tuple<String, Iterable<com.google.api.services.compute.model.Region>> nextResult = Tuple.of(nextCursor, Iterables.transform(nextRegionList, Region.TO_PB_FUNCTION)); Map<ComputeRpc.Option, ?> nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); EasyMock.expect(computeRpcMock.listRegions(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.expect(computeRpcMock.listRegions(nextOptions)).andReturn(nextResult); EasyMock.replay(computeRpcMock); Page<Region> page = compute.listRegions(); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(regionList.toArray(), Iterables.toArray(page.getValues(), Region.class)); page = page.getNextPage(); assertEquals(nextCursor, page.getNextPageToken()); assertArrayEquals(nextRegionList.toArray(), Iterables.toArray(page.getValues(), Region.class)); }