mirror of https://github.com/apache/jclouds.git
update User
This commit is contained in:
parent
bdc09ee053
commit
1309d803e8
|
@ -30,10 +30,9 @@ import javax.xml.bind.annotation.XmlElementWrapper;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
import javax.xml.bind.annotation.XmlType;
|
import javax.xml.bind.annotation.XmlType;
|
||||||
|
|
||||||
import org.testng.collections.Lists;
|
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,6 +24,7 @@ import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ public interface UserAsyncClient {
|
||||||
@Produces(VCloudDirectorMediaType.USER)
|
@Produces(VCloudDirectorMediaType.USER)
|
||||||
@JAXBResponseParser
|
@JAXBResponseParser
|
||||||
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||||
ListenableFuture<User> createUser(@EndpointParam URI orgRef,
|
ListenableFuture<User> createUser(@EndpointParam URI userRef,
|
||||||
@BinderParam(BindToXMLPayload.class) User user);
|
@BinderParam(BindToXMLPayload.class) User user);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,7 +68,16 @@ public interface UserAsyncClient {
|
||||||
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||||
ListenableFuture<User> getUser(@EndpointParam URI userRef);
|
ListenableFuture<User> getUser(@EndpointParam URI userRef);
|
||||||
|
|
||||||
// PUT /admin/user/{id}
|
/**
|
||||||
|
* @see UserClient#updateUser(URI, User)
|
||||||
|
*/
|
||||||
|
@PUT
|
||||||
|
@Consumes(VCloudDirectorMediaType.USER)
|
||||||
|
@Produces(VCloudDirectorMediaType.USER)
|
||||||
|
@JAXBResponseParser
|
||||||
|
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||||
|
ListenableFuture<User> updateUser(@EndpointParam URI userRef,
|
||||||
|
@BinderParam(BindToXMLPayload.class) User user);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see UserClient#deleteUser(URI)
|
* @see UserClient#deleteUser(URI)
|
||||||
|
|
|
@ -57,7 +57,18 @@ public interface UserClient {
|
||||||
*/
|
*/
|
||||||
User getUser(URI userRef);
|
User getUser(URI userRef);
|
||||||
|
|
||||||
// PUT /admin/user/{id}
|
/**
|
||||||
|
* Modifies a user. The user object could be enabled or disabled.
|
||||||
|
* Note: the lock status cannot be changed using this call: use unlockUser.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* PUT /admin/user/{id}
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param userRef the reference for the user
|
||||||
|
* @return the modified user
|
||||||
|
*/
|
||||||
|
User updateUser(URI userRef, User user);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a user. Enabled and disabled users could be deleted.
|
* Deletes a user. Enabled and disabled users could be deleted.
|
||||||
|
|
|
@ -132,7 +132,45 @@ public class UserClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT /admin/user/{id}
|
@Test
|
||||||
|
public void testUpdateUser() {
|
||||||
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
||||||
|
new VcloudHttpRequestPrimer()
|
||||||
|
.apiCommand("PUT", "/admin/user/b37223f3-8792-477a-820f-334998f61cd6")
|
||||||
|
.xmlFilePayload("/user/updateUserSource.xml", VCloudDirectorMediaType.USER)
|
||||||
|
.acceptMedia(VCloudDirectorMediaType.USER)
|
||||||
|
.httpRequestBuilder().build(),
|
||||||
|
new VcloudHttpResponsePrimer()
|
||||||
|
.xmlFilePayload("/user/updateUser.xml", VCloudDirectorMediaType.USER)
|
||||||
|
.httpResponseBuilder().build());
|
||||||
|
|
||||||
|
User source = updateUserSource();
|
||||||
|
User expected = updateUser();
|
||||||
|
|
||||||
|
assertEquals(client.getUserClient().updateUser(userRef.getHref(), source), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final User updateUserSource() {
|
||||||
|
return user().toBuilder()
|
||||||
|
.fullName("new"+user().getFullName())
|
||||||
|
.emailAddress("new"+user().getEmailAddress())
|
||||||
|
.telephone("1-"+user().getTelephone())
|
||||||
|
.isEnabled(true)
|
||||||
|
.im("new"+user().getIM())
|
||||||
|
.isAlertEnabled(true)
|
||||||
|
.alertEmailPrefix("new"+user().getAlertEmailPrefix())
|
||||||
|
.alertEmail("new"+user().getAlertEmail())
|
||||||
|
.storedVmQuota(1)
|
||||||
|
.deployedVmQuota(1)
|
||||||
|
.password("newPassword")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final User updateUser() {
|
||||||
|
return updateUserSource().toBuilder()
|
||||||
|
.password(null)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
// POST /admin/user/{id}/action/unlock
|
// POST /admin/user/{id}/action/unlock
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,12 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.vcloud.director.v1_5.features;
|
package org.jclouds.vcloud.director.v1_5.features;
|
||||||
|
|
||||||
|
import static com.google.common.base.Objects.equal;
|
||||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_DEL;
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_DEL;
|
||||||
|
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertNull;
|
import static org.testng.Assert.assertNull;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
import static org.testng.Assert.fail;
|
import static org.testng.Assert.fail;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -28,6 +31,7 @@ import java.net.URI;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.Checks;
|
import org.jclouds.vcloud.director.v1_5.domain.Checks;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.Error;
|
import org.jclouds.vcloud.director.v1_5.domain.Error;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.Owner;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.Reference;
|
import org.jclouds.vcloud.director.v1_5.domain.Reference;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
|
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.User;
|
import org.jclouds.vcloud.director.v1_5.domain.User;
|
||||||
|
@ -99,12 +103,69 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
||||||
Checks.checkUser(user);
|
Checks.checkUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT /admin/user/{id}
|
@Test(testName = "PUT /admin/user/{id}",
|
||||||
|
dependsOnMethods = { "testGetUser" })
|
||||||
|
public void testUpdateUser() {
|
||||||
|
User oldUser = user.toBuilder().build();
|
||||||
|
User newUser = user.toBuilder()
|
||||||
|
// .name("new"+oldUser.getName())
|
||||||
|
.fullName("new"+oldUser.getFullName())
|
||||||
|
.emailAddress("new"+oldUser.getEmailAddress())
|
||||||
|
.telephone("1-"+oldUser.getTelephone())
|
||||||
|
.isEnabled(true)
|
||||||
|
.im("new"+oldUser.getIM())
|
||||||
|
.isAlertEnabled(true)
|
||||||
|
.alertEmailPrefix("new"+oldUser.getAlertEmailPrefix())
|
||||||
|
.alertEmail("new"+oldUser.getAlertEmail())
|
||||||
|
// .role(Reference.builder() // FIXME: auto-fetch a role? or inject
|
||||||
|
// .name("vApp Author")
|
||||||
|
// .href(URI.create("https://vcloudbeta.bluelock.com/api/admin/role/1bf4457f-a253-3cf1-b163-f319f1a31802"))
|
||||||
|
// .build())
|
||||||
|
.storedVmQuota(1)
|
||||||
|
.deployedVmQuota(1)
|
||||||
|
.password("newPassword")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
userClient.updateUser(user.getHref(), newUser);
|
||||||
|
user = userClient.getUser(user.getHref());
|
||||||
|
Checks.checkUser(user);
|
||||||
|
// assertTrue(equal(user.getName(), newUser.getName()),
|
||||||
|
// String.format(OBJ_FIELD_UPDATABLE, USER, "name"));
|
||||||
|
assertTrue(equal(user.getFullName(), newUser.getFullName()),
|
||||||
|
String.format(OBJ_FIELD_UPDATABLE, USER, "fullName"));
|
||||||
|
assertTrue(equal(user.getEmailAddress(), newUser.getEmailAddress()),
|
||||||
|
String.format(OBJ_FIELD_UPDATABLE, USER, "emailAddress"));
|
||||||
|
assertTrue(equal(user.getTelephone(), newUser.getTelephone()),
|
||||||
|
String.format(OBJ_FIELD_UPDATABLE, USER, "telephone"));
|
||||||
|
assertTrue(equal(user.isEnabled(), newUser.isEnabled()),
|
||||||
|
String.format(OBJ_FIELD_UPDATABLE, USER, "isEnabled"));
|
||||||
|
assertTrue(equal(user.getIM(), newUser.getIM()),
|
||||||
|
String.format(OBJ_FIELD_UPDATABLE, USER, "im"));
|
||||||
|
assertTrue(equal(user.isAlertEnabled(), newUser.isAlertEnabled()),
|
||||||
|
String.format(OBJ_FIELD_UPDATABLE, USER, "isAlertEnabled"));
|
||||||
|
assertTrue(equal(user.getAlertEmailPrefix(), newUser.getAlertEmailPrefix()),
|
||||||
|
String.format(OBJ_FIELD_UPDATABLE, USER, "alertEmailPrefix"));
|
||||||
|
assertTrue(equal(user.getAlertEmail(), newUser.getAlertEmail()),
|
||||||
|
String.format(OBJ_FIELD_UPDATABLE, USER, "alertEmail"));
|
||||||
|
// assertTrue(equal(user.getRole(), newUser.getRole()),
|
||||||
|
// String.format(OBJ_FIELD_UPDATABLE, USER, "role"));
|
||||||
|
assertTrue(equal(user.getStoredVmQuota(), newUser.getStoredVmQuota()),
|
||||||
|
String.format(OBJ_FIELD_UPDATABLE, USER, "storedVmQuota"));
|
||||||
|
assertTrue(equal(user.getDeployedVmQuota(), newUser.getDeployedVmQuota()),
|
||||||
|
String.format(OBJ_FIELD_UPDATABLE, USER, "deployedVmQuota"));
|
||||||
|
|
||||||
|
// FIXME: assert password is changed with session client?
|
||||||
|
} finally {
|
||||||
|
userClient.updateUser(user.getHref(), oldUser);
|
||||||
|
user = userClient.getUser(user.getHref());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// POST /admin/user/{id}/action/unlock
|
// POST /admin/user/{id}/action/unlock
|
||||||
|
|
||||||
@Test(testName = "DELETE /admin/user/{id}",
|
@Test(testName = "DELETE /admin/user/{id}",
|
||||||
dependsOnMethods = { "testGetUser" } )
|
dependsOnMethods = { "testUpdateUser" } )
|
||||||
public void testDeleteUser() {
|
public void testDeleteUser() {
|
||||||
userClient.deleteUser(user.getHref());
|
userClient.deleteUser(user.getHref());
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<User xmlns="http://www.vmware.com/vcloud/v1.5" name="test" id="urn:vcloud:user:b37223f3-8792-477a-820f-334998f61cd6" type="application/vnd.vmware.admin.user+xml" href="https://vcloudbeta.bluelock.com/api/admin/user/5fc76423-0380-4a6d-9f52-dffb4ffaa46a" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd">
|
||||||
|
<Link rel="edit" type="application/vnd.vmware.admin.user+xml" href="https://vcloudbeta.bluelock.com/api/admin/user/b37223f3-8792-477a-820f-334998f61cd6"/>
|
||||||
|
<FullName>newtestFullName</FullName>
|
||||||
|
<EmailAddress>newtest@test.com</EmailAddress>
|
||||||
|
<Telephone>1-555-1234</Telephone>
|
||||||
|
<IsEnabled>true</IsEnabled>
|
||||||
|
<IsLocked>false</IsLocked>
|
||||||
|
<IM>newtestIM</IM>
|
||||||
|
<NameInSource>test</NameInSource>
|
||||||
|
<IsAlertEnabled>true</IsAlertEnabled>
|
||||||
|
<AlertEmailPrefix>newtestPrefix</AlertEmailPrefix>
|
||||||
|
<AlertEmail>newtestAlert@test.com</AlertEmail>
|
||||||
|
<IsExternal>false</IsExternal>
|
||||||
|
<IsDefaultCached>false</IsDefaultCached>
|
||||||
|
<IsGroupRole>false</IsGroupRole>
|
||||||
|
<StoredVmQuota>1</StoredVmQuota>
|
||||||
|
<DeployedVmQuota>1</DeployedVmQuota>
|
||||||
|
<Role type="application/vnd.vmware.admin.role+xml" name="vApp User" href="https://vcloudbeta.bluelock.com/api/admin/role/ff1e0c91-1288-3664-82b7-a6fa303af4d1"/>
|
||||||
|
<GroupReferences/>
|
||||||
|
</User>
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<User name="test" id="urn:vcloud:user:b37223f3-8792-477a-820f-334998f61cd6" type="application/vnd.vmware.admin.user+xml" href="https://vcloudbeta.bluelock.com/api/admin/user/b37223f3-8792-477a-820f-334998f61cd6" xmlns="http://www.vmware.com/vcloud/v1.5">
|
||||||
|
<Link rel="edit" type="application/vnd.vmware.admin.user+xml" href="https://vcloudbeta.bluelock.com/api/admin/user/b37223f3-8792-477a-820f-334998f61cd6"/>
|
||||||
|
<Link rel="remove" href="https://vcloudbeta.bluelock.com/api/admin/user/b37223f3-8792-477a-820f-334998f61cd6"/>
|
||||||
|
<FullName>newtestFullName</FullName>
|
||||||
|
<EmailAddress>newtest@test.com</EmailAddress>
|
||||||
|
<Telephone>1-555-1234</Telephone>
|
||||||
|
<IsEnabled>true</IsEnabled>
|
||||||
|
<IsLocked>false</IsLocked>
|
||||||
|
<IM>newtestIM</IM>
|
||||||
|
<NameInSource>test</NameInSource>
|
||||||
|
<IsAlertEnabled>true</IsAlertEnabled>
|
||||||
|
<AlertEmailPrefix>newtestPrefix</AlertEmailPrefix>
|
||||||
|
<AlertEmail>newtestAlert@test.com</AlertEmail>
|
||||||
|
<IsExternal>false</IsExternal>
|
||||||
|
<IsDefaultCached>false</IsDefaultCached>
|
||||||
|
<IsGroupRole>false</IsGroupRole>
|
||||||
|
<StoredVmQuota>1</StoredVmQuota>
|
||||||
|
<DeployedVmQuota>1</DeployedVmQuota>
|
||||||
|
<Role type="application/vnd.vmware.admin.role+xml" name="vApp User" href="https://vcloudbeta.bluelock.com/api/admin/role/ff1e0c91-1288-3664-82b7-a6fa303af4d1"/>
|
||||||
|
<Password>newPassword</Password>
|
||||||
|
<GroupReferences/>
|
||||||
|
</User>
|
Loading…
Reference in New Issue