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

COVERAGE SUMMARY FOR SOURCE FILE [ParseServerNameToCredentialsMapFromJsonResponse.java]

nameclass, %method, %block, %line, %
ParseServerNameToCredentialsMapFromJsonResponse.java100% (2/2)78%  (7/9)42%  (73/174)47%  (14/30)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ParseServerNameToCredentialsMapFromJsonResponse$Password100% (1/1)71%  (5/7)23%  (30/131)27%  (6/22)
equals (Object): boolean 0%   (0/1)0%   (0/64)0%   (0/12)
hashCode (): int 0%   (0/1)0%   (0/37)0%   (0/4)
ParseServerNameToCredentialsMapFromJsonResponse$Password (): void 100% (1/1)100% (3/3)100% (1/1)
compareTo (ParseServerNameToCredentialsMapFromJsonResponse$Password): int 100% (1/1)100% (18/18)100% (2/2)
getPassword (): String 100% (1/1)100% (3/3)100% (1/1)
getServer (): Server 100% (1/1)100% (3/3)100% (1/1)
getUserName (): String 100% (1/1)100% (3/3)100% (1/1)
     
class ParseServerNameToCredentialsMapFromJsonResponse100% (1/1)100% (2/2)100% (43/43)100% (8/8)
ParseServerNameToCredentialsMapFromJsonResponse (ParseJson): void 100% (1/1)100% (6/6)100% (3/3)
apply (HttpResponse): Map 100% (1/1)100% (37/37)100% (5/5)

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.gogrid.functions;
20 
21import java.util.Map;
22 
23import javax.inject.Inject;
24import javax.inject.Singleton;
25 
26import org.jclouds.domain.Credentials;
27import org.jclouds.gogrid.domain.Server;
28import org.jclouds.http.HttpResponse;
29import org.jclouds.http.functions.ParseJson;
30 
31import com.google.common.base.Function;
32import com.google.common.collect.Maps;
33import com.google.gson.annotations.SerializedName;
34 
35/**
36 * @author Oleksiy Yarmula
37 */
38@Singleton
39public class ParseServerNameToCredentialsMapFromJsonResponse implements
40      Function<HttpResponse, Map<String, Credentials>> {
41   private final ParseJson<GenericResponseContainer<Password>> json;
42 
43   @Inject
44   ParseServerNameToCredentialsMapFromJsonResponse(
45         ParseJson<GenericResponseContainer<Password>> json) {
46      this.json = json;
47   }
48 
49   // incidental wrapper class to assist in getting the correct data
50   // deserialized from json
51   private static class Password implements Comparable<Password> {
52      @SerializedName("username")
53      private String userName;
54      private String password;
55      private Server server;
56 
57      public String getUserName() {
58         return userName;
59      }
60 
61      public String getPassword() {
62         return password;
63      }
64 
65      public Server getServer() {
66         return server;
67      }
68 
69      @Override
70      public boolean equals(Object o) {
71         if (this == o)
72            return true;
73         if (o == null || getClass() != o.getClass())
74            return false;
75 
76         Password password1 = (Password) o;
77 
78         if (password != null ? !password.equals(password1.password)
79               : password1.password != null)
80            return false;
81         if (server != null ? !server.equals(password1.server)
82               : password1.server != null)
83            return false;
84         if (userName != null ? !userName.equals(password1.userName)
85               : password1.userName != null)
86            return false;
87 
88         return true;
89      }
90 
91      @Override
92      public int hashCode() {
93         int result = userName != null ? userName.hashCode() : 0;
94         result = 31 * result + (password != null ? password.hashCode() : 0);
95         result = 31 * result + (server != null ? server.hashCode() : 0);
96         return result;
97      }
98 
99      @Override
100      public int compareTo(Password o) {
101          if (null == o.getServer() || null == server) return -1;
102        return server.getName().compareTo(o.getServer().getName());
103      }
104   }
105 
106   @Override
107   public Map<String, Credentials> apply(HttpResponse arg0) {
108      Map<String, Credentials> serverNameToCredentials = Maps.newHashMap();
109      for (Password password : json.apply(arg0).getList()) {
110          if( null != password.getServer())
111         serverNameToCredentials.put(password.getServer().getName(),
112               new Credentials(password.getUserName(), password.getPassword()));
113      }
114      return serverNameToCredentials;
115   }
116 
117}

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