Juan Hernandez has uploaded a new change for review. Change subject: restapi: Move Assigned Permission remove from collection to entity ......................................................................
restapi: Move Assigned Permission remove from collection to entity This patch moves the method that implements the DELETE operation from the collection interface to the entity interface. This is needed to avoid issues with newer versions of Resteasy. Change-Id: I8fcbc7bf7534f19312d5a3febe82406f214d1e22 Related: https://gerrit.ovirt.org/41783 Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com> --- M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedPermissionsResource.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/PermissionResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendAssignedPermissionsResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendPermissionResource.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendAssignedPermissionsResourceTest.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendPermissionResourceTest.java 6 files changed, 126 insertions(+), 103 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/74/41974/1 diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedPermissionsResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedPermissionsResource.java index bf1bc02..e0de057 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedPermissionsResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedPermissionsResource.java @@ -17,7 +17,6 @@ package org.ovirt.engine.api.resource; import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -33,17 +32,12 @@ */ @Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) public interface AssignedPermissionsResource { - @GET - public Permissions list(); + Permissions list(); @POST @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) - public Response add(Permission permission); - - @DELETE - @Path("{id}") - public Response remove(@PathParam("id") String id); + Response add(Permission permission); /** * Sub-resource locator method, returns individual PermissionResource on which the @@ -53,5 +47,5 @@ * @return matching subresource if found */ @Path("{id}") - public PermissionResource getPermissionSubResource(@PathParam("id") String id); + PermissionResource getPermissionSubResource(@PathParam("id") String id); } diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/PermissionResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/PermissionResource.java index 1772449..0cf879e 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/PermissionResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/PermissionResource.java @@ -16,14 +16,18 @@ package org.ovirt.engine.api.resource; +import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; import org.ovirt.engine.api.model.Permission; @Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) public interface PermissionResource { - @GET - public Permission get(); + Permission get(); + + @DELETE + Response remove(); } diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendAssignedPermissionsResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendAssignedPermissionsResource.java index 98df5d5..65ca912 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendAssignedPermissionsResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendAssignedPermissionsResource.java @@ -112,11 +112,6 @@ } @Override - public Response performRemove(String id) { - return performAction(VdcActionType.RemovePermission, new PermissionsOperationsParameters(getPermissions(id))); - } - - @Override @SingleEntityResource public PermissionResource getPermissionSubResource(String id) { return inject(new BackendPermissionResource(id, this, suggestedParentType)); @@ -278,13 +273,6 @@ protected boolean isGroupSubCollection() { return Group.class.equals(suggestedParentType); - } - - protected org.ovirt.engine.core.common.businessentities.Permission getPermissions(String id) { - return getEntity(org.ovirt.engine.core.common.businessentities.Permission.class, - VdcQueryType.GetPermissionById, - new IdQueryParameters(asGuid(id)), - id); } @Override diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendPermissionResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendPermissionResource.java index 7de0096..d6c9203 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendPermissionResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendPermissionResource.java @@ -6,10 +6,14 @@ import org.ovirt.engine.api.model.Group; import org.ovirt.engine.api.model.Permission; import org.ovirt.engine.api.resource.PermissionResource; +import org.ovirt.engine.core.common.action.PermissionsOperationsParameters; +import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.businessentities.aaa.DbUser; import org.ovirt.engine.core.common.queries.IdQueryParameters; import org.ovirt.engine.core.common.queries.VdcQueryType; import org.ovirt.engine.core.compat.Guid; + +import javax.ws.rs.core.Response; public class BackendPermissionResource extends AbstractBackendSubResource<Permission, org.ovirt.engine.core.common.businessentities.Permission> @@ -53,4 +57,19 @@ protected Permission doPopulate(Permission model, org.ovirt.engine.core.common.businessentities.Permission entity) { return model; } + + @Override + public Response remove() { + get(); + return performAction(VdcActionType.RemovePermission, new PermissionsOperationsParameters(getPermissions())); + } + + private org.ovirt.engine.core.common.businessentities.Permission getPermissions() { + return getEntity( + org.ovirt.engine.core.common.businessentities.Permission.class, + VdcQueryType.GetPermissionById, + new IdQueryParameters(guid), + guid.toString() + ); + } } diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendAssignedPermissionsResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendAssignedPermissionsResourceTest.java index ccefecc..ede02fd 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendAssignedPermissionsResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendAssignedPermissionsResourceTest.java @@ -3,7 +3,6 @@ import java.util.ArrayList; import java.util.List; -import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; import org.junit.Ignore; @@ -58,75 +57,6 @@ @Ignore @Override public void testQuery() throws Exception { - } - - @Test - public void testRemove() throws Exception { - setUpGetEntityExpectations(2, GUIDS[0], getEntity(0)); - setUpEntityQueryExpectations(VdcQueryType.GetAllDbUsers, - VdcQueryParametersBase.class, - new String[] {}, - new Object[] {}, - getUsers()); - - setUriInfo(setUpActionExpectations(VdcActionType.RemovePermission, - PermissionsOperationsParameters.class, - new String[] { "Permission.Id" }, - new Object[] { GUIDS[0] }, - true, - true)); - verifyRemove(collection.remove(GUIDS[0].toString())); - } - - @Test - public void testRemoveCantDo() throws Exception { - setUpEntityQueryExpectations(VdcQueryType.GetAllDbUsers, - VdcQueryParametersBase.class, - new String[] {}, - new Object[] {}, - getUsers()); - - doTestBadRemove(false, true, CANT_DO); - } - - @Test - public void testRemoveFailed() throws Exception { - setUpEntityQueryExpectations(VdcQueryType.GetAllDbUsers, - VdcQueryParametersBase.class, - new String[] {}, - new Object[] {}, - getUsers()); - - doTestBadRemove(true, false, FAILURE); - } - - @Test - public void testRemoveNonExistant() throws Exception{ - setUpGetEntityExpectations(1, NON_EXISTANT_GUID, null); - control.replay(); - try { - collection.remove(NON_EXISTANT_GUID.toString()); - fail("expected WebApplicationException"); - } catch (WebApplicationException wae) { - assertNotNull(wae.getResponse()); - assertEquals(wae.getResponse().getStatus(), 404); - } - } - - protected void doTestBadRemove(boolean canDo, boolean success, String detail) throws Exception { - setUpGetEntityExpectations(2, GUIDS[0], getEntity(0)); - setUriInfo(setUpActionExpectations(VdcActionType.RemovePermission, - PermissionsOperationsParameters.class, - new String[] { "Permission.Id" }, - new Object[] { GUIDS[0] }, - canDo, - success)); - try { - collection.remove(GUIDS[0].toString()); - fail("expected WebApplicationException"); - } catch (WebApplicationException wae) { - verifyFault(wae, detail); - } } @Test diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendPermissionResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendPermissionResourceTest.java index fad92a5..fdd490a 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendPermissionResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendPermissionResourceTest.java @@ -10,6 +10,8 @@ import org.ovirt.engine.api.model.Permission; import org.ovirt.engine.api.model.User; import org.ovirt.engine.core.common.VdcObjectType; +import org.ovirt.engine.core.common.action.PermissionsOperationsParameters; +import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.businessentities.aaa.DbUser; import org.ovirt.engine.core.common.queries.GetPermissionsForObjectParameters; import org.ovirt.engine.core.common.queries.IdQueryParameters; @@ -53,7 +55,7 @@ @Test public void testGetNotFound() throws Exception { setUriInfo(setUpBasicUriExpectations()); - setUpGetEntityExpectations(true); + setUpGetEntityExpectations(1, true); control.replay(); try { resource.get(); @@ -73,22 +75,108 @@ new Object[] { true, false }, getUsers()); - setUpGetEntityExpectations(); + setUpGetEntityExpectations(1); control.replay(); verifyModel(resource.get(), 0); } - protected void setUpGetEntityExpectations() throws Exception { - setUpGetEntityExpectations(false); + @Test + public void testRemove() throws Exception { + setUpGetEntityExpectations(2); + setUpEntityQueryExpectations( + VdcQueryType.GetAllDbUsers, + VdcQueryParametersBase.class, + new String[] { "Refresh", "Filtered" }, + new Object[] { true, false }, + getUsers() + ); + setUriInfo( + setUpActionExpectations( + VdcActionType.RemovePermission, + PermissionsOperationsParameters.class, + new String[] { "Permission.Id" }, + new Object[] { GUIDS[0] }, + true, + true + ) + ); + verifyRemove(resource.remove()); } - protected void setUpGetEntityExpectations(boolean notFound) throws Exception { - setUpGetEntityExpectations(VdcQueryType.GetPermissionById, - IdQueryParameters.class, - new String[] { "Id" }, - new Object[] { GUIDS[0] }, - notFound ? null : getEntity(0)); + @Test + public void testRemoveCantDo() throws Exception { + setUpEntityQueryExpectations( + VdcQueryType.GetAllDbUsers, + VdcQueryParametersBase.class, + new String[] {}, + new Object[] {}, + getUsers() + ); + doTestBadRemove(false, true, CANT_DO); + } + + @Test + public void testRemoveFailed() throws Exception { + setUpEntityQueryExpectations( + VdcQueryType.GetAllDbUsers, + VdcQueryParametersBase.class, + new String[] {}, + new Object[] {}, + getUsers() + ); + doTestBadRemove(true, false, FAILURE); + } + + @Test + public void testRemoveNonExistant() throws Exception{ + setUpGetEntityExpectations(1, true); + control.replay(); + try { + resource.remove(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + assertNotNull(wae.getResponse()); + assertEquals(wae.getResponse().getStatus(), 404); + } + } + + protected void doTestBadRemove(boolean canDo, boolean success, String detail) throws Exception { + setUpGetEntityExpectations(2); + setUriInfo( + setUpActionExpectations( + VdcActionType.RemovePermission, + PermissionsOperationsParameters.class, + new String[] { "Permission.Id" }, + new Object[] { GUIDS[0] }, + canDo, + success + ) + ); + try { + resource.remove(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyFault(wae, detail); + } + } + + protected void setUpGetEntityExpectations(int times) throws Exception { + setUpGetEntityExpectations(times, false); + } + + protected void setUpGetEntityExpectations(int times, boolean notFound) throws Exception { + for (int i = 0; i < times; i++) { + setUpGetEntityExpectations( + VdcQueryType.GetPermissionById, + IdQueryParameters.class, + new String[]{"Id"}, + new Object[]{GUIDS[0]}, + notFound ? null : getEntity(0) + ); + } } @Override -- To view, visit https://gerrit.ovirt.org/41974 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8fcbc7bf7534f19312d5a3febe82406f214d1e22 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches