PageRenderTime 41ms CodeModel.GetById 24ms app.highlight 15ms RepoModel.GetById 0ms app.codeStats 0ms

/labs/greenqloud-compute/src/test/java/org/jclouds/greenqloud/compute/strategy/GreenQloudComputeReviseParsedImageTest.java

https://github.com/richardcloudsoft/legacy-jclouds
Java | 256 lines | 211 code | 22 blank | 23 comment | 0 complexity | ce7d44acc38cfef6ec2014f5fb4a7068 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 */
 19package org.jclouds.greenqloud.compute.strategy;
 20
 21import static org.testng.Assert.assertEquals;
 22
 23import java.util.Map;
 24import java.util.Set;
 25
 26import org.jclouds.compute.config.BaseComputeServiceContextModule;
 27import org.jclouds.compute.domain.ImageBuilder;
 28import org.jclouds.compute.domain.OperatingSystem;
 29import org.jclouds.compute.domain.OsFamily;
 30import org.jclouds.compute.reference.ComputeServiceConstants;
 31import org.jclouds.domain.Location;
 32import org.jclouds.domain.LocationBuilder;
 33import org.jclouds.domain.LocationScope;
 34import org.jclouds.domain.LoginCredentials;
 35import org.jclouds.ec2.compute.config.EC2ComputeServiceDependenciesModule;
 36import org.jclouds.ec2.compute.functions.EC2ImageParser;
 37import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy;
 38import org.jclouds.ec2.domain.Image;
 39import org.jclouds.ec2.xml.DescribeImagesResponseHandlerTest;
 40import org.jclouds.greenqloud.compute.strategy.GreenQloudComputeReviseParsedImage;
 41import org.jclouds.json.Json;
 42import org.jclouds.json.config.GsonModule;
 43import org.testng.annotations.Test;
 44
 45import com.google.common.base.Predicates;
 46import com.google.common.base.Suppliers;
 47import com.google.common.collect.ImmutableMap;
 48import com.google.common.collect.ImmutableSet;
 49import com.google.common.collect.Iterables;
 50import com.google.common.collect.Sets;
 51import com.google.inject.Guice;
 52
 53/**
 54 * @author Adrian Cole
 55 */
 56@Test(groups = "unit", testName = "GreenQloudComputeReviseParsedImageTest")
 57public class GreenQloudComputeReviseParsedImageTest {
 58
 59   public void testParseGreenQloudImage() {
 60
 61      Set<org.jclouds.compute.domain.Image> result = convertImages("/greenqloud_images.xml");
 62      assertEquals(result.size(), 9);
 63
 64      assertEquals(
 65            Iterables.get(result, 0).toString(),
 66            new ImageBuilder()
 67                  .operatingSystem(
 68                        OperatingSystem.builder().family(OsFamily.UBUNTU).version("10.04")
 69                              .description("Ubuntu Server 10.04 (64-bit)").is64Bit(true)
 70                              .arch("paravirtual").build())
 71                  .description("Ubuntu Server 10.04 (64-bit)")
 72                  .name("Ubuntu Server 10.04.3")
 73                  .defaultCredentials(LoginCredentials.builder().user("root").build())
 74                  .id("us-east-1/qmi-4e5b842f")
 75                  .providerId("qmi-4e5b842f")
 76                  .location(defaultLocation)
 77                  .userMetadata(
 78                        ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType",
 79                              "paravirtual", "hypervisor", "xen"))
 80                  .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString());
 81      assertEquals(Iterables.get(result, 0).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
 82
 83      assertEquals(
 84            Iterables.get(result, 1).toString(),
 85            new ImageBuilder()
 86                  .operatingSystem(
 87                        OperatingSystem.builder().family(OsFamily.UBUNTU).version("11.10")
 88                              .description("Ubuntu Server 11.10 (64-bit)").is64Bit(true)
 89                              .arch("paravirtual").build())
 90                  .description("Ubuntu Server 11.10 (64-bit)")
 91                  .name("Ubuntu Server 11.10")
 92                  .defaultCredentials(LoginCredentials.builder().user("root").build())
 93                  .id("us-east-1/qmi-9ac92558")
 94                  .providerId("qmi-9ac92558")
 95                  .location(defaultLocation)
 96                  .userMetadata(
 97                        ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType",
 98                              "paravirtual", "hypervisor", "xen"))
 99                  .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString());
100      assertEquals(Iterables.get(result, 1).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
101      
102      assertEquals(
103               Iterables.get(result, 2).toString(),
104               new ImageBuilder()
105                  .operatingSystem(
106                        OperatingSystem.builder().family(OsFamily.CENTOS).version("5.5")
107                              .description("CentOS 5.5 Server 64-bit").is64Bit(true)
108                              .arch("paravirtual").build())
109                  .description("CentOS 5.5 Server 64-bit")
110                  .name("CentOS 5.5 Server")
111                  .defaultCredentials(LoginCredentials.builder().user("root").build())
112                  .id("us-east-1/qmi-33a467aa")
113                  .providerId("qmi-33a467aa")
114                  .location(defaultLocation)
115                  .userMetadata(
116                        ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType",
117                              "paravirtual", "hypervisor", "xen"))
118                  .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString());               
119         assertEquals(Iterables.get(result, 2).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
120         
121         assertEquals(
122                  Iterables.get(result, 3).toString(),
123                  new ImageBuilder()
124                     .operatingSystem(
125                           OperatingSystem.builder().family(OsFamily.DEBIAN).version("6.0")
126                                 .description("Debian 6.0 (64-bit)").is64Bit(true)
127                                 .arch("paravirtual").build())
128                     .description("Debian 6.0 (64-bit)")
129                     .name("Debian 6.0")
130                     .defaultCredentials(LoginCredentials.builder().user("root").build())
131                     .id("us-east-1/qmi-f2a9d2ba")
132                     .providerId("qmi-f2a9d2ba")
133                     .location(defaultLocation)
134                     .userMetadata(
135                           ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType",
136                                 "paravirtual", "hypervisor", "xen"))
137                     .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString());               
138         assertEquals(Iterables.get(result, 3).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);         
139
140         assertEquals(
141                  Iterables.get(result, 4).toString(),
142                  new ImageBuilder()
143                     .operatingSystem(
144                           OperatingSystem.builder().family(OsFamily.CENTOS).version("6.0")
145                                 .description("CentOS 6.0 (64-bit)").is64Bit(true)
146                                 .arch("paravirtual").build())
147                     .description("CentOS 6.0 (64-bit)")
148                     .name("CentOS 6.0")
149                     .defaultCredentials(LoginCredentials.builder().user("root").build())
150                     .id("us-east-1/qmi-96f82145")
151                     .providerId("qmi-96f82145")
152                     .location(defaultLocation)
153                     .userMetadata(
154                           ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType",
155                                 "paravirtual", "hypervisor", "xen"))
156                     .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString());               
157            assertEquals(Iterables.get(result, 4).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);         
158
159            assertEquals(
160                     Iterables.get(result, 5).toString(),
161                     new ImageBuilder()
162                        .operatingSystem(
163                              OperatingSystem.builder().family(OsFamily.CENTOS).version("6.0")
164                                    .description("CentOS 6.0 GUI (64-bit)").is64Bit(true)
165                                    .arch("paravirtual").build())
166                        .description("CentOS 6.0 GUI (64-bit)")
167                        .name("CentOS 6.0 GUI")
168                        .defaultCredentials(LoginCredentials.builder().user("root").build())
169                        .id("us-east-1/qmi-42e877f6")
170                        .providerId("qmi-42e877f6")
171                        .location(defaultLocation)
172                        .userMetadata(
173                              ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType",
174                                    "paravirtual", "hypervisor", "xen"))
175                        .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString());               
176            assertEquals(Iterables.get(result, 5).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);      
177
178            assertEquals(
179                     Iterables.get(result, 6).toString(),
180                     new ImageBuilder()
181                           .operatingSystem(
182                                 OperatingSystem.builder().family(OsFamily.UBUNTU).version("11.04")
183                                       .description("Ubuntu Server 11.04 (64-bit)").is64Bit(true)
184                                       .arch("paravirtual").build())
185                           .description("Ubuntu Server 11.04 (64-bit)")
186                           .name("Ubuntu Server 11.04")
187                           .defaultCredentials(LoginCredentials.builder().user("root").build())
188                           .id("us-east-1/qmi-eed8cea7")
189                           .providerId("qmi-eed8cea7")
190                           .location(defaultLocation)
191                           .userMetadata(
192                                 ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType",
193                                       "paravirtual", "hypervisor", "xen"))
194                           .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString());
195            assertEquals(Iterables.get(result, 6).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
196
197            assertEquals(
198                     Iterables.get(result, 7).toString(),
199                     new ImageBuilder()
200                        .operatingSystem(
201                              // fedora is not in the image version map, yet
202                              OperatingSystem.builder().family(OsFamily.FEDORA).version("")
203                                    .description("Fedora 16 Server").is64Bit(false)
204                                    .arch("paravirtual").build())
205                        .description("Fedora 16 Server")
206                        .name("Fedora 16 Server")
207                        .defaultCredentials(LoginCredentials.builder().user("root").build())
208                        .id("us-east-1/qmi-fa4bdae0")
209                        .providerId("qmi-fa4bdae0")
210                        .location(defaultLocation)
211                        .userMetadata(
212                              ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType",
213                                    "paravirtual", "hypervisor", "xen"))
214                        .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString());               
215            assertEquals(Iterables.get(result, 7).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);      
216           
217            assertEquals(
218                     Iterables.get(result, 8).toString(),
219                     new ImageBuilder()
220                        .operatingSystem(
221                              OperatingSystem.builder().family(OsFamily.CENTOS).version("5.6")
222                                    .description("CentOS 5.6 Server GUI 64-bit").is64Bit(true)
223                                    .arch("paravirtual").build())
224                        .description("CentOS 5.6 Server GUI 64-bit")
225                        .name("CentOS 5.6 GUI")
226                        .defaultCredentials(LoginCredentials.builder().user("root").build())
227                        .id("us-east-1/qmi-93271d32")
228                        .providerId("qmi-93271d32")
229                        .location(defaultLocation)
230                        .userMetadata(
231                              ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType",
232                                    "paravirtual", "hypervisor", "xen"))
233                        .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString());               
234            assertEquals(Iterables.get(result, 8).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);      
235
236   }
237
238   static Location defaultLocation = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description(
239            "us-east-1").build();
240
241   public static Set<org.jclouds.compute.domain.Image> convertImages(String resource) {
242
243      Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() {
244      }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
245               .getInstance(Json.class));
246
247      // note this method is what mandates the location id as us-east-1
248      Set<Image> result = DescribeImagesResponseHandlerTest.parseImages(resource);
249      EC2ImageParser parser = new EC2ImageParser(EC2ComputeServiceDependenciesModule.toPortableImageStatus,
250               new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, Suppliers
251                        .<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
252                        .ofInstance(defaultLocation), new GreenQloudComputeReviseParsedImage(map));
253      return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull()));
254   }
255
256}