EMMA Coverage Report (generated Wed Jun 22 19:47:49 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%  (126/139)89%  (24/27)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BindLaunchSpecificationToFormParams100% (1/1)100% (3/3)91%  (126/139)89%  (24/27)
apply (LaunchSpecification): Map 100% (1/1)89%  (107/120)87%  (20/23)
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 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
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.getGroupIds().size() > 0)
65         options.withSecurityGroups(launchSpec.getGroupIds());
66      options.asType(checkNotNull(launchSpec.getInstanceType(), "instanceType"));
67      if (launchSpec.getKernelId() != null)
68         options.withKernelId(launchSpec.getKernelId());
69      if (launchSpec.getKeyName() != null)
70         options.withKeyName(launchSpec.getKeyName());
71      if (launchSpec.getRamdiskId() != null)
72         options.withRamdisk(launchSpec.getRamdiskId());
73      if (Boolean.TRUE.equals(launchSpec.isMonitoringEnabled()))
74         options.enableMonitoring();
75      if (launchSpec.getUserData() != null)
76         options.withUserData(launchSpec.getUserData());
77 
78      for (Entry<String, String> entry : options.buildFormParameters().entries()) {
79         builder.put("LaunchSpecification." + entry.getKey(), entry.getValue());
80      }
81      return builder.build();
82   }
83}

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