EMMA Coverage Report (generated Fri Aug 26 14:14:05 EDT 2011)
[all classes][org.jclouds.rimuhosting.miro.functions]

COVERAGE SUMMARY FOR SOURCE FILE [ParseRimuHostingException.java]

nameclass, %method, %block, %line, %
ParseRimuHostingException.java50%  (1/2)33%  (1/3)9%   (6/70)20%  (3/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ParseRimuHostingException$10%   (0/1)0%   (0/1)0%   (0/6)0%   (0/1)
ParseRimuHostingException$1 (ParseRimuHostingException): void 0%   (0/1)0%   (0/6)0%   (0/1)
     
class ParseRimuHostingException100% (1/1)50%  (1/2)9%   (6/64)20%  (3/15)
apply (Exception): Object 0%   (0/1)0%   (0/58)0%   (0/12)
ParseRimuHostingException (Json): void 100% (1/1)100% (6/6)100% (3/3)

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.rimuhosting.miro.functions;
20 
21import static org.jclouds.util.Throwables2.propagateOrNull;
22 
23import java.lang.reflect.Type;
24import java.util.Map;
25 
26import javax.inject.Inject;
27import javax.inject.Singleton;
28 
29import org.jclouds.http.HttpResponseException;
30import org.jclouds.json.Json;
31import org.jclouds.rest.AuthorizationException;
32import org.jclouds.rimuhosting.miro.domain.internal.RimuHostingResponse;
33 
34import com.google.common.base.Function;
35import com.google.common.collect.Iterables;
36import com.google.gson.reflect.TypeToken;
37 
38/**
39 * On non 2xx we have an error. RimuHosting using the same json base object.
40 * 
41 * TODO: map exceptions out into something that suits jclouds.
42 * 
43 * @author Ivan Meredith
44 */
45@Singleton
46public class ParseRimuHostingException implements Function<Exception, Object> {
47   private Json json;
48 
49   @Inject
50   public ParseRimuHostingException(Json json) {
51      this.json = json;
52   }
53 
54   @Override
55   public Object apply(Exception e) {
56      if (e instanceof HttpResponseException) {
57         HttpResponseException responseException = (HttpResponseException) e;
58         if (responseException.getContent() != null) {
59            Type setType = new TypeToken<Map<String, RimuHostingResponse>>() {
60            }.getType();
61            String test = responseException.getContent();
62            Map<String, RimuHostingResponse> responseMap = json.fromJson(test, setType);
63            RimuHostingResponse firstResponse = Iterables.get(responseMap.values(), 0);
64            String errorClass = firstResponse.getErrorInfo().getErrorClass();
65            if (errorClass.equals("PermissionException"))
66               throw new AuthorizationException(
67                        firstResponse.getErrorInfo().getErrorMessage(), responseException);
68            throw new RuntimeException(firstResponse.getErrorInfo().getErrorMessage(), e);
69         }
70      }
71      return propagateOrNull(e);
72   }
73}

[all classes][org.jclouds.rimuhosting.miro.functions]
EMMA 2.0.5312 (C) Vladimir Roubtsov