From a69101a80df1637361b02a93233d0ad3e5d69098 Mon Sep 17 00:00:00 2001 From: Martin Derka Date: Mon, 1 Feb 2016 16:18:16 -0800 Subject: [PATCH 1/3] Added Dns methods. Fixes #596. Added Zone and ZoneTest --- .../main/java/com/google/gcloud/dns/Dns.java | 194 ++++- .../main/java/com/google/gcloud/dns/Zone.java | 256 ++++++ .../google/gcloud/dns/AbstractOptionTest.java | 8 +- .../java/com/google/gcloud/dns/ZoneTest.java | 750 ++++++++++++++++++ 4 files changed, 1200 insertions(+), 8 deletions(-) create mode 100644 gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java create mode 100644 gcloud-java-dns/src/test/java/com/google/gcloud/dns/ZoneTest.java diff --git a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java index 28e79104cf58..b48e4b0a90f2 100644 --- a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java +++ b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java @@ -18,14 +18,14 @@ import com.google.common.base.Joiner; import com.google.common.collect.Sets; +import com.google.gcloud.Page; import com.google.gcloud.Service; import com.google.gcloud.spi.DnsRpc; import java.io.Serializable; +import java.math.BigInteger; import java.util.Set; -import static com.google.gcloud.dns.Dns.ZoneField.selector; - /** * An interface for the Google Cloud DNS service. * @@ -285,7 +285,7 @@ class ZoneListOption extends AbstractOption implements Serializable { */ public static ZoneListOption fields(ZoneField... fields) { StringBuilder builder = new StringBuilder(); - builder.append("managedZones(").append(selector(fields)).append(')'); + builder.append("managedZones(").append(ZoneField.selector(fields)).append(')'); return new ZoneListOption(DnsRpc.Option.FIELDS, builder.toString()); } @@ -420,5 +420,191 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) { } } - // TODO(mderka) Add methods. Created issue #596. + /** + * Creates a new zone. + * + * @return ZoneInfo object representing the new zone's metadata. In addition to the name, dns name + * and description (supplied by the user within the {@code zoneInfo} parameter, the returned + * object will include the following read-only fields supplied by the server: creation time, id, + * and list of name servers. + * @throws DnsException upon failure + * @see Cloud DNS Managed Zones: + * create + */ + ZoneInfo create(ZoneInfo zoneInfo); + + /** + * Retrieves the zone by the specified zone name. Returns {@code null} is the zone is not found. + * The returned fields can be optionally restricted by specifying {@code ZoneFieldOptions}. + * + * @throws DnsException upon failure + * @see Cloud DNS Managed Zones: + * get + */ + ZoneInfo getZone(String zoneName, ZoneOption... options); + + /** + * Retrieves the zone by the specified zone name. Returns {@code null} is the zone is not found. + * The returned fields can be optionally restricted by specifying {@code ZoneFieldOptions}. + * + * @throws DnsException upon failure + * @see Cloud DNS Managed Zones: + * get + */ + ZoneInfo getZone(BigInteger zoneId, ZoneOption... options); + + /** + * Lists the zoned inside the project. + * + *

This method returns zone in an unspecified order. New zones do not necessarily appear at the + * end of the list. Use {@link ZoneListOption} to restrict the listing to a domain name, set page + * size, and set page tokens. + * + * @return {@code Page}, a page of zones + * @throws DnsException upon failure + * @see Cloud DNS Managed Zones: + * list + */ + Page listZones(ZoneListOption... options); + + /** + * Deletes an existing zone identified by name. Returns true if the zone was successfully deleted + * and false otherwise. + * + * @return {@code true} if zone was found and deleted and false otherwise + * @throws DnsException upon failure + * @see Cloud DNS Managed Zones: + * delete + */ + boolean delete(String zoneName); // delete does not admit any options + + /** + * Deletes an existing zone identified by id. Returns true if the zone was successfully deleted + * and false otherwise. + * + * @return {@code true} if zone was found and deleted and false otherwise + * @throws DnsException upon failure + * @see Cloud DNS Managed Zones: + * delete + */ + boolean delete(BigInteger zoneId); // delete does not admit any options + + /** + * Lists the DNS records in the zone identified by name. + * + *

The fields to be returned, page size and page tokens can be specified using {@code + * DnsRecordOptions}. Returns null if the zone cannot be found. + * + * @throws DnsException upon failure + * @see Cloud DNS + * ResourceRecordSets: list + */ + Page listDnsRecords(String zoneName, DnsRecordListOption... options); + + /** + * Lists the DNS records in the zone identified by ID. + * + *

The fields to be returned, page size and page tokens can be specified using {@code + * DnsRecordOptions}. Returns null if the zone cannot be found. + * + * @throws DnsException upon failure + * @see Cloud DNS + * ResourceRecordSets: list + */ + Page listDnsRecords(BigInteger zoneId, DnsRecordListOption... options); + + /** + * Retrieves the metadata about the current project. The returned fields can be optionally + * restricted by specifying {@code ProjectOptions}. + * + * @throws DnsException upon failure + * @see Cloud DNS Projects: get + */ + ProjectInfo getProjectInfo(ProjectGetOption... fields); + + /** + * Returns the current project id. + */ + String getProjectId(); + + /** + * Returns the current project number. + */ + BigInteger getProjectNumber(); + + /** + * Submits a change requests for applying to the zone identified by ID to the service. The + * returned object contains the following read-only fields supplied by the server: id, start time + * and status. time, id, and list of name servers. The returned fields can be modified by {@code + * ChangeRequestFieldOptions}. Returns null if the zone is not found. + * + * @return ChangeRequest object representing the new change request or null if zone is not found + * @throws DnsException upon failure + * @see Cloud DNS Changes: create + */ + ChangeRequest applyChangeRequest(ChangeRequest changeRequest, BigInteger zoneId, + ChangeRequestOption... options); + + /** + * Submits a change requests for applying to the zone identified by name to the service. The + * returned object contains the following read-only fields supplied by the server: id, start time + * and status. time, id, and list of name servers. The returned fields can be modified by {@code + * ChangeRequestFieldOptions}. Returns null if the zone is not found. + * + * @return ChangeRequest object representing the new change request or null if zone is not found + * @throws DnsException upon failure + * @see Cloud DNS Changes: create + */ + ChangeRequest applyChangeRequest(ChangeRequest changeRequest, String zoneName, + ChangeRequestOption... options); + + /** + * Retrieves updated information about a change request previously submitted for a zone identified + * by ID. Returns null if the zone or request cannot be found. + * + *

The fields to be returned using {@code ChangeRequestFieldOptions}. + * + * @throws DnsException upon failure + * @see Cloud DNS Chages: get + */ + ChangeRequest getChangeRequest(ChangeRequest changeRequest, BigInteger zoneId, + ChangeRequestOption... options); + + /** + * Retrieves updated information about a change request previously submitted for a zone identified + * by name. Returns null if the zone or request cannot be found. + * + *

The fields to be returned using {@code ChangeRequestFieldOptions}. + * + * @throws DnsException upon failure + * @see Cloud DNS Chages: get + */ + ChangeRequest getChangeRequest(ChangeRequest changeRequest, String zoneName, + ChangeRequestOption... options); + + /** + * Lists the change requests for the zone identified by ID that were submitted to the service. + * + *

The sorting key for changes, fields to be returned, page and page tokens can be specified + * using {@code ChangeRequestListOptions}. Note that the only sorting key currently supported is + * the timestamp of submitting the change request to the service. + * + * @return {@code Page}, a page of change requests + * @throws DnsException upon failure + * @see Cloud DNS Chages: list + */ + Page listChangeRequests(BigInteger zoneId, ChangeRequestListOption... options); + + /** + * Lists the change requests for the zone identified by name that were submitted to the service. + * + *

The sorting key for changes, fields to be returned, page and page tokens can be specified + * using {@code ChangeRequestListOptions}. Note that the only sorting key currently supported is + * the timestamp of submitting the change request to the service. + * + * @return {@code Page}, a page of change requests + * @throws DnsException upon failure + * @see Cloud DNS Chages: list + */ + Page listChangeRequests(String zoneName, ChangeRequestListOption... options); } diff --git a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java new file mode 100644 index 000000000000..f4d9702ba12f --- /dev/null +++ b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java @@ -0,0 +1,256 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud.dns; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.gcloud.Page; + +import java.io.Serializable; +import java.math.BigInteger; + +/** + * A Google Cloud DNS Zone object. + * + *

A zone is the container for all of your DNS records that share the same DNS name prefix, for + * example, example.com. Zones are automatically assigned a set of name servers when they are + * created to handle responding to DNS queries for that zone. A zone has quotas for the number of + * resource records that it can include. + * + * @see Google Cloud DNS managed zone + * documentation + */ +public class Zone implements Serializable { + + // TODO(mderka) Zone and zoneInfo to be merged. Opened issue #605. + + private static final long serialVersionUID = -4012581571095484813L; + private final ZoneInfo zoneInfo; + private final Dns dns; + + /** + * Constructs a {@code Zone} object that contains the given {@code zoneInfo}. + */ + public Zone(Dns dns, ZoneInfo zoneInfo) { + this.zoneInfo = checkNotNull(zoneInfo); + this.dns = checkNotNull(dns); + } + + /** + * Constructs a {@code Zone} object that contains meta information received from the Google Cloud + * DNS service for the provided zoneName. + * + * @param zoneName Name of the zone to be searched for + * @param options Optional restriction on what fields should be returned by the service + * @return Zone object containing metadata or null if not not found + * @throws DnsException upon failure + */ + public static Zone get(Dns dnsService, String zoneName, + Dns.ZoneOption... options) { + checkNotNull(zoneName); + checkNotNull(dnsService); + ZoneInfo zoneInfo = dnsService.getZone(zoneName, options); + return zoneInfo == null ? null : new Zone(dnsService, zoneInfo); + } + + /** + * Constructs a {@code Zone} object that contains meta information received from the Google Cloud + * DNS service for the provided zoneName. + * + * @param zoneId ID of the zone to be searched for + * @param options Optional restriction on what fields should be returned by the service + * @return Zone object containing metadata or null if not not found + * @throws DnsException upon failure + */ + public static Zone get(Dns dnsService, BigInteger zoneId, + Dns.ZoneOption... options) { + checkNotNull(zoneId); + checkNotNull(dnsService); + ZoneInfo zoneInfo = dnsService.getZone(zoneId, options); + return zoneInfo == null ? null : new Zone(dnsService, zoneInfo); + } + + /** + * Retrieves the latest information about the zone. The method first attempts to retrieve the zone + * by ID and if not set or zone is not found, it searches by name. + * + * @param options Optional restriction on what fields should be fetched + * @return Zone object containing updated metadata or null if not not found + * @throws DnsException upon failure + * @throws NullPointerException if both zone ID and name are not initialized + */ + public Zone reload(Dns.ZoneOption... options) { + checkNameOrIdNotNull(); + Zone zone = null; + if (zoneInfo.id() != null) { + zone = Zone.get(dns, zoneInfo.id(), options); + } + if (zone == null && zoneInfo.name() != null) { + // zone was not found by id or id is not set at all + zone = Zone.get(dns, zoneInfo.name(), options); + } + return zone; + } + + /** + * Deletes the zone. The method first attempts to delete the zone by ID. If the zone is not found + * or id is not set, it attempts to delete by name. + * + * @return true is zone was found and deleted and false otherwise + * @throws DnsException upon failure + * @throws NullPointerException if both zone ID and name are not initialized + */ + public boolean delete() { + checkNameOrIdNotNull(); + boolean deleted = false; + if (zoneInfo.id() != null) { + deleted = dns.delete(zoneInfo.id()); + } + if (!deleted && zoneInfo.name() != null) { + // zone was not found by id or id is not set at all + deleted = dns.delete(zoneInfo.name()); + } + return deleted; + } + + /** + * Lists all {@link DnsRecord}s associated with this zone. First searches for zone by ID and if + * not found then by name. + * + * @param options Optional restriction on listing and on what fields of {@link DnsRecord} should + * be returned by the service + * @return {@code Page}, a page of DNS records, or null if the zone is not found + * @throws DnsException upon failure + * @throws NullPointerException if both zone ID and name are not initialized + */ + public Page listDnsRecords(Dns.DnsRecordListOption... options) { + checkNameOrIdNotNull(); + Page page = null; + if (zoneInfo.id() != null) { + page = dns.listDnsRecords(zoneInfo.id(), options); + } + if (page == null && zoneInfo.name() != null) { + // zone was not found by id or id is not set at all + page = dns.listDnsRecords(zoneInfo.name(), options); + } + return page; + } + + /** + * Submits {@link ChangeRequest} to the service for it to applied to this zone. First searches for + * the zone by ID and if not found then by name. Returns a {@link ChangeRequest} with + * server-assigned ID or null if the zone was not found. + * + * @param options Optional restriction on what fields of {@link ChangeRequest} should be returned + * by the service + * @return ChangeRequest with server-assigned ID or null if the zone was not found. + * @throws DnsException upon failure + * @throws NullPointerException if both zone ID and name are not initialized + */ + public ChangeRequest applyChangeRequest(ChangeRequest changeRequest, + Dns.ChangeRequestOption... options) { + checkNameOrIdNotNull(); + checkNotNull(changeRequest); + ChangeRequest updated = null; + if (zoneInfo.id() != null) { + updated = dns.applyChangeRequest(changeRequest, zoneInfo.id(), options); + } + if (updated == null && zoneInfo.name() != null) { + // zone was not found by id or id is not set at all + updated = dns.applyChangeRequest(changeRequest, zoneInfo.name(), options); + } + return updated; + } + + /** + * Retrieves an updated information about a change request previously submitted to be applied to + * this zone. First searches for the zone by ID and if not found then by name. Returns a {@link + * ChangeRequest} if found and null is the zone or the change request was not found. + * + * @param options Optional restriction on what fields of {@link ChangeRequest} should be returned + * by the service + * @return ChangeRequest with updated information of null if the change request or zone was not + * found. + * @throws DnsException upon failure + * @throws NullPointerException if both zone ID and name are not initialized + * @throws NullPointerException if the change request does not have initialized id + */ + public ChangeRequest getChangeRequest(ChangeRequest changeRequest, + Dns.ChangeRequestOption... options) { + checkNameOrIdNotNull(); + checkNotNull(changeRequest); + checkNotNull(changeRequest.id()); + ChangeRequest updated = null; + if (zoneInfo.id() != null) { + updated = dns.getChangeRequest(changeRequest, zoneInfo.id(), options); + } + if (updated == null && zoneInfo.name() != null) { + // zone was not found by id or id is not set at all + updated = dns.getChangeRequest(changeRequest, zoneInfo.name(), options); + } + return updated; + } + + /** + * Retrieves all change requests for this zone. First searches for the zone by ID and if not found + * then by name. Returns a page of {@link ChangeRequest}s or null if the zone is not found. + * + * @param options Optional restriction on listing and on what fields of {@link ChangeRequest}s + * should be returned by the service + * @return {@code Page}, a page of change requests, or null if the zone is not + * found + * @throws DnsException upon failure + * @throws NullPointerException if both zone ID and name are not initialized + */ + public Page listChangeRequests(Dns.ChangeRequestListOption... options) { + checkNameOrIdNotNull(); + Page changeRequests = null; + if (zoneInfo.id() != null) { + changeRequests = dns.listChangeRequests(zoneInfo.id(), options); + } + if (changeRequests == null && zoneInfo.name() != null) { + // zone was not found by id or id is not set at all + changeRequests = dns.listChangeRequests(zoneInfo.name(), options); + } + return changeRequests; + } + + /** + * Check that at least one of name and ID are initialized and throw and exception if not. + */ + private void checkNameOrIdNotNull() { + if (zoneInfo != null && zoneInfo.id() == null && zoneInfo.name() == null) { + throw new NullPointerException("Both zoneInfo.id and zoneInfo.name are null. " + + "This is an inconsistent state which should never happen."); + } + } + + /** + * Returns the {@link ZoneInfo} object containing meta information about this managed zone. + */ + public ZoneInfo info() { + return this.zoneInfo; + } + + /** + * Returns the {@link Dns} service object associated with this managed zone. + */ + public Dns dns() { + return this.dns; + } + +} diff --git a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/AbstractOptionTest.java b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/AbstractOptionTest.java index e3f2896bd10b..09e35527879b 100644 --- a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/AbstractOptionTest.java +++ b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/AbstractOptionTest.java @@ -16,14 +16,14 @@ package com.google.gcloud.dns; -import com.google.gcloud.spi.DnsRpc; - -import org.junit.Test; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.fail; +import com.google.gcloud.spi.DnsRpc; + +import org.junit.Test; + public class AbstractOptionTest { private static final DnsRpc.Option RPC_OPTION = DnsRpc.Option.DNS_TYPE; diff --git a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/ZoneTest.java b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/ZoneTest.java new file mode 100644 index 000000000000..5f9d119e6150 --- /dev/null +++ b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/ZoneTest.java @@ -0,0 +1,750 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.gcloud.dns; + +import static org.easymock.EasyMock.createStrictMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import com.google.gcloud.Page; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.math.BigInteger; + +public class ZoneTest { + + private static final String ZONE_NAME = "dns-zone-name"; + private static final BigInteger ZONE_ID = new BigInteger("123"); + private static final ZoneInfo ZONE_INFO = ZoneInfo.builder(ZONE_NAME, ZONE_ID) + .dnsName("example.com") + .creationTimeMillis(123478946464L) + .build(); + private static final ZoneInfo NO_ID_INFO = ZoneInfo.builder(ZONE_NAME) + .dnsName("anoter-example.com") + .creationTimeMillis(893123464L) + .build(); + private static final ZoneInfo NO_NAME_INFO = ZoneInfo.builder(ZONE_ID) + .dnsName("one-more-example.com") + .creationTimeMillis(875221546464L) + .build(); + private static final Dns.ZoneOption ZONE_FIELD_OPTIONS = + Dns.ZoneOption.fields(Dns.ZoneField.CREATION_TIME); + private static final Dns.DnsRecordListOption DNS_RECORD_OPTIONS = + Dns.DnsRecordListOption.dnsName("some-dns"); + private static final Dns.ChangeRequestOption CHANGE_REQUEST_FIELD_OPTIONS = + Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.START_TIME); + private static final Dns.ChangeRequestListOption CHANGE_REQUEST_LIST_OPTIONS = + Dns.ChangeRequestListOption.fields(Dns.ChangeRequestField.START_TIME); + private static final ChangeRequest CHANGE_REQUEST = ChangeRequest.builder().id("someid").build(); + private static final ChangeRequest CHANGE_REQUEST_AFTER = CHANGE_REQUEST.toBuilder() + .startTimeMillis(123465L).build(); + private static final ChangeRequest CHANGE_REQUEST_NO_ID = ChangeRequest.builder().build(); + + private Dns dns; + private Zone zone; + private Zone zoneNoName; + private Zone zoneNoId; + + @Before + public void setUp() throws Exception { + dns = createStrictMock(Dns.class); + zone = new Zone(dns, ZONE_INFO); + zoneNoId = new Zone(dns, NO_ID_INFO); + zoneNoName = new Zone(dns, NO_NAME_INFO); + } + + @After + public void tearDown() throws Exception { + verify(dns); + } + + @Test + public void testConstructor() { + replay(dns); + assertNotNull(zone.info()); + assertEquals(ZONE_INFO, zone.info()); + assertNotNull(zone.dns()); + assertEquals(dns, zone.dns()); + } + + @Test + public void testGetById() { + expect(dns.getZone(ZONE_ID)).andReturn(ZONE_INFO); + expect(dns.getZone(ZONE_ID, ZONE_FIELD_OPTIONS)).andReturn(ZONE_INFO); // for options + replay(dns); + Zone retrieved = Zone.get(dns, ZONE_ID); + assertSame(dns, retrieved.dns()); + assertEquals(ZONE_INFO, retrieved.info()); + BigInteger id = null; + try { + Zone.get(dns, id); + fail("Cannot get null zone."); + } catch (NullPointerException e) { + // expected + } + try { + Zone.get(null, id); + fail("Cannot get null zone."); + } catch (NullPointerException e) { + // expected + } + // test passing options + Zone.get(dns, ZONE_ID, ZONE_FIELD_OPTIONS); + } + + @Test + public void testGetByName() { + expect(dns.getZone(ZONE_NAME)).andReturn(ZONE_INFO); + expect(dns.getZone(ZONE_ID, ZONE_FIELD_OPTIONS)).andReturn(ZONE_INFO); // for options + replay(dns); + Zone retrieved = Zone.get(dns, ZONE_NAME); + assertSame(dns, retrieved.dns()); + assertEquals(ZONE_INFO, retrieved.info()); + String name = null; + try { + Zone.get(dns, name); + fail("Cannot get null zone."); + } catch (NullPointerException e) { + // expected + } + try { + Zone.get(null, name); + fail("Cannot get null zone."); + } catch (NullPointerException e) { + // expected + } + // test passing options + Zone.get(dns, ZONE_ID, ZONE_FIELD_OPTIONS); + } + + @Test + public void deleteByIdAndFound() { + expect(dns.delete(ZONE_ID)).andReturn(true); + replay(dns); + boolean result = zone.delete(); + assertTrue(result); + } + + @Test + public void deleteByIdAndNotFoundAndNameSetAndFound() { + expect(dns.delete(ZONE_ID)).andReturn(false); + expect(dns.delete(ZONE_NAME)).andReturn(true); + replay(dns); + boolean result = zone.delete(); + assertTrue(result); + } + + @Test + public void deleteByIdAndNotFoundAndNameSetAndNotFound() { + expect(dns.delete(ZONE_ID)).andReturn(false); + expect(dns.delete(ZONE_NAME)).andReturn(false); + replay(dns); + boolean result = zone.delete(); + assertFalse(result); + } + + @Test + public void deleteByIdAndNotFoundAndNameNotSet() { + expect(dns.delete(ZONE_ID)).andReturn(false); + replay(dns); + boolean result = zoneNoName.delete(); + assertFalse(result); + } + + @Test + public void deleteByNameAndFound() { + expect(dns.delete(ZONE_NAME)).andReturn(true); + replay(dns); + boolean result = zoneNoId.delete(); + assertTrue(result); + } + + @Test + public void deleteByNameAndNotFound() { + expect(dns.delete(ZONE_NAME)).andReturn(true); + replay(dns); + boolean result = zoneNoId.delete(); + assertTrue(result); + } + + @Test + public void listDnsRecordsByIdAndFound() { + Page pageMock = createStrictMock(Page.class); + replay(pageMock); + expect(dns.listDnsRecords(ZONE_ID)).andReturn(pageMock); + // again for options + expect(dns.listDnsRecords(ZONE_ID, DNS_RECORD_OPTIONS)).andReturn(pageMock); + replay(dns); + Page result = zone.listDnsRecords(); + assertSame(pageMock, result); + verify(pageMock); + // verify options + zone.listDnsRecords(DNS_RECORD_OPTIONS); + } + + @Test + public void listDnsRecordsByIdAndNotFoundAndNameSetAndFound() { + Page pageMock = createStrictMock(Page.class); + replay(pageMock); + expect(dns.listDnsRecords(ZONE_ID)).andReturn(null); + expect(dns.listDnsRecords(ZONE_NAME)).andReturn(pageMock); + // again for options + expect(dns.listDnsRecords(ZONE_ID, DNS_RECORD_OPTIONS)).andReturn(null); + expect(dns.listDnsRecords(ZONE_NAME, DNS_RECORD_OPTIONS)).andReturn(pageMock); + replay(dns); + Page result = zone.listDnsRecords(); + assertSame(pageMock, result); + verify(pageMock); + // verify options + zone.listDnsRecords(DNS_RECORD_OPTIONS); + } + + @Test + public void listDnsRecordsByIdAndNotFoundAndNameSetAndNotFound() { + expect(dns.listDnsRecords(ZONE_ID)).andReturn(null); + expect(dns.listDnsRecords(ZONE_NAME)).andReturn(null); + // again for options + expect(dns.listDnsRecords(ZONE_ID, DNS_RECORD_OPTIONS)).andReturn(null); + expect(dns.listDnsRecords(ZONE_NAME, DNS_RECORD_OPTIONS)).andReturn(null); + replay(dns); + Page result = zone.listDnsRecords(); + assertNull(result); + // check options + zone.listDnsRecords(DNS_RECORD_OPTIONS); + } + + @Test + public void listDnsRecordsByIdAndNotFoundAndNameNotSet() { + expect(dns.listDnsRecords(ZONE_ID)).andReturn(null); + expect(dns.listDnsRecords(ZONE_ID, DNS_RECORD_OPTIONS)).andReturn(null); // for options + replay(dns); + Page result = zoneNoName.listDnsRecords(); + assertNull(result); + zoneNoName.listDnsRecords(DNS_RECORD_OPTIONS); // check options + } + + @Test + public void listDnsRecordsByNameAndFound() { + Page pageMock = createStrictMock(Page.class); + replay(pageMock); + expect(dns.listDnsRecords(ZONE_NAME)).andReturn(pageMock); + // again for options + expect(dns.listDnsRecords(ZONE_NAME, DNS_RECORD_OPTIONS)).andReturn(pageMock); + replay(dns); + Page result = zoneNoId.listDnsRecords(); + assertSame(pageMock, result); + verify(pageMock); + zoneNoId.listDnsRecords(DNS_RECORD_OPTIONS); // check options + } + + @Test + public void listDnsRecordsByNameAndNotFound() { + expect(dns.listDnsRecords(ZONE_NAME)).andReturn(null); + // again for options + expect(dns.listDnsRecords(ZONE_NAME, DNS_RECORD_OPTIONS)).andReturn(null); + replay(dns); + Page result = zoneNoId.listDnsRecords(); + assertNull(result); + zoneNoId.listDnsRecords(DNS_RECORD_OPTIONS); // check options + } + + @Test + public void reloadByIdAndFound() { + expect(dns.getZone(ZONE_ID)).andReturn(zone.info()); + expect(dns.getZone(ZONE_ID, ZONE_FIELD_OPTIONS)).andReturn(zone.info()); // for options + replay(dns); + Zone result = zone.reload(); + assertSame(zone.dns(), result.dns()); + assertEquals(zone.info(), result.info()); + zone.reload(ZONE_FIELD_OPTIONS); // for options + } + + @Test + public void reloadByIdAndNotFoundAndNameSetAndFound() { + expect(dns.getZone(ZONE_ID)).andReturn(null); + expect(dns.getZone(ZONE_NAME)).andReturn(zone.info()); + // again for options + expect(dns.getZone(ZONE_ID, ZONE_FIELD_OPTIONS)).andReturn(null); + expect(dns.getZone(ZONE_NAME, ZONE_FIELD_OPTIONS)).andReturn(zone.info()); + replay(dns); + Zone result = zone.reload(); + assertSame(zone.dns(), result.dns()); + assertEquals(zone.info(), result.info()); + zone.reload(ZONE_FIELD_OPTIONS); // for options + } + + @Test + public void reloadByIdAndNotFoundAndNameSetAndNotFound() { + expect(dns.getZone(ZONE_ID)).andReturn(null); + expect(dns.getZone(ZONE_NAME)).andReturn(null); + // again with options + expect(dns.getZone(ZONE_ID, ZONE_FIELD_OPTIONS)).andReturn(null); + expect(dns.getZone(ZONE_NAME, ZONE_FIELD_OPTIONS)).andReturn(null); + replay(dns); + Zone result = zone.reload(); + assertNull(result); + // again for options + zone.reload(ZONE_FIELD_OPTIONS); + } + + @Test + public void reloadByIdAndNotFoundAndNameNotSet() { + expect(dns.getZone(ZONE_ID)).andReturn(null); + expect(dns.getZone(ZONE_ID, ZONE_FIELD_OPTIONS)).andReturn(null); // for options + replay(dns); + Zone result = zoneNoName.reload(); + assertNull(result); + zoneNoName.reload(ZONE_FIELD_OPTIONS); // for options + } + + @Test + public void reloadByNameAndFound() { + expect(dns.getZone(ZONE_NAME)).andReturn(zoneNoId.info()); + // again for options + expect(dns.getZone(ZONE_NAME, ZONE_FIELD_OPTIONS)).andReturn(zoneNoId.info()); + replay(dns); + Zone result = zoneNoId.reload(); + assertSame(zoneNoId.dns(), result.dns()); + assertEquals(zoneNoId.info(), result.info()); + zoneNoId.reload(ZONE_FIELD_OPTIONS); // check options + } + + @Test + public void reloadByNameAndNotFound() { + expect(dns.getZone(ZONE_NAME)).andReturn(null); + // again for options + expect(dns.getZone(ZONE_NAME, ZONE_FIELD_OPTIONS)).andReturn(null); + replay(dns); + Zone result = zoneNoId.reload(); + assertNull(result); + zoneNoId.reload(ZONE_FIELD_OPTIONS); // for options + } + + @Test + public void applyChangeByIdAndFound() { + expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_ID)).andReturn(CHANGE_REQUEST_AFTER); + // again for options + expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + .andReturn(CHANGE_REQUEST_AFTER); + replay(dns); + ChangeRequest result = zone.applyChangeRequest(CHANGE_REQUEST); + assertNotEquals(CHANGE_REQUEST, result); + assertEquals(CHANGE_REQUEST_AFTER, result); + // for options + result = zone.applyChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + assertNotEquals(CHANGE_REQUEST, result); + assertEquals(CHANGE_REQUEST_AFTER, result); + } + + @Test + public void applyChangeByIdAndNotFoundAndNameSetAndFound() { + expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_ID)).andReturn(null); + expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_NAME)) + .andReturn(CHANGE_REQUEST_AFTER); + // again for options + expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + .andReturn(null); + expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + .andReturn(CHANGE_REQUEST_AFTER); + replay(dns); + ChangeRequest result = zone.applyChangeRequest(CHANGE_REQUEST); + assertNotEquals(CHANGE_REQUEST, result); + assertEquals(CHANGE_REQUEST_AFTER, result); + // for options + result = zone.applyChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + assertNotEquals(CHANGE_REQUEST, result); + assertEquals(CHANGE_REQUEST_AFTER, result); + } + + @Test + public void applyChangeIdAndNotFoundAndNameSetAndNotFound() { + expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_ID)).andReturn(null); + expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_NAME)).andReturn(null); + // again with options + expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + .andReturn(null); + expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + .andReturn(null); + replay(dns); + ChangeRequest result = zone.applyChangeRequest(CHANGE_REQUEST); + assertNull(result); + // again for options + result = zone.applyChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + assertNull(result); + } + + @Test + public void applyChangeRequestByIdAndNotFoundAndNameNotSet() { + expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_ID)).andReturn(null); + expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + .andReturn(null); // for options + replay(dns); + ChangeRequest result = zoneNoName.applyChangeRequest(CHANGE_REQUEST); + assertNull(result); + // again for options + result = zoneNoName.applyChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + assertNull(result); + } + + @Test + public void applyChangeByNameAndFound() { + // ID is not set + expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_NAME)) + .andReturn(CHANGE_REQUEST_AFTER); + // again for options + expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + .andReturn(CHANGE_REQUEST_AFTER); + replay(dns); + ChangeRequest result = zoneNoId.applyChangeRequest(CHANGE_REQUEST); + assertEquals(CHANGE_REQUEST_AFTER, result); + // check options + result = zoneNoId.applyChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + assertEquals(CHANGE_REQUEST_AFTER, result); + } + + @Test + public void applyChangeByNameAndNotFound() { + // ID is not set + expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_NAME)).andReturn(null); + // again for options + expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + .andReturn(null); + replay(dns); + ChangeRequest result = zoneNoId.applyChangeRequest(CHANGE_REQUEST); + assertNull(result); + // check options + result = zoneNoId.applyChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + assertNull(result); + } + + @Test + public void applyNullChangeRequest() { + replay(dns); // no calls expected + try { + zone.applyChangeRequest(null); + fail("Cannot apply null ChangeRequest."); + } catch (NullPointerException e) { + // expected + } + try { + zone.applyChangeRequest(null, CHANGE_REQUEST_FIELD_OPTIONS); + fail("Cannot apply null ChangeRequest."); + } catch (NullPointerException e) { + // expected + } + try { + zoneNoId.applyChangeRequest(null); + fail("Cannot apply null ChangeRequest."); + } catch (NullPointerException e) { + // expected + } + try { + zoneNoId.applyChangeRequest(null, CHANGE_REQUEST_FIELD_OPTIONS); + fail("Cannot apply null ChangeRequest."); + } catch (NullPointerException e) { + // expected + } + try { + zoneNoName.applyChangeRequest(null); + fail("Cannot apply null ChangeRequest."); + } catch (NullPointerException e) { + // expected + } + try { + zoneNoName.applyChangeRequest(null, CHANGE_REQUEST_FIELD_OPTIONS); + fail("Cannot apply null ChangeRequest."); + } catch (NullPointerException e) { + // expected + } + } + + @Test + public void getChangeByIdAndFound() { + expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_ID)).andReturn(CHANGE_REQUEST_AFTER); + // again for options + expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + .andReturn(CHANGE_REQUEST_AFTER); + replay(dns); + ChangeRequest result = zone.getChangeRequest(CHANGE_REQUEST); + assertNotEquals(CHANGE_REQUEST, result); + assertEquals(CHANGE_REQUEST_AFTER, result); + // for options + result = zone.getChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + assertNotEquals(CHANGE_REQUEST, result); + assertEquals(CHANGE_REQUEST_AFTER, result); + // test no id + } + + @Test + public void getChangeByIdAndNotFoundAndNameSetAndFound() { + expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_ID)).andReturn(null); + expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_NAME)) + .andReturn(CHANGE_REQUEST_AFTER); + // again for options + expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + .andReturn(null); + expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + .andReturn(CHANGE_REQUEST_AFTER); + replay(dns); + ChangeRequest result = zone.getChangeRequest(CHANGE_REQUEST); + assertNotEquals(CHANGE_REQUEST, result); + assertEquals(CHANGE_REQUEST_AFTER, result); + // for options + result = zone.getChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + assertNotEquals(CHANGE_REQUEST, result); + assertEquals(CHANGE_REQUEST_AFTER, result); + } + + @Test + public void getChangeIdAndNotFoundAndNameSetAndNotFound() { + expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_ID)).andReturn(null); + expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_NAME)).andReturn(null); + // again with options + expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + .andReturn(null); + expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + .andReturn(null); + replay(dns); + ChangeRequest result = zone.getChangeRequest(CHANGE_REQUEST); + assertNull(result); + // again for options + result = zone.getChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + assertNull(result); + } + + @Test + public void getChangeRequestByIdAndNotFoundAndNameNotSet() { + expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_ID)).andReturn(null); + expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + .andReturn(null); // for options + replay(dns); + ChangeRequest result = zoneNoName.getChangeRequest(CHANGE_REQUEST); + assertNull(result); + // again for options + result = zoneNoName.getChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + assertNull(result); + } + + @Test + public void getChangeByNameAndFound() { + // ID is not set + expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_NAME)) + .andReturn(CHANGE_REQUEST_AFTER); + // again for options + expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + .andReturn(CHANGE_REQUEST_AFTER); + replay(dns); + ChangeRequest result = zoneNoId.getChangeRequest(CHANGE_REQUEST); + assertEquals(CHANGE_REQUEST_AFTER, result); + // check options + result = zoneNoId.getChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + assertEquals(CHANGE_REQUEST_AFTER, result); + } + + @Test + public void getChangeByNameAndNotFound() { + // ID is not set + expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_NAME)).andReturn(null); + // again for options + expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + .andReturn(null); + replay(dns); + ChangeRequest result = zoneNoId.getChangeRequest(CHANGE_REQUEST); + assertNull(result); + // check options + result = zoneNoId.getChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + assertNull(result); + } + + @Test + public void getNullChangeRequest() { + replay(dns); // no calls expected + try { + zone.getChangeRequest(null); + fail("Cannot get null ChangeRequest."); + } catch (NullPointerException e) { + // expected + } + try { + zone.getChangeRequest(null, CHANGE_REQUEST_FIELD_OPTIONS); + fail("Cannot get null ChangeRequest."); + } catch (NullPointerException e) { + // expected + } + try { + zoneNoId.getChangeRequest(null); + fail("Cannot get null ChangeRequest."); + } catch (NullPointerException e) { + // expected + } + try { + zoneNoId.getChangeRequest(null, CHANGE_REQUEST_FIELD_OPTIONS); + fail("Cannot get null ChangeRequest."); + } catch (NullPointerException e) { + // expected + } + try { + zoneNoName.getChangeRequest(null); + fail("Cannot get null ChangeRequest."); + } catch (NullPointerException e) { + // expected + } + try { + zoneNoName.getChangeRequest(null, CHANGE_REQUEST_FIELD_OPTIONS); + fail("Cannot get null ChangeRequest."); + } catch (NullPointerException e) { + // expected + } + } + + @Test + public void getChangeRequestWithNoId() { + replay(dns); // no calls expected + try { + zone.getChangeRequest(CHANGE_REQUEST_NO_ID); + fail("Cannot get ChangeRequest with no id."); + } catch (NullPointerException e) { + // expected + } + try { + zone.getChangeRequest(CHANGE_REQUEST_NO_ID, CHANGE_REQUEST_FIELD_OPTIONS); + fail("Cannot get ChangeRequest with no id."); + } catch (NullPointerException e) { + // expected + } + try { + zoneNoId.getChangeRequest(CHANGE_REQUEST_NO_ID); + fail("Cannot get ChangeRequest with no id."); + } catch (NullPointerException e) { + // expected + } + try { + zoneNoId.getChangeRequest(CHANGE_REQUEST_NO_ID, CHANGE_REQUEST_FIELD_OPTIONS); + fail("Cannot get ChangeRequest with no id."); + } catch (NullPointerException e) { + // expected + } + try { + zoneNoName.getChangeRequest(CHANGE_REQUEST_NO_ID); + fail("Cannot get ChangeRequest with no id."); + } catch (NullPointerException e) { + // expected + } + try { + zoneNoName.getChangeRequest(CHANGE_REQUEST_NO_ID, CHANGE_REQUEST_FIELD_OPTIONS); + fail("Cannot get ChangeRequest with no id."); + } catch (NullPointerException e) { + // expected + } + } + + @Test + public void listChangeRequestsByIdAndFound() { + Page pageMock = createStrictMock(Page.class); + replay(pageMock); + expect(dns.listChangeRequests(ZONE_ID)).andReturn(pageMock); + // again for options + expect(dns.listChangeRequests(ZONE_ID, CHANGE_REQUEST_LIST_OPTIONS)).andReturn(pageMock); + replay(dns); + Page result = zone.listChangeRequests(); + assertSame(pageMock, result); + verify(pageMock); + // verify options + zone.listChangeRequests(CHANGE_REQUEST_LIST_OPTIONS); + } + + @Test + public void listChangeRequestsByIdAndNotFoundAndNameSetAndFound() { + Page pageMock = createStrictMock(Page.class); + replay(pageMock); + expect(dns.listChangeRequests(ZONE_ID)).andReturn(null); + expect(dns.listChangeRequests(ZONE_NAME)).andReturn(pageMock); + // again for options + expect(dns.listChangeRequests(ZONE_ID, CHANGE_REQUEST_LIST_OPTIONS)).andReturn(null); + expect(dns.listChangeRequests(ZONE_NAME, CHANGE_REQUEST_LIST_OPTIONS)) + .andReturn(pageMock); + replay(dns); + Page result = zone.listChangeRequests(); + assertSame(pageMock, result); + verify(pageMock); + // verify options + zone.listChangeRequests(CHANGE_REQUEST_LIST_OPTIONS); + } + + @Test + public void listChangeRequestsByIdAndNotFoundAndNameSetAndNotFound() { + expect(dns.listChangeRequests(ZONE_ID)).andReturn(null); + expect(dns.listChangeRequests(ZONE_NAME)).andReturn(null); + // again for options + expect(dns.listChangeRequests(ZONE_ID, CHANGE_REQUEST_LIST_OPTIONS)).andReturn(null); + expect(dns.listChangeRequests(ZONE_NAME, CHANGE_REQUEST_LIST_OPTIONS)).andReturn(null); + replay(dns); + Page result = zone.listChangeRequests(); + assertNull(result); + // check options + zone.listChangeRequests(CHANGE_REQUEST_LIST_OPTIONS); + } + + @Test + public void listChangeRequestsByIdAndNotFoundAndNameNotSet() { + expect(dns.listChangeRequests(ZONE_ID)).andReturn(null); + // again for options + expect(dns.listChangeRequests(ZONE_ID, CHANGE_REQUEST_LIST_OPTIONS)).andReturn(null); + replay(dns); + Page result = zoneNoName.listChangeRequests(); + assertNull(result); + zoneNoName.listChangeRequests(CHANGE_REQUEST_LIST_OPTIONS); // check options + } + + @Test + public void listChangeRequestsByNameAndFound() { + Page pageMock = createStrictMock(Page.class); + replay(pageMock); + expect(dns.listChangeRequests(ZONE_NAME)).andReturn(pageMock); + // again for options + expect(dns.listChangeRequests(ZONE_NAME, CHANGE_REQUEST_LIST_OPTIONS)) + .andReturn(pageMock); + replay(dns); + Page result = zoneNoId.listChangeRequests(); + assertSame(pageMock, result); + verify(pageMock); + zoneNoId.listChangeRequests(CHANGE_REQUEST_LIST_OPTIONS); // check options + } + + @Test + public void listChangeRequestsByNameAndNotFound() { + expect(dns.listChangeRequests(ZONE_NAME)).andReturn(null); + // again for options + expect(dns.listChangeRequests(ZONE_NAME, CHANGE_REQUEST_LIST_OPTIONS)).andReturn(null); + replay(dns); + Page result = zoneNoId.listChangeRequests(); + assertNull(result); + zoneNoId.listChangeRequests(CHANGE_REQUEST_LIST_OPTIONS); // check options + } +} From e083dfd87052a3231067cf0b0535e899d279d5c3 Mon Sep 17 00:00:00 2001 From: Martin Derka Date: Tue, 2 Feb 2016 12:39:08 -0800 Subject: [PATCH 2/3] Fixed documentation and some code formatting. Declared exceptions to be thrown when parent objects do not exist. Changed contracts of applyChangeRequest and getChangeRequest methods. Adjusted tests. --- .../main/java/com/google/gcloud/dns/Dns.java | 147 +++++++++--------- .../main/java/com/google/gcloud/dns/Zone.java | 92 +++++------ .../java/com/google/gcloud/dns/DnsTest.java | 2 +- .../java/com/google/gcloud/dns/ZoneTest.java | 112 ++++++------- 4 files changed, 171 insertions(+), 182 deletions(-) diff --git a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java index b48e4b0a90f2..130e8bb99f5e 100644 --- a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java +++ b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java @@ -37,7 +37,7 @@ public interface Dns extends Service { * The fields of a project. * *

These values can be used to specify the fields to include in a partial response when calling - * {@code Dns#getProjectInfo(ProjectGetOption...)}. Project ID is always returned, even if not + * {@link Dns#getProjectInfo(ProjectOption...)}. Project ID is always returned, even if not * specified. */ enum ProjectField { @@ -69,7 +69,7 @@ static String selector(ProjectField... fields) { * The fields of a zone. * *

These values can be used to specify the fields to include in a partial response when calling - * {@code Dns#getZone(BigInteger, ZoneOption...)} or {@code Dns#getZone(String, ZoneOption...)}. + * {@link Dns#getZone(BigInteger, ZoneOption...)} or {@link Dns#getZone(String, ZoneOption...)}. * The ID is always returned, even if not specified. */ enum ZoneField { @@ -105,7 +105,7 @@ static String selector(ZoneField... fields) { * The fields of a DNS record. * *

These values can be used to specify the fields to include in a partial response when calling - * {@code Dns#listDnsRecords(BigInteger, DnsRecordListOption...)} or {@code + * {@link Dns#listDnsRecords(BigInteger, DnsRecordListOption...)} or {@link * Dns#listDnsRecords(String, DnsRecordListOption...)}. The name is always returned even if not * selected. */ @@ -139,8 +139,8 @@ static String selector(DnsRecordField... fields) { * The fields of a change request. * *

These values can be used to specify the fields to include in a partial response when calling - * {@code Dns#applyChangeRequest(ChangeRequest, BigInteger, ChangeRequestOption...)} or {@code - * Dns#applyChangeRequest(ChangeRequest, String, ChangeRequestOption...)} The ID is always + * {@link Dns#applyChangeRequest(BigInteger, ChangeRequest, ChangeRequestOption...)} or {@link + * Dns#applyChangeRequest(String, ChangeRequest, ChangeRequestOption...)} The ID is always * returned even if not selected. */ enum ChangeRequestField { @@ -313,11 +313,11 @@ public static ZoneListOption pageSize(int pageSize) { /** * Class for specifying project options. */ - class ProjectGetOption extends AbstractOption implements Serializable { + class ProjectOption extends AbstractOption implements Serializable { private static final long serialVersionUID = 6817937338218847748L; - ProjectGetOption(DnsRpc.Option option, Object value) { + ProjectOption(DnsRpc.Option option, Object value) { super(option, value); } @@ -325,12 +325,12 @@ class ProjectGetOption extends AbstractOption implements Serializable { * Returns an option to specify the project's fields to be returned by the RPC call. * *

If this option is not provided all project fields are returned. {@code - * ProjectGetOption.fields} can be used to specify only the fields of interest. Project ID is + * ProjectOption.fields} can be used to specify only the fields of interest. Project ID is * always returned, even if not specified. {@link ProjectField} provides a list of fields that * can be used. */ - public static ProjectGetOption fields(ProjectField... fields) { - return new ProjectGetOption(DnsRpc.Option.FIELDS, ProjectField.selector(fields)); + public static ProjectOption fields(ProjectField... fields) { + return new ProjectOption(DnsRpc.Option.FIELDS, ProjectField.selector(fields)); } } @@ -423,10 +423,11 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) { /** * Creates a new zone. * - * @return ZoneInfo object representing the new zone's metadata. In addition to the name, dns name - * and description (supplied by the user within the {@code zoneInfo} parameter, the returned - * object will include the following read-only fields supplied by the server: creation time, id, - * and list of name servers. + *

Returns {@link ZoneInfo} object representing the new zone's information. In addition to the + * name, dns name and description (supplied by the user within the {@code zoneInfo} parameter), + * the returned object will include the following read-only fields supplied by the server: + * creation time, id, and list of name servers. + * * @throws DnsException upon failure * @see Cloud DNS Managed Zones: * create @@ -434,8 +435,8 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) { ZoneInfo create(ZoneInfo zoneInfo); /** - * Retrieves the zone by the specified zone name. Returns {@code null} is the zone is not found. - * The returned fields can be optionally restricted by specifying {@code ZoneFieldOptions}. + * Returns the zone by the specified zone name. Returns {@code null} if the zone is not found. The + * returned fields can be optionally restricted by specifying {@link ZoneOption}s. * * @throws DnsException upon failure * @see Cloud DNS Managed Zones: @@ -444,8 +445,8 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) { ZoneInfo getZone(String zoneName, ZoneOption... options); /** - * Retrieves the zone by the specified zone name. Returns {@code null} is the zone is not found. - * The returned fields can be optionally restricted by specifying {@code ZoneFieldOptions}. + * Returns the zone by the specified zone id. Returns {@code null} if the zone is not found. The + * returned fields can be optionally restricted by specifying {@link ZoneOption}s. * * @throws DnsException upon failure * @see Cloud DNS Managed Zones: @@ -454,13 +455,13 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) { ZoneInfo getZone(BigInteger zoneId, ZoneOption... options); /** - * Lists the zoned inside the project. + * Lists the zones inside the project. * - *

This method returns zone in an unspecified order. New zones do not necessarily appear at the - * end of the list. Use {@link ZoneListOption} to restrict the listing to a domain name, set page - * size, and set page tokens. + *

This method returns zones in an unspecified order. New zones do not necessarily appear at + * the end of the list. Use {@link ZoneListOption} to restrict the listing to a domain name, set + * page size, and set page token. * - * @return {@code Page}, a page of zones + * @return a page of zones * @throws DnsException upon failure * @see Cloud DNS Managed Zones: * list @@ -468,10 +469,10 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) { Page listZones(ZoneListOption... options); /** - * Deletes an existing zone identified by name. Returns true if the zone was successfully deleted - * and false otherwise. + * Deletes an existing zone identified by name. Returns {@code true} if the zone was successfully + * deleted and {@code false} otherwise. * - * @return {@code true} if zone was found and deleted and false otherwise + * @return {@code true} if zone was found and deleted and {@code false} otherwise * @throws DnsException upon failure * @see Cloud DNS Managed Zones: * delete @@ -479,10 +480,10 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) { boolean delete(String zoneName); // delete does not admit any options /** - * Deletes an existing zone identified by id. Returns true if the zone was successfully deleted - * and false otherwise. + * Deletes an existing zone identified by id. Returns {@code true} if the zone was successfully + * deleted and {@code false} otherwise. * - * @return {@code true} if zone was found and deleted and false otherwise + * @return {@code true} if zone was found and deleted and {@code false} otherwise * @throws DnsException upon failure * @see Cloud DNS Managed Zones: * delete @@ -492,10 +493,10 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) { /** * Lists the DNS records in the zone identified by name. * - *

The fields to be returned, page size and page tokens can be specified using {@code - * DnsRecordOptions}. Returns null if the zone cannot be found. + *

The fields to be returned, page size and page tokens can be specified using {@link + * DnsRecordListOption}s. * - * @throws DnsException upon failure + * @throws DnsException upon failure or if the zone cannot be found * @see Cloud DNS * ResourceRecordSets: list */ @@ -504,23 +505,23 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) { /** * Lists the DNS records in the zone identified by ID. * - *

The fields to be returned, page size and page tokens can be specified using {@code - * DnsRecordOptions}. Returns null if the zone cannot be found. + *

The fields to be returned, page size and page tokens can be specified using {@link + * DnsRecordListOption}s. * - * @throws DnsException upon failure + * @throws DnsException upon failure or if the zone cannot be found * @see Cloud DNS * ResourceRecordSets: list */ Page listDnsRecords(BigInteger zoneId, DnsRecordListOption... options); /** - * Retrieves the metadata about the current project. The returned fields can be optionally - * restricted by specifying {@code ProjectOptions}. + * Retrieves the information about the current project. The returned fields can be optionally + * restricted by specifying {@link ProjectOption}s. * * @throws DnsException upon failure * @see Cloud DNS Projects: get */ - ProjectInfo getProjectInfo(ProjectGetOption... fields); + ProjectInfo getProjectInfo(ProjectOption... fields); /** * Returns the current project id. @@ -533,64 +534,61 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) { BigInteger getProjectNumber(); /** - * Submits a change requests for applying to the zone identified by ID to the service. The - * returned object contains the following read-only fields supplied by the server: id, start time - * and status. time, id, and list of name servers. The returned fields can be modified by {@code - * ChangeRequestFieldOptions}. Returns null if the zone is not found. + * Submits a change request for the specified zone. The returned object contains the following + * read-only fields supplied by the server: id, start time and status. time, id, and list of name + * servers. The fields to be returned can be selected by {@link ChangeRequestOption}s. * - * @return ChangeRequest object representing the new change request or null if zone is not found + * @return the new {@link ChangeRequest} or {@code null} if zone is not found * @throws DnsException upon failure * @see Cloud DNS Changes: create */ - ChangeRequest applyChangeRequest(ChangeRequest changeRequest, BigInteger zoneId, - ChangeRequestOption... options); + ChangeRequest applyChangeRequest(BigInteger zoneId, ChangeRequest changeRequest, + ChangeRequestOption... options); /** - * Submits a change requests for applying to the zone identified by name to the service. The - * returned object contains the following read-only fields supplied by the server: id, start time - * and status. time, id, and list of name servers. The returned fields can be modified by {@code - * ChangeRequestFieldOptions}. Returns null if the zone is not found. + * Submits a change request for the specified zone. The returned object contains the following + * read-only fields supplied by the server: id, start time and status. time, id, and list of name + * servers. The fields to be returned can be selected by {@link ChangeRequestOption}s. * - * @return ChangeRequest object representing the new change request or null if zone is not found - * @throws DnsException upon failure + * @return the new {@link ChangeRequest} + * @throws DnsException upon failure if zone is not found * @see Cloud DNS Changes: create */ - ChangeRequest applyChangeRequest(ChangeRequest changeRequest, String zoneName, - ChangeRequestOption... options); + ChangeRequest applyChangeRequest(String zoneName, ChangeRequest changeRequest, + ChangeRequestOption... options); /** * Retrieves updated information about a change request previously submitted for a zone identified - * by ID. Returns null if the zone or request cannot be found. - * - *

The fields to be returned using {@code ChangeRequestFieldOptions}. + * by ID. Returns {@code null} if the request cannot be found and throws an exception if the zone + * does not exist. The fields to be returned using can be specified using {@link + * ChangeRequestOption}s. * - * @throws DnsException upon failure + * @throws DnsException upon failure or if the zone cannot be found * @see Cloud DNS Chages: get */ - ChangeRequest getChangeRequest(ChangeRequest changeRequest, BigInteger zoneId, - ChangeRequestOption... options); + ChangeRequest getChangeRequest(String changeRequestId, BigInteger zoneId, + ChangeRequestOption... options); /** * Retrieves updated information about a change request previously submitted for a zone identified - * by name. Returns null if the zone or request cannot be found. - * - *

The fields to be returned using {@code ChangeRequestFieldOptions}. + * by ID. Returns {@code null} if the request cannot be found and throws an exception if the zone + * does not exist. The fields to be returned using can be specified using {@link + * ChangeRequestOption}s. * - * @throws DnsException upon failure + * @throws DnsException upon failure or if the zone cannot be found * @see Cloud DNS Chages: get */ - ChangeRequest getChangeRequest(ChangeRequest changeRequest, String zoneName, - ChangeRequestOption... options); + ChangeRequest getChangeRequest(String changeRequestId, String zoneName, + ChangeRequestOption... options); /** * Lists the change requests for the zone identified by ID that were submitted to the service. * - *

The sorting key for changes, fields to be returned, page and page tokens can be specified - * using {@code ChangeRequestListOptions}. Note that the only sorting key currently supported is - * the timestamp of submitting the change request to the service. + *

The sorting order for changes (based on when they were received by the server), fields to be + * returned, page size and page token can be specified using {@link ChangeRequestListOption}s. * - * @return {@code Page}, a page of change requests - * @throws DnsException upon failure + * @return A page of change requests + * @throws DnsException upon failure or if the zone cannot be found * @see Cloud DNS Chages: list */ Page listChangeRequests(BigInteger zoneId, ChangeRequestListOption... options); @@ -598,12 +596,11 @@ ChangeRequest getChangeRequest(ChangeRequest changeRequest, String zoneName, /** * Lists the change requests for the zone identified by name that were submitted to the service. * - *

The sorting key for changes, fields to be returned, page and page tokens can be specified - * using {@code ChangeRequestListOptions}. Note that the only sorting key currently supported is - * the timestamp of submitting the change request to the service. + *

The sorting order for changes (based on when they were received by the server), fields to be + * returned, page size and page token can be specified using {@link ChangeRequestListOption}s. * - * @return {@code Page}, a page of change requests - * @throws DnsException upon failure + * @return A page of change requests + * @throws DnsException upon failure or if the zone cannot be found * @see Cloud DNS Chages: list */ Page listChangeRequests(String zoneName, ChangeRequestListOption... options); diff --git a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java index f4d9702ba12f..dc0be8b94b44 100644 --- a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java +++ b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java @@ -16,6 +16,7 @@ package com.google.gcloud.dns; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import com.google.gcloud.Page; @@ -52,15 +53,14 @@ public Zone(Dns dns, ZoneInfo zoneInfo) { /** * Constructs a {@code Zone} object that contains meta information received from the Google Cloud - * DNS service for the provided zoneName. + * DNS service for the provided {@code zoneName}. * - * @param zoneName Name of the zone to be searched for - * @param options Optional restriction on what fields should be returned by the service - * @return Zone object containing metadata or null if not not found + * @param zoneName name of the zone to be searched for + * @param options optional restriction on what fields should be returned by the service + * @return zone object containing metadata or {@code null} if not not found * @throws DnsException upon failure */ - public static Zone get(Dns dnsService, String zoneName, - Dns.ZoneOption... options) { + public static Zone get(Dns dnsService, String zoneName, Dns.ZoneOption... options) { checkNotNull(zoneName); checkNotNull(dnsService); ZoneInfo zoneInfo = dnsService.getZone(zoneName, options); @@ -68,16 +68,15 @@ public static Zone get(Dns dnsService, String zoneName, } /** - * Constructs a {@code Zone} object that contains meta information received from the Google Cloud - * DNS service for the provided zoneName. + * Constructs a {@code Zone} object that contains information received from the Google Cloud DNS + * service for the provided {@code zoneId}. * * @param zoneId ID of the zone to be searched for - * @param options Optional restriction on what fields should be returned by the service - * @return Zone object containing metadata or null if not not found + * @param options optional restriction on what fields should be returned by the service + * @return zone object containing zone's information or {@code null} if not not found * @throws DnsException upon failure */ - public static Zone get(Dns dnsService, BigInteger zoneId, - Dns.ZoneOption... options) { + public static Zone get(Dns dnsService, BigInteger zoneId, Dns.ZoneOption... options) { checkNotNull(zoneId); checkNotNull(dnsService); ZoneInfo zoneInfo = dnsService.getZone(zoneId, options); @@ -88,8 +87,8 @@ public static Zone get(Dns dnsService, BigInteger zoneId, * Retrieves the latest information about the zone. The method first attempts to retrieve the zone * by ID and if not set or zone is not found, it searches by name. * - * @param options Optional restriction on what fields should be fetched - * @return Zone object containing updated metadata or null if not not found + * @param options optional restriction on what fields should be fetched + * @return zone object containing updated information or {@code null} if not not found * @throws DnsException upon failure * @throws NullPointerException if both zone ID and name are not initialized */ @@ -110,7 +109,7 @@ public Zone reload(Dns.ZoneOption... options) { * Deletes the zone. The method first attempts to delete the zone by ID. If the zone is not found * or id is not set, it attempts to delete by name. * - * @return true is zone was found and deleted and false otherwise + * @return {@code true} is zone was found and deleted and {@code false} otherwise * @throws DnsException upon failure * @throws NullPointerException if both zone ID and name are not initialized */ @@ -131,10 +130,10 @@ public boolean delete() { * Lists all {@link DnsRecord}s associated with this zone. First searches for zone by ID and if * not found then by name. * - * @param options Optional restriction on listing and on what fields of {@link DnsRecord} should + * @param options optional restriction on listing and on what fields of {@link DnsRecord} should * be returned by the service - * @return {@code Page}, a page of DNS records, or null if the zone is not found - * @throws DnsException upon failure + * @return a page of DNS records + * @throws DnsException upon failure or if the zone is not found * @throws NullPointerException if both zone ID and name are not initialized */ public Page listDnsRecords(Dns.DnsRecordListOption... options) { @@ -153,25 +152,24 @@ public Page listDnsRecords(Dns.DnsRecordListOption... options) { /** * Submits {@link ChangeRequest} to the service for it to applied to this zone. First searches for * the zone by ID and if not found then by name. Returns a {@link ChangeRequest} with - * server-assigned ID or null if the zone was not found. + * server-assigned ID or {@code null} if the zone was not found. * - * @param options Optional restriction on what fields of {@link ChangeRequest} should be returned - * by the service - * @return ChangeRequest with server-assigned ID or null if the zone was not found. - * @throws DnsException upon failure + * @param options optional restriction on what fields of {@link ChangeRequest} should be returned + * @return ChangeRequest with server-assigned ID + * @throws DnsException upon failure or if the zone is not found * @throws NullPointerException if both zone ID and name are not initialized */ public ChangeRequest applyChangeRequest(ChangeRequest changeRequest, - Dns.ChangeRequestOption... options) { + Dns.ChangeRequestOption... options) { checkNameOrIdNotNull(); checkNotNull(changeRequest); ChangeRequest updated = null; if (zoneInfo.id() != null) { - updated = dns.applyChangeRequest(changeRequest, zoneInfo.id(), options); + updated = dns.applyChangeRequest(zoneInfo.id(), changeRequest, options); } if (updated == null && zoneInfo.name() != null) { // zone was not found by id or id is not set at all - updated = dns.applyChangeRequest(changeRequest, zoneInfo.name(), options); + updated = dns.applyChangeRequest(zoneInfo.name(), changeRequest, options); } return updated; } @@ -179,41 +177,38 @@ public ChangeRequest applyChangeRequest(ChangeRequest changeRequest, /** * Retrieves an updated information about a change request previously submitted to be applied to * this zone. First searches for the zone by ID and if not found then by name. Returns a {@link - * ChangeRequest} if found and null is the zone or the change request was not found. + * ChangeRequest} if found and {@code null} is the zone or the change request was not found. * - * @param options Optional restriction on what fields of {@link ChangeRequest} should be returned - * by the service - * @return ChangeRequest with updated information of null if the change request or zone was not - * found. - * @throws DnsException upon failure + * @param options optional restriction on what fields of {@link ChangeRequest} should be returned + * @return updated ChangeRequest + * @throws DnsException upon failure or if the zone is not found * @throws NullPointerException if both zone ID and name are not initialized * @throws NullPointerException if the change request does not have initialized id */ - public ChangeRequest getChangeRequest(ChangeRequest changeRequest, - Dns.ChangeRequestOption... options) { + public ChangeRequest getChangeRequest(String changeRequestId, + Dns.ChangeRequestOption... options) { checkNameOrIdNotNull(); - checkNotNull(changeRequest); - checkNotNull(changeRequest.id()); + checkNotNull(changeRequestId); ChangeRequest updated = null; if (zoneInfo.id() != null) { - updated = dns.getChangeRequest(changeRequest, zoneInfo.id(), options); + updated = dns.getChangeRequest(changeRequestId, zoneInfo.id(), options); } if (updated == null && zoneInfo.name() != null) { // zone was not found by id or id is not set at all - updated = dns.getChangeRequest(changeRequest, zoneInfo.name(), options); + updated = dns.getChangeRequest(changeRequestId, zoneInfo.name(), options); } return updated; } /** * Retrieves all change requests for this zone. First searches for the zone by ID and if not found - * then by name. Returns a page of {@link ChangeRequest}s or null if the zone is not found. + * then by name. Returns a page of {@link ChangeRequest}s or {@code null} if the zone is not + * found. * - * @param options Optional restriction on listing and on what fields of {@link ChangeRequest}s + * @param options optional restriction on listing and on what fields of {@link ChangeRequest}s * should be returned by the service - * @return {@code Page}, a page of change requests, or null if the zone is not - * found - * @throws DnsException upon failure + * @return a page of change requests + * @throws DnsException upon failure or if the zone is not found * @throws NullPointerException if both zone ID and name are not initialized */ public Page listChangeRequests(Dns.ChangeRequestListOption... options) { @@ -233,24 +228,21 @@ public Page listChangeRequests(Dns.ChangeRequestListOption... opt * Check that at least one of name and ID are initialized and throw and exception if not. */ private void checkNameOrIdNotNull() { - if (zoneInfo != null && zoneInfo.id() == null && zoneInfo.name() == null) { - throw new NullPointerException("Both zoneInfo.id and zoneInfo.name are null. " - + "This is an inconsistent state which should never happen."); - } + checkArgument(zoneInfo != null && (zoneInfo.id() != null || zoneInfo.name() != null), + "Both zoneInfo.id and zoneInfo.name are null. This is should never happen."); } /** - * Returns the {@link ZoneInfo} object containing meta information about this managed zone. + * Returns the {@link ZoneInfo} object containing information about this zone. */ public ZoneInfo info() { return this.zoneInfo; } /** - * Returns the {@link Dns} service object associated with this managed zone. + * Returns the {@link Dns} service object associated with this zone. */ public Dns dns() { return this.dns; } - } diff --git a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/DnsTest.java b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/DnsTest.java index 2e98dbd46de4..a60cae1d1793 100644 --- a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/DnsTest.java +++ b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/DnsTest.java @@ -94,7 +94,7 @@ public void testZoneList() { @Test public void testProjectGetOption() { // fields - Dns.ProjectGetOption fields = Dns.ProjectGetOption.fields(Dns.ProjectField.QUOTA); + Dns.ProjectOption fields = Dns.ProjectOption.fields(Dns.ProjectField.QUOTA); assertEquals(DnsRpc.Option.FIELDS, fields.rpcOption()); assertTrue(fields.value() instanceof String); assertTrue(((String) fields.value()).contains(Dns.ProjectField.QUOTA.selector())); diff --git a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/ZoneTest.java b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/ZoneTest.java index 5f9d119e6150..a87bb969855b 100644 --- a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/ZoneTest.java +++ b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/ZoneTest.java @@ -348,9 +348,9 @@ public void reloadByNameAndNotFound() { @Test public void applyChangeByIdAndFound() { - expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_ID)).andReturn(CHANGE_REQUEST_AFTER); + expect(dns.applyChangeRequest(ZONE_ID, CHANGE_REQUEST)).andReturn(CHANGE_REQUEST_AFTER); // again for options - expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.applyChangeRequest(ZONE_ID, CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(CHANGE_REQUEST_AFTER); replay(dns); ChangeRequest result = zone.applyChangeRequest(CHANGE_REQUEST); @@ -364,13 +364,13 @@ public void applyChangeByIdAndFound() { @Test public void applyChangeByIdAndNotFoundAndNameSetAndFound() { - expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_ID)).andReturn(null); - expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_NAME)) + expect(dns.applyChangeRequest(ZONE_ID, CHANGE_REQUEST)).andReturn(null); + expect(dns.applyChangeRequest(ZONE_NAME, CHANGE_REQUEST)) .andReturn(CHANGE_REQUEST_AFTER); // again for options - expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.applyChangeRequest(ZONE_ID, CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(null); - expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.applyChangeRequest(ZONE_NAME, CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(CHANGE_REQUEST_AFTER); replay(dns); ChangeRequest result = zone.applyChangeRequest(CHANGE_REQUEST); @@ -384,12 +384,12 @@ public void applyChangeByIdAndNotFoundAndNameSetAndFound() { @Test public void applyChangeIdAndNotFoundAndNameSetAndNotFound() { - expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_ID)).andReturn(null); - expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_NAME)).andReturn(null); + expect(dns.applyChangeRequest(ZONE_ID, CHANGE_REQUEST)).andReturn(null); + expect(dns.applyChangeRequest(ZONE_NAME, CHANGE_REQUEST)).andReturn(null); // again with options - expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.applyChangeRequest(ZONE_ID, CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(null); - expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.applyChangeRequest(ZONE_NAME, CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(null); replay(dns); ChangeRequest result = zone.applyChangeRequest(CHANGE_REQUEST); @@ -401,8 +401,8 @@ public void applyChangeIdAndNotFoundAndNameSetAndNotFound() { @Test public void applyChangeRequestByIdAndNotFoundAndNameNotSet() { - expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_ID)).andReturn(null); - expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.applyChangeRequest(ZONE_ID, CHANGE_REQUEST)).andReturn(null); + expect(dns.applyChangeRequest(ZONE_ID, CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(null); // for options replay(dns); ChangeRequest result = zoneNoName.applyChangeRequest(CHANGE_REQUEST); @@ -415,10 +415,10 @@ public void applyChangeRequestByIdAndNotFoundAndNameNotSet() { @Test public void applyChangeByNameAndFound() { // ID is not set - expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_NAME)) + expect(dns.applyChangeRequest(ZONE_NAME, CHANGE_REQUEST)) .andReturn(CHANGE_REQUEST_AFTER); // again for options - expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.applyChangeRequest(ZONE_NAME, CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(CHANGE_REQUEST_AFTER); replay(dns); ChangeRequest result = zoneNoId.applyChangeRequest(CHANGE_REQUEST); @@ -431,9 +431,9 @@ public void applyChangeByNameAndFound() { @Test public void applyChangeByNameAndNotFound() { // ID is not set - expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_NAME)).andReturn(null); + expect(dns.applyChangeRequest(ZONE_NAME, CHANGE_REQUEST)).andReturn(null); // again for options - expect(dns.applyChangeRequest(CHANGE_REQUEST, ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.applyChangeRequest(ZONE_NAME, CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(null); replay(dns); ChangeRequest result = zoneNoId.applyChangeRequest(CHANGE_REQUEST); @@ -486,16 +486,16 @@ public void applyNullChangeRequest() { @Test public void getChangeByIdAndFound() { - expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_ID)).andReturn(CHANGE_REQUEST_AFTER); + expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_ID)).andReturn(CHANGE_REQUEST_AFTER); // again for options - expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(CHANGE_REQUEST_AFTER); replay(dns); - ChangeRequest result = zone.getChangeRequest(CHANGE_REQUEST); + ChangeRequest result = zone.getChangeRequest(CHANGE_REQUEST.id()); assertNotEquals(CHANGE_REQUEST, result); assertEquals(CHANGE_REQUEST_AFTER, result); // for options - result = zone.getChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + result = zone.getChangeRequest(CHANGE_REQUEST.id(), CHANGE_REQUEST_FIELD_OPTIONS); assertNotEquals(CHANGE_REQUEST, result); assertEquals(CHANGE_REQUEST_AFTER, result); // test no id @@ -503,82 +503,82 @@ public void getChangeByIdAndFound() { @Test public void getChangeByIdAndNotFoundAndNameSetAndFound() { - expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_ID)).andReturn(null); - expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_NAME)) + expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_ID)).andReturn(null); + expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_NAME)) .andReturn(CHANGE_REQUEST_AFTER); // again for options - expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(null); - expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(CHANGE_REQUEST_AFTER); replay(dns); - ChangeRequest result = zone.getChangeRequest(CHANGE_REQUEST); + ChangeRequest result = zone.getChangeRequest(CHANGE_REQUEST.id()); assertNotEquals(CHANGE_REQUEST, result); assertEquals(CHANGE_REQUEST_AFTER, result); // for options - result = zone.getChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + result = zone.getChangeRequest(CHANGE_REQUEST.id(), CHANGE_REQUEST_FIELD_OPTIONS); assertNotEquals(CHANGE_REQUEST, result); assertEquals(CHANGE_REQUEST_AFTER, result); } @Test public void getChangeIdAndNotFoundAndNameSetAndNotFound() { - expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_ID)).andReturn(null); - expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_NAME)).andReturn(null); + expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_ID)).andReturn(null); + expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_NAME)).andReturn(null); // again with options - expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(null); - expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(null); replay(dns); - ChangeRequest result = zone.getChangeRequest(CHANGE_REQUEST); + ChangeRequest result = zone.getChangeRequest(CHANGE_REQUEST.id()); assertNull(result); // again for options - result = zone.getChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + result = zone.getChangeRequest(CHANGE_REQUEST.id(), CHANGE_REQUEST_FIELD_OPTIONS); assertNull(result); } @Test public void getChangeRequestByIdAndNotFoundAndNameNotSet() { - expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_ID)).andReturn(null); - expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_ID)).andReturn(null); + expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(null); // for options replay(dns); - ChangeRequest result = zoneNoName.getChangeRequest(CHANGE_REQUEST); + ChangeRequest result = zoneNoName.getChangeRequest(CHANGE_REQUEST.id()); assertNull(result); // again for options - result = zoneNoName.getChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + result = zoneNoName.getChangeRequest(CHANGE_REQUEST.id(), CHANGE_REQUEST_FIELD_OPTIONS); assertNull(result); } @Test public void getChangeByNameAndFound() { // ID is not set - expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_NAME)) + expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_NAME)) .andReturn(CHANGE_REQUEST_AFTER); // again for options - expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(CHANGE_REQUEST_AFTER); replay(dns); - ChangeRequest result = zoneNoId.getChangeRequest(CHANGE_REQUEST); + ChangeRequest result = zoneNoId.getChangeRequest(CHANGE_REQUEST.id()); assertEquals(CHANGE_REQUEST_AFTER, result); // check options - result = zoneNoId.getChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + result = zoneNoId.getChangeRequest(CHANGE_REQUEST.id(), CHANGE_REQUEST_FIELD_OPTIONS); assertEquals(CHANGE_REQUEST_AFTER, result); } @Test public void getChangeByNameAndNotFound() { // ID is not set - expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_NAME)).andReturn(null); + expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_NAME)).andReturn(null); // again for options - expect(dns.getChangeRequest(CHANGE_REQUEST, ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(null); replay(dns); - ChangeRequest result = zoneNoId.getChangeRequest(CHANGE_REQUEST); + ChangeRequest result = zoneNoId.getChangeRequest(CHANGE_REQUEST.id()); assertNull(result); // check options - result = zoneNoId.getChangeRequest(CHANGE_REQUEST, CHANGE_REQUEST_FIELD_OPTIONS); + result = zoneNoId.getChangeRequest(CHANGE_REQUEST.id(), CHANGE_REQUEST_FIELD_OPTIONS); assertNull(result); } @@ -627,38 +627,38 @@ public void getNullChangeRequest() { public void getChangeRequestWithNoId() { replay(dns); // no calls expected try { - zone.getChangeRequest(CHANGE_REQUEST_NO_ID); - fail("Cannot get ChangeRequest with no id."); + zone.getChangeRequest(CHANGE_REQUEST_NO_ID.id()); + fail("Cannot get ChangeRequest by null id."); } catch (NullPointerException e) { // expected } try { - zone.getChangeRequest(CHANGE_REQUEST_NO_ID, CHANGE_REQUEST_FIELD_OPTIONS); - fail("Cannot get ChangeRequest with no id."); + zone.getChangeRequest(CHANGE_REQUEST_NO_ID.id(), CHANGE_REQUEST_FIELD_OPTIONS); + fail("Cannot get ChangeRequest by null id."); } catch (NullPointerException e) { // expected } try { - zoneNoId.getChangeRequest(CHANGE_REQUEST_NO_ID); - fail("Cannot get ChangeRequest with no id."); + zoneNoId.getChangeRequest(CHANGE_REQUEST_NO_ID.id()); + fail("Cannot get ChangeRequest by null id."); } catch (NullPointerException e) { // expected } try { - zoneNoId.getChangeRequest(CHANGE_REQUEST_NO_ID, CHANGE_REQUEST_FIELD_OPTIONS); - fail("Cannot get ChangeRequest with no id."); + zoneNoId.getChangeRequest(CHANGE_REQUEST_NO_ID.id(), CHANGE_REQUEST_FIELD_OPTIONS); + fail("Cannot get ChangeRequest by null id."); } catch (NullPointerException e) { // expected } try { - zoneNoName.getChangeRequest(CHANGE_REQUEST_NO_ID); - fail("Cannot get ChangeRequest with no id."); + zoneNoName.getChangeRequest(CHANGE_REQUEST_NO_ID.id()); + fail("Cannot get ChangeRequest by null id."); } catch (NullPointerException e) { // expected } try { - zoneNoName.getChangeRequest(CHANGE_REQUEST_NO_ID, CHANGE_REQUEST_FIELD_OPTIONS); - fail("Cannot get ChangeRequest with no id."); + zoneNoName.getChangeRequest(CHANGE_REQUEST_NO_ID.id(), CHANGE_REQUEST_FIELD_OPTIONS); + fail("Cannot get ChangeRequest by null id."); } catch (NullPointerException e) { // expected } From d6daf0956ff0975bed3115f9b09a1381bc1cf137 Mon Sep 17 00:00:00 2001 From: Martin Derka Date: Tue, 2 Feb 2016 16:17:31 -0800 Subject: [PATCH 3/3] Adjusted documentation, removed getProjectId and getProjectNumber --- .../main/java/com/google/gcloud/dns/Dns.java | 14 +---- .../main/java/com/google/gcloud/dns/Zone.java | 12 ++-- .../java/com/google/gcloud/dns/ZoneTest.java | 56 ++++++++++--------- 3 files changed, 37 insertions(+), 45 deletions(-) diff --git a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java index 130e8bb99f5e..644814fa201b 100644 --- a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java +++ b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java @@ -523,16 +523,6 @@ public static ChangeRequestListOption sortOrder(SortingOrder order) { */ ProjectInfo getProjectInfo(ProjectOption... fields); - /** - * Returns the current project id. - */ - String getProjectId(); - - /** - * Returns the current project number. - */ - BigInteger getProjectNumber(); - /** * Submits a change request for the specified zone. The returned object contains the following * read-only fields supplied by the server: id, start time and status. time, id, and list of name @@ -566,7 +556,7 @@ ChangeRequest applyChangeRequest(String zoneName, ChangeRequest changeRequest, * @throws DnsException upon failure or if the zone cannot be found * @see Cloud DNS Chages: get */ - ChangeRequest getChangeRequest(String changeRequestId, BigInteger zoneId, + ChangeRequest getChangeRequest(BigInteger zoneId, String changeRequestId, ChangeRequestOption... options); /** @@ -578,7 +568,7 @@ ChangeRequest getChangeRequest(String changeRequestId, BigInteger zoneId, * @throws DnsException upon failure or if the zone cannot be found * @see Cloud DNS Chages: get */ - ChangeRequest getChangeRequest(String changeRequestId, String zoneName, + ChangeRequest getChangeRequest(String zoneName, String changeRequestId, ChangeRequestOption... options); /** diff --git a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java index dc0be8b94b44..86fc86bc3688 100644 --- a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java +++ b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java @@ -130,8 +130,7 @@ public boolean delete() { * Lists all {@link DnsRecord}s associated with this zone. First searches for zone by ID and if * not found then by name. * - * @param options optional restriction on listing and on what fields of {@link DnsRecord} should - * be returned by the service + * @param options optional restriction on listing and fields of {@link DnsRecord}s returned * @return a page of DNS records * @throws DnsException upon failure or if the zone is not found * @throws NullPointerException if both zone ID and name are not initialized @@ -191,11 +190,11 @@ public ChangeRequest getChangeRequest(String changeRequestId, checkNotNull(changeRequestId); ChangeRequest updated = null; if (zoneInfo.id() != null) { - updated = dns.getChangeRequest(changeRequestId, zoneInfo.id(), options); + updated = dns.getChangeRequest(zoneInfo.id(), changeRequestId, options); } if (updated == null && zoneInfo.name() != null) { // zone was not found by id or id is not set at all - updated = dns.getChangeRequest(changeRequestId, zoneInfo.name(), options); + updated = dns.getChangeRequest(zoneInfo.name(), changeRequestId, options); } return updated; } @@ -205,8 +204,7 @@ public ChangeRequest getChangeRequest(String changeRequestId, * then by name. Returns a page of {@link ChangeRequest}s or {@code null} if the zone is not * found. * - * @param options optional restriction on listing and on what fields of {@link ChangeRequest}s - * should be returned by the service + * @param options optional restriction on listing and fields to be returned * @return a page of change requests * @throws DnsException upon failure or if the zone is not found * @throws NullPointerException if both zone ID and name are not initialized @@ -236,7 +234,7 @@ private void checkNameOrIdNotNull() { * Returns the {@link ZoneInfo} object containing information about this zone. */ public ZoneInfo info() { - return this.zoneInfo; + return zoneInfo; } /** diff --git a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/ZoneTest.java b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/ZoneTest.java index a87bb969855b..c746140ce599 100644 --- a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/ZoneTest.java +++ b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/ZoneTest.java @@ -101,16 +101,15 @@ public void testGetById() { Zone retrieved = Zone.get(dns, ZONE_ID); assertSame(dns, retrieved.dns()); assertEquals(ZONE_INFO, retrieved.info()); - BigInteger id = null; try { - Zone.get(dns, id); - fail("Cannot get null zone."); + Zone.get(dns, (BigInteger) null); + fail("Cannot get by null id."); } catch (NullPointerException e) { // expected } try { - Zone.get(null, id); - fail("Cannot get null zone."); + Zone.get(null, new BigInteger("12")); + fail("Cannot get anything from null service."); } catch (NullPointerException e) { // expected } @@ -126,16 +125,15 @@ public void testGetByName() { Zone retrieved = Zone.get(dns, ZONE_NAME); assertSame(dns, retrieved.dns()); assertEquals(ZONE_INFO, retrieved.info()); - String name = null; try { - Zone.get(dns, name); - fail("Cannot get null zone."); + Zone.get(dns, (String) null); + fail("Cannot get by null name."); } catch (NullPointerException e) { // expected } try { - Zone.get(null, name); - fail("Cannot get null zone."); + Zone.get(null, "Not null"); + fail("Cannot get anything from null service."); } catch (NullPointerException e) { // expected } @@ -195,6 +193,7 @@ public void deleteByNameAndNotFound() { @Test public void listDnsRecordsByIdAndFound() { + @SuppressWarnings("unchecked") Page pageMock = createStrictMock(Page.class); replay(pageMock); expect(dns.listDnsRecords(ZONE_ID)).andReturn(pageMock); @@ -210,6 +209,7 @@ public void listDnsRecordsByIdAndFound() { @Test public void listDnsRecordsByIdAndNotFoundAndNameSetAndFound() { + @SuppressWarnings("unchecked") Page pageMock = createStrictMock(Page.class); replay(pageMock); expect(dns.listDnsRecords(ZONE_ID)).andReturn(null); @@ -251,6 +251,7 @@ public void listDnsRecordsByIdAndNotFoundAndNameNotSet() { @Test public void listDnsRecordsByNameAndFound() { + @SuppressWarnings("unchecked") Page pageMock = createStrictMock(Page.class); replay(pageMock); expect(dns.listDnsRecords(ZONE_NAME)).andReturn(pageMock); @@ -486,9 +487,9 @@ public void applyNullChangeRequest() { @Test public void getChangeByIdAndFound() { - expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_ID)).andReturn(CHANGE_REQUEST_AFTER); + expect(dns.getChangeRequest(ZONE_ID, CHANGE_REQUEST.id())).andReturn(CHANGE_REQUEST_AFTER); // again for options - expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.getChangeRequest(ZONE_ID, CHANGE_REQUEST.id(), CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(CHANGE_REQUEST_AFTER); replay(dns); ChangeRequest result = zone.getChangeRequest(CHANGE_REQUEST.id()); @@ -503,13 +504,13 @@ public void getChangeByIdAndFound() { @Test public void getChangeByIdAndNotFoundAndNameSetAndFound() { - expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_ID)).andReturn(null); - expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_NAME)) + expect(dns.getChangeRequest(ZONE_ID, CHANGE_REQUEST.id())).andReturn(null); + expect(dns.getChangeRequest(ZONE_NAME, CHANGE_REQUEST.id())) .andReturn(CHANGE_REQUEST_AFTER); // again for options - expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.getChangeRequest(ZONE_ID, CHANGE_REQUEST.id(), CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(null); - expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.getChangeRequest(ZONE_NAME, CHANGE_REQUEST.id(), CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(CHANGE_REQUEST_AFTER); replay(dns); ChangeRequest result = zone.getChangeRequest(CHANGE_REQUEST.id()); @@ -523,12 +524,12 @@ public void getChangeByIdAndNotFoundAndNameSetAndFound() { @Test public void getChangeIdAndNotFoundAndNameSetAndNotFound() { - expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_ID)).andReturn(null); - expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_NAME)).andReturn(null); + expect(dns.getChangeRequest(ZONE_ID, CHANGE_REQUEST.id())).andReturn(null); + expect(dns.getChangeRequest(ZONE_NAME, CHANGE_REQUEST.id())).andReturn(null); // again with options - expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.getChangeRequest(ZONE_ID, CHANGE_REQUEST.id(), CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(null); - expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.getChangeRequest(ZONE_NAME, CHANGE_REQUEST.id(), CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(null); replay(dns); ChangeRequest result = zone.getChangeRequest(CHANGE_REQUEST.id()); @@ -540,8 +541,8 @@ public void getChangeIdAndNotFoundAndNameSetAndNotFound() { @Test public void getChangeRequestByIdAndNotFoundAndNameNotSet() { - expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_ID)).andReturn(null); - expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_ID, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.getChangeRequest(ZONE_ID, CHANGE_REQUEST.id())).andReturn(null); + expect(dns.getChangeRequest(ZONE_ID, CHANGE_REQUEST.id(), CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(null); // for options replay(dns); ChangeRequest result = zoneNoName.getChangeRequest(CHANGE_REQUEST.id()); @@ -554,10 +555,10 @@ public void getChangeRequestByIdAndNotFoundAndNameNotSet() { @Test public void getChangeByNameAndFound() { // ID is not set - expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_NAME)) + expect(dns.getChangeRequest(ZONE_NAME, CHANGE_REQUEST.id())) .andReturn(CHANGE_REQUEST_AFTER); // again for options - expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.getChangeRequest(ZONE_NAME, CHANGE_REQUEST.id(), CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(CHANGE_REQUEST_AFTER); replay(dns); ChangeRequest result = zoneNoId.getChangeRequest(CHANGE_REQUEST.id()); @@ -570,9 +571,9 @@ public void getChangeByNameAndFound() { @Test public void getChangeByNameAndNotFound() { // ID is not set - expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_NAME)).andReturn(null); + expect(dns.getChangeRequest(ZONE_NAME, CHANGE_REQUEST.id())).andReturn(null); // again for options - expect(dns.getChangeRequest(CHANGE_REQUEST.id(), ZONE_NAME, CHANGE_REQUEST_FIELD_OPTIONS)) + expect(dns.getChangeRequest(ZONE_NAME, CHANGE_REQUEST.id(), CHANGE_REQUEST_FIELD_OPTIONS)) .andReturn(null); replay(dns); ChangeRequest result = zoneNoId.getChangeRequest(CHANGE_REQUEST.id()); @@ -666,6 +667,7 @@ public void getChangeRequestWithNoId() { @Test public void listChangeRequestsByIdAndFound() { + @SuppressWarnings("unchecked") Page pageMock = createStrictMock(Page.class); replay(pageMock); expect(dns.listChangeRequests(ZONE_ID)).andReturn(pageMock); @@ -681,6 +683,7 @@ public void listChangeRequestsByIdAndFound() { @Test public void listChangeRequestsByIdAndNotFoundAndNameSetAndFound() { + @SuppressWarnings("unchecked") Page pageMock = createStrictMock(Page.class); replay(pageMock); expect(dns.listChangeRequests(ZONE_ID)).andReturn(null); @@ -724,6 +727,7 @@ public void listChangeRequestsByIdAndNotFoundAndNameNotSet() { @Test public void listChangeRequestsByNameAndFound() { + @SuppressWarnings("unchecked") Page pageMock = createStrictMock(Page.class); replay(pageMock); expect(dns.listChangeRequests(ZONE_NAME)).andReturn(pageMock);