Package org.virtualbox_4_2

Examples of org.virtualbox_4_2.IMachine


   public void testDoNothingIfAlreadyTakenSnapshot() throws Exception {
      String snapshotName = "snap";
      String snapshotDesc = "snapDesc";

      VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
      IMachine machine = createMock(IMachine.class);
      IVirtualBox vBox = createMock(IVirtualBox.class);
      ISession session = createMock(ISession.class);
      IConsole console = createNiceMock(IConsole.class);

      IProgress progress = createNiceMock(IProgress.class);
      expect(progress.getCompleted()).andReturn(true);
      expect(machine.getCurrentSnapshot()).andReturn(null).anyTimes();
      expect(manager.openMachineSession(machine)).andReturn(session);
      expect(machine.getState()).andReturn(MachineState.PoweredOff).anyTimes();

      expect(machine.getName()).andReturn("machine").anyTimes();
      expect(session.getConsole()).andReturn(console);
      expect(console.takeSnapshot(snapshotName, snapshotDesc)).andReturn(
            progress);

      session.unlockMachine();
View Full Code Here


@Test(groups = "unit", testName = "AddIDEControllerIfNotExistsTest")
public class AddIDEControllerIfNotExistsTest {

   @Test
   public void testFine() throws Exception {
      IMachine vm = createMock(IMachine.class);

      String controllerName = "IDE Controller";
      StorageController storageController = StorageController.builder().bus(StorageBus.IDE).name(controllerName).build();

      expect(vm.addStorageController(controllerName, StorageBus.IDE)).andReturn(
              createNiceMock(IStorageController.class));
      vm.saveSettings();

      replay(vm);

      new AddIDEControllerIfNotExists(storageController).apply(vm);
View Full Code Here

      verify(vm);
   }

   @Test
   public void testAcceptableException() throws Exception {
      IMachine vm = createMock(IMachine.class);

      String controllerName = "IDE Controller";
      StorageController storageController = StorageController.builder().bus(StorageBus.IDE).name(controllerName).build();

      expect(vm.addStorageController(controllerName, StorageBus.IDE)).andThrow(
              new VBoxException(createNiceMock(Throwable.class),
                      "VirtualBox error: Storage controller named 'IDE Controller' already exists (0x80BB000C)"));

      replay(vm);
View Full Code Here

      verify(vm);
   }

   @Test(expectedExceptions = VBoxException.class)
   public void testUnacceptableException() throws Exception {
      IMachine vm = createMock(IMachine.class);

      String controllerName = "IDE Controller";
      StorageController storageController = StorageController.builder().bus(StorageBus.IDE).name(controllerName).build();

      expect(vm.addStorageController(controllerName, StorageBus.IDE)).andThrow(
              new VBoxException(createNiceMock(Throwable.class), "VirtualBox error: General Error"));

      replay(vm);

      new AddIDEControllerIfNotExists(storageController).apply(vm);
View Full Code Here

                              .build();
   }
  
   @Test
   public void testCloneMachineFromAnotherMachine() {
      IMachine source = getVmWithGuestAdditionsInstalled();
      CloneSpec cloneSpec = CloneSpec.builder().vm(machineSpec.getVmSpec()).network(machineSpec.getNetworkSpec())
               .master(source).linked(true).build();
      IMachine clone = checkNotNull(
              new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, machineUtils)
                                .apply(cloneSpec), "clone");
      assertEquals(clone.getName(), cloneSpec.getVmSpec().getVmName());

   }
View Full Code Here

      }
   }

   private ISession lockSession(String machineId, LockType type, int retries) {
      int count = 0;
      IMachine immutableMachine = manager.get().getVBox().findMachine(machineId);
      ISession session;
      while (true) {
         try {
            session = manager.get().getSessionObject();
            immutableMachine.lockMachine(session, type);
            break;
         } catch (VBoxException e) {
            VBoxException vbex = Throwables2.getFirstThrowableOfType(e, VBoxException.class);
            if (vbex != null && machineNotFoundException(vbex)) {
               return null;
View Full Code Here

    * @param machineId
    * @param function
    * @return
    */
   public <T> T applyForMachine(final String machineId, final Function<IMachine, T> function) {
      final IMachine immutableMachine = manager.get().getVBox().findMachine(machineId);
      return new Function<IMachine, T>() {
         @Override
         public T apply(IMachine machine) {
            return function.apply(machine);
         }
View Full Code Here

      this.executionType = executionType;
   }

   public ISession ensureMachineIsLaunched(String vmName) {
      ISession session = null;
      IMachine machine = manager.get().getVBox().findMachine(vmName);
      while (!machine.getState().equals(MachineState.Running)) {
         try {
            session = machineUtils.applyForMachine(vmName, new LaunchMachineIfNotAlreadyRunning(manager.get(),
                  executionType, ""));
         } catch (RuntimeException e) {
            if (e.getMessage().contains(
View Full Code Here

public class ApplyMemoryToMachineTest {

   @Test
   public void testSetRAMSizeSuccessful() throws Exception {
      long memorySize = 1024l;
      IMachine machine = createMock(IMachine.class);

      machine.setMemorySize(memorySize);
      machine.saveSettings();

      replay(machine);

      new ApplyMemoryToMachine(memorySize).apply(machine);
View Full Code Here

      // Mainly here for documentation purposes
      final String error = "VirtualBox error: Invalid RAM size: "
            + "3567587327 MB (must be in range [4, 2097152] MB) (0x80070057)";

      long memorySize = 1024l;
      IMachine machine = createMock(IMachine.class);

      VBoxException invalidRamSizeException = new VBoxException(createNiceMock(Throwable.class), error);
      machine.setMemorySize(memorySize);
      expectLastCall().andThrow(invalidRamSizeException);
      machine.saveSettings();

      replay(machine);

      new ApplyMemoryToMachine(memorySize).apply(machine);
   }
View Full Code Here

TOP

Related Classes of org.virtualbox_4_2.IMachine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.