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

COVERAGE SUMMARY FOR SOURCE FILE [BindCloneDriveOptionsToPlainTextString.java]

nameclass, %method, %block, %line, %
BindCloneDriveOptionsToPlainTextString.java100% (1/1)75%  (3/4)80%  (71/89)85%  (17/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BindCloneDriveOptionsToPlainTextString100% (1/1)75%  (3/4)80%  (71/89)85%  (17/20)
bindToRequest (HttpRequest, Object): HttpRequest 0%   (0/1)0%   (0/4)0%   (0/1)
findOptionsInArgsOrNull (GeneratedHttpRequest): CloneDriveOptions 100% (1/1)63%  (22/35)72%  (5.1/7)
bindToRequest (HttpRequest, Map): HttpRequest 100% (1/1)98%  (43/44)99%  (9/9)
BindCloneDriveOptionsToPlainTextString (ListOfMapsToListOfKeyValuesDelimitedB... 100% (1/1)100% (6/6)100% (3/3)

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.cloudsigma.binders;
20 
21import static com.google.common.base.Preconditions.checkArgument;
22import static com.google.common.base.Preconditions.checkNotNull;
23import static com.google.common.base.Preconditions.checkState;
24 
25import java.util.Map;
26 
27import javax.inject.Inject;
28import javax.inject.Singleton;
29import javax.ws.rs.core.MediaType;
30 
31import org.jclouds.cloudsigma.CloudSigmaAsyncClient;
32import org.jclouds.cloudsigma.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines;
33import org.jclouds.cloudsigma.options.CloneDriveOptions;
34import org.jclouds.http.HttpRequest;
35import org.jclouds.rest.MapBinder;
36import org.jclouds.rest.internal.GeneratedHttpRequest;
37 
38import com.google.common.collect.ImmutableMap;
39import com.google.common.collect.ImmutableSet;
40 
41/**
42 * 
43 * @author Adrian Cole
44 */
45@Singleton
46public class BindCloneDriveOptionsToPlainTextString implements MapBinder {
47   private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines;
48 
49   @Inject
50   public BindCloneDriveOptionsToPlainTextString(
51         ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) {
52      this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines;
53   }
54 
55   @Override
56   public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
57      checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
58            "this binder is only valid for GeneratedHttpRequests!");
59      @SuppressWarnings("unchecked")
60      GeneratedHttpRequest<CloudSigmaAsyncClient> gRequest = (GeneratedHttpRequest<CloudSigmaAsyncClient>) request;
61      checkState(gRequest.getArgs() != null, "args should be initialized at this point");
62 
63      CloneDriveOptions options = findOptionsInArgsOrNull(gRequest);
64      if (options != null) {
65         postParams = ImmutableMap.<String, String> builder().putAll(postParams).putAll(options.getOptions()).build();
66      }
67 
68      request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(postParams)));
69      request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN);
70      return request;
71   }
72 
73   static CloneDriveOptions findOptionsInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
74      for (Object arg : gRequest.getArgs()) {
75         if (arg instanceof CloneDriveOptions) {
76            return (CloneDriveOptions) arg;
77         } else if (arg instanceof CloneDriveOptions[]) {
78            CloneDriveOptions[] options = (CloneDriveOptions[]) arg;
79            return (options.length > 0) ? options[0] : null;
80         }
81      }
82      return null;
83   }
84 
85   @Override
86   public <R extends HttpRequest> R bindToRequest(R request, Object input) {
87      throw new UnsupportedOperationException();
88   }
89 
90}

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