Search in sources :

Example 1 with Change

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());
}
Also used : Change(com.google.api.services.dns.model.Change) RpcBatch(com.google.cloud.dns.spi.v1.RpcBatch) DnsRpc(com.google.cloud.dns.spi.v1.DnsRpc) GoogleJsonError(com.google.api.client.googleapis.json.GoogleJsonError) Map(java.util.Map) Test(org.junit.Test)

Example 2 with Change

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;
}
Also used : Change(com.google.api.services.dns.model.Change)

Example 3 with Change

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());
}
Also used : Change(com.google.api.services.dns.model.Change) Test(org.junit.Test)

Example 4 with Change

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);
    }
}
Also used : PageImpl(com.google.cloud.PageImpl) RetryHelper(com.google.cloud.RetryHelper) Change(com.google.api.services.dns.model.Change) DnsRpc(com.google.cloud.dns.spi.v1.DnsRpc)

Example 5 with Change

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
    }
}
Also used : Change(com.google.api.services.dns.model.Change) RpcBatch(com.google.cloud.dns.spi.v1.RpcBatch) DnsRpc(com.google.cloud.dns.spi.v1.DnsRpc) GoogleJsonError(com.google.api.client.googleapis.json.GoogleJsonError) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Change (com.google.api.services.dns.model.Change)5 DnsRpc (com.google.cloud.dns.spi.v1.DnsRpc)3 Test (org.junit.Test)3 GoogleJsonError (com.google.api.client.googleapis.json.GoogleJsonError)2 RpcBatch (com.google.cloud.dns.spi.v1.RpcBatch)2 Map (java.util.Map)2 PageImpl (com.google.cloud.PageImpl)1 RetryHelper (com.google.cloud.RetryHelper)1