From 3cf07229834282f96f84cd783b4487a323967bfc Mon Sep 17 00:00:00 2001 From: Martin Derka Date: Tue, 1 Mar 2016 14:41:17 -0800 Subject: [PATCH] Switched ZoneInfo.builder(). to ZoneInfo.of(). Fixes #698. --- .../java/com/google/gcloud/dns/ZoneInfo.java | 6 +-- .../com/google/gcloud/dns/DnsImplTest.java | 3 +- .../google/gcloud/dns/SerializationTest.java | 10 ++--- .../com/google/gcloud/dns/ZoneInfoTest.java | 42 ++++++++--------- .../java/com/google/gcloud/dns/ZoneTest.java | 9 ++-- .../com/google/gcloud/dns/it/ITDnsTest.java | 45 +++---------------- 6 files changed, 38 insertions(+), 77 deletions(-) diff --git a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/ZoneInfo.java b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/ZoneInfo.java index 7dffbcdd365c..38a88b67777e 100644 --- a/gcloud-java-dns/src/main/java/com/google/gcloud/dns/ZoneInfo.java +++ b/gcloud-java-dns/src/main/java/com/google/gcloud/dns/ZoneInfo.java @@ -185,10 +185,10 @@ public ZoneInfo build() { } /** - * Returns a builder for {@code ZoneInfo} with an assigned {@code name}. + * Returns a ZoneInfo object with assigned {@code name}, {@code dnsName} and {@code description}. */ - public static Builder builder(String name) { - return new BuilderImpl(name); + public static ZoneInfo of(String name, String dnsName, String description) { + return new BuilderImpl(name).dnsName(dnsName).description(description).build(); } /** diff --git a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/DnsImplTest.java b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/DnsImplTest.java index e1974d6cccfd..9205de8d99dd 100644 --- a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/DnsImplTest.java +++ b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/DnsImplTest.java @@ -44,6 +44,7 @@ public class DnsImplTest { // Dns entities private static final String ZONE_NAME = "some zone name"; private static final String DNS_NAME = "example.com."; + private static final String DESCRIPTION = "desc"; private static final String CHANGE_ID = "some change id"; private static final DnsRecord DNS_RECORD1 = DnsRecord.builder("Something", DnsRecord.Type.AAAA) .build(); @@ -51,7 +52,7 @@ public class DnsImplTest { .build(); private static final Integer MAX_SIZE = 20; private static final String PAGE_TOKEN = "some token"; - private static final ZoneInfo ZONE_INFO = ZoneInfo.builder(ZONE_NAME).build(); + private static final ZoneInfo ZONE_INFO = ZoneInfo.of(ZONE_NAME, DNS_NAME, DESCRIPTION); private static final ProjectInfo PROJECT_INFO = ProjectInfo.builder().build(); private static final ChangeRequest CHANGE_REQUEST_PARTIAL = ChangeRequest.builder() .add(DNS_RECORD1) diff --git a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/SerializationTest.java b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/SerializationTest.java index adf5744d854e..c2bf9cfca0bb 100644 --- a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/SerializationTest.java +++ b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/SerializationTest.java @@ -35,16 +35,15 @@ public class SerializationTest { - private static final ZoneInfo FULL_ZONE_INFO = Zone.builder("some zone name") + private static final ZoneInfo FULL_ZONE_INFO = Zone.of("some zone name", "www.example.com", + "some descriptions").toBuilder() .creationTimeMillis(132L) - .description("some descriptions") - .dnsName("www.example.com") .id("123333") .nameServers(ImmutableList.of("server 1", "server 2")) .nameServerSet("specificationstring") .build(); - private static final ZoneInfo PARTIAL_ZONE_INFO = Zone.builder("some zone name") - .build(); + private static final ZoneInfo PARTIAL_ZONE_INFO = Zone.of("some zone name", "www.example.com", + "some descriptions").toBuilder().build(); private static final ProjectInfo PARTIAL_PROJECT_INFO = ProjectInfo.builder().id("13").build(); private static final ProjectInfo FULL_PROJECT_INFO = ProjectInfo.builder() .id("342") @@ -87,7 +86,6 @@ public class SerializationTest { .startTimeMillis(132L) .build(); - @Test public void testModelAndRequests() throws Exception { Serializable[] objects = {FULL_ZONE_INFO, PARTIAL_ZONE_INFO, ZONE_LIST_OPTION, diff --git a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/ZoneInfoTest.java b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/ZoneInfoTest.java index 227916b46f96..b743bd385274 100644 --- a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/ZoneInfoTest.java +++ b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/ZoneInfoTest.java @@ -41,25 +41,23 @@ public class ZoneInfoTest { private static final String NS2 = "name server 2"; private static final String NS3 = "name server 3"; private static final List NAME_SERVERS = ImmutableList.of(NS1, NS2, NS3); - private static final ZoneInfo INFO = ZoneInfo.builder(NAME) + private static final ZoneInfo INFO = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder() .creationTimeMillis(CREATION_TIME_MILLIS) .id(ID) - .dnsName(DNS_NAME) - .description(DESCRIPTION) .nameServerSet(NAME_SERVER_SET) .nameServers(NAME_SERVERS) .build(); @Test public void testDefaultBuilders() { - ZoneInfo zone = ZoneInfo.builder(NAME).build(); + ZoneInfo zone = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION); assertTrue(zone.nameServers().isEmpty()); assertEquals(NAME, zone.name()); assertNull(zone.id()); assertNull(zone.creationTimeMillis()); assertNull(zone.nameServerSet()); - assertNull(zone.description()); - assertNull(zone.dnsName()); + assertEquals(DESCRIPTION, zone.description()); + assertEquals(DNS_NAME, zone.dnsName()); } @Test @@ -109,42 +107,38 @@ public void testSameHashCodeOnEquals() { @Test public void testToBuilder() { assertEquals(INFO, INFO.toBuilder().build()); - ZoneInfo partial = ZoneInfo.builder(NAME).build(); + ZoneInfo partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION); assertEquals(partial, partial.toBuilder().build()); - partial = ZoneInfo.builder(NAME).id(ID).build(); + partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder().id(ID).build(); assertEquals(partial, partial.toBuilder().build()); - partial = ZoneInfo.builder(NAME).description(DESCRIPTION).build(); - assertEquals(partial, partial.toBuilder().build()); - partial = ZoneInfo.builder(NAME).dnsName(DNS_NAME).build(); - assertEquals(partial, partial.toBuilder().build()); - partial = ZoneInfo.builder(NAME).creationTimeMillis(CREATION_TIME_MILLIS).build(); + partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder() + .creationTimeMillis(CREATION_TIME_MILLIS).build(); assertEquals(partial, partial.toBuilder().build()); List nameServers = new LinkedList<>(); nameServers.add(NS1); - partial = ZoneInfo.builder(NAME).nameServers(nameServers).build(); + partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder().nameServers(nameServers).build(); assertEquals(partial, partial.toBuilder().build()); - partial = ZoneInfo.builder(NAME).nameServerSet(NAME_SERVER_SET).build(); + partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder().nameServerSet(NAME_SERVER_SET) + .build(); assertEquals(partial, partial.toBuilder().build()); } @Test public void testToAndFromPb() { assertEquals(INFO, ZoneInfo.fromPb(INFO.toPb())); - ZoneInfo partial = ZoneInfo.builder(NAME).build(); - assertEquals(partial, ZoneInfo.fromPb(partial.toPb())); - partial = ZoneInfo.builder(NAME).id(ID).build(); - assertEquals(partial, ZoneInfo.fromPb(partial.toPb())); - partial = ZoneInfo.builder(NAME).description(DESCRIPTION).build(); + ZoneInfo partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION); assertEquals(partial, ZoneInfo.fromPb(partial.toPb())); - partial = ZoneInfo.builder(NAME).dnsName(DNS_NAME).build(); + partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder().id(ID).build(); assertEquals(partial, ZoneInfo.fromPb(partial.toPb())); - partial = ZoneInfo.builder(NAME).creationTimeMillis(CREATION_TIME_MILLIS).build(); + partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder() + .creationTimeMillis(CREATION_TIME_MILLIS).build(); assertEquals(partial, ZoneInfo.fromPb(partial.toPb())); List nameServers = new LinkedList<>(); nameServers.add(NS1); - partial = ZoneInfo.builder(NAME).nameServers(nameServers).build(); + partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder().nameServers(nameServers).build(); assertEquals(partial, ZoneInfo.fromPb(partial.toPb())); - partial = ZoneInfo.builder(NAME).nameServerSet(NAME_SERVER_SET).build(); + partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder().nameServerSet(NAME_SERVER_SET) + .build(); assertEquals(partial, ZoneInfo.fromPb(partial.toPb())); } 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 5164dfb6001c..759c34fc1167 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 @@ -43,13 +43,13 @@ public class ZoneTest { private static final String ZONE_NAME = "dns-zone-name"; private static final String ZONE_ID = "123"; - private static final ZoneInfo ZONE_INFO = Zone.builder(ZONE_NAME) + private static final ZoneInfo ZONE_INFO = Zone.of(ZONE_NAME, "example.com", "description") + .toBuilder() .id(ZONE_ID) - .dnsName("example.com") .creationTimeMillis(123478946464L) .build(); - private static final ZoneInfo NO_ID_INFO = ZoneInfo.builder(ZONE_NAME) - .dnsName("another-example.com") + private static final ZoneInfo NO_ID_INFO = + ZoneInfo.of(ZONE_NAME, "another-example.com", "description").toBuilder() .creationTimeMillis(893123464L) .build(); private static final Dns.ZoneOption ZONE_FIELD_OPTIONS = @@ -71,7 +71,6 @@ public class ZoneTest { private Zone zone; private Zone zoneNoId; - @Before public void setUp() throws Exception { dns = createStrictMock(Dns.class); diff --git a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/it/ITDnsTest.java b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/it/ITDnsTest.java index fda579a4a94b..4ad17fa8b217 100644 --- a/gcloud-java-dns/src/test/java/com/google/gcloud/dns/it/ITDnsTest.java +++ b/gcloud-java-dns/src/test/java/com/google/gcloud/dns/it/ITDnsTest.java @@ -60,29 +60,14 @@ public class ITDnsTest { private static final String ZONE_DNS_NAME1 = ZONE_NAME1 + ".com."; private static final String ZONE_DNS_EMPTY_DESCRIPTION = ZONE_NAME_EMPTY_DESCRIPTION + ".com."; private static final String ZONE_DNS_NAME_NO_PERIOD = ZONE_NAME1 + ".com"; - private static final ZoneInfo ZONE1 = ZoneInfo.builder(ZONE_NAME1) - .description(ZONE_DESCRIPTION1) - .dnsName(ZONE_DNS_EMPTY_DESCRIPTION) - .build(); + private static final ZoneInfo ZONE1 = + ZoneInfo.of(ZONE_NAME1, ZONE_DNS_EMPTY_DESCRIPTION, ZONE_DESCRIPTION1); private static final ZoneInfo ZONE_EMPTY_DESCRIPTION = - ZoneInfo.builder(ZONE_NAME_EMPTY_DESCRIPTION) - .description(ZONE_DESCRIPTION1) - .dnsName(ZONE_DNS_NAME1) - .build(); - private static final ZoneInfo ZONE_NAME_ERROR = ZoneInfo.builder(ZONE_NAME_TOO_LONG) - .description(ZONE_DESCRIPTION1) - .dnsName(ZONE_DNS_NAME1) - .build(); - private static final ZoneInfo ZONE_MISSING_DESCRIPTION = ZoneInfo.builder(ZONE_NAME1) - .dnsName(ZONE_DNS_NAME1) - .build(); - private static final ZoneInfo ZONE_MISSING_DNS_NAME = ZoneInfo.builder(ZONE_NAME1) - .description(ZONE_DESCRIPTION1) - .build(); - private static final ZoneInfo ZONE_DNS_NO_PERIOD = ZoneInfo.builder(ZONE_NAME1) - .description(ZONE_DESCRIPTION1) - .dnsName(ZONE_DNS_NAME_NO_PERIOD) - .build(); + ZoneInfo.of(ZONE_NAME_EMPTY_DESCRIPTION, ZONE_DNS_NAME1, ZONE_DESCRIPTION1); + private static final ZoneInfo ZONE_NAME_ERROR = + ZoneInfo.of(ZONE_NAME_TOO_LONG, ZONE_DNS_NAME1, ZONE_DESCRIPTION1); + private static final ZoneInfo ZONE_DNS_NO_PERIOD = + ZoneInfo.of(ZONE_NAME1, ZONE_DNS_NAME_NO_PERIOD, ZONE_DESCRIPTION1); private static final DnsRecord A_RECORD_ZONE1 = DnsRecord.builder("www." + ZONE1.dnsName(), DnsRecord.Type.A) .records(ImmutableList.of("123.123.55.1")) @@ -211,20 +196,6 @@ public void testCreateValidZone() { @Test public void testCreateZoneWithErrors() { try { - try { - DNS.create(ZONE_MISSING_DNS_NAME); - fail("Zone is missing DNS name. The service returns an error."); - } catch (DnsException ex) { - // expected - // todo(mderka) test non-retryable when implemented within #593 - } - try { - DNS.create(ZONE_MISSING_DESCRIPTION); - fail("Zone is missing description name. The service returns an error."); - } catch (DnsException ex) { - // expected - // todo(mderka) test non-retryable when implemented within #593 - } try { DNS.create(ZONE_NAME_ERROR); fail("Zone name is missing a period. The service returns an error."); @@ -240,8 +211,6 @@ public void testCreateZoneWithErrors() { // todo(mderka) test non-retryable when implemented within #593 } } finally { - DNS.delete(ZONE_MISSING_DNS_NAME.name()); - DNS.delete(ZONE_MISSING_DESCRIPTION.name()); DNS.delete(ZONE_NAME_ERROR.name()); DNS.delete(ZONE_DNS_NO_PERIOD.name()); }