From 4142a84b686d4bb2f9970d20f4e54a7df192b730 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 26 Oct 2016 11:39:30 +0200 Subject: [PATCH] Rename setters/getters/builders for Compute classes to meet proto conventions (#1322) * Rename setters/getters/builders for Compute classes to meet proto conventions * Update Compute examples, snippets and READMEs to use renamed getters/setters/builders --- README.md | 4 +- google-cloud-compute/README.md | 12 +- .../com/google/cloud/compute/Address.java | 54 +- .../com/google/cloud/compute/AddressId.java | 20 + .../com/google/cloud/compute/AddressInfo.java | 188 ++- .../google/cloud/compute/AttachedDisk.java | 352 ++++- .../com/google/cloud/compute/ComputeImpl.java | 139 +- .../cloud/compute/DeprecationStatus.java | 174 ++- .../java/com/google/cloud/compute/Disk.java | 81 +- .../cloud/compute/DiskConfiguration.java | 48 +- .../java/com/google/cloud/compute/DiskId.java | 43 +- .../cloud/compute/DiskImageConfiguration.java | 46 +- .../com/google/cloud/compute/DiskInfo.java | 168 ++- .../com/google/cloud/compute/DiskType.java | 95 +- .../com/google/cloud/compute/DiskTypeId.java | 40 +- .../cloud/compute/ForwardingRuleId.java | 20 + .../google/cloud/compute/GlobalAddressId.java | 18 +- .../cloud/compute/GlobalForwardingRuleId.java | 20 +- .../cloud/compute/GlobalOperationId.java | 18 +- .../java/com/google/cloud/compute/Image.java | 66 +- .../cloud/compute/ImageConfiguration.java | 32 +- .../cloud/compute/ImageDiskConfiguration.java | 61 +- .../com/google/cloud/compute/ImageId.java | 25 +- .../com/google/cloud/compute/ImageInfo.java | 164 +- .../com/google/cloud/compute/Instance.java | 170 ++- .../com/google/cloud/compute/InstanceId.java | 46 +- .../google/cloud/compute/InstanceInfo.java | 332 +++- .../com/google/cloud/compute/License.java | 12 +- .../com/google/cloud/compute/LicenseId.java | 20 +- .../com/google/cloud/compute/MachineType.java | 133 +- .../google/cloud/compute/MachineTypeId.java | 38 +- .../com/google/cloud/compute/Metadata.java | 54 +- .../com/google/cloud/compute/Network.java | 50 +- .../cloud/compute/NetworkConfiguration.java | 10 + .../com/google/cloud/compute/NetworkId.java | 28 +- .../com/google/cloud/compute/NetworkInfo.java | 109 +- .../cloud/compute/NetworkInterface.java | 214 ++- .../com/google/cloud/compute/Operation.java | 263 +++- .../com/google/cloud/compute/OperationId.java | 14 + .../java/com/google/cloud/compute/Option.java | 4 +- .../java/com/google/cloud/compute/Region.java | 127 +- .../google/cloud/compute/RegionAddressId.java | 38 +- .../cloud/compute/RegionForwardingRuleId.java | 40 +- .../com/google/cloud/compute/RegionId.java | 24 +- .../cloud/compute/RegionOperationId.java | 38 +- .../com/google/cloud/compute/ResourceId.java | 16 + .../cloud/compute/SchedulingOptions.java | 8 + .../google/cloud/compute/ServiceAccount.java | 16 + .../com/google/cloud/compute/Snapshot.java | 72 +- .../compute/SnapshotDiskConfiguration.java | 64 +- .../com/google/cloud/compute/SnapshotId.java | 24 +- .../google/cloud/compute/SnapshotInfo.java | 187 ++- .../compute/StandardDiskConfiguration.java | 29 +- .../compute/StandardNetworkConfiguration.java | 20 + .../compute/StorageImageConfiguration.java | 65 +- .../compute/SubnetNetworkConfiguration.java | 8 + .../com/google/cloud/compute/Subnetwork.java | 58 +- .../google/cloud/compute/SubnetworkId.java | 48 +- .../google/cloud/compute/SubnetworkInfo.java | 151 +- .../java/com/google/cloud/compute/Tags.java | 83 +- .../java/com/google/cloud/compute/Zone.java | 92 +- .../java/com/google/cloud/compute/ZoneId.java | 20 +- .../google/cloud/compute/ZoneOperationId.java | 38 +- .../google/cloud/compute/package-info.java | 4 +- .../compute/testing/RemoteComputeHelper.java | 8 + .../cloud/compute/testing/package-info.java | 2 +- .../google/cloud/compute/AddressIdTest.java | 47 +- .../google/cloud/compute/AddressInfoTest.java | 205 ++- .../com/google/cloud/compute/AddressTest.java | 130 +- .../cloud/compute/AttachedDiskTest.java | 279 ++-- .../google/cloud/compute/ComputeImplTest.java | 1093 ++++++++------ .../cloud/compute/DeprecationStatusTest.java | 132 +- .../com/google/cloud/compute/DiskIdTest.java | 29 +- .../compute/DiskImageConfigurationTest.java | 69 +- .../google/cloud/compute/DiskInfoTest.java | 321 ++-- .../com/google/cloud/compute/DiskTest.java | 235 +-- .../google/cloud/compute/DiskTypeIdTest.java | 25 +- .../google/cloud/compute/DiskTypeTest.java | 43 +- .../cloud/compute/ForwardingRuleIdTest.java | 55 +- .../compute/ImageDiskConfigurationTest.java | 69 +- .../com/google/cloud/compute/ImageIdTest.java | 21 +- .../google/cloud/compute/ImageInfoTest.java | 200 ++- .../com/google/cloud/compute/ImageTest.java | 139 +- .../google/cloud/compute/InstanceIdTest.java | 30 +- .../cloud/compute/InstanceInfoTest.java | 184 ++- .../google/cloud/compute/InstanceTest.java | 290 ++-- .../google/cloud/compute/LicenseIdTest.java | 21 +- .../com/google/cloud/compute/LicenseTest.java | 12 +- .../cloud/compute/MachineTypeIdTest.java | 25 +- .../google/cloud/compute/MachineTypeTest.java | 59 +- .../google/cloud/compute/MetadataTest.java | 43 +- .../google/cloud/compute/NetworkIdTest.java | 21 +- .../google/cloud/compute/NetworkInfoTest.java | 90 +- .../cloud/compute/NetworkInterfaceTest.java | 163 +- .../com/google/cloud/compute/NetworkTest.java | 73 +- .../google/cloud/compute/OperationIdTest.java | 81 +- .../google/cloud/compute/OperationTest.java | 274 ++-- .../google/cloud/compute/RegionIdTest.java | 21 +- .../com/google/cloud/compute/RegionTest.java | 50 +- .../cloud/compute/SchedulingOptionsTest.java | 14 +- .../cloud/compute/SerializationTest.java | 70 +- .../cloud/compute/ServiceAccountTest.java | 10 +- .../SnapshotDiskConfigurationTest.java | 69 +- .../google/cloud/compute/SnapshotIdTest.java | 21 +- .../cloud/compute/SnapshotInfoTest.java | 128 +- .../google/cloud/compute/SnapshotTest.java | 113 +- .../StandardDiskConfigurationTest.java | 50 +- .../StandardNetworkConfigurationTest.java | 24 +- .../StorageImageConfigurationTest.java | 64 +- .../SubnetNetworkConfigurationTest.java | 28 +- .../cloud/compute/SubnetworkIdTest.java | 29 +- .../cloud/compute/SubnetworkInfoTest.java | 76 +- .../google/cloud/compute/SubnetworkTest.java | 45 +- .../com/google/cloud/compute/TagsTest.java | 25 +- .../com/google/cloud/compute/ZoneIdTest.java | 21 +- .../com/google/cloud/compute/ZoneTest.java | 47 +- .../cloud/compute/it/ITComputeTest.java | 1342 +++++++++-------- .../testing/RemoteComputeHelperTest.java | 3 +- .../examples/compute/ComputeExample.java | 219 +-- .../CreateAddressDiskAndInstance.java | 12 +- .../compute/snippets/CreateInstance.java | 2 +- .../compute/snippets/CreateSnapshot.java | 2 +- 122 files changed, 8166 insertions(+), 3442 deletions(-) diff --git a/README.md b/README.md index 0a0d208b028c..3bc2219ab2bd 100644 --- a/README.md +++ b/README.md @@ -222,7 +222,7 @@ if (disk != null) { String snapshotName = "disk-name-snapshot"; Operation operation = disk.createSnapshot(snapshotName); operation = operation.waitFor(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { // use snapshot Snapshot snapshot = compute.getSnapshot(snapshotName); } @@ -252,7 +252,7 @@ MachineTypeId machineTypeId = MachineTypeId.of("us-central1-a", "n1-standard-1") Operation operation = compute.create(InstanceInfo.of(instanceId, machineTypeId, attachedDisk, networkInterface)); operation = operation.waitFor(); -if (operation.errors() == null) { +if (operation.getErrors() == null) { // use instance Instance instance = compute.getInstance(instanceId); } diff --git a/google-cloud-compute/README.md b/google-cloud-compute/README.md index 85385f819c8d..395f22936b0c 100644 --- a/google-cloud-compute/README.md +++ b/google-cloud-compute/README.md @@ -119,7 +119,7 @@ operation = operation.waitFor(); if (operation.errors() == null) { System.out.println("Address " + addressId + " was successfully created"); } else { - // inspect operation.errors() + // inspect operation.getErrors() throw new RuntimeException("Address creation failed"); } ``` @@ -150,7 +150,7 @@ DiskInfo disk = DiskInfo.of(diskId, diskConfiguration); Operation operation = compute.create(disk); // Wait for operation to complete operation = operation.waitFor(); -if (operation.errors() == null) { +if (operation.getErrors() == null) { System.out.println("Disk " + diskId + " was successfully created"); } else { // inspect operation.errors() @@ -185,10 +185,10 @@ Address externalIp = compute.getAddress(addressId); InstanceId instanceId = InstanceId.of("us-central1-a", "test-instance"); NetworkId networkId = NetworkId.of("default"); PersistentDiskConfiguration attachConfiguration = - PersistentDiskConfiguration.builder(diskId).boot(true).build(); + PersistentDiskConfiguration.newBuilder(diskId).setBoot(true).build(); AttachedDisk attachedDisk = AttachedDisk.of("dev0", attachConfiguration); -NetworkInterface networkInterface = NetworkInterface.builder(networkId) - .accessConfigurations(AccessConfig.of(externalIp.address())) +NetworkInterface networkInterface = NetworkInterface.newBuilder(networkId) + .setAccessConfigurations(AccessConfig.of(externalIp.getAddress())) .build(); MachineTypeId machineTypeId = MachineTypeId.of("us-central1-a", "n1-standard-1"); InstanceInfo instance = @@ -196,7 +196,7 @@ InstanceInfo instance = Operation operation = compute.create(instance); // Wait for operation to complete operation = operation.waitFor(); -if (operation.errors() == null) { +if (operation.getErrors() == null) { System.out.println("Instance " + instanceId + " was successfully created"); } else { // inspect operation.errors() diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/Address.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/Address.java index 10e99cadb60f..1c40e44dcd26 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/Address.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/Address.java @@ -56,7 +56,7 @@ public static class Builder extends AddressInfo.Builder { Builder(Compute compute, AddressId addressId) { this.compute = compute; this.infoBuilder = new AddressInfo.BuilderImpl(); - this.infoBuilder.addressId(addressId); + this.infoBuilder.setAddressId(addressId); } Builder(Address address) { @@ -65,44 +65,62 @@ public static class Builder extends AddressInfo.Builder { } @Override + @Deprecated public Builder address(String address) { - infoBuilder.address(address); + return setAddress(address); + } + + @Override + public Builder setAddress(String address) { + infoBuilder.setAddress(address); return this; } @Override - Builder creationTimestamp(Long creationTimestamp) { - infoBuilder.creationTimestamp(creationTimestamp); + Builder setCreationTimestamp(Long creationTimestamp) { + infoBuilder.setCreationTimestamp(creationTimestamp); return this; } @Override + @Deprecated public Builder description(String description) { - infoBuilder.description(description); + return setDescription(description); + } + + @Override + public Builder setDescription(String description) { + infoBuilder.setDescription(description); return this; } @Override - Builder generatedId(String generatedId) { - infoBuilder.generatedId(generatedId); + Builder setGeneratedId(String generatedId) { + infoBuilder.setGeneratedId(generatedId); return this; } @Override + @Deprecated public Builder addressId(AddressId addressId) { - infoBuilder.addressId(addressId); + return setAddressId(addressId); + } + + @Override + public Builder setAddressId(AddressId addressId) { + infoBuilder.setAddressId(addressId); return this; } @Override - Builder status(Status status) { - infoBuilder.status(status); + Builder setStatus(Status status) { + infoBuilder.setStatus(status); return this; } @Override - Builder usage(Usage usage) { - infoBuilder.usage(usage); + Builder setUsage(Usage usage) { + infoBuilder.setUsage(usage); return this; } @@ -137,7 +155,7 @@ public boolean exists() { * @throws ComputeException upon failure */ public Address reload(AddressOption... options) { - return compute.getAddress(addressId(), options); + return compute.getAddress(getAddressId(), options); } /** @@ -148,13 +166,21 @@ public Address reload(AddressOption... options) { * @throws ComputeException upon failure */ public Operation delete(OperationOption... options) { - return compute.deleteAddress(addressId(), options); + return compute.deleteAddress(getAddressId(), options); } /** * Returns the address's {@code Compute} object used to issue requests. */ + @Deprecated public Compute compute() { + return getCompute(); + } + + /** + * Returns the address's {@code Compute} object used to issue requests. + */ + public Compute getCompute() { return compute; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/AddressId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/AddressId.java index e5440e6f6d34..756955bb1065 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/AddressId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/AddressId.java @@ -54,8 +54,14 @@ enum Type { /** * Returns the type of this address identity. */ + @Deprecated public abstract Type type(); + /** + * Returns the type of this address identity. + */ + public abstract Type getType(); + /** * Returns the name of the address resource. The name must be 1-63 characters long and comply with * RFC1035. Specifically, the name must match the regular expression @@ -65,7 +71,21 @@ enum Type { * * @see RFC1035 */ + @Deprecated public String address() { + return getAddress(); + } + + /** + * Returns the name of the address resource. The name must be 1-63 characters long and comply with + * RFC1035. Specifically, the name must match the regular expression + * {@code [a-z]([-a-z0-9]*[a-z0-9])?} which means the first character must be a lowercase letter, + * and all following characters must be a dash, lowercase letter, or digit, except the last + * character, which cannot be a dash. + * + * @see RFC1035 + */ + public String getAddress() { return address; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/AddressInfo.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/AddressInfo.java index 9a95c77119c8..b0f6e2716d3c 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/AddressInfo.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/AddressInfo.java @@ -106,17 +106,23 @@ public abstract static class Usage implements Serializable { /** * Returns the identities of resources currently using this address. */ + @Deprecated public abstract List users(); + /** + * Returns the identities of resources currently using this address. + */ + public abstract List getUsers(); + final boolean baseEquals(Usage usage) { return Objects.equals(toPb(), usage.toPb()); } Address toPb() { - return new Address().setUsers(Lists.transform(users(), new Function() { + return new Address().setUsers(Lists.transform(getUsers(), new Function() { @Override public String apply(ResourceId resourceId) { - return resourceId.selfLink(); + return resourceId.getSelfLink(); } })); } @@ -153,12 +159,26 @@ public static final class InstanceUsage extends Usage { /** * Returns the identity of the instance using the address. */ + @Deprecated public InstanceId instance() { + return getInstance(); + } + + /** + * Returns the identity of the instance using the address. + */ + public InstanceId getInstance() { return instance; } @Override + @Deprecated public List users() { + return getUsers(); + } + + @Override + public List getUsers() { return ImmutableList.of(instance); } @@ -200,12 +220,26 @@ public static final class RegionForwardingUsage extends Usage { /** * Returns a list of identities of region forwarding rules that are currently using the address. */ + @Deprecated public List forwardingRules() { + return getForwardingRules(); + } + + /** + * Returns a list of identities of region forwarding rules that are currently using the address. + */ + public List getForwardingRules() { return forwardingRules; } @Override + @Deprecated public List users() { + return getUsers(); + } + + @Override + public List getUsers() { return forwardingRules; } @@ -248,12 +282,26 @@ public static final class GlobalForwardingUsage extends Usage { /** * Returns a list of identities of global forwarding rules that are currently using the address. */ + @Deprecated public List forwardingRules() { + return getForwardingRules(); + } + + /** + * Returns a list of identities of global forwarding rules that are currently using the address. + */ + public List getForwardingRules() { return forwardingRules; } @Override + @Deprecated public List users() { + return getUsers(); + } + + @Override + public List getUsers() { return forwardingRules; } @@ -287,22 +335,37 @@ public abstract static class Builder { /** * Sets the actual IP address. */ + @Deprecated public abstract Builder address(String address); - abstract Builder creationTimestamp(Long creationTimestamp); + /** + * Sets the actual IP address. + */ + public abstract Builder setAddress(String address); + + abstract Builder setCreationTimestamp(Long creationTimestamp); /** * Sets an optional textual description of the address. */ + @Deprecated public abstract Builder description(String description); - abstract Builder generatedId(String generatedId); + /** + * Sets an optional textual description of the address. + */ + public abstract Builder setDescription(String description); + + abstract Builder setGeneratedId(String generatedId); + @Deprecated public abstract Builder addressId(AddressId addressId); - abstract Builder status(Status status); + public abstract Builder setAddressId(AddressId addressId); - abstract Builder usage(Usage usage); + abstract Builder setStatus(Status status); + + abstract Builder setUsage(Usage usage); /** * Creates an {@code AddressInfo} object. @@ -355,43 +418,61 @@ static final class BuilderImpl extends Builder { } @Override + @Deprecated public BuilderImpl address(String address) { + return setAddress(address); + } + + @Override + public BuilderImpl setAddress(String address) { this.address = address; return this; } @Override - BuilderImpl creationTimestamp(Long creationTimestamp) { + BuilderImpl setCreationTimestamp(Long creationTimestamp) { this.creationTimestamp = creationTimestamp; return this; } @Override + @Deprecated public BuilderImpl description(String description) { + return setDescription(description); + } + + @Override + public BuilderImpl setDescription(String description) { this.description = description; return this; } @Override - BuilderImpl generatedId(String generatedId) { + BuilderImpl setGeneratedId(String generatedId) { this.generatedId = generatedId; return this; } @Override + @Deprecated public BuilderImpl addressId(AddressId addressId) { + return setAddressId(addressId); + } + + @Override + public BuilderImpl setAddressId(AddressId addressId) { this.addressId = checkNotNull(addressId); return this; } @Override - BuilderImpl status(Status status) { + BuilderImpl setStatus(Status status) { this.status = status; return this; } @Override - BuilderImpl usage(Usage usage) { + BuilderImpl setUsage(Usage usage) { this.usage = usage; return this; } @@ -415,28 +496,60 @@ public AddressInfo build() { /** * Returns the static external IP address represented by this object. */ + @Deprecated public String address() { + return getAddress(); + } + + /** + * Returns the static external IP address represented by this object. + */ + public String getAddress() { return address; } /** * Returns the creation timestamp in milliseconds since epoch. */ + @Deprecated public Long creationTimestamp() { + return getCreationTimestamp(); + } + + /** + * Returns the creation timestamp in milliseconds since epoch. + */ + public Long getCreationTimestamp() { return creationTimestamp; } /** * Returns an optional textual description of the address. */ + @Deprecated public String description() { + return getDescription(); + } + + /** + * Returns an optional textual description of the address. + */ + public String getDescription() { return description; } /** * Returns the service-generated unique identifier for the address. */ + @Deprecated public String generatedId() { + return getGeneratedId(); + } + + /** + * Returns the service-generated unique identifier for the address. + */ + public String getGeneratedId() { return generatedId; } @@ -445,14 +558,32 @@ public String generatedId() { * {@link RegionAddressId} for a region address. */ @SuppressWarnings("unchecked") + @Deprecated public T addressId() { + return getAddressId(); + } + + /** + * Returns the address identity. Returns {@link GlobalAddressId} for a global address, returns + * {@link RegionAddressId} for a region address. + */ + @SuppressWarnings("unchecked") + public T getAddressId() { return (T) addressId; } /** * Returns the status of the address. */ + @Deprecated public Status status() { + return getStatus(); + } + + /** + * Returns the status of the address. + */ + public Status getStatus() { return status; } @@ -464,7 +595,20 @@ public Status status() { * Returns {@code null} if the address is not in use. */ @SuppressWarnings("unchecked") + @Deprecated public T usage() { + return getUsage(); + } + + /** + * Returns the usage information of the address. Returns an {@link InstanceUsage} object for + * region addresses that are assigned to VM instances. Returns a {@link RegionForwardingUsage} + * object for region addresses assigned to region forwarding rules. Returns a + * {@link GlobalForwardingUsage} object for global addresses assigned to global forwarding rules. + * Returns {@code null} if the address is not in use. + */ + @SuppressWarnings("unchecked") + public T getUsage() { return (T) usage; } @@ -503,10 +647,10 @@ public boolean equals(Object obj) { } AddressInfo setProjectId(String projectId) { - if (addressId().project() != null) { + if (getAddressId().getProject() != null) { return this; } - return toBuilder().addressId(addressId.setProjectId(projectId)).build(); + return toBuilder().setAddressId(addressId.setProjectId(projectId)).build(); } Address toPb() { @@ -519,29 +663,37 @@ Address toPb() { if (generatedId != null) { addressPb.setId(new BigInteger(generatedId)); } - addressPb.setName(addressId.address()); - if (addressId.type() == AddressId.Type.REGION) { - addressPb.setRegion(this.addressId().regionId().selfLink()); + addressPb.setName(addressId.getAddress()); + if (addressId.getType() == AddressId.Type.REGION) { + addressPb.setRegion(this.getAddressId().getRegionId().getSelfLink()); } if (status != null) { addressPb.setStatus(status.name()); } - addressPb.setSelfLink(addressId.selfLink()); + addressPb.setSelfLink(addressId.getSelfLink()); return addressPb; } /** * Returns a builder for the {@code AddressInfo} object given it's identity. */ + @Deprecated public static Builder builder(AddressId addressId) { - return new BuilderImpl().addressId(addressId); + return newBuilder(addressId); + } + + /** + * Returns a builder for the {@code AddressInfo} object given it's identity. + */ + public static Builder newBuilder(AddressId addressId) { + return new BuilderImpl().setAddressId(addressId); } /** * Returns an {@code AddressInfo} object for the provided identity. */ public static AddressInfo of(AddressId addressId) { - return builder(addressId).build(); + return newBuilder(addressId).build(); } /** diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/AttachedDisk.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/AttachedDisk.java index d4ad674a8a5e..fc4d0181bed0 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/AttachedDisk.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/AttachedDisk.java @@ -114,7 +114,15 @@ public enum InterfaceType { /** * Returns the type of the attached disk. */ + @Deprecated public Type type() { + return getType(); + } + + /** + * Returns the type of the attached disk. + */ + public Type getType() { return type; } @@ -122,7 +130,16 @@ public Type type() { * Returns the interface to use to attach the disk. If not specified, {@link InterfaceType#SCSI} * is used. */ + @Deprecated public InterfaceType interfaceType() { + return getInterfaceType(); + } + + /** + * Returns the interface to use to attach the disk. If not specified, {@link InterfaceType#SCSI} + * is used. + */ + public InterfaceType getInterfaceType() { return interfaceType; } @@ -246,7 +263,15 @@ private Builder(PersistentDiskConfiguration configuration) { /** * Sets the identity of the persistent disk to be attached. */ + @Deprecated public Builder sourceDisk(DiskId sourceDisk) { + return setSourceDisk(sourceDisk); + } + + /** + * Sets the identity of the persistent disk to be attached. + */ + public Builder setSourceDisk(DiskId sourceDisk) { this.sourceDisk = checkNotNull(sourceDisk); return this; } @@ -255,7 +280,16 @@ public Builder sourceDisk(DiskId sourceDisk) { * Sets the mode in which to attach this disk. If not specified, the disk is attached in * {@link Mode#READ_WRITE} mode. */ + @Deprecated public Builder mode(Mode mode) { + return setMode(mode); + } + + /** + * Sets the mode in which to attach this disk. If not specified, the disk is attached in + * {@link Mode#READ_WRITE} mode. + */ + public Builder setMode(Mode mode) { this.mode = mode; return this; } @@ -265,7 +299,17 @@ public Builder mode(Mode mode) { * instance will use the first partition of the disk for its root filesystem. If not * specified, the isk is not used as a boot disk. */ + @Deprecated public Builder boot(boolean boot) { + return setBoot(boot); + } + + /** + * Sets whether to use the attached disk as a boot disk. If {@code true} the virtual machine + * instance will use the first partition of the disk for its root filesystem. If not + * specified, the isk is not used as a boot disk. + */ + public Builder setBoot(boolean boot) { this.boot = boot; return this; } @@ -274,7 +318,16 @@ public Builder boot(boolean boot) { * Sets whether the disk should auto-delete when the instance to which it's attached is * deleted. If not specified, the disk is not deleted automatically. */ + @Deprecated public Builder autoDelete(boolean autoDelete) { + return setAutoDelete(autoDelete); + } + + /** + * Sets whether the disk should auto-delete when the instance to which it's attached is + * deleted. If not specified, the disk is not deleted automatically. + */ + public Builder setAutoDelete(boolean autoDelete) { this.autoDelete = autoDelete; return this; } @@ -296,7 +349,15 @@ private PersistentDiskConfiguration(Builder builder) { /** * Returns the identity of the persistent disk to be attached. */ + @Deprecated public DiskId sourceDisk() { + return getSourceDisk(); + } + + /** + * Returns the identity of the persistent disk to be attached. + */ + public DiskId getSourceDisk() { return sourceDisk; } @@ -304,7 +365,16 @@ public DiskId sourceDisk() { * Returns the mode in which to attach this disk. If not specified, the disk is attached in * {@link Mode#READ_WRITE} mode. */ + @Deprecated public Mode mode() { + return getMode(); + } + + /** + * Returns the mode in which to attach this disk. If not specified, the disk is attached in + * {@link Mode#READ_WRITE} mode. + */ + public Mode getMode() { return mode; } @@ -335,16 +405,16 @@ public boolean equals(Object obj) { @Override PersistentDiskConfiguration setProjectId(String projectId) { - if (sourceDisk.project() != null) { + if (sourceDisk.getProject() != null) { return this; } - return toBuilder().sourceDisk(sourceDisk.setProjectId(projectId)).build(); + return toBuilder().setSourceDisk(sourceDisk.setProjectId(projectId)).build(); } @Override com.google.api.services.compute.model.AttachedDisk toPb() { com.google.api.services.compute.model.AttachedDisk attachedDiskPb = super.toPb(); - attachedDiskPb.setSource(sourceDisk.selfLink()); + attachedDiskPb.setSource(sourceDisk.getSelfLink()); attachedDiskPb.setMode(mode != null ? mode.toString() : null); return attachedDiskPb; } @@ -353,7 +423,16 @@ com.google.api.services.compute.model.AttachedDisk toPb() { * Returns a builder for a {@code PersistentDiskConfiguration} object given the identity of the * persistent disk to attach. */ + @Deprecated public static Builder builder(DiskId sourceDisk) { + return newBuilder(sourceDisk); + } + + /** + * Returns a builder for a {@code PersistentDiskConfiguration} object given the identity of the + * persistent disk to attach. + */ + public static Builder newBuilder(DiskId sourceDisk) { return new Builder(sourceDisk); } @@ -362,7 +441,7 @@ public static Builder builder(DiskId sourceDisk) { * disk to attach. */ public static PersistentDiskConfiguration of(DiskId sourceDisk) { - return builder(sourceDisk).build(); + return newBuilder(sourceDisk).build(); } @SuppressWarnings("unchecked") @@ -370,13 +449,13 @@ static PersistentDiskConfiguration fromPb( com.google.api.services.compute.model.AttachedDisk diskPb) { Builder builder = new Builder(DiskId.fromUrl(diskPb.getSource())); if (diskPb.getMode() != null) { - builder.mode(Mode.valueOf(diskPb.getMode())); + builder.setMode(Mode.valueOf(diskPb.getMode())); } if (diskPb.getBoot() != null) { - builder.boot(diskPb.getBoot()); + builder.setBoot(diskPb.getBoot()); } if (diskPb.getAutoDelete() != null) { - builder.autoDelete(diskPb.getAutoDelete()); + builder.setAutoDelete(diskPb.getAutoDelete()); } return builder.build(); } @@ -425,7 +504,16 @@ private Builder(CreateDiskConfiguration configuration) { * Sets the name to be assigned to the disk. If not specified, the disk is given the * instance's name. */ + @Deprecated public Builder diskName(String diskName) { + return setDiskName(diskName); + } + + /** + * Sets the name to be assigned to the disk. If not specified, the disk is given the + * instance's name. + */ + public Builder setDiskName(String diskName) { this.diskName = diskName; return this; } @@ -433,7 +521,15 @@ public Builder diskName(String diskName) { /** * Sets the identity of the disk type. If not specified, {@code pd-standard} is used. */ + @Deprecated public Builder diskType(DiskTypeId diskType) { + return setDiskType(diskType); + } + + /** + * Sets the identity of the disk type. If not specified, {@code pd-standard} is used. + */ + public Builder setDiskType(DiskTypeId diskType) { this.diskType = diskType; return this; } @@ -443,7 +539,17 @@ public Builder diskType(DiskTypeId diskType) { * source image. This value can be larger than the image's size. If the provided size is * smaller than the image's size, then instance creation will fail. */ + @Deprecated public Builder diskSizeGb(Long diskSizeGb) { + return setDiskSizeGb(diskSizeGb); + } + + /** + * Sets the size of the persistent disk, in GB. If not set the disk will have the size of the + * source image. This value can be larger than the image's size. If the provided size is + * smaller than the image's size, then instance creation will fail. + */ + public Builder setDiskSizeGb(Long diskSizeGb) { this.diskSizeGb = diskSizeGb; return this; } @@ -451,7 +557,15 @@ public Builder diskSizeGb(Long diskSizeGb) { /** * Sets the identity of the source image used to create the disk. */ + @Deprecated public Builder sourceImage(ImageId sourceImage) { + return setSourceImage(sourceImage); + } + + /** + * Sets the identity of the source image used to create the disk. + */ + public Builder setSourceImage(ImageId sourceImage) { this.sourceImage = checkNotNull(sourceImage); return this; } @@ -460,7 +574,16 @@ public Builder sourceImage(ImageId sourceImage) { * Sets whether the disk should auto-delete when the instance to which it's attached is * deleted. If not specified, the disk is not deleted automatically. */ + @Deprecated public Builder autoDelete(Boolean autoDelete) { + return setAutoDelete(autoDelete); + } + + /** + * Sets whether the disk should auto-delete when the instance to which it's attached is + * deleted. If not specified, the disk is not deleted automatically. + */ + public Builder setAutoDelete(Boolean autoDelete) { this.autoDelete = autoDelete; return this; } @@ -485,14 +608,31 @@ private CreateDiskConfiguration(Builder builder) { * Returns the name to be assigned to the disk. If not specified, the disk is given the * instance's name. */ + @Deprecated public String diskName() { + return getDiskName(); + } + + /** + * Returns the name to be assigned to the disk. If not specified, the disk is given the + * instance's name. + */ + public String getDiskName() { return diskName; } /** * Returns the identity of the disk type. If not specified, {@code pd-standard} is used. */ + @Deprecated public DiskTypeId diskType() { + return getDiskType(); + } + + /** + * Returns the identity of the disk type. If not specified, {@code pd-standard} is used. + */ + public DiskTypeId getDiskType() { return diskType; } @@ -501,14 +641,32 @@ public DiskTypeId diskType() { * source image. This value can be larger than the image's size. If the provided size is smaller * than the image's size then instance creation will fail. */ + @Deprecated public Long diskSizeGb() { + return getDiskSizeGb(); + } + + /** + * Returns the size of the persistent disk, in GB. If not set the disk will have the size of the + * source image. This value can be larger than the image's size. If the provided size is smaller + * than the image's size then instance creation will fail. + */ + public Long getDiskSizeGb() { return diskSizeGb; } /** * Returns the identity of the source image used to create the disk. */ + @Deprecated public ImageId sourceImage() { + return getSourceImage(); + } + + /** + * Returns the identity of the source image used to create the disk. + */ + public ImageId getSourceImage() { return sourceImage; } @@ -545,10 +703,10 @@ public boolean equals(Object obj) { CreateDiskConfiguration setProjectId(String projectId) { Builder builder = toBuilder(); if (builder.diskType != null) { - builder.diskType(diskType.setProjectId(projectId)); + builder.setDiskType(diskType.setProjectId(projectId)); } if (builder.sourceImage != null) { - builder.sourceImage(sourceImage.setProjectId(projectId)); + builder.setSourceImage(sourceImage.setProjectId(projectId)); } return builder.build(); } @@ -558,9 +716,9 @@ com.google.api.services.compute.model.AttachedDisk toPb() { AttachedDiskInitializeParams initializeParamsPb = new AttachedDiskInitializeParams(); initializeParamsPb.setDiskName(diskName); initializeParamsPb.setDiskSizeGb(diskSizeGb); - initializeParamsPb.setSourceImage(sourceImage.selfLink()); + initializeParamsPb.setSourceImage(sourceImage.getSelfLink()); if (diskType != null) { - initializeParamsPb.setDiskType(diskType.selfLink()); + initializeParamsPb.setDiskType(diskType.getSelfLink()); } com.google.api.services.compute.model.AttachedDisk attachedDiskPb = super.toPb(); attachedDiskPb.setInitializeParams(initializeParamsPb); @@ -571,7 +729,16 @@ com.google.api.services.compute.model.AttachedDisk toPb() { * Returns a builder for a {@code CreateDiskConfiguration} object given the source image that * will be used to create the disk. */ + @Deprecated public static Builder builder(ImageId sourceImage) { + return newBuilder(sourceImage); + } + + /** + * Returns a builder for a {@code CreateDiskConfiguration} object given the source image that + * will be used to create the disk. + */ + public static Builder newBuilder(ImageId sourceImage) { return new Builder(sourceImage); } @@ -580,22 +747,22 @@ public static Builder builder(ImageId sourceImage) { * create the disk. */ public static CreateDiskConfiguration of(ImageId sourceImage) { - return builder(sourceImage).build(); + return newBuilder(sourceImage).build(); } @SuppressWarnings("unchecked") static CreateDiskConfiguration fromPb( com.google.api.services.compute.model.AttachedDisk diskPb) { AttachedDiskInitializeParams initializeParamsPb = diskPb.getInitializeParams(); - Builder builder = builder(ImageId.fromUrl(initializeParamsPb.getSourceImage())); + Builder builder = newBuilder(ImageId.fromUrl(initializeParamsPb.getSourceImage())); if (initializeParamsPb.getDiskType() != null) { - builder.diskType(DiskTypeId.fromUrl(initializeParamsPb.getDiskType())); + builder.setDiskType(DiskTypeId.fromUrl(initializeParamsPb.getDiskType())); } - builder.diskName(initializeParamsPb.getDiskName()); - builder.diskSizeGb(initializeParamsPb.getDiskSizeGb()); - builder.autoDelete(diskPb.getAutoDelete()); + builder.setDiskName(initializeParamsPb.getDiskName()); + builder.setDiskSizeGb(initializeParamsPb.getDiskSizeGb()); + builder.setAutoDelete(diskPb.getAutoDelete()); if (initializeParamsPb.getDiskType() != null) { - builder.diskType(DiskTypeId.fromUrl(initializeParamsPb.getDiskType())); + builder.setDiskType(DiskTypeId.fromUrl(initializeParamsPb.getDiskType())); } return builder.build(); } @@ -623,13 +790,21 @@ private Builder() {} private Builder(ScratchDiskConfiguration configuration) { this.diskType = configuration.diskType; - this.interfaceType = configuration.interfaceType(); + this.interfaceType = configuration.getInterfaceType(); } /** * Sets the identity of the disk type for the scratch disk to attach. */ + @Deprecated public Builder diskType(DiskTypeId diskType) { + return setDiskType(diskType); + } + + /** + * Sets the identity of the disk type for the scratch disk to attach. + */ + public Builder setDiskType(DiskTypeId diskType) { this.diskType = diskType; return this; } @@ -637,7 +812,15 @@ public Builder diskType(DiskTypeId diskType) { /** * Sets the interface type. If not specified, {@code SCSI} is used. */ + @Deprecated public Builder interfaceType(InterfaceType interfaceType) { + return setInterfaceType(interfaceType); + } + + /** + * Sets the interface type. If not specified, {@code SCSI} is used. + */ + public Builder setInterfaceType(InterfaceType interfaceType) { this.interfaceType = interfaceType; return this; } @@ -658,10 +841,18 @@ private ScratchDiskConfiguration(Builder builder) { /** * Returns the identity of the disk type for the scratch disk to attach. */ + @Deprecated public DiskTypeId diskType() { return diskType; } + /** + * Returns the identity of the disk type for the scratch disk to attach. + */ + public DiskTypeId getDiskType() { + return diskType; + } + /** * Returns a builder for the current configuration. */ @@ -689,10 +880,10 @@ public boolean equals(Object obj) { @Override ScratchDiskConfiguration setProjectId(String projectId) { - if (diskType.project() != null) { + if (diskType.getProject() != null) { return this; } - return toBuilder().diskType(diskType.setProjectId(projectId)).build(); + return toBuilder().setDiskType(diskType.setProjectId(projectId)).build(); } @Override @@ -700,7 +891,7 @@ com.google.api.services.compute.model.AttachedDisk toPb() { com.google.api.services.compute.model.AttachedDisk attachedDiskPb = super.toPb(); if (diskType != null) { AttachedDiskInitializeParams initializeParamsPb = new AttachedDiskInitializeParams(); - initializeParamsPb.setDiskType(diskType.selfLink()); + initializeParamsPb.setDiskType(diskType.getSelfLink()); attachedDiskPb.setInitializeParams(initializeParamsPb); } return attachedDiskPb; @@ -709,8 +900,16 @@ com.google.api.services.compute.model.AttachedDisk toPb() { /** * Returns a builder for {@code ScratchDiskConfiguration} objects given the disk type identity. */ + @Deprecated public static Builder builder(DiskTypeId diskType) { - return new Builder().diskType(diskType); + return newBuilder(diskType); + } + + /** + * Returns a builder for {@code ScratchDiskConfiguration} objects given the disk type identity. + */ + public static Builder newBuilder(DiskTypeId diskType) { + return new Builder().setDiskType(diskType); } /** @@ -718,7 +917,7 @@ public static Builder builder(DiskTypeId diskType) { * be attached via the default interface ({@link InterfaceType#SCSI}). */ public static ScratchDiskConfiguration of(DiskTypeId diskType) { - return builder(diskType).build(); + return newBuilder(diskType).build(); } @SuppressWarnings("unchecked") @@ -726,11 +925,11 @@ static ScratchDiskConfiguration fromPb( com.google.api.services.compute.model.AttachedDisk diskPb) { Builder builder = new Builder(); if (diskPb.getInterface() != null) { - builder.interfaceType(InterfaceType.valueOf(diskPb.getInterface())); + builder.setInterfaceType(InterfaceType.valueOf(diskPb.getInterface())); } if (diskPb.getInitializeParams() != null && diskPb.getInitializeParams().getDiskType() != null) { - builder.diskType(DiskTypeId.fromUrl(diskPb.getInitializeParams().getDiskType())); + builder.setDiskType(DiskTypeId.fromUrl(diskPb.getInitializeParams().getDiskType())); } return builder.build(); } @@ -765,7 +964,20 @@ public static final class Builder { * apply to this disk, in the form {@code persistent-disks-x}, where x is a number assigned by * Google Compute Engine. */ + @Deprecated public Builder deviceName(String deviceName) { + return setDeviceName(deviceName); + } + + /** + * Sets the unique device name of your choice that is reflected into the + * {@code /dev/disk/by-id/google-*} tree of a Linux operating system running within the + * instance. This name can be used to reference the device for mounting, resizing, and so on, + * from within the instance. If not specified, the service chooses a default device name to + * apply to this disk, in the form {@code persistent-disks-x}, where x is a number assigned by + * Google Compute Engine. + */ + public Builder setDeviceName(String deviceName) { this.deviceName = deviceName; return this; } @@ -775,7 +987,17 @@ public Builder deviceName(String deviceName) { * if you have many disks attached to an instance, each disk would have an unique index number. * If not specified, the service will choose an appropriate value. */ + @Deprecated public Builder index(Integer index) { + return setIndex(index); + } + + /** + * Sets a zero-based index to this disk, where 0 is reserved for the boot disk. For example, + * if you have many disks attached to an instance, each disk would have an unique index number. + * If not specified, the service will choose an appropriate value. + */ + public Builder setIndex(Integer index) { this.index = index; return this; } @@ -786,12 +1008,23 @@ public Builder index(Integer index) { * persistent disk to the instance. Use {@link CreateDiskConfiguration} to create and attach * a new persistent disk. */ + @Deprecated public Builder configuration(AttachedDiskConfiguration configuration) { + return setConfiguration(configuration); + } + + /** + * Sets the attached disk configuration. Use {@link ScratchDiskConfiguration} to attach a + * scratch disk to the instance. Use {@link PersistentDiskConfiguration} to attach a + * persistent disk to the instance. Use {@link CreateDiskConfiguration} to create and attach + * a new persistent disk. + */ + public Builder setConfiguration(AttachedDiskConfiguration configuration) { this.configuration = checkNotNull(configuration); return this; } - Builder licenses(List licenses) { + Builder setLicenses(List licenses) { this.licenses = licenses; return this; } @@ -819,14 +1052,35 @@ private AttachedDisk(Builder builder) { * apply to this disk, in the form {@code persistent-disks-x}, where x is a number assigned by * Google Compute Engine. */ + @Deprecated public String deviceName() { + return getDeviceName(); + } + + /** + * Returns the unique device name of your choice that is reflected into the + * {@code /dev/disk/by-id/google-*} tree of a Linux operating system running within the + * instance. This name can be used to reference the device for mounting, resizing, and so on, + * from within the instance. If not specified, the service chooses a default device name to + * apply to this disk, in the form {@code persistent-disks-x}, where x is a number assigned by + * Google Compute Engine. + */ + public String getDeviceName() { return deviceName; } /** * Returns a zero-based index to this disk, where 0 is reserved for the boot disk. */ + @Deprecated public Integer index() { + return getIndex(); + } + + /** + * Returns a zero-based index to this disk, where 0 is reserved for the boot disk. + */ + public Integer getIndex() { return index; } @@ -837,14 +1091,34 @@ public Integer index() { * a new persistent disk. */ @SuppressWarnings("unchecked") + @Deprecated public T configuration() { + return getConfiguration(); + } + + /** + * Returns the attached disk configuration. Returns {@link ScratchDiskConfiguration} to attach a + * scratch disk to the instance. Returns {@link PersistentDiskConfiguration} to attach a + * persistent disk to the instance. Returns {@link CreateDiskConfiguration} to create and attach + * a new persistent disk. + */ + @SuppressWarnings("unchecked") + public T getConfiguration() { return (T) configuration; } /** * Returns a list of publicly accessible licenses for the attached disk. */ + @Deprecated public List licenses() { + return getLicenses(); + } + + /** + * Returns a list of publicly accessible licenses for the attached disk. + */ + public List getLicenses() { return licenses; } @@ -879,7 +1153,7 @@ public final boolean equals(Object obj) { } AttachedDisk setProjectId(String projectId) { - return toBuilder().configuration(configuration.setProjectId(projectId)).build(); + return toBuilder().setConfiguration(configuration.setProjectId(projectId)).build(); } com.google.api.services.compute.model.AttachedDisk toPb() { @@ -895,31 +1169,39 @@ com.google.api.services.compute.model.AttachedDisk toPb() { /** * Returns a builder for an {@code AttachedDisk} object given its configuration. */ + @Deprecated public static Builder builder(AttachedDiskConfiguration configuration) { - return new Builder(configuration).configuration(configuration); + return newBuilder(configuration); + } + + /** + * Returns a builder for an {@code AttachedDisk} object given its configuration. + */ + public static Builder newBuilder(AttachedDiskConfiguration configuration) { + return new Builder(configuration); } /** * Returns an {@code AttachedDisk} object given its configuration. */ public static AttachedDisk of(AttachedDiskConfiguration configuration) { - return builder(configuration).build(); + return newBuilder(configuration).build(); } /** * Returns an {@code AttachedDisk} object given the device name and its configuration. */ public static AttachedDisk of(String deviceName, AttachedDiskConfiguration configuration) { - return builder(configuration).deviceName(deviceName).build(); + return newBuilder(configuration).setDeviceName(deviceName).build(); } static AttachedDisk fromPb(com.google.api.services.compute.model.AttachedDisk diskPb) { AttachedDiskConfiguration configuration = AttachedDiskConfiguration.fromPb(diskPb); - Builder builder = builder(configuration); - builder.deviceName(diskPb.getDeviceName()); - builder.index(diskPb.getIndex()); + Builder builder = newBuilder(configuration); + builder.setDeviceName(diskPb.getDeviceName()); + builder.setIndex(diskPb.getIndex()); if (diskPb.getLicenses() != null) { - builder.licenses(Lists.transform(diskPb.getLicenses(), LicenseId.FROM_URL_FUNCTION)); + builder.setLicenses(Lists.transform(diskPb.getLicenses(), LicenseId.FROM_URL_FUNCTION)); } return builder.build(); } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/ComputeImpl.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/ComputeImpl.java index 23501f93bcc6..637b47cc6ff6 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/ComputeImpl.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/ComputeImpl.java @@ -469,7 +469,7 @@ public DiskType getDiskType(final DiskTypeId diskTypeId, DiskTypeOption... optio runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.DiskType call() { - return computeRpc.getDiskType(diskTypeId.zone(), diskTypeId.type(), optionsMap); + return computeRpc.getDiskType(diskTypeId.getZone(), diskTypeId.getType(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : DiskType.fromPb(answer); @@ -557,7 +557,8 @@ public MachineType getMachineType(final MachineTypeId machineType, MachineTypeOp runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.MachineType call() { - return computeRpc.getMachineType(machineType.zone(), machineType.type(), optionsMap); + return computeRpc.getMachineType(machineType.getZone(), machineType.getType(), + optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : MachineType.fromPb(answer); @@ -755,7 +756,8 @@ public License getLicense(LicenseId license, LicenseOption... options) { runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.License call() { - return computeRpc.getLicense(completeId.project(), completeId.license(), optionsMap); + return computeRpc.getLicense(completeId.getProject(), completeId.getLicense(), + optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : License.fromPb(answer); @@ -772,17 +774,17 @@ public Operation getOperation(final OperationId operationId, OperationOption... runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - switch (operationId.type()) { + switch (operationId.getType()) { case REGION: RegionOperationId regionOperationId = (RegionOperationId) operationId; - return computeRpc.getRegionOperation(regionOperationId.region(), - regionOperationId.operation(), optionsMap); + return computeRpc.getRegionOperation(regionOperationId.getRegion(), + regionOperationId.getOperation(), optionsMap); case ZONE: ZoneOperationId zoneOperationId = (ZoneOperationId) operationId; - return computeRpc.getZoneOperation(zoneOperationId.zone(), - zoneOperationId.operation(), optionsMap); + return computeRpc.getZoneOperation(zoneOperationId.getZone(), + zoneOperationId.getOperation(), optionsMap); case GLOBAL: - return computeRpc.getGlobalOperation(operationId.operation(), optionsMap); + return computeRpc.getGlobalOperation(operationId.getOperation(), optionsMap); default: throw new IllegalArgumentException("Unexpected operation identity type"); } @@ -894,17 +896,17 @@ public boolean deleteOperation(final OperationId operation) { return runWithRetries(new Callable() { @Override public Boolean call() { - switch (operation.type()) { + switch (operation.getType()) { case REGION: RegionOperationId regionOperationId = (RegionOperationId) operation; - return computeRpc.deleteRegionOperation(regionOperationId.region(), - regionOperationId.operation()); + return computeRpc.deleteRegionOperation(regionOperationId.getRegion(), + regionOperationId.getOperation()); case ZONE: ZoneOperationId zoneOperationId = (ZoneOperationId) operation; - return computeRpc.deleteZoneOperation(zoneOperationId.zone(), - zoneOperationId.operation()); + return computeRpc.deleteZoneOperation(zoneOperationId.getZone(), + zoneOperationId.getOperation()); case GLOBAL: - return computeRpc.deleteGlobalOperation(operation.operation()); + return computeRpc.deleteGlobalOperation(operation.getOperation()); default: throw new IllegalArgumentException("Unexpected operation identity type"); } @@ -923,13 +925,13 @@ public Address getAddress(final AddressId addressId, AddressOption... options) { runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Address call() { - switch (addressId.type()) { + switch (addressId.getType()) { case REGION: RegionAddressId regionAddressId = (RegionAddressId) addressId; - return computeRpc.getRegionAddress(regionAddressId.region(), - regionAddressId.address(), optionsMap); + return computeRpc.getRegionAddress(regionAddressId.getRegion(), + regionAddressId.getAddress(), optionsMap); case GLOBAL: - return computeRpc.getGlobalAddress(addressId.address(), optionsMap); + return computeRpc.getGlobalAddress(addressId.getAddress(), optionsMap); default: throw new IllegalArgumentException("Unexpected address identity type"); } @@ -951,10 +953,10 @@ public Operation create(final AddressInfo address, OperationOption... options) { runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - switch (address.addressId().type()) { + switch (address.getAddressId().getType()) { case REGION: - RegionAddressId regionAddressId = address.addressId(); - return computeRpc.createRegionAddress(regionAddressId.region(), addressPb, + RegionAddressId regionAddressId = address.getAddressId(); + return computeRpc.createRegionAddress(regionAddressId.getRegion(), addressPb, optionsMap); case GLOBAL: return computeRpc.createGlobalAddress(addressPb, optionsMap); @@ -1076,13 +1078,13 @@ public Operation deleteAddress(final AddressId addressId, OperationOption... opt runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - switch (addressId.type()) { + switch (addressId.getType()) { case REGION: RegionAddressId regionAddressId = (RegionAddressId) addressId; - return computeRpc.deleteRegionAddress(regionAddressId.region(), - regionAddressId.address(), optionsMap); + return computeRpc.deleteRegionAddress(regionAddressId.getRegion(), + regionAddressId.getAddress(), optionsMap); case GLOBAL: - return computeRpc.deleteGlobalAddress(addressId.address(), optionsMap); + return computeRpc.deleteGlobalAddress(addressId.getAddress(), optionsMap); default: throw new IllegalArgumentException("Unexpected address identity type"); } @@ -1103,9 +1105,10 @@ public Operation create(SnapshotInfo snapshot, OperationOption... options) { runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.createSnapshot(completeSnapshot.sourceDisk().zone(), - completeSnapshot.sourceDisk().disk(), completeSnapshot.snapshotId().snapshot(), - completeSnapshot.description(), optionsMap); + return computeRpc.createSnapshot(completeSnapshot.getSourceDisk().getZone(), + completeSnapshot.getSourceDisk().getDisk(), + completeSnapshot.getSnapshotId().getSnapshot(), completeSnapshot.getDescription(), + optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); @@ -1167,7 +1170,7 @@ public Snapshot apply(com.google.api.services.compute.model.Snapshot snapshot) { @Override public Operation deleteSnapshot(SnapshotId snapshot, OperationOption... options) { - return deleteSnapshot(snapshot.snapshot(), options); + return deleteSnapshot(snapshot.getSnapshot(), options); } @Override @@ -1214,7 +1217,7 @@ public Image getImage(ImageId imageId, ImageOption... options) { runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Image call() { - return computeRpc.getImage(completeImageId.project(), completeImageId.image(), + return computeRpc.getImage(completeImageId.getProject(), completeImageId.getImage(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); @@ -1272,7 +1275,8 @@ public Operation deleteImage(ImageId image, OperationOption... options) { runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.deleteImage(completeId.project(), completeId.image(), optionsMap); + return computeRpc.deleteImage(completeId.getProject(), completeId.getImage(), + optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); @@ -1291,7 +1295,7 @@ public Operation deprecate(ImageId image, runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.deprecateImage(completeId.project(), completeId.image(), + return computeRpc.deprecateImage(completeId.getProject(), completeId.getImage(), deprecationStatus.toPb(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); @@ -1309,7 +1313,7 @@ public Disk getDisk(final DiskId diskId, DiskOption... options) { runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Disk call() { - return computeRpc.getDisk(diskId.zone(), diskId.disk(), optionsMap); + return computeRpc.getDisk(diskId.getZone(), diskId.getDisk(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Disk.fromPb(this, answer); @@ -1328,7 +1332,7 @@ public Operation create(final DiskInfo disk, OperationOption... options) { runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.createDisk(disk.diskId().zone(), diskPb, optionsMap); + return computeRpc.createDisk(disk.getDiskId().getZone(), diskPb, optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock())); } catch (RetryHelper.RetryHelperException e) { @@ -1410,7 +1414,7 @@ public Operation deleteDisk(final DiskId disk, OperationOption... options) { runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.deleteDisk(disk.zone(), disk.disk(), optionsMap); + return computeRpc.deleteDisk(disk.getZone(), disk.getDisk(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); @@ -1427,7 +1431,7 @@ public Operation resize(final DiskId disk, final long sizeGb, OperationOption... runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.resizeDisk(disk.zone(), disk.disk(), sizeGb, optionsMap); + return computeRpc.resizeDisk(disk.getZone(), disk.getDisk(), sizeGb, optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); @@ -1444,7 +1448,7 @@ public Operation create(SubnetworkInfo subnetwork, OperationOption... options) { runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.createSubnetwork(completeSubnetwork.subnetworkId().region(), + return computeRpc.createSubnetwork(completeSubnetwork.getSubnetworkId().getRegion(), completeSubnetwork.toPb(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); @@ -1462,8 +1466,8 @@ public Subnetwork getSubnetwork(final SubnetworkId subnetworkId, SubnetworkOptio runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Subnetwork call() { - return computeRpc.getSubnetwork(subnetworkId.region(), subnetworkId.subnetwork(), - optionsMap); + return computeRpc.getSubnetwork(subnetworkId.getRegion(), + subnetworkId.getSubnetwork(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Subnetwork.fromPb(this, answer); @@ -1546,7 +1550,7 @@ public Operation deleteSubnetwork(final SubnetworkId subnetwork, OperationOption runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.deleteSubnetwork(subnetwork.region(), subnetwork.subnetwork(), + return computeRpc.deleteSubnetwork(subnetwork.getRegion(), subnetwork.getSubnetwork(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); @@ -1633,7 +1637,7 @@ public Operation deleteNetwork(final NetworkId network, OperationOption... optio runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.deleteNetwork(network.network(), optionsMap); + return computeRpc.deleteNetwork(network.getNetwork(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); @@ -1656,7 +1660,7 @@ public Operation create(InstanceInfo instance, OperationOption... options) { runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.createInstance(completeInstance.instanceId().zone(), + return computeRpc.createInstance(completeInstance.getInstanceId().getZone(), completeInstance.toPb(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); @@ -1674,7 +1678,7 @@ public Instance getInstance(final InstanceId instance, InstanceOption... options runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Instance call() { - return computeRpc.getInstance(instance.zone(), instance.instance(), optionsMap); + return computeRpc.getInstance(instance.getZone(), instance.getInstance(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Instance.fromPb(this, answer); @@ -1757,7 +1761,8 @@ public Operation deleteInstance(final InstanceId instance, OperationOption... op runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.deleteInstance(instance.zone(), instance.instance(), optionsMap); + return computeRpc.deleteInstance(instance.getZone(), instance.getInstance(), + optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); @@ -1775,7 +1780,7 @@ public Operation addAccessConfig(final InstanceId instance, final String network runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.addAccessConfig(instance.zone(), instance.instance(), + return computeRpc.addAccessConfig(instance.getZone(), instance.getInstance(), networkInterface, accessConfig.toPb(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); @@ -1794,7 +1799,7 @@ private Operation attachDisk(final InstanceId instance, AttachedDisk diskToAttac runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.attachDisk(instance.zone(), instance.instance(), + return computeRpc.attachDisk(instance.getZone(), instance.getInstance(), completeDisk.toPb(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); @@ -1819,9 +1824,9 @@ public Operation attachDisk(InstanceId instance, String deviceName, @Override public Operation attachDisk(InstanceId instance, String deviceName, PersistentDiskConfiguration configuration, int index, OperationOption... options) { - AttachedDisk attachedDisk = AttachedDisk.builder(configuration) - .deviceName(deviceName) - .index(index) + AttachedDisk attachedDisk = AttachedDisk.newBuilder(configuration) + .setDeviceName(deviceName) + .setIndex(index) .build(); return attachDisk(instance, attachedDisk, options); } @@ -1835,7 +1840,7 @@ public Operation deleteAccessConfig(final InstanceId instance, final String netw runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.deleteAccessConfig(instance.zone(), instance.instance(), + return computeRpc.deleteAccessConfig(instance.getZone(), instance.getInstance(), networkInterface, accessConfig, optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); @@ -1854,7 +1859,7 @@ public Operation detachDisk(final InstanceId instance, final String deviceName, runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.detachDisk(instance.zone(), instance.instance(), deviceName, + return computeRpc.detachDisk(instance.getZone(), instance.getInstance(), deviceName, optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); @@ -1870,7 +1875,7 @@ public String getSerialPortOutput(final InstanceId instance, final int port) { return runWithRetries(new Callable() { @Override public String call() { - return computeRpc.getSerialPortOutput(instance.zone(), instance.instance(), port, + return computeRpc.getSerialPortOutput(instance.getZone(), instance.getInstance(), port, optionMap()); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); @@ -1885,7 +1890,7 @@ public String getSerialPortOutput(final InstanceId instance) { return runWithRetries(new Callable() { @Override public String call() { - return computeRpc.getSerialPortOutput(instance.zone(), instance.instance(), null, + return computeRpc.getSerialPortOutput(instance.getZone(), instance.getInstance(), null, optionMap()); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); @@ -1902,7 +1907,7 @@ public Operation reset(final InstanceId instance, OperationOption... options) { runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.reset(instance.zone(), instance.instance(), optionsMap); + return computeRpc.reset(instance.getZone(), instance.getInstance(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); @@ -1920,8 +1925,8 @@ public Operation setDiskAutoDelete(final InstanceId instance, final String devic runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.setDiskAutoDelete(instance.zone(), instance.instance(), deviceName, - autoDelete, optionsMap); + return computeRpc.setDiskAutoDelete(instance.getZone(), instance.getInstance(), + deviceName, autoDelete, optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); @@ -1933,15 +1938,15 @@ public com.google.api.services.compute.model.Operation call() { @Override public Operation setMachineType(final InstanceId instance, final MachineTypeId machineType, OperationOption... options) { - final String machineTypeUrl = machineType.setProjectId(options().projectId()).selfLink(); + final String machineTypeUrl = machineType.setProjectId(options().projectId()).getSelfLink(); final Map optionsMap = optionMap(options); try { com.google.api.services.compute.model.Operation answer = runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.setMachineType(instance.zone(), instance.instance(), machineTypeUrl, - optionsMap); + return computeRpc.setMachineType(instance.getZone(), instance.getInstance(), + machineTypeUrl, optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); @@ -1959,8 +1964,8 @@ public Operation setMetadata(final InstanceId instance, final Metadata metadata, runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.setMetadata(instance.zone(), instance.instance(), metadata.toPb(), - optionsMap); + return computeRpc.setMetadata(instance.getZone(), instance.getInstance(), + metadata.toPb(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); @@ -1978,7 +1983,7 @@ public Operation setSchedulingOptions(final InstanceId instance, runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.setScheduling(instance.zone(), instance.instance(), + return computeRpc.setScheduling(instance.getZone(), instance.getInstance(), schedulingOptions.toPb(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); @@ -1996,7 +2001,7 @@ public Operation setTags(final InstanceId instance, final Tags tags, OperationOp runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.setTags(instance.zone(), instance.instance(), tags.toPb(), + return computeRpc.setTags(instance.getZone(), instance.getInstance(), tags.toPb(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); @@ -2014,7 +2019,7 @@ public Operation start(final InstanceId instance, OperationOption... options) { runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.start(instance.zone(), instance.instance(), optionsMap); + return computeRpc.start(instance.getZone(), instance.getInstance(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); @@ -2031,7 +2036,7 @@ public Operation stop(final InstanceId instance, OperationOption... options) { runWithRetries(new Callable() { @Override public com.google.api.services.compute.model.Operation call() { - return computeRpc.stop(instance.zone(), instance.instance(), optionsMap); + return computeRpc.stop(instance.getZone(), instance.getInstance(), optionsMap); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); return answer == null ? null : Operation.fromPb(this, answer); @@ -2043,7 +2048,7 @@ public com.google.api.services.compute.model.Operation call() { private Map optionMap(Option... options) { Map optionMap = Maps.newEnumMap(ComputeRpc.Option.class); for (Option option : options) { - Object prev = optionMap.put(option.rpcOption(), option.value()); + Object prev = optionMap.put(option.getRpcOption(), option.getValue()); checkArgument(prev == null, "Duplicate option %s", option); } return optionMap; diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/DeprecationStatus.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/DeprecationStatus.java index 44174c66da15..2e8a720d0c26 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/DeprecationStatus.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/DeprecationStatus.java @@ -97,7 +97,7 @@ public static final class Builder { * @see RFC3339 */ // Wrongly-formatted timestamps were allowed, we must still support them (see #732 for details) - Builder deleted(String deleted) { + Builder setDeleted(String deleted) { this.deleted = deleted; return this; } @@ -109,7 +109,7 @@ Builder deleted(String deleted) { * @see RFC3339 */ // Wrongly-formatted timestamps were allowed, we must still support them (see #732 for details) - Builder deprecated(String deprecated) { + Builder setDeprecated(String deprecated) { this.deprecated = deprecated; return this; } @@ -121,7 +121,7 @@ Builder deprecated(String deprecated) { * @see RFC3339 */ // Wrongly-formatted timestamps were allowed, we must still support them (see #732 for details) - Builder obsolete(String obsolete) { + Builder setObsolete(String obsolete) { this.obsolete = obsolete; return this; } @@ -130,7 +130,16 @@ Builder obsolete(String obsolete) { * Sets the timestamp on or after which the deprecation state of this resource will be changed * to {@link Status#DELETED}. In milliseconds since epoch. */ + @Deprecated public Builder deleted(long deleted) { + return setDeleted(deleted); + } + + /** + * Sets the timestamp on or after which the deprecation state of this resource will be changed + * to {@link Status#DELETED}. In milliseconds since epoch. + */ + public Builder setDeleted(long deleted) { this.deleted = TIMESTAMP_FORMATTER.print(deleted); return this; } @@ -139,7 +148,16 @@ public Builder deleted(long deleted) { * Sets the timestamp on or after which the deprecation state of this resource will be changed * to {@link Status#DEPRECATED}. In milliseconds since epoch. */ + @Deprecated public Builder deprecated(long deprecated) { + return setDeprecated(deprecated); + } + + /** + * Sets the timestamp on or after which the deprecation state of this resource will be changed + * to {@link Status#DEPRECATED}. In milliseconds since epoch. + */ + public Builder setDeprecated(long deprecated) { this.deprecated = TIMESTAMP_FORMATTER.print(deprecated); return this; } @@ -148,7 +166,16 @@ public Builder deprecated(long deprecated) { * Sets the timestamp on or after which the deprecation state of this resource will be changed * to {@link Status#OBSOLETE}. In milliseconds since epoch. */ + @Deprecated public Builder obsolete(long obsolete) { + return setObsolete(obsolete); + } + + /** + * Sets the timestamp on or after which the deprecation state of this resource will be changed + * to {@link Status#OBSOLETE}. In milliseconds since epoch. + */ + public Builder setObsolete(long obsolete) { this.obsolete = TIMESTAMP_FORMATTER.print(obsolete); return this; } @@ -157,7 +184,16 @@ public Builder obsolete(long obsolete) { * Sets the identity of the suggested replacement for a deprecated resource. The suggested * replacement resource must be the same kind of resource as the deprecated resource. */ + @Deprecated public Builder replacement(T replacement) { + return setReplacement(replacement); + } + + /** + * Sets the identity of the suggested replacement for a deprecated resource. The suggested + * replacement resource must be the same kind of resource as the deprecated resource. + */ + public Builder setReplacement(T replacement) { this.replacement = replacement; return this; } @@ -165,7 +201,15 @@ public Builder replacement(T replacement) { /** * Sets the status of the deprecated resource. */ + @Deprecated public Builder status(Status status) { + return setStatus(status); + } + + /** + * Sets the status of the deprecated resource. + */ + public Builder setStatus(Status status) { this.status = checkNotNull(status); return this; } @@ -194,7 +238,20 @@ public DeprecationStatus build() { * @see RFC3339 */ // Wrongly-formatted timestamps were allowed, we must still support them (see #732 for details) + @Deprecated public String deleted() { + return getDeleted(); + } + + /** + * Returns the timestamp on or after which the deprecation state of this resource will be changed + * to {@link Status#DELETED}. Returns {@code null} if not set. This value should be in RFC3339 + * format. + * + * @see RFC3339 + */ + // Wrongly-formatted timestamps were allowed, we must still support them (see #732 for details) + public String getDeleted() { return deleted; } @@ -206,7 +263,20 @@ public String deleted() { * @see RFC3339 */ // Wrongly-formatted timestamps were allowed, we must still support them (see #732 for details) + @Deprecated public String deprecated() { + return getDeprecated(); + } + + /** + * Returns the timestamp on or after which the deprecation state of this resource will be changed + * to {@link Status#DEPRECATED}. Returns {@code null} if not set. This value should be in RFC3339 + * format. + * + * @see RFC3339 + */ + // Wrongly-formatted timestamps were allowed, we must still support them (see #732 for details) + public String getDeprecated() { return deprecated; } @@ -218,7 +288,20 @@ public String deprecated() { * @see RFC3339 */ // Wrongly-formatted timestamps were allowed, we must still support them (see #732 for details) + @Deprecated public String obsolete() { + return getObsolete(); + } + + /** + * Returns the timestamp on or after which the deprecation state of this resource will be changed + * to {@link Status#OBSOLETE}. Returns {@code null} if not set. This value should be in RFC3339 + * format. + * + * @see RFC3339 + */ + // Wrongly-formatted timestamps were allowed, we must still support them (see #732 for details) + public String getObsolete() { return obsolete; } @@ -228,7 +311,18 @@ public String obsolete() { * * @throws IllegalStateException if {@link #deleted()} is not a valid date, time or datetime */ + @Deprecated public Long deletedMillis() { + return getDeletedMillis(); + } + + /** + * Returns the timestamp (in milliseconds since epoch) on or after which the deprecation state of + * this resource will be changed to {@link Status#DELETED}. Returns {@code null} if not set. + * + * @throws IllegalStateException if {@link #deleted()} is not a valid date, time or datetime + */ + public Long getDeletedMillis() { try { return deleted != null ? TIMESTAMP_PARSER.parseMillis(deleted) : null; } catch (IllegalArgumentException ex) { @@ -242,7 +336,18 @@ public Long deletedMillis() { * * @throws IllegalStateException if {@link #deprecated()} is not a valid date, time or datetime */ + @Deprecated public Long deprecatedMillis() { + return getDeprecatedMillis(); + } + + /** + * Returns the timestamp (in milliseconds since epoch) on or after which the deprecation state of + * this resource will be changed to {@link Status#DEPRECATED}. Returns {@code null} if not set. + * + * @throws IllegalStateException if {@link #deprecated()} is not a valid date, time or datetime + */ + public Long getDeprecatedMillis() { try { return deprecated != null ? TIMESTAMP_PARSER.parseMillis(deprecated) : null; } catch (IllegalArgumentException ex) { @@ -256,7 +361,18 @@ public Long deprecatedMillis() { * * @throws IllegalStateException if {@link #obsolete()} is not a valid date, time or datetime */ + @Deprecated public Long obsoleteMillis() { + return getObsoleteMillis(); + } + + /** + * Returns the timestamp (in milliseconds since epoch) on or after which the deprecation state of + * this resource will be changed to {@link Status#OBSOLETE}. Returns {@code null} if not set. + * + * @throws IllegalStateException if {@link #obsolete()} is not a valid date, time or datetime + */ + public Long getObsoleteMillis() { try { return obsolete != null ? TIMESTAMP_PARSER.parseMillis(obsolete) : null; } catch (IllegalArgumentException ex) { @@ -268,14 +384,31 @@ public Long obsoleteMillis() { * Returns the identity of the suggested replacement for a deprecated resource. The suggested * replacement resource must be the same kind of resource as the deprecated resource. */ + @Deprecated public T replacement() { + return getReplacement(); + } + + /** + * Returns the identity of the suggested replacement for a deprecated resource. The suggested + * replacement resource must be the same kind of resource as the deprecated resource. + */ + public T getReplacement() { return replacement; } /** * Returns the deprecation state of this resource. */ + @Deprecated public Status status() { + return getStatus(); + } + + /** + * Returns the deprecation state of this resource. + */ + public Status getStatus() { return status; } @@ -315,7 +448,7 @@ com.google.api.services.compute.model.DeprecationStatus toPb() { deprecationStatusPb.setDeleted(deleted); deprecationStatusPb.setDeprecated(deprecated); deprecationStatusPb.setObsolete(obsolete); - deprecationStatusPb.setReplacement(replacement.selfLink()); + deprecationStatusPb.setReplacement(replacement.getSelfLink()); deprecationStatusPb.setState(status.name()); return deprecationStatusPb; } @@ -323,37 +456,54 @@ com.google.api.services.compute.model.DeprecationStatus toPb() { /** * Returns the builder for a {@code DeprecationStatus} object given the status. */ + @Deprecated public static Builder builder(Status status) { - return new Builder().status(status); + return newBuilder(status); + } + + /** + * Returns the builder for a {@code DeprecationStatus} object given the status. + */ + public static Builder newBuilder(Status status) { + return new Builder().setStatus(status); } /** * Returns the builder for a {@code DeprecationStatus} object given the status and replacement's * identity. */ + @Deprecated public static Builder builder(Status status, T replacement) { - return new Builder().status(status).replacement(replacement); + return newBuilder(status, replacement); + } + + /** + * Returns the builder for a {@code DeprecationStatus} object given the status and replacement's + * identity. + */ + public static Builder newBuilder(Status status, T replacement) { + return new Builder().setStatus(status).setReplacement(replacement); } /** * Returns a {@code DeprecationStatus} object given the status and replacement's identity. */ public static DeprecationStatus of(Status status, T replacement) { - return builder(status, replacement).build(); + return newBuilder(status, replacement).build(); } static DeprecationStatus fromPb( com.google.api.services.compute.model.DeprecationStatus deprecationStatusPb, Function fromUrl) { Builder builder = new Builder<>(); - builder.deleted(deprecationStatusPb.getDeleted()); - builder.deprecated(deprecationStatusPb.getDeprecated()); - builder.obsolete(deprecationStatusPb.getObsolete()); + builder.setDeleted(deprecationStatusPb.getDeleted()); + builder.setDeprecated(deprecationStatusPb.getDeprecated()); + builder.setObsolete(deprecationStatusPb.getObsolete()); if (deprecationStatusPb.getReplacement() != null) { - builder.replacement(fromUrl.apply(deprecationStatusPb.getReplacement())); + builder.setReplacement(fromUrl.apply(deprecationStatusPb.getReplacement())); } if (deprecationStatusPb.getState() != null) { - builder.status(Status.valueOf(deprecationStatusPb.getState())); + builder.setStatus(Status.valueOf(deprecationStatusPb.getState())); } return builder.build(); } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/Disk.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/Disk.java index f1c6cd26291c..41a7f95b91b5 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/Disk.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/Disk.java @@ -60,62 +60,80 @@ public static class Builder extends DiskInfo.Builder { } @Override - Builder generatedId(String generatedId) { - infoBuilder.generatedId(generatedId); + Builder setGeneratedId(String generatedId) { + infoBuilder.setGeneratedId(generatedId); return this; } @Override + @Deprecated public Builder configuration(DiskConfiguration configuration) { - infoBuilder.configuration(configuration); + return setConfiguration(configuration); + } + + @Override + public Builder setConfiguration(DiskConfiguration configuration) { + infoBuilder.setConfiguration(configuration); return this; } @Override + @Deprecated public Builder diskId(DiskId diskId) { - infoBuilder.diskId(diskId); + return setDiskId(diskId); + } + + @Override + public Builder setDiskId(DiskId diskId) { + infoBuilder.setDiskId(diskId); return this; } @Override - Builder creationTimestamp(Long creationTimestamp) { - infoBuilder.creationTimestamp(creationTimestamp); + Builder setCreationTimestamp(Long creationTimestamp) { + infoBuilder.setCreationTimestamp(creationTimestamp); return this; } @Override - Builder creationStatus(CreationStatus creationStatus) { - infoBuilder.creationStatus(creationStatus); + Builder setCreationStatus(CreationStatus creationStatus) { + infoBuilder.setCreationStatus(creationStatus); return this; } @Override + @Deprecated public Builder description(String description) { - infoBuilder.description(description); + return setDescription(description); + } + + @Override + public Builder setDescription(String description) { + infoBuilder.setDescription(description); return this; } @Override - Builder licenses(List licenses) { - infoBuilder.licenses(licenses); + Builder setLicenses(List licenses) { + infoBuilder.setLicenses(licenses); return this; } @Override - Builder attachedInstances(List attachedInstances) { - infoBuilder.attachedInstances(attachedInstances); + Builder setAttachedInstances(List attachedInstances) { + infoBuilder.setAttachedInstances(attachedInstances); return this; } @Override - Builder lastAttachTimestamp(Long lastAttachTimestamp) { - infoBuilder.lastAttachTimestamp(lastAttachTimestamp); + Builder setLastAttachTimestamp(Long lastAttachTimestamp) { + infoBuilder.setLastAttachTimestamp(lastAttachTimestamp); return this; } @Override - Builder lastDetachTimestamp(Long lastDetachTimestamp) { - infoBuilder.lastDetachTimestamp(lastDetachTimestamp); + Builder setLastDetachTimestamp(Long lastDetachTimestamp) { + infoBuilder.setLastDetachTimestamp(lastDetachTimestamp); return this; } @@ -149,7 +167,7 @@ public boolean exists() { * @throws ComputeException upon failure */ public Disk reload(DiskOption... options) { - return compute.getDisk(diskId(), options); + return compute.getDisk(getDiskId(), options); } /** @@ -160,7 +178,7 @@ public Disk reload(DiskOption... options) { * @throws ComputeException upon failure */ public Operation delete(OperationOption... options) { - return compute.deleteDisk(diskId(), options); + return compute.deleteDisk(getDiskId(), options); } /** @@ -170,7 +188,7 @@ public Operation delete(OperationOption... options) { * @throws ComputeException upon failure */ public Operation createSnapshot(String snapshot, OperationOption... options) { - return compute.create(SnapshotInfo.of(SnapshotId.of(snapshot), diskId()), options); + return compute.create(SnapshotInfo.of(SnapshotId.of(snapshot), getDiskId()), options); } /** @@ -180,8 +198,8 @@ public Operation createSnapshot(String snapshot, OperationOption... options) { * @throws ComputeException upon failure */ public Operation createSnapshot(String snapshot, String description, OperationOption... options) { - SnapshotInfo snapshotInfo = SnapshotInfo.builder(SnapshotId.of(snapshot), diskId()) - .description(description) + SnapshotInfo snapshotInfo = SnapshotInfo.newBuilder(SnapshotId.of(snapshot), getDiskId()) + .setDescription(description) .build(); return compute.create(snapshotInfo, options); } @@ -193,7 +211,7 @@ public Operation createSnapshot(String snapshot, String description, OperationOp * @throws ComputeException upon failure */ public Operation createImage(String image, OperationOption... options) { - ImageInfo imageInfo = ImageInfo.of(ImageId.of(image), DiskImageConfiguration.of(diskId())); + ImageInfo imageInfo = ImageInfo.of(ImageId.of(image), DiskImageConfiguration.of(getDiskId())); return compute.create(imageInfo, options); } @@ -204,9 +222,10 @@ public Operation createImage(String image, OperationOption... options) { * @throws ComputeException upon failure */ public Operation createImage(String image, String description, OperationOption... options) { - ImageInfo imageInfo = ImageInfo.builder(ImageId.of(image), DiskImageConfiguration.of(diskId())) - .description(description) - .build(); + ImageInfo imageInfo = + ImageInfo.newBuilder(ImageId.of(image), DiskImageConfiguration.of(getDiskId())) + .setDescription(description) + .build(); return compute.create(imageInfo, options); } @@ -218,13 +237,21 @@ public Operation createImage(String image, String description, OperationOption.. * @throws ComputeException upon failure or if the new disk size is smaller than the previous one */ public Operation resize(long sizeGb, OperationOption... options) { - return compute.resize(diskId(), sizeGb, options); + return compute.resize(getDiskId(), sizeGb, options); } /** * Returns the disk's {@code Compute} object used to issue requests. */ + @Deprecated public Compute compute() { + return getCompute(); + } + + /** + * Returns the disk's {@code Compute} object used to issue requests. + */ + public Compute getCompute() { return compute; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskConfiguration.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskConfiguration.java index 1670bcf8b56b..32c12b96aa56 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskConfiguration.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskConfiguration.java @@ -95,7 +95,7 @@ protected B self() { return (B) this; } - B type(Type type) { + B setType(Type type) { this.type = type; return self(); } @@ -103,7 +103,15 @@ B type(Type type) { /** * Sets the size of the persistent disk, in GB. */ + @Deprecated public B sizeGb(Long sizeGb) { + return setSizeGb(sizeGb); + } + + /** + * Sets the size of the persistent disk, in GB. + */ + public B setSizeGb(Long sizeGb) { this.sizeGb = sizeGb; return self(); } @@ -111,7 +119,15 @@ public B sizeGb(Long sizeGb) { /** * Sets the identity of the disk type. If not set {@code pd-standard} will be used. */ + @Deprecated public B diskType(DiskTypeId diskType) { + return setDiskType(diskType); + } + + /** + * Sets the identity of the disk type. If not set {@code pd-standard} will be used. + */ + public B setDiskType(DiskTypeId diskType) { this.diskType = diskType; return self(); } @@ -135,21 +151,49 @@ public B diskType(DiskTypeId diskType) { * snapshot. This method returns {@link Type#IMAGE} for a configuration that creates a disk * from a Google Compute Engine image. */ + @Deprecated public Type type() { + return getType(); + } + + /** + * Returns the disk configuration's type. This method returns {@link Type#STANDARD} for a standard + * configuration that creates a disk given its type and size. This method returns + * {@link Type#SNAPSHOT} for a configuration that creates a disk from a Google Compute Engine + * snapshot. This method returns {@link Type#IMAGE} for a configuration that creates a disk + * from a Google Compute Engine image. + */ + public Type getType() { return type; } /** * Returns the size of the persistent disk, in GB. */ + @Deprecated public Long sizeGb() { + return getSizeGb(); + } + + /** + * Returns the size of the persistent disk, in GB. + */ + public Long getSizeGb() { return sizeGb; } /** * Returns the identity of the disk type. */ + @Deprecated public DiskTypeId diskType() { + return getDiskType(); + } + + /** + * Returns the identity of the disk type. + */ + public DiskTypeId getDiskType() { return diskType; } @@ -186,7 +230,7 @@ Disk toPb() { Disk diskPb = new Disk(); diskPb.setSizeGb(sizeGb); if (diskType != null) { - diskPb.setType(diskType.selfLink()); + diskPb.setType(diskType.getSelfLink()); } return diskPb; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskId.java index 58f55beb9a9a..f3d060eceaf4 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskId.java @@ -45,15 +45,31 @@ private DiskId(String project, String zone, String disk) { /** * Returns the name of the zone this disk belongs to. */ + @Deprecated public String zone() { + return getZone(); + } + + /** + * Returns the name of the zone this disk belongs to. + */ + public String getZone() { return zone; } /** * Returns the identity of the zone this disk belongs to. */ + @Deprecated public ZoneId zoneId() { - return ZoneId.of(project(), zone); + return getZoneId(); + } + + /** + * Returns the identity of the zone this disk belongs to. + */ + public ZoneId getZoneId() { + return ZoneId.of(getProject(), zone); } /** @@ -64,13 +80,32 @@ public ZoneId zoneId() { * * @see RFC1035 */ + @Deprecated public String disk() { + return getDisk(); + } + + /** + * Returns the name of the disk. The name must be 1-63 characters long and comply with RFC1035. + * Specifically, the name must match the regular expression {@code [a-z]([-a-z0-9]*[a-z0-9])?} + * which means the first character must be a lowercase letter, and all following characters must + * be a dash, lowercase letter, or digit, except the last character, which cannot be a dash. + * + * @see RFC1035 + */ + public String getDisk() { return disk; } @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/zones/" + zone + "/disks/" + disk; + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/zones/" + zone + "/disks/" + disk; } @Override @@ -99,7 +134,7 @@ public boolean equals(Object obj) { @Override DiskId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } return DiskId.of(projectId, zone, disk); @@ -115,7 +150,7 @@ DiskId setProjectId(String projectId) { * @see RFC1035 */ public static DiskId of(ZoneId zoneId, String disk) { - return new DiskId(zoneId.project(), zoneId.zone(), disk); + return new DiskId(zoneId.getProject(), zoneId.getZone(), disk); } /** diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskImageConfiguration.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskImageConfiguration.java index a31c8199ec07..7aa16b683f44 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskImageConfiguration.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskImageConfiguration.java @@ -62,12 +62,20 @@ private Builder(Image imagePb) { /** * Sets the identity of the source disk used to create the image. */ + @Deprecated public Builder sourceDisk(DiskId sourceDisk) { + return setSourceDisk(sourceDisk); + } + + /** + * Sets the identity of the source disk used to create the image. + */ + public Builder setSourceDisk(DiskId sourceDisk) { this.sourceDisk = checkNotNull(sourceDisk); return this; } - Builder sourceDiskId(String sourceDiskId) { + Builder setSourceDiskId(String sourceDiskId) { this.sourceDiskId = sourceDiskId; return this; } @@ -90,7 +98,15 @@ private DiskImageConfiguration(Builder builder) { /** * Returns the identity of the source disk used to create this image. */ + @Deprecated public DiskId sourceDisk() { + return getSourceDisk(); + } + + /** + * Returns the identity of the source disk used to create this image. + */ + public DiskId getSourceDisk() { return sourceDisk; } @@ -99,7 +115,17 @@ public DiskId sourceDisk() { * be used to determine whether the image was taken from the current or a previous instance of a * given disk name. */ + @Deprecated public String sourceDiskId() { + return getSourceDiskId(); + } + + /** + * Returns the service-generated unique id of the disk used to create this image. This value may + * be used to determine whether the image was taken from the current or a previous instance of a + * given disk name. + */ + public String getSourceDiskId() { return sourceDiskId; } @@ -130,16 +156,16 @@ public final boolean equals(Object obj) { @Override DiskImageConfiguration setProjectId(String projectId) { - if (sourceDisk.project() != null) { + if (sourceDisk.getProject() != null) { return this; } - return toBuilder().sourceDisk(sourceDisk.setProjectId(projectId)).build(); + return toBuilder().setSourceDisk(sourceDisk.setProjectId(projectId)).build(); } @Override Image toPb() { Image imagePb = super.toPb(); - imagePb.setSourceDisk(sourceDisk.selfLink()); + imagePb.setSourceDisk(sourceDisk.getSelfLink()); imagePb.setSourceDiskId(sourceDiskId); return imagePb; } @@ -147,15 +173,23 @@ Image toPb() { /** * Creates a builder for a {@code DiskImageConfiguration} given the source disk identity. */ + @Deprecated public static Builder builder(DiskId sourceDisk) { - return new Builder().sourceDisk(sourceDisk); + return newBuilder(sourceDisk); + } + + /** + * Creates a builder for a {@code DiskImageConfiguration} given the source disk identity. + */ + public static Builder newBuilder(DiskId sourceDisk) { + return new Builder().setSourceDisk(sourceDisk); } /** * Creates a {@code DiskImageConfiguration} object given the source disk identity. */ public static DiskImageConfiguration of(DiskId sourceId) { - return builder(sourceId).build(); + return newBuilder(sourceId).build(); } @SuppressWarnings("unchecked") diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskInfo.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskInfo.java index aab6d90ff345..eec4c8de8b54 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskInfo.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskInfo.java @@ -99,34 +99,52 @@ public enum CreationStatus { */ public abstract static class Builder { - abstract Builder generatedId(String generatedId); + abstract Builder setGeneratedId(String generatedId); /** * Sets the disk configuration. */ + @Deprecated public abstract Builder configuration(DiskConfiguration configuration); + /** + * Sets the disk configuration. + */ + public abstract Builder setConfiguration(DiskConfiguration configuration); + /** * Sets the disk identity. */ + @Deprecated public abstract Builder diskId(DiskId diskId); - abstract Builder creationTimestamp(Long creationTimestamp); + /** + * Sets the disk identity. + */ + public abstract Builder setDiskId(DiskId diskId); + + abstract Builder setCreationTimestamp(Long creationTimestamp); - abstract Builder creationStatus(CreationStatus creationStatus); + abstract Builder setCreationStatus(CreationStatus creationStatus); /** * Sets an optional textual description of the resource. */ + @Deprecated public abstract Builder description(String description); - abstract Builder licenses(List licenses); + /** + * Sets an optional textual description of the resource. + */ + public abstract Builder setDescription(String description); + + abstract Builder setLicenses(List licenses); - abstract Builder attachedInstances(List attachedInstances); + abstract Builder setAttachedInstances(List attachedInstances); - abstract Builder lastAttachTimestamp(Long lastAttachTimestamp); + abstract Builder setLastAttachTimestamp(Long lastAttachTimestamp); - abstract Builder lastDetachTimestamp(Long lastDetachTimestamp); + abstract Builder setLastDetachTimestamp(Long lastDetachTimestamp); /** * Creates a {@code DiskInfo} object. @@ -193,62 +211,80 @@ static final class BuilderImpl extends Builder { } @Override - BuilderImpl generatedId(String generatedId) { + BuilderImpl setGeneratedId(String generatedId) { this.generatedId = generatedId; return this; } @Override + @Deprecated public BuilderImpl configuration(DiskConfiguration configuration) { + return setConfiguration(configuration); + } + + @Override + public BuilderImpl setConfiguration(DiskConfiguration configuration) { this.configuration = checkNotNull(configuration); return this; } @Override + @Deprecated public BuilderImpl diskId(DiskId diskId) { + return setDiskId(diskId); + } + + @Override + public BuilderImpl setDiskId(DiskId diskId) { this.diskId = checkNotNull(diskId); return this; } @Override - BuilderImpl creationTimestamp(Long creationTimestamp) { + BuilderImpl setCreationTimestamp(Long creationTimestamp) { this.creationTimestamp = creationTimestamp; return this; } @Override - BuilderImpl creationStatus(CreationStatus creationStatus) { + BuilderImpl setCreationStatus(CreationStatus creationStatus) { this.creationStatus = creationStatus; return this; } @Override + @Deprecated public BuilderImpl description(String description) { + return setDescription(description); + } + + @Override + public BuilderImpl setDescription(String description) { this.description = description; return this; } @Override - BuilderImpl licenses(List licenses) { + BuilderImpl setLicenses(List licenses) { this.licenses = licenses != null ? ImmutableList.copyOf(licenses) : null; return this; } @Override - BuilderImpl attachedInstances(List attachedInstances) { + BuilderImpl setAttachedInstances(List attachedInstances) { this.attachedInstances = attachedInstances != null ? ImmutableList.copyOf(attachedInstances) : null; return this; } @Override - BuilderImpl lastAttachTimestamp(Long lastAttachTimestamp) { + BuilderImpl setLastAttachTimestamp(Long lastAttachTimestamp) { this.lastAttachTimestamp = lastAttachTimestamp; return this; } @Override - BuilderImpl lastDetachTimestamp(Long lastDetachTimestamp) { + BuilderImpl setLastDetachTimestamp(Long lastDetachTimestamp) { this.lastDetachTimestamp = lastDetachTimestamp; return this; } @@ -275,14 +311,30 @@ public DiskInfo build() { /** * Returns the creation timestamp in milliseconds since epoch. */ + @Deprecated public Long creationTimestamp() { + return getCreationTimestamp(); + } + + /** + * Returns the creation timestamp in milliseconds since epoch. + */ + public Long getCreationTimestamp() { return creationTimestamp; } /** * Returns the service-generated unique identifier for the disk. */ + @Deprecated public String generatedId() { + return getGeneratedId(); + } + + /** + * Returns the service-generated unique identifier for the disk. + */ + public String getGeneratedId() { return generatedId; } @@ -290,56 +342,121 @@ public String generatedId() { * Returns the disk configuration. */ @SuppressWarnings("unchecked") + @Deprecated public T configuration() { + return getConfiguration(); + } + + /** + * Returns the disk configuration. + */ + @SuppressWarnings("unchecked") + public T getConfiguration() { return (T) configuration; } /** * Returns the disk identity. */ + @Deprecated public DiskId diskId() { + return getDiskId(); + } + + /** + * Returns the disk identity. + */ + public DiskId getDiskId() { return diskId; } /** * Returns the creation status of the disk. */ + @Deprecated public CreationStatus creationStatus() { + return getCreationStatus(); + } + + /** + * Returns the creation status of the disk. + */ + public CreationStatus getCreationStatus() { return creationStatus; } /** * Returns a textual description of the disk. */ + @Deprecated public String description() { + return getDescription(); + } + + /** + * Returns a textual description of the disk. + */ + public String getDescription() { return description; } /** * Returns all applicable publicly visible licenses for the disk. */ + @Deprecated public List licenses() { + return getLicenses(); + } + + /** + * Returns all applicable publicly visible licenses for the disk. + */ + public List getLicenses() { return licenses; } /** * Returns all the identities of the instances this disk is attached to. */ + @Deprecated public List attachedInstances() { + return getAttachedInstances(); + } + + /** + * Returns all the identities of the instances this disk is attached to. + */ + public List getAttachedInstances() { return attachedInstances; } /** * Returns the last attach timestamp in milliseconds since epoch. */ + @Deprecated public Long lastAttachTimestamp() { + return getLastAttachTimestamp(); + } + + /** + * Returns the last attach timestamp in milliseconds since epoch. + */ + public Long getLastAttachTimestamp() { return lastAttachTimestamp; } /** * Returns the last detach timestamp in milliseconds since epoch. */ + @Deprecated public Long lastDetachTimestamp() { + return getLastDetachTimestamp(); + } + + /** + * Returns the last detach timestamp in milliseconds since epoch. + */ + public Long getLastDetachTimestamp() { return lastDetachTimestamp; } @@ -386,7 +503,18 @@ public boolean equals(Object obj) { * {@link SnapshotDiskConfiguration} to create a disk from a snapshot. Use * {@link ImageDiskConfiguration} to create a disk from a disk image. */ + @Deprecated public static Builder builder(DiskId diskId, DiskConfiguration configuration) { + return newBuilder(diskId, configuration); + } + + /** + * Returns a builder for a {@code DiskInfo} object given its identity and configuration. Use + * {@link StandardDiskConfiguration} to create a simple disk given its type and size. Use + * {@link SnapshotDiskConfiguration} to create a disk from a snapshot. Use + * {@link ImageDiskConfiguration} to create a disk from a disk image. + */ + public static Builder newBuilder(DiskId diskId, DiskConfiguration configuration) { return new BuilderImpl(diskId, configuration); } @@ -397,13 +525,13 @@ public static Builder builder(DiskId diskId, DiskConfiguration configuration) { * {@link ImageDiskConfiguration} to create a disk from a disk image. */ public static DiskInfo of(DiskId diskId, DiskConfiguration configuration) { - return builder(diskId, configuration).build(); + return newBuilder(diskId, configuration).build(); } DiskInfo setProjectId(String projectId) { return toBuilder() - .diskId(diskId.setProjectId(projectId)) - .configuration(configuration.setProjectId(projectId)) + .setDiskId(diskId.setProjectId(projectId)) + .setConfiguration(configuration.setProjectId(projectId)) .build(); } @@ -415,13 +543,13 @@ Disk toPb() { if (creationTimestamp != null) { diskPb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp)); } - diskPb.setZone(diskId.zoneId().selfLink()); + diskPb.setZone(diskId.getZoneId().getSelfLink()); if (creationStatus != null) { diskPb.setStatus(creationStatus.toString()); } - diskPb.setName(diskId.disk()); + diskPb.setName(diskId.getDisk()); diskPb.setDescription(description); - diskPb.setSelfLink(diskId.selfLink()); + diskPb.setSelfLink(diskId.getSelfLink()); if (licenses != null) { diskPb.setLicenses(Lists.transform(licenses, LicenseId.TO_URL_FUNCTION)); } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskType.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskType.java index cbe6f625e764..5a9c6dca3d13 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskType.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskType.java @@ -72,37 +72,37 @@ static final class Builder { private Builder() {} - Builder generatedId(String generatedId) { + Builder setGeneratedId(String generatedId) { this.generatedId = generatedId; return this; } - Builder creationTimestamp(Long creationTimestamp) { + Builder setCreationTimestamp(Long creationTimestamp) { this.creationTimestamp = creationTimestamp; return this; } - Builder diskTypeId(DiskTypeId diskTypeId) { + Builder setDiskTypeId(DiskTypeId diskTypeId) { this.diskTypeId = diskTypeId; return this; } - Builder description(String description) { + Builder setDescription(String description) { this.description = description; return this; } - Builder validDiskSize(String validDiskSize) { + Builder setValidDiskSize(String validDiskSize) { this.validDiskSize = validDiskSize; return this; } - Builder defaultDiskSizeGb(Long defaultDiskSizeGb) { + Builder setDefaultDiskSizeGb(Long defaultDiskSizeGb) { this.defaultDiskSizeGb = defaultDiskSizeGb; return this; } - Builder deprecationStatus(DeprecationStatus deprecationStatus) { + Builder setDeprecationStatus(DeprecationStatus deprecationStatus) { this.deprecationStatus = deprecationStatus; return this; } @@ -125,42 +125,90 @@ private DiskType(Builder builder) { /** * Returns the creation timestamp in milliseconds since epoch. */ + @Deprecated public Long creationTimestamp() { + return getCreationTimestamp(); + } + + /** + * Returns the creation timestamp in milliseconds since epoch. + */ + public Long getCreationTimestamp() { return creationTimestamp; } /** * Returns the disk type's identity. */ + @Deprecated public DiskTypeId diskTypeId() { + return getDiskTypeId(); + } + + /** + * Returns the disk type's identity. + */ + public DiskTypeId getDiskTypeId() { return diskTypeId; } /** * Returns the service-generated unique identifier for the disk type. */ + @Deprecated public String generatedId() { + return getGeneratedId(); + } + + /** + * Returns the service-generated unique identifier for the disk type. + */ + public String getGeneratedId() { return generatedId; } /** * Returns a textual description of the disk type. */ + @Deprecated public String description() { + return getDescription(); + } + + /** + * Returns a textual description of the disk type. + */ + public String getDescription() { return description; } /** * Returns an optional textual description of the valid disk size, such as "10GB-10TB". */ + @Deprecated public String validDiskSize() { + return getValidDiskSize(); + } + + /** + * Returns an optional textual description of the valid disk size, such as "10GB-10TB". + */ + public String getValidDiskSize() { return validDiskSize; } /** * Returns the service-defined default disk size in GB. */ + @Deprecated public Long defaultDiskSizeGb() { + return getDefaultDiskSizeGb(); + } + + /** + * Returns the service-defined default disk size in GB. + */ + public Long getDefaultDiskSizeGb() { return defaultDiskSizeGb; } @@ -169,7 +217,17 @@ public Long defaultDiskSizeGb() { * either {@link DeprecationStatus.Status#DELETED} or {@link DeprecationStatus.Status#OBSOLETE} * the disk type should not be used. Returns {@code null} if the disk type is not deprecated. */ + @Deprecated public DeprecationStatus deprecationStatus() { + return getDeprecationStatus(); + } + + /** + * Returns the deprecation status of the disk type. If {@link DeprecationStatus#status()} is + * either {@link DeprecationStatus.Status#DELETED} or {@link DeprecationStatus.Status#OBSOLETE} + * the disk type should not be used. Returns {@code null} if the disk type is not deprecated. + */ + public DeprecationStatus getDeprecationStatus() { return deprecationStatus; } @@ -209,33 +267,34 @@ com.google.api.services.compute.model.DiskType toPb() { } diskTypePb.setDescription(description); diskTypePb.setValidDiskSize(validDiskSize); - diskTypePb.setSelfLink(diskTypeId.selfLink()); + diskTypePb.setSelfLink(diskTypeId.getSelfLink()); diskTypePb.setDefaultDiskSizeGb(defaultDiskSizeGb); - diskTypePb.setZone(diskTypeId.zoneId().selfLink()); + diskTypePb.setZone(diskTypeId.getZoneId().getSelfLink()); if (deprecationStatus != null) { diskTypePb.setDeprecated(deprecationStatus.toPb()); } return diskTypePb; } - static Builder builder() { + static Builder newBuilder() { return new Builder(); } static DiskType fromPb(com.google.api.services.compute.model.DiskType diskTypePb) { - Builder builder = builder(); + Builder builder = newBuilder(); if (diskTypePb.getId() != null) { - builder.generatedId(diskTypePb.getId().toString()); + builder.setGeneratedId(diskTypePb.getId().toString()); } if (diskTypePb.getCreationTimestamp() != null) { - builder.creationTimestamp(TIMESTAMP_FORMATTER.parseMillis(diskTypePb.getCreationTimestamp())); + builder.setCreationTimestamp( + TIMESTAMP_FORMATTER.parseMillis(diskTypePb.getCreationTimestamp())); } - builder.diskTypeId(DiskTypeId.fromUrl(diskTypePb.getSelfLink())); - builder.description(diskTypePb.getDescription()); - builder.validDiskSize(diskTypePb.getValidDiskSize()); - builder.defaultDiskSizeGb(diskTypePb.getDefaultDiskSizeGb()); + builder.setDiskTypeId(DiskTypeId.fromUrl(diskTypePb.getSelfLink())); + builder.setDescription(diskTypePb.getDescription()); + builder.setValidDiskSize(diskTypePb.getValidDiskSize()); + builder.setDefaultDiskSizeGb(diskTypePb.getDefaultDiskSizeGb()); if (diskTypePb.getDeprecated() != null) { - builder.deprecationStatus( + builder.setDeprecationStatus( DeprecationStatus.fromPb(diskTypePb.getDeprecated(), DiskTypeId.FROM_URL_FUNCTION)); } return builder.build(); diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskTypeId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskTypeId.java index 1ed0cfdea472..644d027e7bc0 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskTypeId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/DiskTypeId.java @@ -39,7 +39,7 @@ public DiskTypeId apply(String pb) { static final Function TO_URL_FUNCTION = new Function() { @Override public String apply(DiskTypeId diskTypeId) { - return diskTypeId.selfLink(); + return diskTypeId.getSelfLink(); } }; @@ -59,27 +59,57 @@ private DiskTypeId(String project, String zone, String type) { /** * Returns the name of the disk type. */ + @Deprecated public String type() { + return getType(); + } + + /** + * Returns the name of the disk type. + */ + public String getType() { return type; } /** * Returns the name of the zone this disk type belongs to. */ + @Deprecated public String zone() { + return getZone(); + } + + /** + * Returns the name of the zone this disk type belongs to. + */ + public String getZone() { return zone; } /** * Returns the identity of the zone this disk type belongs to. */ + @Deprecated public ZoneId zoneId() { - return ZoneId.of(project(), zone); + return getZoneId(); + } + + /** + * Returns the identity of the zone this disk type belongs to. + */ + public ZoneId getZoneId() { + return ZoneId.of(getProject(), zone); } @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/zones/" + zone + "/diskTypes/" + type; + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/zones/" + zone + "/diskTypes/" + type; } @Override @@ -108,7 +138,7 @@ public boolean equals(Object obj) { @Override DiskTypeId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } return DiskTypeId.of(projectId, zone, type); @@ -118,7 +148,7 @@ DiskTypeId setProjectId(String projectId) { * Returns a disk type identity given the zone identity and the disk type name. */ public static DiskTypeId of(ZoneId zoneId, String type) { - return new DiskTypeId(zoneId.project(), zoneId.zone(), type); + return new DiskTypeId(zoneId.getProject(), zoneId.getZone(), type); } /** diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/ForwardingRuleId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/ForwardingRuleId.java index 09d447cb8072..d43925f1c599 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/ForwardingRuleId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/ForwardingRuleId.java @@ -56,8 +56,14 @@ enum Type { /** * Returns the type of this forwarding rule identity. */ + @Deprecated public abstract Type type(); + /** + * Returns the type of this forwarding rule identity. + */ + public abstract Type getType(); + /** * Returns the name of the forwarding rule. The forwarding rule name must be 1-63 characters long * and comply with RFC1035. Specifically, the name must match the regular expression @@ -67,7 +73,21 @@ enum Type { * * @see RFC1035 */ + @Deprecated public String rule() { + return getRule(); + } + + /** + * Returns the name of the forwarding rule. The forwarding rule name must be 1-63 characters long + * and comply with RFC1035. Specifically, the name must match the regular expression + * {@code [a-z]([-a-z0-9]*[a-z0-9])?} which means the first character must be a lowercase letter, + * and all following characters must be a dash, lowercase letter, or digit, except the last + * character, which cannot be a dash. + * + * @see RFC1035 + */ + public String getRule() { return rule; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/GlobalAddressId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/GlobalAddressId.java index 45232edeff48..1773c6d4ae0e 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/GlobalAddressId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/GlobalAddressId.java @@ -33,13 +33,25 @@ private GlobalAddressId(String project, String address) { } @Override + @Deprecated public Type type() { + return getType(); + } + + @Override + public Type getType() { return Type.GLOBAL; } @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/global/addresses/" + address(); + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/global/addresses/" + getAddress(); } @Override @@ -54,10 +66,10 @@ public boolean equals(Object obj) { @Override GlobalAddressId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } - return GlobalAddressId.of(projectId, address()); + return GlobalAddressId.of(projectId, getAddress()); } /** diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/GlobalForwardingRuleId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/GlobalForwardingRuleId.java index b9acfa989b85..1c189eca929e 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/GlobalForwardingRuleId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/GlobalForwardingRuleId.java @@ -37,7 +37,7 @@ public GlobalForwardingRuleId apply(String pb) { new Function() { @Override public String apply(GlobalForwardingRuleId forwardingRuleId) { - return forwardingRuleId.selfLink(); + return forwardingRuleId.getSelfLink(); } }; @@ -50,13 +50,25 @@ private GlobalForwardingRuleId(String project, String rule) { } @Override + @Deprecated public Type type() { + return getType(); + } + + @Override + public Type getType() { return Type.GLOBAL; } @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/global/forwardingRules/" + rule(); + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/global/forwardingRules/" + getRule(); } @Override @@ -73,10 +85,10 @@ public boolean equals(Object obj) { @Override GlobalForwardingRuleId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } - return GlobalForwardingRuleId.of(projectId, rule()); + return GlobalForwardingRuleId.of(projectId, getRule()); } /** diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/GlobalOperationId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/GlobalOperationId.java index ee3e4fc2d40e..0e5fb162dd7f 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/GlobalOperationId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/GlobalOperationId.java @@ -33,13 +33,25 @@ private GlobalOperationId(String project, String operation) { } @Override + @Deprecated public Type type() { + return getType(); + } + + @Override + public Type getType() { return Type.GLOBAL; } @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/global/operations/" + operation(); + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/global/operations/" + getOperation(); } @Override @@ -54,10 +66,10 @@ public boolean equals(Object obj) { @Override GlobalOperationId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } - return GlobalOperationId.of(projectId, operation()); + return GlobalOperationId.of(projectId, getOperation()); } /** diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/Image.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/Image.java index e457ee71da13..0b5fbb8487e3 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/Image.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/Image.java @@ -55,8 +55,8 @@ public static class Builder extends ImageInfo.Builder { Builder(Compute compute, ImageId imageId, ImageConfiguration configuration) { this.compute = compute; this.infoBuilder = new ImageInfo.BuilderImpl(); - this.infoBuilder.imageId(imageId); - this.infoBuilder.configuration(configuration); + this.infoBuilder.setImageId(imageId); + this.infoBuilder.setConfiguration(configuration); } Builder(Image image) { @@ -65,56 +65,74 @@ public static class Builder extends ImageInfo.Builder { } @Override - Builder generatedId(String generatedId) { - infoBuilder.generatedId(generatedId); + Builder setGeneratedId(String generatedId) { + infoBuilder.setGeneratedId(generatedId); return this; } @Override - Builder creationTimestamp(Long creationTimestamp) { - infoBuilder.creationTimestamp(creationTimestamp); + Builder getCreationTimestamp(Long creationTimestamp) { + infoBuilder.getCreationTimestamp(creationTimestamp); return this; } @Override + @Deprecated public Builder imageId(ImageId imageId) { - infoBuilder.imageId(imageId); + return setImageId(imageId); + } + + @Override + public Builder setImageId(ImageId imageId) { + infoBuilder.setImageId(imageId); return this; } @Override + @Deprecated public Builder description(String description) { - infoBuilder.description(description); + return setDescription(description); + } + + @Override + public Builder setDescription(String description) { + infoBuilder.setDescription(description); return this; } @Override + @Deprecated public Builder configuration(ImageConfiguration configuration) { - infoBuilder.configuration(configuration); + return setConfiguration(configuration); + } + + @Override + public Builder setConfiguration(ImageConfiguration configuration) { + infoBuilder.setConfiguration(configuration); return this; } @Override - Builder status(Status status) { - infoBuilder.status(status); + Builder setStatus(Status status) { + infoBuilder.setStatus(status); return this; } @Override - Builder diskSizeGb(Long diskSizeGb) { - infoBuilder.diskSizeGb(diskSizeGb); + Builder setDiskSizeGb(Long diskSizeGb) { + infoBuilder.setDiskSizeGb(diskSizeGb); return this; } @Override - Builder licenses(List licenses) { - infoBuilder.licenses(licenses); + Builder setLicenses(List licenses) { + infoBuilder.setLicenses(licenses); return this; } @Override - Builder deprecationStatus(DeprecationStatus deprecationStatus) { - infoBuilder.deprecationStatus(deprecationStatus); + Builder setDeprecationStatus(DeprecationStatus deprecationStatus) { + infoBuilder.setDeprecationStatus(deprecationStatus); return this; } @@ -148,7 +166,7 @@ public boolean exists() { * @throws ComputeException upon failure */ public Image reload(ImageOption... options) { - return compute.getImage(imageId(), options); + return compute.getImage(getImageId(), options); } /** @@ -159,7 +177,7 @@ public Image reload(ImageOption... options) { * @throws ComputeException upon failure or if this image is a publicly-available image */ public Operation delete(OperationOption... options) { - return compute.deleteImage(imageId(), options); + return compute.deleteImage(getImageId(), options); } /** @@ -171,13 +189,21 @@ public Operation delete(OperationOption... options) { */ public Operation deprecate(DeprecationStatus deprecationStatus, OperationOption... options) { - return compute.deprecate(imageId(), deprecationStatus, options); + return compute.deprecate(getImageId(), deprecationStatus, options); } /** * Returns the image's {@code Compute} object used to issue requests. */ + @Deprecated public Compute compute() { + return getCompute(); + } + + /** + * Returns the image's {@code Compute} object used to issue requests. + */ + public Compute getCompute() { return compute; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/ImageConfiguration.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/ImageConfiguration.java index 34b12dab16af..916456f196b3 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/ImageConfiguration.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/ImageConfiguration.java @@ -92,17 +92,17 @@ B self() { return (B) this; } - B type(Type type) { + B setType(Type type) { this.type = type; return self(); } - B sourceType(SourceType sourceType) { + B setSourceType(SourceType sourceType) { this.sourceType = sourceType; return self(); } - B archiveSizeBytes(Long archiveSizeBytes) { + B setArchiveSizeBytes(Long archiveSizeBytes) { this.archiveSizeBytes = archiveSizeBytes; return self(); } @@ -124,21 +124,47 @@ B archiveSizeBytes(Long archiveSizeBytes) { * an existing disk. This method returns {@link Type#STORAGE} if this image was created from a * file in Google Cloud Storage. */ + @Deprecated public Type type() { + return getType(); + } + + /** + * Returns the image's type. This method returns {@link Type#DISK} if this image was created from + * an existing disk. This method returns {@link Type#STORAGE} if this image was created from a + * file in Google Cloud Storage. + */ + public Type getType() { return type; } /** * Returns the source type of the disk. The default and only value is {@link SourceType#RAW}. */ + @Deprecated public SourceType sourceType() { + return getSourceType(); + } + + /** + * Returns the source type of the disk. The default and only value is {@link SourceType#RAW}. + */ + public SourceType getSourceType() { return sourceType; } /** * Returns the size of the image archive stored in Google Cloud Storage (in bytes). */ + @Deprecated public Long archiveSizeBytes() { + return getArchiveSizeBytes(); + } + + /** + * Returns the size of the image archive stored in Google Cloud Storage (in bytes). + */ + public Long getArchiveSizeBytes() { return archiveSizeBytes; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/ImageDiskConfiguration.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/ImageDiskConfiguration.java index cf8ede2f061a..41c99247316c 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/ImageDiskConfiguration.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/ImageDiskConfiguration.java @@ -67,20 +67,39 @@ private Builder(Disk diskPb) { * the image's size then disk creation will fail. */ @Override + @Deprecated public Builder sizeGb(Long sizeGb) { - super.sizeGb(sizeGb); + return setSizeGb(sizeGb); + } + + /** + * Sets the size of the persistent disk, in GB. If not set the disk will have the size of the + * image. This value can be larger than the image's size. If the provided size is smaller than + * the image's size then disk creation will fail. + */ + @Override + public Builder setSizeGb(Long sizeGb) { + super.setSizeGb(sizeGb); return this; } /** * Sets the identity of the source image used to create the disk. */ + @Deprecated public Builder sourceImage(ImageId sourceImage) { + return setSourceImage(sourceImage); + } + + /** + * Sets the identity of the source image used to create the disk. + */ + public Builder setSourceImage(ImageId sourceImage) { this.sourceImage = checkNotNull(sourceImage); return this; } - Builder sourceImageId(String sourceImageId) { + Builder setSourceImageId(String sourceImageId) { this.sourceImageId = sourceImageId; return this; } @@ -103,7 +122,15 @@ private ImageDiskConfiguration(Builder builder) { /** * Returns the identity of the source image used to create the disk. */ + @Deprecated public ImageId sourceImage() { + return getSourceImage(); + } + + /** + * Returns the identity of the source image used to create the disk. + */ + public ImageId getSourceImage() { return sourceImage; } @@ -114,7 +141,19 @@ public ImageId sourceImage() { * name, the source image service-generated id would identify the exact version of the image that * was used. */ + @Deprecated public String sourceImageId() { + return getSourceImageId(); + } + + /** + * Returns the service-generated unique id of the image used to create this disk. This value + * identifies the exact image that was used to create this persistent disk. For example, if you + * created the persistent disk from an image that was later deleted and recreated under the same + * name, the source image service-generated id would identify the exact version of the image that + * was used. + */ + public String getSourceImageId() { return sourceImageId; } @@ -145,22 +184,30 @@ public final boolean equals(Object obj) { @Override ImageDiskConfiguration setProjectId(String projectId) { - Builder builder = toBuilder().sourceImage(sourceImage.setProjectId(projectId)); - if (diskType() != null) { - builder.diskType(diskType().setProjectId(projectId)); + Builder builder = toBuilder().setSourceImage(sourceImage.setProjectId(projectId)); + if (getDiskType() != null) { + builder.setDiskType(getDiskType().setProjectId(projectId)); } return builder.build(); } @Override Disk toPb() { - return super.toPb().setSourceImage(sourceImage.selfLink()).setSourceImageId(sourceImageId); + return super.toPb().setSourceImage(sourceImage.getSelfLink()).setSourceImageId(sourceImageId); } /** * Returns a builder for an {@code ImageDiskConfiguration} object given the image identity. */ + @Deprecated public static Builder builder(ImageId imageId) { + return newBuilder(imageId); + } + + /** + * Returns a builder for an {@code ImageDiskConfiguration} object given the image identity. + */ + public static Builder newBuilder(ImageId imageId) { return new Builder(imageId); } @@ -168,7 +215,7 @@ public static Builder builder(ImageId imageId) { * Returns an {@code ImageDiskConfiguration} object given the image identity. */ public static ImageDiskConfiguration of(ImageId imageId) { - return builder(imageId).build(); + return newBuilder(imageId).build(); } @SuppressWarnings("unchecked") diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/ImageId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/ImageId.java index 51a252afd6cc..b85c5a9b3eec 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/ImageId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/ImageId.java @@ -39,7 +39,7 @@ public ImageId apply(String pb) { static final Function TO_URL_FUNCTION = new Function() { @Override public String apply(ImageId imageId) { - return imageId.selfLink(); + return imageId.getSelfLink(); } }; @@ -62,13 +62,32 @@ private ImageId(String project, String image) { * * @see RFC1035 */ + @Deprecated public String image() { + return getImage(); + } + + /** + * Returns the name of the image. The name must be 1-63 characters long and comply with RFC1035. + * Specifically, the name must match the regular expression {@code [a-z]([-a-z0-9]*[a-z0-9])?} + * which means the first character must be a lowercase letter, and all following characters must + * be a dash, lowercase letter, or digit, except the last character, which cannot be a dash. + * + * @see RFC1035 + */ + public String getImage() { return image; } @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/global/images/" + image; + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/global/images/" + image; } @Override @@ -95,7 +114,7 @@ public boolean equals(Object obj) { @Override ImageId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } return ImageId.of(projectId, image); diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/ImageInfo.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/ImageInfo.java index 102e2c742d71..c128b5e2461b 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/ImageInfo.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/ImageInfo.java @@ -99,34 +99,54 @@ public enum Status { */ public abstract static class Builder { - abstract Builder generatedId(String generatedId); + abstract Builder setGeneratedId(String generatedId); - abstract Builder creationTimestamp(Long creationTimestamp); + abstract Builder getCreationTimestamp(Long creationTimestamp); /** * Sets the image identity. */ + @Deprecated public abstract Builder imageId(ImageId imageId); + /** + * Sets the image identity. + */ + public abstract Builder setImageId(ImageId imageId); + /** * Sets an optional textual description of the image. */ + @Deprecated public abstract Builder description(String description); + /** + * Sets an optional textual description of the image. + */ + public abstract Builder setDescription(String description); + /** * Sets the image configuration. Use {@link DiskImageConfiguration} to create an image from an * existing disk. Use {@link StorageImageConfiguration} to create an image from a file stored in * Google Cloud Storage. */ + @Deprecated public abstract Builder configuration(ImageConfiguration configuration); - abstract Builder status(Status status); + /** + * Sets the image configuration. Use {@link DiskImageConfiguration} to create an image from an + * existing disk. Use {@link StorageImageConfiguration} to create an image from a file stored in + * Google Cloud Storage. + */ + public abstract Builder setConfiguration(ImageConfiguration configuration); + + abstract Builder setStatus(Status status); - abstract Builder diskSizeGb(Long diskSizeGb); + abstract Builder setDiskSizeGb(Long diskSizeGb); - abstract Builder licenses(List licenses); + abstract Builder setLicenses(List licenses); - abstract Builder deprecationStatus(DeprecationStatus deprecationStatus); + abstract Builder setDeprecationStatus(DeprecationStatus deprecationStatus); /** * Creates a {@code ImageInfo} object. @@ -184,55 +204,73 @@ static final class BuilderImpl extends Builder { } @Override - BuilderImpl generatedId(String generatedId) { + BuilderImpl setGeneratedId(String generatedId) { this.generatedId = generatedId; return this; } @Override - BuilderImpl creationTimestamp(Long creationTimestamp) { + BuilderImpl getCreationTimestamp(Long creationTimestamp) { this.creationTimestamp = creationTimestamp; return this; } @Override + @Deprecated public BuilderImpl imageId(ImageId imageId) { + return setImageId(imageId); + } + + @Override + public BuilderImpl setImageId(ImageId imageId) { this.imageId = checkNotNull(imageId); return this; } @Override + @Deprecated public BuilderImpl description(String description) { + return setDescription(description); + } + + @Override + public BuilderImpl setDescription(String description) { this.description = description; return this; } @Override + @Deprecated public BuilderImpl configuration(ImageConfiguration configuration) { + return setConfiguration(configuration); + } + + @Override + public BuilderImpl setConfiguration(ImageConfiguration configuration) { this.configuration = checkNotNull(configuration); return this; } @Override - BuilderImpl status(Status status) { + BuilderImpl setStatus(Status status) { this.status = status; return this; } @Override - BuilderImpl diskSizeGb(Long diskSizeGb) { + BuilderImpl setDiskSizeGb(Long diskSizeGb) { this.diskSizeGb = diskSizeGb; return this; } @Override - BuilderImpl licenses(List licenses) { + BuilderImpl setLicenses(List licenses) { this.licenses = licenses != null ? ImmutableList.copyOf(licenses) : null; return this; } @Override - BuilderImpl deprecationStatus(DeprecationStatus deprecationStatus) { + BuilderImpl setDeprecationStatus(DeprecationStatus deprecationStatus) { this.deprecationStatus = deprecationStatus; return this; } @@ -258,28 +296,60 @@ public ImageInfo build() { /** * Returns the service-generated unique identifier for the image. */ + @Deprecated public String generatedId() { + return getGeneratedId(); + } + + /** + * Returns the service-generated unique identifier for the image. + */ + public String getGeneratedId() { return generatedId; } /** * Returns the creation timestamp in milliseconds since epoch. */ + @Deprecated public Long creationTimestamp() { + return getCreationTimestamp(); + } + + /** + * Returns the creation timestamp in milliseconds since epoch. + */ + public Long getCreationTimestamp() { return creationTimestamp; } /** * Returns the image identity. */ + @Deprecated public ImageId imageId() { + return getImageId(); + } + + /** + * Returns the image identity. + */ + public ImageId getImageId() { return imageId; } /** * Returns a textual description of the image. */ + @Deprecated public String description() { + return getDescription(); + } + + /** + * Returns a textual description of the image. + */ + public String getDescription() { return description; } @@ -290,14 +360,34 @@ public String description() { * from a file stored in Google Cloud Storage. */ @SuppressWarnings("unchecked") + @Deprecated public T configuration() { + return getConfiguration(); + } + + /** + * Returns the image configuration. This method returns an instance of + * {@link DiskImageConfiguration} if the the image was created from a Google Compute Engine disk. + * This method returns an instance of {@link StorageImageConfiguration} if the image was created + * from a file stored in Google Cloud Storage. + */ + @SuppressWarnings("unchecked") + public T getConfiguration() { return (T) configuration; } /** * Returns all applicable publicly visible licenses. */ + @Deprecated public List licenses() { + return getLicenses(); + } + + /** + * Returns all applicable publicly visible licenses. + */ + public List getLicenses() { return licenses; } @@ -305,14 +395,31 @@ public List licenses() { * Returns the status of the image. An image can be used to create other disks only after it has * been successfully created and its status is set to {@link Status#READY}. */ + @Deprecated public Status status() { + return getStatus(); + } + + /** + * Returns the status of the image. An image can be used to create other disks only after it has + * been successfully created and its status is set to {@link Status#READY}. + */ + public Status getStatus() { return status; } /** * Returns the size of the image when restored onto a persistent disk (in GB). */ + @Deprecated public Long diskSizeGb() { + return getDiskSizeGb(); + } + + /** + * Returns the size of the image when restored onto a persistent disk (in GB). + */ + public Long getDiskSizeGb() { return diskSizeGb; } @@ -321,7 +428,17 @@ public Long diskSizeGb() { * {@link DeprecationStatus.Status#DELETED} or {@link DeprecationStatus.Status#OBSOLETE} the * image must not be used. Returns {@code null} if the image is not deprecated. */ + @Deprecated public DeprecationStatus deprecationStatus() { + return getDeprecationStatus(); + } + + /** + * Returns the deprecation status of the image. If {@link DeprecationStatus#status()} is either + * {@link DeprecationStatus.Status#DELETED} or {@link DeprecationStatus.Status#OBSOLETE} the + * image must not be used. Returns {@code null} if the image is not deprecated. + */ + public DeprecationStatus getDeprecationStatus() { return deprecationStatus; } @@ -362,8 +479,8 @@ public boolean equals(Object obj) { ImageInfo setProjectId(String projectId) { return toBuilder() - .imageId(imageId.setProjectId(projectId)) - .configuration(configuration.setProjectId(projectId)) + .setImageId(imageId.setProjectId(projectId)) + .setConfiguration(configuration.setProjectId(projectId)) .build(); } @@ -375,9 +492,9 @@ Image toPb() { if (creationTimestamp != null) { imagePb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp)); } - imagePb.setName(imageId.image()); + imagePb.setName(imageId.getImage()); imagePb.setDescription(description); - imagePb.setSelfLink(imageId.selfLink()); + imagePb.setSelfLink(imageId.getSelfLink()); if (status != null) { imagePb.setStatus(status.name()); } @@ -397,8 +514,19 @@ Image toPb() { * {@link StorageImageConfiguration} to create an image from a file stored in Google Cloud * Storage. */ + @Deprecated public static Builder builder(ImageId imageId, ImageConfiguration configuration) { - return new BuilderImpl().imageId(imageId).configuration(configuration); + return newBuilder(imageId, configuration); + } + + /** + * Returns a builder for an {@code ImageInfo} object given the image identity and an image + * configuration. Use {@link DiskImageConfiguration} to create an image from an existing disk. Use + * {@link StorageImageConfiguration} to create an image from a file stored in Google Cloud + * Storage. + */ + public static Builder newBuilder(ImageId imageId, ImageConfiguration configuration) { + return new BuilderImpl().setImageId(imageId).setConfiguration(configuration); } /** @@ -408,7 +536,7 @@ public static Builder builder(ImageId imageId, ImageConfiguration configuration) * Storage. */ public static ImageInfo of(ImageId imageId, ImageConfiguration configuration) { - return builder(imageId, configuration).build(); + return newBuilder(imageId, configuration).build(); } static ImageInfo fromPb(Image imagePb) { diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/Instance.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/Instance.java index e1ee91f4e58d..c28761cbeaa9 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/Instance.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/Instance.java @@ -59,9 +59,9 @@ public static class Builder extends InstanceInfo.Builder { AttachedDisk attachedDisk, NetworkInterface networkInterface) { this.compute = compute; this.infoBuilder = new InstanceInfo.BuilderImpl(instanceId); - this.infoBuilder.machineType(machineType); - this.infoBuilder.attachedDisks(ImmutableList.of(attachedDisk)); - this.infoBuilder.networkInterfaces(ImmutableList.of(networkInterface)); + this.infoBuilder.setMachineType(machineType); + this.infoBuilder.setAttachedDisks(ImmutableList.of(attachedDisk)); + this.infoBuilder.setNetworkInterfaces(ImmutableList.of(networkInterface)); } Builder(Instance instance) { @@ -70,104 +70,176 @@ public static class Builder extends InstanceInfo.Builder { } @Override - Builder generatedId(String generatedId) { - this.infoBuilder.generatedId(generatedId); + Builder setGeneratedId(String generatedId) { + this.infoBuilder.setGeneratedId(generatedId); return this; } @Override + @Deprecated public Builder instanceId(InstanceId instanceId) { - this.infoBuilder.instanceId(instanceId); + return setInstanceId(instanceId); + } + + @Override + public Builder setInstanceId(InstanceId instanceId) { + this.infoBuilder.setInstanceId(instanceId); return this; } @Override - Builder creationTimestamp(Long creationTimestamp) { - this.infoBuilder.creationTimestamp(creationTimestamp); + Builder setCreationTimestamp(Long creationTimestamp) { + this.infoBuilder.setCreationTimestamp(creationTimestamp); return this; } @Override + @Deprecated public Builder description(String description) { - this.infoBuilder.description(description); + return setDescription(description); + } + + @Override + public Builder setDescription(String description) { + this.infoBuilder.setDescription(description); return this; } @Override - Builder status(Status status) { - this.infoBuilder.status(status); + Builder setStatus(Status status) { + this.infoBuilder.setStatus(status); return this; } @Override - Builder statusMessage(String statusMessage) { - this.infoBuilder.statusMessage(statusMessage); + Builder setStatusMessage(String statusMessage) { + this.infoBuilder.setStatusMessage(statusMessage); return this; } @Override + @Deprecated public Builder tags(Tags tags) { - this.infoBuilder.tags(tags); + return setTags(tags); + } + + @Override + public Builder setTags(Tags tags) { + this.infoBuilder.setTags(tags); return this; } @Override + @Deprecated public Builder machineType(MachineTypeId machineType) { - this.infoBuilder.machineType(machineType); + return setMachineType(machineType); + } + + @Override + public Builder setMachineType(MachineTypeId machineType) { + this.infoBuilder.setMachineType(machineType); return this; } @Override + @Deprecated public Builder canIpForward(Boolean canIpForward) { - this.infoBuilder.canIpForward(canIpForward); + return setCanIpForward(canIpForward); + } + + @Override + public Builder setCanIpForward(Boolean canIpForward) { + this.infoBuilder.setCanIpForward(canIpForward); return this; } @Override + @Deprecated public Builder networkInterfaces(List networkInterfaces) { - this.infoBuilder.networkInterfaces(networkInterfaces); + return setNetworkInterfaces(networkInterfaces); + } + + @Override + public Builder setNetworkInterfaces(List networkInterfaces) { + this.infoBuilder.setNetworkInterfaces(networkInterfaces); return this; } @Override + @Deprecated public Builder networkInterfaces(NetworkInterface... networkInterfaces) { - this.infoBuilder.networkInterfaces(networkInterfaces); + return setNetworkInterfaces(networkInterfaces); + } + + @Override + public Builder setNetworkInterfaces(NetworkInterface... networkInterfaces) { + this.infoBuilder.setNetworkInterfaces(networkInterfaces); return this; } @Override + @Deprecated public Builder attachedDisks(List attachedDisks) { - this.infoBuilder.attachedDisks(attachedDisks); + return setAttachedDisks(attachedDisks); + } + + @Override + public Builder setAttachedDisks(List attachedDisks) { + this.infoBuilder.setAttachedDisks(attachedDisks); return this; } @Override + @Deprecated public Builder attachedDisks(AttachedDisk... attachedDisks) { - this.infoBuilder.attachedDisks(attachedDisks); + return setAttachedDisks(attachedDisks); + } + + @Override + public Builder setAttachedDisks(AttachedDisk... attachedDisks) { + this.infoBuilder.setAttachedDisks(attachedDisks); return this; } @Override + @Deprecated public Builder metadata(Metadata metadata) { - this.infoBuilder.metadata(metadata); + return setMetadata(metadata); + } + + @Override + public Builder setMetadata(Metadata metadata) { + this.infoBuilder.setMetadata(metadata); return this; } @Override + @Deprecated public Builder serviceAccounts(List serviceAccounts) { - this.infoBuilder.serviceAccounts(serviceAccounts); + return setServiceAccounts(serviceAccounts); + } + + @Override + public Builder setServiceAccounts(List serviceAccounts) { + this.infoBuilder.setServiceAccounts(serviceAccounts); return this; } @Override + @Deprecated public Builder schedulingOptions(SchedulingOptions schedulingOptions) { - this.infoBuilder.schedulingOptions(schedulingOptions); + return setSchedulingOptions(schedulingOptions); + } + + @Override + public Builder setSchedulingOptions(SchedulingOptions schedulingOptions) { + this.infoBuilder.setSchedulingOptions(schedulingOptions); return this; } @Override - Builder cpuPlatform(String cpuPlatform) { - this.infoBuilder.cpuPlatform(cpuPlatform); + Builder setCpuPlatform(String cpuPlatform) { + this.infoBuilder.setCpuPlatform(cpuPlatform); return this; } @@ -202,7 +274,7 @@ public boolean exists() { * @throws ComputeException upon failure */ public Instance reload(InstanceOption... options) { - return compute.getInstance(instanceId(), options); + return compute.getInstance(getInstanceId(), options); } /** @@ -213,7 +285,7 @@ public Instance reload(InstanceOption... options) { * @throws ComputeException upon failure */ public Operation delete(OperationOption... options) { - return compute.deleteInstance(instanceId(), options); + return compute.deleteInstance(getInstanceId(), options); } /** @@ -225,7 +297,7 @@ public Operation delete(OperationOption... options) { */ public Operation addAccessConfig(String networkInterface, AccessConfig accessConfig, OperationOption... options) { - return compute.addAccessConfig(instanceId(), networkInterface, accessConfig, options); + return compute.addAccessConfig(getInstanceId(), networkInterface, accessConfig, options); } /** @@ -237,7 +309,7 @@ public Operation addAccessConfig(String networkInterface, AccessConfig accessCon */ public Operation attachDisk(PersistentDiskConfiguration configuration, OperationOption... options) { - return compute.attachDisk(instanceId(), configuration, options); + return compute.attachDisk(getInstanceId(), configuration, options); } /** @@ -249,7 +321,7 @@ public Operation attachDisk(PersistentDiskConfiguration configuration, */ public Operation attachDisk(String deviceName, PersistentDiskConfiguration configuration, OperationOption... options) { - return compute.attachDisk(instanceId(), deviceName, configuration, options); + return compute.attachDisk(getInstanceId(), deviceName, configuration, options); } /** @@ -262,7 +334,7 @@ public Operation attachDisk(String deviceName, PersistentDiskConfiguration confi */ public Operation attachDisk(String deviceName, PersistentDiskConfiguration configuration, int index, OperationOption... options) { - return compute.attachDisk(instanceId(), deviceName, configuration, index, options); + return compute.attachDisk(getInstanceId(), deviceName, configuration, index, options); } /** @@ -274,7 +346,7 @@ public Operation attachDisk(String deviceName, PersistentDiskConfiguration confi */ public Operation deleteAccessConfig(String networkInterface, String accessConfig, OperationOption... options) { - return compute.deleteAccessConfig(instanceId(), networkInterface, accessConfig, options); + return compute.deleteAccessConfig(getInstanceId(), networkInterface, accessConfig, options); } /** @@ -285,7 +357,7 @@ public Operation deleteAccessConfig(String networkInterface, String accessConfig * @throws ComputeException upon failure */ public Operation detachDisk(String deviceName, OperationOption... options) { - return compute.detachDisk(instanceId(), deviceName, options); + return compute.detachDisk(getInstanceId(), deviceName, options); } /** @@ -296,7 +368,7 @@ public Operation detachDisk(String deviceName, OperationOption... options) { * @throws ComputeException upon failure */ public String getSerialPortOutput(int port) { - return compute.getSerialPortOutput(instanceId(), port); + return compute.getSerialPortOutput(getInstanceId(), port); } /** @@ -307,7 +379,7 @@ public String getSerialPortOutput(int port) { * @throws ComputeException upon failure */ public String getSerialPortOutput() { - return compute.getSerialPortOutput(instanceId()); + return compute.getSerialPortOutput(getInstanceId()); } /** @@ -318,7 +390,7 @@ public String getSerialPortOutput() { * @throws ComputeException upon failure */ public Operation reset(OperationOption... options) { - return compute.reset(instanceId(), options); + return compute.reset(getInstanceId(), options); } /** @@ -330,7 +402,7 @@ public Operation reset(OperationOption... options) { */ public Operation setDiskAutoDelete(String deviceName, boolean autoDelete, OperationOption... options) { - return compute.setDiskAutoDelete(instanceId(), deviceName, autoDelete, options); + return compute.setDiskAutoDelete(getInstanceId(), deviceName, autoDelete, options); } /** @@ -342,7 +414,7 @@ public Operation setDiskAutoDelete(String deviceName, boolean autoDelete, * @throws ComputeException upon failure */ public Operation setMachineType(MachineTypeId machineType, OperationOption... options) { - return compute.setMachineType(instanceId(), machineType, options); + return compute.setMachineType(getInstanceId(), machineType, options); } /** @@ -353,7 +425,7 @@ public Operation setMachineType(MachineTypeId machineType, OperationOption... op * @throws ComputeException upon failure */ public Operation setMetadata(Metadata metadata, OperationOption... options) { - return compute.setMetadata(instanceId(), metadata, options); + return compute.setMetadata(getInstanceId(), metadata, options); } /** @@ -365,7 +437,7 @@ public Operation setMetadata(Metadata metadata, OperationOption... options) { * @throws ComputeException upon failure */ public Operation setMetadata(Map metadata, OperationOption... options) { - return setMetadata(metadata().toBuilder().values(metadata).build(), options); + return setMetadata(getMetadata().toBuilder().setValues(metadata).build(), options); } /** @@ -376,7 +448,7 @@ public Operation setMetadata(Map metadata, OperationOption... op * @throws ComputeException upon failure */ public Operation setSchedulingOptions(SchedulingOptions scheduling, OperationOption... options) { - return compute.setSchedulingOptions(instanceId(), scheduling, options); + return compute.setSchedulingOptions(getInstanceId(), scheduling, options); } /** @@ -387,7 +459,7 @@ public Operation setSchedulingOptions(SchedulingOptions scheduling, OperationOpt * @throws ComputeException upon failure */ public Operation setTags(Tags tags, OperationOption... options) { - return compute.setTags(instanceId(), tags, options); + return compute.setTags(getInstanceId(), tags, options); } /** @@ -399,7 +471,7 @@ public Operation setTags(Tags tags, OperationOption... options) { * @throws ComputeException upon failure */ public Operation setTags(Iterable tags, OperationOption... options) { - return setTags(tags().toBuilder().values(tags).build(), options); + return setTags(getTags().toBuilder().setValues(tags).build(), options); } /** @@ -410,7 +482,7 @@ public Operation setTags(Iterable tags, OperationOption... options) { * @throws ComputeException upon failure */ public Operation start(OperationOption... options) { - return compute.start(instanceId(), options); + return compute.start(getInstanceId(), options); } /** @@ -421,13 +493,21 @@ public Operation start(OperationOption... options) { * @throws ComputeException upon failure */ public Operation stop(OperationOption... options) { - return compute.stop(instanceId(), options); + return compute.stop(getInstanceId(), options); } /** * Returns the snapshot's {@code Compute} object used to issue requests. */ + @Deprecated public Compute compute() { + return getCompute(); + } + + /** + * Returns the snapshot's {@code Compute} object used to issue requests. + */ + public Compute getCompute() { return compute; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/InstanceId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/InstanceId.java index 8fde843020f3..607abeacd999 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/InstanceId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/InstanceId.java @@ -39,7 +39,7 @@ public InstanceId apply(String pb) { static final Function TO_URL_FUNCTION = new Function() { @Override public String apply(InstanceId instanceId) { - return instanceId.selfLink(); + return instanceId.getSelfLink(); } }; @@ -65,27 +65,63 @@ private InstanceId(String project, String zone, String instance) { * * @see RFC1035 */ + @Deprecated public String instance() { + return getInstance(); + } + + /** + * Returns the name of the instance. The name must be 1-63 characters long and comply with + * RFC1035. Specifically, the name must match the regular expression + * {@code [a-z]([-a-z0-9]*[a-z0-9])?} which means the first character must be a lowercase letter, + * and all following characters must be a dash, lowercase letter, or digit, except the last + * character, which cannot be a dash. + * + * @see RFC1035 + */ + public String getInstance() { return instance; } /** * Returns the name of the zone this instance belongs to. */ + @Deprecated public String zone() { + return getZone(); + } + + /** + * Returns the name of the zone this instance belongs to. + */ + public String getZone() { return zone; } /** * Returns the identity of the zone this instance belongs to. */ + @Deprecated public ZoneId zoneId() { - return ZoneId.of(project(), zone); + return getZoneId(); + } + + /** + * Returns the identity of the zone this instance belongs to. + */ + public ZoneId getZoneId() { + return ZoneId.of(getProject(), zone); } @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/zones/" + zone + "/instances/" + instance; + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/zones/" + zone + "/instances/" + instance; } @Override @@ -114,7 +150,7 @@ public boolean equals(Object obj) { @Override InstanceId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } return InstanceId.of(projectId, zone, instance); @@ -130,7 +166,7 @@ InstanceId setProjectId(String projectId) { * @see RFC1035 */ public static InstanceId of(ZoneId zoneId, String instance) { - return new InstanceId(zoneId.project(), zoneId.zone(), instance); + return new InstanceId(zoneId.getProject(), zoneId.getZone(), instance); } /** diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/InstanceInfo.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/InstanceInfo.java index 7f85985afd2d..05dfd52d7e70 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/InstanceInfo.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/InstanceInfo.java @@ -125,35 +125,60 @@ public enum Status { */ public abstract static class Builder { - abstract Builder generatedId(String generatedId); + abstract Builder setGeneratedId(String generatedId); /** * Sets the identity of the virtual machine instance. */ + @Deprecated public abstract Builder instanceId(InstanceId instanceId); - abstract Builder creationTimestamp(Long creationTimestamp); + /** + * Sets the identity of the virtual machine instance. + */ + public abstract Builder setInstanceId(InstanceId instanceId); + + abstract Builder setCreationTimestamp(Long creationTimestamp); /** * Sets an optional description of this Google Compute Engine instance. */ + @Deprecated public abstract Builder description(String description); - abstract Builder status(Status status); + /** + * Sets an optional description of this Google Compute Engine instance. + */ + public abstract Builder setDescription(String description); + + abstract Builder setStatus(Status status); - abstract Builder statusMessage(String statusMessage); + abstract Builder setStatusMessage(String statusMessage); /** * Sets the tags to apply to this instance. Tags are used to identify valid sources or targets * for network firewalls. */ + @Deprecated public abstract Builder tags(Tags tags); + /** + * Sets the tags to apply to this instance. Tags are used to identify valid sources or targets + * for network firewalls. + */ + public abstract Builder setTags(Tags tags); + /** * Sets the machine type identity. */ + @Deprecated public abstract Builder machineType(MachineTypeId machineType); + /** + * Sets the machine type identity. + */ + public abstract Builder setMachineType(MachineTypeId machineType); + /** * Sets whether to allow this instance to send and receive packets with non-matching destination * or source IPs. This is required if you plan to use this instance to forward routes. @@ -161,13 +186,24 @@ public abstract static class Builder { * @see Enabling IP * Forwarding */ + @Deprecated public abstract Builder canIpForward(Boolean canIpForward); + /** + * Sets whether to allow this instance to send and receive packets with non-matching destination + * or source IPs. This is required if you plan to use this instance to forward routes. + * + * @see Enabling IP + * Forwarding + */ + public abstract Builder setCanIpForward(Boolean canIpForward); + /** * Sets a list of network interfaces. This specifies how this instance is configured to interact * with other network services, such as connecting to the internet. At the moment, instances * only support one network interface. */ + @Deprecated public abstract Builder networkInterfaces(List networkInterfaces); /** @@ -175,25 +211,60 @@ public abstract static class Builder { * with other network services, such as connecting to the internet. At the moment, instances * only support one network interface. */ + public abstract Builder setNetworkInterfaces(List networkInterfaces); + + /** + * Sets a list of network interfaces. This specifies how this instance is configured to interact + * with other network services, such as connecting to the internet. At the moment, instances + * only support one network interface. + */ + @Deprecated public abstract Builder networkInterfaces(NetworkInterface... networkInterfaces); + /** + * Sets a list of network interfaces. This specifies how this instance is configured to interact + * with other network services, such as connecting to the internet. At the moment, instances + * only support one network interface. + */ + public abstract Builder setNetworkInterfaces(NetworkInterface... networkInterfaces); + /** * Sets a list of disks to attach to the instance. One boot disk must be provided (i.e. an * attached disk such that {@link AttachedDisk.AttachedDiskConfiguration#boot()} returns * {@code true}). */ + @Deprecated public abstract Builder attachedDisks(List attachedDisks); + /** + * Sets a list of disks to attach to the instance. One boot disk must be provided (i.e. an + * attached disk such that {@link AttachedDisk.AttachedDiskConfiguration#boot()} returns + * {@code true}). + */ + public abstract Builder setAttachedDisks(List attachedDisks); + /** * Sets a list of disks to attach to the instance. One boot disk must be provided. */ + @Deprecated public abstract Builder attachedDisks(AttachedDisk... attachedDisks); + /** + * Sets a list of disks to attach to the instance. One boot disk must be provided. + */ + public abstract Builder setAttachedDisks(AttachedDisk... attachedDisks); + /** * Sets the instance metadata. */ + @Deprecated public abstract Builder metadata(Metadata metadata); + /** + * Sets the instance metadata. + */ + public abstract Builder setMetadata(Metadata metadata); + /** * Sets a list of service accounts, with their specified scopes, authorized for this instance. * Service accounts generate access tokens that can be accessed through the metadata server and @@ -202,14 +273,31 @@ public abstract static class Builder { * @see Authenticating from * Google Compute Engine */ + @Deprecated public abstract Builder serviceAccounts(List serviceAccounts); + /** + * Sets a list of service accounts, with their specified scopes, authorized for this instance. + * Service accounts generate access tokens that can be accessed through the metadata server and + * used to authenticate applications on the instance. + * + * @see Authenticating from + * Google Compute Engine + */ + public abstract Builder setServiceAccounts(List serviceAccounts); + /** * Sets the scheduling options for the instance. */ + @Deprecated public abstract Builder schedulingOptions(SchedulingOptions schedulingOptions); - abstract Builder cpuPlatform(String cpuPlatform); + /** + * Sets the scheduling options for the instance. + */ + public abstract Builder setSchedulingOptions(SchedulingOptions schedulingOptions); + + abstract Builder setCpuPlatform(String cpuPlatform); /** * Creates an {@code InstanceInfo} object. @@ -298,103 +386,175 @@ public static final class BuilderImpl extends Builder { } @Override - Builder generatedId(String generatedId) { + Builder setGeneratedId(String generatedId) { this.generatedId = generatedId; return this; } @Override + @Deprecated public Builder instanceId(InstanceId instanceId) { + return setInstanceId(instanceId); + } + + @Override + public Builder setInstanceId(InstanceId instanceId) { this.instanceId = checkNotNull(instanceId); return this; } @Override - Builder creationTimestamp(Long creationTimestamp) { + Builder setCreationTimestamp(Long creationTimestamp) { this.creationTimestamp = creationTimestamp; return this; } @Override + @Deprecated public Builder description(String description) { + return setDescription(description); + } + + @Override + public Builder setDescription(String description) { this.description = description; return this; } @Override - Builder status(Status status) { + Builder setStatus(Status status) { this.status = status; return this; } @Override - Builder statusMessage(String statusMessage) { + Builder setStatusMessage(String statusMessage) { this.statusMessage = statusMessage; return this; } @Override + @Deprecated public Builder tags(Tags tags) { + return setTags(tags); + } + + @Override + public Builder setTags(Tags tags) { this.tags = tags; return this; } @Override + @Deprecated public Builder machineType(MachineTypeId machineType) { + return setMachineType(machineType); + } + + @Override + public Builder setMachineType(MachineTypeId machineType) { this.machineType = checkNotNull(machineType); return this; } @Override + @Deprecated public Builder canIpForward(Boolean canIpForward) { + return setCanIpForward(canIpForward); + } + + @Override + public Builder setCanIpForward(Boolean canIpForward) { this.canIpForward = canIpForward; return this; } @Override + @Deprecated public Builder networkInterfaces(List networkInterfaces) { + return setNetworkInterfaces(networkInterfaces); + } + + @Override + public Builder setNetworkInterfaces(List networkInterfaces) { this.networkInterfaces = ImmutableList.copyOf(checkNotNull(networkInterfaces)); return this; } @Override + @Deprecated public Builder networkInterfaces(NetworkInterface... networkInterfaces) { + return setNetworkInterfaces(networkInterfaces); + } + + @Override + public Builder setNetworkInterfaces(NetworkInterface... networkInterfaces) { this.networkInterfaces = Arrays.asList(networkInterfaces); return this; } @Override + @Deprecated public Builder attachedDisks(List attachedDisks) { + return setAttachedDisks(attachedDisks); + } + + @Override + public Builder setAttachedDisks(List attachedDisks) { this.attachedDisks = ImmutableList.copyOf(checkNotNull(attachedDisks)); return this; } @Override + @Deprecated public Builder attachedDisks(AttachedDisk... attachedDisks) { + return setAttachedDisks(attachedDisks); + } + + @Override + public Builder setAttachedDisks(AttachedDisk... attachedDisks) { this.attachedDisks = Arrays.asList(attachedDisks); return this; } @Override + @Deprecated public Builder metadata(Metadata metadata) { + return setMetadata(metadata); + } + + @Override + public Builder setMetadata(Metadata metadata) { this.metadata = metadata; return this; } @Override + @Deprecated public Builder serviceAccounts(List serviceAccounts) { + return setServiceAccounts(serviceAccounts); + } + + @Override + public Builder setServiceAccounts(List serviceAccounts) { this.serviceAccounts = ImmutableList.copyOf(checkNotNull(serviceAccounts)); return this; } @Override + @Deprecated public Builder schedulingOptions(SchedulingOptions schedulingOptions) { + return setSchedulingOptions(schedulingOptions); + } + + @Override + public Builder setSchedulingOptions(SchedulingOptions schedulingOptions) { this.schedulingOptions = schedulingOptions; return this; } @Override - Builder cpuPlatform(String cpuPlatform) { + Builder setCpuPlatform(String cpuPlatform) { this.cpuPlatform = cpuPlatform; return this; } @@ -428,42 +588,90 @@ public InstanceInfo build() { /** * Returns the service-generated unique identifier for the instance. */ + @Deprecated public String generatedId() { + return getGeneratedId(); + } + + /** + * Returns the service-generated unique identifier for the instance. + */ + public String getGeneratedId() { return generatedId; } /** * Returns the instance identity. */ + @Deprecated public InstanceId instanceId() { + return getInstanceId(); + } + + /** + * Returns the instance identity. + */ + public InstanceId getInstanceId() { return instanceId; } /** * Returns the creation timestamp in milliseconds since epoch. */ + @Deprecated public Long creationTimestamp() { + return getCreationTimestamp(); + } + + /** + * Returns the creation timestamp in milliseconds since epoch. + */ + public Long getCreationTimestamp() { return creationTimestamp; } /** * Returns a textual description of the instance. */ + @Deprecated public String description() { + return getDescription(); + } + + /** + * Returns a textual description of the instance. + */ + public String getDescription() { return description; } /** * Returns the status of the instance. */ + @Deprecated public Status status() { + return getStatus(); + } + + /** + * Returns the status of the instance. + */ + public Status getStatus() { return status; } /** * Returns an optional, human-readable explanation of the status. */ + @Deprecated public String statusMessage() { + return getStatusMessage(); + } + + /** + * Returns an optional, human-readable explanation of the status. + */ + public String getStatusMessage() { return statusMessage; } @@ -471,14 +679,31 @@ public String statusMessage() { * Returns the tags of this instance. Tags are used to identify valid sources or targets for * network firewalls. */ + @Deprecated public Tags tags() { + return getTags(); + } + + /** + * Returns the tags of this instance. Tags are used to identify valid sources or targets for + * network firewalls. + */ + public Tags getTags() { return tags; } /** * Returns the machine type identity. */ + @Deprecated public MachineTypeId machineType() { + return getMachineType(); + } + + /** + * Returns the machine type identity. + */ + public MachineTypeId getMachineType() { return machineType; } @@ -497,21 +722,46 @@ public Boolean canIpForward() { * Returns a list of network interfaces. This specifies how this instance is configured to * interact with other network services, such as connecting to the internet. */ + @Deprecated public List networkInterfaces() { + return getNetworkInterfaces(); + } + + /** + * Returns a list of network interfaces. This specifies how this instance is configured to + * interact with other network services, such as connecting to the internet. + */ + public List getNetworkInterfaces() { return networkInterfaces; } /** * Returns a list of disks attached to the instance. */ + @Deprecated public List attachedDisks() { + return getAttachedDisks(); + } + + /** + * Returns a list of disks attached to the instance. + */ + public List getAttachedDisks() { return attachedDisks; } /** * Returns the instance metadata. */ + @Deprecated public Metadata metadata() { + return getMetadata(); + } + + /** + * Returns the instance metadata. + */ + public Metadata getMetadata() { return metadata; } @@ -523,21 +773,50 @@ public Metadata metadata() { * @see Authenticating from * Google Compute Engine */ + @Deprecated public List serviceAccounts() { + return getServiceAccounts(); + } + + /** + * Returns a list of service accounts, with their specified scopes, authorized for this instance. + * Service accounts generate access tokens that can be accessed through the metadata server and + * used to authenticate applications on the instance. + * + * @see Authenticating from + * Google Compute Engine + */ + public List getServiceAccounts() { return serviceAccounts; } /** * Returns the scheduling options for the instance. */ + @Deprecated public SchedulingOptions schedulingOptions() { + return getSchedulingOptions(); + } + + /** + * Returns the scheduling options for the instance. + */ + public SchedulingOptions getSchedulingOptions() { return schedulingOptions; } /** * Returns the CPU platform used by this instance. */ + @Deprecated public String cpuPlatform() { + return getCpuPlatform(); + } + + /** + * Returns the CPU platform used by this instance. + */ + public String getCpuPlatform() { return cpuPlatform; } @@ -586,22 +865,22 @@ public boolean equals(Object obj) { InstanceInfo setProjectId(final String projectId) { Builder builder = toBuilder(); - builder.networkInterfaces(Lists.transform(networkInterfaces, + builder.setNetworkInterfaces(Lists.transform(networkInterfaces, new Function() { @Override public NetworkInterface apply(NetworkInterface networkInterface) { return networkInterface.setProjectId(projectId); } })); - builder.attachedDisks(Lists.transform(attachedDisks, + builder.setAttachedDisks(Lists.transform(attachedDisks, new Function() { @Override public AttachedDisk apply(AttachedDisk attachedDisk) { return attachedDisk.setProjectId(projectId); } })); - return builder.instanceId(instanceId.setProjectId(projectId)) - .machineType(machineType.setProjectId(projectId)) + return builder.setInstanceId(instanceId.setProjectId(projectId)) + .setMachineType(machineType.setProjectId(projectId)) .build(); } @@ -613,10 +892,10 @@ Instance toPb() { if (creationTimestamp != null) { instancePb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp)); } - instancePb.setName(instanceId.instance()); + instancePb.setName(instanceId.getInstance()); instancePb.setDescription(description); - instancePb.setSelfLink(instanceId.selfLink()); - instancePb.setZone(instanceId.zoneId().selfLink()); + instancePb.setSelfLink(instanceId.getSelfLink()); + instancePb.setZone(instanceId.getZoneId().getSelfLink()); if (status != null) { instancePb.setStatus(status.name()); } @@ -625,7 +904,7 @@ Instance toPb() { instancePb.setTags(tags.toPb()); } if (machineType != null) { - instancePb.setMachineType(machineType.selfLink()); + instancePb.setMachineType(machineType.getSelfLink()); } instancePb.setCanIpForward(canIpForward); if (networkInterfaces != null) { @@ -653,8 +932,17 @@ Instance toPb() { * Returns a builder for an {@code InstanceInfo} object given the instance identity and the * machine type. */ + @Deprecated public static Builder builder(InstanceId instanceId, MachineTypeId machineType) { - return new BuilderImpl(instanceId).machineType(machineType); + return newBuilder(instanceId, machineType); + } + + /** + * Returns a builder for an {@code InstanceInfo} object given the instance identity and the + * machine type. + */ + public static Builder newBuilder(InstanceId instanceId, MachineTypeId machineType) { + return new BuilderImpl(instanceId).setMachineType(machineType); } /** @@ -664,9 +952,9 @@ public static Builder builder(InstanceId instanceId, MachineTypeId machineType) */ public static InstanceInfo of(InstanceId instanceId, MachineTypeId machineType, AttachedDisk disk, NetworkInterface networkInterface) { - return builder(instanceId, machineType) - .attachedDisks(ImmutableList.of(disk)) - .networkInterfaces(ImmutableList.of(networkInterface)) + return newBuilder(instanceId, machineType) + .setAttachedDisks(ImmutableList.of(disk)) + .setNetworkInterfaces(ImmutableList.of(networkInterface)) .build(); } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/License.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/License.java index dc0e49bace31..d57add1f1a29 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/License.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/License.java @@ -44,10 +44,18 @@ public class License implements Serializable { /** * Returns the identity of the license. */ + @Deprecated public LicenseId licenseId() { return licenseId; } + /** + * Returns the identity of the license. + */ + public LicenseId getLicenseId() { + return licenseId; + } + /** * Returns {@code true} if the customer will be charged a license fee for running software that * contains this license on an instance. @@ -80,9 +88,9 @@ public final boolean equals(Object obj) { com.google.api.services.compute.model.License toPb() { com.google.api.services.compute.model.License licensePb = new com.google.api.services.compute.model.License(); - licensePb.setName(licenseId.license()); + licensePb.setName(licenseId.getLicense()); licensePb.setChargesUseFee(chargesUseFee); - licensePb.setSelfLink(licenseId.selfLink()); + licensePb.setSelfLink(licenseId.getSelfLink()); return licensePb; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/LicenseId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/LicenseId.java index 284572ba58bb..273c36d1050f 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/LicenseId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/LicenseId.java @@ -39,7 +39,7 @@ public LicenseId apply(String pb) { static final Function TO_URL_FUNCTION = new Function() { @Override public String apply(LicenseId licenseId) { - return licenseId.selfLink(); + return licenseId.getSelfLink(); } }; @@ -57,13 +57,27 @@ private LicenseId(String project, String license) { /** * Returns the name of the license. */ + @Deprecated public String license() { return license; } + /** + * Returns the name of the license. + */ + public String getLicense() { + return license; + } + @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/global/licenses/" + license; + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/global/licenses/" + license; } @Override @@ -90,7 +104,7 @@ public boolean equals(Object obj) { @Override LicenseId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } return LicenseId.of(projectId, license); diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/MachineType.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/MachineType.java index c850b351c946..4ce7aff7c11d 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/MachineType.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/MachineType.java @@ -84,52 +84,52 @@ static final class Builder { private Builder() {} - Builder machineTypeId(MachineTypeId machineTypeId) { + Builder setMachineTypeId(MachineTypeId machineTypeId) { this.machineTypeId = machineTypeId; return this; } - Builder generatedId(String generatedId) { + Builder setGeneratedId(String generatedId) { this.generatedId = generatedId; return this; } - Builder creationTimestamp(Long creationTimestamp) { + Builder setCreationTimestamp(Long creationTimestamp) { this.creationTimestamp = creationTimestamp; return this; } - Builder description(String description) { + Builder setDescription(String description) { this.description = description; return this; } - Builder cpus(Integer cpus) { + Builder setCpus(Integer cpus) { this.cpus = cpus; return this; } - Builder memoryMb(Integer memoryMb) { + Builder setMemoryMb(Integer memoryMb) { this.memoryMb = memoryMb; return this; } - Builder scratchDisksSizeGb(List scratchDisksSizeGb) { + Builder setScratchDisksSizeGb(List scratchDisksSizeGb) { this.scratchDisksSizeGb = scratchDisksSizeGb; return this; } - Builder maximumPersistentDisks(Integer maximumPersistentDisks) { + Builder setMaximumPersistentDisks(Integer maximumPersistentDisks) { this.maximumPersistentDisks = maximumPersistentDisks; return this; } - Builder maximumPersistentDisksSizeGb(Long maximumPersistentDisksSizeGb) { + Builder setMaximumPersistentDisksSizeGb(Long maximumPersistentDisksSizeGb) { this.maximumPersistentDisksSizeGb = maximumPersistentDisksSizeGb; return this; } - Builder deprecationStatus(DeprecationStatus deprecationStatus) { + Builder setDeprecationStatus(DeprecationStatus deprecationStatus) { this.deprecationStatus = deprecationStatus; return this; } @@ -155,63 +155,135 @@ private MachineType(Builder builder) { /** * Returns the machine type's identity. */ + @Deprecated public MachineTypeId machineTypeId() { + return getMachineTypeId(); + } + + /** + * Returns the machine type's identity. + */ + public MachineTypeId getMachineTypeId() { return machineTypeId; } /** * Returns the service-generated unique identifier for the machine type. */ + @Deprecated public String generatedId() { + return getGeneratedId(); + } + + /** + * Returns the service-generated unique identifier for the machine type. + */ + public String getGeneratedId() { return generatedId; } /** * Returns the creation timestamp in milliseconds since epoch. */ + @Deprecated public Long creationTimestamp() { + return getCreationTimestamp(); + } + + /** + * Returns the creation timestamp in milliseconds since epoch. + */ + public Long getCreationTimestamp() { return creationTimestamp; } /** * Returns an optional textual description of the machine type. */ + @Deprecated public String description() { + return getDescription(); + } + + /** + * Returns an optional textual description of the machine type. + */ + public String getDescription() { return description; } /** * Returns the number of virtual CPUs that are available to the instance. */ + @Deprecated public Integer cpus() { + return getCpus(); + } + + /** + * Returns the number of virtual CPUs that are available to the instance. + */ + public Integer getCpus() { return cpus; } /** * Returns the amount of physical memory available to the instance, defined in MB. */ + @Deprecated public Integer memoryMb() { + return getMemoryMb(); + } + + /** + * Returns the amount of physical memory available to the instance, defined in MB. + */ + public Integer getMemoryMb() { return memoryMb; } /** * Returns the size of all extended scratch disks assigned to the instance, defined in GB. */ + @Deprecated public List scratchDisksSizeGb() { + return getScratchDisksSizeGb(); + } + + /** + * Returns the size of all extended scratch disks assigned to the instance, defined in GB. + */ + public List getScratchDisksSizeGb() { return scratchDisksSizeGb; } /** * Returns the maximum number of persistent disks allowed by this instance type. */ + @Deprecated public Integer maximumPersistentDisks() { + return getMaximumPersistentDisks(); + } + + /** + * Returns the maximum number of persistent disks allowed by this instance type. + */ + public Integer getMaximumPersistentDisks() { return maximumPersistentDisks; } /** * Returns the maximum total persistent disks size allowed, defined in GB. */ + @Deprecated public Long maximumPersistentDisksSizeGb() { + return getMaximumPersistentDisksSizeGb(); + } + + /** + * Returns the maximum total persistent disks size allowed, defined in GB. + */ + public Long getMaximumPersistentDisksSizeGb() { return maximumPersistentDisksSizeGb; } @@ -221,7 +293,18 @@ public Long maximumPersistentDisksSizeGb() { * the machine type should not be used. Returns {@code null} if the machine type is not * deprecated. */ + @Deprecated public DeprecationStatus deprecationStatus() { + return getDeprecationStatus(); + } + + /** + * Returns the deprecation status of the machine type. If {@link DeprecationStatus#status()} is + * either {@link DeprecationStatus.Status#DELETED} or {@link DeprecationStatus.Status#OBSOLETE} + * the machine type should not be used. Returns {@code null} if the machine type is not + * deprecated. + */ + public DeprecationStatus getDeprecationStatus() { return deprecationStatus; } @@ -263,9 +346,9 @@ com.google.api.services.compute.model.MachineType toPb() { if (creationTimestamp != null) { machineTypePb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp)); } - machineTypePb.setName(machineTypeId.type()); + machineTypePb.setName(machineTypeId.getType()); machineTypePb.setDescription(description); - machineTypePb.setSelfLink(machineTypeId.selfLink()); + machineTypePb.setSelfLink(machineTypeId.getSelfLink()); machineTypePb.setGuestCpus(cpus); machineTypePb.setMemoryMb(memoryMb); if (scratchDisksSizeGb != null) { @@ -279,32 +362,32 @@ public ScratchDisks apply(Integer diskSize) { } machineTypePb.setMaximumPersistentDisks(maximumPersistentDisks); machineTypePb.setMaximumPersistentDisksSizeGb(maximumPersistentDisksSizeGb); - machineTypePb.setZone(machineTypeId.zoneId().zone()); + machineTypePb.setZone(machineTypeId.getZoneId().getZone()); if (deprecationStatus != null) { machineTypePb.setDeprecated(deprecationStatus.toPb()); } return machineTypePb; } - static Builder builder() { + static Builder newBuilder() { return new Builder(); } static MachineType fromPb(com.google.api.services.compute.model.MachineType machineTypePb) { - Builder builder = builder(); - builder.machineTypeId(MachineTypeId.fromUrl(machineTypePb.getSelfLink())); + Builder builder = newBuilder(); + builder.setMachineTypeId(MachineTypeId.fromUrl(machineTypePb.getSelfLink())); if (machineTypePb.getId() != null) { - builder.generatedId(machineTypePb.getId().toString()); + builder.setGeneratedId(machineTypePb.getId().toString()); } if (machineTypePb.getCreationTimestamp() != null) { - builder.creationTimestamp( + builder.setCreationTimestamp( TIMESTAMP_FORMATTER.parseMillis(machineTypePb.getCreationTimestamp())); } - builder.description(machineTypePb.getDescription()); - builder.cpus(machineTypePb.getGuestCpus()); - builder.memoryMb(machineTypePb.getMemoryMb()); + builder.setDescription(machineTypePb.getDescription()); + builder.setCpus(machineTypePb.getGuestCpus()); + builder.setMemoryMb(machineTypePb.getMemoryMb()); if (machineTypePb.getScratchDisks() != null) { - builder.scratchDisksSizeGb( + builder.setScratchDisksSizeGb( Lists.transform(machineTypePb.getScratchDisks(), new Function() { @Override public Integer apply(ScratchDisks scratchDiskPb) { @@ -312,10 +395,10 @@ public Integer apply(ScratchDisks scratchDiskPb) { } })); } - builder.maximumPersistentDisks(machineTypePb.getMaximumPersistentDisks()); - builder.maximumPersistentDisksSizeGb(machineTypePb.getMaximumPersistentDisksSizeGb()); + builder.setMaximumPersistentDisks(machineTypePb.getMaximumPersistentDisks()); + builder.setMaximumPersistentDisksSizeGb(machineTypePb.getMaximumPersistentDisksSizeGb()); if (machineTypePb.getDeprecated() != null) { - builder.deprecationStatus( + builder.setDeprecationStatus( DeprecationStatus.fromPb(machineTypePb.getDeprecated(), MachineTypeId.FROM_URL_FUNCTION)); } return builder.build(); diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/MachineTypeId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/MachineTypeId.java index bb439c1e29fe..d85bca911ac7 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/MachineTypeId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/MachineTypeId.java @@ -41,7 +41,7 @@ public MachineTypeId apply(String pb) { new Function() { @Override public String apply(MachineTypeId machineTypeId) { - return machineTypeId.selfLink(); + return machineTypeId.getSelfLink(); } }; @@ -61,27 +61,57 @@ private MachineTypeId(String project, String zone, String type) { /** * Returns the name of the machine type. */ + @Deprecated public String type() { + return getType(); + } + + /** + * Returns the name of the machine type. + */ + public String getType() { return type; } /** * Returns the name of the zone this machine type belongs to. */ + @Deprecated public String zone() { + return getZone(); + } + + /** + * Returns the name of the zone this machine type belongs to. + */ + public String getZone() { return zone; } /** * Returns the identity of the zone this machine type belongs to. */ + @Deprecated public ZoneId zoneId() { - return ZoneId.of(project(), zone); + return getZoneId(); + } + + /** + * Returns the identity of the zone this machine type belongs to. + */ + public ZoneId getZoneId() { + return ZoneId.of(getProject(), zone); } @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/zones/" + zone + "/machineTypes/" + type; + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/zones/" + zone + "/machineTypes/" + type; } @Override @@ -110,7 +140,7 @@ public boolean equals(Object obj) { @Override MachineTypeId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } return MachineTypeId.of(projectId, zone, type); diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/Metadata.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/Metadata.java index 22ba59834d4b..0c62fc7bda8a 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/Metadata.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/Metadata.java @@ -83,7 +83,19 @@ public static final class Builder { * a URL in the metadata server. Additionally, to avoid ambiguity, keys must not conflict with * any other metadata keys for the project. Values must be less than or equal to 32768 bytes. */ + @Deprecated public Builder values(Map values) { + return setValues(values); + } + + /** + * Sets the metadata for the instance as key/value pairs. The total size of all keys and + * values must be less than 512 KB. Keys must conform to the following regexp: + * {@code [a-zA-Z0-9-_]+}, and be less than 128 bytes in length. This is reflected as part of + * a URL in the metadata server. Additionally, to avoid ambiguity, keys must not conflict with + * any other metadata keys for the project. Values must be less than or equal to 32768 bytes. + */ + public Builder setValues(Map values) { this.values = Maps.newHashMap(checkNotNull(values)); return this; } @@ -104,7 +116,16 @@ public Builder add(String key, String value) { * Sets the fingerprint for the metadata. This value can be used to update instance's * metadata. */ + @Deprecated public Builder fingerprint(String fingerprint) { + return setFingerprint(fingerprint); + } + + /** + * Sets the fingerprint for the metadata. This value can be used to update instance's + * metadata. + */ + public Builder setFingerprint(String fingerprint) { this.fingerprint = fingerprint; return this; } @@ -125,18 +146,35 @@ private Metadata(Builder builder) { /** * Returns instance's metadata as key/value pairs. */ + @Deprecated public Map values() { return values; } + /** + * Returns instance's metadata as key/value pairs. + */ + public Map getValues() { + return values; + } + /** * Returns the fingerprint for the metadata. This value can be used to update instance's * metadata. */ + @Deprecated public String fingerprint() { return fingerprint; } + /** + * Returns the fingerprint for the metadata. This value can be used to update instance's + * metadata. + */ + public String getFingerprint() { + return fingerprint; + } + /** * Returns a builder for the current instance metadata. */ @@ -182,7 +220,15 @@ com.google.api.services.compute.model.Metadata toPb() { /** * Returns a builder for a {@code Metadata} object. */ + @Deprecated public static Builder builder() { + return newBuilder(); + } + + /** + * Returns a builder for a {@code Metadata} object. + */ + public static Builder newBuilder() { return new Builder(); } @@ -194,19 +240,19 @@ public static Builder builder() { * other metadata keys for the project. Values must be less than or equal to 32768 bytes. */ public static Metadata of(Map values) { - return builder().values(values).build(); + return newBuilder().setValues(values).build(); } static Metadata fromPb(com.google.api.services.compute.model.Metadata metadataPb) { - Builder builder = builder(); + Builder builder = newBuilder(); if (metadataPb.getItems() != null) { Map metadataValues = Maps.newHashMapWithExpectedSize(metadataPb.getItems().size()); for (com.google.api.services.compute.model.Metadata.Items item : metadataPb.getItems()) { metadataValues.put(item.getKey(), item.getValue()); } - builder.values(metadataValues); + builder.setValues(metadataValues); } - return builder.fingerprint(metadataPb.getFingerprint()).build(); + return builder.setFingerprint(metadataPb.getFingerprint()).build(); } } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/Network.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/Network.java index 51a0287f3fed..3f57619db859 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/Network.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/Network.java @@ -53,8 +53,8 @@ public static class Builder extends NetworkInfo.Builder { Builder(Compute compute, NetworkId networkId, NetworkConfiguration configuration) { this.compute = compute; this.infoBuilder = new NetworkInfo.BuilderImpl(networkId, configuration); - this.infoBuilder.networkId(networkId); - this.infoBuilder.configuration(configuration); + this.infoBuilder.setNetworkId(networkId); + this.infoBuilder.setConfiguration(configuration); } Builder(Network subnetwork) { @@ -63,32 +63,50 @@ public static class Builder extends NetworkInfo.Builder { } @Override - Builder generatedId(String generatedId) { - infoBuilder.generatedId(generatedId); + Builder setGeneratedId(String generatedId) { + infoBuilder.setGeneratedId(generatedId); return this; } @Override - Builder creationTimestamp(Long creationTimestamp) { - infoBuilder.creationTimestamp(creationTimestamp); + Builder setCreationTimestamp(Long creationTimestamp) { + infoBuilder.setCreationTimestamp(creationTimestamp); return this; } @Override + @Deprecated public Builder networkId(NetworkId networkId) { - infoBuilder.networkId(networkId); + return setNetworkId(networkId); + } + + @Override + public Builder setNetworkId(NetworkId networkId) { + infoBuilder.setNetworkId(networkId); return this; } @Override + @Deprecated public Builder description(String description) { - infoBuilder.description(description); + return setDescription(description); + } + + @Override + public Builder setDescription(String description) { + infoBuilder.setDescription(description); return this; } @Override + @Deprecated public Builder configuration(NetworkConfiguration configuration) { - infoBuilder.configuration(configuration); + return setConfiguration(configuration); + } + + @Override + public Builder setConfiguration(NetworkConfiguration configuration) { + infoBuilder.setConfiguration(configuration); return this; } @@ -123,7 +141,7 @@ public boolean exists() { * @throws ComputeException upon failure */ public Network reload(NetworkOption... options) { - return compute.getNetwork(networkId().network(), options); + return compute.getNetwork(getNetworkId().getNetwork(), options); } /** @@ -134,7 +152,7 @@ public Network reload(NetworkOption... options) { * @throws ComputeException upon failure */ public Operation delete(OperationOption... options) { - return compute.deleteNetwork(networkId().network(), options); + return compute.deleteNetwork(getNetworkId().getNetwork(), options); } /** @@ -150,13 +168,21 @@ public Operation delete(OperationOption... options) { */ public Operation createSubnetwork(SubnetworkId subnetworkId, String ipRange, OperationOption... options) { - return compute.create(SubnetworkInfo.of(subnetworkId, networkId(), ipRange), options); + return compute.create(SubnetworkInfo.of(subnetworkId, getNetworkId(), ipRange), options); } /** * Returns the network's {@code Compute} object used to issue requests. */ + @Deprecated public Compute compute() { + return getCompute(); + } + + /** + * Returns the network's {@code Compute} object used to issue requests. + */ + public Compute getCompute() { return compute; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/NetworkConfiguration.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/NetworkConfiguration.java index 4a7500f66d07..6728784fadf8 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/NetworkConfiguration.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/NetworkConfiguration.java @@ -62,7 +62,17 @@ public enum Type { * with no subnetworks. This method returns {@link Type#SUBNET} for a network that supports the * creation of subnetworks (either automatic or manual). */ + @Deprecated public Type type() { + return getType(); + } + + /** + * 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 getType() { return type; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/NetworkId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/NetworkId.java index 1108f126588b..298d78ad3d96 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/NetworkId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/NetworkId.java @@ -41,8 +41,8 @@ public final class NetworkId extends ResourceId { } private NetworkId(NetworkId networkId) { - super(networkId.project()); - this.network = checkNotNull(networkId.network()); + super(networkId.getProject()); + this.network = checkNotNull(networkId.getNetwork()); } /** @@ -54,13 +54,33 @@ private NetworkId(NetworkId networkId) { * * @see RFC1035 */ + @Deprecated public String network() { return network; } + /** + * Returns the name of the network. The network name must be 1-63 characters long and comply with + * RFC1035. Specifically, the name must match the regular expression + * {@code [a-z]([-a-z0-9]*[a-z0-9])?} which means the first character must be a lowercase letter, + * and all following characters must be a dash, lowercase letter, or digit, except the last + * character, which cannot be a dash. + * + * @see RFC1035 + */ + public String getNetwork() { + return network; + } + @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/global/networks/" + network; + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/global/networks/" + network; } @Override @@ -87,7 +107,7 @@ public boolean equals(Object obj) { @Override NetworkId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } return NetworkId.of(projectId, network); diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/NetworkInfo.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/NetworkInfo.java index a7864135b810..74cde200c509 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/NetworkInfo.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/NetworkInfo.java @@ -71,28 +71,49 @@ public Network apply(NetworkInfo network) { */ public abstract static class Builder { - abstract Builder generatedId(String generatedId); + abstract Builder setGeneratedId(String generatedId); - abstract Builder creationTimestamp(Long creationTimestamp); + abstract Builder setCreationTimestamp(Long creationTimestamp); /** * Sets the identity of the network. */ + @Deprecated public abstract Builder networkId(NetworkId networkId); + /** + * Sets the identity of the network. + */ + public abstract Builder setNetworkId(NetworkId networkId); + /** * Sets an optional textual description of the network. */ + @Deprecated public abstract Builder description(String description); + /** + * Sets an optional textual description of the network. + */ + public abstract Builder setDescription(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. */ + @Deprecated public abstract Builder configuration(NetworkConfiguration configuration); + /** + * 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 setConfiguration(NetworkConfiguration configuration); + /** * Creates a {@code NetworkInfo} object. */ @@ -133,31 +154,49 @@ static final class BuilderImpl extends Builder { } @Override - BuilderImpl generatedId(String generatedId) { + BuilderImpl setGeneratedId(String generatedId) { this.generatedId = generatedId; return this; } @Override - BuilderImpl creationTimestamp(Long creationTimestamp) { + BuilderImpl setCreationTimestamp(Long creationTimestamp) { this.creationTimestamp = creationTimestamp; return this; } @Override + @Deprecated public BuilderImpl networkId(NetworkId networkId) { + return setNetworkId(networkId); + } + + @Override + public BuilderImpl setNetworkId(NetworkId networkId) { this.networkId = checkNotNull(networkId); return this; } @Override + @Deprecated public BuilderImpl description(String description) { + return setDescription(description); + } + + @Override + public BuilderImpl setDescription(String description) { this.description = description; return this; } @Override + @Deprecated public BuilderImpl configuration(NetworkConfiguration configuration) { + return setConfiguration(configuration); + } + + @Override + public BuilderImpl setConfiguration(NetworkConfiguration configuration) { this.configuration = checkNotNull(configuration); return this; } @@ -179,28 +218,60 @@ public NetworkInfo build() { /** * Returns the service-generated unique identifier for the network. */ + @Deprecated public String generatedId() { + return getGeneratedId(); + } + + /** + * Returns the service-generated unique identifier for the network. + */ + public String getGeneratedId() { return generatedId; } /** * Returns the creation timestamp in milliseconds since epoch. */ + @Deprecated public Long creationTimestamp() { + return getCreationTimestamp(); + } + + /** + * Returns the creation timestamp in milliseconds since epoch. + */ + public Long getCreationTimestamp() { return creationTimestamp; } /** * Returns the network identity. */ + @Deprecated public NetworkId networkId() { + return getNetworkId(); + } + + /** + * Returns the network identity. + */ + public NetworkId getNetworkId() { return networkId; } /** * Returns a textual description of the network. */ + @Deprecated public String description() { + return getDescription(); + } + + /** + * Returns a textual description of the network. + */ + public String getDescription() { return description; } @@ -210,7 +281,18 @@ public String description() { * that could be divided into subnetworks, up to one per region, each with its own address range. */ @SuppressWarnings("unchecked") + @Deprecated public T configuration() { + return getConfiguration(); + } + + /** + * 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 getConfiguration() { return (T) configuration; } @@ -247,7 +329,7 @@ public boolean equals(Object obj) { NetworkInfo setProjectId(String projectId) { return toBuilder() - .networkId(networkId.setProjectId(projectId)) + .setNetworkId(networkId.setProjectId(projectId)) .build(); } @@ -259,9 +341,9 @@ Network toPb() { if (creationTimestamp != null) { networkPb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp)); } - networkPb.setName(networkId.network()); + networkPb.setName(networkId.getNetwork()); networkPb.setDescription(description); - networkPb.setSelfLink(networkId.selfLink()); + networkPb.setSelfLink(networkId.getSelfLink()); return networkPb; } @@ -271,7 +353,18 @@ Network toPb() { * associated address range. Use {@link SubnetNetworkConfiguration} to create a network that * supports subnetworks, up to one per region, each with its own address range. */ + @Deprecated public static Builder builder(NetworkId networkId, NetworkConfiguration configuration) { + return newBuilder(networkId, configuration); + } + + /** + * 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 newBuilder(NetworkId networkId, NetworkConfiguration configuration) { return new BuilderImpl(networkId, configuration); } @@ -282,7 +375,7 @@ public static Builder builder(NetworkId networkId, NetworkConfiguration configur * to one per region, each with its own address range. */ public static NetworkInfo of(NetworkId networkId, NetworkConfiguration configuration) { - return builder(networkId, configuration).build(); + return newBuilder(networkId, configuration).build(); } static NetworkInfo fromPb(Network networkPb) { diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/NetworkInterface.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/NetworkInterface.java index 06964f6641af..13d8652ace36 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/NetworkInterface.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/NetworkInterface.java @@ -127,7 +127,15 @@ private Builder(AccessConfig accessConfig) { /** * Sets the name of the access configuration. */ + @Deprecated public Builder name(String name) { + return setName(name); + } + + /** + * Sets the name of the access configuration. + */ + public Builder setName(String name) { this.name = name; return this; } @@ -144,7 +152,24 @@ public Builder name(String name) { * href="https://cloud.google.com/compute/docs/instances-and-network#ephemeraladdress"> * Ephemeral external IP addresses */ + @Deprecated public Builder natIp(String natIp) { + return setNatIp(natIp); + } + + /** + * Sets an external IP address associated with this instance. Specify an unused static + * external IP address available to the project or leave this field undefined to use an IP + * from a shared ephemeral IP address pool. If you specify a static external IP address, it + * must live in the same region as the zone of the instance. + * + * @see + * Ephemeral external IP addresses + * @see + * Ephemeral external IP addresses + */ + public Builder setNatIp(String natIp) { this.natIp = natIp; return this; } @@ -153,7 +178,16 @@ public Builder natIp(String natIp) { * Sets the type of the access configuration. The only supported value is * {@link Type#ONE_TO_ONE_NAT}. */ + @Deprecated public Builder type(Type type) { + return setType(type); + } + + /** + * Sets the type of the access configuration. The only supported value is + * {@link Type#ONE_TO_ONE_NAT}. + */ + public Builder setType(Type type) { this.type = type; return this; } @@ -175,14 +209,30 @@ public AccessConfig build() { /** * Returns the name of the access configuration. */ + @Deprecated public String name() { + return getName(); + } + + /** + * Returns the name of the access configuration. + */ + public String getName() { return name; } /** * Returns an external IP address associated with this instance. */ + @Deprecated public String natIp() { + return getNatIp(); + } + + /** + * Returns an external IP address associated with this instance. + */ + public String getNatIp() { return natIp; } @@ -190,7 +240,16 @@ public String natIp() { * Returns the type of network access configuration. The only supported value is * {@link Type#ONE_TO_ONE_NAT}. */ + @Deprecated public Type type() { + return getType(); + } + + /** + * Returns the type of network access configuration. The only supported value is + * {@link Type#ONE_TO_ONE_NAT}. + */ + public Type getType() { return type; } @@ -236,7 +295,15 @@ com.google.api.services.compute.model.AccessConfig toPb() { /** * Returns a builder for an {@code AccessConfig} object. */ + @Deprecated public static Builder builder() { + return newBuilder(); + } + + /** + * Returns a builder for an {@code AccessConfig} object. + */ + public static Builder newBuilder() { return new Builder(); } @@ -247,7 +314,7 @@ public static Builder builder() { * Static external IP addresses */ public static AccessConfig of(String natIp) { - return builder().natIp(natIp).build(); + return newBuilder().setNatIp(natIp).build(); } /** @@ -258,17 +325,17 @@ public static AccessConfig of(String natIp) { * Ephemeral external IP addresses */ public static AccessConfig of() { - return builder().build(); + return newBuilder().build(); } static AccessConfig fromPb(com.google.api.services.compute.model.AccessConfig configPb) { - Builder builder = builder(); - builder.name(configPb.getName()); + Builder builder = newBuilder(); + builder.setName(configPb.getName()); if (configPb.getNatIP() != null) { - builder.natIp(configPb.getNatIP()); + builder.setNatIp(configPb.getNatIP()); } if (configPb.getType() != null) { - builder.type(Type.valueOf(configPb.getType())); + builder.setType(Type.valueOf(configPb.getType())); } return builder.build(); } @@ -294,7 +361,7 @@ private Builder(NetworkInterface networkInterface) { this.accessConfigurations = networkInterface.accessConfigurations; } - Builder name(String name) { + Builder setName(String name) { this.name = name; return this; } @@ -302,12 +369,20 @@ Builder name(String name) { /** * Sets the identity of the network this interface applies to. */ + @Deprecated public Builder network(NetworkId network) { + return setNetwork(network); + } + + /** + * Sets the identity of the network this interface applies to. + */ + public Builder setNetwork(NetworkId network) { this.network = checkNotNull(network); return this; } - Builder networkIp(String networkIp) { + Builder setNetworkIp(String networkIp) { this.networkIp = networkIp; return this; } @@ -316,7 +391,16 @@ Builder networkIp(String networkIp) { * Sets the identity of the subnetwork this interface applies to. Setting the subnetwork is * not necessary when the network is in "automatic subnet mode". */ + @Deprecated public Builder subnetwork(SubnetworkId subnetwork) { + return setSubnetwork(subnetwork); + } + + /** + * Sets the identity of the subnetwork this interface applies to. Setting the subnetwork is + * not necessary when the network is in "automatic subnet mode". + */ + public Builder setSubnetwork(SubnetworkId subnetwork) { this.subnetwork = subnetwork; return this; } @@ -331,7 +415,22 @@ public Builder subnetwork(SubnetworkId subnetwork) { * @see * Ephemeral external IP addresses */ + @Deprecated public Builder accessConfigurations(List accessConfigurations) { + return setAccessConfigurations(accessConfigurations); + } + + /** + * Sets a list of access configurations for the network interface. Access configurations can be + * used to assign either a static or an ephemeral external IP address to Google Compute Engine + * instances. At the moment, network interfaces only support one access configuration. + * + * @see + * Static external IP addresses + * @see + * Ephemeral external IP addresses + */ + public Builder setAccessConfigurations(List accessConfigurations) { this.accessConfigurations = ImmutableList.copyOf(accessConfigurations); return this; } @@ -346,8 +445,23 @@ public Builder accessConfigurations(List accessConfigurations) { * @see * Ephemeral external IP addresses */ + @Deprecated public Builder accessConfigurations(AccessConfig... accessConfigurations) { - accessConfigurations(Arrays.asList(accessConfigurations)); + return setAccessConfigurations(accessConfigurations); + } + + /** + * Sets a list of access configurations for the network interface. Access configurations can be + * used to assign either a static or an ephemeral external IP address to Google Compute Engine + * instances. At the moment, network interfaces only support one access configuration. + * + * @see + * Static external IP addresses + * @see + * Ephemeral external IP addresses + */ + public Builder setAccessConfigurations(AccessConfig... accessConfigurations) { + setAccessConfigurations(Arrays.asList(accessConfigurations)); return this; } @@ -372,14 +486,31 @@ private NetworkInterface(Builder builder) { * Returns the name of the network interface, generated by the service. For network devices, * these are {@code eth0}, {@code eth1}, etc. */ + @Deprecated public String name() { + return getName(); + } + + /** + * Returns the name of the network interface, generated by the service. For network devices, + * these are {@code eth0}, {@code eth1}, etc. + */ + public String getName() { return name; } /** * Returns the identity of the network this interface applies to. */ + @Deprecated public NetworkId network() { + return getNetwork(); + } + + /** + * Returns the identity of the network this interface applies to. + */ + public NetworkId getNetwork() { return network; } @@ -387,21 +518,46 @@ public NetworkId network() { * An optional IPv4 internal network address assigned by the service to the instance for this * network interface. */ + @Deprecated public String networkIp() { + return getNetworkIp(); + } + + /** + * An optional IPv4 internal network address assigned by the service to the instance for this + * network interface. + */ + public String getNetworkIp() { return networkIp; } /** * Returns the identity of the subnetwork this interface applies to. */ + @Deprecated public SubnetworkId subnetwork() { + return getSubnetwork(); + } + + /** + * Returns the identity of the subnetwork this interface applies to. + */ + public SubnetworkId getSubnetwork() { return subnetwork; } /** * Returns a list of access configurations for the network interface. */ + @Deprecated public List accessConfigurations() { + return getAccessConfigurations(); + } + + /** + * Returns a list of access configurations for the network interface. + */ + public List getAccessConfigurations() { return accessConfigurations; } @@ -440,9 +596,9 @@ com.google.api.services.compute.model.NetworkInterface toPb() { com.google.api.services.compute.model.NetworkInterface interfacePb = new com.google.api.services.compute.model.NetworkInterface(); interfacePb.setName(name); - interfacePb.setNetwork(network.selfLink()); + interfacePb.setNetwork(network.getSelfLink()); if (subnetwork != null) { - interfacePb.setSubnetwork(subnetwork.selfLink()); + interfacePb.setSubnetwork(subnetwork.getSelfLink()); } interfacePb.setNetworkIP(networkIp); if (accessConfigurations != null) { @@ -454,9 +610,9 @@ com.google.api.services.compute.model.NetworkInterface toPb() { NetworkInterface setProjectId(String projectId) { Builder builder = toBuilder(); - builder.network(network.setProjectId(projectId)); + builder.setNetwork(network.setProjectId(projectId)); if (subnetwork != null) { - builder.subnetwork(subnetwork.setProjectId(projectId)); + builder.setSubnetwork(subnetwork.setProjectId(projectId)); } return builder.build(); } @@ -464,40 +620,56 @@ NetworkInterface setProjectId(String projectId) { /** * Returns a builder for a {@code NetworkInterface} object given the network's identity. */ + @Deprecated public static Builder builder(NetworkId networkId) { + return newBuilder(networkId); + } + + /** + * Returns a builder for a {@code NetworkInterface} object given the network's identity. + */ + public static Builder newBuilder(NetworkId networkId) { return new Builder(networkId); } /** * Returns a builder for a {@code NetworkInterface} object given the network's name. */ + @Deprecated public static Builder builder(String network) { - return builder(NetworkId.of(network)); + return newBuilder(network); + } + + /** + * Returns a builder for a {@code NetworkInterface} object given the network's name. + */ + public static Builder newBuilder(String network) { + return newBuilder(NetworkId.of(network)); } /** * Returns a {@code NetworkInterface} object given the network's identity. */ public static NetworkInterface of(NetworkId networkId) { - return builder(networkId).build(); + return newBuilder(networkId).build(); } /** * Returns a {@code NetworkInterface} object given the network's name. */ public static NetworkInterface of(String network) { - return builder(network).build(); + return newBuilder(network).build(); } static NetworkInterface fromPb( com.google.api.services.compute.model.NetworkInterface interfacePb) { - Builder builder = builder(NetworkId.fromUrl(interfacePb.getNetwork())) - .name(interfacePb.getName()); + Builder builder = newBuilder(NetworkId.fromUrl(interfacePb.getNetwork())) + .setName(interfacePb.getName()); if (interfacePb.getSubnetwork() != null) { - builder.subnetwork(SubnetworkId.fromUrl(interfacePb.getSubnetwork())); + builder.setSubnetwork(SubnetworkId.fromUrl(interfacePb.getSubnetwork())); } - builder.networkIp(interfacePb.getNetworkIP()); - builder.accessConfigurations(interfacePb.getAccessConfigs() != null + builder.setNetworkIp(interfacePb.getNetworkIP()); + builder.setAccessConfigurations(interfacePb.getAccessConfigs() != null ? Lists.transform(interfacePb.getAccessConfigs(), AccessConfig.FROM_PB_FUNCTION) : ImmutableList.of()); return builder.build(); diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/Operation.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/Operation.java index 78752e9cdaeb..c1034bc2de77 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/Operation.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/Operation.java @@ -124,21 +124,45 @@ public com.google.api.services.compute.model.Operation.Error.Errors apply( /** * Returns an error type identifier for this error. */ + @Deprecated public String code() { + return getCode(); + } + + /** + * Returns an error type identifier for this error. + */ + public String getCode() { return code; } /** * Returns the field in the request which caused the error. This value is optional. */ + @Deprecated public String location() { + return getLocation(); + } + + /** + * Returns the field in the request which caused the error. This value is optional. + */ + public String getLocation() { return location; } /** * Returns an optional, human-readable error message. */ + @Deprecated public String message() { + return getMessage(); + } + + /** + * Returns an optional, human-readable error message. + */ + public String getMessage() { return message; } @@ -221,14 +245,31 @@ public com.google.api.services.compute.model.Operation.Warnings apply( * Returns a warning identifier for this warning. For example, {@code NO_RESULTS_ON_PAGE} if * there are no results in the response. */ + @Deprecated public String code() { + return getCode(); + } + + /** + * Returns a warning identifier for this warning. For example, {@code NO_RESULTS_ON_PAGE} if + * there are no results in the response. + */ + public String getCode() { return code; } /** * Returns a human-readable error message. */ + @Deprecated public String message() { + return getMessage(); + } + + /** + * Returns a human-readable error message. + */ + public String getMessage() { return message; } @@ -240,7 +281,20 @@ public String message() { * or a warning about invalid network settings (for example, if an instance attempts to perform * IP forwarding but is not enabled for IP forwarding). */ + @Deprecated public Map metadata() { + return getMetadata(); + } + + /** + * Returns metadata about this warning. Each key provides more detail on the warning being + * returned. For example, for warnings where there are no results in a list request for a + * particular zone, this key might be {@code scope} and the key's value might be the zone name. + * Other examples might be a key indicating a deprecated resource, and a suggested replacement, + * or a warning about invalid network settings (for example, if an instance attempts to perform + * IP forwarding but is not enabled for IP forwarding). + */ + public Map getMetadata() { return metadata; } @@ -368,92 +422,92 @@ static final class Builder { description = operationPb.getDescription(); } - Builder generatedId(String generatedId) { + Builder getGeneratedId(String generatedId) { this.generatedId = generatedId; return this; } - Builder operationId(OperationId operationId) { + Builder setOperationId(OperationId operationId) { this.operationId = checkNotNull(operationId); return this; } - Builder clientOperationId(String clientOperationId) { + Builder setClientOperationId(String clientOperationId) { this.clientOperationId = clientOperationId; return this; } - Builder operationType(String operationType) { + Builder setOperationType(String operationType) { this.operationType = operationType; return this; } - Builder targetLink(String targetLink) { + Builder setTargetLink(String targetLink) { this.targetLink = targetLink; return this; } - Builder targetId(String targetId) { + Builder setTargetId(String targetId) { this.targetId = targetId; return this; } - Builder status(Status status) { + Builder setStatus(Status status) { this.status = status; return this; } - Builder statusMessage(String statusMessage) { + Builder setStatusMessage(String statusMessage) { this.statusMessage = statusMessage; return this; } - Builder user(String user) { + Builder setUser(String user) { this.user = user; return this; } - Builder progress(Integer progress) { + Builder setProgress(Integer progress) { this.progress = progress; return this; } - Builder insertTime(Long insertTime) { + Builder setInsertTime(Long insertTime) { this.insertTime = insertTime; return this; } - Builder startTime(Long startTime) { + Builder setStartTime(Long startTime) { this.startTime = startTime; return this; } - Builder endTime(Long endTime) { + Builder setEndTime(Long endTime) { this.endTime = endTime; return this; } - Builder errors(List errors) { + Builder setErrors(List errors) { this.errors = ImmutableList.copyOf(checkNotNull(errors)); return this; } - Builder warnings(List warnings) { + Builder setWarnings(List warnings) { this.warnings = ImmutableList.copyOf(checkNotNull(warnings)); return this; } - Builder httpErrorStatusCode(Integer httpErrorStatusCode) { + Builder setHttpErrorStatusCode(Integer httpErrorStatusCode) { this.httpErrorStatusCode = httpErrorStatusCode; return this; } - Builder httpErrorMessage(String httpErrorMessage) { + Builder setHttpErrorMessage(String httpErrorMessage) { this.httpErrorMessage = httpErrorMessage; return this; } - Builder description(String description) { + Builder setDescription(String description) { this.description = description; return this; } @@ -489,14 +543,30 @@ private Operation(Builder builder) { /** * Returns the operation's {@code Compute} object used to issue requests. */ + @Deprecated public Compute compute() { + return getCompute(); + } + + /** + * Returns the operation's {@code Compute} object used to issue requests. + */ + public Compute getCompute() { return compute; } /** * Returns the service-generated unique identifier for the operation. */ + @Deprecated public String generatedId() { + return getGeneratedId(); + } + + /** + * Returns the service-generated unique identifier for the operation. + */ + public String getGeneratedId() { return generatedId; } @@ -508,28 +578,57 @@ public String generatedId() { * @see RFC1035 */ @SuppressWarnings("unchecked") + @Deprecated public T operationId() { + return getOperationId(); + } + + /** + * Returns the operation's identity. This method returns an {@link GlobalOperationId} for global + * operations, a {@link RegionOperationId} for region operations and a {@link ZoneOperationId} for + * zone operations. + * + * @see RFC1035 + */ + @SuppressWarnings("unchecked") + public T getOperationId() { return (T) operationId; } /** * Reserved for future use. */ - String clientOperationId() { + String getClientOperationId() { return clientOperationId; } /** * Returns the type of operation. */ + @Deprecated public String operationType() { + return getOperationType(); + } + + /** + * Returns the type of operation. + */ + public String getOperationType() { return operationType; } /** * Returns the URL of the resource that the operation is modifying. */ + @Deprecated public String targetLink() { + return getTargetLink(); + } + + /** + * Returns the URL of the resource that the operation is modifying. + */ + public String getTargetLink() { return targetLink; } @@ -537,28 +636,61 @@ public String targetLink() { * Returns the unique service-defined target ID, which identifies the resource that the operation * is modifying. */ + @Deprecated public String targetId() { + return getTargetId(); + } + + /** + * Returns the unique service-defined target ID, which identifies the resource that the operation + * is modifying. + */ + public String getTargetId() { return targetId; } /** * Returns the status of the operation. */ + @Deprecated public Status status() { + return getStatus(); + } + + /** + * Returns the status of the operation. + */ + public Status getStatus() { return status; } /** * Returns an optional textual description of the current status of the operation. */ + @Deprecated public String statusMessage() { + return getStatusMessage(); + } + + /** + * Returns an optional textual description of the current status of the operation. + */ + public String getStatusMessage() { return statusMessage; } /** * Returns the user who requested the operation, for example: {@code user@example.com}. */ + @Deprecated public String user() { + return getUser(); + } + + /** + * Returns the user who requested the operation, for example: {@code user@example.com}. + */ + public String getUser() { return user; } @@ -568,14 +700,33 @@ public String user() { * the operation will be complete. This number should monotonically increase as the operation * progresses. */ + @Deprecated public Integer progress() { + return getProgress(); + } + + /** + * Returns an optional progress indicator that ranges from 0 to 100. There is no requirement that + * this be linear or support any granularity of operations. This should not be used to guess when + * the operation will be complete. This number should monotonically increase as the operation + * progresses. + */ + public Integer getProgress() { return progress; } /** * Returns the time that this operation was requested. In milliseconds since epoch. */ + @Deprecated public Long insertTime() { + return getInsertTime(); + } + + /** + * Returns the time that this operation was requested. In milliseconds since epoch. + */ + public Long getInsertTime() { return insertTime; } @@ -583,7 +734,16 @@ public Long insertTime() { * Returns the time that this operation was started by the service. In milliseconds since epoch. * This value will be {@code null} if the operation has not started yet. */ + @Deprecated public Long startTime() { + return getStartTime(); + } + + /** + * Returns the time that this operation was started by the service. In milliseconds since epoch. + * This value will be {@code null} if the operation has not started yet. + */ + public Long getStartTime() { return startTime; } @@ -591,7 +751,16 @@ public Long startTime() { * Returns the time that this operation was completed. In milliseconds since epoch. This value * will be {@code null} if the operation has not finished yet. */ + @Deprecated public Long endTime() { + return getEndTime(); + } + + /** + * Returns the time that this operation was completed. In milliseconds since epoch. This value + * will be {@code null} if the operation has not finished yet. + */ + public Long getEndTime() { return endTime; } @@ -599,7 +768,16 @@ public Long endTime() { * Returns the errors encountered while processing this operation, if any. Returns {@code null} if * no error occurred. */ + @Deprecated public List errors() { + return getErrors(); + } + + /** + * Returns the errors encountered while processing this operation, if any. Returns {@code null} if + * no error occurred. + */ + public List getErrors() { return errors; } @@ -607,7 +785,16 @@ public List errors() { * Returns the warnings encountered while processing this operation, if any. Returns {@code null} * if no warning occurred. */ + @Deprecated public List warnings() { + return getWarnings(); + } + + /** + * Returns the warnings encountered while processing this operation, if any. Returns {@code null} + * if no warning occurred. + */ + public List getWarnings() { return warnings; } @@ -615,7 +802,16 @@ public List warnings() { * Returns the HTTP error status code that was returned, if the operation failed. For example, a * {@code 404} means the resource was not found. */ + @Deprecated public Integer httpErrorStatusCode() { + return getHttpErrorStatusCode(); + } + + /** + * Returns the HTTP error status code that was returned, if the operation failed. For example, a + * {@code 404} means the resource was not found. + */ + public Integer getHttpErrorStatusCode() { return httpErrorStatusCode; } @@ -623,14 +819,31 @@ public Integer httpErrorStatusCode() { * Returns the the HTTP error message that was returned, if the operation failed. For example, a * {@code NOT FOUND} message is returned if the resource was not found. */ + @Deprecated public String httpErrorMessage() { + return getHttpErrorMessage(); + } + + /** + * Returns the the HTTP error message that was returned, if the operation failed. For example, a + * {@code NOT FOUND} message is returned if the resource was not found. + */ + public String getHttpErrorMessage() { return httpErrorMessage; } /** * Returns an optional textual description of the operation. */ + @Deprecated public String description() { + return getDescription(); + } + + /** + * Returns an optional textual description of the operation. + */ + public String getDescription() { return description; } @@ -660,7 +873,7 @@ public boolean exists() { public boolean isDone() { Operation operation = compute.getOperation(operationId, OperationOption.fields(Compute.OperationField.STATUS)); - return operation == null || operation.status() == Status.DONE; + return operation == null || operation.getStatus() == Status.DONE; } /** @@ -788,14 +1001,14 @@ com.google.api.services.compute.model.Operation toPb() { if (generatedId != null) { operationPb.setId(new BigInteger(generatedId)); } - operationPb.setName(operationId.operation()); + operationPb.setName(operationId.getOperation()); operationPb.setClientOperationId(clientOperationId); - switch (operationId.type()) { + switch (operationId.getType()) { case REGION: - operationPb.setRegion(this.operationId().regionId().selfLink()); + operationPb.setRegion(this.getOperationId().getRegionId().getSelfLink()); break; case ZONE: - operationPb.setZone(this.operationId().zoneId().selfLink()); + operationPb.setZone(this.getOperationId().getZoneId().getSelfLink()); break; } if (operationType != null) { @@ -829,7 +1042,7 @@ com.google.api.services.compute.model.Operation toPb() { } operationPb.setHttpErrorStatusCode(httpErrorStatusCode); operationPb.setHttpErrorMessage(httpErrorMessage); - operationPb.setSelfLink(operationId.selfLink()); + operationPb.setSelfLink(operationId.getSelfLink()); operationPb.setDescription(description); return operationPb; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/OperationId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/OperationId.java index 2a3dc2a28d76..d6f7ddd5dfaf 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/OperationId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/OperationId.java @@ -62,12 +62,26 @@ enum Type { /** * Returns the type of this operation identity. */ + @Deprecated public abstract Type type(); + /** + * Returns the type of this operation identity. + */ + public abstract Type getType(); + /** * Returns the name of the operation resource. */ + @Deprecated public String operation() { + return getOperation(); + } + + /** + * Returns the name of the operation resource. + */ + public String getOperation() { return operation; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/Option.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/Option.java index de8676b2ac79..1e96726ca83d 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/Option.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/Option.java @@ -39,11 +39,11 @@ class Option implements Serializable { this.value = value; } - ComputeRpc.Option rpcOption() { + ComputeRpc.Option getRpcOption() { return rpcOption; } - Object value() { + Object getValue() { return value; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/Region.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/Region.java index 85845283010c..70c1c5b880c2 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/Region.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/Region.java @@ -108,21 +108,45 @@ public com.google.api.services.compute.model.Quota apply(Quota quota) { /** * Returns the name of the quota metric. */ + @Deprecated public String metric() { + return getMetric(); + } + + /** + * Returns the name of the quota metric. + */ + public String getMetric() { return metric; } /** * Returns the quota limit for this metric. */ + @Deprecated public double limit() { + return getLimit(); + } + + /** + * Returns the quota limit for this metric. + */ + public double getLimit() { return limit; } /** * Returns the current usage for this quota. */ + @Deprecated public double usage() { + return getUsage(); + } + + /** + * Returns the current usage for this quota. + */ + public double getUsage() { return usage; } @@ -177,42 +201,42 @@ static final class Builder { private Builder() {} - Builder regionId(RegionId regionId) { + Builder setRegionId(RegionId regionId) { this.regionId = regionId; return this; } - Builder generatedId(String generatedId) { + Builder setGeneratedId(String generatedId) { this.generatedId = generatedId; return this; } - Builder creationTimestamp(Long creationTimestamp) { + Builder setCreationTimestamp(Long creationTimestamp) { this.creationTimestamp = creationTimestamp; return this; } - Builder description(String description) { + Builder setDescription(String description) { this.description = description; return this; } - Builder status(Status status) { + Builder setStatus(Status status) { this.status = status; return this; } - Builder zones(List zones) { + Builder setZones(List zones) { this.zones = ImmutableList.copyOf(zones); return this; } - Builder quotas(List quotas) { + Builder setQuotas(List quotas) { this.quotas = ImmutableList.copyOf(quotas); return this; } - Builder deprecationStatus(DeprecationStatus deprecationStatus) { + Builder setDeprecationStatus(DeprecationStatus deprecationStatus) { this.deprecationStatus = deprecationStatus; return this; } @@ -236,49 +260,105 @@ private Region(Builder builder) { /** * Returns the region's identity. */ + @Deprecated public RegionId regionId() { + return getRegionId(); + } + + /** + * Returns the region's identity. + */ + public RegionId getRegionId() { return regionId; } /** * Returns the service-generated unique identifier for the region. */ + @Deprecated public String generatedId() { + return getGeneratedId(); + } + + /** + * Returns the service-generated unique identifier for the region. + */ + public String getGeneratedId() { return generatedId; } /** * Returns the creation timestamp in milliseconds since epoch. */ + @Deprecated public Long creationTimestamp() { + return getCreationTimestamp(); + } + + /** + * Returns the creation timestamp in milliseconds since epoch. + */ + public Long getCreationTimestamp() { return creationTimestamp; } /** * Returns an optional textual description of the region. */ + @Deprecated public String description() { + return getDescription(); + } + + /** + * Returns an optional textual description of the region. + */ + public String getDescription() { return description; } /** * Returns the status of the status. */ + @Deprecated public Status status() { + return getStatus(); + } + + /** + * Returns the status of the status. + */ + public Status getStatus() { return status; } /** * Returns a list of identities of zones available in this region. */ + @Deprecated public List zones() { + return getZones(); + } + + /** + * Returns a list of identities of zones available in this region. + */ + public List getZones() { return zones; } /** * Returns quotas assigned to this region. */ + @Deprecated public List quotas() { + return getQuotas(); + } + + /** + * Returns quotas assigned to this region. + */ + public List getQuotas() { return quotas; } @@ -287,7 +367,17 @@ public List quotas() { * {@link DeprecationStatus.Status#DELETED} or {@link DeprecationStatus.Status#OBSOLETE} the * region should not be used. Returns {@code null} if the region is not deprecated. */ + @Deprecated public DeprecationStatus deprecationStatus() { + return getDeprecationStatus(); + } + + /** + * Returns the deprecation status of the region. If {@link DeprecationStatus#status()} is either + * {@link DeprecationStatus.Status#DELETED} or {@link DeprecationStatus.Status#OBSOLETE} the + * region should not be used. Returns {@code null} if the region is not deprecated. + */ + public DeprecationStatus getDeprecationStatus() { return deprecationStatus; } @@ -327,9 +417,9 @@ com.google.api.services.compute.model.Region toPb() { if (creationTimestamp != null) { regionPb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp)); } - regionPb.setName(regionId.region()); + regionPb.setName(regionId.getRegion()); regionPb.setDescription(description); - regionPb.setSelfLink(regionId.selfLink()); + regionPb.setSelfLink(regionId.getSelfLink()); if (status != null) { regionPb.setStatus(status.name()); } @@ -351,25 +441,26 @@ static Builder builder() { static Region fromPb(com.google.api.services.compute.model.Region regionPb) { Builder builder = builder(); - builder.regionId(RegionId.fromUrl(regionPb.getSelfLink())); + builder.setRegionId(RegionId.fromUrl(regionPb.getSelfLink())); if (regionPb.getId() != null) { - builder.generatedId(regionPb.getId().toString()); + builder.setGeneratedId(regionPb.getId().toString()); } if (regionPb.getCreationTimestamp() != null) { - builder.creationTimestamp(TIMESTAMP_FORMATTER.parseMillis(regionPb.getCreationTimestamp())); + builder.setCreationTimestamp( + TIMESTAMP_FORMATTER.parseMillis(regionPb.getCreationTimestamp())); } - builder.description(regionPb.getDescription()); + builder.setDescription(regionPb.getDescription()); if (regionPb.getStatus() != null) { - builder.status(Status.valueOf(regionPb.getStatus())); + builder.setStatus(Status.valueOf(regionPb.getStatus())); } if (regionPb.getZones() != null) { - builder.zones(Lists.transform(regionPb.getZones(), ZoneId.FROM_URL_FUNCTION)); + builder.setZones(Lists.transform(regionPb.getZones(), ZoneId.FROM_URL_FUNCTION)); } if (regionPb.getQuotas() != null) { - builder.quotas(Lists.transform(regionPb.getQuotas(), Quota.FROM_PB_FUNCTION)); + builder.setQuotas(Lists.transform(regionPb.getQuotas(), Quota.FROM_PB_FUNCTION)); } if (regionPb.getDeprecated() != null) { - builder.deprecationStatus( + builder.setDeprecationStatus( DeprecationStatus.fromPb(regionPb.getDeprecated(), RegionId.FROM_URL_FUNCTION)); } return builder.build(); diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/RegionAddressId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/RegionAddressId.java index 9e81b3ca909a..bcc5870a1e26 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/RegionAddressId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/RegionAddressId.java @@ -41,27 +41,55 @@ private RegionAddressId(String project, String region, String address) { } @Override + @Deprecated public Type type() { + return getType(); + } + + @Override + public Type getType() { return Type.REGION; } /** * Returns the name of the region this address belongs to. */ + @Deprecated public String region() { return region; } + /** + * Returns the name of the region this address belongs to. + */ + public String getRegion() { + return region; + } + /** * Returns the identity of the region this address belongs to. */ + @Deprecated public RegionId regionId() { - return RegionId.of(project(), region); + return RegionId.of(getProject(), region); + } + + /** + * Returns the identity of the region this address belongs to. + */ + public RegionId getRegionId() { + return RegionId.of(getProject(), region); } @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/regions/" + region + "/addresses/" + address(); + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/regions/" + region + "/addresses/" + getAddress(); } @Override @@ -88,10 +116,10 @@ public boolean equals(Object obj) { @Override RegionAddressId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } - return RegionAddressId.of(projectId, region, address()); + return RegionAddressId.of(projectId, region, getAddress()); } /** @@ -104,7 +132,7 @@ RegionAddressId setProjectId(String projectId) { * @see RFC1035 */ public static RegionAddressId of(RegionId regionId, String address) { - return new RegionAddressId(regionId.project(), regionId.region(), address); + return new RegionAddressId(regionId.getProject(), regionId.getRegion(), address); } /** diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/RegionForwardingRuleId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/RegionForwardingRuleId.java index f1f2460ef811..a15e03222d9a 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/RegionForwardingRuleId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/RegionForwardingRuleId.java @@ -41,7 +41,7 @@ public RegionForwardingRuleId apply(String pb) { new Function() { @Override public String apply(RegionForwardingRuleId forwardingRuleId) { - return forwardingRuleId.selfLink(); + return forwardingRuleId.getSelfLink(); } }; @@ -57,27 +57,55 @@ private RegionForwardingRuleId(String project, String region, String rule) { } @Override + @Deprecated public Type type() { + return getType(); + } + + @Override + public Type getType() { return Type.REGION; } /** * Returns the name of the region this forwarding rule belongs to. */ + @Deprecated public String region() { return region; } + /** + * Returns the name of the region this forwarding rule belongs to. + */ + public String getRegion() { + return region; + } + /** * Returns the identity of the region this forwarding rule belongs to. */ + @Deprecated public RegionId regionId() { - return RegionId.of(project(), region); + return RegionId.of(getProject(), region); + } + + /** + * Returns the identity of the region this forwarding rule belongs to. + */ + public RegionId getRegionId() { + return RegionId.of(getProject(), region); } @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/regions/" + region + "/forwardingRules/" + rule(); + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/regions/" + region + "/forwardingRules/" + getRule(); } @Override @@ -104,10 +132,10 @@ public boolean equals(Object obj) { @Override RegionForwardingRuleId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } - return RegionForwardingRuleId.of(projectId, region, rule()); + return RegionForwardingRuleId.of(projectId, region, getRule()); } /** @@ -120,7 +148,7 @@ RegionForwardingRuleId setProjectId(String projectId) { * @see RFC1035 */ public static RegionForwardingRuleId of(RegionId regionId, String rule) { - return new RegionForwardingRuleId(regionId.project(), regionId.region(), rule); + return new RegionForwardingRuleId(regionId.getProject(), regionId.getRegion(), rule); } /** diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/RegionId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/RegionId.java index 1f3c74084692..dce62d7bd267 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/RegionId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/RegionId.java @@ -39,7 +39,7 @@ public RegionId apply(String pb) { static final Function TO_URL_FUNCTION = new Function() { @Override public String apply(RegionId regionId) { - return regionId.selfLink(); + return regionId.getSelfLink(); } }; @@ -55,20 +55,34 @@ private RegionId(String project, String region) { } private RegionId(RegionId regionId) { - super(regionId.project()); - this.region = checkNotNull(regionId.region()); + super(regionId.getProject()); + this.region = checkNotNull(regionId.getRegion()); } /** * Returns the name of the region. */ + @Deprecated public final String region() { + return getRegion(); + } + + /** + * Returns the name of the region. + */ + public String getRegion() { return region; } @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/regions/" + region; + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/regions/" + region; } @Override @@ -95,7 +109,7 @@ public boolean equals(Object obj) { @Override RegionId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } return RegionId.of(projectId, region); diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/RegionOperationId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/RegionOperationId.java index f66f3cc615bc..1bb834118b0a 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/RegionOperationId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/RegionOperationId.java @@ -41,27 +41,55 @@ private RegionOperationId(String project, String region, String operation) { } @Override + @Deprecated public Type type() { + return getType(); + } + + @Override + public Type getType() { return Type.REGION; } /** * Returns the name of the region this operation belongs to. */ + @Deprecated public String region() { return region; } + /** + * Returns the name of the region this operation belongs to. + */ + public String getRegion() { + return region; + } + /** * Returns the identity of the region this operation belongs to. */ + @Deprecated public RegionId regionId() { - return RegionId.of(project(), region); + return RegionId.of(getProject(), region); + } + + /** + * Returns the identity of the region this operation belongs to. + */ + public RegionId getRegionId() { + return RegionId.of(getProject(), region); } @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/regions/" + region + "/operations/" + operation(); + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/regions/" + region + "/operations/" + getOperation(); } @Override @@ -88,17 +116,17 @@ public boolean equals(Object obj) { @Override RegionOperationId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } - return RegionOperationId.of(projectId, region, operation()); + return RegionOperationId.of(projectId, region, getOperation()); } /** * Returns a region operation identity given the region identity and the operation name. */ public static RegionOperationId of(RegionId regionId, String operation) { - return new RegionOperationId(regionId.project(), regionId.region(), operation); + return new RegionOperationId(regionId.getProject(), regionId.getRegion(), operation); } /** diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/ResourceId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/ResourceId.java index fed67c8fd72a..f3d773e247cf 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/ResourceId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/ResourceId.java @@ -39,14 +39,30 @@ public abstract class ResourceId implements Serializable { /** * Returns a fully qualified URL to the entity. */ + @Deprecated public String selfLink() { + return getSelfLink(); + } + + /** + * Returns a fully qualified URL to the entity. + */ + public String getSelfLink() { return BASE_URL + project; } /** * Returns the name of the project. */ + @Deprecated public final String project() { + return getProject(); + } + + /** + * Returns the name of the project. + */ + public final String getProject() { return project; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/SchedulingOptions.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/SchedulingOptions.java index 8abac14f8fcb..0752b5b308e4 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/SchedulingOptions.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/SchedulingOptions.java @@ -72,10 +72,18 @@ public Boolean automaticRestart() { /** * Returns the maintenance behavior for the instance. */ + @Deprecated public Maintenance maintenance() { return maintenance; } + /** + * Returns the maintenance behavior for the instance. + */ + public Maintenance getMaintenance() { + return maintenance; + } + /** * Returns {@code true} if the instance is preemptible, {@code false} otherwhise. * diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/ServiceAccount.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/ServiceAccount.java index 65508a0a4c3f..19d0be7cb68b 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/ServiceAccount.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/ServiceAccount.java @@ -64,17 +64,33 @@ private ServiceAccount(String email, List scopes) { /** * Returns the email address of the service account. */ + @Deprecated public String email() { return email; } + /** + * Returns the email address of the service account. + */ + public String getEmail() { + return email; + } + /** * Returns the list of scopes to be made available for this service account. */ + @Deprecated public List scopes() { return scopes; } + /** + * Returns the list of scopes to be made available for this service account. + */ + public List getScopes() { + return scopes; + } + @Override public String toString() { return MoreObjects.toStringHelper(this) diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/Snapshot.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/Snapshot.java index fee0e2fcfac5..3947addb969a 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/Snapshot.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/Snapshot.java @@ -55,8 +55,8 @@ public static class Builder extends SnapshotInfo.Builder { Builder(Compute compute, SnapshotId snapshotId, DiskId sourceDisk) { this.compute = compute; this.infoBuilder = new SnapshotInfo.BuilderImpl(); - this.infoBuilder.snapshotId(snapshotId); - this.infoBuilder.sourceDisk(sourceDisk); + this.infoBuilder.setSnapshotId(snapshotId); + this.infoBuilder.setSourceDisk(sourceDisk); } Builder(Snapshot snapshot) { @@ -65,68 +65,86 @@ public static class Builder extends SnapshotInfo.Builder { } @Override - Builder generatedId(String generatedId) { - infoBuilder.generatedId(generatedId); + Builder setGeneratedId(String generatedId) { + infoBuilder.setGeneratedId(generatedId); return this; } @Override - Builder creationTimestamp(Long creationTimestamp) { - infoBuilder.creationTimestamp(creationTimestamp); + Builder setCreationTimestamp(Long creationTimestamp) { + infoBuilder.setCreationTimestamp(creationTimestamp); return this; } @Override + @Deprecated public Builder snapshotId(SnapshotId snapshotId) { - infoBuilder.snapshotId(snapshotId); + return setSnapshotId(snapshotId); + } + + @Override + public Builder setSnapshotId(SnapshotId snapshotId) { + infoBuilder.setSnapshotId(snapshotId); return this; } @Override + @Deprecated public Builder description(String description) { - infoBuilder.description(description); + return setDescription(description); + } + + @Override + public Builder setDescription(String description) { + infoBuilder.setDescription(description); return this; } @Override - Builder status(Status status) { - infoBuilder.status(status); + Builder setStatus(Status status) { + infoBuilder.setStatus(status); return this; } @Override - Builder diskSizeGb(Long diskSizeGb) { - infoBuilder.diskSizeGb(diskSizeGb); + Builder setDiskSizeGb(Long diskSizeGb) { + infoBuilder.setDiskSizeGb(diskSizeGb); return this; } @Override - Builder licenses(List licenses) { - infoBuilder.licenses(licenses); + Builder setLicenses(List licenses) { + infoBuilder.setLicenses(licenses); return this; } @Override + @Deprecated public Builder sourceDisk(DiskId sourceDisk) { - infoBuilder.sourceDisk(sourceDisk); + return setSourceDisk(sourceDisk); + } + + @Override + public Builder setSourceDisk(DiskId sourceDisk) { + infoBuilder.setSourceDisk(sourceDisk); return this; } @Override - Builder sourceDiskId(String sourceDiskId) { - infoBuilder.sourceDiskId(sourceDiskId); + Builder setSourceDiskId(String sourceDiskId) { + infoBuilder.setSourceDiskId(sourceDiskId); return this; } @Override - Builder storageBytes(Long storageBytes) { - infoBuilder.storageBytes(storageBytes); + Builder setStorageBytes(Long storageBytes) { + infoBuilder.setStorageBytes(storageBytes); return this; } @Override - Builder storageBytesStatus(StorageBytesStatus storageBytesStatus) { - infoBuilder.storageBytesStatus(storageBytesStatus); + Builder setStorageBytesStatus(StorageBytesStatus storageBytesStatus) { + infoBuilder.setStorageBytesStatus(storageBytesStatus); return this; } @@ -161,7 +179,7 @@ public boolean exists() { * @throws ComputeException upon failure */ public Snapshot reload(SnapshotOption... options) { - return compute.getSnapshot(snapshotId().snapshot(), options); + return compute.getSnapshot(getSnapshotId().getSnapshot(), options); } /** @@ -172,13 +190,21 @@ public Snapshot reload(SnapshotOption... options) { * @throws ComputeException upon failure */ public Operation delete(OperationOption... options) { - return compute.deleteSnapshot(snapshotId(), options); + return compute.deleteSnapshot(getSnapshotId(), options); } /** * Returns the snapshot's {@code Compute} object used to issue requests. */ + @Deprecated public Compute compute() { + return getCompute(); + } + + /** + * Returns the snapshot's {@code Compute} object used to issue requests. + */ + public Compute getCompute() { return compute; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/SnapshotDiskConfiguration.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/SnapshotDiskConfiguration.java index 15909b6092d1..ee64b768c8f2 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/SnapshotDiskConfiguration.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/SnapshotDiskConfiguration.java @@ -72,20 +72,43 @@ private Builder(Disk diskPb) { * Restoring a snapshot to a larger size */ @Override + @Deprecated public Builder sizeGb(Long sizeGb) { - super.sizeGb(sizeGb); + return setSizeGb(sizeGb); + } + + /** + * Sets the size of the persistent disk, in GB. If not set the disk will have the size of the + * snapshot. This value can be larger than the snapshot's size. If the provided size is smaller + * than the snapshot's size then disk creation will fail. + * + * @see + * Restoring a snapshot to a larger size + */ + @Override + public Builder setSizeGb(Long sizeGb) { + super.setSizeGb(sizeGb); return this; } /** * Sets the identity of the source snapshot used to create the disk. */ + @Deprecated public Builder sourceSnapshot(SnapshotId sourceSnapshot) { + return setSourceSnapshot(sourceSnapshot); + } + + /** + * Sets the identity of the source snapshot used to create the disk. + */ + public Builder setSourceSnapshot(SnapshotId sourceSnapshot) { this.sourceSnapshot = checkNotNull(sourceSnapshot); return this; } - Builder sourceSnapshotId(String sourceSnapshotId) { + Builder setSourceSnapshotId(String sourceSnapshotId) { this.sourceSnapshotId = sourceSnapshotId; return this; } @@ -108,20 +131,39 @@ private SnapshotDiskConfiguration(Builder builder) { /** * Returns the identity of the source snapshot used to create the disk. */ + @Deprecated public SnapshotId sourceSnapshot() { return sourceSnapshot; } + /** + * Returns the identity of the source snapshot used to create the disk. + */ + public SnapshotId getSourceSnapshot() { + return sourceSnapshot; + } + /** * Returns the service-generated unique id of the snapshot used to create this disk. This value * identifies the exact snapshot that was used to create the persistent disk. For example, if you * created the persistent disk from a snapshot that was later deleted and recreated under the same * name, the source snapshot ID would identify the exact version of the snapshot that was used. */ + @Deprecated public String sourceSnapshotId() { return sourceSnapshotId; } + /** + * Returns the service-generated unique id of the snapshot used to create this disk. This value + * identifies the exact snapshot that was used to create the persistent disk. For example, if you + * created the persistent disk from a snapshot that was later deleted and recreated under the same + * name, the source snapshot ID would identify the exact version of the snapshot that was used. + */ + public String getSourceSnapshotId() { + return sourceSnapshotId; + } + @Override public Builder toBuilder() { return new Builder(this); @@ -149,9 +191,9 @@ public final boolean equals(Object obj) { @Override SnapshotDiskConfiguration setProjectId(String projectId) { - Builder builder = toBuilder().sourceSnapshot(sourceSnapshot.setProjectId(projectId)); - if (diskType() != null) { - builder.diskType(diskType().setProjectId(projectId)); + Builder builder = toBuilder().setSourceSnapshot(sourceSnapshot.setProjectId(projectId)); + if (getDiskType() != null) { + builder.setDiskType(getDiskType().setProjectId(projectId)); } return builder.build(); } @@ -159,14 +201,22 @@ SnapshotDiskConfiguration setProjectId(String projectId) { @Override Disk toPb() { return super.toPb() - .setSourceSnapshot(sourceSnapshot.selfLink()) + .setSourceSnapshot(sourceSnapshot.getSelfLink()) .setSourceSnapshotId(sourceSnapshotId); } /** * Returns a builder for a {@code SnapshotDiskConfiguration} object given the snapshot identity. */ + @Deprecated public static Builder builder(SnapshotId sourceSnapshot) { + return newBuilder(sourceSnapshot); + } + + /** + * Returns a builder for a {@code SnapshotDiskConfiguration} object given the snapshot identity. + */ + public static Builder newBuilder(SnapshotId sourceSnapshot) { return new Builder(sourceSnapshot); } @@ -174,7 +224,7 @@ public static Builder builder(SnapshotId sourceSnapshot) { * Returns a {@code SnapshotDiskConfiguration} object given the snapshot identity. */ public static SnapshotDiskConfiguration of(SnapshotId sourceSnapshot) { - return builder(sourceSnapshot).build(); + return newBuilder(sourceSnapshot).build(); } @SuppressWarnings("unchecked") diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/SnapshotId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/SnapshotId.java index a30d531b65be..349b22354dda 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/SnapshotId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/SnapshotId.java @@ -49,13 +49,33 @@ private SnapshotId(String project, String snapshot) { * * @see RFC1035 */ + @Deprecated public String snapshot() { + return getSnapshot(); + } + + /** + * Returns the name of the snapshot. The name must be 1-63 characters long and comply with + * RFC1035. Specifically, the name must match the regular expression + * {@code [a-z]([-a-z0-9]*[a-z0-9])?} which means the first character must be a lowercase letter, + * and all following characters must be a dash, lowercase letter, or digit, except the last + * character, which cannot be a dash. + * + * @see RFC1035 + */ + public String getSnapshot() { return snapshot; } @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/global/snapshots/" + snapshot; + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/global/snapshots/" + snapshot; } @Override @@ -82,7 +102,7 @@ public boolean equals(Object obj) { @Override SnapshotId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } return SnapshotId.of(projectId, snapshot); diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/SnapshotInfo.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/SnapshotInfo.java index ce9ebbc7825c..618933dc4017 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/SnapshotInfo.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/SnapshotInfo.java @@ -125,36 +125,54 @@ public enum StorageBytesStatus { */ public abstract static class Builder { - abstract Builder generatedId(String generatedId); + abstract Builder setGeneratedId(String generatedId); - abstract Builder creationTimestamp(Long creationTimestamp); + abstract Builder setCreationTimestamp(Long creationTimestamp); /** * Sets the snapshot identity. */ + @Deprecated public abstract Builder snapshotId(SnapshotId snapshotId); + /** + * Sets the snapshot identity. + */ + public abstract Builder setSnapshotId(SnapshotId snapshotId); + /** * Sets an optional textual description of the snapshot. */ + @Deprecated public abstract Builder description(String description); - abstract Builder status(Status status); + /** + * Sets an optional textual description of the snapshot. + */ + public abstract Builder setDescription(String description); + + abstract Builder setStatus(Status status); - abstract Builder diskSizeGb(Long diskSizeGb); + abstract Builder setDiskSizeGb(Long diskSizeGb); - abstract Builder licenses(List licenses); + abstract Builder setLicenses(List licenses); /** * Sets the identity of the source disk used to create the snapshot. */ + @Deprecated public abstract Builder sourceDisk(DiskId sourceDisk); - abstract Builder sourceDiskId(String sourceDiskId); + /** + * Sets the identity of the source disk used to create the snapshot. + */ + public abstract Builder setSourceDisk(DiskId sourceDisk); + + abstract Builder setSourceDiskId(String sourceDiskId); - abstract Builder storageBytes(Long storageBytes); + abstract Builder setStorageBytes(Long storageBytes); - abstract Builder storageBytesStatus(StorageBytesStatus storageBytesStatus); + abstract Builder setStorageBytesStatus(StorageBytesStatus storageBytesStatus); /** * Creates a {@code SnapshotInfo} object. @@ -219,67 +237,85 @@ static final class BuilderImpl extends Builder { } @Override - BuilderImpl generatedId(String generatedId) { + BuilderImpl setGeneratedId(String generatedId) { this.generatedId = generatedId; return this; } @Override - BuilderImpl creationTimestamp(Long creationTimestamp) { + BuilderImpl setCreationTimestamp(Long creationTimestamp) { this.creationTimestamp = creationTimestamp; return this; } @Override + @Deprecated public BuilderImpl snapshotId(SnapshotId snapshotId) { + return setSnapshotId(snapshotId); + } + + @Override + public BuilderImpl setSnapshotId(SnapshotId snapshotId) { this.snapshotId = checkNotNull(snapshotId); return this; } @Override + @Deprecated public BuilderImpl description(String description) { + return setDescription(description); + } + + @Override + public BuilderImpl setDescription(String description) { this.description = description; return this; } @Override - BuilderImpl status(Status status) { + BuilderImpl setStatus(Status status) { this.status = status; return this; } @Override - BuilderImpl diskSizeGb(Long diskSizeGb) { + BuilderImpl setDiskSizeGb(Long diskSizeGb) { this.diskSizeGb = diskSizeGb; return this; } @Override - BuilderImpl licenses(List licenses) { + BuilderImpl setLicenses(List licenses) { this.licenses = licenses != null ? ImmutableList.copyOf(licenses) : null; return this; } @Override + @Deprecated public BuilderImpl sourceDisk(DiskId sourceDisk) { + return setSourceDisk(sourceDisk); + } + + @Override + public BuilderImpl setSourceDisk(DiskId sourceDisk) { this.sourceDisk = checkNotNull(sourceDisk); return this; } @Override - BuilderImpl sourceDiskId(String sourceDiskId) { + BuilderImpl setSourceDiskId(String sourceDiskId) { this.sourceDiskId = sourceDiskId; return this; } @Override - BuilderImpl storageBytes(Long storageBytes) { + BuilderImpl setStorageBytes(Long storageBytes) { this.storageBytes = storageBytes; return this; } @Override - BuilderImpl storageBytesStatus(StorageBytesStatus storageBytesStatus) { + BuilderImpl setStorageBytesStatus(StorageBytesStatus storageBytesStatus) { this.storageBytesStatus = storageBytesStatus; return this; } @@ -307,35 +343,75 @@ public SnapshotInfo build() { /** * Returns the service-generated unique identifier for the snapshot. */ + @Deprecated public String generatedId() { + return getGeneratedId(); + } + + /** + * Returns the service-generated unique identifier for the snapshot. + */ + public String getGeneratedId() { return generatedId; } /** * Returns the creation timestamp in milliseconds since epoch. */ + @Deprecated public Long creationTimestamp() { + return getCreationTimestamp(); + } + + /** + * Returns the creation timestamp in milliseconds since epoch. + */ + public Long getCreationTimestamp() { return creationTimestamp; } /** * Returns the snapshot identity. */ + @Deprecated public SnapshotId snapshotId() { + return getSnapshotId(); + } + + /** + * Returns the snapshot identity. + */ + public SnapshotId getSnapshotId() { return snapshotId; } /** * Returns a textual description of the snapshot. */ + @Deprecated public String description() { + return getDescription(); + } + + /** + * Returns a textual description of the snapshot. + */ + public String getDescription() { return description; } /** * Returns all applicable publicly visible licenses. */ + @Deprecated public List licenses() { + return getLicenses(); + } + + /** + * Returns all applicable publicly visible licenses. + */ + public List getLicenses() { return licenses; } @@ -344,21 +420,47 @@ public List licenses() { * disks, only after the snapshot has been successfully created and the status is set to * {@code READY}. */ + @Deprecated public Status status() { + return getStatus(); + } + + /** + * Returns the status of the snapshot. A snapshot can be used to create other resources, such as + * disks, only after the snapshot has been successfully created and the status is set to + * {@code READY}. + */ + public Status getStatus() { return status; } /** * Returns the size of the snapshot (in GB). */ + @Deprecated public Long diskSizeGb() { + return getDiskSizeGb(); + } + + /** + * Returns the size of the snapshot (in GB). + */ + public Long getDiskSizeGb() { return diskSizeGb; } /** * Returns the identity of the source disk used to create this snapshot. */ + @Deprecated public DiskId sourceDisk() { + return getSourceDisk(); + } + + /** + * Returns the identity of the source disk used to create this snapshot. + */ + public DiskId getSourceDisk() { return sourceDisk; } @@ -367,7 +469,17 @@ public DiskId sourceDisk() { * may be used to determine whether the snapshot was taken from the current or a previous instance * of a given disk name. */ + @Deprecated public String sourceDiskId() { + return getSourceDiskId(); + } + + /** + * Returns the service-generated unique id of the disk used to create this snapshot. This value + * may be used to determine whether the snapshot was taken from the current or a previous instance + * of a given disk name. + */ + public String getSourceDiskId() { return sourceDiskId; } @@ -375,7 +487,16 @@ public String sourceDiskId() { * Returns the size of the the storage used by the snapshot. As snapshots share storage, this * number is expected to change with snapshot creation/deletion. */ + @Deprecated public Long storageBytes() { + return getStorageBytes(); + } + + /** + * Returns the size of the the storage used by the snapshot. As snapshots share storage, this + * number is expected to change with snapshot creation/deletion. + */ + public Long getStorageBytes() { return storageBytes; } @@ -385,7 +506,18 @@ public Long storageBytes() { * indicates that the size of the snapshot is being updated. {@link StorageBytesStatus#UP_TO_DATE} * indicates that the size of the snapshot is up-to-date. */ + @Deprecated public StorageBytesStatus storageBytesStatus() { + return getStorageBytesStatus(); + } + + /** + * Indicates whether {@link SnapshotInfo#storageBytes()} is in a stable state or it is being + * adjusted as a result of shared storage reallocation. {@link StorageBytesStatus#UPDATING} + * indicates that the size of the snapshot is being updated. {@link StorageBytesStatus#UP_TO_DATE} + * indicates that the size of the snapshot is up-to-date. + */ + public StorageBytesStatus getStorageBytesStatus() { return storageBytesStatus; } @@ -429,8 +561,8 @@ public boolean equals(Object obj) { SnapshotInfo setProjectId(String projectId) { return toBuilder() - .snapshotId(snapshotId.setProjectId(projectId)) - .sourceDisk(sourceDisk.setProjectId(projectId)) + .setSnapshotId(snapshotId.setProjectId(projectId)) + .setSourceDisk(sourceDisk.setProjectId(projectId)) .build(); } @@ -442,9 +574,9 @@ Snapshot toPb() { if (creationTimestamp != null) { snapshotPb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp)); } - snapshotPb.setName(snapshotId.snapshot()); + snapshotPb.setName(snapshotId.getSnapshot()); snapshotPb.setDescription(description); - snapshotPb.setSelfLink(snapshotId.selfLink()); + snapshotPb.setSelfLink(snapshotId.getSelfLink()); if (status != null) { snapshotPb.setStatus(status.name()); } @@ -453,7 +585,7 @@ Snapshot toPb() { snapshotPb.setLicenses(Lists.transform(licenses, LicenseId.TO_URL_FUNCTION)); } if (sourceDisk != null) { - snapshotPb.setSourceDisk(sourceDisk.selfLink()); + snapshotPb.setSourceDisk(sourceDisk.getSelfLink()); } snapshotPb.setSourceDiskId(sourceDiskId); snapshotPb.setStorageBytes(storageBytes); @@ -467,15 +599,24 @@ Snapshot toPb() { * Returns a builder for a {@code SnapshotInfo} object given the snapshot identity and a source * disk identity. */ + @Deprecated public static Builder builder(SnapshotId snapshotId, DiskId source) { - return new BuilderImpl().snapshotId(snapshotId).sourceDisk(source); + return newBuilder(snapshotId, source); + } + + /** + * Returns a builder for a {@code SnapshotInfo} object given the snapshot identity and a source + * disk identity. + */ + public static Builder newBuilder(SnapshotId snapshotId, DiskId source) { + return new BuilderImpl().setSnapshotId(snapshotId).setSourceDisk(source); } /** * Returns a {@code SnapshotInfo} object given the snapshot identity and a source disk identity. */ public static SnapshotInfo of(SnapshotId snapshotId, DiskId source) { - return builder(snapshotId, source).build(); + return newBuilder(snapshotId, source).build(); } static SnapshotInfo fromPb(Snapshot snapshotPb) { diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/StandardDiskConfiguration.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/StandardDiskConfiguration.java index 90cf9fb7c40b..5138c7d7b8ea 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/StandardDiskConfiguration.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/StandardDiskConfiguration.java @@ -52,8 +52,17 @@ private Builder(Disk diskPb) { * Sets the size of the persistent disk, in GB. If not set, 500GB is used. */ @Override + @Deprecated public Builder sizeGb(Long sizeGb) { - super.sizeGb(sizeGb); + return setSizeGb(sizeGb); + } + + /** + * Sets the size of the persistent disk, in GB. If not set, 500GB is used. + */ + @Override + public Builder setSizeGb(Long sizeGb) { + super.setSizeGb(sizeGb); return this; } @@ -90,16 +99,24 @@ public final boolean equals(Object obj) { @Override StandardDiskConfiguration setProjectId(String projectId) { - if (diskType() == null || diskType().project() != null) { + if (getDiskType() == null || getDiskType().getProject() != null) { return this; } - return toBuilder().diskType(diskType().setProjectId(projectId)).build(); + return toBuilder().setDiskType(getDiskType().setProjectId(projectId)).build(); } /** * Returns a builder for a {@code StandardDiskConfiguration} object. */ + @Deprecated public static Builder builder() { + return newBuilder(); + } + + /** + * Returns a builder for a {@code StandardDiskConfiguration} object. + */ + public static Builder newBuilder() { return new Builder(); } @@ -107,21 +124,21 @@ public static Builder builder() { * Returns a {@code StandardDiskConfiguration} object given the disk type. */ public static StandardDiskConfiguration of(DiskTypeId diskType) { - return builder().diskType(diskType).build(); + return newBuilder().setDiskType(diskType).build(); } /** * Returns a {@code StandardDiskConfiguration} object given the disk size in GB. */ public static StandardDiskConfiguration of(long sizeGb) { - return builder().sizeGb(sizeGb).build(); + return newBuilder().setSizeGb(sizeGb).build(); } /** * Returns a {@code StandardDiskConfiguration} object given the disk type and size in GB. */ public static StandardDiskConfiguration of(DiskTypeId diskType, long sizeGb) { - return builder().diskType(diskType).sizeGb(sizeGb).build(); + return newBuilder().setDiskType(diskType).setSizeGb(sizeGb).build(); } @SuppressWarnings("unchecked") diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/StandardNetworkConfiguration.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/StandardNetworkConfiguration.java index 16aa8a128d0a..1a29e8fb3d06 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/StandardNetworkConfiguration.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/StandardNetworkConfiguration.java @@ -49,7 +49,18 @@ public class StandardNetworkConfiguration extends NetworkConfiguration { * * @see CIDR */ + @Deprecated public String ipRange() { + return getIpRange(); + } + + /** + * 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 getIpRange() { return ipRange; } @@ -57,7 +68,16 @@ public String 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}. */ + @Deprecated public String gatewayAddress() { + return getGatewayAddress(); + } + + /** + * 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 getGatewayAddress() { return gatewayAddress; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/StorageImageConfiguration.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/StorageImageConfiguration.java index f90e9fa4e13a..3796cf6a688c 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/StorageImageConfiguration.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/StorageImageConfiguration.java @@ -77,7 +77,16 @@ private Builder(Image imagePb) { * Sets the format used to encode and transmit the block device. The only supported value is * {@code TAR}. This is just a container and transmission format, not a runtime format. */ + @Deprecated public Builder containerType(ContainerType containerType) { + return setContainerType(containerType); + } + + /** + * Sets the format used to encode and transmit the block device. The only supported value is + * {@code TAR}. This is just a container and transmission format, not a runtime format. + */ + public Builder setContainerType(ContainerType containerType) { this.containerType = containerType; return this; } @@ -85,7 +94,15 @@ public Builder containerType(ContainerType containerType) { /** * Sets the SHA1 checksum of the disk image before unpackaging. */ + @Deprecated public Builder sha1(String sha1) { + return setSha1(sha1); + } + + /** + * Sets the SHA1 checksum of the disk image before unpackaging. + */ + public Builder setSha1(String sha1) { this.sha1 = sha1; return this; } @@ -94,7 +111,16 @@ public Builder sha1(String sha1) { * Sets the full Google Cloud Storage URL where the disk image is stored (e.g. * {@code gs://bucket/file}). */ + @Deprecated public Builder source(String source) { + return setSource(source); + } + + /** + * Sets the full Google Cloud Storage URL where the disk image is stored (e.g. + * {@code gs://bucket/file}). + */ + public Builder setSource(String source) { this.source = checkNotNull(source); return this; } @@ -119,14 +145,31 @@ private StorageImageConfiguration(Builder builder) { * Returns the format used to encode and transmit the block device. This is just a container and * transmission format, not a runtime format. */ + @Deprecated public ContainerType containerType() { + return getContainerType(); + } + + /** + * Returns the format used to encode and transmit the block device. This is just a container and + * transmission format, not a runtime format. + */ + public ContainerType getContainerType() { return containerType; } /** * Returns the SHA1 checksum of the disk image before unpackaging. */ + @Deprecated public String sha1() { + return getSha1(); + } + + /** + * Returns the SHA1 checksum of the disk image before unpackaging. + */ + public String getSha1() { return sha1; } @@ -134,7 +177,16 @@ public String sha1() { * Returns the full Google Cloud Storage URL where the disk image is stored (e.g. * {@code gs://bucket/file}). */ + @Deprecated public String source() { + return getSource(); + } + + /** + * Returns the full Google Cloud Storage URL where the disk image is stored (e.g. + * {@code gs://bucket/file}). + */ + public String getSource() { return source; } @@ -185,8 +237,17 @@ Image toPb() { * Creates a {@code StorageImageConfiguration} builder given the full Google Cloud Storage URL * where the disk image is stored. */ + @Deprecated public static Builder builder(String source) { - return new Builder().source(source); + return newBuilder(source); + } + + /** + * Creates a {@code StorageImageConfiguration} builder given the full Google Cloud Storage URL + * where the disk image is stored. + */ + public static Builder newBuilder(String source) { + return new Builder().setSource(source); } /** @@ -194,7 +255,7 @@ public static Builder builder(String source) { * where the disk image is stored. */ public static StorageImageConfiguration of(String source) { - return builder(source).build(); + return newBuilder(source).build(); } @SuppressWarnings("unchecked") diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/SubnetNetworkConfiguration.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/SubnetNetworkConfiguration.java index d060e91eab73..727ba1210b8b 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/SubnetNetworkConfiguration.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/SubnetNetworkConfiguration.java @@ -56,7 +56,15 @@ public Boolean autoCreateSubnetworks() { /** * Returns the identities of all networks in this network. */ + @Deprecated public List subnetworks() { + return getSubnetworks(); + } + + /** + * Returns the identities of all networks in this network. + */ + public List getSubnetworks() { return subnetworks; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/Subnetwork.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/Subnetwork.java index b3929dd937ea..c190d0201415 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/Subnetwork.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/Subnetwork.java @@ -52,9 +52,9 @@ public static class Builder extends SubnetworkInfo.Builder { Builder(Compute compute, SubnetworkId subnetworkId, NetworkId networkId, String ipRange) { this.compute = compute; this.infoBuilder = new SubnetworkInfo.BuilderImpl(subnetworkId, networkId, ipRange); - this.infoBuilder.subnetworkId(subnetworkId); - this.infoBuilder.network(networkId); - this.infoBuilder.ipRange(ipRange); + this.infoBuilder.setSubnetworkId(subnetworkId); + this.infoBuilder.setNetwork(networkId); + this.infoBuilder.setIpRange(ipRange); } Builder(Subnetwork subnetwork) { @@ -63,44 +63,64 @@ public static class Builder extends SubnetworkInfo.Builder { } @Override - Builder generatedId(String generatedId) { - infoBuilder.generatedId(generatedId); + Builder setGeneratedId(String generatedId) { + infoBuilder.setGeneratedId(generatedId); return this; } @Override - Builder creationTimestamp(Long creationTimestamp) { - infoBuilder.creationTimestamp(creationTimestamp); + Builder setCreationTimestamp(Long creationTimestamp) { + infoBuilder.setCreationTimestamp(creationTimestamp); return this; } + @Override + public Builder setSubnetworkId(SubnetworkId subnetworkId) { + return setSubnetworkId(subnetworkId); + } + @Override public Builder subnetworkId(SubnetworkId subnetworkId) { - infoBuilder.subnetworkId(subnetworkId); + infoBuilder.setSubnetworkId(subnetworkId); return this; } + @Override + public Builder setDescription(String description) { + return setDescription(description); + } + @Override public Builder description(String description) { - infoBuilder.description(description); + infoBuilder.setDescription(description); return this; } @Override - Builder gatewayAddress(String gatewayAddress) { - infoBuilder.gatewayAddress(gatewayAddress); + Builder setGatewayAddress(String gatewayAddress) { + infoBuilder.setGatewayAddress(gatewayAddress); return this; } + @Override + public Builder setNetwork(NetworkId network) { + return setNetwork(network); + } + @Override public Builder network(NetworkId network) { - infoBuilder.network(network); + infoBuilder.setNetwork(network); return this; } + @Override + public Builder setIpRange(String ipRange) { + return setIpRange(ipRange); + } + @Override public Builder ipRange(String ipRange) { - infoBuilder.ipRange(ipRange); + infoBuilder.setIpRange(ipRange); return this; } @@ -135,7 +155,7 @@ public boolean exists() { * @throws ComputeException upon failure */ public Subnetwork reload(SubnetworkOption... options) { - return compute.getSubnetwork(subnetworkId(), options); + return compute.getSubnetwork(getSubnetworkId(), options); } /** @@ -146,13 +166,21 @@ public Subnetwork reload(SubnetworkOption... options) { * @throws ComputeException upon failure */ public Operation delete(OperationOption... options) { - return compute.deleteSubnetwork(subnetworkId(), options); + return compute.deleteSubnetwork(getSubnetworkId(), options); } /** * Returns the subnetwork's {@code Compute} object used to issue requests. */ + @Deprecated public Compute compute() { + return getCompute(); + } + + /** + * Returns the subnetwork's {@code Compute} object used to issue requests. + */ + public Compute getCompute() { return compute; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/SubnetworkId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/SubnetworkId.java index b750847a3d10..cd1c48fe33f4 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/SubnetworkId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/SubnetworkId.java @@ -41,7 +41,7 @@ public SubnetworkId apply(String pb) { new Function() { @Override public String apply(SubnetworkId zoneId) { - return zoneId.selfLink(); + return zoneId.getSelfLink(); } }; @@ -61,15 +61,31 @@ private SubnetworkId(String project, String region, String subnetwork) { /** * Returns the name of the region this subnetwork belongs to. */ + @Deprecated public String region() { + return getRegion(); + } + + /** + * Returns the name of the region this subnetwork belongs to. + */ + public String getRegion() { return region; } /** * Returns the identity of the region this subnetwork belongs to. */ + @Deprecated public RegionId regionId() { - return RegionId.of(project(), region); + return getRegionId(); + } + + /** + * Returns the identity of the region this subnetwork belongs to. + */ + public RegionId getRegionId() { + return RegionId.of(getProject(), region); } /** @@ -81,13 +97,33 @@ public RegionId regionId() { * * @see RFC1035 */ + @Deprecated public String subnetwork() { + return getSubnetwork(); + } + + /** + * Returns the name of the subnetwork. The name must be 1-63 characters long and comply with + * RFC1035. Specifically, the name must match the regular expression + * {@code [a-z]([-a-z0-9]*[a-z0-9])?} which means the first character must be a lowercase letter, + * and all following characters must be a dash, lowercase letter, or digit, except the last + * character, which cannot be a dash. + * + * @see RFC1035 + */ + public String getSubnetwork() { return subnetwork; } @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/regions/" + region + "/subnetworks/" + subnetwork; + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/regions/" + region + "/subnetworks/" + subnetwork; } @Override @@ -116,10 +152,10 @@ public boolean equals(Object obj) { @Override SubnetworkId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } - return SubnetworkId.of(projectId, region(), subnetwork); + return SubnetworkId.of(projectId, getRegion(), subnetwork); } /** @@ -132,7 +168,7 @@ SubnetworkId setProjectId(String projectId) { * @see RFC1035 */ public static SubnetworkId of(RegionId regionId, String subnetwork) { - return new SubnetworkId(regionId.project(), regionId.region(), subnetwork); + return new SubnetworkId(regionId.getProject(), regionId.getRegion(), subnetwork); } /** diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/SubnetworkInfo.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/SubnetworkInfo.java index a89a5d713f0f..9705030af27a 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/SubnetworkInfo.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/SubnetworkInfo.java @@ -69,28 +69,47 @@ public Subnetwork apply(SubnetworkInfo subnetwork) { */ public abstract static class Builder { - abstract Builder generatedId(String generatedId); + abstract Builder setGeneratedId(String generatedId); - abstract Builder creationTimestamp(Long creationTimestamp); + abstract Builder setCreationTimestamp(Long creationTimestamp); /** * Sets the identity of the subnework. */ + @Deprecated public abstract Builder subnetworkId(SubnetworkId subnetworkId); + /** + * Sets the identity of the subnework. + */ + public abstract Builder setSubnetworkId(SubnetworkId subnetworkId); + /** * Sets an optional textual description of the subnetwork. */ + @Deprecated public abstract Builder description(String description); - abstract Builder gatewayAddress(String gatewayAddress); + /** + * Sets an optional textual description of the subnetwork. + */ + public abstract Builder setDescription(String description); + + abstract Builder setGatewayAddress(String gatewayAddress); /** * Sets the identity of the network to which this subnetwork belongs. Only networks that are in * subnet mode can have subnetworks. */ + @Deprecated public abstract Builder network(NetworkId network); + /** + * Sets the identity of the network to which this subnetwork belongs. Only networks that are in + * subnet mode can have subnetworks. + */ + public abstract Builder setNetwork(NetworkId network); + /** * Sets the range of internal IPv4 addresses that are owned by this subnetwork. This range must * be a CIDR specification, for example: {@code 192.168.0.0/16}. Ranges must be unique and @@ -98,8 +117,18 @@ public abstract static class Builder { * * @see CIDR */ + @Deprecated public abstract Builder ipRange(String ipRange); + /** + * Sets the range of internal IPv4 addresses that are owned by this subnetwork. This range must + * be a CIDR specification, for example: {@code 192.168.0.0/16}. Ranges must be unique and + * non-overlapping within a network. + * + * @see CIDR + */ + public abstract Builder setIpRange(String ipRange); + /** * Creates a {@code SubnetworkInfo} object. */ @@ -150,43 +179,67 @@ static final class BuilderImpl extends Builder { } @Override - BuilderImpl generatedId(String generatedId) { + BuilderImpl setGeneratedId(String generatedId) { this.generatedId = generatedId; return this; } @Override - BuilderImpl creationTimestamp(Long creationTimestamp) { + BuilderImpl setCreationTimestamp(Long creationTimestamp) { this.creationTimestamp = creationTimestamp; return this; } @Override + @Deprecated public BuilderImpl subnetworkId(SubnetworkId subnetworkId) { + return setSubnetworkId(subnetworkId); + } + + @Override + public BuilderImpl setSubnetworkId(SubnetworkId subnetworkId) { this.subnetworkId = checkNotNull(subnetworkId); return this; } @Override + @Deprecated public BuilderImpl description(String description) { + return setDescription(description); + } + + @Override + public BuilderImpl setDescription(String description) { this.description = description; return this; } @Override - BuilderImpl gatewayAddress(String gatewayAddress) { + BuilderImpl setGatewayAddress(String gatewayAddress) { this.gatewayAddress = gatewayAddress; return this; } @Override + @Deprecated public BuilderImpl network(NetworkId network) { + return setNetwork(network); + } + + @Override + public BuilderImpl setNetwork(NetworkId network) { this.network = checkNotNull(network); return this; } @Override + @Deprecated public BuilderImpl ipRange(String ipRange) { + return setIpRange(ipRange); + } + + @Override + public BuilderImpl setIpRange(String ipRange) { this.ipRange = checkNotNull(ipRange); return this; } @@ -210,35 +263,75 @@ public SubnetworkInfo build() { /** * Returns the service-generated unique identifier for the subnetwork. */ + @Deprecated public String generatedId() { + return getGeneratedId(); + } + + /** + * Returns the service-generated unique identifier for the subnetwork. + */ + public String getGeneratedId() { return generatedId; } /** * Returns the creation timestamp in milliseconds since epoch. */ + @Deprecated public Long creationTimestamp() { + return getCreationTimestamp(); + } + + /** + * Returns the creation timestamp in milliseconds since epoch. + */ + public Long getCreationTimestamp() { return creationTimestamp; } /** * Returns the subnetwork identity. */ + @Deprecated public SubnetworkId subnetworkId() { + return getSubnetworkId(); + } + + /** + * Returns the subnetwork identity. + */ + public SubnetworkId getSubnetworkId() { return subnetworkId; } /** * Returns a textual description of the subnetwork. */ + @Deprecated public String description() { + return getDescription(); + } + + /** + * Returns a textual description of the subnetwork. + */ + public String getDescription() { return description; } /** * Returns the gateway IPv4 address for this subnetwork, selected by the service. */ + @Deprecated public String gatewayAddress() { + return getGatewayAddress(); + } + + /** + * Returns the gateway IPv4 address for this subnetwork, selected by the service. + */ + public String getGatewayAddress() { return gatewayAddress; } @@ -246,7 +339,16 @@ public String gatewayAddress() { * Returns the identity of the network to which this subnetwork belongs. Only networks that are in * subnet mode can have subnetworks. */ + @Deprecated public NetworkId network() { + return getNetwork(); + } + + /** + * Returns the identity of the network to which this subnetwork belongs. Only networks that are in + * subnet mode can have subnetworks. + */ + public NetworkId getNetwork() { return network; } @@ -257,10 +359,22 @@ public NetworkId network() { * * @see CIDR */ + @Deprecated public String ipRange() { return ipRange; } + /** + * Returns the range of internal IPv4 addresses that are owned by this subnetwork. This range is a + * CIDR specification, for example: {@code 192.168.0.0/16}. Ranges must be unique and + * non-overlapping within a network. + * + * @see CIDR + */ + public String getIpRange() { + return ipRange; + } + /** * Returns a builder for the current subnetwork. */ @@ -297,8 +411,8 @@ public boolean equals(Object obj) { SubnetworkInfo setProjectId(String projectId) { return toBuilder() - .subnetworkId(subnetworkId.setProjectId(projectId)) - .network(network.setProjectId(projectId)) + .setSubnetworkId(subnetworkId.setProjectId(projectId)) + .setNetwork(network.setProjectId(projectId)) .build(); } @@ -310,11 +424,11 @@ Subnetwork toPb() { if (creationTimestamp != null) { subnetworkPb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp)); } - subnetworkPb.setName(subnetworkId.subnetwork()); + subnetworkPb.setName(subnetworkId.getSubnetwork()); subnetworkPb.setDescription(description); - subnetworkPb.setSelfLink(subnetworkId.selfLink()); + subnetworkPb.setSelfLink(subnetworkId.getSelfLink()); subnetworkPb.setGatewayAddress(gatewayAddress); - subnetworkPb.setNetwork(network.selfLink()); + subnetworkPb.setNetwork(network.getSelfLink()); subnetworkPb.setIpCidrRange(ipRange); return subnetworkPb; } @@ -327,7 +441,20 @@ Subnetwork toPb() { * * @see CIDR */ + @Deprecated public static Builder builder(SubnetworkId subnetworkId, NetworkId network, String ipRange) { + return newBuilder(subnetworkId, network, ipRange); + } + + /** + * Returns a builder for a {@code SubnetworkInfo} object given the identity of the subnetwork, the + * identity of the network this subnetwork belongs to and the range of IPv4 addresses owned by + * this subnetwork. {@code ipRange} must be a CIDR specification, for example: + * {@code 192.168.0.0/16}. + * + * @see CIDR + */ + public static Builder newBuilder(SubnetworkId subnetworkId, NetworkId network, String ipRange) { return new BuilderImpl(subnetworkId, network, ipRange); } @@ -339,7 +466,7 @@ public static Builder builder(SubnetworkId subnetworkId, NetworkId network, Stri * @see CIDR */ public static SubnetworkInfo of(SubnetworkId subnetworkId, NetworkId network, String ipRange) { - return builder(subnetworkId, network, ipRange).build(); + return newBuilder(subnetworkId, network, ipRange).build(); } static SubnetworkInfo fromPb(Subnetwork subnetworkPb) { diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/Tags.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/Tags.java index 7be604cd5a64..d8e0366f468a 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/Tags.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/Tags.java @@ -81,7 +81,18 @@ private Builder(Tags tags) { * * @see RFC1035 */ + @Deprecated public Builder values(Iterable values) { + return setValues(values); + } + + /** + * Sets a list of tags to apply to an instance. Tags are used to identify valid sources or + * targets for network firewalls. Each tag within the list must comply with RFC1035. + * + * @see RFC1035 + */ + public Builder setValues(Iterable values) { this.values = Lists.newArrayList(values); return this; } @@ -92,7 +103,18 @@ public Builder values(Iterable values) { * * @see RFC1035 */ + @Deprecated public Builder values(String... values) { + return setValues(values); + } + + /** + * Sets a list of tags to apply to an instance. Tags are used to identify valid sources or + * targets for network firewalls. Each tag within the list must comply with RFC1035. + * + * @see RFC1035 + */ + public Builder setValues(String... values) { this.values = Lists.newArrayList(Arrays.asList(checkNotNull(values))); return this; } @@ -111,7 +133,15 @@ public Builder add(String tag) { /** * Sets the fingerprint for the tags. This value is needed to update instance's tags. */ + @Deprecated public Builder fingerprint(String fingerprint) { + return setFingerprint(fingerprint); + } + + /** + * Sets the fingerprint for the tags. This value is needed to update instance's tags. + */ + public Builder setFingerprint(String fingerprint) { this.fingerprint = fingerprint; return this; } @@ -135,14 +165,33 @@ private Tags(Builder builder) { * * @see RFC1035 */ + @Deprecated public List values() { + return getValues(); + } + + /** + * Returns a list of tags to apply to an instance. Tags are used to identify valid sources or + * targets for network firewalls. Each tag within the list must comply with RFC1035. + * + * @see RFC1035 + */ + public List getValues() { return values; } /** * Returns the fingerprint for the tags. This value is needed to update instance's tags. */ + @Deprecated public String fingerprint() { + return getFingerprint(); + } + + /** + * Returns the fingerprint for the tags. This value is needed to update instance's tags. + */ + public String getFingerprint() { return fingerprint; } @@ -185,8 +234,9 @@ com.google.api.services.compute.model.Tags toPb() { * * @see RFC1035 */ + @Deprecated public static Builder builder(Iterable values) { - return new Builder().values(values); + return newBuilder(values); } /** @@ -195,8 +245,29 @@ public static Builder builder(Iterable values) { * * @see RFC1035 */ + public static Builder newBuilder(Iterable values) { + return new Builder().setValues(values); + } + + /** + * Returns a builder for a {@code Tags} object given the tags to apply to the instance. Each tag + * within the list must comply with RFC1035. + * + * @see RFC1035 + */ + @Deprecated public static Builder builder(String... values) { - return new Builder().values(values); + return newBuilder(values); + } + + /** + * Returns a builder for a {@code Tags} object given the tags to apply to the instance. Each tag + * within the list must comply with RFC1035. + * + * @see RFC1035 + */ + public static Builder newBuilder(String... values) { + return new Builder().setValues(values); } /** @@ -206,7 +277,7 @@ public static Builder builder(String... values) { * @see RFC1035 */ public static Tags of(Iterable values) { - return builder(values).build(); + return newBuilder(values).build(); } /** @@ -216,12 +287,12 @@ public static Tags of(Iterable values) { * @see RFC1035 */ public static Tags of(String... values) { - return builder(values).build(); + return newBuilder(values).build(); } static Tags fromPb(com.google.api.services.compute.model.Tags tagsPb) { Builder builder = - builder(tagsPb.getItems() != null ? tagsPb.getItems() : ImmutableList.of()); - return builder.fingerprint(tagsPb.getFingerprint()).build(); + newBuilder(tagsPb.getItems() != null ? tagsPb.getItems() : ImmutableList.of()); + return builder.setFingerprint(tagsPb.getFingerprint()).build(); } } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/Zone.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/Zone.java index 1534506c55a3..bd90ca6ee050 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/Zone.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/Zone.java @@ -80,37 +80,37 @@ static final class Builder { private Builder() {} - Builder zoneId(ZoneId zoneId) { + Builder setZoneId(ZoneId zoneId) { this.zoneId = zoneId; return this; } - Builder generatedId(String generatedId) { + Builder setGeneratedId(String generatedId) { this.generatedId = generatedId; return this; } - Builder creationTimestamp(Long creationTimestamp) { + Builder setCreationTimestamp(Long creationTimestamp) { this.creationTimestamp = creationTimestamp; return this; } - Builder description(String description) { + Builder setDescription(String description) { this.description = description; return this; } - Builder status(Status status) { + Builder setStatus(Status status) { this.status = status; return this; } - Builder region(RegionId region) { + Builder setRegion(RegionId region) { this.region = region; return this; } - Builder deprecationStatus(DeprecationStatus deprecationStatus) { + Builder setDeprecationStatus(DeprecationStatus deprecationStatus) { this.deprecationStatus = deprecationStatus; return this; } @@ -133,42 +133,90 @@ private Zone(Builder builder) { /** * Returns the zone's identity. */ + @Deprecated public ZoneId zoneId() { + return getZoneId(); + } + + /** + * Returns the zone's identity. + */ + public ZoneId getZoneId() { return zoneId; } /** * Returns the creation timestamp in milliseconds since epoch. */ + @Deprecated public Long creationTimestamp() { + return getCreationTimestamp(); + } + + /** + * Returns the creation timestamp in milliseconds since epoch. + */ + public Long getCreationTimestamp() { return creationTimestamp; } /** * Returns an optional textual description of the zone. */ + @Deprecated public String description() { + return getDescription(); + } + + /** + * Returns an optional textual description of the zone. + */ + public String getDescription() { return description; } /** * Returns the service-generated unique identifier for the zone. */ + @Deprecated public String generatedId() { + return getGeneratedId(); + } + + /** + * Returns the service-generated unique identifier for the zone. + */ + public String getGeneratedId() { return generatedId; } /** * Returns the status of the zone. */ + @Deprecated public Status status() { + return getStatus(); + } + + /** + * Returns the status of the zone. + */ + public Status getStatus() { return status; } /** * Returns the identity of the region that hosts the zone. */ + @Deprecated public RegionId region() { + return getRegion(); + } + + /** + * Returns the identity of the region that hosts the zone. + */ + public RegionId getRegion() { return region; } @@ -177,7 +225,17 @@ public RegionId region() { * {@link DeprecationStatus.Status#DELETED} or {@link DeprecationStatus.Status#OBSOLETE} the zone * should not be used. Returns {@code null} if the zone is not deprecated. */ + @Deprecated public DeprecationStatus deprecationStatus() { + return getDeprecationStatus(); + } + + /** + * Returns the deprecation status of the zone. If {@link DeprecationStatus#status()} is either + * {@link DeprecationStatus.Status#DELETED} or {@link DeprecationStatus.Status#OBSOLETE} the zone + * should not be used. Returns {@code null} if the zone is not deprecated. + */ + public DeprecationStatus getDeprecationStatus() { return deprecationStatus; } @@ -216,14 +274,14 @@ com.google.api.services.compute.model.Zone toPb() { if (creationTimestamp != null) { zonePb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp)); } - zonePb.setName(zoneId.zone()); + zonePb.setName(zoneId.getZone()); zonePb.setDescription(description); - zonePb.setSelfLink(zoneId.selfLink()); + zonePb.setSelfLink(zoneId.getSelfLink()); if (status != null) { zonePb.setStatus(status.name()); } if (region != null) { - zonePb.setRegion(region.selfLink()); + zonePb.setRegion(region.getSelfLink()); } if (deprecationStatus != null) { zonePb.setDeprecated(deprecationStatus.toPb()); @@ -237,22 +295,22 @@ static Builder builder() { static Zone fromPb(com.google.api.services.compute.model.Zone zonePb) { Builder builder = builder(); - builder.zoneId(ZoneId.fromUrl(zonePb.getSelfLink())); + builder.setZoneId(ZoneId.fromUrl(zonePb.getSelfLink())); if (zonePb.getId() != null) { - builder.generatedId(zonePb.getId().toString()); + builder.setGeneratedId(zonePb.getId().toString()); } if (zonePb.getCreationTimestamp() != null) { - builder.creationTimestamp(TIMESTAMP_FORMATTER.parseMillis(zonePb.getCreationTimestamp())); + builder.setCreationTimestamp(TIMESTAMP_FORMATTER.parseMillis(zonePb.getCreationTimestamp())); } - builder.description(zonePb.getDescription()); + builder.setDescription(zonePb.getDescription()); if (zonePb.getStatus() != null) { - builder.status(Status.valueOf(zonePb.getStatus())); + builder.setStatus(Status.valueOf(zonePb.getStatus())); } if (zonePb.getRegion() != null) { - builder.region(RegionId.fromUrl(zonePb.getRegion())); + builder.setRegion(RegionId.fromUrl(zonePb.getRegion())); } if (zonePb.getDeprecated() != null) { - builder.deprecationStatus( + builder.setDeprecationStatus( DeprecationStatus.fromPb(zonePb.getDeprecated(), ZoneId.FROM_URL_FUNCTION)); } return builder.build(); diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/ZoneId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/ZoneId.java index 1a1e2bf207be..b95bcbce766d 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/ZoneId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/ZoneId.java @@ -39,7 +39,7 @@ public ZoneId apply(String pb) { static final Function TO_URL_FUNCTION = new Function() { @Override public String apply(ZoneId zoneId) { - return zoneId.selfLink(); + return zoneId.getSelfLink(); } }; @@ -57,13 +57,27 @@ private ZoneId(String project, String zone) { /** * Returns the name of the zone. */ + @Deprecated public final String zone() { + return getZone(); + } + + /** + * Returns the name of the zone. + */ + public String getZone() { return zone; } @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/zones/" + zone; + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/zones/" + zone; } @Override @@ -90,7 +104,7 @@ public boolean equals(Object obj) { @Override ZoneId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } return ZoneId.of(projectId, zone); diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/ZoneOperationId.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/ZoneOperationId.java index 1403773d2d99..34a5c6624be5 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/ZoneOperationId.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/ZoneOperationId.java @@ -41,27 +41,55 @@ private ZoneOperationId(String project, String zone, String operation) { } @Override + @Deprecated public Type type() { + return getType(); + } + + @Override + public Type getType() { return Type.ZONE; } /** * Returns the name of the zone this operation belongs to. */ + @Deprecated public String zone() { + return getZone(); + } + + /** + * Returns the name of the zone this operation belongs to. + */ + public String getZone() { return zone; } /** * Returns the identity of the zone this address belongs to. */ + @Deprecated public ZoneId zoneId() { - return ZoneId.of(project(), zone); + return getZoneId(); + } + + /** + * Returns the identity of the zone this address belongs to. + */ + public ZoneId getZoneId() { + return ZoneId.of(getProject(), zone); } @Override + @Deprecated public String selfLink() { - return super.selfLink() + "/zones/" + zone + "/operations/" + operation(); + return getSelfLink(); + } + + @Override + public String getSelfLink() { + return super.getSelfLink() + "/zones/" + zone + "/operations/" + getOperation(); } @Override @@ -88,17 +116,17 @@ public boolean equals(Object obj) { @Override ZoneOperationId setProjectId(String projectId) { - if (project() != null) { + if (getProject() != null) { return this; } - return ZoneOperationId.of(projectId, zone, operation()); + return ZoneOperationId.of(projectId, zone, getOperation()); } /** * Returns a zone operation identity given the zone identity and the operation name. */ public static ZoneOperationId of(ZoneId zoneId, String operation) { - return new ZoneOperationId(zoneId.project(), zoneId.zone(), operation); + return new ZoneOperationId(zoneId.getProject(), zoneId.getZone(), operation); } /** diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/package-info.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/package-info.java index f602b5d8831f..51c9babdaeb6 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/package-info.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/package-info.java @@ -29,7 +29,7 @@ * String snapshotName = "disk-name-snapshot"; * Operation operation = disk.createSnapshot(snapshotName); * operation = operation.waitFor(); - * if (operation.errors() == null) { + * if (operation.getErrors() == null) { * // use snapshot * Snapshot snapshot = compute.getSnapshot(snapshotName); * } @@ -49,7 +49,7 @@ * Operation operation = * compute.create(InstanceInfo.of(instanceId, machineTypeId, attachedDisk, networkInterface)); * operation = operation.waitFor(); - * if (operation.errors() == null) { + * if (operation.getErrors() == null) { * // use instance * Instance instance = compute.getInstance(instanceId); * }} diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/testing/RemoteComputeHelper.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/testing/RemoteComputeHelper.java index eb443a25af28..92937c824ba0 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/testing/RemoteComputeHelper.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/testing/RemoteComputeHelper.java @@ -48,7 +48,15 @@ private RemoteComputeHelper(ComputeOptions options) { /** * Returns a {@link ComputeOptions} object to be used for testing. */ + @Deprecated public ComputeOptions options() { + return getOptions(); + } + + /** + * Returns a {@link ComputeOptions} object to be used for testing. + */ + public ComputeOptions getOptions() { return options; } diff --git a/google-cloud-compute/src/main/java/com/google/cloud/compute/testing/package-info.java b/google-cloud-compute/src/main/java/com/google/cloud/compute/testing/package-info.java index d30df3b1fd11..897999dfcce5 100644 --- a/google-cloud-compute/src/main/java/com/google/cloud/compute/testing/package-info.java +++ b/google-cloud-compute/src/main/java/com/google/cloud/compute/testing/package-info.java @@ -22,7 +22,7 @@ *

Before the test: *

 {@code
  * RemoteComputeHelper computeHelper = RemoteComputeHelper.create();
- * Compute compute = computeHelper.options().service();
+ * Compute compute = computeHelper.getOptions().service();
  * } 
* * @see diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/AddressIdTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/AddressIdTest.java index 361012f3a30f..ae0ec0bf3900 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/AddressIdTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/AddressIdTest.java @@ -41,6 +41,31 @@ public class AddressIdTest { @Test public void testOf() { + GlobalAddressId addressId = GlobalAddressId.of(PROJECT, NAME); + assertEquals(PROJECT, addressId.getProject()); + assertEquals(NAME, addressId.getAddress()); + assertEquals(GLOBAL_URL, addressId.getSelfLink()); + addressId = GlobalAddressId.of(NAME); + assertNull(addressId.getProject()); + assertEquals(NAME, addressId.getAddress()); + RegionAddressId regionAddressId = RegionAddressId.of(PROJECT, REGION, NAME); + assertEquals(PROJECT, regionAddressId.getProject()); + assertEquals(REGION, regionAddressId.getRegion()); + assertEquals(NAME, regionAddressId.getAddress()); + assertEquals(REGION_URL, regionAddressId.getSelfLink()); + regionAddressId = RegionAddressId.of(RegionId.of(PROJECT, REGION), NAME); + assertEquals(PROJECT, regionAddressId.getProject()); + assertEquals(REGION, regionAddressId.getRegion()); + assertEquals(NAME, regionAddressId.getAddress()); + assertEquals(REGION_URL, regionAddressId.getSelfLink()); + regionAddressId = RegionAddressId.of(REGION, NAME); + assertNull(regionAddressId.getProject()); + assertEquals(REGION, regionAddressId.getRegion()); + assertEquals(NAME, regionAddressId.getAddress()); + } + + @Test + public void testOfDeprecated() { GlobalAddressId addressId = GlobalAddressId.of(PROJECT, NAME); assertEquals(PROJECT, addressId.project()); assertEquals(NAME, addressId.address()); @@ -67,7 +92,7 @@ public void testOf() { @Test public void testToAndFromUrlGlobal() { GlobalAddressId addressId = GlobalAddressId.of(PROJECT, NAME); - compareAddressId(addressId, GlobalAddressId.fromUrl(addressId.selfLink())); + compareAddressId(addressId, GlobalAddressId.fromUrl(addressId.getSelfLink())); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("notMatchingUrl is not a valid global address URL"); GlobalAddressId.fromUrl("notMatchingUrl"); @@ -76,7 +101,7 @@ public void testToAndFromUrlGlobal() { @Test public void testToAndFromUrlRegion() { RegionAddressId regionAddressId = RegionAddressId.of(PROJECT, REGION, NAME); - compareRegionAddressId(regionAddressId, RegionAddressId.fromUrl(regionAddressId.selfLink())); + compareRegionAddressId(regionAddressId, RegionAddressId.fromUrl(regionAddressId.getSelfLink())); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("notMatchingUrl is not a valid region address URL"); RegionAddressId.fromUrl("notMatchingUrl"); @@ -94,26 +119,26 @@ public void testSetProjectId() { @Test public void testMatchesUrl() { - assertTrue(GlobalAddressId.matchesUrl(GlobalAddressId.of(PROJECT, NAME).selfLink())); + assertTrue(GlobalAddressId.matchesUrl(GlobalAddressId.of(PROJECT, NAME).getSelfLink())); assertFalse(GlobalAddressId.matchesUrl("notMatchingUrl")); - assertTrue(RegionAddressId.matchesUrl(RegionAddressId.of(PROJECT, REGION, NAME).selfLink())); + assertTrue(RegionAddressId.matchesUrl(RegionAddressId.of(PROJECT, REGION, NAME).getSelfLink())); assertFalse(RegionAddressId.matchesUrl("notMatchingUrl")); } private void compareAddressId(GlobalAddressId expected, GlobalAddressId value) { assertEquals(expected, value); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.address(), expected.address()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getAddress(), expected.getAddress()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } private void compareRegionAddressId(RegionAddressId expected, RegionAddressId value) { assertEquals(expected, value); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.region(), expected.region()); - assertEquals(expected.address(), expected.address()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getRegion(), expected.getRegion()); + assertEquals(expected.getAddress(), expected.getAddress()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/AddressInfoTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/AddressInfoTest.java index 1e69608c8d40..47ac9917b6c4 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/AddressInfoTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/AddressInfoTest.java @@ -19,9 +19,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import com.google.cloud.compute.AddressInfo.GlobalForwardingUsage; +import com.google.cloud.compute.AddressInfo.RegionForwardingUsage; import com.google.common.collect.ImmutableList; -import org.junit.Assert; import org.junit.Test; import java.util.List; @@ -44,72 +45,112 @@ public class AddressInfoTest { RegionForwardingRuleId.of("project", "region", "forwardingRule2")); private static final AddressInfo.InstanceUsage INSTANCE_USAGE = new AddressInfo.InstanceUsage(InstanceId.of("project", "zone", "instance1")); - private static final AddressInfo.GlobalForwardingUsage GLOBAL_FORWARDING_USAGE = - new AddressInfo.GlobalForwardingUsage(GLOBAL_FORWARDING_RULES); - private static final AddressInfo.RegionForwardingUsage REGION_FORWARDING_USAGE = - new AddressInfo.RegionForwardingUsage(REGION_FORWARDING_RULES); - private static final AddressInfo INSTANCE_ADDRESS_INFO = AddressInfo.builder(REGION_ADDRESS_ID) - .address(ADDRESS) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .generatedId(GENERATED_ID) - .status(STATUS) - .usage(INSTANCE_USAGE) + private static final GlobalForwardingUsage GLOBAL_FORWARDING_USAGE = + new GlobalForwardingUsage(GLOBAL_FORWARDING_RULES); + private static final RegionForwardingUsage REGION_FORWARDING_USAGE = + new RegionForwardingUsage(REGION_FORWARDING_RULES); + private static final AddressInfo INSTANCE_ADDRESS_INFO = AddressInfo.newBuilder(REGION_ADDRESS_ID) + .setAddress(ADDRESS) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setGeneratedId(GENERATED_ID) + .setStatus(STATUS) + .setUsage(INSTANCE_USAGE) .build(); private static final AddressInfo GLOBAL_FORWARDING_ADDRESS_INFO = - AddressInfo.builder(GLOBAL_ADDRESS_ID) - .address(ADDRESS) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .generatedId(GENERATED_ID) - .status(STATUS) - .usage(GLOBAL_FORWARDING_USAGE) + AddressInfo.newBuilder(GLOBAL_ADDRESS_ID) + .setAddress(ADDRESS) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setGeneratedId(GENERATED_ID) + .setStatus(STATUS) + .setUsage(GLOBAL_FORWARDING_USAGE) .build(); private static final AddressInfo REGION_FORWARDING_ADDRESS_INFO = - AddressInfo.builder(REGION_ADDRESS_ID) + AddressInfo.newBuilder(REGION_ADDRESS_ID) + .setAddress(ADDRESS) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setGeneratedId(GENERATED_ID) + .setStatus(STATUS) + .setUsage(REGION_FORWARDING_USAGE) + .build(); + private static final AddressInfo DEPRECATED_ADDRESS_INFO = + AddressInfo.newBuilder(REGION_ADDRESS_ID) .address(ADDRESS) - .creationTimestamp(CREATION_TIMESTAMP) + .setCreationTimestamp(CREATION_TIMESTAMP) .description(DESCRIPTION) - .generatedId(GENERATED_ID) - .status(STATUS) - .usage(REGION_FORWARDING_USAGE) + .setGeneratedId(GENERATED_ID) + .setStatus(STATUS) + .setUsage(INSTANCE_USAGE) .build(); @Test public void testToBuilder() { compareAddressInfo(INSTANCE_ADDRESS_INFO, INSTANCE_ADDRESS_INFO.toBuilder().build()); AddressInfo addressInfo = INSTANCE_ADDRESS_INFO.toBuilder() - .address("192.168.1.2") - .description("description2") + .setAddress("192.168.1.2") + .setDescription("description2") .build(); - assertEquals("description2", addressInfo.description()); - assertEquals("192.168.1.2", addressInfo.address()); + assertEquals("description2", addressInfo.getDescription()); + assertEquals("192.168.1.2", addressInfo.getAddress()); addressInfo = addressInfo.toBuilder() - .address("192.168.1.1") - .description("description") + .setAddress("192.168.1.1") + .setDescription("description") .build(); compareAddressInfo(INSTANCE_ADDRESS_INFO, addressInfo); } @Test public void testToBuilderIncomplete() { - AddressInfo addressInfo = AddressInfo.builder(GLOBAL_ADDRESS_ID).build(); + AddressInfo addressInfo = AddressInfo.newBuilder(GLOBAL_ADDRESS_ID).build(); assertEquals(addressInfo, addressInfo.toBuilder().build()); - addressInfo = AddressInfo.builder(REGION_ADDRESS_ID).build(); + addressInfo = AddressInfo.newBuilder(REGION_ADDRESS_ID).build(); assertEquals(addressInfo, addressInfo.toBuilder().build()); } @Test public void testBuilder() { - assertEquals(ADDRESS, INSTANCE_ADDRESS_INFO.address()); - assertEquals(CREATION_TIMESTAMP, INSTANCE_ADDRESS_INFO.creationTimestamp()); - assertEquals(DESCRIPTION, INSTANCE_ADDRESS_INFO.description()); - assertEquals(GENERATED_ID, INSTANCE_ADDRESS_INFO.generatedId()); - assertEquals(REGION_ADDRESS_ID, INSTANCE_ADDRESS_INFO.addressId()); - assertEquals(STATUS, INSTANCE_ADDRESS_INFO.status()); - assertEquals(INSTANCE_USAGE, INSTANCE_ADDRESS_INFO.usage()); - Assert.assertEquals(INSTANCE_USAGE.instance(), - INSTANCE_ADDRESS_INFO.usage().instance()); + assertEquals(ADDRESS, INSTANCE_ADDRESS_INFO.getAddress()); + assertEquals(CREATION_TIMESTAMP, INSTANCE_ADDRESS_INFO.getCreationTimestamp()); + assertEquals(DESCRIPTION, INSTANCE_ADDRESS_INFO.getDescription()); + assertEquals(GENERATED_ID, INSTANCE_ADDRESS_INFO.getGeneratedId()); + assertEquals(REGION_ADDRESS_ID, INSTANCE_ADDRESS_INFO.getAddressId()); + assertEquals(STATUS, INSTANCE_ADDRESS_INFO.getStatus()); + assertEquals(INSTANCE_USAGE, INSTANCE_ADDRESS_INFO.getUsage()); + assertEquals(INSTANCE_USAGE.getInstance(), + INSTANCE_ADDRESS_INFO.getUsage().getInstance()); + assertEquals(ADDRESS, REGION_FORWARDING_ADDRESS_INFO.getAddress()); + assertEquals(CREATION_TIMESTAMP, REGION_FORWARDING_ADDRESS_INFO.getCreationTimestamp()); + assertEquals(DESCRIPTION, REGION_FORWARDING_ADDRESS_INFO.getDescription()); + assertEquals(GENERATED_ID, REGION_FORWARDING_ADDRESS_INFO.getGeneratedId()); + assertEquals(REGION_ADDRESS_ID, REGION_FORWARDING_ADDRESS_INFO.getAddressId()); + assertEquals(STATUS, REGION_FORWARDING_ADDRESS_INFO.getStatus()); + assertEquals(REGION_FORWARDING_USAGE, REGION_FORWARDING_ADDRESS_INFO.getUsage()); + assertEquals(REGION_FORWARDING_RULES, + REGION_FORWARDING_ADDRESS_INFO.getUsage().getForwardingRules()); + assertEquals(ADDRESS, GLOBAL_FORWARDING_ADDRESS_INFO.getAddress()); + assertEquals(CREATION_TIMESTAMP, GLOBAL_FORWARDING_ADDRESS_INFO.getCreationTimestamp()); + assertEquals(DESCRIPTION, GLOBAL_FORWARDING_ADDRESS_INFO.getDescription()); + assertEquals(GENERATED_ID, GLOBAL_FORWARDING_ADDRESS_INFO.getGeneratedId()); + assertEquals(GLOBAL_ADDRESS_ID, GLOBAL_FORWARDING_ADDRESS_INFO.getAddressId()); + assertEquals(STATUS, GLOBAL_FORWARDING_ADDRESS_INFO.getStatus()); + assertEquals(GLOBAL_FORWARDING_USAGE, GLOBAL_FORWARDING_ADDRESS_INFO.getUsage()); + assertEquals(GLOBAL_FORWARDING_RULES, + GLOBAL_FORWARDING_ADDRESS_INFO.getUsage().getForwardingRules()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(ADDRESS, DEPRECATED_ADDRESS_INFO.address()); + assertEquals(CREATION_TIMESTAMP, DEPRECATED_ADDRESS_INFO.creationTimestamp()); + assertEquals(DESCRIPTION, DEPRECATED_ADDRESS_INFO.description()); + assertEquals(GENERATED_ID, DEPRECATED_ADDRESS_INFO.generatedId()); + assertEquals(REGION_ADDRESS_ID, DEPRECATED_ADDRESS_INFO.addressId()); + assertEquals(STATUS, DEPRECATED_ADDRESS_INFO.status()); + assertEquals(INSTANCE_USAGE, DEPRECATED_ADDRESS_INFO.usage()); + assertEquals(INSTANCE_USAGE.instance(), + DEPRECATED_ADDRESS_INFO.usage().instance()); assertEquals(ADDRESS, REGION_FORWARDING_ADDRESS_INFO.address()); assertEquals(CREATION_TIMESTAMP, REGION_FORWARDING_ADDRESS_INFO.creationTimestamp()); assertEquals(DESCRIPTION, REGION_FORWARDING_ADDRESS_INFO.description()); @@ -117,8 +158,8 @@ public void testBuilder() { assertEquals(REGION_ADDRESS_ID, REGION_FORWARDING_ADDRESS_INFO.addressId()); assertEquals(STATUS, REGION_FORWARDING_ADDRESS_INFO.status()); assertEquals(REGION_FORWARDING_USAGE, REGION_FORWARDING_ADDRESS_INFO.usage()); - Assert.assertEquals(REGION_FORWARDING_RULES, - REGION_FORWARDING_ADDRESS_INFO.usage().forwardingRules()); + assertEquals(REGION_FORWARDING_RULES, + REGION_FORWARDING_ADDRESS_INFO.usage().forwardingRules()); assertEquals(ADDRESS, GLOBAL_FORWARDING_ADDRESS_INFO.address()); assertEquals(CREATION_TIMESTAMP, GLOBAL_FORWARDING_ADDRESS_INFO.creationTimestamp()); assertEquals(DESCRIPTION, GLOBAL_FORWARDING_ADDRESS_INFO.description()); @@ -126,44 +167,44 @@ public void testBuilder() { assertEquals(GLOBAL_ADDRESS_ID, GLOBAL_FORWARDING_ADDRESS_INFO.addressId()); assertEquals(STATUS, GLOBAL_FORWARDING_ADDRESS_INFO.status()); assertEquals(GLOBAL_FORWARDING_USAGE, GLOBAL_FORWARDING_ADDRESS_INFO.usage()); - Assert.assertEquals(GLOBAL_FORWARDING_RULES, - GLOBAL_FORWARDING_ADDRESS_INFO.usage().forwardingRules()); + assertEquals(GLOBAL_FORWARDING_RULES, + GLOBAL_FORWARDING_ADDRESS_INFO.usage().forwardingRules()); } @Test public void testOf() { AddressInfo addressInfo = AddressInfo.of("address"); - assertEquals(GlobalAddressId.of("address"), addressInfo.addressId()); - assertNull(addressInfo.address()); - assertNull(addressInfo.creationTimestamp()); - assertNull(addressInfo.description()); - assertNull(addressInfo.generatedId()); - assertNull(addressInfo.status()); - assertNull(addressInfo.usage()); + assertEquals(GlobalAddressId.of("address"), addressInfo.getAddressId()); + assertNull(addressInfo.getAddress()); + assertNull(addressInfo.getCreationTimestamp()); + assertNull(addressInfo.getDescription()); + assertNull(addressInfo.getGeneratedId()); + assertNull(addressInfo.getStatus()); + assertNull(addressInfo.getUsage()); addressInfo = AddressInfo.of(GLOBAL_ADDRESS_ID); - assertEquals(GLOBAL_ADDRESS_ID, addressInfo.addressId()); - assertNull(addressInfo.address()); - assertNull(addressInfo.creationTimestamp()); - assertNull(addressInfo.description()); - assertNull(addressInfo.generatedId()); - assertNull(addressInfo.status()); - assertNull(addressInfo.usage()); + assertEquals(GLOBAL_ADDRESS_ID, addressInfo.getAddressId()); + assertNull(addressInfo.getAddress()); + assertNull(addressInfo.getCreationTimestamp()); + assertNull(addressInfo.getDescription()); + assertNull(addressInfo.getGeneratedId()); + assertNull(addressInfo.getStatus()); + assertNull(addressInfo.getUsage()); addressInfo = AddressInfo.of("region", "address"); - assertEquals(RegionAddressId.of("region", "address"), addressInfo.addressId()); - assertNull(addressInfo.address()); - assertNull(addressInfo.creationTimestamp()); - assertNull(addressInfo.description()); - assertNull(addressInfo.generatedId()); - assertNull(addressInfo.status()); - assertNull(addressInfo.usage()); + assertEquals(RegionAddressId.of("region", "address"), addressInfo.getAddressId()); + assertNull(addressInfo.getAddress()); + assertNull(addressInfo.getCreationTimestamp()); + assertNull(addressInfo.getDescription()); + assertNull(addressInfo.getGeneratedId()); + assertNull(addressInfo.getStatus()); + assertNull(addressInfo.getUsage()); addressInfo = AddressInfo.of(RegionId.of("region"), "address"); - assertEquals(RegionAddressId.of("region", "address"), addressInfo.addressId()); - assertNull(addressInfo.address()); - assertNull(addressInfo.creationTimestamp()); - assertNull(addressInfo.description()); - assertNull(addressInfo.generatedId()); - assertNull(addressInfo.status()); - assertNull(addressInfo.usage()); + assertEquals(RegionAddressId.of("region", "address"), addressInfo.getAddressId()); + assertNull(addressInfo.getAddress()); + assertNull(addressInfo.getCreationTimestamp()); + assertNull(addressInfo.getDescription()); + assertNull(addressInfo.getGeneratedId()); + assertNull(addressInfo.getStatus()); + assertNull(addressInfo.getUsage()); } @Test @@ -173,27 +214,27 @@ public void testToPbAndFromPb() { AddressInfo.fromPb(REGION_FORWARDING_ADDRESS_INFO.toPb())); compareAddressInfo(GLOBAL_FORWARDING_ADDRESS_INFO, AddressInfo.fromPb(GLOBAL_FORWARDING_ADDRESS_INFO.toPb())); - AddressInfo addressInfo = AddressInfo.builder(GLOBAL_ADDRESS_ID).build(); + AddressInfo addressInfo = AddressInfo.newBuilder(GLOBAL_ADDRESS_ID).build(); compareAddressInfo(addressInfo, AddressInfo.fromPb(addressInfo.toPb())); } @Test public void testSetProjectId() { AddressInfo addressInfo = GLOBAL_FORWARDING_ADDRESS_INFO.toBuilder() - .addressId(GlobalAddressId.of(GLOBAL_ADDRESS_ID.address())) + .setAddressId(GlobalAddressId.of(GLOBAL_ADDRESS_ID.getAddress())) .build(); compareAddressInfo(GLOBAL_FORWARDING_ADDRESS_INFO, addressInfo.setProjectId("project")); } private void compareAddressInfo(AddressInfo expected, AddressInfo value) { assertEquals(expected, value); - assertEquals(expected.address(), value.address()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.addressId(), value.addressId()); - assertEquals(expected.usage(), value.usage()); - assertEquals(expected.status(), value.status()); + assertEquals(expected.getAddress(), value.getAddress()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getAddressId(), value.getAddressId()); + assertEquals(expected.getUsage(), value.getUsage()); + assertEquals(expected.getStatus(), value.getStatus()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/AddressTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/AddressTest.java index 914d7e510b3a..aca5721c6306 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/AddressTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/AddressTest.java @@ -69,40 +69,40 @@ private void initializeExpectedAddress(int optionsCalls) { expect(serviceMockReturnsOptions.options()).andReturn(mockOptions).times(optionsCalls); replay(serviceMockReturnsOptions); instanceAddress = new Address.Builder(serviceMockReturnsOptions, REGION_ADDRESS_ID) - .address(ADDRESS) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .generatedId(GENERATED_ID) - .status(STATUS) - .usage(INSTANCE_USAGE) + .setAddress(ADDRESS) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setGeneratedId(GENERATED_ID) + .setStatus(STATUS) + .setUsage(INSTANCE_USAGE) .build(); globalForwardingAddress = new Address.Builder(serviceMockReturnsOptions, GLOBAL_ADDRESS_ID) - .address(ADDRESS) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .generatedId(GENERATED_ID) - .status(STATUS) - .usage(GLOBAL_FORWARDING_USAGE) + .setAddress(ADDRESS) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setGeneratedId(GENERATED_ID) + .setStatus(STATUS) + .setUsage(GLOBAL_FORWARDING_USAGE) .build(); regionForwardingAddress = new Address.Builder(serviceMockReturnsOptions, REGION_ADDRESS_ID) - .address(ADDRESS) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .generatedId(GENERATED_ID) - .status(STATUS) - .usage(REGION_FORWARDING_USAGE) + .setAddress(ADDRESS) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setGeneratedId(GENERATED_ID) + .setStatus(STATUS) + .setUsage(REGION_FORWARDING_USAGE) .build(); compute = createStrictMock(Compute.class); } private void initializeAddress() { address = new Address.Builder(compute, REGION_ADDRESS_ID) - .address(ADDRESS) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .generatedId(GENERATED_ID) - .status(STATUS) - .usage(REGION_FORWARDING_USAGE) + .setAddress(ADDRESS) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setGeneratedId(GENERATED_ID) + .setStatus(STATUS) + .setUsage(REGION_FORWARDING_USAGE) .build(); } @@ -113,6 +113,64 @@ public void tearDown() throws Exception { @Test public void testBuilder() { + initializeExpectedAddress(6); + assertEquals(ADDRESS, instanceAddress.getAddress()); + assertEquals(CREATION_TIMESTAMP, instanceAddress.getCreationTimestamp()); + assertEquals(DESCRIPTION, instanceAddress.getDescription()); + assertEquals(GENERATED_ID, instanceAddress.getGeneratedId()); + assertEquals(REGION_ADDRESS_ID, instanceAddress.getAddressId()); + assertEquals(STATUS, instanceAddress.getStatus()); + assertEquals(INSTANCE_USAGE, instanceAddress.getUsage()); + assertSame(serviceMockReturnsOptions, instanceAddress.getCompute()); + assertEquals(ADDRESS, regionForwardingAddress.getAddress()); + assertEquals(CREATION_TIMESTAMP, regionForwardingAddress.getCreationTimestamp()); + assertEquals(DESCRIPTION, regionForwardingAddress.getDescription()); + assertEquals(GENERATED_ID, regionForwardingAddress.getGeneratedId()); + assertEquals(REGION_ADDRESS_ID, regionForwardingAddress.getAddressId()); + assertEquals(STATUS, regionForwardingAddress.getStatus()); + assertEquals(REGION_FORWARDING_USAGE, regionForwardingAddress.getUsage()); + assertSame(serviceMockReturnsOptions, regionForwardingAddress.getCompute()); + assertEquals(ADDRESS, globalForwardingAddress.getAddress()); + assertEquals(CREATION_TIMESTAMP, globalForwardingAddress.getCreationTimestamp()); + assertEquals(DESCRIPTION, globalForwardingAddress.getDescription()); + assertEquals(GENERATED_ID, globalForwardingAddress.getGeneratedId()); + assertEquals(GLOBAL_ADDRESS_ID, globalForwardingAddress.getAddressId()); + assertEquals(STATUS, globalForwardingAddress.getStatus()); + assertEquals(GLOBAL_FORWARDING_USAGE, globalForwardingAddress.getUsage()); + assertSame(serviceMockReturnsOptions, globalForwardingAddress.getCompute()); + Address address = new Address.Builder(serviceMockReturnsOptions, GLOBAL_ADDRESS_ID).build(); + assertEquals(GLOBAL_ADDRESS_ID, address.getAddressId()); + assertSame(serviceMockReturnsOptions, address.getCompute()); + assertNull(address.getAddress()); + assertNull(address.getCreationTimestamp()); + assertNull(address.getDescription()); + assertNull(address.getGeneratedId()); + assertNull(address.getStatus()); + assertNull(address.getUsage()); + address = new Address.Builder(serviceMockReturnsOptions, REGION_ADDRESS_ID).build(); + assertEquals(REGION_ADDRESS_ID, address.getAddressId()); + assertSame(serviceMockReturnsOptions, address.getCompute()); + assertNull(address.getAddress()); + assertNull(address.getCreationTimestamp()); + assertNull(address.getDescription()); + assertNull(address.getGeneratedId()); + assertNull(address.getStatus()); + assertNull(address.getUsage()); + address = new Address.Builder(serviceMockReturnsOptions, REGION_ADDRESS_ID) + .setAddressId(GLOBAL_ADDRESS_ID) + .build(); + assertEquals(GLOBAL_ADDRESS_ID, address.getAddressId()); + assertSame(serviceMockReturnsOptions, address.getCompute()); + assertNull(address.getAddress()); + assertNull(address.getCreationTimestamp()); + assertNull(address.getDescription()); + assertNull(address.getGeneratedId()); + assertNull(address.getStatus()); + assertNull(address.getUsage()); + } + + @Test + public void testBuilderDeprecated() { initializeExpectedAddress(6); assertEquals(ADDRESS, instanceAddress.address()); assertEquals(CREATION_TIMESTAMP, instanceAddress.creationTimestamp()); @@ -175,9 +233,9 @@ public void testToBuilder() { compareAddress(instanceAddress, instanceAddress.toBuilder().build()); compareAddress(globalForwardingAddress, globalForwardingAddress.toBuilder().build()); compareAddress(regionForwardingAddress, regionForwardingAddress.toBuilder().build()); - Address newAddress = instanceAddress.toBuilder().description("newDescription").build(); - assertEquals("newDescription", newAddress.description()); - newAddress = newAddress.toBuilder().description("description").build(); + Address newAddress = instanceAddress.toBuilder().setDescription("newDescription").build(); + assertEquals("newDescription", newAddress.getDescription()); + newAddress = newAddress.toBuilder().setDescription("description").build(); compareAddress(instanceAddress, newAddress); } @@ -201,7 +259,7 @@ public void testDeleteOperation() { initializeExpectedAddress(4); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(GlobalOperationId.of("project", "op")) + .setOperationId(GlobalOperationId.of("project", "op")) .build(); expect(compute.deleteAddress(REGION_ADDRESS_ID)).andReturn(operation); replay(compute); @@ -281,14 +339,14 @@ public void testReloadWithOptions() throws Exception { private void compareAddress(Address expected, Address value) { assertEquals(expected, value); - assertEquals(expected.compute().options(), value.compute().options()); - assertEquals(expected.address(), value.address()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.addressId(), value.addressId()); - assertEquals(expected.usage(), value.usage()); - assertEquals(expected.status(), value.status()); + assertEquals(expected.getCompute().options(), value.getCompute().options()); + assertEquals(expected.getAddress(), value.getAddress()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getAddressId(), value.getAddressId()); + assertEquals(expected.getUsage(), value.getUsage()); + assertEquals(expected.getStatus(), value.getStatus()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/AttachedDiskTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/AttachedDiskTest.java index 6e68e18590c2..9d318d6fc178 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/AttachedDiskTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/AttachedDiskTest.java @@ -47,14 +47,50 @@ public class AttachedDiskTest { private static final PersistentDiskConfiguration.Mode MODE = PersistentDiskConfiguration.Mode.READ_ONLY; private static final PersistentDiskConfiguration PERSISTENT_DISK_CONFIGURATION = + PersistentDiskConfiguration.newBuilder(DISK_ID) + .setBoot(BOOT) + .setAutoDelete(AUTO_DELETE) + .setMode(MODE) + .build(); + private static final ScratchDiskConfiguration SCRATCH_DISK_CONFIGURATION = + ScratchDiskConfiguration.newBuilder(DISK_TYPE_ID).setInterfaceType(INTERFACE_TYPE).build(); + private static final CreateDiskConfiguration CREATE_DISK_CONFIGURATION = + CreateDiskConfiguration.newBuilder(IMAGE_ID) + .setAutoDelete(AUTO_DELETE) + .setDiskName(DISK_NAME) + .setDiskType(DISK_TYPE_ID) + .setDiskSizeGb(DISK_SIZE_GB) + .setSourceImage(IMAGE_ID) + .build(); + private static final List LICENSES = ImmutableList.of( + LicenseId.of("project", "license1"), LicenseId.of("project", "license2")); + private static final AttachedDisk PERSISTENT_DISK = + AttachedDisk.newBuilder(PERSISTENT_DISK_CONFIGURATION) + .setDeviceName(DEVICE_NAME) + .setIndex(INDEX) + .setLicenses(LICENSES) + .build(); + private static final AttachedDisk SCRATCH_DISK = + AttachedDisk.newBuilder(SCRATCH_DISK_CONFIGURATION) + .setDeviceName(DEVICE_NAME) + .setIndex(INDEX) + .setLicenses(LICENSES) + .build(); + private static final AttachedDisk CREATED_DISK = + AttachedDisk.newBuilder(CREATE_DISK_CONFIGURATION) + .setDeviceName(DEVICE_NAME) + .setIndex(INDEX) + .setLicenses(LICENSES) + .build(); + private static final PersistentDiskConfiguration DEPRECATED_PERSISTENT_DISK_CONFIGURATION = PersistentDiskConfiguration.builder(DISK_ID) .boot(BOOT) .autoDelete(AUTO_DELETE) .mode(MODE) .build(); - private static final ScratchDiskConfiguration SCRATCH_DISK_CONFIGURATION = + private static final ScratchDiskConfiguration DEPRECATED_SCRATCH_DISK_CONFIGURATION = ScratchDiskConfiguration.builder(DISK_TYPE_ID).interfaceType(INTERFACE_TYPE).build(); - private static final CreateDiskConfiguration CREATE_DISK_CONFIGURATION = + private static final CreateDiskConfiguration DEPRECATED_CREATE_DISK_CONFIGURATION = CreateDiskConfiguration.builder(IMAGE_ID) .autoDelete(AUTO_DELETE) .diskName(DISK_NAME) @@ -62,25 +98,23 @@ public class AttachedDiskTest { .diskSizeGb(DISK_SIZE_GB) .sourceImage(IMAGE_ID) .build(); - private static final List LICENSES = ImmutableList.of( - LicenseId.of("project", "license1"), LicenseId.of("project", "license2")); - private static final AttachedDisk PERSISTENT_DISK = + private static final AttachedDisk DEPRECATED_PERSISTENT_DISK = AttachedDisk.builder(PERSISTENT_DISK_CONFIGURATION) .deviceName(DEVICE_NAME) .index(INDEX) - .licenses(LICENSES) + .setLicenses(LICENSES) .build(); - private static final AttachedDisk SCRATCH_DISK = + private static final AttachedDisk DEPRECATED_SCRATCH_DISK = AttachedDisk.builder(SCRATCH_DISK_CONFIGURATION) .deviceName(DEVICE_NAME) .index(INDEX) - .licenses(LICENSES) + .setLicenses(LICENSES) .build(); - private static final AttachedDisk CREATED_DISK = + private static final AttachedDisk DEPRECATED_CREATED_DISK = AttachedDisk.builder(CREATE_DISK_CONFIGURATION) .deviceName(DEVICE_NAME) .index(INDEX) - .licenses(LICENSES) + .setLicenses(LICENSES) .build(); @Test @@ -92,21 +126,22 @@ public void testConfigurationToBuilder() { compareCreateDiskConfiguration(CREATE_DISK_CONFIGURATION, CREATE_DISK_CONFIGURATION.toBuilder().build()); PersistentDiskConfiguration persistentDiskConfiguration = - PERSISTENT_DISK_CONFIGURATION.toBuilder().autoDelete(false).build(); + PERSISTENT_DISK_CONFIGURATION.toBuilder().setAutoDelete(false).build(); assertFalse(persistentDiskConfiguration.autoDelete()); persistentDiskConfiguration = - persistentDiskConfiguration.toBuilder().autoDelete(AUTO_DELETE).build(); + persistentDiskConfiguration.toBuilder().setAutoDelete(AUTO_DELETE).build(); assertEquals(PERSISTENT_DISK_CONFIGURATION, persistentDiskConfiguration); ScratchDiskConfiguration scratchDiskConfiguration = - SCRATCH_DISK_CONFIGURATION.toBuilder().interfaceType(InterfaceType.SCSI).build(); - assertEquals(InterfaceType.SCSI, scratchDiskConfiguration.interfaceType()); + SCRATCH_DISK_CONFIGURATION.toBuilder().setInterfaceType(InterfaceType.SCSI).build(); + assertEquals(InterfaceType.SCSI, scratchDiskConfiguration.getInterfaceType()); scratchDiskConfiguration = - scratchDiskConfiguration.toBuilder().interfaceType(INTERFACE_TYPE).build(); + scratchDiskConfiguration.toBuilder().setInterfaceType(INTERFACE_TYPE).build(); assertEquals(SCRATCH_DISK_CONFIGURATION, scratchDiskConfiguration); CreateDiskConfiguration createDiskConfiguration = - CREATE_DISK_CONFIGURATION.toBuilder().autoDelete(false).build(); + CREATE_DISK_CONFIGURATION.toBuilder().setAutoDelete(false).build(); assertFalse(createDiskConfiguration.autoDelete()); - createDiskConfiguration = createDiskConfiguration.toBuilder().autoDelete(AUTO_DELETE).build(); + createDiskConfiguration = + createDiskConfiguration.toBuilder().setAutoDelete(AUTO_DELETE).build(); assertEquals(CREATE_DISK_CONFIGURATION, createDiskConfiguration); } @@ -131,9 +166,9 @@ public void testToBuilder() { compareAttachedDisk(PERSISTENT_DISK, PERSISTENT_DISK.toBuilder().build()); compareAttachedDisk(SCRATCH_DISK, SCRATCH_DISK.toBuilder().build()); compareAttachedDisk(CREATED_DISK, CREATED_DISK.toBuilder().build()); - AttachedDisk attachedDisk = PERSISTENT_DISK.toBuilder().deviceName("newDeviceName").build(); - assertEquals("newDeviceName", attachedDisk.deviceName()); - attachedDisk = attachedDisk.toBuilder().deviceName(DEVICE_NAME).build(); + AttachedDisk attachedDisk = PERSISTENT_DISK.toBuilder().setDeviceName("newDeviceName").build(); + assertEquals("newDeviceName", attachedDisk.getDeviceName()); + attachedDisk = attachedDisk.toBuilder().setDeviceName(DEVICE_NAME).build(); compareAttachedDisk(PERSISTENT_DISK, attachedDisk); } @@ -151,103 +186,145 @@ public void testToBuilderIncomplete() { public void testConfigurationBuilder() { assertTrue(CREATE_DISK_CONFIGURATION.boot()); assertEquals(AUTO_DELETE, CREATE_DISK_CONFIGURATION.autoDelete()); - assertNull(CREATE_DISK_CONFIGURATION.interfaceType()); - assertEquals(Type.PERSISTENT, CREATE_DISK_CONFIGURATION.type()); - assertEquals(IMAGE_ID, CREATE_DISK_CONFIGURATION.sourceImage()); - assertEquals(DISK_NAME, CREATE_DISK_CONFIGURATION.diskName()); - assertEquals(DISK_TYPE_ID, CREATE_DISK_CONFIGURATION.diskType()); - assertEquals(DISK_SIZE_GB, CREATE_DISK_CONFIGURATION.diskSizeGb()); - assertEquals(IMAGE_ID, CREATE_DISK_CONFIGURATION.sourceImage()); + assertNull(CREATE_DISK_CONFIGURATION.getInterfaceType()); + assertEquals(Type.PERSISTENT, CREATE_DISK_CONFIGURATION.getType()); + assertEquals(IMAGE_ID, CREATE_DISK_CONFIGURATION.getSourceImage()); + assertEquals(DISK_NAME, CREATE_DISK_CONFIGURATION.getDiskName()); + assertEquals(DISK_TYPE_ID, CREATE_DISK_CONFIGURATION.getDiskType()); + assertEquals(DISK_SIZE_GB, CREATE_DISK_CONFIGURATION.getDiskSizeGb()); + assertEquals(IMAGE_ID, CREATE_DISK_CONFIGURATION.getSourceImage()); assertEquals(BOOT, PERSISTENT_DISK_CONFIGURATION.boot()); assertEquals(AUTO_DELETE, PERSISTENT_DISK_CONFIGURATION.autoDelete()); - assertNull(PERSISTENT_DISK_CONFIGURATION.interfaceType()); - assertEquals(Type.PERSISTENT, PERSISTENT_DISK_CONFIGURATION.type()); - assertEquals(MODE, PERSISTENT_DISK_CONFIGURATION.mode()); - assertEquals(DISK_ID, PERSISTENT_DISK_CONFIGURATION.sourceDisk()); + assertNull(PERSISTENT_DISK_CONFIGURATION.getInterfaceType()); + assertEquals(Type.PERSISTENT, PERSISTENT_DISK_CONFIGURATION.getType()); + assertEquals(MODE, PERSISTENT_DISK_CONFIGURATION.getMode()); + assertEquals(DISK_ID, PERSISTENT_DISK_CONFIGURATION.getSourceDisk()); assertFalse(SCRATCH_DISK_CONFIGURATION.boot()); assertTrue(SCRATCH_DISK_CONFIGURATION.autoDelete()); - assertEquals(INTERFACE_TYPE, SCRATCH_DISK_CONFIGURATION.interfaceType()); - assertEquals(Type.SCRATCH, SCRATCH_DISK_CONFIGURATION.type()); - assertEquals(DISK_TYPE_ID, SCRATCH_DISK_CONFIGURATION.diskType()); + assertEquals(INTERFACE_TYPE, SCRATCH_DISK_CONFIGURATION.getInterfaceType()); + assertEquals(Type.SCRATCH, SCRATCH_DISK_CONFIGURATION.getType()); + assertEquals(DISK_TYPE_ID, SCRATCH_DISK_CONFIGURATION.getDiskType()); + } + + @Test + public void testConfigurationBuilderDeprecated() { + assertTrue(DEPRECATED_CREATE_DISK_CONFIGURATION.boot()); + assertEquals(AUTO_DELETE, DEPRECATED_CREATE_DISK_CONFIGURATION.autoDelete()); + assertNull(DEPRECATED_CREATE_DISK_CONFIGURATION.interfaceType()); + assertEquals(Type.PERSISTENT, DEPRECATED_CREATE_DISK_CONFIGURATION.type()); + assertEquals(IMAGE_ID, DEPRECATED_CREATE_DISK_CONFIGURATION.sourceImage()); + assertEquals(DISK_NAME, DEPRECATED_CREATE_DISK_CONFIGURATION.diskName()); + assertEquals(DISK_TYPE_ID, DEPRECATED_CREATE_DISK_CONFIGURATION.diskType()); + assertEquals(DISK_SIZE_GB, DEPRECATED_CREATE_DISK_CONFIGURATION.diskSizeGb()); + assertEquals(IMAGE_ID, DEPRECATED_CREATE_DISK_CONFIGURATION.sourceImage()); + + assertEquals(BOOT, DEPRECATED_PERSISTENT_DISK_CONFIGURATION.boot()); + assertEquals(AUTO_DELETE, DEPRECATED_PERSISTENT_DISK_CONFIGURATION.autoDelete()); + assertNull(DEPRECATED_PERSISTENT_DISK_CONFIGURATION.interfaceType()); + assertEquals(Type.PERSISTENT, DEPRECATED_PERSISTENT_DISK_CONFIGURATION.type()); + assertEquals(MODE, DEPRECATED_PERSISTENT_DISK_CONFIGURATION.mode()); + assertEquals(DISK_ID, DEPRECATED_PERSISTENT_DISK_CONFIGURATION.sourceDisk()); + + assertFalse(DEPRECATED_SCRATCH_DISK_CONFIGURATION.boot()); + assertTrue(DEPRECATED_SCRATCH_DISK_CONFIGURATION.autoDelete()); + assertEquals(INTERFACE_TYPE, DEPRECATED_SCRATCH_DISK_CONFIGURATION.interfaceType()); + assertEquals(Type.SCRATCH, DEPRECATED_SCRATCH_DISK_CONFIGURATION.type()); + assertEquals(DISK_TYPE_ID, DEPRECATED_SCRATCH_DISK_CONFIGURATION.diskType()); } @Test public void testBuilder() { - assertEquals(PERSISTENT_DISK_CONFIGURATION, PERSISTENT_DISK.configuration()); - assertEquals(DEVICE_NAME, PERSISTENT_DISK.deviceName()); - assertEquals(INDEX, PERSISTENT_DISK.index()); - assertEquals(LICENSES, PERSISTENT_DISK.licenses()); - assertEquals(SCRATCH_DISK_CONFIGURATION, SCRATCH_DISK.configuration()); - assertEquals(DEVICE_NAME, SCRATCH_DISK.deviceName()); - assertEquals(INDEX, SCRATCH_DISK.index()); - assertEquals(LICENSES, SCRATCH_DISK.licenses()); - assertEquals(CREATE_DISK_CONFIGURATION, CREATED_DISK.configuration()); - assertEquals(DEVICE_NAME, CREATED_DISK.deviceName()); - assertEquals(INDEX, CREATED_DISK.index()); - assertEquals(LICENSES, CREATED_DISK.licenses()); + assertEquals(PERSISTENT_DISK_CONFIGURATION, PERSISTENT_DISK.getConfiguration()); + assertEquals(DEVICE_NAME, PERSISTENT_DISK.getDeviceName()); + assertEquals(INDEX, PERSISTENT_DISK.getIndex()); + assertEquals(LICENSES, PERSISTENT_DISK.getLicenses()); + assertEquals(SCRATCH_DISK_CONFIGURATION, SCRATCH_DISK.getConfiguration()); + assertEquals(DEVICE_NAME, SCRATCH_DISK.getDeviceName()); + assertEquals(INDEX, SCRATCH_DISK.getIndex()); + assertEquals(LICENSES, SCRATCH_DISK.getLicenses()); + assertEquals(CREATE_DISK_CONFIGURATION, CREATED_DISK.getConfiguration()); + assertEquals(DEVICE_NAME, CREATED_DISK.getDeviceName()); + assertEquals(INDEX, CREATED_DISK.getIndex()); + assertEquals(LICENSES, CREATED_DISK.getLicenses()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(PERSISTENT_DISK_CONFIGURATION, DEPRECATED_PERSISTENT_DISK.configuration()); + assertEquals(DEVICE_NAME, DEPRECATED_PERSISTENT_DISK.deviceName()); + assertEquals(INDEX, DEPRECATED_PERSISTENT_DISK.index()); + assertEquals(LICENSES, DEPRECATED_PERSISTENT_DISK.licenses()); + assertEquals(SCRATCH_DISK_CONFIGURATION, DEPRECATED_SCRATCH_DISK.configuration()); + assertEquals(DEVICE_NAME, DEPRECATED_SCRATCH_DISK.deviceName()); + assertEquals(INDEX, DEPRECATED_SCRATCH_DISK.index()); + assertEquals(LICENSES, DEPRECATED_SCRATCH_DISK.licenses()); + assertEquals(CREATE_DISK_CONFIGURATION, DEPRECATED_CREATED_DISK.configuration()); + assertEquals(DEVICE_NAME, DEPRECATED_CREATED_DISK.deviceName()); + assertEquals(INDEX, DEPRECATED_CREATED_DISK.index()); + assertEquals(LICENSES, DEPRECATED_CREATED_DISK.licenses()); } @Test public void testConfigurationOf() { PersistentDiskConfiguration persistentConfiguration = PersistentDiskConfiguration.of(DISK_ID); - assertEquals(DISK_ID, persistentConfiguration.sourceDisk()); - assertEquals(Type.PERSISTENT, persistentConfiguration.type()); + assertEquals(DISK_ID, persistentConfiguration.getSourceDisk()); + assertEquals(Type.PERSISTENT, persistentConfiguration.getType()); assertNull(persistentConfiguration.autoDelete()); assertNull(persistentConfiguration.boot()); - assertNull(persistentConfiguration.interfaceType()); + assertNull(persistentConfiguration.getInterfaceType()); ScratchDiskConfiguration scratchDiskConfiguration = ScratchDiskConfiguration.of(DISK_TYPE_ID); - assertEquals(DISK_TYPE_ID, scratchDiskConfiguration.diskType()); - assertNull(scratchDiskConfiguration.interfaceType()); - assertEquals(Type.SCRATCH, scratchDiskConfiguration.type()); + assertEquals(DISK_TYPE_ID, scratchDiskConfiguration.getDiskType()); + assertNull(scratchDiskConfiguration.getInterfaceType()); + assertEquals(Type.SCRATCH, scratchDiskConfiguration.getType()); assertTrue(scratchDiskConfiguration.autoDelete()); assertFalse(scratchDiskConfiguration.boot()); - assertNull(scratchDiskConfiguration.interfaceType()); + assertNull(scratchDiskConfiguration.getInterfaceType()); CreateDiskConfiguration createDiskConfiguration = CreateDiskConfiguration.of(IMAGE_ID); - assertEquals(IMAGE_ID, createDiskConfiguration.sourceImage()); - assertNull(createDiskConfiguration.diskType()); - assertNull(createDiskConfiguration.diskName()); - assertNull(createDiskConfiguration.diskSizeGb()); - assertNull(createDiskConfiguration.interfaceType()); - assertEquals(Type.PERSISTENT, createDiskConfiguration.type()); + assertEquals(IMAGE_ID, createDiskConfiguration.getSourceImage()); + assertNull(createDiskConfiguration.getDiskType()); + assertNull(createDiskConfiguration.getDiskName()); + assertNull(createDiskConfiguration.getDiskSizeGb()); + assertNull(createDiskConfiguration.getInterfaceType()); + assertEquals(Type.PERSISTENT, createDiskConfiguration.getType()); assertNull(createDiskConfiguration.autoDelete()); assertTrue(createDiskConfiguration.boot()); - assertNull(createDiskConfiguration.interfaceType()); + assertNull(createDiskConfiguration.getInterfaceType()); } @Test public void testOf() { AttachedDisk attachedDisk = AttachedDisk.of(DEVICE_NAME, PERSISTENT_DISK_CONFIGURATION); - assertEquals(PERSISTENT_DISK_CONFIGURATION, attachedDisk.configuration()); - assertEquals(DEVICE_NAME, attachedDisk.deviceName()); - assertNull(attachedDisk.index()); - assertNull(attachedDisk.licenses()); + assertEquals(PERSISTENT_DISK_CONFIGURATION, attachedDisk.getConfiguration()); + assertEquals(DEVICE_NAME, attachedDisk.getDeviceName()); + assertNull(attachedDisk.getIndex()); + assertNull(attachedDisk.getLicenses()); attachedDisk = AttachedDisk.of(PERSISTENT_DISK_CONFIGURATION); - assertEquals(PERSISTENT_DISK_CONFIGURATION, attachedDisk.configuration()); - assertNull(attachedDisk.deviceName()); - assertNull(attachedDisk.index()); - assertNull(attachedDisk.licenses()); + assertEquals(PERSISTENT_DISK_CONFIGURATION, attachedDisk.getConfiguration()); + assertNull(attachedDisk.getDeviceName()); + assertNull(attachedDisk.getIndex()); + assertNull(attachedDisk.getLicenses()); attachedDisk = AttachedDisk.of(DEVICE_NAME, SCRATCH_DISK_CONFIGURATION); - assertEquals(SCRATCH_DISK_CONFIGURATION, attachedDisk.configuration()); - assertEquals(DEVICE_NAME, attachedDisk.deviceName()); - assertNull(attachedDisk.index()); - assertNull(attachedDisk.licenses()); + assertEquals(SCRATCH_DISK_CONFIGURATION, attachedDisk.getConfiguration()); + assertEquals(DEVICE_NAME, attachedDisk.getDeviceName()); + assertNull(attachedDisk.getIndex()); + assertNull(attachedDisk.getLicenses()); attachedDisk = AttachedDisk.of(SCRATCH_DISK_CONFIGURATION); - assertEquals(SCRATCH_DISK_CONFIGURATION, attachedDisk.configuration()); - assertNull(attachedDisk.deviceName()); - assertNull(attachedDisk.index()); - assertNull(attachedDisk.licenses()); + assertEquals(SCRATCH_DISK_CONFIGURATION, attachedDisk.getConfiguration()); + assertNull(attachedDisk.getDeviceName()); + assertNull(attachedDisk.getIndex()); + assertNull(attachedDisk.getLicenses()); attachedDisk = AttachedDisk.of(DEVICE_NAME, CREATE_DISK_CONFIGURATION); - assertEquals(CREATE_DISK_CONFIGURATION, attachedDisk.configuration()); - assertEquals(DEVICE_NAME, attachedDisk.deviceName()); - assertNull(attachedDisk.index()); - assertNull(attachedDisk.licenses()); + assertEquals(CREATE_DISK_CONFIGURATION, attachedDisk.getConfiguration()); + assertEquals(DEVICE_NAME, attachedDisk.getDeviceName()); + assertNull(attachedDisk.getIndex()); + assertNull(attachedDisk.getLicenses()); attachedDisk = AttachedDisk.of(CREATE_DISK_CONFIGURATION); - assertEquals(CREATE_DISK_CONFIGURATION, attachedDisk.configuration()); - assertNull(attachedDisk.deviceName()); - assertNull(attachedDisk.index()); - assertNull(attachedDisk.licenses()); + assertEquals(CREATE_DISK_CONFIGURATION, attachedDisk.getConfiguration()); + assertNull(attachedDisk.getDeviceName()); + assertNull(attachedDisk.getIndex()); + assertNull(attachedDisk.getLicenses()); } @Test @@ -313,8 +390,8 @@ public void testConfigurationSetProjectId() { ScratchDiskConfiguration.of(DiskTypeId.of("project", "zone", "diskType")), scratchDiskConfiguration.setProjectId("project")); CreateDiskConfiguration createDiskConfiguration = CREATE_DISK_CONFIGURATION.toBuilder() - .diskType(DiskTypeId.of("zone", "diskType")) - .sourceImage(ImageId.of("image")) + .setDiskType(DiskTypeId.of("zone", "diskType")) + .setSourceImage(ImageId.of("image")) .build(); compareCreateDiskConfiguration(CREATE_DISK_CONFIGURATION, createDiskConfiguration.setProjectId("project")); @@ -342,8 +419,8 @@ public void testSetProjectId() { compareAttachedDisk(AttachedDisk.of(createDiskConfigurationWithProject), AttachedDisk.of(createDiskConfiguration).setProjectId("project")); createDiskConfiguration = CREATE_DISK_CONFIGURATION.toBuilder() - .diskType(DiskTypeId.of("zone", "diskType")) - .sourceImage(ImageId.of("image")) + .setDiskType(DiskTypeId.of("zone", "diskType")) + .setSourceImage(ImageId.of("image")) .build(); compareAttachedDisk(AttachedDisk.of(CREATE_DISK_CONFIGURATION), AttachedDisk.of(createDiskConfiguration).setProjectId("project")); @@ -352,8 +429,8 @@ public void testSetProjectId() { public void compareAttachedDiskConfiguration(AttachedDisk.AttachedDiskConfiguration expected, AttachedDisk.AttachedDiskConfiguration value) { assertEquals(expected, value); - assertEquals(expected.type(), value.type()); - assertEquals(expected.interfaceType(), value.interfaceType()); + assertEquals(expected.getType(), value.getType()); + assertEquals(expected.getInterfaceType(), value.getInterfaceType()); assertEquals(expected.boot(), value.boot()); assertEquals(expected.autoDelete(), value.autoDelete()); assertEquals(expected.hashCode(), value.hashCode()); @@ -362,31 +439,31 @@ public void compareAttachedDiskConfiguration(AttachedDisk.AttachedDiskConfigurat public void comparePersistentDiskConfiguration(PersistentDiskConfiguration expected, PersistentDiskConfiguration value) { compareAttachedDiskConfiguration(expected, value); - assertEquals(expected.mode(), value.mode()); - assertEquals(expected.sourceDisk(), value.sourceDisk()); + assertEquals(expected.getMode(), value.getMode()); + assertEquals(expected.getSourceDisk(), value.getSourceDisk()); } public void compareCreateDiskConfiguration(CreateDiskConfiguration expected, CreateDiskConfiguration value) { compareAttachedDiskConfiguration(expected, value); - assertEquals(expected.diskName(), value.diskName()); - assertEquals(expected.diskType(), value.diskType()); - assertEquals(expected.diskSizeGb(), value.diskSizeGb()); - assertEquals(expected.sourceImage(), value.sourceImage()); + assertEquals(expected.getDiskName(), value.getDiskName()); + assertEquals(expected.getDiskType(), value.getDiskType()); + assertEquals(expected.getDiskSizeGb(), value.getDiskSizeGb()); + assertEquals(expected.getSourceImage(), value.getSourceImage()); } public void compareScratchDiskConfiguration(ScratchDiskConfiguration expected, ScratchDiskConfiguration value) { compareAttachedDiskConfiguration(expected, value); - assertEquals(expected.diskType(), value.diskType()); + assertEquals(expected.getDiskType(), value.getDiskType()); } public void compareAttachedDisk(AttachedDisk expected, AttachedDisk value) { assertEquals(expected, value); - assertEquals(expected.deviceName(), value.deviceName()); - assertEquals(expected.index(), value.index()); - assertEquals(expected.configuration(), value.configuration()); - assertEquals(expected.licenses(), value.licenses()); + assertEquals(expected.getDeviceName(), value.getDeviceName()); + assertEquals(expected.getIndex(), value.getIndex()); + assertEquals(expected.getConfiguration(), value.getConfiguration()); + assertEquals(expected.getLicenses(), value.getLicenses()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/ComputeImplTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/ComputeImplTest.java index 6d1226df1a08..b8c4205586ff 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/ComputeImplTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/ComputeImplTest.java @@ -55,13 +55,13 @@ public class ComputeImplTest { private static final String VALID_DISK_SIZE = "10GB-10TB"; private static final Long DEFAULT_DISK_SIZE_GB = 10L; private static final DiskTypeId DISK_TYPE_ID = DiskTypeId.of("project", "zone", "diskType"); - private static final DiskType DISK_TYPE = DiskType.builder() - .generatedId(GENERATED_ID) - .diskTypeId(DISK_TYPE_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .validDiskSize(VALID_DISK_SIZE) - .defaultDiskSizeGb(DEFAULT_DISK_SIZE_GB) + private static final DiskType DISK_TYPE = DiskType.newBuilder() + .setGeneratedId(GENERATED_ID) + .setDiskTypeId(DISK_TYPE_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setValidDiskSize(VALID_DISK_SIZE) + .setDefaultDiskSizeGb(DEFAULT_DISK_SIZE_GB) .build(); private static final MachineTypeId MACHINE_TYPE_ID = MachineTypeId.of("project", "zone", "type"); private static final Integer GUEST_CPUS = 1; @@ -69,16 +69,16 @@ public class ComputeImplTest { private static final List SCRATCH_DISKS = ImmutableList.of(3); private static final Integer MAXIMUM_PERSISTENT_DISKS = 4; private static final Long MAXIMUM_PERSISTENT_DISKS_SIZE_GB = 5L; - private static final MachineType MACHINE_TYPE = MachineType.builder() - .generatedId(GENERATED_ID) - .machineTypeId(MACHINE_TYPE_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .cpus(GUEST_CPUS) - .memoryMb(MEMORY_MB) - .scratchDisksSizeGb(SCRATCH_DISKS) - .maximumPersistentDisks(MAXIMUM_PERSISTENT_DISKS) - .maximumPersistentDisksSizeGb(MAXIMUM_PERSISTENT_DISKS_SIZE_GB) + private static final MachineType MACHINE_TYPE = MachineType.newBuilder() + .setGeneratedId(GENERATED_ID) + .setMachineTypeId(MACHINE_TYPE_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setCpus(GUEST_CPUS) + .setMemoryMb(MEMORY_MB) + .setScratchDisksSizeGb(SCRATCH_DISKS) + .setMaximumPersistentDisks(MAXIMUM_PERSISTENT_DISKS) + .setMaximumPersistentDisksSizeGb(MAXIMUM_PERSISTENT_DISKS_SIZE_GB) .build(); private static final RegionId REGION_ID = RegionId.of("project", "region"); private static final Region.Status REGION_STATUS = Region.Status.DOWN; @@ -91,23 +91,23 @@ public class ComputeImplTest { new Region.Quota("METRIC2", 4, 3); private static final List QUOTAS = ImmutableList.of(QUOTA1, QUOTA2); private static final Region REGION = Region.builder() - .regionId(REGION_ID) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .status(REGION_STATUS) - .zones(ZONES) - .quotas(QUOTAS) + .setRegionId(REGION_ID) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(REGION_STATUS) + .setZones(ZONES) + .setQuotas(QUOTAS) .build(); private static final ZoneId ZONE_ID = ZoneId.of("project", "zone"); private static final Zone.Status ZONE_STATUS = Zone.Status.DOWN; private static final Zone ZONE = Zone.builder() - .zoneId(ZONE_ID) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .status(ZONE_STATUS) - .region(REGION_ID) + .setZoneId(ZONE_ID) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(ZONE_STATUS) + .setRegion(REGION_ID) .build(); private static final LicenseId LICENSE_ID = LicenseId.of("project", "license"); private static final Boolean CHARGES_USE_FEE = true; @@ -147,15 +147,17 @@ public class ComputeImplTest { RegionAddressId.of("project", "region", "address"); private static final GlobalAddressId GLOBAL_ADDRESS_ID = GlobalAddressId.of("project", "address"); - private static final AddressInfo REGION_ADDRESS = AddressInfo.builder(REGION_ADDRESS_ID).build(); - private static final AddressInfo GLOBAL_ADDRESS = AddressInfo.builder(GLOBAL_ADDRESS_ID).build(); + private static final AddressInfo REGION_ADDRESS = + AddressInfo.newBuilder(REGION_ADDRESS_ID).build(); + private static final AddressInfo GLOBAL_ADDRESS = + AddressInfo.newBuilder(GLOBAL_ADDRESS_ID).build(); private static final DiskId DISK_ID = DiskId.of("project", "zone", "disk"); private static final SnapshotId SNAPSHOT_ID = SnapshotId.of("project", "snapshot"); private static final SnapshotInfo SNAPSHOT = SnapshotInfo.of(SNAPSHOT_ID, DISK_ID); private static final ImageId IMAGE_ID = ImageId.of("project", "image"); private static final ImageInfo IMAGE = ImageInfo.of(IMAGE_ID, DiskImageConfiguration.of(DISK_ID)); private static final DeprecationStatus DEPRECATION_STATUS = - DeprecationStatus.builder(DeprecationStatus.Status.DEPRECATED, IMAGE_ID).build(); + DeprecationStatus.newBuilder(DeprecationStatus.Status.DEPRECATED, IMAGE_ID).build(); private static final DiskInfo DISK = DiskInfo.of(DISK_ID, StandardDiskConfiguration.of(DISK_TYPE_ID)); private static final NetworkId NETWORK_ID = NetworkId.of("project", "network"); @@ -222,9 +224,11 @@ public class ComputeImplTest { ComputeRpc.Option.FILTER, "maximumPersistentDisks ne 42"); // MachineType aggregated list options - private static final Compute.MachineTypeAggregatedListOption MACHINE_TYPE_AGGREGATED_LIST_PAGE_TOKEN = + private static final Compute.MachineTypeAggregatedListOption + MACHINE_TYPE_AGGREGATED_LIST_PAGE_TOKEN = Compute.MachineTypeAggregatedListOption.pageToken("cursor"); - private static final Compute.MachineTypeAggregatedListOption MACHINE_TYPE_AGGREGATED_LIST_PAGE_SIZE = + private static final Compute.MachineTypeAggregatedListOption + MACHINE_TYPE_AGGREGATED_LIST_PAGE_SIZE = Compute.MachineTypeAggregatedListOption.pageSize(42L); private static final Compute.MachineTypeAggregatedListOption MACHINE_TYPE_AGGREGATED_LIST_FILTER = Compute.MachineTypeAggregatedListOption.filter(MACHINE_TYPE_FILTER); @@ -256,8 +260,10 @@ public class ComputeImplTest { Compute.ZoneFilter.notEquals(Compute.ZoneField.NAME, "someName"); private static final Compute.ZoneListOption ZONE_LIST_PAGE_TOKEN = Compute.ZoneListOption.pageToken("cursor"); - private static final Compute.ZoneListOption ZONE_LIST_PAGE_SIZE = Compute.ZoneListOption.pageSize(42L); - private static final Compute.ZoneListOption ZONE_LIST_FILTER = Compute.ZoneListOption.filter(ZONE_FILTER); + private static final Compute.ZoneListOption ZONE_LIST_PAGE_SIZE = + Compute.ZoneListOption.pageSize(42L); + private static final Compute.ZoneListOption ZONE_LIST_FILTER = + Compute.ZoneListOption.filter(ZONE_FILTER); private static final Map ZONE_LIST_OPTIONS = ImmutableMap.of( ComputeRpc.Option.PAGE_TOKEN, "cursor", ComputeRpc.Option.MAX_RESULTS, 42L, @@ -294,7 +300,8 @@ public class ComputeImplTest { Compute.AddressFilter.notEquals(Compute.AddressField.REGION, "someRegion"); private static final Compute.AddressListOption ADDRESS_LIST_PAGE_TOKEN = Compute.AddressListOption.pageToken("cursor"); - private static final Compute.AddressListOption ADDRESS_LIST_PAGE_SIZE = Compute.AddressListOption.pageSize(42L); + private static final Compute.AddressListOption ADDRESS_LIST_PAGE_SIZE = + Compute.AddressListOption.pageSize(42L); private static final Compute.AddressListOption ADDRESS_LIST_FILTER = Compute.AddressListOption.filter(ADDRESS_FILTER); private static final Map ADDRESS_LIST_OPTIONS = ImmutableMap.of( @@ -335,9 +342,12 @@ public class ComputeImplTest { // Image list options private static final Compute.ImageFilter IMAGE_FILTER = Compute.ImageFilter.notEquals(Compute.ImageField.DISK_SIZE_GB, 500L); - private static final Compute.ImageListOption IMAGE_LIST_PAGE_TOKEN = Compute.ImageListOption.pageToken("cursor"); - private static final Compute.ImageListOption IMAGE_LIST_PAGE_SIZE = Compute.ImageListOption.pageSize(42L); - private static final Compute.ImageListOption IMAGE_LIST_FILTER = Compute.ImageListOption.filter(IMAGE_FILTER); + private static final Compute.ImageListOption IMAGE_LIST_PAGE_TOKEN = + Compute.ImageListOption.pageToken("cursor"); + private static final Compute.ImageListOption IMAGE_LIST_PAGE_SIZE = + Compute.ImageListOption.pageSize(42L); + private static final Compute.ImageListOption IMAGE_LIST_FILTER = + Compute.ImageListOption.filter(IMAGE_FILTER); private static final Map IMAGE_LIST_OPTIONS = ImmutableMap.of( ComputeRpc.Option.PAGE_TOKEN, "cursor", ComputeRpc.Option.MAX_RESULTS, 42L, @@ -348,10 +358,14 @@ public class ComputeImplTest { Compute.DiskOption.fields(Compute.DiskField.ID, Compute.DiskField.DESCRIPTION); // Disk list options - private static final Compute.DiskFilter DISK_FILTER = Compute.DiskFilter.notEquals(Compute.DiskField.SIZE_GB, 500L); - private static final Compute.DiskListOption DISK_LIST_PAGE_TOKEN = Compute.DiskListOption.pageToken("cursor"); - private static final Compute.DiskListOption DISK_LIST_PAGE_SIZE = Compute.DiskListOption.pageSize(42L); - private static final Compute.DiskListOption DISK_LIST_FILTER = Compute.DiskListOption.filter(DISK_FILTER); + private static final Compute.DiskFilter DISK_FILTER = + Compute.DiskFilter.notEquals(Compute.DiskField.SIZE_GB, 500L); + private static final Compute.DiskListOption DISK_LIST_PAGE_TOKEN = + Compute.DiskListOption.pageToken("cursor"); + private static final Compute.DiskListOption DISK_LIST_PAGE_SIZE = + Compute.DiskListOption.pageSize(42L); + private static final Compute.DiskListOption DISK_LIST_FILTER = + Compute.DiskListOption.filter(DISK_FILTER); private static final Map DISK_LIST_OPTIONS = ImmutableMap.of( ComputeRpc.Option.PAGE_TOKEN, "cursor", ComputeRpc.Option.MAX_RESULTS, 42L, @@ -367,7 +381,8 @@ public class ComputeImplTest { // Subnetwork options private static final Compute.SubnetworkOption SUBNETWORK_OPTION_FIELDS = - Compute.SubnetworkOption.fields(Compute.SubnetworkField.ID, Compute.SubnetworkField.DESCRIPTION); + Compute.SubnetworkOption.fields(Compute.SubnetworkField.ID, + Compute.SubnetworkField.DESCRIPTION); // Subnetwork list options private static final Compute.SubnetworkFilter SUBNETWORK_FILTER = @@ -384,7 +399,8 @@ public class ComputeImplTest { ComputeRpc.Option.FILTER, "ipCidrRange eq 192.168.0.0/16"); // Subnetwork aggregated list options - private static final Compute.SubnetworkAggregatedListOption SUBNETWORK_AGGREGATED_LIST_PAGE_TOKEN = + private static final Compute.SubnetworkAggregatedListOption + SUBNETWORK_AGGREGATED_LIST_PAGE_TOKEN = Compute.SubnetworkAggregatedListOption.pageToken("cursor"); private static final Compute.SubnetworkAggregatedListOption SUBNETWORK_AGGREGATED_LIST_PAGE_SIZE = Compute.SubnetworkAggregatedListOption.pageSize(42L); @@ -470,64 +486,64 @@ public void setUp() { .build(); Compute otherService = options.toBuilder().build().service(); globalOperation = new Operation.Builder(otherService) - .generatedId(GENERATED_ID) - .operationId(GLOBAL_OPERATION_ID) - .clientOperationId(CLIENT_OPERATION_ID) - .operationType(OPERATION_TYPE) - .targetLink(TARGET_LINK) - .targetId(TARGET_ID) - .status(STATUS) - .statusMessage(STATUS_MESSAGE) - .user(USER) - .progress(PROGRESS) - .insertTime(INSERT_TIME) - .startTime(START_TIME) - .endTime(END_TIME) - .errors(ERRORS) - .warnings(WARNINGS) - .httpErrorStatusCode(HTTP_ERROR_STATUS_CODE) - .httpErrorMessage(HTTP_ERROR_MESSAGE) - .description(DESCRIPTION) + .getGeneratedId(GENERATED_ID) + .setOperationId(GLOBAL_OPERATION_ID) + .setClientOperationId(CLIENT_OPERATION_ID) + .setOperationType(OPERATION_TYPE) + .setTargetLink(TARGET_LINK) + .setTargetId(TARGET_ID) + .setStatus(STATUS) + .setStatusMessage(STATUS_MESSAGE) + .setUser(USER) + .setProgress(PROGRESS) + .setInsertTime(INSERT_TIME) + .setStartTime(START_TIME) + .setEndTime(END_TIME) + .setErrors(ERRORS) + .setWarnings(WARNINGS) + .setHttpErrorStatusCode(HTTP_ERROR_STATUS_CODE) + .setHttpErrorMessage(HTTP_ERROR_MESSAGE) + .setDescription(DESCRIPTION) .build(); zoneOperation = new Operation.Builder(otherService) - .generatedId(GENERATED_ID) - .operationId(ZONE_OPERATION_ID) - .clientOperationId(CLIENT_OPERATION_ID) - .operationType(OPERATION_TYPE) - .targetLink(TARGET_LINK) - .targetId(TARGET_ID) - .status(STATUS) - .statusMessage(STATUS_MESSAGE) - .user(USER) - .progress(PROGRESS) - .insertTime(INSERT_TIME) - .startTime(START_TIME) - .endTime(END_TIME) - .errors(ERRORS) - .warnings(WARNINGS) - .httpErrorStatusCode(HTTP_ERROR_STATUS_CODE) - .httpErrorMessage(HTTP_ERROR_MESSAGE) - .description(DESCRIPTION) + .getGeneratedId(GENERATED_ID) + .setOperationId(ZONE_OPERATION_ID) + .setClientOperationId(CLIENT_OPERATION_ID) + .setOperationType(OPERATION_TYPE) + .setTargetLink(TARGET_LINK) + .setTargetId(TARGET_ID) + .setStatus(STATUS) + .setStatusMessage(STATUS_MESSAGE) + .setUser(USER) + .setProgress(PROGRESS) + .setInsertTime(INSERT_TIME) + .setStartTime(START_TIME) + .setEndTime(END_TIME) + .setErrors(ERRORS) + .setWarnings(WARNINGS) + .setHttpErrorStatusCode(HTTP_ERROR_STATUS_CODE) + .setHttpErrorMessage(HTTP_ERROR_MESSAGE) + .setDescription(DESCRIPTION) .build(); regionOperation = new Operation.Builder(otherService) - .generatedId(GENERATED_ID) - .operationId(REGION_OPERATION_ID) - .clientOperationId(CLIENT_OPERATION_ID) - .operationType(OPERATION_TYPE) - .targetLink(TARGET_LINK) - .targetId(TARGET_ID) - .status(STATUS) - .statusMessage(STATUS_MESSAGE) - .user(USER) - .progress(PROGRESS) - .insertTime(INSERT_TIME) - .startTime(START_TIME) - .endTime(END_TIME) - .errors(ERRORS) - .warnings(WARNINGS) - .httpErrorStatusCode(HTTP_ERROR_STATUS_CODE) - .httpErrorMessage(HTTP_ERROR_MESSAGE) - .description(DESCRIPTION) + .getGeneratedId(GENERATED_ID) + .setOperationId(REGION_OPERATION_ID) + .setClientOperationId(CLIENT_OPERATION_ID) + .setOperationType(OPERATION_TYPE) + .setTargetLink(TARGET_LINK) + .setTargetId(TARGET_ID) + .setStatus(STATUS) + .setStatusMessage(STATUS_MESSAGE) + .setUser(USER) + .setProgress(PROGRESS) + .setInsertTime(INSERT_TIME) + .setStartTime(START_TIME) + .setEndTime(END_TIME) + .setErrors(ERRORS) + .setWarnings(WARNINGS) + .setHttpErrorStatusCode(HTTP_ERROR_STATUS_CODE) + .setHttpErrorMessage(HTTP_ERROR_MESSAGE) + .setDescription(DESCRIPTION) .build(); } @@ -545,29 +561,29 @@ public void testGetOptions() { @Test public void testGetDiskType() { - EasyMock.expect( - computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getDiskType( + DISK_TYPE_ID.getZone(), DISK_TYPE_ID.getType(), EMPTY_RPC_OPTIONS)) .andReturn(DISK_TYPE.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); - DiskType diskType = compute.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type()); + DiskType diskType = compute.getDiskType(DISK_TYPE_ID.getZone(), DISK_TYPE_ID.getType()); assertEquals(DISK_TYPE, diskType); } @Test public void testGetDiskType_Null() { - EasyMock.expect( - computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getDiskType( + DISK_TYPE_ID.getZone(), DISK_TYPE_ID.getType(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); - assertNull(compute.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type())); + assertNull(compute.getDiskType(DISK_TYPE_ID.getZone(), DISK_TYPE_ID.getType())); } @Test public void testGetDiskTypeFromDiskTypeId() { - EasyMock.expect( - computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getDiskType( + DISK_TYPE_ID.getZone(), DISK_TYPE_ID.getType(), EMPTY_RPC_OPTIONS)) .andReturn(DISK_TYPE.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -580,13 +596,14 @@ public void testGetDiskTypeWithSelectedFields() { Capture> capturedOptions = Capture.newInstance(); EasyMock.expect( computeRpcMock.getDiskType( - eq(DISK_TYPE_ID.zone()), eq(DISK_TYPE_ID.type()), capture(capturedOptions))) + eq(DISK_TYPE_ID.getZone()), eq(DISK_TYPE_ID.getType()), capture(capturedOptions))) .andReturn(DISK_TYPE.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); - DiskType diskType = - compute.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), DISK_TYPE_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(DISK_TYPE_OPTION_FIELDS.rpcOption()); + DiskType diskType = compute.getDiskType(DISK_TYPE_ID.getZone(), DISK_TYPE_ID.getType(), + DISK_TYPE_OPTION_FIELDS); + String selector = + (String) capturedOptions.getValue().get(DISK_TYPE_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -601,10 +618,10 @@ public void testListDiskTypes() { ImmutableList diskTypeList = ImmutableList.of(DISK_TYPE, DISK_TYPE); ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(diskTypeList, DiskType.TO_PB_FUNCTION)); - EasyMock.expect(computeRpcMock.listDiskTypes(DISK_TYPE_ID.zone(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.listDiskTypes(DISK_TYPE_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page page = compute.listDiskTypes(DISK_TYPE_ID.zone()); + Page page = compute.listDiskTypes(DISK_TYPE_ID.getZone()); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(diskTypeList.toArray(), Iterables.toArray(page.values(), DiskType.class)); } @@ -619,14 +636,15 @@ public void testListDiskTypesNextPage() { ComputeRpc.Tuple.of(cursor, Iterables.transform(diskTypeList, DiskType.TO_PB_FUNCTION)); ImmutableList nextDiskTypeList = ImmutableList.of(DISK_TYPE); ComputeRpc.Tuple> nextResult = - ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextDiskTypeList, DiskType.TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(nextCursor, + Iterables.transform(nextDiskTypeList, DiskType.TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); - EasyMock.expect(computeRpcMock.listDiskTypes(DISK_TYPE_ID.zone(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.listDiskTypes(DISK_TYPE_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); - EasyMock.expect(computeRpcMock.listDiskTypes(DISK_TYPE_ID.zone(), nextOptions)) + EasyMock.expect(computeRpcMock.listDiskTypes(DISK_TYPE_ID.getZone(), nextOptions)) .andReturn(nextResult); EasyMock.replay(computeRpcMock); - Page page = compute.listDiskTypes(DISK_TYPE_ID.zone()); + Page page = compute.listDiskTypes(DISK_TYPE_ID.getZone()); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(diskTypeList.toArray(), Iterables.toArray(page.values(), DiskType.class)); page = page.nextPage(); @@ -639,11 +657,11 @@ public void testListEmptyDiskTypes() { ImmutableList diskTypes = ImmutableList.of(); ComputeRpc.Tuple> result = ComputeRpc.Tuple.>of(null, diskTypes); - EasyMock.expect(computeRpcMock.listDiskTypes(DISK_TYPE_ID.zone(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.listDiskTypes(DISK_TYPE_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); compute = options.service(); - Page page = compute.listDiskTypes(DISK_TYPE_ID.zone()); + Page page = compute.listDiskTypes(DISK_TYPE_ID.getZone()); assertNull(page.nextPageCursor()); assertArrayEquals(diskTypes.toArray(), Iterables.toArray(page.values(), DiskType.class)); } @@ -655,10 +673,10 @@ public void testListDiskTypesWithOptions() { ImmutableList diskTypeList = ImmutableList.of(DISK_TYPE, DISK_TYPE); ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(diskTypeList, DiskType.TO_PB_FUNCTION)); - EasyMock.expect(computeRpcMock.listDiskTypes(DISK_TYPE_ID.zone(), DISK_TYPE_LIST_OPTIONS)) + EasyMock.expect(computeRpcMock.listDiskTypes(DISK_TYPE_ID.getZone(), DISK_TYPE_LIST_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page page = compute.listDiskTypes(DISK_TYPE_ID.zone(), DISK_TYPE_LIST_PAGE_SIZE, + Page page = compute.listDiskTypes(DISK_TYPE_ID.getZone(), DISK_TYPE_LIST_PAGE_SIZE, DISK_TYPE_LIST_PAGE_TOKEN, DISK_TYPE_LIST_FILTER); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(diskTypeList.toArray(), Iterables.toArray(page.values(), DiskType.class)); @@ -688,7 +706,8 @@ public void testAggregatedListDiskTypesNextPage() { ComputeRpc.Tuple.of(cursor, Iterables.transform(diskTypeList, DiskType.TO_PB_FUNCTION)); ImmutableList nextDiskTypeList = ImmutableList.of(DISK_TYPE); ComputeRpc.Tuple> nextResult = - ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextDiskTypeList, DiskType.TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(nextCursor, + Iterables.transform(nextDiskTypeList, DiskType.TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); EasyMock.expect(computeRpcMock.listDiskTypes(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.expect(computeRpcMock.listDiskTypes(nextOptions)).andReturn(nextResult); @@ -733,12 +752,12 @@ public void testAggregatedListDiskTypesWithOptions() { public void testGetMachineType() { EasyMock.expect( computeRpcMock.getMachineType( - MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type(), EMPTY_RPC_OPTIONS)) + MACHINE_TYPE_ID.getZone(), MACHINE_TYPE_ID.getType(), EMPTY_RPC_OPTIONS)) .andReturn(MACHINE_TYPE.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); MachineType machineType = - compute.getMachineType(MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type()); + compute.getMachineType(MACHINE_TYPE_ID.getZone(), MACHINE_TYPE_ID.getType()); assertEquals(MACHINE_TYPE, machineType); } @@ -746,17 +765,17 @@ public void testGetMachineType() { public void testGetMachineType_Null() { EasyMock.expect( computeRpcMock.getMachineType( - MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type(), EMPTY_RPC_OPTIONS)) + MACHINE_TYPE_ID.getZone(), MACHINE_TYPE_ID.getType(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); - assertNull(compute.getMachineType(MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type())); + assertNull(compute.getMachineType(MACHINE_TYPE_ID.getZone(), MACHINE_TYPE_ID.getType())); } @Test public void testGetMachineTypeFromMachineTypeId() { EasyMock.expect(computeRpcMock.getMachineType( - MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type(), EMPTY_RPC_OPTIONS)) + MACHINE_TYPE_ID.getZone(), MACHINE_TYPE_ID.getType(), EMPTY_RPC_OPTIONS)) .andReturn(MACHINE_TYPE.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -768,14 +787,15 @@ public void testGetMachineTypeFromMachineTypeId() { public void testGetMachineTypeWithSelectedFields() { Capture> capturedOptions = Capture.newInstance(); EasyMock.expect( - computeRpcMock.getMachineType(eq(MACHINE_TYPE_ID.zone()), eq(MACHINE_TYPE_ID.type()), + computeRpcMock.getMachineType(eq(MACHINE_TYPE_ID.getZone()), eq(MACHINE_TYPE_ID.getType()), capture(capturedOptions))) .andReturn(MACHINE_TYPE.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); - MachineType machineType = compute.getMachineType(MACHINE_TYPE_ID.zone(), - MACHINE_TYPE_ID.type(), MACHINE_TYPE_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(DISK_TYPE_OPTION_FIELDS.rpcOption()); + MachineType machineType = compute.getMachineType(MACHINE_TYPE_ID.getZone(), + MACHINE_TYPE_ID.getType(), MACHINE_TYPE_OPTION_FIELDS); + String selector = + (String) capturedOptions.getValue().get(DISK_TYPE_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -789,11 +809,12 @@ public void testListMachineTypes() { compute = options.service(); ImmutableList machineTypeList = ImmutableList.of(MACHINE_TYPE, MACHINE_TYPE); ComputeRpc.Tuple> result = - ComputeRpc.Tuple.of(cursor, Iterables.transform(machineTypeList, MachineType.TO_PB_FUNCTION)); - EasyMock.expect(computeRpcMock.listMachineTypes(MACHINE_TYPE_ID.zone(), EMPTY_RPC_OPTIONS)) + ComputeRpc.Tuple.of(cursor, + Iterables.transform(machineTypeList, MachineType.TO_PB_FUNCTION)); + EasyMock.expect(computeRpcMock.listMachineTypes(MACHINE_TYPE_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page page = compute.listMachineTypes(MACHINE_TYPE_ID.zone()); + Page page = compute.listMachineTypes(MACHINE_TYPE_ID.getZone()); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(machineTypeList.toArray(), Iterables.toArray(page.values(), MachineType.class)); @@ -806,17 +827,20 @@ public void testListMachineTypesNextPage() { compute = options.service(); ImmutableList machineTypeList = ImmutableList.of(MACHINE_TYPE, MACHINE_TYPE); ComputeRpc.Tuple> result = - ComputeRpc.Tuple.of(cursor, Iterables.transform(machineTypeList, MachineType.TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(cursor, + Iterables.transform(machineTypeList, MachineType.TO_PB_FUNCTION)); ImmutableList nextMachineTypeList = ImmutableList.of(MACHINE_TYPE); - ComputeRpc.Tuple> nextResult = - ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextMachineTypeList, MachineType.TO_PB_FUNCTION)); + ComputeRpc.Tuple> + nextResult = + ComputeRpc.Tuple.of(nextCursor, + Iterables.transform(nextMachineTypeList, MachineType.TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); - EasyMock.expect(computeRpcMock.listMachineTypes(MACHINE_TYPE_ID.zone(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.listMachineTypes(MACHINE_TYPE_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); - EasyMock.expect(computeRpcMock.listMachineTypes(MACHINE_TYPE_ID.zone(), nextOptions)) + EasyMock.expect(computeRpcMock.listMachineTypes(MACHINE_TYPE_ID.getZone(), nextOptions)) .andReturn(nextResult); EasyMock.replay(computeRpcMock); - Page page = compute.listMachineTypes(MACHINE_TYPE_ID.zone()); + Page page = compute.listMachineTypes(MACHINE_TYPE_ID.getZone()); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(machineTypeList.toArray(), Iterables.toArray(page.values(), MachineType.class)); @@ -833,11 +857,11 @@ public void testListEmptyMachineTypes() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.>of(null, machineTypes); - EasyMock.expect(computeRpcMock.listMachineTypes(MACHINE_TYPE_ID.zone(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.listMachineTypes(MACHINE_TYPE_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); compute = options.service(); - Page page = compute.listMachineTypes(MACHINE_TYPE_ID.zone()); + Page page = compute.listMachineTypes(MACHINE_TYPE_ID.getZone()); assertNull(page.nextPageCursor()); assertArrayEquals(machineTypes.toArray(), Iterables.toArray(page.values(), MachineType.class)); } @@ -848,12 +872,13 @@ public void testListMachineTypesWithOptions() { compute = options.service(); ImmutableList machineTypeList = ImmutableList.of(MACHINE_TYPE, MACHINE_TYPE); ComputeRpc.Tuple> result = - ComputeRpc.Tuple.of(cursor, Iterables.transform(machineTypeList, MachineType.TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(cursor, + Iterables.transform(machineTypeList, MachineType.TO_PB_FUNCTION)); EasyMock.expect( - computeRpcMock.listMachineTypes(MACHINE_TYPE_ID.zone(), MACHINE_TYPE_LIST_OPTIONS)) + computeRpcMock.listMachineTypes(MACHINE_TYPE_ID.getZone(), MACHINE_TYPE_LIST_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page page = compute.listMachineTypes(MACHINE_TYPE_ID.zone(), + Page page = compute.listMachineTypes(MACHINE_TYPE_ID.getZone(), MACHINE_TYPE_LIST_PAGE_SIZE, MACHINE_TYPE_LIST_PAGE_TOKEN, MACHINE_TYPE_LIST_FILTER); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(machineTypeList.toArray(), @@ -866,7 +891,8 @@ public void testAggregatedListMachineTypes() { compute = options.service(); ImmutableList machineTypeList = ImmutableList.of(MACHINE_TYPE, MACHINE_TYPE); ComputeRpc.Tuple> result = - ComputeRpc.Tuple.of(cursor, Iterables.transform(machineTypeList, MachineType.TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(cursor, + Iterables.transform(machineTypeList, MachineType.TO_PB_FUNCTION)); EasyMock.expect(computeRpcMock.listMachineTypes(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.replay(computeRpcMock); Page page = compute.listMachineTypes(); @@ -882,10 +908,13 @@ public void testAggregatedListMachineTypesNextPage() { compute = options.service(); ImmutableList machineTypeList = ImmutableList.of(MACHINE_TYPE, MACHINE_TYPE); ComputeRpc.Tuple> result = - ComputeRpc.Tuple.of(cursor, Iterables.transform(machineTypeList, MachineType.TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(cursor, + Iterables.transform(machineTypeList, MachineType.TO_PB_FUNCTION)); ImmutableList nextMachineTypeList = ImmutableList.of(MACHINE_TYPE); - ComputeRpc.Tuple> nextResult = - ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextMachineTypeList, MachineType.TO_PB_FUNCTION)); + ComputeRpc.Tuple> + nextResult = + ComputeRpc.Tuple.of(nextCursor, + Iterables.transform(nextMachineTypeList, MachineType.TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); EasyMock.expect(computeRpcMock.listMachineTypes(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.expect(computeRpcMock.listMachineTypes(nextOptions)).andReturn(nextResult); @@ -921,7 +950,8 @@ public void testAggregatedListMachineTypesWithOptions() { compute = options.service(); ImmutableList machineTypeList = ImmutableList.of(MACHINE_TYPE, MACHINE_TYPE); ComputeRpc.Tuple> result = - ComputeRpc.Tuple.of(cursor, Iterables.transform(machineTypeList, MachineType.TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(cursor, + Iterables.transform(machineTypeList, MachineType.TO_PB_FUNCTION)); EasyMock.expect(computeRpcMock.listMachineTypes(MACHINE_TYPE_LIST_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); @@ -934,32 +964,32 @@ public void testAggregatedListMachineTypesWithOptions() { @Test public void testGetRegion() { - EasyMock.expect(computeRpcMock.getRegion(REGION_ID.region(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getRegion(REGION_ID.getRegion(), EMPTY_RPC_OPTIONS)) .andReturn(REGION.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); - Region region = compute.getRegion(REGION_ID.region()); + Region region = compute.getRegion(REGION_ID.getRegion()); assertEquals(REGION, region); } @Test public void testGetRegion_Null() { - EasyMock.expect(computeRpcMock.getRegion(REGION_ID.region(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getRegion(REGION_ID.getRegion(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); - assertNull(compute.getRegion(REGION_ID.region())); + assertNull(compute.getRegion(REGION_ID.getRegion())); } @Test public void testGetRegionWithSelectedFields() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.getRegion(eq(REGION_ID.region()), capture(capturedOptions))) + EasyMock.expect(computeRpcMock.getRegion(eq(REGION_ID.getRegion()), capture(capturedOptions))) .andReturn(REGION.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); - Region region = compute.getRegion(REGION_ID.region(), REGION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(REGION_OPTION_FIELDS.rpcOption()); + Region region = compute.getRegion(REGION_ID.getRegion(), REGION_OPTION_FIELDS); + String selector = (String) capturedOptions.getValue().get(REGION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -1035,31 +1065,31 @@ public void testListRegionsWithOptions() { @Test public void testGetZone() { - EasyMock.expect(computeRpcMock.getZone(ZONE_ID.zone(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getZone(ZONE_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(ZONE.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); - Zone zone = compute.getZone(ZONE_ID.zone()); + Zone zone = compute.getZone(ZONE_ID.getZone()); assertEquals(ZONE, zone); } @Test public void testGetZone_Null() { - EasyMock.expect(computeRpcMock.getZone(ZONE_ID.zone(), EMPTY_RPC_OPTIONS)).andReturn(null); + EasyMock.expect(computeRpcMock.getZone(ZONE_ID.getZone(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); - assertNull(compute.getZone(ZONE_ID.zone())); + assertNull(compute.getZone(ZONE_ID.getZone())); } @Test public void testGetZoneWithSelectedFields() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.getZone(eq(ZONE_ID.zone()), capture(capturedOptions))) + EasyMock.expect(computeRpcMock.getZone(eq(ZONE_ID.getZone()), capture(capturedOptions))) .andReturn(ZONE.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); - Zone zone = compute.getZone(ZONE_ID.zone(), ZONE_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(ZONE_OPTION_FIELDS.rpcOption()); + Zone zone = compute.getZone(ZONE_ID.getZone(), ZONE_OPTION_FIELDS); + String selector = (String) capturedOptions.getValue().get(ZONE_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -1134,34 +1164,34 @@ public void testListZonesWithOptions() { @Test public void testGetLicenseFromString() { - EasyMock.expect(computeRpcMock.getLicense(PROJECT, LICENSE_ID.license(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getLicense(PROJECT, LICENSE_ID.getLicense(), EMPTY_RPC_OPTIONS)) .andReturn(LICENSE.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); - License license = compute.getLicense(LICENSE_ID.license()); + License license = compute.getLicense(LICENSE_ID.getLicense()); assertEquals(LICENSE, license); } @Test public void testGetLicenseFromString_Null() { - EasyMock.expect(computeRpcMock.getLicense(PROJECT, LICENSE_ID.license(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getLicense(PROJECT, LICENSE_ID.getLicense(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); - assertNull(compute.getLicense(LICENSE_ID.license())); + assertNull(compute.getLicense(LICENSE_ID.getLicense())); } @Test public void testGetLicenseFromStringWithOptions() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect( - computeRpcMock.getLicense(eq(PROJECT), eq(LICENSE_ID.license()), capture(capturedOptions))) + EasyMock.expect(computeRpcMock.getLicense( + eq(PROJECT), eq(LICENSE_ID.getLicense()), capture(capturedOptions))) .andReturn(LICENSE.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); - License license = compute.getLicense(LICENSE_ID.license(), LICENSE_OPTION_FIELDS); + License license = compute.getLicense(LICENSE_ID.getLicense(), LICENSE_OPTION_FIELDS); assertEquals(LICENSE, license); - String selector = (String) capturedOptions.getValue().get(LICENSE_OPTION_FIELDS.rpcOption()); + String selector = (String) capturedOptions.getValue().get(LICENSE_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("chargesUseFee")); assertEquals(22, selector.length()); @@ -1172,14 +1202,14 @@ public void testGetLicenseFromStringWithOptions() { public void testGetLicenseFromIdWithOptions() { Capture> capturedOptions = Capture.newInstance(); LicenseId licenseId = LicenseId.of("project2", "license2"); - EasyMock.expect(computeRpcMock.getLicense(eq(licenseId.project()), eq(licenseId.license()), - capture(capturedOptions))) + EasyMock.expect(computeRpcMock.getLicense( + eq(licenseId.getProject()), eq(licenseId.getLicense()), capture(capturedOptions))) .andReturn(LICENSE.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); License license = compute.getLicense(licenseId, LICENSE_OPTION_FIELDS); assertEquals(LICENSE, license); - String selector = (String) capturedOptions.getValue().get(LICENSE_OPTION_FIELDS.rpcOption()); + String selector = (String) capturedOptions.getValue().get(LICENSE_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("chargesUseFee")); assertEquals(22, selector.length()); @@ -1189,9 +1219,8 @@ public void testGetLicenseFromIdWithOptions() { @Test public void testGetLicenseFromId() { LicenseId licenseId = LicenseId.of("project2", "license2"); - EasyMock.expect( - computeRpcMock.getLicense(licenseId.project(), licenseId.license(), EMPTY_RPC_OPTIONS)) - .andReturn(LICENSE.toPb()); + EasyMock.expect(computeRpcMock.getLicense(licenseId.getProject(), licenseId.getLicense(), + EMPTY_RPC_OPTIONS)).andReturn(LICENSE.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); License license = compute.getLicense(licenseId); @@ -1201,8 +1230,8 @@ public void testGetLicenseFromId() { @Test public void testGetLicenseFromId_Null() { LicenseId licenseId = LicenseId.of("project2", "license2"); - EasyMock.expect( - computeRpcMock.getLicense(licenseId.project(), licenseId.license(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getLicense( + licenseId.getProject(), licenseId.getLicense(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -1212,7 +1241,7 @@ public void testGetLicenseFromId_Null() { @Test public void testGetGlobalOperation() { EasyMock.expect( - computeRpcMock.getGlobalOperation(GLOBAL_OPERATION_ID.operation(), EMPTY_RPC_OPTIONS)) + computeRpcMock.getGlobalOperation(GLOBAL_OPERATION_ID.getOperation(), EMPTY_RPC_OPTIONS)) .andReturn(globalOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -1222,7 +1251,7 @@ public void testGetGlobalOperation() { @Test public void testGetGlobalOperation_Null() { EasyMock.expect( - computeRpcMock.getGlobalOperation(GLOBAL_OPERATION_ID.operation(), EMPTY_RPC_OPTIONS)) + computeRpcMock.getGlobalOperation(GLOBAL_OPERATION_ID.getOperation(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -1233,12 +1262,13 @@ public void testGetGlobalOperation_Null() { public void testGetGlobalOperationWithSelectedFields() { Capture> capturedOptions = Capture.newInstance(); EasyMock.expect(computeRpcMock.getGlobalOperation( - eq(GLOBAL_OPERATION_ID.operation()), capture(capturedOptions))) + eq(GLOBAL_OPERATION_ID.getOperation()), capture(capturedOptions))) .andReturn(globalOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.getOperation(GLOBAL_OPERATION_ID, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -1270,7 +1300,8 @@ public void testListGlobalOperationsNextPage() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(operationList, OPERATION_TO_PB_FUNCTION)); ComputeRpc.Tuple> nextResult = - ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextOperationList, OPERATION_TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(nextCursor, + Iterables.transform(nextOperationList, OPERATION_TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); EasyMock.expect(computeRpcMock.listGlobalOperations(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.expect(computeRpcMock.listGlobalOperations(nextOptions)).andReturn(nextResult); @@ -1315,7 +1346,7 @@ public void testListGlobalOperationsWithOptions() { @Test public void testDeleteGlobalOperation_True() { - EasyMock.expect(computeRpcMock.deleteGlobalOperation(GLOBAL_OPERATION_ID.operation())) + EasyMock.expect(computeRpcMock.deleteGlobalOperation(GLOBAL_OPERATION_ID.getOperation())) .andReturn(true); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -1324,7 +1355,7 @@ public void testDeleteGlobalOperation_True() { @Test public void testDeleteGlobalOperation_False() { - EasyMock.expect(computeRpcMock.deleteGlobalOperation(GLOBAL_OPERATION_ID.operation())) + EasyMock.expect(computeRpcMock.deleteGlobalOperation(GLOBAL_OPERATION_ID.getOperation())) .andReturn(false); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -1333,8 +1364,8 @@ public void testDeleteGlobalOperation_False() { @Test public void testGetRegionOperation() { - EasyMock.expect(computeRpcMock.getRegionOperation(REGION_OPERATION_ID.region(), - REGION_OPERATION_ID.operation(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getRegionOperation(REGION_OPERATION_ID.getRegion(), + REGION_OPERATION_ID.getOperation(), EMPTY_RPC_OPTIONS)) .andReturn(regionOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -1344,8 +1375,8 @@ public void testGetRegionOperation() { @Test public void testGetRegionOperation_Null() { - EasyMock.expect(computeRpcMock.getRegionOperation(REGION_OPERATION_ID.region(), - REGION_OPERATION_ID.operation(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getRegionOperation(REGION_OPERATION_ID.getRegion(), + REGION_OPERATION_ID.getOperation(), EMPTY_RPC_OPTIONS)) .andReturn(regionOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -1356,13 +1387,14 @@ public void testGetRegionOperation_Null() { @Test public void testGetRegionOperationWithSelectedFields() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.getRegionOperation(eq(REGION_OPERATION_ID.region()), - eq(REGION_OPERATION_ID.operation()), capture(capturedOptions))) + EasyMock.expect(computeRpcMock.getRegionOperation(eq(REGION_OPERATION_ID.getRegion()), + eq(REGION_OPERATION_ID.getOperation()), capture(capturedOptions))) .andReturn(regionOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.getOperation(REGION_OPERATION_ID, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -1378,10 +1410,10 @@ public void testListRegionOperations() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(operationList, OPERATION_TO_PB_FUNCTION)); EasyMock.expect( - computeRpcMock.listRegionOperations(REGION_OPERATION_ID.region(), EMPTY_RPC_OPTIONS)) + computeRpcMock.listRegionOperations(REGION_OPERATION_ID.getRegion(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page page = compute.listRegionOperations(REGION_OPERATION_ID.region()); + Page page = compute.listRegionOperations(REGION_OPERATION_ID.getRegion()); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(operationList.toArray(), Iterables.toArray(page.values(), Operation.class)); } @@ -1396,14 +1428,15 @@ public void testListRegionOperationsNextPage() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(operationList, OPERATION_TO_PB_FUNCTION)); ComputeRpc.Tuple> nextResult = - ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextOperationList, OPERATION_TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(nextCursor, + Iterables.transform(nextOperationList, OPERATION_TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); - EasyMock.expect(computeRpcMock.listRegionOperations(REGION_OPERATION_ID.region(), + EasyMock.expect(computeRpcMock.listRegionOperations(REGION_OPERATION_ID.getRegion(), EMPTY_RPC_OPTIONS)).andReturn(result); - EasyMock.expect(computeRpcMock.listRegionOperations(REGION_OPERATION_ID.region(), + EasyMock.expect(computeRpcMock.listRegionOperations(REGION_OPERATION_ID.getRegion(), nextOptions)).andReturn(nextResult); EasyMock.replay(computeRpcMock); - Page page = compute.listRegionOperations(REGION_OPERATION_ID.region()); + Page page = compute.listRegionOperations(REGION_OPERATION_ID.getRegion()); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(operationList.toArray(), Iterables.toArray(page.values(), Operation.class)); page = page.nextPage(); @@ -1419,11 +1452,11 @@ public void testListEmptyRegionOperations() { ComputeRpc.Tuple.>of(null, operations); EasyMock.expect( - computeRpcMock.listRegionOperations(REGION_OPERATION_ID.region(), EMPTY_RPC_OPTIONS)) + computeRpcMock.listRegionOperations(REGION_OPERATION_ID.getRegion(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); compute = options.service(); - Page page = compute.listRegionOperations(REGION_OPERATION_ID.region()); + Page page = compute.listRegionOperations(REGION_OPERATION_ID.getRegion()); assertNull(page.nextPageCursor()); assertArrayEquals(operations.toArray(), Iterables.toArray(page.values(), Operation.class)); } @@ -1435,11 +1468,11 @@ public void testListRegionOperationsWithOptions() { ImmutableList operationList = ImmutableList.of(regionOperation, regionOperation); ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(operationList, OPERATION_TO_PB_FUNCTION)); - EasyMock.expect( - computeRpcMock.listRegionOperations(REGION_OPERATION_ID.region(), OPERATION_LIST_OPTIONS)) + EasyMock.expect(computeRpcMock.listRegionOperations( + REGION_OPERATION_ID.getRegion(), OPERATION_LIST_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page page = compute.listRegionOperations(REGION_OPERATION_ID.region(), + Page page = compute.listRegionOperations(REGION_OPERATION_ID.getRegion(), OPERATION_LIST_PAGE_SIZE, OPERATION_LIST_PAGE_TOKEN, OPERATION_LIST_FILTER); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(operationList.toArray(), Iterables.toArray(page.values(), Operation.class)); @@ -1447,8 +1480,8 @@ public void testListRegionOperationsWithOptions() { @Test public void testDeleteRegionOperation_True() { - EasyMock.expect(computeRpcMock.deleteRegionOperation(REGION_OPERATION_ID.region(), - REGION_OPERATION_ID.operation())).andReturn(true); + EasyMock.expect(computeRpcMock.deleteRegionOperation(REGION_OPERATION_ID.getRegion(), + REGION_OPERATION_ID.getOperation())).andReturn(true); EasyMock.replay(computeRpcMock); compute = options.service(); assertTrue(compute.deleteOperation(REGION_OPERATION_ID)); @@ -1456,8 +1489,8 @@ public void testDeleteRegionOperation_True() { @Test public void testDeleteRegionOperation_False() { - EasyMock.expect(computeRpcMock.deleteRegionOperation(REGION_OPERATION_ID.region(), - REGION_OPERATION_ID.operation())).andReturn(false); + EasyMock.expect(computeRpcMock.deleteRegionOperation(REGION_OPERATION_ID.getRegion(), + REGION_OPERATION_ID.getOperation())).andReturn(false); EasyMock.replay(computeRpcMock); compute = options.service(); assertFalse(compute.deleteOperation(REGION_OPERATION_ID)); @@ -1465,8 +1498,8 @@ public void testDeleteRegionOperation_False() { @Test public void testGetZoneOperation() { - EasyMock.expect(computeRpcMock.getZoneOperation(ZONE_OPERATION_ID.zone(), - ZONE_OPERATION_ID.operation(), EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); + EasyMock.expect(computeRpcMock.getZoneOperation(ZONE_OPERATION_ID.getZone(), + ZONE_OPERATION_ID.getOperation(), EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.getOperation(ZONE_OPERATION_ID); @@ -1475,8 +1508,8 @@ public void testGetZoneOperation() { @Test public void testGetZoneOperation_Null() { - EasyMock.expect(computeRpcMock.getZoneOperation(ZONE_OPERATION_ID.zone(), - ZONE_OPERATION_ID.operation(), EMPTY_RPC_OPTIONS)).andReturn(null); + EasyMock.expect(computeRpcMock.getZoneOperation(ZONE_OPERATION_ID.getZone(), + ZONE_OPERATION_ID.getOperation(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); assertNull(compute.getOperation(ZONE_OPERATION_ID)); @@ -1485,13 +1518,14 @@ public void testGetZoneOperation_Null() { @Test public void testGetZoneOperationWithSelectedFields() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.getZoneOperation(eq(ZONE_OPERATION_ID.zone()), - eq(ZONE_OPERATION_ID.operation()), capture(capturedOptions))) + EasyMock.expect(computeRpcMock.getZoneOperation(eq(ZONE_OPERATION_ID.getZone()), + eq(ZONE_OPERATION_ID.getOperation()), capture(capturedOptions))) .andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.getOperation(ZONE_OPERATION_ID, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -1507,10 +1541,10 @@ public void testListZoneOperations() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(operationList, OPERATION_TO_PB_FUNCTION)); EasyMock.expect( - computeRpcMock.listZoneOperations(ZONE_OPERATION_ID.zone(), EMPTY_RPC_OPTIONS)) + computeRpcMock.listZoneOperations(ZONE_OPERATION_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page page = compute.listZoneOperations(ZONE_OPERATION_ID.zone()); + Page page = compute.listZoneOperations(ZONE_OPERATION_ID.getZone()); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(operationList.toArray(), Iterables.toArray(page.values(), Operation.class)); } @@ -1525,14 +1559,16 @@ public void testListZoneOperationsNextPage() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(operationList, OPERATION_TO_PB_FUNCTION)); ComputeRpc.Tuple> nextResult = - ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextOperationList, OPERATION_TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(nextCursor, + Iterables.transform(nextOperationList, OPERATION_TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); - EasyMock.expect(computeRpcMock.listZoneOperations(ZONE_OPERATION_ID.zone(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.listZoneOperations( + ZONE_OPERATION_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); - EasyMock.expect(computeRpcMock.listZoneOperations(ZONE_OPERATION_ID.zone(), nextOptions)) + EasyMock.expect(computeRpcMock.listZoneOperations(ZONE_OPERATION_ID.getZone(), nextOptions)) .andReturn(nextResult); EasyMock.replay(computeRpcMock); - Page page = compute.listZoneOperations(ZONE_OPERATION_ID.zone()); + Page page = compute.listZoneOperations(ZONE_OPERATION_ID.getZone()); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(operationList.toArray(), Iterables.toArray(page.values(), Operation.class)); page = page.nextPage(); @@ -1548,11 +1584,11 @@ public void testListEmptyZoneOperations() { ComputeRpc.Tuple.>of(null, operations); EasyMock.expect( - computeRpcMock.listZoneOperations(ZONE_OPERATION_ID.zone(), EMPTY_RPC_OPTIONS)) + computeRpcMock.listZoneOperations(ZONE_OPERATION_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); compute = options.service(); - Page page = compute.listZoneOperations(ZONE_OPERATION_ID.zone()); + Page page = compute.listZoneOperations(ZONE_OPERATION_ID.getZone()); assertNull(page.nextPageCursor()); assertArrayEquals(operations.toArray(), Iterables.toArray(page.values(), Operation.class)); } @@ -1565,10 +1601,10 @@ public void testListZoneOperationsWithOptions() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(operationList, OPERATION_TO_PB_FUNCTION)); EasyMock.expect( - computeRpcMock.listZoneOperations(ZONE_OPERATION_ID.zone(), OPERATION_LIST_OPTIONS)) + computeRpcMock.listZoneOperations(ZONE_OPERATION_ID.getZone(), OPERATION_LIST_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page page = compute.listZoneOperations(ZONE_OPERATION_ID.zone(), + Page page = compute.listZoneOperations(ZONE_OPERATION_ID.getZone(), OPERATION_LIST_PAGE_SIZE, OPERATION_LIST_PAGE_TOKEN, OPERATION_LIST_FILTER); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(operationList.toArray(), Iterables.toArray(page.values(), Operation.class)); @@ -1576,8 +1612,8 @@ public void testListZoneOperationsWithOptions() { @Test public void testDeleteZoneOperation_True() { - EasyMock.expect(computeRpcMock.deleteZoneOperation(ZONE_OPERATION_ID.zone(), - ZONE_OPERATION_ID.operation())).andReturn(true); + EasyMock.expect(computeRpcMock.deleteZoneOperation(ZONE_OPERATION_ID.getZone(), + ZONE_OPERATION_ID.getOperation())).andReturn(true); EasyMock.replay(computeRpcMock); compute = options.service(); assertTrue(compute.deleteOperation(ZONE_OPERATION_ID)); @@ -1585,8 +1621,8 @@ public void testDeleteZoneOperation_True() { @Test public void testDeleteZoneOperation_False() { - EasyMock.expect(computeRpcMock.deleteZoneOperation(ZONE_OPERATION_ID.zone(), - ZONE_OPERATION_ID.operation())).andReturn(false); + EasyMock.expect(computeRpcMock.deleteZoneOperation(ZONE_OPERATION_ID.getZone(), + ZONE_OPERATION_ID.getOperation())).andReturn(false); EasyMock.replay(computeRpcMock); compute = options.service(); assertFalse(compute.deleteOperation(ZONE_OPERATION_ID)); @@ -1594,7 +1630,8 @@ public void testDeleteZoneOperation_False() { @Test public void testGetGlobalAddress() { - EasyMock.expect(computeRpcMock.getGlobalAddress(GLOBAL_ADDRESS_ID.address(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getGlobalAddress( + GLOBAL_ADDRESS_ID.getAddress(), EMPTY_RPC_OPTIONS)) .andReturn(GLOBAL_ADDRESS.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -1604,7 +1641,8 @@ public void testGetGlobalAddress() { @Test public void testGetGlobalAddress_Null() { - EasyMock.expect(computeRpcMock.getGlobalAddress(GLOBAL_ADDRESS_ID.address(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getGlobalAddress( + GLOBAL_ADDRESS_ID.getAddress(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -1615,12 +1653,12 @@ public void testGetGlobalAddress_Null() { public void testGetGlobalAddressWithSelectedFields() { Capture> capturedOptions = Capture.newInstance(); EasyMock.expect(computeRpcMock.getGlobalAddress( - eq(GLOBAL_ADDRESS_ID.address()), capture(capturedOptions))) + eq(GLOBAL_ADDRESS_ID.getAddress()), capture(capturedOptions))) .andReturn(GLOBAL_ADDRESS.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Address address = compute.getAddress(GLOBAL_ADDRESS_ID, ADDRESS_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(ADDRESS_OPTION_FIELDS.rpcOption()); + String selector = (String) capturedOptions.getValue().get(ADDRESS_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -1630,8 +1668,8 @@ public void testGetGlobalAddressWithSelectedFields() { @Test public void testGetRegionAddress() { - EasyMock.expect(computeRpcMock.getRegionAddress(REGION_ADDRESS_ID.region(), - REGION_ADDRESS_ID.address(), EMPTY_RPC_OPTIONS)).andReturn(REGION_ADDRESS.toPb()); + EasyMock.expect(computeRpcMock.getRegionAddress(REGION_ADDRESS_ID.getRegion(), + REGION_ADDRESS_ID.getAddress(), EMPTY_RPC_OPTIONS)).andReturn(REGION_ADDRESS.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Address address = compute.getAddress(REGION_ADDRESS_ID); @@ -1640,8 +1678,8 @@ public void testGetRegionAddress() { @Test public void testGetRegionAddress_Null() { - EasyMock.expect(computeRpcMock.getRegionAddress(REGION_ADDRESS_ID.region(), - REGION_ADDRESS_ID.address(), EMPTY_RPC_OPTIONS)).andReturn(REGION_ADDRESS.toPb()); + EasyMock.expect(computeRpcMock.getRegionAddress(REGION_ADDRESS_ID.getRegion(), + REGION_ADDRESS_ID.getAddress(), EMPTY_RPC_OPTIONS)).andReturn(REGION_ADDRESS.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Address address = compute.getAddress(REGION_ADDRESS_ID); @@ -1651,13 +1689,13 @@ public void testGetRegionAddress_Null() { @Test public void testGetRegionAddressWithSelectedFields() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.getRegionAddress(eq(REGION_ADDRESS_ID.region()), - eq(REGION_ADDRESS_ID.address()), capture(capturedOptions))) + EasyMock.expect(computeRpcMock.getRegionAddress(eq(REGION_ADDRESS_ID.getRegion()), + eq(REGION_ADDRESS_ID.getAddress()), capture(capturedOptions))) .andReturn(REGION_ADDRESS.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Address address = compute.getAddress(REGION_ADDRESS_ID, ADDRESS_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(ADDRESS_OPTION_FIELDS.rpcOption()); + String selector = (String) capturedOptions.getValue().get(ADDRESS_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -1667,8 +1705,8 @@ public void testGetRegionAddressWithSelectedFields() { @Test public void testDeleteGlobalAddress_Operation() { - EasyMock - .expect(computeRpcMock.deleteGlobalAddress(GLOBAL_ADDRESS_ID.address(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.deleteGlobalAddress( + GLOBAL_ADDRESS_ID.getAddress(), EMPTY_RPC_OPTIONS)) .andReturn(globalOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -1678,12 +1716,13 @@ public void testDeleteGlobalAddress_Operation() { @Test public void testDeleteGlobalAddressWithSelectedFields_Operation() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.deleteGlobalAddress(eq(GLOBAL_ADDRESS_ID.address()), + EasyMock.expect(computeRpcMock.deleteGlobalAddress(eq(GLOBAL_ADDRESS_ID.getAddress()), capture(capturedOptions))).andReturn(globalOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.deleteAddress(GLOBAL_ADDRESS_ID, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -1693,8 +1732,8 @@ public void testDeleteGlobalAddressWithSelectedFields_Operation() { @Test public void testDeleteGlobalAddress_Null() { - EasyMock - .expect(computeRpcMock.deleteGlobalAddress(GLOBAL_ADDRESS_ID.address(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.deleteGlobalAddress( + GLOBAL_ADDRESS_ID.getAddress(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -1703,8 +1742,8 @@ public void testDeleteGlobalAddress_Null() { @Test public void testDeleteRegionAddress_Operation() { - EasyMock.expect(computeRpcMock.deleteRegionAddress(REGION_ADDRESS_ID.region(), - REGION_ADDRESS_ID.address(), EMPTY_RPC_OPTIONS)).andReturn(regionOperation.toPb()); + EasyMock.expect(computeRpcMock.deleteRegionAddress(REGION_ADDRESS_ID.getRegion(), + REGION_ADDRESS_ID.getAddress(), EMPTY_RPC_OPTIONS)).andReturn(regionOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); assertEquals(regionOperation, compute.deleteAddress(REGION_ADDRESS_ID)); @@ -1713,13 +1752,14 @@ public void testDeleteRegionAddress_Operation() { @Test public void testDeleteRegionAddressWithSelectedFields_Operation() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.deleteRegionAddress(eq(REGION_ADDRESS_ID.region()), - eq(REGION_ADDRESS_ID.address()), capture(capturedOptions))) + EasyMock.expect(computeRpcMock.deleteRegionAddress(eq(REGION_ADDRESS_ID.getRegion()), + eq(REGION_ADDRESS_ID.getAddress()), capture(capturedOptions))) .andReturn(globalOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.deleteAddress(REGION_ADDRESS_ID, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -1729,8 +1769,8 @@ public void testDeleteRegionAddressWithSelectedFields_Operation() { @Test public void testDeleteRegionAddress_Null() { - EasyMock.expect(computeRpcMock.deleteRegionAddress(REGION_ADDRESS_ID.region(), - REGION_ADDRESS_ID.address(), EMPTY_RPC_OPTIONS)).andReturn(null); + EasyMock.expect(computeRpcMock.deleteRegionAddress(REGION_ADDRESS_ID.getRegion(), + REGION_ADDRESS_ID.getAddress(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); assertNull(compute.deleteAddress(REGION_ADDRESS_ID)); @@ -1765,7 +1805,8 @@ public void testListGlobalAddressesNextPage() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(addressList, AddressInfo.TO_PB_FUNCTION)); ComputeRpc.Tuple> nextResult = - ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextAddressList, AddressInfo.TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(nextCursor, + Iterables.transform(nextAddressList, AddressInfo.TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); EasyMock.expect(computeRpcMock.listGlobalAddresses(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.expect(computeRpcMock.listGlobalAddresses(nextOptions)).andReturn(nextResult); @@ -1818,10 +1859,10 @@ public void testListRegionAddresses() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(addressList, AddressInfo.TO_PB_FUNCTION)); EasyMock.expect( - computeRpcMock.listRegionAddresses(REGION_ADDRESS_ID.region(), EMPTY_RPC_OPTIONS)) + computeRpcMock.listRegionAddresses(REGION_ADDRESS_ID.getRegion(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page
page = compute.listRegionAddresses(REGION_ADDRESS_ID.region()); + Page
page = compute.listRegionAddresses(REGION_ADDRESS_ID.getRegion()); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(addressList.toArray(), Iterables.toArray(page.values(), Address.class)); } @@ -1839,16 +1880,17 @@ public void testListRegionAddressesNextPage() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(addressList, AddressInfo.TO_PB_FUNCTION)); ComputeRpc.Tuple> nextResult = - ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextAddressList, AddressInfo.TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(nextCursor, + Iterables.transform(nextAddressList, AddressInfo.TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); EasyMock.expect( - computeRpcMock.listRegionAddresses(REGION_ADDRESS_ID.region(), EMPTY_RPC_OPTIONS)) + computeRpcMock.listRegionAddresses(REGION_ADDRESS_ID.getRegion(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.expect( - computeRpcMock.listRegionAddresses(REGION_ADDRESS_ID.region(), nextOptions)) + computeRpcMock.listRegionAddresses(REGION_ADDRESS_ID.getRegion(), nextOptions)) .andReturn(nextResult); EasyMock.replay(computeRpcMock); - Page
page = compute.listRegionAddresses(REGION_ADDRESS_ID.region()); + Page
page = compute.listRegionAddresses(REGION_ADDRESS_ID.getRegion()); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(addressList.toArray(), Iterables.toArray(page.values(), Address.class)); page = page.nextPage(); @@ -1862,11 +1904,11 @@ public void testListEmptyRegionAddresses() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.>of(null, addresses); EasyMock.expect( - computeRpcMock.listRegionAddresses(REGION_ADDRESS_ID.region(), EMPTY_RPC_OPTIONS)) + computeRpcMock.listRegionAddresses(REGION_ADDRESS_ID.getRegion(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); compute = options.service(); - Page
page = compute.listRegionAddresses(REGION_ADDRESS_ID.region()); + Page
page = compute.listRegionAddresses(REGION_ADDRESS_ID.getRegion()); assertNull(page.nextPageCursor()); assertArrayEquals(addresses.toArray(), Iterables.toArray(page.values(), Address.class)); } @@ -1881,10 +1923,10 @@ public void testListRegionAddressesWithOptions() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(addressList, AddressInfo.TO_PB_FUNCTION)); EasyMock.expect( - computeRpcMock.listRegionAddresses(REGION_ADDRESS_ID.region(), ADDRESS_LIST_OPTIONS)) + computeRpcMock.listRegionAddresses(REGION_ADDRESS_ID.getRegion(), ADDRESS_LIST_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page
page = compute.listRegionAddresses(REGION_ADDRESS_ID.region(), + Page
page = compute.listRegionAddresses(REGION_ADDRESS_ID.getRegion(), ADDRESS_LIST_PAGE_SIZE, ADDRESS_LIST_PAGE_TOKEN, ADDRESS_LIST_FILTER); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(addressList.toArray(), Iterables.toArray(page.values(), Address.class)); @@ -1919,7 +1961,8 @@ public void testAggregatedListAddressesNextPage() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(addressList, AddressInfo.TO_PB_FUNCTION)); ComputeRpc.Tuple> nextResult = - ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextAddressList, AddressInfo.TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(nextCursor, + Iterables.transform(nextAddressList, AddressInfo.TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); EasyMock.expect(computeRpcMock.listAddresses(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.expect(computeRpcMock.listAddresses(nextOptions)).andReturn(nextResult); @@ -1970,7 +2013,7 @@ public void testCreateGlobalAddress() { compute = options.service(); AddressId incompleteId = GlobalAddressId.of("address"); Operation operation = - compute.create(GLOBAL_ADDRESS.toBuilder().addressId(incompleteId).build()); + compute.create(GLOBAL_ADDRESS.toBuilder().setAddressId(incompleteId).build()); assertEquals(globalOperation, operation); } @@ -1983,7 +2026,8 @@ public void testCreateGlobalAddressWithOptions() { EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.create(GLOBAL_ADDRESS, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -1993,25 +2037,26 @@ public void testCreateGlobalAddressWithOptions() { @Test public void testCreateRegionAddress() { - EasyMock.expect(computeRpcMock.createRegionAddress(REGION_ADDRESS_ID.region(), + EasyMock.expect(computeRpcMock.createRegionAddress(REGION_ADDRESS_ID.getRegion(), REGION_ADDRESS.toPb(), EMPTY_RPC_OPTIONS)).andReturn(regionOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); AddressId incompleteId = RegionAddressId.of("region", "address"); Operation operation = - compute.create(REGION_ADDRESS.toBuilder().addressId(incompleteId).build()); + compute.create(REGION_ADDRESS.toBuilder().setAddressId(incompleteId).build()); assertEquals(regionOperation, operation); } @Test public void testCreateRegionAddressWithOptions() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.createRegionAddress(eq(REGION_ADDRESS_ID.region()), + EasyMock.expect(computeRpcMock.createRegionAddress(eq(REGION_ADDRESS_ID.getRegion()), eq(REGION_ADDRESS.toPb()), capture(capturedOptions))).andReturn(regionOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.create(REGION_ADDRESS, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -2021,8 +2066,8 @@ public void testCreateRegionAddressWithOptions() { @Test public void testCreateSnapshot() { - EasyMock.expect(computeRpcMock.createSnapshot(DISK_ID.zone(), DISK_ID.disk(), - SNAPSHOT_ID.snapshot(), null, EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); + EasyMock.expect(computeRpcMock.createSnapshot(DISK_ID.getZone(), DISK_ID.getDisk(), + SNAPSHOT_ID.getSnapshot(), null, EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.create(SNAPSHOT); @@ -2032,13 +2077,14 @@ public void testCreateSnapshot() { @Test public void testCreateSnapshotWithOptions() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.createSnapshot(eq(DISK_ID.zone()), eq(DISK_ID.disk()), - eq(SNAPSHOT_ID.snapshot()), EasyMock.isNull(), capture(capturedOptions))) + EasyMock.expect(computeRpcMock.createSnapshot(eq(DISK_ID.getZone()), eq(DISK_ID.getDisk()), + eq(SNAPSHOT_ID.getSnapshot()), EasyMock.isNull(), capture(capturedOptions))) .andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.create(SNAPSHOT, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -2048,32 +2094,33 @@ public void testCreateSnapshotWithOptions() { @Test public void testGetSnapshot() { - EasyMock.expect(computeRpcMock.getSnapshot(SNAPSHOT_ID.snapshot(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getSnapshot(SNAPSHOT_ID.getSnapshot(), EMPTY_RPC_OPTIONS)) .andReturn(SNAPSHOT.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); - Snapshot snapshot = compute.getSnapshot(SNAPSHOT_ID.snapshot()); + Snapshot snapshot = compute.getSnapshot(SNAPSHOT_ID.getSnapshot()); assertEquals(new Snapshot(compute, new SnapshotInfo.BuilderImpl(SNAPSHOT)), snapshot); } @Test public void testGetSnapshot_Null() { - EasyMock.expect(computeRpcMock.getSnapshot(SNAPSHOT_ID.snapshot(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getSnapshot(SNAPSHOT_ID.getSnapshot(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); - assertNull(compute.getSnapshot(SNAPSHOT_ID.snapshot())); + assertNull(compute.getSnapshot(SNAPSHOT_ID.getSnapshot())); } @Test public void testGetSnapshotWithSelectedFields() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.getSnapshot(eq(SNAPSHOT_ID.snapshot()), + EasyMock.expect(computeRpcMock.getSnapshot(eq(SNAPSHOT_ID.getSnapshot()), capture(capturedOptions))).andReturn(SNAPSHOT.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); - Snapshot snapshot = compute.getSnapshot(SNAPSHOT_ID.snapshot(), SNAPSHOT_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(SNAPSHOT_OPTION_FIELDS.rpcOption()); + Snapshot snapshot = compute.getSnapshot(SNAPSHOT_ID.getSnapshot(), SNAPSHOT_OPTION_FIELDS); + String selector = + (String) capturedOptions.getValue().get(SNAPSHOT_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -2083,22 +2130,23 @@ public void testGetSnapshotWithSelectedFields() { @Test public void testDeleteSnapshot_Operation() { - EasyMock.expect(computeRpcMock.deleteSnapshot(SNAPSHOT_ID.snapshot(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.deleteSnapshot(SNAPSHOT_ID.getSnapshot(), EMPTY_RPC_OPTIONS)) .andReturn(globalOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); - assertEquals(globalOperation, compute.deleteSnapshot(SNAPSHOT_ID.snapshot())); + assertEquals(globalOperation, compute.deleteSnapshot(SNAPSHOT_ID.getSnapshot())); } @Test public void testDeleteSnapshotWithSelectedFields_Operation() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.deleteSnapshot(eq(SNAPSHOT_ID.snapshot()), + EasyMock.expect(computeRpcMock.deleteSnapshot(eq(SNAPSHOT_ID.getSnapshot()), capture(capturedOptions))).andReturn(globalOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.deleteSnapshot(SNAPSHOT_ID, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -2108,7 +2156,7 @@ public void testDeleteSnapshotWithSelectedFields_Operation() { @Test public void testDeleteSnapshot_Null() { - EasyMock.expect(computeRpcMock.deleteSnapshot(SNAPSHOT_ID.snapshot(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.deleteSnapshot(SNAPSHOT_ID.getSnapshot(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -2144,7 +2192,8 @@ public void testListSnapshotsNextPage() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(snapshotList, SnapshotInfo.TO_PB_FUNCTION)); ComputeRpc.Tuple> nextResult = - ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextSnapshotList, SnapshotInfo.TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(nextCursor, + Iterables.transform(nextSnapshotList, SnapshotInfo.TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); EasyMock.expect(computeRpcMock.listSnapshots(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.expect(computeRpcMock.listSnapshots(nextOptions)).andReturn(nextResult); @@ -2205,7 +2254,8 @@ public void testCreateImageWithOptions() { EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.create(IMAGE, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -2216,7 +2266,7 @@ public void testCreateImageWithOptions() { @Test public void testGetImage() { EasyMock.expect( - computeRpcMock.getImage(IMAGE_ID.project(), IMAGE_ID.image(), EMPTY_RPC_OPTIONS)) + computeRpcMock.getImage(IMAGE_ID.getProject(), IMAGE_ID.getImage(), EMPTY_RPC_OPTIONS)) .andReturn(IMAGE.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -2227,7 +2277,7 @@ public void testGetImage() { @Test public void testGetImage_Null() { EasyMock.expect( - computeRpcMock.getImage(IMAGE_ID.project(), IMAGE_ID.image(), EMPTY_RPC_OPTIONS)) + computeRpcMock.getImage(IMAGE_ID.getProject(), IMAGE_ID.getImage(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -2237,12 +2287,12 @@ public void testGetImage_Null() { @Test public void testGetImageWithSelectedFields() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.getImage(eq(IMAGE_ID.project()), eq(IMAGE_ID.image()), + EasyMock.expect(computeRpcMock.getImage(eq(IMAGE_ID.getProject()), eq(IMAGE_ID.getImage()), capture(capturedOptions))).andReturn(IMAGE.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Image image = compute.getImage(IMAGE_ID, IMAGE_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(IMAGE_OPTION_FIELDS.rpcOption()); + String selector = (String) capturedOptions.getValue().get(IMAGE_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("sourceDisk")); @@ -2254,7 +2304,7 @@ public void testGetImageWithSelectedFields() { @Test public void testDeleteImage_Operation() { - EasyMock.expect(computeRpcMock.deleteImage(IMAGE_ID.project(), IMAGE_ID.image(), + EasyMock.expect(computeRpcMock.deleteImage(IMAGE_ID.getProject(), IMAGE_ID.getImage(), EMPTY_RPC_OPTIONS)).andReturn(globalOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -2264,12 +2314,13 @@ public void testDeleteImage_Operation() { @Test public void testDeleteImageWithSelectedFields_Operation() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.deleteImage(eq(PROJECT), eq(IMAGE_ID.image()), + EasyMock.expect(computeRpcMock.deleteImage(eq(PROJECT), eq(IMAGE_ID.getImage()), capture(capturedOptions))).andReturn(globalOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.deleteImage(ImageId.of("image"), OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -2279,7 +2330,7 @@ public void testDeleteImageWithSelectedFields_Operation() { @Test public void testDeleteImage_Null() { - EasyMock.expect(computeRpcMock.deleteImage(IMAGE_ID.project(), IMAGE_ID.image(), + EasyMock.expect(computeRpcMock.deleteImage(IMAGE_ID.getProject(), IMAGE_ID.getImage(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -2288,7 +2339,7 @@ public void testDeleteImage_Null() { @Test public void testDeprecateImage_Operation() { - EasyMock.expect(computeRpcMock.deprecateImage(IMAGE_ID.project(), IMAGE_ID.image(), + EasyMock.expect(computeRpcMock.deprecateImage(IMAGE_ID.getProject(), IMAGE_ID.getImage(), DEPRECATION_STATUS.toPb(), EMPTY_RPC_OPTIONS)).andReturn(globalOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -2298,13 +2349,14 @@ public void testDeprecateImage_Operation() { @Test public void testDeprecateImageWithSelectedFields_Operation() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.deprecateImage(eq(PROJECT), eq(IMAGE_ID.image()), + EasyMock.expect(computeRpcMock.deprecateImage(eq(PROJECT), eq(IMAGE_ID.getImage()), eq(DEPRECATION_STATUS.toPb()), capture(capturedOptions))).andReturn(globalOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.deprecate(ImageId.of("image"), DEPRECATION_STATUS, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -2314,7 +2366,7 @@ public void testDeprecateImageWithSelectedFields_Operation() { @Test public void testDeprecateImage_Null() { - EasyMock.expect(computeRpcMock.deprecateImage(IMAGE_ID.project(), IMAGE_ID.image(), + EasyMock.expect(computeRpcMock.deprecateImage(IMAGE_ID.getProject(), IMAGE_ID.getImage(), DEPRECATION_STATUS.toPb(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -2350,7 +2402,8 @@ public void testListImagesNextPage() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(imageList, ImageInfo.TO_PB_FUNCTION)); ComputeRpc.Tuple> nextResult = - ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextImageList, ImageInfo.TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(nextCursor, + Iterables.transform(nextImageList, ImageInfo.TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); EasyMock.expect(computeRpcMock.listImages(PROJECT, EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.expect(computeRpcMock.listImages(PROJECT, nextOptions)).andReturn(nextResult); @@ -2441,7 +2494,7 @@ public void testListImagesForProjectWithOptions() { @Test public void testGetDisk() { - EasyMock.expect(computeRpcMock.getDisk(DISK_ID.zone(), DISK_ID.disk(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getDisk(DISK_ID.getZone(), DISK_ID.getDisk(), EMPTY_RPC_OPTIONS)) .andReturn(DISK.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -2451,7 +2504,7 @@ public void testGetDisk() { @Test public void testGetDisk_Null() { - EasyMock.expect(computeRpcMock.getDisk(DISK_ID.zone(), DISK_ID.disk(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getDisk(DISK_ID.getZone(), DISK_ID.getDisk(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -2461,12 +2514,12 @@ public void testGetDisk_Null() { @Test public void testGetDiskWithSelectedFields() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.getDisk(eq(DISK_ID.zone()), eq(DISK_ID.disk()), + EasyMock.expect(computeRpcMock.getDisk(eq(DISK_ID.getZone()), eq(DISK_ID.getDisk()), capture(capturedOptions))).andReturn(DISK.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Disk disk = compute.getDisk(DISK_ID, DISK_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(DISK_OPTION_FIELDS.rpcOption()); + String selector = (String) capturedOptions.getValue().get(DISK_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("type")); assertTrue(selector.contains("sourceImage")); @@ -2479,7 +2532,8 @@ public void testGetDiskWithSelectedFields() { @Test public void testDeleteDisk_Operation() { - EasyMock.expect(computeRpcMock.deleteDisk(DISK_ID.zone(), DISK_ID.disk(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.deleteDisk( + DISK_ID.getZone(), DISK_ID.getDisk(), EMPTY_RPC_OPTIONS)) .andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -2489,12 +2543,13 @@ public void testDeleteDisk_Operation() { @Test public void testDeleteDiskWithSelectedFields_Operation() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.deleteDisk(eq(DISK_ID.zone()), eq(DISK_ID.disk()), + EasyMock.expect(computeRpcMock.deleteDisk(eq(DISK_ID.getZone()), eq(DISK_ID.getDisk()), capture(capturedOptions))).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.deleteDisk(DISK_ID, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -2504,7 +2559,8 @@ public void testDeleteDiskWithSelectedFields_Operation() { @Test public void testDeleteDisk_Null() { - EasyMock.expect(computeRpcMock.deleteDisk(DISK_ID.zone(), DISK_ID.disk(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.deleteDisk( + DISK_ID.getZone(), DISK_ID.getDisk(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -2520,10 +2576,10 @@ public void testListDisks() { new Disk(compute, new DiskInfo.BuilderImpl(DISK))); ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(diskList, DiskInfo.TO_PB_FUNCTION)); - EasyMock.expect(computeRpcMock.listDisks(DISK_ID.zone(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.listDisks(DISK_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page page = compute.listDisks(DISK_ID.zone()); + Page page = compute.listDisks(DISK_ID.getZone()); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(diskList.toArray(), Iterables.toArray(page.values(), Disk.class)); } @@ -2543,10 +2599,11 @@ public void testListDisksNextPage() { ComputeRpc.Tuple> nextResult = ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextDiskList, DiskInfo.TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); - EasyMock.expect(computeRpcMock.listDisks(DISK_ID.zone(), EMPTY_RPC_OPTIONS)).andReturn(result); - EasyMock.expect(computeRpcMock.listDisks(DISK_ID.zone(), nextOptions)).andReturn(nextResult); + EasyMock.expect(computeRpcMock.listDisks(DISK_ID.getZone(), EMPTY_RPC_OPTIONS)) + .andReturn(result); + EasyMock.expect(computeRpcMock.listDisks(DISK_ID.getZone(), nextOptions)).andReturn(nextResult); EasyMock.replay(computeRpcMock); - Page page = compute.listDisks(DISK_ID.zone()); + Page page = compute.listDisks(DISK_ID.getZone()); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(diskList.toArray(), Iterables.toArray(page.values(), Disk.class)); page = page.nextPage(); @@ -2560,10 +2617,10 @@ public void testListEmptyDisks() { ImmutableList disks = ImmutableList.of(); ComputeRpc.Tuple> result = ComputeRpc.Tuple.>of(null, disks); - EasyMock.expect(computeRpcMock.listDisks(DISK_ID.zone(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.listDisks(DISK_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page page = compute.listDisks(DISK_ID.zone()); + Page page = compute.listDisks(DISK_ID.getZone()); assertNull(page.nextPageCursor()); assertArrayEquals(disks.toArray(), Iterables.toArray(page.values(), Disk.class)); } @@ -2577,11 +2634,11 @@ public void testListDisksWithOptions() { new Disk(compute, new DiskInfo.BuilderImpl(DISK))); ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(diskList, DiskInfo.TO_PB_FUNCTION)); - EasyMock.expect(computeRpcMock.listDisks(DISK_ID.zone(), DISK_LIST_OPTIONS)) + EasyMock.expect(computeRpcMock.listDisks(DISK_ID.getZone(), DISK_LIST_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page page = compute.listDisks(DISK_ID.zone(), DISK_LIST_PAGE_SIZE, DISK_LIST_PAGE_TOKEN, - DISK_LIST_FILTER); + Page page =compute.listDisks( + DISK_ID.getZone(), DISK_LIST_PAGE_SIZE, DISK_LIST_PAGE_TOKEN, DISK_LIST_FILTER); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(diskList.toArray(), Iterables.toArray(page.values(), Disk.class)); } @@ -2660,15 +2717,15 @@ public void testAggregatedListDisksWithOptions() { @Test public void testCreateDisk() { - EasyMock.expect(computeRpcMock.createDisk(DISK_ID.zone(), DISK.toPb(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.createDisk(DISK_ID.getZone(), DISK.toPb(), EMPTY_RPC_OPTIONS)) .andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); DiskId diskId = DiskId.of("zone", "disk"); DiskTypeId diskTypeId = DiskTypeId.of("zone", "diskType"); DiskInfo disk = DISK.toBuilder() - .diskId(diskId) - .configuration(StandardDiskConfiguration.of(diskTypeId)) + .setDiskId(diskId) + .setConfiguration(StandardDiskConfiguration.of(diskTypeId)) .build(); Operation operation = compute.create(disk); assertEquals(zoneOperation, operation); @@ -2677,12 +2734,13 @@ public void testCreateDisk() { @Test public void testCreateDiskWithOptions() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.createDisk(eq(DISK_ID.zone()), eq(DISK.toPb()), + EasyMock.expect(computeRpcMock.createDisk(eq(DISK_ID.getZone()), eq(DISK.toPb()), capture(capturedOptions))).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.create(DISK, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -2692,7 +2750,7 @@ public void testCreateDiskWithOptions() { @Test public void testResizeDisk_Operation() { - EasyMock.expect(computeRpcMock.resizeDisk(DISK_ID.zone(), DISK_ID.disk(), 42L, + EasyMock.expect(computeRpcMock.resizeDisk(DISK_ID.getZone(), DISK_ID.getDisk(), 42L, EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -2702,12 +2760,13 @@ public void testResizeDisk_Operation() { @Test public void testResizeDiskWithSelectedFields_Operation() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.resizeDisk(eq(DISK_ID.zone()), eq(DISK_ID.disk()), eq(42L), + EasyMock.expect(computeRpcMock.resizeDisk(eq(DISK_ID.getZone()), eq(DISK_ID.getDisk()), eq(42L), capture(capturedOptions))).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.resize(DISK_ID, 42L, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -2717,7 +2776,7 @@ public void testResizeDiskWithSelectedFields_Operation() { @Test public void testResizeDisk_Null() { - EasyMock.expect(computeRpcMock.resizeDisk(DISK_ID.zone(), DISK_ID.disk(), 42L, + EasyMock.expect(computeRpcMock.resizeDisk(DISK_ID.getZone(), DISK_ID.getDisk(), 42L, EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -2726,8 +2785,9 @@ public void testResizeDisk_Null() { @Test public void testGetSubnetwork() { - EasyMock.expect(computeRpcMock.getSubnetwork(SUBNETWORK_ID.region(), SUBNETWORK_ID.subnetwork(), - EMPTY_RPC_OPTIONS)).andReturn(SUBNETWORK.toPb()); + EasyMock.expect(computeRpcMock.getSubnetwork( + SUBNETWORK_ID.getRegion(), SUBNETWORK_ID.getSubnetwork(), EMPTY_RPC_OPTIONS)) + .andReturn(SUBNETWORK.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Subnetwork subnetwork = compute.getSubnetwork(SUBNETWORK_ID); @@ -2736,8 +2796,9 @@ public void testGetSubnetwork() { @Test public void testGetSubnetwork_Null() { - EasyMock.expect(computeRpcMock.getSubnetwork(SUBNETWORK_ID.region(), SUBNETWORK_ID.subnetwork(), - EMPTY_RPC_OPTIONS)).andReturn(null); + EasyMock.expect(computeRpcMock.getSubnetwork( + SUBNETWORK_ID.getRegion(), SUBNETWORK_ID.getSubnetwork(), EMPTY_RPC_OPTIONS)) + .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); assertNull(compute.getSubnetwork(SUBNETWORK_ID)); @@ -2746,12 +2807,13 @@ public void testGetSubnetwork_Null() { @Test public void testGetSubnetworkWithSelectedFields() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.getSubnetwork(eq(SUBNETWORK_ID.region()), - eq(SUBNETWORK_ID.subnetwork()), capture(capturedOptions))).andReturn(SUBNETWORK.toPb()); + EasyMock.expect(computeRpcMock.getSubnetwork(eq(SUBNETWORK_ID.getRegion()), + eq(SUBNETWORK_ID.getSubnetwork()), capture(capturedOptions))).andReturn(SUBNETWORK.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Subnetwork subnetwork = compute.getSubnetwork(SUBNETWORK_ID, SUBNETWORK_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(SUBNETWORK_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(SUBNETWORK_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -2761,8 +2823,8 @@ public void testGetSubnetworkWithSelectedFields() { @Test public void testDeleteSubnetwork_Operation() { - EasyMock.expect(computeRpcMock.deleteSubnetwork(SUBNETWORK_ID.region(), - SUBNETWORK_ID.subnetwork(), EMPTY_RPC_OPTIONS)).andReturn(regionOperation.toPb()); + EasyMock.expect(computeRpcMock.deleteSubnetwork(SUBNETWORK_ID.getRegion(), + SUBNETWORK_ID.getSubnetwork(), EMPTY_RPC_OPTIONS)).andReturn(regionOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); assertEquals(regionOperation, compute.deleteSubnetwork(SUBNETWORK_ID)); @@ -2771,13 +2833,14 @@ public void testDeleteSubnetwork_Operation() { @Test public void testDeleteSubnetworkWithSelectedFields_Operation() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.deleteSubnetwork(eq(SUBNETWORK_ID.region()), - eq(SUBNETWORK_ID.subnetwork()), capture(capturedOptions))) + EasyMock.expect(computeRpcMock.deleteSubnetwork(eq(SUBNETWORK_ID.getRegion()), + eq(SUBNETWORK_ID.getSubnetwork()), capture(capturedOptions))) .andReturn(regionOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.deleteSubnetwork(SUBNETWORK_ID, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -2787,8 +2850,8 @@ public void testDeleteSubnetworkWithSelectedFields_Operation() { @Test public void testDeleteSubnetwork_Null() { - EasyMock.expect(computeRpcMock.deleteSubnetwork(SUBNETWORK_ID.region(), - SUBNETWORK_ID.subnetwork(), EMPTY_RPC_OPTIONS)).andReturn(null); + EasyMock.expect(computeRpcMock.deleteSubnetwork(SUBNETWORK_ID.getRegion(), + SUBNETWORK_ID.getSubnetwork(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); assertNull(compute.deleteSubnetwork(SUBNETWORK_ID)); @@ -2802,11 +2865,12 @@ public void testListSubnetworks() { new Subnetwork(compute, new SubnetworkInfo.BuilderImpl(SUBNETWORK)), new Subnetwork(compute, new SubnetworkInfo.BuilderImpl(SUBNETWORK))); ComputeRpc.Tuple> result = - ComputeRpc.Tuple.of(cursor, Iterables.transform(subnetworkList, SubnetworkInfo.TO_PB_FUNCTION)); - EasyMock.expect(computeRpcMock.listSubnetworks(SUBNETWORK_ID.region(), EMPTY_RPC_OPTIONS)) + ComputeRpc.Tuple.of(cursor, + Iterables.transform(subnetworkList, SubnetworkInfo.TO_PB_FUNCTION)); + EasyMock.expect(computeRpcMock.listSubnetworks(SUBNETWORK_ID.getRegion(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page page = compute.listSubnetworks(SUBNETWORK_ID.region()); + Page page = compute.listSubnetworks(SUBNETWORK_ID.getRegion()); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(subnetworkList.toArray(), Iterables.toArray(page.values(), Subnetwork.class)); } @@ -2822,17 +2886,18 @@ public void testListSubnetworksNextPage() { ImmutableList nextSubnetworkList = ImmutableList.of( new Subnetwork(compute, new SubnetworkInfo.BuilderImpl(SUBNETWORK))); ComputeRpc.Tuple> result = - ComputeRpc.Tuple.of(cursor, Iterables.transform(subnetworkList, SubnetworkInfo.TO_PB_FUNCTION)); - ComputeRpc.Tuple> nextResult = - ComputeRpc.Tuple.of(nextCursor, + ComputeRpc.Tuple.of(cursor, + Iterables.transform(subnetworkList, SubnetworkInfo.TO_PB_FUNCTION)); + ComputeRpc.Tuple> + nextResult = ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextSubnetworkList, SubnetworkInfo.TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); - EasyMock.expect(computeRpcMock.listSubnetworks(SUBNETWORK_ID.region(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.listSubnetworks(SUBNETWORK_ID.getRegion(), EMPTY_RPC_OPTIONS)) .andReturn(result); - EasyMock.expect(computeRpcMock.listSubnetworks(SUBNETWORK_ID.region(), nextOptions)) + EasyMock.expect(computeRpcMock.listSubnetworks(SUBNETWORK_ID.getRegion(), nextOptions)) .andReturn(nextResult); EasyMock.replay(computeRpcMock); - Page page = compute.listSubnetworks(SUBNETWORK_ID.region()); + Page page = compute.listSubnetworks(SUBNETWORK_ID.getRegion()); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(subnetworkList.toArray(), Iterables.toArray(page.values(), Subnetwork.class)); page = page.nextPage(); @@ -2849,10 +2914,10 @@ public void testListEmptySubnetworks() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.>of(null, subnetworks); - EasyMock.expect(computeRpcMock.listSubnetworks(SUBNETWORK_ID.region(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.listSubnetworks(SUBNETWORK_ID.getRegion(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page page = compute.listSubnetworks(SUBNETWORK_ID.region()); + Page page = compute.listSubnetworks(SUBNETWORK_ID.getRegion()); assertNull(page.nextPageCursor()); assertArrayEquals(subnetworks.toArray(), Iterables.toArray(page.values(), Subnetwork.class)); } @@ -2865,11 +2930,13 @@ public void testListSubnetworksWithOptions() { new Subnetwork(compute, new SubnetworkInfo.BuilderImpl(SUBNETWORK)), new Subnetwork(compute, new SubnetworkInfo.BuilderImpl(SUBNETWORK))); ComputeRpc.Tuple> result = - ComputeRpc.Tuple.of(cursor, Iterables.transform(subnetworkList, SubnetworkInfo.TO_PB_FUNCTION)); - EasyMock.expect(computeRpcMock.listSubnetworks(SUBNETWORK_ID.region(), SUBNETWORK_LIST_OPTIONS)) + ComputeRpc.Tuple.of(cursor, + Iterables.transform(subnetworkList, SubnetworkInfo.TO_PB_FUNCTION)); + EasyMock.expect(computeRpcMock.listSubnetworks( + SUBNETWORK_ID.getRegion(), SUBNETWORK_LIST_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page page = compute.listSubnetworks(SUBNETWORK_ID.region(), + Page page = compute.listSubnetworks(SUBNETWORK_ID.getRegion(), SUBNETWORK_LIST_PAGE_SIZE, SUBNETWORK_LIST_PAGE_TOKEN, SUBNETWORK_LIST_FILTER); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(subnetworkList.toArray(), Iterables.toArray(page.values(), Subnetwork.class)); @@ -2883,7 +2950,8 @@ public void testAggregatedListSubnetworks() { new Subnetwork(compute, new SubnetworkInfo.BuilderImpl(SUBNETWORK)), new Subnetwork(compute, new SubnetworkInfo.BuilderImpl(SUBNETWORK))); ComputeRpc.Tuple> result = - ComputeRpc.Tuple.of(cursor, Iterables.transform(subnetworkList, SubnetworkInfo.TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(cursor, + Iterables.transform(subnetworkList, SubnetworkInfo.TO_PB_FUNCTION)); EasyMock.expect(computeRpcMock.listSubnetworks(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.replay(computeRpcMock); Page page = compute.listSubnetworks(); @@ -2902,9 +2970,10 @@ public void testAggregatedListSubnetworksNextPage() { ImmutableList nextSubnetworkList = ImmutableList.of( new Subnetwork(compute, new SubnetworkInfo.BuilderImpl(SUBNETWORK))); ComputeRpc.Tuple> result = - ComputeRpc.Tuple.of(cursor, Iterables.transform(subnetworkList, SubnetworkInfo.TO_PB_FUNCTION)); - ComputeRpc.Tuple> nextResult = - ComputeRpc.Tuple.of(nextCursor, + ComputeRpc.Tuple.of(cursor, + Iterables.transform(subnetworkList, SubnetworkInfo.TO_PB_FUNCTION)); + ComputeRpc.Tuple> + nextResult = ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextSubnetworkList, SubnetworkInfo.TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); EasyMock.expect(computeRpcMock.listSubnetworks(EMPTY_RPC_OPTIONS)).andReturn(result); @@ -2942,7 +3011,8 @@ public void testAggregatedListSubnetworksWithOptions() { new Subnetwork(compute, new SubnetworkInfo.BuilderImpl(SUBNETWORK)), new Subnetwork(compute, new SubnetworkInfo.BuilderImpl(SUBNETWORK))); ComputeRpc.Tuple> result = - ComputeRpc.Tuple.of(cursor, Iterables.transform(subnetworkList, SubnetworkInfo.TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(cursor, + Iterables.transform(subnetworkList, SubnetworkInfo.TO_PB_FUNCTION)); EasyMock.expect(computeRpcMock.listSubnetworks(SUBNETWORK_LIST_OPTIONS)).andReturn(result); EasyMock.replay(computeRpcMock); Page page = compute.listSubnetworks(SUBNETWORK_AGGREGATED_LIST_PAGE_SIZE, @@ -2953,7 +3023,7 @@ public void testAggregatedListSubnetworksWithOptions() { @Test public void testCreateSubnetwork() { - EasyMock.expect(computeRpcMock.createSubnetwork(SUBNETWORK_ID.region(), SUBNETWORK.toPb(), + EasyMock.expect(computeRpcMock.createSubnetwork(SUBNETWORK_ID.getRegion(), SUBNETWORK.toPb(), EMPTY_RPC_OPTIONS)).andReturn(regionOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -2967,12 +3037,13 @@ public void testCreateSubnetwork() { @Test public void testCreateSubnetworkWithOptions() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.createSubnetwork(eq(SUBNETWORK_ID.region()), + EasyMock.expect(computeRpcMock.createSubnetwork(eq(SUBNETWORK_ID.getRegion()), eq(SUBNETWORK.toPb()), capture(capturedOptions))).andReturn(regionOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.create(SUBNETWORK, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -2982,32 +3053,33 @@ public void testCreateSubnetworkWithOptions() { @Test public void testGetNetwork() { - EasyMock.expect(computeRpcMock.getNetwork(NETWORK_ID.network(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getNetwork(NETWORK_ID.getNetwork(), EMPTY_RPC_OPTIONS)) .andReturn(NETWORK.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); - Network network = compute.getNetwork(NETWORK_ID.network()); + Network network = compute.getNetwork(NETWORK_ID.getNetwork()); assertEquals(new Network(compute, new NetworkInfo.BuilderImpl(NETWORK)), network); } @Test public void testGetNetwork_Null() { - EasyMock.expect(computeRpcMock.getNetwork(NETWORK_ID.network(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getNetwork(NETWORK_ID.getNetwork(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); - assertNull(compute.getNetwork(NETWORK_ID.network())); + assertNull(compute.getNetwork(NETWORK_ID.getNetwork())); } @Test public void testGetNetworkWithSelectedFields() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.getNetwork(eq(NETWORK_ID.network()), capture(capturedOptions))) + EasyMock.expect(computeRpcMock.getNetwork(eq( + NETWORK_ID.getNetwork()), capture(capturedOptions))) .andReturn(NETWORK.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); - Network network = compute.getNetwork(NETWORK_ID.network(), NETWORK_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(NETWORK_OPTION_FIELDS.rpcOption()); + Network network = compute.getNetwork(NETWORK_ID.getNetwork(), NETWORK_OPTION_FIELDS); + String selector = (String) capturedOptions.getValue().get(NETWORK_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3019,7 +3091,7 @@ public void testGetNetworkWithSelectedFields() { @Test public void testDeleteNetwork_Operation() { - EasyMock.expect(computeRpcMock.deleteNetwork(NETWORK_ID.network(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.deleteNetwork(NETWORK_ID.getNetwork(), EMPTY_RPC_OPTIONS)) .andReturn(globalOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3029,12 +3101,13 @@ public void testDeleteNetwork_Operation() { @Test public void testDeleteNetworkWithSelectedFields_Operation() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.deleteNetwork(eq(NETWORK_ID.network()), + EasyMock.expect(computeRpcMock.deleteNetwork(eq(NETWORK_ID.getNetwork()), capture(capturedOptions))).andReturn(globalOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.deleteNetwork(NETWORK_ID, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3044,7 +3117,7 @@ public void testDeleteNetworkWithSelectedFields_Operation() { @Test public void testDeleteNetwork_Null() { - EasyMock.expect(computeRpcMock.deleteNetwork(NETWORK_ID.network(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.deleteNetwork(NETWORK_ID.getNetwork(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3080,7 +3153,8 @@ public void testListNetworksNextPage() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(networkList, NetworkInfo.TO_PB_FUNCTION)); ComputeRpc.Tuple> nextResult = - ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextNetworkList, NetworkInfo.TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(nextCursor, + Iterables.transform(nextNetworkList, NetworkInfo.TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); EasyMock.expect(computeRpcMock.listNetworks(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.expect(computeRpcMock.listNetworks(nextOptions)).andReturn(nextResult); @@ -3143,7 +3217,8 @@ public void testCreateNetworkWithOptions() { EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.create(NETWORK, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3153,7 +3228,7 @@ public void testCreateNetworkWithOptions() { @Test public void testGetInstance() { - EasyMock.expect(computeRpcMock.getInstance(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.getInstance(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), EMPTY_RPC_OPTIONS)).andReturn(INSTANCE.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3163,7 +3238,7 @@ public void testGetInstance() { @Test public void testGetInstance_Null() { - EasyMock.expect(computeRpcMock.getInstance(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.getInstance(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3173,12 +3248,14 @@ public void testGetInstance_Null() { @Test public void testGetInstanceWithSelectedFields() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.getInstance(eq(INSTANCE_ID.zone()), eq(INSTANCE_ID.instance()), - capture(capturedOptions))).andReturn(INSTANCE.toPb()); + EasyMock.expect(computeRpcMock.getInstance( + eq(INSTANCE_ID.getZone()), eq(INSTANCE_ID.getInstance()), capture(capturedOptions))) + .andReturn(INSTANCE.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Instance instance = compute.getInstance(INSTANCE_ID, INSTANCE_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(INSTANCE_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(INSTANCE_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3188,7 +3265,7 @@ public void testGetInstanceWithSelectedFields() { @Test public void testDeleteInstance_Operation() { - EasyMock.expect(computeRpcMock.deleteInstance(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.deleteInstance(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3198,12 +3275,13 @@ public void testDeleteInstance_Operation() { @Test public void testDeleteInstanceWithSelectedFields_Operation() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.deleteInstance(eq(INSTANCE_ID.zone()), - eq(INSTANCE_ID.instance()), capture(capturedOptions))).andReturn(zoneOperation.toPb()); + EasyMock.expect(computeRpcMock.deleteInstance(eq(INSTANCE_ID.getZone()), + eq(INSTANCE_ID.getInstance()), capture(capturedOptions))).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.deleteInstance(INSTANCE_ID, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3213,7 +3291,7 @@ public void testDeleteInstanceWithSelectedFields_Operation() { @Test public void testDeleteInstance_Null() { - EasyMock.expect(computeRpcMock.deleteInstance(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.deleteInstance(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3229,10 +3307,10 @@ public void testListInstances() { new Instance(compute, new InstanceInfo.BuilderImpl(INSTANCE))); ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(instanceList, InstanceInfo.TO_PB_FUNCTION)); - EasyMock.expect(computeRpcMock.listInstances(INSTANCE_ID.zone(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.listInstances(INSTANCE_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page page = compute.listInstances(INSTANCE_ID.zone()); + Page page = compute.listInstances(INSTANCE_ID.getZone()); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(instanceList.toArray(), Iterables.toArray(page.values(), Instance.class)); } @@ -3250,14 +3328,15 @@ public void testListInstancesNextPage() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(instanceList, InstanceInfo.TO_PB_FUNCTION)); ComputeRpc.Tuple> nextResult = - ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextInstanceList, InstanceInfo.TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(nextCursor, + Iterables.transform(nextInstanceList, InstanceInfo.TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); - EasyMock.expect(computeRpcMock.listInstances(INSTANCE_ID.zone(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.listInstances(INSTANCE_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); - EasyMock.expect(computeRpcMock.listInstances(INSTANCE_ID.zone(), nextOptions)) + EasyMock.expect(computeRpcMock.listInstances(INSTANCE_ID.getZone(), nextOptions)) .andReturn(nextResult); EasyMock.replay(computeRpcMock); - Page page = compute.listInstances(INSTANCE_ID.zone()); + Page page = compute.listInstances(INSTANCE_ID.getZone()); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(instanceList.toArray(), Iterables.toArray(page.values(), Instance.class)); page = page.nextPage(); @@ -3271,10 +3350,10 @@ public void testListEmptyInstances() { ImmutableList instances = ImmutableList.of(); ComputeRpc.Tuple> result = ComputeRpc.Tuple.>of(null, instances); - EasyMock.expect(computeRpcMock.listInstances(INSTANCE_ID.zone(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.listInstances(INSTANCE_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page page = compute.listInstances(INSTANCE_ID.zone()); + Page page = compute.listInstances(INSTANCE_ID.getZone()); assertNull(page.nextPageCursor()); assertArrayEquals(instances.toArray(), Iterables.toArray(page.values(), Instance.class)); } @@ -3288,10 +3367,10 @@ public void testListInstancesWithOptions() { new Instance(compute, new InstanceInfo.BuilderImpl(INSTANCE))); ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(instanceList, InstanceInfo.TO_PB_FUNCTION)); - EasyMock.expect(computeRpcMock.listInstances(INSTANCE_ID.zone(), INSTANCE_LIST_OPTIONS)) + EasyMock.expect(computeRpcMock.listInstances(INSTANCE_ID.getZone(), INSTANCE_LIST_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); - Page page = compute.listInstances(INSTANCE_ID.zone(), INSTANCE_LIST_PAGE_SIZE, + Page page = compute.listInstances(INSTANCE_ID.getZone(), INSTANCE_LIST_PAGE_SIZE, INSTANCE_LIST_PAGE_TOKEN, INSTANCE_LIST_FILTER); assertEquals(cursor, page.nextPageCursor()); assertArrayEquals(instanceList.toArray(), Iterables.toArray(page.values(), Instance.class)); @@ -3326,7 +3405,8 @@ public void testAggregatedListInstancesNextPage() { ComputeRpc.Tuple> result = ComputeRpc.Tuple.of(cursor, Iterables.transform(instanceList, InstanceInfo.TO_PB_FUNCTION)); ComputeRpc.Tuple> nextResult = - ComputeRpc.Tuple.of(nextCursor, Iterables.transform(nextInstanceList, InstanceInfo.TO_PB_FUNCTION)); + ComputeRpc.Tuple.of(nextCursor, + Iterables.transform(nextInstanceList, InstanceInfo.TO_PB_FUNCTION)); Map nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); EasyMock.expect(computeRpcMock.listInstances(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.expect(computeRpcMock.listInstances(nextOptions)).andReturn(nextResult); @@ -3372,7 +3452,7 @@ public void testAggregatedListInstancesWithOptions() { @Test public void testCreateInstance() { - EasyMock.expect(computeRpcMock.createInstance(INSTANCE_ID.zone(), INSTANCE.toPb(), + EasyMock.expect(computeRpcMock.createInstance(INSTANCE_ID.getZone(), INSTANCE.toPb(), EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3386,12 +3466,13 @@ public void testCreateInstance() { @Test public void testCreateInstanceWithOptions() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.createInstance(eq(INSTANCE_ID.zone()), eq(INSTANCE.toPb()), + EasyMock.expect(computeRpcMock.createInstance(eq(INSTANCE_ID.getZone()), eq(INSTANCE.toPb()), capture(capturedOptions))).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.create(INSTANCE, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3402,7 +3483,7 @@ public void testCreateInstanceWithOptions() { @Test public void testAddAccessConfig_Operation() { AccessConfig accessConfig = AccessConfig.of("192.168.1.1"); - EasyMock.expect(computeRpcMock.addAccessConfig(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.addAccessConfig(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), "networkInterface", accessConfig.toPb(), EMPTY_RPC_OPTIONS)) .andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); @@ -3415,14 +3496,15 @@ public void testAddAccessConfig_Operation() { public void testAddAccessConfigWithSelectedFields_Operation() { Capture> capturedOptions = Capture.newInstance(); AccessConfig accessConfig = AccessConfig.of("192.168.1.1"); - EasyMock.expect(computeRpcMock.addAccessConfig(eq(INSTANCE_ID.zone()), - eq(INSTANCE_ID.instance()), eq("networkInterface"), eq(accessConfig.toPb()), + EasyMock.expect(computeRpcMock.addAccessConfig(eq(INSTANCE_ID.getZone()), + eq(INSTANCE_ID.getInstance()), eq("networkInterface"), eq(accessConfig.toPb()), capture(capturedOptions))).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.addAccessConfig(INSTANCE_ID, "networkInterface", accessConfig, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3433,7 +3515,7 @@ public void testAddAccessConfigWithSelectedFields_Operation() { @Test public void testAddAccessConfig_Null() { AccessConfig accessConfig = AccessConfig.of("192.168.1.1"); - EasyMock.expect(computeRpcMock.addAccessConfig(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.addAccessConfig(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), "networkInterface", accessConfig.toPb(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3443,7 +3525,7 @@ public void testAddAccessConfig_Null() { @Test public void testAttachDisk_Operation() { AttachedDisk attachedDisk = AttachedDisk.of(PERSISTENT_DISK_CONFIGURATION); - EasyMock.expect(computeRpcMock.attachDisk(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.attachDisk(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), attachedDisk.toPb(), EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3454,13 +3536,15 @@ public void testAttachDisk_Operation() { public void testAttachDiskWithSelectedFields_Operation() { AttachedDisk attachedDisk = AttachedDisk.of(PERSISTENT_DISK_CONFIGURATION); Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.attachDisk(eq(INSTANCE_ID.zone()), eq(INSTANCE_ID.instance()), - eq(attachedDisk.toPb()), capture(capturedOptions))).andReturn(zoneOperation.toPb()); + EasyMock.expect(computeRpcMock.attachDisk( + eq(INSTANCE_ID.getZone()), eq(INSTANCE_ID.getInstance()), eq(attachedDisk.toPb()), + capture(capturedOptions))).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.attachDisk(INSTANCE_ID, PERSISTENT_DISK_CONFIGURATION, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3471,7 +3555,7 @@ public void testAttachDiskWithSelectedFields_Operation() { @Test public void testAttachDisk_Null() { AttachedDisk attachedDisk = AttachedDisk.of(PERSISTENT_DISK_CONFIGURATION); - EasyMock.expect(computeRpcMock.attachDisk(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.attachDisk(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), attachedDisk.toPb(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3481,7 +3565,7 @@ public void testAttachDisk_Null() { @Test public void testAttachDiskName_Operation() { AttachedDisk attachedDisk = AttachedDisk.of("dev0", PERSISTENT_DISK_CONFIGURATION); - EasyMock.expect(computeRpcMock.attachDisk(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.attachDisk(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), attachedDisk.toPb(), EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3493,13 +3577,15 @@ public void testAttachDiskName_Operation() { public void testAttachDiskNameWithSelectedFields_Operation() { AttachedDisk attachedDisk = AttachedDisk.of("dev0", PERSISTENT_DISK_CONFIGURATION); Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.attachDisk(eq(INSTANCE_ID.zone()), eq(INSTANCE_ID.instance()), - eq(attachedDisk.toPb()), capture(capturedOptions))).andReturn(zoneOperation.toPb()); + EasyMock.expect(computeRpcMock.attachDisk( + eq(INSTANCE_ID.getZone()), eq(INSTANCE_ID.getInstance()), eq(attachedDisk.toPb()), + capture(capturedOptions))).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.attachDisk(INSTANCE_ID, "dev0", PERSISTENT_DISK_CONFIGURATION, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3510,7 +3596,7 @@ public void testAttachDiskNameWithSelectedFields_Operation() { @Test public void testAttachDiskName_Null() { AttachedDisk attachedDisk = AttachedDisk.of("dev0", PERSISTENT_DISK_CONFIGURATION); - EasyMock.expect(computeRpcMock.attachDisk(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.attachDisk(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), attachedDisk.toPb(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3519,8 +3605,9 @@ public void testAttachDiskName_Null() { @Test public void testDeleteAccessConfig_Operation() { - EasyMock.expect(computeRpcMock.deleteAccessConfig(INSTANCE_ID.zone(), INSTANCE_ID.instance(), - "networkInterface", "accessConfig", EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); + EasyMock.expect(computeRpcMock.deleteAccessConfig(INSTANCE_ID.getZone(), + INSTANCE_ID.getInstance(), "networkInterface", "accessConfig", EMPTY_RPC_OPTIONS)) + .andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); assertEquals(zoneOperation, @@ -3530,14 +3617,15 @@ public void testDeleteAccessConfig_Operation() { @Test public void testDeleteAccessConfigWithSelectedFields_Operation() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.deleteAccessConfig(eq(INSTANCE_ID.zone()), - eq(INSTANCE_ID.instance()), eq("networkInterface"), eq("accessConfig"), + EasyMock.expect(computeRpcMock.deleteAccessConfig(eq(INSTANCE_ID.getZone()), + eq(INSTANCE_ID.getInstance()), eq("networkInterface"), eq("accessConfig"), capture(capturedOptions))).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.deleteAccessConfig(INSTANCE_ID, "networkInterface", "accessConfig", OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3547,8 +3635,9 @@ public void testDeleteAccessConfigWithSelectedFields_Operation() { @Test public void testDeleteAccessConfig_Null() { - EasyMock.expect(computeRpcMock.deleteAccessConfig(INSTANCE_ID.zone(), INSTANCE_ID.instance(), - "networkInterface", "accessConfig", EMPTY_RPC_OPTIONS)).andReturn(null); + EasyMock.expect(computeRpcMock.deleteAccessConfig(INSTANCE_ID.getZone(), + INSTANCE_ID.getInstance(), "networkInterface", "accessConfig", EMPTY_RPC_OPTIONS)) + .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); assertNull(compute.deleteAccessConfig(INSTANCE_ID, "networkInterface", "accessConfig")); @@ -3556,7 +3645,7 @@ public void testDeleteAccessConfig_Null() { @Test public void testDetachDisk_Operation() { - EasyMock.expect(computeRpcMock.detachDisk(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.detachDisk(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), "device", EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3566,13 +3655,14 @@ public void testDetachDisk_Operation() { @Test public void testDetachDiskWithSelectedFields_Operation() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.detachDisk(eq(INSTANCE_ID.zone()), - eq(INSTANCE_ID.instance()), eq("device"), capture(capturedOptions))) + EasyMock.expect(computeRpcMock.detachDisk(eq(INSTANCE_ID.getZone()), + eq(INSTANCE_ID.getInstance()), eq("device"), capture(capturedOptions))) .andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.detachDisk(INSTANCE_ID, "device", OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3582,8 +3672,8 @@ public void testDetachDiskWithSelectedFields_Operation() { @Test public void testDetachDisk_Null() { - EasyMock.expect(computeRpcMock.detachDisk(INSTANCE_ID.zone(), INSTANCE_ID.instance(), "device", - EMPTY_RPC_OPTIONS)).andReturn(null); + EasyMock.expect(computeRpcMock.detachDisk(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), + "device", EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); assertNull(compute.detachDisk(INSTANCE_ID, "device")); @@ -3592,8 +3682,8 @@ public void testDetachDisk_Null() { @Test public void testSerialPortOutputFromPort() { String output = "output"; - EasyMock.expect(computeRpcMock.getSerialPortOutput(INSTANCE_ID.zone(), INSTANCE_ID.instance(), - 2, EMPTY_RPC_OPTIONS)).andReturn(output); + EasyMock.expect(computeRpcMock.getSerialPortOutput(INSTANCE_ID.getZone(), + INSTANCE_ID.getInstance(), 2, EMPTY_RPC_OPTIONS)).andReturn(output); EasyMock.replay(computeRpcMock); compute = options.service(); assertEquals(output, compute.getSerialPortOutput(INSTANCE_ID, 2)); @@ -3602,8 +3692,8 @@ public void testSerialPortOutputFromPort() { @Test public void testSerialPortOutputDefault() { String output = "output"; - EasyMock.expect(computeRpcMock.getSerialPortOutput(INSTANCE_ID.zone(), INSTANCE_ID.instance(), - null, EMPTY_RPC_OPTIONS)).andReturn(output); + EasyMock.expect(computeRpcMock.getSerialPortOutput(INSTANCE_ID.getZone(), + INSTANCE_ID.getInstance(), null, EMPTY_RPC_OPTIONS)).andReturn(output); EasyMock.replay(computeRpcMock); compute = options.service(); assertEquals(output, compute.getSerialPortOutput(INSTANCE_ID)); @@ -3611,8 +3701,8 @@ public void testSerialPortOutputDefault() { @Test public void testSerialPortOutputFromPort_Null() { - EasyMock.expect(computeRpcMock.getSerialPortOutput(INSTANCE_ID.zone(), INSTANCE_ID.instance(), - 2, EMPTY_RPC_OPTIONS)).andReturn(null); + EasyMock.expect(computeRpcMock.getSerialPortOutput(INSTANCE_ID.getZone(), + INSTANCE_ID.getInstance(), 2, EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); assertNull(compute.getSerialPortOutput(INSTANCE_ID, 2)); @@ -3620,8 +3710,8 @@ public void testSerialPortOutputFromPort_Null() { @Test public void testSerialPortOutputDefault_Null() { - EasyMock.expect(computeRpcMock.getSerialPortOutput(INSTANCE_ID.zone(), INSTANCE_ID.instance(), - null, EMPTY_RPC_OPTIONS)).andReturn(null); + EasyMock.expect(computeRpcMock.getSerialPortOutput(INSTANCE_ID.getZone(), + INSTANCE_ID.getInstance(), null, EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); assertNull(compute.getSerialPortOutput(INSTANCE_ID)); @@ -3629,7 +3719,7 @@ public void testSerialPortOutputDefault_Null() { @Test public void testResetInstance_Operation() { - EasyMock.expect(computeRpcMock.reset(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.reset(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3639,12 +3729,13 @@ public void testResetInstance_Operation() { @Test public void testResetInstanceWithSelectedFields_Operation() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.reset(eq(INSTANCE_ID.zone()), eq(INSTANCE_ID.instance()), + EasyMock.expect(computeRpcMock.reset(eq(INSTANCE_ID.getZone()), eq(INSTANCE_ID.getInstance()), capture(capturedOptions))).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.reset(INSTANCE_ID, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3654,7 +3745,7 @@ public void testResetInstanceWithSelectedFields_Operation() { @Test public void testResetInstance_Null() { - EasyMock.expect(computeRpcMock.reset(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.reset(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3663,8 +3754,9 @@ public void testResetInstance_Null() { @Test public void testSetDiskAutodelete_Operation() { - EasyMock.expect(computeRpcMock.setDiskAutoDelete(INSTANCE_ID.zone(), INSTANCE_ID.instance(), - "device", true, EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); + EasyMock.expect(computeRpcMock.setDiskAutoDelete(INSTANCE_ID.getZone(), + INSTANCE_ID.getInstance(), "device", true, EMPTY_RPC_OPTIONS)) + .andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); assertEquals(zoneOperation, compute.setDiskAutoDelete(INSTANCE_ID, "device", true)); @@ -3673,14 +3765,15 @@ public void testSetDiskAutodelete_Operation() { @Test public void testSetDiskAutodeleteWithSelectedFields_Operation() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.setDiskAutoDelete(eq(INSTANCE_ID.zone()), - eq(INSTANCE_ID.instance()), eq("device"), eq(true), capture(capturedOptions))) + EasyMock.expect(computeRpcMock.setDiskAutoDelete(eq(INSTANCE_ID.getZone()), + eq(INSTANCE_ID.getInstance()), eq("device"), eq(true), capture(capturedOptions))) .andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.setDiskAutoDelete(INSTANCE_ID, "device", true, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3690,8 +3783,8 @@ public void testSetDiskAutodeleteWithSelectedFields_Operation() { @Test public void testSetDiskAutodelete_Null() { - EasyMock.expect(computeRpcMock.setDiskAutoDelete(INSTANCE_ID.zone(), INSTANCE_ID.instance(), - "device", false, EMPTY_RPC_OPTIONS)).andReturn(null); + EasyMock.expect(computeRpcMock.setDiskAutoDelete(INSTANCE_ID.getZone(), + INSTANCE_ID.getInstance(), "device", false, EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); assertNull(compute.setDiskAutoDelete(INSTANCE_ID, "device", false)); @@ -3699,8 +3792,8 @@ public void testSetDiskAutodelete_Null() { @Test public void testSetMachineType_Operation() { - EasyMock.expect(computeRpcMock.setMachineType(INSTANCE_ID.zone(), INSTANCE_ID.instance(), - MACHINE_TYPE_ID.selfLink(), EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); + EasyMock.expect(computeRpcMock.setMachineType(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), + MACHINE_TYPE_ID.getSelfLink(), EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); assertEquals(zoneOperation, @@ -3710,14 +3803,15 @@ public void testSetMachineType_Operation() { @Test public void testSetMachineTypeWithOptions_Operation() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.setMachineType(eq(INSTANCE_ID.zone()), - eq(INSTANCE_ID.instance()), eq(MACHINE_TYPE_ID.selfLink()), capture(capturedOptions))) + EasyMock.expect(computeRpcMock.setMachineType(eq(INSTANCE_ID.getZone()), + eq(INSTANCE_ID.getInstance()), eq(MACHINE_TYPE_ID.getSelfLink()), capture(capturedOptions))) .andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.setMachineType(INSTANCE_ID, MachineTypeId.of("zone", "type"), OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3727,8 +3821,8 @@ public void testSetMachineTypeWithOptions_Operation() { @Test public void testSetMachineType_Null() { - EasyMock.expect(computeRpcMock.setMachineType(INSTANCE_ID.zone(), INSTANCE_ID.instance(), - MACHINE_TYPE_ID.selfLink(), EMPTY_RPC_OPTIONS)).andReturn(null); + EasyMock.expect(computeRpcMock.setMachineType(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), + MACHINE_TYPE_ID.getSelfLink(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); assertNull(compute.setMachineType(INSTANCE_ID, MachineTypeId.of("zone", "type"))); @@ -3736,11 +3830,11 @@ public void testSetMachineType_Null() { @Test public void testSetMetadata_Operation() { - Metadata metadata = Metadata.builder() + Metadata metadata = Metadata.newBuilder() .add("key", "value") - .fingerprint("fingerprint") + .setFingerprint("fingerprint") .build(); - EasyMock.expect(computeRpcMock.setMetadata(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.setMetadata(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), metadata.toPb(), EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3750,16 +3844,18 @@ public void testSetMetadata_Operation() { @Test public void testSetMetadataWithOptions_Operation() { Capture> capturedOptions = Capture.newInstance(); - Metadata metadata = Metadata.builder() + Metadata metadata = Metadata.newBuilder() .add("key", "value") - .fingerprint("fingerprint") + .setFingerprint("fingerprint") .build(); - EasyMock.expect(computeRpcMock.setMetadata(eq(INSTANCE_ID.zone()), eq(INSTANCE_ID.instance()), - eq(metadata.toPb()), capture(capturedOptions))).andReturn(zoneOperation.toPb()); + EasyMock.expect(computeRpcMock.setMetadata(eq(INSTANCE_ID.getZone()), + eq(INSTANCE_ID.getInstance()), eq(metadata.toPb()), capture(capturedOptions))) + .andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.setMetadata(INSTANCE_ID, metadata, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3769,11 +3865,11 @@ public void testSetMetadataWithOptions_Operation() { @Test public void testSetMetadata_Null() { - Metadata metadata = Metadata.builder() + Metadata metadata = Metadata.newBuilder() .add("key", "value") - .fingerprint("fingerprint") + .setFingerprint("fingerprint") .build(); - EasyMock.expect(computeRpcMock.setMetadata(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.setMetadata(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), metadata.toPb(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3784,7 +3880,7 @@ public void testSetMetadata_Null() { public void testSetSchedulingOptions_Operation() { SchedulingOptions schedulingOptions = SchedulingOptions.standard(true, SchedulingOptions.Maintenance.MIGRATE); - EasyMock.expect(computeRpcMock.setScheduling(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.setScheduling(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), schedulingOptions.toPb(), EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3796,13 +3892,15 @@ public void testSetSchedulingOptionsWithOptions_Operation() { Capture> capturedOptions = Capture.newInstance(); SchedulingOptions schedulingOptions = SchedulingOptions.standard(true, SchedulingOptions.Maintenance.MIGRATE); - EasyMock.expect(computeRpcMock.setScheduling(eq(INSTANCE_ID.zone()), eq(INSTANCE_ID.instance()), - eq(schedulingOptions.toPb()), capture(capturedOptions))).andReturn(zoneOperation.toPb()); + EasyMock.expect(computeRpcMock.setScheduling(eq(INSTANCE_ID.getZone()), + eq(INSTANCE_ID.getInstance()), eq(schedulingOptions.toPb()), capture(capturedOptions))) + .andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.setSchedulingOptions(INSTANCE_ID, schedulingOptions, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3814,7 +3912,7 @@ public void testSetSchedulingOptionsWithOptions_Operation() { public void testSetSchedulingOptions_Null() { SchedulingOptions schedulingOptions = SchedulingOptions.standard(true, SchedulingOptions.Maintenance.MIGRATE); - EasyMock.expect(computeRpcMock.setScheduling(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.setScheduling(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), schedulingOptions.toPb(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3824,8 +3922,8 @@ public void testSetSchedulingOptions_Null() { @Test public void testTags_Operation() { Tags tags = Tags.of("tag1", "tag2"); - EasyMock.expect(computeRpcMock.setTags(INSTANCE_ID.zone(), INSTANCE_ID.instance(), tags.toPb(), - EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); + EasyMock.expect(computeRpcMock.setTags(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), + tags.toPb(), EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); assertEquals(zoneOperation, compute.setTags(INSTANCE_ID, tags)); @@ -3835,12 +3933,13 @@ public void testTags_Operation() { public void testSetTagsWithOptions_Operation() { Tags tags = Tags.of("tag1", "tag2"); Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.setTags(eq(INSTANCE_ID.zone()), eq(INSTANCE_ID.instance()), + EasyMock.expect(computeRpcMock.setTags(eq(INSTANCE_ID.getZone()), eq(INSTANCE_ID.getInstance()), eq(tags.toPb()), capture(capturedOptions))).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.setTags(INSTANCE_ID, tags, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3851,8 +3950,8 @@ public void testSetTagsWithOptions_Operation() { @Test public void testSetTags_Null() { Tags tags = Tags.of("tag1", "tag2"); - EasyMock.expect(computeRpcMock.setTags(INSTANCE_ID.zone(), INSTANCE_ID.instance(), tags.toPb(), - EMPTY_RPC_OPTIONS)).andReturn(null); + EasyMock.expect(computeRpcMock.setTags(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), + tags.toPb(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); assertNull(compute.setTags(INSTANCE_ID, tags)); @@ -3860,7 +3959,7 @@ public void testSetTags_Null() { @Test public void testStartInstance_Operation() { - EasyMock.expect(computeRpcMock.start(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.start(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3870,12 +3969,13 @@ public void testStartInstance_Operation() { @Test public void testStartInstanceWithSelectedFields_Operation() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.start(eq(INSTANCE_ID.zone()), eq(INSTANCE_ID.instance()), + EasyMock.expect(computeRpcMock.start(eq(INSTANCE_ID.getZone()), eq(INSTANCE_ID.getInstance()), capture(capturedOptions))).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.start(INSTANCE_ID, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3885,7 +3985,7 @@ public void testStartInstanceWithSelectedFields_Operation() { @Test public void testStartInstance_Null() { - EasyMock.expect(computeRpcMock.start(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.start(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3894,7 +3994,7 @@ public void testStartInstance_Null() { @Test public void testStopInstance_Operation() { - EasyMock.expect(computeRpcMock.stop(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.stop(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), EMPTY_RPC_OPTIONS)).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3904,12 +4004,13 @@ public void testStopInstance_Operation() { @Test public void testStopInstanceWithSelectedFields_Operation() { Capture> capturedOptions = Capture.newInstance(); - EasyMock.expect(computeRpcMock.stop(eq(INSTANCE_ID.zone()), eq(INSTANCE_ID.instance()), + EasyMock.expect(computeRpcMock.stop(eq(INSTANCE_ID.getZone()), eq(INSTANCE_ID.getInstance()), capture(capturedOptions))).andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.service(); Operation operation = compute.stop(INSTANCE_ID, OPERATION_OPTION_FIELDS); - String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.rpcOption()); + String selector = + (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); @@ -3919,7 +4020,7 @@ public void testStopInstanceWithSelectedFields_Operation() { @Test public void testStopInstance_Null() { - EasyMock.expect(computeRpcMock.stop(INSTANCE_ID.zone(), INSTANCE_ID.instance(), + EasyMock.expect(computeRpcMock.stop(INSTANCE_ID.getZone(), INSTANCE_ID.getInstance(), EMPTY_RPC_OPTIONS)).andReturn(null); EasyMock.replay(computeRpcMock); compute = options.service(); @@ -3928,8 +4029,8 @@ public void testStopInstance_Null() { @Test public void testRetryableException() { - EasyMock.expect( - computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getDiskType( + DISK_TYPE_ID.getZone(), DISK_TYPE_ID.getType(), EMPTY_RPC_OPTIONS)) .andThrow(new ComputeException(500, "InternalError")) .andReturn(DISK_TYPE.toPb()); EasyMock.replay(computeRpcMock); @@ -3941,8 +4042,8 @@ public void testRetryableException() { @Test public void testNonRetryableException() { String exceptionMessage = "Not Implemented"; - EasyMock.expect( - computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getDiskType( + DISK_TYPE_ID.getZone(), DISK_TYPE_ID.getType(), EMPTY_RPC_OPTIONS)) .andThrow(new ComputeException(501, exceptionMessage)); EasyMock.replay(computeRpcMock); compute = options.toBuilder().retryParams(RetryParams.defaultInstance()).build().service(); @@ -3954,8 +4055,8 @@ public void testNonRetryableException() { @Test public void testRuntimeException() { String exceptionMessage = "Artificial runtime exception"; - EasyMock.expect( - computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS)) + EasyMock.expect(computeRpcMock.getDiskType( + DISK_TYPE_ID.getZone(), DISK_TYPE_ID.getType(), EMPTY_RPC_OPTIONS)) .andThrow(new RuntimeException(exceptionMessage)); EasyMock.replay(computeRpcMock); compute = options.toBuilder().retryParams(RetryParams.defaultInstance()).build().service(); diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/DeprecationStatusTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/DeprecationStatusTest.java index 57fc8ba0a786..e3a423880995 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/DeprecationStatusTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/DeprecationStatusTest.java @@ -38,37 +38,73 @@ public class DeprecationStatusTest { MachineTypeId.of("project", "zone", "machineType"); private static final DeprecationStatus.Status STATUS = DeprecationStatus.Status.DELETED; private static final DeprecationStatus DISK_TYPE_STATUS = - DeprecationStatus.builder(STATUS) - .replacement(DISK_TYPE_ID) - .deprecated(DEPRECATED) - .obsolete(OBSOLETE) - .deleted(DELETED) + DeprecationStatus.newBuilder(STATUS) + .setReplacement(DISK_TYPE_ID) + .setDeprecated(DEPRECATED) + .setObsolete(OBSOLETE) + .setDeleted(DELETED) .build(); private static final DeprecationStatus DISK_TYPE_STATUS_MILLIS = + DeprecationStatus.newBuilder(STATUS) + .setReplacement(DISK_TYPE_ID) + .setDeprecated(DEPRECATED_MILLIS) + .setObsolete(OBSOLETE_MILLIS) + .setDeleted(DELETED_MILLIS) + .build(); + private static final DeprecationStatus MACHINE_TYPE_STATUS = + DeprecationStatus.newBuilder(STATUS, MACHINE_TYPE_ID) + .setDeprecated(DEPRECATED) + .setObsolete(OBSOLETE) + .setDeleted(DELETED) + .build(); + private static final DeprecationStatus DEPRECATED_STATUS = DeprecationStatus.builder(STATUS) .replacement(DISK_TYPE_ID) .deprecated(DEPRECATED_MILLIS) .obsolete(OBSOLETE_MILLIS) .deleted(DELETED_MILLIS) .build(); - private static final DeprecationStatus MACHINE_TYPE_STATUS = - DeprecationStatus.builder(STATUS, MACHINE_TYPE_ID) - .deprecated(DEPRECATED) - .obsolete(OBSOLETE) - .deleted(DELETED) - .build(); @Test public void testBuilder() { compareDeprecationStatus(DISK_TYPE_STATUS, DISK_TYPE_STATUS_MILLIS); - assertEquals(DELETED, DISK_TYPE_STATUS.deleted()); - assertEquals(DEPRECATED, DISK_TYPE_STATUS.deprecated()); - assertEquals(OBSOLETE, DISK_TYPE_STATUS.obsolete()); - assertEquals(DISK_TYPE_ID, DISK_TYPE_STATUS.replacement()); - assertEquals(DEPRECATED_MILLIS, DISK_TYPE_STATUS.deprecatedMillis()); - assertEquals(DELETED_MILLIS, DISK_TYPE_STATUS.deletedMillis()); - assertEquals(OBSOLETE_MILLIS, DISK_TYPE_STATUS.obsoleteMillis()); - assertEquals(STATUS, DISK_TYPE_STATUS.status()); + assertEquals(DELETED, DISK_TYPE_STATUS.getDeleted()); + assertEquals(DEPRECATED, DISK_TYPE_STATUS.getDeprecated()); + assertEquals(OBSOLETE, DISK_TYPE_STATUS.getObsolete()); + assertEquals(DISK_TYPE_ID, DISK_TYPE_STATUS.getReplacement()); + assertEquals(DEPRECATED_MILLIS, DISK_TYPE_STATUS.getDeprecatedMillis()); + assertEquals(DELETED_MILLIS, DISK_TYPE_STATUS.getDeletedMillis()); + assertEquals(OBSOLETE_MILLIS, DISK_TYPE_STATUS.getObsoleteMillis()); + assertEquals(STATUS, DISK_TYPE_STATUS.getStatus()); + assertEquals(DELETED, DISK_TYPE_STATUS_MILLIS.getDeleted()); + assertEquals(DEPRECATED, DISK_TYPE_STATUS_MILLIS.getDeprecated()); + assertEquals(OBSOLETE, DISK_TYPE_STATUS_MILLIS.getObsolete()); + assertEquals(DISK_TYPE_ID, DISK_TYPE_STATUS_MILLIS.getReplacement()); + assertEquals(DEPRECATED_MILLIS, DISK_TYPE_STATUS_MILLIS.getDeprecatedMillis()); + assertEquals(DELETED_MILLIS, DISK_TYPE_STATUS_MILLIS.getDeletedMillis()); + assertEquals(OBSOLETE_MILLIS, DISK_TYPE_STATUS_MILLIS.getObsoleteMillis()); + assertEquals(STATUS, DISK_TYPE_STATUS.getStatus()); + assertEquals(DELETED, MACHINE_TYPE_STATUS.getDeleted()); + assertEquals(DEPRECATED, MACHINE_TYPE_STATUS.getDeprecated()); + assertEquals(OBSOLETE, MACHINE_TYPE_STATUS.getObsolete()); + assertEquals(DEPRECATED_MILLIS, MACHINE_TYPE_STATUS.getDeprecatedMillis()); + assertEquals(DELETED_MILLIS, MACHINE_TYPE_STATUS.getDeletedMillis()); + assertEquals(OBSOLETE_MILLIS, MACHINE_TYPE_STATUS.getObsoleteMillis()); + assertEquals(MACHINE_TYPE_ID, MACHINE_TYPE_STATUS.getReplacement()); + assertEquals(STATUS, MACHINE_TYPE_STATUS.getStatus()); + } + + @Test + public void testBuilderDeprecated() { + compareDeprecationStatus(DISK_TYPE_STATUS, DISK_TYPE_STATUS_MILLIS); + assertEquals(DELETED, DEPRECATED_STATUS.deleted()); + assertEquals(DEPRECATED, DEPRECATED_STATUS.deprecated()); + assertEquals(OBSOLETE, DEPRECATED_STATUS.obsolete()); + assertEquals(DISK_TYPE_ID, DEPRECATED_STATUS.replacement()); + assertEquals(DEPRECATED_MILLIS, DEPRECATED_STATUS.deprecatedMillis()); + assertEquals(DELETED_MILLIS, DEPRECATED_STATUS.deletedMillis()); + assertEquals(OBSOLETE_MILLIS, DEPRECATED_STATUS.obsoleteMillis()); + assertEquals(STATUS, DEPRECATED_STATUS.status()); assertEquals(DELETED, DISK_TYPE_STATUS_MILLIS.deleted()); assertEquals(DEPRECATED, DISK_TYPE_STATUS_MILLIS.deprecated()); assertEquals(OBSOLETE, DISK_TYPE_STATUS_MILLIS.obsolete()); @@ -90,28 +126,28 @@ public void testBuilder() { @Test public void testGettersIllegalArgument() { DeprecationStatus deprecationStatus = - DeprecationStatus.builder(STATUS, MACHINE_TYPE_ID) - .deprecated("deprecated") - .obsolete("obsolete") - .deleted("delete") + DeprecationStatus.newBuilder(STATUS, MACHINE_TYPE_ID) + .setDeprecated("deprecated") + .setObsolete("obsolete") + .setDeleted("delete") .build(); - assertEquals("deprecated", deprecationStatus.deprecated()); + assertEquals("deprecated", deprecationStatus.getDeprecated()); try { - deprecationStatus.deprecatedMillis(); + deprecationStatus.getDeprecatedMillis(); fail("Expected IllegalArgumentException"); } catch (IllegalStateException ex) { // never reached } - assertEquals("obsolete", deprecationStatus.obsolete()); + assertEquals("obsolete", deprecationStatus.getObsolete()); try { - deprecationStatus.obsoleteMillis(); + deprecationStatus.getObsoleteMillis(); fail("Expected IllegalArgumentException"); } catch (IllegalStateException ex) { // never reached } - assertEquals("delete", deprecationStatus.deleted()); + assertEquals("delete", deprecationStatus.getDeleted()); try { - deprecationStatus.deletedMillis(); + deprecationStatus.getDeletedMillis(); fail("Expected IllegalArgumentException"); } catch (IllegalStateException ex) { // never reached @@ -123,10 +159,10 @@ public void testToBuilder() { compareDeprecationStatus(DISK_TYPE_STATUS, DISK_TYPE_STATUS.toBuilder().build()); compareDeprecationStatus(MACHINE_TYPE_STATUS, MACHINE_TYPE_STATUS.toBuilder().build()); DeprecationStatus deprecationStatus = DISK_TYPE_STATUS.toBuilder() - .deleted(DEPRECATED) + .setDeleted(DEPRECATED) .build(); - assertEquals(DEPRECATED, deprecationStatus.deleted()); - deprecationStatus = deprecationStatus.toBuilder().deleted(DELETED).build(); + assertEquals(DEPRECATED, deprecationStatus.getDeleted()); + deprecationStatus = deprecationStatus.toBuilder().setDeleted(DELETED).build(); compareDeprecationStatus(DISK_TYPE_STATUS, deprecationStatus); } @@ -139,11 +175,11 @@ public void testToBuilderIncomplete() { @Test public void testOf() { DeprecationStatus diskStatus = DeprecationStatus.of(STATUS, DISK_TYPE_ID); - assertNull(diskStatus.deleted()); - assertNull(diskStatus.deprecated()); - assertNull(diskStatus.obsolete()); - assertEquals(DISK_TYPE_ID, diskStatus.replacement()); - assertEquals(STATUS, diskStatus.status()); + assertNull(diskStatus.getDeleted()); + assertNull(diskStatus.getDeprecated()); + assertNull(diskStatus.getObsolete()); + assertEquals(DISK_TYPE_ID, diskStatus.getReplacement()); + assertEquals(STATUS, diskStatus.getStatus()); } @Test @@ -154,11 +190,13 @@ public void testToAndFromPb() { DeprecationStatus machineStatus = DeprecationStatus.fromPb(MACHINE_TYPE_STATUS.toPb(), MachineTypeId.FROM_URL_FUNCTION); compareDeprecationStatus(MACHINE_TYPE_STATUS, machineStatus); - diskStatus = DeprecationStatus.builder(STATUS, DISK_TYPE_ID).deprecated(DEPRECATED).build(); + diskStatus = DeprecationStatus.newBuilder(STATUS, DISK_TYPE_ID) + .setDeprecated(DEPRECATED) + .build(); assertEquals(diskStatus, DeprecationStatus.fromPb(diskStatus.toPb(), DiskTypeId.FROM_URL_FUNCTION)); machineStatus = - DeprecationStatus.builder(STATUS, MACHINE_TYPE_ID).deprecated(DEPRECATED).build(); + DeprecationStatus.newBuilder(STATUS, MACHINE_TYPE_ID).setDeprecated(DEPRECATED).build(); assertEquals(machineStatus, DeprecationStatus.fromPb(machineStatus.toPb(), MachineTypeId.FROM_URL_FUNCTION)); diskStatus = DeprecationStatus.of(STATUS, DISK_TYPE_ID); @@ -168,14 +206,14 @@ public void testToAndFromPb() { private void compareDeprecationStatus(DeprecationStatus expected, DeprecationStatus value) { assertEquals(expected, value); - assertEquals(expected.deleted(), value.deleted()); - assertEquals(expected.deprecated(), value.deprecated()); - assertEquals(expected.obsolete(), value.obsolete()); - assertEquals(expected.deletedMillis(), value.deletedMillis()); - assertEquals(expected.deprecatedMillis(), value.deprecatedMillis()); - assertEquals(expected.obsoleteMillis(), value.obsoleteMillis()); - assertEquals(expected.replacement(), value.replacement()); - assertEquals(expected.status(), value.status()); + assertEquals(expected.getDeleted(), value.getDeleted()); + assertEquals(expected.getDeprecated(), value.getDeprecated()); + assertEquals(expected.getObsolete(), value.getObsolete()); + assertEquals(expected.getDeletedMillis(), value.getDeletedMillis()); + assertEquals(expected.getDeprecatedMillis(), value.getDeprecatedMillis()); + assertEquals(expected.getObsoleteMillis(), value.getObsoleteMillis()); + assertEquals(expected.getReplacement(), value.getReplacement()); + assertEquals(expected.getStatus(), value.getStatus()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskIdTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskIdTest.java index df5fee9e6ac7..1405e993b274 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskIdTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskIdTest.java @@ -39,6 +39,23 @@ public class DiskIdTest { @Test public void testOf() { + DiskId diskId = DiskId.of(PROJECT, ZONE, NAME); + assertEquals(PROJECT, diskId.getProject()); + assertEquals(ZONE, diskId.getZone()); + assertEquals(NAME, diskId.getDisk()); + assertEquals(URL, diskId.getSelfLink()); + diskId = DiskId.of(ZONE, NAME); + assertNull(diskId.getProject()); + assertEquals(ZONE, diskId.getZone()); + assertEquals(NAME, diskId.getDisk()); + diskId = DiskId.of(ZoneId.of(ZONE), NAME); + assertNull(diskId.getProject()); + assertEquals(ZONE, diskId.getZone()); + assertEquals(NAME, diskId.getDisk()); + } + + @Test + public void testOfDeprecated() { DiskId diskId = DiskId.of(PROJECT, ZONE, NAME); assertEquals(PROJECT, diskId.project()); assertEquals(ZONE, diskId.zone()); @@ -57,7 +74,7 @@ public void testOf() { @Test public void testToAndFromUrl() { DiskId diskId = DiskId.of(PROJECT, ZONE, NAME); - compareDiskId(diskId, DiskId.fromUrl(diskId.selfLink())); + compareDiskId(diskId, DiskId.fromUrl(diskId.getSelfLink())); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("notMatchingUrl is not a valid disk URL"); DiskId.fromUrl("notMatchingUrl"); @@ -72,16 +89,16 @@ public void testSetProjectId() { @Test public void testMatchesUrl() { - assertTrue(DiskId.matchesUrl(DiskId.of(PROJECT, ZONE, NAME).selfLink())); + assertTrue(DiskId.matchesUrl(DiskId.of(PROJECT, ZONE, NAME).getSelfLink())); assertFalse(DiskId.matchesUrl("notMatchingUrl")); } private void compareDiskId(DiskId expected, DiskId value) { assertEquals(expected, value); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.zone(), expected.zone()); - assertEquals(expected.disk(), expected.disk()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getZone(), expected.getZone()); + assertEquals(expected.getDisk(), expected.getDisk()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskImageConfigurationTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskImageConfigurationTest.java index f5ecf03ddf2a..88699de88664 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskImageConfigurationTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskImageConfigurationTest.java @@ -20,7 +20,6 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import org.junit.Assert; import org.junit.Test; public class DiskImageConfigurationTest { @@ -28,12 +27,19 @@ public class DiskImageConfigurationTest { private static final DiskId SOURCE_DISK = DiskId.of("project", "zone", "disk"); private static final String SOURCE_DISK_ID = "diskId"; private static final Long ARCHIVE_SIZE_BYTES = 42L; - private static final ImageConfiguration.SourceType SOURCE_TYPE = ImageConfiguration.SourceType.RAW; + private static final ImageConfiguration.SourceType SOURCE_TYPE = + ImageConfiguration.SourceType.RAW; private static final DiskImageConfiguration CONFIGURATION = + DiskImageConfiguration.newBuilder(SOURCE_DISK) + .setSourceDiskId(SOURCE_DISK_ID) + .setSourceType(SOURCE_TYPE) + .setArchiveSizeBytes(ARCHIVE_SIZE_BYTES) + .build(); + private static final DiskImageConfiguration DEPRECATED_CONFIGURATION = DiskImageConfiguration.builder(SOURCE_DISK) - .sourceDiskId(SOURCE_DISK_ID) - .sourceType(SOURCE_TYPE) - .archiveSizeBytes(ARCHIVE_SIZE_BYTES) + .setSourceDiskId(SOURCE_DISK_ID) + .setSourceType(SOURCE_TYPE) + .setArchiveSizeBytes(ARCHIVE_SIZE_BYTES) .build(); @Test @@ -42,14 +48,14 @@ public void testToBuilder() { DiskId newDisk = DiskId.of("newProject", "newZone", "newDisk"); String newDiskId = "newDiskId"; DiskImageConfiguration configuration = CONFIGURATION.toBuilder() - .sourceDisk(newDisk) - .sourceDiskId(newDiskId) + .setSourceDisk(newDisk) + .setSourceDiskId(newDiskId) .build(); - assertEquals(newDisk, configuration.sourceDisk()); - assertEquals(newDiskId, configuration.sourceDiskId()); + assertEquals(newDisk, configuration.getSourceDisk()); + assertEquals(newDiskId, configuration.getSourceDiskId()); configuration = configuration.toBuilder() - .sourceDiskId(SOURCE_DISK_ID) - .sourceDisk(SOURCE_DISK) + .setSourceDiskId(SOURCE_DISK_ID) + .setSourceDisk(SOURCE_DISK) .build(); compareDiskImageConfiguration(CONFIGURATION, configuration); } @@ -62,11 +68,20 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { - assertEquals(SOURCE_TYPE, CONFIGURATION.sourceType()); - assertEquals(SOURCE_DISK, CONFIGURATION.sourceDisk()); - assertEquals(SOURCE_DISK_ID, CONFIGURATION.sourceDiskId()); - assertEquals(ARCHIVE_SIZE_BYTES, CONFIGURATION.archiveSizeBytes()); - Assert.assertEquals(ImageConfiguration.Type.DISK, CONFIGURATION.type()); + assertEquals(SOURCE_TYPE, CONFIGURATION.getSourceType()); + assertEquals(SOURCE_DISK, CONFIGURATION.getSourceDisk()); + assertEquals(SOURCE_DISK_ID, CONFIGURATION.getSourceDiskId()); + assertEquals(ARCHIVE_SIZE_BYTES, CONFIGURATION.getArchiveSizeBytes()); + assertEquals(ImageConfiguration.Type.DISK, CONFIGURATION.getType()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(SOURCE_TYPE, DEPRECATED_CONFIGURATION.sourceType()); + assertEquals(SOURCE_DISK, DEPRECATED_CONFIGURATION.sourceDisk()); + assertEquals(SOURCE_DISK_ID, DEPRECATED_CONFIGURATION.sourceDiskId()); + assertEquals(ARCHIVE_SIZE_BYTES, DEPRECATED_CONFIGURATION.archiveSizeBytes()); + assertEquals(ImageConfiguration.Type.DISK, DEPRECATED_CONFIGURATION.type()); } @Test @@ -82,17 +97,17 @@ public void testToAndFromPb() { @Test public void testOf() { DiskImageConfiguration configuration = DiskImageConfiguration.of(SOURCE_DISK); - Assert.assertEquals(ImageConfiguration.Type.DISK, configuration.type()); - assertNull(configuration.sourceDiskId()); - assertNull(configuration.sourceType()); - assertNull(configuration.archiveSizeBytes()); - assertEquals(SOURCE_DISK, configuration.sourceDisk()); + assertEquals(ImageConfiguration.Type.DISK, configuration.getType()); + assertNull(configuration.getSourceDiskId()); + assertNull(configuration.getSourceType()); + assertNull(configuration.getArchiveSizeBytes()); + assertEquals(SOURCE_DISK, configuration.getSourceDisk()); } @Test public void testSetProjectId() { DiskImageConfiguration configuration = CONFIGURATION.toBuilder() - .sourceDisk(DiskId.of("zone", "disk")) + .setSourceDisk(DiskId.of("zone", "disk")) .build(); compareDiskImageConfiguration(CONFIGURATION, configuration.setProjectId("project")); } @@ -100,11 +115,11 @@ public void testSetProjectId() { private void compareDiskImageConfiguration(DiskImageConfiguration expected, DiskImageConfiguration value) { assertEquals(expected, value); - assertEquals(expected.type(), value.type()); - assertEquals(expected.archiveSizeBytes(), value.archiveSizeBytes()); - assertEquals(expected.sourceDisk(), value.sourceDisk()); - assertEquals(expected.sourceDiskId(), value.sourceDiskId()); - assertEquals(expected.sourceType(), value.sourceType()); + assertEquals(expected.getType(), value.getType()); + assertEquals(expected.getArchiveSizeBytes(), value.getArchiveSizeBytes()); + assertEquals(expected.getSourceDisk(), value.getSourceDisk()); + assertEquals(expected.getSourceDiskId(), value.getSourceDiskId()); + assertEquals(expected.getSourceType(), value.getSourceType()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskInfoTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskInfoTest.java index 7e4bbc31b617..f2c073a177b4 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskInfoTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskInfoTest.java @@ -47,53 +47,86 @@ public class DiskInfoTest { private static final Long LAST_ATTACH_TIMESTAMP = 1453293600000L; private static final Long LAST_DETACH_TIMESTAMP = 1453293660000L; private static final StandardDiskConfiguration DISK_CONFIGURATION = - StandardDiskConfiguration.builder() - .sizeGb(SIZE_GB) - .diskType(TYPE) + StandardDiskConfiguration.newBuilder() + .setSizeGb(SIZE_GB) + .setDiskType(TYPE) .build(); private static final SnapshotDiskConfiguration SNAPSHOT_DISK_CONFIGURATION = - SnapshotDiskConfiguration.builder(SNAPSHOT) - .sizeGb(SIZE_GB) - .diskType(TYPE) - .sourceSnapshotId(SNAPSHOT_ID) + SnapshotDiskConfiguration.newBuilder(SNAPSHOT) + .setSizeGb(SIZE_GB) + .setDiskType(TYPE) + .setSourceSnapshotId(SNAPSHOT_ID) .build(); private static final ImageDiskConfiguration IMAGE_DISK_CONFIGURATION = - ImageDiskConfiguration.builder(IMAGE) - .sizeGb(SIZE_GB) - .diskType(TYPE) - .sourceImageId(IMAGE_ID) + ImageDiskConfiguration.newBuilder(IMAGE) + .setSizeGb(SIZE_GB) + .setDiskType(TYPE) + .setSourceImageId(IMAGE_ID) .build(); - private static final DiskInfo DISK_INFO = DiskInfo.builder(DISK_ID, DISK_CONFIGURATION) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .creationStatus(CREATION_STATUS) - .description(DESCRIPTION) - .licenses(LICENSES) - .attachedInstances(ATTACHED_INSTANCES) - .lastAttachTimestamp(LAST_ATTACH_TIMESTAMP) - .lastDetachTimestamp(LAST_DETACH_TIMESTAMP) + private static final DiskInfo DISK_INFO = DiskInfo.newBuilder(DISK_ID, DISK_CONFIGURATION) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setCreationStatus(CREATION_STATUS) + .setDescription(DESCRIPTION) + .setLicenses(LICENSES) + .setAttachedInstances(ATTACHED_INSTANCES) + .setLastAttachTimestamp(LAST_ATTACH_TIMESTAMP) + .setLastDetachTimestamp(LAST_DETACH_TIMESTAMP) .build(); private static final DiskInfo SNAPSHOT_DISK_INFO = + DiskInfo.newBuilder(DISK_ID, SNAPSHOT_DISK_CONFIGURATION) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setCreationStatus(CREATION_STATUS) + .setDescription(DESCRIPTION) + .setLicenses(LICENSES) + .setAttachedInstances(ATTACHED_INSTANCES) + .setLastAttachTimestamp(LAST_ATTACH_TIMESTAMP) + .setLastDetachTimestamp(LAST_DETACH_TIMESTAMP) + .build(); + private static final DiskInfo IMAGE_DISK_INFO = + DiskInfo.newBuilder(DISK_ID, IMAGE_DISK_CONFIGURATION) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setCreationStatus(CREATION_STATUS) + .setDescription(DESCRIPTION) + .setLicenses(LICENSES) + .setAttachedInstances(ATTACHED_INSTANCES) + .setLastAttachTimestamp(LAST_ATTACH_TIMESTAMP) + .setLastDetachTimestamp(LAST_DETACH_TIMESTAMP) + .build(); + private static final DiskInfo DEPRECATED_DISK_INFO = + DiskInfo.builder(DISK_ID, DISK_CONFIGURATION) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setCreationStatus(CREATION_STATUS) + .description(DESCRIPTION) + .setLicenses(LICENSES) + .setAttachedInstances(ATTACHED_INSTANCES) + .setLastAttachTimestamp(LAST_ATTACH_TIMESTAMP) + .setLastDetachTimestamp(LAST_DETACH_TIMESTAMP) + .build(); + private static final DiskInfo DEPRECATED_SNAPSHOT_DISK_INFO = DiskInfo.builder(DISK_ID, SNAPSHOT_DISK_CONFIGURATION) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .creationStatus(CREATION_STATUS) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setCreationStatus(CREATION_STATUS) .description(DESCRIPTION) - .licenses(LICENSES) - .attachedInstances(ATTACHED_INSTANCES) - .lastAttachTimestamp(LAST_ATTACH_TIMESTAMP) - .lastDetachTimestamp(LAST_DETACH_TIMESTAMP) + .setLicenses(LICENSES) + .setAttachedInstances(ATTACHED_INSTANCES) + .setLastAttachTimestamp(LAST_ATTACH_TIMESTAMP) + .setLastDetachTimestamp(LAST_DETACH_TIMESTAMP) .build(); - private static final DiskInfo IMAGE_DISK_INFO = + private static final DiskInfo DEPRECATED_IMAGE_DISK_INFO = DiskInfo.builder(DISK_ID, IMAGE_DISK_CONFIGURATION) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .creationStatus(CREATION_STATUS) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setCreationStatus(CREATION_STATUS) .description(DESCRIPTION) - .licenses(LICENSES) - .attachedInstances(ATTACHED_INSTANCES) - .lastAttachTimestamp(LAST_ATTACH_TIMESTAMP) - .lastDetachTimestamp(LAST_DETACH_TIMESTAMP) + .setLicenses(LICENSES) + .setAttachedInstances(ATTACHED_INSTANCES) + .setLastAttachTimestamp(LAST_ATTACH_TIMESTAMP) + .setLastDetachTimestamp(LAST_DETACH_TIMESTAMP) .build(); @Test @@ -101,9 +134,9 @@ public void testToBuilder() { compareDiskInfo(DISK_INFO, DISK_INFO.toBuilder().build()); compareDiskInfo(IMAGE_DISK_INFO, IMAGE_DISK_INFO.toBuilder().build()); compareDiskInfo(SNAPSHOT_DISK_INFO, SNAPSHOT_DISK_INFO.toBuilder().build()); - DiskInfo diskInfo = DISK_INFO.toBuilder().description("newDescription").build(); - assertEquals("newDescription", diskInfo.description()); - diskInfo = diskInfo.toBuilder().description("description").build(); + DiskInfo diskInfo = DISK_INFO.toBuilder().setDescription("newDescription").build(); + assertEquals("newDescription", diskInfo.getDescription()); + diskInfo = diskInfo.toBuilder().setDescription("description").build(); compareDiskInfo(DISK_INFO, diskInfo); } @@ -119,73 +152,107 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { - assertEquals(GENERATED_ID, DISK_INFO.generatedId()); - assertEquals(DISK_ID, DISK_INFO.diskId()); - assertEquals(DISK_CONFIGURATION, DISK_INFO.configuration()); - assertEquals(CREATION_TIMESTAMP, DISK_INFO.creationTimestamp()); - assertEquals(CREATION_STATUS, DISK_INFO.creationStatus()); - assertEquals(DESCRIPTION, DISK_INFO.description()); - assertEquals(LICENSES, DISK_INFO.licenses()); - assertEquals(ATTACHED_INSTANCES, DISK_INFO.attachedInstances()); - assertEquals(LAST_ATTACH_TIMESTAMP, DISK_INFO.lastAttachTimestamp()); - assertEquals(LAST_DETACH_TIMESTAMP, DISK_INFO.lastDetachTimestamp()); - assertEquals(GENERATED_ID, IMAGE_DISK_INFO.generatedId()); - assertEquals(DISK_ID, IMAGE_DISK_INFO.diskId()); - assertEquals(IMAGE_DISK_CONFIGURATION, IMAGE_DISK_INFO.configuration()); - assertEquals(CREATION_TIMESTAMP, IMAGE_DISK_INFO.creationTimestamp()); - assertEquals(CREATION_STATUS, IMAGE_DISK_INFO.creationStatus()); - assertEquals(DESCRIPTION, IMAGE_DISK_INFO.description()); - assertEquals(LICENSES, IMAGE_DISK_INFO.licenses()); - assertEquals(ATTACHED_INSTANCES, IMAGE_DISK_INFO.attachedInstances()); - assertEquals(LAST_ATTACH_TIMESTAMP, IMAGE_DISK_INFO.lastAttachTimestamp()); - assertEquals(LAST_DETACH_TIMESTAMP, IMAGE_DISK_INFO.lastDetachTimestamp()); - assertEquals(GENERATED_ID, SNAPSHOT_DISK_INFO.generatedId()); - assertEquals(DISK_ID, SNAPSHOT_DISK_INFO.diskId()); - assertEquals(SNAPSHOT_DISK_CONFIGURATION, SNAPSHOT_DISK_INFO.configuration()); - assertEquals(CREATION_TIMESTAMP, SNAPSHOT_DISK_INFO.creationTimestamp()); - assertEquals(CREATION_STATUS, SNAPSHOT_DISK_INFO.creationStatus()); - assertEquals(DESCRIPTION, SNAPSHOT_DISK_INFO.description()); - assertEquals(LICENSES, SNAPSHOT_DISK_INFO.licenses()); - assertEquals(ATTACHED_INSTANCES, SNAPSHOT_DISK_INFO.attachedInstances()); - assertEquals(LAST_ATTACH_TIMESTAMP, SNAPSHOT_DISK_INFO.lastAttachTimestamp()); - assertEquals(LAST_DETACH_TIMESTAMP, SNAPSHOT_DISK_INFO.lastDetachTimestamp()); + assertEquals(GENERATED_ID, DISK_INFO.getGeneratedId()); + assertEquals(DISK_ID, DISK_INFO.getDiskId()); + assertEquals(DISK_CONFIGURATION, DISK_INFO.getConfiguration()); + assertEquals(CREATION_TIMESTAMP, DISK_INFO.getCreationTimestamp()); + assertEquals(CREATION_STATUS, DISK_INFO.getCreationStatus()); + assertEquals(DESCRIPTION, DISK_INFO.getDescription()); + assertEquals(LICENSES, DISK_INFO.getLicenses()); + assertEquals(ATTACHED_INSTANCES, DISK_INFO.getAttachedInstances()); + assertEquals(LAST_ATTACH_TIMESTAMP, DISK_INFO.getLastAttachTimestamp()); + assertEquals(LAST_DETACH_TIMESTAMP, DISK_INFO.getLastDetachTimestamp()); + assertEquals(GENERATED_ID, IMAGE_DISK_INFO.getGeneratedId()); + assertEquals(DISK_ID, IMAGE_DISK_INFO.getDiskId()); + assertEquals(IMAGE_DISK_CONFIGURATION, IMAGE_DISK_INFO.getConfiguration()); + assertEquals(CREATION_TIMESTAMP, IMAGE_DISK_INFO.getCreationTimestamp()); + assertEquals(CREATION_STATUS, IMAGE_DISK_INFO.getCreationStatus()); + assertEquals(DESCRIPTION, IMAGE_DISK_INFO.getDescription()); + assertEquals(LICENSES, IMAGE_DISK_INFO.getLicenses()); + assertEquals(ATTACHED_INSTANCES, IMAGE_DISK_INFO.getAttachedInstances()); + assertEquals(LAST_ATTACH_TIMESTAMP, IMAGE_DISK_INFO.getLastAttachTimestamp()); + assertEquals(LAST_DETACH_TIMESTAMP, IMAGE_DISK_INFO.getLastDetachTimestamp()); + assertEquals(GENERATED_ID, SNAPSHOT_DISK_INFO.getGeneratedId()); + assertEquals(DISK_ID, SNAPSHOT_DISK_INFO.getDiskId()); + assertEquals(SNAPSHOT_DISK_CONFIGURATION, SNAPSHOT_DISK_INFO.getConfiguration()); + assertEquals(CREATION_TIMESTAMP, SNAPSHOT_DISK_INFO.getCreationTimestamp()); + assertEquals(CREATION_STATUS, SNAPSHOT_DISK_INFO.getCreationStatus()); + assertEquals(DESCRIPTION, SNAPSHOT_DISK_INFO.getDescription()); + assertEquals(LICENSES, SNAPSHOT_DISK_INFO.getLicenses()); + assertEquals(ATTACHED_INSTANCES, SNAPSHOT_DISK_INFO.getAttachedInstances()); + assertEquals(LAST_ATTACH_TIMESTAMP, SNAPSHOT_DISK_INFO.getLastAttachTimestamp()); + assertEquals(LAST_DETACH_TIMESTAMP, SNAPSHOT_DISK_INFO.getLastDetachTimestamp()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(GENERATED_ID, DEPRECATED_DISK_INFO.generatedId()); + assertEquals(DISK_ID, DEPRECATED_DISK_INFO.diskId()); + assertEquals(DISK_CONFIGURATION, DEPRECATED_DISK_INFO.configuration()); + assertEquals(CREATION_TIMESTAMP, DEPRECATED_DISK_INFO.creationTimestamp()); + assertEquals(CREATION_STATUS, DEPRECATED_DISK_INFO.creationStatus()); + assertEquals(DESCRIPTION, DEPRECATED_DISK_INFO.description()); + assertEquals(LICENSES, DEPRECATED_DISK_INFO.licenses()); + assertEquals(ATTACHED_INSTANCES, DEPRECATED_DISK_INFO.attachedInstances()); + assertEquals(LAST_ATTACH_TIMESTAMP, DEPRECATED_DISK_INFO.lastAttachTimestamp()); + assertEquals(LAST_DETACH_TIMESTAMP, DEPRECATED_DISK_INFO.lastDetachTimestamp()); + assertEquals(GENERATED_ID, DEPRECATED_IMAGE_DISK_INFO.generatedId()); + assertEquals(DISK_ID, DEPRECATED_IMAGE_DISK_INFO.diskId()); + assertEquals(IMAGE_DISK_CONFIGURATION, DEPRECATED_IMAGE_DISK_INFO.configuration()); + assertEquals(CREATION_TIMESTAMP, DEPRECATED_IMAGE_DISK_INFO.creationTimestamp()); + assertEquals(CREATION_STATUS, DEPRECATED_IMAGE_DISK_INFO.creationStatus()); + assertEquals(DESCRIPTION, DEPRECATED_IMAGE_DISK_INFO.description()); + assertEquals(LICENSES, DEPRECATED_IMAGE_DISK_INFO.licenses()); + assertEquals(ATTACHED_INSTANCES, DEPRECATED_IMAGE_DISK_INFO.attachedInstances()); + assertEquals(LAST_ATTACH_TIMESTAMP, DEPRECATED_IMAGE_DISK_INFO.lastAttachTimestamp()); + assertEquals(LAST_DETACH_TIMESTAMP, DEPRECATED_IMAGE_DISK_INFO.lastDetachTimestamp()); + assertEquals(GENERATED_ID, DEPRECATED_SNAPSHOT_DISK_INFO.generatedId()); + assertEquals(DISK_ID, DEPRECATED_SNAPSHOT_DISK_INFO.diskId()); + assertEquals(SNAPSHOT_DISK_CONFIGURATION, DEPRECATED_SNAPSHOT_DISK_INFO.configuration()); + assertEquals(CREATION_TIMESTAMP, DEPRECATED_SNAPSHOT_DISK_INFO.creationTimestamp()); + assertEquals(CREATION_STATUS, DEPRECATED_SNAPSHOT_DISK_INFO.creationStatus()); + assertEquals(DESCRIPTION, DEPRECATED_SNAPSHOT_DISK_INFO.description()); + assertEquals(LICENSES, DEPRECATED_SNAPSHOT_DISK_INFO.licenses()); + assertEquals(ATTACHED_INSTANCES, DEPRECATED_SNAPSHOT_DISK_INFO.attachedInstances()); + assertEquals(LAST_ATTACH_TIMESTAMP, DEPRECATED_SNAPSHOT_DISK_INFO.lastAttachTimestamp()); + assertEquals(LAST_DETACH_TIMESTAMP, DEPRECATED_SNAPSHOT_DISK_INFO.lastDetachTimestamp()); } @Test public void testOf() { DiskInfo diskInfo = DiskInfo.of(DISK_ID, DISK_CONFIGURATION); - assertNull(diskInfo.generatedId()); - assertEquals(DISK_ID, diskInfo.diskId()); - assertEquals(DISK_CONFIGURATION, diskInfo.configuration()); - assertNull(diskInfo.creationTimestamp()); - assertNull(diskInfo.creationStatus()); - assertNull(diskInfo.description()); - assertNull(diskInfo.licenses()); - assertNull(diskInfo.attachedInstances()); - assertNull(diskInfo.lastAttachTimestamp()); - assertNull(diskInfo.lastDetachTimestamp()); + assertNull(diskInfo.getGeneratedId()); + assertEquals(DISK_ID, diskInfo.getDiskId()); + assertEquals(DISK_CONFIGURATION, diskInfo.getConfiguration()); + assertNull(diskInfo.getCreationTimestamp()); + assertNull(diskInfo.getCreationStatus()); + assertNull(diskInfo.getDescription()); + assertNull(diskInfo.getLicenses()); + assertNull(diskInfo.getAttachedInstances()); + assertNull(diskInfo.getLastAttachTimestamp()); + assertNull(diskInfo.getLastDetachTimestamp()); diskInfo = DiskInfo.of(DISK_ID, IMAGE_DISK_CONFIGURATION); - assertNull(diskInfo.generatedId()); - assertEquals(DISK_ID, diskInfo.diskId()); - assertEquals(IMAGE_DISK_CONFIGURATION, diskInfo.configuration()); - assertNull(diskInfo.creationTimestamp()); - assertNull(diskInfo.creationStatus()); - assertNull(diskInfo.description()); - assertNull(diskInfo.licenses()); - assertNull(diskInfo.attachedInstances()); - assertNull(diskInfo.lastAttachTimestamp()); - assertNull(diskInfo.lastDetachTimestamp()); + assertNull(diskInfo.getGeneratedId()); + assertEquals(DISK_ID, diskInfo.getDiskId()); + assertEquals(IMAGE_DISK_CONFIGURATION, diskInfo.getConfiguration()); + assertNull(diskInfo.getCreationTimestamp()); + assertNull(diskInfo.getCreationStatus()); + assertNull(diskInfo.getDescription()); + assertNull(diskInfo.getLicenses()); + assertNull(diskInfo.getAttachedInstances()); + assertNull(diskInfo.getLastAttachTimestamp()); + assertNull(diskInfo.getLastDetachTimestamp()); diskInfo = DiskInfo.of(DISK_ID, SNAPSHOT_DISK_CONFIGURATION); - assertNull(diskInfo.generatedId()); - assertEquals(DISK_ID, diskInfo.diskId()); - assertEquals(SNAPSHOT_DISK_CONFIGURATION, diskInfo.configuration()); - assertNull(diskInfo.creationTimestamp()); - assertNull(diskInfo.creationStatus()); - assertNull(diskInfo.description()); - assertNull(diskInfo.licenses()); - assertNull(diskInfo.attachedInstances()); - assertNull(diskInfo.lastAttachTimestamp()); - assertNull(diskInfo.lastDetachTimestamp()); + assertNull(diskInfo.getGeneratedId()); + assertEquals(DISK_ID, diskInfo.getDiskId()); + assertEquals(SNAPSHOT_DISK_CONFIGURATION, diskInfo.getConfiguration()); + assertNull(diskInfo.getCreationTimestamp()); + assertNull(diskInfo.getCreationStatus()); + assertNull(diskInfo.getDescription()); + assertNull(diskInfo.getLicenses()); + assertNull(diskInfo.getAttachedInstances()); + assertNull(diskInfo.getLastAttachTimestamp()); + assertNull(diskInfo.getLastDetachTimestamp()); } @Test @@ -197,25 +264,25 @@ public void testToAndFromPb() { diskInfo = DiskInfo.fromPb(IMAGE_DISK_INFO.toPb()); compareDiskInfo(IMAGE_DISK_INFO, diskInfo); Disk disk = new Disk() - .setSelfLink(DISK_ID.selfLink()) - .setType(TYPE.selfLink()) + .setSelfLink(DISK_ID.getSelfLink()) + .setType(TYPE.getSelfLink()) .setSizeGb(SIZE_GB); diskInfo = DiskInfo.of(DISK_ID, DISK_CONFIGURATION); compareDiskInfo(diskInfo, DiskInfo.fromPb(disk)); disk = new Disk() - .setType(TYPE.selfLink()) + .setType(TYPE.getSelfLink()) .setSizeGb(SIZE_GB) - .setSelfLink(DISK_ID.selfLink()) + .setSelfLink(DISK_ID.getSelfLink()) .setSourceSnapshotId(SNAPSHOT_ID) - .setSourceSnapshot(SNAPSHOT.selfLink()); + .setSourceSnapshot(SNAPSHOT.getSelfLink()); diskInfo = DiskInfo.of(DISK_ID, SNAPSHOT_DISK_CONFIGURATION); compareDiskInfo(diskInfo, DiskInfo.fromPb(disk)); disk = new Disk() - .setType(TYPE.selfLink()) + .setType(TYPE.getSelfLink()) .setSizeGb(SIZE_GB) - .setSelfLink(DISK_ID.selfLink()) + .setSelfLink(DISK_ID.getSelfLink()) .setSourceImageId(IMAGE_ID) - .setSourceImage(IMAGE.selfLink()); + .setSourceImage(IMAGE.getSelfLink()); diskInfo = DiskInfo.of(DISK_ID, IMAGE_DISK_CONFIGURATION); compareDiskInfo(diskInfo, DiskInfo.fromPb(disk)); } @@ -223,45 +290,45 @@ public void testToAndFromPb() { @Test public void testSetProjectId() { StandardDiskConfiguration standardDiskConfiguration = DISK_CONFIGURATION.toBuilder() - .diskType(DiskTypeId.of(TYPE.zone(), TYPE.type())) + .setDiskType(DiskTypeId.of(TYPE.getZone(), TYPE.getType())) .build(); DiskInfo diskInfo = DISK_INFO.toBuilder() - .diskId(DiskId.of(DISK_ID.zone(), DISK_ID.disk())) - .configuration(standardDiskConfiguration) + .setDiskId(DiskId.of(DISK_ID.getZone(), DISK_ID.getDisk())) + .setConfiguration(standardDiskConfiguration) .build(); compareDiskInfo(DISK_INFO, diskInfo.setProjectId("project")); SnapshotDiskConfiguration snapshotDiskConfiguration = SNAPSHOT_DISK_CONFIGURATION.toBuilder() - .diskType(DiskTypeId.of(TYPE.zone(), TYPE.type())) - .sourceSnapshot(SnapshotId.of(SNAPSHOT.snapshot())) + .setDiskType(DiskTypeId.of(TYPE.getZone(), TYPE.getType())) + .setSourceSnapshot(SnapshotId.of(SNAPSHOT.getSnapshot())) .build(); diskInfo = SNAPSHOT_DISK_INFO.toBuilder() - .diskId(DiskId.of(DISK_ID.zone(), DISK_ID.disk())) - .configuration(snapshotDiskConfiguration) + .setDiskId(DiskId.of(DISK_ID.getZone(), DISK_ID.getDisk())) + .setConfiguration(snapshotDiskConfiguration) .build(); compareDiskInfo(SNAPSHOT_DISK_INFO, diskInfo.setProjectId("project")); ImageDiskConfiguration imageDiskConfiguration = IMAGE_DISK_CONFIGURATION.toBuilder() - .diskType(DiskTypeId.of(TYPE.zone(), TYPE.type())) - .sourceImage(ImageId.of(IMAGE.image())) + .setDiskType(DiskTypeId.of(TYPE.getZone(), TYPE.getType())) + .setSourceImage(ImageId.of(IMAGE.getImage())) .build(); diskInfo = IMAGE_DISK_INFO.toBuilder() - .diskId(DiskId.of(DISK_ID.zone(), DISK_ID.disk())) - .configuration(imageDiskConfiguration) + .setDiskId(DiskId.of(DISK_ID.getZone(), DISK_ID.getDisk())) + .setConfiguration(imageDiskConfiguration) .build(); compareDiskInfo(IMAGE_DISK_INFO, diskInfo.setProjectId("project")); } public void compareDiskInfo(DiskInfo expected, DiskInfo value) { assertEquals(expected, value); - assertEquals(expected.configuration(), value.configuration()); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.diskId(), value.diskId()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.creationStatus(), value.creationStatus()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.licenses(), value.licenses()); - assertEquals(expected.attachedInstances(), value.attachedInstances()); - assertEquals(expected.lastAttachTimestamp(), value.lastAttachTimestamp()); - assertEquals(expected.lastDetachTimestamp(), value.lastDetachTimestamp()); + assertEquals(expected.getConfiguration(), value.getConfiguration()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getDiskId(), value.getDiskId()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getCreationStatus(), value.getCreationStatus()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getLicenses(), value.getLicenses()); + assertEquals(expected.getAttachedInstances(), value.getAttachedInstances()); + assertEquals(expected.getLastAttachTimestamp(), value.getLastAttachTimestamp()); + assertEquals(expected.getLastDetachTimestamp(), value.getLastDetachTimestamp()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskTest.java index 03182493803c..24b214d6a5bd 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskTest.java @@ -54,21 +54,21 @@ public class DiskTest { private static final Long LAST_ATTACH_TIMESTAMP = 1453293600000L; private static final Long LAST_DETACH_TIMESTAMP = 1453293660000L; private static final StandardDiskConfiguration DISK_CONFIGURATION = - StandardDiskConfiguration.builder() - .sizeGb(SIZE_GB) - .diskType(TYPE) + StandardDiskConfiguration.newBuilder() + .setSizeGb(SIZE_GB) + .setDiskType(TYPE) .build(); private static final SnapshotDiskConfiguration SNAPSHOT_DISK_CONFIGURATION = - SnapshotDiskConfiguration.builder(SNAPSHOT) - .sizeGb(SIZE_GB) - .diskType(TYPE) - .sourceSnapshotId(SNAPSHOT_ID) + SnapshotDiskConfiguration.newBuilder(SNAPSHOT) + .setSizeGb(SIZE_GB) + .setDiskType(TYPE) + .setSourceSnapshotId(SNAPSHOT_ID) .build(); private static final ImageDiskConfiguration IMAGE_DISK_CONFIGURATION = - ImageDiskConfiguration.builder(IMAGE) - .sizeGb(SIZE_GB) - .diskType(TYPE) - .sourceImageId(IMAGE_ID) + ImageDiskConfiguration.newBuilder(IMAGE) + .setSizeGb(SIZE_GB) + .setDiskType(TYPE) + .setSourceImageId(IMAGE_ID) .build(); private final Compute serviceMockReturnsOptions = createStrictMock(Compute.class); @@ -83,46 +83,46 @@ private void initializeExpectedDisk(int optionsCalls) { expect(serviceMockReturnsOptions.options()).andReturn(mockOptions).times(optionsCalls); replay(serviceMockReturnsOptions); standardDisk = new Disk.Builder(serviceMockReturnsOptions, DISK_ID, DISK_CONFIGURATION) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .creationStatus(CREATION_STATUS) - .description(DESCRIPTION) - .licenses(LICENSES) - .attachedInstances(ATTACHED_INSTANCES) - .lastAttachTimestamp(LAST_ATTACH_TIMESTAMP) - .lastDetachTimestamp(LAST_DETACH_TIMESTAMP) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setCreationStatus(CREATION_STATUS) + .setDescription(DESCRIPTION) + .setLicenses(LICENSES) + .setAttachedInstances(ATTACHED_INSTANCES) + .setLastAttachTimestamp(LAST_ATTACH_TIMESTAMP) + .setLastDetachTimestamp(LAST_DETACH_TIMESTAMP) .build(); snapshotDisk = new Disk.Builder(serviceMockReturnsOptions, DISK_ID, SNAPSHOT_DISK_CONFIGURATION) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .creationStatus(CREATION_STATUS) - .description(DESCRIPTION) - .licenses(LICENSES) - .attachedInstances(ATTACHED_INSTANCES) - .lastAttachTimestamp(LAST_ATTACH_TIMESTAMP) - .lastDetachTimestamp(LAST_DETACH_TIMESTAMP) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setCreationStatus(CREATION_STATUS) + .setDescription(DESCRIPTION) + .setLicenses(LICENSES) + .setAttachedInstances(ATTACHED_INSTANCES) + .setLastAttachTimestamp(LAST_ATTACH_TIMESTAMP) + .setLastDetachTimestamp(LAST_DETACH_TIMESTAMP) .build(); imageDisk = new Disk.Builder(serviceMockReturnsOptions, DISK_ID, IMAGE_DISK_CONFIGURATION) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .creationStatus(CREATION_STATUS) - .description(DESCRIPTION) - .licenses(LICENSES) - .attachedInstances(ATTACHED_INSTANCES) - .lastAttachTimestamp(LAST_ATTACH_TIMESTAMP) - .lastDetachTimestamp(LAST_DETACH_TIMESTAMP) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setCreationStatus(CREATION_STATUS) + .setDescription(DESCRIPTION) + .setLicenses(LICENSES) + .setAttachedInstances(ATTACHED_INSTANCES) + .setLastAttachTimestamp(LAST_ATTACH_TIMESTAMP) + .setLastDetachTimestamp(LAST_DETACH_TIMESTAMP) .build(); compute = createStrictMock(Compute.class); } private void initializeDisk() { disk = new Disk.Builder(compute, DISK_ID, DISK_CONFIGURATION) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .creationStatus(CREATION_STATUS) - .description(DESCRIPTION) - .licenses(LICENSES) - .attachedInstances(ATTACHED_INSTANCES) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setCreationStatus(CREATION_STATUS) + .setDescription(DESCRIPTION) + .setLicenses(LICENSES) + .setAttachedInstances(ATTACHED_INSTANCES) .build(); } @@ -132,9 +132,9 @@ public void testToBuilder() { compareDisk(standardDisk, standardDisk.toBuilder().build()); compareDisk(imageDisk, imageDisk.toBuilder().build()); compareDisk(snapshotDisk, snapshotDisk.toBuilder().build()); - Disk newDisk = standardDisk.toBuilder().description("newDescription").build(); - assertEquals("newDescription", newDisk.description()); - newDisk = newDisk.toBuilder().description("description").build(); + Disk newDisk = standardDisk.toBuilder().setDescription("newDescription").build(); + assertEquals("newDescription", newDisk.getDescription()); + newDisk = newDisk.toBuilder().setDescription("description").build(); compareDisk(standardDisk, newDisk); } @@ -154,6 +154,59 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { + initializeExpectedDisk(4); + assertEquals(DISK_ID, standardDisk.getDiskId()); + assertEquals(GENERATED_ID, standardDisk.getGeneratedId()); + assertEquals(DISK_CONFIGURATION, standardDisk.getConfiguration()); + assertEquals(CREATION_TIMESTAMP, standardDisk.getCreationTimestamp()); + assertEquals(CREATION_STATUS, standardDisk.getCreationStatus()); + assertEquals(DESCRIPTION, standardDisk.getDescription()); + assertEquals(LICENSES, standardDisk.getLicenses()); + assertEquals(ATTACHED_INSTANCES, standardDisk.getAttachedInstances()); + assertEquals(LAST_ATTACH_TIMESTAMP, standardDisk.getLastAttachTimestamp()); + assertEquals(LAST_DETACH_TIMESTAMP, standardDisk.getLastDetachTimestamp()); + assertSame(serviceMockReturnsOptions, standardDisk.getCompute()); + assertEquals(DISK_ID, imageDisk.getDiskId()); + assertEquals(GENERATED_ID, imageDisk.getGeneratedId()); + assertEquals(IMAGE_DISK_CONFIGURATION, imageDisk.getConfiguration()); + assertEquals(CREATION_TIMESTAMP, imageDisk.getCreationTimestamp()); + assertEquals(CREATION_STATUS, imageDisk.getCreationStatus()); + assertEquals(DESCRIPTION, imageDisk.getDescription()); + assertEquals(LICENSES, imageDisk.getLicenses()); + assertEquals(ATTACHED_INSTANCES, imageDisk.getAttachedInstances()); + assertEquals(LAST_ATTACH_TIMESTAMP, imageDisk.getLastAttachTimestamp()); + assertEquals(LAST_DETACH_TIMESTAMP, imageDisk.getLastDetachTimestamp()); + assertSame(serviceMockReturnsOptions, imageDisk.getCompute()); + assertEquals(DISK_ID, snapshotDisk.getDiskId()); + assertEquals(GENERATED_ID, snapshotDisk.getGeneratedId()); + assertEquals(SNAPSHOT_DISK_CONFIGURATION, snapshotDisk.getConfiguration()); + assertEquals(CREATION_TIMESTAMP, snapshotDisk.getCreationTimestamp()); + assertEquals(CREATION_STATUS, snapshotDisk.getCreationStatus()); + assertEquals(DESCRIPTION, snapshotDisk.getDescription()); + assertEquals(LICENSES, snapshotDisk.getLicenses()); + assertEquals(ATTACHED_INSTANCES, snapshotDisk.getAttachedInstances()); + assertEquals(LAST_ATTACH_TIMESTAMP, snapshotDisk.getLastAttachTimestamp()); + assertEquals(LAST_DETACH_TIMESTAMP, snapshotDisk.getLastDetachTimestamp()); + assertSame(serviceMockReturnsOptions, snapshotDisk.getCompute()); + Disk disk = new Disk.Builder(serviceMockReturnsOptions, DISK_ID, DISK_CONFIGURATION) + .setDiskId(DiskId.of("newProject", "newZone")) + .setConfiguration(SNAPSHOT_DISK_CONFIGURATION) + .build(); + assertEquals(DiskId.of("newProject", "newZone"), disk.getDiskId()); + assertNull(disk.getGeneratedId()); + assertEquals(SNAPSHOT_DISK_CONFIGURATION, disk.getConfiguration()); + assertNull(disk.getCreationTimestamp()); + assertNull(disk.getCreationStatus()); + assertNull(disk.getDescription()); + assertNull(disk.getLicenses()); + assertNull(disk.getAttachedInstances()); + assertNull(disk.getLastAttachTimestamp()); + assertNull(disk.getLastDetachTimestamp()); + assertSame(serviceMockReturnsOptions, disk.getCompute()); + } + + @Test + public void testBuilderDeprecated() { initializeExpectedDisk(4); assertEquals(DISK_ID, standardDisk.diskId()); assertEquals(GENERATED_ID, standardDisk.generatedId()); @@ -225,7 +278,7 @@ public void testDeleteOperation() { initializeExpectedDisk(4); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "zone", "op")) + .setOperationId(ZoneOperationId.of("project", "zone", "op")) .build(); expect(compute.deleteDisk(DISK_ID)).andReturn(operation); replay(compute); @@ -307,14 +360,14 @@ public void testCreateSnapshot() { initializeExpectedDisk(4); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "zone", "op")) + .setOperationId(ZoneOperationId.of("project", "zone", "op")) .build(); - SnapshotId snapshotId = SnapshotId.of(SNAPSHOT.snapshot()); - SnapshotInfo snapshot = SnapshotInfo.builder(snapshotId, DISK_ID).build(); + SnapshotId snapshotId = SnapshotId.of(SNAPSHOT.getSnapshot()); + SnapshotInfo snapshot = SnapshotInfo.newBuilder(snapshotId, DISK_ID).build(); expect(compute.create(snapshot)).andReturn(operation); replay(compute); initializeDisk(); - assertSame(operation, disk.createSnapshot(SNAPSHOT.snapshot())); + assertSame(operation, disk.createSnapshot(SNAPSHOT.getSnapshot())); } @Test @@ -322,16 +375,16 @@ public void testCreateSnapshotWithDescription() { initializeExpectedDisk(4); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "zone", "op")) + .setOperationId(ZoneOperationId.of("project", "zone", "op")) .build(); - SnapshotId snapshotId = SnapshotId.of(SNAPSHOT.snapshot()); - SnapshotInfo snapshot = SnapshotInfo.builder(snapshotId, DISK_ID) - .description("description") + SnapshotId snapshotId = SnapshotId.of(SNAPSHOT.getSnapshot()); + SnapshotInfo snapshot = SnapshotInfo.newBuilder(snapshotId, DISK_ID) + .setDescription("description") .build(); expect(compute.create(snapshot)).andReturn(operation); replay(compute); initializeDisk(); - assertSame(operation, disk.createSnapshot(SNAPSHOT.snapshot(), "description")); + assertSame(operation, disk.createSnapshot(SNAPSHOT.getSnapshot(), "description")); } @Test @@ -339,15 +392,15 @@ public void testCreateSnapshotWithOptions() { initializeExpectedDisk(4); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "zone", "op")) + .setOperationId(ZoneOperationId.of("project", "zone", "op")) .build(); - SnapshotId snapshotId = SnapshotId.of(SNAPSHOT.snapshot()); - SnapshotInfo snapshot = SnapshotInfo.builder(snapshotId, DISK_ID).build(); + SnapshotId snapshotId = SnapshotId.of(SNAPSHOT.getSnapshot()); + SnapshotInfo snapshot = SnapshotInfo.newBuilder(snapshotId, DISK_ID).build(); expect(compute.create(snapshot, Compute.OperationOption.fields())).andReturn(operation); replay(compute); initializeDisk(); assertSame(operation, - disk.createSnapshot(SNAPSHOT.snapshot(), Compute.OperationOption.fields())); + disk.createSnapshot(SNAPSHOT.getSnapshot(), Compute.OperationOption.fields())); } @Test @@ -355,17 +408,17 @@ public void testCreateSnapshotWithDescriptionAndOptions() { initializeExpectedDisk(4); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "zone", "op")) + .setOperationId(ZoneOperationId.of("project", "zone", "op")) .build(); - SnapshotId snapshotId = SnapshotId.of(SNAPSHOT.snapshot()); - SnapshotInfo snapshot = SnapshotInfo.builder(snapshotId, DISK_ID) - .description("description") + SnapshotId snapshotId = SnapshotId.of(SNAPSHOT.getSnapshot()); + SnapshotInfo snapshot = SnapshotInfo.newBuilder(snapshotId, DISK_ID) + .setDescription("description") .build(); expect(compute.create(snapshot, Compute.OperationOption.fields())).andReturn(operation); replay(compute); initializeDisk(); assertSame(operation, - disk.createSnapshot(SNAPSHOT.snapshot(), "description", Compute.OperationOption.fields())); + disk.createSnapshot(SNAPSHOT.getSnapshot(), "description", Compute.OperationOption.fields())); } @Test @@ -373,14 +426,14 @@ public void testCreateImage() { initializeExpectedDisk(4); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(GlobalOperationId.of("project", "op")) + .setOperationId(GlobalOperationId.of("project", "op")) .build(); - ImageId imageId = ImageId.of(IMAGE.image()); + ImageId imageId = ImageId.of(IMAGE.getImage()); ImageInfo image = ImageInfo.of(imageId, DiskImageConfiguration.of(DISK_ID)); expect(compute.create(image)).andReturn(operation); replay(compute); initializeDisk(); - assertSame(operation, disk.createImage(IMAGE.image())); + assertSame(operation, disk.createImage(IMAGE.getImage())); } @Test @@ -388,16 +441,16 @@ public void testCreateImageWithDescription() { initializeExpectedDisk(4); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(GlobalOperationId.of("project", "op")) + .setOperationId(GlobalOperationId.of("project", "op")) .build(); - ImageId imageId = ImageId.of(IMAGE.image()); - ImageInfo image = ImageInfo.builder(imageId, DiskImageConfiguration.of(DISK_ID)) - .description("description") + ImageId imageId = ImageId.of(IMAGE.getImage()); + ImageInfo image = ImageInfo.newBuilder(imageId, DiskImageConfiguration.of(DISK_ID)) + .setDescription("description") .build(); expect(compute.create(image)).andReturn(operation); replay(compute); initializeDisk(); - assertSame(operation, disk.createImage(IMAGE.image(), "description")); + assertSame(operation, disk.createImage(IMAGE.getImage(), "description")); } @Test @@ -405,14 +458,14 @@ public void testCreateImageWithOptions() { initializeExpectedDisk(4); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(GlobalOperationId.of("project", "op")) + .setOperationId(GlobalOperationId.of("project", "op")) .build(); - ImageId imageId = ImageId.of(IMAGE.image()); + ImageId imageId = ImageId.of(IMAGE.getImage()); ImageInfo image = ImageInfo.of(imageId, DiskImageConfiguration.of(DISK_ID)); expect(compute.create(image, Compute.OperationOption.fields())).andReturn(operation); replay(compute); initializeDisk(); - assertSame(operation, disk.createImage(IMAGE.image(), Compute.OperationOption.fields())); + assertSame(operation, disk.createImage(IMAGE.getImage(), Compute.OperationOption.fields())); } @Test @@ -420,17 +473,17 @@ public void testCreateImageWithDescriptionAndOptions() { initializeExpectedDisk(4); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(GlobalOperationId.of("project", "op")) + .setOperationId(GlobalOperationId.of("project", "op")) .build(); - ImageId imageId = ImageId.of(IMAGE.image()); - ImageInfo image = ImageInfo.builder(imageId, DiskImageConfiguration.of(DISK_ID)) - .description("description") + ImageId imageId = ImageId.of(IMAGE.getImage()); + ImageInfo image = ImageInfo.newBuilder(imageId, DiskImageConfiguration.of(DISK_ID)) + .setDescription("description") .build(); expect(compute.create(image, Compute.OperationOption.fields())).andReturn(operation); replay(compute); initializeDisk(); assertSame(operation, - disk.createImage(IMAGE.image(), "description", Compute.OperationOption.fields())); + disk.createImage(IMAGE.getImage(), "description", Compute.OperationOption.fields())); } @Test @@ -438,7 +491,7 @@ public void testResizeOperation() { initializeExpectedDisk(4); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "zone", "op")) + .setOperationId(ZoneOperationId.of("project", "zone", "op")) .build(); expect(compute.resize(DISK_ID, 42L)).andReturn(operation); replay(compute); @@ -458,17 +511,17 @@ public void testResizeNull() { public void compareDisk(Disk expected, Disk value) { assertEquals(expected, value); - assertEquals(expected.compute().options(), value.compute().options()); - assertEquals(expected.diskId(), value.diskId()); - assertEquals(expected.configuration(), value.configuration()); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.creationStatus(), value.creationStatus()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.licenses(), value.licenses()); - assertEquals(expected.attachedInstances(), value.attachedInstances()); - assertEquals(expected.lastAttachTimestamp(), value.lastAttachTimestamp()); - assertEquals(expected.lastDetachTimestamp(), value.lastDetachTimestamp()); + assertEquals(expected.getCompute().options(), value.getCompute().options()); + assertEquals(expected.getDiskId(), value.getDiskId()); + assertEquals(expected.getConfiguration(), value.getConfiguration()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getCreationStatus(), value.getCreationStatus()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getLicenses(), value.getLicenses()); + assertEquals(expected.getAttachedInstances(), value.getAttachedInstances()); + assertEquals(expected.getLastAttachTimestamp(), value.getLastAttachTimestamp()); + assertEquals(expected.getLastDetachTimestamp(), value.getLastDetachTimestamp()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskTypeIdTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskTypeIdTest.java index ac6788329a32..6483c3d70e07 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskTypeIdTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskTypeIdTest.java @@ -39,6 +39,19 @@ public class DiskTypeIdTest { @Test public void testOf() { + DiskTypeId diskTypeId = DiskTypeId.of(PROJECT, ZONE, DISK_TYPE); + assertEquals(PROJECT, diskTypeId.getProject()); + assertEquals(ZONE, diskTypeId.getZone()); + assertEquals(DISK_TYPE, diskTypeId.getType()); + assertEquals(URL, diskTypeId.getSelfLink()); + diskTypeId = DiskTypeId.of(ZONE, DISK_TYPE); + assertNull(diskTypeId.getProject()); + assertEquals(ZONE, diskTypeId.getZone()); + assertEquals(DISK_TYPE, diskTypeId.getType()); + } + + @Test + public void testOfDeprecated() { DiskTypeId diskTypeId = DiskTypeId.of(PROJECT, ZONE, DISK_TYPE); assertEquals(PROJECT, diskTypeId.project()); assertEquals(ZONE, diskTypeId.zone()); @@ -54,7 +67,7 @@ public void testOf() { public void testToAndFromUrl() { DiskTypeId diskTypeId = DiskTypeId.of(PROJECT, ZONE, DISK_TYPE); assertSame(diskTypeId, diskTypeId.setProjectId(PROJECT)); - compareDiskTypeId(diskTypeId, DiskTypeId.fromUrl(diskTypeId.selfLink())); + compareDiskTypeId(diskTypeId, DiskTypeId.fromUrl(diskTypeId.getSelfLink())); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("notMatchingUrl is not a valid disk type URL"); DiskTypeId.fromUrl("notMatchingUrl"); @@ -69,16 +82,16 @@ public void testSetProjectId() { @Test public void testMatchesUrl() { - assertTrue(DiskTypeId.matchesUrl(DiskTypeId.of(PROJECT, ZONE, DISK_TYPE).selfLink())); + assertTrue(DiskTypeId.matchesUrl(DiskTypeId.of(PROJECT, ZONE, DISK_TYPE).getSelfLink())); assertFalse(DiskTypeId.matchesUrl("notMatchingUrl")); } private void compareDiskTypeId(DiskTypeId expected, DiskTypeId value) { assertEquals(expected, value); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.zone(), expected.zone()); - assertEquals(expected.type(), expected.type()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getZone(), expected.getZone()); + assertEquals(expected.getType(), expected.getType()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskTypeTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskTypeTest.java index 691d1fcd336d..f0a8747b0880 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskTypeTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/DiskTypeTest.java @@ -30,18 +30,29 @@ public class DiskTypeTest { private static final DiskTypeId DISK_TYPE_ID = DiskTypeId.of("project", "zone", "diskType"); private static final DeprecationStatus DEPRECATION_STATUS = DeprecationStatus.of(DeprecationStatus.Status.DELETED, DISK_TYPE_ID); - private static final DiskType DISK_TYPE = DiskType.builder() - .generatedId(GENERATED_ID) - .diskTypeId(DISK_TYPE_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .validDiskSize(VALID_DISK_SIZE) - .defaultDiskSizeGb(DEFAULT_DISK_SIZE_GB) - .deprecationStatus(DEPRECATION_STATUS) + private static final DiskType DISK_TYPE = DiskType.newBuilder() + .setGeneratedId(GENERATED_ID) + .setDiskTypeId(DISK_TYPE_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setValidDiskSize(VALID_DISK_SIZE) + .setDefaultDiskSizeGb(DEFAULT_DISK_SIZE_GB) + .setDeprecationStatus(DEPRECATION_STATUS) .build(); @Test public void testBuilder() { + assertEquals(GENERATED_ID, DISK_TYPE.getGeneratedId()); + assertEquals(DISK_TYPE_ID, DISK_TYPE.getDiskTypeId()); + assertEquals(CREATION_TIMESTAMP, DISK_TYPE.getCreationTimestamp()); + assertEquals(DESCRIPTION, DISK_TYPE.getDescription()); + assertEquals(VALID_DISK_SIZE, DISK_TYPE.getValidDiskSize()); + assertEquals(DEFAULT_DISK_SIZE_GB, DISK_TYPE.getDefaultDiskSizeGb()); + assertEquals(DEPRECATION_STATUS, DISK_TYPE.getDeprecationStatus()); + } + + @Test + public void testBuilderDeprecated() { assertEquals(GENERATED_ID, DISK_TYPE.generatedId()); assertEquals(DISK_TYPE_ID, DISK_TYPE.diskTypeId()); assertEquals(CREATION_TIMESTAMP, DISK_TYPE.creationTimestamp()); @@ -54,19 +65,19 @@ public void testBuilder() { @Test public void testToPbAndFromPb() { compareDiskTypes(DISK_TYPE, DiskType.fromPb(DISK_TYPE.toPb())); - DiskType diskType = DiskType.builder().diskTypeId(DISK_TYPE_ID).build(); + DiskType diskType = DiskType.newBuilder().setDiskTypeId(DISK_TYPE_ID).build(); compareDiskTypes(diskType, DiskType.fromPb(diskType.toPb())); } private void compareDiskTypes(DiskType expected, DiskType value) { assertEquals(expected, value); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.diskTypeId(), value.diskTypeId()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.validDiskSize(), value.validDiskSize()); - assertEquals(expected.defaultDiskSizeGb(), value.defaultDiskSizeGb()); - assertEquals(expected.deprecationStatus(), value.deprecationStatus()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getDiskTypeId(), value.getDiskTypeId()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getValidDiskSize(), value.getValidDiskSize()); + assertEquals(expected.getDefaultDiskSizeGb(), value.getDefaultDiskSizeGb()); + assertEquals(expected.getDeprecationStatus(), value.getDeprecationStatus()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/ForwardingRuleIdTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/ForwardingRuleIdTest.java index 3afc0c187c05..b3c7aad52b12 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/ForwardingRuleIdTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/ForwardingRuleIdTest.java @@ -41,6 +41,37 @@ public class ForwardingRuleIdTest { @Test public void testOf() { + GlobalForwardingRuleId forwardingRuleId = GlobalForwardingRuleId.of(PROJECT, NAME); + assertEquals(PROJECT, forwardingRuleId.getProject()); + assertEquals(NAME, forwardingRuleId.getRule()); + assertEquals(GLOBAL_URL, forwardingRuleId.getSelfLink()); + assertEquals(ForwardingRuleId.Type.GLOBAL, forwardingRuleId.getType()); + forwardingRuleId = GlobalForwardingRuleId.of(NAME); + assertNull(forwardingRuleId.getProject()); + assertEquals(NAME, forwardingRuleId.getRule()); + assertEquals(ForwardingRuleId.Type.GLOBAL, forwardingRuleId.getType()); + RegionForwardingRuleId regionForwardingRuleId = + RegionForwardingRuleId.of(PROJECT, REGION, NAME); + assertEquals(PROJECT, regionForwardingRuleId.getProject()); + assertEquals(REGION, regionForwardingRuleId.getRegion()); + assertEquals(NAME, regionForwardingRuleId.getRule()); + assertEquals(REGION_URL, regionForwardingRuleId.getSelfLink()); + assertEquals(ForwardingRuleId.Type.REGION, regionForwardingRuleId.getType()); + regionForwardingRuleId = RegionForwardingRuleId.of(RegionId.of(PROJECT, REGION), NAME); + assertEquals(PROJECT, regionForwardingRuleId.getProject()); + assertEquals(REGION, regionForwardingRuleId.getRegion()); + assertEquals(NAME, regionForwardingRuleId.getRule()); + assertEquals(REGION_URL, regionForwardingRuleId.getSelfLink()); + assertEquals(ForwardingRuleId.Type.REGION, regionForwardingRuleId.getType()); + regionForwardingRuleId = RegionForwardingRuleId.of(REGION, NAME); + assertNull(regionForwardingRuleId.getProject()); + assertEquals(REGION, regionForwardingRuleId.getRegion()); + assertEquals(NAME, regionForwardingRuleId.getRule()); + assertEquals(ForwardingRuleId.Type.REGION, regionForwardingRuleId.getType()); + } + + @Test + public void testOfDeprecated() { GlobalForwardingRuleId forwardingRuleId = GlobalForwardingRuleId.of(PROJECT, NAME); assertEquals(PROJECT, forwardingRuleId.project()); assertEquals(NAME, forwardingRuleId.rule()); @@ -74,11 +105,11 @@ public void testOf() { public void testToAndFromUrlGlobal() { GlobalForwardingRuleId forwardingRuleId = GlobalForwardingRuleId.of(PROJECT, NAME); compareGlobalForwardingRuleId(forwardingRuleId, - GlobalForwardingRuleId.fromUrl(forwardingRuleId.selfLink())); + GlobalForwardingRuleId.fromUrl(forwardingRuleId.getSelfLink())); RegionForwardingRuleId regionForwardingRuleId = RegionForwardingRuleId.of(PROJECT, REGION, NAME); compareRegionForwardingRuleId(regionForwardingRuleId, - RegionForwardingRuleId.fromUrl(regionForwardingRuleId.selfLink())); + RegionForwardingRuleId.fromUrl(regionForwardingRuleId.getSelfLink())); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("notMatchingUrl is not a valid global forwarding rule URL"); GlobalForwardingRuleId.fromUrl("notMatchingUrl"); @@ -89,7 +120,7 @@ public void testToAndFromUrlRegion() { RegionForwardingRuleId regionForwardingRuleId = RegionForwardingRuleId.of(PROJECT, REGION, NAME); compareRegionForwardingRuleId(regionForwardingRuleId, - RegionForwardingRuleId.fromUrl(regionForwardingRuleId.selfLink())); + RegionForwardingRuleId.fromUrl(regionForwardingRuleId.getSelfLink())); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("notMatchingUrl is not a valid region forwarding rule URL"); RegionForwardingRuleId.fromUrl("notMatchingUrl"); @@ -111,29 +142,29 @@ public void testSetProjectId() { @Test public void testMatchesUrl() { assertTrue(GlobalForwardingRuleId.matchesUrl( - GlobalForwardingRuleId.of(PROJECT, NAME).selfLink())); + GlobalForwardingRuleId.of(PROJECT, NAME).getSelfLink())); assertFalse(GlobalForwardingRuleId.matchesUrl("notMatchingUrl")); assertTrue(RegionForwardingRuleId.matchesUrl( - RegionForwardingRuleId.of(PROJECT, REGION, NAME).selfLink())); + RegionForwardingRuleId.of(PROJECT, REGION, NAME).getSelfLink())); assertFalse(RegionForwardingRuleId.matchesUrl("notMatchingUrl")); } private void compareGlobalForwardingRuleId(GlobalForwardingRuleId expected, GlobalForwardingRuleId value) { assertEquals(expected, value); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.rule(), expected.rule()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getRule(), expected.getRule()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } private void compareRegionForwardingRuleId(RegionForwardingRuleId expected, RegionForwardingRuleId value) { assertEquals(expected, value); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.region(), expected.region()); - assertEquals(expected.rule(), expected.rule()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getRegion(), expected.getRegion()); + assertEquals(expected.getRule(), expected.getRule()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/ImageDiskConfigurationTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/ImageDiskConfigurationTest.java index db8974ddeee4..4fcd856d544c 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/ImageDiskConfigurationTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/ImageDiskConfigurationTest.java @@ -31,10 +31,16 @@ public class ImageDiskConfigurationTest { private static final ImageId IMAGE = ImageId.of("project", "image"); private static final String IMAGE_ID = "imageId"; private static final ImageDiskConfiguration DISK_CONFIGURATION = + ImageDiskConfiguration.newBuilder(IMAGE) + .setSizeGb(SIZE) + .setDiskType(DISK_TYPE) + .setSourceImageId(IMAGE_ID) + .build(); + private static final ImageDiskConfiguration DEPRECATED_DISK_CONFIGURATION = ImageDiskConfiguration.builder(IMAGE) .sizeGb(SIZE) .diskType(DISK_TYPE) - .sourceImageId(IMAGE_ID) + .setSourceImageId(IMAGE_ID) .build(); @Test @@ -42,17 +48,17 @@ public void testToBuilder() { compareImageDiskConfiguration(DISK_CONFIGURATION, DISK_CONFIGURATION.toBuilder().build()); ImageId newImageId = ImageId.of("newProject", "newImage"); ImageDiskConfiguration diskConfiguration = DISK_CONFIGURATION.toBuilder() - .sizeGb(24L) - .sourceImage(newImageId) - .sourceImageId("newImageId") + .setSizeGb(24L) + .setSourceImage(newImageId) + .setSourceImageId("newImageId") .build(); - assertEquals(24L, diskConfiguration.sizeGb().longValue()); - assertEquals(newImageId, diskConfiguration.sourceImage()); - assertEquals("newImageId", diskConfiguration.sourceImageId()); + assertEquals(24L, diskConfiguration.getSizeGb().longValue()); + assertEquals(newImageId, diskConfiguration.getSourceImage()); + assertEquals("newImageId", diskConfiguration.getSourceImageId()); diskConfiguration = diskConfiguration.toBuilder() - .sizeGb(SIZE) - .sourceImage(IMAGE) - .sourceImageId(IMAGE_ID) + .setSizeGb(SIZE) + .setSourceImage(IMAGE) + .setSourceImageId(IMAGE_ID) .build(); compareImageDiskConfiguration(DISK_CONFIGURATION, diskConfiguration); } @@ -65,11 +71,20 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { - assertEquals(DISK_TYPE, DISK_CONFIGURATION.diskType()); - assertEquals(SIZE, DISK_CONFIGURATION.sizeGb()); - assertEquals(IMAGE, DISK_CONFIGURATION.sourceImage()); - assertEquals(IMAGE_ID, DISK_CONFIGURATION.sourceImageId()); - assertEquals(Type.IMAGE, DISK_CONFIGURATION.type()); + assertEquals(DISK_TYPE, DISK_CONFIGURATION.getDiskType()); + assertEquals(SIZE, DISK_CONFIGURATION.getSizeGb()); + assertEquals(IMAGE, DISK_CONFIGURATION.getSourceImage()); + assertEquals(IMAGE_ID, DISK_CONFIGURATION.getSourceImageId()); + assertEquals(Type.IMAGE, DISK_CONFIGURATION.getType()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(DISK_TYPE, DEPRECATED_DISK_CONFIGURATION.diskType()); + assertEquals(SIZE, DEPRECATED_DISK_CONFIGURATION.sizeGb()); + assertEquals(IMAGE, DEPRECATED_DISK_CONFIGURATION.sourceImage()); + assertEquals(IMAGE_ID, DEPRECATED_DISK_CONFIGURATION.sourceImageId()); + assertEquals(Type.IMAGE, DEPRECATED_DISK_CONFIGURATION.type()); } @Test @@ -83,18 +98,18 @@ public void testToAndFromPb() { @Test public void testOf() { ImageDiskConfiguration configuration = ImageDiskConfiguration.of(IMAGE); - assertNull(configuration.diskType()); - assertNull(configuration.sizeGb()); - assertNull(configuration.sourceImageId()); - assertEquals(IMAGE, configuration.sourceImage()); - assertEquals(Type.IMAGE, configuration.type()); + assertNull(configuration.getDiskType()); + assertNull(configuration.getSizeGb()); + assertNull(configuration.getSourceImageId()); + assertEquals(IMAGE, configuration.getSourceImage()); + assertEquals(Type.IMAGE, configuration.getType()); } @Test public void testSetProjectId() { ImageDiskConfiguration diskConfiguration = DISK_CONFIGURATION.toBuilder() - .diskType(DiskTypeId.of(DISK_TYPE.zone(), DISK_TYPE.type())) - .sourceImage(ImageId.of(IMAGE.image())) + .setDiskType(DiskTypeId.of(DISK_TYPE.getZone(), DISK_TYPE.getType())) + .setSourceImage(ImageId.of(IMAGE.getImage())) .build(); compareImageDiskConfiguration(DISK_CONFIGURATION, diskConfiguration.setProjectId("project")); } @@ -102,11 +117,11 @@ public void testSetProjectId() { private void compareImageDiskConfiguration(ImageDiskConfiguration expected, ImageDiskConfiguration value) { assertEquals(expected, value); - assertEquals(expected.diskType(), value.diskType()); - assertEquals(expected.sizeGb(), value.sizeGb()); - assertEquals(expected.sourceImage(), value.sourceImage()); - assertEquals(expected.sourceImageId(), value.sourceImageId()); - assertEquals(expected.type(), value.type()); + assertEquals(expected.getDiskType(), value.getDiskType()); + assertEquals(expected.getSizeGb(), value.getSizeGb()); + assertEquals(expected.getSourceImage(), value.getSourceImage()); + assertEquals(expected.getSourceImageId(), value.getSourceImageId()); + assertEquals(expected.getType(), value.getType()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/ImageIdTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/ImageIdTest.java index 32f8ac7c024b..a773ea1942fb 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/ImageIdTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/ImageIdTest.java @@ -38,6 +38,17 @@ public class ImageIdTest { @Test public void testOf() { + ImageId imageId = ImageId.of(PROJECT, NAME); + assertEquals(PROJECT, imageId.getProject()); + assertEquals(NAME, imageId.getImage()); + assertEquals(URL, imageId.getSelfLink()); + imageId = ImageId.of(NAME); + assertNull(imageId.getProject()); + assertEquals(NAME, imageId.getImage()); + } + + @Test + public void testOfDeprecated() { ImageId imageId = ImageId.of(PROJECT, NAME); assertEquals(PROJECT, imageId.project()); assertEquals(NAME, imageId.image()); @@ -50,7 +61,7 @@ public void testOf() { @Test public void testToAndFromUrl() { ImageId imageId = ImageId.of(PROJECT, NAME); - compareImageId(imageId, ImageId.fromUrl(imageId.selfLink())); + compareImageId(imageId, ImageId.fromUrl(imageId.getSelfLink())); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("notMatchingUrl is not a valid image URL"); ImageId.fromUrl("notMatchingUrl"); @@ -65,15 +76,15 @@ public void testSetProjectId() { @Test public void testMatchesUrl() { - assertTrue(ImageId.matchesUrl(ImageId.of(PROJECT, NAME).selfLink())); + assertTrue(ImageId.matchesUrl(ImageId.of(PROJECT, NAME).getSelfLink())); assertFalse(ImageId.matchesUrl("notMatchingUrl")); } private void compareImageId(ImageId expected, ImageId value) { assertEquals(expected, value); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.image(), expected.image()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getImage(), expected.getImage()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/ImageInfoTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/ImageInfoTest.java index 4433fbe96ffb..131fc55929da 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/ImageInfoTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/ImageInfoTest.java @@ -43,46 +43,68 @@ public class ImageInfoTest { private static final String SOURCE_DISK_ID = "diskId"; private static final SourceType SOURCE_TYPE = SourceType.RAW; private static final StorageImageConfiguration STORAGE_CONFIGURATION = - StorageImageConfiguration.builder(STORAGE_SOURCE) - .archiveSizeBytes(ARCHIVE_SIZE_BYTES) - .containerType(StorageImageConfiguration.ContainerType.TAR) - .sha1(SHA1_CHECKSUM) - .sourceType(SOURCE_TYPE) + StorageImageConfiguration.newBuilder(STORAGE_SOURCE) + .setArchiveSizeBytes(ARCHIVE_SIZE_BYTES) + .setContainerType(StorageImageConfiguration.ContainerType.TAR) + .setSha1(SHA1_CHECKSUM) + .setSourceType(SOURCE_TYPE) .build(); private static final DiskImageConfiguration DISK_CONFIGURATION = - DiskImageConfiguration.builder(SOURCE_DISK) - .archiveSizeBytes(ARCHIVE_SIZE_BYTES) - .sourceDiskId(SOURCE_DISK_ID) - .sourceType(SOURCE_TYPE) + DiskImageConfiguration.newBuilder(SOURCE_DISK) + .setArchiveSizeBytes(ARCHIVE_SIZE_BYTES) + .setSourceDiskId(SOURCE_DISK_ID) + .setSourceType(SOURCE_TYPE) .build(); private static final DeprecationStatus DEPRECATION_STATUS = DeprecationStatus.of(DeprecationStatus.Status.DELETED, IMAGE_ID); - private static final ImageInfo STORAGE_IMAGE = ImageInfo.builder(IMAGE_ID, STORAGE_CONFIGURATION) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .status(STATUS) - .diskSizeGb(DISK_SIZE_GB) - .licenses(LICENSES) - .deprecationStatus(DEPRECATION_STATUS) - .build(); - private static final ImageInfo DISK_IMAGE = ImageInfo.builder(IMAGE_ID, DISK_CONFIGURATION) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .status(STATUS) - .diskSizeGb(DISK_SIZE_GB) - .licenses(LICENSES) - .deprecationStatus(DEPRECATION_STATUS) - .build(); + private static final ImageInfo STORAGE_IMAGE = + ImageInfo.newBuilder(IMAGE_ID, STORAGE_CONFIGURATION) + .setGeneratedId(GENERATED_ID) + .getCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(STATUS) + .setDiskSizeGb(DISK_SIZE_GB) + .setLicenses(LICENSES) + .setDeprecationStatus(DEPRECATION_STATUS) + .build(); + private static final ImageInfo DISK_IMAGE = + ImageInfo.newBuilder(IMAGE_ID, DISK_CONFIGURATION) + .setGeneratedId(GENERATED_ID) + .getCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(STATUS) + .setDiskSizeGb(DISK_SIZE_GB) + .setLicenses(LICENSES) + .setDeprecationStatus(DEPRECATION_STATUS) + .build(); + private static final ImageInfo DEPRECATED_STORAGE_IMAGE = + ImageInfo.builder(IMAGE_ID, STORAGE_CONFIGURATION) + .setGeneratedId(GENERATED_ID) + .getCreationTimestamp(CREATION_TIMESTAMP) + .description(DESCRIPTION) + .setStatus(STATUS) + .setDiskSizeGb(DISK_SIZE_GB) + .setLicenses(LICENSES) + .setDeprecationStatus(DEPRECATION_STATUS) + .build(); + private static final ImageInfo DEPRECATED_DISK_IMAGE = + ImageInfo.builder(IMAGE_ID, DISK_CONFIGURATION) + .setGeneratedId(GENERATED_ID) + .getCreationTimestamp(CREATION_TIMESTAMP) + .description(DESCRIPTION) + .setStatus(STATUS) + .setDiskSizeGb(DISK_SIZE_GB) + .setLicenses(LICENSES) + .setDeprecationStatus(DEPRECATION_STATUS) + .build(); @Test public void testToBuilder() { compareImageInfo(STORAGE_IMAGE, STORAGE_IMAGE.toBuilder().build()); compareImageInfo(DISK_IMAGE, DISK_IMAGE.toBuilder().build()); - ImageInfo imageInfo = STORAGE_IMAGE.toBuilder().description("newDescription").build(); - assertEquals("newDescription", imageInfo.description()); - imageInfo = imageInfo.toBuilder().description("description").build(); + ImageInfo imageInfo = STORAGE_IMAGE.toBuilder().setDescription("newDescription").build(); + assertEquals("newDescription", imageInfo.getDescription()); + imageInfo = imageInfo.toBuilder().setDescription("description").build(); compareImageInfo(STORAGE_IMAGE, imageInfo); } @@ -96,48 +118,70 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { - assertEquals(GENERATED_ID, STORAGE_IMAGE.generatedId()); - assertEquals(IMAGE_ID, STORAGE_IMAGE.imageId()); - assertEquals(CREATION_TIMESTAMP, STORAGE_IMAGE.creationTimestamp()); - assertEquals(DESCRIPTION, STORAGE_IMAGE.description()); - assertEquals(STORAGE_CONFIGURATION, STORAGE_IMAGE.configuration()); - assertEquals(STATUS, STORAGE_IMAGE.status()); - assertEquals(DISK_SIZE_GB, STORAGE_IMAGE.diskSizeGb()); - assertEquals(LICENSES, STORAGE_IMAGE.licenses()); - assertEquals(DEPRECATION_STATUS, STORAGE_IMAGE.deprecationStatus()); - assertEquals(GENERATED_ID, DISK_IMAGE.generatedId()); - assertEquals(IMAGE_ID, DISK_IMAGE.imageId()); - assertEquals(CREATION_TIMESTAMP, DISK_IMAGE.creationTimestamp()); - assertEquals(DESCRIPTION, DISK_IMAGE.description()); - assertEquals(DISK_CONFIGURATION, DISK_IMAGE.configuration()); - assertEquals(STATUS, DISK_IMAGE.status()); - assertEquals(DISK_SIZE_GB, DISK_IMAGE.diskSizeGb()); - assertEquals(LICENSES, DISK_IMAGE.licenses()); - assertEquals(DEPRECATION_STATUS, DISK_IMAGE.deprecationStatus()); + assertEquals(GENERATED_ID, STORAGE_IMAGE.getGeneratedId()); + assertEquals(IMAGE_ID, STORAGE_IMAGE.getImageId()); + assertEquals(CREATION_TIMESTAMP, STORAGE_IMAGE.getCreationTimestamp()); + assertEquals(DESCRIPTION, STORAGE_IMAGE.getDescription()); + assertEquals(STORAGE_CONFIGURATION, STORAGE_IMAGE.getConfiguration()); + assertEquals(STATUS, STORAGE_IMAGE.getStatus()); + assertEquals(DISK_SIZE_GB, STORAGE_IMAGE.getDiskSizeGb()); + assertEquals(LICENSES, STORAGE_IMAGE.getLicenses()); + assertEquals(DEPRECATION_STATUS, STORAGE_IMAGE.getDeprecationStatus()); + assertEquals(GENERATED_ID, DISK_IMAGE.getGeneratedId()); + assertEquals(IMAGE_ID, DISK_IMAGE.getImageId()); + assertEquals(CREATION_TIMESTAMP, DISK_IMAGE.getCreationTimestamp()); + assertEquals(DESCRIPTION, DISK_IMAGE.getDescription()); + assertEquals(DISK_CONFIGURATION, DISK_IMAGE.getConfiguration()); + assertEquals(STATUS, DISK_IMAGE.getStatus()); + assertEquals(DISK_SIZE_GB, DISK_IMAGE.getDiskSizeGb()); + assertEquals(LICENSES, DISK_IMAGE.getLicenses()); + assertEquals(DEPRECATION_STATUS, DISK_IMAGE.getDeprecationStatus()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(GENERATED_ID, DEPRECATED_STORAGE_IMAGE.generatedId()); + assertEquals(IMAGE_ID, DEPRECATED_STORAGE_IMAGE.imageId()); + assertEquals(CREATION_TIMESTAMP, DEPRECATED_STORAGE_IMAGE.creationTimestamp()); + assertEquals(DESCRIPTION, DEPRECATED_STORAGE_IMAGE.description()); + assertEquals(STORAGE_CONFIGURATION, DEPRECATED_STORAGE_IMAGE.configuration()); + assertEquals(STATUS, DEPRECATED_STORAGE_IMAGE.status()); + assertEquals(DISK_SIZE_GB, DEPRECATED_STORAGE_IMAGE.diskSizeGb()); + assertEquals(LICENSES, DEPRECATED_STORAGE_IMAGE.licenses()); + assertEquals(DEPRECATION_STATUS, DEPRECATED_STORAGE_IMAGE.deprecationStatus()); + assertEquals(GENERATED_ID, DEPRECATED_DISK_IMAGE.generatedId()); + assertEquals(IMAGE_ID, DEPRECATED_DISK_IMAGE.imageId()); + assertEquals(CREATION_TIMESTAMP, DEPRECATED_DISK_IMAGE.creationTimestamp()); + assertEquals(DESCRIPTION, DEPRECATED_DISK_IMAGE.description()); + assertEquals(DISK_CONFIGURATION, DEPRECATED_DISK_IMAGE.configuration()); + assertEquals(STATUS, DEPRECATED_DISK_IMAGE.status()); + assertEquals(DISK_SIZE_GB, DEPRECATED_DISK_IMAGE.diskSizeGb()); + assertEquals(LICENSES, DEPRECATED_DISK_IMAGE.licenses()); + assertEquals(DEPRECATION_STATUS, DEPRECATED_DISK_IMAGE.deprecationStatus()); } @Test public void testOf() { ImageInfo imageInfo = ImageInfo.of(IMAGE_ID, STORAGE_CONFIGURATION); - assertEquals(IMAGE_ID, imageInfo.imageId()); - assertEquals(STORAGE_CONFIGURATION, imageInfo.configuration()); - assertNull(imageInfo.generatedId()); - assertNull(imageInfo.creationTimestamp()); - assertNull(imageInfo.description()); - assertNull(imageInfo.status()); - assertNull(imageInfo.diskSizeGb()); - assertNull(imageInfo.licenses()); - assertNull(imageInfo.deprecationStatus()); + assertEquals(IMAGE_ID, imageInfo.getImageId()); + assertEquals(STORAGE_CONFIGURATION, imageInfo.getConfiguration()); + assertNull(imageInfo.getGeneratedId()); + assertNull(imageInfo.getCreationTimestamp()); + assertNull(imageInfo.getDescription()); + assertNull(imageInfo.getStatus()); + assertNull(imageInfo.getDiskSizeGb()); + assertNull(imageInfo.getLicenses()); + assertNull(imageInfo.getDeprecationStatus()); imageInfo = ImageInfo.of(IMAGE_ID, DISK_CONFIGURATION); - assertEquals(IMAGE_ID, imageInfo.imageId()); - assertEquals(DISK_CONFIGURATION, imageInfo.configuration()); - assertNull(imageInfo.generatedId()); - assertNull(imageInfo.creationTimestamp()); - assertNull(imageInfo.description()); - assertNull(imageInfo.status()); - assertNull(imageInfo.diskSizeGb()); - assertNull(imageInfo.licenses()); - assertNull(imageInfo.deprecationStatus()); + assertEquals(IMAGE_ID, imageInfo.getImageId()); + assertEquals(DISK_CONFIGURATION, imageInfo.getConfiguration()); + assertNull(imageInfo.getGeneratedId()); + assertNull(imageInfo.getCreationTimestamp()); + assertNull(imageInfo.getDescription()); + assertNull(imageInfo.getStatus()); + assertNull(imageInfo.getDiskSizeGb()); + assertNull(imageInfo.getLicenses()); + assertNull(imageInfo.getDeprecationStatus()); } @Test @@ -153,23 +197,25 @@ public void testToAndFromPb() { @Test public void testSetProjectId() { ImageInfo imageInfo = DISK_IMAGE.toBuilder() - .imageId(ImageId.of("image")) - .configuration(DISK_CONFIGURATION.toBuilder().sourceDisk(DiskId.of("zone", "disk")).build()) + .setImageId(ImageId.of("image")) + .setConfiguration(DISK_CONFIGURATION.toBuilder() + .setSourceDisk(DiskId.of("zone", "disk")) + .build()) .build(); compareImageInfo(DISK_IMAGE, imageInfo.setProjectId("project")); } public void compareImageInfo(ImageInfo expected, ImageInfo value) { assertEquals(expected, value); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.imageId(), value.imageId()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.configuration(), value.configuration()); - assertEquals(expected.status(), value.status()); - assertEquals(expected.diskSizeGb(), value.diskSizeGb()); - assertEquals(expected.licenses(), value.licenses()); - assertEquals(expected.deprecationStatus(), value.deprecationStatus()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getImageId(), value.getImageId()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getConfiguration(), value.getConfiguration()); + assertEquals(expected.getStatus(), value.getStatus()); + assertEquals(expected.getDiskSizeGb(), value.getDiskSizeGb()); + assertEquals(expected.getLicenses(), value.getLicenses()); + assertEquals(expected.getDeprecationStatus(), value.getDeprecationStatus()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/ImageTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/ImageTest.java index ca1cd009c5eb..2dc8694361c5 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/ImageTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/ImageTest.java @@ -48,19 +48,20 @@ public class ImageTest { private static final String SHA1_CHECKSUM = "checksum"; private static final DiskId SOURCE_DISK = DiskId.of("project", "zone", "disk"); private static final String SOURCE_DISK_ID = "diskId"; - private static final ImageConfiguration.SourceType SOURCE_TYPE = ImageConfiguration.SourceType.RAW; + private static final ImageConfiguration.SourceType SOURCE_TYPE = + ImageConfiguration.SourceType.RAW; private static final StorageImageConfiguration STORAGE_CONFIGURATION = - StorageImageConfiguration.builder(STORAGE_SOURCE) - .archiveSizeBytes(ARCHIVE_SIZE_BYTES) - .containerType(StorageImageConfiguration.ContainerType.TAR) - .sha1(SHA1_CHECKSUM) - .sourceType(SOURCE_TYPE) + StorageImageConfiguration.newBuilder(STORAGE_SOURCE) + .setArchiveSizeBytes(ARCHIVE_SIZE_BYTES) + .setContainerType(StorageImageConfiguration.ContainerType.TAR) + .setSha1(SHA1_CHECKSUM) + .setSourceType(SOURCE_TYPE) .build(); private static final DiskImageConfiguration DISK_CONFIGURATION = - DiskImageConfiguration.builder(SOURCE_DISK) - .archiveSizeBytes(ARCHIVE_SIZE_BYTES) - .sourceDiskId(SOURCE_DISK_ID) - .sourceType(SOURCE_TYPE) + DiskImageConfiguration.newBuilder(SOURCE_DISK) + .setArchiveSizeBytes(ARCHIVE_SIZE_BYTES) + .setSourceDiskId(SOURCE_DISK_ID) + .setSourceType(SOURCE_TYPE) .build(); private static final DeprecationStatus DEPRECATION_STATUS = DeprecationStatus.of(DeprecationStatus.Status.DELETED, IMAGE_ID); @@ -76,35 +77,35 @@ private void initializeExpectedImage(int optionsCalls) { expect(serviceMockReturnsOptions.options()).andReturn(mockOptions).times(optionsCalls); replay(serviceMockReturnsOptions); diskImage = new Image.Builder(serviceMockReturnsOptions, IMAGE_ID, DISK_CONFIGURATION) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .status(STATUS) - .diskSizeGb(DISK_SIZE_GB) - .licenses(LICENSES) - .deprecationStatus(DEPRECATION_STATUS) + .setGeneratedId(GENERATED_ID) + .getCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(STATUS) + .setDiskSizeGb(DISK_SIZE_GB) + .setLicenses(LICENSES) + .setDeprecationStatus(DEPRECATION_STATUS) .build(); storageImage = new Image.Builder(serviceMockReturnsOptions, IMAGE_ID, STORAGE_CONFIGURATION) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .status(STATUS) - .diskSizeGb(DISK_SIZE_GB) - .licenses(LICENSES) - .deprecationStatus(DEPRECATION_STATUS) + .setGeneratedId(GENERATED_ID) + .getCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(STATUS) + .setDiskSizeGb(DISK_SIZE_GB) + .setLicenses(LICENSES) + .setDeprecationStatus(DEPRECATION_STATUS) .build(); compute = createStrictMock(Compute.class); } private void initializeImage() { image = new Image.Builder(compute, IMAGE_ID, DISK_CONFIGURATION) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .status(STATUS) - .diskSizeGb(DISK_SIZE_GB) - .licenses(LICENSES) - .deprecationStatus(DEPRECATION_STATUS) + .setGeneratedId(GENERATED_ID) + .getCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(STATUS) + .setDiskSizeGb(DISK_SIZE_GB) + .setLicenses(LICENSES) + .setDeprecationStatus(DEPRECATION_STATUS) .build(); } @@ -113,9 +114,9 @@ public void testToBuilder() { initializeExpectedImage(12); compareImage(diskImage, diskImage.toBuilder().build()); compareImage(storageImage, storageImage.toBuilder().build()); - Image newImage = diskImage.toBuilder().description("newDescription").build(); - assertEquals("newDescription", newImage.description()); - newImage = newImage.toBuilder().description("description").build(); + Image newImage = diskImage.toBuilder().setDescription("newDescription").build(); + assertEquals("newDescription", newImage.getDescription()); + newImage = newImage.toBuilder().setDescription("description").build(); compareImage(diskImage, newImage); } @@ -130,6 +131,46 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { + initializeExpectedImage(3); + assertEquals(GENERATED_ID, diskImage.getGeneratedId()); + assertEquals(IMAGE_ID, diskImage.getImageId()); + assertEquals(CREATION_TIMESTAMP, diskImage.getCreationTimestamp()); + assertEquals(DESCRIPTION, diskImage.getDescription()); + assertEquals(DISK_CONFIGURATION, diskImage.getConfiguration()); + assertEquals(STATUS, diskImage.getStatus()); + assertEquals(DISK_SIZE_GB, diskImage.getDiskSizeGb()); + assertEquals(LICENSES, diskImage.getLicenses()); + assertEquals(DEPRECATION_STATUS, diskImage.getDeprecationStatus()); + assertSame(serviceMockReturnsOptions, diskImage.getCompute()); + assertEquals(GENERATED_ID, storageImage.getGeneratedId()); + assertEquals(IMAGE_ID, storageImage.getImageId()); + assertEquals(CREATION_TIMESTAMP, storageImage.getCreationTimestamp()); + assertEquals(DESCRIPTION, storageImage.getDescription()); + assertEquals(STORAGE_CONFIGURATION, storageImage.getConfiguration()); + assertEquals(STATUS, storageImage.getStatus()); + assertEquals(DISK_SIZE_GB, storageImage.getDiskSizeGb()); + assertEquals(LICENSES, storageImage.getLicenses()); + assertEquals(DEPRECATION_STATUS, storageImage.getDeprecationStatus()); + assertSame(serviceMockReturnsOptions, storageImage.getCompute()); + ImageId imageId = ImageId.of("otherImage"); + Image image = new Image.Builder(serviceMockReturnsOptions, IMAGE_ID, STORAGE_CONFIGURATION) + .setImageId(imageId) + .setConfiguration(DISK_CONFIGURATION) + .build(); + assertNull(image.getGeneratedId()); + assertEquals(imageId, image.getImageId()); + assertNull(image.getCreationTimestamp()); + assertNull(image.getDescription()); + assertEquals(DISK_CONFIGURATION, image.getConfiguration()); + assertNull(image.getStatus()); + assertNull(image.getDiskSizeGb()); + assertNull(image.getLicenses()); + assertNull(image.getDeprecationStatus()); + assertSame(serviceMockReturnsOptions, image.getCompute()); + } + + @Test + public void testBuilderDeprecated() { initializeExpectedImage(3); assertEquals(GENERATED_ID, diskImage.generatedId()); assertEquals(IMAGE_ID, diskImage.imageId()); @@ -185,7 +226,7 @@ public void testDeleteOperation() { initializeExpectedImage(3); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(GlobalOperationId.of("project", "op")) + .setOperationId(GlobalOperationId.of("project", "op")) .build(); expect(compute.deleteImage(IMAGE_ID)).andReturn(operation); replay(compute); @@ -267,9 +308,10 @@ public void testDeprecateImage() { initializeExpectedImage(3); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(GlobalOperationId.of("project", "op")) + .setOperationId(GlobalOperationId.of("project", "op")) .build(); - DeprecationStatus status = DeprecationStatus.of(DeprecationStatus.Status.DEPRECATED, IMAGE_ID); + DeprecationStatus status = + DeprecationStatus.of(DeprecationStatus.Status.DEPRECATED, IMAGE_ID); expect(compute.deprecate(IMAGE_ID, status)).andReturn(operation); replay(compute); initializeImage(); @@ -280,7 +322,8 @@ public void testDeprecateImage() { public void testDeprecateNull() { initializeExpectedImage(2); expect(compute.options()).andReturn(mockOptions); - DeprecationStatus status = DeprecationStatus.of(DeprecationStatus.Status.DEPRECATED, IMAGE_ID); + DeprecationStatus status = + DeprecationStatus.of(DeprecationStatus.Status.DEPRECATED, IMAGE_ID); expect(compute.deprecate(IMAGE_ID, status)).andReturn(null); replay(compute); initializeImage(); @@ -289,16 +332,16 @@ public void testDeprecateNull() { public void compareImage(Image expected, Image value) { assertEquals(expected, value); - assertEquals(expected.compute().options(), value.compute().options()); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.imageId(), value.imageId()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.configuration(), value.configuration()); - assertEquals(expected.status(), value.status()); - assertEquals(expected.diskSizeGb(), value.diskSizeGb()); - assertEquals(expected.licenses(), value.licenses()); - assertEquals(expected.deprecationStatus(), value.deprecationStatus()); + assertEquals(expected.getCompute().options(), value.getCompute().options()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getImageId(), value.getImageId()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getConfiguration(), value.getConfiguration()); + assertEquals(expected.getStatus(), value.getStatus()); + assertEquals(expected.getDiskSizeGb(), value.getDiskSizeGb()); + assertEquals(expected.getLicenses(), value.getLicenses()); + assertEquals(expected.getDeprecationStatus(), value.getDeprecationStatus()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/InstanceIdTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/InstanceIdTest.java index 5c02e6d7c7ee..38a2b788d045 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/InstanceIdTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/InstanceIdTest.java @@ -39,6 +39,24 @@ public class InstanceIdTest { @Test public void testOf() { + InstanceId instanceId = InstanceId.of(PROJECT, ZONE, NAME); + assertEquals(PROJECT, instanceId.getProject()); + assertEquals(ZONE, instanceId.getZone()); + assertEquals(NAME, instanceId.getInstance()); + assertEquals(URL, instanceId.getSelfLink()); + instanceId = InstanceId.of(ZoneId.of(PROJECT, ZONE), NAME); + assertEquals(PROJECT, instanceId.getProject()); + assertEquals(ZONE, instanceId.getZone()); + assertEquals(NAME, instanceId.getInstance()); + assertEquals(URL, instanceId.getSelfLink()); + instanceId = InstanceId.of(ZONE, NAME); + assertNull(instanceId.getProject()); + assertEquals(ZONE, instanceId.getZone()); + assertEquals(NAME, instanceId.getInstance()); + } + + @Test + public void testOfDeprecated() { InstanceId instanceId = InstanceId.of(PROJECT, ZONE, NAME); assertEquals(PROJECT, instanceId.project()); assertEquals(ZONE, instanceId.zone()); @@ -58,7 +76,7 @@ public void testOf() { @Test public void testToAndFromUrl() { InstanceId instanceId = InstanceId.of(PROJECT, ZONE, NAME); - compareInstanceId(instanceId, InstanceId.fromUrl(instanceId.selfLink())); + compareInstanceId(instanceId, InstanceId.fromUrl(instanceId.getSelfLink())); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("notMatchingUrl is not a valid instance URL"); InstanceId.fromUrl("notMatchingUrl"); @@ -73,16 +91,16 @@ public void testSetProjectId() { @Test public void testMatchesUrl() { - assertTrue(InstanceId.matchesUrl(InstanceId.of(PROJECT, ZONE, NAME).selfLink())); + assertTrue(InstanceId.matchesUrl(InstanceId.of(PROJECT, ZONE, NAME).getSelfLink())); assertFalse(InstanceId.matchesUrl("notMatchingUrl")); } private void compareInstanceId(InstanceId expected, InstanceId value) { assertEquals(expected, value); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.zone(), expected.zone()); - assertEquals(expected.instance(), expected.instance()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getZone(), expected.getZone()); + assertEquals(expected.getInstance(), expected.getInstance()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/InstanceInfoTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/InstanceInfoTest.java index 13e7a87af06e..dab2308b36d4 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/InstanceInfoTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/InstanceInfoTest.java @@ -44,7 +44,7 @@ public class InstanceInfoTest { private static final AttachedDisk ATTACHED_DISK = AttachedDisk.of(AttachedDisk.PersistentDiskConfiguration.of(DISK_ID)); private static final List ATTACHED_DISKS = ImmutableList.of(ATTACHED_DISK); - private static final Metadata METADATA = Metadata.builder() + private static final Metadata METADATA = Metadata.newBuilder() .add("key1", "value1") .add("key2", "value2") .build(); @@ -53,28 +53,45 @@ public class InstanceInfoTest { private static final List SERVICE_ACCOUNTS = ImmutableList.of(SERVICE_ACCOUNT); private static final SchedulingOptions SCHEDULING_OPTIONS = SchedulingOptions.preemptible(); private static final String CPU_PLATFORM = "cpuPlatform"; - private static final InstanceInfo INSTANCE_INFO = InstanceInfo.builder(INSTANCE_ID, MACHINE_TYPE) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .status(STATUS) - .statusMessage(STATUS_MESSAGE) - .tags(TAGS) - .canIpForward(CAN_IP_FORWARD) - .networkInterfaces(NETWORK_INTERFACES) - .attachedDisks(ATTACHED_DISKS) - .metadata(METADATA) - .serviceAccounts(SERVICE_ACCOUNTS) - .schedulingOptions(SCHEDULING_OPTIONS) - .cpuPlatform(CPU_PLATFORM) - .build(); + private static final InstanceInfo INSTANCE_INFO = + InstanceInfo.newBuilder(INSTANCE_ID, MACHINE_TYPE) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(STATUS) + .setStatusMessage(STATUS_MESSAGE) + .setTags(TAGS) + .setCanIpForward(CAN_IP_FORWARD) + .setNetworkInterfaces(NETWORK_INTERFACES) + .setAttachedDisks(ATTACHED_DISKS) + .setMetadata(METADATA) + .setServiceAccounts(SERVICE_ACCOUNTS) + .setSchedulingOptions(SCHEDULING_OPTIONS) + .setCpuPlatform(CPU_PLATFORM) + .build(); + private static final InstanceInfo DEPRECATED_INSTANCE_INFO = + InstanceInfo.newBuilder(INSTANCE_ID, MACHINE_TYPE) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .description(DESCRIPTION) + .setStatus(STATUS) + .setStatusMessage(STATUS_MESSAGE) + .tags(TAGS) + .canIpForward(CAN_IP_FORWARD) + .networkInterfaces(NETWORK_INTERFACES) + .attachedDisks(ATTACHED_DISKS) + .metadata(METADATA) + .serviceAccounts(SERVICE_ACCOUNTS) + .schedulingOptions(SCHEDULING_OPTIONS) + .setCpuPlatform(CPU_PLATFORM) + .build(); @Test public void testToBuilder() { compareInstanceInfo(INSTANCE_INFO, INSTANCE_INFO.toBuilder().build()); - InstanceInfo instance = INSTANCE_INFO.toBuilder().description("newDescription").build(); - assertEquals("newDescription", instance.description()); - instance = instance.toBuilder().description(DESCRIPTION).build(); + InstanceInfo instance = INSTANCE_INFO.toBuilder().setDescription("newDescription").build(); + assertEquals("newDescription", instance.getDescription()); + instance = instance.toBuilder().setDescription(DESCRIPTION).build(); compareInstanceInfo(INSTANCE_INFO, instance); } @@ -87,27 +104,62 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { - assertEquals(GENERATED_ID, INSTANCE_INFO.generatedId()); - assertEquals(INSTANCE_ID, INSTANCE_INFO.instanceId()); - assertEquals(CREATION_TIMESTAMP, INSTANCE_INFO.creationTimestamp()); - assertEquals(DESCRIPTION, INSTANCE_INFO.description()); - assertEquals(STATUS, INSTANCE_INFO.status()); - assertEquals(STATUS_MESSAGE, INSTANCE_INFO.statusMessage()); - assertEquals(TAGS, INSTANCE_INFO.tags()); - assertEquals(MACHINE_TYPE, INSTANCE_INFO.machineType()); + assertEquals(GENERATED_ID, INSTANCE_INFO.getGeneratedId()); + assertEquals(INSTANCE_ID, INSTANCE_INFO.getInstanceId()); + assertEquals(CREATION_TIMESTAMP, INSTANCE_INFO.getCreationTimestamp()); + assertEquals(DESCRIPTION, INSTANCE_INFO.getDescription()); + assertEquals(STATUS, INSTANCE_INFO.getStatus()); + assertEquals(STATUS_MESSAGE, INSTANCE_INFO.getStatusMessage()); + assertEquals(TAGS, INSTANCE_INFO.getTags()); + assertEquals(MACHINE_TYPE, INSTANCE_INFO.getMachineType()); assertEquals(CAN_IP_FORWARD, INSTANCE_INFO.canIpForward()); - assertEquals(NETWORK_INTERFACES, INSTANCE_INFO.networkInterfaces()); - assertEquals(ATTACHED_DISKS, INSTANCE_INFO.attachedDisks()); - assertEquals(METADATA, INSTANCE_INFO.metadata()); - assertEquals(SERVICE_ACCOUNTS, INSTANCE_INFO.serviceAccounts()); - assertEquals(SCHEDULING_OPTIONS, INSTANCE_INFO.schedulingOptions()); - assertEquals(CPU_PLATFORM, INSTANCE_INFO.cpuPlatform()); + assertEquals(NETWORK_INTERFACES, INSTANCE_INFO.getNetworkInterfaces()); + assertEquals(ATTACHED_DISKS, INSTANCE_INFO.getAttachedDisks()); + assertEquals(METADATA, INSTANCE_INFO.getMetadata()); + assertEquals(SERVICE_ACCOUNTS, INSTANCE_INFO.getServiceAccounts()); + assertEquals(SCHEDULING_OPTIONS, INSTANCE_INFO.getSchedulingOptions()); + assertEquals(CPU_PLATFORM, INSTANCE_INFO.getCpuPlatform()); + InstanceInfo instanceInfo = InstanceInfo.newBuilder(INSTANCE_ID, MACHINE_TYPE) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(STATUS) + .setStatusMessage(STATUS_MESSAGE) + .setTags(TAGS) + .setCanIpForward(CAN_IP_FORWARD) + .setNetworkInterfaces(NETWORK_INTERFACE) + .setAttachedDisks(ATTACHED_DISK) + .setMetadata(METADATA) + .setServiceAccounts(SERVICE_ACCOUNTS) + .setSchedulingOptions(SCHEDULING_OPTIONS) + .setCpuPlatform(CPU_PLATFORM) + .build(); + compareInstanceInfo(INSTANCE_INFO, instanceInfo); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(GENERATED_ID, DEPRECATED_INSTANCE_INFO.generatedId()); + assertEquals(INSTANCE_ID, DEPRECATED_INSTANCE_INFO.instanceId()); + assertEquals(CREATION_TIMESTAMP, DEPRECATED_INSTANCE_INFO.creationTimestamp()); + assertEquals(DESCRIPTION, DEPRECATED_INSTANCE_INFO.description()); + assertEquals(STATUS, DEPRECATED_INSTANCE_INFO.status()); + assertEquals(STATUS_MESSAGE, DEPRECATED_INSTANCE_INFO.statusMessage()); + assertEquals(TAGS, DEPRECATED_INSTANCE_INFO.tags()); + assertEquals(MACHINE_TYPE, DEPRECATED_INSTANCE_INFO.machineType()); + assertEquals(CAN_IP_FORWARD, DEPRECATED_INSTANCE_INFO.canIpForward()); + assertEquals(NETWORK_INTERFACES, DEPRECATED_INSTANCE_INFO.networkInterfaces()); + assertEquals(ATTACHED_DISKS, DEPRECATED_INSTANCE_INFO.attachedDisks()); + assertEquals(METADATA, DEPRECATED_INSTANCE_INFO.metadata()); + assertEquals(SERVICE_ACCOUNTS, DEPRECATED_INSTANCE_INFO.serviceAccounts()); + assertEquals(SCHEDULING_OPTIONS, DEPRECATED_INSTANCE_INFO.schedulingOptions()); + assertEquals(CPU_PLATFORM, DEPRECATED_INSTANCE_INFO.cpuPlatform()); InstanceInfo instanceInfo = InstanceInfo.builder(INSTANCE_ID, MACHINE_TYPE) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) .description(DESCRIPTION) - .status(STATUS) - .statusMessage(STATUS_MESSAGE) + .setStatus(STATUS) + .setStatusMessage(STATUS_MESSAGE) .tags(TAGS) .canIpForward(CAN_IP_FORWARD) .networkInterfaces(NETWORK_INTERFACE) @@ -115,7 +167,7 @@ public void testBuilder() { .metadata(METADATA) .serviceAccounts(SERVICE_ACCOUNTS) .schedulingOptions(SCHEDULING_OPTIONS) - .cpuPlatform(CPU_PLATFORM) + .setCpuPlatform(CPU_PLATFORM) .build(); compareInstanceInfo(INSTANCE_INFO, instanceInfo); } @@ -124,21 +176,21 @@ public void testBuilder() { public void testOf() { InstanceInfo instance = InstanceInfo.of(INSTANCE_ID, MACHINE_TYPE, ATTACHED_DISK, NETWORK_INTERFACE); - assertNull(instance.generatedId()); - assertEquals(INSTANCE_ID, instance.instanceId()); - assertNull(instance.creationTimestamp()); - assertNull(instance.description()); - assertNull(instance.status()); - assertNull(instance.statusMessage()); - assertNull(instance.tags()); - assertEquals(MACHINE_TYPE, instance.machineType()); + assertNull(instance.getGeneratedId()); + assertEquals(INSTANCE_ID, instance.getInstanceId()); + assertNull(instance.getCreationTimestamp()); + assertNull(instance.getDescription()); + assertNull(instance.getStatus()); + assertNull(instance.getStatusMessage()); + assertNull(instance.getTags()); + assertEquals(MACHINE_TYPE, instance.getMachineType()); assertNull(instance.canIpForward()); - assertEquals(NETWORK_INTERFACES, instance.networkInterfaces()); - assertEquals(ATTACHED_DISKS, instance.attachedDisks()); - assertNull(instance.metadata()); - assertNull(instance.serviceAccounts()); - assertNull(instance.schedulingOptions()); - assertNull(instance.cpuPlatform()); + assertEquals(NETWORK_INTERFACES, instance.getNetworkInterfaces()); + assertEquals(ATTACHED_DISKS, instance.getAttachedDisks()); + assertNull(instance.getMetadata()); + assertNull(instance.getServiceAccounts()); + assertNull(instance.getSchedulingOptions()); + assertNull(instance.getCpuPlatform()); } @Test @@ -163,21 +215,21 @@ public void testSetProjectId() { public void compareInstanceInfo(InstanceInfo expected, InstanceInfo value) { assertEquals(expected, value); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.instanceId(), value.instanceId()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.status(), value.status()); - assertEquals(expected.statusMessage(), value.statusMessage()); - assertEquals(expected.tags(), value.tags()); - assertEquals(expected.machineType(), value.machineType()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getInstanceId(), value.getInstanceId()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getStatus(), value.getStatus()); + assertEquals(expected.getStatusMessage(), value.getStatusMessage()); + assertEquals(expected.getTags(), value.getTags()); + assertEquals(expected.getMachineType(), value.getMachineType()); assertEquals(expected.canIpForward(), value.canIpForward()); - assertEquals(expected.networkInterfaces(), value.networkInterfaces()); - assertEquals(expected.attachedDisks(), value.attachedDisks()); - assertEquals(expected.metadata(), value.metadata()); - assertEquals(expected.serviceAccounts(), value.serviceAccounts()); - assertEquals(expected.schedulingOptions(), value.schedulingOptions()); - assertEquals(expected.cpuPlatform(), value.cpuPlatform()); + assertEquals(expected.getNetworkInterfaces(), value.getNetworkInterfaces()); + assertEquals(expected.getAttachedDisks(), value.getAttachedDisks()); + assertEquals(expected.getMetadata(), value.getMetadata()); + assertEquals(expected.getServiceAccounts(), value.getServiceAccounts()); + assertEquals(expected.getSchedulingOptions(), value.getSchedulingOptions()); + assertEquals(expected.getCpuPlatform(), value.getCpuPlatform()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/InstanceTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/InstanceTest.java index 522e1a7daf28..eacc72f12ab6 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/InstanceTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/InstanceTest.java @@ -43,9 +43,9 @@ public class InstanceTest { private static final InstanceId INSTANCE_ID = InstanceId.of("project", "zone", "instance"); private static final InstanceInfo.Status STATUS = InstanceInfo.Status.RUNNING; private static final String STATUS_MESSAGE = "statusMessage"; - private static final Tags TAGS = Tags.builder() - .values("tag1", "tag2") - .fingerprint("fingerprint") + private static final Tags TAGS = Tags.newBuilder() + .setValues("tag1", "tag2") + .setFingerprint("fingerprint") .build(); private static final MachineTypeId MACHINE_TYPE = MachineTypeId.of("project", "zone", "type"); private static final Boolean CAN_IP_FORWARD = true; @@ -57,10 +57,10 @@ public class InstanceTest { private static final AttachedDisk ATTACHED_DISK = AttachedDisk.of(AttachedDisk.PersistentDiskConfiguration.of(DISK_ID)); private static final List ATTACHED_DISKS = ImmutableList.of(ATTACHED_DISK); - private static final Metadata METADATA = Metadata.builder() + private static final Metadata METADATA = Metadata.newBuilder() .add("key1", "value1") .add("key2", "value2") - .fingerprint("fingerprint") + .setFingerprint("fingerprint") .build(); private static final ServiceAccount SERVICE_ACCOUNT = ServiceAccount.of("email", ImmutableList.of("scope1")); @@ -80,17 +80,17 @@ private void initializeExpectedInstance(int optionsCalls) { replay(serviceMockReturnsOptions); expectedInstance = new Instance.Builder(serviceMockReturnsOptions, INSTANCE_ID, MACHINE_TYPE, ATTACHED_DISK, NETWORK_INTERFACE) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .status(STATUS) - .statusMessage(STATUS_MESSAGE) - .tags(TAGS) - .canIpForward(CAN_IP_FORWARD) - .metadata(METADATA) - .serviceAccounts(SERVICE_ACCOUNTS) - .schedulingOptions(SCHEDULING_OPTIONS) - .cpuPlatform(CPU_PLATFORM) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(STATUS) + .setStatusMessage(STATUS_MESSAGE) + .setTags(TAGS) + .setCanIpForward(CAN_IP_FORWARD) + .setMetadata(METADATA) + .setServiceAccounts(SERVICE_ACCOUNTS) + .setSchedulingOptions(SCHEDULING_OPTIONS) + .setCpuPlatform(CPU_PLATFORM) .build(); compute = createStrictMock(Compute.class); } @@ -98,17 +98,17 @@ private void initializeExpectedInstance(int optionsCalls) { private void initializeInstance() { instance = new Instance.Builder(compute, INSTANCE_ID, MACHINE_TYPE, ATTACHED_DISK, NETWORK_INTERFACE) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .status(STATUS) - .statusMessage(STATUS_MESSAGE) - .tags(TAGS) - .canIpForward(CAN_IP_FORWARD) - .metadata(METADATA) - .serviceAccounts(SERVICE_ACCOUNTS) - .schedulingOptions(SCHEDULING_OPTIONS) - .cpuPlatform(CPU_PLATFORM) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(STATUS) + .setStatusMessage(STATUS_MESSAGE) + .setTags(TAGS) + .setCanIpForward(CAN_IP_FORWARD) + .setMetadata(METADATA) + .setServiceAccounts(SERVICE_ACCOUNTS) + .setSchedulingOptions(SCHEDULING_OPTIONS) + .setCpuPlatform(CPU_PLATFORM) .build(); } @@ -116,9 +116,9 @@ private void initializeInstance() { public void testToBuilder() { initializeExpectedInstance(8); compareInstance(expectedInstance, expectedInstance.toBuilder().build()); - Instance newInstance = expectedInstance.toBuilder().description("newDescription").build(); - assertEquals("newDescription", newInstance.description()); - newInstance = newInstance.toBuilder().description("description").build(); + Instance newInstance = expectedInstance.toBuilder().setDescription("newDescription").build(); + assertEquals("newDescription", newInstance.getDescription()); + newInstance = newInstance.toBuilder().setDescription("description").build(); compareInstance(expectedInstance, newInstance); } @@ -134,6 +134,47 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { + initializeExpectedInstance(2); + assertEquals(GENERATED_ID, expectedInstance.getGeneratedId()); + assertEquals(INSTANCE_ID, expectedInstance.getInstanceId()); + assertEquals(CREATION_TIMESTAMP, expectedInstance.getCreationTimestamp()); + assertEquals(DESCRIPTION, expectedInstance.getDescription()); + assertEquals(STATUS, expectedInstance.getStatus()); + assertEquals(STATUS_MESSAGE, expectedInstance.getStatusMessage()); + assertEquals(TAGS, expectedInstance.getTags()); + assertEquals(MACHINE_TYPE, expectedInstance.getMachineType()); + assertEquals(CAN_IP_FORWARD, expectedInstance.canIpForward()); + assertEquals(NETWORK_INTERFACES, expectedInstance.getNetworkInterfaces()); + assertEquals(ATTACHED_DISKS, expectedInstance.getAttachedDisks()); + assertEquals(METADATA, expectedInstance.getMetadata()); + assertEquals(SERVICE_ACCOUNTS, expectedInstance.getServiceAccounts()); + assertEquals(SCHEDULING_OPTIONS, expectedInstance.getSchedulingOptions()); + assertEquals(CPU_PLATFORM, expectedInstance.getCpuPlatform()); + assertSame(serviceMockReturnsOptions, expectedInstance.getCompute()); + InstanceInfo instanceInfo = + InstanceInfo.of(INSTANCE_ID, MACHINE_TYPE, ATTACHED_DISK, NETWORK_INTERFACE); + Instance instance = + new Instance(serviceMockReturnsOptions, new InstanceInfo.BuilderImpl(instanceInfo)); + assertNull(instance.getGeneratedId()); + assertEquals(INSTANCE_ID, instance.getInstanceId()); + assertNull(instance.getCreationTimestamp()); + assertNull(instance.getDescription()); + assertNull(instance.getStatus()); + assertNull(instance.getStatusMessage()); + assertNull(instance.getTags()); + assertEquals(MACHINE_TYPE, instance.getMachineType()); + assertNull(instance.canIpForward()); + assertEquals(NETWORK_INTERFACES, instance.getNetworkInterfaces()); + assertEquals(ATTACHED_DISKS, instance.getAttachedDisks()); + assertNull(instance.getMetadata()); + assertNull(instance.getServiceAccounts()); + assertNull(instance.getSchedulingOptions()); + assertNull(instance.getCpuPlatform()); + assertSame(serviceMockReturnsOptions, instance.getCompute()); + } + + @Test + public void testBuilderDeprecated() { initializeExpectedInstance(2); assertEquals(GENERATED_ID, expectedInstance.generatedId()); assertEquals(INSTANCE_ID, expectedInstance.instanceId()); @@ -188,7 +229,7 @@ public void testDeleteOperation() { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); expect(compute.deleteInstance(INSTANCE_ID)).andReturn(operation); replay(compute); @@ -257,7 +298,8 @@ public void testReloadNull() throws Exception { public void testReloadWithOptions() throws Exception { initializeExpectedInstance(3); expect(compute.options()).andReturn(mockOptions); - expect(compute.getInstance(INSTANCE_ID, Compute.InstanceOption.fields())).andReturn(expectedInstance); + expect(compute.getInstance(INSTANCE_ID, + Compute.InstanceOption.fields())).andReturn(expectedInstance); replay(compute); initializeInstance(); Instance updateInstance = instance.reload(Compute.InstanceOption.fields()); @@ -271,7 +313,7 @@ public void testAddAccessConfig() throws Exception { expect(compute.options()).andReturn(mockOptions); NetworkInterface.AccessConfig accessConfig = NetworkInterface.AccessConfig.of("192.168.1.1"); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); expect(compute.addAccessConfig(INSTANCE_ID, "nic0", accessConfig)).andReturn(operation); replay(compute); @@ -296,22 +338,25 @@ public void testAddAccessConfigWithOptions() throws Exception { expect(compute.options()).andReturn(mockOptions); NetworkInterface.AccessConfig accessConfig = NetworkInterface.AccessConfig.of("192.168.1.1"); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); - expect(compute.addAccessConfig(INSTANCE_ID, "nic0", accessConfig, Compute.OperationOption.fields())) + expect(compute.addAccessConfig( + INSTANCE_ID, "nic0", accessConfig, Compute.OperationOption.fields())) .andReturn(operation); replay(compute); initializeInstance(); - assertSame(operation, instance.addAccessConfig("nic0", accessConfig, Compute.OperationOption.fields())); + assertSame(operation, + instance.addAccessConfig("nic0", accessConfig, Compute.OperationOption.fields())); } @Test public void testAttachDisk() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); - AttachedDisk.PersistentDiskConfiguration configuration = AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); + AttachedDisk.PersistentDiskConfiguration configuration = + AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); expect(compute.attachDisk(INSTANCE_ID, configuration)).andReturn(operation); replay(compute); @@ -323,7 +368,8 @@ public void testAttachDisk() throws Exception { public void testAttachDisk_Null() throws Exception { initializeExpectedInstance(1); expect(compute.options()).andReturn(mockOptions); - AttachedDisk.PersistentDiskConfiguration configuration = AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); + AttachedDisk.PersistentDiskConfiguration configuration = + AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); expect(compute.attachDisk(INSTANCE_ID, configuration)).andReturn(null); replay(compute); initializeInstance(); @@ -334,9 +380,10 @@ public void testAttachDisk_Null() throws Exception { public void testAttachDiskWithOptions() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); - AttachedDisk.PersistentDiskConfiguration configuration = AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); + AttachedDisk.PersistentDiskConfiguration configuration = + AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); expect(compute.attachDisk(INSTANCE_ID, configuration, Compute.OperationOption.fields())) .andReturn(operation); @@ -349,9 +396,10 @@ public void testAttachDiskWithOptions() throws Exception { public void testAttachDiskName() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); - AttachedDisk.PersistentDiskConfiguration configuration = AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); + AttachedDisk.PersistentDiskConfiguration configuration = + AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); expect(compute.attachDisk(INSTANCE_ID, "dev0", configuration)).andReturn(operation); replay(compute); @@ -363,7 +411,8 @@ public void testAttachDiskName() throws Exception { public void testAttachDiskName_Null() throws Exception { initializeExpectedInstance(1); expect(compute.options()).andReturn(mockOptions); - AttachedDisk.PersistentDiskConfiguration configuration = AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); + AttachedDisk.PersistentDiskConfiguration configuration = + AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); expect(compute.attachDisk(INSTANCE_ID, "dev0", configuration)).andReturn(null); replay(compute); initializeInstance(); @@ -374,24 +423,27 @@ public void testAttachDiskName_Null() throws Exception { public void testAttachDiskNameWithOptions() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); - AttachedDisk.PersistentDiskConfiguration configuration = AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); + AttachedDisk.PersistentDiskConfiguration configuration = + AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); expect(compute.attachDisk(INSTANCE_ID, "dev0", configuration, Compute.OperationOption.fields())) .andReturn(operation); replay(compute); initializeInstance(); - assertSame(operation, instance.attachDisk("dev0", configuration, Compute.OperationOption.fields())); + assertSame(operation, + instance.attachDisk("dev0", configuration, Compute.OperationOption.fields())); } @Test public void testAttachDiskNameIndex() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); - AttachedDisk.PersistentDiskConfiguration configuration = AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); + AttachedDisk.PersistentDiskConfiguration configuration = + AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); expect(compute.attachDisk(INSTANCE_ID, "dev0", configuration, 1)).andReturn(operation); replay(compute); @@ -403,7 +455,8 @@ public void testAttachDiskNameIndex() throws Exception { public void testAttachDiskNameIndex_Null() throws Exception { initializeExpectedInstance(1); expect(compute.options()).andReturn(mockOptions); - AttachedDisk.PersistentDiskConfiguration configuration = AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); + AttachedDisk.PersistentDiskConfiguration configuration = + AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); expect(compute.attachDisk(INSTANCE_ID, "dev0", configuration, 1)).andReturn(null); replay(compute); initializeInstance(); @@ -414,11 +467,13 @@ public void testAttachDiskNameIndex_Null() throws Exception { public void testAttachDiskNameIndexWithOptions() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); - AttachedDisk.PersistentDiskConfiguration configuration = AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); + AttachedDisk.PersistentDiskConfiguration configuration = + AttachedDisk.PersistentDiskConfiguration.of(DISK_ID); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); - expect(compute.attachDisk(INSTANCE_ID, "dev0", configuration, 1, Compute.OperationOption.fields())) + expect(compute.attachDisk( + INSTANCE_ID, "dev0", configuration, 1, Compute.OperationOption.fields())) .andReturn(operation); replay(compute); initializeInstance(); @@ -431,7 +486,7 @@ public void testDeleteAccessConfig() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); expect(compute.deleteAccessConfig(INSTANCE_ID, "nic0", "NAT")).andReturn(operation); replay(compute); @@ -454,13 +509,15 @@ public void testDeleteAccessConfigWithOptions() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); - expect(compute.deleteAccessConfig(INSTANCE_ID, "nic0", "NAT", Compute.OperationOption.fields())) + expect(compute.deleteAccessConfig( + INSTANCE_ID, "nic0", "NAT", Compute.OperationOption.fields())) .andReturn(operation); replay(compute); initializeInstance(); - assertSame(operation, instance.deleteAccessConfig("nic0", "NAT", Compute.OperationOption.fields())); + assertSame(operation, + instance.deleteAccessConfig("nic0", "NAT", Compute.OperationOption.fields())); } @Test @@ -468,7 +525,7 @@ public void testDetachDisk() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); expect(compute.detachDisk(INSTANCE_ID, "dev0")).andReturn(operation); replay(compute); @@ -491,9 +548,10 @@ public void testDetachDiskWithOptions() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); - expect(compute.detachDisk(INSTANCE_ID, "dev0", Compute.OperationOption.fields())).andReturn(operation); + expect(compute.detachDisk(INSTANCE_ID, "dev0", Compute.OperationOption.fields())) + .andReturn(operation); replay(compute); initializeInstance(); assertSame(operation, instance.detachDisk("dev0", Compute.OperationOption.fields())); @@ -524,7 +582,7 @@ public void testResetOperation() { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); expect(compute.reset(INSTANCE_ID)).andReturn(operation); replay(compute); @@ -547,7 +605,7 @@ public void testSetDiskAutodelete() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); expect(compute.setDiskAutoDelete(INSTANCE_ID, "dev0", true)).andReturn(operation); replay(compute); @@ -570,13 +628,14 @@ public void testSetDiskAutodeleteWithOptions() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); expect(compute.setDiskAutoDelete(INSTANCE_ID, "dev0", true, Compute.OperationOption.fields())) .andReturn(operation); replay(compute); initializeInstance(); - assertSame(operation, instance.setDiskAutoDelete("dev0", true, Compute.OperationOption.fields())); + assertSame(operation, + instance.setDiskAutoDelete("dev0", true, Compute.OperationOption.fields())); } @Test @@ -584,7 +643,7 @@ public void testSetMachineType() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); expect(compute.setMachineType(INSTANCE_ID, MACHINE_TYPE)).andReturn(operation); replay(compute); @@ -607,7 +666,7 @@ public void testSetMachineTypeWithOptions() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); expect(compute.setMachineType(INSTANCE_ID, MACHINE_TYPE, Compute.OperationOption.fields())) .andReturn(operation); @@ -621,9 +680,9 @@ public void testSetMetadata() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); - Metadata metadata = Metadata.builder().add("k", "v").fingerprint("fingerprint").build(); + Metadata metadata = Metadata.newBuilder().add("k", "v").setFingerprint("fingerprint").build(); expect(compute.setMetadata(INSTANCE_ID, metadata)).andReturn(operation); replay(compute); initializeInstance(); @@ -634,7 +693,7 @@ public void testSetMetadata() throws Exception { public void testSetMetadata_Null() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); - Metadata metadata = Metadata.builder().add("k", "v").fingerprint("fingerprint").build(); + Metadata metadata = Metadata.newBuilder().add("k", "v").setFingerprint("fingerprint").build(); expect(compute.setMetadata(INSTANCE_ID, metadata)).andReturn(null); replay(compute); initializeInstance(); @@ -646,9 +705,9 @@ public void testSetMetadataWithOptions() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); - Metadata metadata = Metadata.builder().add("k", "v").fingerprint("fingerprint").build(); + Metadata metadata = Metadata.newBuilder().add("k", "v").setFingerprint("fingerprint").build(); expect(compute.setMetadata(INSTANCE_ID, metadata, Compute.OperationOption.fields())) .andReturn(operation); replay(compute); @@ -661,10 +720,11 @@ public void testSetMetadataFromMap() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); Map metadataMap = ImmutableMap.of("k", "v"); - Metadata metadata = Metadata.builder().values(metadataMap).fingerprint("fingerprint").build(); + Metadata metadata = + Metadata.newBuilder().setValues(metadataMap).setFingerprint("fingerprint").build(); expect(compute.setMetadata(INSTANCE_ID, metadata)).andReturn(operation); replay(compute); initializeInstance(); @@ -676,7 +736,8 @@ public void testSetMetadataFromMap_Null() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Map metadataMap = ImmutableMap.of("k", "v"); - Metadata metadata = Metadata.builder().values(metadataMap).fingerprint("fingerprint").build(); + Metadata metadata = + Metadata.newBuilder().setValues(metadataMap).setFingerprint("fingerprint").build(); expect(compute.setMetadata(INSTANCE_ID, metadata)).andReturn(null); replay(compute); initializeInstance(); @@ -688,10 +749,11 @@ public void testSetMetadataFromMapWithOptions() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); Map metadataMap = ImmutableMap.of("k", "v"); - Metadata metadata = Metadata.builder().values(metadataMap).fingerprint("fingerprint").build(); + Metadata metadata = + Metadata.newBuilder().setValues(metadataMap).setFingerprint("fingerprint").build(); expect(compute.setMetadata(INSTANCE_ID, metadata, Compute.OperationOption.fields())) .andReturn(operation); replay(compute); @@ -704,9 +766,10 @@ public void testSetSchedulingOptions() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); - SchedulingOptions schedulingOptions = SchedulingOptions.standard(true, SchedulingOptions.Maintenance.MIGRATE); + SchedulingOptions schedulingOptions = + SchedulingOptions.standard(true, SchedulingOptions.Maintenance.MIGRATE); expect(compute.setSchedulingOptions(INSTANCE_ID, schedulingOptions)).andReturn(operation); replay(compute); initializeInstance(); @@ -717,7 +780,8 @@ public void testSetSchedulingOptions() throws Exception { public void testSetSchedulingOptions_Null() throws Exception { initializeExpectedInstance(1); expect(compute.options()).andReturn(mockOptions); - SchedulingOptions schedulingOptions = SchedulingOptions.standard(true, SchedulingOptions.Maintenance.MIGRATE); + SchedulingOptions schedulingOptions = + SchedulingOptions.standard(true, SchedulingOptions.Maintenance.MIGRATE); expect(compute.setSchedulingOptions(INSTANCE_ID, schedulingOptions)).andReturn(null); replay(compute); initializeInstance(); @@ -729,10 +793,12 @@ public void testSetSchedulingOptionsWithOptions() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); - SchedulingOptions schedulingOptions = SchedulingOptions.standard(true, SchedulingOptions.Maintenance.MIGRATE); - expect(compute.setSchedulingOptions(INSTANCE_ID, schedulingOptions, Compute.OperationOption.fields())) + SchedulingOptions schedulingOptions = + SchedulingOptions.standard(true, SchedulingOptions.Maintenance.MIGRATE); + expect(compute.setSchedulingOptions( + INSTANCE_ID, schedulingOptions, Compute.OperationOption.fields())) .andReturn(operation); replay(compute); initializeInstance(); @@ -745,9 +811,9 @@ public void testSetTags() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); - Tags tags = Tags.builder().values("v1", "v2").fingerprint("fingerprint").build(); + Tags tags = Tags.newBuilder().setValues("v1", "v2").setFingerprint("fingerprint").build(); expect(compute.setTags(INSTANCE_ID, tags)).andReturn(operation); replay(compute); initializeInstance(); @@ -758,7 +824,7 @@ public void testSetTags() throws Exception { public void testSetTags_Null() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); - Tags tags = Tags.builder().values("v1", "v2").fingerprint("fingerprint").build(); + Tags tags = Tags.newBuilder().setValues("v1", "v2").setFingerprint("fingerprint").build(); expect(compute.setTags(INSTANCE_ID, tags)).andReturn(null); replay(compute); initializeInstance(); @@ -770,10 +836,11 @@ public void testSetTagsWithOptions() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); - Tags tags = Tags.builder().values("v1", "v2").fingerprint("fingerprint").build(); - expect(compute.setTags(INSTANCE_ID, tags, Compute.OperationOption.fields())).andReturn(operation); + Tags tags = Tags.newBuilder().setValues("v1", "v2").setFingerprint("fingerprint").build(); + expect(compute.setTags(INSTANCE_ID, tags, Compute.OperationOption.fields())) + .andReturn(operation); replay(compute); initializeInstance(); assertSame(operation, instance.setTags(tags, Compute.OperationOption.fields())); @@ -784,10 +851,10 @@ public void testSetTagsFromList() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); List tagList = ImmutableList.of("v1", "v2"); - Tags tags = Tags.builder().values(tagList).fingerprint("fingerprint").build(); + Tags tags = Tags.newBuilder().setValues(tagList).setFingerprint("fingerprint").build(); expect(compute.setTags(INSTANCE_ID, tags)).andReturn(operation); replay(compute); initializeInstance(); @@ -799,7 +866,7 @@ public void testSetTagsFromList_Null() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); List tagList = ImmutableList.of("v1", "v2"); - Tags tags = Tags.builder().values(tagList).fingerprint("fingerprint").build(); + Tags tags = Tags.newBuilder().setValues(tagList).setFingerprint("fingerprint").build(); expect(compute.setTags(INSTANCE_ID, tags)).andReturn(null); replay(compute); initializeInstance(); @@ -811,11 +878,12 @@ public void testSetTagsFromListWithOptions() throws Exception { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); List tagList = ImmutableList.of("v1", "v2"); - Tags tags = Tags.builder().values(tagList).fingerprint("fingerprint").build(); - expect(compute.setTags(INSTANCE_ID, tags, Compute.OperationOption.fields())).andReturn(operation); + Tags tags = Tags.newBuilder().setValues(tagList).setFingerprint("fingerprint").build(); + expect(compute.setTags(INSTANCE_ID, tags, Compute.OperationOption.fields())) + .andReturn(operation); replay(compute); initializeInstance(); assertSame(operation, instance.setTags(tagList, Compute.OperationOption.fields())); @@ -826,7 +894,7 @@ public void testStartOperation() { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); expect(compute.start(INSTANCE_ID)).andReturn(operation); replay(compute); @@ -849,7 +917,7 @@ public void testStopOperation() { initializeExpectedInstance(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZoneOperationId.of("project", "op")) + .setOperationId(ZoneOperationId.of("project", "op")) .build(); expect(compute.stop(INSTANCE_ID)).andReturn(operation); replay(compute); @@ -869,22 +937,22 @@ public void testStopNull() { public void compareInstance(Instance expected, Instance value) { assertEquals(expected, value); - assertEquals(expected.compute().options(), value.compute().options()); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.instanceId(), value.instanceId()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.status(), value.status()); - assertEquals(expected.statusMessage(), value.statusMessage()); - assertEquals(expected.tags(), value.tags()); - assertEquals(expected.machineType(), value.machineType()); + assertEquals(expected.getCompute().options(), value.getCompute().options()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getInstanceId(), value.getInstanceId()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getStatus(), value.getStatus()); + assertEquals(expected.getStatusMessage(), value.getStatusMessage()); + assertEquals(expected.getTags(), value.getTags()); + assertEquals(expected.getMachineType(), value.getMachineType()); assertEquals(expected.canIpForward(), value.canIpForward()); - assertEquals(expected.networkInterfaces(), value.networkInterfaces()); - assertEquals(expected.attachedDisks(), value.attachedDisks()); - assertEquals(expected.metadata(), value.metadata()); - assertEquals(expected.serviceAccounts(), value.serviceAccounts()); - assertEquals(expected.schedulingOptions(), value.schedulingOptions()); - assertEquals(expected.cpuPlatform(), value.cpuPlatform()); + assertEquals(expected.getNetworkInterfaces(), value.getNetworkInterfaces()); + assertEquals(expected.getAttachedDisks(), value.getAttachedDisks()); + assertEquals(expected.getMetadata(), value.getMetadata()); + assertEquals(expected.getServiceAccounts(), value.getServiceAccounts()); + assertEquals(expected.getSchedulingOptions(), value.getSchedulingOptions()); + assertEquals(expected.getCpuPlatform(), value.getCpuPlatform()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/LicenseIdTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/LicenseIdTest.java index cdb5e7adf992..c16b054a7039 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/LicenseIdTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/LicenseIdTest.java @@ -38,6 +38,17 @@ public class LicenseIdTest { @Test public void testOf() { + LicenseId licenseId = LicenseId.of(PROJECT, LICENSE); + assertEquals(PROJECT, licenseId.getProject()); + assertEquals(LICENSE, licenseId.getLicense()); + assertEquals(URL, licenseId.getSelfLink()); + licenseId = LicenseId.of(LICENSE); + assertNull(licenseId.getProject()); + assertEquals(LICENSE, licenseId.getLicense()); + } + + @Test + public void testOfDeprecated() { LicenseId licenseId = LicenseId.of(PROJECT, LICENSE); assertEquals(PROJECT, licenseId.project()); assertEquals(LICENSE, licenseId.license()); @@ -50,7 +61,7 @@ public void testOf() { @Test public void testToAndFromUrl() { LicenseId licenseId = LicenseId.of(PROJECT, LICENSE); - compareLicenseId(licenseId, LicenseId.fromUrl(licenseId.selfLink())); + compareLicenseId(licenseId, LicenseId.fromUrl(licenseId.getSelfLink())); } @Test @@ -65,15 +76,15 @@ public void testSetProjectId() { @Test public void testMatchesUrl() { - assertTrue(LicenseId.matchesUrl(LicenseId.of(PROJECT, LICENSE).selfLink())); + assertTrue(LicenseId.matchesUrl(LicenseId.of(PROJECT, LICENSE).getSelfLink())); assertFalse(LicenseId.matchesUrl("notMatchingUrl")); } private void compareLicenseId(LicenseId expected, LicenseId value) { assertEquals(expected, value); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.license(), expected.license()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getLicense(), expected.getLicense()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/LicenseTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/LicenseTest.java index 6bbe50b71489..2ce8d2c06572 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/LicenseTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/LicenseTest.java @@ -28,6 +28,12 @@ public class LicenseTest { @Test public void testBuilder() { + assertEquals(LICENSE_ID, LICENSE.getLicenseId()); + assertEquals(CHARGES_USE_FEE, LICENSE.chargesUseFee()); + } + + @Test + public void testBuilderDeprecated() { assertEquals(LICENSE_ID, LICENSE.licenseId()); assertEquals(CHARGES_USE_FEE, LICENSE.chargesUseFee()); } @@ -36,13 +42,13 @@ public void testBuilder() { public void testToAndFromPb() { License license = License.fromPb(LICENSE.toPb()); compareLicenses(LICENSE, license); - assertEquals(LICENSE_ID.project(), license.licenseId().project()); - assertEquals(LICENSE_ID.license(), license.licenseId().license()); + assertEquals(LICENSE_ID.getProject(), license.getLicenseId().getProject()); + assertEquals(LICENSE_ID.getLicense(), license.getLicenseId().getLicense()); } private void compareLicenses(License expected, License value) { assertEquals(expected, value); - assertEquals(expected.licenseId(), value.licenseId()); + assertEquals(expected.getLicenseId(), value.getLicenseId()); assertEquals(expected.chargesUseFee(), value.chargesUseFee()); assertEquals(expected.hashCode(), value.hashCode()); } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/MachineTypeIdTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/MachineTypeIdTest.java index f7f776aec5a5..baecfad0ed15 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/MachineTypeIdTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/MachineTypeIdTest.java @@ -39,6 +39,19 @@ public class MachineTypeIdTest { @Test public void testOf() { + MachineTypeId machineTypeId = MachineTypeId.of(PROJECT, ZONE, TYPE); + assertEquals(PROJECT, machineTypeId.getProject()); + assertEquals(ZONE, machineTypeId.getZone()); + assertEquals(TYPE, machineTypeId.getType()); + assertEquals(URL, machineTypeId.getSelfLink()); + machineTypeId = MachineTypeId.of(ZONE, TYPE); + assertNull(machineTypeId.getProject()); + assertEquals(ZONE, machineTypeId.getZone()); + assertEquals(TYPE, machineTypeId.getType()); + } + + @Test + public void testOfDeprecated() { MachineTypeId machineTypeId = MachineTypeId.of(PROJECT, ZONE, TYPE); assertEquals(PROJECT, machineTypeId.project()); assertEquals(ZONE, machineTypeId.zone()); @@ -53,7 +66,7 @@ public void testOf() { @Test public void testToAndFromUrl() { MachineTypeId machineTypeId = MachineTypeId.of(PROJECT, ZONE, TYPE); - compareMachineTypeId(machineTypeId, MachineTypeId.fromUrl(machineTypeId.selfLink())); + compareMachineTypeId(machineTypeId, MachineTypeId.fromUrl(machineTypeId.getSelfLink())); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("notMatchingUrl is not a valid machine type URL"); MachineTypeId.fromUrl("notMatchingUrl"); @@ -68,16 +81,16 @@ public void testSetProjectId() { @Test public void testMatchesUrl() { - assertTrue(MachineTypeId.matchesUrl(MachineTypeId.of(PROJECT, ZONE, TYPE).selfLink())); + assertTrue(MachineTypeId.matchesUrl(MachineTypeId.of(PROJECT, ZONE, TYPE).getSelfLink())); assertFalse(MachineTypeId.matchesUrl("notMatchingUrl")); } private void compareMachineTypeId(MachineTypeId expected, MachineTypeId value) { assertEquals(expected, value); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.zone(), expected.zone()); - assertEquals(expected.type(), expected.type()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getZone(), expected.getZone()); + assertEquals(expected.getType(), expected.getType()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/MachineTypeTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/MachineTypeTest.java index 924d22bde36c..90ca3e5320c9 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/MachineTypeTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/MachineTypeTest.java @@ -37,21 +37,35 @@ public class MachineTypeTest { private static final Long MAXIMUM_PERSISTENT_DISKS_SIZE_GB = 5L; private static final DeprecationStatus DEPRECATION_STATUS = DeprecationStatus.of(DeprecationStatus.Status.DELETED, MACHINE_TYPE_ID); - private static final MachineType MACHINE_TYPE = MachineType.builder() - .generatedId(GENERATED_ID) - .machineTypeId(MACHINE_TYPE_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .cpus(CPUS) - .memoryMb(MEMORY_MB) - .scratchDisksSizeGb(SCRATCH_DISKS) - .maximumPersistentDisks(MAXIMUM_PERSISTENT_DISKS) - .maximumPersistentDisksSizeGb(MAXIMUM_PERSISTENT_DISKS_SIZE_GB) - .deprecationStatus(DEPRECATION_STATUS) + private static final MachineType MACHINE_TYPE = MachineType.newBuilder() + .setGeneratedId(GENERATED_ID) + .setMachineTypeId(MACHINE_TYPE_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setCpus(CPUS) + .setMemoryMb(MEMORY_MB) + .setScratchDisksSizeGb(SCRATCH_DISKS) + .setMaximumPersistentDisks(MAXIMUM_PERSISTENT_DISKS) + .setMaximumPersistentDisksSizeGb(MAXIMUM_PERSISTENT_DISKS_SIZE_GB) + .setDeprecationStatus(DEPRECATION_STATUS) .build(); @Test public void testBuilder() { + assertEquals(GENERATED_ID, MACHINE_TYPE.getGeneratedId()); + assertEquals(MACHINE_TYPE_ID, MACHINE_TYPE.getMachineTypeId()); + assertEquals(CREATION_TIMESTAMP, MACHINE_TYPE.getCreationTimestamp()); + assertEquals(DESCRIPTION, MACHINE_TYPE.getDescription()); + assertEquals(CPUS, MACHINE_TYPE.getCpus()); + assertEquals(MEMORY_MB, MACHINE_TYPE.getMemoryMb()); + assertEquals(SCRATCH_DISKS, MACHINE_TYPE.getScratchDisksSizeGb()); + assertEquals(MAXIMUM_PERSISTENT_DISKS, MACHINE_TYPE.getMaximumPersistentDisks()); + assertEquals(MAXIMUM_PERSISTENT_DISKS_SIZE_GB, MACHINE_TYPE.getMaximumPersistentDisksSizeGb()); + assertEquals(DEPRECATION_STATUS, MACHINE_TYPE.getDeprecationStatus()); + } + + @Test + public void testBuilderDeprecated() { assertEquals(GENERATED_ID, MACHINE_TYPE.generatedId()); assertEquals(MACHINE_TYPE_ID, MACHINE_TYPE.machineTypeId()); assertEquals(CREATION_TIMESTAMP, MACHINE_TYPE.creationTimestamp()); @@ -67,22 +81,23 @@ public void testBuilder() { @Test public void testToPbAndFromPb() { compareMachineTypes(MACHINE_TYPE, MachineType.fromPb(MACHINE_TYPE.toPb())); - MachineType machineType = MachineType.builder().machineTypeId(MACHINE_TYPE_ID).build(); + MachineType machineType = MachineType.newBuilder().setMachineTypeId(MACHINE_TYPE_ID).build(); compareMachineTypes(machineType, MachineType.fromPb(machineType.toPb())); } private void compareMachineTypes(MachineType expected, MachineType value) { assertEquals(expected, value); - assertEquals(expected.machineTypeId(), value.machineTypeId()); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.cpus(), value.cpus()); - assertEquals(expected.memoryMb(), value.memoryMb()); - assertEquals(expected.scratchDisksSizeGb(), value.scratchDisksSizeGb()); - assertEquals(expected.maximumPersistentDisks(), value.maximumPersistentDisks()); - assertEquals(expected.maximumPersistentDisksSizeGb(), value.maximumPersistentDisksSizeGb()); - assertEquals(expected.deprecationStatus(), value.deprecationStatus()); + assertEquals(expected.getMachineTypeId(), value.getMachineTypeId()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getCpus(), value.getCpus()); + assertEquals(expected.getMemoryMb(), value.getMemoryMb()); + assertEquals(expected.getScratchDisksSizeGb(), value.getScratchDisksSizeGb()); + assertEquals(expected.getMaximumPersistentDisks(), value.getMaximumPersistentDisks()); + assertEquals(expected.getMaximumPersistentDisksSizeGb(), + value.getMaximumPersistentDisksSizeGb()); + assertEquals(expected.getDeprecationStatus(), value.getDeprecationStatus()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/MetadataTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/MetadataTest.java index 9de656ff24d0..93a093686c48 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/MetadataTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/MetadataTest.java @@ -27,22 +27,43 @@ public class MetadataTest { - private static final Metadata METADATA = Metadata.builder() + private static final Metadata METADATA = Metadata.newBuilder() + .add("key1", "value1") + .add("key2", "value2") + .build(); + private static final Metadata DEPRECATED_METADATA = Metadata.builder() .add("key1", "value1") .add("key2", "value2") .build(); @Test public void testToBuilder() { - Metadata metadata = METADATA.toBuilder().fingerprint("newFingerprint").build(); - assertEquals("newFingerprint", metadata.fingerprint()); - compareMetadata(METADATA, metadata.toBuilder().fingerprint(null).build()); + Metadata metadata = METADATA.toBuilder().setFingerprint("newFingerprint").build(); + assertEquals("newFingerprint", metadata.getFingerprint()); + compareMetadata(METADATA, metadata.toBuilder().setFingerprint(null).build()); } @Test public void testBuilder() { - assertEquals(ImmutableMap.of("key1", "value1", "key2", "value2"), METADATA.values()); - assertNull(METADATA.fingerprint()); + assertEquals(ImmutableMap.of("key1", "value1", "key2", "value2"), METADATA.getValues()); + assertNull(METADATA.getFingerprint()); + Metadata metadata = Metadata.newBuilder() + .setValues(ImmutableMap.of("key1", "value1", "key2", "value2")) + .build(); + assertEquals(ImmutableMap.of("key1", "value1", "key2", "value2"), metadata.getValues()); + assertNull(metadata.getFingerprint()); + metadata = Metadata.newBuilder() + .setValues(ImmutableMap.of("key1", "value1", "key2", "value2")) + .setFingerprint("fingerprint") + .build(); + assertEquals(ImmutableMap.of("key1", "value1", "key2", "value2"), metadata.getValues()); + assertEquals("fingerprint", metadata.getFingerprint()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(ImmutableMap.of("key1", "value1", "key2", "value2"), DEPRECATED_METADATA.values()); + assertNull(DEPRECATED_METADATA.fingerprint()); Metadata metadata = Metadata.builder() .values(ImmutableMap.of("key1", "value1", "key2", "value2")) .build(); @@ -65,17 +86,17 @@ public void testOf() { @Test public void testToAndFromPb() { compareMetadata(METADATA, Metadata.fromPb(METADATA.toPb())); - Metadata metadata = Metadata.builder() - .values(ImmutableMap.of("key1", "value1", "key2", "value2")) - .fingerprint("fingerprint") + Metadata metadata = Metadata.newBuilder() + .setValues(ImmutableMap.of("key1", "value1", "key2", "value2")) + .setFingerprint("fingerprint") .build(); compareMetadata(metadata, Metadata.fromPb(metadata.toPb())); } public void compareMetadata(Metadata expected, Metadata value) { assertEquals(expected, value); - assertEquals(expected.fingerprint(), value.fingerprint()); - assertEquals(expected.values(), value.values()); + assertEquals(expected.getFingerprint(), value.getFingerprint()); + assertEquals(expected.getValues(), value.getValues()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/NetworkIdTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/NetworkIdTest.java index fb785852cf71..ec8c1905b444 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/NetworkIdTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/NetworkIdTest.java @@ -38,6 +38,17 @@ public class NetworkIdTest { @Test public void testOf() { + NetworkId networkId = NetworkId.of(PROJECT, NETWORK); + assertEquals(PROJECT, networkId.getProject()); + assertEquals(NETWORK, networkId.getNetwork()); + assertEquals(URL, networkId.getSelfLink()); + networkId = NetworkId.of(NETWORK); + assertNull(networkId.getProject()); + assertEquals(NETWORK, networkId.getNetwork()); + } + + @Test + public void testOfDeprecated() { NetworkId networkId = NetworkId.of(PROJECT, NETWORK); assertEquals(PROJECT, networkId.project()); assertEquals(NETWORK, networkId.network()); @@ -50,7 +61,7 @@ public void testOf() { @Test public void testToAndFromUrl() { NetworkId networkId = NetworkId.of(PROJECT, NETWORK); - compareNetworkId(networkId, NetworkId.fromUrl(networkId.selfLink())); + compareNetworkId(networkId, NetworkId.fromUrl(networkId.getSelfLink())); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("notMatchingUrl is not a valid network URL"); NetworkId.fromUrl("notMatchingUrl"); @@ -65,15 +76,15 @@ public void testSetProjectId() { @Test public void testMatchesUrl() { - assertTrue(NetworkId.matchesUrl(NetworkId.of(PROJECT, NETWORK).selfLink())); + assertTrue(NetworkId.matchesUrl(NetworkId.of(PROJECT, NETWORK).getSelfLink())); assertFalse(NetworkId.matchesUrl("notMatchingUrl")); } private void compareNetworkId(NetworkId expected, NetworkId value) { assertEquals(expected, value); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.network(), expected.network()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getNetwork(), expected.getNetwork()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/NetworkInfoTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/NetworkInfoTest.java index e2d9c4451ee4..4ba8dd3d5bad 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/NetworkInfoTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/NetworkInfoTest.java @@ -42,29 +42,41 @@ public class NetworkInfoTest { private static final SubnetNetworkConfiguration SUBNET_NETWORK_CONFIGURATION = new SubnetNetworkConfiguration(AUTO_CREATE_SUBNETWORKS, SUBNETWORKS); private static final NetworkInfo NETWORK_INFO = + NetworkInfo.newBuilder(NETWORK_ID, NETWORK_CONFIGURATION) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .build(); + private static final NetworkInfo SUBNET_NETWORK_INFO = + NetworkInfo.newBuilder(NETWORK_ID, SUBNET_NETWORK_CONFIGURATION) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .build(); + private static final NetworkInfo DEPRECATED_NETWORK_INFO = NetworkInfo.builder(NETWORK_ID, NETWORK_CONFIGURATION) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) .description(DESCRIPTION) .build(); - private static final NetworkInfo SUBNET_NETWORK_INFO = + private static final NetworkInfo DEPRECATED_SUBNET_NETWORK_INFO = NetworkInfo.builder(NETWORK_ID, SUBNET_NETWORK_CONFIGURATION) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(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(); + NetworkInfo networkInfo = NETWORK_INFO.toBuilder().setDescription("newDescription").build(); + assertEquals("newDescription", networkInfo.getDescription()); + networkInfo = networkInfo.toBuilder().setDescription("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(); + networkInfo = SUBNET_NETWORK_INFO.toBuilder().setDescription("newDescription").build(); + assertEquals("newDescription", networkInfo.getDescription()); + networkInfo = networkInfo.toBuilder().setDescription("description").build(); compareNetworkInfo(SUBNET_NETWORK_INFO, networkInfo); } @@ -76,26 +88,40 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { - assertEquals(GENERATED_ID, NETWORK_INFO.generatedId()); - assertEquals(NETWORK_ID, NETWORK_INFO.networkId()); - assertEquals(CREATION_TIMESTAMP, NETWORK_INFO.creationTimestamp()); - assertEquals(DESCRIPTION, NETWORK_INFO.description()); - assertEquals(NETWORK_CONFIGURATION, NETWORK_INFO.configuration()); - assertEquals(GENERATED_ID, SUBNET_NETWORK_INFO.generatedId()); - 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()); + assertEquals(GENERATED_ID, NETWORK_INFO.getGeneratedId()); + assertEquals(NETWORK_ID, NETWORK_INFO.getNetworkId()); + assertEquals(CREATION_TIMESTAMP, NETWORK_INFO.getCreationTimestamp()); + assertEquals(DESCRIPTION, NETWORK_INFO.getDescription()); + assertEquals(NETWORK_CONFIGURATION, NETWORK_INFO.getConfiguration()); + assertEquals(GENERATED_ID, SUBNET_NETWORK_INFO.getGeneratedId()); + assertEquals(NETWORK_ID, SUBNET_NETWORK_INFO.getNetworkId()); + assertEquals(CREATION_TIMESTAMP, SUBNET_NETWORK_INFO.getCreationTimestamp()); + assertEquals(DESCRIPTION, SUBNET_NETWORK_INFO.getDescription()); + assertEquals(SUBNET_NETWORK_CONFIGURATION, SUBNET_NETWORK_INFO.getConfiguration()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(GENERATED_ID, DEPRECATED_NETWORK_INFO.generatedId()); + assertEquals(NETWORK_ID, DEPRECATED_NETWORK_INFO.networkId()); + assertEquals(CREATION_TIMESTAMP, DEPRECATED_NETWORK_INFO.creationTimestamp()); + assertEquals(DESCRIPTION, DEPRECATED_NETWORK_INFO.description()); + assertEquals(NETWORK_CONFIGURATION, DEPRECATED_NETWORK_INFO.configuration()); + assertEquals(GENERATED_ID, DEPRECATED_SUBNET_NETWORK_INFO.generatedId()); + assertEquals(NETWORK_ID, DEPRECATED_SUBNET_NETWORK_INFO.networkId()); + assertEquals(CREATION_TIMESTAMP, DEPRECATED_SUBNET_NETWORK_INFO.creationTimestamp()); + assertEquals(DESCRIPTION, DEPRECATED_SUBNET_NETWORK_INFO.description()); + assertEquals(SUBNET_NETWORK_CONFIGURATION, DEPRECATED_SUBNET_NETWORK_INFO.configuration()); } @Test public void testOf() { NetworkInfo networkInfo = NetworkInfo.of(NETWORK_ID, NETWORK_CONFIGURATION); - assertNull(networkInfo.generatedId()); - assertEquals(NETWORK_ID, NETWORK_INFO.networkId()); - assertEquals(NETWORK_CONFIGURATION, NETWORK_INFO.configuration()); - assertNull(networkInfo.creationTimestamp()); - assertNull(networkInfo.description()); + assertNull(networkInfo.getGeneratedId()); + assertEquals(NETWORK_ID, NETWORK_INFO.getNetworkId()); + assertEquals(NETWORK_CONFIGURATION, NETWORK_INFO.getConfiguration()); + assertNull(networkInfo.getCreationTimestamp()); + assertNull(networkInfo.getDescription()); } @Test @@ -109,18 +135,18 @@ public void testToAndFromPb() { @Test public void testSetProjectId() { NetworkInfo networkInfo = NETWORK_INFO.toBuilder() - .networkId(NetworkId.of("network")) + .setNetworkId(NetworkId.of("network")) .build(); compareNetworkInfo(NETWORK_INFO, networkInfo.setProjectId("project")); } public void compareNetworkInfo(NetworkInfo expected, NetworkInfo value) { assertEquals(expected, value); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.networkId(), value.networkId()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.configuration(), value.configuration()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getNetworkId(), value.getNetworkId()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getConfiguration(), value.getConfiguration()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/NetworkInterfaceTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/NetworkInterfaceTest.java index c36d52d8bd0f..508e0bc87452 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/NetworkInterfaceTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/NetworkInterfaceTest.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import com.google.cloud.compute.NetworkInterface.AccessConfig; import com.google.common.collect.ImmutableList; import org.junit.Assert; @@ -32,39 +33,64 @@ public class NetworkInterfaceTest { private static final NetworkId NETWORK = NetworkId.of("project", "network"); private static final String NETWORK_IP = "192.168.1.1"; private static final SubnetworkId SUBNETWORK = SubnetworkId.of("project", "region", "subnetwork"); - private static final NetworkInterface.AccessConfig ACCESS_CONFIG = NetworkInterface.AccessConfig.builder() - .name("accessConfig") - .natIp("192.168.1.1") - .type(NetworkInterface.AccessConfig.Type.ONE_TO_ONE_NAT) - .build(); - private static final List ACCESS_CONFIGURATIONS = + private static final AccessConfig ACCESS_CONFIG = + AccessConfig.newBuilder() + .setName("accessConfig") + .setNatIp("192.168.1.1") + .setType(AccessConfig.Type.ONE_TO_ONE_NAT) + .build(); + private static final AccessConfig DEPRECATED_ACCESS_CONFIG = + AccessConfig.builder() + .name("accessConfig") + .natIp("192.168.1.1") + .type(AccessConfig.Type.ONE_TO_ONE_NAT) + .build(); + private static final List ACCESS_CONFIGURATIONS = ImmutableList.of(ACCESS_CONFIG); - private static final NetworkInterface NETWORK_INTERFACE = NetworkInterface.builder(NETWORK) - .name(NAME) - .networkIp(NETWORK_IP) + private static final NetworkInterface NETWORK_INTERFACE = NetworkInterface.newBuilder(NETWORK) + .setName(NAME) + .setNetworkIp(NETWORK_IP) + .setSubnetwork(SUBNETWORK) + .setAccessConfigurations(ACCESS_CONFIGURATIONS) + .build(); + private static final NetworkInterface DEPRECATED_NETWORK_INTERFACE = + NetworkInterface.builder(NETWORK) + .setName(NAME) + .setNetworkIp(NETWORK_IP) .subnetwork(SUBNETWORK) .accessConfigurations(ACCESS_CONFIGURATIONS) .build(); @Test public void testAccessConfigToBuilder() { - NetworkInterface.AccessConfig accessConfig = ACCESS_CONFIG.toBuilder().name("newName").build(); + AccessConfig accessConfig = + ACCESS_CONFIG.toBuilder().setName("newName").build(); + assertEquals("newName", accessConfig.getName()); + compareAccessConfig(ACCESS_CONFIG, accessConfig.toBuilder().setName("accessConfig").build()); + } + + @Test + public void testAccessConfigToBuilderDeprecated() { + AccessConfig accessConfig = + DEPRECATED_ACCESS_CONFIG.toBuilder().name("newName").build(); assertEquals("newName", accessConfig.name()); - compareAccessConfig(ACCESS_CONFIG, accessConfig.toBuilder().name("accessConfig").build()); + compareAccessConfig(DEPRECATED_ACCESS_CONFIG, + accessConfig.toBuilder().name("accessConfig").build()); } @Test public void testAccessConfigToBuilderIncomplete() { - NetworkInterface.AccessConfig accessConfig = NetworkInterface.AccessConfig.of(); + AccessConfig accessConfig = AccessConfig.of(); compareAccessConfig(accessConfig, accessConfig.toBuilder().build()); } @Test public void testToBuilder() { compareNetworkInterface(NETWORK_INTERFACE, NETWORK_INTERFACE.toBuilder().build()); - NetworkInterface networkInterface = NETWORK_INTERFACE.toBuilder().name("newInterface").build(); - assertEquals("newInterface", networkInterface.name()); - networkInterface = networkInterface.toBuilder().name(NAME).build(); + NetworkInterface networkInterface = + NETWORK_INTERFACE.toBuilder().setName("newInterface").build(); + assertEquals("newInterface", networkInterface.getName()); + networkInterface = networkInterface.toBuilder().setName(NAME).build(); compareNetworkInterface(NETWORK_INTERFACE, networkInterface); } @@ -72,27 +98,47 @@ public void testToBuilder() { public void testToBuilderIncomplete() { NetworkInterface networkInterface = NetworkInterface.of(NETWORK); assertEquals(networkInterface, networkInterface.toBuilder().build()); - networkInterface = NetworkInterface.of(NETWORK.network()); + networkInterface = NetworkInterface.of(NETWORK.getNetwork()); assertEquals(networkInterface, networkInterface.toBuilder().build()); } @Test public void testAccessConfigBuilder() { - assertEquals("accessConfig", ACCESS_CONFIG.name()); - assertEquals("192.168.1.1", ACCESS_CONFIG.natIp()); - Assert.assertEquals(NetworkInterface.AccessConfig.Type.ONE_TO_ONE_NAT, ACCESS_CONFIG.type()); + assertEquals("accessConfig", ACCESS_CONFIG.getName()); + assertEquals("192.168.1.1", ACCESS_CONFIG.getNatIp()); + assertEquals(AccessConfig.Type.ONE_TO_ONE_NAT, ACCESS_CONFIG.getType()); } @Test public void testBuilder() { - assertEquals(NAME, NETWORK_INTERFACE.name()); - assertEquals(NETWORK, NETWORK_INTERFACE.network()); - assertEquals(NETWORK_IP, NETWORK_INTERFACE.networkIp()); - assertEquals(SUBNETWORK, NETWORK_INTERFACE.subnetwork()); - assertEquals(ACCESS_CONFIGURATIONS, NETWORK_INTERFACE.accessConfigurations()); + assertEquals(NAME, NETWORK_INTERFACE.getName()); + assertEquals(NETWORK, NETWORK_INTERFACE.getNetwork()); + assertEquals(NETWORK_IP, NETWORK_INTERFACE.getNetworkIp()); + assertEquals(SUBNETWORK, NETWORK_INTERFACE.getSubnetwork()); + assertEquals(ACCESS_CONFIGURATIONS, NETWORK_INTERFACE.getAccessConfigurations()); + NetworkInterface networkInterface = NetworkInterface.newBuilder("network") + .setName(NAME) + .setNetworkIp(NETWORK_IP) + .setSubnetwork(SUBNETWORK) + .setAccessConfigurations(ACCESS_CONFIG) + .build(); + assertEquals(NAME, networkInterface.getName()); + assertEquals(NetworkId.of("network"), networkInterface.getNetwork()); + assertEquals(NETWORK_IP, networkInterface.getNetworkIp()); + assertEquals(SUBNETWORK, networkInterface.getSubnetwork()); + assertEquals(ACCESS_CONFIGURATIONS, networkInterface.getAccessConfigurations()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(NAME, DEPRECATED_NETWORK_INTERFACE.name()); + assertEquals(NETWORK, DEPRECATED_NETWORK_INTERFACE.network()); + assertEquals(NETWORK_IP, DEPRECATED_NETWORK_INTERFACE.networkIp()); + assertEquals(SUBNETWORK, DEPRECATED_NETWORK_INTERFACE.subnetwork()); + assertEquals(ACCESS_CONFIGURATIONS, DEPRECATED_NETWORK_INTERFACE.accessConfigurations()); NetworkInterface networkInterface = NetworkInterface.builder("network") - .name(NAME) - .networkIp(NETWORK_IP) + .setName(NAME) + .setNetworkIp(NETWORK_IP) .subnetwork(SUBNETWORK) .accessConfigurations(ACCESS_CONFIG) .build(); @@ -105,37 +151,38 @@ public void testBuilder() { @Test public void testAccessConfigOf() { - NetworkInterface.AccessConfig accessConfig = NetworkInterface.AccessConfig.of("192.168.1.1"); - assertNull(accessConfig.name()); - assertEquals("192.168.1.1", accessConfig.natIp()); - assertNull(accessConfig.type()); - accessConfig = NetworkInterface.AccessConfig.of(); - assertNull(accessConfig.name()); - assertNull(accessConfig.natIp()); - assertNull(accessConfig.type()); + AccessConfig accessConfig = AccessConfig.of("192.168.1.1"); + assertNull(accessConfig.getName()); + assertEquals("192.168.1.1", accessConfig.getNatIp()); + assertNull(accessConfig.getType()); + accessConfig = AccessConfig.of(); + assertNull(accessConfig.getName()); + assertNull(accessConfig.getNatIp()); + assertNull(accessConfig.getType()); } @Test public void testOf() { NetworkInterface networkInterface = NetworkInterface.of(NETWORK); - assertNull(networkInterface.name()); - assertEquals(NETWORK, networkInterface.network()); - assertNull(networkInterface.networkIp()); - assertNull(networkInterface.subnetwork()); - networkInterface = NetworkInterface.of(NETWORK.network()); - assertNull(networkInterface.name()); - assertNull(networkInterface.network().project()); - assertEquals(NETWORK.network(), networkInterface.network().network()); - assertNull(networkInterface.networkIp()); - assertNull(networkInterface.subnetwork()); + assertNull(networkInterface.getName()); + assertEquals(NETWORK, networkInterface.getNetwork()); + assertNull(networkInterface.getNetworkIp()); + assertNull(networkInterface.getSubnetwork()); + networkInterface = NetworkInterface.of(NETWORK.getNetwork()); + assertNull(networkInterface.getName()); + assertNull(networkInterface.getNetwork().getProject()); + assertEquals(NETWORK.getNetwork(), networkInterface.getNetwork().getNetwork()); + assertNull(networkInterface.getNetworkIp()); + assertNull(networkInterface.getSubnetwork()); } @Test public void testAccessConfigToAndFromPb() { - NetworkInterface.AccessConfig accessConfig = NetworkInterface.AccessConfig.fromPb(ACCESS_CONFIG.toPb()); + AccessConfig accessConfig = + AccessConfig.fromPb(ACCESS_CONFIG.toPb()); compareAccessConfig(ACCESS_CONFIG, accessConfig); - accessConfig = NetworkInterface.AccessConfig.of(); - compareAccessConfig(accessConfig, NetworkInterface.AccessConfig.fromPb(accessConfig.toPb())); + accessConfig = AccessConfig.of(); + compareAccessConfig(accessConfig, AccessConfig.fromPb(accessConfig.toPb())); } @Test @@ -152,27 +199,27 @@ public void testSetProjectId() { compareNetworkInterface(networkInterface, NetworkInterface.of(NetworkId.of("network")).setProjectId("project")); networkInterface = NETWORK_INTERFACE.toBuilder() - .network(NetworkId.of("network")) - .subnetwork(SubnetworkId.of("region", "subnetwork")) + .setNetwork(NetworkId.of("network")) + .setSubnetwork(SubnetworkId.of("region", "subnetwork")) .build(); compareNetworkInterface(NETWORK_INTERFACE, networkInterface.setProjectId("project")); } - public void compareAccessConfig(NetworkInterface.AccessConfig expected, NetworkInterface.AccessConfig value) { + public void compareAccessConfig(AccessConfig expected, AccessConfig value) { assertEquals(expected, value); - assertEquals(expected.name(), value.name()); - assertEquals(expected.natIp(), value.natIp()); - assertEquals(expected.type(), value.type()); + assertEquals(expected.getName(), value.getName()); + assertEquals(expected.getNatIp(), value.getNatIp()); + assertEquals(expected.getType(), value.getType()); assertEquals(expected.hashCode(), value.hashCode()); } public void compareNetworkInterface(NetworkInterface expected, NetworkInterface value) { assertEquals(expected, value); - assertEquals(expected.name(), value.name()); - assertEquals(expected.network(), value.network()); - assertEquals(expected.networkIp(), value.networkIp()); - assertEquals(expected.subnetwork(), value.subnetwork()); - assertEquals(expected.accessConfigurations(), value.accessConfigurations()); + assertEquals(expected.getName(), value.getName()); + assertEquals(expected.getNetwork(), value.getNetwork()); + assertEquals(expected.getNetworkIp(), value.getNetworkIp()); + assertEquals(expected.getSubnetwork(), value.getSubnetwork()); + assertEquals(expected.getAccessConfigurations(), value.getAccessConfigurations()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/NetworkTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/NetworkTest.java index 5bc240fafddc..73ba3a346799 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/NetworkTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/NetworkTest.java @@ -62,24 +62,24 @@ private void initializeExpectedNetwork(int optionsCalls) { replay(serviceMockReturnsOptions); standardNetwork = new Network.Builder(serviceMockReturnsOptions, NETWORK_ID, NETWORK_CONFIGURATION) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) .build(); subnetNetwork = new Network.Builder(serviceMockReturnsOptions, NETWORK_ID, SUBNET_NETWORK_CONFIGURATION) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) .build(); compute = createStrictMock(Compute.class); } private void initializeNetwork() { network = new Network.Builder(compute, NETWORK_ID, NETWORK_CONFIGURATION) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) .build(); } @@ -87,9 +87,9 @@ private void initializeNetwork() { public void testToBuilder() { initializeExpectedNetwork(9); compareNetwork(standardNetwork, standardNetwork.toBuilder().build()); - Network newNetwork = standardNetwork.toBuilder().description("newDescription").build(); - assertEquals("newDescription", newNetwork.description()); - newNetwork = newNetwork.toBuilder().description("description").build(); + Network newNetwork = standardNetwork.toBuilder().setDescription("newDescription").build(); + assertEquals("newDescription", newNetwork.getDescription()); + newNetwork = newNetwork.toBuilder().setDescription("description").build(); compareNetwork(standardNetwork, newNetwork); } @@ -104,6 +104,23 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { + initializeExpectedNetwork(2); + assertEquals(GENERATED_ID, standardNetwork.getGeneratedId()); + assertEquals(NETWORK_ID, standardNetwork.getNetworkId()); + assertEquals(CREATION_TIMESTAMP, standardNetwork.getCreationTimestamp()); + assertEquals(DESCRIPTION, standardNetwork.getDescription()); + assertEquals(NETWORK_CONFIGURATION, standardNetwork.getConfiguration()); + assertSame(serviceMockReturnsOptions, standardNetwork.getCompute()); + assertEquals(GENERATED_ID, subnetNetwork.getGeneratedId()); + assertEquals(NETWORK_ID, subnetNetwork.getNetworkId()); + assertEquals(CREATION_TIMESTAMP, subnetNetwork.getCreationTimestamp()); + assertEquals(DESCRIPTION, subnetNetwork.getDescription()); + assertEquals(SUBNET_NETWORK_CONFIGURATION, subnetNetwork.getConfiguration()); + assertSame(serviceMockReturnsOptions, subnetNetwork.getCompute()); + } + + @Test + public void testBuilderDeprecated() { initializeExpectedNetwork(2); assertEquals(GENERATED_ID, standardNetwork.generatedId()); assertEquals(NETWORK_ID, standardNetwork.networkId()); @@ -136,9 +153,9 @@ public void testDeleteOperation() { initializeExpectedNetwork(3); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(GlobalOperationId.of("project", "op")) + .setOperationId(GlobalOperationId.of("project", "op")) .build(); - expect(compute.deleteNetwork(NETWORK_ID.network())).andReturn(operation); + expect(compute.deleteNetwork(NETWORK_ID.getNetwork())).andReturn(operation); replay(compute); initializeNetwork(); assertSame(operation, network.delete()); @@ -148,7 +165,7 @@ public void testDeleteOperation() { public void testDeleteNull() { initializeExpectedNetwork(2); expect(compute.options()).andReturn(mockOptions); - expect(compute.deleteNetwork(NETWORK_ID.network())).andReturn(null); + expect(compute.deleteNetwork(NETWORK_ID.getNetwork())).andReturn(null); replay(compute); initializeNetwork(); assertNull(network.delete()); @@ -159,7 +176,7 @@ public void testExists_True() throws Exception { initializeExpectedNetwork(2); Compute.NetworkOption[] expectedOptions = {Compute.NetworkOption.fields()}; expect(compute.options()).andReturn(mockOptions); - expect(compute.getNetwork(NETWORK_ID.network(), expectedOptions)) + expect(compute.getNetwork(NETWORK_ID.getNetwork(), expectedOptions)) .andReturn(standardNetwork); replay(compute); initializeNetwork(); @@ -172,7 +189,7 @@ public void testExists_False() throws Exception { initializeExpectedNetwork(2); Compute.NetworkOption[] expectedOptions = {Compute.NetworkOption.fields()}; expect(compute.options()).andReturn(mockOptions); - expect(compute.getNetwork(NETWORK_ID.network(), expectedOptions)).andReturn(null); + expect(compute.getNetwork(NETWORK_ID.getNetwork(), expectedOptions)).andReturn(null); replay(compute); initializeNetwork(); assertFalse(network.exists()); @@ -183,7 +200,7 @@ public void testExists_False() throws Exception { public void testReload() throws Exception { initializeExpectedNetwork(4); expect(compute.options()).andReturn(mockOptions); - expect(compute.getNetwork(NETWORK_ID.network())).andReturn(standardNetwork); + expect(compute.getNetwork(NETWORK_ID.getNetwork())).andReturn(standardNetwork); replay(compute); initializeNetwork(); Network updatedNetwork = network.reload(); @@ -195,7 +212,7 @@ public void testReload() throws Exception { public void testReloadNull() throws Exception { initializeExpectedNetwork(2); expect(compute.options()).andReturn(mockOptions); - expect(compute.getNetwork(NETWORK_ID.network())).andReturn(null); + expect(compute.getNetwork(NETWORK_ID.getNetwork())).andReturn(null); replay(compute); initializeNetwork(); assertNull(network.reload()); @@ -206,7 +223,7 @@ public void testReloadNull() throws Exception { public void testReloadWithOptions() throws Exception { initializeExpectedNetwork(4); expect(compute.options()).andReturn(mockOptions); - expect(compute.getNetwork(NETWORK_ID.network(), Compute.NetworkOption.fields())) + expect(compute.getNetwork(NETWORK_ID.getNetwork(), Compute.NetworkOption.fields())) .andReturn(standardNetwork); replay(compute); initializeNetwork(); @@ -219,7 +236,7 @@ public void testReloadWithOptions() throws Exception { public void testCreateSubnetwork() throws Exception { initializeExpectedNetwork(3); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(RegionOperationId.of(SUBNETWORK1.regionId(), "op")) + .setOperationId(RegionOperationId.of(SUBNETWORK1.getRegionId(), "op")) .build(); expect(compute.options()).andReturn(mockOptions); expect(compute.create(SubnetworkInfo.of(SUBNETWORK1, NETWORK_ID, IP_RANGE))) @@ -234,7 +251,7 @@ public void testCreateSubnetwork() throws Exception { public void testCreateSubnetworkWithOptions() throws Exception { initializeExpectedNetwork(3); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(RegionOperationId.of(SUBNETWORK1.regionId(), "op")) + .setOperationId(RegionOperationId.of(SUBNETWORK1.getRegionId(), "op")) .build(); expect(compute.options()).andReturn(mockOptions); expect(compute.create(SubnetworkInfo.of(SUBNETWORK1, NETWORK_ID, IP_RANGE), @@ -248,12 +265,12 @@ public void testCreateSubnetworkWithOptions() throws Exception { public void compareNetwork(Network expected, Network value) { assertEquals(expected, value); - assertEquals(expected.compute().options(), value.compute().options()); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.networkId(), value.networkId()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.configuration(), value.configuration()); + assertEquals(expected.getCompute().options(), value.getCompute().options()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getNetworkId(), value.getNetworkId()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getConfiguration(), value.getConfiguration()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/OperationIdTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/OperationIdTest.java index 9944a6fc7585..58ea548a67f9 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/OperationIdTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/OperationIdTest.java @@ -44,6 +44,51 @@ public class OperationIdTest { @Test public void testOf() { + GlobalOperationId operationId = GlobalOperationId.of(PROJECT, NAME); + assertEquals(OperationId.Type.GLOBAL, operationId.getType()); + assertEquals(PROJECT, operationId.getProject()); + assertEquals(NAME, operationId.getOperation()); + assertEquals(GLOBAL_URL, operationId.getSelfLink()); + operationId = GlobalOperationId.of(NAME); + assertEquals(OperationId.Type.GLOBAL, operationId.getType()); + assertNull(operationId.getProject()); + assertEquals(NAME, operationId.getOperation()); + ZoneOperationId zoneOperationId = ZoneOperationId.of(PROJECT, ZONE, NAME); + assertEquals(OperationId.Type.ZONE, zoneOperationId.getType()); + assertEquals(PROJECT, zoneOperationId.getProject()); + assertEquals(ZONE, zoneOperationId.getZone()); + assertEquals(NAME, zoneOperationId.getOperation()); + assertEquals(ZONE_URL, zoneOperationId.getSelfLink()); + zoneOperationId = ZoneOperationId.of(ZONE, NAME); + assertEquals(OperationId.Type.ZONE, zoneOperationId.getType()); + assertNull(zoneOperationId.getProject()); + assertEquals(ZONE, zoneOperationId.getZone()); + assertEquals(NAME, zoneOperationId.getOperation()); + zoneOperationId = ZoneOperationId.of(ZoneId.of(PROJECT, ZONE), NAME); + assertEquals(OperationId.Type.ZONE, zoneOperationId.getType()); + assertEquals(PROJECT, zoneOperationId.getProject()); + assertEquals(ZONE, zoneOperationId.getZone()); + assertEquals(NAME, zoneOperationId.getOperation()); + RegionOperationId regionOperationId = RegionOperationId.of(PROJECT, REGION, NAME); + assertEquals(OperationId.Type.REGION, regionOperationId.getType()); + assertEquals(PROJECT, regionOperationId.getProject()); + assertEquals(REGION, regionOperationId.getRegion()); + assertEquals(NAME, regionOperationId.getOperation()); + assertEquals(REGION_URL, regionOperationId.getSelfLink()); + regionOperationId = RegionOperationId.of(REGION, NAME); + assertEquals(OperationId.Type.REGION, regionOperationId.getType()); + assertNull(regionOperationId.getProject()); + assertEquals(REGION, regionOperationId.getRegion()); + assertEquals(NAME, regionOperationId.getOperation()); + regionOperationId = RegionOperationId.of(RegionId.of(PROJECT, REGION), NAME); + assertEquals(OperationId.Type.REGION, regionOperationId.getType()); + assertEquals(PROJECT, regionOperationId.getProject()); + assertEquals(REGION, regionOperationId.getRegion()); + assertEquals(NAME, regionOperationId.getOperation()); + } + + @Test + public void testOfDeprecated() { GlobalOperationId operationId = GlobalOperationId.of(PROJECT, NAME); assertEquals(OperationId.Type.GLOBAL, operationId.type()); assertEquals(PROJECT, operationId.project()); @@ -90,7 +135,7 @@ public void testOf() { @Test public void testToAndFromUrlGlobal() { GlobalOperationId operationId = GlobalOperationId.of(PROJECT, NAME); - compareOperationId(operationId, GlobalOperationId.fromUrl(operationId.selfLink())); + compareOperationId(operationId, GlobalOperationId.fromUrl(operationId.getSelfLink())); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("notMatchingUrl is not a valid global operation URL"); GlobalOperationId.fromUrl("notMatchingUrl"); @@ -100,7 +145,7 @@ public void testToAndFromUrlGlobal() { public void testToAndFromUrlRegion() { RegionOperationId regionOperationId = RegionOperationId.of(PROJECT, REGION, NAME); compareRegionOperationId(regionOperationId, - RegionOperationId.fromUrl(regionOperationId.selfLink())); + RegionOperationId.fromUrl(regionOperationId.getSelfLink())); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("notMatchingUrl is not a valid region operation URL"); RegionOperationId.fromUrl("notMatchingUrl"); @@ -109,7 +154,7 @@ public void testToAndFromUrlRegion() { @Test public void testToAndFromUrlZone() { ZoneOperationId zoneOperationId = ZoneOperationId.of(PROJECT, ZONE, NAME); - compareZoneOperationId(zoneOperationId, ZoneOperationId.fromUrl(zoneOperationId.selfLink())); + compareZoneOperationId(zoneOperationId, ZoneOperationId.fromUrl(zoneOperationId.getSelfLink())); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("notMatchingUrl is not a valid zone operation URL"); ZoneOperationId.fromUrl("notMatchingUrl"); @@ -131,39 +176,39 @@ public void testSetProjectId() { @Test public void testMatchesUrl() { - assertTrue(GlobalOperationId.matchesUrl(GlobalOperationId.of(PROJECT, NAME).selfLink())); + assertTrue(GlobalOperationId.matchesUrl(GlobalOperationId.of(PROJECT, NAME).getSelfLink())); assertFalse(GlobalOperationId.matchesUrl("notMatchingUrl")); assertTrue( - RegionOperationId.matchesUrl(RegionOperationId.of(PROJECT, REGION, NAME).selfLink())); + RegionOperationId.matchesUrl(RegionOperationId.of(PROJECT, REGION, NAME).getSelfLink())); assertFalse(RegionOperationId.matchesUrl("notMatchingUrl")); - assertTrue(ZoneOperationId.matchesUrl(ZoneOperationId.of(PROJECT, REGION, NAME).selfLink())); + assertTrue(ZoneOperationId.matchesUrl(ZoneOperationId.of(PROJECT, REGION, NAME).getSelfLink())); assertFalse(ZoneOperationId.matchesUrl("notMatchingUrl")); } private void compareOperationId(GlobalOperationId expected, GlobalOperationId value) { assertEquals(expected, value); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.operation(), expected.operation()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getOperation(), expected.getOperation()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } private void compareZoneOperationId(ZoneOperationId expected, ZoneOperationId value) { assertEquals(expected, value); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.zone(), expected.zone()); - assertEquals(expected.operation(), expected.operation()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getZone(), expected.getZone()); + assertEquals(expected.getOperation(), expected.getOperation()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } private void compareRegionOperationId(RegionOperationId expected, RegionOperationId value) { assertEquals(expected, value); - assertEquals(expected.type(), value.type()); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.region(), expected.region()); - assertEquals(expected.operation(), expected.operation()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getType(), value.getType()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getRegion(), expected.getRegion()); + assertEquals(expected.getOperation(), expected.getOperation()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/OperationTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/OperationTest.java index 975610f93609..1a499b0f67ea 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/OperationTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/OperationTest.java @@ -96,88 +96,88 @@ private void initializeExpectedOperation(int optionsCalls) { expect(serviceMockReturnsOptions.options()).andReturn(mockOptions).times(optionsCalls); replay(serviceMockReturnsOptions); globalOperation = new Operation.Builder(serviceMockReturnsOptions) - .generatedId(GENERATED_ID) - .operationId(GLOBAL_OPERATION_ID) - .clientOperationId(CLIENT_OPERATION_ID) - .operationType(OPERATION_TYPE) - .targetLink(TARGET_LINK) - .targetId(TARGET_ID) - .status(STATUS) - .statusMessage(STATUS_MESSAGE) - .user(USER) - .progress(PROGRESS) - .insertTime(INSERT_TIME) - .startTime(START_TIME) - .endTime(END_TIME) - .errors(ERRORS) - .warnings(WARNINGS) - .httpErrorStatusCode(HTTP_ERROR_STATUS_CODE) - .httpErrorMessage(HTTP_ERROR_MESSAGE) - .description(DESCRIPTION) + .getGeneratedId(GENERATED_ID) + .setOperationId(GLOBAL_OPERATION_ID) + .setClientOperationId(CLIENT_OPERATION_ID) + .setOperationType(OPERATION_TYPE) + .setTargetLink(TARGET_LINK) + .setTargetId(TARGET_ID) + .setStatus(STATUS) + .setStatusMessage(STATUS_MESSAGE) + .setUser(USER) + .setProgress(PROGRESS) + .setInsertTime(INSERT_TIME) + .setStartTime(START_TIME) + .setEndTime(END_TIME) + .setErrors(ERRORS) + .setWarnings(WARNINGS) + .setHttpErrorStatusCode(HTTP_ERROR_STATUS_CODE) + .setHttpErrorMessage(HTTP_ERROR_MESSAGE) + .setDescription(DESCRIPTION) .build(); zoneOperation = new Operation.Builder(serviceMockReturnsOptions) - .generatedId(GENERATED_ID) - .operationId(ZONE_OPERATION_ID) - .clientOperationId(CLIENT_OPERATION_ID) - .operationType(OPERATION_TYPE) - .targetLink(TARGET_LINK) - .targetId(TARGET_ID) - .status(STATUS) - .statusMessage(STATUS_MESSAGE) - .user(USER) - .progress(PROGRESS) - .insertTime(INSERT_TIME) - .startTime(START_TIME) - .endTime(END_TIME) - .errors(ERRORS) - .warnings(WARNINGS) - .httpErrorStatusCode(HTTP_ERROR_STATUS_CODE) - .httpErrorMessage(HTTP_ERROR_MESSAGE) - .description(DESCRIPTION) + .getGeneratedId(GENERATED_ID) + .setOperationId(ZONE_OPERATION_ID) + .setClientOperationId(CLIENT_OPERATION_ID) + .setOperationType(OPERATION_TYPE) + .setTargetLink(TARGET_LINK) + .setTargetId(TARGET_ID) + .setStatus(STATUS) + .setStatusMessage(STATUS_MESSAGE) + .setUser(USER) + .setProgress(PROGRESS) + .setInsertTime(INSERT_TIME) + .setStartTime(START_TIME) + .setEndTime(END_TIME) + .setErrors(ERRORS) + .setWarnings(WARNINGS) + .setHttpErrorStatusCode(HTTP_ERROR_STATUS_CODE) + .setHttpErrorMessage(HTTP_ERROR_MESSAGE) + .setDescription(DESCRIPTION) .build(); regionOperation = new Operation.Builder(serviceMockReturnsOptions) - .generatedId(GENERATED_ID) - .operationId(REGION_OPERATION_ID) - .clientOperationId(CLIENT_OPERATION_ID) - .operationType(OPERATION_TYPE) - .targetLink(TARGET_LINK) - .targetId(TARGET_ID) - .status(STATUS) - .statusMessage(STATUS_MESSAGE) - .user(USER) - .progress(PROGRESS) - .insertTime(INSERT_TIME) - .startTime(START_TIME) - .endTime(END_TIME) - .errors(ERRORS) - .warnings(WARNINGS) - .httpErrorStatusCode(HTTP_ERROR_STATUS_CODE) - .httpErrorMessage(HTTP_ERROR_MESSAGE) - .description(DESCRIPTION) + .getGeneratedId(GENERATED_ID) + .setOperationId(REGION_OPERATION_ID) + .setClientOperationId(CLIENT_OPERATION_ID) + .setOperationType(OPERATION_TYPE) + .setTargetLink(TARGET_LINK) + .setTargetId(TARGET_ID) + .setStatus(STATUS) + .setStatusMessage(STATUS_MESSAGE) + .setUser(USER) + .setProgress(PROGRESS) + .setInsertTime(INSERT_TIME) + .setStartTime(START_TIME) + .setEndTime(END_TIME) + .setErrors(ERRORS) + .setWarnings(WARNINGS) + .setHttpErrorStatusCode(HTTP_ERROR_STATUS_CODE) + .setHttpErrorMessage(HTTP_ERROR_MESSAGE) + .setDescription(DESCRIPTION) .build(); compute = createStrictMock(Compute.class); } private void initializeOperation() { operation = new Operation.Builder(compute) - .generatedId(GENERATED_ID) - .operationId(GLOBAL_OPERATION_ID) - .clientOperationId(CLIENT_OPERATION_ID) - .operationType(OPERATION_TYPE) - .targetLink(TARGET_LINK) - .targetId(TARGET_ID) - .status(STATUS) - .statusMessage(STATUS_MESSAGE) - .user(USER) - .progress(PROGRESS) - .insertTime(INSERT_TIME) - .startTime(START_TIME) - .endTime(END_TIME) - .errors(ERRORS) - .warnings(WARNINGS) - .httpErrorStatusCode(HTTP_ERROR_STATUS_CODE) - .httpErrorMessage(HTTP_ERROR_MESSAGE) - .description(DESCRIPTION) + .getGeneratedId(GENERATED_ID) + .setOperationId(GLOBAL_OPERATION_ID) + .setClientOperationId(CLIENT_OPERATION_ID) + .setOperationType(OPERATION_TYPE) + .setTargetLink(TARGET_LINK) + .setTargetId(TARGET_ID) + .setStatus(STATUS) + .setStatusMessage(STATUS_MESSAGE) + .setUser(USER) + .setProgress(PROGRESS) + .setInsertTime(INSERT_TIME) + .setStartTime(START_TIME) + .setEndTime(END_TIME) + .setErrors(ERRORS) + .setWarnings(WARNINGS) + .setHttpErrorStatusCode(HTTP_ERROR_STATUS_CODE) + .setHttpErrorMessage(HTTP_ERROR_MESSAGE) + .setDescription(DESCRIPTION) .build(); } @@ -187,8 +187,29 @@ public void tearDown() throws Exception { } private void assertEqualsCommonFields(Operation operation) { + assertEquals(GENERATED_ID, operation.getGeneratedId()); + assertEquals(CLIENT_OPERATION_ID, operation.getClientOperationId()); + assertEquals(OPERATION_TYPE, operation.getOperationType()); + assertEquals(TARGET_LINK, operation.getTargetLink()); + assertEquals(TARGET_ID, operation.getTargetId()); + assertEquals(STATUS, operation.getStatus()); + assertEquals(STATUS_MESSAGE, operation.getStatusMessage()); + assertEquals(USER, operation.getUser()); + assertEquals(PROGRESS, operation.getProgress()); + assertEquals(INSERT_TIME, operation.getInsertTime()); + assertEquals(START_TIME, operation.getStartTime()); + assertEquals(END_TIME, operation.getEndTime()); + assertEquals(ERRORS, operation.getErrors()); + assertEquals(WARNINGS, operation.getWarnings()); + assertEquals(HTTP_ERROR_STATUS_CODE, globalOperation.getHttpErrorStatusCode()); + assertEquals(HTTP_ERROR_MESSAGE, globalOperation.getHttpErrorMessage()); + assertEquals(DESCRIPTION, globalOperation.getDescription()); + assertSame(serviceMockReturnsOptions, globalOperation.getCompute()); + } + + private void assertEqualsCommonFieldsDeprecated(Operation operation) { assertEquals(GENERATED_ID, operation.generatedId()); - assertEquals(CLIENT_OPERATION_ID, operation.clientOperationId()); + assertEquals(CLIENT_OPERATION_ID, operation.getClientOperationId()); assertEquals(OPERATION_TYPE, operation.operationType()); assertEquals(TARGET_LINK, operation.targetLink()); assertEquals(TARGET_ID, operation.targetId()); @@ -208,8 +229,29 @@ private void assertEqualsCommonFields(Operation operation) { } private void assertNullCommonFields(Operation operation) { + assertNull(operation.getGeneratedId()); + assertNull(operation.getClientOperationId()); + assertNull(operation.getOperationType()); + assertNull(operation.getTargetLink()); + assertNull(operation.getTargetId()); + assertNull(operation.getStatus()); + assertNull(operation.getStatusMessage()); + assertNull(operation.getUser()); + assertNull(operation.getProgress()); + assertNull(operation.getInsertTime()); + assertNull(operation.getStartTime()); + assertNull(operation.getEndTime()); + assertNull(operation.getErrors()); + assertNull(operation.getWarnings()); + assertNull(operation.getHttpErrorStatusCode()); + assertNull(operation.getHttpErrorMessage()); + assertNull(operation.getDescription()); + assertSame(serviceMockReturnsOptions, operation.getCompute()); + } + + private void assertNullCommonFieldsDeprecated(Operation operation) { assertNull(operation.generatedId()); - assertNull(operation.clientOperationId()); + assertNull(operation.getClientOperationId()); assertNull(operation.operationType()); assertNull(operation.targetLink()); assertNull(operation.targetId()); @@ -232,25 +274,51 @@ private void assertNullCommonFields(Operation operation) { public void testBuilder() { initializeExpectedOperation(6); assertEqualsCommonFields(globalOperation); - assertEquals(GLOBAL_OPERATION_ID, globalOperation.operationId()); + assertEquals(GLOBAL_OPERATION_ID, globalOperation.getOperationId()); assertEqualsCommonFields(regionOperation); - assertEquals(REGION_OPERATION_ID, regionOperation.operationId()); + assertEquals(REGION_OPERATION_ID, regionOperation.getOperationId()); assertEqualsCommonFields(zoneOperation); - assertEquals(ZONE_OPERATION_ID, zoneOperation.operationId()); + assertEquals(ZONE_OPERATION_ID, zoneOperation.getOperationId()); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(GLOBAL_OPERATION_ID) + .setOperationId(GLOBAL_OPERATION_ID) .build(); assertNullCommonFields(operation); - assertEquals(GLOBAL_OPERATION_ID, operation.operationId()); + assertEquals(GLOBAL_OPERATION_ID, operation.getOperationId()); operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZONE_OPERATION_ID) + .setOperationId(ZONE_OPERATION_ID) .build(); assertNullCommonFields(operation); - assertEquals(ZONE_OPERATION_ID, operation.operationId()); + assertEquals(ZONE_OPERATION_ID, operation.getOperationId()); operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(REGION_OPERATION_ID) + .setOperationId(REGION_OPERATION_ID) .build(); assertNullCommonFields(operation); + assertEquals(REGION_OPERATION_ID, operation.getOperationId()); + } + + @Test + public void testBuilderDeprecated() { + initializeExpectedOperation(6); + assertEqualsCommonFieldsDeprecated(globalOperation); + assertEquals(GLOBAL_OPERATION_ID, globalOperation.operationId()); + assertEqualsCommonFieldsDeprecated(regionOperation); + assertEquals(REGION_OPERATION_ID, regionOperation.operationId()); + assertEqualsCommonFieldsDeprecated(zoneOperation); + assertEquals(ZONE_OPERATION_ID, zoneOperation.operationId()); + Operation operation = new Operation.Builder(serviceMockReturnsOptions) + .setOperationId(GLOBAL_OPERATION_ID) + .build(); + assertNullCommonFieldsDeprecated(operation); + assertEquals(GLOBAL_OPERATION_ID, operation.operationId()); + operation = new Operation.Builder(serviceMockReturnsOptions) + .setOperationId(ZONE_OPERATION_ID) + .build(); + assertNullCommonFieldsDeprecated(operation); + assertEquals(ZONE_OPERATION_ID, operation.operationId()); + operation = new Operation.Builder(serviceMockReturnsOptions) + .setOperationId(REGION_OPERATION_ID) + .build(); + assertNullCommonFieldsDeprecated(operation); assertEquals(REGION_OPERATION_ID, operation.operationId()); } @@ -266,15 +334,15 @@ public void testToAndFromPb() { compareOperation(zoneOperation, Operation.fromPb(serviceMockReturnsOptions, zoneOperation.toPb())); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(GLOBAL_OPERATION_ID) + .setOperationId(GLOBAL_OPERATION_ID) .build(); compareOperation(operation, Operation.fromPb(serviceMockReturnsOptions, operation.toPb())); operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(ZONE_OPERATION_ID) + .setOperationId(ZONE_OPERATION_ID) .build(); compareOperation(operation, Operation.fromPb(serviceMockReturnsOptions, operation.toPb())); operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(REGION_OPERATION_ID) + .setOperationId(REGION_OPERATION_ID) .build(); compareOperation(operation, Operation.fromPb(serviceMockReturnsOptions, operation.toPb())); } @@ -505,24 +573,24 @@ public void testReloadWithOptions() throws Exception { private void compareOperation(Operation expected, Operation value) { assertEquals(expected, value); - assertEquals(expected.compute().options(), value.compute().options()); - assertEquals(expected.operationId(), value.operationId()); - assertEquals(expected.clientOperationId(), value.clientOperationId()); - assertEquals(expected.operationType(), value.operationType()); - assertEquals(expected.targetLink(), value.targetLink()); - assertEquals(expected.targetId(), value.targetId()); - assertEquals(expected.status(), value.status()); - assertEquals(expected.statusMessage(), value.statusMessage()); - assertEquals(expected.user(), value.user()); - assertEquals(expected.progress(), value.progress()); - assertEquals(expected.insertTime(), value.insertTime()); - assertEquals(expected.startTime(), value.startTime()); - assertEquals(expected.endTime(), value.endTime()); - assertEquals(expected.errors(), value.errors()); - assertEquals(expected.warnings(), value.warnings()); - assertEquals(expected.httpErrorStatusCode(), value.httpErrorStatusCode()); - assertEquals(expected.httpErrorMessage(), value.httpErrorMessage()); - assertEquals(expected.description(), value.description()); + assertEquals(expected.getCompute().options(), value.getCompute().options()); + assertEquals(expected.getOperationId(), value.getOperationId()); + assertEquals(expected.getClientOperationId(), value.getClientOperationId()); + assertEquals(expected.getOperationType(), value.getOperationType()); + assertEquals(expected.getTargetLink(), value.getTargetLink()); + assertEquals(expected.getTargetId(), value.getTargetId()); + assertEquals(expected.getStatus(), value.getStatus()); + assertEquals(expected.getStatusMessage(), value.getStatusMessage()); + assertEquals(expected.getUser(), value.getUser()); + assertEquals(expected.getProgress(), value.getProgress()); + assertEquals(expected.getInsertTime(), value.getInsertTime()); + assertEquals(expected.getStartTime(), value.getStartTime()); + assertEquals(expected.getEndTime(), value.getEndTime()); + assertEquals(expected.getErrors(), value.getErrors()); + assertEquals(expected.getWarnings(), value.getWarnings()); + assertEquals(expected.getHttpErrorStatusCode(), value.getHttpErrorStatusCode()); + assertEquals(expected.getHttpErrorMessage(), value.getHttpErrorMessage()); + assertEquals(expected.getDescription(), value.getDescription()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/RegionIdTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/RegionIdTest.java index c6646db93acf..0e0a3ac9dce7 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/RegionIdTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/RegionIdTest.java @@ -38,6 +38,17 @@ public class RegionIdTest { @Test public void testOf() { + RegionId regionId = RegionId.of(PROJECT, REGION); + assertEquals(PROJECT, regionId.getProject()); + assertEquals(REGION, regionId.getRegion()); + assertEquals(URL, regionId.getSelfLink()); + regionId = RegionId.of(REGION); + assertNull(regionId.getProject()); + assertEquals(REGION, regionId.getRegion()); + } + + @Test + public void testOfDeprecated() { RegionId regionId = RegionId.of(PROJECT, REGION); assertEquals(PROJECT, regionId.project()); assertEquals(REGION, regionId.region()); @@ -50,7 +61,7 @@ public void testOf() { @Test public void testToAndFromUrl() { RegionId regionId = RegionId.of(PROJECT, REGION); - compareRegionId(regionId, RegionId.fromUrl(regionId.selfLink())); + compareRegionId(regionId, RegionId.fromUrl(regionId.getSelfLink())); } @Test @@ -65,15 +76,15 @@ public void testSetProjectId() { @Test public void testMatchesUrl() { - assertTrue(RegionId.matchesUrl(RegionId.of(PROJECT, REGION).selfLink())); + assertTrue(RegionId.matchesUrl(RegionId.of(PROJECT, REGION).getSelfLink())); assertFalse(RegionId.matchesUrl("notMatchingUrl")); } private void compareRegionId(RegionId expected, RegionId value) { assertEquals(expected, value); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.region(), expected.region()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getRegion(), expected.getRegion()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/RegionTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/RegionTest.java index 80e2fdc0b027..50c0fd1ce66d 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/RegionTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/RegionTest.java @@ -42,18 +42,30 @@ public class RegionTest { private static final DeprecationStatus DEPRECATION_STATUS = DeprecationStatus.of(DeprecationStatus.Status.DELETED, REGION_ID); private static final Region REGION = Region.builder() - .regionId(REGION_ID) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .status(STATUS) - .zones(ZONES) - .quotas(QUOTAS) - .deprecationStatus(DEPRECATION_STATUS) + .setRegionId(REGION_ID) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(STATUS) + .setZones(ZONES) + .setQuotas(QUOTAS) + .setDeprecationStatus(DEPRECATION_STATUS) .build(); @Test public void testBuilder() { + assertEquals(REGION_ID, REGION.getRegionId()); + assertEquals(GENERATED_ID, REGION.getGeneratedId()); + assertEquals(CREATION_TIMESTAMP, REGION.getCreationTimestamp()); + assertEquals(DESCRIPTION, REGION.getDescription()); + assertEquals(STATUS, REGION.getStatus()); + assertEquals(ZONES, REGION.getZones()); + assertEquals(QUOTAS, REGION.getQuotas()); + assertEquals(DEPRECATION_STATUS, REGION.getDeprecationStatus()); + } + + @Test + public void testBuilderDeprecated() { assertEquals(REGION_ID, REGION.regionId()); assertEquals(GENERATED_ID, REGION.generatedId()); assertEquals(CREATION_TIMESTAMP, REGION.creationTimestamp()); @@ -68,22 +80,22 @@ public void testBuilder() { public void testToAndFromPb() { Region region = Region.fromPb(REGION.toPb()); compareRegions(REGION, region); - assertEquals(REGION_ID.project(), region.regionId().project()); - assertEquals(REGION_ID.region(), region.regionId().region()); - region = Region.builder().regionId(REGION_ID).build(); + assertEquals(REGION_ID.getProject(), region.getRegionId().getProject()); + assertEquals(REGION_ID.getRegion(), region.getRegionId().getRegion()); + region = Region.builder().setRegionId(REGION_ID).build(); compareRegions(region, Region.fromPb(region.toPb())); } private void compareRegions(Region expected, Region value) { assertEquals(expected, value); - assertEquals(expected.regionId(), value.regionId()); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.status(), value.status()); - assertEquals(expected.zones(), value.zones()); - assertEquals(expected.quotas(), value.quotas()); - assertEquals(expected.deprecationStatus(), value.deprecationStatus()); + assertEquals(expected.getRegionId(), value.getRegionId()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getStatus(), value.getStatus()); + assertEquals(expected.getZones(), value.getZones()); + assertEquals(expected.getQuotas(), value.getQuotas()); + assertEquals(expected.getDeprecationStatus(), value.getDeprecationStatus()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/SchedulingOptionsTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/SchedulingOptionsTest.java index de2c66a5ff1e..52acaecdddd0 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/SchedulingOptionsTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/SchedulingOptionsTest.java @@ -28,6 +28,18 @@ public class SchedulingOptionsTest { @Test public void testFactoryMethods() { + assertTrue(SCHEDULING_OPTIONS.isPreemptible()); + assertFalse(SCHEDULING_OPTIONS.automaticRestart()); + assertEquals(SchedulingOptions.Maintenance.TERMINATE, SCHEDULING_OPTIONS.getMaintenance()); + SchedulingOptions schedulingOptions = + SchedulingOptions.standard(true, SchedulingOptions.Maintenance.MIGRATE); + assertFalse(schedulingOptions.isPreemptible()); + assertTrue(schedulingOptions.automaticRestart()); + assertEquals(SchedulingOptions.Maintenance.MIGRATE, schedulingOptions.getMaintenance()); + } + + @Test + public void testFactoryMethodsDeprecated() { assertTrue(SCHEDULING_OPTIONS.isPreemptible()); assertFalse(SCHEDULING_OPTIONS.automaticRestart()); assertEquals(SchedulingOptions.Maintenance.TERMINATE, SCHEDULING_OPTIONS.maintenance()); @@ -50,7 +62,7 @@ public void testToAndFromPb() { public void compareSchedulingOptions(SchedulingOptions expected, SchedulingOptions value) { assertEquals(expected, value); assertEquals(expected.isPreemptible(), value.isPreemptible()); - assertEquals(expected.maintenance(), value.maintenance()); + assertEquals(expected.getMaintenance(), value.getMaintenance()); assertEquals(expected.automaticRestart(), value.automaticRestart()); assertEquals(expected.hashCode(), value.hashCode()); } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/SerializationTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/SerializationTest.java index 0ef68731183d..ea3b7be1e1c9 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/SerializationTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/SerializationTest.java @@ -38,12 +38,12 @@ public class SerializationTest extends BaseSerializationTest { private static final String VALID_DISK_SIZE = "10GB-10TB"; private static final Long DEFAULT_DISK_SIZE_GB = 10L; private static final DiskTypeId DISK_TYPE_ID = DiskTypeId.of("project", "zone", "diskType"); - private static final DiskType DISK_TYPE = DiskType.builder() - .diskTypeId(DISK_TYPE_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .validDiskSize(VALID_DISK_SIZE) - .defaultDiskSizeGb(DEFAULT_DISK_SIZE_GB) + private static final DiskType DISK_TYPE = DiskType.newBuilder() + .setDiskTypeId(DISK_TYPE_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setValidDiskSize(VALID_DISK_SIZE) + .setDefaultDiskSizeGb(DEFAULT_DISK_SIZE_GB) .build(); private static final MachineTypeId MACHINE_TYPE_ID = MachineTypeId.of("project", "zone", "type"); private static final Integer GUEST_CPUS = 1; @@ -51,15 +51,15 @@ public class SerializationTest extends BaseSerializationTest { private static final List SCRATCH_DISKS = ImmutableList.of(3); private static final Integer MAXIMUM_PERSISTENT_DISKS = 4; private static final Long MAXIMUM_PERSISTENT_DISKS_SIZE_GB = 5L; - private static final MachineType MACHINE_TYPE = MachineType.builder() - .machineTypeId(MACHINE_TYPE_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .cpus(GUEST_CPUS) - .memoryMb(MEMORY_MB) - .scratchDisksSizeGb(SCRATCH_DISKS) - .maximumPersistentDisks(MAXIMUM_PERSISTENT_DISKS) - .maximumPersistentDisksSizeGb(MAXIMUM_PERSISTENT_DISKS_SIZE_GB) + private static final MachineType MACHINE_TYPE = MachineType.newBuilder() + .setMachineTypeId(MACHINE_TYPE_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setCpus(GUEST_CPUS) + .setMemoryMb(MEMORY_MB) + .setScratchDisksSizeGb(SCRATCH_DISKS) + .setMaximumPersistentDisks(MAXIMUM_PERSISTENT_DISKS) + .setMaximumPersistentDisksSizeGb(MAXIMUM_PERSISTENT_DISKS_SIZE_GB) .build(); private static final RegionId REGION_ID = RegionId.of("project", "region"); private static final Region.Status REGION_STATUS = Region.Status.DOWN; @@ -72,21 +72,21 @@ public class SerializationTest extends BaseSerializationTest { new Region.Quota("METRIC2", 4, 3); private static final List QUOTAS = ImmutableList.of(QUOTA1, QUOTA2); private static final Region REGION = Region.builder() - .regionId(REGION_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .status(REGION_STATUS) - .zones(ZONES) - .quotas(QUOTAS) + .setRegionId(REGION_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(REGION_STATUS) + .setZones(ZONES) + .setQuotas(QUOTAS) .build(); private static final ZoneId ZONE_ID = ZoneId.of("project", "zone"); private static final Zone.Status ZONE_STATUS = Zone.Status.DOWN; private static final Zone ZONE = Zone.builder() - .zoneId(ZONE_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .status(ZONE_STATUS) - .region(REGION_ID) + .setZoneId(ZONE_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(ZONE_STATUS) + .setRegion(REGION_ID) .build(); private static final DeprecationStatus DEPRECATION_STATUS = DeprecationStatus.of(DeprecationStatus.Status.DELETED, MACHINE_TYPE_ID); @@ -100,11 +100,11 @@ public class SerializationTest extends BaseSerializationTest { private static final RegionOperationId REGION_OPERATION_ID = RegionOperationId.of("project", "region", "op"); private static final Operation GLOBAL_OPERATION = - new Operation.Builder(COMPUTE).operationId(GLOBAL_OPERATION_ID).build(); + new Operation.Builder(COMPUTE).setOperationId(GLOBAL_OPERATION_ID).build(); private static final Operation ZONE_OPERATION = - new Operation.Builder(COMPUTE).operationId(ZONE_OPERATION_ID).build(); + new Operation.Builder(COMPUTE).setOperationId(ZONE_OPERATION_ID).build(); private static final Operation REGION_OPERATION = - new Operation.Builder(COMPUTE).operationId(REGION_OPERATION_ID).build(); + new Operation.Builder(COMPUTE).setOperationId(REGION_OPERATION_ID).build(); private static final InstanceId INSTANCE_ID = InstanceId.of("project", "zone", "instance"); private static final GlobalForwardingRuleId GLOBAL_FORWARDING_RULE_ID = GlobalForwardingRuleId.of("project", "rule"); @@ -119,10 +119,10 @@ public class SerializationTest extends BaseSerializationTest { new AddressInfo.GlobalForwardingUsage(ImmutableList.of(GLOBAL_FORWARDING_RULE_ID)); private static final AddressInfo.RegionForwardingUsage REGION_FORWARDING_USAGE = new AddressInfo.RegionForwardingUsage(ImmutableList.of(REGION_FORWARDING_RULE_ID)); - private static final AddressInfo ADDRESS_INFO = AddressInfo.builder(REGION_ADDRESS_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .usage(INSTANCE_USAGE) + private static final AddressInfo ADDRESS_INFO = AddressInfo.newBuilder(REGION_ADDRESS_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setUsage(INSTANCE_USAGE) .build(); private static final Address ADDRESS = new Address.Builder(COMPUTE, REGION_ADDRESS_ID).build(); private static final DiskId DISK_ID = DiskId.of("project", "zone", "disk"); @@ -163,8 +163,8 @@ public class SerializationTest extends BaseSerializationTest { private static final Network NETWORK = new Network.Builder(COMPUTE, NETWORK_ID, STANDARD_NETWORK_CONFIGURATION).build(); private static final AccessConfig ACCESS_CONFIG = AccessConfig.of("192.168.1.1"); - private static final NetworkInterface NETWORK_INTERFACE = NetworkInterface.builder(NETWORK_ID) - .accessConfigurations(ACCESS_CONFIG) + private static final NetworkInterface NETWORK_INTERFACE = NetworkInterface.newBuilder(NETWORK_ID) + .setAccessConfigurations(ACCESS_CONFIG) .build(); private static final CreateDiskConfiguration CREATE_DISK_CONFIGURATION = CreateDiskConfiguration.of(IMAGE_ID); diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/ServiceAccountTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/ServiceAccountTest.java index dd29589e5037..3634024718c3 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/ServiceAccountTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/ServiceAccountTest.java @@ -33,6 +33,12 @@ public void testOf() { compareServiceAccount(SERVICE_ACCOUNT, ServiceAccount.of("email", "scope1")); } + @Test + public void testOfDeprecated() { + assertEquals("email", SERVICE_ACCOUNT.email()); + assertEquals(ImmutableList.of("scope1"), SERVICE_ACCOUNT.scopes()); + } + @Test public void testToAndFromPb() { compareServiceAccount(SERVICE_ACCOUNT, ServiceAccount.fromPb(SERVICE_ACCOUNT.toPb())); @@ -40,8 +46,8 @@ public void testToAndFromPb() { public void compareServiceAccount(ServiceAccount expected, ServiceAccount value) { assertEquals(expected, value); - assertEquals(expected.email(), value.email()); - assertEquals(expected.scopes(), value.scopes()); + assertEquals(expected.getEmail(), value.getEmail()); + assertEquals(expected.getScopes(), value.getScopes()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/SnapshotDiskConfigurationTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/SnapshotDiskConfigurationTest.java index 5f95891b3252..b397ba9625bd 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/SnapshotDiskConfigurationTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/SnapshotDiskConfigurationTest.java @@ -31,10 +31,16 @@ public class SnapshotDiskConfigurationTest { private static final SnapshotId SNAPSHOT = SnapshotId.of("project", "snapshot"); private static final String SNAPSHOT_ID = "snapshotId"; private static final SnapshotDiskConfiguration DISK_CONFIGURATION = + SnapshotDiskConfiguration.newBuilder(SNAPSHOT) + .setSizeGb(SIZE) + .setDiskType(DISK_TYPE) + .setSourceSnapshotId(SNAPSHOT_ID) + .build(); + private static final SnapshotDiskConfiguration DEPRECATED_DISK_CONFIGURATION = SnapshotDiskConfiguration.builder(SNAPSHOT) .sizeGb(SIZE) .diskType(DISK_TYPE) - .sourceSnapshotId(SNAPSHOT_ID) + .setSourceSnapshotId(SNAPSHOT_ID) .build(); @Test @@ -42,17 +48,17 @@ public void testToBuilder() { compareSnapshotDiskConfiguration(DISK_CONFIGURATION, DISK_CONFIGURATION.toBuilder().build()); SnapshotId newSnapshot = SnapshotId.of("newProject", "newSnapshot"); SnapshotDiskConfiguration diskConfiguration = DISK_CONFIGURATION.toBuilder() - .sizeGb(24L) - .sourceSnapshot(newSnapshot) - .sourceSnapshotId("newSnapshotId") + .setSizeGb(24L) + .setSourceSnapshot(newSnapshot) + .setSourceSnapshotId("newSnapshotId") .build(); - assertEquals(24L, diskConfiguration.sizeGb().longValue()); - assertEquals(newSnapshot, diskConfiguration.sourceSnapshot()); - assertEquals("newSnapshotId", diskConfiguration.sourceSnapshotId()); + assertEquals(24L, diskConfiguration.getSizeGb().longValue()); + assertEquals(newSnapshot, diskConfiguration.getSourceSnapshot()); + assertEquals("newSnapshotId", diskConfiguration.getSourceSnapshotId()); diskConfiguration = diskConfiguration.toBuilder() - .sizeGb(SIZE) - .sourceSnapshot(SNAPSHOT) - .sourceSnapshotId(SNAPSHOT_ID) + .setSizeGb(SIZE) + .setSourceSnapshot(SNAPSHOT) + .setSourceSnapshotId(SNAPSHOT_ID) .build(); compareSnapshotDiskConfiguration(DISK_CONFIGURATION, diskConfiguration); } @@ -65,11 +71,20 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { - assertEquals(DISK_TYPE, DISK_CONFIGURATION.diskType()); - assertEquals(SIZE, DISK_CONFIGURATION.sizeGb()); - assertEquals(SNAPSHOT, DISK_CONFIGURATION.sourceSnapshot()); - assertEquals(SNAPSHOT_ID, DISK_CONFIGURATION.sourceSnapshotId()); - assertEquals(Type.SNAPSHOT, DISK_CONFIGURATION.type()); + assertEquals(DISK_TYPE, DISK_CONFIGURATION.getDiskType()); + assertEquals(SIZE, DISK_CONFIGURATION.getSizeGb()); + assertEquals(SNAPSHOT, DISK_CONFIGURATION.getSourceSnapshot()); + assertEquals(SNAPSHOT_ID, DISK_CONFIGURATION.getSourceSnapshotId()); + assertEquals(Type.SNAPSHOT, DISK_CONFIGURATION.getType()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(DISK_TYPE, DEPRECATED_DISK_CONFIGURATION.diskType()); + assertEquals(SIZE, DEPRECATED_DISK_CONFIGURATION.sizeGb()); + assertEquals(SNAPSHOT, DEPRECATED_DISK_CONFIGURATION.sourceSnapshot()); + assertEquals(SNAPSHOT_ID, DEPRECATED_DISK_CONFIGURATION.sourceSnapshotId()); + assertEquals(Type.SNAPSHOT, DEPRECATED_DISK_CONFIGURATION.type()); } @Test @@ -83,18 +98,18 @@ public void testToAndFromPb() { @Test public void testOf() { SnapshotDiskConfiguration configuration = SnapshotDiskConfiguration.of(SNAPSHOT); - assertNull(configuration.diskType()); - assertNull(configuration.sizeGb()); - assertNull(configuration.sourceSnapshotId()); - assertEquals(SNAPSHOT, configuration.sourceSnapshot()); - assertEquals(Type.SNAPSHOT, configuration.type()); + assertNull(configuration.getDiskType()); + assertNull(configuration.getSizeGb()); + assertNull(configuration.getSourceSnapshotId()); + assertEquals(SNAPSHOT, configuration.getSourceSnapshot()); + assertEquals(Type.SNAPSHOT, configuration.getType()); } @Test public void testSetProjectId() { SnapshotDiskConfiguration configuration = DISK_CONFIGURATION.toBuilder() - .diskType(DiskTypeId.of(DISK_TYPE.zone(), DISK_TYPE.type())) - .sourceSnapshot(SnapshotId.of(SNAPSHOT.snapshot())) + .setDiskType(DiskTypeId.of(DISK_TYPE.getZone(), DISK_TYPE.getType())) + .setSourceSnapshot(SnapshotId.of(SNAPSHOT.getSnapshot())) .build(); compareSnapshotDiskConfiguration(DISK_CONFIGURATION, configuration.setProjectId("project")); } @@ -102,11 +117,11 @@ public void testSetProjectId() { private void compareSnapshotDiskConfiguration(SnapshotDiskConfiguration expected, SnapshotDiskConfiguration value) { assertEquals(expected, value); - assertEquals(expected.diskType(), value.diskType()); - assertEquals(expected.sizeGb(), value.sizeGb()); - assertEquals(expected.sourceSnapshot(), value.sourceSnapshot()); - assertEquals(expected.sourceSnapshotId(), value.sourceSnapshotId()); - assertEquals(expected.type(), value.type()); + assertEquals(expected.getDiskType(), value.getDiskType()); + assertEquals(expected.getSizeGb(), value.getSizeGb()); + assertEquals(expected.getSourceSnapshot(), value.getSourceSnapshot()); + assertEquals(expected.getSourceSnapshotId(), value.getSourceSnapshotId()); + assertEquals(expected.getType(), value.getType()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/SnapshotIdTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/SnapshotIdTest.java index b723832dbbac..fbeff0650c62 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/SnapshotIdTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/SnapshotIdTest.java @@ -38,6 +38,17 @@ public class SnapshotIdTest { @Test public void testOf() { + SnapshotId snapshotId = SnapshotId.of(PROJECT, NAME); + assertEquals(PROJECT, snapshotId.getProject()); + assertEquals(NAME, snapshotId.getSnapshot()); + assertEquals(URL, snapshotId.getSelfLink()); + snapshotId = SnapshotId.of(NAME); + assertNull(snapshotId.getProject()); + assertEquals(NAME, snapshotId.getSnapshot()); + } + + @Test + public void testOfDeprecated() { SnapshotId snapshotId = SnapshotId.of(PROJECT, NAME); assertEquals(PROJECT, snapshotId.project()); assertEquals(NAME, snapshotId.snapshot()); @@ -50,7 +61,7 @@ public void testOf() { @Test public void testToAndFromUrl() { SnapshotId snapshotId = SnapshotId.of(PROJECT, NAME); - compareSnapshotId(snapshotId, SnapshotId.fromUrl(snapshotId.selfLink())); + compareSnapshotId(snapshotId, SnapshotId.fromUrl(snapshotId.getSelfLink())); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("notMatchingUrl is not a valid snapshot URL"); SnapshotId.fromUrl("notMatchingUrl"); @@ -65,15 +76,15 @@ public void testSetProjectId() { @Test public void testMatchesUrl() { - assertTrue(SnapshotId.matchesUrl(SnapshotId.of(PROJECT, NAME).selfLink())); + assertTrue(SnapshotId.matchesUrl(SnapshotId.of(PROJECT, NAME).getSelfLink())); assertFalse(SnapshotId.matchesUrl("notMatchingUrl")); } private void compareSnapshotId(SnapshotId expected, SnapshotId value) { assertEquals(expected, value); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.snapshot(), expected.snapshot()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getSnapshot(), expected.getSnapshot()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/SnapshotInfoTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/SnapshotInfoTest.java index 38d295184ae6..9eff5b7a8141 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/SnapshotInfoTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/SnapshotInfoTest.java @@ -41,24 +41,37 @@ public class SnapshotInfoTest { private static final String SOURCE_DISK_ID = "diskId"; private static final Long STORAGE_BYTES = 24L; private static final StorageBytesStatus STORAGE_BYTES_STATUS = StorageBytesStatus.UP_TO_DATE; - private static final SnapshotInfo SNAPSHOT_INFO = SnapshotInfo.builder(SNAPSHOT_ID, SOURCE_DISK) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .status(STATUS) - .diskSizeGb(DISK_SIZE_GB) - .licenses(LICENSES) - .sourceDiskId(SOURCE_DISK_ID) - .storageBytes(STORAGE_BYTES) - .storageBytesStatus(STORAGE_BYTES_STATUS) - .build(); + private static final SnapshotInfo SNAPSHOT_INFO = + SnapshotInfo.newBuilder(SNAPSHOT_ID, SOURCE_DISK) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(STATUS) + .setDiskSizeGb(DISK_SIZE_GB) + .setLicenses(LICENSES) + .setSourceDiskId(SOURCE_DISK_ID) + .setStorageBytes(STORAGE_BYTES) + .setStorageBytesStatus(STORAGE_BYTES_STATUS) + .build(); + private static final SnapshotInfo DEPRECATED_SNAPSHOT_INFO = + SnapshotInfo.builder(SNAPSHOT_ID, SOURCE_DISK) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .description(DESCRIPTION) + .setStatus(STATUS) + .setDiskSizeGb(DISK_SIZE_GB) + .setLicenses(LICENSES) + .setSourceDiskId(SOURCE_DISK_ID) + .setStorageBytes(STORAGE_BYTES) + .setStorageBytesStatus(STORAGE_BYTES_STATUS) + .build(); @Test public void testToBuilder() { compareSnapshotInfo(SNAPSHOT_INFO, SNAPSHOT_INFO.toBuilder().build()); - SnapshotInfo snapshotInfo = SNAPSHOT_INFO.toBuilder().description("newDescription").build(); - assertEquals("newDescription", snapshotInfo.description()); - snapshotInfo = snapshotInfo.toBuilder().description("description").build(); + SnapshotInfo snapshotInfo = SNAPSHOT_INFO.toBuilder().setDescription("newDescription").build(); + assertEquals("newDescription", snapshotInfo.getDescription()); + snapshotInfo = snapshotInfo.toBuilder().setDescription("description").build(); compareSnapshotInfo(SNAPSHOT_INFO, snapshotInfo); } @@ -70,33 +83,48 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { - assertEquals(GENERATED_ID, SNAPSHOT_INFO.generatedId()); - assertEquals(SNAPSHOT_ID, SNAPSHOT_INFO.snapshotId()); - assertEquals(CREATION_TIMESTAMP, SNAPSHOT_INFO.creationTimestamp()); - assertEquals(DESCRIPTION, SNAPSHOT_INFO.description()); - assertEquals(STATUS, SNAPSHOT_INFO.status()); - assertEquals(DISK_SIZE_GB, SNAPSHOT_INFO.diskSizeGb()); - assertEquals(LICENSES, SNAPSHOT_INFO.licenses()); - assertEquals(SOURCE_DISK, SNAPSHOT_INFO.sourceDisk()); - assertEquals(SOURCE_DISK_ID, SNAPSHOT_INFO.sourceDiskId()); - assertEquals(STORAGE_BYTES, SNAPSHOT_INFO.storageBytes()); - assertEquals(STORAGE_BYTES_STATUS, SNAPSHOT_INFO.storageBytesStatus()); + assertEquals(GENERATED_ID, SNAPSHOT_INFO.getGeneratedId()); + assertEquals(SNAPSHOT_ID, SNAPSHOT_INFO.getSnapshotId()); + assertEquals(CREATION_TIMESTAMP, SNAPSHOT_INFO.getCreationTimestamp()); + assertEquals(DESCRIPTION, SNAPSHOT_INFO.getDescription()); + assertEquals(STATUS, SNAPSHOT_INFO.getStatus()); + assertEquals(DISK_SIZE_GB, SNAPSHOT_INFO.getDiskSizeGb()); + assertEquals(LICENSES, SNAPSHOT_INFO.getLicenses()); + assertEquals(SOURCE_DISK, SNAPSHOT_INFO.getSourceDisk()); + assertEquals(SOURCE_DISK_ID, SNAPSHOT_INFO.getSourceDiskId()); + assertEquals(STORAGE_BYTES, SNAPSHOT_INFO.getStorageBytes()); + assertEquals(STORAGE_BYTES_STATUS, SNAPSHOT_INFO.getStorageBytesStatus()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(GENERATED_ID, DEPRECATED_SNAPSHOT_INFO.generatedId()); + assertEquals(SNAPSHOT_ID, DEPRECATED_SNAPSHOT_INFO.snapshotId()); + assertEquals(CREATION_TIMESTAMP, DEPRECATED_SNAPSHOT_INFO.creationTimestamp()); + assertEquals(DESCRIPTION, DEPRECATED_SNAPSHOT_INFO.description()); + assertEquals(STATUS, DEPRECATED_SNAPSHOT_INFO.status()); + assertEquals(DISK_SIZE_GB, DEPRECATED_SNAPSHOT_INFO.diskSizeGb()); + assertEquals(LICENSES, DEPRECATED_SNAPSHOT_INFO.licenses()); + assertEquals(SOURCE_DISK, DEPRECATED_SNAPSHOT_INFO.sourceDisk()); + assertEquals(SOURCE_DISK_ID, DEPRECATED_SNAPSHOT_INFO.sourceDiskId()); + assertEquals(STORAGE_BYTES, DEPRECATED_SNAPSHOT_INFO.storageBytes()); + assertEquals(STORAGE_BYTES_STATUS, DEPRECATED_SNAPSHOT_INFO.storageBytesStatus()); } @Test public void testOf() { SnapshotInfo snapshotInfo = SnapshotInfo.of(SNAPSHOT_ID, SOURCE_DISK); - assertNull(snapshotInfo.generatedId()); - assertEquals(SNAPSHOT_ID, snapshotInfo.snapshotId()); - assertNull(snapshotInfo.creationTimestamp()); - assertNull(snapshotInfo.description()); - assertNull(snapshotInfo.status()); - assertNull(snapshotInfo.diskSizeGb()); - assertNull(snapshotInfo.licenses()); - assertEquals(SOURCE_DISK, snapshotInfo.sourceDisk()); - assertNull(snapshotInfo.sourceDiskId()); - assertNull(snapshotInfo.storageBytes()); - assertNull(snapshotInfo.storageBytesStatus()); + assertNull(snapshotInfo.getGeneratedId()); + assertEquals(SNAPSHOT_ID, snapshotInfo.getSnapshotId()); + assertNull(snapshotInfo.getCreationTimestamp()); + assertNull(snapshotInfo.getDescription()); + assertNull(snapshotInfo.getStatus()); + assertNull(snapshotInfo.getDiskSizeGb()); + assertNull(snapshotInfo.getLicenses()); + assertEquals(SOURCE_DISK, snapshotInfo.getSourceDisk()); + assertNull(snapshotInfo.getSourceDiskId()); + assertNull(snapshotInfo.getStorageBytes()); + assertNull(snapshotInfo.getStorageBytesStatus()); } @Test @@ -104,32 +132,32 @@ public void testToAndFromPb() { compareSnapshotInfo(SNAPSHOT_INFO, SnapshotInfo.fromPb(SNAPSHOT_INFO.toPb())); SnapshotInfo snapshotInfo = SnapshotInfo.of(SNAPSHOT_ID, SOURCE_DISK); compareSnapshotInfo(snapshotInfo, SnapshotInfo.fromPb(snapshotInfo.toPb())); - snapshotInfo = new SnapshotInfo.BuilderImpl().snapshotId(SNAPSHOT_ID).build(); + snapshotInfo = new SnapshotInfo.BuilderImpl().setSnapshotId(SNAPSHOT_ID).build(); compareSnapshotInfo(snapshotInfo, SnapshotInfo.fromPb(snapshotInfo.toPb())); } @Test public void testSetProjectId() { SnapshotInfo snapshotInfo = SNAPSHOT_INFO.toBuilder() - .snapshotId(SnapshotId.of("snapshot")) - .sourceDisk(DiskId.of("zone", "disk")) + .setSnapshotId(SnapshotId.of("snapshot")) + .setSourceDisk(DiskId.of("zone", "disk")) .build(); compareSnapshotInfo(SNAPSHOT_INFO, snapshotInfo.setProjectId("project")); } public void compareSnapshotInfo(SnapshotInfo expected, SnapshotInfo value) { assertEquals(expected, value); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.snapshotId(), value.snapshotId()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.status(), value.status()); - assertEquals(expected.diskSizeGb(), value.diskSizeGb()); - assertEquals(expected.licenses(), value.licenses()); - assertEquals(expected.sourceDisk(), value.sourceDisk()); - assertEquals(expected.sourceDiskId(), value.sourceDiskId()); - assertEquals(expected.storageBytes(), value.storageBytes()); - assertEquals(expected.storageBytesStatus(), value.storageBytesStatus()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getSnapshotId(), value.getSnapshotId()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getStatus(), value.getStatus()); + assertEquals(expected.getDiskSizeGb(), value.getDiskSizeGb()); + assertEquals(expected.getLicenses(), value.getLicenses()); + assertEquals(expected.getSourceDisk(), value.getSourceDisk()); + assertEquals(expected.getSourceDiskId(), value.getSourceDiskId()); + assertEquals(expected.getStorageBytes(), value.getStorageBytes()); + assertEquals(expected.getStorageBytesStatus(), value.getStorageBytesStatus()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/SnapshotTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/SnapshotTest.java index d74cdf988f8c..22620bba8df1 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/SnapshotTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/SnapshotTest.java @@ -59,30 +59,30 @@ private void initializeExpectedSnapshot(int optionsCalls) { expect(serviceMockReturnsOptions.options()).andReturn(mockOptions).times(optionsCalls); replay(serviceMockReturnsOptions); expectedSnapshot = new Snapshot.Builder(serviceMockReturnsOptions, SNAPSHOT_ID, SOURCE_DISK) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .status(STATUS) - .diskSizeGb(DISK_SIZE_GB) - .licenses(LICENSES) - .sourceDiskId(SOURCE_DISK_ID) - .storageBytes(STORAGE_BYTES) - .storageBytesStatus(STORAGE_BYTES_STATUS) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(STATUS) + .setDiskSizeGb(DISK_SIZE_GB) + .setLicenses(LICENSES) + .setSourceDiskId(SOURCE_DISK_ID) + .setStorageBytes(STORAGE_BYTES) + .setStorageBytesStatus(STORAGE_BYTES_STATUS) .build(); compute = createStrictMock(Compute.class); } private void initializeSnapshot() { snapshot = new Snapshot.Builder(compute, SNAPSHOT_ID, SOURCE_DISK) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .status(STATUS) - .diskSizeGb(DISK_SIZE_GB) - .licenses(LICENSES) - .sourceDiskId(SOURCE_DISK_ID) - .storageBytes(STORAGE_BYTES) - .storageBytesStatus(STORAGE_BYTES_STATUS) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(STATUS) + .setDiskSizeGb(DISK_SIZE_GB) + .setLicenses(LICENSES) + .setSourceDiskId(SOURCE_DISK_ID) + .setStorageBytes(STORAGE_BYTES) + .setStorageBytesStatus(STORAGE_BYTES_STATUS) .build(); } @@ -90,9 +90,9 @@ private void initializeSnapshot() { public void testToBuilder() { initializeExpectedSnapshot(8); compareSnapshot(expectedSnapshot, expectedSnapshot.toBuilder().build()); - Snapshot newSnapshot = expectedSnapshot.toBuilder().description("newDescription").build(); - assertEquals("newDescription", newSnapshot.description()); - newSnapshot = newSnapshot.toBuilder().description("description").build(); + Snapshot newSnapshot = expectedSnapshot.toBuilder().setDescription("newDescription").build(); + assertEquals("newDescription", newSnapshot.getDescription()); + newSnapshot = newSnapshot.toBuilder().setDescription("description").build(); compareSnapshot(expectedSnapshot, newSnapshot); } @@ -140,6 +140,41 @@ public void testBuilder() { assertSame(serviceMockReturnsOptions, snapshot.compute()); } + @Test + public void testBuilderDeprecated() { + initializeExpectedSnapshot(2); + assertEquals(GENERATED_ID, expectedSnapshot.getGeneratedId()); + assertEquals(SNAPSHOT_ID, expectedSnapshot.getSnapshotId()); + assertEquals(CREATION_TIMESTAMP, expectedSnapshot.getCreationTimestamp()); + assertEquals(DESCRIPTION, expectedSnapshot.getDescription()); + assertEquals(STATUS, expectedSnapshot.getStatus()); + assertEquals(DISK_SIZE_GB, expectedSnapshot.getDiskSizeGb()); + assertEquals(LICENSES, expectedSnapshot.getLicenses()); + assertEquals(SOURCE_DISK, expectedSnapshot.getSourceDisk()); + assertEquals(SOURCE_DISK_ID, expectedSnapshot.getSourceDiskId()); + assertEquals(STORAGE_BYTES, expectedSnapshot.getStorageBytes()); + assertEquals(STORAGE_BYTES_STATUS, expectedSnapshot.getStorageBytesStatus()); + assertSame(serviceMockReturnsOptions, expectedSnapshot.getCompute()); + SnapshotId otherSnapshotId = SnapshotId.of("otherSnapshot"); + DiskId otherSourceDisk = DiskId.of("zone", "otherDisk"); + Snapshot snapshot = new Snapshot.Builder(serviceMockReturnsOptions, SNAPSHOT_ID, SOURCE_DISK) + .setSnapshotId(otherSnapshotId) + .setSourceDisk(otherSourceDisk) + .build(); + assertNull(snapshot.getGeneratedId()); + assertEquals(otherSnapshotId, snapshot.getSnapshotId()); + assertNull(snapshot.getCreationTimestamp()); + assertNull(snapshot.getDescription()); + assertNull(snapshot.getStatus()); + assertNull(snapshot.getDiskSizeGb()); + assertNull(snapshot.getLicenses()); + assertEquals(otherSourceDisk, snapshot.getSourceDisk()); + assertNull(snapshot.getSourceDiskId()); + assertNull(snapshot.getStorageBytes()); + assertNull(snapshot.getStorageBytesStatus()); + assertSame(serviceMockReturnsOptions, snapshot.getCompute()); + } + @Test public void testToAndFromPb() { initializeExpectedSnapshot(8); @@ -155,7 +190,7 @@ public void testDeleteOperation() { initializeExpectedSnapshot(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(GlobalOperationId.of("project", "op")) + .setOperationId(GlobalOperationId.of("project", "op")) .build(); expect(compute.deleteSnapshot(SNAPSHOT_ID)).andReturn(operation); replay(compute); @@ -178,7 +213,7 @@ public void testExists_True() throws Exception { initializeExpectedSnapshot(1); Compute.SnapshotOption[] expectedOptions = {Compute.SnapshotOption.fields()}; expect(compute.options()).andReturn(mockOptions); - expect(compute.getSnapshot(SNAPSHOT_ID.snapshot(), expectedOptions)) + expect(compute.getSnapshot(SNAPSHOT_ID.getSnapshot(), expectedOptions)) .andReturn(expectedSnapshot); replay(compute); initializeSnapshot(); @@ -191,7 +226,7 @@ public void testExists_False() throws Exception { initializeExpectedSnapshot(1); Compute.SnapshotOption[] expectedOptions = {Compute.SnapshotOption.fields()}; expect(compute.options()).andReturn(mockOptions); - expect(compute.getSnapshot(SNAPSHOT_ID.snapshot(), expectedOptions)).andReturn(null); + expect(compute.getSnapshot(SNAPSHOT_ID.getSnapshot(), expectedOptions)).andReturn(null); replay(compute); initializeSnapshot(); assertFalse(snapshot.exists()); @@ -202,7 +237,7 @@ public void testExists_False() throws Exception { public void testReload() throws Exception { initializeExpectedSnapshot(3); expect(compute.options()).andReturn(mockOptions); - expect(compute.getSnapshot(SNAPSHOT_ID.snapshot())).andReturn(expectedSnapshot); + expect(compute.getSnapshot(SNAPSHOT_ID.getSnapshot())).andReturn(expectedSnapshot); replay(compute); initializeSnapshot(); Snapshot updatedSnapshot = snapshot.reload(); @@ -214,7 +249,7 @@ public void testReload() throws Exception { public void testReloadNull() throws Exception { initializeExpectedSnapshot(1); expect(compute.options()).andReturn(mockOptions); - expect(compute.getSnapshot(SNAPSHOT_ID.snapshot())).andReturn(null); + expect(compute.getSnapshot(SNAPSHOT_ID.getSnapshot())).andReturn(null); replay(compute); initializeSnapshot(); assertNull(snapshot.reload()); @@ -225,7 +260,7 @@ public void testReloadNull() throws Exception { public void testReloadWithOptions() throws Exception { initializeExpectedSnapshot(3); expect(compute.options()).andReturn(mockOptions); - expect(compute.getSnapshot(SNAPSHOT_ID.snapshot(), Compute.SnapshotOption.fields())) + expect(compute.getSnapshot(SNAPSHOT_ID.getSnapshot(), Compute.SnapshotOption.fields())) .andReturn(expectedSnapshot); replay(compute); initializeSnapshot(); @@ -236,18 +271,18 @@ public void testReloadWithOptions() throws Exception { public void compareSnapshot(Snapshot expected, Snapshot value) { assertEquals(expected, value); - assertEquals(expected.compute().options(), value.compute().options()); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.snapshotId(), value.snapshotId()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.status(), value.status()); - assertEquals(expected.diskSizeGb(), value.diskSizeGb()); - assertEquals(expected.licenses(), value.licenses()); - assertEquals(expected.sourceDisk(), value.sourceDisk()); - assertEquals(expected.sourceDiskId(), value.sourceDiskId()); - assertEquals(expected.storageBytes(), value.storageBytes()); - assertEquals(expected.storageBytesStatus(), value.storageBytesStatus()); + assertEquals(expected.getCompute().options(), value.getCompute().options()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getSnapshotId(), value.getSnapshotId()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getStatus(), value.getStatus()); + assertEquals(expected.getDiskSizeGb(), value.getDiskSizeGb()); + assertEquals(expected.getLicenses(), value.getLicenses()); + assertEquals(expected.getSourceDisk(), value.getSourceDisk()); + assertEquals(expected.getSourceDiskId(), value.getSourceDiskId()); + assertEquals(expected.getStorageBytes(), value.getStorageBytes()); + assertEquals(expected.getStorageBytesStatus(), value.getStorageBytesStatus()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/StandardDiskConfigurationTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/StandardDiskConfigurationTest.java index 3651eef2ad99..f0616e5d833d 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/StandardDiskConfigurationTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/StandardDiskConfigurationTest.java @@ -29,6 +29,11 @@ public class StandardDiskConfigurationTest { private static final Long SIZE = 42L; private static final DiskTypeId DISK_TYPE = DiskTypeId.of("project", "zone", "type"); private static final StandardDiskConfiguration DISK_CONFIGURATION = + StandardDiskConfiguration.newBuilder() + .setSizeGb(SIZE) + .setDiskType(DISK_TYPE) + .build(); + private static final StandardDiskConfiguration DEPRECATED_DISK_CONFIGURATION = StandardDiskConfiguration.builder() .sizeGb(SIZE) .diskType(DISK_TYPE) @@ -38,11 +43,11 @@ public class StandardDiskConfigurationTest { public void testToBuilder() { compareStandardDiskConfiguration(DISK_CONFIGURATION, DISK_CONFIGURATION.toBuilder().build()); StandardDiskConfiguration diskConfiguration = DISK_CONFIGURATION.toBuilder() - .sizeGb(24L) + .setSizeGb(24L) .build(); - assertEquals(24L, diskConfiguration.sizeGb().longValue()); + assertEquals(24L, diskConfiguration.getSizeGb().longValue()); diskConfiguration = diskConfiguration.toBuilder() - .sizeGb(SIZE) + .setSizeGb(SIZE) .build(); compareStandardDiskConfiguration(DISK_CONFIGURATION, diskConfiguration); } @@ -55,9 +60,16 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { - assertEquals(DISK_TYPE, DISK_CONFIGURATION.diskType()); - assertEquals(SIZE, DISK_CONFIGURATION.sizeGb()); - assertEquals(Type.STANDARD, DISK_CONFIGURATION.type()); + assertEquals(DISK_TYPE, DISK_CONFIGURATION.getDiskType()); + assertEquals(SIZE, DISK_CONFIGURATION.getSizeGb()); + assertEquals(Type.STANDARD, DISK_CONFIGURATION.getType()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(DISK_TYPE, DEPRECATED_DISK_CONFIGURATION.diskType()); + assertEquals(SIZE, DEPRECATED_DISK_CONFIGURATION.sizeGb()); + assertEquals(Type.STANDARD, DEPRECATED_DISK_CONFIGURATION.type()); } @Test @@ -71,23 +83,23 @@ public void testToAndFromPb() { @Test public void testOf() { StandardDiskConfiguration configuration = StandardDiskConfiguration.of(DISK_TYPE); - assertEquals(DISK_TYPE, configuration.diskType()); - assertNull(configuration.sizeGb()); - assertEquals(Type.STANDARD, configuration.type()); + assertEquals(DISK_TYPE, configuration.getDiskType()); + assertNull(configuration.getSizeGb()); + assertEquals(Type.STANDARD, configuration.getType()); configuration = StandardDiskConfiguration.of(DISK_TYPE, SIZE); - assertEquals(DISK_TYPE, configuration.diskType()); - assertEquals(SIZE, configuration.sizeGb()); - assertEquals(Type.STANDARD, configuration.type()); + assertEquals(DISK_TYPE, configuration.getDiskType()); + assertEquals(SIZE, configuration.getSizeGb()); + assertEquals(Type.STANDARD, configuration.getType()); configuration = StandardDiskConfiguration.of(SIZE); - assertNull(configuration.diskType()); - assertEquals(SIZE, configuration.sizeGb()); - assertEquals(Type.STANDARD, configuration.type()); + assertNull(configuration.getDiskType()); + assertEquals(SIZE, configuration.getSizeGb()); + assertEquals(Type.STANDARD, configuration.getType()); } @Test public void testSetProjectId() { StandardDiskConfiguration configuration = DISK_CONFIGURATION.toBuilder() - .diskType(DiskTypeId.of(DISK_TYPE.zone(), DISK_TYPE.type())) + .setDiskType(DiskTypeId.of(DISK_TYPE.getZone(), DISK_TYPE.getType())) .build(); compareStandardDiskConfiguration(DISK_CONFIGURATION, configuration.setProjectId("project")); } @@ -95,9 +107,9 @@ public void testSetProjectId() { private void compareStandardDiskConfiguration(StandardDiskConfiguration expected, StandardDiskConfiguration value) { assertEquals(expected, value); - assertEquals(expected.diskType(), value.diskType()); - assertEquals(expected.sizeGb(), value.sizeGb()); - assertEquals(expected.type(), value.type()); + assertEquals(expected.getDiskType(), value.getDiskType()); + assertEquals(expected.getSizeGb(), value.getSizeGb()); + assertEquals(expected.getType(), value.getType()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/StandardNetworkConfigurationTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/StandardNetworkConfigurationTest.java index 4949327415f0..1fa7954444f2 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/StandardNetworkConfigurationTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/StandardNetworkConfigurationTest.java @@ -33,6 +33,18 @@ public class StandardNetworkConfigurationTest { @Test public void testConstructor() { + assertEquals(Type.STANDARD, NETWORK_CONFIGURATION.getType()); + assertEquals(IP_RANGE, NETWORK_CONFIGURATION.getIpRange()); + assertEquals(GATEWAY_ADDRESS, NETWORK_CONFIGURATION.getGatewayAddress()); + StandardNetworkConfiguration networkConfiguration = + new StandardNetworkConfiguration(IP_RANGE, null); + assertEquals(Type.STANDARD, networkConfiguration.getType()); + assertEquals(IP_RANGE, networkConfiguration.getIpRange()); + assertNull(networkConfiguration.getGatewayAddress()); + } + + @Test + public void testConstructorDeprecated() { assertEquals(Type.STANDARD, NETWORK_CONFIGURATION.type()); assertEquals(IP_RANGE, NETWORK_CONFIGURATION.ipRange()); assertEquals(GATEWAY_ADDRESS, NETWORK_CONFIGURATION.gatewayAddress()); @@ -60,17 +72,17 @@ public void testToAndFromPb() { @Test public void testOf() { StandardNetworkConfiguration configuration = StandardNetworkConfiguration.of(IP_RANGE); - assertEquals(Type.STANDARD, configuration.type()); - assertEquals(IP_RANGE, configuration.ipRange()); - assertNull(configuration.gatewayAddress()); + assertEquals(Type.STANDARD, configuration.getType()); + assertEquals(IP_RANGE, configuration.getIpRange()); + assertNull(configuration.getGatewayAddress()); } 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.getIpRange(), value.getIpRange()); + assertEquals(expected.getGatewayAddress(), value.getGatewayAddress()); + assertEquals(expected.getType(), value.getType()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/StorageImageConfigurationTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/StorageImageConfigurationTest.java index 3ecd80c66097..5d819ae58562 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/StorageImageConfigurationTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/StorageImageConfigurationTest.java @@ -21,7 +21,6 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import org.junit.Assert; import org.junit.Test; public class StorageImageConfigurationTest { @@ -32,10 +31,17 @@ public class StorageImageConfigurationTest { private static final Long ARCHIVE_SIZE_BYTES = 42L; private static final String SHA1 = "sha1"; private static final StorageImageConfiguration CONFIGURATION = + StorageImageConfiguration.newBuilder(SOURCE) + .setSourceType(SOURCE_TYPE) + .setContainerType(CONTAINER_TYPE) + .setArchiveSizeBytes(ARCHIVE_SIZE_BYTES) + .setSha1(SHA1) + .build(); + private static final StorageImageConfiguration DEPRECATED_CONFIGURATION = StorageImageConfiguration.builder(SOURCE) - .sourceType(SOURCE_TYPE) + .setSourceType(SOURCE_TYPE) .containerType(CONTAINER_TYPE) - .archiveSizeBytes(ARCHIVE_SIZE_BYTES) + .setArchiveSizeBytes(ARCHIVE_SIZE_BYTES) .sha1(SHA1) .build(); @@ -43,9 +49,9 @@ public class StorageImageConfigurationTest { public void testToBuilder() { compareRawImageConfiguration(CONFIGURATION, CONFIGURATION.toBuilder().build()); String newSource = "newSource"; - StorageImageConfiguration configuration = CONFIGURATION.toBuilder().source(newSource).build(); - assertEquals(newSource, configuration.source()); - configuration = configuration.toBuilder().source(SOURCE).build(); + StorageImageConfiguration configuration = CONFIGURATION.toBuilder().setSource(newSource).build(); + assertEquals(newSource, configuration.getSource()); + configuration = configuration.toBuilder().setSource(SOURCE).build(); compareRawImageConfiguration(CONFIGURATION, configuration); } @@ -57,12 +63,22 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { - assertEquals(SOURCE_TYPE, CONFIGURATION.sourceType()); - assertEquals(SOURCE, CONFIGURATION.source()); - assertEquals(CONTAINER_TYPE, CONFIGURATION.containerType()); - assertEquals(ARCHIVE_SIZE_BYTES, CONFIGURATION.archiveSizeBytes()); - assertEquals(SHA1, CONFIGURATION.sha1()); - Assert.assertEquals(ImageConfiguration.Type.STORAGE, CONFIGURATION.type()); + assertEquals(SOURCE_TYPE, CONFIGURATION.getSourceType()); + assertEquals(SOURCE, CONFIGURATION.getSource()); + assertEquals(CONTAINER_TYPE, CONFIGURATION.getContainerType()); + assertEquals(ARCHIVE_SIZE_BYTES, CONFIGURATION.getArchiveSizeBytes()); + assertEquals(SHA1, CONFIGURATION.getSha1()); + assertEquals(ImageConfiguration.Type.STORAGE, CONFIGURATION.getType()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(SOURCE_TYPE, DEPRECATED_CONFIGURATION.sourceType()); + assertEquals(SOURCE, DEPRECATED_CONFIGURATION.source()); + assertEquals(CONTAINER_TYPE, DEPRECATED_CONFIGURATION.containerType()); + assertEquals(ARCHIVE_SIZE_BYTES, DEPRECATED_CONFIGURATION.archiveSizeBytes()); + assertEquals(SHA1, DEPRECATED_CONFIGURATION.sha1()); + assertEquals(ImageConfiguration.Type.STORAGE, DEPRECATED_CONFIGURATION.type()); } @Test @@ -78,12 +94,12 @@ public void testToAndFromPb() { @Test public void testOf() { StorageImageConfiguration configuration = StorageImageConfiguration.of(SOURCE); - Assert.assertEquals(ImageConfiguration.Type.STORAGE, configuration.type()); - assertNull(configuration.sourceType()); - assertEquals(SOURCE, configuration.source()); - assertNull(configuration.containerType()); - assertNull(configuration.archiveSizeBytes()); - assertNull(configuration.sha1()); + assertEquals(ImageConfiguration.Type.STORAGE, configuration.getType()); + assertNull(configuration.getSourceType()); + assertEquals(SOURCE, configuration.getSource()); + assertNull(configuration.getContainerType()); + assertNull(configuration.getArchiveSizeBytes()); + assertNull(configuration.getSha1()); } @Test @@ -94,12 +110,12 @@ public void testSetProjectId() { private void compareRawImageConfiguration(StorageImageConfiguration expected, StorageImageConfiguration value) { assertEquals(expected, value); - assertEquals(expected.type(), value.type()); - assertEquals(expected.source(), value.source()); - assertEquals(expected.sourceType(), value.sourceType()); - assertEquals(expected.containerType(), value.containerType()); - assertEquals(expected.archiveSizeBytes(), value.archiveSizeBytes()); - assertEquals(expected.sha1(), value.sha1()); + assertEquals(expected.getType(), value.getType()); + assertEquals(expected.getSource(), value.getSource()); + assertEquals(expected.getSourceType(), value.getSourceType()); + assertEquals(expected.getContainerType(), value.getContainerType()); + assertEquals(expected.getArchiveSizeBytes(), value.getArchiveSizeBytes()); + assertEquals(expected.getSha1(), value.getSha1()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/SubnetNetworkConfigurationTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/SubnetNetworkConfigurationTest.java index 5fbec3e99c93..6b88317c4273 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/SubnetNetworkConfigurationTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/SubnetNetworkConfigurationTest.java @@ -22,7 +22,6 @@ import com.google.common.collect.ImmutableList; -import org.junit.Assert; import org.junit.Test; import java.util.List; @@ -39,12 +38,25 @@ public class SubnetNetworkConfigurationTest { @Test public void testConstructor() { assertEquals(AUTO_CREATE_SUBNETWORKS, NETWORK_CONFIGURATION.autoCreateSubnetworks()); - Assert.assertEquals(NetworkConfiguration.Type.SUBNET, NETWORK_CONFIGURATION.type()); + assertEquals(NetworkConfiguration.Type.SUBNET, NETWORK_CONFIGURATION.getType()); + assertEquals(SUBNETWORKS, NETWORK_CONFIGURATION.getSubnetworks()); + assertEquals(NetworkConfiguration.Type.SUBNET, NETWORK_CONFIGURATION.getType()); + SubnetNetworkConfiguration networkConfiguration = + new SubnetNetworkConfiguration(AUTO_CREATE_SUBNETWORKS, null); + assertEquals(NetworkConfiguration.Type.SUBNET, networkConfiguration.getType()); + assertEquals(AUTO_CREATE_SUBNETWORKS, networkConfiguration.autoCreateSubnetworks()); + assertNull(networkConfiguration.getSubnetworks()); + } + + @Test + public void testConstructorDeprecated() { + assertEquals(AUTO_CREATE_SUBNETWORKS, NETWORK_CONFIGURATION.autoCreateSubnetworks()); + assertEquals(NetworkConfiguration.Type.SUBNET, NETWORK_CONFIGURATION.type()); assertEquals(SUBNETWORKS, NETWORK_CONFIGURATION.subnetworks()); - Assert.assertEquals(NetworkConfiguration.Type.SUBNET, NETWORK_CONFIGURATION.type()); + assertEquals(NetworkConfiguration.Type.SUBNET, NETWORK_CONFIGURATION.type()); SubnetNetworkConfiguration networkConfiguration = new SubnetNetworkConfiguration(AUTO_CREATE_SUBNETWORKS, null); - Assert.assertEquals(NetworkConfiguration.Type.SUBNET, networkConfiguration.type()); + assertEquals(NetworkConfiguration.Type.SUBNET, networkConfiguration.type()); assertEquals(AUTO_CREATE_SUBNETWORKS, networkConfiguration.autoCreateSubnetworks()); assertNull(networkConfiguration.subnetworks()); } @@ -68,16 +80,16 @@ public void testOf() { SubnetNetworkConfiguration configuration = SubnetNetworkConfiguration.of(AUTO_CREATE_SUBNETWORKS); assertEquals(AUTO_CREATE_SUBNETWORKS, configuration.autoCreateSubnetworks()); - assertNull(configuration.subnetworks()); - Assert.assertEquals(NetworkConfiguration.Type.SUBNET, configuration.type()); + assertNull(configuration.getSubnetworks()); + assertEquals(NetworkConfiguration.Type.SUBNET, configuration.getType()); } 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.getSubnetworks(), value.getSubnetworks()); + assertEquals(expected.getType(), value.getType()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/SubnetworkIdTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/SubnetworkIdTest.java index 972c0d5f1d13..0670e6d69604 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/SubnetworkIdTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/SubnetworkIdTest.java @@ -39,6 +39,23 @@ public class SubnetworkIdTest { @Test public void testOf() { + SubnetworkId subnetworkId = SubnetworkId.of(PROJECT, REGION, NAME); + assertEquals(PROJECT, subnetworkId.getProject()); + assertEquals(REGION, subnetworkId.getRegion()); + assertEquals(NAME, subnetworkId.getSubnetwork()); + assertEquals(URL, subnetworkId.getSelfLink()); + subnetworkId = SubnetworkId.of(REGION, NAME); + assertNull(subnetworkId.getProject()); + assertEquals(REGION, subnetworkId.getRegion()); + assertEquals(NAME, subnetworkId.getSubnetwork()); + subnetworkId = SubnetworkId.of(RegionId.of(PROJECT, REGION), NAME); + assertEquals(PROJECT, subnetworkId.getProject()); + assertEquals(REGION, subnetworkId.getRegion()); + assertEquals(NAME, subnetworkId.getSubnetwork()); + } + + @Test + public void testOfDeprecated() { SubnetworkId subnetworkId = SubnetworkId.of(PROJECT, REGION, NAME); assertEquals(PROJECT, subnetworkId.project()); assertEquals(REGION, subnetworkId.region()); @@ -57,7 +74,7 @@ public void testOf() { @Test public void testToAndFromUrl() { SubnetworkId subnetworkId = SubnetworkId.of(PROJECT, REGION, NAME); - compareSubnetworkId(subnetworkId, SubnetworkId.fromUrl(subnetworkId.selfLink())); + compareSubnetworkId(subnetworkId, SubnetworkId.fromUrl(subnetworkId.getSelfLink())); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("notMatchingUrl is not a valid subnetwork URL"); SubnetworkId.fromUrl("notMatchingUrl"); @@ -72,16 +89,16 @@ public void testSetProjectId() { @Test public void testMatchesUrl() { - assertTrue(SubnetworkId.matchesUrl(SubnetworkId.of(PROJECT, REGION, NAME).selfLink())); + assertTrue(SubnetworkId.matchesUrl(SubnetworkId.of(PROJECT, REGION, NAME).getSelfLink())); assertFalse(SubnetworkId.matchesUrl("notMatchingUrl")); } private void compareSubnetworkId(SubnetworkId expected, SubnetworkId value) { assertEquals(expected, value); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.region(), expected.region()); - assertEquals(expected.subnetwork(), expected.subnetwork()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getRegion(), expected.getRegion()); + assertEquals(expected.getSubnetwork(), expected.getSubnetwork()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/SubnetworkInfoTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/SubnetworkInfoTest.java index 17907ea2ac3a..04c92e4aa546 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/SubnetworkInfoTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/SubnetworkInfoTest.java @@ -32,20 +32,27 @@ public class SubnetworkInfoTest { private static final NetworkId NETWORK_ID = NetworkId.of("project", "network"); private static final String IP_RANGE = "192.168.0.0/16"; private static final SubnetworkInfo SUBNETWORK_INFO = + SubnetworkInfo.newBuilder(SUBNETWORK_ID, NETWORK_ID, IP_RANGE) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setGatewayAddress(GATEWAY_ADDRESS) + .build(); + private static final SubnetworkInfo DEPRECATED_SUBNETWORK_INFO = SubnetworkInfo.builder(SUBNETWORK_ID, NETWORK_ID, IP_RANGE) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) .description(DESCRIPTION) - .gatewayAddress(GATEWAY_ADDRESS) + .setGatewayAddress(GATEWAY_ADDRESS) .build(); @Test public void testToBuilder() { compareSubnetworkInfo(SUBNETWORK_INFO, SUBNETWORK_INFO.toBuilder().build()); SubnetworkInfo subnetworkInfo = - SUBNETWORK_INFO.toBuilder().description("newDescription").build(); - assertEquals("newDescription", subnetworkInfo.description()); - subnetworkInfo = subnetworkInfo.toBuilder().description("description").build(); + SUBNETWORK_INFO.toBuilder().setDescription("newDescription").build(); + assertEquals("newDescription", subnetworkInfo.getDescription()); + subnetworkInfo = subnetworkInfo.toBuilder().setDescription("description").build(); compareSubnetworkInfo(SUBNETWORK_INFO, subnetworkInfo); } @@ -57,25 +64,36 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { - assertEquals(GENERATED_ID, SUBNETWORK_INFO.generatedId()); - assertEquals(SUBNETWORK_ID, SUBNETWORK_INFO.subnetworkId()); - assertEquals(CREATION_TIMESTAMP, SUBNETWORK_INFO.creationTimestamp()); - assertEquals(DESCRIPTION, SUBNETWORK_INFO.description()); - assertEquals(GATEWAY_ADDRESS, SUBNETWORK_INFO.gatewayAddress()); - assertEquals(NETWORK_ID, SUBNETWORK_INFO.network()); - assertEquals(IP_RANGE, SUBNETWORK_INFO.ipRange()); + assertEquals(GENERATED_ID, SUBNETWORK_INFO.getGeneratedId()); + assertEquals(SUBNETWORK_ID, SUBNETWORK_INFO.getSubnetworkId()); + assertEquals(CREATION_TIMESTAMP, SUBNETWORK_INFO.getCreationTimestamp()); + assertEquals(DESCRIPTION, SUBNETWORK_INFO.getDescription()); + assertEquals(GATEWAY_ADDRESS, SUBNETWORK_INFO.getGatewayAddress()); + assertEquals(NETWORK_ID, SUBNETWORK_INFO.getNetwork()); + assertEquals(IP_RANGE, SUBNETWORK_INFO.getIpRange()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(GENERATED_ID, DEPRECATED_SUBNETWORK_INFO.generatedId()); + assertEquals(SUBNETWORK_ID, DEPRECATED_SUBNETWORK_INFO.subnetworkId()); + assertEquals(CREATION_TIMESTAMP, DEPRECATED_SUBNETWORK_INFO.creationTimestamp()); + assertEquals(DESCRIPTION, DEPRECATED_SUBNETWORK_INFO.description()); + assertEquals(GATEWAY_ADDRESS, DEPRECATED_SUBNETWORK_INFO.gatewayAddress()); + assertEquals(NETWORK_ID, DEPRECATED_SUBNETWORK_INFO.network()); + assertEquals(IP_RANGE, DEPRECATED_SUBNETWORK_INFO.ipRange()); } @Test public void testOf() { SubnetworkInfo subnetworkInfo = SubnetworkInfo.of(SUBNETWORK_ID, NETWORK_ID, IP_RANGE); - assertNull(subnetworkInfo.generatedId()); - assertEquals(SUBNETWORK_ID, subnetworkInfo.subnetworkId()); - assertNull(subnetworkInfo.creationTimestamp()); - assertNull(subnetworkInfo.description()); - assertNull(subnetworkInfo.gatewayAddress()); - assertEquals(NETWORK_ID, subnetworkInfo.network()); - assertEquals(IP_RANGE, subnetworkInfo.ipRange()); + assertNull(subnetworkInfo.getGeneratedId()); + assertEquals(SUBNETWORK_ID, subnetworkInfo.getSubnetworkId()); + assertNull(subnetworkInfo.getCreationTimestamp()); + assertNull(subnetworkInfo.getDescription()); + assertNull(subnetworkInfo.getGatewayAddress()); + assertEquals(NETWORK_ID, subnetworkInfo.getNetwork()); + assertEquals(IP_RANGE, subnetworkInfo.getIpRange()); } @Test @@ -88,21 +106,21 @@ public void testToAndFromPb() { @Test public void testSetProjectId() { SubnetworkInfo subnetworkInfo = SUBNETWORK_INFO.toBuilder() - .subnetworkId(SubnetworkId.of("region", "subnetwork")) - .network(NetworkId.of("network")) + .setSubnetworkId(SubnetworkId.of("region", "subnetwork")) + .setNetwork(NetworkId.of("network")) .build(); compareSubnetworkInfo(SUBNETWORK_INFO, subnetworkInfo.setProjectId("project")); } public void compareSubnetworkInfo(SubnetworkInfo expected, SubnetworkInfo value) { assertEquals(expected, value); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.subnetworkId(), value.subnetworkId()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.gatewayAddress(), value.gatewayAddress()); - assertEquals(expected.network(), value.network()); - assertEquals(expected.ipRange(), value.ipRange()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getSubnetworkId(), value.getSubnetworkId()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getGatewayAddress(), value.getGatewayAddress()); + assertEquals(expected.getNetwork(), value.getNetwork()); + assertEquals(expected.getIpRange(), value.getIpRange()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/SubnetworkTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/SubnetworkTest.java index 6a710738b935..cb52b74522eb 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/SubnetworkTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/SubnetworkTest.java @@ -50,10 +50,10 @@ private void initializeExpectedSubnetwork(int optionsCalls) { replay(serviceMockReturnsOptions); expectedSubnetwork = new Subnetwork.Builder(serviceMockReturnsOptions, SUBNETWORK_ID, NETWORK_ID, IP_RANGE) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) .description(DESCRIPTION) - .gatewayAddress(GATEWAY_ADDRESS) + .setGatewayAddress(GATEWAY_ADDRESS) .build(); compute = createStrictMock(Compute.class); } @@ -61,10 +61,10 @@ private void initializeExpectedSubnetwork(int optionsCalls) { private void initializeSubnetwork() { subnetwork = new Subnetwork.Builder(compute, SUBNETWORK_ID, NETWORK_ID, IP_RANGE) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) .description(DESCRIPTION) - .gatewayAddress(GATEWAY_ADDRESS) + .setGatewayAddress(GATEWAY_ADDRESS) .build(); } @@ -73,7 +73,7 @@ public void testToBuilder() { initializeExpectedSubnetwork(8); compareSubnetwork(expectedSubnetwork, expectedSubnetwork.toBuilder().build()); Subnetwork newSubnetwork = expectedSubnetwork.toBuilder().description("newDescription").build(); - assertEquals("newDescription", newSubnetwork.description()); + assertEquals("newDescription", newSubnetwork.getDescription()); newSubnetwork = newSubnetwork.toBuilder().description("description").build(); compareSubnetwork(expectedSubnetwork, newSubnetwork); } @@ -89,6 +89,19 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { + initializeExpectedSubnetwork(1); + assertEquals(GENERATED_ID, expectedSubnetwork.getGeneratedId()); + assertEquals(SUBNETWORK_ID, expectedSubnetwork.getSubnetworkId()); + assertEquals(CREATION_TIMESTAMP, expectedSubnetwork.getCreationTimestamp()); + assertEquals(DESCRIPTION, expectedSubnetwork.getDescription()); + assertEquals(GATEWAY_ADDRESS, expectedSubnetwork.getGatewayAddress()); + assertEquals(NETWORK_ID, expectedSubnetwork.getNetwork()); + assertEquals(IP_RANGE, expectedSubnetwork.getIpRange()); + assertSame(serviceMockReturnsOptions, expectedSubnetwork.getCompute()); + } + + @Test + public void testBuilderDeprecated() { initializeExpectedSubnetwork(1); assertEquals(GENERATED_ID, expectedSubnetwork.generatedId()); assertEquals(SUBNETWORK_ID, expectedSubnetwork.subnetworkId()); @@ -116,7 +129,7 @@ public void testDeleteOperation() { initializeExpectedSubnetwork(2); expect(compute.options()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) - .operationId(GlobalOperationId.of("project", "op")) + .setOperationId(GlobalOperationId.of("project", "op")) .build(); expect(compute.deleteSubnetwork(SUBNETWORK_ID)).andReturn(operation); replay(compute); @@ -197,14 +210,14 @@ public void testReloadWithOptions() throws Exception { public void compareSubnetwork(Subnetwork expected, Subnetwork value) { assertEquals(expected, value); - assertEquals(expected.compute().options(), value.compute().options()); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.subnetworkId(), value.subnetworkId()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.gatewayAddress(), value.gatewayAddress()); - assertEquals(expected.network(), value.network()); - assertEquals(expected.ipRange(), value.ipRange()); + assertEquals(expected.getCompute().options(), value.getCompute().options()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getSubnetworkId(), value.getSubnetworkId()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getGatewayAddress(), value.getGatewayAddress()); + assertEquals(expected.getNetwork(), value.getNetwork()); + assertEquals(expected.getIpRange(), value.getIpRange()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/TagsTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/TagsTest.java index f626a418fefd..d06433371fd8 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/TagsTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/TagsTest.java @@ -29,13 +29,26 @@ public class TagsTest { @Test public void testToBuilder() { - Tags tags = TAGS.toBuilder().values("tag1").build(); - assertEquals(ImmutableList.of("tag1"), tags.values()); - compareTags(TAGS, tags.toBuilder().values("tag1", "tag2").build()); + Tags tags = TAGS.toBuilder().setValues("tag1").build(); + assertEquals(ImmutableList.of("tag1"), tags.getValues()); + compareTags(TAGS, tags.toBuilder().setValues("tag1", "tag2").build()); } @Test public void testBuilder() { + Tags tags = Tags.newBuilder().setValues(ImmutableList.of("tag1", "tag2")).build(); + assertEquals(ImmutableList.of("tag1", "tag2"), tags.getValues()); + assertNull(tags.getFingerprint()); + tags = Tags.newBuilder().add("tag1").add("tag2").build(); + assertEquals(ImmutableList.of("tag1", "tag2"), tags.getValues()); + assertNull(tags.getFingerprint()); + tags = Tags.newBuilder().add("tag1").add("tag2").setFingerprint("fingerprint").build(); + assertEquals(ImmutableList.of("tag1", "tag2"), tags.getValues()); + assertEquals("fingerprint", tags.getFingerprint()); + } + + @Test + public void testBuilderDeprecated() { Tags tags = Tags.builder().values(ImmutableList.of("tag1", "tag2")).build(); assertEquals(ImmutableList.of("tag1", "tag2"), tags.values()); assertNull(tags.fingerprint()); @@ -56,14 +69,14 @@ public void testOf() { @Test public void testToAndFromPb() { compareTags(TAGS, Tags.fromPb(TAGS.toPb())); - Tags tags = Tags.builder().add("tag1").add("tag2").fingerprint("fingerprint").build(); + Tags tags = Tags.newBuilder().add("tag1").add("tag2").setFingerprint("fingerprint").build(); compareTags(tags, Tags.fromPb(tags.toPb())); } public void compareTags(Tags expected, Tags value) { assertEquals(expected, value); - assertEquals(expected.fingerprint(), value.fingerprint()); - assertEquals(expected.values(), value.values()); + assertEquals(expected.getFingerprint(), value.getFingerprint()); + assertEquals(expected.getValues(), value.getValues()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/ZoneIdTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/ZoneIdTest.java index 90bdc6de2bf3..7629a567cb83 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/ZoneIdTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/ZoneIdTest.java @@ -38,6 +38,17 @@ public class ZoneIdTest { @Test public void testOf() { + ZoneId zoneId = ZoneId.of(PROJECT, ZONE); + assertEquals(PROJECT, zoneId.getProject()); + assertEquals(ZONE, zoneId.getZone()); + assertEquals(URL, zoneId.getSelfLink()); + zoneId = ZoneId.of(ZONE); + assertNull(zoneId.getProject()); + assertEquals(ZONE, zoneId.getZone()); + } + + @Test + public void testOfDeprecated() { ZoneId zoneId = ZoneId.of(PROJECT, ZONE); assertEquals(PROJECT, zoneId.project()); assertEquals(ZONE, zoneId.zone()); @@ -50,7 +61,7 @@ public void testOf() { @Test public void testToAndFromUrl() { ZoneId zoneId = ZoneId.of(PROJECT, ZONE); - compareZoneId(zoneId, ZoneId.fromUrl(zoneId.selfLink())); + compareZoneId(zoneId, ZoneId.fromUrl(zoneId.getSelfLink())); } @Test @@ -65,15 +76,15 @@ public void testSetProjectId() { @Test public void testMatchesUrl() { - assertTrue(ZoneId.matchesUrl(ZoneId.of(PROJECT, ZONE).selfLink())); + assertTrue(ZoneId.matchesUrl(ZoneId.of(PROJECT, ZONE).getSelfLink())); assertFalse(ZoneId.matchesUrl("notMatchingUrl")); } private void compareZoneId(ZoneId expected, ZoneId value) { assertEquals(expected, value); - assertEquals(expected.project(), expected.project()); - assertEquals(expected.zone(), expected.zone()); - assertEquals(expected.selfLink(), expected.selfLink()); + assertEquals(expected.getProject(), expected.getProject()); + assertEquals(expected.getZone(), expected.getZone()); + assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/ZoneTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/ZoneTest.java index b03aabc5b34e..64f05049c74b 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/ZoneTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/ZoneTest.java @@ -31,17 +31,28 @@ public class ZoneTest { private static final DeprecationStatus DEPRECATION_STATUS = DeprecationStatus.of(DeprecationStatus.Status.DELETED, ZONE_ID); private static final Zone ZONE = Zone.builder() - .zoneId(ZONE_ID) - .generatedId(GENERATED_ID) - .creationTimestamp(CREATION_TIMESTAMP) - .description(DESCRIPTION) - .status(STATUS) - .deprecationStatus(DEPRECATION_STATUS) - .region(REGION_ID) + .setZoneId(ZONE_ID) + .setGeneratedId(GENERATED_ID) + .setCreationTimestamp(CREATION_TIMESTAMP) + .setDescription(DESCRIPTION) + .setStatus(STATUS) + .setDeprecationStatus(DEPRECATION_STATUS) + .setRegion(REGION_ID) .build(); @Test public void testBuilder() { + assertEquals(REGION_ID, ZONE.getRegion()); + assertEquals(GENERATED_ID, ZONE.getGeneratedId()); + assertEquals(CREATION_TIMESTAMP, ZONE.getCreationTimestamp()); + assertEquals(DESCRIPTION, ZONE.getDescription()); + assertEquals(STATUS, ZONE.getStatus()); + assertEquals(REGION_ID, ZONE.getRegion()); + assertEquals(DEPRECATION_STATUS, ZONE.getDeprecationStatus()); + } + + @Test + public void testBuilderDeprecated() { assertEquals(REGION_ID, ZONE.region()); assertEquals(GENERATED_ID, ZONE.generatedId()); assertEquals(CREATION_TIMESTAMP, ZONE.creationTimestamp()); @@ -54,24 +65,24 @@ public void testBuilder() { @Test public void testToAndFromPb() { com.google.api.services.compute.model.Zone zonePb = ZONE.toPb(); - assertEquals(REGION_ID.selfLink(), zonePb.getRegion()); + assertEquals(REGION_ID.getSelfLink(), zonePb.getRegion()); Zone zone = Zone.fromPb(zonePb); compareZones(ZONE, zone); - assertEquals(ZONE_ID.project(), zone.zoneId().project()); - assertEquals(ZONE_ID.zone(), zone.zoneId().zone()); - zone = Zone.builder().zoneId(ZONE_ID).build(); + assertEquals(ZONE_ID.getProject(), zone.getZoneId().getProject()); + assertEquals(ZONE_ID.getZone(), zone.getZoneId().getZone()); + zone = Zone.builder().setZoneId(ZONE_ID).build(); compareZones(zone, Zone.fromPb(zone.toPb())); } private void compareZones(Zone expected, Zone value) { assertEquals(expected, value); - assertEquals(expected.zoneId(), value.zoneId()); - assertEquals(expected.generatedId(), value.generatedId()); - assertEquals(expected.creationTimestamp(), value.creationTimestamp()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.status(), value.status()); - assertEquals(expected.region(), value.region()); - assertEquals(expected.deprecationStatus(), value.deprecationStatus()); + assertEquals(expected.getZoneId(), value.getZoneId()); + assertEquals(expected.getGeneratedId(), value.getGeneratedId()); + assertEquals(expected.getCreationTimestamp(), value.getCreationTimestamp()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getStatus(), value.getStatus()); + assertEquals(expected.getRegion(), value.getRegion()); + assertEquals(expected.getDeprecationStatus(), value.getDeprecationStatus()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/it/ITComputeTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/it/ITComputeTest.java index 5ee58c6bfda4..9f7d234cdccb 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/it/ITComputeTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/it/ITComputeTest.java @@ -78,7 +78,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; @@ -109,32 +108,32 @@ public class ITComputeTest { @BeforeClass public static void beforeClass() { RemoteComputeHelper computeHelper = RemoteComputeHelper.create(); - compute = computeHelper.options().service(); + compute = computeHelper.getOptions().service(); } @Test public void testGetDiskType() { DiskType diskType = compute.getDiskType(ZONE, DISK_TYPE); - // assertNotNull(diskType.generatedId()); - assertEquals(ZONE, diskType.diskTypeId().zone()); - assertEquals(DISK_TYPE, diskType.diskTypeId().type()); - assertNotNull(diskType.creationTimestamp()); - assertNotNull(diskType.description()); - assertNotNull(diskType.validDiskSize()); - assertNotNull(diskType.defaultDiskSizeGb()); + // assertNotNull(diskType.getGeneratedId()); + assertEquals(ZONE, diskType.getDiskTypeId().getZone()); + assertEquals(DISK_TYPE, diskType.getDiskTypeId().getType()); + assertNotNull(diskType.getCreationTimestamp()); + assertNotNull(diskType.getDescription()); + assertNotNull(diskType.getValidDiskSize()); + assertNotNull(diskType.getDefaultDiskSizeGb()); } @Test public void testGetDiskTypeWithSelectedFields() { DiskType diskType = compute.getDiskType(ZONE, DISK_TYPE, Compute.DiskTypeOption.fields(Compute.DiskTypeField.CREATION_TIMESTAMP)); - // assertNotNull(diskType.generatedId()); - assertEquals(ZONE, diskType.diskTypeId().zone()); - assertEquals(DISK_TYPE, diskType.diskTypeId().type()); - assertNotNull(diskType.creationTimestamp()); - assertNull(diskType.description()); - assertNull(diskType.validDiskSize()); - assertNull(diskType.defaultDiskSizeGb()); + // assertNotNull(diskType.getGeneratedId()); + assertEquals(ZONE, diskType.getDiskTypeId().getZone()); + assertEquals(DISK_TYPE, diskType.getDiskTypeId().getType()); + assertNotNull(diskType.getCreationTimestamp()); + assertNull(diskType.getDescription()); + assertNull(diskType.getValidDiskSize()); + assertNull(diskType.getDefaultDiskSizeGb()); } @Test @@ -144,13 +143,13 @@ public void testListDiskTypes() { assertTrue(diskTypeIterator.hasNext()); while (diskTypeIterator.hasNext()) { DiskType diskType = diskTypeIterator.next(); - // assertNotNull(diskType.generatedId()); - assertNotNull(diskType.diskTypeId()); - assertEquals(ZONE, diskType.diskTypeId().zone()); - assertNotNull(diskType.creationTimestamp()); - assertNotNull(diskType.description()); - assertNotNull(diskType.validDiskSize()); - assertNotNull(diskType.defaultDiskSizeGb()); + // assertNotNull(diskType.getGeneratedId()); + assertNotNull(diskType.getDiskTypeId()); + assertEquals(ZONE, diskType.getDiskTypeId().getZone()); + assertNotNull(diskType.getCreationTimestamp()); + assertNotNull(diskType.getDescription()); + assertNotNull(diskType.getValidDiskSize()); + assertNotNull(diskType.getDefaultDiskSizeGb()); } } @@ -162,13 +161,13 @@ public void testListDiskTypesWithSelectedFields() { assertTrue(diskTypeIterator.hasNext()); while (diskTypeIterator.hasNext()) { DiskType diskType = diskTypeIterator.next(); - assertNull(diskType.generatedId()); - assertNotNull(diskType.diskTypeId()); - assertEquals(ZONE, diskType.diskTypeId().zone()); - assertNotNull(diskType.creationTimestamp()); - assertNull(diskType.description()); - assertNull(diskType.validDiskSize()); - assertNull(diskType.defaultDiskSizeGb()); + assertNull(diskType.getGeneratedId()); + assertNotNull(diskType.getDiskTypeId()); + assertEquals(ZONE, diskType.getDiskTypeId().getZone()); + assertNotNull(diskType.getCreationTimestamp()); + assertNull(diskType.getDescription()); + assertNull(diskType.getValidDiskSize()); + assertNull(diskType.getDefaultDiskSizeGb()); } } @@ -181,13 +180,13 @@ public void testListDiskTypesWithFilter() { while (diskTypeIterator.hasNext()) { DiskType diskType = diskTypeIterator.next(); // todo(mziccard): uncomment or remove once #695 is closed - // assertNotNull(diskType.generatedId()); - assertNotNull(diskType.diskTypeId()); - assertEquals(ZONE, diskType.diskTypeId().zone()); - assertNotNull(diskType.creationTimestamp()); - assertNotNull(diskType.description()); - assertNotNull(diskType.validDiskSize()); - assertEquals(375, (long) diskType.defaultDiskSizeGb()); + // assertNotNull(diskType.getGeneratedId()); + assertNotNull(diskType.getDiskTypeId()); + assertEquals(ZONE, diskType.getDiskTypeId().getZone()); + assertNotNull(diskType.getCreationTimestamp()); + assertNotNull(diskType.getDescription()); + assertNotNull(diskType.getValidDiskSize()); + assertEquals(375, (long) diskType.getDefaultDiskSizeGb()); } } @@ -198,12 +197,12 @@ public void testAggregatedListDiskTypes() { assertTrue(diskTypeIterator.hasNext()); while (diskTypeIterator.hasNext()) { DiskType diskType = diskTypeIterator.next(); - // assertNotNull(diskType.generatedId()); - assertNotNull(diskType.diskTypeId()); - assertNotNull(diskType.creationTimestamp()); - assertNotNull(diskType.description()); - assertNotNull(diskType.validDiskSize()); - assertNotNull(diskType.defaultDiskSizeGb()); + // assertNotNull(diskType.getGeneratedId()); + assertNotNull(diskType.getDiskTypeId()); + assertNotNull(diskType.getCreationTimestamp()); + assertNotNull(diskType.getDescription()); + assertNotNull(diskType.getValidDiskSize()); + assertNotNull(diskType.getDefaultDiskSizeGb()); } } @@ -216,42 +215,42 @@ public void testAggregatedListDiskTypesWithFilter() { while (diskTypeIterator.hasNext()) { DiskType diskType = diskTypeIterator.next(); // todo(mziccard): uncomment or remove once #695 is closed - // assertNotNull(diskType.generatedId()); - assertNotNull(diskType.diskTypeId()); - assertNotNull(diskType.creationTimestamp()); - assertNotNull(diskType.description()); - assertNotNull(diskType.validDiskSize()); - assertNotEquals(375, (long) diskType.defaultDiskSizeGb()); + // assertNotNull(diskType.getGeneratedId()); + assertNotNull(diskType.getDiskTypeId()); + assertNotNull(diskType.getCreationTimestamp()); + assertNotNull(diskType.getDescription()); + assertNotNull(diskType.getValidDiskSize()); + assertNotEquals(375, (long) diskType.getDefaultDiskSizeGb()); } } @Test public void testGetMachineType() { MachineType machineType = compute.getMachineType(ZONE, MACHINE_TYPE); - assertEquals(ZONE, machineType.machineTypeId().zone()); - assertEquals(MACHINE_TYPE, machineType.machineTypeId().type()); - assertNotNull(machineType.generatedId()); - assertNotNull(machineType.creationTimestamp()); - assertNotNull(machineType.description()); - assertNotNull(machineType.cpus()); - assertNotNull(machineType.memoryMb()); - assertNotNull(machineType.maximumPersistentDisks()); - assertNotNull(machineType.maximumPersistentDisksSizeGb()); + assertEquals(ZONE, machineType.getMachineTypeId().getZone()); + assertEquals(MACHINE_TYPE, machineType.getMachineTypeId().getType()); + assertNotNull(machineType.getGeneratedId()); + assertNotNull(machineType.getCreationTimestamp()); + assertNotNull(machineType.getDescription()); + assertNotNull(machineType.getCpus()); + assertNotNull(machineType.getMemoryMb()); + assertNotNull(machineType.getMaximumPersistentDisks()); + assertNotNull(machineType.getMaximumPersistentDisksSizeGb()); } @Test public void testGetMachineTypeWithSelectedFields() { MachineType machineType = compute.getMachineType(ZONE, MACHINE_TYPE, Compute.MachineTypeOption.fields(Compute.MachineTypeField.ID)); - assertEquals(ZONE, machineType.machineTypeId().zone()); - assertEquals(MACHINE_TYPE, machineType.machineTypeId().type()); - assertNotNull(machineType.generatedId()); - assertNull(machineType.creationTimestamp()); - assertNull(machineType.description()); - assertNull(machineType.cpus()); - assertNull(machineType.memoryMb()); - assertNull(machineType.maximumPersistentDisks()); - assertNull(machineType.maximumPersistentDisksSizeGb()); + assertEquals(ZONE, machineType.getMachineTypeId().getZone()); + assertEquals(MACHINE_TYPE, machineType.getMachineTypeId().getType()); + assertNotNull(machineType.getGeneratedId()); + assertNull(machineType.getCreationTimestamp()); + assertNull(machineType.getDescription()); + assertNull(machineType.getCpus()); + assertNull(machineType.getMemoryMb()); + assertNull(machineType.getMaximumPersistentDisks()); + assertNull(machineType.getMaximumPersistentDisksSizeGb()); } @Test @@ -261,15 +260,15 @@ public void testListMachineTypes() { assertTrue(machineTypeIterator.hasNext()); while (machineTypeIterator.hasNext()) { MachineType machineType = machineTypeIterator.next(); - assertNotNull(machineType.machineTypeId()); - assertEquals(ZONE, machineType.machineTypeId().zone()); - assertNotNull(machineType.generatedId()); - assertNotNull(machineType.creationTimestamp()); - assertNotNull(machineType.description()); - assertNotNull(machineType.cpus()); - assertNotNull(machineType.memoryMb()); - assertNotNull(machineType.maximumPersistentDisks()); - assertNotNull(machineType.maximumPersistentDisksSizeGb()); + assertNotNull(machineType.getMachineTypeId()); + assertEquals(ZONE, machineType.getMachineTypeId().getZone()); + assertNotNull(machineType.getGeneratedId()); + assertNotNull(machineType.getCreationTimestamp()); + assertNotNull(machineType.getDescription()); + assertNotNull(machineType.getCpus()); + assertNotNull(machineType.getMemoryMb()); + assertNotNull(machineType.getMaximumPersistentDisks()); + assertNotNull(machineType.getMaximumPersistentDisksSizeGb()); } } @@ -281,15 +280,15 @@ public void testListMachineTypesWithSelectedFields() { assertTrue(machineTypeIterator.hasNext()); while (machineTypeIterator.hasNext()) { MachineType machineType = machineTypeIterator.next(); - assertNotNull(machineType.machineTypeId()); - assertEquals(ZONE, machineType.machineTypeId().zone()); - assertNull(machineType.generatedId()); - assertNotNull(machineType.creationTimestamp()); - assertNull(machineType.description()); - assertNull(machineType.cpus()); - assertNull(machineType.memoryMb()); - assertNull(machineType.maximumPersistentDisks()); - assertNull(machineType.maximumPersistentDisksSizeGb()); + assertNotNull(machineType.getMachineTypeId()); + assertEquals(ZONE, machineType.getMachineTypeId().getZone()); + assertNull(machineType.getGeneratedId()); + assertNotNull(machineType.getCreationTimestamp()); + assertNull(machineType.getDescription()); + assertNull(machineType.getCpus()); + assertNull(machineType.getMemoryMb()); + assertNull(machineType.getMaximumPersistentDisks()); + assertNull(machineType.getMaximumPersistentDisksSizeGb()); } } @@ -302,16 +301,16 @@ public void testListMachineTypesWithFilter() { assertTrue(machineTypeIterator.hasNext()); while (machineTypeIterator.hasNext()) { MachineType machineType = machineTypeIterator.next(); - assertNotNull(machineType.machineTypeId()); - assertEquals(ZONE, machineType.machineTypeId().zone()); - assertNotNull(machineType.generatedId()); - assertNotNull(machineType.creationTimestamp()); - assertNotNull(machineType.description()); - assertNotNull(machineType.cpus()); - assertEquals(2, (long) machineType.cpus()); - assertNotNull(machineType.memoryMb()); - assertNotNull(machineType.maximumPersistentDisks()); - assertNotNull(machineType.maximumPersistentDisksSizeGb()); + assertNotNull(machineType.getMachineTypeId()); + assertEquals(ZONE, machineType.getMachineTypeId().getZone()); + assertNotNull(machineType.getGeneratedId()); + assertNotNull(machineType.getCreationTimestamp()); + assertNotNull(machineType.getDescription()); + assertNotNull(machineType.getCpus()); + assertEquals(2, (long) machineType.getCpus()); + assertNotNull(machineType.getMemoryMb()); + assertNotNull(machineType.getMaximumPersistentDisks()); + assertNotNull(machineType.getMaximumPersistentDisksSizeGb()); } } @@ -322,14 +321,14 @@ public void testAggregatedListMachineTypes() { assertTrue(machineTypeIterator.hasNext()); while (machineTypeIterator.hasNext()) { MachineType machineType = machineTypeIterator.next(); - assertNotNull(machineType.machineTypeId()); - assertNotNull(machineType.generatedId()); - assertNotNull(machineType.creationTimestamp()); - assertNotNull(machineType.description()); - assertNotNull(machineType.cpus()); - assertNotNull(machineType.memoryMb()); - assertNotNull(machineType.maximumPersistentDisks()); - assertNotNull(machineType.maximumPersistentDisksSizeGb()); + assertNotNull(machineType.getMachineTypeId()); + assertNotNull(machineType.getGeneratedId()); + assertNotNull(machineType.getCreationTimestamp()); + assertNotNull(machineType.getDescription()); + assertNotNull(machineType.getCpus()); + assertNotNull(machineType.getMemoryMb()); + assertNotNull(machineType.getMaximumPersistentDisks()); + assertNotNull(machineType.getMaximumPersistentDisksSizeGb()); } } @@ -342,54 +341,54 @@ public void testAggregatedListMachineTypesWithFilter() { assertTrue(machineTypeIterator.hasNext()); while (machineTypeIterator.hasNext()) { MachineType machineType = machineTypeIterator.next(); - assertNotNull(machineType.machineTypeId()); - assertNotNull(machineType.generatedId()); - assertNotNull(machineType.creationTimestamp()); - assertNotNull(machineType.description()); - assertNotNull(machineType.cpus()); - assertNotEquals(2, (long) machineType.cpus()); - assertNotNull(machineType.memoryMb()); - assertNotNull(machineType.maximumPersistentDisks()); - assertNotNull(machineType.maximumPersistentDisksSizeGb()); + assertNotNull(machineType.getMachineTypeId()); + assertNotNull(machineType.getGeneratedId()); + assertNotNull(machineType.getCreationTimestamp()); + assertNotNull(machineType.getDescription()); + assertNotNull(machineType.getCpus()); + assertNotEquals(2, (long) machineType.getCpus()); + assertNotNull(machineType.getMemoryMb()); + assertNotNull(machineType.getMaximumPersistentDisks()); + assertNotNull(machineType.getMaximumPersistentDisksSizeGb()); } } @Test public void testGetLicense() { License license = compute.getLicense(LICENSE_ID); - assertEquals(LICENSE_ID, license.licenseId()); + assertEquals(LICENSE_ID, license.getLicenseId()); assertNotNull(license.chargesUseFee()); } @Test public void testGetLicenseWithSelectedFields() { License license = compute.getLicense(LICENSE_ID, Compute.LicenseOption.fields()); - assertEquals(LICENSE_ID, license.licenseId()); + assertEquals(LICENSE_ID, license.getLicenseId()); assertNull(license.chargesUseFee()); } @Test public void testGetRegion() { Region region = compute.getRegion(REGION); - assertEquals(REGION, region.regionId().region()); - assertNotNull(region.description()); - assertNotNull(region.creationTimestamp()); - assertNotNull(region.generatedId()); - assertNotNull(region.quotas()); - assertNotNull(region.status()); - assertNotNull(region.zones()); + assertEquals(REGION, region.getRegionId().getRegion()); + assertNotNull(region.getDescription()); + assertNotNull(region.getCreationTimestamp()); + assertNotNull(region.getGeneratedId()); + assertNotNull(region.getQuotas()); + assertNotNull(region.getStatus()); + assertNotNull(region.getZones()); } @Test public void testGetRegionWithSelectedFields() { Region region = compute.getRegion(REGION, Compute.RegionOption.fields(Compute.RegionField.ID)); - assertEquals(REGION, region.regionId().region()); - assertNotNull(region.generatedId()); - assertNull(region.description()); - assertNull(region.creationTimestamp()); - assertNull(region.quotas()); - assertNull(region.status()); - assertNull(region.zones()); + assertEquals(REGION, region.getRegionId().getRegion()); + assertNotNull(region.getGeneratedId()); + assertNull(region.getDescription()); + assertNull(region.getCreationTimestamp()); + assertNull(region.getQuotas()); + assertNull(region.getStatus()); + assertNull(region.getZones()); } @Test @@ -398,13 +397,13 @@ public void testListRegions() { Iterator regionIterator = regionPage.iterateAll(); while (regionIterator.hasNext()) { Region region = regionIterator.next(); - assertNotNull(region.regionId()); - assertNotNull(region.description()); - assertNotNull(region.creationTimestamp()); - assertNotNull(region.generatedId()); - assertNotNull(region.quotas()); - assertNotNull(region.status()); - assertNotNull(region.zones()); + assertNotNull(region.getRegionId()); + assertNotNull(region.getDescription()); + assertNotNull(region.getCreationTimestamp()); + assertNotNull(region.getGeneratedId()); + assertNotNull(region.getQuotas()); + assertNotNull(region.getStatus()); + assertNotNull(region.getZones()); } } @@ -415,13 +414,13 @@ public void testListRegionsWithSelectedFields() { Iterator regionIterator = regionPage.iterateAll(); while (regionIterator.hasNext()) { Region region = regionIterator.next(); - assertNotNull(region.regionId()); - assertNull(region.description()); - assertNull(region.creationTimestamp()); - assertNotNull(region.generatedId()); - assertNull(region.quotas()); - assertNull(region.status()); - assertNull(region.zones()); + assertNotNull(region.getRegionId()); + assertNull(region.getDescription()); + assertNull(region.getCreationTimestamp()); + assertNotNull(region.getGeneratedId()); + assertNull(region.getQuotas()); + assertNull(region.getStatus()); + assertNull(region.getZones()); } } @@ -430,30 +429,30 @@ public void testListRegionsWithFilter() { Page regionPage = compute.listRegions(Compute.RegionListOption.filter( Compute.RegionFilter.equals(Compute.RegionField.NAME, REGION))); Iterator regionIterator = regionPage.iterateAll(); - assertEquals(REGION, regionIterator.next().regionId().region()); + assertEquals(REGION, regionIterator.next().getRegionId().getRegion()); assertFalse(regionIterator.hasNext()); } @Test public void testGetZone() { Zone zone = compute.getZone(ZONE); - assertEquals(ZONE, zone.zoneId().zone()); - assertNotNull(zone.generatedId()); - assertNotNull(zone.creationTimestamp()); - assertNotNull(zone.description()); - assertNotNull(zone.status()); - assertNotNull(zone.region()); + assertEquals(ZONE, zone.getZoneId().getZone()); + assertNotNull(zone.getGeneratedId()); + assertNotNull(zone.getCreationTimestamp()); + assertNotNull(zone.getDescription()); + assertNotNull(zone.getStatus()); + assertNotNull(zone.getRegion()); } @Test public void testGetZoneWithSelectedFields() { Zone zone = compute.getZone(ZONE, Compute.ZoneOption.fields(Compute.ZoneField.ID)); - assertEquals(ZONE, zone.zoneId().zone()); - assertNotNull(zone.generatedId()); - assertNull(zone.creationTimestamp()); - assertNull(zone.description()); - assertNull(zone.status()); - assertNull(zone.region()); + assertEquals(ZONE, zone.getZoneId().getZone()); + assertNotNull(zone.getGeneratedId()); + assertNull(zone.getCreationTimestamp()); + assertNull(zone.getDescription()); + assertNull(zone.getStatus()); + assertNull(zone.getRegion()); } @Test @@ -462,12 +461,12 @@ public void testListZones() { Iterator zoneIterator = zonePage.iterateAll(); while (zoneIterator.hasNext()) { Zone zone = zoneIterator.next(); - assertNotNull(zone.zoneId()); - assertNotNull(zone.generatedId()); - assertNotNull(zone.creationTimestamp()); - assertNotNull(zone.description()); - assertNotNull(zone.status()); - assertNotNull(zone.region()); + assertNotNull(zone.getZoneId()); + assertNotNull(zone.getGeneratedId()); + assertNotNull(zone.getCreationTimestamp()); + assertNotNull(zone.getDescription()); + assertNotNull(zone.getStatus()); + assertNotNull(zone.getRegion()); } } @@ -478,12 +477,12 @@ public void testListZonesWithSelectedFields() { Iterator zoneIterator = zonePage.iterateAll(); while (zoneIterator.hasNext()) { Zone zone = zoneIterator.next(); - assertNotNull(zone.zoneId()); - assertNull(zone.generatedId()); - assertNotNull(zone.creationTimestamp()); - assertNull(zone.description()); - assertNull(zone.status()); - assertNull(zone.region()); + assertNotNull(zone.getZoneId()); + assertNull(zone.getGeneratedId()); + assertNotNull(zone.getCreationTimestamp()); + assertNull(zone.getDescription()); + assertNull(zone.getStatus()); + assertNull(zone.getRegion()); } } @@ -492,7 +491,7 @@ public void testListZonesWithFilter() { Page zonePage = compute.listZones( Compute.ZoneListOption.filter(Compute.ZoneFilter.equals(Compute.ZoneField.NAME, ZONE))); Iterator zoneIterator = zonePage.iterateAll(); - assertEquals(ZONE, zoneIterator.next().zoneId().zone()); + assertEquals(ZONE, zoneIterator.next().getZoneId().getZone()); assertFalse(zoneIterator.hasNext()); } @@ -502,13 +501,13 @@ public void testListGlobalOperations() { Iterator operationIterator = operationPage.iterateAll(); while (operationIterator.hasNext()) { Operation operation = operationIterator.next(); - assertNotNull(operation.generatedId()); - assertNotNull(operation.operationId()); + assertNotNull(operation.getGeneratedId()); + assertNotNull(operation.getOperationId()); // todo(mziccard): uncomment or remove once #727 is closed - // assertNotNull(operation.creationTimestamp()); - assertNotNull(operation.operationType()); - assertNotNull(operation.status()); - assertNotNull(operation.user()); + // assertNotNull(operation.getCreationTimestamp()); + assertNotNull(operation.getOperationType()); + assertNotNull(operation.getStatus()); + assertNotNull(operation.getUser()); } } @@ -519,22 +518,22 @@ public void testListGlobalOperationsWithSelectedFields() { Iterator operationIterator = operationPage.iterateAll(); while (operationIterator.hasNext()) { Operation operation = operationIterator.next(); - assertNotNull(operation.generatedId()); - assertNotNull(operation.operationId()); - assertNull(operation.operationType()); - assertNull(operation.targetLink()); - assertNull(operation.targetId()); - assertNull(operation.operationType()); - assertNull(operation.status()); - assertNull(operation.statusMessage()); - assertNull(operation.user()); - assertNull(operation.progress()); - assertNull(operation.description()); - assertNull(operation.insertTime()); - assertNull(operation.startTime()); - assertNull(operation.endTime()); - assertNull(operation.warnings()); - assertNull(operation.httpErrorMessage()); + assertNotNull(operation.getGeneratedId()); + assertNotNull(operation.getOperationId()); + assertNull(operation.getOperationType()); + assertNull(operation.getTargetLink()); + assertNull(operation.getTargetId()); + assertNull(operation.getOperationType()); + assertNull(operation.getStatus()); + assertNull(operation.getStatusMessage()); + assertNull(operation.getUser()); + assertNull(operation.getProgress()); + assertNull(operation.getDescription()); + assertNull(operation.getInsertTime()); + assertNull(operation.getStartTime()); + assertNull(operation.getEndTime()); + assertNull(operation.getWarnings()); + assertNull(operation.getHttpErrorMessage()); } } @@ -545,13 +544,13 @@ public void testListGlobalOperationsWithFilter() { Iterator operationIterator = operationPage.iterateAll(); while (operationIterator.hasNext()) { Operation operation = operationIterator.next(); - assertNotNull(operation.generatedId()); - assertNotNull(operation.operationId()); + assertNotNull(operation.getGeneratedId()); + assertNotNull(operation.getOperationId()); // todo(mziccard): uncomment or remove once #727 is closed - // assertNotNull(operation.creationTimestamp()); - assertNotNull(operation.operationType()); - assertEquals(Operation.Status.DONE, operation.status()); - assertNotNull(operation.user()); + // assertNotNull(operation.getCreationTimestamp()); + assertNotNull(operation.getOperationType()); + assertEquals(Operation.Status.DONE, operation.getStatus()); + assertNotNull(operation.getUser()); } } @@ -561,14 +560,14 @@ public void testListRegionOperations() { Iterator operationIterator = operationPage.iterateAll(); while (operationIterator.hasNext()) { Operation operation = operationIterator.next(); - assertNotNull(operation.generatedId()); - assertNotNull(operation.operationId()); - assertEquals(REGION, operation.operationId().region()); + assertNotNull(operation.getGeneratedId()); + assertNotNull(operation.getOperationId()); + assertEquals(REGION, operation.getOperationId().getRegion()); // todo(mziccard): uncomment or remove once #727 is closed - // assertNotNull(operation.creationTimestamp()); - assertNotNull(operation.operationType()); - assertNotNull(operation.status()); - assertNotNull(operation.user()); + // assertNotNull(operation.getCreationTimestamp()); + assertNotNull(operation.getOperationType()); + assertNotNull(operation.getStatus()); + assertNotNull(operation.getUser()); } } @@ -579,23 +578,23 @@ public void testListRegionOperationsWithSelectedFields() { Iterator operationIterator = operationPage.iterateAll(); while (operationIterator.hasNext()) { Operation operation = operationIterator.next(); - assertNotNull(operation.generatedId()); - assertNotNull(operation.operationId()); - assertEquals(REGION, operation.operationId().region()); - assertNull(operation.operationType()); - assertNull(operation.targetLink()); - assertNull(operation.targetId()); - assertNull(operation.operationType()); - assertNull(operation.status()); - assertNull(operation.statusMessage()); - assertNull(operation.user()); - assertNull(operation.progress()); - assertNull(operation.description()); - assertNull(operation.insertTime()); - assertNull(operation.startTime()); - assertNull(operation.endTime()); - assertNull(operation.warnings()); - assertNull(operation.httpErrorMessage()); + assertNotNull(operation.getGeneratedId()); + assertNotNull(operation.getOperationId()); + assertEquals(REGION, operation.getOperationId().getRegion()); + assertNull(operation.getOperationType()); + assertNull(operation.getTargetLink()); + assertNull(operation.getTargetId()); + assertNull(operation.getOperationType()); + assertNull(operation.getStatus()); + assertNull(operation.getStatusMessage()); + assertNull(operation.getUser()); + assertNull(operation.getProgress()); + assertNull(operation.getDescription()); + assertNull(operation.getInsertTime()); + assertNull(operation.getStartTime()); + assertNull(operation.getEndTime()); + assertNull(operation.getWarnings()); + assertNull(operation.getHttpErrorMessage()); } } @@ -607,14 +606,14 @@ public void testListRegionOperationsWithFilter() { Iterator operationIterator = operationPage.iterateAll(); while (operationIterator.hasNext()) { Operation operation = operationIterator.next(); - assertNotNull(operation.generatedId()); - assertNotNull(operation.operationId()); - assertEquals(REGION, operation.operationId().region()); + assertNotNull(operation.getGeneratedId()); + assertNotNull(operation.getOperationId()); + assertEquals(REGION, operation.getOperationId().getRegion()); // todo(mziccard): uncomment or remove once #727 is closed - // assertNotNull(operation.creationTimestamp()); - assertNotNull(operation.operationType()); - assertEquals(Operation.Status.DONE, operation.status()); - assertNotNull(operation.user()); + // assertNotNull(operation.getCreationTimestamp()); + assertNotNull(operation.getOperationType()); + assertEquals(Operation.Status.DONE, operation.getStatus()); + assertNotNull(operation.getUser()); } } @@ -624,14 +623,14 @@ public void testListZoneOperations() { Iterator operationIterator = operationPage.iterateAll(); while (operationIterator.hasNext()) { Operation operation = operationIterator.next(); - assertNotNull(operation.generatedId()); - assertNotNull(operation.operationId()); - Assert.assertEquals(ZONE, operation.operationId().zone()); + assertNotNull(operation.getGeneratedId()); + assertNotNull(operation.getOperationId()); + assertEquals(ZONE, operation.getOperationId().getZone()); // todo(mziccard): uncomment or remove once #727 is closed - // assertNotNull(operation.creationTimestamp()); - assertNotNull(operation.operationType()); - assertNotNull(operation.status()); - assertNotNull(operation.user()); + // assertNotNull(operation.getCreationTimestamp()); + assertNotNull(operation.getOperationType()); + assertNotNull(operation.getStatus()); + assertNotNull(operation.getUser()); } } @@ -642,23 +641,23 @@ public void testListZoneOperationsWithSelectedFields() { Iterator operationIterator = operationPage.iterateAll(); while (operationIterator.hasNext()) { Operation operation = operationIterator.next(); - assertNotNull(operation.generatedId()); - assertNotNull(operation.operationId()); - assertEquals(ZONE, operation.operationId().zone()); - assertNull(operation.operationType()); - assertNull(operation.targetLink()); - assertNull(operation.targetId()); - assertNull(operation.operationType()); - assertNull(operation.status()); - assertNull(operation.statusMessage()); - assertNull(operation.user()); - assertNull(operation.progress()); - assertNull(operation.description()); - assertNull(operation.insertTime()); - assertNull(operation.startTime()); - assertNull(operation.endTime()); - assertNull(operation.warnings()); - assertNull(operation.httpErrorMessage()); + assertNotNull(operation.getGeneratedId()); + assertNotNull(operation.getOperationId()); + assertEquals(ZONE, operation.getOperationId().getZone()); + assertNull(operation.getOperationType()); + assertNull(operation.getTargetLink()); + assertNull(operation.getTargetId()); + assertNull(operation.getOperationType()); + assertNull(operation.getStatus()); + assertNull(operation.getStatusMessage()); + assertNull(operation.getUser()); + assertNull(operation.getProgress()); + assertNull(operation.getDescription()); + assertNull(operation.getInsertTime()); + assertNull(operation.getStartTime()); + assertNull(operation.getEndTime()); + assertNull(operation.getWarnings()); + assertNull(operation.getHttpErrorMessage()); } } @@ -670,14 +669,14 @@ public void testListZoneOperationsWithFilter() { Iterator operationIterator = operationPage.iterateAll(); while (operationIterator.hasNext()) { Operation operation = operationIterator.next(); - assertNotNull(operation.generatedId()); - assertNotNull(operation.operationId()); - assertEquals(ZONE, operation.operationId().zone()); + assertNotNull(operation.getGeneratedId()); + assertNotNull(operation.getOperationId()); + assertEquals(ZONE, operation.getOperationId().getZone()); // todo(mziccard): uncomment or remove once #727 is closed - // assertNotNull(operation.creationTimestamp()); - assertNotNull(operation.operationType()); - assertEquals(Operation.Status.DONE, operation.status()); - assertNotNull(operation.user()); + // assertNotNull(operation.getCreationTimestamp()); + assertNotNull(operation.getOperationType()); + assertEquals(Operation.Status.DONE, operation.getStatus()); + assertNotNull(operation.getUser()); } } @@ -691,22 +690,22 @@ public void testCreateGetAndDeleteRegionAddress() throws InterruptedException, T // test get Address remoteAddress = compute.getAddress(addressId); assertNotNull(remoteAddress); - assertTrue(remoteAddress.addressId() instanceof RegionAddressId); - assertEquals(REGION, remoteAddress.addressId().region()); - assertEquals(addressId.address(), remoteAddress.addressId().address()); - assertNotNull(remoteAddress.address()); - assertNotNull(remoteAddress.creationTimestamp()); - assertNotNull(remoteAddress.generatedId()); - assertNotNull(remoteAddress.status()); + assertTrue(remoteAddress.getAddressId() instanceof RegionAddressId); + assertEquals(REGION, remoteAddress.getAddressId().getRegion()); + assertEquals(addressId.getAddress(), remoteAddress.getAddressId().getAddress()); + assertNotNull(remoteAddress.getAddress()); + assertNotNull(remoteAddress.getCreationTimestamp()); + assertNotNull(remoteAddress.getGeneratedId()); + assertNotNull(remoteAddress.getStatus()); // test get with selected fields remoteAddress = compute.getAddress(addressId, Compute.AddressOption.fields()); assertNotNull(remoteAddress); - assertTrue(remoteAddress.addressId() instanceof RegionAddressId); - assertEquals(REGION, remoteAddress.addressId().region()); - assertEquals(addressId.address(), remoteAddress.addressId().address()); - assertNull(remoteAddress.address()); - assertNull(remoteAddress.creationTimestamp()); - assertNull(remoteAddress.generatedId()); + assertTrue(remoteAddress.getAddressId() instanceof RegionAddressId); + assertEquals(REGION, remoteAddress.getAddressId().getRegion()); + assertEquals(addressId.getAddress(), remoteAddress.getAddressId().getAddress()); + assertNull(remoteAddress.getAddress()); + assertNull(remoteAddress.getCreationTimestamp()); + assertNull(remoteAddress.getGeneratedId()); operation = remoteAddress.delete(); operation.waitFor(); assertNull(compute.getAddress(addressId)); @@ -732,13 +731,13 @@ public void testListRegionAddresses() throws InterruptedException, TimeoutExcept int count = 0; while (addressIterator.hasNext()) { Address address = addressIterator.next(); - assertNotNull(address.addressId()); - assertTrue(address.addressId() instanceof RegionAddressId); - assertEquals(REGION, address.addressId().region()); - assertTrue(addressSet.contains(address.addressId().address())); - assertNotNull(address.address()); - assertNotNull(address.creationTimestamp()); - assertNotNull(address.generatedId()); + assertNotNull(address.getAddressId()); + assertTrue(address.getAddressId() instanceof RegionAddressId); + assertEquals(REGION, address.getAddressId().getRegion()); + assertTrue(addressSet.contains(address.getAddressId().getAddress())); + assertNotNull(address.getAddress()); + assertNotNull(address.getCreationTimestamp()); + assertNotNull(address.getGeneratedId()); count++; } assertEquals(2, count); @@ -749,14 +748,14 @@ public void testListRegionAddresses() throws InterruptedException, TimeoutExcept addressIterator = addressPage.iterateAll(); while (addressIterator.hasNext()) { Address address = addressIterator.next(); - assertTrue(address.addressId() instanceof RegionAddressId); - assertEquals(REGION, address.addressId().region()); - assertTrue(addressSet.contains(address.addressId().address())); - assertNotNull(address.address()); - assertNull(address.creationTimestamp()); - assertNull(address.generatedId()); - assertNull(address.status()); - assertNull(address.usage()); + assertTrue(address.getAddressId() instanceof RegionAddressId); + assertEquals(REGION, address.getAddressId().getRegion()); + assertTrue(addressSet.contains(address.getAddressId().getAddress())); + assertNotNull(address.getAddress()); + assertNull(address.getCreationTimestamp()); + assertNull(address.getGeneratedId()); + assertNull(address.getStatus()); + assertNull(address.getUsage()); count++; } assertEquals(2, count); @@ -783,11 +782,11 @@ public void testAggregatedListAddresses() throws InterruptedException, TimeoutEx int count = 0; while (addressIterator.hasNext()) { Address address = addressIterator.next(); - assertNotNull(address.addressId()); - assertTrue(addressSet.contains(address.addressId().address())); - assertNotNull(address.address()); - assertNotNull(address.creationTimestamp()); - assertNotNull(address.generatedId()); + assertNotNull(address.getAddressId()); + assertTrue(addressSet.contains(address.getAddressId().getAddress())); + assertNotNull(address.getAddress()); + assertNotNull(address.getCreationTimestamp()); + assertNotNull(address.getGeneratedId()); count++; } assertEquals(2, count); @@ -805,20 +804,20 @@ public void testCreateGetAndDeleteGlobalAddress() throws InterruptedException, T // test get Address remoteAddress = compute.getAddress(addressId); assertNotNull(remoteAddress); - assertTrue(remoteAddress.addressId() instanceof GlobalAddressId); - assertEquals(addressId.address(), remoteAddress.addressId().address()); - assertNotNull(remoteAddress.address()); - assertNotNull(remoteAddress.creationTimestamp()); - assertNotNull(remoteAddress.generatedId()); - assertNotNull(remoteAddress.status()); + assertTrue(remoteAddress.getAddressId() instanceof GlobalAddressId); + assertEquals(addressId.getAddress(), remoteAddress.getAddressId().getAddress()); + assertNotNull(remoteAddress.getAddress()); + assertNotNull(remoteAddress.getCreationTimestamp()); + assertNotNull(remoteAddress.getGeneratedId()); + assertNotNull(remoteAddress.getStatus()); // test get with selected fields remoteAddress = compute.getAddress(addressId, Compute.AddressOption.fields()); assertNotNull(remoteAddress); - assertTrue(remoteAddress.addressId() instanceof GlobalAddressId); - assertEquals(addressId.address(), remoteAddress.addressId().address()); - assertNull(remoteAddress.address()); - assertNull(remoteAddress.creationTimestamp()); - assertNull(remoteAddress.generatedId()); + assertTrue(remoteAddress.getAddressId() instanceof GlobalAddressId); + assertEquals(addressId.getAddress(), remoteAddress.getAddressId().getAddress()); + assertNull(remoteAddress.getAddress()); + assertNull(remoteAddress.getCreationTimestamp()); + assertNull(remoteAddress.getGeneratedId()); operation = remoteAddress.delete(); operation.waitFor(); assertNull(compute.getAddress(addressId)); @@ -844,12 +843,12 @@ public void testListGlobalAddresses() throws InterruptedException, TimeoutExcept int count = 0; while (addressIterator.hasNext()) { Address address = addressIterator.next(); - assertNotNull(address.addressId()); - assertTrue(address.addressId() instanceof GlobalAddressId); - assertTrue(addressSet.contains(address.addressId().address())); - assertNotNull(address.address()); - assertNotNull(address.creationTimestamp()); - assertNotNull(address.generatedId()); + assertNotNull(address.getAddressId()); + assertTrue(address.getAddressId() instanceof GlobalAddressId); + assertTrue(addressSet.contains(address.getAddressId().getAddress())); + assertNotNull(address.getAddress()); + assertNotNull(address.getCreationTimestamp()); + assertNotNull(address.getGeneratedId()); count++; } assertEquals(2, count); @@ -860,13 +859,13 @@ public void testListGlobalAddresses() throws InterruptedException, TimeoutExcept addressIterator = addressPage.iterateAll(); while (addressIterator.hasNext()) { Address address = addressIterator.next(); - assertTrue(address.addressId() instanceof GlobalAddressId); - assertTrue(addressSet.contains(address.addressId().address())); - assertNotNull(address.address()); - assertNull(address.creationTimestamp()); - assertNull(address.generatedId()); - assertNull(address.status()); - assertNull(address.usage()); + assertTrue(address.getAddressId() instanceof GlobalAddressId); + assertTrue(addressSet.contains(address.getAddressId().getAddress())); + assertNotNull(address.getAddress()); + assertNull(address.getCreationTimestamp()); + assertNull(address.getGeneratedId()); + assertNull(address.getStatus()); + assertNull(address.getUsage()); count++; } assertEquals(2, count); @@ -875,7 +874,8 @@ public void testListGlobalAddresses() throws InterruptedException, TimeoutExcept } @Test - public void testCreateGetResizeAndDeleteStandardDisk() throws InterruptedException, TimeoutException { + public void testCreateGetResizeAndDeleteStandardDisk() + throws InterruptedException, TimeoutException { String name = BASE_RESOURCE_NAME + "create-and-get-standard-disk"; DiskId diskId = DiskId.of(ZONE, name); DiskInfo diskInfo = @@ -885,33 +885,33 @@ public void testCreateGetResizeAndDeleteStandardDisk() throws InterruptedExcepti // test get Disk remoteDisk = compute.getDisk(diskId); assertNotNull(remoteDisk); - assertEquals(ZONE, remoteDisk.diskId().zone()); - assertEquals(diskId.disk(), remoteDisk.diskId().disk()); - assertNotNull(remoteDisk.creationTimestamp()); - assertNotNull(remoteDisk.generatedId()); - assertTrue(remoteDisk.configuration() instanceof StandardDiskConfiguration); - StandardDiskConfiguration remoteConfiguration = remoteDisk.configuration(); - assertEquals(100L, (long) remoteConfiguration.sizeGb()); - assertEquals("pd-ssd", remoteConfiguration.diskType().type()); - assertEquals(DiskConfiguration.Type.STANDARD, remoteConfiguration.type()); - assertNull(remoteDisk.lastAttachTimestamp()); - assertNull(remoteDisk.lastDetachTimestamp()); + assertEquals(ZONE, remoteDisk.getDiskId().getZone()); + assertEquals(diskId.getDisk(), remoteDisk.getDiskId().getDisk()); + assertNotNull(remoteDisk.getCreationTimestamp()); + assertNotNull(remoteDisk.getGeneratedId()); + assertTrue(remoteDisk.getConfiguration() instanceof StandardDiskConfiguration); + StandardDiskConfiguration remoteConfiguration = remoteDisk.getConfiguration(); + assertEquals(100L, (long) remoteConfiguration.getSizeGb()); + assertEquals("pd-ssd", remoteConfiguration.getDiskType().getType()); + assertEquals(DiskConfiguration.Type.STANDARD, remoteConfiguration.getType()); + assertNull(remoteDisk.getLastAttachTimestamp()); + assertNull(remoteDisk.getLastDetachTimestamp()); operation = remoteDisk.resize(200L); operation.waitFor(); // test resize and get with selected fields remoteDisk = compute.getDisk(diskId, Compute.DiskOption.fields(Compute.DiskField.SIZE_GB)); assertNotNull(remoteDisk); - assertEquals(ZONE, remoteDisk.diskId().zone()); - assertEquals(diskId.disk(), remoteDisk.diskId().disk()); - assertNull(remoteDisk.creationTimestamp()); - assertNull(remoteDisk.generatedId()); - assertTrue(remoteDisk.configuration() instanceof StandardDiskConfiguration); - remoteConfiguration = remoteDisk.configuration(); - assertEquals(200L, (long) remoteConfiguration.sizeGb()); - assertEquals("pd-ssd", remoteConfiguration.diskType().type()); - assertEquals(DiskConfiguration.Type.STANDARD, remoteConfiguration.type()); - assertNull(remoteDisk.lastAttachTimestamp()); - assertNull(remoteDisk.lastDetachTimestamp()); + assertEquals(ZONE, remoteDisk.getDiskId().getZone()); + assertEquals(diskId.getDisk(), remoteDisk.getDiskId().getDisk()); + assertNull(remoteDisk.getCreationTimestamp()); + assertNull(remoteDisk.getGeneratedId()); + assertTrue(remoteDisk.getConfiguration() instanceof StandardDiskConfiguration); + remoteConfiguration = remoteDisk.getConfiguration(); + assertEquals(200L, (long) remoteConfiguration.getSizeGb()); + assertEquals("pd-ssd", remoteConfiguration.getDiskType().getType()); + assertEquals(DiskConfiguration.Type.STANDARD, remoteConfiguration.getType()); + assertNull(remoteDisk.getLastAttachTimestamp()); + assertNull(remoteDisk.getLastDetachTimestamp()); operation = remoteDisk.delete(); operation.waitFor(); assertNull(compute.getDisk(diskId)); @@ -927,43 +927,44 @@ public void testCreateGetAndDeleteImageDisk() throws InterruptedException, Timeo // test get Disk remoteDisk = compute.getDisk(diskId); assertNotNull(remoteDisk); - assertEquals(ZONE, remoteDisk.diskId().zone()); - assertEquals(diskId.disk(), remoteDisk.diskId().disk()); - assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.creationStatus()); - assertNotNull(remoteDisk.creationTimestamp()); - assertNotNull(remoteDisk.generatedId()); - assertTrue(remoteDisk.configuration() instanceof ImageDiskConfiguration); - ImageDiskConfiguration remoteConfiguration = remoteDisk.configuration(); - assertEquals(IMAGE_ID, remoteConfiguration.sourceImage()); - assertNotNull(remoteConfiguration.sourceImageId()); - assertEquals(DiskConfiguration.Type.IMAGE, remoteConfiguration.type()); - assertNotNull(remoteConfiguration.sizeGb()); - assertEquals("pd-standard", remoteConfiguration.diskType().type()); - assertNull(remoteDisk.lastAttachTimestamp()); - assertNull(remoteDisk.lastDetachTimestamp()); + assertEquals(ZONE, remoteDisk.getDiskId().getZone()); + assertEquals(diskId.getDisk(), remoteDisk.getDiskId().getDisk()); + assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.getCreationStatus()); + assertNotNull(remoteDisk.getCreationTimestamp()); + assertNotNull(remoteDisk.getGeneratedId()); + assertTrue(remoteDisk.getConfiguration() instanceof ImageDiskConfiguration); + ImageDiskConfiguration remoteConfiguration = remoteDisk.getConfiguration(); + assertEquals(IMAGE_ID, remoteConfiguration.getSourceImage()); + assertNotNull(remoteConfiguration.getSourceImageId()); + assertEquals(DiskConfiguration.Type.IMAGE, remoteConfiguration.getType()); + assertNotNull(remoteConfiguration.getSizeGb()); + assertEquals("pd-standard", remoteConfiguration.getDiskType().getType()); + assertNull(remoteDisk.getLastAttachTimestamp()); + assertNull(remoteDisk.getLastDetachTimestamp()); // test get with selected fields remoteDisk = compute.getDisk(diskId, Compute.DiskOption.fields()); assertNotNull(remoteDisk); - assertEquals(ZONE, remoteDisk.diskId().zone()); - assertEquals(diskId.disk(), remoteDisk.diskId().disk()); - assertNull(remoteDisk.creationTimestamp()); - assertNull(remoteDisk.generatedId()); - assertTrue(remoteDisk.configuration() instanceof ImageDiskConfiguration); - remoteConfiguration = remoteDisk.configuration(); - assertEquals(IMAGE_ID, remoteConfiguration.sourceImage()); - assertNull(remoteConfiguration.sourceImageId()); - assertEquals(DiskConfiguration.Type.IMAGE, remoteConfiguration.type()); - assertNull(remoteConfiguration.sizeGb()); - assertEquals("pd-standard", remoteConfiguration.diskType().type()); - assertNull(remoteDisk.lastAttachTimestamp()); - assertNull(remoteDisk.lastDetachTimestamp()); + assertEquals(ZONE, remoteDisk.getDiskId().getZone()); + assertEquals(diskId.getDisk(), remoteDisk.getDiskId().getDisk()); + assertNull(remoteDisk.getCreationTimestamp()); + assertNull(remoteDisk.getGeneratedId()); + assertTrue(remoteDisk.getConfiguration() instanceof ImageDiskConfiguration); + remoteConfiguration = remoteDisk.getConfiguration(); + assertEquals(IMAGE_ID, remoteConfiguration.getSourceImage()); + assertNull(remoteConfiguration.getSourceImageId()); + assertEquals(DiskConfiguration.Type.IMAGE, remoteConfiguration.getType()); + assertNull(remoteConfiguration.getSizeGb()); + assertEquals("pd-standard", remoteConfiguration.getDiskType().getType()); + assertNull(remoteDisk.getLastAttachTimestamp()); + assertNull(remoteDisk.getLastDetachTimestamp()); operation = remoteDisk.delete(); operation.waitFor(); assertNull(compute.getDisk(diskId)); } @Test - public void testCreateGetAndDeleteSnapshotAndSnapshotDisk() throws InterruptedException, TimeoutException { + public void testCreateGetAndDeleteSnapshotAndSnapshotDisk() + throws InterruptedException, TimeoutException { String diskName = BASE_RESOURCE_NAME + "create-and-get-snapshot-disk1"; String snapshotDiskName = BASE_RESOURCE_NAME + "create-and-get-snapshot-disk2"; DiskId diskId = DiskId.of(ZONE, diskName); @@ -979,28 +980,28 @@ public void testCreateGetAndDeleteSnapshotAndSnapshotDisk() throws InterruptedEx // test get snapshot with selected fields Snapshot snapshot = compute.getSnapshot(snapshotName, Compute.SnapshotOption.fields(Compute.SnapshotField.CREATION_TIMESTAMP)); - assertNull(snapshot.generatedId()); - assertNotNull(snapshot.snapshotId()); - assertNotNull(snapshot.creationTimestamp()); - assertNull(snapshot.description()); - assertNull(snapshot.status()); - assertNull(snapshot.diskSizeGb()); - assertNull(snapshot.licenses()); - assertNull(snapshot.sourceDisk()); - assertNull(snapshot.sourceDiskId()); - assertNull(snapshot.storageBytes()); - assertNull(snapshot.storageBytesStatus()); + assertNull(snapshot.getGeneratedId()); + assertNotNull(snapshot.getSnapshotId()); + assertNotNull(snapshot.getCreationTimestamp()); + assertNull(snapshot.getDescription()); + assertNull(snapshot.getStatus()); + assertNull(snapshot.getDiskSizeGb()); + assertNull(snapshot.getLicenses()); + assertNull(snapshot.getSourceDisk()); + assertNull(snapshot.getSourceDiskId()); + assertNull(snapshot.getStorageBytes()); + assertNull(snapshot.getStorageBytesStatus()); // test get snapshot snapshot = compute.getSnapshot(snapshotName); - assertNotNull(snapshot.generatedId()); - assertNotNull(snapshot.snapshotId()); - assertNotNull(snapshot.creationTimestamp()); - assertNotNull(snapshot.status()); - assertEquals(100L, (long) snapshot.diskSizeGb()); - assertEquals(diskName, snapshot.sourceDisk().disk()); - assertNotNull(snapshot.sourceDiskId()); - assertNotNull(snapshot.storageBytes()); - assertNotNull(snapshot.storageBytesStatus()); + assertNotNull(snapshot.getGeneratedId()); + assertNotNull(snapshot.getSnapshotId()); + assertNotNull(snapshot.getCreationTimestamp()); + assertNotNull(snapshot.getStatus()); + assertEquals(100L, (long) snapshot.getDiskSizeGb()); + assertEquals(diskName, snapshot.getSourceDisk().getDisk()); + assertNotNull(snapshot.getSourceDiskId()); + assertNotNull(snapshot.getStorageBytes()); + assertNotNull(snapshot.getStorageBytesStatus()); remoteDisk.delete(); diskInfo = DiskInfo.of(snapshotDiskId, SnapshotDiskConfiguration.of(SnapshotId.of(snapshotName))); @@ -1009,37 +1010,37 @@ public void testCreateGetAndDeleteSnapshotAndSnapshotDisk() throws InterruptedEx // test get disk remoteDisk = compute.getDisk(snapshotDiskId); assertNotNull(remoteDisk); - assertEquals(ZONE, remoteDisk.diskId().zone()); - assertEquals(snapshotDiskId.disk(), remoteDisk.diskId().disk()); - assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.creationStatus()); - assertNotNull(remoteDisk.creationTimestamp()); - assertNotNull(remoteDisk.generatedId()); - assertTrue(remoteDisk.configuration() instanceof SnapshotDiskConfiguration); - SnapshotDiskConfiguration remoteConfiguration = remoteDisk.configuration(); - assertEquals(DiskConfiguration.Type.SNAPSHOT, remoteConfiguration.type()); - assertEquals(snapshotName, remoteConfiguration.sourceSnapshot().snapshot()); - assertEquals(100L, (long) remoteConfiguration.sizeGb()); - assertEquals("pd-standard", remoteConfiguration.diskType().type()); - assertNotNull(remoteConfiguration.sourceSnapshotId()); - assertNull(remoteDisk.lastAttachTimestamp()); - assertNull(remoteDisk.lastDetachTimestamp()); + assertEquals(ZONE, remoteDisk.getDiskId().getZone()); + assertEquals(snapshotDiskId.getDisk(), remoteDisk.getDiskId().getDisk()); + assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.getCreationStatus()); + assertNotNull(remoteDisk.getCreationTimestamp()); + assertNotNull(remoteDisk.getGeneratedId()); + assertTrue(remoteDisk.getConfiguration() instanceof SnapshotDiskConfiguration); + SnapshotDiskConfiguration remoteConfiguration = remoteDisk.getConfiguration(); + assertEquals(DiskConfiguration.Type.SNAPSHOT, remoteConfiguration.getType()); + assertEquals(snapshotName, remoteConfiguration.getSourceSnapshot().getSnapshot()); + assertEquals(100L, (long) remoteConfiguration.getSizeGb()); + assertEquals("pd-standard", remoteConfiguration.getDiskType().getType()); + assertNotNull(remoteConfiguration.getSourceSnapshotId()); + assertNull(remoteDisk.getLastAttachTimestamp()); + assertNull(remoteDisk.getLastDetachTimestamp()); // test get disk with selected fields remoteDisk = compute.getDisk(snapshotDiskId, Compute.DiskOption.fields()); assertNotNull(remoteDisk); - assertEquals(ZONE, remoteDisk.diskId().zone()); - assertEquals(snapshotDiskId.disk(), remoteDisk.diskId().disk()); - assertNull(remoteDisk.creationStatus()); - assertNull(remoteDisk.creationTimestamp()); - assertNull(remoteDisk.generatedId()); - assertTrue(remoteDisk.configuration() instanceof SnapshotDiskConfiguration); - remoteConfiguration = remoteDisk.configuration(); - assertEquals(DiskConfiguration.Type.SNAPSHOT, remoteConfiguration.type()); - assertEquals(snapshotName, remoteConfiguration.sourceSnapshot().snapshot()); - assertNull(remoteConfiguration.sizeGb()); - assertEquals("pd-standard", remoteConfiguration.diskType().type()); - assertNull(remoteDisk.configuration().sourceSnapshotId()); - assertNull(remoteDisk.lastAttachTimestamp()); - assertNull(remoteDisk.lastDetachTimestamp()); + assertEquals(ZONE, remoteDisk.getDiskId().getZone()); + assertEquals(snapshotDiskId.getDisk(), remoteDisk.getDiskId().getDisk()); + assertNull(remoteDisk.getCreationStatus()); + assertNull(remoteDisk.getCreationTimestamp()); + assertNull(remoteDisk.getGeneratedId()); + assertTrue(remoteDisk.getConfiguration() instanceof SnapshotDiskConfiguration); + remoteConfiguration = remoteDisk.getConfiguration(); + assertEquals(DiskConfiguration.Type.SNAPSHOT, remoteConfiguration.getType()); + assertEquals(snapshotName, remoteConfiguration.getSourceSnapshot().getSnapshot()); + assertNull(remoteConfiguration.getSizeGb()); + assertEquals("pd-standard", remoteConfiguration.getDiskType().getType()); + assertNull(remoteDisk.getConfiguration().getSourceSnapshotId()); + assertNull(remoteDisk.getLastAttachTimestamp()); + assertNull(remoteDisk.getLastDetachTimestamp()); operation = remoteDisk.delete(); operation.waitFor(); assertNull(compute.getDisk(snapshotDiskId)); @@ -1069,18 +1070,18 @@ public void testListDisksAndSnapshots() throws InterruptedException, TimeoutExce int count = 0; while (diskIterator.hasNext()) { Disk remoteDisk = diskIterator.next(); - assertEquals(ZONE, remoteDisk.diskId().zone()); - assertTrue(diskSet.contains(remoteDisk.diskId().disk())); - assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.creationStatus()); - assertNotNull(remoteDisk.creationTimestamp()); - assertNotNull(remoteDisk.generatedId()); - assertTrue(remoteDisk.configuration() instanceof StandardDiskConfiguration); - StandardDiskConfiguration remoteConfiguration = remoteDisk.configuration(); - assertEquals(100L, (long) remoteConfiguration.sizeGb()); - assertEquals("pd-ssd", remoteConfiguration.diskType().type()); - assertEquals(DiskConfiguration.Type.STANDARD, remoteConfiguration.type()); - assertNull(remoteDisk.lastAttachTimestamp()); - assertNull(remoteDisk.lastDetachTimestamp()); + assertEquals(ZONE, remoteDisk.getDiskId().getZone()); + assertTrue(diskSet.contains(remoteDisk.getDiskId().getDisk())); + assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.getCreationStatus()); + assertNotNull(remoteDisk.getCreationTimestamp()); + assertNotNull(remoteDisk.getGeneratedId()); + assertTrue(remoteDisk.getConfiguration() instanceof StandardDiskConfiguration); + StandardDiskConfiguration remoteConfiguration = remoteDisk.getConfiguration(); + assertEquals(100L, (long) remoteConfiguration.getSizeGb()); + assertEquals("pd-ssd", remoteConfiguration.getDiskType().getType()); + assertEquals(DiskConfiguration.Type.STANDARD, remoteConfiguration.getType()); + assertNull(remoteDisk.getLastAttachTimestamp()); + assertNull(remoteDisk.getLastDetachTimestamp()); count++; } assertEquals(2, count); @@ -1091,18 +1092,18 @@ public void testListDisksAndSnapshots() throws InterruptedException, TimeoutExce diskIterator = diskPage.iterateAll(); while (diskIterator.hasNext()) { Disk remoteDisk = diskIterator.next(); - assertEquals(ZONE, remoteDisk.diskId().zone()); - assertTrue(diskSet.contains(remoteDisk.diskId().disk())); - assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.creationStatus()); - assertNull(remoteDisk.creationTimestamp()); - assertNull(remoteDisk.generatedId()); - assertTrue(remoteDisk.configuration() instanceof StandardDiskConfiguration); - StandardDiskConfiguration remoteConfiguration = remoteDisk.configuration(); - assertNull(remoteConfiguration.sizeGb()); - assertEquals("pd-ssd", remoteConfiguration.diskType().type()); - assertEquals(DiskConfiguration.Type.STANDARD, remoteConfiguration.type()); - assertNull(remoteDisk.lastAttachTimestamp()); - assertNull(remoteDisk.lastDetachTimestamp()); + assertEquals(ZONE, remoteDisk.getDiskId().getZone()); + assertTrue(diskSet.contains(remoteDisk.getDiskId().getDisk())); + assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.getCreationStatus()); + assertNull(remoteDisk.getCreationTimestamp()); + assertNull(remoteDisk.getGeneratedId()); + assertTrue(remoteDisk.getConfiguration() instanceof StandardDiskConfiguration); + StandardDiskConfiguration remoteConfiguration = remoteDisk.getConfiguration(); + assertNull(remoteConfiguration.getSizeGb()); + assertEquals("pd-ssd", remoteConfiguration.getDiskType().getType()); + assertEquals(DiskConfiguration.Type.STANDARD, remoteConfiguration.getType()); + assertNull(remoteDisk.getLastAttachTimestamp()); + assertNull(remoteDisk.getLastDetachTimestamp()); count++; } assertEquals(2, count); @@ -1122,15 +1123,15 @@ public void testListDisksAndSnapshots() throws InterruptedException, TimeoutExce count = 0; while (snapshotIterator.hasNext()) { Snapshot remoteSnapshot = snapshotIterator.next(); - assertNotNull(remoteSnapshot.generatedId()); - assertTrue(diskSet.contains(remoteSnapshot.snapshotId().snapshot())); - assertNotNull(remoteSnapshot.creationTimestamp()); - assertNotNull(remoteSnapshot.status()); - assertEquals(100L, (long) remoteSnapshot.diskSizeGb()); - assertTrue(diskSet.contains(remoteSnapshot.sourceDisk().disk())); - assertNotNull(remoteSnapshot.sourceDiskId()); - assertNotNull(remoteSnapshot.storageBytes()); - assertNotNull(remoteSnapshot.storageBytesStatus()); + assertNotNull(remoteSnapshot.getGeneratedId()); + assertTrue(diskSet.contains(remoteSnapshot.getSnapshotId().getSnapshot())); + assertNotNull(remoteSnapshot.getCreationTimestamp()); + assertNotNull(remoteSnapshot.getStatus()); + assertEquals(100L, (long) remoteSnapshot.getDiskSizeGb()); + assertTrue(diskSet.contains(remoteSnapshot.getSourceDisk().getDisk())); + assertNotNull(remoteSnapshot.getSourceDiskId()); + assertNotNull(remoteSnapshot.getStorageBytes()); + assertNotNull(remoteSnapshot.getStorageBytesStatus()); count++; } assertEquals(2, count); @@ -1141,15 +1142,15 @@ public void testListDisksAndSnapshots() throws InterruptedException, TimeoutExce count = 0; while (snapshotIterator.hasNext()) { Snapshot remoteSnapshot = snapshotIterator.next(); - assertNull(remoteSnapshot.generatedId()); - assertTrue(diskSet.contains(remoteSnapshot.snapshotId().snapshot())); - assertNotNull(remoteSnapshot.creationTimestamp()); - assertNull(remoteSnapshot.status()); - assertNull(remoteSnapshot.diskSizeGb()); - assertNull(remoteSnapshot.sourceDisk()); - assertNull(remoteSnapshot.sourceDiskId()); - assertNull(remoteSnapshot.storageBytes()); - assertNull(remoteSnapshot.storageBytesStatus()); + assertNull(remoteSnapshot.getGeneratedId()); + assertTrue(diskSet.contains(remoteSnapshot.getSnapshotId().getSnapshot())); + assertNotNull(remoteSnapshot.getCreationTimestamp()); + assertNull(remoteSnapshot.getStatus()); + assertNull(remoteSnapshot.getDiskSizeGb()); + assertNull(remoteSnapshot.getSourceDisk()); + assertNull(remoteSnapshot.getSourceDiskId()); + assertNull(remoteSnapshot.getStorageBytes()); + assertNull(remoteSnapshot.getStorageBytesStatus()); count++; } assertEquals(2, count); @@ -1181,16 +1182,16 @@ public void testAggregatedListDisks() throws InterruptedException, TimeoutExcept int count = 0; while (diskIterator.hasNext()) { Disk remoteDisk = diskIterator.next(); - assertTrue(zoneSet.contains(remoteDisk.diskId().zone())); - assertTrue(diskSet.contains(remoteDisk.diskId().disk())); - assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.creationStatus()); - assertNotNull(remoteDisk.creationTimestamp()); - assertNotNull(remoteDisk.generatedId()); - assertTrue(remoteDisk.configuration() instanceof StandardDiskConfiguration); - StandardDiskConfiguration remoteConfiguration = remoteDisk.configuration(); - assertEquals(100L, (long) remoteConfiguration.sizeGb()); - assertEquals("pd-ssd", remoteConfiguration.diskType().type()); - assertEquals(DiskConfiguration.Type.STANDARD, remoteConfiguration.type()); + assertTrue(zoneSet.contains(remoteDisk.getDiskId().getZone())); + assertTrue(diskSet.contains(remoteDisk.getDiskId().getDisk())); + assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.getCreationStatus()); + assertNotNull(remoteDisk.getCreationTimestamp()); + assertNotNull(remoteDisk.getGeneratedId()); + assertTrue(remoteDisk.getConfiguration() instanceof StandardDiskConfiguration); + StandardDiskConfiguration remoteConfiguration = remoteDisk.getConfiguration(); + assertEquals(100L, (long) remoteConfiguration.getSizeGb()); + assertEquals("pd-ssd", remoteConfiguration.getDiskType().getType()); + assertEquals(DiskConfiguration.Type.STANDARD, remoteConfiguration.getType()); count++; } assertEquals(2, count); @@ -1215,41 +1216,41 @@ public void testCreateGetAndDeprecateImage() throws InterruptedException, Timeou // test get image with selected fields Image image = compute.getImage(imageId, Compute.ImageOption.fields(Compute.ImageField.CREATION_TIMESTAMP)); - assertNull(image.generatedId()); - assertNotNull(image.imageId()); - assertNotNull(image.creationTimestamp()); - assertNull(image.description()); - assertNotNull(image.configuration()); - assertTrue(image.configuration() instanceof DiskImageConfiguration); - DiskImageConfiguration remoteConfiguration = image.configuration(); - Assert.assertEquals(ImageConfiguration.Type.DISK, remoteConfiguration.type()); - assertEquals(diskName, remoteConfiguration.sourceDisk().disk()); - assertNull(image.status()); - assertNull(image.diskSizeGb()); - assertNull(image.licenses()); - assertNull(image.deprecationStatus()); + assertNull(image.getGeneratedId()); + assertNotNull(image.getImageId()); + assertNotNull(image.getCreationTimestamp()); + assertNull(image.getDescription()); + assertNotNull(image.getConfiguration()); + assertTrue(image.getConfiguration() instanceof DiskImageConfiguration); + DiskImageConfiguration remoteConfiguration = image.getConfiguration(); + assertEquals(ImageConfiguration.Type.DISK, remoteConfiguration.getType()); + assertEquals(diskName, remoteConfiguration.getSourceDisk().getDisk()); + assertNull(image.getStatus()); + assertNull(image.getDiskSizeGb()); + assertNull(image.getLicenses()); + assertNull(image.getDeprecationStatus()); // test get image image = compute.getImage(imageId); - assertNotNull(image.generatedId()); - assertNotNull(image.imageId()); - assertNotNull(image.creationTimestamp()); - assertNotNull(image.configuration()); - assertTrue(image.configuration() instanceof DiskImageConfiguration); - remoteConfiguration = image.configuration(); - assertEquals(ImageConfiguration.Type.DISK, remoteConfiguration.type()); - assertEquals(diskName, remoteConfiguration.sourceDisk().disk()); - assertEquals(100L, (long) image.diskSizeGb()); - assertNotNull(image.status()); - assertNull(image.deprecationStatus()); + assertNotNull(image.getGeneratedId()); + assertNotNull(image.getImageId()); + assertNotNull(image.getCreationTimestamp()); + assertNotNull(image.getConfiguration()); + assertTrue(image.getConfiguration() instanceof DiskImageConfiguration); + remoteConfiguration = image.getConfiguration(); + assertEquals(ImageConfiguration.Type.DISK, remoteConfiguration.getType()); + assertEquals(diskName, remoteConfiguration.getSourceDisk().getDisk()); + assertEquals(100L, (long) image.getDiskSizeGb()); + assertNotNull(image.getStatus()); + assertNull(image.getDeprecationStatus()); // test deprecate image DeprecationStatus deprecationStatus = - DeprecationStatus.builder(DeprecationStatus.Status.DEPRECATED, imageId) - .deprecated(System.currentTimeMillis()) + DeprecationStatus.newBuilder(DeprecationStatus.Status.DEPRECATED, imageId) + .setDeprecated(System.currentTimeMillis()) .build(); operation = image.deprecate(deprecationStatus); operation.waitFor(); image = compute.getImage(imageId); - assertEquals(deprecationStatus, image.deprecationStatus()); + assertEquals(deprecationStatus, image.getDeprecationStatus()); remoteDisk.delete(); operation = image.delete(); operation.waitFor(); @@ -1264,12 +1265,12 @@ public void testListImages() { while (imageIterator.hasNext()) { count++; Image image = imageIterator.next(); - assertNotNull(image.generatedId()); - assertNotNull(image.imageId()); - assertNotNull(image.creationTimestamp()); - assertNotNull(image.configuration()); - assertNotNull(image.status()); - assertNotNull(image.diskSizeGb()); + assertNotNull(image.getGeneratedId()); + assertNotNull(image.getImageId()); + assertNotNull(image.getCreationTimestamp()); + assertNotNull(image.getConfiguration()); + assertNotNull(image.getStatus()); + assertNotNull(image.getDiskSizeGb()); } assertTrue(count > 0); } @@ -1283,14 +1284,14 @@ public void testListImagesWithSelectedFields() { while (imageIterator.hasNext()) { count++; Image image = imageIterator.next(); - assertNotNull(image.generatedId()); - assertNotNull(image.imageId()); - assertNull(image.creationTimestamp()); - assertNotNull(image.configuration()); - assertNull(image.status()); - assertNull(image.diskSizeGb()); - assertNull(image.licenses()); - assertNull(image.deprecationStatus()); + assertNotNull(image.getGeneratedId()); + assertNotNull(image.getImageId()); + assertNull(image.getCreationTimestamp()); + assertNotNull(image.getConfiguration()); + assertNull(image.getStatus()); + assertNull(image.getDiskSizeGb()); + assertNull(image.getLicenses()); + assertNull(image.getDeprecationStatus()); } assertTrue(count > 0); } @@ -1304,14 +1305,14 @@ public void testListImagesWithFilter() { while (imageIterator.hasNext()) { count++; Image image = imageIterator.next(); - assertNotNull(image.generatedId()); - assertNotNull(image.imageId()); - assertNotNull(image.creationTimestamp()); - assertNotNull(image.configuration()); - assertNotNull(image.status()); - assertNotNull(image.diskSizeGb()); + assertNotNull(image.getGeneratedId()); + assertNotNull(image.getImageId()); + assertNotNull(image.getCreationTimestamp()); + assertNotNull(image.getConfiguration()); + assertNotNull(image.getStatus()); + assertNotNull(image.getDiskSizeGb()); assertEquals(365056004L, - (long) image.configuration().archiveSizeBytes()); + (long) image.getConfiguration().getArchiveSizeBytes()); } assertTrue(count > 0); } @@ -1325,23 +1326,23 @@ public void testCreateAndGetNetwork() throws InterruptedException, TimeoutExcept Operation operation = compute.create(networkInfo); operation.waitFor(); // test get network with selected fields - Network network = compute.getNetwork(networkId.network(), + Network network = compute.getNetwork(networkId.getNetwork(), Compute.NetworkOption.fields(Compute.NetworkField.CREATION_TIMESTAMP)); - assertEquals(networkId.network(), network.networkId().network()); - assertNull(network.generatedId()); - assertNotNull(network.creationTimestamp()); - assertNull(network.description()); - assertEquals(NetworkConfiguration.Type.STANDARD, network.configuration().type()); - StandardNetworkConfiguration remoteConfiguration = network.configuration(); - assertEquals("192.168.0.0/16", remoteConfiguration.ipRange()); + assertEquals(networkId.getNetwork(), network.getNetworkId().getNetwork()); + assertNull(network.getGeneratedId()); + assertNotNull(network.getCreationTimestamp()); + assertNull(network.getDescription()); + assertEquals(NetworkConfiguration.Type.STANDARD, network.getConfiguration().getType()); + StandardNetworkConfiguration remoteConfiguration = network.getConfiguration(); + assertEquals("192.168.0.0/16", remoteConfiguration.getIpRange()); // test get network - network = compute.getNetwork(networkId.network()); - assertEquals(networkId.network(), network.networkId().network()); - assertNotNull(network.generatedId()); - assertNotNull(network.creationTimestamp()); - assertEquals(NetworkConfiguration.Type.STANDARD, network.configuration().type()); - remoteConfiguration = network.configuration(); - assertEquals("192.168.0.0/16", remoteConfiguration.ipRange()); + network = compute.getNetwork(networkId.getNetwork()); + assertEquals(networkId.getNetwork(), network.getNetworkId().getNetwork()); + assertNotNull(network.getGeneratedId()); + assertNotNull(network.getCreationTimestamp()); + assertEquals(NetworkConfiguration.Type.STANDARD, network.getConfiguration().getType()); + remoteConfiguration = network.getConfiguration(); + assertEquals("192.168.0.0/16", remoteConfiguration.getIpRange()); operation = network.delete(); operation.waitFor(); assertNull(compute.getNetwork(name)); @@ -1362,12 +1363,12 @@ public void testListNetworks() throws InterruptedException, TimeoutException { int count = 0; while (networkIterator.hasNext()) { Network network = networkIterator.next(); - assertEquals(networkId.network(), network.networkId().network()); - assertNotNull(network.generatedId()); - assertNotNull(network.creationTimestamp()); - assertEquals(NetworkConfiguration.Type.STANDARD, network.configuration().type()); - StandardNetworkConfiguration remoteConfiguration = network.configuration(); - assertEquals("192.168.0.0/16", remoteConfiguration.ipRange()); + assertEquals(networkId.getNetwork(), network.getNetworkId().getNetwork()); + assertNotNull(network.getGeneratedId()); + assertNotNull(network.getCreationTimestamp()); + assertEquals(NetworkConfiguration.Type.STANDARD, network.getConfiguration().getType()); + StandardNetworkConfiguration remoteConfiguration = network.getConfiguration(); + assertEquals("192.168.0.0/16", remoteConfiguration.getIpRange()); count++; } assertEquals(1, count); @@ -1378,13 +1379,13 @@ public void testListNetworks() throws InterruptedException, TimeoutException { networkIterator = networkPage.iterateAll(); while (networkIterator.hasNext()) { Network network = networkIterator.next(); - assertEquals(networkId.network(), network.networkId().network()); - assertNull(network.generatedId()); - assertNotNull(network.creationTimestamp()); - assertNull(network.description()); - assertEquals(NetworkConfiguration.Type.STANDARD, network.configuration().type()); - StandardNetworkConfiguration remoteConfiguration = network.configuration(); - assertEquals("192.168.0.0/16", remoteConfiguration.ipRange()); + assertEquals(networkId.getNetwork(), network.getNetworkId().getNetwork()); + assertNull(network.getGeneratedId()); + assertNotNull(network.getCreationTimestamp()); + assertNull(network.getDescription()); + assertEquals(NetworkConfiguration.Type.STANDARD, network.getConfiguration().getType()); + StandardNetworkConfiguration remoteConfiguration = network.getConfiguration(); + assertEquals("192.168.0.0/16", remoteConfiguration.getIpRange()); count++; } assertEquals(1, count); @@ -1401,13 +1402,13 @@ public void testCreateNetworkAndSubnetwork() throws InterruptedException, Timeou Operation operation = compute.create(networkInfo); operation.waitFor(); // test get network - Network network = compute.getNetwork(networkId.network()); - assertEquals(networkId.network(), network.networkId().network()); - assertNotNull(network.generatedId()); - assertNotNull(network.creationTimestamp()); - assertEquals(NetworkConfiguration.Type.SUBNET, network.configuration().type()); - assertTrue(network.configuration() instanceof SubnetNetworkConfiguration); - assertFalse(network.configuration().autoCreateSubnetworks()); + Network network = compute.getNetwork(networkId.getNetwork()); + assertEquals(networkId.getNetwork(), network.getNetworkId().getNetwork()); + assertNotNull(network.getGeneratedId()); + assertNotNull(network.getCreationTimestamp()); + assertEquals(NetworkConfiguration.Type.SUBNET, network.getConfiguration().getType()); + assertTrue(network.getConfiguration() instanceof SubnetNetworkConfiguration); + assertFalse(network.getConfiguration().autoCreateSubnetworks()); String subnetworkName = BASE_RESOURCE_NAME + "create-subnetwork-subnetwork"; SubnetworkId subnetworkId = SubnetworkId.of(REGION, subnetworkName); SubnetworkInfo subnetworkInfo = SubnetworkInfo.of(subnetworkId, networkId, "192.168.0.0/16"); @@ -1416,21 +1417,21 @@ public void testCreateNetworkAndSubnetwork() throws InterruptedException, Timeou // test get subnetwork with selected fields Subnetwork subnetwork = compute.getSubnetwork(subnetworkId, Compute.SubnetworkOption.fields(Compute.SubnetworkField.CREATION_TIMESTAMP)); - assertNull(subnetwork.generatedId()); - assertEquals(subnetworkId.subnetwork(), subnetwork.subnetworkId().subnetwork()); - assertNotNull(subnetwork.creationTimestamp()); - assertNull(subnetwork.description()); - assertNull(subnetwork.gatewayAddress()); - assertNull(subnetwork.network()); - assertNull(subnetwork.ipRange()); + assertNull(subnetwork.getGeneratedId()); + assertEquals(subnetworkId.getSubnetwork(), subnetwork.getSubnetworkId().getSubnetwork()); + assertNotNull(subnetwork.getCreationTimestamp()); + assertNull(subnetwork.getDescription()); + assertNull(subnetwork.getGatewayAddress()); + assertNull(subnetwork.getNetwork()); + assertNull(subnetwork.getIpRange()); // test get subnetwork subnetwork = compute.getSubnetwork(subnetworkId); - assertNotNull(subnetwork.generatedId()); - assertEquals(subnetworkId.subnetwork(), subnetwork.subnetworkId().subnetwork()); - assertNotNull(subnetwork.creationTimestamp()); - assertNotNull(subnetwork.gatewayAddress()); - assertEquals(networkId.network(), subnetwork.network().network()); - assertEquals("192.168.0.0/16", subnetwork.ipRange()); + assertNotNull(subnetwork.getGeneratedId()); + assertEquals(subnetworkId.getSubnetwork(), subnetwork.getSubnetworkId().getSubnetwork()); + assertNotNull(subnetwork.getCreationTimestamp()); + assertNotNull(subnetwork.getGatewayAddress()); + assertEquals(networkId.getNetwork(), subnetwork.getNetwork().getNetwork()); + assertEquals("192.168.0.0/16", subnetwork.getIpRange()); // test list subnetworks Compute.SubnetworkFilter filter = Compute.SubnetworkFilter.equals(Compute.SubnetworkField.NAME, subnetworkName); @@ -1440,12 +1441,13 @@ public void testCreateNetworkAndSubnetwork() throws InterruptedException, Timeou int count = 0; while (subnetworkIterator.hasNext()) { Subnetwork remoteSubnetwork = subnetworkIterator.next(); - assertNotNull(remoteSubnetwork.generatedId()); - assertEquals(subnetworkId.subnetwork(), remoteSubnetwork.subnetworkId().subnetwork()); - assertNotNull(remoteSubnetwork.creationTimestamp()); - assertNotNull(remoteSubnetwork.gatewayAddress()); - assertEquals(networkId.network(), remoteSubnetwork.network().network()); - assertEquals("192.168.0.0/16", remoteSubnetwork.ipRange()); + assertNotNull(remoteSubnetwork.getGeneratedId()); + assertEquals(subnetworkId.getSubnetwork(), + remoteSubnetwork.getSubnetworkId().getSubnetwork()); + assertNotNull(remoteSubnetwork.getCreationTimestamp()); + assertNotNull(remoteSubnetwork.getGatewayAddress()); + assertEquals(networkId.getNetwork(), remoteSubnetwork.getNetwork().getNetwork()); + assertEquals("192.168.0.0/16", remoteSubnetwork.getIpRange()); count++; } assertEquals(1, count); @@ -1456,13 +1458,14 @@ public void testCreateNetworkAndSubnetwork() throws InterruptedException, Timeou count = 0; while (subnetworkIterator.hasNext()) { Subnetwork remoteSubnetwork = subnetworkIterator.next(); - assertNull(remoteSubnetwork.generatedId()); - assertEquals(subnetworkId.subnetwork(), remoteSubnetwork.subnetworkId().subnetwork()); - assertNotNull(remoteSubnetwork.creationTimestamp()); - assertNull(remoteSubnetwork.description()); - assertNull(remoteSubnetwork.gatewayAddress()); - assertNull(remoteSubnetwork.network()); - assertNull(remoteSubnetwork.ipRange()); + assertNull(remoteSubnetwork.getGeneratedId()); + assertEquals(subnetworkId.getSubnetwork(), + remoteSubnetwork.getSubnetworkId().getSubnetwork()); + assertNotNull(remoteSubnetwork.getCreationTimestamp()); + assertNull(remoteSubnetwork.getDescription()); + assertNull(remoteSubnetwork.getGatewayAddress()); + assertNull(remoteSubnetwork.getNetwork()); + assertNull(remoteSubnetwork.getIpRange()); count++; } assertEquals(1, count); @@ -1506,13 +1509,13 @@ public void testAggregatedListSubnetworks() throws InterruptedException, Timeout int count = 0; while (subnetworkIterator.hasNext()) { Subnetwork remoteSubnetwork = subnetworkIterator.next(); - assertNotNull(remoteSubnetwork.generatedId()); - assertTrue(regionSet.contains(remoteSubnetwork.subnetworkId().region())); - assertTrue(subnetworkSet.contains(remoteSubnetwork.subnetworkId().subnetwork())); - assertNotNull(remoteSubnetwork.creationTimestamp()); - assertNotNull(remoteSubnetwork.gatewayAddress()); - assertEquals(networkId.network(), remoteSubnetwork.network().network()); - assertTrue(rangeSet.contains(remoteSubnetwork.ipRange())); + assertNotNull(remoteSubnetwork.getGeneratedId()); + assertTrue(regionSet.contains(remoteSubnetwork.getSubnetworkId().getRegion())); + assertTrue(subnetworkSet.contains(remoteSubnetwork.getSubnetworkId().getSubnetwork())); + assertNotNull(remoteSubnetwork.getCreationTimestamp()); + assertNotNull(remoteSubnetwork.getGatewayAddress()); + assertEquals(networkId.getNetwork(), remoteSubnetwork.getNetwork().getNetwork()); + assertTrue(rangeSet.contains(remoteSubnetwork.getIpRange())); count++; } assertEquals(2, count); @@ -1538,64 +1541,68 @@ public void testCreateGetAndDeleteInstance() throws InterruptedException, Timeou // Create an instance InstanceId instanceId = InstanceId.of(ZONE, instanceName); NetworkId networkId = NetworkId.of("default"); - NetworkInterface networkInterface = NetworkInterface.builder(networkId) - .accessConfigurations(NetworkInterface.AccessConfig.builder().name("NAT").natIp(address.address()).build()) + NetworkInterface networkInterface = NetworkInterface.newBuilder(networkId) + .setAccessConfigurations(NetworkInterface.AccessConfig.newBuilder() + .setName("NAT") + .setNatIp(address.getAddress()).build()) .build(); AttachedDisk disk1 = AttachedDisk.of("dev0", - AttachedDisk.CreateDiskConfiguration.builder(IMAGE_ID).autoDelete(true).build()); + AttachedDisk.CreateDiskConfiguration.newBuilder(IMAGE_ID).setAutoDelete(true).build()); AttachedDisk disk2 = - AttachedDisk.of("dev1", AttachedDisk.ScratchDiskConfiguration.of(DiskTypeId.of(ZONE, DISK_TYPE))); + AttachedDisk.of("dev1", + AttachedDisk.ScratchDiskConfiguration.of(DiskTypeId.of(ZONE, DISK_TYPE))); InstanceInfo instanceInfo = - InstanceInfo.builder(instanceId, MachineTypeId.of(ZONE, "n1-standard-1")) - .attachedDisks(disk1, disk2) - .networkInterfaces(networkInterface) + InstanceInfo.newBuilder(instanceId, MachineTypeId.of(ZONE, "n1-standard-1")) + .setAttachedDisks(disk1, disk2) + .setNetworkInterfaces(networkInterface) .build(); operation = compute.create(instanceInfo); operation.waitFor(); // test get Instance remoteInstance = compute.getInstance(instanceId); - assertEquals(instanceName, remoteInstance.instanceId().instance()); - assertEquals(ZONE, remoteInstance.instanceId().zone()); - assertEquals(InstanceInfo.Status.RUNNING, remoteInstance.status()); - assertEquals("n1-standard-1", remoteInstance.machineType().type()); - assertEquals(ZONE, remoteInstance.machineType().zone()); - assertNotNull(remoteInstance.creationTimestamp()); + assertEquals(instanceName, remoteInstance.getInstanceId().getInstance()); + assertEquals(ZONE, remoteInstance.getInstanceId().getZone()); + assertEquals(InstanceInfo.Status.RUNNING, remoteInstance.getStatus()); + assertEquals("n1-standard-1", remoteInstance.getMachineType().getType()); + assertEquals(ZONE, remoteInstance.getMachineType().getZone()); + assertNotNull(remoteInstance.getCreationTimestamp()); Set deviceSet = ImmutableSet.of("dev0", "dev1"); - assertEquals(2, remoteInstance.attachedDisks().size()); - for (AttachedDisk remoteAttachedDisk : remoteInstance.attachedDisks()) { - assertTrue(deviceSet.contains(remoteAttachedDisk.deviceName())); + assertEquals(2, remoteInstance.getAttachedDisks().size()); + for (AttachedDisk remoteAttachedDisk : remoteInstance.getAttachedDisks()) { + assertTrue(deviceSet.contains(remoteAttachedDisk.getDeviceName())); } - Assert.assertEquals(AttachedDisk.AttachedDiskConfiguration.Type.PERSISTENT, - remoteInstance.attachedDisks().get(0).configuration().type()); + assertEquals(AttachedDisk.AttachedDiskConfiguration.Type.PERSISTENT, + remoteInstance.getAttachedDisks().get(0).getConfiguration().getType()); AttachedDisk.PersistentDiskConfiguration remoteConfiguration = - remoteInstance.attachedDisks().get(0).configuration(); - assertEquals(instanceName, remoteConfiguration.sourceDisk().disk()); - assertEquals(ZONE, remoteConfiguration.sourceDisk().zone()); + remoteInstance.getAttachedDisks().get(0).getConfiguration(); + assertEquals(instanceName, remoteConfiguration.getSourceDisk().getDisk()); + assertEquals(ZONE, remoteConfiguration.getSourceDisk().getZone()); assertTrue(remoteConfiguration.boot()); assertTrue(remoteConfiguration.autoDelete()); - assertEquals(1, remoteInstance.networkInterfaces().size()); - NetworkInterface remoteNetworkInterface = remoteInstance.networkInterfaces().get(0); - assertNotNull(remoteNetworkInterface.name()); - assertEquals("default", remoteNetworkInterface.network().network()); - List remoteAccessConfigurations = remoteNetworkInterface.accessConfigurations(); + assertEquals(1, remoteInstance.getNetworkInterfaces().size()); + NetworkInterface remoteNetworkInterface = remoteInstance.getNetworkInterfaces().get(0); + assertNotNull(remoteNetworkInterface.getName()); + assertEquals("default", remoteNetworkInterface.getNetwork().getNetwork()); + List remoteAccessConfigurations = + remoteNetworkInterface.getAccessConfigurations(); assertNotNull(remoteAccessConfigurations); assertEquals(1, remoteAccessConfigurations.size()); NetworkInterface.AccessConfig remoteAccessConfig = remoteAccessConfigurations.get(0); - assertEquals(address.address(), remoteAccessConfig.natIp()); - assertEquals("NAT", remoteAccessConfig.name()); - assertNotNull(remoteInstance.metadata()); - assertNotNull(remoteInstance.tags()); + assertEquals(address.getAddress(), remoteAccessConfig.getNatIp()); + assertEquals("NAT", remoteAccessConfig.getName()); + assertNotNull(remoteInstance.getMetadata()); + assertNotNull(remoteInstance.getTags()); // test get with selected fields remoteInstance = compute.getInstance(instanceId, Compute.InstanceOption.fields(Compute.InstanceField.CREATION_TIMESTAMP)); - assertEquals(instanceName, remoteInstance.instanceId().instance()); - assertEquals(ZONE, remoteInstance.instanceId().zone()); - assertNull(remoteInstance.machineType()); - assertNotNull(remoteInstance.creationTimestamp()); - assertNull(remoteInstance.attachedDisks()); - assertNull(remoteInstance.networkInterfaces()); - assertNull(remoteInstance.metadata()); - assertNull(remoteInstance.tags()); + assertEquals(instanceName, remoteInstance.getInstanceId().getInstance()); + assertEquals(ZONE, remoteInstance.getInstanceId().getZone()); + assertNull(remoteInstance.getMachineType()); + assertNotNull(remoteInstance.getCreationTimestamp()); + assertNull(remoteInstance.getAttachedDisks()); + assertNull(remoteInstance.getNetworkInterfaces()); + assertNull(remoteInstance.getMetadata()); + assertNull(remoteInstance.getTags()); // test get default serial port output String serialPortOutput = remoteInstance.getSerialPortOutput(); assertNotNull(serialPortOutput); @@ -1613,34 +1620,34 @@ public void testStartStopAndResetInstance() throws InterruptedException, Timeout String instanceName = BASE_RESOURCE_NAME + "start-stop-reset-instance"; InstanceId instanceId = InstanceId.of(ZONE, instanceName); NetworkId networkId = NetworkId.of("default"); - NetworkInterface networkInterface = NetworkInterface.builder(networkId).build(); + NetworkInterface networkInterface = NetworkInterface.newBuilder(networkId).build(); AttachedDisk disk = AttachedDisk.of("dev0", - AttachedDisk.CreateDiskConfiguration.builder(IMAGE_ID).autoDelete(true).build()); + AttachedDisk.CreateDiskConfiguration.newBuilder(IMAGE_ID).setAutoDelete(true).build()); InstanceInfo instanceInfo = - InstanceInfo.builder(instanceId, MachineTypeId.of(ZONE, MACHINE_TYPE)) - .attachedDisks(disk) - .networkInterfaces(networkInterface) + InstanceInfo.newBuilder(instanceId, MachineTypeId.of(ZONE, MACHINE_TYPE)) + .setAttachedDisks(disk) + .setNetworkInterfaces(networkInterface) .build(); Operation operation = compute.create(instanceInfo); operation.waitFor(); Instance remoteInstance = compute.getInstance(instanceId, Compute.InstanceOption.fields(Compute.InstanceField.STATUS)); - assertEquals(InstanceInfo.Status.RUNNING, remoteInstance.status()); + assertEquals(InstanceInfo.Status.RUNNING, remoteInstance.getStatus()); operation = remoteInstance.stop(); operation.waitFor(); remoteInstance = compute.getInstance(instanceId, Compute.InstanceOption.fields(Compute.InstanceField.STATUS)); - assertEquals(InstanceInfo.Status.TERMINATED, remoteInstance.status()); + assertEquals(InstanceInfo.Status.TERMINATED, remoteInstance.getStatus()); operation = remoteInstance.start(); operation.waitFor(); remoteInstance = compute.getInstance(instanceId, Compute.InstanceOption.fields(Compute.InstanceField.STATUS)); - assertEquals(InstanceInfo.Status.RUNNING, remoteInstance.status()); + assertEquals(InstanceInfo.Status.RUNNING, remoteInstance.getStatus()); operation = remoteInstance.reset(); operation.waitFor(); remoteInstance = compute.getInstance(instanceId, Compute.InstanceOption.fields(Compute.InstanceField.STATUS)); - assertEquals(InstanceInfo.Status.RUNNING, remoteInstance.status()); + assertEquals(InstanceInfo.Status.RUNNING, remoteInstance.getStatus()); remoteInstance.delete(); } @@ -1649,13 +1656,13 @@ public void testSetInstanceProperties() throws InterruptedException, TimeoutExce String instanceName = BASE_RESOURCE_NAME + "set-properties-instance"; InstanceId instanceId = InstanceId.of(ZONE, instanceName); NetworkId networkId = NetworkId.of("default"); - NetworkInterface networkInterface = NetworkInterface.builder(networkId).build(); + NetworkInterface networkInterface = NetworkInterface.newBuilder(networkId).build(); AttachedDisk disk = AttachedDisk.of("dev0", - AttachedDisk.CreateDiskConfiguration.builder(IMAGE_ID).autoDelete(true).build()); + AttachedDisk.CreateDiskConfiguration.newBuilder(IMAGE_ID).setAutoDelete(true).build()); InstanceInfo instanceInfo = - InstanceInfo.builder(instanceId, MachineTypeId.of(ZONE, MACHINE_TYPE)) - .attachedDisks(disk) - .networkInterfaces(networkInterface) + InstanceInfo.newBuilder(instanceId, MachineTypeId.of(ZONE, MACHINE_TYPE)) + .setAttachedDisks(disk) + .setNetworkInterfaces(networkInterface) .build(); Operation operation = compute.create(instanceInfo); operation.waitFor(); @@ -1665,27 +1672,28 @@ public void testSetInstanceProperties() throws InterruptedException, TimeoutExce operation = remoteInstance.setTags(tags); operation.waitFor(); remoteInstance = compute.getInstance(instanceId); - assertEquals(tags, remoteInstance.tags().values()); + assertEquals(tags, remoteInstance.getTags().getValues()); // test set metadata Map metadata = ImmutableMap.of("key", "value"); operation = remoteInstance.setMetadata(metadata); operation.waitFor(); remoteInstance = compute.getInstance(instanceId); - assertEquals(metadata, remoteInstance.metadata().values()); + assertEquals(metadata, remoteInstance.getMetadata().getValues()); // test set machine type operation = remoteInstance.stop(); operation.waitFor(); operation = remoteInstance.setMachineType(MachineTypeId.of(ZONE, "n1-standard-1")); operation.waitFor(); remoteInstance = compute.getInstance(instanceId); - assertEquals("n1-standard-1", remoteInstance.machineType().type()); - assertEquals(ZONE, remoteInstance.machineType().zone()); + assertEquals("n1-standard-1", remoteInstance.getMachineType().getType()); + assertEquals(ZONE, remoteInstance.getMachineType().getZone()); // test set scheduling options - SchedulingOptions options = SchedulingOptions.standard(false, SchedulingOptions.Maintenance.TERMINATE); + SchedulingOptions options = + SchedulingOptions.standard(false, SchedulingOptions.Maintenance.TERMINATE); operation = remoteInstance.setSchedulingOptions(options); operation.waitFor(); remoteInstance = compute.getInstance(instanceId); - assertEquals(options, remoteInstance.schedulingOptions()); + assertEquals(options, remoteInstance.getSchedulingOptions()); remoteInstance.delete(); } @@ -1695,13 +1703,13 @@ public void testAttachAndDetachDisk() throws InterruptedException, TimeoutExcept String diskName = BASE_RESOURCE_NAME + "attach-and-detach-disk"; InstanceId instanceId = InstanceId.of(ZONE, instanceName); NetworkId networkId = NetworkId.of("default"); - NetworkInterface networkInterface = NetworkInterface.builder(networkId).build(); + NetworkInterface networkInterface = NetworkInterface.newBuilder(networkId).build(); AttachedDisk disk = AttachedDisk.of("dev0", - AttachedDisk.CreateDiskConfiguration.builder(IMAGE_ID).autoDelete(true).build()); + AttachedDisk.CreateDiskConfiguration.newBuilder(IMAGE_ID).setAutoDelete(true).build()); InstanceInfo instanceInfo = - InstanceInfo.builder(instanceId, MachineTypeId.of(ZONE, MACHINE_TYPE)) - .attachedDisks(disk) - .networkInterfaces(networkInterface) + InstanceInfo.newBuilder(instanceId, MachineTypeId.of(ZONE, MACHINE_TYPE)) + .setAttachedDisks(disk) + .setNetworkInterfaces(networkInterface) .build(); Operation instanceOperation = compute.create(instanceInfo); DiskId diskId = DiskId.of(ZONE, diskName); @@ -1712,29 +1720,29 @@ public void testAttachAndDetachDisk() throws InterruptedException, TimeoutExcept Instance remoteInstance = compute.getInstance(instanceId); // test attach disk instanceOperation = remoteInstance.attachDisk("dev1", - AttachedDisk.PersistentDiskConfiguration.builder(diskId).build()); + AttachedDisk.PersistentDiskConfiguration.newBuilder(diskId).build()); instanceOperation.waitFor(); remoteInstance = compute.getInstance(instanceId); Set deviceSet = ImmutableSet.of("dev0", "dev1"); - assertEquals(2, remoteInstance.attachedDisks().size()); - for (AttachedDisk remoteAttachedDisk : remoteInstance.attachedDisks()) { - assertTrue(deviceSet.contains(remoteAttachedDisk.deviceName())); + assertEquals(2, remoteInstance.getAttachedDisks().size()); + for (AttachedDisk remoteAttachedDisk : remoteInstance.getAttachedDisks()) { + assertTrue(deviceSet.contains(remoteAttachedDisk.getDeviceName())); } // test set disk auto-delete instanceOperation = remoteInstance.setDiskAutoDelete("dev1", true); instanceOperation.waitFor(); remoteInstance = compute.getInstance(instanceId); - assertEquals(2, remoteInstance.attachedDisks().size()); - for (AttachedDisk remoteAttachedDisk : remoteInstance.attachedDisks()) { - assertTrue(deviceSet.contains(remoteAttachedDisk.deviceName())); - assertTrue(remoteAttachedDisk.configuration().autoDelete()); + assertEquals(2, remoteInstance.getAttachedDisks().size()); + for (AttachedDisk remoteAttachedDisk : remoteInstance.getAttachedDisks()) { + assertTrue(deviceSet.contains(remoteAttachedDisk.getDeviceName())); + assertTrue(remoteAttachedDisk.getConfiguration().autoDelete()); } // test detach disk instanceOperation = remoteInstance.detachDisk("dev1"); instanceOperation.waitFor(); remoteInstance = compute.getInstance(instanceId); - assertEquals(1, remoteInstance.attachedDisks().size()); - assertEquals("dev0", remoteInstance.attachedDisks().get(0).deviceName()); + assertEquals(1, remoteInstance.getAttachedDisks().size()); + assertEquals("dev0", remoteInstance.getAttachedDisks().get(0).getDeviceName()); remoteInstance.delete(); compute.deleteDisk(diskId); } @@ -1745,13 +1753,13 @@ public void testAddAndRemoveAccessConfig() throws InterruptedException, TimeoutE String addressName = BASE_RESOURCE_NAME + "add-and-remove-access-address"; InstanceId instanceId = InstanceId.of(ZONE, instanceName); NetworkId networkId = NetworkId.of("default"); - NetworkInterface networkInterface = NetworkInterface.builder(networkId).build(); + NetworkInterface networkInterface = NetworkInterface.newBuilder(networkId).build(); AttachedDisk disk = AttachedDisk.of("dev0", - AttachedDisk.CreateDiskConfiguration.builder(IMAGE_ID).autoDelete(true).build()); + AttachedDisk.CreateDiskConfiguration.newBuilder(IMAGE_ID).setAutoDelete(true).build()); InstanceInfo instanceInfo = - InstanceInfo.builder(instanceId, MachineTypeId.of(ZONE, MACHINE_TYPE)) - .attachedDisks(disk) - .networkInterfaces(networkInterface) + InstanceInfo.newBuilder(instanceId, MachineTypeId.of(ZONE, MACHINE_TYPE)) + .setAttachedDisks(disk) + .setNetworkInterfaces(networkInterface) .build(); Operation instanceOperation = compute.create(instanceInfo); AddressId addressId = RegionAddressId.of(REGION, addressName); @@ -1761,24 +1769,24 @@ public void testAddAndRemoveAccessConfig() throws InterruptedException, TimeoutE instanceOperation.waitFor(); Address remoteAddress = compute.getAddress(addressId); Instance remoteInstance = compute.getInstance(instanceId); - String networkInterfaceName = remoteInstance.networkInterfaces().get(0).name(); + String networkInterfaceName = remoteInstance.getNetworkInterfaces().get(0).getName(); // test add access config - NetworkInterface.AccessConfig accessConfig = NetworkInterface.AccessConfig.builder() - .natIp(remoteAddress.address()) - .name("NAT") + NetworkInterface.AccessConfig accessConfig = NetworkInterface.AccessConfig.newBuilder() + .setNatIp(remoteAddress.getAddress()) + .setName("NAT") .build(); instanceOperation = remoteInstance.addAccessConfig(networkInterfaceName, accessConfig); instanceOperation.waitFor(); remoteInstance = compute.getInstance(instanceId); List accessConfigurations = - remoteInstance.networkInterfaces().get(0).accessConfigurations(); + remoteInstance.getNetworkInterfaces().get(0).getAccessConfigurations(); assertEquals(1, accessConfigurations.size()); - assertEquals("NAT", accessConfigurations.get(0).name()); + assertEquals("NAT", accessConfigurations.get(0).getName()); // test delete access config instanceOperation = remoteInstance.deleteAccessConfig(networkInterfaceName, "NAT"); instanceOperation.waitFor(); remoteInstance = compute.getInstance(instanceId); - assertTrue(remoteInstance.networkInterfaces().get(0).accessConfigurations().isEmpty()); + assertTrue(remoteInstance.getNetworkInterfaces().get(0).getAccessConfigurations().isEmpty()); remoteInstance.delete(); remoteAddress.delete(); } diff --git a/google-cloud-compute/src/test/java/com/google/cloud/compute/testing/RemoteComputeHelperTest.java b/google-cloud-compute/src/test/java/com/google/cloud/compute/testing/RemoteComputeHelperTest.java index 947bd4f1ea8c..5e57e658d509 100644 --- a/google-cloud-compute/src/test/java/com/google/cloud/compute/testing/RemoteComputeHelperTest.java +++ b/google-cloud-compute/src/test/java/com/google/cloud/compute/testing/RemoteComputeHelperTest.java @@ -74,7 +74,8 @@ public void testBaseResourceName() { @Test public void testCreateFromStream() { RemoteComputeHelper helper = RemoteComputeHelper.create(PROJECT_ID, JSON_KEY_STREAM); - ComputeOptions options = helper.options(); + ComputeOptions options = helper.getOptions(); + assertEquals(options, helper.options()); assertEquals(PROJECT_ID, options.projectId()); assertEquals(60000, options.connectTimeout()); assertEquals(60000, options.readTimeout()); diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/compute/ComputeExample.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/compute/ComputeExample.java index 7d8fbd2e228d..bea18bedc3c0 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/compute/ComputeExample.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/compute/ComputeExample.java @@ -308,7 +308,7 @@ private static class ListDiskTypesAction extends OptionalZoneAction { public void run(Compute compute, ZoneId zone) { Iterator diskTypeIterator; if (zone != null) { - diskTypeIterator = compute.listDiskTypes(zone.zone()).iterateAll(); + diskTypeIterator = compute.listDiskTypes(zone.getZone()).iterateAll(); } else { diskTypeIterator = compute.listDiskTypes().iterateAll(); } @@ -363,7 +363,7 @@ private static class ListMachineTypesAction extends OptionalZoneAction { public void run(Compute compute, ZoneId zone) { Iterator machineTypeIterator; if (zone != null) { - machineTypeIterator = compute.listMachineTypes(zone.zone()).iterateAll(); + machineTypeIterator = compute.listMachineTypes(zone.getZone()).iterateAll(); } else { machineTypeIterator = compute.listMachineTypes().iterateAll(); } @@ -429,7 +429,7 @@ public void run(Compute compute, Void arg) { private static class RegionInfoAction extends ComputeAction { @Override public void run(Compute compute, RegionId region) { - System.out.printf("Region info: %s%n", compute.getRegion(region.region())); + System.out.printf("Region info: %s%n", compute.getRegion(region.getRegion())); } @Override @@ -475,7 +475,7 @@ public void run(Compute compute, Void arg) { private static class ZoneInfoAction extends ComputeAction { @Override public void run(Compute compute, ZoneId zone) { - System.out.printf("Zone info: %s%n", compute.getZone(zone.zone())); + System.out.printf("Zone info: %s%n", compute.getZone(zone.getZone())); } @Override @@ -506,7 +506,7 @@ public String params() { private static class LicenseInfoAction extends ComputeAction { @Override public void run(Compute compute, LicenseId license) { - System.out.printf("License info: %s%n", compute.getLicense(license.license())); + System.out.printf("License info: %s%n", compute.getLicense(license.getLicense())); } @Override @@ -553,7 +553,8 @@ public void run(Compute compute, Void arg) { private static class ListZoneOperationsAction extends ComputeAction { @Override public void run(Compute compute, ZoneId zone) { - Iterator operationIterator = compute.listZoneOperations(zone.zone()).iterateAll(); + Iterator operationIterator = + compute.listZoneOperations(zone.getZone()).iterateAll(); while (operationIterator.hasNext()) { System.out.println(operationIterator.next()); } @@ -588,7 +589,7 @@ private static class ListRegionOperationsAction extends ComputeAction @Override public void run(Compute compute, RegionId region) { Iterator operationIterator = - compute.listRegionOperations(region.region()).iterateAll(); + compute.listRegionOperations(region.getRegion()).iterateAll(); while (operationIterator.hasNext()) { System.out.println(operationIterator.next()); } @@ -776,7 +777,7 @@ private static class ListAddressesAction extends OptionalRegionAction { public void run(Compute compute, RegionId region) { Iterator
addressIterator; if (region != null) { - addressIterator = compute.listRegionAddresses(region.region()).iterateAll(); + addressIterator = compute.listRegionAddresses(region.getRegion()).iterateAll(); } else { addressIterator = compute.listAddresses().iterateAll(); } @@ -841,15 +842,15 @@ public void run(Compute compute, AddressId address) throws InterruptedException } while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Address %s was deleted%n", address); } else { System.out.printf("Deletion of address %s failed%n", address); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } } @@ -868,15 +869,15 @@ public void run(Compute compute, AddressId address) throws InterruptedException Operation operation = compute.create(AddressInfo.of(address)); while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Address %s was created%n", address); } else { System.out.printf("Creation of address %s failed%n", address); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } } @@ -926,7 +927,7 @@ public String params() { private static class SnapshotInfoAction extends SnapshotAction { @Override public void run(Compute compute, SnapshotId snapshot) { - System.out.printf("Snapshot info: %s%n", compute.getSnapshot(snapshot.snapshot())); + System.out.printf("Snapshot info: %s%n", compute.getSnapshot(snapshot.getSnapshot())); } } @@ -939,22 +940,22 @@ public void run(Compute compute, SnapshotId snapshot) { private static class DeleteSnapshotAction extends SnapshotAction { @Override public void run(Compute compute, SnapshotId snapshot) throws InterruptedException { - Operation operation = compute.deleteSnapshot(snapshot.snapshot()); + Operation operation = compute.deleteSnapshot(snapshot.getSnapshot()); if (operation == null) { System.out.printf("Snapshot %s does not exist%n", snapshot); return; } while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Snapshot %s was deleted%n", snapshot); } else { System.out.printf("Deletion of snapshot %s failed%n", snapshot); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } } @@ -971,15 +972,15 @@ public void run(Compute compute, SnapshotInfo snapshot) throws InterruptedExcept Operation operation = compute.create(snapshot); while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { - System.out.printf("Snapshot %s was created%n", snapshot.snapshotId()); + if (operation.getErrors() == null) { + System.out.printf("Snapshot %s was created%n", snapshot.getSnapshotId()); } else { - System.out.printf("Creation of snapshot %s failed%n", snapshot.snapshotId()); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Creation of snapshot %s failed%n", snapshot.getSnapshotId()); + System.out.printf("Error: %s%n", operation.getErrors()); } } @@ -1070,15 +1071,15 @@ public void run(Compute compute, ImageId image) throws InterruptedException { } while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Image %s was deleted%n", image); } else { System.out.printf("Deletion of image %s failed%n", image); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } } @@ -1095,15 +1096,15 @@ public void run(Compute compute, ImageInfo image) throws InterruptedException { Operation operation = compute.create(image); while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { - System.out.printf("Image %s was created%n", image.imageId()); + if (operation.getErrors() == null) { + System.out.printf("Image %s was created%n", image.getImageId()); } else { - System.out.printf("Creation of image %s failed%n", image.imageId()); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Creation of image %s failed%n", image.getImageId()); + System.out.printf("Error: %s%n", operation.getErrors()); } } @@ -1178,15 +1179,15 @@ public void run(Compute compute, DiskId disk) throws InterruptedException { } while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Disk %s was deleted%n", disk); } else { System.out.printf("Deletion of disk %s failed%n", disk); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } } @@ -1213,15 +1214,15 @@ public void run(Compute compute, DiskInfo disk) throws InterruptedException { Operation operation = compute.create(disk); while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { - System.out.printf("Disk %s was created%n", disk.diskId()); + if (operation.getErrors() == null) { + System.out.printf("Disk %s was created%n", disk.getDiskId()); } else { - System.out.printf("Creation of disk %s failed%n", disk.diskId()); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Creation of disk %s failed%n", disk.getDiskId()); + System.out.printf("Error: %s%n", operation.getErrors()); } } @@ -1245,13 +1246,13 @@ DiskInfo parse(String... args) throws Exception { DiskConfiguration configuration; if (args.length == 4) { try { - configuration = StandardDiskConfiguration.of(DiskTypeId.of(diskId.zone(), diskType), + configuration = StandardDiskConfiguration.of(DiskTypeId.of(diskId.getZone(), diskType), Integer.parseInt(args[3])); } catch (NumberFormatException ex) { throw new IllegalArgumentException("Error parsing disk size parameter."); } } else if (args.length == 3) { - configuration = StandardDiskConfiguration.of(DiskTypeId.of(diskId.zone(), diskType)); + configuration = StandardDiskConfiguration.of(DiskTypeId.of(diskId.getZone(), diskType)); } else { throw new IllegalArgumentException("Too many arguments."); } @@ -1365,7 +1366,7 @@ public String params() { private static class NetworkInfoAction extends NetworkAction { @Override public void run(Compute compute, NetworkId network) { - System.out.printf("Network info: %s%n", compute.getNetwork(network.network())); + System.out.printf("Network info: %s%n", compute.getNetwork(network.getNetwork())); } } @@ -1378,22 +1379,22 @@ public void run(Compute compute, NetworkId network) { private static class DeleteNetworkAction extends NetworkAction { @Override public void run(Compute compute, NetworkId network) throws InterruptedException { - Operation operation = compute.deleteNetwork(network.network()); + Operation operation = compute.deleteNetwork(network.getNetwork()); if (operation == null) { System.out.printf("Network %s does not exist%n", network); return; } while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Network %s was deleted%n", network); } else { System.out.printf("Deletion of network %s failed%n", network); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } } @@ -1404,15 +1405,15 @@ public void run(Compute compute, NetworkInfo network) throws InterruptedExceptio Operation operation = compute.create(network); while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { - System.out.printf("Network %s was created%n", network.networkId()); + if (operation.getErrors() == null) { + System.out.printf("Network %s was created%n", network.getNetworkId()); } else { - System.out.printf("Creation of network %s failed%n", network.networkId()); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Creation of network %s failed%n", network.getNetworkId()); + System.out.printf("Error: %s%n", operation.getErrors()); } } } @@ -1491,7 +1492,7 @@ private static class ListSubnetworksAction extends OptionalRegionAction { public void run(Compute compute, RegionId region) { Iterator subnetworkIterator; if (region != null) { - subnetworkIterator = compute.listSubnetworks(region.region()).iterateAll(); + subnetworkIterator = compute.listSubnetworks(region.getRegion()).iterateAll(); } else { subnetworkIterator = compute.listSubnetworks().iterateAll(); } @@ -1550,15 +1551,15 @@ public void run(Compute compute, SubnetworkId subnetwork) throws InterruptedExce } while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Subnetwork %s was deleted%n", subnetwork); } else { System.out.printf("Deletion of subnetwork %s failed%n", subnetwork); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } } @@ -1575,15 +1576,15 @@ public void run(Compute compute, SubnetworkInfo subnetwork) throws InterruptedEx Operation operation = compute.create(subnetwork); while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { - System.out.printf("Subnetwork %s was created%n", subnetwork.subnetworkId()); + if (operation.getErrors() == null) { + System.out.printf("Subnetwork %s was created%n", subnetwork.getSubnetworkId()); } else { - System.out.printf("Creation of subnetwork %s failed%n", subnetwork.subnetworkId()); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Creation of subnetwork %s failed%n", subnetwork.getSubnetworkId()); + System.out.printf("Error: %s%n", operation.getErrors()); } } @@ -1618,7 +1619,7 @@ private static class ListInstancesAction extends OptionalZoneAction { public void run(Compute compute, ZoneId zone) { Iterator instanceIterator; if (zone != null) { - instanceIterator = compute.listInstances(zone.zone()).iterateAll(); + instanceIterator = compute.listInstances(zone.getZone()).iterateAll(); } else { instanceIterator = compute.listInstances().iterateAll(); } @@ -1677,15 +1678,15 @@ public void run(Compute compute, InstanceId instance) throws InterruptedExceptio } while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Instance %s was deleted%n", instance); } else { System.out.printf("Deletion of instance %s failed%n", instance); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } } @@ -1702,15 +1703,15 @@ public void run(Compute compute, InstanceInfo instance) throws InterruptedExcept Operation operation = compute.create(instance); while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { - System.out.printf("Instance %s was created%n", instance.instanceId()); + if (operation.getErrors() == null) { + System.out.printf("Instance %s was created%n", instance.getInstanceId()); } else { - System.out.printf("Creation of instance %s failed%n", instance.instanceId()); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Creation of instance %s failed%n", instance.getInstanceId()); + System.out.printf("Error: %s%n", operation.getErrors()); } } @@ -1724,7 +1725,7 @@ InstanceInfo parse(String... args) throws Exception { MachineTypeId machineTypeId = MachineTypeId.of(zone, args[2]); DiskId diskId = DiskId.of(zone, args[3]); AttachedDisk disk = - AttachedDisk.of(PersistentDiskConfiguration.builder(diskId).boot(true).build()); + AttachedDisk.of(PersistentDiskConfiguration.newBuilder(diskId).setBoot(true).build()); NetworkInterface networkInterface = NetworkInterface.of(args[4]); return InstanceInfo.of(instanceId, machineTypeId, disk, networkInterface); } else if (args.length > 5) { @@ -1813,17 +1814,17 @@ public void run(Compute compute, Triple interf } while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Access config added to network interface %s of instance %s%n", networkInterface, instance); } else { System.out.printf("Attempt to add access config to network interface %s of instance %s%n", networkInterface, instance); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } @@ -1836,10 +1837,10 @@ Triple parse(String... args) throws Exception String accessConfig = args[3]; if (args.length == 4) { return Triple.of(instance, networkInterface, - AccessConfig.builder().name(accessConfig).build()); + AccessConfig.newBuilder().setName(accessConfig).build()); } else if (args.length == 5) { return Triple.of(instance, networkInterface, - AccessConfig.builder().name(accessConfig).natIp(args[4]).build()); + AccessConfig.newBuilder().setName(accessConfig).setNatIp(args[4]).build()); } else { message = "Too many arguments."; } @@ -1877,18 +1878,18 @@ public void run(Compute compute, Triple interfaceAnd } while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Access config deleted from network interface %s of instance %s%n", networkInterface, instance); } else { System.out.printf( "Attempt to delete access config from network interface %s of instance %s failed%n", networkInterface, instance); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } @@ -1935,15 +1936,15 @@ public void run(Compute compute, Triple instanceAndDevice) } while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Disk detached from instance %s%n", instance); } else { System.out.printf("Attempt to detach disk from instance %s failed%n", instance); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } @@ -2046,16 +2047,16 @@ public void run(Compute compute, Triple deviceAndAu } while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Auto-delete set for device %s of instance %s%n", deviceName, instance); } else { System.out.printf("Attempt to set auto-delete for device %s of instance %s failed%n", deviceName, instance); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } @@ -2112,15 +2113,15 @@ public void run(Compute compute, Tuple instanceAndTyp } while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Machine type set for instance %s%n", instance); } else { System.out.printf("Attempt to set machine type for instance %s failed%n", instance); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } @@ -2166,15 +2167,15 @@ public void run(Compute compute, Tuple> instanceAndTags Operation operation = instance.setTags(tags); while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Tags set for instance %s%n", instanceId); } else { System.out.printf("Attempt to set tags for instance %s failed%n", instanceId); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } @@ -2217,15 +2218,15 @@ public void run(Compute compute, Tuple> instance Operation operation = instance.setMetadata(metadata); while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Metadata set for instance %s%n", instanceId); } else { System.out.printf("Attempt to set metadata for instance %s failed%n", instanceId); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } @@ -2272,16 +2273,16 @@ public void run(Compute compute, Tuple instanceAn } while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Scheduling options set for instance %s%n", instanceId); } else { System.out.printf( "Attempt to set scheduling options for instance %s failed%n", instanceId); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } @@ -2338,15 +2339,15 @@ public void run(Compute compute, InstanceId instance) throws InterruptedExceptio } while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Instance %s was reset%n", instance); } else { System.out.printf("Attempt to reset instance %s failed%n", instance); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } } @@ -2367,15 +2368,15 @@ public void run(Compute compute, InstanceId instance) throws InterruptedExceptio } while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Instance %s was stopped%n", instance); } else { System.out.printf("Attempt to stop instance %s failed%n", instance); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } } @@ -2396,15 +2397,15 @@ public void run(Compute compute, InstanceId instance) throws InterruptedExceptio } while (!operation.isDone()) { System.out.printf( - "Waiting for operation %s to complete%n", operation.operationId().operation()); + "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.printf("Instance %s was started%n", instance); } else { System.out.printf("Attempt to start instance %s failed%n", instance); - System.out.printf("Error: %s%n", operation.errors()); + System.out.printf("Error: %s%n", operation.getErrors()); } } } diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/compute/snippets/CreateAddressDiskAndInstance.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/compute/snippets/CreateAddressDiskAndInstance.java index 0a63865904e0..2e0834fa600b 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/compute/snippets/CreateAddressDiskAndInstance.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/compute/snippets/CreateAddressDiskAndInstance.java @@ -53,7 +53,7 @@ public static void main(String... args) throws InterruptedException, TimeoutExce Operation operation = compute.create(AddressInfo.of(addressId)); // Wait for operation to complete operation = operation.waitFor(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.println("Address " + addressId + " was successfully created"); } else { // inspect operation.errors() @@ -68,7 +68,7 @@ public static void main(String... args) throws InterruptedException, TimeoutExce operation = compute.create(disk); // Wait for operation to complete operation = operation.waitFor(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.println("Disk " + diskId + " was successfully created"); } else { // inspect operation.errors() @@ -80,10 +80,10 @@ public static void main(String... args) throws InterruptedException, TimeoutExce InstanceId instanceId = InstanceId.of("us-central1-a", "test-instance"); NetworkId networkId = NetworkId.of("default"); PersistentDiskConfiguration attachConfiguration = - PersistentDiskConfiguration.builder(diskId).boot(true).build(); + PersistentDiskConfiguration.newBuilder(diskId).setBoot(true).build(); AttachedDisk attachedDisk = AttachedDisk.of("dev0", attachConfiguration); - NetworkInterface networkInterface = NetworkInterface.builder(networkId) - .accessConfigurations(AccessConfig.of(externalIp.address())) + NetworkInterface networkInterface = NetworkInterface.newBuilder(networkId) + .setAccessConfigurations(AccessConfig.of(externalIp.getAddress())) .build(); MachineTypeId machineTypeId = MachineTypeId.of("us-central1-a", "n1-standard-1"); InstanceInfo instance = @@ -91,7 +91,7 @@ public static void main(String... args) throws InterruptedException, TimeoutExce operation = compute.create(instance); // Wait for operation to complete operation = operation.waitFor(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { System.out.println("Instance " + instanceId + " was successfully created"); } else { // inspect operation.errors() diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/compute/snippets/CreateInstance.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/compute/snippets/CreateInstance.java index 66c10bace269..0d55dfa3e52f 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/compute/snippets/CreateInstance.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/compute/snippets/CreateInstance.java @@ -46,7 +46,7 @@ public static void main(String... args) throws InterruptedException, TimeoutExce Operation operation = compute.create(InstanceInfo.of(instanceId, machineTypeId, attachedDisk, networkInterface)); operation = operation.waitFor(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { // use instance Instance instance = compute.getInstance(instanceId); } diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/compute/snippets/CreateSnapshot.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/compute/snippets/CreateSnapshot.java index 35d19e38e18e..8c221d6bb5f6 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/compute/snippets/CreateSnapshot.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/compute/snippets/CreateSnapshot.java @@ -39,7 +39,7 @@ public static void main(String... args) throws InterruptedException, TimeoutExce String snapshotName = "disk-name-snapshot"; Operation operation = disk.createSnapshot(snapshotName); operation = operation.waitFor(); - if (operation.errors() == null) { + if (operation.getErrors() == null) { // use snapshot Snapshot snapshot = compute.getSnapshot(snapshotName); }