From 1a7eebdb317beebac688016be4fe5ba7ee99281c Mon Sep 17 00:00:00 2001 From: andreaturli Date: Tue, 4 Oct 2011 22:49:36 +0100 Subject: [PATCH] issue 384: IsoToMachine + Test mock completed --- .../VirtualBoxComputeServiceAdapter.java | 3 +++ .../config/VirtualBoxConstants.java | 2 +- .../virtualbox/functions/IsoToIMachine.java | 16 ++++--------- .../functions/IsoToIMachineTest.java | 24 +++++++++++++++---- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java index 9b1a1799ef..22e8972efc 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java @@ -78,6 +78,9 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter listImages() { + for (IMachine iMachine : manager.getVBox().getMachines()) { + System.out.println(iMachine.getName()); + } return manager.getVBox().getMachines(); } diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxConstants.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxConstants.java index 8af131d7e4..78ba11b2f1 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxConstants.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxConstants.java @@ -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"; } diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IsoToIMachine.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IsoToIMachine.java index 6327cbc765..50dfce47f3 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IsoToIMachine.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IsoToIMachine.java @@ -103,9 +103,6 @@ public class IsoToIMachine implements Function { 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 { 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 { try { sendKeyboardSequence(VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE); } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + propagate(e); } session.unlockMachine(); diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IsoToIMachineTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IsoToIMachineTest.java index aee04c4de7..028c81c309 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IsoToIMachineTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IsoToIMachineTest.java @@ -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();