issue 384: improve UnregisterMachineIfExistsAndDeleteItsMedia + Test, vmSpec

This commit is contained in:
andreaturli 2011-12-20 08:30:55 +00:00
parent 3f559bf0c5
commit 912a2f9ae0
3 changed files with 8 additions and 4 deletions

View File

@ -52,6 +52,7 @@ public class VmSpec {
checkArgument(memory > 0, "memory must be > 0");
checkNotNull(controllers, "controllers");
checkNotNull(natNetworkAdapters, "natNetworkAdapters");
checkNotNull(cleanupMode, "cleanupMode");
this.vmId = vmId;
this.vmName = vmName;
this.osTypeId = osTypeId;
@ -170,7 +171,8 @@ public class VmSpec {
Objects.equal(memory, other.memory) &&
Objects.equal(forceOverwrite, other.forceOverwrite) &&
Objects.equal(natNetworkAdapters, other.natNetworkAdapters) &&
Objects.equal(controllers, other.controllers);
Objects.equal(controllers, other.controllers) &&
Objects.equal(cleanupMode, other.cleanupMode);
}
return false;
}
@ -190,6 +192,7 @@ public class VmSpec {
", forceOverwrite=" + forceOverwrite +
", natNetworkAdapters=" + natNetworkAdapters +
", controllers=" + controllers +
", cleanupMode=" + cleanupMode +
'}';
}
}

View File

@ -39,6 +39,7 @@ import org.virtualbox_4_1.VirtualBoxManager;
import com.google.common.base.Function;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
public class UnregisterMachineIfExistsAndDeleteItsMedia implements Function<VmSpec, Void> {
@ -48,7 +49,7 @@ public class UnregisterMachineIfExistsAndDeleteItsMedia implements Function<VmSp
private VirtualBoxManager manager;
public UnregisterMachineIfExistsAndDeleteItsMedia(VirtualBoxManager manager, CleanupMode mode) {
public UnregisterMachineIfExistsAndDeleteItsMedia(VirtualBoxManager manager) {
this.manager = manager;
}
@ -75,7 +76,7 @@ public class UnregisterMachineIfExistsAndDeleteItsMedia implements Function<VmSp
try {
for (IMedium iMedium : mediaToBeDeleted) {
if(iMedium.getDeviceType().equals(DeviceType.HardDisk)) {
IProgress deletion = machine.delete(mediaToBeDeleted);
IProgress deletion = machine.delete(Lists.newArrayList(iMedium));
deletion.waitForCompletion(-1);
}
}

View File

@ -68,7 +68,7 @@ public class UnregisterMachineIfExistsAndDeleteItsMediaTest {
replay(manager, vBox, registeredMachine, progress);
new UnregisterMachineIfExistsAndDeleteItsMedia(manager, mode).apply(vmSpecification);
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(vmSpecification);
}
}