createDiskConfiguration = CREATE_DISK_CONFIGURATION .toBuilder() .setDiskType(DiskTypeId.of("zone", "diskType")) .setSourceImage(ImageId.of("image"))
@Test public void testConfigurationToBuilder() { comparePersistentDiskConfiguration( PERSISTENT_DISK_CONFIGURATION, PERSISTENT_DISK_CONFIGURATION.toBuilder().build()); compareScratchDiskConfiguration( SCRATCH_DISK_CONFIGURATION, SCRATCH_DISK_CONFIGURATION.toBuilder().build()); compareCreateDiskConfiguration( CREATE_DISK_CONFIGURATION, CREATE_DISK_CONFIGURATION.toBuilder().build()); PersistentDiskConfiguration persistentDiskConfiguration = PERSISTENT_DISK_CONFIGURATION.toBuilder().setAutoDelete(false).build(); assertFalse(persistentDiskConfiguration.autoDelete()); persistentDiskConfiguration = persistentDiskConfiguration.toBuilder().setAutoDelete(AUTO_DELETE).build(); assertEquals(PERSISTENT_DISK_CONFIGURATION, persistentDiskConfiguration); ScratchDiskConfiguration scratchDiskConfiguration = SCRATCH_DISK_CONFIGURATION.toBuilder().setInterfaceType(InterfaceType.SCSI).build(); assertEquals(InterfaceType.SCSI, scratchDiskConfiguration.getInterfaceType()); scratchDiskConfiguration = scratchDiskConfiguration.toBuilder().setInterfaceType(INTERFACE_TYPE).build(); assertEquals(SCRATCH_DISK_CONFIGURATION, scratchDiskConfiguration); CreateDiskConfiguration createDiskConfiguration = CREATE_DISK_CONFIGURATION.toBuilder().setAutoDelete(false).build(); assertFalse(createDiskConfiguration.autoDelete()); createDiskConfiguration = createDiskConfiguration.toBuilder().setAutoDelete(AUTO_DELETE).build(); assertEquals(CREATE_DISK_CONFIGURATION, createDiskConfiguration); }
@Test public void testConfigurationSetProjectId() { PersistentDiskConfiguration persistentConfiguration = PersistentDiskConfiguration.of(DiskId.of("zone", "disk")); comparePersistentDiskConfiguration( PersistentDiskConfiguration.of(DiskId.of("project", "zone", "disk")), persistentConfiguration.setProjectId("project")); ScratchDiskConfiguration scratchDiskConfiguration = ScratchDiskConfiguration.of(DiskTypeId.of("zone", "diskType")); compareScratchDiskConfiguration( ScratchDiskConfiguration.of(DiskTypeId.of("project", "zone", "diskType")), scratchDiskConfiguration.setProjectId("project")); CreateDiskConfiguration createDiskConfiguration = CREATE_DISK_CONFIGURATION .toBuilder() .setDiskType(DiskTypeId.of("zone", "diskType")) .setSourceImage(ImageId.of("image")) .build(); compareCreateDiskConfiguration( CREATE_DISK_CONFIGURATION, createDiskConfiguration.setProjectId("project")); }
@Override CreateDiskConfiguration setProjectId(String projectId) { Builder builder = toBuilder(); if (builder.diskType != null) { builder.setDiskType(diskType.setProjectId(projectId)); } if (builder.sourceImage != null) { builder.setSourceImage(sourceImage.setProjectId(projectId)); } return builder.build(); }