Ori Liel has uploaded a new change for review.

Change subject: restapi: Move HostNic remove from collction to entity
......................................................................

restapi: Move HostNic remove from collction 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: If29201687008185109e05352c65bdf6e807b67e9
Signed-off-by: Ori Liel <[email protected]>
---
M 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicResource.java
M 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicsResource.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResource.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResourceTest.java
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResourceTest.java
6 files changed, 103 insertions(+), 90 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/57/42157/1

diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicResource.java
index 1e63bdf..15bc5a7 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicResource.java
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicResource.java
@@ -17,6 +17,7 @@
 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;
@@ -34,6 +35,9 @@
     @GET
     public HostNIC get();
 
+    @DELETE
+    public Response remove();
+
     @Path("{action: (attach|detach)}/{oid}")
     public ActionResource getActionSubresource(@PathParam("action") String 
action, @PathParam("oid") String oid);
 
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicsResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicsResource.java
index 1a4087f..3295212 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicsResource.java
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicsResource.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;
@@ -42,10 +41,6 @@
     @POST
     @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
     public Response add(HostNIC nic);
-
-    @DELETE
-    @Path("{id}")
-    public Response remove(@PathParam("id") String id);
 
     /**
      * Sub-resource locator method, returns individual HostNicResource on 
which the
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResource.java
index 8c6e2d4..d26ee3f 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResource.java
@@ -17,6 +17,7 @@
 import org.ovirt.engine.api.resource.LabelsResource;
 import org.ovirt.engine.api.resource.StatisticsResource;
 import org.ovirt.engine.core.common.action.AttachNetworkToVdsParameters;
+import org.ovirt.engine.core.common.action.RemoveBondParameters;
 import org.ovirt.engine.core.common.action.UpdateNetworkToVdsParameters;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import 
org.ovirt.engine.core.common.businessentities.network.NetworkBootProtocol;
@@ -203,4 +204,12 @@
     public LabelsResource getLabelsResource() {
         return inject(new BackendHostNicLabelsResource(asGuid(id), 
parent.getHostId()));
     }
+
+    @Override
+    public Response remove() {
+        get();
+        return performAction(VdcActionType.RemoveBond,
+                new RemoveBondParameters(asGuid(parent.hostId),
+                        parent.lookupInterface(id).getName()));
+    }
 }
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java
index 3846a4a..98c5393 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java
@@ -42,7 +42,7 @@
 
     static final String[] SUB_COLLECTIONS = { "statistics", "labels" };
 
-    private String hostId;
+    protected String hostId;
 
     public BackendHostNicsResource(String hostId) {
         super(HostNIC.class, VdsNetworkInterface.class, SUB_COLLECTIONS);
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResourceTest.java
index 827c05b..7029233 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResourceTest.java
@@ -25,6 +25,7 @@
 import org.ovirt.engine.api.model.Statistic;
 import org.ovirt.engine.api.restapi.util.RxTxCalculator;
 import org.ovirt.engine.core.common.action.AttachNetworkToVdsParameters;
+import org.ovirt.engine.core.common.action.RemoveBondParameters;
 import org.ovirt.engine.core.common.action.UpdateNetworkToVdsParameters;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.businessentities.VDS;
@@ -458,6 +459,83 @@
         verifyQuery(statisticsResource.getQuery(), entity);
     }
 
+    @Test
+    public void testRemove() throws Exception {
+        setGetVdsQueryExpectations(1);
+        setGetNetworksQueryExpectations(1);
+        setUpEntityQueryExpectations(2);
+
+        setUriInfo(setUpActionExpectations(VdcActionType.RemoveBond,
+                RemoveBondParameters.class,
+                new String[] { "VdsId", "BondName" },
+                new Object[] { PARENT_GUID, NAMES[1] },
+                true,
+                true));
+        verifyRemove(resource.remove());
+    }
+
+    @Test
+    public void testRemoveNonExistant() throws Exception {
+        setUpEntityQueryExpectations(VdcQueryType.GetVdsInterfacesByVdsId,
+                IdQueryParameters.class,
+                new String[] { "Id" },
+                new Object[] { PARENT_GUID },
+                new LinkedList<VdsNetworkInterface>());
+        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 {
+        setGetVdsQueryExpectations(1);
+        setGetNetworksQueryExpectations(1);
+        setUpEntityQueryExpectations(2);
+
+        setUriInfo(setUpActionExpectations(VdcActionType.RemoveBond,
+                RemoveBondParameters.class,
+                new String[] { "VdsId", "BondName" },
+                new Object[] { PARENT_GUID, NAMES[1] },
+                canDo,
+                success));
+        try {
+            resource.remove();
+            fail("expected WebApplicationException");
+        } catch (WebApplicationException wae) {
+            verifyFault(wae, detail);
+        }
+    }
+
+    @Test
+    public void testRemoveEntityNotFound() throws Exception {
+        setUpEntityQueryExpectations(VdcQueryType.GetVdsInterfacesByVdsId,
+                IdQueryParameters.class,
+                new String[] { "Id" },
+                new Object[] { PARENT_GUID },
+                new ArrayList<VdsNetworkInterface>());
+        control.replay();
+        try {
+            resource.remove();
+            fail("expected WebApplicationException");
+        } catch (WebApplicationException wae) {
+            verifyNotFoundException(wae);
+        }
+    }
+
     protected VdsNetworkInterface setUpStatisticalExpectations() throws 
Exception {
         VdsNetworkStatistics stats = 
control.createMock(VdsNetworkStatistics.class);
         VdsNetworkInterface entity = 
control.createMock(VdsNetworkInterface.class);
@@ -499,12 +577,18 @@
         assertEquals(GUIDS[0].toString(), 
adopted.getHostNic().getHost().getId());
     }
 
+    protected void setUpEntityQueryExpectations(int times) throws Exception {
+        while (times-- > 0) {
+            setUpEntityQueryExpectations(VdcQueryType.GetVdsInterfacesByVdsId,
+                    IdQueryParameters.class,
+                    new String[] { "Id" },
+                    new Object[] { PARENT_GUID },
+                    setUpInterfaces());
+        }
+    }
+
     protected void setUpEntityQueryExpectations() throws Exception {
-        setUpEntityQueryExpectations(VdcQueryType.GetVdsInterfacesByVdsId,
-                                     IdQueryParameters.class,
-                                     new String[] { "Id" },
-                                     new Object[] { PARENT_GUID },
-                                     setUpInterfaces());
+        setUpEntityQueryExpectations(1);
     }
 
     protected void verifyActionResponse(Response r) throws Exception {
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResourceTest.java
index 8b95cff..74587e1 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResourceTest.java
@@ -4,7 +4,6 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.LinkedList;
 import java.util.List;
 
 import javax.ws.rs.WebApplicationException;
@@ -23,7 +22,6 @@
 import org.ovirt.engine.api.model.Slaves;
 import org.ovirt.engine.api.resource.HostNicResource;
 import org.ovirt.engine.core.common.action.AddBondParameters;
-import org.ovirt.engine.core.common.action.RemoveBondParameters;
 import org.ovirt.engine.core.common.action.SetupNetworksParameters;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.businessentities.VDS;
@@ -173,64 +171,6 @@
     }
 
     @Test
-    public void testGetNotFound() throws Exception {
-        setUpEntityQueryExpectations(VdcQueryType.GetVdsInterfacesByVdsId,
-                                     IdQueryParameters.class,
-                                     new String[] { "Id" },
-                                     new Object[] { PARENT_GUID },
-                                     new ArrayList<VdsNetworkInterface>());
-        control.replay();
-        try {
-            collection.remove(MASTER_GUID.toString());
-            fail("expected WebApplicationException");
-        } catch (WebApplicationException wae) {
-            verifyNotFoundException(wae);
-        }
-    }
-
-    @Test
-    public void testRemove() throws Exception {
-        setGetVdsQueryExpectations(1);
-        setGetNetworksQueryExpectations(1);
-        setUpEntityQueryExpectations(2);
-
-        setUriInfo(setUpActionExpectations(VdcActionType.RemoveBond,
-                                           RemoveBondParameters.class,
-                                           new String[] { "VdsId", "BondName" 
},
-                                           new Object[] { PARENT_GUID, 
MASTER_NAME },
-                                           true,
-                                           true));
-        verifyRemove(collection.remove(MASTER_GUID.toString()));
-    }
-
-    @Test
-    public void testRemoveNonExistant() throws Exception{
-        setUpEntityQueryExpectations(VdcQueryType.GetVdsInterfacesByVdsId,
-                IdQueryParameters.class,
-                new String[] { "Id" },
-                new Object[] { PARENT_GUID },
-                new LinkedList<VdsNetworkInterface>());
-        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);
-    }
-
-    @Test
     public void testSetupNetworksNotSyncsNetwork() throws Exception {
         setUpNetworkQueryExpectations(1);
         setUpEntityQueryExpectations(1);
@@ -300,25 +240,6 @@
         assertNotNull(list.getActions().getLinks().get(0));
         assertEquals(list.getActions().getLinks().get(0).getHref(), 
SETUPNETWORKS_ACTION_URL);
         assertEquals(list.getActions().getLinks().get(0).getRel(), 
SETUPNETWORKS_ACTION_REL);
-    }
-
-    protected void doTestBadRemove(boolean canDo, boolean success, String 
detail) throws Exception {
-        setGetVdsQueryExpectations(1);
-        setGetNetworksQueryExpectations(1);
-        setUpEntityQueryExpectations(2);
-
-        setUriInfo(setUpActionExpectations(VdcActionType.RemoveBond,
-                                           RemoveBondParameters.class,
-                                           new String[] { "VdsId", "BondName" 
},
-                                           new Object[] { PARENT_GUID, 
MASTER_NAME },
-                                           canDo,
-                                           success));
-        try {
-            collection.remove(MASTER_GUID.toString());
-            fail("expected WebApplicationException");
-        } catch (WebApplicationException wae) {
-            verifyFault(wae, detail);
-        }
     }
 
     protected void setUpEntityQueryExpectations(int times) throws Exception {


-- 
To view, visit https://gerrit.ovirt.org/42157
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If29201687008185109e05352c65bdf6e807b67e9
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Ori Liel <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to