@Test public void testToBuilder() { compareSnapshotDiskConfiguration(DISK_CONFIGURATION, DISK_CONFIGURATION.toBuilder().build()); SnapshotId newSnapshot = SnapshotId.of("newProject", "newSnapshot"); SnapshotDiskConfiguration diskConfiguration = DISK_CONFIGURATION .toBuilder() .setSizeGb(24L) .setSourceSnapshot(newSnapshot) .setSourceSnapshotId("newSnapshotId") .build(); assertEquals(24L, diskConfiguration.getSizeGb().longValue()); assertEquals(newSnapshot, diskConfiguration.getSourceSnapshot()); assertEquals("newSnapshotId", diskConfiguration.getSourceSnapshotId()); diskConfiguration = diskConfiguration .toBuilder() .setSizeGb(SIZE) .setSourceSnapshot(SNAPSHOT) .setSourceSnapshotId(SNAPSHOT_ID) .build(); compareSnapshotDiskConfiguration(DISK_CONFIGURATION, diskConfiguration); }
.setDiskType(DiskTypeId.of(TYPE.getZone(), TYPE.getType())) .setSourceSnapshot(SnapshotId.of(SNAPSHOT.getSnapshot())) .build(); diskInfo = SNAPSHOT_DISK_INFO
/** Returns a {@code SnapshotDiskConfiguration} object given the snapshot identity. */ public static SnapshotDiskConfiguration of(SnapshotId sourceSnapshot) { return newBuilder(sourceSnapshot).build(); }
@Test public void testToBuilderIncomplete() { SnapshotDiskConfiguration diskConfiguration = SnapshotDiskConfiguration.of(SNAPSHOT); compareSnapshotDiskConfiguration(diskConfiguration, diskConfiguration.toBuilder().build()); }
@SuppressWarnings("unchecked") static SnapshotDiskConfiguration fromPb(Disk diskPb) { return new Builder(diskPb).build(); } }
@Test public void testSetProjectId() { SnapshotDiskConfiguration configuration = DISK_CONFIGURATION .toBuilder() .setDiskType(DiskTypeId.of(DISK_TYPE.getZone(), DISK_TYPE.getType())) .setSourceSnapshot(SnapshotId.of(SNAPSHOT.getSnapshot())) .build(); compareSnapshotDiskConfiguration(DISK_CONFIGURATION, configuration.setProjectId("project")); }
@Override SnapshotDiskConfiguration setProjectId(String projectId) { Builder builder = toBuilder().setSourceSnapshot(sourceSnapshot.setProjectId(projectId)); if (getDiskType() != null) { builder.setDiskType(getDiskType().setProjectId(projectId)); } return builder.build(); }