Juan Hernandez has uploaded a new change for review. Change subject: restapi: Move Disk Profile remove from collection to entity ......................................................................
restapi: Move Disk Profile 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: Ib304bf8c3d7d4f3d5c948aadc11b00b37c8aa78a Related: https://gerrit.ovirt.org/41783 Signed-off-by: Juan Hernandez <[email protected]> --- M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedDiskProfileResource.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedDiskProfilesResource.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/DiskProfileResource.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/DiskProfilesResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfileResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfilesResource.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfilesResourceTest.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendAssignedDiskProfileResourceTest.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendDiskProfileResourceTest.java 9 files changed, 199 insertions(+), 103 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/03/41803/1 diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedDiskProfileResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedDiskProfileResource.java index f0c64ca..ef39240 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedDiskProfileResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedDiskProfileResource.java @@ -1,13 +1,17 @@ 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.DiskProfile; @Produces({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML }) public interface AssignedDiskProfileResource { - @GET - public DiskProfile get(); + DiskProfile get(); + + @DELETE + Response remove(); } diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedDiskProfilesResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedDiskProfilesResource.java index 9992a00..4b5db62 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedDiskProfilesResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/AssignedDiskProfilesResource.java @@ -1,7 +1,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.POST; import javax.ws.rs.Path; @@ -14,18 +13,13 @@ @Produces({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML }) public interface AssignedDiskProfilesResource { - @GET - public DiskProfiles list(); + DiskProfiles list(); @POST @Consumes({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML }) - public Response add(DiskProfile diskProfile); - - @DELETE - @Path("{id}") - public Response remove(@PathParam("id") String id); + Response add(DiskProfile diskProfile); @Path("{id}") - public AssignedDiskProfileResource getAssignedDiskProfileSubResource(@PathParam("id") String id); + AssignedDiskProfileResource getAssignedDiskProfileSubResource(@PathParam("id") String id); } diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/DiskProfileResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/DiskProfileResource.java index bacaeb5..c95b883 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/DiskProfileResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/DiskProfileResource.java @@ -1,12 +1,16 @@ package org.ovirt.engine.api.resource; +import javax.ws.rs.DELETE; import javax.ws.rs.Path; import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; import org.ovirt.engine.api.model.DiskProfile; @Produces({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML }) public interface DiskProfileResource extends UpdatableResource<DiskProfile> { + @DELETE + Response remove(); @Path("permissions") public AssignedPermissionsResource getPermissionsResource(); diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/DiskProfilesResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/DiskProfilesResource.java index 9e75173..e03206b 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/DiskProfilesResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/DiskProfilesResource.java @@ -1,7 +1,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.POST; import javax.ws.rs.Path; @@ -15,18 +14,13 @@ @Path("/diskprofiles") @Produces({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML }) public interface DiskProfilesResource { - @GET - public DiskProfiles list(); + DiskProfiles list(); @POST @Consumes({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML }) - public Response add(DiskProfile diskProfile); - - @DELETE - @Path("{id}") - public Response remove(@PathParam("id") String id); + Response add(DiskProfile diskProfile); @Path("{id}") - public DiskProfileResource getDiskProfileSubResource(@PathParam("id") String id); + DiskProfileResource getDiskProfileSubResource(@PathParam("id") String id); } diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfileResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfileResource.java index 9801764..78d594a 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfileResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfileResource.java @@ -3,9 +3,13 @@ import org.ovirt.engine.api.model.BaseResource; import org.ovirt.engine.api.model.DataCenter; import org.ovirt.engine.api.model.DiskProfile; +import org.ovirt.engine.core.common.action.DiskProfileParameters; +import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.businessentities.qos.QosBase; import org.ovirt.engine.core.common.queries.IdQueryParameters; import org.ovirt.engine.core.common.queries.VdcQueryType; + +import javax.ws.rs.core.Response; public abstract class AbstractBackendDiskProfileResource extends AbstractBackendSubResource<DiskProfile, org.ovirt.engine.core.common.businessentities.profiles.DiskProfile> { @@ -40,4 +44,22 @@ } return super.addLinks(model, suggestedParent, subCollectionMembersToExclude); } + + private org.ovirt.engine.core.common.businessentities.profiles.DiskProfile getDiskProfile(String id) { + return getEntity( + org.ovirt.engine.core.common.businessentities.profiles.DiskProfile.class, + VdcQueryType.GetDiskProfileById, + new IdQueryParameters(asGuidOr404(id)), + "DiskProfile" + ); + } + + public Response remove() { + get(); + org.ovirt.engine.core.common.businessentities.profiles.DiskProfile diskProfile = getDiskProfile(id); + return performAction( + VdcActionType.RemoveDiskProfile, + new DiskProfileParameters(diskProfile, diskProfile.getId()) + ); + } } diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfilesResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfilesResource.java index 219fd4a..e042ca8 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfilesResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfilesResource.java @@ -79,21 +79,6 @@ protected abstract void validateParameters(DiskProfile diskProfile); @Override - protected Response performRemove(String id) { - org.ovirt.engine.core.common.businessentities.profiles.DiskProfile diskProfile = getDiskProfile(id); - return performAction(VdcActionType.RemoveDiskProfile, - new DiskProfileParameters(diskProfile, - diskProfile.getId())); - } - - protected org.ovirt.engine.core.common.businessentities.profiles.DiskProfile getDiskProfile(String id) { - return getEntity(org.ovirt.engine.core.common.businessentities.profiles.DiskProfile.class, - VdcQueryType.GetDiskProfileById, - new IdQueryParameters(asGuidOr404(id)), - "DiskProfiles"); - } - - @Override protected DiskProfile doPopulate(DiskProfile model, org.ovirt.engine.core.common.businessentities.profiles.DiskProfile entity) { return model; diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfilesResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfilesResourceTest.java index d1e0ed9..76f16cd 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfilesResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfilesResourceTest.java @@ -40,74 +40,6 @@ } @Test - public void testRemoveNotFound() throws Exception { - setUpEntityQueryExpectations(1, 0, true); - control.replay(); - try { - collection.remove(GUIDS[0].toString()); - fail("expected WebApplicationException"); - } catch (WebApplicationException wae) { - verifyNotFoundException(wae); - } - } - - @Test - public void testRemove() throws Exception { - setUpEntityQueryExpectations(2, 0, false); - setUriInfo(setUpActionExpectations(VdcActionType.RemoveDiskProfile, - DiskProfileParameters.class, - new String[] {}, - new Object[] {}, - true, - true)); - verifyRemove(collection.remove(GUIDS[0].toString())); - } - - @Test - public void testRemoveNonExistant() throws Exception { - setUpEntityQueryExpectations(VdcQueryType.GetDiskProfileById, - IdQueryParameters.class, - new String[] { "Id" }, - new Object[] { NON_EXISTANT_GUID }, - null); - control.replay(); - try { - collection.remove(NON_EXISTANT_GUID.toString()); - fail("expected WebApplicationException"); - } catch (WebApplicationException wae) { - assertNotNull(wae.getResponse()); - assertEquals(404, wae.getResponse().getStatus()); - } - } - - @Test - public void testRemoveCantDo() throws Exception { - doTestBadRemove(false, true, CANT_DO); - } - - @Test - public void testRemoveFailed() throws Exception { - doTestBadRemove(true, false, FAILURE); - } - - protected void doTestBadRemove(boolean canDo, boolean success, String detail) throws Exception { - setUpEntityQueryExpectations(2, 0, false); - - setUriInfo(setUpActionExpectations(VdcActionType.RemoveDiskProfile, - DiskProfileParameters.class, - new String[] {}, - new Object[] {}, - canDo, - success)); - try { - collection.remove(GUIDS[0].toString()); - fail("expected WebApplicationException"); - } catch (WebApplicationException wae) { - verifyFault(wae, detail); - } - } - - @Test public void testAddDiskProfile() throws Exception { setUriInfo(setUpBasicUriExpectations()); setUpStorageDomainQueryExpectations(); diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendAssignedDiskProfileResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendAssignedDiskProfileResourceTest.java index 030c86a..24cf335 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendAssignedDiskProfileResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendAssignedDiskProfileResourceTest.java @@ -9,6 +9,8 @@ import org.junit.Test; import org.ovirt.engine.api.model.DiskProfile; +import org.ovirt.engine.core.common.action.DiskProfileParameters; +import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.queries.IdQueryParameters; import org.ovirt.engine.core.common.queries.VdcQueryType; @@ -53,6 +55,86 @@ verifyModel(resource.get(), 0); } + + @Test + public void testRemoveNotFound() throws Exception { + setUpEntityQueryExpectations(1, 0, true); + control.replay(); + try { + resource.remove(); + fail("expected WebApplicationException"); + } catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testRemove() throws Exception { + setUpEntityQueryExpectations(2, 0, false); + setUriInfo( + setUpActionExpectations( + VdcActionType.RemoveDiskProfile, + DiskProfileParameters.class, + new String[] {}, + new Object[] {}, + true, + true + ) + ); + verifyRemove(resource.remove()); + } + + @Test + public void testRemoveNonExistant() throws Exception { + setUpEntityQueryExpectations( + VdcQueryType.GetDiskProfileById, + IdQueryParameters.class, + new String[] { "Id" }, + new Object[] { GUIDS[0] }, + null + ); + control.replay(); + try { + resource.remove(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + assertNotNull(wae.getResponse()); + assertEquals(404, wae.getResponse().getStatus()); + } + } + + @Test + public void testRemoveCantDo() throws Exception { + doTestBadRemove(false, true, CANT_DO); + } + + @Test + public void testRemoveFailed() throws Exception { + doTestBadRemove(true, false, FAILURE); + } + + protected void doTestBadRemove(boolean canDo, boolean success, String detail) throws Exception { + setUpEntityQueryExpectations(2, 0, false); + setUriInfo( + setUpActionExpectations( + VdcActionType.RemoveDiskProfile, + DiskProfileParameters.class, + new String[] {}, + new Object[] {}, + canDo, + success + ) + ); + try { + resource.remove(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyFault(wae, detail); + } + } + protected void setUpEntityQueryExpectations(int times, int index, boolean notFound) throws Exception { while (times-- > 0) { setUpEntityQueryExpectations(VdcQueryType.GetDiskProfileById, diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendDiskProfileResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendDiskProfileResourceTest.java index 1aa224a..c29479d 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendDiskProfileResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendDiskProfileResourceTest.java @@ -123,6 +123,85 @@ } } + @Test + public void testRemoveNotFound() throws Exception { + setUpEntityQueryExpectations(1, 0, true); + control.replay(); + try { + resource.remove(); + fail("expected WebApplicationException"); + } catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testRemove() throws Exception { + setUpEntityQueryExpectations(2, 0, false); + setUriInfo( + setUpActionExpectations( + VdcActionType.RemoveDiskProfile, + DiskProfileParameters.class, + new String[] {}, + new Object[] {}, + true, + true + ) + ); + verifyRemove(resource.remove()); + } + + @Test + public void testRemoveNonExistant() throws Exception { + setUpEntityQueryExpectations( + VdcQueryType.GetDiskProfileById, + IdQueryParameters.class, + new String[] { "Id" }, + new Object[] { GUIDS[0] }, + null + ); + control.replay(); + try { + resource.remove(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + assertNotNull(wae.getResponse()); + assertEquals(404, wae.getResponse().getStatus()); + } + } + + @Test + public void testRemoveCantDo() throws Exception { + doTestBadRemove(false, true, CANT_DO); + } + + @Test + public void testRemoveFailed() throws Exception { + doTestBadRemove(true, false, FAILURE); + } + + protected void doTestBadRemove(boolean canDo, boolean success, String detail) throws Exception { + setUpEntityQueryExpectations(2, 0, false); + setUriInfo( + setUpActionExpectations( + VdcActionType.RemoveDiskProfile, + DiskProfileParameters.class, + new String[] {}, + new Object[] {}, + canDo, + success + ) + ); + try { + resource.remove(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyFault(wae, detail); + } + } + protected void setUpEntityQueryExpectations(int times, int index, boolean notFound) throws Exception { while (times-- > 0) { setUpEntityQueryExpectations(VdcQueryType.GetDiskProfileById, -- To view, visit https://gerrit.ovirt.org/41803 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib304bf8c3d7d4f3d5c948aadc11b00b37c8aa78a Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Juan Hernandez <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
