mirror of https://github.com/apache/jclouds.git
issue 384: IsoToMachine + Test mock completed
This commit is contained in:
parent
a7d1f38266
commit
1a7eebdb31
|
@ -78,6 +78,9 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
|
|||
|
||||
@Override
|
||||
public Iterable<IMachine> listImages() {
|
||||
for (IMachine iMachine : manager.getVBox().getMachines()) {
|
||||
System.out.println(iMachine.getName());
|
||||
}
|
||||
return manager.getVBox().getMachines();
|
||||
}
|
||||
|
||||
|
|
|
@ -51,5 +51,5 @@ public interface VirtualBoxConstants {
|
|||
|
||||
public static final String VIRTUALBOX_HOST_ID = "jclouds.virtualbox.hostid";
|
||||
|
||||
public static final String VIRTUALBOX_DISTRO_ISO_NAME = "jclouds.virtualbox.distroIsoName";
|
||||
public static final String VIRTUALBOX_DISTRO_ISO_NAME = "jclouds.virtualbox.distroisoname";
|
||||
}
|
||||
|
|
|
@ -103,9 +103,6 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
|||
machine.lockMachine(session, LockType.Write);
|
||||
IMachine mutable = session.getMachine();
|
||||
mutable.addStorageController(controllerIDE, StorageBus.IDE);
|
||||
// assertEquals(manager.getVBox().findMachine(vmName).getStorageControllers().size(),
|
||||
// 1);
|
||||
|
||||
mutable.saveSettings();
|
||||
|
||||
// CONTROLLER
|
||||
|
@ -123,15 +120,13 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
|||
new Long(MediumVariant.STANDARD.ordinal()));
|
||||
mutable.attachDevice(controllerIDE, 0, 1, DeviceType.HardDisk, hd);
|
||||
mutable.saveSettings();
|
||||
assertEquals(hd.getId().equals(""), false);
|
||||
|
||||
|
||||
// NIC
|
||||
mutable.getNetworkAdapter(new Long(0)).setAttachmentType(
|
||||
NetworkAttachmentType.NAT);
|
||||
machine.getNetworkAdapter(new Long(0))
|
||||
.getNatDriver()
|
||||
.addRedirect("guestssh", NATProtocol.TCP, "127.0.0.1", 2222,
|
||||
"", 22);
|
||||
|
||||
|
||||
machine.getNetworkAdapter(new Long(0)).getNatDriver().addRedirect("guestssh", NATProtocol.TCP, "127.0.0.1", 2222, "", 22);
|
||||
mutable.getNetworkAdapter(new Long(0)).setEnabled(true);
|
||||
mutable.saveSettings();
|
||||
|
||||
|
@ -146,8 +141,7 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
|||
try {
|
||||
sendKeyboardSequence(VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
propagate(e);
|
||||
}
|
||||
|
||||
session.unlockMachine();
|
||||
|
|
|
@ -35,8 +35,15 @@ import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
|||
import org.jclouds.virtualbox.experiment.TestUtils;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.INATEngine;
|
||||
import org.virtualbox_4_1.INetworkAdapter;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.MachineState;
|
||||
import org.virtualbox_4_1.NATProtocol;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
//TODO should it be a live test?
|
||||
|
@ -59,17 +66,26 @@ public class IsoToIMachineTest {
|
|||
VirtualBoxManager vbm = createNiceMock(VirtualBoxManager.class);
|
||||
IVirtualBox vBox = createNiceMock(IVirtualBox.class);
|
||||
IMachine vm = createNiceMock(IMachine.class);
|
||||
IMedium hd = createNiceMock(IMedium.class);
|
||||
INetworkAdapter iNetworkAdapter = createNiceMock(INetworkAdapter.class);
|
||||
INATEngine inatEngine = createNiceMock(INATEngine.class);
|
||||
IProgress iProgress = createNiceMock(IProgress.class);
|
||||
|
||||
ISession session = createNiceMock(ISession.class);
|
||||
expect(vbm.getVBox()).andReturn(vBox).anyTimes();
|
||||
expect(vbm.getSessionObject()).andReturn(session).anyTimes();
|
||||
expect(vBox.findMachine(vmName)).andReturn(vm).anyTimes();
|
||||
expect(
|
||||
vBox.createMachine(settingsFile, vmName, osTypeId, vmId,
|
||||
expect(vBox.createMachine(settingsFile, vmName, osTypeId, vmId,
|
||||
forceOverwrite)).andReturn(vm).anyTimes();
|
||||
expect(vm.getName()).andReturn(vmName).anyTimes();
|
||||
// expect(vm.lockMachine(session, LockType.Write)).and
|
||||
expect(vm.getNetworkAdapter(new Long(0))).andReturn(iNetworkAdapter).anyTimes();
|
||||
expect(iNetworkAdapter.getNatDriver()).andReturn(inatEngine).anyTimes();
|
||||
expect(vBox.createHardDisk(diskFormat, adminDisk)).andReturn(hd).anyTimes();
|
||||
expect(vm.launchVMProcess(session, "gui", "")).andReturn(iProgress).anyTimes();
|
||||
expect(session.getMachine()).andReturn(vm).anyTimes();
|
||||
replay(vbm, vBox, vm, session);
|
||||
expect(vm.getState()).andReturn(MachineState.Running).anyTimes();
|
||||
|
||||
replay(vbm, vBox, vm, session, hd, iNetworkAdapter, iProgress);
|
||||
|
||||
ComputeServiceContext context = TestUtils
|
||||
.computeServiceForLocalhostAndGuest();
|
||||
|
|
Loading…
Reference in New Issue