@Test public void testListEmptyGlobalAddresses() { ImmutableList<com.google.api.services.compute.model.Address> addresses = ImmutableList.of(); Tuple<String, Iterable<com.google.api.services.compute.model.Address>> result = Tuple.<String, Iterable<com.google.api.services.compute.model.Address>>of(null, addresses); EasyMock.expect(computeRpcMock.listGlobalAddresses(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.replay(computeRpcMock); compute = options.getService(); Page<Address> page = compute.listGlobalAddresses(); assertNull(page.getNextPageToken()); assertArrayEquals(addresses.toArray(), Iterables.toArray(page.getValues(), Address.class)); }
@Test public void testListGlobalAddressesWithOptions() { String cursor = "cursor"; compute = options.getService(); ImmutableList<Address> addressList = ImmutableList.of( new Address(compute, new AddressInfo.BuilderImpl(GLOBAL_ADDRESS)), new Address(compute, new AddressInfo.BuilderImpl(GLOBAL_ADDRESS))); Tuple<String, Iterable<com.google.api.services.compute.model.Address>> result = Tuple.of(cursor, Iterables.transform(addressList, AddressInfo.TO_PB_FUNCTION)); EasyMock.expect(computeRpcMock.listGlobalAddresses(ADDRESS_LIST_OPTIONS)).andReturn(result); EasyMock.replay(computeRpcMock); Page<Address> page = compute.listGlobalAddresses( ADDRESS_LIST_PAGE_SIZE, ADDRESS_LIST_PAGE_TOKEN, ADDRESS_LIST_FILTER); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(addressList.toArray(), Iterables.toArray(page.getValues(), Address.class)); }
@Test public void testListGlobalAddresses() { String cursor = "cursor"; compute = options.getService(); ImmutableList<Address> addressList = ImmutableList.of( new Address(compute, new AddressInfo.BuilderImpl(GLOBAL_ADDRESS)), new Address(compute, new AddressInfo.BuilderImpl(GLOBAL_ADDRESS))); Tuple<String, Iterable<com.google.api.services.compute.model.Address>> result = Tuple.of(cursor, Iterables.transform(addressList, AddressInfo.TO_PB_FUNCTION)); EasyMock.expect(computeRpcMock.listGlobalAddresses(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.replay(computeRpcMock); Page<Address> page = compute.listGlobalAddresses(); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(addressList.toArray(), Iterables.toArray(page.getValues(), Address.class)); }
@Test public void testListGlobalAddressesNextPage() { String cursor = "cursor"; String nextCursor = "nextCursor"; compute = options.getService(); ImmutableList<Address> addressList = ImmutableList.of( new Address(compute, new AddressInfo.BuilderImpl(GLOBAL_ADDRESS)), new Address(compute, new AddressInfo.BuilderImpl(GLOBAL_ADDRESS))); ImmutableList<Address> nextAddressList = ImmutableList.of(new Address(compute, new AddressInfo.BuilderImpl(GLOBAL_ADDRESS))); Tuple<String, Iterable<com.google.api.services.compute.model.Address>> result = Tuple.of(cursor, Iterables.transform(addressList, AddressInfo.TO_PB_FUNCTION)); Tuple<String, Iterable<com.google.api.services.compute.model.Address>> nextResult = Tuple.of(nextCursor, Iterables.transform(nextAddressList, AddressInfo.TO_PB_FUNCTION)); Map<ComputeRpc.Option, ?> nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); EasyMock.expect(computeRpcMock.listGlobalAddresses(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.expect(computeRpcMock.listGlobalAddresses(nextOptions)).andReturn(nextResult); EasyMock.replay(computeRpcMock); Page<Address> page = compute.listGlobalAddresses(); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(addressList.toArray(), Iterables.toArray(page.getValues(), Address.class)); page = page.getNextPage(); assertEquals(nextCursor, page.getNextPageToken()); assertArrayEquals( nextAddressList.toArray(), Iterables.toArray(page.getValues(), Address.class)); }
Compute.AddressFilter.equals(Compute.AddressField.NAME, prefix + "\\d"); Page<Address> addressPage = compute.listGlobalAddresses(Compute.AddressListOption.filter(filter)); Iterator<Address> addressIterator = addressPage.iterateAll().iterator(); int count = 0; compute.listGlobalAddresses( Compute.AddressListOption.filter(filter), Compute.AddressListOption.fields(Compute.AddressField.ADDRESS));