diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java index 10b75631fa..9beebf4384 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorAsyncClient.java @@ -26,6 +26,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Media; import org.jclouds.vcloud.director.v1_5.domain.Org; import org.jclouds.vcloud.director.v1_5.domain.Session; import org.jclouds.vcloud.director.v1_5.domain.Task; +import org.jclouds.vcloud.director.v1_5.domain.User; import org.jclouds.vcloud.director.v1_5.domain.Vdc; import org.jclouds.vcloud.director.v1_5.domain.ovf.Network; import org.jclouds.vcloud.director.v1_5.features.AdminCatalogAsyncClient; @@ -37,6 +38,7 @@ import org.jclouds.vcloud.director.v1_5.features.OrgAsyncClient; import org.jclouds.vcloud.director.v1_5.features.QueryAsyncClient; import org.jclouds.vcloud.director.v1_5.features.TaskAsyncClient; import org.jclouds.vcloud.director.v1_5.features.UploadAsyncClient; +import org.jclouds.vcloud.director.v1_5.features.UserAsyncClient; import org.jclouds.vcloud.director.v1_5.features.VAppTemplateAsyncClient; import org.jclouds.vcloud.director.v1_5.features.VdcAsyncClient; @@ -128,4 +130,10 @@ public interface VCloudDirectorAsyncClient { */ @Delegate AdminOrgAsyncClient getAdminOrgClient(); + + /** + * @return asynchronous access to {@link User} features + */ + @Delegate + UserAsyncClient getUserClient(); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java index 87fee2652a..9ae0e70357 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/VCloudDirectorClient.java @@ -29,6 +29,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Media; import org.jclouds.vcloud.director.v1_5.domain.Org; import org.jclouds.vcloud.director.v1_5.domain.Session; import org.jclouds.vcloud.director.v1_5.domain.Task; +import org.jclouds.vcloud.director.v1_5.domain.User; import org.jclouds.vcloud.director.v1_5.domain.Vdc; import org.jclouds.vcloud.director.v1_5.domain.ovf.Network; import org.jclouds.vcloud.director.v1_5.features.AdminCatalogClient; @@ -41,6 +42,7 @@ import org.jclouds.vcloud.director.v1_5.features.OrgClient; import org.jclouds.vcloud.director.v1_5.features.QueryClient; import org.jclouds.vcloud.director.v1_5.features.TaskClient; import org.jclouds.vcloud.director.v1_5.features.UploadClient; +import org.jclouds.vcloud.director.v1_5.features.UserClient; import org.jclouds.vcloud.director.v1_5.features.VAppTemplateClient; import org.jclouds.vcloud.director.v1_5.features.VdcClient; @@ -131,4 +133,10 @@ public interface VCloudDirectorClient { */ @Delegate AdminOrgClient getAdminOrgClient(); + + /** + * @return synchronous access to {@link User} features + */ + @Delegate + UserClient getUserClient(); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java index b77551ea0a..859060432d 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java @@ -64,6 +64,8 @@ import org.jclouds.vcloud.director.v1_5.features.TaskAsyncClient; import org.jclouds.vcloud.director.v1_5.features.TaskClient; import org.jclouds.vcloud.director.v1_5.features.UploadAsyncClient; import org.jclouds.vcloud.director.v1_5.features.UploadClient; +import org.jclouds.vcloud.director.v1_5.features.UserAsyncClient; +import org.jclouds.vcloud.director.v1_5.features.UserClient; import org.jclouds.vcloud.director.v1_5.features.VAppTemplateAsyncClient; import org.jclouds.vcloud.director.v1_5.features.VAppTemplateClient; import org.jclouds.vcloud.director.v1_5.features.VdcAsyncClient; @@ -109,6 +111,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule @@ -122,7 +125,7 @@ public class User private Integer deployedVmQuota; private Reference role; private String password; - private Object /* GroupsList */ groupReferences; + private List groups; /** * @see User#getFullName() @@ -261,20 +264,27 @@ public class User } /** - * @see User#getGroupReferences() + * @see User#getGroups() */ - public Builder groupReferences(Object /* GroupsList */ groupReferences) { - this.groupReferences = groupReferences; + public Builder groups(List groups) { + this.groups = ImmutableList.copyOf(groups); + return this; + } + + /** + * @see User#getGroups() + */ + public Builder group(Reference group) { + this.groups.add(checkNotNull(group, "group")); return this; } - public User build() { return new User(href, type, links, description, tasks, id, name, fullName, emailAddress, telephone, isEnabled, isLocked, im, nameInSource, isAlertEnabled, alertEmailPrefix, alertEmail, isExternal, isDefaultCached, isGroupRole, storedVmQuota, deployedVmQuota, - role, password, groupReferences); + role, password, groups); } @@ -357,7 +367,7 @@ public class User .deployedVmQuota(in.getDeployedVmQuota()) .role(in.getRole()) .password(in.getPassword()) - .groupReferences(in.getGroupReferences()); + .groups(in.getGroups()); } } @@ -395,14 +405,14 @@ public class User protected Reference role; @XmlElement(name = "Password") protected String password; - @XmlElement(name = "GroupReferences") - protected Object /* GroupsList */ groupReferences; + @XmlElementWrapper(name = "GroupReferences") + protected List groups; public User(URI href, String type, Set links, String description, Set tasks, String id, String name, String fullName, String emailAddress, String telephone, Boolean enabled, Boolean locked, String im, String nameInSource, Boolean alertEnabled, String alertEmailPrefix, String alertEmail, Boolean external, Boolean defaultCached, Boolean groupRole, Integer storedVmQuota, Integer deployedVmQuota, - Reference role, String password, Object groupReferences) { + Reference role, String password, List groups) { super(href, type, links, description, tasks, id, name); this.fullName = fullName; this.emailAddress = emailAddress; @@ -421,7 +431,7 @@ public class User this.deployedVmQuota = deployedVmQuota; this.role = role; this.password = password; - this.groupReferences = groupReferences; + this.groups = groups; } private User() { @@ -605,8 +615,8 @@ public class User * @return possible object is * {@link GroupsListType } */ - public Object /* GroupsList */ getGroupReferences() { - return groupReferences; + public List getGroups() { + return groups; } @Override @@ -633,7 +643,7 @@ public class User equal(deployedVmQuota, that.deployedVmQuota) && equal(role, that.role) && equal(password, that.password) && - equal(groupReferences, that.groupReferences); + equal(groups, that.groups); } @Override @@ -655,7 +665,7 @@ public class User deployedVmQuota, role, password, - groupReferences); + groups); } @Override @@ -678,7 +688,7 @@ public class User .add("deployedVmQuota", deployedVmQuota) .add("role", role) .add("password", password) - .add("groupReferences", groupReferences).toString(); + .add("groups", groups).toString(); } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java new file mode 100644 index 0000000000..24c80c9c45 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserAsyncClient.java @@ -0,0 +1,39 @@ +/** + * 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.vcloud.director.v1_5.features; + +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; + +/** + * @see GroupClient + * @author danikov + */ +@RequestFilters(AddVCloudAuthorizationToRequest.class) +public interface UserAsyncClient { +// POST /admin/org/{id}/users + +// GET /admin/user/{id} + +// PUT /admin/user/{id} + +// DELETE /admin/user/{id} + +// POST /admin/user/{id}/action/unlock +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.java new file mode 100644 index 0000000000..694efaf5a5 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/UserClient.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.vcloud.director.v1_5.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.vcloud.director.v1_5.domain.Group; + +/** + * Provides synchronous access to {@link Group} objects. + * + * @see GroupAsyncClient + * @author danikov + */ +@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) +public interface UserClient { +// POST /admin/org/{id}/users + +// GET /admin/user/{id} + +// PUT /admin/user/{id} + +// DELETE /admin/user/{id} + +// POST /admin/user/{id}/action/unlock +} diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java index d6f966d534..4612365b00 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java @@ -748,4 +748,52 @@ public class Checks { // parent type checkResourceType(settings); } + + public static void checkUser(User user) { + // Check optional fields + // NOTE fullName cannot be checked + // NOTE isEnabled cannot be checked + // NOTE isLocked cannot be checked + // NOTE im cannot be checked + // NOTE nameInSource cannot be checked + // NOTE isAlertEnabled cannot be checked + // NOTE alterEmailPrefix cannot be checked + // NOTE isExternal cannot be checked + // NOTE isDefaultCached cannot be checked + // NOTE isGroupRole cannot be checked + // NOTE password cannot be checked + + if (user.getEmailAddress() != null) { + checkEmailAddress(user.getEmailAddress()); + } + if (user.getTelephone() != null) { + checkTelephone(user.getTelephone()); + } + if (user.getAlertEmail() != null) { + checkEmailAddress(user.getAlertEmail()); + } + if (user.getStoredVmQuota() != null) { + assertTrue(user.getStoredVmQuota() >= 0, String.format(OBJ_FIELD_GTE_0, + "User", "storedVmQuota", user.getStoredVmQuota())); + } + if (user.getDeployedVmQuota() != null) { + assertTrue(user.getDeployedVmQuota() >= 0, String.format(OBJ_FIELD_GTE_0, + "User", "deployedVmQuota", user.getDeployedVmQuota())); + } + if (user.getRole() != null) { + checkReferenceType(user.getRole()); + } + if (user.getGroups() != null) { + for (Reference group : user.getGroups()) { + checkReferenceType(group); + } + } + + // parent type + checkEntityType(user); + } + + public static void checkTelephone(String number) { + // TODO: regex validate telephone + } } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java new file mode 100644 index 0000000000..0100e1aecd --- /dev/null +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientExpectTest.java @@ -0,0 +1,48 @@ +/* + * 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.vcloud.director.v1_5.features; + +import java.net.URI; + +import org.jclouds.vcloud.director.v1_5.domain.Reference; +import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; +import org.testng.annotations.Test; + +/** + * Test the {@link GroupClient} by observing its side effects. + * + * @author danikov + */ +@Test(groups = { "unit", "admin", "adminUser"}, singleThreaded = true, testName = "UserClientExpectTest") +public class UserClientExpectTest extends BaseVCloudDirectorRestClientExpectTest { + + private Reference userRef = Reference.builder() + .href(URI.create(endpoint + "/admin/user/???")) + .build(); + +// POST /admin/org/{id}/users + +// GET /admin/user/{id} + +// PUT /admin/user/{id} + +// DELETE /admin/user/{id} + +// POST /admin/user/{id}/action/unlock +} diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java new file mode 100644 index 0000000000..5e715b70bc --- /dev/null +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/UserClientLiveTest.java @@ -0,0 +1,57 @@ +/* + * 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.vcloud.director.v1_5.features; + +import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Tests live behavior of {@link AdminGroupClient}. + * + * @author danikov + */ +@Test(groups = { "live", "admin", "adminUser" }, singleThreaded = true, testName = "UserClientLiveTest") +public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest { + + public static final String GROUP = "admin group"; + + /* + * Convenience references to API clients. + */ + + /* + * Shared state between dependant tests. + */ + + @Override + @BeforeClass(inheritGroups = true) + public void setupRequiredClients() { + } + +// POST /admin/org/{id}/users + +// GET /admin/user/{id} + +// PUT /admin/user/{id} + +// DELETE /admin/user/{id} + +// POST /admin/user/{id}/action/unlock +}