/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/strategy/NovaReviseParsedImageTest.java

https://github.com/andreisavu/jclouds · Java · 103 lines · 69 code · 13 blank · 21 comment · 0 complexity · df41ac00aa40f2fcdfbac19fa9e18408 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.openstack.nova.ec2.strategy;
  20. import static org.testng.Assert.assertEquals;
  21. import java.util.Map;
  22. import java.util.Set;
  23. import org.jclouds.compute.config.BaseComputeServiceContextModule;
  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.domain.LoginCredentials;
  32. import org.jclouds.ec2.compute.config.EC2ComputeServiceDependenciesModule;
  33. import org.jclouds.ec2.compute.functions.EC2ImageParser;
  34. import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy;
  35. import org.jclouds.ec2.domain.Image;
  36. import org.jclouds.ec2.xml.DescribeImagesResponseHandlerTest;
  37. import org.jclouds.json.Json;
  38. import org.jclouds.json.config.GsonModule;
  39. import org.jclouds.openstack.nova.v2_0.compute.functions.ImageToOperatingSystem;
  40. import org.testng.annotations.Test;
  41. import com.google.common.base.Predicates;
  42. import com.google.common.base.Suppliers;
  43. import com.google.common.collect.ImmutableMap;
  44. import com.google.common.collect.ImmutableSet;
  45. import com.google.common.collect.Iterables;
  46. import com.google.common.collect.Sets;
  47. import com.google.inject.Guice;
  48. /**
  49. * @author Adrian Cole
  50. */
  51. @Test(groups = "unit", testName = "NovaReviseParsedImageTest")
  52. public class NovaReviseParsedImageTest {
  53. public void test() {
  54. Set<org.jclouds.compute.domain.Image> result = convertImages("/nova_ec2_images.xml");
  55. assertEquals(result.size(), 7);
  56. assertEquals(
  57. Iterables.get(result, 4).toString(),
  58. new ImageBuilder()
  59. .operatingSystem(
  60. OperatingSystem.builder().family(OsFamily.UBUNTU).arch("paravirtual").version("10.10")
  61. .name("Ubuntu Maverick 10.10 Server 64-bit 20111212")
  62. .description("Ubuntu Maverick 10.10 Server 64-bit 20111212").is64Bit(true)
  63. .build())
  64. .name("Ubuntu Maverick 10.10 Server 64-bit 20111212")
  65. .description("")
  66. .defaultCredentials(new LoginCredentials("root", false))
  67. .id("us-east-1/ami-000004d6")
  68. .providerId("ami-000004d6")
  69. .location(defaultLocation)
  70. .status(org.jclouds.compute.domain.Image.Status.AVAILABLE)
  71. .backendStatus("available")
  72. .userMetadata(
  73. ImmutableMap.of("owner", "", "rootDeviceType", "instance-store", "virtualizationType",
  74. "paravirtual", "hypervisor", "xen")).build().toString());
  75. assertEquals(Iterables.get(result, 4).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
  76. }
  77. static Location defaultLocation = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description(
  78. "us-east-1").build();
  79. public static Set<org.jclouds.compute.domain.Image> convertImages(String resource) {
  80. Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() {
  81. }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
  82. .getInstance(Json.class));
  83. Set<Image> result = DescribeImagesResponseHandlerTest.parseImages(resource);
  84. EC2ImageParser parser = new EC2ImageParser(EC2ComputeServiceDependenciesModule.toPortableImageStatus,
  85. new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, Suppliers
  86. .<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
  87. .ofInstance(defaultLocation), new NovaReviseParsedImage(new ImageToOperatingSystem(map)));
  88. return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull()));
  89. }
  90. }