Skip to content

Commit db52e09

Browse files
committed
Made nameServerSet read only and setters package private.
Adds dnsName filter for Zone listing and tests. Adds serialization test. Fixes googleapis#630, googleapis#602 and googleapis#631.
1 parent ee5bb8f commit db52e09

File tree

7 files changed

+150
-6
lines changed

7 files changed

+150
-6
lines changed

gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java

+8
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ public static ZoneListOption pageToken(String pageToken) {
295295
return new ZoneListOption(DnsRpc.Option.PAGE_TOKEN, pageToken);
296296
}
297297

298+
/**
299+
* Restricts the list to only zone with this fully qualified domain name.
300+
*/
301+
public static ZoneListOption dnsName(String dnsName) {
302+
StringBuilder builder = new StringBuilder();
303+
return new ZoneListOption(DnsRpc.Option.DNS_NAME, dnsName);
304+
}
305+
298306
/**
299307
* The maximum number of zones to return per RPC.
300308
*

gcloud-java-dns/src/main/java/com/google/gcloud/dns/DnsOptions.java

+10
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,14 @@ public Builder toBuilder() {
9595
public static Builder builder() {
9696
return new Builder();
9797
}
98+
99+
@Override
100+
public boolean equals(Object obj) {
101+
return obj instanceof DnsOptions && baseEquals((DnsOptions) obj);
102+
}
103+
104+
@Override
105+
public int hashCode() {
106+
return baseHashCode();
107+
}
98108
}

gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public Builder description(String description) {
8585
}
8686

8787
@Override
88-
public Builder nameServerSet(String nameServerSet) {
88+
Builder nameServerSet(String nameServerSet) {
8989
infoBuilder.nameServerSet(nameServerSet);
9090
return this;
9191
}

gcloud-java-dns/src/main/java/com/google/gcloud/dns/ZoneInfo.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public abstract static class Builder {
8282
* servers that all host the same zones. Most users will not need to specify this value.
8383
*/
8484
abstract Builder nameServerSet(String nameServerSet);
85-
// todo(mderka) add more to the doc when questions are answered by the service owner
85+
// this should not be included in tooling as per the service owners
8686

8787
/**
8888
* Sets a list of servers that hold the information about the zone. This information is provided
@@ -155,7 +155,7 @@ public Builder description(String description) {
155155
}
156156

157157
@Override
158-
public Builder nameServerSet(String nameServerSet) {
158+
Builder nameServerSet(String nameServerSet) {
159159
this.nameServerSet = checkNotNull(nameServerSet);
160160
return this;
161161
}
@@ -227,10 +227,10 @@ public String description() {
227227
}
228228

229229
/**
230-
* Returns the optionally specified set of DNS name servers that all host this zone.
230+
* Returns the optionally specified set of DNS name servers that all host this zone. This value is
231+
* set only for specific use cases and is left empty for vast majority of users.
231232
*/
232233
public String nameServerSet() {
233-
// todo(mderka) update this doc after finding out more about this from the service owners
234234
return nameServerSet;
235235
}
236236

gcloud-java-dns/src/test/java/com/google/gcloud/dns/DnsImplTest.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public class DnsImplTest {
8383
// Listing options
8484
private static final Dns.ZoneListOption[] ZONE_LIST_OPTIONS = {
8585
Dns.ZoneListOption.pageSize(MAX_SIZE), Dns.ZoneListOption.pageToken(PAGE_TOKEN),
86-
Dns.ZoneListOption.fields(Dns.ZoneField.DESCRIPTION)};
86+
Dns.ZoneListOption.fields(Dns.ZoneField.DESCRIPTION),
87+
Dns.ZoneListOption.dnsName(DNS_NAME)};
8788
private static final Dns.ChangeRequestListOption[] CHANGE_LIST_OPTIONS = {
8889
Dns.ChangeRequestListOption.pageSize(MAX_SIZE),
8990
Dns.ChangeRequestListOption.pageToken(PAGE_TOKEN),
@@ -330,6 +331,8 @@ public void testListZonesWithOptions() {
330331
selector = (String) capturedOptions.getValue().get(ZONE_LIST_OPTIONS[2].rpcOption());
331332
assertTrue(selector.contains(Dns.ZoneField.DESCRIPTION.selector()));
332333
assertTrue(selector.contains(Dns.ZoneField.NAME.selector()));
334+
selector = (String) capturedOptions.getValue().get(ZONE_LIST_OPTIONS[3].rpcOption());
335+
assertEquals(DNS_NAME, selector);
333336
}
334337

335338
@Test

gcloud-java-dns/src/test/java/com/google/gcloud/dns/DnsTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class DnsTest {
2727

2828
private static final Integer PAGE_SIZE = 20;
2929
private static final String PAGE_TOKEN = "page token";
30+
private static final String DNS_NAME = "www.example.com.";
3031

3132
@Test
3233
public void testDnsRecordListOption() {
@@ -89,6 +90,10 @@ public void testZoneList() {
8990
option = Dns.ZoneListOption.pageSize(PAGE_SIZE);
9091
assertEquals(PAGE_SIZE, option.value());
9192
assertEquals(DnsRpc.Option.PAGE_SIZE, option.rpcOption());
93+
// dnsName filter
94+
option = Dns.ZoneListOption.dnsName(DNS_NAME);
95+
assertEquals(DNS_NAME, option.value());
96+
assertEquals(DnsRpc.Option.DNS_NAME, option.rpcOption());
9297
}
9398

9499
@Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.dns;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNotSame;
21+
22+
import com.google.common.collect.ImmutableList;
23+
import com.google.gcloud.RetryParams;
24+
25+
import org.junit.Test;
26+
27+
import java.io.ByteArrayInputStream;
28+
import java.io.ByteArrayOutputStream;
29+
import java.io.IOException;
30+
import java.io.ObjectInputStream;
31+
import java.io.ObjectOutputStream;
32+
import java.io.Serializable;
33+
import java.math.BigInteger;
34+
import java.util.concurrent.TimeUnit;
35+
36+
public class SerializationTest {
37+
38+
private static final ZoneInfo FULL_ZONE_INFO = Zone.builder("some zone name")
39+
.creationTimeMillis(132L)
40+
.description("some descriptions")
41+
.dnsName("www.example.com")
42+
.id("123333")
43+
.nameServers(ImmutableList.of("server 1", "server 2"))
44+
.nameServerSet("specificationstring")
45+
.build();
46+
private static final ZoneInfo PARTIAL_ZONE_INFO = Zone.builder("some zone name")
47+
.build();
48+
private static final ProjectInfo PARTIAL_PROJECT_INFO = ProjectInfo.builder().id("13").build();
49+
private static final ProjectInfo FULL_PROJECT_INFO = ProjectInfo.builder()
50+
.id("342")
51+
.number(new BigInteger("2343245"))
52+
.quota(new ProjectInfo.Quota(12, 13, 14, 15, 16, 17))
53+
.build();
54+
private static final Dns.ZoneListOption ZONE_LIST_OPTION =
55+
Dns.ZoneListOption.dnsName("www.example.com.");
56+
private static final Dns.DnsRecordListOption DNS_REOCRD_LIST_OPTION =
57+
Dns.DnsRecordListOption.fields(Dns.DnsRecordField.TTL);
58+
private static final Dns.ChangeRequestListOption CHANGE_REQUEST_LIST_OPTION =
59+
Dns.ChangeRequestListOption.fields(Dns.ChangeRequestField.STATUS);
60+
private static final Dns.ZoneOption ZONE_OPTION =
61+
Dns.ZoneOption.fields(Dns.ZoneField.CREATION_TIME);
62+
private static final Dns.ChangeRequestOption CHANGE_REQUEST_OPTION =
63+
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.STATUS);
64+
private static final Dns.ProjectOption PROJECT_OPTION =
65+
Dns.ProjectOption.fields(Dns.ProjectField.QUOTA);
66+
private static final DnsOptions OPTIONS = DnsOptions.builder()
67+
.projectId("some-unnecessary-project-ID")
68+
.retryParams(RetryParams.defaultInstance())
69+
.build();
70+
private static final Dns DNS = OPTIONS.service();
71+
private static final Zone FULL_ZONE = new Zone(DNS, new ZoneInfo.BuilderImpl(FULL_ZONE_INFO));
72+
private static final Zone PARTIAL_ZONE =
73+
new Zone(DNS, new ZoneInfo.BuilderImpl(PARTIAL_ZONE_INFO));
74+
private static final ChangeRequest CHANGE_REQUEST_PARTIAL = ChangeRequest.builder().build();
75+
private static final DnsRecord DNS_RECORD_PARTIAL =
76+
DnsRecord.builder("www.www.com", DnsRecord.Type.AAAA).build();
77+
private static final DnsRecord DNS_RECORD_COMPLETE =
78+
DnsRecord.builder("www.sadfa.com", DnsRecord.Type.A)
79+
.ttl(12, TimeUnit.HOURS)
80+
.addRecord("record")
81+
.build();
82+
private static final ChangeRequest CHANGE_REQUEST_COMPLETE = ChangeRequest.builder()
83+
.add(DNS_RECORD_COMPLETE)
84+
.delete(DNS_RECORD_PARTIAL)
85+
.status(ChangeRequest.Status.PENDING)
86+
.id("some id")
87+
.startTimeMillis(132L)
88+
.build();
89+
90+
91+
@Test
92+
public void testModelAndRequests() throws Exception {
93+
Serializable[] objects = {FULL_ZONE_INFO, PARTIAL_ZONE_INFO, ZONE_LIST_OPTION,
94+
DNS_REOCRD_LIST_OPTION, CHANGE_REQUEST_LIST_OPTION, ZONE_OPTION, CHANGE_REQUEST_OPTION,
95+
PROJECT_OPTION, PARTIAL_PROJECT_INFO, FULL_PROJECT_INFO, OPTIONS, FULL_ZONE, PARTIAL_ZONE,
96+
OPTIONS, CHANGE_REQUEST_PARTIAL, DNS_RECORD_PARTIAL, DNS_RECORD_COMPLETE,
97+
CHANGE_REQUEST_COMPLETE};
98+
for (Serializable obj : objects) {
99+
Object copy = serializeAndDeserialize(obj);
100+
assertEquals(obj, obj);
101+
assertEquals(obj, copy);
102+
assertNotSame(obj, copy);
103+
assertEquals(copy, copy);
104+
}
105+
}
106+
107+
@SuppressWarnings("unchecked")
108+
private <T> T serializeAndDeserialize(T obj) throws IOException, ClassNotFoundException {
109+
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
110+
try (ObjectOutputStream output = new ObjectOutputStream(bytes)) {
111+
output.writeObject(obj);
112+
}
113+
try (ObjectInputStream input =
114+
new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) {
115+
return (T) input.readObject();
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)