diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/NetworkConfiguration.java b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/NetworkConfiguration.java
new file mode 100644
index 000000000000..f1d118347175
--- /dev/null
+++ b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/NetworkConfiguration.java
@@ -0,0 +1,98 @@
+/*
+ * 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.compute;
+
+import com.google.api.services.compute.model.Network;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+/**
+ * Base class for Google Compute Engine network configuration. Use
+ * {@link StandardNetworkConfiguration} to create a standard network with associated address range.
+ * Use {@link SubnetNetworkConfiguration} to create a network that supports subnetworks, up to one
+ * per region, each with its own address range.
+ *
+ * @see Using Networks and Firewalls
+ */
+public abstract class NetworkConfiguration implements Serializable {
+
+ private static final long serialVersionUID = 6599798536784576564L;
+
+ private final Type type;
+
+ /**
+ * Type of a Google Compute Engine disk configuration.
+ */
+ public enum Type {
+ /**
+ * A Google Compute Engine network with no subnetworks.
+ */
+ STANDARD,
+
+ /**
+ * A Google Compute Engine network that supports the creation of subnetworks (either automatic
+ * or manual).
+ */
+ SUBNET
+ }
+
+ NetworkConfiguration(Type type) {
+ this.type = type;
+ }
+
+ /**
+ * Returns the network's type. This method returns {@link Type#STANDARD} for a standard networks
+ * with no subnetworks. This method returns {@link Type#SUBNET} for a network that supports the
+ * creation of subnetworks (either automatic or manual).
+ */
+ public Type type() {
+ return type;
+ }
+
+ ToStringHelper toStringHelper() {
+ return MoreObjects.toStringHelper(this).add("type", type);
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper().toString();
+ }
+
+ final int baseHashCode() {
+ return Objects.hash(type);
+ }
+
+ final boolean baseEquals(NetworkConfiguration networkConfiguration) {
+ return networkConfiguration != null
+ && getClass().equals(networkConfiguration.getClass())
+ && Objects.equals(toPb(), networkConfiguration.toPb());
+ }
+
+ abstract Network toPb();
+
+ @SuppressWarnings("unchecked")
+ static T fromPb(Network networkPb) {
+ if (networkPb.getIPv4Range() != null) {
+ return (T) StandardNetworkConfiguration.fromPb(networkPb);
+ } else {
+ return (T) SubnetNetworkConfiguration.fromPb(networkPb);
+ }
+ }
+}
diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/NetworkInfo.java b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/NetworkInfo.java
new file mode 100644
index 000000000000..1e1d4f4bf907
--- /dev/null
+++ b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/NetworkInfo.java
@@ -0,0 +1,288 @@
+/*
+ * 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.compute;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.api.services.compute.model.Network;
+import com.google.common.base.Function;
+import com.google.common.base.MoreObjects;
+
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.ISODateTimeFormat;
+
+import java.io.Serializable;
+import java.math.BigInteger;
+import java.util.Objects;
+
+/**
+ * A Google Compute Engine Network. Every virtual machine instance is created as a member of a
+ * network. Networks connect instances to each other and to the Internet. You can segment your
+ * networks, use firewall rules to restrict access to instances, and create static routes to forward
+ * traffic to specific destinations.
+ *
+ * @see Using Networks and Firewalls
+ */
+public class NetworkInfo implements Serializable {
+
+ static final Function FROM_PB_FUNCTION =
+ new Function() {
+ @Override
+ public NetworkInfo apply(Network pb) {
+ return NetworkInfo.fromPb(pb);
+ }
+ };
+ static final Function TO_PB_FUNCTION =
+ new Function() {
+ @Override
+ public Network apply(NetworkInfo network) {
+ return network.toPb();
+ }
+ };
+
+ private static final long serialVersionUID = 4336912581538114026L;
+ private static final DateTimeFormatter TIMESTAMP_FORMATTER = ISODateTimeFormat.dateTime();
+
+ private final String id;
+ private final NetworkId networkId;
+ private final Long creationTimestamp;
+ private final String description;
+ private final NetworkConfiguration configuration;
+
+ /**
+ * A builder for {@code NetworkInfo} objects.
+ */
+ public abstract static class Builder {
+
+ abstract Builder id(String id);
+
+ abstract Builder creationTimestamp(Long creationTimestamp);
+
+ /**
+ * Sets the identity of the network.
+ */
+ public abstract Builder networkId(NetworkId networkId);
+
+ /**
+ * Sets an optional textual description of the network.
+ */
+ public abstract Builder description(String description);
+
+ /**
+ * Sets the network configuration. Use {@link StandardNetworkConfiguration} to create a standard
+ * network with associated IPv4 range. Use {@link SubnetNetworkConfiguration} to create a
+ * network that could be divided into subnetworks, up to one per region, each with its own
+ * address range.
+ */
+ public abstract Builder configuration(NetworkConfiguration configuration);
+
+ /**
+ * Creates a {@code NetworkInfo} object.
+ */
+ public abstract NetworkInfo build();
+ }
+
+ static final class BuilderImpl extends Builder {
+
+ private String id;
+ private NetworkId networkId;
+ private Long creationTimestamp;
+ private String description;
+ private NetworkConfiguration configuration;
+
+ BuilderImpl(NetworkId networkId, NetworkConfiguration configuration) {
+ this.networkId = checkNotNull(networkId);
+ this.configuration = checkNotNull(configuration);
+ }
+
+ BuilderImpl(NetworkInfo networkInfo) {
+ this.id = networkInfo.id;
+ this.creationTimestamp = networkInfo.creationTimestamp;
+ this.networkId = networkInfo.networkId;
+ this.description = networkInfo.description;
+ this.configuration = networkInfo.configuration;
+ }
+
+ BuilderImpl(Network networkPb) {
+ if (networkPb.getId() != null) {
+ this.id = networkPb.getId().toString();
+ }
+ if (networkPb.getCreationTimestamp() != null) {
+ this.creationTimestamp = TIMESTAMP_FORMATTER.parseMillis(networkPb.getCreationTimestamp());
+ }
+ this.networkId = NetworkId.fromUrl(networkPb.getSelfLink());
+ this.description = networkPb.getDescription();
+ this.configuration = NetworkConfiguration.fromPb(networkPb);
+ }
+
+ @Override
+ BuilderImpl id(String id) {
+ this.id = id;
+ return this;
+ }
+
+ @Override
+ BuilderImpl creationTimestamp(Long creationTimestamp) {
+ this.creationTimestamp = creationTimestamp;
+ return this;
+ }
+
+ @Override
+ public BuilderImpl networkId(NetworkId networkId) {
+ this.networkId = checkNotNull(networkId);
+ return this;
+ }
+
+ @Override
+ public BuilderImpl description(String description) {
+ this.description = description;
+ return this;
+ }
+
+ @Override
+ public BuilderImpl configuration(NetworkConfiguration configuration) {
+ this.configuration = checkNotNull(configuration);
+ return this;
+ }
+
+ @Override
+ public NetworkInfo build() {
+ return new NetworkInfo(this);
+ }
+ }
+
+ NetworkInfo(BuilderImpl builder) {
+ this.id = builder.id;
+ this.creationTimestamp = builder.creationTimestamp;
+ this.networkId = builder.networkId;
+ this.description = builder.description;
+ this.configuration = builder.configuration;
+ }
+
+ /**
+ * Returns the unique identifier for the subnetwork; defined by the service.
+ */
+ public String id() {
+ return id;
+ }
+
+ /**
+ * Returns the creation timestamp in milliseconds since epoch.
+ */
+ public Long creationTimestamp() {
+ return creationTimestamp;
+ }
+
+ /**
+ * Returns the network identity.
+ */
+ public NetworkId networkId() {
+ return networkId;
+ }
+
+ /**
+ * Returns a textual description of the network.
+ */
+ public String description() {
+ return description;
+ }
+
+ /**
+ * Returns the network configuration. Returns a {@link StandardNetworkConfiguration} for standard
+ * networks with associated IPv4 range. Returns {@link SubnetNetworkConfiguration} for networks
+ * that could be divided into subnetworks, up to one per region, each with its own address range.
+ */
+ @SuppressWarnings("unchecked")
+ public T configuration() {
+ return (T) configuration;
+ }
+
+ /**
+ * Returns a builder for the current network.
+ */
+ public Builder toBuilder() {
+ return new BuilderImpl(this);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("id", id)
+ .add("creationTimestamp", creationTimestamp)
+ .add("networkId", networkId)
+ .add("description", description)
+ .add("configuration", configuration)
+ .toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, networkId, creationTimestamp, description, configuration);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return obj == this
+ || obj != null
+ && obj.getClass().equals(NetworkInfo.class)
+ && Objects.equals(toPb(), ((NetworkInfo) obj).toPb());
+ }
+
+ NetworkInfo setProjectId(String projectId) {
+ return toBuilder()
+ .networkId(networkId.setProjectId(projectId))
+ .build();
+ }
+
+ Network toPb() {
+ Network networkPb = configuration.toPb();
+ if (id != null) {
+ networkPb.setId(new BigInteger(id));
+ }
+ if (creationTimestamp != null) {
+ networkPb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp));
+ }
+ networkPb.setName(networkId.network());
+ networkPb.setDescription(description);
+ networkPb.setSelfLink(networkId.selfLink());
+ return networkPb;
+ }
+
+ /**
+ * Returns a builder for a {@code NetworkInfo} object given the network identity and its
+ * configuration. Use {@link StandardNetworkConfiguration} to create a standard network with
+ * associated address range. Use {@link SubnetNetworkConfiguration} to create a network that
+ * supports subnetworks, up to one per region, each with its own address range.
+ */
+ public static Builder builder(NetworkId networkId, NetworkConfiguration configuration) {
+ return new BuilderImpl(networkId, configuration);
+ }
+
+ /**
+ * Returns a {@code NetworkInfo} object given the network identity. Use
+ * {@link StandardNetworkConfiguration} to create a standard network with associated address
+ * range. Use {@link SubnetNetworkConfiguration} to create a network that supports subnetworks, up
+ * to one per region, each with its own address range.
+ */
+ public static NetworkInfo of(NetworkId networkId, NetworkConfiguration configuration) {
+ return builder(networkId, configuration).build();
+ }
+
+ static NetworkInfo fromPb(Network networkPb) {
+ return new BuilderImpl(networkPb).build();
+ }
+}
diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/StandardNetworkConfiguration.java b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/StandardNetworkConfiguration.java
new file mode 100644
index 000000000000..d4595efb6eb6
--- /dev/null
+++ b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/StandardNetworkConfiguration.java
@@ -0,0 +1,102 @@
+/*
+ * 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.compute;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.api.services.compute.model.Network;
+import com.google.common.base.MoreObjects;
+
+import java.util.Objects;
+
+/**
+ * A Google Compute Engine standard network configuration. This class allows users to create a
+ * network with its own address range. A network created with a {@code StandardNetworkConfiguration}
+ * does not support the creation of subnetworks.
+ *
+ * @see Using Networks and Firewalls
+ */
+public class StandardNetworkConfiguration extends NetworkConfiguration {
+
+ private static final long serialVersionUID = -5143748459659467966L;
+
+ private final String ipRange;
+ private final String gatewayAddress;
+
+ StandardNetworkConfiguration(String ipRange, String gatewayAddress) {
+ super(Type.STANDARD);
+ this.ipRange = checkNotNull(ipRange);
+ this.gatewayAddress = gatewayAddress;
+ }
+
+ /**
+ * Returns the range of internal IPv4 addresses that are legal on this network. This range is a
+ * CIDR specification, for example: {@code 192.168.0.0/16}.
+ *
+ * @see CIDR
+ */
+ public String ipRange() {
+ return ipRange;
+ }
+
+ /**
+ * Returns the gateway IPv4 address for this networks. This value is read only and is selected by
+ * Google Compute Engine, typically as the first usable address in {@code ipRange}.
+ */
+ public String gatewayAddress() {
+ return gatewayAddress;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(super.baseHashCode(), ipRange, gatewayAddress);
+ }
+
+ @Override
+ public final boolean equals(Object obj) {
+ return obj == this
+ || obj != null
+ && obj.getClass().equals(StandardNetworkConfiguration.class)
+ && Objects.equals(toPb(), ((StandardNetworkConfiguration) obj).toPb());
+ }
+
+ @Override
+ MoreObjects.ToStringHelper toStringHelper() {
+ return super.toStringHelper().add("ipRange", ipRange).add("gatewayAddress", gatewayAddress);
+ }
+
+ @Override
+ Network toPb() {
+ return new Network().setIPv4Range(ipRange).setGatewayIPv4(gatewayAddress);
+ }
+
+ /**
+ * Returns a {@code StandardNetworkConfiguration} object given the range of internal addresses
+ * that are legal on this network. {@code ipRange} must be a CIDR specification, for example:
+ * {@code 192.168.0.0/16}.
+ *
+ * @see CIDR
+ */
+ public static StandardNetworkConfiguration of(String ipRange) {
+ return new StandardNetworkConfiguration(ipRange, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ static StandardNetworkConfiguration fromPb(Network networkPb) {
+ return new StandardNetworkConfiguration(networkPb.getIPv4Range(), networkPb.getGatewayIPv4());
+ }
+}
diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/SubnetNetworkConfiguration.java b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/SubnetNetworkConfiguration.java
new file mode 100644
index 000000000000..0d4c9f07b85f
--- /dev/null
+++ b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/SubnetNetworkConfiguration.java
@@ -0,0 +1,111 @@
+/*
+ * 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.compute;
+
+import com.google.api.services.compute.model.Network;
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.Lists;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * A Google Compute Engine configuration for networks that support subnetworks, up to one per
+ * region, each with its own address range. Subnetworks can be either automatically or manually
+ * created, depending on the value of {@link SubnetNetworkConfiguration#autoCreateSubnetworks()}.
+ *
+ * @see Using Networks and Firewalls
+ */
+public class SubnetNetworkConfiguration extends NetworkConfiguration {
+
+ private static final long serialVersionUID = -5286394393047479494L;
+
+ private final Boolean autoCreateSubnetworks;
+ private final List subnetworks;
+
+ SubnetNetworkConfiguration(boolean autoCreateSubnetworks, List subnetworks) {
+ super(Type.SUBNET);
+ this.autoCreateSubnetworks = autoCreateSubnetworks;
+ this.subnetworks = subnetworks;
+ }
+
+ /**
+ * Returns whether the subnetworks should be automatically created. When set to {@code true}, the
+ * network is created in "auto subnet mode". When set to {@code false}, the network is in
+ * "custom subnet mode". In "auto subnet mode", a subnetwork per region is automatically created.
+ * In "custom subnet mode", a custom topology of subnetworks can be created by the user.
+ */
+ public Boolean autoCreateSubnetworks() {
+ return autoCreateSubnetworks;
+ }
+
+ /**
+ * Returns the identities of all networks in this network.
+ */
+ public List subnetworks() {
+ return subnetworks;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(autoCreateSubnetworks, subnetworks);
+ }
+
+ @Override
+ public final boolean equals(Object obj) {
+ return obj == this
+ || obj != null
+ && obj.getClass().equals(SubnetNetworkConfiguration.class)
+ && Objects.equals(toPb(), ((SubnetNetworkConfiguration) obj).toPb());
+ }
+
+ @Override
+ MoreObjects.ToStringHelper toStringHelper() {
+ return super.toStringHelper()
+ .add("autoCreateSubnetworks", autoCreateSubnetworks)
+ .add("subnetworks", subnetworks);
+ }
+
+ @Override
+ Network toPb() {
+ Network networkPb = new Network().setAutoCreateSubnetworks(autoCreateSubnetworks);
+ if (subnetworks != null) {
+ networkPb.setSubnetworks(Lists.transform(subnetworks, SubnetworkId.TO_URL_FUNCTION));
+ }
+ return networkPb;
+ }
+
+ /**
+ * Returns a {@code SubnetNetworkConfiguration} object. The {@code autoCreateSubnetworks}
+ * parameter sets whether subnetworks should be automatically created. When set to {@code true},
+ * the network is created in "auto subnet mode". When set to {@code false}, the network is in
+ * "custom subnet mode". In "auto subnet mode", a subnetwork per region is automatically created.
+ * In "custom subnet mode", a custom topology of subnetworks can be created by the user.
+ */
+ public static SubnetNetworkConfiguration of(boolean autoCreateSubnetworks) {
+ return new SubnetNetworkConfiguration(autoCreateSubnetworks, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ static SubnetNetworkConfiguration fromPb(Network networkPb) {
+ List subnetworks = null;
+ if (networkPb.getSubnetworks() != null) {
+ subnetworks = Lists.transform(networkPb.getSubnetworks(), SubnetworkId.FROM_URL_FUNCTION);
+ }
+ return new SubnetNetworkConfiguration(networkPb.getAutoCreateSubnetworks(), subnetworks);
+ }
+}
diff --git a/gcloud-java-compute/src/test/java/com/google/gcloud/compute/NetworkInfoTest.java b/gcloud-java-compute/src/test/java/com/google/gcloud/compute/NetworkInfoTest.java
new file mode 100644
index 000000000000..3886e13816fe
--- /dev/null
+++ b/gcloud-java-compute/src/test/java/com/google/gcloud/compute/NetworkInfoTest.java
@@ -0,0 +1,126 @@
+/*
+ * 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.compute;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import com.google.common.collect.ImmutableList;
+
+import org.junit.Test;
+
+import java.util.List;
+
+public class NetworkInfoTest {
+
+ private static final String ID = "42";
+ private static final Long CREATION_TIMESTAMP = 1453293540000L;
+ private static final String DESCRIPTION = "description";
+ private static final SubnetworkId SUBNETWORK1 = SubnetworkId.of("project", "region1", "network1");
+ private static final SubnetworkId SUBNETWORK2 = SubnetworkId.of("project", "region2", "network2");
+ private static final List SUBNETWORKS = ImmutableList.of(SUBNETWORK1, SUBNETWORK2);
+ private static final String GATEWAY_ADDRESS = "192.168.1.1";
+ private static final NetworkId NETWORK_ID = NetworkId.of("project", "network");
+ private static final String IP_RANGE = "192.168.0.0/16";
+ private static final Boolean AUTO_CREATE_SUBNETWORKS = true;
+ private static final StandardNetworkConfiguration NETWORK_CONFIGURATION =
+ new StandardNetworkConfiguration(IP_RANGE, GATEWAY_ADDRESS);
+ private static final SubnetNetworkConfiguration SUBNET_NETWORK_CONFIGURATION =
+ new SubnetNetworkConfiguration(AUTO_CREATE_SUBNETWORKS, SUBNETWORKS);
+ private static final NetworkInfo NETWORK_INFO =
+ NetworkInfo.builder(NETWORK_ID, NETWORK_CONFIGURATION)
+ .id(ID)
+ .creationTimestamp(CREATION_TIMESTAMP)
+ .description(DESCRIPTION)
+ .build();
+ private static final NetworkInfo SUBNET_NETWORK_INFO =
+ NetworkInfo.builder(NETWORK_ID, SUBNET_NETWORK_CONFIGURATION)
+ .id(ID)
+ .creationTimestamp(CREATION_TIMESTAMP)
+ .description(DESCRIPTION)
+ .build();
+
+ @Test
+ public void testToBuilder() {
+ compareNetworkInfo(NETWORK_INFO, NETWORK_INFO.toBuilder().build());
+ NetworkInfo networkInfo = NETWORK_INFO.toBuilder().description("newDescription").build();
+ assertEquals("newDescription", networkInfo.description());
+ networkInfo = networkInfo.toBuilder().description("description").build();
+ compareNetworkInfo(NETWORK_INFO, networkInfo);
+ compareNetworkInfo(SUBNET_NETWORK_INFO, SUBNET_NETWORK_INFO.toBuilder().build());
+ networkInfo = SUBNET_NETWORK_INFO.toBuilder().description("newDescription").build();
+ assertEquals("newDescription", networkInfo.description());
+ networkInfo = networkInfo.toBuilder().description("description").build();
+ compareNetworkInfo(SUBNET_NETWORK_INFO, networkInfo);
+ }
+
+ @Test
+ public void testToBuilderIncomplete() {
+ NetworkInfo networkInfo = NetworkInfo.of(NETWORK_ID, NETWORK_CONFIGURATION);
+ assertEquals(networkInfo, networkInfo.toBuilder().build());
+ }
+
+ @Test
+ public void testBuilder() {
+ assertEquals(ID, NETWORK_INFO.id());
+ assertEquals(NETWORK_ID, NETWORK_INFO.networkId());
+ assertEquals(CREATION_TIMESTAMP, NETWORK_INFO.creationTimestamp());
+ assertEquals(DESCRIPTION, NETWORK_INFO.description());
+ assertEquals(NETWORK_CONFIGURATION, NETWORK_INFO.configuration());
+ assertEquals(ID, SUBNET_NETWORK_INFO.id());
+ assertEquals(NETWORK_ID, SUBNET_NETWORK_INFO.networkId());
+ assertEquals(CREATION_TIMESTAMP, SUBNET_NETWORK_INFO.creationTimestamp());
+ assertEquals(DESCRIPTION, SUBNET_NETWORK_INFO.description());
+ assertEquals(SUBNET_NETWORK_CONFIGURATION, SUBNET_NETWORK_INFO.configuration());
+ }
+
+ @Test
+ public void testOf() {
+ NetworkInfo networkInfo = NetworkInfo.of(NETWORK_ID, NETWORK_CONFIGURATION);
+ assertNull(networkInfo.id());
+ assertEquals(NETWORK_ID, NETWORK_INFO.networkId());
+ assertEquals(NETWORK_CONFIGURATION, NETWORK_INFO.configuration());
+ assertNull(networkInfo.creationTimestamp());
+ assertNull(networkInfo.description());
+ }
+
+ @Test
+ public void testToAndFromPb() {
+ compareNetworkInfo(NETWORK_INFO, NetworkInfo.fromPb(NETWORK_INFO.toPb()));
+ compareNetworkInfo(SUBNET_NETWORK_INFO, NetworkInfo.fromPb(SUBNET_NETWORK_INFO.toPb()));
+ NetworkInfo networkInfo = NetworkInfo.of(NETWORK_ID, NETWORK_CONFIGURATION);
+ compareNetworkInfo(networkInfo, NetworkInfo.fromPb(networkInfo.toPb()));
+ }
+
+ @Test
+ public void testSetProjectId() {
+ NetworkInfo networkInfo = NETWORK_INFO.toBuilder()
+ .networkId(NetworkId.of("network"))
+ .build();
+ compareNetworkInfo(NETWORK_INFO, networkInfo.setProjectId("project"));
+ }
+
+ public void compareNetworkInfo(NetworkInfo expected, NetworkInfo value) {
+ assertEquals(expected, value);
+ assertEquals(expected.id(), value.id());
+ assertEquals(expected.networkId(), value.networkId());
+ assertEquals(expected.creationTimestamp(), value.creationTimestamp());
+ assertEquals(expected.description(), value.description());
+ assertEquals(expected.configuration(), value.configuration());
+ assertEquals(expected.hashCode(), value.hashCode());
+ }
+}
diff --git a/gcloud-java-compute/src/test/java/com/google/gcloud/compute/StandardNetworkConfigurationTest.java b/gcloud-java-compute/src/test/java/com/google/gcloud/compute/StandardNetworkConfigurationTest.java
new file mode 100644
index 000000000000..7546f0b70494
--- /dev/null
+++ b/gcloud-java-compute/src/test/java/com/google/gcloud/compute/StandardNetworkConfigurationTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.compute;
+
+import com.google.gcloud.compute.NetworkConfiguration.Type;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class StandardNetworkConfigurationTest {
+
+ private static final String IP_RANGE = "192.168.0.0/16";
+ private static final String GATEWAY_ADDRESS = "192.168.1.1";
+ private static final StandardNetworkConfiguration NETWORK_CONFIGURATION =
+ new StandardNetworkConfiguration(IP_RANGE, GATEWAY_ADDRESS);
+
+ @Test
+ public void testConstructor() {
+ assertEquals(Type.STANDARD, NETWORK_CONFIGURATION.type());
+ assertEquals(IP_RANGE, NETWORK_CONFIGURATION.ipRange());
+ assertEquals(GATEWAY_ADDRESS, NETWORK_CONFIGURATION.gatewayAddress());
+ StandardNetworkConfiguration networkConfiguration =
+ new StandardNetworkConfiguration(IP_RANGE, null);
+ assertEquals(Type.STANDARD, networkConfiguration.type());
+ assertEquals(IP_RANGE, networkConfiguration.ipRange());
+ assertNull(networkConfiguration.gatewayAddress());
+ }
+
+ @Test
+ public void testToAndFromPb() {
+ assertTrue(NetworkConfiguration.fromPb(NETWORK_CONFIGURATION.toPb())
+ instanceof StandardNetworkConfiguration);
+ compareNetworkConfiguration(NETWORK_CONFIGURATION,
+ NetworkConfiguration.fromPb(NETWORK_CONFIGURATION.toPb()));
+ StandardNetworkConfiguration networkConfiguration =
+ new StandardNetworkConfiguration(IP_RANGE, null);
+ assertTrue(NetworkConfiguration.fromPb(networkConfiguration.toPb())
+ instanceof StandardNetworkConfiguration);
+ compareNetworkConfiguration(networkConfiguration,
+ NetworkConfiguration.fromPb(networkConfiguration.toPb()));
+ }
+
+ @Test
+ public void testOf() {
+ StandardNetworkConfiguration configuration = StandardNetworkConfiguration.of(IP_RANGE);
+ assertEquals(Type.STANDARD, configuration.type());
+ assertEquals(IP_RANGE, configuration.ipRange());
+ assertNull(configuration.gatewayAddress());
+ }
+
+ private void compareNetworkConfiguration(StandardNetworkConfiguration expected,
+ StandardNetworkConfiguration value) {
+ assertEquals(expected, value);
+ assertEquals(expected.ipRange(), value.ipRange());
+ assertEquals(expected.gatewayAddress(), value.gatewayAddress());
+ assertEquals(expected.type(), value.type());
+ assertEquals(expected.hashCode(), value.hashCode());
+ }
+}
diff --git a/gcloud-java-compute/src/test/java/com/google/gcloud/compute/SubnetNetworkConfigurationTest.java b/gcloud-java-compute/src/test/java/com/google/gcloud/compute/SubnetNetworkConfigurationTest.java
new file mode 100644
index 000000000000..c2a5ddafcd0e
--- /dev/null
+++ b/gcloud-java-compute/src/test/java/com/google/gcloud/compute/SubnetNetworkConfigurationTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.compute;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import com.google.common.collect.ImmutableList;
+import com.google.gcloud.compute.NetworkConfiguration.Type;
+
+import org.junit.Test;
+
+import java.util.List;
+
+public class SubnetNetworkConfigurationTest {
+
+ private static final Boolean AUTO_CREATE_SUBNETWORKS = true;
+ private static final List SUBNETWORKS = ImmutableList.of(
+ SubnetworkId.of("project", "region", "subnetwork1"),
+ SubnetworkId.of("project", "region", "subnetwork2"));
+ private static final SubnetNetworkConfiguration NETWORK_CONFIGURATION =
+ new SubnetNetworkConfiguration(AUTO_CREATE_SUBNETWORKS, SUBNETWORKS);
+
+ @Test
+ public void testConstructor() {
+ assertEquals(AUTO_CREATE_SUBNETWORKS, NETWORK_CONFIGURATION.autoCreateSubnetworks());
+ assertEquals(Type.SUBNET, NETWORK_CONFIGURATION.type());
+ assertEquals(SUBNETWORKS, NETWORK_CONFIGURATION.subnetworks());
+ assertEquals(Type.SUBNET, NETWORK_CONFIGURATION.type());
+ SubnetNetworkConfiguration networkConfiguration =
+ new SubnetNetworkConfiguration(AUTO_CREATE_SUBNETWORKS, null);
+ assertEquals(Type.SUBNET, networkConfiguration.type());
+ assertEquals(AUTO_CREATE_SUBNETWORKS, networkConfiguration.autoCreateSubnetworks());
+ assertNull(networkConfiguration.subnetworks());
+ }
+
+ @Test
+ public void testToAndFromPb() {
+ assertTrue(NetworkConfiguration.fromPb(NETWORK_CONFIGURATION.toPb())
+ instanceof SubnetNetworkConfiguration);
+ compareNetworkConfiguration(NETWORK_CONFIGURATION,
+ NetworkConfiguration.fromPb(NETWORK_CONFIGURATION.toPb()));
+ SubnetNetworkConfiguration networkConfiguration =
+ new SubnetNetworkConfiguration(AUTO_CREATE_SUBNETWORKS, null);
+ assertTrue(NetworkConfiguration.fromPb(networkConfiguration.toPb())
+ instanceof SubnetNetworkConfiguration);
+ compareNetworkConfiguration(networkConfiguration,
+ NetworkConfiguration.fromPb(networkConfiguration.toPb()));
+ }
+
+ @Test
+ public void testOf() {
+ SubnetNetworkConfiguration configuration =
+ SubnetNetworkConfiguration.of(AUTO_CREATE_SUBNETWORKS);
+ assertEquals(AUTO_CREATE_SUBNETWORKS, configuration.autoCreateSubnetworks());
+ assertNull(configuration.subnetworks());
+ assertEquals(Type.SUBNET, configuration.type());
+ }
+
+ private void compareNetworkConfiguration(SubnetNetworkConfiguration expected,
+ SubnetNetworkConfiguration value) {
+ assertEquals(expected, value);
+ assertEquals(expected.autoCreateSubnetworks(), value.autoCreateSubnetworks());
+ assertEquals(expected.subnetworks(), value.subnetworks());
+ assertEquals(expected.type(), value.type());
+ assertEquals(expected.hashCode(), value.hashCode());
+ }
+}