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

COVERAGE SUMMARY FOR SOURCE FILE [UnwrapLoadBalancer.java]

nameclass, %method, %block, %line, %
UnwrapLoadBalancer.java100% (1/1)100% (4/4)96%  (49/51)91%  (10/11)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class UnwrapLoadBalancer100% (1/1)100% (4/4)96%  (49/51)91%  (10/11)
apply (HttpResponse): LoadBalancer 100% (1/1)92%  (22/24)80%  (4/5)
UnwrapLoadBalancer (ParseJson): void 100% (1/1)100% (6/6)100% (3/3)
setContext (HttpRequest): UnwrapLoadBalancer 100% (1/1)100% (13/13)100% (1/1)
setRegion (String): UnwrapLoadBalancer 100% (1/1)100% (8/8)100% (2/2)

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.cloudloadbalancers.functions;
20 
21import java.util.Map;
22 
23import javax.inject.Inject;
24 
25import org.jclouds.cloudloadbalancers.domain.LoadBalancer;
26import org.jclouds.http.HttpRequest;
27import org.jclouds.http.HttpResponse;
28import org.jclouds.http.functions.ParseJson;
29import org.jclouds.rest.InvocationContext;
30 
31import com.google.common.base.Function;
32import com.google.common.collect.Iterables;
33 
34/**
35 * @author Adrian Cole
36 */
37public class UnwrapLoadBalancer implements Function<HttpResponse, LoadBalancer>, InvocationContext<UnwrapLoadBalancer> {
38 
39   private final ParseJson<Map<String, LB>> json;
40   private ConvertLB convertLB;
41 
42   @Inject
43   UnwrapLoadBalancer(ParseJson<Map<String, LB>> json) {
44      this.json = json;
45   }
46 
47   @Override
48   public LoadBalancer apply(HttpResponse arg0) {
49      Map<String, LB> map = json.apply(arg0);
50      if (map == null || map.size() == 0)
51         return null;
52      LB lb = Iterables.get(map.values(), 0);
53      return convertLB.apply(lb);
54   }
55 
56   @Override
57   public UnwrapLoadBalancer setContext(HttpRequest request) {
58      return setRegion(request.getEndpoint().getHost().substring(0, request.getEndpoint().getHost().indexOf('.')));
59   }
60 
61   UnwrapLoadBalancer setRegion(String region) {
62      this.convertLB = new ConvertLB(region);
63      return this;
64   }
65 
66}

[all classes][org.jclouds.cloudloadbalancers.functions]
EMMA 2.0.5312 (C) Vladimir Roubtsov