Search in sources :

Example 1 with Zone

use of com.google.cloud.dns.Zone in project google-cloud-java by GoogleCloudPlatform.

the class ITDnsTest method testCreateValidZone.

@Test
public void testCreateValidZone() {
    try {
        Zone created = DNS.create(ZONE1);
        assertEquals(ZONE1.getDescription(), created.getDescription());
        assertEquals(ZONE1.getDnsName(), created.getDnsName());
        assertEquals(ZONE1.getName(), created.getName());
        assertNotNull(created.getCreationTimeMillis());
        assertNotNull(created.getNameServers());
        assertNull(created.getNameServerSet());
        assertNotNull(created.getGeneratedId());
        Zone retrieved = DNS.getZone(ZONE1.getName());
        assertEquals(created, retrieved);
        created = DNS.create(ZONE_EMPTY_DESCRIPTION);
        assertEquals(ZONE_EMPTY_DESCRIPTION.getDescription(), created.getDescription());
        assertEquals(ZONE_EMPTY_DESCRIPTION.getDnsName(), created.getDnsName());
        assertEquals(ZONE_EMPTY_DESCRIPTION.getName(), created.getName());
        assertNotNull(created.getCreationTimeMillis());
        assertNotNull(created.getNameServers());
        assertNull(created.getNameServerSet());
        assertNotNull(created.getGeneratedId());
        retrieved = DNS.getZone(ZONE_EMPTY_DESCRIPTION.getName());
        assertEquals(created, retrieved);
    } finally {
        DNS.delete(ZONE1.getName());
        DNS.delete(ZONE_EMPTY_DESCRIPTION.getName());
    }
}
Also used : Zone(com.google.cloud.dns.Zone) Test(org.junit.Test)

Example 2 with Zone

use of com.google.cloud.dns.Zone 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());
    }
}
Also used : DnsException(com.google.cloud.dns.DnsException) Zone(com.google.cloud.dns.Zone) Test(org.junit.Test)

Example 3 with Zone

use of com.google.cloud.dns.Zone in project google-cloud-java by GoogleCloudPlatform.

the class ITDnsTest method testDeleteZone.

@Test
public void testDeleteZone() {
    try {
        Zone created = DNS.create(ZONE1);
        assertEquals(created, DNS.getZone(ZONE1.getName()));
        DNS.delete(ZONE1.getName());
        assertNull(DNS.getZone(ZONE1.getName()));
    } finally {
        DNS.delete(ZONE1.getName());
    }
}
Also used : Zone(com.google.cloud.dns.Zone) Test(org.junit.Test)

Example 4 with Zone

use of com.google.cloud.dns.Zone in project google-cloud-java by GoogleCloudPlatform.

the class ITDnsTest method testCreateZoneWithOptions.

@Test
public void testCreateZoneWithOptions() {
    try {
        Zone created = DNS.create(ZONE1, Dns.ZoneOption.fields(ZoneField.CREATION_TIME));
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNotNull(created.getCreationTimeMillis());
        assertNull(created.getDescription());
        assertNull(created.getDnsName());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created.delete();
        created = DNS.create(ZONE1, Dns.ZoneOption.fields(ZoneField.DESCRIPTION));
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertEquals(ZONE1.getDescription(), created.getDescription());
        assertNull(created.getDnsName());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created.delete();
        created = DNS.create(ZONE1, Dns.ZoneOption.fields(ZoneField.DNS_NAME));
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertEquals(ZONE1.getDnsName(), created.getDnsName());
        assertNull(created.getDescription());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created.delete();
        created = DNS.create(ZONE1, Dns.ZoneOption.fields(ZoneField.NAME));
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertNull(created.getDnsName());
        assertNull(created.getDescription());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created.delete();
        created = DNS.create(ZONE1, Dns.ZoneOption.fields(ZoneField.NAME_SERVER_SET));
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertNull(created.getDnsName());
        assertNull(created.getDescription());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        // we did not set it
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created.delete();
        created = DNS.create(ZONE1, Dns.ZoneOption.fields(ZoneField.NAME_SERVERS));
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertNull(created.getDnsName());
        assertNull(created.getDescription());
        assertFalse(created.getNameServers().isEmpty());
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created.delete();
        created = DNS.create(ZONE1, Dns.ZoneOption.fields(ZoneField.ZONE_ID));
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertNull(created.getDnsName());
        assertNull(created.getDescription());
        assertNotNull(created.getNameServers());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        assertNotNull(created.getGeneratedId());
        created.delete();
        // combination of multiple things
        created = DNS.create(ZONE1, Dns.ZoneOption.fields(ZoneField.ZONE_ID, ZoneField.NAME_SERVERS, ZoneField.NAME_SERVER_SET, ZoneField.DESCRIPTION));
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertNull(created.getDnsName());
        assertEquals(ZONE1.getDescription(), created.getDescription());
        assertFalse(created.getNameServers().isEmpty());
        // we did not set it
        assertNull(created.getNameServerSet());
        assertNotNull(created.getGeneratedId());
    } finally {
        DNS.delete(ZONE1.getName());
    }
}
Also used : Zone(com.google.cloud.dns.Zone) Test(org.junit.Test)

Example 5 with Zone

use of com.google.cloud.dns.Zone in project google-cloud-java by GoogleCloudPlatform.

the class ITDnsTest method testGetZoneBatch.

@Test
public void testGetZoneBatch() {
    try {
        DNS.create(ZONE1, Dns.ZoneOption.fields(ZoneField.NAME));
        DnsBatch batch = DNS.batch();
        DnsBatchResult<Zone> timeResult = batch.getZone(ZONE1.getName(), Dns.ZoneOption.fields(ZoneField.CREATION_TIME));
        DnsBatchResult<Zone> descriptionResult = batch.getZone(ZONE1.getName(), Dns.ZoneOption.fields(ZoneField.DESCRIPTION));
        DnsBatchResult<Zone> dnsNameResult = batch.getZone(ZONE1.getName(), Dns.ZoneOption.fields(ZoneField.DNS_NAME));
        DnsBatchResult<Zone> nameResult = batch.getZone(ZONE1.getName(), Dns.ZoneOption.fields(ZoneField.NAME));
        DnsBatchResult<Zone> nameServerSetResult = batch.getZone(ZONE1.getName(), Dns.ZoneOption.fields(ZoneField.NAME_SERVER_SET));
        DnsBatchResult<Zone> nameServersResult = batch.getZone(ZONE1.getName(), Dns.ZoneOption.fields(ZoneField.NAME_SERVERS));
        DnsBatchResult<Zone> idResult = batch.getZone(ZONE1.getName(), Dns.ZoneOption.fields(ZoneField.ZONE_ID));
        DnsBatchResult<Zone> combinationResult = batch.getZone(ZONE1.getName(), Dns.ZoneOption.fields(ZoneField.ZONE_ID, ZoneField.NAME_SERVERS, ZoneField.NAME_SERVER_SET, ZoneField.DESCRIPTION));
        batch.submit();
        Zone created = timeResult.get();
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNotNull(created.getCreationTimeMillis());
        assertNull(created.getDescription());
        assertNull(created.getDnsName());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created = descriptionResult.get();
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertEquals(ZONE1.getDescription(), created.getDescription());
        assertNull(created.getDnsName());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created = dnsNameResult.get();
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertEquals(ZONE1.getDnsName(), created.getDnsName());
        assertNull(created.getDescription());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created = nameResult.get();
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertNull(created.getDnsName());
        assertNull(created.getDescription());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created = nameServerSetResult.get();
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertNull(created.getDnsName());
        assertNull(created.getDescription());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        // we did not set it
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created = nameServersResult.get();
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertNull(created.getDnsName());
        assertNull(created.getDescription());
        assertFalse(created.getNameServers().isEmpty());
        assertNull(created.getNameServerSet());
        assertNull(created.getGeneratedId());
        created = idResult.get();
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertNull(created.getDnsName());
        assertNull(created.getDescription());
        assertNotNull(created.getNameServers());
        // never returns null
        assertTrue(created.getNameServers().isEmpty());
        assertNotNull(created.getGeneratedId());
        // combination of multiple things
        created = combinationResult.get();
        // always returned
        assertEquals(ZONE1.getName(), created.getName());
        assertNull(created.getCreationTimeMillis());
        assertNull(created.getDnsName());
        assertEquals(ZONE1.getDescription(), created.getDescription());
        assertFalse(created.getNameServers().isEmpty());
        // we did not set it
        assertNull(created.getNameServerSet());
        assertNotNull(created.getGeneratedId());
    } finally {
        DNS.delete(ZONE1.getName());
    }
}
Also used : Zone(com.google.cloud.dns.Zone) DnsBatch(com.google.cloud.dns.DnsBatch) Test(org.junit.Test)

Aggregations

Zone (com.google.cloud.dns.Zone)21 Test (org.junit.Test)17 DnsBatch (com.google.cloud.dns.DnsBatch)9 ChangeRequest (com.google.cloud.dns.ChangeRequest)8 DnsException (com.google.cloud.dns.DnsException)6 RecordSet (com.google.cloud.dns.RecordSet)6 Page (com.google.api.gax.paging.Page)3 ChangeRequestInfo (com.google.cloud.dns.ChangeRequestInfo)3 Dns (com.google.cloud.dns.Dns)3 ZoneInfo (com.google.cloud.dns.ZoneInfo)2 LinkedList (java.util.LinkedList)2 ProjectInfo (com.google.cloud.dns.ProjectInfo)1