mirror of https://github.com/apache/jclouds.git
started finishing incomplete mock test
This commit is contained in:
parent
66c49135eb
commit
347a12a68f
|
@ -33,7 +33,9 @@ import org.jclouds.virtualbox.domain.VmSpec;
|
|||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.LockType;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
|
@ -43,18 +45,21 @@ import org.virtualbox_4_1.VirtualBoxManager;
|
|||
@Test(groups = "unit", testName = "CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest")
|
||||
public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||
|
||||
@Test
|
||||
public void testCreateIfNotAlreadyExists() throws Exception {
|
||||
@Test(enabled = false)
|
||||
public void testCreateAndSetMemoryWhenNotAlreadyExists() throws Exception {
|
||||
|
||||
VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
|
||||
VirtualBoxManager manager = createMock(VirtualBoxManager.class);
|
||||
IVirtualBox vBox = createMock(IVirtualBox.class);
|
||||
String vmName = "jclouds-image-my-ubuntu-image";
|
||||
|
||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).cleanUpMode(CleanupMode.Full).build();
|
||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).cleanUpMode(
|
||||
CleanupMode.Full).build();
|
||||
|
||||
IMachine createdMachine = createMock(IMachine.class);
|
||||
ISession session = createMock(ISession.class);
|
||||
|
||||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||
expect(vBox.composeMachineFilename(vmName, "/tmp/workingDir")).andReturn("settingsFile");
|
||||
|
||||
StringBuilder errorMessageBuilder = new StringBuilder();
|
||||
errorMessageBuilder.append("VirtualBox error: Could not find a registered machine named ");
|
||||
|
@ -62,19 +67,28 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
|||
String errorMessage = errorMessageBuilder.toString();
|
||||
VBoxException vBoxException = new VBoxException(createNiceMock(Throwable.class), errorMessage);
|
||||
|
||||
vBox.findMachine(vmName);
|
||||
expectLastCall().andThrow(vBoxException);
|
||||
expect(vBox.findMachine(vmName)).andThrow(vBoxException);
|
||||
|
||||
expect(vBox.createMachine(anyString(), eq(vmName), anyString(), anyString(), anyBoolean())).andReturn(
|
||||
createdMachine).anyTimes();
|
||||
|
||||
createdMachine).anyTimes();
|
||||
vBox.registerMachine(createdMachine);
|
||||
|
||||
expect(vBox.findMachine(vmName)).andReturn(createdMachine).anyTimes();
|
||||
expect(manager.getSessionObject()).andReturn(session);
|
||||
expect(session.getMachine()).andReturn(createdMachine);
|
||||
createdMachine.lockMachine(session, LockType.Write);
|
||||
createdMachine.setMemorySize(1024l);
|
||||
createdMachine.saveSettings();
|
||||
session.unlockMachine();
|
||||
|
||||
|
||||
//TODO: this mock test is not finished.
|
||||
|
||||
replay(manager, createdMachine, vBox, session);
|
||||
|
||||
replay(manager, vBox);
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager, "/tmp/workingDir").apply(launchSpecification);
|
||||
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(launchSpecification);
|
||||
|
||||
verify(manager, vBox);
|
||||
verify(manager, createdMachine, vBox, session);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
|
@ -91,8 +105,9 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
|||
|
||||
replay(manager, vBox);
|
||||
|
||||
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").memoryMB(1024).cleanUpMode(CleanupMode.Full).build();
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(launchSpecification);
|
||||
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").memoryMB(1024).cleanUpMode(
|
||||
CleanupMode.Full).build();
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager, "/tmp/workingDir").apply(launchSpecification);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = VBoxException.class)
|
||||
|
@ -112,12 +127,13 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
|||
|
||||
replay(manager, vBox);
|
||||
|
||||
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").cleanUpMode(CleanupMode.Full).memoryMB(1024).build();
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(launchSpecification);
|
||||
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").cleanUpMode(CleanupMode.Full)
|
||||
.memoryMB(1024).build();
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager, "/tmp/workingDir").apply(launchSpecification);
|
||||
|
||||
}
|
||||
|
||||
private String anyString() {
|
||||
return EasyMock.<String>anyObject();
|
||||
return EasyMock.<String> anyObject();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue