From 394536d7658b83ea0d57898cb9211c084a3b7603 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 21 Mar 2015 10:57:02 -0700 Subject: [PATCH] Corrects CloudDNS implementation as it doesn't support duplicate zones --- CHANGELOG.md | 2 +- .../java/denominator/cli/DenominatorTest.java | 4 +- .../clouddns/CloudDNSFunctions.java | 27 ++++++++++- .../clouddns/CloudDNSProvider.java | 9 ++-- .../CloudDNSResourceRecordSetApi.java | 39 +++++----------- .../clouddns/RackspaceAdapters.java | 45 ++++++++++++++----- .../denominator/clouddns/RackspaceApis.java | 31 +++++++------ .../clouddns/CloudDNSProviderTest.java | 3 +- .../CloudDNSResourceRecordSetApiMockTest.java | 44 ++++++++++++++---- .../clouddns/CloudDNSZoneApiMockTest.java | 4 +- .../clouddns/RackspaceApisTest.java | 33 +++++++++----- 11 files changed, 153 insertions(+), 88 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad285110..fe034351 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ * Publishes model and core test jars * Adds example server * Enforces source compatibility with animal-sniffer -* Corrects Designate implementation as it doesn't support duplicate zones +* Corrects CloudDNS and Designate implementations as they don't support duplicate zones ### Version 4.4.2 * Updates to feign 8.1 diff --git a/cli/src/test/java/denominator/cli/DenominatorTest.java b/cli/src/test/java/denominator/cli/DenominatorTest.java index 8479a60a..d66baedd 100644 --- a/cli/src/test/java/denominator/cli/DenominatorTest.java +++ b/cli/src/test/java/denominator/cli/DenominatorTest.java @@ -63,8 +63,8 @@ public void listsAllProvidersWithCredentials() { assertThat(ListProviders.providerAndCredentialsTable()) .isEqualTo(Util.join('\n', "provider url duplicateZones credentialType credentialArgs", - "clouddns https://identity.api.rackspacecloud.com/v2.0 true password username password", - "clouddns https://identity.api.rackspacecloud.com/v2.0 true apiKey username apiKey", + "clouddns https://identity.api.rackspacecloud.com/v2.0 false password username password", + "clouddns https://identity.api.rackspacecloud.com/v2.0 false apiKey username apiKey", "designate http://localhost:5000/v2.0 false password tenantId username password", "dynect https://api2.dynect.net/REST false password customer username password", "mock mem:mock false ", diff --git a/clouddns/src/main/java/denominator/clouddns/CloudDNSFunctions.java b/clouddns/src/main/java/denominator/clouddns/CloudDNSFunctions.java index a67df382..4bd81c26 100644 --- a/clouddns/src/main/java/denominator/clouddns/CloudDNSFunctions.java +++ b/clouddns/src/main/java/denominator/clouddns/CloudDNSFunctions.java @@ -3,6 +3,8 @@ import java.util.List; import java.util.Map; +import denominator.clouddns.RackspaceApis.CloudDNS; +import denominator.clouddns.RackspaceApis.Job; import denominator.clouddns.RackspaceApis.Record; import denominator.model.rdata.AAAAData; import denominator.model.rdata.AData; @@ -11,12 +13,30 @@ import denominator.model.rdata.NSData; import denominator.model.rdata.SRVData; import denominator.model.rdata.TXTData; +import feign.RetryableException; +import feign.Retryer; import static denominator.common.Util.split; +import static java.lang.String.format; -public final class CloudDNSFunctions { +final class CloudDNSFunctions { - private CloudDNSFunctions() { + static void awaitComplete(CloudDNS api, Job job) { + RetryableException retryableException = new RetryableException( + format("Job %s did not complete. Check your logs.", job.id), null); + Retryer retryer = new Retryer.Default(500, 1000, 30); + + while (true) { + job = api.getStatus(job.id); + + if ("COMPLETED".equals(job.status)) { + break; + } else if ("ERROR".equals(job.status)) { + throw retryableException; + } + + retryer.continueOrPropagate(retryableException); + } } static Map toRDataMap(Record record) { @@ -43,4 +63,7 @@ static Map toRDataMap(Record record) { throw new UnsupportedOperationException("record type not yet supported" + record); } } + + private CloudDNSFunctions() { + } } diff --git a/clouddns/src/main/java/denominator/clouddns/CloudDNSProvider.java b/clouddns/src/main/java/denominator/clouddns/CloudDNSProvider.java index 93d393e0..0ce9aaf7 100644 --- a/clouddns/src/main/java/denominator/clouddns/CloudDNSProvider.java +++ b/clouddns/src/main/java/denominator/clouddns/CloudDNSProvider.java @@ -15,6 +15,7 @@ import denominator.DNSApiManager; import denominator.ResourceRecordSetApi; import denominator.ZoneApi; +import denominator.clouddns.RackspaceAdapters.DomainIdListAdapter; import denominator.clouddns.RackspaceAdapters.DomainListAdapter; import denominator.clouddns.RackspaceAdapters.JobIdAndStatusAdapter; import denominator.clouddns.RackspaceAdapters.RecordListAdapter; @@ -70,11 +71,6 @@ public Map> profileToRecordTypes() { return profileToRecordTypes; } - @Override - public boolean supportsDuplicateZoneNames() { - return true; - } - @Override public Map> credentialTypeToParameterNames() { Map> options = new LinkedHashMap>(); @@ -109,7 +105,7 @@ ResourceRecordSetApi.Factory provideResourceRecordSetApiFactory( } @dagger.Module(injects = CloudDNSResourceRecordSetApi.Factory.class, - complete = false // doesn't bind Provider used by DesignateTarget + complete = false // doesn't bind Provider used by CloudDNSTarget ) public static final class FeignModule { @@ -146,6 +142,7 @@ Feign feign(Logger logger, Logger.Level logLevel) { new KeystoneAccessAdapter("rax:dns"), new JobIdAndStatusAdapter(), new DomainListAdapter(), + new DomainIdListAdapter(), new RecordListAdapter())) ) .build(); diff --git a/clouddns/src/main/java/denominator/clouddns/CloudDNSResourceRecordSetApi.java b/clouddns/src/main/java/denominator/clouddns/CloudDNSResourceRecordSetApi.java index dfbe8f44..685cc74c 100644 --- a/clouddns/src/main/java/denominator/clouddns/CloudDNSResourceRecordSetApi.java +++ b/clouddns/src/main/java/denominator/clouddns/CloudDNSResourceRecordSetApi.java @@ -11,15 +11,13 @@ import denominator.ResourceRecordSetApi; import denominator.clouddns.RackspaceApis.CloudDNS; -import denominator.clouddns.RackspaceApis.JobIdAndStatus; import denominator.clouddns.RackspaceApis.ListWithNext; import denominator.clouddns.RackspaceApis.Pager; import denominator.clouddns.RackspaceApis.Record; import denominator.common.Util; import denominator.model.ResourceRecordSet; -import feign.RetryableException; -import feign.Retryer; +import static denominator.clouddns.CloudDNSFunctions.awaitComplete; import static denominator.clouddns.CloudDNSFunctions.toRDataMap; import static denominator.clouddns.RackspaceApis.emptyOn404; import static denominator.common.Preconditions.checkArgument; @@ -89,10 +87,10 @@ public void put(ResourceRecordSet rrset) { continue; } - awaitComplete(api.updateRecord(domainId, record.id, rrset.ttl(), record.data())); + awaitComplete(api, api.updateRecord(domainId, record.id, rrset.ttl(), record.data())); } } else { - awaitComplete(api.deleteRecord(domainId, record.id)); + awaitComplete(api, api.deleteRecord(domainId, record.id)); } } @@ -104,32 +102,15 @@ public void put(ResourceRecordSet rrset) { String data = join(' ', mutableRData.values().toArray()); if (priority == null) { - awaitComplete(api.createRecord(domainId, rrset.name(), rrset.type(), ttlToApply, data)); + awaitComplete(api, + api.createRecord(domainId, rrset.name(), rrset.type(), ttlToApply, data)); } else { - awaitComplete(api.createRecordWithPriority( + awaitComplete(api, api.createRecordWithPriority( domainId, rrset.name(), rrset.type(), ttlToApply, data, priority)); } } } - private void awaitComplete(JobIdAndStatus job) { - RetryableException retryableException = new RetryableException( - String.format("JobId %s did not complete. Check your logs.", job.id), null); - Retryer retryer = new Retryer.Default(500, 1000, 30); - - while (true) { - JobIdAndStatus jobIdAndStatus = api.getStatus(job.id); - - if ("COMPLETED".equals(jobIdAndStatus.status)) { - break; - } else if ("ERROR".equals(jobIdAndStatus.status)) { - throw retryableException; - } - - retryer.continueOrPropagate(retryableException); - } - } - /** * Has the side effect of removing the priority from the mutableRData. * @@ -153,7 +134,7 @@ public void deleteByNameAndType(String name, String type) { checkNotNull(type, "type"); for (Record record : api.recordsByNameAndType(domainId, name, type)) { - awaitComplete(api.deleteRecord(domainId, record.id)); + awaitComplete(api, api.deleteRecord(domainId, record.id)); } } @@ -200,8 +181,10 @@ static final class Factory implements denominator.ResourceRecordSetApi.Factory { } @Override - public ResourceRecordSetApi create(String id) { - return new CloudDNSResourceRecordSetApi(api, Integer.parseInt(id)); + public ResourceRecordSetApi create(String name) { + ListWithNext matching = api.domainIdsByName(name); + checkArgument(!matching.isEmpty(), "zone %s does not exist", name); + return new CloudDNSResourceRecordSetApi(api, matching.get(0)); } } } diff --git a/clouddns/src/main/java/denominator/clouddns/RackspaceAdapters.java b/clouddns/src/main/java/denominator/clouddns/RackspaceAdapters.java index b07c9934..121ffdbb 100644 --- a/clouddns/src/main/java/denominator/clouddns/RackspaceAdapters.java +++ b/clouddns/src/main/java/denominator/clouddns/RackspaceAdapters.java @@ -9,7 +9,7 @@ import java.util.Collections; import java.util.Comparator; -import denominator.clouddns.RackspaceApis.JobIdAndStatus; +import denominator.clouddns.RackspaceApis.Job; import denominator.clouddns.RackspaceApis.ListWithNext; import denominator.clouddns.RackspaceApis.Record; import denominator.model.Zone; @@ -28,25 +28,25 @@ private static Comparator toStringComparator() { return Comparator.class.cast(TO_STRING_COMPARATOR); } - static class JobIdAndStatusAdapter extends TypeAdapter { + static class JobIdAndStatusAdapter extends TypeAdapter { @Override - public void write(JsonWriter out, JobIdAndStatus value) throws IOException { + public void write(JsonWriter out, Job value) throws IOException { // never need to write this object } @Override - public JobIdAndStatus read(JsonReader reader) throws IOException { - JobIdAndStatus jobIdAndStatus = new JobIdAndStatus(); + public Job read(JsonReader reader) throws IOException { + Job job = new Job(); reader.beginObject(); while (reader.hasNext()) { String key = reader.nextName(); if (key.equals("jobId")) { - jobIdAndStatus.id = reader.nextString(); + job.id = reader.nextString(); } else if (key.equals("status")) { - jobIdAndStatus.status = reader.nextString(); + job.status = reader.nextString(); } else { reader.skipValue(); } @@ -54,10 +54,34 @@ public JobIdAndStatus read(JsonReader reader) throws IOException { reader.endObject(); - return jobIdAndStatus; + return job; } } + static class DomainIdListAdapter extends ListWithNextAdapter { + + @Override + protected String jsonKey() { + return "domains"; + } + + protected Integer build(JsonReader reader) throws IOException { + Integer id = null; + while (reader.hasNext()) { + if (reader.nextName().equals("id")) { + id = reader.nextInt(); + } else { + reader.skipValue(); + } + } + return id; + } + } + + /** + * Note that we do not expose the ID back to the user as ID isn't semantic when the API doesn't + * support multiple zones + */ static class DomainListAdapter extends ListWithNextAdapter { @Override @@ -69,11 +93,8 @@ protected Zone build(JsonReader reader) throws IOException { String name = null; String id = null; while (reader.hasNext()) { - String key = reader.nextName(); - if (key.equals("name")) { + if (reader.nextName().equals("name")) { name = reader.nextString(); - } else if (key.equals("id")) { - id = reader.nextString(); } else { reader.skipValue(); } diff --git a/clouddns/src/main/java/denominator/clouddns/RackspaceApis.java b/clouddns/src/main/java/denominator/clouddns/RackspaceApis.java index 51d23069..e66595d8 100644 --- a/clouddns/src/main/java/denominator/clouddns/RackspaceApis.java +++ b/clouddns/src/main/java/denominator/clouddns/RackspaceApis.java @@ -44,7 +44,14 @@ static interface CloudDNS { Map limits(); @RequestLine("GET /status/{jobId}?showDetails=true") - JobIdAndStatus getStatus(@Param("jobId") String jobId); + Job getStatus(@Param("jobId") String jobId); + + /** + * Note this doesn't make sense to return anything except one or none, as duplicate domains + * aren't permitted in the create api. + */ + @RequestLine("GET /domains?name={name}") + ListWithNext domainIdsByName(@Param("name") String name); @RequestLine("GET") ListWithNext domains(URI href); @@ -66,27 +73,25 @@ ListWithNext recordsByNameAndType(@Param("domainId") int id, @RequestLine("POST /domains/{domainId}/records") @Body("%7B\"records\":[%7B\"name\":\"{name}\",\"type\":\"{type}\",\"ttl\":\"{ttl}\",\"data\":\"{data}\"%7D]%7D") @Headers("Content-Type: application/json") - JobIdAndStatus createRecord(@Param("domainId") int id, @Param("name") String name, - @Param("type") String type, @Param("ttl") int ttl, - @Param("data") String data); + Job createRecord(@Param("domainId") int id, @Param("name") String name, + @Param("type") String type, @Param("ttl") int ttl, @Param("data") String data); @RequestLine("POST /domains/{domainId}/records") @Body("%7B\"records\":[%7B\"name\":\"{name}\",\"type\":\"{type}\",\"ttl\":\"{ttl}\",\"data\":\"{data}\",\"priority\":\"{priority}\"%7D]%7D") @Headers("Content-Type: application/json") - JobIdAndStatus createRecordWithPriority(@Param("domainId") int id, @Param("name") String name, - @Param("type") String type, @Param("ttl") int ttl, - @Param("data") String data, - @Param("priority") int priority); + Job createRecordWithPriority(@Param("domainId") int id, @Param("name") String name, + @Param("type") String type, @Param("ttl") int ttl, + @Param("data") String data, @Param("priority") int priority); @RequestLine("PUT /domains/{domainId}/records/{recordId}") @Body("%7B\"ttl\":\"{ttl}\",\"data\":\"{data}\"%7D") @Headers("Content-Type: application/json") - JobIdAndStatus updateRecord(@Param("domainId") int domainId, @Param("recordId") String recordId, - @Param("ttl") int ttl, @Param("data") String data); + Job updateRecord(@Param("domainId") int domainId, @Param("recordId") String recordId, + @Param("ttl") int ttl, @Param("data") String data); @RequestLine("DELETE /domains/{domainId}/records/{recordId}") - JobIdAndStatus deleteRecord(@Param("domainId") int domainId, - @Param("recordId") String recordId); + Job deleteRecord(@Param("domainId") int domainId, + @Param("recordId") String recordId); } interface Pager { @@ -100,7 +105,7 @@ static class TokenIdAndPublicURL { String publicURL; } - static class JobIdAndStatus { + static class Job { String id; String status; diff --git a/clouddns/src/test/java/denominator/clouddns/CloudDNSProviderTest.java b/clouddns/src/test/java/denominator/clouddns/CloudDNSProviderTest.java index 553c4d32..c2cc0ddc 100644 --- a/clouddns/src/test/java/denominator/clouddns/CloudDNSProviderTest.java +++ b/clouddns/src/test/java/denominator/clouddns/CloudDNSProviderTest.java @@ -18,7 +18,6 @@ import static denominator.Providers.list; import static denominator.Providers.provide; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertTrue; public class CloudDNSProviderTest { @@ -30,7 +29,7 @@ public class CloudDNSProviderTest { @Test public void testCloudDNSMetadata() { assertThat(PROVIDER.name()).isEqualTo("clouddns"); - assertTrue(PROVIDER.supportsDuplicateZoneNames()); + assertThat(PROVIDER.supportsDuplicateZoneNames()).isFalse(); assertThat(PROVIDER.credentialTypeToParameterNames()) .containsEntry("password", Arrays.asList("username", "password")) .containsEntry("apiKey", Arrays.asList("username", "apiKey")); diff --git a/clouddns/src/test/java/denominator/clouddns/CloudDNSResourceRecordSetApiMockTest.java b/clouddns/src/test/java/denominator/clouddns/CloudDNSResourceRecordSetApiMockTest.java index 0dd85acf..5bc25878 100644 --- a/clouddns/src/test/java/denominator/clouddns/CloudDNSResourceRecordSetApiMockTest.java +++ b/clouddns/src/test/java/denominator/clouddns/CloudDNSResourceRecordSetApiMockTest.java @@ -12,7 +12,7 @@ import denominator.model.rdata.AData; import static denominator.assertj.ModelAssertions.assertThat; -import static denominator.clouddns.RackspaceApisTest.domainId; +import static denominator.clouddns.RackspaceApisTest.domainsResponse; import static junit.framework.Assert.assertFalse; import static org.junit.Assert.assertNull; @@ -40,9 +40,10 @@ public class CloudDNSResourceRecordSetApiMockTest { @Test public void listWhenPresent() throws Exception { server.enqueueAuthResponse(); + server.enqueue(new MockResponse().setBody(domainsResponse)); server.enqueue(new MockResponse().setBody(records)); - ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone(domainId + ""); + ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone("denominator.io"); Iterator> records = api.iterator(); while (records.hasNext()) { @@ -52,6 +53,9 @@ public void listWhenPresent() throws Exception { } server.assertAuthRequest(); + server.assertRequest() + .hasMethod("GET") + .hasPath("/v1.0/123123/domains?name=denominator.io"); server.assertRequest() .hasMethod("GET") .hasPath("/v1.0/123123/domains/1234/records"); @@ -60,14 +64,18 @@ public void listWhenPresent() throws Exception { @Test public void listWhenAbsent() throws Exception { server.enqueueAuthResponse(); + server.enqueue(new MockResponse().setBody(domainsResponse)); server.enqueue(new MockResponse().setResponseCode(404).setBody( "{\"message\":\"Not Found\",\"code\":404,\"details\":\"\"}")); - ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone(domainId + ""); + ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone("denominator.io"); assertFalse(api.iterator().hasNext()); server.assertAuthRequest(); + server.assertRequest() + .hasMethod("GET") + .hasPath("/v1.0/123123/domains?name=denominator.io"); server.assertRequest() .hasMethod("GET") .hasPath("/v1.0/123123/domains/1234/records"); @@ -76,10 +84,11 @@ public void listWhenAbsent() throws Exception { @Test public void listPagesWhenPresent() throws Exception { server.enqueueAuthResponse(); + server.enqueue(new MockResponse().setBody(domainsResponse)); server.enqueue(new MockResponse().setBody(recordsPage1.replace("URL", server.url()))); server.enqueue(new MockResponse().setBody(recordsPage2.replace("URL", server.url()))); - ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone(domainId + ""); + ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone("denominator.io"); Iterator> records = api.iterator(); while (records.hasNext()) { @@ -89,6 +98,9 @@ public void listPagesWhenPresent() throws Exception { } server.assertAuthRequest(); + server.assertRequest() + .hasMethod("GET") + .hasPath("/v1.0/123123/domains?name=denominator.io"); server.assertRequest() .hasMethod("GET") .hasPath("/v1.0/123123/domains/1234/records"); @@ -100,9 +112,10 @@ public void listPagesWhenPresent() throws Exception { @Test public void iterateByNameWhenPresent() throws Exception { server.enqueueAuthResponse(); + server.enqueue(new MockResponse().setBody(domainsResponse)); server.enqueue(new MockResponse().setBody(recordsByName)); - ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone(domainId + ""); + ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone("denominator.io"); Iterator> records = api.iterateByName("www.denominator.io"); while (records.hasNext()) { @@ -112,6 +125,9 @@ public void iterateByNameWhenPresent() throws Exception { } server.assertAuthRequest(); + server.assertRequest() + .hasMethod("GET") + .hasPath("/v1.0/123123/domains?name=denominator.io"); server.assertRequest() .hasMethod("GET") .hasPath("/v1.0/123123/domains/1234/records"); @@ -120,13 +136,17 @@ public void iterateByNameWhenPresent() throws Exception { @Test public void iterateByNameWhenAbsent() throws Exception { server.enqueueAuthResponse(); + server.enqueue(new MockResponse().setBody(domainsResponse)); server.enqueue(new MockResponse().setResponseCode(404).setBody( "{\"message\":\"Not Found\",\"code\":404,\"details\":\"\"}")); - ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone(domainId + ""); + ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone("denominator.io"); assertFalse(api.iterateByName("www.denominator.io").hasNext()); server.assertAuthRequest(); + server.assertRequest() + .hasMethod("GET") + .hasPath("/v1.0/123123/domains?name=denominator.io"); server.assertRequest() .hasMethod("GET") .hasPath("/v1.0/123123/domains/1234/records"); @@ -135,9 +155,10 @@ public void iterateByNameWhenAbsent() throws Exception { @Test public void getByNameAndTypeWhenPresent() throws Exception { server.enqueueAuthResponse(); + server.enqueue(new MockResponse().setBody(domainsResponse)); server.enqueue(new MockResponse().setBody(recordsByNameAndType)); - ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone(domainId + ""); + ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone("denominator.io"); assertThat(api.getByNameAndType("www.denominator.io", "A")) .hasName("www.denominator.io") @@ -146,6 +167,9 @@ public void getByNameAndTypeWhenPresent() throws Exception { .containsExactlyRecords(AData.create("1.2.3.4"), AData.create("5.6.7.8")); server.assertAuthRequest(); + server.assertRequest() + .hasMethod("GET") + .hasPath("/v1.0/123123/domains?name=denominator.io"); server.assertRequest() .hasMethod("GET") .hasPath("/v1.0/123123/domains/1234/records?name=www.denominator.io&type=A"); @@ -154,13 +178,17 @@ public void getByNameAndTypeWhenPresent() throws Exception { @Test public void getByNameAndTypeWhenAbsent() throws Exception { server.enqueueAuthResponse(); + server.enqueue(new MockResponse().setBody(domainsResponse)); server.enqueue(new MockResponse().setResponseCode(404).setBody( "{\"message\":\"Not Found\",\"code\":404,\"details\":\"\"}")); - ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone(domainId + ""); + ResourceRecordSetApi api = server.connect().api().basicRecordSetsInZone("denominator.io"); assertNull(api.getByNameAndType("www.denominator.io", "A")); server.assertAuthRequest(); + server.assertRequest() + .hasMethod("GET") + .hasPath("/v1.0/123123/domains?name=denominator.io"); server.assertRequest() .hasMethod("GET") .hasPath("/v1.0/123123/domains/1234/records?name=www.denominator.io&type=A"); diff --git a/clouddns/src/test/java/denominator/clouddns/CloudDNSZoneApiMockTest.java b/clouddns/src/test/java/denominator/clouddns/CloudDNSZoneApiMockTest.java index d7600663..04bc0996 100644 --- a/clouddns/src/test/java/denominator/clouddns/CloudDNSZoneApiMockTest.java +++ b/clouddns/src/test/java/denominator/clouddns/CloudDNSZoneApiMockTest.java @@ -11,7 +11,6 @@ import denominator.model.Zone; import static denominator.assertj.ModelAssertions.assertThat; -import static denominator.clouddns.RackspaceApisTest.domainId; import static denominator.clouddns.RackspaceApisTest.domainsResponse; import static org.junit.Assert.assertFalse; @@ -29,8 +28,7 @@ public void iteratorWhenPresent() throws Exception { Iterator domains = api.iterator(); assertThat(domains.next()) - .hasName("denominator.io") - .hasId(String.valueOf(domainId)); + .hasName("denominator.io"); server.assertAuthRequest(); server.assertRequest().hasPath("/v1.0/123123/domains"); diff --git a/clouddns/src/test/java/denominator/clouddns/RackspaceApisTest.java b/clouddns/src/test/java/denominator/clouddns/RackspaceApisTest.java index b8d4c3e2..91dcd2e3 100644 --- a/clouddns/src/test/java/denominator/clouddns/RackspaceApisTest.java +++ b/clouddns/src/test/java/denominator/clouddns/RackspaceApisTest.java @@ -11,7 +11,7 @@ import denominator.Provider; import denominator.clouddns.RackspaceApis.CloudDNS; import denominator.clouddns.RackspaceApis.CloudIdentity; -import denominator.clouddns.RackspaceApis.JobIdAndStatus; +import denominator.clouddns.RackspaceApis.Job; import denominator.clouddns.RackspaceApis.TokenIdAndPublicURL; import feign.Feign; @@ -65,8 +65,7 @@ public void domainsPresent() throws Exception { server.enqueue(new MockResponse().setBody(domainsResponse)); assertThat(mockApi().domains().get(0)) - .hasName("denominator.io") - .hasId(String.valueOf("1234")); + .hasName("denominator.io"); server.assertAuthRequest(); server.assertRequest() @@ -74,6 +73,20 @@ public void domainsPresent() throws Exception { .hasPath("/v1.0/123123/domains"); } + @Test + public void domainIdsByNamePresent() throws Exception { + server.enqueueAuthResponse(); + server.enqueue(new MockResponse().setBody(domainsResponse)); + + assertThat(mockApi().domainIdsByName("denominator.io")) + .containsOnly(1234); + + server.assertAuthRequest(); + server.assertRequest() + .hasMethod("GET") + .hasPath("/v1.0/123123/domains?name=denominator.io"); + } + @Test public void domainsAbsent() throws Exception { server.enqueueAuthResponse(); @@ -125,9 +138,8 @@ public void createMXRecord() throws Exception { server.enqueueAuthResponse(); server.enqueue(new MockResponse().setBody(mxRecordInitialResponse)); - JobIdAndStatus job = mockApi().createRecordWithPriority(domainId, "www.denominator.io", "MX", - 1800, - "mail.denominator.io", 10); + Job job = mockApi().createRecordWithPriority(domainId, "www.denominator.io", "MX", + 1800, "mail.denominator.io", 10); assertThat(job.id).isEqualTo("0ade2b3b-07e4-4e68-821a-fcce4f5406f3"); assertThat(job.status).isEqualTo("RUNNING"); @@ -144,7 +156,7 @@ public void runningRequest() throws Exception { server.enqueueAuthResponse(); server.enqueue(new MockResponse().setBody(mxRecordRunningResponse)); - JobIdAndStatus job = mockApi().getStatus("0ade2b3b-07e4-4e68-821a-fcce4f5406f3"); + Job job = mockApi().getStatus("0ade2b3b-07e4-4e68-821a-fcce4f5406f3"); assertThat(job.id).isEqualTo("0ade2b3b-07e4-4e68-821a-fcce4f5406f3"); assertThat(job.status).isEqualTo("RUNNING"); @@ -160,7 +172,7 @@ public void completedRequest() throws Exception { server.enqueueAuthResponse(); server.enqueue(new MockResponse().setBody(mxRecordCompletedResponse)); - JobIdAndStatus job = mockApi().getStatus("0ade2b3b-07e4-4e68-821a-fcce4f5406f3"); + Job job = mockApi().getStatus("0ade2b3b-07e4-4e68-821a-fcce4f5406f3"); assertThat(job.id).isEqualTo("0ade2b3b-07e4-4e68-821a-fcce4f5406f3"); assertThat(job.status).isEqualTo("COMPLETED"); @@ -176,8 +188,7 @@ public void updateMXRecord() throws Exception { server.enqueueAuthResponse(); server.enqueue(new MockResponse().setBody(mxRecordUpdateInitialResponse)); - JobIdAndStatus job = mockApi().updateRecord(domainId, "MX-4582544", 600, - "mail.denominator.io"); + Job job = mockApi().updateRecord(domainId, "MX-4582544", 600, "mail.denominator.io"); assertThat(job.id).isEqualTo("e32eace1-c44f-49af-8f74-768fa34469f4"); assertThat(job.status).isEqualTo("RUNNING"); @@ -194,7 +205,7 @@ public void deleteRecord() throws Exception { server.enqueueAuthResponse(); server.enqueue(new MockResponse().setBody(mxRecordDeleteInitialResponse)); - JobIdAndStatus job = mockApi().deleteRecord(domainId, "MX-4582544"); + Job job = mockApi().deleteRecord(domainId, "MX-4582544"); assertThat(job.id).isEqualTo("da520d24-dd5b-4387-92be-2020a7f2b176"); assertThat(job.status).isEqualTo("RUNNING");