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

COVERAGE SUMMARY FOR SOURCE FILE [BindAzureBlobMetadataToRequest.java]

nameclass, %method, %block, %line, %
BindAzureBlobMetadataToRequest.java100% (2/2)100% (3/3)87%  (113/130)82%  (13.9/17)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BindAzureBlobMetadataToRequest100% (1/1)100% (2/2)86%  (96/111)82%  (14/17)
bindToRequest (HttpRequest, Object): HttpRequest 100% (1/1)84%  (81/96)77%  (10/13)
BindAzureBlobMetadataToRequest (AzureBlobToBlob, BindUserMetadataToHeadersWit... 100% (1/1)100% (15/15)100% (4/4)
     
class BindAzureBlobMetadataToRequest$1100% (1/1)100% (1/1)89%  (17/19)89%  (0.9/1)
<static initializer> 100% (1/1)89%  (17/19)89%  (0.9/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.azureblob.binders;
20 
21import static com.google.common.base.Preconditions.checkArgument;
22import static com.google.common.base.Preconditions.checkNotNull;
23 
24import javax.inject.Inject;
25import javax.inject.Singleton;
26import javax.ws.rs.core.HttpHeaders;
27 
28import org.jclouds.azureblob.blobstore.functions.AzureBlobToBlob;
29import org.jclouds.azureblob.domain.AzureBlob;
30import org.jclouds.blobstore.binders.BindUserMetadataToHeadersWithPrefix;
31import org.jclouds.http.HttpRequest;
32import org.jclouds.http.utils.ModifyRequest;
33import org.jclouds.rest.Binder;
34 
35import com.google.common.collect.ImmutableMap;
36import com.google.common.collect.ImmutableMap.Builder;
37import com.google.common.collect.Multimaps;
38 
39@Singleton
40public class BindAzureBlobMetadataToRequest implements Binder {
41 
42   private final AzureBlobToBlob azureBlob2Blob;
43   private final BindUserMetadataToHeadersWithPrefix blobBinder;
44 
45   @Inject
46   public BindAzureBlobMetadataToRequest(AzureBlobToBlob azureBlob2Blob, BindUserMetadataToHeadersWithPrefix blobBinder) {
47      this.azureBlob2Blob = checkNotNull(azureBlob2Blob, "azureBlob2Blob");
48      this.blobBinder = checkNotNull(blobBinder, "blobBinder");
49   }
50 
51   @Override
52   public <R extends HttpRequest> R bindToRequest(R request, Object input) {
53      checkArgument(checkNotNull(input, "input") instanceof AzureBlob, "this binder is only valid for AzureBlobs!");
54      checkNotNull(request, "request");
55      AzureBlob blob = AzureBlob.class.cast(input);
56 
57      checkArgument(blob.getPayload().getContentMetadata().getContentLength() != null
58            && blob.getPayload().getContentMetadata().getContentLength() >= 0, "size must be set");
59 
60      Builder<String, String> headers = ImmutableMap.<String, String> builder();
61 
62      headers.put("x-ms-blob-type", blob.getProperties().getType().toString());
63 
64      switch (blob.getProperties().getType()) {
65      case PAGE_BLOB:
66         headers.put(HttpHeaders.CONTENT_LENGTH, "0");
67         headers.put("x-ms-blob-content-length", blob.getPayload().getContentMetadata().getContentLength().toString());
68         break;
69      case BLOCK_BLOB:
70         checkArgument(
71               checkNotNull(blob.getPayload().getContentMetadata().getContentLength(), "blob.getContentLength()") <= 64l * 1024 * 1024,
72               "maximum size for put Blob is 64MB");
73         break;
74      }
75      request = ModifyRequest.putHeaders(request, Multimaps.forMap(headers.build()));
76 
77      return blobBinder.bindToRequest(request, azureBlob2Blob.apply(blob));
78   }
79}

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