Ori Liel has uploaded a new change for review. Change subject: restapi: Move MacPool remove from collection to entity ......................................................................
restapi: Move MacPool 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: I4ec4c4bd2a6abd3c2b1f05b7c5dad1443ef8779e Signed-off-by: Ori Liel <ol...@redhat.com> --- M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/MacPoolResource.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/MacPoolsResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolsResource.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolResourceTest.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolsResourceTest.java 6 files changed, 95 insertions(+), 88 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/26/41826/1 diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/MacPoolResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/MacPoolResource.java index 94cbaaf..d2667e4 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/MacPoolResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/MacPoolResource.java @@ -1,9 +1,15 @@ package org.ovirt.engine.api.resource; +import javax.ws.rs.DELETE; import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; import org.ovirt.engine.api.model.MacPool; @Produces({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML }) public interface MacPoolResource extends UpdatableResource<MacPool> { + + @DELETE + public Response remove(); + } diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/MacPoolsResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/MacPoolsResource.java index bd10245..c2a9b0e 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/MacPoolsResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/MacPoolsResource.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; @@ -22,10 +21,6 @@ @POST @Consumes({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML }) public Response add(MacPool macPool); - - @DELETE - @Path("{id}") - public Response remove(@PathParam("id") String id); @Path("{id}") public MacPoolResource getMacPoolSubResource(@PathParam("id") String id); diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolResource.java index dea0a34..e62efd8 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolResource.java @@ -1,8 +1,12 @@ package org.ovirt.engine.api.restapi.resource; +import javax.ws.rs.DELETE; +import javax.ws.rs.core.Response; + import org.ovirt.engine.api.model.MacPool; import org.ovirt.engine.api.resource.MacPoolResource; import org.ovirt.engine.core.common.action.MacPoolParameters; +import org.ovirt.engine.core.common.action.RemoveMacPoolByIdParameters; import org.ovirt.engine.core.common.action.VdcActionParametersBase; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.queries.IdQueryParameters; @@ -41,4 +45,11 @@ return new MacPoolParameters(macPool); } } + + @Override + @DELETE + public Response remove() { + get(); + return performAction(VdcActionType.RemoveMacPool, new RemoveMacPoolByIdParameters(asGuid(id))); + } } diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolsResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolsResource.java index 3b9bb2c..4ad1363 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolsResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolsResource.java @@ -9,7 +9,6 @@ import org.ovirt.engine.api.resource.MacPoolResource; import org.ovirt.engine.api.resource.MacPoolsResource; import org.ovirt.engine.core.common.action.MacPoolParameters; -import org.ovirt.engine.core.common.action.RemoveMacPoolByIdParameters; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.queries.IdQueryParameters; import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; @@ -22,11 +21,6 @@ public BackendMacPoolsResource() { super(MacPool.class, org.ovirt.engine.core.common.businessentities.MacPool.class); - } - - @Override - protected Response performRemove(String id) { - return performAction(VdcActionType.RemoveMacPool, new RemoveMacPoolByIdParameters(asGuid(id))); } @Override diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolResourceTest.java index 9cac78a..c48f96b 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolResourceTest.java @@ -7,6 +7,7 @@ import org.junit.Test; import org.ovirt.engine.api.model.MacPool; import org.ovirt.engine.core.common.action.MacPoolParameters; +import org.ovirt.engine.core.common.action.RemoveMacPoolByIdParameters; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.queries.IdQueryParameters; import org.ovirt.engine.core.common.queries.VdcQueryType; @@ -126,6 +127,75 @@ } } + @Test + public void testRemove() throws Exception { + setUpEntityQueryExpectations(false); + setUriInfo(setUpActionExpectations(VdcActionType.RemoveMacPool, + RemoveMacPoolByIdParameters.class, + new String[] { "MacPoolId" }, + new Object[] { MAC_POOL_ID }, + true, + true)); + verifyRemove(resource.remove()); + } + + @Test + public void testRemoveNotFound() throws Exception { + setUpEntityQueryExpectations(true); + control.replay(); + try { + resource.remove(); + fail("expected WebApplicationException"); + } catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testRemoveNonExistant() throws Exception { + setUpEntityQueryExpectations(VdcQueryType.GetMacPoolById, + IdQueryParameters.class, + new String[] { "Id" }, + new Object[] { NON_EXISTANT_GUID }, + null); + control.replay(); + try { + resource.guid = NON_EXISTANT_GUID; + 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(false); + + setUriInfo(setUpActionExpectations(VdcActionType.RemoveMacPool, + RemoveMacPoolByIdParameters.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.GetMacPoolById, @@ -157,4 +227,12 @@ expect(entity.getDescription()).andReturn(DESCRIPTIONS[index]).anyTimes(); return entity; } + + protected void setUpEntityQueryExpectations(boolean notFound) throws Exception { + setUpEntityQueryExpectations(VdcQueryType.GetMacPoolById, + IdQueryParameters.class, + new String[] { "Id" }, + new Object[] { GUIDS[0] }, + notFound ? null : getEntity(0)); + } } diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolsResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolsResourceTest.java index 9517ef0..55c70a9 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolsResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendMacPoolsResourceTest.java @@ -16,7 +16,6 @@ import org.ovirt.engine.api.model.Fault; import org.ovirt.engine.api.model.MacPool; import org.ovirt.engine.core.common.action.MacPoolParameters; -import org.ovirt.engine.core.common.action.RemoveMacPoolByIdParameters; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.queries.IdQueryParameters; import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; @@ -40,74 +39,6 @@ @Override protected List<MacPool> getCollection() { return collection.list().getMacPools(); - } - - @Test - public void testRemoveNotFound() throws Exception { - setUpEntityQueryExpectations(true); - control.replay(); - try { - collection.remove(GUIDS[0].toString()); - fail("expected WebApplicationException"); - } catch (WebApplicationException wae) { - verifyNotFoundException(wae); - } - } - - @Test - public void testRemove() throws Exception { - setUpEntityQueryExpectations(false); - setUriInfo(setUpActionExpectations(VdcActionType.RemoveMacPool, - RemoveMacPoolByIdParameters.class, - new String[] { "MacPoolId" }, - new Object[] { MAC_POOL_ID }, - true, - true)); - verifyRemove(collection.remove(GUIDS[0].toString())); - } - - @Test - public void testRemoveNonExistant() throws Exception { - setUpEntityQueryExpectations(VdcQueryType.GetMacPoolById, - 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(false); - - setUriInfo(setUpActionExpectations(VdcActionType.RemoveMacPool, - RemoveMacPoolByIdParameters.class, - new String[] {}, - new Object[] {}, - canDo, - success)); - try { - collection.remove(GUIDS[0].toString()); - fail("expected WebApplicationException"); - } catch (WebApplicationException wae) { - verifyFault(wae, detail); - } } @Test @@ -277,14 +208,6 @@ } expect(backend.runQuery(eq(listQueryType), anyObject(listQueryParamsClass))).andReturn( queryResult); - } - - protected void setUpEntityQueryExpectations(boolean notFound) throws Exception { - setUpEntityQueryExpectations(VdcQueryType.GetMacPoolById, - IdQueryParameters.class, - new String[] { "Id" }, - new Object[] { GUIDS[0] }, - notFound ? null : getEntity(0)); } static MacPool getModel(int index) { -- To view, visit https://gerrit.ovirt.org/41826 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4ec4c4bd2a6abd3c2b1f05b7c5dad1443ef8779e Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Ori Liel <ol...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches