use of com.google.api.services.dns.model.ManagedZone in project google-cloud-java by GoogleCloudPlatform.
the class DnsBatchTest method testGetZoneNotFound.
@Test
public void testGetZoneNotFound() {
EasyMock.reset(batchMock);
Capture<RpcBatch.Callback<ManagedZone>> callback = Capture.newInstance();
Capture<Map<DnsRpc.Option, Object>> capturedOptions = Capture.newInstance();
batchMock.addGetZone(EasyMock.eq(ZONE_NAME), EasyMock.capture(callback), EasyMock.capture(capturedOptions));
EasyMock.replay(batchMock);
DnsBatchResult<Zone> batchResult = dnsBatch.getZone(ZONE_NAME);
assertEquals(0, capturedOptions.getValue().size());
GoogleJsonError error = new GoogleJsonError();
error.setCode(404);
RpcBatch.Callback<ManagedZone> capturedCallback = callback.getValue();
capturedCallback.onFailure(error);
assertNull(batchResult.get());
}
use of com.google.api.services.dns.model.ManagedZone in project google-cloud-java by GoogleCloudPlatform.
the class ZoneInfoTest method testDateParsing.
@Test
public void testDateParsing() {
ManagedZone pb = INFO.toPb();
// a real value obtained from Google Cloud DNS
pb.setCreationTime("2016-01-19T18:00:12.854Z");
// parses the string timestamp to millis
ZoneInfo mz = ZoneInfo.fromPb(pb);
// converts it back to string
ManagedZone pbClone = mz.toPb();
assertEquals(pb, pbClone);
assertEquals(pb.getCreationTime(), pbClone.getCreationTime());
}
use of com.google.api.services.dns.model.ManagedZone in project google-cloud-java by GoogleCloudPlatform.
the class ZoneInfo method toPb.
ManagedZone toPb() {
ManagedZone pb = new ManagedZone();
pb.setDescription(this.getDescription());
pb.setDnsName(this.getDnsName());
if (this.getGeneratedId() != null) {
pb.setId(new BigInteger(this.getGeneratedId()));
}
pb.setName(this.getName());
// do use real attribute value which may be null
pb.setNameServers(this.nameServers);
pb.setNameServerSet(this.getNameServerSet());
if (this.getCreationTimeMillis() != null) {
pb.setCreationTime(ISODateTimeFormat.dateTime().withZoneUTC().print(this.getCreationTimeMillis()));
}
return pb;
}
use of com.google.api.services.dns.model.ManagedZone in project google-cloud-java by GoogleCloudPlatform.
the class DnsImpl method listZones.
private static Page<Zone> listZones(final DnsOptions serviceOptions, final Map<DnsRpc.Option, ?> optionsMap) {
try {
// get a list of managed zones
final DnsRpc rpc = serviceOptions.getDnsRpcV1();
DnsRpc.ListResult<ManagedZone> result = runWithRetries(new Callable<DnsRpc.ListResult<ManagedZone>>() {
@Override
public DnsRpc.ListResult<ManagedZone> call() {
return rpc.listZones(optionsMap);
}
}, serviceOptions.getRetrySettings(), EXCEPTION_HANDLER, serviceOptions.getClock());
String cursor = result.pageToken();
// transform that list into zone objects
Iterable<Zone> zones = result.results() == null ? ImmutableList.<Zone>of() : Iterables.transform(result.results(), zoneFromPb(serviceOptions));
return new PageImpl<>(new ZonePageFetcher(serviceOptions, cursor, optionsMap), cursor, zones);
} catch (RetryHelper.RetryHelperException e) {
throw DnsException.translateAndThrow(e);
}
}
use of com.google.api.services.dns.model.ManagedZone in project google-cloud-java by GoogleCloudPlatform.
the class DnsBatchTest method testCreateZone.
@Test
public void testCreateZone() {
EasyMock.reset(batchMock);
Capture<RpcBatch.Callback<ManagedZone>> callback = Capture.newInstance();
Capture<Map<DnsRpc.Option, Object>> capturedOptions = Capture.newInstance();
Capture<ManagedZone> capturedZone = Capture.newInstance();
batchMock.addCreateZone(EasyMock.capture(capturedZone), EasyMock.capture(callback), EasyMock.capture(capturedOptions));
EasyMock.replay(batchMock);
DnsBatchResult<Zone> batchResult = dnsBatch.createZone(ZONE_INFO);
assertEquals(0, capturedOptions.getValue().size());
assertEquals(ZONE_INFO.toPb(), capturedZone.getValue());
assertNotNull(callback.getValue());
try {
batchResult.get();
fail("No result available yet.");
} catch (IllegalStateException ex) {
// expected
}
// testing error here, success is tested with options
RpcBatch.Callback<ManagedZone> capturedCallback = callback.getValue();
GoogleJsonError error = new GoogleJsonError();
error.setCode(404);
capturedCallback.onFailure(error);
try {
batchResult.get();
fail("Should throw a DnsException on error.");
} catch (DnsException ex) {
// expected
}
}
Aggregations