EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.savvis.vpdc.util]

COVERAGE SUMMARY FOR SOURCE FILE [Utils.java]

nameclass, %method, %block, %line, %
Utils.java33%  (1/3)40%  (4/10)72%  (115/160)68%  (17.8/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class Utils$10%   (0/1)0%   (0/2)0%   (0/6)0%   (0/2)
Utils$1 (): void 0%   (0/1)0%   (0/3)0%   (0/1)
apply (NetworkConnectionSection): String 0%   (0/1)0%   (0/3)0%   (0/1)
     
class Utils$20%   (0/1)0%   (0/2)0%   (0/11)0%   (0/2)
Utils$2 (): void 0%   (0/1)0%   (0/3)0%   (0/1)
apply (NetworkConfigSection): Iterable 0%   (0/1)0%   (0/8)0%   (0/1)
     
class Utils100% (1/1)67%  (4/6)80%  (115/143)81%  (17.8/22)
Utils (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getIpsFromVM (VM): Set 0%   (0/1)0%   (0/22)0%   (0/3)
currentOrNull (StringBuilder): String 100% (1/1)83%  (10/12)92%  (1.8/2)
newResource (Map, String): Resource 100% (1/1)98%  (64/65)100% (8/8)
cleanseAttributes (Attributes): Map 100% (1/1)100% (37/37)100% (7/7)
newResource (Map): Resource 100% (1/1)100% (4/4)100% (1/1)

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.savvis.vpdc.util;
20 
21import static com.google.common.base.Predicates.notNull;
22import static com.google.common.collect.Iterables.concat;
23import static com.google.common.collect.Iterables.filter;
24import static com.google.common.collect.Iterables.transform;
25 
26import java.net.URI;
27import java.util.Map;
28import java.util.Set;
29 
30import org.jclouds.savvis.vpdc.domain.Link;
31import org.jclouds.savvis.vpdc.domain.NetworkConfigSection;
32import org.jclouds.savvis.vpdc.domain.NetworkConnectionSection;
33import org.jclouds.savvis.vpdc.domain.Resource;
34import org.jclouds.savvis.vpdc.domain.ResourceImpl;
35import org.jclouds.savvis.vpdc.domain.VM;
36import org.xml.sax.Attributes;
37 
38import com.google.common.base.Function;
39import com.google.common.collect.ImmutableMap;
40import com.google.common.collect.ImmutableSet;
41import com.google.common.collect.ImmutableMap.Builder;
42 
43/**
44 * 
45 * @author Adrian Cole
46 */
47public class Utils {
48 
49   public static Resource newResource(Map<String, String> attributes, String defaultType) {
50      String uri = attributes.get("href");
51      String type = attributes.get("type");
52      // savvis org has null href
53      String id = null;
54      URI href = null;
55      if (uri != null) {
56         href = URI.create(uri);
57         id = uri.substring(uri.lastIndexOf('/') + 1);
58      }
59      return (attributes.containsKey("rel")) ? new Link(id, attributes.get("name"), type != null ? type : defaultType,
60               href, attributes.get("rel")) : new ResourceImpl(id, attributes.get("name"), type != null ? type
61               : defaultType, href);
62   }
63 
64   public static Set<String> getIpsFromVM(VM vm) {
65      Iterable<String> ipFromConnections = transform(vm.getNetworkConnectionSections(),
66               new Function<NetworkConnectionSection, String>() {
67                  @Override
68                  public String apply(NetworkConnectionSection input) {
69                     return input.getIpAddress();
70                  };
71               });
72      Iterable<String> ipsFromNat = concat(transform(vm.getNetworkConfigSections(),
73               new Function<NetworkConfigSection, Iterable<String>>() {
74                  @Override
75                  public Iterable<String> apply(NetworkConfigSection input) {
76                     return concat(input.getInternalToExternalNATRules().keySet(), input
77                              .getInternalToExternalNATRules().values());
78                  };
79               }));
80      return ImmutableSet.copyOf(filter(concat(ipFromConnections, ipsFromNat), notNull()));
81   }
82 
83   public static Map<String, String> cleanseAttributes(Attributes in) {
84      Builder<String, String> attrs = ImmutableMap.<String, String> builder();
85      for (int i = 0; i < in.getLength(); i++) {
86         String name = in.getQName(i);
87         if (name.indexOf(':') != -1)
88            name = name.substring(name.indexOf(':') + 1);
89         attrs.put(name, in.getValue(i));
90      }
91      return attrs.build();
92   }
93 
94   public static String currentOrNull(StringBuilder currentText) {
95      String returnVal = currentText.toString().trim();
96      return returnVal.equals("") ? null : returnVal;
97   }
98 
99   public static Resource newResource(Map<String, String> attributes) {
100      return newResource(attributes, null);
101   }
102}

[all classes][org.jclouds.savvis.vpdc.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov