PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterTest.java

https://github.com/richardcloudsoft/legacy-jclouds
Java | 88 lines | 55 code | 15 blank | 18 comment | 0 complexity | edddc5f539533b1685648873bd73d414 MD5 | raw file
  1. /**
  2. * Licensed to jclouds, Inc. (jclouds) under one or more
  3. * contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. jclouds licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package org.jclouds.virtualbox.compute;
  20. import static org.easymock.EasyMock.createNiceMock;
  21. import static org.easymock.EasyMock.expect;
  22. import static org.easymock.EasyMock.replay;
  23. import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
  24. import java.util.ArrayList;
  25. import java.util.List;
  26. import java.util.Map;
  27. import org.easymock.EasyMock;
  28. import org.jclouds.compute.config.BaseComputeServiceContextModule;
  29. import org.jclouds.compute.domain.Image;
  30. import org.jclouds.compute.domain.OsFamily;
  31. import org.jclouds.compute.reference.ComputeServiceConstants;
  32. import org.jclouds.json.Json;
  33. import org.jclouds.json.config.GsonModule;
  34. import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule;
  35. import org.jclouds.virtualbox.functions.IMachineToImage;
  36. import org.testng.annotations.Test;
  37. import org.virtualbox_4_2.IGuestOSType;
  38. import org.virtualbox_4_2.IMachine;
  39. import org.virtualbox_4_2.IVirtualBox;
  40. import org.virtualbox_4_2.VirtualBoxManager;
  41. import com.beust.jcommander.internal.Lists;
  42. import com.google.common.base.Function;
  43. import com.google.common.base.Suppliers;
  44. import com.google.inject.Guice;
  45. @Test(groups = "unit")
  46. public class VirtualBoxComputeServiceAdapterTest {
  47. Map<OsFamily, Map<String, String>> osMap = new BaseComputeServiceContextModule() {
  48. }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
  49. .getInstance(Json.class));
  50. @Test
  51. public void testListImages() throws Exception {
  52. VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
  53. IVirtualBox vBox = createNiceMock(IVirtualBox.class);
  54. IGuestOSType osType = createNiceMock(IGuestOSType.class);
  55. List<IMachine> machines = Lists.newArrayList();
  56. IMachine imageMachine = createNiceMock(IMachine.class);
  57. IMachine clonedMachine = createNiceMock(IMachine.class);
  58. machines.add(imageMachine);
  59. machines.add(clonedMachine);
  60. expect(clonedMachine.getName()).andReturn("My Linux Node");
  61. expect(clonedMachine.getDescription()).andReturn("My Linux Node");
  62. expect(imageMachine.getName()).andReturn(VIRTUALBOX_IMAGE_PREFIX + "ubuntu-10.04");
  63. expect(imageMachine.getDescription()).andReturn(VIRTUALBOX_IMAGE_PREFIX + "ubuntu-10.04");
  64. expect(manager.getVBox()).andReturn(vBox).anyTimes();
  65. expect(vBox.getMachines()).andReturn(machines).anyTimes();
  66. expect(vBox.getGuestOSType(EasyMock.<String> anyObject())).andReturn(osType).anyTimes();
  67. expect(osType.getDescription()).andReturn("Ubuntu 10.04").anyTimes();
  68. expect(osType.getIs64Bit()).andReturn(true).anyTimes();
  69. replay(manager, vBox, clonedMachine, imageMachine, osType);
  70. Function<IMachine, Image> iMachineToImage = new IMachineToImage(
  71. VirtualBoxComputeServiceContextModule.toPortableImageStatus, Suppliers.ofInstance(manager), osMap);
  72. }
  73. }