@Test public void testCreateSnapshot() { initializeExpectedDisk(4); expect(compute.getOptions()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) .setOperationId(ZoneOperationId.of("project", "zone", "op")) .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.getSnapshot())); }
@Test public void testCreateSnapshotWithOptions() { initializeExpectedDisk(4); expect(compute.getOptions()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) .setOperationId(ZoneOperationId.of("project", "zone", "op")) .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.getSnapshot(), Compute.OperationOption.fields())); }
@Test public void testCreateSnapshotWithDescription() { initializeExpectedDisk(4); expect(compute.getOptions()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) .setOperationId(ZoneOperationId.of("project", "zone", "op")) .build(); 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.getSnapshot(), "description")); }
@Test public void testCreateSnapshotWithDescriptionAndOptions() { initializeExpectedDisk(4); expect(compute.getOptions()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) .setOperationId(ZoneOperationId.of("project", "zone", "op")) .build(); 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.getSnapshot(), "description", Compute.OperationOption.fields())); }
/** * Creates a snapshot for this disk given the snapshot's name and description. * * @return a zone operation for snapshot creation * @throws ComputeException upon failure */ public Operation createSnapshot(String snapshot, String description, OperationOption... options) { SnapshotInfo snapshotInfo = SnapshotInfo.newBuilder(SnapshotId.of(snapshot), getDiskId()) .setDescription(description) .build(); return compute.create(snapshotInfo, options); }
@Test public void testSetProjectId() { SnapshotInfo snapshotInfo = SNAPSHOT_INFO .toBuilder() .setSnapshotId(SnapshotId.of("snapshot")) .setSourceDisk(DiskId.of("zone", "disk")) .build(); compareSnapshotInfo(SNAPSHOT_INFO, snapshotInfo.setProjectId("project")); }
/** * Returns a {@code SnapshotInfo} object given the snapshot identity and a source disk identity. */ public static SnapshotInfo of(SnapshotId snapshotId, DiskId source) { return newBuilder(snapshotId, source).build(); }
SnapshotInfo setProjectId(String projectId) { return toBuilder() .setSnapshotId(snapshotId.setProjectId(projectId)) .setSourceDisk(sourceDisk.setProjectId(projectId)) .build(); }
@Test public void testToBuilderIncomplete() { SnapshotInfo snapshotInfo = SnapshotInfo.of(SNAPSHOT_ID, SOURCE_DISK); assertEquals(snapshotInfo, snapshotInfo.toBuilder().build()); }
@Test public void testToBuilder() { compareSnapshotInfo(SNAPSHOT_INFO, SNAPSHOT_INFO.toBuilder().build()); SnapshotInfo snapshotInfo = SNAPSHOT_INFO.toBuilder().setDescription("newDescription").build(); assertEquals("newDescription", snapshotInfo.getDescription()); snapshotInfo = snapshotInfo.toBuilder().setDescription("description").build(); compareSnapshotInfo(SNAPSHOT_INFO, snapshotInfo); }