From 288e2b23d01b163255c524eedbad6bdb5bbd565e Mon Sep 17 00:00:00 2001 From: danikov Date: Thu, 8 Mar 2012 09:14:26 +0000 Subject: [PATCH] updateGroup with tests --- .../vcloud/director/v1_5/domain/Group.java | 18 +++++ .../v1_5/features/GroupAsyncClient.java | 65 ++++++++++++------- .../director/v1_5/features/GroupClient.java | 10 +++ .../v1_5/features/GroupClientExpectTest.java | 21 ++++++ .../v1_5/features/GroupClientLiveTest.java | 42 +++++++++++- .../src/test/resources/group/updateGroup.xml | 0 .../resources/group/updateGroupSource.xml | 0 7 files changed, 132 insertions(+), 24 deletions(-) create mode 100644 labs/vcloud-director/src/test/resources/group/updateGroup.xml create mode 100644 labs/vcloud-director/src/test/resources/group/updateGroupSource.xml diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Group.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Group.java index a340f47257..5c7887e04d 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Group.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Group.java @@ -109,6 +109,24 @@ public class Group extends EntityType { return new Group(href, type, links, description, tasksInProgress, id, name, nameInSource, usersList, role); } + + /** + * @see EntityType#getName() + */ + @Override + public Builder name(String name) { + super.name(name); + return this; + } + + /** + * @see EntityType#getDescription() + */ + @Override + public Builder description(String idname) { + super.description(name); + return this; + } /** * @see EntityType#getId() diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/GroupAsyncClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/GroupAsyncClient.java index 4ede84e1d4..76e13dda4b 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/GroupAsyncClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/GroupAsyncClient.java @@ -24,38 +24,59 @@ import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; +import org.jclouds.rest.annotations.EndpointParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.JAXBResponseParser; +import javax.ws.rs.PUT; +import javax.ws.rs.Produces; + +import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.vcloud.director.v1_5.domain.Group; +import org.jclouds.rest.binders.BindToXMLPayload; +import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; +import org.jclouds.vcloud.director.v1_5.domain.Group; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest; import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx; import com.google.common.util.concurrent.ListenableFuture; +/** + * @see GroupClient + * @author danikov + */ +@RequestFilters(AddVCloudAuthorizationToRequest.class) +public interface GroupAsyncClient { + /** - * @see GroupClient - * @author danikov + * @see GroupClient#getGroup(URI) */ - @RequestFilters(AddVCloudAuthorizationToRequest.class) - public interface GroupAsyncClient { - - /** - * @see GroupClient#getGroup(URI) - */ - @GET - @Consumes - @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture getGroup(@EndpointParam URI groupUri); - - /** - * @see GroupClient#deleteGroup(URI) - */ - @DELETE - @Consumes - @JAXBResponseParser - @ExceptionParser(ThrowVCloudErrorOn4xx.class) - ListenableFuture deleteGroup(@EndpointParam URI groupRef); + @GET + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture getGroup(@EndpointParam URI groupUri); + + /** + * @see GroupClient#updateGroup(URI, Group) + */ + @PUT + @Consumes(VCloudDirectorMediaType.GROUP) + @Produces(VCloudDirectorMediaType.GROUP) + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture updateCatalog(@EndpointParam URI groupRef, + @BinderParam(BindToXMLPayload.class) Group group); + + /** + * @see GroupClient#deleteGroup(URI) + */ + @DELETE + @Consumes + @JAXBResponseParser + @ExceptionParser(ThrowVCloudErrorOn4xx.class) + ListenableFuture deleteGroup(@EndpointParam URI groupRef); } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/GroupClient.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/GroupClient.java index 877328c711..9d0edfb9f9 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/GroupClient.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/features/GroupClient.java @@ -44,6 +44,16 @@ public interface GroupClient { * @return a group */ Group getGroup(URI groupUri); + /** + * Modifies a group. + * + *
+    * PUT /admin/group/{id}
+    * 
+ * + * @return the updated group + */ + Group updateGroup(URI groupRef, Group group); /** * Deletes a group. diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/GroupClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/GroupClientExpectTest.java index 9877477f26..c5e5e95464 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/GroupClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/GroupClientExpectTest.java @@ -65,6 +65,27 @@ public class GroupClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .build(); } + @Test(enabled = false) + public void testUpdateGroup() { + VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, + new VcloudHttpRequestPrimer() + .apiCommand("PUT", "/admin/group/???") + .xmlFilePayload("/group/updateGroupSource.xml", VCloudDirectorMediaType.GROUP) + .acceptMedia(VCloudDirectorMediaType.GROUP) + .httpRequestBuilder().build(), + new VcloudHttpResponsePrimer() + .xmlFilePayload("/group/updateGroup.xml", VCloudDirectorMediaType.GROUP) + .httpResponseBuilder().build()); + + Group expected = updateGroup(); + + assertEquals(client.getGroupClient().updateGroup(groupRef.getURI(), expected), expected); + } + + public static Group updateGroup() { + return null; // TODO chain onto group() then toBuilder() and modify? + } + @Test public void testDeleteGroup() { VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/GroupClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/GroupClientLiveTest.java index 0b8b2c2192..6a618fc4d9 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/GroupClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/GroupClientLiveTest.java @@ -25,6 +25,10 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.O import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; import static org.testng.Assert.fail; +import static com.google.common.base.Objects.equal; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_UPDATABLE; +import static org.testng.Assert.assertTrue; + import java.net.URI; @@ -32,6 +36,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Checks; import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; import org.jclouds.vcloud.director.v1_5.domain.Error; import org.jclouds.vcloud.director.v1_5.domain.Group; +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.ReferenceType; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest; @@ -39,11 +44,11 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; /** - * Tests live behavior of {@link AdminCatalogClient}. + * Tests live behavior of {@link AdminGroupClient}. * * @author danikov */ -@Test(groups = { "live", "admin", "group" }, singleThreaded = true, testName = "CatalogClientLiveTest") +@Test(groups = { "live", "admin", "group" }, singleThreaded = true, testName = "GroupClientLiveTest") public class GroupClientLiveTest extends BaseVCloudDirectorClientLiveTest { public static final String GROUP = "admin group"; @@ -76,6 +81,39 @@ public class GroupClientLiveTest extends BaseVCloudDirectorClientLiveTest { Checks.checkGroup(group); } + @Test(testName = "PUT /admin/group/{id}") // TODO: depends on? + public void updateGroup() { + String oldName = group.getName(); + String newName = "new "+oldName; + String oldDescription = group.getDescription(); + String newDescription = "new "+oldDescription; + //TODO: check other modifiables + + try { + group = group.toBuilder() + .name(newName) + .description(newDescription) + .build(); + + group = groupClient.updateGroup(group.getURI(), group); + + assertTrue(equal(group.getName(), newName), String.format(OBJ_FIELD_UPDATABLE, GROUP, "name")); + assertTrue(equal(group.getDescription(), newDescription), + String.format(OBJ_FIELD_UPDATABLE, GROUP, "description")); + + //TODO negative tests? + + Checks.checkGroup(group); + } finally { + group = group.toBuilder() + .name(oldName) + .description(oldDescription) + .build(); + + group = groupClient.updateGroup(group.getURI(), group); + } + } + @Test(testName = "DELETE /admin/group/{id}", enabled = false ) public void testDeleteCatalog() { groupClient.deleteGroup(groupRef.getURI()); diff --git a/labs/vcloud-director/src/test/resources/group/updateGroup.xml b/labs/vcloud-director/src/test/resources/group/updateGroup.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/labs/vcloud-director/src/test/resources/group/updateGroupSource.xml b/labs/vcloud-director/src/test/resources/group/updateGroupSource.xml new file mode 100644 index 0000000000..e69de29bb2