made admin features optional and url based on adminURL for identity service in catalog

This commit is contained in:
Adrian Cole 2012-06-07 10:24:58 -07:00
parent ee64660f45
commit 12e57eec53
19 changed files with 582 additions and 60 deletions

View File

@ -25,6 +25,7 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.Constants;
import org.jclouds.openstack.keystone.v2_0.domain.ApiMetadata;
import org.jclouds.openstack.keystone.v2_0.features.ServiceAsyncClient;
import org.jclouds.openstack.keystone.v2_0.features.TenantAsyncClient;
import org.jclouds.openstack.keystone.v2_0.features.TokenAsyncClient;
import org.jclouds.openstack.keystone.v2_0.features.UserAsyncClient;
@ -33,6 +34,7 @@ import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
/**
@ -54,23 +56,29 @@ public interface KeystoneAsyncClient {
@Path("/v{" + Constants.PROPERTY_API_VERSION + "}/")
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ApiMetadata> getApiMetadata();
/**
* @see KeystoneClient#getServiceClient()
*/
@Delegate
ServiceAsyncClient getServiceClient();
/**
* @see KeystoneClient#getTokenClient()
*/
@Delegate
TokenAsyncClient getTokenClient();
Optional<TokenAsyncClient> getTokenClient();
/**
* @see KeystoneClient#getUserClient()
*/
@Delegate
UserAsyncClient getUserClient();
Optional<UserAsyncClient> getUserClient();
/**
* @see KeystoneClient#getTenantClient()
*/
@Delegate
TenantAsyncClient getTenantClient();
Optional<TenantAsyncClient> getTenantClient();
}

View File

@ -22,11 +22,14 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.openstack.keystone.v2_0.domain.ApiMetadata;
import org.jclouds.openstack.keystone.v2_0.features.ServiceClient;
import org.jclouds.openstack.keystone.v2_0.features.TenantClient;
import org.jclouds.openstack.keystone.v2_0.features.TokenClient;
import org.jclouds.openstack.keystone.v2_0.features.UserClient;
import org.jclouds.rest.annotations.Delegate;
import com.google.common.base.Optional;
/**
* Provides access to Openstack keystone resources via their REST API.
* <p/>
@ -44,23 +47,29 @@ public interface KeystoneClient {
* @return the requested information
*/
ApiMetadata getApiMetadata();
/**
* Provides synchronous access to Token features
*/
@Delegate
ServiceClient getServiceClient();
/**
* Provides synchronous access to Token features
*/
@Delegate
TokenClient getTokenClient();
Optional<TokenClient> getTokenClient();
/**
* Provides synchronous access to User features
*/
@Delegate
UserClient getUserClient();
Optional<UserClient> getUserClient();
/**
* Provides synchronous access to Tenant features
*/
@Delegate
TenantClient getTenantClient();
Optional<TenantClient> getTenantClient();
}

View File

@ -18,27 +18,45 @@
*/
package org.jclouds.openstack.keystone.v2_0.config;
import java.net.URI;
import java.util.Map;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.openstack.keystone.v2_0.KeystoneAsyncClient;
import org.jclouds.openstack.keystone.v2_0.KeystoneClient;
import org.jclouds.openstack.keystone.v2_0.features.ServiceAsyncClient;
import org.jclouds.openstack.keystone.v2_0.features.ServiceClient;
import org.jclouds.openstack.keystone.v2_0.features.TenantAsyncClient;
import org.jclouds.openstack.keystone.v2_0.features.TenantClient;
import org.jclouds.openstack.keystone.v2_0.features.TokenAsyncClient;
import org.jclouds.openstack.keystone.v2_0.features.TokenClient;
import org.jclouds.openstack.keystone.v2_0.features.UserAsyncClient;
import org.jclouds.openstack.keystone.v2_0.features.UserClient;
import org.jclouds.openstack.keystone.v2_0.functions.PresentWhenAdminURLExistsForIdentityService;
import org.jclouds.openstack.keystone.v2_0.handlers.KeystoneErrorHandler;
import org.jclouds.openstack.keystone.v2_0.suppliers.RegionIdToAdminURIFromAccessForTypeAndVersion;
import org.jclouds.openstack.keystone.v2_0.suppliers.RegionIdToAdminURISupplier;
import org.jclouds.openstack.v2_0.ServiceType;
import org.jclouds.openstack.v2_0.services.Identity;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import org.jclouds.rest.functions.ImplicitOptionalConverter;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.reflect.TypeToken;
import com.google.inject.util.Modules;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.assistedinject.FactoryModuleBuilder;
/**
* Configures the Keystone connection.
@ -46,17 +64,19 @@ import com.google.inject.util.Modules;
* @author Adam Lowe
*/
@ConfiguresRestClient
public class KeystoneRestClientModule<S extends KeystoneClient, A extends KeystoneAsyncClient> extends RestClientModule<S, A> {
public class KeystoneRestClientModule<S extends KeystoneClient, A extends KeystoneAsyncClient> extends
RestClientModule<S, A> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
.put(TokenClient.class, TokenAsyncClient.class)
.put(UserClient.class, UserAsyncClient.class)
.put(TenantClient.class, TenantAsyncClient.class)
.build();
.put(ServiceClient.class, ServiceAsyncClient.class)
.put(TokenClient.class, TokenAsyncClient.class)
.put(UserClient.class, UserAsyncClient.class)
.put(TenantClient.class, TenantAsyncClient.class).build();
@SuppressWarnings("unchecked")
public KeystoneRestClientModule() {
super((TypeToken) TypeToken.of(KeystoneClient.class), (TypeToken) TypeToken.of(KeystoneAsyncClient.class), DELEGATE_MAP);
super((TypeToken) TypeToken.of(KeystoneClient.class), (TypeToken) TypeToken.of(KeystoneAsyncClient.class),
DELEGATE_MAP);
}
protected KeystoneRestClientModule(TypeToken<S> syncClientType, TypeToken<A> asyncClientType,
@ -72,10 +92,36 @@ public class KeystoneRestClientModule<S extends KeystoneClient, A extends Keysto
@Override
protected void installLocations() {
install(new KeystoneAuthenticationModule(Modules.EMPTY_MODULE));
install(new KeystoneAuthenticationModule(new KeystoneAdminURLModule()));
super.installLocations();
}
public static class KeystoneAdminURLModule extends AbstractModule {
@Override
protected void configure() {
bind(ImplicitOptionalConverter.class).to(PresentWhenAdminURLExistsForIdentityService.class);
install(new FactoryModuleBuilder().implement(RegionIdToAdminURISupplier.class,
RegionIdToAdminURIFromAccessForTypeAndVersion.class).build(RegionIdToAdminURISupplier.Factory.class));
}
// return any identity url.
@Provides
@Singleton
@Identity
protected Supplier<URI> provideStorageUrl(RegionIdToAdminURISupplier.Factory factory,
@Named(KeystoneProperties.VERSION) String version) {
return Suppliers.compose(new Function<Map<String, Supplier<URI>>, URI>() {
//TODO: throw a nice error when there's nothing here
@Override
public URI apply(Map<String, Supplier<URI>> input) {
return Iterables.getLast(input.values()).get();
}
}, factory.createForApiTypeAndVersion(ServiceType.IDENTITY, version));
}
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(KeystoneErrorHandler.class);

View File

@ -0,0 +1,85 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.keystone.v2_0.features;
import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Constants;
import org.jclouds.openstack.keystone.v2_0.domain.Tenant;
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to Service via their REST API.
* <p/>
*
* @see ServiceClient
* @see <a href=
* "http://docs.openstack.org/api/openstack-identity-service/2.0/content/Service_API_Client_Operations.html"
* />
* @author Adam Lowe
*/
@Path("/v{" + Constants.PROPERTY_API_VERSION + "}")
@SkipEncoding( { '/', '=' })
public interface ServiceAsyncClient {
/**
* @see ServiceClient#listTenants()
*/
@GET
@SelectJson("tenants")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/tenants")
@RequestFilters(AuthenticateRequest.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Tenant>> listTenants();
/** @see ServiceClient#getTenant(String) */
@GET
@SelectJson("tenant")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/tenants/{tenantId}")
@RequestFilters(AuthenticateRequest.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Tenant> getTenant(@PathParam("tenantId") String tenantId);
/** @see ServiceClient#getTenantByName(String) */
@GET
@SelectJson("tenant")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/tenants")
@RequestFilters(AuthenticateRequest.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Tenant> getTenantByName(@QueryParam("name") String tenantName);
}

View File

@ -0,0 +1,60 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.keystone.v2_0.features;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.openstack.keystone.v2_0.domain.Tenant;
/**
* Provides synchronous access to the KeyStone Tenant API.
* <p/>
*
* @author Adam Lowe
* @see ServiceAsyncClient
* @see <a href=
* "http://docs.openstack.org/api/openstack-identity-service/2.0/content/Service_API_Client_Operations.html"
* />
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface ServiceClient {
/**
* The operation returns a list of tenants which the current token provides access to.
*/
Set<Tenant> listTenants();
/**
* Retrieve information about a tenant, by tenant ID
*
* @return the information about the tenant
*/
Tenant getTenant(String tenantId);
/**
* Retrieve information about a tenant, by tenant name
* <p/>
* NOTE: currently not working in openstack ( https://bugs.launchpad.net/keystone/+bug/956687 )
*
* @return the information about the tenant
*/
Tenant getTenantByName(String tenantName);
}

View File

@ -27,9 +27,9 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Constants;
import org.jclouds.openstack.keystone.v2_0.domain.Tenant;
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.openstack.v2_0.services.Identity;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
@ -49,7 +49,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* />
* @author Adam Lowe
*/
@Path("/v{" + Constants.PROPERTY_API_VERSION + "}")
@org.jclouds.rest.annotations.Endpoint(Identity.class)
@SkipEncoding( { '/', '=' })
public interface TenantAsyncClient {

View File

@ -27,11 +27,11 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Constants;
import org.jclouds.openstack.keystone.v2_0.domain.Endpoint;
import org.jclouds.openstack.keystone.v2_0.domain.Token;
import org.jclouds.openstack.keystone.v2_0.domain.User;
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.openstack.v2_0.services.Identity;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
@ -52,8 +52,8 @@ import com.google.common.util.concurrent.ListenableFuture;
* />
* @author Adam Lowe
*/
@Path("/v{" + Constants.PROPERTY_API_VERSION + "}")
@SkipEncoding({ '/', '=' })
@org.jclouds.rest.annotations.Endpoint(Identity.class)
public interface TokenAsyncClient {

View File

@ -27,10 +27,10 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Constants;
import org.jclouds.openstack.keystone.v2_0.domain.Role;
import org.jclouds.openstack.keystone.v2_0.domain.User;
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.openstack.v2_0.services.Identity;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
@ -50,7 +50,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* />
* @author Adam Lowe
*/
@Path("/v{" + Constants.PROPERTY_API_VERSION + "}")
@org.jclouds.rest.annotations.Endpoint(Identity.class)
@SkipEncoding({ '/', '=' })
public interface UserAsyncClient {

View File

@ -0,0 +1,46 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.keystone.v2_0.functions;
import javax.inject.Singleton;
import org.jclouds.internal.ClassMethodArgsAndReturnVal;
import org.jclouds.rest.functions.ImplicitOptionalConverter;
import com.google.common.base.Optional;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class PresentWhenAdminURLExistsForIdentityService implements ImplicitOptionalConverter {
@Override
public Optional<Object> apply(ClassMethodArgsAndReturnVal input) {
//TODO: log and return absent when the admin url for identity service isn't available
return Optional.of(input.getReturnVal());
}
public String toString() {
return "presentWhenAdminURLExistsForIdentityService()";
}
}

View File

@ -0,0 +1,43 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.v2_0.services;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
import org.jclouds.openstack.v2_0.ServiceType;
/**
* Identity Service (Keystone)
*
* @author Adrian Cole
* @see <a href="http://docs.openstack.org/api/openstack-typeentity-service/2.0/content/Identity-Service-Concepts-e1362.html"
* />
* @see ServiceType#IMAGE
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface Identity {
}

View File

@ -0,0 +1,112 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 1.1 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-1.1
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.keystone.v2_0.features;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import java.util.Set;
import org.jclouds.openstack.keystone.v2_0.KeystoneClient;
import org.jclouds.openstack.keystone.v2_0.domain.Tenant;
import org.jclouds.openstack.keystone.v2_0.internal.BaseKeystoneRestClientExpectTest;
import org.jclouds.rest.AuthorizationException;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* Tests parsing and Guice wiring of ServiceClient
*
* @author Adam Lowe
*/
@Test(testName = "ServiceClientExpectTest")
public class ServiceClientExpectTest extends BaseKeystoneRestClientExpectTest<KeystoneClient> {
public void testListTenants() {
ServiceClient client = requestsSendResponses(
keystoneAuthWithUsernameAndPassword,
responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/tenants").build(),
standardResponseBuilder(200).payload(
payloadFromResourceWithContentType("/tenant_list.json", APPLICATION_JSON)).build())
.getServiceClient();
Set<Tenant> tenants = client.listTenants();
assertNotNull(tenants);
assertFalse(tenants.isEmpty());
Set<Tenant> expected = ImmutableSet.of(Tenant.builder().name("demo").id("05d1dc7af71646deba64cfc17b81bec0")
.build(), Tenant.builder().name("admin").id("7aa2e17ec29f44d193c48feaba0852cc").build());
assertEquals(tenants, expected);
}
public void testListTenantsFailNotFound() {
ServiceClient client = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/tenants").build(), standardResponseBuilder(404).build())
.getServiceClient();
assertTrue(client.listTenants().isEmpty());
}
public void testGetTenant() {
ServiceClient client = requestsSendResponses(
keystoneAuthWithUsernameAndPassword,
responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/tenants/013ba41150a14830bec85ffe93353bcc").build(),
standardResponseBuilder(200).payload(
payloadFromResourceWithContentType("/tenant_details.json", APPLICATION_JSON)).build())
.getServiceClient();
Tenant tenant = client.getTenant("013ba41150a14830bec85ffe93353bcc");
assertNotNull(tenant);
assertEquals(tenant, Tenant.builder().id("013ba41150a14830bec85ffe93353bcc").name("admin").build());
}
@Test(expectedExceptions = AuthorizationException.class)
public void testListTenantsFailNotAuthorized() {
ServiceClient client = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/tenants/013ba41150a14830bec85ffe93353bcc").build(),
standardResponseBuilder(401).build()).getServiceClient();
client.getTenant("013ba41150a14830bec85ffe93353bcc");
}
public void testGetTenantByName() {
ServiceClient client = requestsSendResponses(
keystoneAuthWithUsernameAndPassword,
responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/tenants?name=admin").build(),
standardResponseBuilder(200).payload(
payloadFromResourceWithContentType("/tenant_details.json", APPLICATION_JSON)).build())
.getServiceClient();
Tenant tenant = client.getTenantByName("admin");
assertNotNull(tenant);
assertEquals(tenant, Tenant.builder().id("013ba41150a14830bec85ffe93353bcc").name("admin").build());
}
public void testGetTenantByNameFailNotFound() {
ServiceClient client = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/tenants?name=admin").build(),
standardResponseBuilder(404).build()).getServiceClient();
assertNull(client.getTenantByName("admin"));
}
}

View File

@ -0,0 +1,67 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 1.1 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-1.1
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.keystone.v2_0.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import java.util.Set;
import org.jclouds.openstack.keystone.v2_0.domain.Tenant;
import org.jclouds.openstack.keystone.v2_0.internal.BaseKeystoneClientLiveTest;
import org.testng.annotations.Test;
/**
* Tests ServiceClient
*
* @author Adam Lowe
*/
@Test(groups = "live", testName = "ServiceClientLiveTest")
public class ServiceClientLiveTest extends BaseKeystoneClientLiveTest {
public void testTenants() {
ServiceClient client = keystoneContext.getApi().getServiceClient();
Set<Tenant> result = client.listTenants();
assertNotNull(result);
assertFalse(result.isEmpty());
for (Tenant tenant : result) {
assertNotNull(tenant.getId());
Tenant aTenant = client.getTenant(tenant.getId());
assertNotNull(aTenant, "get returned null for tenant: " + tenant);
assertEquals(aTenant, tenant);
}
}
public void testTenantsByName() {
ServiceClient client = keystoneContext.getApi().getServiceClient();
for (Tenant tenant : client.listTenants()) {
Tenant aTenant = client.getTenantByName(tenant.getName());
assertNotNull(aTenant, "get returned null for tenant: " + tenant);
assertEquals(aTenant, tenant);
}
}
}

View File

@ -43,6 +43,10 @@ import com.google.common.collect.ImmutableSet;
@Test(testName = "TenantClientExpectTest")
public class TenantClientExpectTest extends BaseKeystoneRestClientExpectTest<KeystoneClient> {
public TenantClientExpectTest(){
endpoint = "https://csnode.jclouds.org:35357";
}
public void testListTenants() {
TenantClient client = requestsSendResponses(
keystoneAuthWithUsernameAndPassword,
@ -50,7 +54,7 @@ public class TenantClientExpectTest extends BaseKeystoneRestClientExpectTest<Key
standardRequestBuilder(endpoint + "/v2.0/tenants").build(),
standardResponseBuilder(200).payload(
payloadFromResourceWithContentType("/tenant_list.json", APPLICATION_JSON)).build())
.getTenantClient();
.getTenantClient().get();
Set<Tenant> tenants = client.list();
assertNotNull(tenants);
assertFalse(tenants.isEmpty());
@ -64,7 +68,7 @@ public class TenantClientExpectTest extends BaseKeystoneRestClientExpectTest<Key
public void testListTenantsFailNotFound() {
TenantClient client = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/tenants").build(), standardResponseBuilder(404).build())
.getTenantClient();
.getTenantClient().get();
assertTrue(client.list().isEmpty());
}
@ -75,7 +79,7 @@ public class TenantClientExpectTest extends BaseKeystoneRestClientExpectTest<Key
standardRequestBuilder(endpoint + "/v2.0/tenants/013ba41150a14830bec85ffe93353bcc").build(),
standardResponseBuilder(200).payload(
payloadFromResourceWithContentType("/tenant_details.json", APPLICATION_JSON)).build())
.getTenantClient();
.getTenantClient().get();
Tenant tenant = client.get("013ba41150a14830bec85ffe93353bcc");
assertNotNull(tenant);
assertEquals(tenant, Tenant.builder().id("013ba41150a14830bec85ffe93353bcc").name("admin").build());
@ -85,7 +89,7 @@ public class TenantClientExpectTest extends BaseKeystoneRestClientExpectTest<Key
public void testListTenantsFailNotAuthorized() {
TenantClient client = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/tenants/013ba41150a14830bec85ffe93353bcc").build(),
standardResponseBuilder(401).build()).getTenantClient();
standardResponseBuilder(401).build()).getTenantClient().get();
client.get("013ba41150a14830bec85ffe93353bcc");
}
@ -96,7 +100,7 @@ public class TenantClientExpectTest extends BaseKeystoneRestClientExpectTest<Key
standardRequestBuilder(endpoint + "/v2.0/tenants?name=admin").build(),
standardResponseBuilder(200).payload(
payloadFromResourceWithContentType("/tenant_details.json", APPLICATION_JSON)).build())
.getTenantClient();
.getTenantClient().get();
Tenant tenant = client.getByName("admin");
assertNotNull(tenant);
assertEquals(tenant, Tenant.builder().id("013ba41150a14830bec85ffe93353bcc").name("admin").build());
@ -105,7 +109,7 @@ public class TenantClientExpectTest extends BaseKeystoneRestClientExpectTest<Key
public void testGetTenantByNameFailNotFound() {
TenantClient client = requestsSendResponses(keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/tenants?name=admin").build(),
standardResponseBuilder(404).build()).getTenantClient();
standardResponseBuilder(404).build()).getTenantClient().get();
assertNull(client.getByName("admin"));
}

View File

@ -37,7 +37,7 @@ import org.testng.annotations.Test;
public class TenantClientLiveTest extends BaseKeystoneClientLiveTest {
public void testTenants() {
TenantClient client = keystoneContext.getApi().getTenantClient();
TenantClient client = keystoneContext.getApi().getTenantClient().get();
Set<Tenant> result = client.list();
assertNotNull(result);
assertFalse(result.isEmpty());
@ -54,7 +54,7 @@ public class TenantClientLiveTest extends BaseKeystoneClientLiveTest {
public void testTenantsByName() {
TenantClient client = keystoneContext.getApi().getTenantClient();
TenantClient client = keystoneContext.getApi().getTenantClient().get();
for (Tenant tenant : client.list()) {
Tenant aTenant = client.getByName(tenant.getName());

View File

@ -50,6 +50,11 @@ import com.google.common.collect.ImmutableSet;
*/
@Test(testName = "TokenClientExpectTest")
public class TokenClientExpectTest extends BaseKeystoneRestClientExpectTest<KeystoneClient> {
public TokenClientExpectTest(){
endpoint = "https://csnode.jclouds.org:35357";
}
private DateService dateService = new SimpleDateFormatDateService();
public void testGetToken() {
@ -57,7 +62,7 @@ public class TokenClientExpectTest extends BaseKeystoneRestClientExpectTest<Keys
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/tokens/sometokenorother").build(),
standardResponseBuilder(200).payload(payloadFromResourceWithContentType("/token_details.json", APPLICATION_JSON)).build())
.getTokenClient();
.getTokenClient().get();
Token token = client.get("sometokenorother");
assertNotNull(token);
assertEquals(token,
@ -70,7 +75,7 @@ public class TokenClientExpectTest extends BaseKeystoneRestClientExpectTest<Keys
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/tokens/sometokenorother").build(),
standardResponseBuilder(404).build())
.getTokenClient();
.getTokenClient().get();
assertNull(client.get("sometokenorother"));
}
@ -79,7 +84,7 @@ public class TokenClientExpectTest extends BaseKeystoneRestClientExpectTest<Keys
TokenClient client = requestsSendResponses(
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/tokens/sometokenorother").build(),
standardResponseBuilder(500).build()).getTokenClient();
standardResponseBuilder(500).build()).getTokenClient().get();
client.get("sometokenorother");
}
@ -88,7 +93,7 @@ public class TokenClientExpectTest extends BaseKeystoneRestClientExpectTest<Keys
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/tokens/sometokenorother").build(),
standardResponseBuilder(200).payload(payloadFromResourceWithContentType("/token_details.json", APPLICATION_JSON)).build())
.getTokenClient();
.getTokenClient().get();
User user = client.getUserOfToken("sometokenorother");
assertNotNull(user);
assertEquals(user, User.builder().id("2b9b606181634ae9ac86fd95a8bc2cde").name("admin")
@ -100,7 +105,7 @@ public class TokenClientExpectTest extends BaseKeystoneRestClientExpectTest<Keys
TokenClient client = requestsSendResponses(
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/tokens/sometokenorother").build(),
standardResponseBuilder(404).build()).getTokenClient();
standardResponseBuilder(404).build()).getTokenClient().get();
assertNull(client.getUserOfToken("sometokenorother"));
}
@ -110,7 +115,7 @@ public class TokenClientExpectTest extends BaseKeystoneRestClientExpectTest<Keys
standardRequestBuilder(endpoint + "/v2.0/tokens/sometokenorother").method("HEAD")
.headers(ImmutableMultimap.of("X-Auth-Token", authToken)).build(),
standardResponseBuilder(200).payload(payloadFromResourceWithContentType("/token_details.json", APPLICATION_JSON)).build())
.getTokenClient();
.getTokenClient().get();
assertTrue(client.isValid("sometokenorother"));
}
@ -119,7 +124,7 @@ public class TokenClientExpectTest extends BaseKeystoneRestClientExpectTest<Keys
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/tokens/sometokenorother").method("HEAD")
.headers(ImmutableMultimap.of("X-Auth-Token", authToken)).build(),
standardResponseBuilder(404).build()).getTokenClient();
standardResponseBuilder(404).build()).getTokenClient().get();
assertFalse(client.isValid("sometokenorother"));
}
@ -129,7 +134,7 @@ public class TokenClientExpectTest extends BaseKeystoneRestClientExpectTest<Keys
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/tokens/XXXXXX/endpoints").build(),
standardResponseBuilder(200).payload(payloadFromResourceWithContentType("/user_endpoints.json", APPLICATION_JSON)).build())
.getTokenClient();
.getTokenClient().get();
Set<Endpoint> endpoints = client.listEndpointsForToken("XXXXXX");
assertEquals(endpoints, ImmutableSet.of(
@ -145,7 +150,7 @@ public class TokenClientExpectTest extends BaseKeystoneRestClientExpectTest<Keys
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/tokens/XXXXXX/endpoints").build(),
standardResponseBuilder(404).build())
.getTokenClient();
.getTokenClient().get();
assertTrue(client.listEndpointsForToken("XXXXXX").isEmpty());
}

View File

@ -58,7 +58,7 @@ public class TokenClientLiveTest extends BaseKeystoneClientLiveTest {
public void testToken() {
TokenClient client = keystoneContext.getApi().getTokenClient();
TokenClient client = keystoneContext.getApi().getTokenClient().get();
assertTrue(client.isValid(token));
Token result = client.get(token);
assertNotNull(result);
@ -74,7 +74,7 @@ public class TokenClientLiveTest extends BaseKeystoneClientLiveTest {
public void testInvalidToken() {
TokenClient client = keystoneContext.getApi().getTokenClient();
TokenClient client = keystoneContext.getApi().getTokenClient().get();
assertFalse(client.isValid("thisisnotarealtoken!"));
assertNull(client.get("thisisnotarealtoken!"));
@ -82,7 +82,7 @@ public class TokenClientLiveTest extends BaseKeystoneClientLiveTest {
public void testTokenEndpoints() {
TokenClient client = keystoneContext.getApi().getTokenClient();
TokenClient client = keystoneContext.getApi().getTokenClient().get();
Set<Endpoint> endpoints = client.listEndpointsForToken(token);
assertNotNull(endpoints);
assertFalse(endpoints.isEmpty());
@ -91,7 +91,7 @@ public class TokenClientLiveTest extends BaseKeystoneClientLiveTest {
public void testInvalidTokenEndpoints() {
TokenClient client = keystoneContext.getApi().getTokenClient();
TokenClient client = keystoneContext.getApi().getTokenClient().get();
assertTrue(client.listEndpointsForToken("thisisnotarealtoken!").isEmpty());
}

View File

@ -44,13 +44,17 @@ import com.google.common.collect.ImmutableSet;
*/
@Test(testName = "UserClientExpectTest")
public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest<KeystoneClient> {
public UserClientExpectTest(){
endpoint = "https://csnode.jclouds.org:35357";
}
public void testListUsers() {
UserClient client = requestsSendResponses(
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/users").build(),
standardResponseBuilder(200).payload(payloadFromResourceWithContentType("/user_list.json", APPLICATION_JSON)).build())
.getUserClient();
.getUserClient().get();
Set<User> users = client.list();
assertNotNull(users);
assertFalse(users.isEmpty());
@ -70,7 +74,7 @@ public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest<Keyst
UserClient client = requestsSendResponses(
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/users").build(),
standardResponseBuilder(401).build()).getUserClient();
standardResponseBuilder(401).build()).getUserClient().get();
client.list();
}
@ -79,7 +83,7 @@ public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest<Keyst
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/users/e021dfd758eb44a89f1c57c8ef3be8e2").build(),
standardResponseBuilder(200).payload(payloadFromResourceWithContentType("/user_details.json", APPLICATION_JSON)).build())
.getUserClient();
.getUserClient().get();
User user = client.get("e021dfd758eb44a89f1c57c8ef3be8e2");
assertNotNull(user);
assertEquals(user, User.builder().name("nova").id("e021dfd758eb44a89f1c57c8ef3be8e2").build());
@ -89,7 +93,7 @@ public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest<Keyst
UserClient client = requestsSendResponses(
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/users/f021dfd758eb44a89f1c57c8ef3be8e2").build(),
standardResponseBuilder(404).build()).getUserClient();
standardResponseBuilder(404).build()).getUserClient().get();
assertNull(client.get("f021dfd758eb44a89f1c57c8ef3be8e2"));
}
@ -98,7 +102,7 @@ public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest<Keyst
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/users?name=nova").build(),
standardResponseBuilder(200).payload(payloadFromResourceWithContentType("/user_details.json", APPLICATION_JSON)).build())
.getUserClient();
.getUserClient().get();
User user = client.getByName("nova");
assertNotNull(user);
assertEquals(user, User.builder().name("nova").id("e021dfd758eb44a89f1c57c8ef3be8e2").build());
@ -108,7 +112,7 @@ public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest<Keyst
UserClient client = requestsSendResponses(
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/users?name=fred").build(),
standardResponseBuilder(404).build()).getUserClient();
standardResponseBuilder(404).build()).getUserClient().get();
assertNull(client.getByName("fred"));
}
@ -117,7 +121,7 @@ public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest<Keyst
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/users/3f6c1c9ba993495ead7d2eb2192e284f/roles").build(),
standardResponseBuilder(200).payload(payloadFromResourceWithContentType("/user_role_list.json", APPLICATION_JSON)).build())
.getUserClient();
.getUserClient().get();
Set<Role> roles = client.listRolesOfUser("3f6c1c9ba993495ead7d2eb2192e284f");
assertNotNull(roles);
assertFalse(roles.isEmpty());
@ -130,7 +134,7 @@ public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest<Keyst
UserClient client = requestsSendResponses(
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/users/4f6c1c9ba993495ead7d2eb2192e284f/roles").build(),
standardResponseBuilder(404).build()).getUserClient();
standardResponseBuilder(404).build()).getUserClient().get();
assertTrue(client.listRolesOfUser("4f6c1c9ba993495ead7d2eb2192e284f").isEmpty());
}
@ -139,7 +143,7 @@ public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest<Keyst
UserClient client = requestsSendResponses(
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/users/5f6c1c9ba993495ead7d2eb2192e284f/roles").build(),
standardResponseBuilder(501).build()).getUserClient();
standardResponseBuilder(501).build()).getUserClient().get();
assertTrue(client.listRolesOfUser("5f6c1c9ba993495ead7d2eb2192e284f").isEmpty());
}
@ -148,7 +152,7 @@ public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest<Keyst
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/users/3f6c1c9ba993495ead7d2eb2192e284f/roles").build(),
standardResponseBuilder(200).payload(payloadFromResourceWithContentType("/user_tenant_role_list.json", APPLICATION_JSON)).build())
.getUserClient();
.getUserClient().get();
Set<Role> roles = client.listRolesOfUser("3f6c1c9ba993495ead7d2eb2192e284f");
assertNotNull(roles);
assertFalse(roles.isEmpty());
@ -162,7 +166,7 @@ public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest<Keyst
UserClient client = requestsSendResponses(
keystoneAuthWithUsernameAndPassword, responseWithKeystoneAccess,
standardRequestBuilder(endpoint + "/v2.0/users/3f6c1c9ba993495ead7d2eb2192e284f/roles").build(),
standardResponseBuilder(404).build()).getUserClient();
standardResponseBuilder(404).build()).getUserClient().get();
assertTrue(client.listRolesOfUser("3f6c1c9ba993495ead7d2eb2192e284f").isEmpty());
}

View File

@ -40,7 +40,7 @@ public class UserClientLiveTest extends BaseKeystoneClientLiveTest {
public void testUsers() {
UserClient client = keystoneContext.getApi().getUserClient();
UserClient client = keystoneContext.getApi().getUserClient().get();
Set<User> users = client.list();
assertNotNull(users);
assertFalse(users.isEmpty());
@ -53,9 +53,9 @@ public class UserClientLiveTest extends BaseKeystoneClientLiveTest {
public void testUserRolesOnTenant() {
UserClient client = keystoneContext.getApi().getUserClient();
UserClient client = keystoneContext.getApi().getUserClient().get();
Set<User> users = client.list();
Set<Tenant> tenants = keystoneContext.getApi().getTenantClient().list();
Set<Tenant> tenants = keystoneContext.getApi().getTenantClient().get().list();
for (User user : users) {
for (Tenant tenant : tenants) {
@ -70,7 +70,7 @@ public class UserClientLiveTest extends BaseKeystoneClientLiveTest {
public void testListRolesOfUser() {
UserClient client = keystoneContext.getApi().getUserClient();
UserClient client = keystoneContext.getApi().getUserClient().get();
for (User user : client.list()) {
Set<Role> roles = client.listRolesOfUser(user.getId());
for (Role role : roles) {
@ -82,7 +82,7 @@ public class UserClientLiveTest extends BaseKeystoneClientLiveTest {
public void testUsersByName() {
UserClient client = keystoneContext.getApi().getUserClient();
UserClient client = keystoneContext.getApi().getUserClient().get();
for (User user : client.list()) {
User aUser = client.getByName(user.getName());
assertEquals(aUser, user);

View File

@ -0,0 +1,33 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 1.1 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-1.1
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudidentity.v2_0.features;
import org.jclouds.openstack.keystone.v2_0.features.ServiceClientLiveTest;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "CloudIdentityServiceClientLiveTest", singleThreaded = true)
public class CloudIdentityServiceClientLiveTest extends ServiceClientLiveTest {
public CloudIdentityServiceClientLiveTest() {
provider = "cloudidentity";
}
}