use of com.google.cloud.dns.DnsException in project google-cloud-java by GoogleCloudPlatform.
the class ITDnsTest method testListZones.
@Test
public void testListZones() {
try {
List<Zone> zones = filter(DNS.listZones().iterateAll().iterator());
assertEquals(0, zones.size());
// some zones exists
Zone created = DNS.create(ZONE1);
zones = filter(DNS.listZones().iterateAll().iterator());
assertEquals(created, zones.get(0));
assertEquals(1, zones.size());
created = DNS.create(ZONE_EMPTY_DESCRIPTION);
zones = filter(DNS.listZones().iterateAll().iterator());
assertEquals(2, zones.size());
assertTrue(zones.contains(created));
// error in options
try {
DNS.listZones(Dns.ZoneListOption.pageSize(0));
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
try {
DNS.listZones(Dns.ZoneListOption.pageSize(-1));
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
// ok size
zones = filter(DNS.listZones(Dns.ZoneListOption.pageSize(1000)).iterateAll().iterator());
// we still have only 2 zones
assertEquals(2, zones.size());
// dns name problems
try {
DNS.listZones(Dns.ZoneListOption.dnsName("aaaaa"));
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
// ok name
zones = filter(DNS.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName())).iterateAll().iterator());
assertEquals(1, zones.size());
// field options
Iterator<Zone> zoneIterator = DNS.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.ZONE_ID)).iterateAll().iterator();
Zone zone = zoneIterator.next();
assertNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNull(zone.getDnsName());
assertNull(zone.getDescription());
assertNull(zone.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNotNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
zoneIterator = DNS.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.CREATION_TIME)).iterateAll().iterator();
zone = zoneIterator.next();
assertNotNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNull(zone.getDnsName());
assertNull(zone.getDescription());
assertNull(zone.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
zoneIterator = DNS.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.DNS_NAME)).iterateAll().iterator();
zone = zoneIterator.next();
assertNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNotNull(zone.getDnsName());
assertNull(zone.getDescription());
assertNull(zone.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
zoneIterator = DNS.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.DESCRIPTION)).iterateAll().iterator();
zone = zoneIterator.next();
assertNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNull(zone.getDnsName());
assertNotNull(zone.getDescription());
assertNull(zone.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
zoneIterator = DNS.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.NAME_SERVERS)).iterateAll().iterator();
zone = zoneIterator.next();
assertNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNull(zone.getDnsName());
assertNull(zone.getDescription());
assertNull(zone.getNameServerSet());
assertFalse(zone.getNameServers().isEmpty());
assertNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
zoneIterator = DNS.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.NAME_SERVER_SET)).iterateAll().iterator();
zone = zoneIterator.next();
assertNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNull(zone.getDnsName());
assertNull(zone.getDescription());
// we cannot set it using google-cloud
assertNull(zone.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
// several combined
zones = filter(DNS.listZones(Dns.ZoneListOption.fields(ZoneField.ZONE_ID, ZoneField.DESCRIPTION), Dns.ZoneListOption.pageSize(1)).iterateAll().iterator());
assertEquals(2, zones.size());
for (Zone current : zones) {
assertNull(current.getCreationTimeMillis());
assertNotNull(current.getName());
assertNull(current.getDnsName());
assertNotNull(current.getDescription());
assertNull(current.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNotNull(current.getGeneratedId());
}
} finally {
DNS.delete(ZONE1.getName());
DNS.delete(ZONE_EMPTY_DESCRIPTION.getName());
}
}
use of com.google.cloud.dns.DnsException in project google-cloud-java by GoogleCloudPlatform.
the class ITDnsTest method testListChanges.
@Test
public void testListChanges() {
try {
// no such zone exists
try {
DNS.listChangeRequests(ZONE1.getName());
fail();
} catch (DnsException ex) {
// expected
assertEquals(404, ex.getCode());
assertFalse(ex.isRetryable());
}
// zone exists but has no changes
DNS.create(ZONE1);
ImmutableList<ChangeRequest> changes = ImmutableList.copyOf(DNS.listChangeRequests(ZONE1.getName()).iterateAll());
// default change creating SOA and NS
assertEquals(1, changes.size());
// zone has changes
ChangeRequest change = DNS.applyChangeRequest(ZONE1.getName(), CHANGE_ADD_ZONE1);
waitForChangeToComplete(ZONE1.getName(), change.getGeneratedId());
change = DNS.applyChangeRequest(ZONE1.getName(), CHANGE_DELETE_ZONE1);
waitForChangeToComplete(ZONE1.getName(), change.getGeneratedId());
change = DNS.applyChangeRequest(ZONE1.getName(), CHANGE_ADD_ZONE1);
waitForChangeToComplete(ZONE1.getName(), change.getGeneratedId());
change = DNS.applyChangeRequest(ZONE1.getName(), CHANGE_DELETE_ZONE1);
waitForChangeToComplete(ZONE1.getName(), change.getGeneratedId());
changes = ImmutableList.copyOf(DNS.listChangeRequests(ZONE1.getName()).iterateAll());
assertEquals(5, changes.size());
// error in options
try {
DNS.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.pageSize(0));
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
try {
DNS.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.pageSize(-1));
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
// sorting order
ImmutableList<ChangeRequest> ascending = ImmutableList.copyOf(DNS.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING)).iterateAll());
ImmutableList<ChangeRequest> descending = ImmutableList.copyOf(DNS.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.DESCENDING)).iterateAll());
int size = 5;
assertEquals(size, descending.size());
assertEquals(size, ascending.size());
for (int i = 0; i < size; i++) {
assertEquals(descending.get(i), ascending.get(size - i - 1));
}
// field options
changes = ImmutableList.copyOf(DNS.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING), Dns.ChangeRequestListOption.fields(ChangeRequestField.ADDITIONS)).iterateAll());
change = changes.get(1);
assertEquals(CHANGE_ADD_ZONE1.getAdditions(), change.getAdditions());
assertTrue(change.getDeletions().isEmpty());
assertNotNull(change.getGeneratedId());
assertNull(change.getStartTimeMillis());
assertNull(change.status());
changes = ImmutableList.copyOf(DNS.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING), Dns.ChangeRequestListOption.fields(ChangeRequestField.DELETIONS)).iterateAll());
change = changes.get(2);
assertTrue(change.getAdditions().isEmpty());
assertNotNull(change.getDeletions());
assertNotNull(change.getGeneratedId());
assertNull(change.getStartTimeMillis());
assertNull(change.status());
changes = ImmutableList.copyOf(DNS.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING), Dns.ChangeRequestListOption.fields(ChangeRequestField.ID)).iterateAll());
change = changes.get(1);
assertTrue(change.getAdditions().isEmpty());
assertTrue(change.getDeletions().isEmpty());
assertNotNull(change.getGeneratedId());
assertNull(change.getStartTimeMillis());
assertNull(change.status());
changes = ImmutableList.copyOf(DNS.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING), Dns.ChangeRequestListOption.fields(ChangeRequestField.START_TIME)).iterateAll());
change = changes.get(1);
assertTrue(change.getAdditions().isEmpty());
assertTrue(change.getDeletions().isEmpty());
assertNotNull(change.getGeneratedId());
assertNotNull(change.getStartTimeMillis());
assertNull(change.status());
changes = ImmutableList.copyOf(DNS.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING), Dns.ChangeRequestListOption.fields(ChangeRequestField.STATUS)).iterateAll());
change = changes.get(1);
assertTrue(change.getAdditions().isEmpty());
assertTrue(change.getDeletions().isEmpty());
assertNotNull(change.getGeneratedId());
assertNull(change.getStartTimeMillis());
assertEquals(ChangeRequest.Status.DONE, change.status());
} finally {
clear();
}
}
use of com.google.cloud.dns.DnsException in project google-cloud-java by GoogleCloudPlatform.
the class ITDnsTest method testListDnsRecordSetsBatch.
@Test
public void testListDnsRecordSetsBatch() {
try {
Zone zone = DNS.create(ZONE1);
DnsBatch batch = DNS.batch();
DnsBatchResult<Page<RecordSet>> result = batch.listRecordSets(zone.getName());
batch.submit();
ImmutableList<RecordSet> recordSets = ImmutableList.copyOf(result.get().iterateAll());
assertEquals(2, recordSets.size());
ImmutableList<RecordSet.Type> defaultRecords = ImmutableList.of(RecordSet.Type.NS, RecordSet.Type.SOA);
for (RecordSet recordSet : recordSets) {
assertTrue(defaultRecords.contains(recordSet.getType()));
}
// field options
batch = DNS.batch();
DnsBatchResult<Page<RecordSet>> ttlResult = batch.listRecordSets(zone.getName(), Dns.RecordSetListOption.fields(RecordSetField.TTL));
DnsBatchResult<Page<RecordSet>> nameResult = batch.listRecordSets(zone.getName(), Dns.RecordSetListOption.fields(RecordSetField.NAME));
DnsBatchResult<Page<RecordSet>> recordsResult = batch.listRecordSets(zone.getName(), Dns.RecordSetListOption.fields(RecordSetField.DNS_RECORDS));
DnsBatchResult<Page<RecordSet>> pageSizeResult = batch.listRecordSets(zone.getName(), Dns.RecordSetListOption.fields(RecordSetField.TYPE), Dns.RecordSetListOption.pageSize(1));
batch.submit();
Iterator<RecordSet> recordSetIterator = ttlResult.get().iterateAll().iterator();
int counter = 0;
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertEquals(recordSets.get(counter).getTtl(), recordSet.getTtl());
assertEquals(recordSets.get(counter).getName(), recordSet.getName());
assertEquals(recordSets.get(counter).getType(), recordSet.getType());
assertTrue(recordSet.getRecords().isEmpty());
counter++;
}
assertEquals(2, counter);
recordSetIterator = nameResult.get().iterateAll().iterator();
counter = 0;
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertEquals(recordSets.get(counter).getName(), recordSet.getName());
assertEquals(recordSets.get(counter).getType(), recordSet.getType());
assertTrue(recordSet.getRecords().isEmpty());
assertNull(recordSet.getTtl());
counter++;
}
assertEquals(2, counter);
recordSetIterator = recordsResult.get().iterateAll().iterator();
counter = 0;
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertEquals(recordSets.get(counter).getRecords(), recordSet.getRecords());
assertEquals(recordSets.get(counter).getName(), recordSet.getName());
assertEquals(recordSets.get(counter).getType(), recordSet.getType());
assertNull(recordSet.getTtl());
counter++;
}
assertEquals(2, counter);
// also test paging
recordSetIterator = pageSizeResult.get().iterateAll().iterator();
counter = 0;
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertEquals(recordSets.get(counter).getType(), recordSet.getType());
assertEquals(recordSets.get(counter).getName(), recordSet.getName());
assertTrue(recordSet.getRecords().isEmpty());
assertNull(recordSet.getTtl());
counter++;
}
assertEquals(2, counter);
// test page size
Page<RecordSet> recordSetPage = pageSizeResult.get();
assertEquals(1, ImmutableList.copyOf(recordSetPage.getValues().iterator()).size());
// test name filter
ChangeRequest change = DNS.applyChangeRequest(ZONE1.getName(), CHANGE_ADD_ZONE1);
waitForChangeToComplete(ZONE1.getName(), change.getGeneratedId());
batch = DNS.batch();
result = batch.listRecordSets(ZONE1.getName(), Dns.RecordSetListOption.dnsName(A_RECORD_ZONE1.getName()));
batch.submit();
recordSetIterator = result.get().iterateAll().iterator();
counter = 0;
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertTrue(ImmutableList.of(A_RECORD_ZONE1.getType(), AAAA_RECORD_ZONE1.getType()).contains(recordSet.getType()));
counter++;
}
assertEquals(2, counter);
// test type filter
batch = DNS.batch();
result = batch.listRecordSets(ZONE1.getName(), Dns.RecordSetListOption.dnsName(A_RECORD_ZONE1.getName()), Dns.RecordSetListOption.type(A_RECORD_ZONE1.getType()));
batch.submit();
recordSetIterator = result.get().iterateAll().iterator();
counter = 0;
while (recordSetIterator.hasNext()) {
RecordSet recordSet = recordSetIterator.next();
assertEquals(A_RECORD_ZONE1, recordSet);
counter++;
}
assertEquals(1, counter);
batch = DNS.batch();
DnsBatchResult<Page<RecordSet>> noNameError = batch.listRecordSets(ZONE1.getName(), Dns.RecordSetListOption.type(A_RECORD_ZONE1.getType()));
DnsBatchResult<Page<RecordSet>> zeroSizeError = batch.listRecordSets(ZONE1.getName(), Dns.RecordSetListOption.pageSize(0));
DnsBatchResult<Page<RecordSet>> negativeSizeError = batch.listRecordSets(ZONE1.getName(), Dns.RecordSetListOption.pageSize(-1));
batch.submit();
// check wrong arguments
try {
// name is not set
noNameError.get();
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
try {
zeroSizeError.get();
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
try {
negativeSizeError.get();
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
waitForChangeToComplete(ZONE1.getName(), change.getGeneratedId());
} finally {
clear();
}
}
use of com.google.cloud.dns.DnsException in project google-cloud-java by GoogleCloudPlatform.
the class ITDnsTest method testListChangesBatch.
@Test
public void testListChangesBatch() {
try {
DnsBatch batch = DNS.batch();
DnsBatchResult<Page<ChangeRequest>> result = batch.listChangeRequests(ZONE1.getName());
batch.submit();
try {
result.get();
fail("Zone does not exist yet");
} catch (DnsException ex) {
// expected
assertEquals(404, ex.getCode());
assertFalse(ex.isRetryable());
}
// zone exists but has no changes
DNS.create(ZONE1);
batch = DNS.batch();
result = batch.listChangeRequests(ZONE1.getName());
batch.submit();
// default change creating SOA and NS
assertEquals(1, Iterables.size(result.get().getValues()));
// zone has changes
ChangeRequest change = DNS.applyChangeRequest(ZONE1.getName(), CHANGE_ADD_ZONE1);
waitForChangeToComplete(ZONE1.getName(), change.getGeneratedId());
change = DNS.applyChangeRequest(ZONE1.getName(), CHANGE_DELETE_ZONE1);
waitForChangeToComplete(ZONE1.getName(), change.getGeneratedId());
batch = DNS.batch();
result = batch.listChangeRequests(ZONE1.getName());
DnsBatchResult<Page<ChangeRequest>> errorPageSize = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.pageSize(0));
DnsBatchResult<Page<ChangeRequest>> errorPageNegative = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.pageSize(-1));
DnsBatchResult<Page<ChangeRequest>> resultAscending = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING));
DnsBatchResult<Page<ChangeRequest>> resultDescending = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.DESCENDING));
DnsBatchResult<Page<ChangeRequest>> resultAdditions = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING), Dns.ChangeRequestListOption.fields(ChangeRequestField.ADDITIONS));
DnsBatchResult<Page<ChangeRequest>> resultDeletions = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING), Dns.ChangeRequestListOption.fields(ChangeRequestField.DELETIONS));
DnsBatchResult<Page<ChangeRequest>> resultId = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING), Dns.ChangeRequestListOption.fields(ChangeRequestField.ID));
DnsBatchResult<Page<ChangeRequest>> resultTime = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING), Dns.ChangeRequestListOption.fields(ChangeRequestField.START_TIME));
DnsBatchResult<Page<ChangeRequest>> resultStatus = batch.listChangeRequests(ZONE1.getName(), Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING), Dns.ChangeRequestListOption.fields(ChangeRequestField.STATUS));
batch.submit();
assertEquals(3, Iterables.size(result.get().getValues()));
// error in options
try {
errorPageSize.get();
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
try {
errorPageNegative.get();
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
// sorting order
ImmutableList<ChangeRequest> ascending = ImmutableList.copyOf(resultAscending.get().iterateAll());
ImmutableList<ChangeRequest> descending = ImmutableList.copyOf(resultDescending.get().iterateAll());
int size = 3;
assertEquals(size, descending.size());
assertEquals(size, ascending.size());
for (int i = 0; i < size; i++) {
assertEquals(descending.get(i), ascending.get(size - i - 1));
}
// field options
change = Iterables.get(resultAdditions.get().getValues(), 1);
assertEquals(CHANGE_ADD_ZONE1.getAdditions(), change.getAdditions());
assertTrue(change.getDeletions().isEmpty());
assertNotNull(change.getGeneratedId());
assertNull(change.getStartTimeMillis());
assertNull(change.status());
change = Iterables.get(resultDeletions.get().getValues(), 2);
assertTrue(change.getAdditions().isEmpty());
assertNotNull(change.getDeletions());
assertNotNull(change.getGeneratedId());
assertNull(change.getStartTimeMillis());
assertNull(change.status());
change = Iterables.get(resultId.get().getValues(), 1);
assertTrue(change.getAdditions().isEmpty());
assertTrue(change.getDeletions().isEmpty());
assertNotNull(change.getGeneratedId());
assertNull(change.getStartTimeMillis());
assertNull(change.status());
change = Iterables.get(resultTime.get().getValues(), 1);
assertTrue(change.getAdditions().isEmpty());
assertTrue(change.getDeletions().isEmpty());
assertNotNull(change.getGeneratedId());
assertNotNull(change.getStartTimeMillis());
assertNull(change.status());
change = Iterables.get(resultStatus.get().getValues(), 1);
assertTrue(change.getAdditions().isEmpty());
assertTrue(change.getDeletions().isEmpty());
assertNotNull(change.getGeneratedId());
assertNull(change.getStartTimeMillis());
assertEquals(ChangeRequest.Status.DONE, change.status());
} finally {
clear();
}
}
use of com.google.cloud.dns.DnsException in project google-cloud-java by GoogleCloudPlatform.
the class ITDnsTest method testListZonesBatch.
@Test
public void testListZonesBatch() {
try {
DnsBatch batch = DNS.batch();
DnsBatchResult<Page<Zone>> result = batch.listZones();
batch.submit();
List<Zone> zones = filter(result.get().iterateAll().iterator());
assertEquals(0, zones.size());
// some zones exists
Zone firstZone = DNS.create(ZONE1);
batch = DNS.batch();
result = batch.listZones();
batch.submit();
zones = filter(result.get().iterateAll().iterator());
assertEquals(1, zones.size());
assertEquals(firstZone, zones.get(0));
Zone created = DNS.create(ZONE_EMPTY_DESCRIPTION);
batch = DNS.batch();
result = batch.listZones();
DnsBatchResult<Page<Zone>> zeroSizeError = batch.listZones(Dns.ZoneListOption.pageSize(0));
DnsBatchResult<Page<Zone>> negativeSizeError = batch.listZones(Dns.ZoneListOption.pageSize(-1));
DnsBatchResult<Page<Zone>> okSize = batch.listZones(Dns.ZoneListOption.pageSize(1));
DnsBatchResult<Page<Zone>> nameError = batch.listZones(Dns.ZoneListOption.dnsName("aaaaa"));
DnsBatchResult<Page<Zone>> okName = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()));
DnsBatchResult<Page<Zone>> idResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.ZONE_ID));
DnsBatchResult<Page<Zone>> timeResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.CREATION_TIME));
DnsBatchResult<Page<Zone>> dnsNameResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.DNS_NAME));
DnsBatchResult<Page<Zone>> descriptionResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.DESCRIPTION));
DnsBatchResult<Page<Zone>> nameServersResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.NAME_SERVERS));
DnsBatchResult<Page<Zone>> nameServerSetResult = batch.listZones(Dns.ZoneListOption.dnsName(ZONE1.getDnsName()), Dns.ZoneListOption.fields(ZoneField.NAME_SERVER_SET));
DnsBatchResult<Page<Zone>> combinationResult = batch.listZones(Dns.ZoneListOption.fields(ZoneField.ZONE_ID, ZoneField.DESCRIPTION), Dns.ZoneListOption.pageSize(1));
batch.submit();
zones = filter(result.get().iterateAll().iterator());
assertEquals(2, zones.size());
assertTrue(zones.contains(firstZone));
assertTrue(zones.contains(created));
// error in options
try {
zeroSizeError.get();
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
try {
negativeSizeError.get();
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
// ok size
assertEquals(1, Iterables.size(okSize.get().getValues()));
// dns name problems
try {
nameError.get();
fail();
} catch (DnsException ex) {
// expected
assertEquals(400, ex.getCode());
assertFalse(ex.isRetryable());
}
// ok name
zones = filter(okName.get().iterateAll().iterator());
assertEquals(1, zones.size());
// field options
Iterator<Zone> zoneIterator = idResult.get().iterateAll().iterator();
Zone zone = zoneIterator.next();
assertNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNull(zone.getDnsName());
assertNull(zone.getDescription());
assertNull(zone.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNotNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
zoneIterator = timeResult.get().iterateAll().iterator();
zone = zoneIterator.next();
assertNotNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNull(zone.getDnsName());
assertNull(zone.getDescription());
assertNull(zone.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
zoneIterator = dnsNameResult.get().iterateAll().iterator();
zone = zoneIterator.next();
assertNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNotNull(zone.getDnsName());
assertNull(zone.getDescription());
assertNull(zone.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
zoneIterator = descriptionResult.get().iterateAll().iterator();
zone = zoneIterator.next();
assertNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNull(zone.getDnsName());
assertNotNull(zone.getDescription());
assertNull(zone.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
zoneIterator = nameServersResult.get().iterateAll().iterator();
zone = zoneIterator.next();
assertNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNull(zone.getDnsName());
assertNull(zone.getDescription());
assertNull(zone.getNameServerSet());
assertFalse(zone.getNameServers().isEmpty());
assertNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
zoneIterator = nameServerSetResult.get().iterateAll().iterator();
zone = zoneIterator.next();
assertNull(zone.getCreationTimeMillis());
assertNotNull(zone.getName());
assertNull(zone.getDnsName());
assertNull(zone.getDescription());
// we cannot set it using google-cloud
assertNull(zone.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNull(zone.getGeneratedId());
assertFalse(zoneIterator.hasNext());
// several combined
zones = filter(combinationResult.get().iterateAll().iterator());
assertEquals(2, zones.size());
for (Zone current : zones) {
assertNull(current.getCreationTimeMillis());
assertNotNull(current.getName());
assertNull(current.getDnsName());
assertNotNull(current.getDescription());
assertNull(current.getNameServerSet());
assertTrue(zone.getNameServers().isEmpty());
assertNotNull(current.getGeneratedId());
}
} finally {
DNS.delete(ZONE1.getName());
DNS.delete(ZONE_EMPTY_DESCRIPTION.getName());
}
}
Aggregations