JCLOUDS-78: Fix record pagination problem. Backfill tests.

This commit is contained in:
Everett Toews 2013-05-22 19:05:41 -06:00
parent a3eea35e53
commit a86df9bb88
10 changed files with 380 additions and 1 deletions

View File

@ -36,7 +36,7 @@ import com.google.common.base.Optional;
* @author Everett Toews * @author Everett Toews
*/ */
@Beta @Beta
public class RecordsToPagedIterable extends Arg0ToPagedIterable<RecordDetail, RecordsToPagedIterable> { public class RecordsToPagedIterable extends Arg0ToPagedIterable.FromCaller<RecordDetail, RecordsToPagedIterable> {
private final CloudDNSApi api; private final CloudDNSApi api;

View File

@ -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.DomainChange;
import org.jclouds.rackspace.clouddns.v1.domain.Job; import org.jclouds.rackspace.clouddns.v1.domain.Job;
import org.jclouds.rackspace.clouddns.v1.domain.Record; 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.domain.UpdateDomain;
import org.jclouds.rackspace.clouddns.v1.functions.DomainFunctions; import org.jclouds.rackspace.clouddns.v1.functions.DomainFunctions;
import org.jclouds.rackspace.clouddns.v1.internal.BaseCloudDNSApiExpectTest; import org.jclouds.rackspace.clouddns.v1.internal.BaseCloudDNSApiExpectTest;
@ -143,6 +144,63 @@ public class DomainApiExpectTest extends BaseCloudDNSApiExpectTest<CloudDNSApi>
} }
} }
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<Domain> 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<Subdomain> 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<Subdomain> subdomains = api.listSubdomains(3650908).concat().toList();
assertEquals(subdomains.size(), 8);
for (Subdomain subdomain: subdomains) {
assertTrue(subdomain.getName().contains(JCLOUDS_EXAMPLE));
}
}
public void testListWithFilterByNamesMatching() { public void testListWithFilterByNamesMatching() {
URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains?name=test.jclouds-example.com"); URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains?name=test.jclouds-example.com");
DomainApi api = requestsSendResponses( DomainApi api = requestsSendResponses(

View File

@ -131,6 +131,26 @@ public class RecordApiExpectTest extends BaseCloudDNSApiExpectTest<CloudDNSApi>
} }
} }
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<RecordDetail> records = api.list().concat().toList();
assertEquals(records.size(), 8);
for (RecordDetail record: records) {
assertTrue(record.getName().contains(JCLOUDS_EXAMPLE));
}
}
public void testListByType() { public void testListByType() {
URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records?type=A"); URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/domains/3650908/records?type=A");
RecordApi api = requestsSendResponses( RecordApi api = requestsSendResponses(

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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
}