Skip to content

Commit a9cc927

Browse files
committed
Implemented comments by @aozarov. Added test for option accessors.
1 parent adf5c1c commit a9cc927

File tree

4 files changed

+173
-58
lines changed

4 files changed

+173
-58
lines changed

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

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131
*/
3232
public interface Dns extends Service<DnsOptions> {
3333

34+
35+
3436
/**
3537
* The fields of a project.
3638
*
3739
* <p>These values can be used to specify the fields to include in a partial response when calling
38-
* {@code Dns#getProjectInfo(ProjectGetOption...)}. Project ID is always returned, even if
39-
* not specified.
40+
* {@code Dns#getProjectInfo(ProjectGetOption...)}. Project ID is always returned, even if not
41+
* specified.
4042
*/
4143
enum ProjectField {
4244
PROJECT_ID("id"),
@@ -67,8 +69,8 @@ static String selector(ProjectField... fields) {
6769
* The fields of a zone.
6870
*
6971
* <p>These values can be used to specify the fields to include in a partial response when calling
70-
* {@code Dns#getZone(BigInteger, ZoneFieldOption...)} or {@code Dns#getZone(String,
71-
* ZoneFieldOption...)}. The ID is always returned, even if not specified.
72+
* {@code Dns#getZone(BigInteger, ZoneOption...)} or {@code Dns#getZone(String, ZoneOption...)}.
73+
* The ID is always returned, even if not specified.
7274
*/
7375
enum ZoneField {
7476
CREATION_TIME("creationTime"),
@@ -104,8 +106,8 @@ static String selector(ZoneField... fields) {
104106
*
105107
* <p>These values can be used to specify the fields to include in a partial response when calling
106108
* {@code Dns#listDnsRecords(BigInteger, DnsRecordListOption...)} or {@code
107-
* Dns#listDnsRecords(String, DnsRecordListOption...)}. The name is always returned even if
108-
* not selected.
109+
* Dns#listDnsRecords(String, DnsRecordListOption...)}. The name is always returned even if not
110+
* selected.
109111
*/
110112
enum DnsRecordField {
111113
DNS_RECORDS("rrdatas"),
@@ -137,9 +139,9 @@ static String selector(DnsRecordField... fields) {
137139
* The fields of a change request.
138140
*
139141
* <p>These values can be used to specify the fields to include in a partial response when calling
140-
* {@code Dns#applyChangeRequest(ChangeRequest, BigInteger, ChangeRequestOption...)}
141-
* or {@code Dns#applyChangeRequest(ChangeRequest, String, ChangeRequestOption...)}
142-
* The ID is always returned even if not selected.
142+
* {@code Dns#applyChangeRequest(ChangeRequest, BigInteger, ChangeRequestOption...)} or {@code
143+
* Dns#applyChangeRequest(ChangeRequest, String, ChangeRequestOption...)} The ID is always
144+
* returned even if not selected.
143145
*/
144146
enum ChangeRequestField {
145147
ID("id"),
@@ -168,24 +170,6 @@ static String selector(ChangeRequestField... fields) {
168170
}
169171
}
170172

171-
/**
172-
* The sorting keys for listing change requests. The only currently supported sorting key is the
173-
* when the change request was created.
174-
*/
175-
enum ChangeRequestSortingKey {
176-
TIME_CREATED("changeSequence");
177-
178-
private final String selector;
179-
180-
ChangeRequestSortingKey(String selector) {
181-
this.selector = selector;
182-
}
183-
184-
String selector() {
185-
return selector;
186-
}
187-
}
188-
189173
/**
190174
* The sorting order for listing.
191175
*/
@@ -261,24 +245,23 @@ public static DnsRecordListOption type(DnsRecord.Type type) {
261245
/**
262246
* Class for specifying zone field options.
263247
*/
264-
class ZoneFieldOption extends AbstractOption implements Serializable {
248+
class ZoneOption extends AbstractOption implements Serializable {
265249

266250
private static final long serialVersionUID = -8065564464895945037L;
267251

268-
ZoneFieldOption(DnsRpc.Option option, Object value) {
252+
ZoneOption(DnsRpc.Option option, Object value) {
269253
super(option, value);
270254
}
271255

272256
/**
273257
* Returns an option to specify the zones's fields to be returned by the RPC call.
274258
*
275-
* <p>If this option is not provided all zone fields are returned. {@code
276-
* ZoneFieldOption.fields} can be used to specify only the fields of interest. Zone ID is always
277-
* returned, even if not specified. {@link ZoneField} provides a list of fields that can be
278-
* used.
259+
* <p>If this option is not provided all zone fields are returned. {@code ZoneOption.fields} can
260+
* be used to specify only the fields of interest. Zone ID is always returned, even if not
261+
* specified. {@link ZoneField} provides a list of fields that can be used.
279262
*/
280-
public static ZoneFieldOption fields(ZoneField... fields) {
281-
return new ZoneFieldOption(DnsRpc.Option.FIELDS, ZoneField.selector(fields));
263+
public static ZoneOption fields(ZoneField... fields) {
264+
return new ZoneOption(DnsRpc.Option.FIELDS, ZoneField.selector(fields));
282265
}
283266
}
284267

@@ -296,10 +279,9 @@ class ZoneListOption extends AbstractOption implements Serializable {
296279
/**
297280
* Returns an option to specify the zones's fields to be returned by the RPC call.
298281
*
299-
* <p>If this option is not provided all zone fields are returned. {@code
300-
* ZoneFieldOption.fields} can be used to specify only the fields of interest. Zone ID is always
301-
* returned, even if not specified. {@link ZoneField} provides a list of fields that can be
302-
* used.
282+
* <p>If this option is not provided all zone fields are returned. {@code ZoneOption.fields} can
283+
* be used to specify only the fields of interest. Zone ID is always returned, even if not
284+
* specified. {@link ZoneField} provides a list of fields that can be used.
303285
*/
304286
public static ZoneListOption fields(ZoneField... fields) {
305287
return new ZoneListOption(DnsRpc.Option.FIELDS, ZoneField.selector(fields));
@@ -366,9 +348,9 @@ class ChangeRequestOption extends AbstractOption implements Serializable {
366348
* service.
367349
*
368350
* <p>If this option is not provided all change request fields are returned. {@code
369-
* ChangeRequestOption.fields} can be used to specify only the fields of interest. The ID
370-
* of the change request is always returned, even if not specified. {@link ChangeRequestField}
371-
* provides a list of fields that can be used.
351+
* ChangeRequestOption.fields} can be used to specify only the fields of interest. The ID of the
352+
* change request is always returned, even if not specified. {@link ChangeRequestField} provides
353+
* a list of fields that can be used.
372354
*/
373355
public static ChangeRequestOption fields(ChangeRequestField... fields) {
374356
return new ChangeRequestOption(
@@ -394,9 +376,9 @@ class ChangeRequestListOption extends AbstractOption implements Serializable {
394376
* service.
395377
*
396378
* <p>If this option is not provided all change request fields are returned. {@code
397-
* ChangeRequestOption.fields} can be used to specify only the fields of interest. The ID
398-
* of the change request is always returned, even if not specified. {@link ChangeRequestField}
399-
* provides a list of fields that can be used.
379+
* ChangeRequestOption.fields} can be used to specify only the fields of interest. The ID of the
380+
* change request is always returned, even if not specified. {@link ChangeRequestField} provides
381+
* a list of fields that can be used.
400382
*/
401383
public static ChangeRequestListOption fields(ChangeRequestField... fields) {
402384
return new ChangeRequestListOption(
@@ -427,16 +409,10 @@ public static ChangeRequestListOption pageSize(int pageSize) {
427409
}
428410

429411
/**
430-
* Returns an option for specifying the sorting criterion of change requests. Note the the only
431-
* currently supported criterion is the change sequence.
432-
*/
433-
public static ChangeRequestListOption sortBy(ChangeRequestSortingKey key) {
434-
return new ChangeRequestListOption(DnsRpc.Option.SORTING_KEY, key.selector());
435-
}
436-
437-
/**
438-
* Returns an option to specify whether the the change requests should be listed in ascending or
439-
* descending order.
412+
* Returns an option to specify whether the the change requests should be listed in ascending
413+
* (most-recent last) or descending (most-recent first) order with respect to when the change
414+
* request was accepted by the server. If this option is not provided, the listing order is
415+
* undefined.
440416
*/
441417
public static ChangeRequestListOption sortOrder(SortingOrder order) {
442418
return new ChangeRequestListOption(DnsRpc.Option.SORTING_ORDER, order.selector());

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public class DnsOptions
2828

2929
private static final long serialVersionUID = -519128051411747771L;
3030
private static final String GC_DNS_RW = "https://www.googleapis.com/auth/ndev.clouddns.readwrite";
31-
private static final String GC_DNS_R = "https://www.googleapis.com/auth/ndev.clouddns.readonly";
32-
private static final Set<String> SCOPES = ImmutableSet.of(GC_DNS_RW, GC_DNS_R);
31+
private static final Set<String> SCOPES = ImmutableSet.of(GC_DNS_RW);
3332

3433
public static class DefaultDnsFactory implements DnsFactory {
3534
private static final DnsFactory INSTANCE = new DefaultDnsFactory();

gcloud-java-dns/src/main/java/com/google/gcloud/spi/DnsRpc.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ enum Option {
2626
PAGE_TOKEN("pageToken"),
2727
DNS_NAME("dnsName"),
2828
DNS_TYPE("type"),
29-
SORTING_KEY("sortBy"),
3029
SORTING_ORDER("sortOrder");
3130

3231
private final String value;
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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.assertTrue;
21+
22+
import com.google.gcloud.spi.DnsRpc;
23+
24+
import org.junit.Test;
25+
26+
public class DnsTest {
27+
28+
private static final Integer PAGE_SIZE = 20;
29+
private static final String PAGE_TOKEN = "page token";
30+
31+
@Test
32+
public void testDnsRecordListOption() {
33+
// dns name
34+
String dnsName = "some name";
35+
Dns.DnsRecordListOption dnsRecordListOption = Dns.DnsRecordListOption.dnsName(dnsName);
36+
assertEquals(dnsName, dnsRecordListOption.value());
37+
assertEquals(DnsRpc.Option.DNS_NAME, dnsRecordListOption.rpcOption());
38+
// page token
39+
dnsRecordListOption = Dns.DnsRecordListOption.pageToken(PAGE_TOKEN);
40+
assertEquals(PAGE_TOKEN, dnsRecordListOption.value());
41+
assertEquals(DnsRpc.Option.PAGE_TOKEN, dnsRecordListOption.rpcOption());
42+
// page size
43+
dnsRecordListOption = Dns.DnsRecordListOption.pageSize(PAGE_SIZE);
44+
assertEquals(PAGE_SIZE, dnsRecordListOption.value());
45+
assertEquals(DnsRpc.Option.PAGE_SIZE, dnsRecordListOption.rpcOption());
46+
// record type
47+
DnsRecord.Type recordType = DnsRecord.Type.AAAA;
48+
dnsRecordListOption = Dns.DnsRecordListOption.type(recordType);
49+
assertEquals(recordType, dnsRecordListOption.value());
50+
assertEquals(DnsRpc.Option.DNS_TYPE, dnsRecordListOption.rpcOption());
51+
// fields
52+
dnsRecordListOption = Dns.DnsRecordListOption.fields(Dns.DnsRecordField.NAME,
53+
Dns.DnsRecordField.TTL);
54+
assertEquals(DnsRpc.Option.FIELDS, dnsRecordListOption.rpcOption());
55+
assertTrue(dnsRecordListOption.value() instanceof String);
56+
assertTrue(((String) dnsRecordListOption.value()).contains(
57+
Dns.DnsRecordField.NAME.selector()));
58+
assertTrue(((String) dnsRecordListOption.value()).contains(
59+
Dns.DnsRecordField.TTL.selector()));
60+
assertTrue(((String) dnsRecordListOption.value()).contains(
61+
Dns.DnsRecordField.NAME.selector()));
62+
}
63+
64+
@Test
65+
public void testZoneOption() {
66+
Dns.ZoneOption fields = Dns.ZoneOption.fields(Dns.ZoneField.CREATION_TIME,
67+
Dns.ZoneField.DESCRIPTION);
68+
assertEquals(DnsRpc.Option.FIELDS, fields.rpcOption());
69+
assertTrue(fields.value() instanceof String);
70+
assertTrue(((String) fields.value()).contains(Dns.ZoneField.CREATION_TIME.selector()));
71+
assertTrue(((String) fields.value()).contains(Dns.ZoneField.DESCRIPTION.selector()));
72+
}
73+
74+
@Test
75+
public void testZoneList() {
76+
// fields
77+
Dns.ZoneListOption fields = Dns.ZoneListOption.fields(Dns.ZoneField.CREATION_TIME,
78+
Dns.ZoneField.DESCRIPTION);
79+
assertEquals(DnsRpc.Option.FIELDS, fields.rpcOption());
80+
assertTrue(fields.value() instanceof String);
81+
assertTrue(((String) fields.value()).contains(Dns.ZoneField.CREATION_TIME.selector()));
82+
assertTrue(((String) fields.value()).contains(Dns.ZoneField.DESCRIPTION.selector()));
83+
assertTrue(((String) fields.value()).contains(Dns.ZoneField.ZONE_ID.selector()));
84+
// page token
85+
Dns.ZoneListOption option = Dns.ZoneListOption.pageToken(PAGE_TOKEN);
86+
assertEquals(PAGE_TOKEN, option.value());
87+
assertEquals(DnsRpc.Option.PAGE_TOKEN, option.rpcOption());
88+
// page size
89+
option = Dns.ZoneListOption.pageSize(PAGE_SIZE);
90+
assertEquals(PAGE_SIZE, option.value());
91+
assertEquals(DnsRpc.Option.PAGE_SIZE, option.rpcOption());
92+
}
93+
94+
@Test
95+
public void testProjectGetOption() {
96+
// fields
97+
Dns.ProjectGetOption fields = Dns.ProjectGetOption.fields(Dns.ProjectField.QUOTA);
98+
assertEquals(DnsRpc.Option.FIELDS, fields.rpcOption());
99+
assertTrue(fields.value() instanceof String);
100+
assertTrue(((String) fields.value()).contains(Dns.ProjectField.QUOTA.selector()));
101+
assertTrue(((String) fields.value()).contains(Dns.ProjectField.PROJECT_ID.selector()));
102+
}
103+
104+
@Test
105+
public void testChangeRequestOption() {
106+
// fields
107+
Dns.ChangeRequestOption fields = Dns.ChangeRequestOption.fields(
108+
Dns.ChangeRequestField.START_TIME, Dns.ChangeRequestField.STATUS);
109+
assertEquals(DnsRpc.Option.FIELDS, fields.rpcOption());
110+
assertTrue(fields.value() instanceof String);
111+
assertTrue(((String) fields.value()).contains(
112+
Dns.ChangeRequestField.START_TIME.selector()));
113+
assertTrue(((String) fields.value()).contains(Dns.ChangeRequestField.STATUS.selector()));
114+
assertTrue(((String) fields.value()).contains(Dns.ChangeRequestField.ID.selector()));
115+
}
116+
117+
@Test
118+
public void testChangeRequestListOption() {
119+
// fields
120+
Dns.ChangeRequestListOption fields = Dns.ChangeRequestListOption.fields(
121+
Dns.ChangeRequestField.START_TIME, Dns.ChangeRequestField.STATUS);
122+
assertEquals(DnsRpc.Option.FIELDS, fields.rpcOption());
123+
assertTrue(fields.value() instanceof String);
124+
assertTrue(((String) fields.value()).contains(
125+
Dns.ChangeRequestField.START_TIME.selector()));
126+
assertTrue(((String) fields.value()).contains(Dns.ChangeRequestField.STATUS.selector()));
127+
assertTrue(((String) fields.value()).contains(Dns.ChangeRequestField.ID.selector()));
128+
// page token
129+
Dns.ChangeRequestListOption option = Dns.ChangeRequestListOption.pageToken(PAGE_TOKEN);
130+
assertEquals(PAGE_TOKEN, option.value());
131+
assertEquals(DnsRpc.Option.PAGE_TOKEN, option.rpcOption());
132+
// page size
133+
option = Dns.ChangeRequestListOption.pageSize(PAGE_SIZE);
134+
assertEquals(PAGE_SIZE, option.value());
135+
assertEquals(DnsRpc.Option.PAGE_SIZE, option.rpcOption());
136+
// sort order
137+
option = Dns.ChangeRequestListOption.sortOrder(Dns.SortingOrder.ASCENDING);
138+
assertEquals(DnsRpc.Option.SORTING_ORDER, option.rpcOption());
139+
assertEquals(Dns.SortingOrder.ASCENDING.selector(), option.value());
140+
}
141+
}

0 commit comments

Comments
 (0)