EMMA Coverage Report (generated Wed Jun 22 19:47:49 EDT 2011)
[all classes][org.jclouds.vcloud.config]

COVERAGE SUMMARY FOR SOURCE FILE [BaseVCloudRestClientModule.java]

nameclass, %method, %block, %line, %
BaseVCloudRestClientModule.java80%  (4/5)50%  (6/12)46%  (57/124)55%  (12/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BaseVCloudRestClientModule$30%   (0/1)0%   (0/3)0%   (0/38)0%   (0/6)
<static initializer> 0%   (0/1)0%   (0/8)0%   (0/1)
BaseVCloudRestClientModule$3 (BaseVCloudRestClientModule, VCloudLoginAsyncCli... 0%   (0/1)0%   (0/9)0%   (0/1)
get (): VCloudSession 0%   (0/1)0%   (0/21)0%   (0/5)
     
class BaseVCloudRestClientModule$VCloudWritableCatalog100% (1/1)50%  (1/2)37%  (7/19)75%  (3/4)
apply (ReferenceType): boolean 0%   (0/1)0%   (0/12)0%   (0/1)
BaseVCloudRestClientModule$VCloudWritableCatalog (VCloudClient): void 100% (1/1)100% (7/7)100% (3/3)
     
class BaseVCloudRestClientModule100% (1/1)60%  (3/5)69%  (38/55)73%  (8/11)
BaseVCloudRestClientModule (Class, Class): void 0%   (0/1)0%   (0/5)0%   (0/2)
provideVCloudTokenCache (long, VCloudLoginAsyncClient): Supplier 0%   (0/1)0%   (0/12)0%   (0/1)
BaseVCloudRestClientModule (Class, Class, Map): void 100% (1/1)100% (6/6)100% (2/2)
configure (): void 100% (1/1)100% (27/27)100% (5/5)
provideVCloudLogin (AsyncClientFactory): VCloudLoginAsyncClient 100% (1/1)100% (5/5)100% (1/1)
     
class BaseVCloudRestClientModule$1100% (1/1)100% (1/1)100% (6/6)100% (1/1)
BaseVCloudRestClientModule$1 (BaseVCloudRestClientModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class BaseVCloudRestClientModule$2100% (1/1)100% (1/1)100% (6/6)100% (1/1)
BaseVCloudRestClientModule$2 (BaseVCloudRestClientModule): void 100% (1/1)100% (6/6)100% (1/1)

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.vcloud.config;
20 
21import static com.google.common.base.Throwables.propagate;
22import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
23 
24import java.util.Map;
25import java.util.concurrent.TimeUnit;
26 
27import javax.inject.Inject;
28import javax.inject.Named;
29import javax.inject.Singleton;
30 
31import org.jclouds.cim.xml.ResourceAllocationSettingDataHandler;
32import org.jclouds.http.RequiresHttp;
33import org.jclouds.rest.AsyncClientFactory;
34import org.jclouds.rest.ConfiguresRestClient;
35import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
36import org.jclouds.vcloud.VCloudAsyncClient;
37import org.jclouds.vcloud.VCloudClient;
38import org.jclouds.vcloud.VCloudLoginAsyncClient;
39import org.jclouds.vcloud.domain.CatalogItem;
40import org.jclouds.vcloud.domain.ReferenceType;
41import org.jclouds.vcloud.domain.VAppTemplate;
42import org.jclouds.vcloud.domain.VCloudSession;
43import org.jclouds.vcloud.functions.VAppTemplatesForCatalogItems;
44import org.jclouds.vcloud.xml.ovf.VCloudResourceAllocationSettingDataHandler;
45 
46import com.google.common.base.Function;
47import com.google.common.base.Supplier;
48import com.google.inject.Provides;
49import com.google.inject.TypeLiteral;
50 
51/**
52 * Configures the VCloud authentication service connection, including logging and http transport.
53 * 
54 * @author Adrian Cole
55 */
56@RequiresHttp
57@ConfiguresRestClient
58public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A extends VCloudAsyncClient> extends
59         CommonVCloudRestClientModule<S, A> {
60 
61   public BaseVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
62      super(syncClientType, asyncClientType);
63   }
64 
65   public BaseVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
66            Map<Class<?>, Class<?>> delegateMap) {
67      super(syncClientType, asyncClientType, delegateMap);
68   }
69 
70   @Singleton
71   public static class VCloudWritableCatalog extends WriteableCatalog {
72      private final VCloudClient client;
73 
74      @Inject
75      public VCloudWritableCatalog(VCloudClient client) {
76         super(client);
77         this.client = client;
78      }
79 
80      @Override
81      public boolean apply(ReferenceType arg0) {
82         return !client.getCatalogClient().getCatalog(arg0.getHref()).isReadOnly();
83      }
84   }
85 
86   @Override
87   protected void configure() {
88      bind(new TypeLiteral<Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>>>() {
89      }).to(new TypeLiteral<VAppTemplatesForCatalogItems>() {
90      });
91      bind(ResourceAllocationSettingDataHandler.class).to(VCloudResourceAllocationSettingDataHandler.class);
92      bind(WriteableCatalog.class).to(VCloudWritableCatalog.class);
93      super.configure();
94   }
95 
96   @Provides
97   @Singleton
98   protected VCloudLoginAsyncClient provideVCloudLogin(AsyncClientFactory factory) {
99      return factory.create(VCloudLoginAsyncClient.class);
100   }
101 
102   @Provides
103   @Singleton
104   protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
105            final VCloudLoginAsyncClient login) {
106      return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
107               new Supplier<VCloudSession>() {
108 
109                  @Override
110                  public VCloudSession get() {
111                     try {
112                        return login.login().get(10, TimeUnit.SECONDS);
113                     } catch (Exception e) {
114                        propagate(e);
115                        assert false : e;
116                        return null;
117                     }
118                  }
119 
120               });
121   }
122}

[all classes][org.jclouds.vcloud.config]
EMMA 2.0.5312 (C) Vladimir Roubtsov