use of com.google.api.services.dns.model.Change in project google-cloud-java by GoogleCloudPlatform.
the class DnsBatchTest method testGetChangeRequestNotFound.
@Test
public void testGetChangeRequestNotFound() {
EasyMock.reset(batchMock);
Capture<RpcBatch.Callback<Change>> callback = Capture.newInstance();
Capture<Map<DnsRpc.Option, Object>> capturedOptions = Capture.newInstance();
batchMock.addGetChangeRequest(EasyMock.eq(ZONE_NAME), EasyMock.eq(CHANGE_REQUEST_COMPLETE.getGeneratedId()), EasyMock.capture(callback), EasyMock.capture(capturedOptions));
EasyMock.replay(batchMock);
DnsBatchResult<ChangeRequest> batchResult = dnsBatch.getChangeRequest(ZONE_NAME, CHANGE_REQUEST_COMPLETE.getGeneratedId());
assertEquals(0, capturedOptions.getValue().size());
RpcBatch.Callback<Change> capturedCallback = callback.getValue();
GoogleJsonError error = new GoogleJsonError();
GoogleJsonError.ErrorInfo errorInfo = new GoogleJsonError.ErrorInfo();
errorInfo.setReason("reason");
errorInfo.setLocation("entity.parameters.changeId");
error.setCode(404);
error.setErrors(ImmutableList.of(errorInfo));
capturedCallback.onFailure(error);
assertNull(batchResult.get());
}
use of com.google.api.services.dns.model.Change in project google-cloud-java by GoogleCloudPlatform.
the class ChangeRequestInfo method toPb.
Change toPb() {
Change pb = new Change();
// set id
if (getGeneratedId() != null) {
pb.setId(getGeneratedId());
}
// set timestamp
if (getStartTimeMillis() != null) {
pb.setStartTime(ISODateTimeFormat.dateTime().withZoneUTC().print(getStartTimeMillis()));
}
// set status
if (status() != null) {
pb.setStatus(status().name().toLowerCase());
}
// set a list of additions
pb.setAdditions(Lists.transform(getAdditions(), RecordSet.TO_PB_FUNCTION));
// set a list of deletions
pb.setDeletions(Lists.transform(getDeletions(), RecordSet.TO_PB_FUNCTION));
return pb;
}
use of com.google.api.services.dns.model.Change in project google-cloud-java by GoogleCloudPlatform.
the class ChangeRequestInfoTest method testDateParsing.
@Test
public void testDateParsing() {
// obtained from service
String startTime = "2016-01-26T18:33:43.512Z";
Change change = CHANGE.toPb().setStartTime(startTime);
ChangeRequestInfo converted = ChangeRequest.fromPb(change);
assertNotNull(converted.getStartTimeMillis());
assertEquals(change, converted.toPb());
assertEquals(change.getStartTime(), converted.toPb().getStartTime());
}
use of com.google.api.services.dns.model.Change in project google-cloud-java by GoogleCloudPlatform.
the class DnsImpl method listChangeRequests.
private static Page<ChangeRequest> listChangeRequests(final String zoneName, final DnsOptions serviceOptions, final Map<DnsRpc.Option, ?> optionsMap) {
try {
// get a list of changes
final DnsRpc rpc = serviceOptions.getDnsRpcV1();
DnsRpc.ListResult<Change> result = runWithRetries(new Callable<DnsRpc.ListResult<Change>>() {
@Override
public DnsRpc.ListResult<Change> call() {
return rpc.listChangeRequests(zoneName, optionsMap);
}
}, serviceOptions.getRetrySettings(), EXCEPTION_HANDLER, serviceOptions.getClock());
String cursor = result.pageToken();
// transform that list into change request objects
Iterable<ChangeRequest> changes = result.results() == null ? ImmutableList.<ChangeRequest>of() : Iterables.transform(result.results(), ChangeRequest.fromPbFunction(serviceOptions.getService(), zoneName));
return new PageImpl<>(new ChangeRequestPageFetcher(zoneName, serviceOptions, cursor, optionsMap), cursor, changes);
} catch (RetryHelper.RetryHelperException e) {
throw DnsException.translateAndThrow(e);
}
}
use of com.google.api.services.dns.model.Change in project google-cloud-java by GoogleCloudPlatform.
the class DnsBatchTest method testApplyChangeRequest.
@Test
public void testApplyChangeRequest() {
EasyMock.reset(batchMock);
Capture<RpcBatch.Callback<Change>> callback = Capture.newInstance();
Capture<Map<DnsRpc.Option, Object>> capturedOptions = Capture.newInstance();
batchMock.addApplyChangeRequest(EasyMock.eq(ZONE_NAME), EasyMock.eq(CHANGE_REQUEST_PARTIAL.toPb()), EasyMock.capture(callback), EasyMock.capture(capturedOptions));
EasyMock.replay(batchMock);
DnsBatchResult<ChangeRequest> batchResult = dnsBatch.applyChangeRequest(ZONE_INFO.getName(), CHANGE_REQUEST_PARTIAL);
assertEquals(0, capturedOptions.getValue().size());
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<Change> 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