diff --git a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/RecordsToPagedIterable.java b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/RecordsToPagedIterable.java index b3ffadab02..3bab55caaa 100644 --- a/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/RecordsToPagedIterable.java +++ b/apis/rackspace-clouddns/src/main/java/org/jclouds/rackspace/clouddns/v1/functions/RecordsToPagedIterable.java @@ -36,7 +36,7 @@ import com.google.common.base.Optional; * @author Everett Toews */ @Beta -public class RecordsToPagedIterable extends Arg0ToPagedIterable { +public class RecordsToPagedIterable extends Arg0ToPagedIterable.FromCaller { private final CloudDNSApi api; diff --git a/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/DomainApiExpectTest.java b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/DomainApiExpectTest.java index 383c1825ba..a2f4d3bfa0 100644 --- a/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/DomainApiExpectTest.java +++ b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/DomainApiExpectTest.java @@ -39,6 +39,7 @@ import org.jclouds.rackspace.clouddns.v1.domain.Domain; import org.jclouds.rackspace.clouddns.v1.domain.DomainChange; import org.jclouds.rackspace.clouddns.v1.domain.Job; import org.jclouds.rackspace.clouddns.v1.domain.Record; +import org.jclouds.rackspace.clouddns.v1.domain.Subdomain; import org.jclouds.rackspace.clouddns.v1.domain.UpdateDomain; import org.jclouds.rackspace.clouddns.v1.functions.DomainFunctions; import org.jclouds.rackspace.clouddns.v1.internal.BaseCloudDNSApiExpectTest; @@ -143,6 +144,63 @@ public class DomainApiExpectTest extends BaseCloudDNSApiExpectTest } } + public void testListDomainsPaginated() { + URI endpointPage1 = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains"); + URI endpointPage2 = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains?limit=4&offset=4"); + DomainApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpointPage1).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/domain-list-page1.json")).build(), + authenticatedGET().endpoint(endpointPage2).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/domain-list-page2.json")).build()) + .getDomainApi(); + + ImmutableList domains = api.list().concat().toList(); + assertEquals(domains.size(), 8); + + for (Domain domain: domains) { + assertTrue(domain.getName().contains(JCLOUDS_EXAMPLE)); + } + } + + public void testListSubdomains() { + URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/subdomains"); + DomainApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpoint).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/subdomain-list.json")).build()) + .getDomainApi(); + + ImmutableList subdomains = api.listSubdomains(3650908).concat().toList(); + assertEquals(subdomains.size(), 4); + + for (Subdomain subdomain: subdomains) { + assertTrue(subdomain.getName().contains(JCLOUDS_EXAMPLE)); + } + } + + public void testListSubdomainsPaginated() { + URI endpointPage1 = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/subdomains"); + URI endpointPage2 = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/subdomains?limit=4&offset=4"); + DomainApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpointPage1).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/subdomain-list-page1.json")).build(), + authenticatedGET().endpoint(endpointPage2).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/subdomain-list-page2.json")).build()) + .getDomainApi(); + + ImmutableList subdomains = api.listSubdomains(3650908).concat().toList(); + assertEquals(subdomains.size(), 8); + + for (Subdomain subdomain: subdomains) { + assertTrue(subdomain.getName().contains(JCLOUDS_EXAMPLE)); + } + } + public void testListWithFilterByNamesMatching() { URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains?name=test.jclouds-example.com"); DomainApi api = requestsSendResponses( diff --git a/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/RecordApiExpectTest.java b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/RecordApiExpectTest.java index b061331cf3..bfd2b00450 100644 --- a/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/RecordApiExpectTest.java +++ b/apis/rackspace-clouddns/src/test/java/org/jclouds/rackspace/clouddns/v1/features/RecordApiExpectTest.java @@ -131,6 +131,26 @@ public class RecordApiExpectTest extends BaseCloudDNSApiExpectTest } } + public void testListRecordsPagination() { + URI endpointPage1 = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records"); + URI endpointPage2 = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records?limit=4&offset=4"); + RecordApi api = requestsSendResponses( + rackspaceAuthWithUsernameAndApiKey, + responseWithAccess, + authenticatedGET().endpoint(endpointPage1).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/record-list-page1.json")).build(), + authenticatedGET().endpoint(endpointPage2).build(), + HttpResponse.builder().statusCode(OK.getStatusCode()).payload(payloadFromResource("/record-list-page2.json")).build()) + .getRecordApiForDomain(3650908); + + ImmutableList records = api.list().concat().toList(); + assertEquals(records.size(), 8); + + for (RecordDetail record: records) { + assertTrue(record.getName().contains(JCLOUDS_EXAMPLE)); + } + } + public void testListByType() { URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records?type=A"); RecordApi api = requestsSendResponses( diff --git a/apis/rackspace-clouddns/src/test/resources/domain-list-page1.json b/apis/rackspace-clouddns/src/test/resources/domain-list-page1.json new file mode 100644 index 0000000000..8d28bd1e08 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/domain-list-page1.json @@ -0,0 +1,47 @@ +{ + "domains": [ + { + "name": "dev.jclouds-example.com", + "id": 3650907, + "comment": "Hello dev subdomain", + "accountId": 123123, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-03-22T03:04:15.000+0000", + "created": "2013-03-22T03:04:15.000+0000" + }, + { + "name": "jclouds-example.com", + "id": 3650906, + "comment": "Hello Domain", + "accountId": 123123, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-03-22T03:04:14.000+0000", + "created": "2013-03-22T03:04:12.000+0000" + }, + { + "name": "test.jclouds-example.com", + "id": 3650908, + "comment": "Hello test subdomain", + "accountId": 123123, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-03-22T03:04:16.000+0000", + "created": "2013-03-22T03:04:15.000+0000" + }, + { + "name": "xjclouds-example.com", + "id": 3650909, + "comment": "Hello Domain", + "accountId": 123123, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-03-22T03:04:16.000+0000", + "created": "2013-03-22T03:04:16.000+0000" + } + ], + "totalEntries": 8, + "links": [ + { + "href":"https://dns.api.rackspacecloud.com/v1.0/123123/domains?limit=4&offset=4", + "rel":"next" + } + ] +} diff --git a/apis/rackspace-clouddns/src/test/resources/domain-list-page2.json b/apis/rackspace-clouddns/src/test/resources/domain-list-page2.json new file mode 100644 index 0000000000..2fe7ff0d0f --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/domain-list-page2.json @@ -0,0 +1,47 @@ +{ + "domains": [ + { + "name": "dev.jclouds-example.com", + "id": 3650907, + "comment": "Hello dev subdomain", + "accountId": 123123, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-03-22T03:04:15.000+0000", + "created": "2013-03-22T03:04:15.000+0000" + }, + { + "name": "jclouds-example.com", + "id": 3650906, + "comment": "Hello Domain", + "accountId": 123123, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-03-22T03:04:14.000+0000", + "created": "2013-03-22T03:04:12.000+0000" + }, + { + "name": "test.jclouds-example.com", + "id": 3650908, + "comment": "Hello test subdomain", + "accountId": 123123, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-03-22T03:04:16.000+0000", + "created": "2013-03-22T03:04:15.000+0000" + }, + { + "name": "xjclouds-example.com", + "id": 3650909, + "comment": "Hello Domain", + "accountId": 123123, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-03-22T03:04:16.000+0000", + "created": "2013-03-22T03:04:16.000+0000" + } + ], + "totalEntries": 8, + "links": [ + { + "href":"https://dns.api.rackspacecloud.com/v1.0/123123/domains?limit=4&offset=0", + "rel":"previous" + } + ] +} diff --git a/apis/rackspace-clouddns/src/test/resources/record-list-page1.json b/apis/rackspace-clouddns/src/test/resources/record-list-page1.json new file mode 100644 index 0000000000..2b88304211 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/record-list-page1.json @@ -0,0 +1,48 @@ +{ + "records": [ + { + "name": "jclouds-example.com", + "id": "A-9846147", + "type": "A", + "data": "10.0.1.0", + "ttl": 60000, + "updated": "2013-04-06T15:20:29.000+0000", + "created": "2013-04-06T15:20:29.000+0000" + }, + { + "name": "jclouds-example.com", + "id": "NS-8684719", + "type": "NS", + "data": "dns1.stabletransit.com", + "ttl": 60000, + "updated": "2013-04-06T15:19:20.000+0000", + "created": "2013-04-06T15:19:20.000+0000" + }, + { + "name": "jclouds-example.com", + "id": "NS-8684720", + "type": "NS", + "data": "dns2.stabletransit.com", + "ttl": 60000, + "updated": "2013-04-06T15:19:20.000+0000", + "created": "2013-04-06T15:19:20.000+0000" + }, + { + "name": "jclouds-example.com", + "id": "MX-4351045", + "priority": 11235, + "type": "MX", + "data": "mail.jclouds-example.com.com", + "ttl": 60000, + "updated": "2013-04-06T15:20:28.000+0000", + "created": "2013-04-06T15:20:28.000+0000" + } + ], + "totalEntries": 8, + "links": [ + { + "href":"https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records?limit=4&offset=4", + "rel":"next" + } + ] +} diff --git a/apis/rackspace-clouddns/src/test/resources/record-list-page2.json b/apis/rackspace-clouddns/src/test/resources/record-list-page2.json new file mode 100644 index 0000000000..cccc1383e7 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/record-list-page2.json @@ -0,0 +1,48 @@ +{ + "records": [ + { + "name": "jclouds-example.com", + "id": "A-9846146", + "type": "A", + "data": "10.0.1.0", + "ttl": 60000, + "updated": "2013-04-06T15:20:29.000+0000", + "created": "2013-04-06T15:20:29.000+0000" + }, + { + "name": "jclouds-example.com", + "id": "NS-8684719", + "type": "NS", + "data": "dns1.stabletransit.com", + "ttl": 60000, + "updated": "2013-04-06T15:19:20.000+0000", + "created": "2013-04-06T15:19:20.000+0000" + }, + { + "name": "jclouds-example.com", + "id": "NS-8684720", + "type": "NS", + "data": "dns2.stabletransit.com", + "ttl": 60000, + "updated": "2013-04-06T15:19:20.000+0000", + "created": "2013-04-06T15:19:20.000+0000" + }, + { + "name": "jclouds-example.com", + "id": "MX-4351045", + "priority": 11235, + "type": "MX", + "data": "mail.jclouds-example.com.com", + "ttl": 60000, + "updated": "2013-04-06T15:20:28.000+0000", + "created": "2013-04-06T15:20:28.000+0000" + } + ], + "totalEntries": 8, + "links": [ + { + "href":"https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records?limit=4&offset=0", + "rel":"previous" + } + ] +} diff --git a/apis/rackspace-clouddns/src/test/resources/subdomain-list-page1.json b/apis/rackspace-clouddns/src/test/resources/subdomain-list-page1.json new file mode 100644 index 0000000000..3cfe450121 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/subdomain-list-page1.json @@ -0,0 +1,39 @@ +{ + "domains": [ + { + "name": "1of4.jclouds-example.com", + "id": 3728279, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-05-23T00:32:21.000+0000", + "created": "2013-05-23T00:32:21.000+0000" + }, + { + "name": "2of4.jclouds-example.com", + "id": 3728280, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-05-23T00:32:21.000+0000", + "created": "2013-05-23T00:32:21.000+0000" + }, + { + "name": "3of4.jclouds-example.com", + "id": 3728281, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-05-23T00:32:22.000+0000", + "created": "2013-05-23T00:32:22.000+0000" + }, + { + "name": "4of4.jclouds-example.com", + "id": 3728282, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-05-23T00:32:22.000+0000", + "created": "2013-05-23T00:32:22.000+0000" + } + ], + "totalEntries": 8, + "links": [ + { + "href":"https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/subdomains?limit=4&offset=4", + "rel":"next" + } + ] +} \ No newline at end of file diff --git a/apis/rackspace-clouddns/src/test/resources/subdomain-list-page2.json b/apis/rackspace-clouddns/src/test/resources/subdomain-list-page2.json new file mode 100644 index 0000000000..e39acefa85 --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/subdomain-list-page2.json @@ -0,0 +1,39 @@ +{ + "domains": [ + { + "name": "1of4.jclouds-example.com", + "id": 3728279, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-05-23T00:32:21.000+0000", + "created": "2013-05-23T00:32:21.000+0000" + }, + { + "name": "2of4.jclouds-example.com", + "id": 3728280, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-05-23T00:32:21.000+0000", + "created": "2013-05-23T00:32:21.000+0000" + }, + { + "name": "3of4.jclouds-example.com", + "id": 3728281, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-05-23T00:32:22.000+0000", + "created": "2013-05-23T00:32:22.000+0000" + }, + { + "name": "4of4.jclouds-example.com", + "id": 3728282, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-05-23T00:32:22.000+0000", + "created": "2013-05-23T00:32:22.000+0000" + } + ], + "totalEntries": 8, + "links": [ + { + "href":"https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/subdomains?limit=4&offset=0", + "rel":"previous" + } + ] +} \ No newline at end of file diff --git a/apis/rackspace-clouddns/src/test/resources/subdomain-list.json b/apis/rackspace-clouddns/src/test/resources/subdomain-list.json new file mode 100644 index 0000000000..f6ce905f9d --- /dev/null +++ b/apis/rackspace-clouddns/src/test/resources/subdomain-list.json @@ -0,0 +1,33 @@ +{ + "domains": [ + { + "name": "1of4.jclouds-example.com", + "id": 3728279, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-05-23T00:32:21.000+0000", + "created": "2013-05-23T00:32:21.000+0000" + }, + { + "name": "2of4.jclouds-example.com", + "id": 3728280, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-05-23T00:32:21.000+0000", + "created": "2013-05-23T00:32:21.000+0000" + }, + { + "name": "3of4.jclouds-example.com", + "id": 3728281, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-05-23T00:32:22.000+0000", + "created": "2013-05-23T00:32:22.000+0000" + }, + { + "name": "4of4.jclouds-example.com", + "id": 3728282, + "emailAddress": "jclouds@jclouds-example.com", + "updated": "2013-05-23T00:32:22.000+0000", + "created": "2013-05-23T00:32:22.000+0000" + } + ], + "totalEntries": 4 +} \ No newline at end of file