mirror of https://github.com/apache/jclouds.git
openstack-keystone: reducing ServiceClient to simply listTenants()
This commit is contained in:
parent
46b4a6c8da
commit
9718634570
|
@ -23,8 +23,6 @@ import java.util.Set;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.QueryParam;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
|
@ -35,7 +33,6 @@ import org.jclouds.rest.annotations.RequestFilters;
|
||||||
import org.jclouds.rest.annotations.SelectJson;
|
import org.jclouds.rest.annotations.SelectJson;
|
||||||
import org.jclouds.rest.annotations.SkipEncoding;
|
import org.jclouds.rest.annotations.SkipEncoding;
|
||||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
@ -63,23 +60,4 @@ public interface ServiceAsyncClient {
|
||||||
@RequestFilters(AuthenticateRequest.class)
|
@RequestFilters(AuthenticateRequest.class)
|
||||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||||
ListenableFuture<Set<Tenant>> listTenants();
|
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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,20 +41,4 @@ public interface ServiceClient {
|
||||||
* The operation returns a list of tenants which the current token provides access to.
|
* The operation returns a list of tenants which the current token provides access to.
|
||||||
*/
|
*/
|
||||||
Set<Tenant> listTenants();
|
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);
|
|
||||||
}
|
}
|
|
@ -22,7 +22,6 @@ import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertFalse;
|
import static org.testng.Assert.assertFalse;
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
import static org.testng.Assert.assertNull;
|
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -30,7 +29,6 @@ import java.util.Set;
|
||||||
import org.jclouds.openstack.keystone.v2_0.KeystoneClient;
|
import org.jclouds.openstack.keystone.v2_0.KeystoneClient;
|
||||||
import org.jclouds.openstack.keystone.v2_0.domain.Tenant;
|
import org.jclouds.openstack.keystone.v2_0.domain.Tenant;
|
||||||
import org.jclouds.openstack.keystone.v2_0.internal.BaseKeystoneRestClientExpectTest;
|
import org.jclouds.openstack.keystone.v2_0.internal.BaseKeystoneRestClientExpectTest;
|
||||||
import org.jclouds.rest.AuthorizationException;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
@ -67,46 +65,4 @@ public class ServiceClientExpectTest extends BaseKeystoneRestClientExpectTest<Ke
|
||||||
.getServiceClient();
|
.getServiceClient();
|
||||||
assertTrue(client.listTenants().isEmpty());
|
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"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.keystone.v2_0.features;
|
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.assertFalse;
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
|
||||||
|
@ -44,24 +43,6 @@ public class ServiceClientLiveTest extends BaseKeystoneClientLiveTest {
|
||||||
|
|
||||||
for (Tenant tenant : result) {
|
for (Tenant tenant : result) {
|
||||||
assertNotNull(tenant.getId());
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue