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

COVERAGE SUMMARY FOR SOURCE FILE [BindAddNodeServiceToXmlPayload.java]

nameclass, %method, %block, %line, %
BindAddNodeServiceToXmlPayload.java100% (1/1)67%  (2/3)87%  (76/87)77%  (10/13)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BindAddNodeServiceToXmlPayload100% (1/1)67%  (2/3)87%  (76/87)77%  (10/13)
bindToRequest (HttpRequest, Object): HttpRequest 0%   (0/1)0%   (0/5)0%   (0/1)
bindToRequest (HttpRequest, Map): HttpRequest 100% (1/1)92%  (73/79)82%  (9/11)
BindAddNodeServiceToXmlPayload (): void 100% (1/1)100% (3/3)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.trmk.vcloud_0_8.binders;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NS;
23 
24import java.util.Map;
25import java.util.concurrent.ExecutionException;
26 
27import javax.inject.Inject;
28import javax.inject.Named;
29import javax.inject.Singleton;
30 
31import org.jclouds.http.HttpRequest;
32import org.jclouds.rest.MapBinder;
33import org.jclouds.rest.binders.BindToStringPayload;
34import org.jclouds.util.Patterns;
35import org.jclouds.util.Strings2;
36 
37import com.google.common.base.Throwables;
38import com.google.common.collect.ImmutableMap;
39 
40/**
41 * 
42 * @author Adrian Cole
43 * 
44 */
45@Singleton
46public class BindAddNodeServiceToXmlPayload implements MapBinder {
47 
48   @Inject
49   @Named("CreateNodeService")
50   private String xmlTemplate;
51   @Inject
52   private BindToStringPayload stringBinder;
53   @Inject
54   @Named(PROPERTY_TERREMARK_EXTENSION_NS)
55   private String ns;
56 
57   @Override
58   public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
59      String ipAddress = checkNotNull(postParams.get("ipAddress"), "ipAddress parameter not present");
60      String name = checkNotNull(postParams.get("name"), "name parameter not present");
61      String port = checkNotNull(postParams.get("port"), "port parameter not present");
62      String enabled = checkNotNull(postParams.get("enabled"), "enabled parameter not present");
63      String description = postParams.get("description");
64 
65      String payload = Strings2.replaceTokens(xmlTemplate,
66            ImmutableMap.of("name", name, "ipAddress", ipAddress, "port", port, "enabled", enabled, "ns", ns));
67      try {
68         payload = Strings2.replaceAll(payload, Patterns.TOKEN_TO_PATTERN.get("description"), description == null ? ""
69               : String.format("\n    <Description>%s</Description>", description));
70      } catch (ExecutionException e) {
71         Throwables.propagate(e);
72      }
73      return stringBinder.bindToRequest(request, payload);
74   }
75 
76   @Override
77   public <R extends HttpRequest> R bindToRequest(R request, Object input) {
78      throw new IllegalStateException("CreateNodeService needs parameters");
79   }
80 
81}

[all classes][org.jclouds.trmk.vcloud_0_8.binders]
EMMA 2.0.5312 (C) Vladimir Roubtsov