/providers/slicehost/src/test/java/org/jclouds/slicehost/compute/functions/SlicehostImageToImageTest.java

https://github.com/andreisavu/jclouds · Java · 92 lines · 59 code · 12 blank · 21 comment · 0 complexity · bc179c08ab49dda656689e425860b934 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.slicehost.compute.functions;
  20. import static org.testng.Assert.assertEquals;
  21. import java.net.UnknownHostException;
  22. import org.jclouds.compute.config.BaseComputeServiceContextModule;
  23. import org.jclouds.compute.domain.Image;
  24. import org.jclouds.compute.domain.ImageBuilder;
  25. import org.jclouds.compute.domain.OperatingSystem;
  26. import org.jclouds.compute.domain.OsFamily;
  27. import org.jclouds.compute.reference.ComputeServiceConstants;
  28. import org.jclouds.domain.Location;
  29. import org.jclouds.domain.LocationBuilder;
  30. import org.jclouds.domain.LocationScope;
  31. import org.jclouds.json.Json;
  32. import org.jclouds.json.config.GsonModule;
  33. import org.jclouds.slicehost.xml.ImageHandlerTest;
  34. import org.testng.annotations.Test;
  35. import com.google.inject.Guice;
  36. /**
  37. * @author Adrian Cole
  38. */
  39. @Test(groups = "unit", testName = "SlicehostImageToImageTest")
  40. public class SlicehostImageToImageTest {
  41. Location provider = new LocationBuilder().scope(LocationScope.ZONE).id("dallas").description("description").build();
  42. @Test
  43. public void test() throws UnknownHostException {
  44. Image toTest = convertImage();
  45. assertEquals(
  46. toTest,
  47. new ImageBuilder()
  48. .name("CentOS 5.2")
  49. .operatingSystem(
  50. new OperatingSystem.Builder().family(OsFamily.CENTOS).version("5.2").description("CentOS 5.2")
  51. .is64Bit(true).build()).description("CentOS 5.2").ids("2")
  52. .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build());
  53. assertEquals(toTest.getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
  54. }
  55. @Test
  56. public void test32() throws UnknownHostException {
  57. Image toTest = convertImage("/test_get_image32.xml");
  58. assertEquals(
  59. toTest,
  60. new ImageBuilder()
  61. .name("Ubuntu 10.10 (maverick) 32-bit")
  62. .operatingSystem(
  63. new OperatingSystem.Builder().family(OsFamily.UBUNTU).version("10.10")
  64. .description("Ubuntu 10.10 (maverick) 32-bit").build())
  65. .description("Ubuntu 10.10 (maverick) 32-bit").ids("70")
  66. .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build());
  67. assertEquals(toTest.getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
  68. }
  69. public static Image convertImage() {
  70. return convertImage("/test_get_image.xml");
  71. }
  72. public static Image convertImage(String resource) {
  73. org.jclouds.slicehost.domain.Image image = ImageHandlerTest.parseImage(resource);
  74. SlicehostImageToImage parser = new SlicehostImageToImage(new SlicehostImageToOperatingSystem(
  75. new BaseComputeServiceContextModule() {
  76. }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
  77. .getInstance(Json.class))));
  78. return parser.apply(image);
  79. }
  80. }