Skip to content

Commit 7839d8a

Browse files
committed
---
yaml --- r: 2923 b: refs/heads/dns-alpha-batch c: c95c3aa h: refs/heads/master i: 2921: eee6680 2919: 7f44f8a
1 parent a5e03ae commit 7839d8a

3 files changed

Lines changed: 50 additions & 60 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ refs/tags/v0.0.11: ffbfba48a6426ff63c08ff2117e58681f251fbf2
1212
refs/tags/v0.0.12: 2fd8066e891fb3dfea69b65f6bf6461db79342b9
1313
refs/heads/compute-alpha: b1274b5bdf4eea955f3588b56378a5ae4ba59cef
1414
refs/heads/dns-alpha: 2f90e7e338349287ace33375896907af0f032ca1
15-
refs/heads/dns-alpha-batch: e8dd142fb0a6db4322fb83b79e999d97bd88e94e
15+
refs/heads/dns-alpha-batch: c95c3aaa0c514ba573f29ee8d19a7619a0bf0e1c

branches/dns-alpha-batch/gcloud-java-dns/src/main/java/com/google/gcloud/dns/ManagedZoneInfo.java

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
package com.google.gcloud.dns;
1818

19-
import static com.google.common.base.Preconditions.checkArgument;
2019
import static com.google.common.base.Preconditions.checkNotNull;
2120

2221
import com.google.common.base.MoreObjects;
2322
import com.google.common.collect.ImmutableList;
23+
import com.google.common.collect.Lists;
2424

2525
import org.joda.time.DateTime;
2626
import org.joda.time.format.ISODateTimeFormat;
@@ -32,15 +32,16 @@
3232
import java.util.Objects;
3333

3434
/**
35-
* This class is a container for the managed zone metainformation. Managed zone is a resource that
36-
* represents a DNS zone hosted by the Cloud DNS service. See <a href="https://cloud.google.com/dns/api/v1/managedZones">Google
37-
* Cloud DNS documentation</a> for more information.
35+
* A {@code ManagedZone} represents a DNS zone hosted by the Google Cloud DNS service. A zone is a
36+
* subtree of the DNS namespace under one administrative responsibility. See <a
37+
* href="https://cloud.google.com/dns/api/v1/managedZones">Google Cloud DNS documentation</a> for
38+
* more information.
3839
*/
3940
public class ManagedZoneInfo implements Serializable {
4041

4142
private static final long serialVersionUID = 201601191647L;
4243
private final String name;
43-
private final Long id;
44+
private final BigInteger id;
4445
private final Long creationTimeMillis;
4546
private final String dnsName;
4647
private final String description;
@@ -52,25 +53,29 @@ public class ManagedZoneInfo implements Serializable {
5253
*/
5354
public static class Builder {
5455
private String name;
55-
private Long id;
56+
private BigInteger id;
5657
private Long creationTimeMillis;
5758
private String dnsName;
5859
private String description;
5960
private String nameServerSet;
6061
private List<String> nameServers = new LinkedList<>();
6162

63+
/**
64+
* Returns an empty builder for {@code ManagedZoneInfo}. We use it internally in {@code
65+
* toPb()}.
66+
*/
6267
private Builder() {
6368
}
6469

65-
private Builder(Long id) {
70+
private Builder(BigInteger id) {
6671
this.id = checkNotNull(id);
6772
}
6873

6974
private Builder(String name) {
7075
this.name = checkNotNull(name);
7176
}
7277

73-
private Builder(String name, Long id) {
78+
private Builder(String name, BigInteger id) {
7479
this.name = checkNotNull(name);
7580
this.id = checkNotNull(id);
7681
}
@@ -99,7 +104,7 @@ public Builder name(String name) {
99104
/**
100105
* Sets an id for the managed zone which is assigned to the managed zone by the server.
101106
*/
102-
public Builder id(long id) {
107+
Builder id(BigInteger id) {
103108
this.id = id;
104109
return this;
105110
}
@@ -108,7 +113,6 @@ public Builder id(long id) {
108113
* Sets the time when this managed zone was created.
109114
*/
110115
Builder creationTimeMillis(long creationTimeMillis) {
111-
checkArgument(creationTimeMillis >= 0, "The timestamp cannot be negative.");
112116
this.creationTimeMillis = creationTimeMillis;
113117
return this;
114118
}
@@ -123,8 +127,7 @@ public Builder dnsName(String dnsName) {
123127

124128
/**
125129
* Sets a mandatory description for this managed zone. The value is a string of at most 1024
126-
* characters (this limit is posed by Google Cloud DNS; gcloud-java does not enforce the limit)
127-
* which has no effect on the managed zone's function.
130+
* characters which has no effect on the managed zone's function.
128131
*/
129132
public Builder description(String description) {
130133
this.description = checkNotNull(description);
@@ -133,7 +136,8 @@ public Builder description(String description) {
133136

134137
/**
135138
* Optionally specifies the NameServerSet for this managed zone. A NameServerSet is a set of DNS
136-
* name servers that all host the same ManagedZones.
139+
* name servers that all host the same ManagedZones. Most users will not need to specify this
140+
* value.
137141
*/
138142
public Builder nameServerSet(String nameServerSet) {
139143
// todo(mderka) add more to the doc when questions are answered by the service owner
@@ -146,20 +150,13 @@ public Builder nameServerSet(String nameServerSet) {
146150
* provided by Google Cloud DNS and is read only.
147151
*/
148152
Builder nameServers(List<String> nameServers) {
149-
this.nameServers.addAll(checkNotNull(nameServers));
153+
checkNotNull(nameServers);
154+
this.nameServers = Lists.newLinkedList(nameServers);
150155
return this;
151156
}
152157

153158
/**
154-
* Removes all the nameservers from the list.
155-
*/
156-
Builder clearNameServers() {
157-
this.nameServers.clear();
158-
return this;
159-
}
160-
161-
/**
162-
* Builds the instance of ManagedZoneInfo based on the information set here.
159+
* Builds the instance of {@code ManagedZoneInfo} based on the information set by this builder.
163160
*/
164161
public ManagedZoneInfo build() {
165162
return new ManagedZoneInfo(this);
@@ -186,24 +183,17 @@ public static Builder builder(String name) {
186183
/**
187184
* Returns a builder for {@code ManagedZoneInfo} with an assigned {@code id}.
188185
*/
189-
public static Builder builder(Long id) {
186+
public static Builder builder(BigInteger id) {
190187
return new Builder(id);
191188
}
192189

193190
/**
194191
* Returns a builder for {@code ManagedZoneInfo} with an assigned {@code name} and {@code id}.
195192
*/
196-
public static Builder builder(String name, Long id) {
193+
public static Builder builder(String name, BigInteger id) {
197194
return new Builder(name, id);
198195
}
199196

200-
/**
201-
* Returns an empty builder for {@code ManagedZoneInfo}. We use it internally in {@code toPb()}.
202-
*/
203-
private static Builder builder() {
204-
return new Builder();
205-
}
206-
207197
/**
208198
* Returns the user-defined name of the managed zone.
209199
*/
@@ -214,7 +204,7 @@ public String name() {
214204
/**
215205
* Returns the read-only managed zone id assigned by the server.
216206
*/
217-
public Long id() {
207+
public BigInteger id() {
218208
return id;
219209
}
220210

@@ -233,8 +223,7 @@ public String dnsName() {
233223
}
234224

235225
/**
236-
* Returns the description of this managed zone. This is at most 1024 long mandatory string
237-
* provided by the user.
226+
* Returns the description of this managed zone.
238227
*/
239228
public String description() {
240229
return description;
@@ -270,7 +259,7 @@ com.google.api.services.dns.model.ManagedZone toPb() {
270259
pb.setDescription(this.description());
271260
pb.setDnsName(this.dnsName());
272261
if (this.id() != null) {
273-
pb.setId(BigInteger.valueOf(this.id()));
262+
pb.setId(this.id());
274263
}
275264
pb.setName(this.name());
276265
pb.setNameServers(this.nameServers());
@@ -284,15 +273,15 @@ com.google.api.services.dns.model.ManagedZone toPb() {
284273
}
285274

286275
static ManagedZoneInfo fromPb(com.google.api.services.dns.model.ManagedZone pb) {
287-
Builder b = builder();
276+
Builder b = new Builder();
288277
if (pb.getDescription() != null) {
289278
b.description(pb.getDescription());
290279
}
291280
if (pb.getDnsName() != null) {
292281
b.dnsName(pb.getDnsName());
293282
}
294283
if (pb.getId() != null) {
295-
b.id(pb.getId().longValue());
284+
b.id(pb.getId());
296285
}
297286
if (pb.getName() != null) {
298287
b.name(pb.getName());

branches/dns-alpha-batch/gcloud-java-dns/src/test/java/com/google/gcloud/dns/ManagedZoneInfoTest.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,45 @@
1717
package com.google.gcloud.dns;
1818

1919
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertFalse;
2120
import static org.junit.Assert.assertNotEquals;
2221
import static org.junit.Assert.assertNull;
2322
import static org.junit.Assert.assertTrue;
24-
import static org.junit.Assert.fail;
2523

2624
import com.google.common.collect.Lists;
2725

28-
import org.junit.BeforeClass;
26+
import org.junit.Before;
2927
import org.junit.Test;
3028

29+
import java.math.BigInteger;
3130
import java.util.LinkedList;
3231
import java.util.List;
3332

3433
public class ManagedZoneInfoTest {
3534

3635
private static final String NAME = "mz-example.com";
37-
private static final Long ID = 123L;
36+
private static final BigInteger ID = BigInteger.valueOf(123L);
3837
private static final Long CREATION_TIME_MILLIS = 1123468321321L;
3938
private static final String DNS_NAME = "example.com.";
4039
private static final String DESCRIPTION = "description for the zone";
4140
private static final String NAME_SERVER_SET = "some set";
4241
private static final String NS1 = "name server 1";
4342
private static final String NS2 = "name server 2";
4443
private static final String NS3 = "name server 3";
45-
private static List<String> nameServers = new LinkedList<>();
46-
private static ManagedZoneInfo info;
44+
private List<String> nameServers = new LinkedList<>();
45+
private ManagedZoneInfo info;
4746

48-
@BeforeClass
49-
public static void setUp() {
47+
@Before
48+
public void setUp() {
5049
nameServers.add(NS1);
5150
nameServers.add(NS2);
5251
nameServers.add(NS3);
53-
assertEquals(3, nameServers.size());
5452
info = ManagedZoneInfo.builder(NAME, ID)
5553
.creationTimeMillis(CREATION_TIME_MILLIS)
5654
.dnsName(DNS_NAME)
5755
.description(DESCRIPTION)
5856
.nameServerSet(NAME_SERVER_SET)
5957
.nameServers(nameServers)
6058
.build();
61-
System.out.println(info);
6259
}
6360

6461
@Test
@@ -105,12 +102,7 @@ public void testBuilder() {
105102

106103
@Test
107104
public void testValidCreationTime() {
108-
try {
109-
ManagedZoneInfo.builder(NAME).creationTimeMillis(-1);
110-
fail("A negative value is not acceptable for creation time.");
111-
} catch (IllegalArgumentException e) {
112-
// expected
113-
}
105+
ManagedZoneInfo.builder(NAME).creationTimeMillis(-1);
114106
ManagedZoneInfo.builder(NAME).creationTimeMillis(0);
115107
ManagedZoneInfo.builder(NAME).creationTimeMillis(Long.MAX_VALUE);
116108
}
@@ -132,7 +124,7 @@ public void testEqualsAndNotEquals() {
132124
assertNotEquals(clone, info);
133125
clone = info.toBuilder().dnsName(differentName).build();
134126
assertNotEquals(clone, info);
135-
clone = info.toBuilder().id(info.id() + 1).build();
127+
clone = info.toBuilder().id(info.id().add(BigInteger.ONE)).build();
136128
assertNotEquals(clone, info);
137129
clone = info.toBuilder().nameServerSet(info.nameServerSet() + "salt").build();
138130
assertNotEquals(clone, info);
@@ -188,11 +180,20 @@ public void testToAndFromPb() {
188180
}
189181

190182
@Test
191-
public void testClearNameServers() {
192-
ManagedZoneInfo clone = info.toBuilder().build();
193-
assertFalse(clone.nameServers().isEmpty());
194-
clone = clone.toBuilder().clearNameServers().build();
183+
public void testEmptyNameServers() {
184+
ManagedZoneInfo clone = info.toBuilder().nameServers(new LinkedList<String>()).build();
195185
assertTrue(clone.nameServers().isEmpty());
196186
clone.toPb(); // test that this is allowed
197187
}
188+
189+
@Test
190+
public void testDateParsing() {
191+
com.google.api.services.dns.model.ManagedZone pb =
192+
info.toPb();
193+
pb.setCreationTime("2016-01-19T18:00:12.854Z"); // a real value obtained from Google Cloud DNS
194+
ManagedZoneInfo mz = ManagedZoneInfo.fromPb(pb); // parses the string timestamp to millis
195+
com.google.api.services.dns.model.ManagedZone pbClone = mz.toPb(); // converts it back to string
196+
assertEquals(pb, pbClone);
197+
assertEquals(pb.getCreationTime(), pbClone.getCreationTime());
198+
}
198199
}

0 commit comments

Comments
 (0)