EMMA Coverage Report (generated Mon Dec 09 15:12:29 EST 2013)
[all classes][org.jclouds.glesys.options]

COVERAGE SUMMARY FOR SOURCE FILE [CreateServerOptions.java]

nameclass, %method, %block, %line, %
CreateServerOptions.java100% (2/2)45%  (5/11)69%  (159/230)70%  (26.5/38)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CreateServerOptions$Builder100% (1/1)33%  (1/3)42%  (8/19)40%  (2/5)
CreateServerOptions$Builder (): void 0%   (0/1)0%   (0/3)0%   (0/1)
ip (String): CreateServerOptions 0%   (0/1)0%   (0/8)0%   (0/2)
description (String): CreateServerOptions 100% (1/1)100% (8/8)100% (2/2)
     
class CreateServerOptions100% (1/1)50%  (4/8)72%  (151/211)74%  (25/34)
bindToRequest (HttpRequest, Object): HttpRequest 0%   (0/1)0%   (0/4)0%   (0/1)
equals (Object): boolean 0%   (0/1)0%   (0/30)0%   (0/6)
hashCode (): int 0%   (0/1)0%   (0/14)0%   (0/1)
toString (): String 0%   (0/1)0%   (0/12)0%   (0/1)
CreateServerOptions (): void 100% (1/1)100% (3/3)100% (2/2)
bindToRequest (HttpRequest, Map): HttpRequest 100% (1/1)100% (138/138)100% (19/19)
description (String): CreateServerOptions 100% (1/1)100% (5/5)100% (2/2)
ip (String): CreateServerOptions 100% (1/1)100% (5/5)100% (2/2)

1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package org.jclouds.glesys.options;
18 
19import static com.google.common.base.Objects.equal;
20import static com.google.common.base.Objects.toStringHelper;
21import static com.google.common.base.Preconditions.checkArgument;
22import static com.google.common.base.Preconditions.checkNotNull;
23import static com.google.common.base.Predicates.instanceOf;
24import static com.google.common.collect.Iterables.find;
25 
26import java.util.Map;
27 
28import org.jclouds.glesys.domain.ServerSpec;
29import org.jclouds.http.HttpRequest;
30import org.jclouds.io.payloads.UrlEncodedFormPayload;
31import org.jclouds.rest.MapBinder;
32import org.jclouds.rest.internal.GeneratedHttpRequest;
33 
34import com.google.common.base.Objects;
35import com.google.common.collect.ImmutableMultimap;
36 
37/**
38 * @author Adam Lowe
39 */
40public class CreateServerOptions implements MapBinder {
41 
42   private String ip;
43   private String description;
44 
45   @Override
46   public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
47      checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
48            "this binder is only valid for GeneratedHttpRequests!");
49      GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
50      ImmutableMultimap.Builder<String, String> formParams = ImmutableMultimap.builder();
51      for (Map.Entry<String, Object> entry : postParams.entrySet())
52         formParams.put(entry.getKey(), (String) entry.getValue());
53      ServerSpec serverSpec = ServerSpec.class.cast(find(gRequest.getInvocation().getArgs(),
54            instanceOf(ServerSpec.class)));
55      formParams.put("datacenter", serverSpec.getDatacenter());
56      formParams.put("platform", serverSpec.getPlatform());
57      formParams.put("templatename", serverSpec.getTemplateName());
58      formParams.put("disksize", serverSpec.getDiskSizeGB() + "");
59      formParams.put("memorysize", serverSpec.getMemorySizeMB() + "");
60      formParams.put("cpucores", serverSpec.getCpuCores() + "");
61      formParams.put("transfer", serverSpec.getTransferGB() + "");
62      if (ip != null)
63         formParams.put("ip", ip);
64      if (description != null)
65         formParams.put("description", description);
66 
67      request.setPayload(new UrlEncodedFormPayload(formParams.build()));
68      return request;
69   }
70 
71   public static class Builder {
72      /**
73       * @see CreateServerOptions#description
74       */
75      public static CreateServerOptions description(String primaryNameServer) {
76         CreateServerOptions options = new CreateServerOptions();
77         return options.description(primaryNameServer);
78      }
79 
80      /**
81       * @see CreateServerOptions#ip
82       */
83      public static CreateServerOptions ip(String ip) {
84         CreateServerOptions options = new CreateServerOptions();
85         return options.ip(ip);
86      }
87   }
88 
89   /**
90    * @param description
91    *           the description of the server
92    */
93   public CreateServerOptions description(String description) {
94      this.description = description;
95      return this;
96   }
97 
98   /**
99    * @param ip
100    *           the ip address to assign to the server
101    */
102   public CreateServerOptions ip(String ip) {
103      this.ip = ip;
104      return this;
105   }
106 
107   @Override
108   public <R extends HttpRequest> R bindToRequest(R request, Object input) {
109      throw new IllegalArgumentException();
110   }
111 
112   @Override
113   public int hashCode() {
114      return Objects.hashCode(ip, description);
115   }
116 
117   @Override
118   public boolean equals(Object obj) {
119      if (obj == null)
120         return false;
121      if (!(obj instanceof CreateServerOptions))
122         return false;
123      CreateServerOptions that = CreateServerOptions.class.cast(obj);
124      return equal(this.ip, that.ip) && equal(this.description, that.description);
125   }
126 
127   @Override
128   public String toString() {
129      return toStringHelper("").add("ip", ip).add("description", description).toString();
130   }
131 
132}

[all classes][org.jclouds.glesys.options]
EMMA 2.0.5312 (C) Vladimir Roubtsov