Skip to content

Commit

Permalink
Switched ZoneInfo.builder(). to ZoneInfo.of(). Fixes googleapis#698.
Browse files Browse the repository at this point in the history
  • Loading branch information
mderka committed Mar 10, 2016
1 parent 53e87fe commit 3cf0722
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ 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();
private static final DnsRecord DNS_RECORD2 = DnsRecord.builder("Different", DnsRecord.Type.AAAA)
.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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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
Expand Down Expand Up @@ -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<String> 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<String> 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()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -71,7 +71,6 @@ public class ZoneTest {
private Zone zone;
private Zone zoneNoId;


@Before
public void setUp() throws Exception {
dns = createStrictMock(Dns.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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.");
Expand All @@ -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());
}
Expand Down

0 comments on commit 3cf0722

Please sign in to comment.