From 9741babe39a9d149acc83118e2cf7180ec370f56 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 24 Feb 2013 12:34:25 -0800 Subject: [PATCH] updated IAM listing to be inline with other recent aws apis --- .../java/org/jclouds/iam/IAMAsyncApi.java | 1 - .../iam/config/IAMRestClientModule.java | 1 - .../java/org/jclouds/iam/domain/User.java | 217 ++++++++---------- .../org/jclouds/iam/features/UserApi.java | 68 ++++-- .../jclouds/iam/features/UserAsyncApi.java | 88 +++++-- .../iam/functions/UsersToPagedIterable.java | 63 +++-- .../jclouds/iam/options/ListUsersOptions.java | 144 ------------ .../iam/xml/ListUsersResultHandler.java | 37 ++- .../java/org/jclouds/iam/xml/UserHandler.java | 33 ++- .../iam/features/UserApiExpectTest.java | 60 ++++- .../jclouds/iam/features/UserApiLiveTest.java | 37 ++- .../iam/options/ListUsersOptionsTest.java | 68 ------ 12 files changed, 343 insertions(+), 474 deletions(-) delete mode 100644 labs/iam/src/main/java/org/jclouds/iam/options/ListUsersOptions.java delete mode 100644 labs/iam/src/test/java/org/jclouds/iam/options/ListUsersOptionsTest.java diff --git a/labs/iam/src/main/java/org/jclouds/iam/IAMAsyncApi.java b/labs/iam/src/main/java/org/jclouds/iam/IAMAsyncApi.java index ac6fec6324..6978582741 100644 --- a/labs/iam/src/main/java/org/jclouds/iam/IAMAsyncApi.java +++ b/labs/iam/src/main/java/org/jclouds/iam/IAMAsyncApi.java @@ -62,5 +62,4 @@ public interface IAMAsyncApi { */ @Delegate UserAsyncApi getUserApi(); - } diff --git a/labs/iam/src/main/java/org/jclouds/iam/config/IAMRestClientModule.java b/labs/iam/src/main/java/org/jclouds/iam/config/IAMRestClientModule.java index 68b2a27905..1b80c35ab1 100644 --- a/labs/iam/src/main/java/org/jclouds/iam/config/IAMRestClientModule.java +++ b/labs/iam/src/main/java/org/jclouds/iam/config/IAMRestClientModule.java @@ -45,5 +45,4 @@ public class IAMRestClientModule extends FormSigningRestClientModule builder() { - return new ConcreteBuilder(); - } +public final class User { - public Builder toBuilder() { - return new ConcreteBuilder().fromUser(this); - } - - public abstract static class Builder> { - protected abstract T self(); - - private Optional path = Optional.absent(); - private String id; - private Optional name = Optional.absent(); - private String arn; - private Date createDate; - - /** - * @see User#getPath() - */ - public T path(String path) { - this.path = Optional.fromNullable(path); - return self(); - } - - /** - * @see User#getId() - */ - public T id(String id) { - this.id = id; - return self(); - } - - /** - * @see User#getName() - */ - public T name(String name) { - this.name = Optional.fromNullable(name); - return self(); - } - - /** - * @see User#getArn() - */ - public T arn(String arn) { - this.arn = arn; - return self(); - } - - /** - * @see User#getCreateDate() - */ - public T createDate(Date createDate) { - this.createDate = createDate; - return self(); - } - - public User build() { - return new User(path, name, id, arn, createDate); - } - - public T fromUser(User in) { - return this - .path(in.getPath().orNull()) - .name(in.getName().orNull()) - .id(in.getId()) - .arn(in.getArn()) - .createDate(in.getCreateDate()) - ; - } - } - - private static class ConcreteBuilder extends Builder { - @Override - protected ConcreteBuilder self() { - return this; - } - } - private final Optional path; private final Optional name; private final String id; private final String arn; private final Date createDate; - - protected User(Optional path, Optional name, String id, String arn, Date createDate) { - this.path = path; - this.name = name; - this.id = id; - this.arn = arn; - this.createDate = createDate; + + private User(String id, String arn, Optional path, Optional name, Date createDate) { + this.id = checkNotNull(id, "id"); + this.arn = checkNotNull(arn, "arn for %s", id); + this.path = checkNotNull(path, "path for %s", arn); + this.name = checkNotNull(name, "name for %s", arn); + this.createDate = checkNotNull(createDate, "createDate for %s", arn); } /** - * you can also optionally give the entity a path that you define. You might use the path to - * identify which division or part of the organization the entity belongs in. For example: - * /division_abc/subdivision_xyz/product_1234/engineering/ - */ - public Optional getPath() { - return path; - } - - /** - * When you create a user, a role, or a group, or when you upload a server certificate, you give - * it a friendly name, such as Bob, TestApp1, Developers, or ProdServerCert. Whenever you need to - * specify a particular entity in an API call to IAM (for example, to delete a user, or update a - * group with a new user), you use the friendly name. - */ - public Optional getName() { - return name; - } - - /** - * We assign each user, group, and server certificate a globally unique identifier (GUID), which - * we return to you when you use the API or CLI to create it. We recommend you store the GUID in - * your own database along with the user, group, or certificate name. Internally we use the GUID - * to identify the user, group, or certificate, and we translate the value into the ARN or - * friendly name as appropriate when displaying the user, group, or certificate information to - * you. If you delete a user, group, or server certificate, any residual remote references to - * that item display the GUID as the friendly name part in the ARN. If you've stored the GUID in - * your own system, you can then use the displayed GUID to identify the deleted item being - * referred to. + * a globally unique identifier (GUID), returned from the api. */ public String getId() { return id; } /** - * Although most resources have a friendly name (for example, a user named Bob or a group named - * Developers), the access policy language requires you to specify the resource or resources - * using the following Amazon Resource Name (ARN) format. - * + * how to specify the resource in the access policy language ex. * {@code arn:aws::::} */ public String getArn() { return arn; } + /** + * path ex {@code /division_abc/subdivision_xyz/product_1234/engineering/} + */ + public Optional getPath() { + return path; + } + + /** + * friendly name ex. {@code Developers} + */ + public Optional getName() { + return name; + } + /** * Date the user was created */ public Date getCreateDate() { return createDate; } - + /** * {@inheritDoc} */ @@ -189,9 +97,7 @@ public class User { public boolean equals(Object obj) { if (this == obj) return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) + if (obj == null || getClass() != obj.getClass()) return false; User other = (User) obj; return Objects.equal(this.id, other.id) && Objects.equal(this.arn, other.arn); @@ -202,8 +108,71 @@ public class User { */ @Override public String toString() { - return Objects.toStringHelper(this).add("path", path).add("name", name).add("id", id).add("arn", arn).add( - "createDate", createDate).toString(); + return Objects.toStringHelper(this).add("path", path).add("name", name).add("id", id).add("arn", arn) + .add("createDate", createDate).toString(); } + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().from(this); + } + + public static class Builder { + private Optional path = Optional.absent(); + private String id; + private Optional name = Optional.absent(); + private String arn; + private Date createDate; + + /** + * @see User#getPath() + */ + public Builder path(String path) { + this.path = Optional.fromNullable(path); + return this; + } + + /** + * @see User#getId() + */ + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see User#getName() + */ + public Builder name(String name) { + this.name = Optional.fromNullable(name); + return this; + } + + /** + * @see User#getArn() + */ + public Builder arn(String arn) { + this.arn = arn; + return this; + } + + /** + * @see User#getCreateDate() + */ + public Builder createDate(Date createDate) { + this.createDate = createDate; + return this; + } + + public User build() { + return new User(id, arn, path, name, createDate); + } + + public Builder from(User in) { + return this.path(in.path.orNull()).name(in.name.orNull()).id(in.id).arn(in.arn).createDate(in.createDate); + } + } } diff --git a/labs/iam/src/main/java/org/jclouds/iam/features/UserApi.java b/labs/iam/src/main/java/org/jclouds/iam/features/UserApi.java index c1f26bdf53..bca4eae459 100644 --- a/labs/iam/src/main/java/org/jclouds/iam/features/UserApi.java +++ b/labs/iam/src/main/java/org/jclouds/iam/features/UserApi.java @@ -21,7 +21,6 @@ package org.jclouds.iam.features; import org.jclouds.collect.IterableWithMarker; import org.jclouds.collect.PagedIterable; import org.jclouds.iam.domain.User; -import org.jclouds.iam.options.ListUsersOptions; import org.jclouds.javax.annotation.Nullable; /** @@ -37,6 +36,50 @@ public interface UserApi { */ User getCurrent(); + /** + * returns all users in order. + */ + PagedIterable list(); + + /** + * retrieves up to 100 users in order. + */ + IterableWithMarker listFirstPage(); + + /** + * retrieves up to 100 users in order, starting at {@code marker} + * + * @param marker + * starting point to resume the list + */ + IterableWithMarker listAt(String marker); + + /** + * returns all users in order at the specified {@code pathPrefix}. + * + * @param pathPrefix + * ex. {@code /division_abc/subdivision_xyz/} + */ + PagedIterable listPathPrefix(String pathPrefix); + + /** + * retrieves up to 100 users in order at the specified {@code pathPrefix}. + * + * @param pathPrefix + * ex. {@code /division_abc/subdivision_xyz/} + */ + IterableWithMarker listPathPrefixFirstPage(String pathPrefix); + + /** + * retrieves up to 100 users in order at the specified {@code pathPrefix}, starting at {@code marker}. + * + * @param pathPrefix + * ex. {@code /division_abc/subdivision_xyz/} + * @param marker + * starting point to resume the list + */ + IterableWithMarker listPathPrefixAt(String pathPrefix, String marker); + /** * Retrieves information about the specified user, including the user's path, GUID, and ARN. * @@ -46,27 +89,4 @@ public interface UserApi { */ @Nullable User get(String name); - - /** - * Lists the users that have the specified path prefix. If there are none, the action returns an - * empty list. - * - *
- * You can paginate the results using the {@link ListUsersOptions parameter} - * - * @param options - * the options describing the users query - * - * @return the response object - */ - IterableWithMarker list(ListUsersOptions options); - - /** - * Lists the users that have the specified path prefix. If there are none, the action returns an - * empty list. - * - * @return the response object - */ - PagedIterable list(); - } diff --git a/labs/iam/src/main/java/org/jclouds/iam/features/UserAsyncApi.java b/labs/iam/src/main/java/org/jclouds/iam/features/UserAsyncApi.java index 45f4e3b397..e2cbb96dcd 100644 --- a/labs/iam/src/main/java/org/jclouds/iam/features/UserAsyncApi.java +++ b/labs/iam/src/main/java/org/jclouds/iam/features/UserAsyncApi.java @@ -29,7 +29,6 @@ import org.jclouds.collect.IterableWithMarker; import org.jclouds.collect.PagedIterable; import org.jclouds.iam.domain.User; import org.jclouds.iam.functions.UsersToPagedIterable; -import org.jclouds.iam.options.ListUsersOptions; import org.jclouds.iam.xml.ListUsersResultHandler; import org.jclouds.iam.xml.UserHandler; import org.jclouds.rest.annotations.Fallback; @@ -52,6 +51,69 @@ import com.google.common.util.concurrent.ListenableFuture; @VirtualHost public interface UserAsyncApi { + /** + * @see UserApi#list() + */ + @Named("ListUsers") + @POST + @Path("/") + @FormParams(keys = "Action", values = "ListUsers") + @XMLResponseParser(ListUsersResultHandler.class) + @Transform(UsersToPagedIterable.class) + ListenableFuture> list(); + + /** + * @see UserApi#listFirstPage + */ + @Named("ListUsers") + @POST + @Path("/") + @FormParams(keys = "Action", values = "ListUsers") + @XMLResponseParser(ListUsersResultHandler.class) + ListenableFuture> listFirstPage(); + + /** + * @see UserApi#listAt(String) + */ + @Named("ListUsers") + @POST + @Path("/") + @FormParams(keys = "Action", values = "ListUsers") + @XMLResponseParser(ListUsersResultHandler.class) + ListenableFuture> listAt(@FormParam("Marker") String marker); + + /** + * @see UserApi#listPathPrefix(String) + */ + @Named("ListUsers") + @POST + @Path("/") + @FormParams(keys = "Action", values = "ListUsers") + @XMLResponseParser(ListUsersResultHandler.class) + @Transform(UsersToPagedIterable.class) + ListenableFuture> listPathPrefix(@FormParam("PathPrefix") String pathPrefix); + + /** + * @see UserApi#listPathPrefixFirstPage(String) + */ + @Named("ListUsers") + @POST + @Path("/") + @FormParams(keys = "Action", values = "ListUsers") + @XMLResponseParser(ListUsersResultHandler.class) + ListenableFuture> listPathPrefixFirstPage(@FormParam("PathPrefix") String pathPrefix); + + /** + * @see UserApi#listPathPrefixAt(String, String) + */ + @Named("ListUsers") + @POST + @Path("/") + @FormParams(keys = "Action", values = "ListUsers") + @XMLResponseParser(ListUsersResultHandler.class) + ListenableFuture> listPathPrefixAt(@FormParam("PathPrefix") String pathPrefix, + @FormParam("Marker") String marker); + /** * @see UserApi#getCurrent() */ @@ -61,7 +123,7 @@ public interface UserAsyncApi { @XMLResponseParser(UserHandler.class) @FormParams(keys = "Action", values = "GetUser") ListenableFuture getCurrent(); - + /** * @see UserApi#get() */ @@ -72,26 +134,4 @@ public interface UserAsyncApi { @FormParams(keys = "Action", values = "GetUser") @Fallback(NullOnNotFoundOr404.class) ListenableFuture get(@FormParam("UserName") String name); - - /** - * @see UserApi#list() - */ - @Named("ListUsers") - @POST - @Path("/") - @XMLResponseParser(ListUsersResultHandler.class) - @Transform(UsersToPagedIterable.class) - @FormParams(keys = "Action", values = "ListUsers") - ListenableFuture> list(); - - /** - * @see UserApi#list(ListUsersOptions) - */ - @Named("ListUsers") - @POST - @Path("/") - @XMLResponseParser(ListUsersResultHandler.class) - @FormParams(keys = "Action", values = "ListUsers") - ListenableFuture> list(ListUsersOptions options); - } diff --git a/labs/iam/src/main/java/org/jclouds/iam/functions/UsersToPagedIterable.java b/labs/iam/src/main/java/org/jclouds/iam/functions/UsersToPagedIterable.java index f5f772b7df..085f9005de 100644 --- a/labs/iam/src/main/java/org/jclouds/iam/functions/UsersToPagedIterable.java +++ b/labs/iam/src/main/java/org/jclouds/iam/functions/UsersToPagedIterable.java @@ -23,43 +23,68 @@ import static com.google.common.base.Preconditions.checkNotNull; import javax.inject.Inject; import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.internal.CallerArg0ToPagedIterable; +import org.jclouds.collect.internal.Arg0ToPagedIterable; import org.jclouds.iam.IAMApi; import org.jclouds.iam.domain.User; import org.jclouds.iam.features.UserApi; -import org.jclouds.iam.options.ListUsersOptions; import com.google.common.annotations.Beta; import com.google.common.base.Function; +import com.google.common.base.Optional; /** * @author Adrian Cole */ @Beta -public class UsersToPagedIterable extends CallerArg0ToPagedIterable { +public class UsersToPagedIterable extends Arg0ToPagedIterable { - private final IAMApi api; + private final UserApi api; @Inject protected UsersToPagedIterable(IAMApi api) { - this.api = checkNotNull(api, "api"); + this.api = checkNotNull(api, "api").getUserApi(); } @Override - protected Function> markerToNextForCallingArg0(String ignored) { - final UserApi userApi = api.getUserApi(); - return new Function>() { - - @Override - public IterableWithMarker apply(Object input) { - return userApi.list(ListUsersOptions.Builder.afterMarker(input.toString())); - } - - @Override - public String toString() { - return "listUsers()"; - } - }; + protected Function> markerToNextForArg0(Optional pathPrefix) { + if (pathPrefix.isPresent()) + return new ListUsersUnderPathPrefixAtMarker(api, pathPrefix.get().toString()); + return new ListUsersAtMarker(api); } + private static class ListUsersUnderPathPrefixAtMarker implements Function> { + private final UserApi api; + private final String pathPrefix; + + @Inject + protected ListUsersUnderPathPrefixAtMarker(UserApi api, String pathPrefix) { + this.api = checkNotNull(api, "api"); + this.pathPrefix = checkNotNull(pathPrefix, "pathPrefix"); + } + + public IterableWithMarker apply(Object input) { + return api.listPathPrefixAt(pathPrefix, input.toString()); + } + + public String toString() { + return "ListUsersUnderPathPrefixAtMarker(" + pathPrefix + ")"; + } + } + + private static class ListUsersAtMarker implements Function> { + private final UserApi api; + + @Inject + protected ListUsersAtMarker(UserApi api) { + this.api = checkNotNull(api, "api"); + } + + public IterableWithMarker apply(Object input) { + return api.listAt(input.toString()); + } + + public String toString() { + return "listUsersAtMarker()"; + } + } } diff --git a/labs/iam/src/main/java/org/jclouds/iam/options/ListUsersOptions.java b/labs/iam/src/main/java/org/jclouds/iam/options/ListUsersOptions.java deleted file mode 100644 index f38773b810..0000000000 --- a/labs/iam/src/main/java/org/jclouds/iam/options/ListUsersOptions.java +++ /dev/null @@ -1,144 +0,0 @@ -/** - * 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.iam.options; - -import org.jclouds.http.options.BaseHttpRequestOptions; - -import com.google.common.base.Objects; -import com.google.common.collect.Multimap; - -/** - * Options used to list available users. - * - * @see - * - * @author Adrian Cole - */ -public class ListUsersOptions extends BaseHttpRequestOptions implements Cloneable { - - private Integer maxItems; - private String pathPrefix; - private Object afterMarker; - - /** - * Use this parameter only when paginating results, and only in a subsequent request after you've - * received a response where the results are truncated. Set it to the value of the Marker element - * in the response you just received. - */ - public ListUsersOptions afterMarker(Object afterMarker) { - this.afterMarker = afterMarker; - return this; - } - - /** - * Use this parameter only when paginating results to indicate the maximum number of user names - * you want in the response. If there are additional user names beyond the maximum you specify, - * the IsTruncated response element is true. - */ - public ListUsersOptions maxItems(Integer maxItems) { - this.maxItems = maxItems; - return this; - } - - /** - * The path prefix for filtering the results. For example: /division_abc/subdivision_xyz/, which - * would get all user names whose path starts with /division_abc/subdivision_xyz/. - *

- * This parameter is optional. If it is not included, it defaults to a slash (/), listing all - * user names. - */ - public ListUsersOptions pathPrefix(String pathPrefix) { - this.pathPrefix = pathPrefix; - return this; - } - - public static class Builder { - - /** - * @see ListUsersOptions#afterMarker - */ - public static ListUsersOptions afterMarker(Object afterMarker) { - return new ListUsersOptions().afterMarker(afterMarker); - } - - /** - * @see ListUsersOptions#maxItems - */ - public static ListUsersOptions maxItems(Integer maxItems) { - return new ListUsersOptions().maxItems(maxItems); - } - - /** - * @see ListUsersOptions#pathPrefix - */ - public static ListUsersOptions pathPrefix(String pathPrefix) { - return new ListUsersOptions().pathPrefix(pathPrefix); - } - } - - @Override - public Multimap buildFormParameters() { - Multimap params = super.buildFormParameters(); - if (afterMarker != null) - params.put("Marker", afterMarker.toString()); - if (maxItems != null) - params.put("MaxItems", maxItems.toString()); - if (pathPrefix != null) - params.put("PathPrefix", pathPrefix); - return params; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(afterMarker, maxItems, pathPrefix); - } - - @Override - public ListUsersOptions clone() { - return new ListUsersOptions().afterMarker(afterMarker).maxItems(maxItems).pathPrefix(pathPrefix); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ListUsersOptions other = ListUsersOptions.class.cast(obj); - return Objects.equal(this.afterMarker, other.afterMarker) && Objects.equal(this.maxItems, other.maxItems) - && Objects.equal(this.pathPrefix, other.pathPrefix); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return Objects.toStringHelper(this).omitNullValues().add("afterMarker", afterMarker).add("maxItems", maxItems).add( - "pathPrefix", pathPrefix).toString(); - } -} diff --git a/labs/iam/src/main/java/org/jclouds/iam/xml/ListUsersResultHandler.java b/labs/iam/src/main/java/org/jclouds/iam/xml/ListUsersResultHandler.java index 50fb532bb9..980d24b0cc 100644 --- a/labs/iam/src/main/java/org/jclouds/iam/xml/ListUsersResultHandler.java +++ b/labs/iam/src/main/java/org/jclouds/iam/xml/ListUsersResultHandler.java @@ -18,17 +18,17 @@ */ package org.jclouds.iam.xml; -import java.util.Set; +import static org.jclouds.util.SaxUtils.currentOrNull; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; import org.jclouds.collect.IterableWithMarker; import org.jclouds.collect.IterableWithMarkers; import org.jclouds.http.functions.ParseSax; import org.jclouds.iam.domain.User; -import org.jclouds.util.SaxUtils; import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import com.google.common.collect.Sets; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; import com.google.inject.Inject; /** @@ -41,7 +41,7 @@ public class ListUsersResultHandler extends ParseSax.HandlerForGeneratedRequestW private final UserHandler userHandler; private StringBuilder currentText = new StringBuilder(); - private Set users = Sets.newLinkedHashSet(); + private Builder users = ImmutableList. builder(); private boolean inUsers; private String afterMarker; @@ -50,20 +50,18 @@ public class ListUsersResultHandler extends ParseSax.HandlerForGeneratedRequestW this.userHandler = userHandler; } - /** - * {@inheritDoc} - */ @Override public IterableWithMarker getResult() { - return IterableWithMarkers.from(users, afterMarker); + try { + return IterableWithMarkers.from(users.build(), afterMarker); + } finally { + users = ImmutableList. builder(); + } } - /** - * {@inheritDoc} - */ @Override - public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException { - if (SaxUtils.equalsOrSuffix(qName, "Users")) { + public void startElement(String url, String name, String qName, Attributes attributes) { + if (equalsOrSuffix(qName, "Users")) { inUsers = true; } if (inUsers) { @@ -71,11 +69,8 @@ public class ListUsersResultHandler extends ParseSax.HandlerForGeneratedRequestW } } - /** - * {@inheritDoc} - */ @Override - public void endElement(String uri, String name, String qName) throws SAXException { + public void endElement(String uri, String name, String qName) { if (inUsers) { if (qName.equals("Users")) { inUsers = false; @@ -85,15 +80,12 @@ public class ListUsersResultHandler extends ParseSax.HandlerForGeneratedRequestW userHandler.endElement(uri, name, qName); } } else if (qName.equals("Marker")) { - afterMarker = SaxUtils.currentOrNull(currentText); + afterMarker = currentOrNull(currentText); } currentText = new StringBuilder(); } - /** - * {@inheritDoc} - */ @Override public void characters(char ch[], int start, int length) { if (inUsers) { @@ -102,5 +94,4 @@ public class ListUsersResultHandler extends ParseSax.HandlerForGeneratedRequestW currentText.append(ch, start, length); } } - } diff --git a/labs/iam/src/main/java/org/jclouds/iam/xml/UserHandler.java b/labs/iam/src/main/java/org/jclouds/iam/xml/UserHandler.java index 35db67d42a..0c155a30d0 100644 --- a/labs/iam/src/main/java/org/jclouds/iam/xml/UserHandler.java +++ b/labs/iam/src/main/java/org/jclouds/iam/xml/UserHandler.java @@ -18,13 +18,14 @@ */ package org.jclouds.iam.xml; +import static org.jclouds.util.SaxUtils.currentOrNull; + import javax.inject.Inject; import org.jclouds.date.DateService; import org.jclouds.http.functions.ParseSax; import org.jclouds.iam.domain.User; -import org.jclouds.util.SaxUtils; -import org.xml.sax.SAXException; +import org.xml.sax.Attributes; /** * @see @@ -40,11 +41,8 @@ public class UserHandler extends ParseSax.HandlerForGeneratedRequestWithResult builder = User.builder(); + private User.Builder builder = User.builder(); - /** - * {@inheritDoc} - */ @Override public User getResult() { try { @@ -54,31 +52,28 @@ public class UserHandler extends ParseSax.HandlerForGeneratedRequestWithResult response = api().list().get(0); - - for (User user : response) { - checkUser(user); - } - - if (Iterables.size(response) > 0) { - User user = response.iterator().next(); - Assert.assertEquals(api().get(user.getName().get()), user); - } + ImmutableList users = api().list().concat().toList(); + getAnonymousLogger().info("users: " + users.size()); - // Test with a Marker, even if it's null - response = api().list(ListUsersOptions.Builder.afterMarker(response.nextMarker().orNull())); - for (User user : response) { + for (User user : users) { checkUser(user); + assertEquals(api().get(user.getId()), user); + if (user.getPath().isPresent()) + assertEquals(api().listPathPrefix(user.getPath().get()).toSet(), ImmutableSet.of(user)); } } diff --git a/labs/iam/src/test/java/org/jclouds/iam/options/ListUsersOptionsTest.java b/labs/iam/src/test/java/org/jclouds/iam/options/ListUsersOptionsTest.java deleted file mode 100644 index bca9f9a507..0000000000 --- a/labs/iam/src/test/java/org/jclouds/iam/options/ListUsersOptionsTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * 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.iam.options; - -import static org.jclouds.iam.options.ListUsersOptions.Builder.afterMarker; -import static org.jclouds.iam.options.ListUsersOptions.Builder.maxItems; -import static org.jclouds.iam.options.ListUsersOptions.Builder.pathPrefix; -import static org.testng.Assert.assertEquals; - -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; - -/** - * Tests behavior of {@code ListUsersOptions} - * - * @author Adrian Cole - */ -@Test(groups = "maxItems", testName = "ListUsersOptionsTest") -public class ListUsersOptionsTest { - - public void testMarker() { - ListUsersOptions options = new ListUsersOptions().afterMarker("FFFFF"); - assertEquals(ImmutableSet.of("FFFFF"), options.buildFormParameters().get("Marker")); - } - - public void testMarkerStatic() { - ListUsersOptions options = afterMarker("FFFFF"); - assertEquals(ImmutableSet.of("FFFFF"), options.buildFormParameters().get("Marker")); - } - - public void testMaxItems() { - ListUsersOptions options = new ListUsersOptions().maxItems(1000); - assertEquals(ImmutableSet.of("1000"), options.buildFormParameters().get("MaxItems")); - } - - public void testMaxItemsStatic() { - ListUsersOptions options = maxItems(1000); - assertEquals(ImmutableSet.of("1000"), options.buildFormParameters().get("MaxItems")); - } - - public void testPathPrefix() { - ListUsersOptions options = new ListUsersOptions().pathPrefix("/division_abc/subdivision_xyz/"); - assertEquals(ImmutableSet.of("/division_abc/subdivision_xyz/"), options.buildFormParameters().get("PathPrefix")); - } - - public void testPathPrefixStatic() { - ListUsersOptions options = pathPrefix("/division_abc/subdivision_xyz/"); - assertEquals(ImmutableSet.of("/division_abc/subdivision_xyz/"), options.buildFormParameters().get("PathPrefix")); - } - -}