Fixed CreateAndRegisterMachineFromIsoIfNotAlreadyExists and added more tests.

This commit is contained in:
Mattias Holmqvist 2011-10-23 12:19:55 +02:00
parent 3f716c4f3e
commit b04f38b0d8
2 changed files with 23 additions and 0 deletions

View File

@ -52,6 +52,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
final IVirtualBox vBox = manager.getVBox();
try {
vBox.findMachine(vmName);
throw new IllegalStateException("Machine " + vmName + " is already registered.");
} catch (VBoxException e) {
if (machineNotFoundException(e))

View File

@ -83,6 +83,28 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("", "", "", false, manager).apply(vmName);
}
@Test(expectedExceptions = VBoxException.class)
public void testFailIfOtherVBoxExceptionIsThrown() throws Exception {
VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
IVirtualBox vBox = createNiceMock(IVirtualBox.class);
String vmName = "jclouds-image-my-ubuntu-image";
String errorMessage = "VirtualBox error: Soem other VBox error";
VBoxException vBoxException = new VBoxException(createNiceMock(Throwable.class), errorMessage);
expect(manager.getVBox()).andReturn(vBox).anyTimes();
vBox.findMachine(vmName);
expectLastCall().andThrow(vBoxException);
replay(manager, vBox);
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("", "", "", false, manager).apply(vmName);
}
private String anyString() {
return EasyMock.<String>anyObject();
}