@Test public void testCreateImageWithDescription() { initializeExpectedDisk(4); expect(compute.getOptions()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) .setOperationId(GlobalOperationId.of("project", "op")) .build(); 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.getImage(), "description")); }
@Test public void testCreateImageWithDescriptionAndOptions() { initializeExpectedDisk(4); expect(compute.getOptions()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) .setOperationId(GlobalOperationId.of("project", "op")) .build(); 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.getImage(), "description", Compute.OperationOption.fields())); }
/** * Creates an image for this disk given the image's name and description. * * @return a global operation if the image creation was successfully requested * @throws ComputeException upon failure */ public Operation createImage(String image, String description, OperationOption... options) { ImageInfo imageInfo = ImageInfo.newBuilder(ImageId.of(image), DiskImageConfiguration.of(getDiskId())) .setDescription(description) .build(); return compute.create(imageInfo, options); }
@Test public void testToBuilder() { compareImageInfo(STORAGE_IMAGE, STORAGE_IMAGE.toBuilder().build()); compareImageInfo(DISK_IMAGE, DISK_IMAGE.toBuilder().build()); ImageInfo imageInfo = STORAGE_IMAGE.toBuilder().setDescription("newDescription").build(); assertEquals("newDescription", imageInfo.getDescription()); imageInfo = imageInfo.toBuilder().setDescription("description").build(); compareImageInfo(STORAGE_IMAGE, imageInfo); }
/** * Returns 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 ImageInfo of(ImageId imageId, ImageConfiguration configuration) { return newBuilder(imageId, configuration).build(); }
ImageInfo setProjectId(String projectId) { return toBuilder() .setImageId(imageId.setProjectId(projectId)) .setConfiguration(configuration.setProjectId(projectId)) .build(); }
@Test public void testSetProjectId() { ImageInfo imageInfo = DISK_IMAGE .toBuilder() .setImageId(ImageId.of("image")) .setConfiguration( DISK_CONFIGURATION.toBuilder().setSourceDisk(DiskId.of("zone", "disk")).build()) .build(); compareImageInfo(DISK_IMAGE, imageInfo.setProjectId("project")); }