EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.trmk.vcloud_0_8.compute.strategy]

COVERAGE SUMMARY FOR SOURCE FILE [CreateNewKeyPairUnlessUserSpecifiedOtherwise.java]

nameclass, %method, %block, %line, %
CreateNewKeyPairUnlessUserSpecifiedOtherwise.java100% (1/1)100% (2/2)68%  (42/62)79%  (11/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CreateNewKeyPairUnlessUserSpecifiedOtherwise100% (1/1)100% (2/2)68%  (42/62)79%  (11/14)
execute (URI, String, String, TerremarkVCloudTemplateOptions): void 100% (1/1)62%  (33/53)70%  (7/10)
CreateNewKeyPairUnlessUserSpecifiedOtherwise (ConcurrentMap, CreateUniqueKeyP... 100% (1/1)100% (9/9)100% (4/4)

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.trmk.vcloud_0_8.compute.strategy;
20 
21import java.net.URI;
22import java.util.concurrent.ConcurrentMap;
23 
24import javax.inject.Inject;
25import javax.inject.Singleton;
26 
27import org.jclouds.trmk.vcloud_0_8.compute.domain.KeyPairCredentials;
28import org.jclouds.trmk.vcloud_0_8.compute.domain.OrgAndName;
29import org.jclouds.trmk.vcloud_0_8.compute.functions.CreateUniqueKeyPair;
30import org.jclouds.trmk.vcloud_0_8.compute.options.TerremarkVCloudTemplateOptions;
31import org.jclouds.trmk.vcloud_0_8.domain.KeyPair;
32 
33import com.google.common.annotations.VisibleForTesting;
34 
35/**
36 * 
37 * @author Adrian Cole
38 * 
39 */
40@Singleton
41public class CreateNewKeyPairUnlessUserSpecifiedOtherwise {
42   final ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap;
43   @VisibleForTesting
44   final CreateUniqueKeyPair createUniqueKeyPair;
45 
46   @Inject
47   CreateNewKeyPairUnlessUserSpecifiedOtherwise(ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap,
48         CreateUniqueKeyPair createUniqueKeyPair) {
49      this.credentialsMap = credentialsMap;
50      this.createUniqueKeyPair = createUniqueKeyPair;
51   }
52 
53   @VisibleForTesting
54   public void execute(URI org, String tag, String identity, TerremarkVCloudTemplateOptions options) {
55      String sshKeyFingerprint = options.getSshKeyFingerprint();
56      boolean shouldAutomaticallyCreateKeyPair = options.shouldAutomaticallyCreateKeyPair();
57      if (sshKeyFingerprint == null && shouldAutomaticallyCreateKeyPair) {
58         OrgAndName orgAndName = new OrgAndName(org, tag);
59         if (credentialsMap.containsKey(orgAndName)) {
60            options.sshKeyFingerprint(credentialsMap.get(orgAndName).getKeyPair().getFingerPrint());
61         } else {
62            KeyPair keyPair = createUniqueKeyPair.apply(orgAndName);
63            credentialsMap.put(orgAndName, new KeyPairCredentials(identity, keyPair));
64            options.sshKeyFingerprint(keyPair.getFingerPrint());
65         }
66      }
67   }
68}

[all classes][org.jclouds.trmk.vcloud_0_8.compute.strategy]
EMMA 2.0.5312 (C) Vladimir Roubtsov