Problem when instantiating the SessionClient via ContextBuilder, solved by forcing the getProviderMetadata override method to be used

This commit is contained in:
Andrew Donald Kennedy 2012-04-19 00:13:54 +01:00
parent 47cbbeef57
commit 6b10fb8f32
3 changed files with 31 additions and 13 deletions

View File

@ -18,6 +18,12 @@
*/ */
package org.jclouds.vcloud.director.v1_5; package org.jclouds.vcloud.director.v1_5;
import org.jclouds.rest.RestContext;
import org.jclouds.vcloud.director.v1_5.login.SessionAsyncClient;
import org.jclouds.vcloud.director.v1_5.login.SessionClient;
import com.google.common.reflect.TypeToken;
/** /**
* Constants used by VCloudDirector clients * Constants used by VCloudDirector clients
* *
@ -63,4 +69,11 @@ public class VCloudDirectorConstants {
/** TODO javadoc */ /** TODO javadoc */
public static final String PROPERTY_NS_NAME_LEN_MAX = "jclouds.dns_name_length_max"; public static final String PROPERTY_NS_NAME_LEN_MAX = "jclouds.dns_name_length_max";
/** TODO javadoc */
public static final TypeToken<RestContext<SessionClient, SessionAsyncClient>> SESSION_CONTEXT_TYPE =
new TypeToken<RestContext<SessionClient, SessionAsyncClient>>() {
/** The serialVersionUID */
private static final long serialVersionUID = -3625362618882122604L;
};
} }

View File

@ -19,8 +19,6 @@ import org.jclouds.vcloud.director.v1_5.domain.Role.DefaultRoles;
import org.jclouds.vcloud.director.v1_5.domain.User; import org.jclouds.vcloud.director.v1_5.domain.User;
import org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates; import org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates;
import org.jclouds.vcloud.director.v1_5.predicates.ReferencePredicates; import org.jclouds.vcloud.director.v1_5.predicates.ReferencePredicates;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncClient;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;

View File

@ -24,11 +24,13 @@ import static org.testng.Assert.assertTrue;
import java.net.URI; import java.net.URI;
import org.jclouds.apis.ApiMetadata; import org.jclouds.ContextBuilder;
import org.jclouds.apis.BaseContextLiveTest; import org.jclouds.apis.BaseContextLiveTest;
import org.jclouds.rest.AnonymousRestApiMetadata; import org.jclouds.providers.AnonymousProviderMetadata;
import org.jclouds.providers.ProviderMetadata;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.vcloud.director.testng.FormatApiResultsListener; import org.jclouds.vcloud.director.testng.FormatApiResultsListener;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants;
import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken; import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Listeners; import org.testng.annotations.Listeners;
@ -84,17 +86,22 @@ public class SessionClientLiveTest extends BaseContextLiveTest<RestContext<Sessi
public void testLogout() { public void testLogout() {
client.logoutSessionWithToken(sessionWithToken.getSession().getHref(), sessionWithToken.getToken()); client.logoutSessionWithToken(sessionWithToken.getSession().getHref(), sessionWithToken.getToken());
} }
@Override
protected ApiMetadata createApiMetadata() {
return AnonymousRestApiMetadata.forClientMappedToAsyncClient(SessionClient.class, SessionAsyncClient.class);
}
@Override @Override
protected TypeToken<RestContext<SessionClient, SessionAsyncClient>> contextType() { protected TypeToken<RestContext<SessionClient, SessionAsyncClient>> contextType() {
return new TypeToken<RestContext<SessionClient, SessionAsyncClient>>(){ return VCloudDirectorConstants.SESSION_CONTEXT_TYPE;
/** The serialVersionUID */
private static final long serialVersionUID = -3625362618882122604L;};
} }
@Override
protected ProviderMetadata createProviderMetadata() {
return AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint(SessionClient.class, SessionAsyncClient.class, endpoint);
}
@Override
protected ContextBuilder newBuilder() {
ProviderMetadata pm = createProviderMetadata();
ContextBuilder builder = ContextBuilder.newBuilder(pm);
return builder;
}
} }