PageRenderTime 318ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/jclouds/jclouds
Java | 98 lines | 69 code | 13 blank | 16 comment | 0 complexity | 5069c7d50745b49f13edab9ffc5cfd28 MD5 | raw file
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package org.jclouds.openstack.nova.ec2.strategy;
  18. import static org.testng.Assert.assertEquals;
  19. import java.util.Map;
  20. import java.util.Set;
  21. import org.jclouds.compute.config.BaseComputeServiceContextModule;
  22. import org.jclouds.compute.domain.ImageBuilder;
  23. import org.jclouds.compute.domain.OperatingSystem;
  24. import org.jclouds.compute.domain.OsFamily;
  25. import org.jclouds.compute.reference.ComputeServiceConstants;
  26. import org.jclouds.domain.Location;
  27. import org.jclouds.domain.LocationBuilder;
  28. import org.jclouds.domain.LocationScope;
  29. import org.jclouds.domain.LoginCredentials;
  30. import org.jclouds.ec2.compute.config.EC2ComputeServiceDependenciesModule;
  31. import org.jclouds.ec2.compute.functions.EC2ImageParser;
  32. import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy;
  33. import org.jclouds.ec2.domain.Image;
  34. import org.jclouds.ec2.xml.DescribeImagesResponseHandlerTest;
  35. import org.jclouds.json.Json;
  36. import org.jclouds.json.config.GsonModule;
  37. import org.jclouds.openstack.nova.v2_0.compute.functions.ImageToOperatingSystem;
  38. import org.testng.annotations.Test;
  39. import com.google.common.base.Predicates;
  40. import com.google.common.base.Suppliers;
  41. import com.google.common.collect.ImmutableMap;
  42. import com.google.common.collect.ImmutableSet;
  43. import com.google.common.collect.Iterables;
  44. import com.google.common.collect.Sets;
  45. import com.google.inject.Guice;
  46. @Test(groups = "unit", testName = "NovaReviseParsedImageTest")
  47. public class NovaReviseParsedImageTest {
  48. public void test() {
  49. Set<org.jclouds.compute.domain.Image> result = convertImages("/nova_ec2_images.xml");
  50. assertEquals(result.size(), 7);
  51. assertEquals(
  52. Iterables.get(result, 4).toString(),
  53. new ImageBuilder()
  54. .operatingSystem(
  55. OperatingSystem.builder().family(OsFamily.UBUNTU).arch("paravirtual").version("10.10")
  56. .name("Ubuntu Maverick 10.10 Server 64-bit 20111212")
  57. .description("Ubuntu Maverick 10.10 Server 64-bit 20111212").is64Bit(true)
  58. .build())
  59. .name("Ubuntu Maverick 10.10 Server 64-bit 20111212")
  60. .description("")
  61. .defaultCredentials(LoginCredentials.builder().user("root").build())
  62. .id("us-east-1/ami-000004d6")
  63. .providerId("ami-000004d6")
  64. .location(defaultLocation)
  65. .status(org.jclouds.compute.domain.Image.Status.AVAILABLE)
  66. .backendStatus("available")
  67. .userMetadata(
  68. ImmutableMap.of("owner", "", "rootDeviceType", "instance-store", "virtualizationType",
  69. "paravirtual", "hypervisor", "xen")).build().toString());
  70. assertEquals(Iterables.get(result, 4).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
  71. }
  72. static Location defaultLocation = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description(
  73. "us-east-1").build();
  74. public static Set<org.jclouds.compute.domain.Image> convertImages(String resource) {
  75. Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() {
  76. }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
  77. .getInstance(Json.class));
  78. Set<Image> result = DescribeImagesResponseHandlerTest.parseImages(resource);
  79. EC2ImageParser parser = new EC2ImageParser(EC2ComputeServiceDependenciesModule.toPortableImageStatus,
  80. new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, Suppliers
  81. .<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
  82. .ofInstance(defaultLocation), new NovaReviseParsedImage(new ImageToOperatingSystem(map)));
  83. return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull()));
  84. }
  85. }