EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.aws.ec2.binders]

COVERAGE SUMMARY FOR SOURCE FILE [BindLaunchSpecificationToFormParams.java]

nameclass, %method, %block, %line, %
BindLaunchSpecificationToFormParams.java100% (1/1)100% (3/3)91%  (135/148)90%  (26/29)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BindLaunchSpecificationToFormParams100% (1/1)100% (3/3)91%  (135/148)90%  (26/29)
apply (LaunchSpecification): Map 100% (1/1)90%  (116/129)88%  (22/25)
BindLaunchSpecificationToFormParams (): void 100% (1/1)100% (3/3)100% (1/1)
bindToRequest (HttpRequest, Object): HttpRequest 100% (1/1)100% (16/16)100% (3/3)

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.aws.ec2.binders;
20 
21import static com.google.common.base.Preconditions.checkArgument;
22import static com.google.common.base.Preconditions.checkNotNull;
23 
24import java.util.Map;
25import java.util.Map.Entry;
26 
27import javax.inject.Singleton;
28 
29import org.jclouds.aws.ec2.domain.LaunchSpecification;
30import org.jclouds.aws.ec2.options.AWSRunInstancesOptions;
31import org.jclouds.http.HttpRequest;
32import org.jclouds.http.utils.ModifyRequest;
33import org.jclouds.rest.Binder;
34 
35import com.google.common.base.Function;
36import com.google.common.collect.ImmutableMap;
37import com.google.common.collect.ImmutableMap.Builder;
38import com.google.common.collect.Multimaps;
39 
40/**
41 * 
42 * @author Adrian Cole
43 */
44@Singleton
45public class BindLaunchSpecificationToFormParams implements Binder, Function<LaunchSpecification, Map<String, String>> {
46 
47   @Override
48   public <R extends HttpRequest> R bindToRequest(R request, Object input) {
49      checkArgument(input instanceof LaunchSpecification, "this binder is only valid for LaunchSpecifications!");
50      LaunchSpecification launchSpec = LaunchSpecification.class.cast(input);
51      return ModifyRequest.putFormParams(request, Multimaps.forMap(apply(launchSpec)));
52   }
53 
54   @Override
55   public Map<String, String> apply(LaunchSpecification launchSpec) {
56      Builder<String, String> builder = ImmutableMap.<String, String> builder();
57      builder.put("LaunchSpecification.ImageId", checkNotNull(launchSpec.getImageId(), "imageId"));
58      if (launchSpec.getAvailabilityZone() != null)
59         builder.put("LaunchSpecification.Placement.AvailabilityZone", launchSpec.getAvailabilityZone());
60 
61      AWSRunInstancesOptions options = new AWSRunInstancesOptions();
62      if (launchSpec.getBlockDeviceMappings().size() > 0)
63         options.withBlockDeviceMappings(launchSpec.getBlockDeviceMappings());
64      if (launchSpec.getSecurityGroupNames().size() > 0)
65         options.withSecurityGroups(launchSpec.getSecurityGroupNames());
66      if (launchSpec.getSecurityGroupIds().size() > 0)
67         options.withSecurityGroupIds(launchSpec.getSecurityGroupIds());
68      options.asType(checkNotNull(launchSpec.getInstanceType(), "instanceType"));
69      if (launchSpec.getKernelId() != null)
70         options.withKernelId(launchSpec.getKernelId());
71      if (launchSpec.getKeyName() != null)
72         options.withKeyName(launchSpec.getKeyName());
73      if (launchSpec.getRamdiskId() != null)
74         options.withRamdisk(launchSpec.getRamdiskId());
75      if (Boolean.TRUE.equals(launchSpec.isMonitoringEnabled()))
76         options.enableMonitoring();
77      if (launchSpec.getUserData() != null)
78         options.withUserData(launchSpec.getUserData());
79 
80      for (Entry<String, String> entry : options.buildFormParameters().entries()) {
81         builder.put("LaunchSpecification." + entry.getKey(), entry.getValue());
82      }
83      return builder.build();
84   }
85}

[all classes][org.jclouds.aws.ec2.binders]
EMMA 2.0.5312 (C) Vladimir Roubtsov