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

COVERAGE SUMMARY FOR SOURCE FILE [AtmosUtils.java]

nameclass, %method, %block, %line, %
AtmosUtils.java0%   (0/2)0%   (0/8)0%   (0/149)0%   (0/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AtmosUtils0%   (0/1)0%   (0/6)0%   (0/124)0%   (0/20)
AtmosUtils (): void 0%   (0/1)0%   (0/3)0%   (0/1)
adjustContainerIfDirOptionPresent (String, ListContainerOptions): String 0%   (0/1)0%   (0/20)0%   (0/4)
deleteAndEnsureGone (AtmosClient, String): void 0%   (0/1)0%   (0/36)0%   (0/6)
parseAtmosErrorFromContent (HttpCommand, HttpResponse, InputStream): AtmosError 0%   (0/1)0%   (0/24)0%   (0/4)
parseAtmosErrorFromContent (HttpCommand, HttpResponse, String): AtmosError 0%   (0/1)0%   (0/10)0%   (0/1)
putBlob (AtmosClient, Crypto, BlobToObject, String, Blob, PutOptions): String 0%   (0/1)0%   (0/31)0%   (0/4)
     
class AtmosUtils$10%   (0/1)0%   (0/2)0%   (0/25)0%   (0/3)
AtmosUtils$1 (AtmosClient, String): void 0%   (0/1)0%   (0/9)0%   (0/1)
get (): Boolean 0%   (0/1)0%   (0/16)0%   (0/2)

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.atmos.util;
20 
21import java.io.ByteArrayInputStream;
22import java.io.InputStream;
23 
24import javax.inject.Inject;
25import javax.inject.Provider;
26 
27import org.jclouds.atmos.AtmosClient;
28import org.jclouds.atmos.blobstore.functions.BlobToObject;
29import org.jclouds.atmos.domain.AtmosError;
30import org.jclouds.atmos.filters.SignRequest;
31import org.jclouds.atmos.options.PutOptions;
32import org.jclouds.atmos.xml.ErrorHandler;
33import org.jclouds.blobstore.domain.Blob;
34import org.jclouds.crypto.Crypto;
35import org.jclouds.http.HttpCommand;
36import org.jclouds.http.HttpException;
37import org.jclouds.http.HttpResponse;
38import org.jclouds.http.functions.ParseSax;
39import org.jclouds.util.Assertions;
40 
41import com.google.common.base.Supplier;
42 
43/**
44 * Encryption, Hashing, and IO Utilities needed to sign and verify Atmos Storage requests and
45 * responses.
46 * 
47 * @author Adrian Cole
48 */
49public class AtmosUtils {
50 
51   @Inject
52   SignRequest signer;
53 
54   @Inject
55   ParseSax.Factory factory;
56 
57   @Inject
58   Provider<ErrorHandler> errorHandlerProvider;
59 
60   public AtmosError parseAtmosErrorFromContent(HttpCommand command, HttpResponse response, InputStream content)
61            throws HttpException {
62      AtmosError error = (AtmosError) factory.create(errorHandlerProvider.get()).parse(content);
63      if (error.getCode() == 1032) {
64         error.setStringSigned(signer.createStringToSign(command.getCurrentRequest()));
65      }
66      return error;
67 
68   }
69 
70   public static String putBlob(final AtmosClient sync, Crypto crypto, BlobToObject blob2Object, String container,
71            Blob blob, PutOptions options) {
72      final String path = container + "/" + blob.getMetadata().getName();
73      deleteAndEnsureGone(sync, path);
74      sync.createFile(container, blob2Object.apply(blob), options);
75      return path;
76   }
77 
78   public static void deleteAndEnsureGone(final AtmosClient sync, final String path) {
79      try {
80         if (!Assertions.eventuallyTrue(new Supplier<Boolean>() {
81            public Boolean get() {
82               sync.deletePath(path);
83               return !sync.pathExists(path);
84            }
85         }, 3000)) {
86            throw new IllegalStateException(path + " still exists after deleting!");
87         }
88      } catch (InterruptedException e) {
89         new IllegalStateException(path + " interrupted during deletion!", e);
90      }
91   }
92 
93   public AtmosError parseAtmosErrorFromContent(HttpCommand command, HttpResponse response, String content)
94            throws HttpException {
95      return parseAtmosErrorFromContent(command, response, new ByteArrayInputStream(content.getBytes()));
96   }
97 
98   public static String adjustContainerIfDirOptionPresent(String container,
99            org.jclouds.blobstore.options.ListContainerOptions options) {
100      if (options != org.jclouds.blobstore.options.ListContainerOptions.NONE) {
101         // if (options.isRecursive()) {
102         // throw new UnsupportedOperationException("recursive not currently supported in emcsaas");
103         // }
104         if (options.getDir() != null) {
105            container = container + "/" + options.getDir();
106         }
107      }
108      return container;
109   }
110}

[all classes][org.jclouds.atmos.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov