diff --git a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/it/ITDnsTest.java b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/it/ITDnsTest.java index 4ad17fa8b217..c06367b8abcc 100644 --- a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/it/ITDnsTest.java +++ b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/it/ITDnsTest.java @@ -48,8 +48,6 @@ public class ITDnsTest { - // todo(mderka) Implement test for creating invalid change when DnsException is finished. #673 - private static final String PREFIX = "gcldjvit-"; private static final Dns DNS = DnsOptions.builder().build().service(); private static final String ZONE_NAME1 = (PREFIX + UUID.randomUUID()).substring(0, 32); @@ -201,14 +199,14 @@ public void testCreateZoneWithErrors() { fail("Zone name is missing a period. The service returns an error."); } catch (DnsException ex) { // expected - // todo(mderka) test non-retryable when implemented within #593 + assertFalse(ex.retryable()); } try { DNS.create(ZONE_DNS_NO_PERIOD); fail("Zone name is missing a period. The service returns an error."); } catch (DnsException ex) { // expected - // todo(mderka) test non-retryable when implemented within #593 + assertFalse(ex.retryable()); } } finally { DNS.delete(ZONE_NAME_ERROR.name()); @@ -393,7 +391,7 @@ public void testListZones() { } catch (DnsException ex) { // expected assertEquals(400, ex.code()); - // todo(mderka) test not-retryable + assertFalse(ex.retryable()); } try { DNS.listZones(Dns.ZoneListOption.pageSize(-1)); @@ -401,7 +399,7 @@ public void testListZones() { } catch (DnsException ex) { // expected assertEquals(400, ex.code()); - // todo(mderka) test not-retryable + assertFalse(ex.retryable()); } // ok size zones = filter(DNS.listZones(Dns.ZoneListOption.pageSize(1000)).iterateAll()); @@ -413,7 +411,7 @@ public void testListZones() { } catch (DnsException ex) { // expected assertEquals(400, ex.code()); - // todo(mderka) test not-retryable + assertFalse(ex.retryable()); } // ok name zones = filter(DNS.listZones(Dns.ZoneListOption.dnsName(ZONE1.dnsName())).iterateAll()); @@ -586,6 +584,73 @@ public void testCreateChange() { } } + @Test + public void testInvalidChangeRequest() { + Zone zone = DNS.create(ZONE1); + DnsRecord validA = DnsRecord.builder("subdomain." + zone.dnsName(), DnsRecord.Type.A) + .records(ImmutableList.of("0.255.1.5")) + .build(); + try { + ChangeRequest validChange = ChangeRequest.builder().add(validA).build(); + zone.applyChangeRequest(validChange); + try { + zone.applyChangeRequest(validChange); + fail(); + } catch (DnsException ex) { + // expected + assertFalse(ex.retryable()); + assertEquals(409, ex.code()); + } + // delete with field mismatch + DnsRecord mismatch = validA.toBuilder().ttl(20, TimeUnit.SECONDS).build(); + ChangeRequest deletion = ChangeRequest.builder().delete(mismatch).build(); + try { + zone.applyChangeRequest(deletion); + fail(); + } catch (DnsException ex) { + // expected + assertEquals(412, ex.code()); + assertFalse(ex.retryable()); + } + // delete and add SOA + Iterator recordIterator = zone.listDnsRecords().iterateAll(); + LinkedList deletions = new LinkedList<>(); + LinkedList additions = new LinkedList<>(); + while (recordIterator.hasNext()) { + DnsRecord record = recordIterator.next(); + if (record.type() == DnsRecord.Type.SOA) { + deletions.add(record); + DnsRecord copy = record.toBuilder().name("x." + record.name()).build(); + additions.add(copy); + break; + } + } + deletion = deletion.toBuilder().deletions(deletions).build(); + ChangeRequest addition = ChangeRequest.builder().additions(additions).build(); + try { + zone.applyChangeRequest(deletion); + fail(); + } catch (DnsException ex) { + // expected + assertFalse(ex.retryable()); + assertEquals(400, ex.code()); + } + try { + zone.applyChangeRequest(addition); + fail(); + } catch (DnsException ex) { + // expected + assertFalse(ex.retryable()); + assertEquals(400, ex.code()); + } + } finally { + ChangeRequest deletion = ChangeRequest.builder().delete(validA).build(); + ChangeRequest request = zone.applyChangeRequest(deletion); + waitForChangeToComplete(zone.name(), request.id()); + zone.delete(); + } + } + @Test public void testListChanges() { try { @@ -596,7 +661,7 @@ public void testListChanges() { } catch (DnsException ex) { // expected assertEquals(404, ex.code()); - // todo(mderka) test retry functionality + assertFalse(ex.retryable()); } // zone exists but has no changes DNS.create(ZONE1); @@ -621,7 +686,7 @@ public void testListChanges() { } catch (DnsException ex) { // expected assertEquals(400, ex.code()); - // todo(mderka) test retry functionality + assertFalse(ex.retryable()); } try { DNS.listChangeRequests(ZONE1.name(), Dns.ChangeRequestListOption.pageSize(-1)); @@ -629,7 +694,7 @@ public void testListChanges() { } catch (DnsException ex) { // expected assertEquals(400, ex.code()); - // todo(mderka) test retry functionality + assertFalse(ex.retryable()); } // sorting order ImmutableList ascending = ImmutableList.copyOf(DNS.listChangeRequests( @@ -863,7 +928,7 @@ public void testListDnsRecords() { } catch (DnsException ex) { // expected assertEquals(400, ex.code()); - // todo(mderka) test retry functionality when available + assertFalse(ex.retryable()); } try { DNS.listDnsRecords(ZONE1.name(), Dns.DnsRecordListOption.pageSize(0)); @@ -871,7 +936,7 @@ public void testListDnsRecords() { } catch (DnsException ex) { // expected assertEquals(400, ex.code()); - // todo(mderka) test retry functionality when available + assertFalse(ex.retryable()); } try { DNS.listDnsRecords(ZONE1.name(), Dns.DnsRecordListOption.pageSize(-1)); @@ -879,7 +944,7 @@ public void testListDnsRecords() { } catch (DnsException ex) { // expected assertEquals(400, ex.code()); - // todo(mderka) test retry functionality when available + assertFalse(ex.retryable()); } waitForChangeToComplete(ZONE1.name(), change.id()); } finally {