mirror of https://github.com/apache/jclouds.git
updateGroup with tests
This commit is contained in:
parent
7b635ddf77
commit
288e2b23d0
|
@ -109,6 +109,24 @@ public class Group extends EntityType<Group> {
|
|||
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()
|
||||
|
|
|
@ -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<Group> getGroup(@EndpointParam URI groupUri);
|
||||
|
||||
/**
|
||||
* @see GroupClient#deleteGroup(URI)
|
||||
*/
|
||||
@DELETE
|
||||
@Consumes
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||
ListenableFuture<Void> deleteGroup(@EndpointParam URI groupRef);
|
||||
@GET
|
||||
@Consumes
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||
ListenableFuture<Group> getGroup(@EndpointParam URI groupUri);
|
||||
|
||||
/**
|
||||
* @see GroupClient#updateGroup(URI, Group)
|
||||
*/
|
||||
@PUT
|
||||
@Consumes(VCloudDirectorMediaType.GROUP)
|
||||
@Produces(VCloudDirectorMediaType.GROUP)
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||
ListenableFuture<Group> updateCatalog(@EndpointParam URI groupRef,
|
||||
@BinderParam(BindToXMLPayload.class) Group group);
|
||||
|
||||
/**
|
||||
* @see GroupClient#deleteGroup(URI)
|
||||
*/
|
||||
@DELETE
|
||||
@Consumes
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||
ListenableFuture<Void> deleteGroup(@EndpointParam URI groupRef);
|
||||
}
|
||||
|
|
|
@ -44,6 +44,16 @@ public interface GroupClient {
|
|||
* @return a group
|
||||
*/
|
||||
Group getGroup(URI groupUri);
|
||||
/**
|
||||
* Modifies a group.
|
||||
*
|
||||
* <pre>
|
||||
* PUT /admin/group/{id}
|
||||
* </pre>
|
||||
*
|
||||
* @return the updated group
|
||||
*/
|
||||
Group updateGroup(URI groupRef, Group group);
|
||||
|
||||
/**
|
||||
* Deletes a group.
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue