Search in sources :

Example 1 with ManagedZone

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

Example 2 with ManagedZone

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

Example 3 with ManagedZone

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

Example 4 with ManagedZone

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

Example 5 with ManagedZone

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

Aggregations

ManagedZone (com.google.api.services.dns.model.ManagedZone)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 BigInteger (java.math.BigInteger)1