@Override protected IterableWithMarker<T> computeNext() { if (unread) try { return current; } finally { unread = false; } else if (current.nextMarker().isPresent()) return current = markerToNext.apply(current.nextMarker().get()); else return endOfData(); }
@Override public Iterator<E> next() { return iterator.next().iterator(); } };
@Test public void testMarkerEqual() { IterableWithMarker<String> initial = IterableWithMarkers.from(ImmutableSet.of("foo", "bar"), "MARKER"); Assert.assertEquals(initial.toSet(), ImmutableSet.of("foo", "bar")); Assert.assertEquals(initial.nextMarker(), Optional.of("MARKER")); } }
/** * Tests parsing all possible XML elements that could be encountered by {@link ListAlarmHistoryResponseHandler}. * * @throws Exception if something goes wrong */ public void testParseFullResponse() throws Exception { IterableWithMarker<AlarmHistoryItem> alarmHistoryItems = factory.create(injector.getInstance(ListAlarmHistoryResponseHandler.class)) .parse(getClass().getResourceAsStream("/DescribeAlarmHistoryResponse.xml")); assertEquals(alarmHistoryItems.toString(), expected().toString()); assertFalse(alarmHistoryItems.nextMarker().isPresent()); }
Metric metric = response.iterator().next(); response = api().list(ListMetricsOptions.Builder.afterMarker(response.nextMarker().orNull()));
public void test() { InputStream is = getClass().getResourceAsStream("/hosted_zones.xml"); IterableWithMarker<HostedZone> expected = expected(); ListHostedZonesResponseHandler handler = injector.getInstance(ListHostedZonesResponseHandler.class); IterableWithMarker<HostedZone> result = factory.create(handler).parse(is); assertEquals(result.toString(), expected.toString()); }
@Test(expectedExceptions = ResourceNotFoundException.class) public void testListWhenResponseIs404() { Route53Api fail = requestSendsResponse(list, notFound); assertEquals(fail.getResourceRecordSetApiForHostedZone("Z1PA6795UKMFR9").list().get(0).toSet(), ImmutableSet.of()); }
public void testListRegionsOnePage() { final AtomicInteger found = new AtomicInteger(0); assertTrue(api().list(page(1)).allMatch(new Predicate<Region>() { @Override public boolean apply(Region input) { found.incrementAndGet(); return !Strings.isNullOrEmpty(input.slug()); } }), "All regions must have the 'slug' field populated"); assertTrue(found.get() > 0, "Expected some regions to be returned"); }
private PagedIterable<HostedZone> zones() { PagedIterable<HostedZone> zones = api.getHostedZoneApi().list(); if (zones.get(0).isEmpty()) throw new SkipException("no zones in context: " + identity); return zones; }
/** * Tests {@link S3#listBucket(S3Client, String, ListBucketOptions)} where a * single response returns all results. * * @throws Exception * if anything goes wrong */ @Test public void testSinglePageResult() throws Exception { S3Client api = createMock(S3Client.class); ListBucketOptions options = new ListBucketOptions(); ListBucketResponse response = new ListBucketHandlerTest().expected(); expect(api.listBucket("bucket", options)).andReturn(response).once(); EasyMock.replay(api); PagedIterable<ObjectMetadata> result = S3.listBucket(api, "bucket", options); // number of pages assertEquals(result.size(), 1); // number of objects assertEquals(result.get(0).size(), 10); }
/** * Tests parsing all possible XML elements that could be encountered by {@link ListAlarmsResponseHandler}. * * @throws Exception if something goes wrong */ public void testParseFullResponse() throws Exception { IterableWithMarker<Alarm> metricAlarms = factory.create(injector.getInstance(ListAlarmsResponseHandler.class)) .parse(getClass().getResourceAsStream("/DescribeAlarmsResponse.xml")); assertEquals(metricAlarms.toString(), expected().toString()); assertFalse(metricAlarms.nextMarker().isPresent()); }
Metric metric = response.iterator().next(); response = api().list(ListMetricsOptions.Builder.afterMarker(response.nextMarker().orNull()));
public void test() { InputStream is = getClass().getResourceAsStream("/hosted_zones.xml"); IterableWithMarker<HostedZone> expected = expected(); ListHostedZonesResponseHandler handler = injector.getInstance(ListHostedZonesResponseHandler.class); IterableWithMarker<HostedZone> result = factory.create(handler).parse(is); assertEquals(result.toString(), expected.toString()); }
@Test(expectedExceptions = ResourceNotFoundException.class) public void testListWhenResponseIs404() { Route53Api fail = requestSendsResponse(list, notFound); assertEquals(fail.getHostedZoneApi().list().get(0).toSet(), ImmutableSet.of()); }
public void testListSizesOnePage() { final AtomicInteger found = new AtomicInteger(0); assertTrue(api().list(page(1)).allMatch(new Predicate<Size>() { @Override public boolean apply(Size input) { found.incrementAndGet(); return !Strings.isNullOrEmpty(input.slug()); } }), "All sizes must have the 'slug' field populated"); assertTrue(found.get() > 0, "Expected some sizes to be returned"); }
private PagedIterable<HostedZone> zones() { PagedIterable<HostedZone> zones = api.getHostedZoneApi().list(); if (zones.get(0).isEmpty()) throw new SkipException("no zones in context: " + identity); return zones; }
/** * Tests {@link S3#listBucket(S3Client, String, ListBucketOptions)} where a * single response returns all results. * * @throws Exception * if anything goes wrong */ @Test public void testSinglePageResult() throws Exception { S3Client api = createMock(S3Client.class); ListBucketOptions options = new ListBucketOptions(); ListBucketResponse response = new ListBucketHandlerTest().expected(); expect(api.listBucket("bucket", options)).andReturn(response).once(); EasyMock.replay(api); PagedIterable<ObjectMetadata> result = S3.listBucket(api, "bucket", options); // number of pages assertEquals(result.size(), 1); // number of objects assertEquals(result.get(0).size(), 10); }
@Override protected IterableWithMarker<T> computeNext() { if (unread) try { return current; } finally { unread = false; } else if (current.nextMarker().isPresent()) return current = markerToNext.apply(current.nextMarker().get()); else return endOfData(); }
@Test public void testElementsEqual() { IterableWithMarker<String> initial = IterableWithMarkers.from(ImmutableSet.of("foo", "bar")); Assert.assertEquals(initial.toSet(), ImmutableSet.of("foo", "bar")); Assert.assertEquals(initial.nextMarker(), Optional.absent()); }
@Override public Iterator<E> next() { return iterator.next().iterator(); } };