PageRenderTime 421ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/jclouds/jclouds
Java | 106 lines | 54 code | 15 blank | 37 comment | 0 complexity | 04dabbec8ffbd373e8e2f545d30cdaf7 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.List;
  25. import java.util.Map;
  26. import org.easymock.EasyMock;
  27. import org.jclouds.compute.config.BaseComputeServiceContextModule;
  28. import org.jclouds.compute.domain.Image;
  29. import org.jclouds.compute.domain.OsFamily;
  30. import org.jclouds.compute.reference.ComputeServiceConstants;
  31. import org.jclouds.json.Json;
  32. import org.jclouds.json.config.GsonModule;
  33. import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule;
  34. import org.jclouds.virtualbox.functions.IMachineToImage;
  35. import org.testng.annotations.Test;
  36. import org.virtualbox_4_1.IGuestOSType;
  37. import org.virtualbox_4_1.IMachine;
  38. import org.virtualbox_4_1.IVirtualBox;
  39. import org.virtualbox_4_1.VirtualBoxManager;
  40. import com.google.common.base.Function;
  41. import com.google.common.base.Suppliers;
  42. import com.google.common.collect.Lists;
  43. import com.google.inject.Guice;
  44. @Test(groups = "unit")
  45. public class VirtualBoxComputeServiceAdapterTest {
  46. Map<OsFamily, Map<String, String>> osMap = new BaseComputeServiceContextModule() {
  47. }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
  48. .getInstance(Json.class));
  49. @Test
  50. public void testListImages() throws Exception {
  51. VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
  52. IVirtualBox vBox = createNiceMock(IVirtualBox.class);
  53. IGuestOSType osType = createNiceMock(IGuestOSType.class);
  54. List<IMachine> machines = Lists.newArrayList();
  55. IMachine imageMachine = createNiceMock(IMachine.class);
  56. IMachine clonedMachine = createNiceMock(IMachine.class);
  57. machines.add(imageMachine);
  58. machines.add(clonedMachine);
  59. expect(clonedMachine.getName()).andReturn("My Linux Node");
  60. expect(clonedMachine.getDescription()).andReturn("My Linux Node");
  61. expect(imageMachine.getName()).andReturn(VIRTUALBOX_IMAGE_PREFIX + "ubuntu-10.04");
  62. expect(imageMachine.getDescription()).andReturn(VIRTUALBOX_IMAGE_PREFIX + "ubuntu-10.04");
  63. expect(manager.getVBox()).andReturn(vBox).anyTimes();
  64. expect(vBox.getMachines()).andReturn(machines).anyTimes();
  65. expect(vBox.getGuestOSType(EasyMock.<String> anyObject())).andReturn(osType).anyTimes();
  66. expect(osType.getDescription()).andReturn("Ubuntu 10.04").anyTimes();
  67. expect(osType.getIs64Bit()).andReturn(true).anyTimes();
  68. replay(manager, vBox, clonedMachine, imageMachine, osType);
  69. Function<IMachine, Image> iMachineToImage = new IMachineToImage(
  70. VirtualBoxComputeServiceContextModule.toPortableImageStatus, Suppliers.ofInstance(manager), osMap);
  71. // VirtualBoxComputeServiceAdapter adapter = new VirtualBoxComputeServiceAdapter(Suppliers.ofInstance(manager), iMachineToImage, new ImageFromYamlString(), new Supplier<String>() {
  72. //
  73. // @Override
  74. // public String get() {
  75. // return "images:\n" +
  76. // " - id: myTestId\n" +
  77. // " name: ubuntu-11.04-server-i386\n" +
  78. // " description: ubuntu 11.04 server (i386)\n" +
  79. // " os_arch: x86\n" +
  80. // " os_family: ubuntu\n" +
  81. // " os_description: ubuntu\n" +
  82. // " os_version: 11.04\n" +
  83. // " iso: http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso";
  84. // }
  85. // });
  86. //
  87. // Iterator<Image> iterator = adapter.listImages().iterator();
  88. // Image image = Iterators.getOnlyElement(iterator);
  89. // assertEquals(image.getDescription(), "ubuntu 11.04 server (i386)");
  90. }
  91. }