EMMA Coverage Report (generated Wed Jun 22 19:47:49 EDT 2011)
[all classes][org.jclouds.vcloud.terremark.binders]

COVERAGE SUMMARY FOR SOURCE FILE [BindAddNodeServiceToXmlPayload.java]

nameclass, %method, %block, %line, %
BindAddNodeServiceToXmlPayload.java100% (1/1)67%  (2/3)91%  (75/82)90%  (9/10)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BindAddNodeServiceToXmlPayload100% (1/1)67%  (2/3)91%  (75/82)90%  (9/10)
bindToRequest (HttpRequest, Object): HttpRequest 0%   (0/1)0%   (0/5)0%   (0/1)
bindToRequest (HttpRequest, Map): HttpRequest 100% (1/1)97%  (72/74)100% (8/8)
BindAddNodeServiceToXmlPayload (): void 100% (1/1)100% (3/3)100% (1/1)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.vcloud.terremark.binders;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static org.jclouds.vcloud.terremark.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NS;
23 
24import java.util.Map;
25 
26import javax.inject.Inject;
27import javax.inject.Named;
28import javax.inject.Singleton;
29 
30import org.jclouds.http.HttpRequest;
31import org.jclouds.rest.MapBinder;
32import org.jclouds.rest.binders.BindToStringPayload;
33import org.jclouds.util.Patterns;
34import org.jclouds.util.Strings2;
35 
36import com.google.common.collect.ImmutableMap;
37 
38/**
39 * 
40 * @author Adrian Cole
41 * 
42 */
43@Singleton
44public class BindAddNodeServiceToXmlPayload implements MapBinder {
45 
46   @Inject
47   @Named("CreateNodeService")
48   private String xmlTemplate;
49   @Inject
50   private BindToStringPayload stringBinder;
51   @Inject
52   @Named(PROPERTY_TERREMARK_EXTENSION_NS)
53   private String ns;
54 
55   @Override
56   public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
57      String ipAddress = checkNotNull(postParams.get("ipAddress"), "ipAddress parameter not present");
58      String name = checkNotNull(postParams.get("name"), "name parameter not present");
59      String port = checkNotNull(postParams.get("port"), "port parameter not present");
60      String enabled = checkNotNull(postParams.get("enabled"), "enabled parameter not present");
61      String description = postParams.get("description");
62 
63      String payload = Strings2.replaceTokens(xmlTemplate,
64            ImmutableMap.of("name", name, "ipAddress", ipAddress, "port", port, "enabled", enabled, "ns", ns));
65      payload = Strings2.replaceAll(payload, Patterns.TOKEN_TO_PATTERN.get("description"), description == null ? ""
66            : String.format("\n    <Description>%s</Description>", description));
67      return stringBinder.bindToRequest(request, payload);
68   }
69 
70   @Override
71   public <R extends HttpRequest> R bindToRequest(R request, Object input) {
72      throw new IllegalStateException("CreateNodeService needs parameters");
73   }
74 
75}

[all classes][org.jclouds.vcloud.terremark.binders]
EMMA 2.0.5312 (C) Vladimir Roubtsov