diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneAsyncClient.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneAsyncClient.java index c05af31d49..f23cdaa7ce 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneAsyncClient.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneAsyncClient.java @@ -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 getApiMetadata(); + + /** + * @see KeystoneClient#getServiceClient() + */ + @Delegate + ServiceAsyncClient getServiceClient(); /** * @see KeystoneClient#getTokenClient() */ @Delegate - TokenAsyncClient getTokenClient(); + Optional getTokenClient(); /** * @see KeystoneClient#getUserClient() */ @Delegate - UserAsyncClient getUserClient(); + Optional getUserClient(); /** * @see KeystoneClient#getTenantClient() */ @Delegate - TenantAsyncClient getTenantClient(); + Optional getTenantClient(); } diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneClient.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneClient.java index a73f75859b..cd63c07366 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneClient.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/KeystoneClient.java @@ -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. *

@@ -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 getTokenClient(); /** * Provides synchronous access to User features */ @Delegate - UserClient getUserClient(); + Optional getUserClient(); /** * Provides synchronous access to Tenant features */ @Delegate - TenantClient getTenantClient(); + Optional getTenantClient(); } \ No newline at end of file diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneRestClientModule.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneRestClientModule.java index 4e6c9c10e3..7967d3dfa4 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneRestClientModule.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/config/KeystoneRestClientModule.java @@ -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 extends RestClientModule { +public class KeystoneRestClientModule extends + RestClientModule { public static final Map, Class> DELEGATE_MAP = ImmutableMap., 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 syncClientType, TypeToken asyncClientType, @@ -72,10 +92,36 @@ public class KeystoneRestClientModule provideStorageUrl(RegionIdToAdminURISupplier.Factory factory, + @Named(KeystoneProperties.VERSION) String version) { + return Suppliers.compose(new Function>, URI>() { + + //TODO: throw a nice error when there's nothing here + @Override + public URI apply(Map> 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); diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/ServiceAsyncClient.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/ServiceAsyncClient.java new file mode 100644 index 0000000000..d18fa64ffc --- /dev/null +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/ServiceAsyncClient.java @@ -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. + *

+ * + * @see ServiceClient + * @see + * @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> listTenants(); + + /** @see ServiceClient#getTenant(String) */ + @GET + @SelectJson("tenant") + @Consumes(MediaType.APPLICATION_JSON) + @Path("/tenants/{tenantId}") + @RequestFilters(AuthenticateRequest.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture 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 getTenantByName(@QueryParam("name") String tenantName); + +} diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/ServiceClient.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/ServiceClient.java new file mode 100644 index 0000000000..852e5fec61 --- /dev/null +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/ServiceClient.java @@ -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. + *

+ * + * @author Adam Lowe + * @see ServiceAsyncClient + * @see + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface ServiceClient { + + /** + * The operation returns a list of tenants which the current token provides access to. + */ + Set 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 + *

+ * NOTE: currently not working in openstack ( https://bugs.launchpad.net/keystone/+bug/956687 ) + * + * @return the information about the tenant + */ + Tenant getTenantByName(String tenantName); +} \ No newline at end of file diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/TenantAsyncClient.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/TenantAsyncClient.java index 20955ecb66..d46a0a86c5 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/TenantAsyncClient.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/TenantAsyncClient.java @@ -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 { diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/TokenAsyncClient.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/TokenAsyncClient.java index 7975954954..4a6fed3ce3 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/TokenAsyncClient.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/TokenAsyncClient.java @@ -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 { diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/UserAsyncClient.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/UserAsyncClient.java index d56f0d1b02..d0357d58fb 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/UserAsyncClient.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/features/UserAsyncClient.java @@ -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 { diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/PresentWhenAdminURLExistsForIdentityService.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/PresentWhenAdminURLExistsForIdentityService.java new file mode 100644 index 0000000000..71c2e299b6 --- /dev/null +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/PresentWhenAdminURLExistsForIdentityService.java @@ -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 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()"; + } + +} \ No newline at end of file diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/services/Identity.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/services/Identity.java new file mode 100644 index 0000000000..59f9c55368 --- /dev/null +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/services/Identity.java @@ -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 + * @see ServiceType#IMAGE + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface Identity { + +} \ No newline at end of file diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/ServiceClientExpectTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/ServiceClientExpectTest.java new file mode 100644 index 0000000000..7b30253064 --- /dev/null +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/ServiceClientExpectTest.java @@ -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 { + + 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 tenants = client.listTenants(); + assertNotNull(tenants); + assertFalse(tenants.isEmpty()); + + Set 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")); + } + +} diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/ServiceClientLiveTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/ServiceClientLiveTest.java new file mode 100644 index 0000000000..0a1717cc90 --- /dev/null +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/ServiceClientLiveTest.java @@ -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 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); + } + + } +} diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/TenantClientExpectTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/TenantClientExpectTest.java index afe2bcb2cd..8260d9cb39 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/TenantClientExpectTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/TenantClientExpectTest.java @@ -43,6 +43,10 @@ import com.google.common.collect.ImmutableSet; @Test(testName = "TenantClientExpectTest") public class TenantClientExpectTest extends BaseKeystoneRestClientExpectTest { + public TenantClientExpectTest(){ + endpoint = "https://csnode.jclouds.org:35357"; + } + public void testListTenants() { TenantClient client = requestsSendResponses( keystoneAuthWithUsernameAndPassword, @@ -50,7 +54,7 @@ public class TenantClientExpectTest extends BaseKeystoneRestClientExpectTest tenants = client.list(); assertNotNull(tenants); assertFalse(tenants.isEmpty()); @@ -64,7 +68,7 @@ public class TenantClientExpectTest extends BaseKeystoneRestClientExpectTest 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()); diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/TokenClientExpectTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/TokenClientExpectTest.java index bb77b3a4e9..3ed014a566 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/TokenClientExpectTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/TokenClientExpectTest.java @@ -50,6 +50,11 @@ import com.google.common.collect.ImmutableSet; */ @Test(testName = "TokenClientExpectTest") public class TokenClientExpectTest extends BaseKeystoneRestClientExpectTest { + + 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 endpoints = client.listEndpointsForToken("XXXXXX"); assertEquals(endpoints, ImmutableSet.of( @@ -145,7 +150,7 @@ public class TokenClientExpectTest extends BaseKeystoneRestClientExpectTest 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()); } diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/UserClientExpectTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/UserClientExpectTest.java index 71b83dca17..d813824b31 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/UserClientExpectTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/features/UserClientExpectTest.java @@ -44,13 +44,17 @@ import com.google.common.collect.ImmutableSet; */ @Test(testName = "UserClientExpectTest") public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest { - + + 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 users = client.list(); assertNotNull(users); assertFalse(users.isEmpty()); @@ -70,7 +74,7 @@ public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest roles = client.listRolesOfUser("3f6c1c9ba993495ead7d2eb2192e284f"); assertNotNull(roles); assertFalse(roles.isEmpty()); @@ -130,7 +134,7 @@ public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest roles = client.listRolesOfUser("3f6c1c9ba993495ead7d2eb2192e284f"); assertNotNull(roles); assertFalse(roles.isEmpty()); @@ -162,7 +166,7 @@ public class UserClientExpectTest extends BaseKeystoneRestClientExpectTest 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 users = client.list(); - Set tenants = keystoneContext.getApi().getTenantClient().list(); + Set 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 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); diff --git a/labs/cloudidentity/src/test/java/org/jclouds/cloudidentity/v2_0/features/CloudIdentityServiceClientLiveTest.java b/labs/cloudidentity/src/test/java/org/jclouds/cloudidentity/v2_0/features/CloudIdentityServiceClientLiveTest.java new file mode 100644 index 0000000000..05e4cac34c --- /dev/null +++ b/labs/cloudidentity/src/test/java/org/jclouds/cloudidentity/v2_0/features/CloudIdentityServiceClientLiveTest.java @@ -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"; + } +} \ No newline at end of file