Skip to content

Commit

Permalink
Unified imports of model objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
mderka committed Apr 4, 2016
1 parent c178259 commit ff65582
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.api.services.dns.model.Change;
import com.google.api.services.dns.model.ManagedZone;
import com.google.api.services.dns.model.Project;
import com.google.api.services.dns.model.ResourceRecordSet;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -256,10 +257,10 @@ public Boolean call() {
public ProjectInfo getProject(Dns.ProjectOption... fields) {
final Map<DnsRpc.Option, ?> optionsMap = optionMap(fields);
try {
com.google.api.services.dns.model.Project answer = runWithRetries(
new Callable<com.google.api.services.dns.model.Project>() {
Project answer = runWithRetries(
new Callable<Project>() {
@Override
public com.google.api.services.dns.model.Project call() {
public Project call() {
return dnsRpc.getProject(optionsMap);
}
}, options().retryParams(), EXCEPTION_HANDLER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.google.api.client.repackaged.com.google.common.base.Preconditions.checkNotNull;

import com.google.api.services.dns.model.Project;
import com.google.common.base.MoreObjects;

import java.io.Serializable;
Expand Down Expand Up @@ -143,14 +144,13 @@ com.google.api.services.dns.model.Quota toPb() {
}

static Quota fromPb(com.google.api.services.dns.model.Quota pb) {
Quota quota = new Quota(pb.getManagedZones(),
return new Quota(pb.getManagedZones(),
pb.getResourceRecordsPerRrset(),
pb.getRrsetAdditionsPerChange(),
pb.getRrsetDeletionsPerChange(),
pb.getRrsetsPerManagedZone(),
pb.getTotalRrdataSizePerChange()
);
return quota;
}

@Override
Expand Down Expand Up @@ -243,8 +243,8 @@ String id() {
return id;
}

com.google.api.services.dns.model.Project toPb() {
com.google.api.services.dns.model.Project pb = new com.google.api.services.dns.model.Project();
Project toPb() {
Project pb = new Project();
pb.setId(id);
pb.setNumber(number);
if (this.quota != null) {
Expand All @@ -253,7 +253,7 @@ com.google.api.services.dns.model.Project toPb() {
return pb;
}

static ProjectInfo fromPb(com.google.api.services.dns.model.Project pb) {
static ProjectInfo fromPb(Project pb) {
Builder builder = builder();
if (pb.getId() != null) {
builder.id(pb.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.api.services.dns.model.ManagedZone;
import com.google.gcloud.Page;

import java.io.IOException;
Expand Down Expand Up @@ -210,7 +211,7 @@ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFo
this.dns = options.service();
}

static Zone fromPb(Dns dns, com.google.api.services.dns.model.ManagedZone zone) {
static Zone fromPb(Dns dns, ManagedZone zone) {
ZoneInfo info = ZoneInfo.fromPb(zone);
return new Zone(dns, new ZoneInfo.BuilderImpl(info));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.api.services.dns.model.ManagedZone;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -248,9 +249,9 @@ public Builder toBuilder() {
return new BuilderImpl(this);
}

com.google.api.services.dns.model.ManagedZone toPb() {
com.google.api.services.dns.model.ManagedZone pb =
new com.google.api.services.dns.model.ManagedZone();
ManagedZone toPb() {
ManagedZone pb =
new ManagedZone();
pb.setDescription(this.description());
pb.setDnsName(this.dnsName());
if (this.generatedId() != null) {
Expand All @@ -267,7 +268,7 @@ com.google.api.services.dns.model.ManagedZone toPb() {
return pb;
}

static ZoneInfo fromPb(com.google.api.services.dns.model.ManagedZone pb) {
static ZoneInfo fromPb(ManagedZone pb) {
Builder builder = new BuilderImpl(pb.getName());
if (pb.getDescription() != null) {
builder.description(pb.getDescription());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.google.api.services.dns.model.Change;
import com.google.common.collect.ImmutableList;

import org.junit.Test;
Expand Down Expand Up @@ -209,7 +210,7 @@ public void testRemoveDeletion() {
@Test
public void testDateParsing() {
String startTime = "2016-01-26T18:33:43.512Z"; // obtained from service
com.google.api.services.dns.model.Change change = CHANGE.toPb().setStartTime(startTime);
Change change = CHANGE.toPb().setStartTime(startTime);
ChangeRequestInfo converted = ChangeRequest.fromPb(change);
assertNotNull(converted.startTimeMillis());
assertEquals(change, converted.toPb());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.api.services.dns.model.Change;
import com.google.api.services.dns.model.ManagedZone;
import com.google.api.services.dns.model.ResourceRecordSet;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -69,8 +70,7 @@ public class DnsImplTest {
CHANGE_REQUEST_PARTIAL.toPb()));
private static final DnsRpc.ListResult<ManagedZone> LIST_RESULT_OF_PB_ZONES =
DnsRpc.ListResult.of("cursor", ImmutableList.of(ZONE_INFO.toPb()));
private static final DnsRpc.ListResult<com.google.api.services.dns.model.ResourceRecordSet>
LIST_OF_PB_DNS_RECORDS =
private static final DnsRpc.ListResult<ResourceRecordSet> LIST_OF_PB_DNS_RECORDS =
DnsRpc.ListResult.of("cursor", ImmutableList.of(DNS_RECORD1.toPb(), DNS_RECORD2.toPb()));

// Field options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import com.google.api.services.dns.model.ManagedZone;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

Expand Down Expand Up @@ -155,10 +156,10 @@ public void testEmptyNameServers() {

@Test
public void testDateParsing() {
com.google.api.services.dns.model.ManagedZone pb = INFO.toPb();
ManagedZone pb = INFO.toPb();
pb.setCreationTime("2016-01-19T18:00:12.854Z"); // a real value obtained from Google Cloud DNS
ZoneInfo mz = ZoneInfo.fromPb(pb); // parses the string timestamp to millis
com.google.api.services.dns.model.ManagedZone pbClone = mz.toPb(); // converts it back to string
ManagedZone pbClone = mz.toPb(); // converts it back to string
assertEquals(pb, pbClone);
assertEquals(pb.getCreationTime(), pbClone.getCreationTime());
}
Expand Down

0 comments on commit ff65582

Please sign in to comment.