mirror of https://github.com/apache/jclouds.git
Fixed CreateAndRegisterMachineFromIsoIfNotAlreadyExists and added more tests.
This commit is contained in:
parent
3f716c4f3e
commit
b04f38b0d8
|
@ -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))
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue