Juan Hernandez has uploaded a new change for review.

Change subject: restapi: Move Network Label remove from collection to entity
......................................................................

restapi: Move Network Label 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: I8d31813da3e6a061d4c70baecbb1801f82382e7e
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/LabelResource.java
M 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/LabelsResource.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelResource.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelsResource.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelResource.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelsResource.java
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelResourceTest.java
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelsResourceTest.java
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelResourceTest.java
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelsResourceTest.java
10 files changed, 230 insertions(+), 196 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/55/41855/1

diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/LabelResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/LabelResource.java
index e09fa2d..777ee0f 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/LabelResource.java
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/LabelResource.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.Label;
 
 @Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
 public interface LabelResource {
-
     @GET
-    public Label get();
+    Label get();
+
+    @DELETE
+    Response remove();
 }
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/LabelsResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/LabelsResource.java
index af59d6a..98cb05d 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/LabelsResource.java
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/LabelsResource.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.POST;
 import javax.ws.rs.Path;
@@ -30,18 +29,13 @@
 
 @Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
 public interface LabelsResource {
-
     @GET
-    public Labels list();
+    Labels list();
 
     @POST
     @Consumes({ ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML })
-    public Response add(Label label);
-
-    @DELETE
-    @Path("{id}")
-    public Response remove(@PathParam("id") String id);
+    Response add(Label label);
 
     @Path("{id}")
-    public LabelResource getLabelSubResource(@PathParam("id") String id);
+    LabelResource getLabelSubResource(@PathParam("id") String id);
 }
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelResource.java
index 48b3abc..347248e 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelResource.java
@@ -3,7 +3,11 @@
 import org.ovirt.engine.api.model.Label;
 import org.ovirt.engine.api.model.Labels;
 import org.ovirt.engine.api.resource.LabelResource;
+import org.ovirt.engine.core.common.action.LabelNicParameters;
+import org.ovirt.engine.core.common.action.VdcActionType;
 import 
org.ovirt.engine.core.common.businessentities.network.pseudo.NetworkLabel;
+
+import javax.ws.rs.core.Response;
 
 public class BackendHostNicLabelResource extends 
AbstractBackendSubResource<Label, NetworkLabel> implements LabelResource {
 
@@ -39,4 +43,10 @@
     protected Label doPopulate(Label model, NetworkLabel entity) {
         return model;
     }
+
+    @Override
+    public Response remove() {
+        get();
+        return performAction(VdcActionType.UnlabelNic, new 
LabelNicParameters(parent.getHostNicId(), id));
+    }
 }
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelsResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelsResource.java
index a21360d..ebf0201 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelsResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelsResource.java
@@ -66,11 +66,6 @@
     }
 
     @Override
-    protected Response performRemove(String id) {
-        return performAction(VdcActionType.UnlabelNic, new 
LabelNicParameters(nicId, id));
-    }
-
-    @Override
     protected Label doPopulate(Label model, NetworkLabel entity) {
         return model;
     }
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelResource.java
index cee5ccc..26e0a2c 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelResource.java
@@ -4,7 +4,11 @@
 import org.ovirt.engine.api.model.Labels;
 import org.ovirt.engine.api.model.Network;
 import org.ovirt.engine.api.resource.LabelResource;
+import org.ovirt.engine.core.common.action.UnlabelNetworkParameters;
+import org.ovirt.engine.core.common.action.VdcActionType;
 import 
org.ovirt.engine.core.common.businessentities.network.pseudo.NetworkLabel;
+
+import javax.ws.rs.core.Response;
 
 public class BackendNetworkLabelResource extends 
AbstractBackendSubResource<Label, NetworkLabel> implements LabelResource {
 
@@ -40,4 +44,10 @@
     protected Label doPopulate(Label model, NetworkLabel entity) {
         return model;
     }
+
+    @Override
+    public Response remove() {
+        get();
+        return performAction(VdcActionType.UnlabelNetwork, new 
UnlabelNetworkParameters(parent.getNetworkId()));
+    }
 }
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelsResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelsResource.java
index 1e02002..d30d8fc 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelsResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelsResource.java
@@ -11,7 +11,6 @@
 import org.ovirt.engine.api.resource.LabelResource;
 import org.ovirt.engine.api.resource.LabelsResource;
 import org.ovirt.engine.core.common.action.LabelNetworkParameters;
-import org.ovirt.engine.core.common.action.UnlabelNetworkParameters;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import 
org.ovirt.engine.core.common.businessentities.network.pseudo.NetworkLabel;
 import org.ovirt.engine.core.common.queries.IdQueryParameters;
@@ -60,11 +59,6 @@
     @Override
     public LabelResource getLabelSubResource(String id) {
         return inject(new BackendNetworkLabelResource(id, this));
-    }
-
-    @Override
-    protected Response performRemove(String id) {
-        return performAction(VdcActionType.UnlabelNetwork, new 
UnlabelNetworkParameters(networkId));
     }
 
     @Override
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelResourceTest.java
index 5b8a84b..5a76541 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelResourceTest.java
@@ -2,26 +2,35 @@
 
 import static org.easymock.EasyMock.expect;
 
-import java.util.Arrays;
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.List;
 
 import javax.ws.rs.WebApplicationException;
 
 import org.junit.Test;
 import org.ovirt.engine.api.model.Label;
+import org.ovirt.engine.core.common.action.LabelNicParameters;
+import org.ovirt.engine.core.common.action.VdcActionType;
 import 
org.ovirt.engine.core.common.businessentities.network.pseudo.NetworkLabel;
 import org.ovirt.engine.core.common.queries.IdQueryParameters;
 import org.ovirt.engine.core.common.queries.VdcQueryType;
+import org.ovirt.engine.core.compat.Guid;
 
 public class BackendHostNicLabelResourceTest
-extends AbstractBackendSubResourceTest<Label, NetworkLabel, 
BackendHostNicLabelResource> {
+    extends AbstractBackendSubResourceTest<Label, NetworkLabel, 
BackendHostNicLabelResource> {
 
-    private static final String LABEL = "aaa";
+    private static final Guid NIC_ID = Guid.newGuid();
+    private static final Guid HOST_ID = Guid.newGuid();
+    private static final String[] LABELS = { "lbl1", "lbl2", "lbl3" };
 
     public BackendHostNicLabelResourceTest() {
-        super(new BackendHostNicLabelResource(LABEL,
-                new 
BackendHostNicLabelsResource(BackendHostNicLabelsResourceTest.nicId,
-                        BackendHostNicLabelsResourceTest.hostId)));
+        super(
+            new BackendHostNicLabelResource(
+                LABELS[0],
+                new BackendHostNicLabelsResource(NIC_ID, HOST_ID.toString())
+            )
+        );
     }
 
     protected void init() {
@@ -32,16 +41,13 @@
     @Test
     public void testGetNotFound() throws Exception {
         setUriInfo(setUpBasicUriExpectations());
-        setUpEntityQueryExpectations(VdcQueryType.GetNetworkLabelsByHostNicId,
-                                     IdQueryParameters.class,
-                                     new String[] { "Id" },
-                                     new Object[] { 
BackendHostNicLabelsResourceTest.nicId },
-                                     Collections.emptyList());
+        setUpEntityQueryExpectations(Collections.emptyList());
         control.replay();
         try {
             resource.get();
             fail("expected WebApplicationException");
-        } catch (WebApplicationException wae) {
+        }
+        catch (WebApplicationException wae) {
             verifyNotFoundException(wae);
         }
     }
@@ -49,28 +55,97 @@
     @Test
     public void testGet() throws Exception {
         setUriInfo(setUpBasicUriExpectations());
-        setUpEntityQueryExpectations(1);
+        setUpEntityQueryExpectations(getEntityList());
         control.replay();
-
         Label model = resource.get();
-        assertEquals(LABEL, model.getId());
+        assertEquals(LABELS[0], model.getId());
         verifyLinks(model);
     }
 
-    protected void setUpEntityQueryExpectations(int times) throws Exception {
-        while (times-- > 0) {
-            
setUpEntityQueryExpectations(VdcQueryType.GetNetworkLabelsByHostNicId,
-                                         IdQueryParameters.class,
-                                         new String[] { "Id" },
-                                         new Object[] { 
BackendHostNicLabelsResourceTest.nicId },
-                                         Arrays.asList(getEntity(0)));
+    @Test
+    public void testRemove() throws Exception {
+        setUpEntityQueryExpectations(getEntityList());
+        setUriInfo(
+            setUpActionExpectations(
+                VdcActionType.UnlabelNic,
+                LabelNicParameters.class,
+                new String[] { "NicId", "Label" },
+                new Object[] { NIC_ID, LABELS[0] },
+                true,
+                true
+            )
+        );
+        verifyRemove(resource.remove());
+    }
+
+    @Test
+    public void testRemoveNonExistant() throws Exception {
+        setUpEntityQueryExpectations(Collections.emptyList());
+        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 {
+        setUpEntityQueryExpectations(getEntityList());
+        doTestBadRemove(false, true, CANT_DO);
+    }
+
+    @Test
+    public void testRemoveFailed() throws Exception {
+        setUpEntityQueryExpectations(getEntityList());
+        doTestBadRemove(true, false, FAILURE);
+    }
+
+    protected void doTestBadRemove(boolean canDo, boolean success, String 
detail) throws Exception {
+        setUriInfo(
+            setUpActionExpectations(
+                VdcActionType.UnlabelNic,
+                LabelNicParameters.class,
+                new String[] { "NicId", "Label" },
+                new Object[] { NIC_ID, LABELS[0] },
+                canDo,
+                success
+            )
+        );
+        try {
+            resource.remove();
+            fail("expected WebApplicationException");
+        }
+        catch (WebApplicationException wae) {
+            verifyFault(wae, detail);
+        }
+    }
+
+    private void setUpEntityQueryExpectations(List<? super NetworkLabel> 
result) throws Exception {
+        setUpEntityQueryExpectations(
+            VdcQueryType.GetNetworkLabelsByHostNicId,
+            IdQueryParameters.class,
+            new String[] { "Id" },
+            new Object[] { NIC_ID },
+            result
+        );
+    }
+
+    private List<NetworkLabel> getEntityList() {
+        List<NetworkLabel> labels = new ArrayList<>();
+        for (int i = 0; i < LABELS.length; i++) {
+            labels.add(getEntity(i));
+        }
+        return labels;
     }
 
     @Override
     protected NetworkLabel getEntity(int index) {
         NetworkLabel entity = control.createMock(NetworkLabel.class);
-        expect(entity.getId()).andReturn(LABEL).anyTimes();
+        expect(entity.getId()).andReturn(LABELS[index]).anyTimes();
         return entity;
     }
 }
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelsResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelsResourceTest.java
index 7b9199a..cb2c6f2 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelsResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelsResourceTest.java
@@ -18,7 +18,8 @@
 import org.ovirt.engine.core.common.queries.VdcQueryType;
 import org.ovirt.engine.core.compat.Guid;
 
-public class BackendHostNicLabelsResourceTest extends 
AbstractBackendCollectionResourceTest<Label, NetworkLabel, 
BackendHostNicLabelsResource> {
+public class BackendHostNicLabelsResourceTest
+    extends AbstractBackendCollectionResourceTest<Label, NetworkLabel, 
BackendHostNicLabelsResource> {
 
     public static Guid nicId = Guid.newGuid();
     public static String hostId = Guid.newGuid().toString();
@@ -85,66 +86,6 @@
             fail("expected WebApplicationException on incomplete parameters");
         } catch (WebApplicationException wae) {
             verifyIncompleteException(wae, "Label", "add", "id");
-        }
-    }
-
-    @Test
-    public void testRemove() throws Exception {
-        setUpGetEntityExpectations();
-        setUriInfo(setUpActionExpectations(VdcActionType.UnlabelNic,
-                LabelNicParameters.class,
-                new String[] { "NicId", "Label" },
-                new Object[] { nicId, LABELS[0] },
-                true,
-                true));
-        verifyRemove(collection.remove(LABELS[0]));
-    }
-
-    @Test
-    public void testRemoveNonExistant() throws Exception {
-        setUpGetEntityExpectations();
-        control.replay();
-        try {
-            collection.remove(NON_EXISTANT_LABEL);
-            fail("expected WebApplicationException");
-        } catch (WebApplicationException wae) {
-            assertNotNull(wae.getResponse());
-            assertEquals(404, wae.getResponse().getStatus());
-        }
-    }
-
-    @Test
-    public void testRemoveCantDo() throws Exception {
-        setUpGetEntityExpectations();
-        doTestBadRemove(false, true, CANT_DO);
-    }
-
-    @Test
-    public void testRemoveFailed() throws Exception {
-        setUpGetEntityExpectations();
-        doTestBadRemove(true, false, FAILURE);
-    }
-
-    private void setUpGetEntityExpectations() throws Exception {
-        setUpGetEntityExpectations(VdcQueryType.GetNetworkLabelsByHostNicId,
-                IdQueryParameters.class,
-                new String[] { "Id" },
-                new Object[] { nicId },
-                getEntityList());
-    }
-
-    protected void doTestBadRemove(boolean canDo, boolean success, String 
detail) throws Exception {
-        setUriInfo(setUpActionExpectations(VdcActionType.UnlabelNic,
-                LabelNicParameters.class,
-                new String[] { "NicId", "Label" },
-                new Object[] { nicId, LABELS[0] },
-                canDo,
-                success));
-        try {
-            collection.remove(LABELS[0]);
-            fail("expected WebApplicationException");
-        } catch (WebApplicationException wae) {
-            verifyFault(wae, detail);
         }
     }
 
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelResourceTest.java
index 0735100..6d38156 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelResourceTest.java
@@ -2,25 +2,29 @@
 
 import static org.easymock.EasyMock.expect;
 
-import java.util.Arrays;
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.List;
 
 import javax.ws.rs.WebApplicationException;
 
 import org.junit.Test;
 import org.ovirt.engine.api.model.Label;
+import org.ovirt.engine.core.common.action.UnlabelNetworkParameters;
+import org.ovirt.engine.core.common.action.VdcActionType;
 import 
org.ovirt.engine.core.common.businessentities.network.pseudo.NetworkLabel;
 import org.ovirt.engine.core.common.queries.IdQueryParameters;
 import org.ovirt.engine.core.common.queries.VdcQueryType;
+import org.ovirt.engine.core.compat.Guid;
 
 public class BackendNetworkLabelResourceTest
-extends AbstractBackendSubResourceTest<Label, NetworkLabel, 
BackendNetworkLabelResource> {
+    extends AbstractBackendSubResourceTest<Label, NetworkLabel, 
BackendNetworkLabelResource> {
 
-    private static final String LABEL = "aaa";
+    private static final Guid NETWORK_ID = Guid.newGuid();
+    private static final String[] LABELS = { "lbl1", "lbl2", "lbl3" };
 
     public BackendNetworkLabelResourceTest() {
-        super(new BackendNetworkLabelResource(LABEL,
-                new 
BackendNetworkLabelsResource(BackendNetworkLabelsResourceTest.networkId)));
+        super(new BackendNetworkLabelResource(LABELS[0], new 
BackendNetworkLabelsResource(NETWORK_ID)));
     }
 
     protected void init() {
@@ -31,11 +35,7 @@
     @Test
     public void testGetNotFound() throws Exception {
         setUriInfo(setUpBasicUriExpectations());
-        setUpEntityQueryExpectations(VdcQueryType.GetNetworkLabelsByNetworkId,
-                                     IdQueryParameters.class,
-                                     new String[] { "Id" },
-                                     new Object[] { 
BackendNetworkLabelsResourceTest.networkId },
-                                     Collections.emptyList());
+        setUpEntityQueryExpectations(Collections.emptyList());
         control.replay();
         try {
             resource.get();
@@ -48,28 +48,99 @@
     @Test
     public void testGet() throws Exception {
         setUriInfo(setUpBasicUriExpectations());
-        setUpEntityQueryExpectations(1);
+        setUpEntityQueryExpectations(getEntityList());
         control.replay();
-
         Label model = resource.get();
-        assertEquals(LABEL, model.getId());
+        assertEquals(LABELS[0], model.getId());
         verifyLinks(model);
     }
 
-    protected void setUpEntityQueryExpectations(int times) throws Exception {
-        while (times-- > 0) {
-            
setUpEntityQueryExpectations(VdcQueryType.GetNetworkLabelsByNetworkId,
-                                         IdQueryParameters.class,
-                                         new String[] { "Id" },
-                                         new Object[] { 
BackendNetworkLabelsResourceTest.networkId },
-                                         Arrays.asList(getEntity(0)));
+    @Test
+    public void testRemove() throws Exception {
+        setUpEntityQueryExpectations(getEntityList());
+        setUriInfo(
+            setUpActionExpectations(
+                VdcActionType.UnlabelNetwork,
+                UnlabelNetworkParameters.class,
+                new String[] { "NetworkId" },
+                new Object[] { NETWORK_ID },
+                true,
+                true
+            )
+        );
+        verifyRemove(resource.remove());
+    }
+
+    @Test
+    public void testRemoveNonExistant() throws Exception {
+        setUpEntityQueryExpectations(Collections.emptyList());
+        setUriInfo(setUpBasicUriExpectations());
+        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 {
+        setUpEntityQueryExpectations(getEntityList());
+        doTestBadRemove(false, true, CANT_DO);
+    }
+
+    @Test
+    public void testRemoveFailed() throws Exception {
+        setUpEntityQueryExpectations(getEntityList());
+        doTestBadRemove(true, false, FAILURE);
+    }
+
+    private void doTestBadRemove(boolean canDo, boolean success, String 
detail) throws Exception {
+        setUriInfo(
+            setUpActionExpectations(
+                VdcActionType.UnlabelNetwork,
+                UnlabelNetworkParameters.class,
+                new String[] { "NetworkId" },
+                new Object[] { NETWORK_ID },
+                canDo,
+                success
+            )
+        );
+        try {
+            resource.remove();
+            fail("expected WebApplicationException");
+        }
+        catch (WebApplicationException wae) {
+            verifyFault(wae, detail);
+        }
+    }
+
+    private void setUpEntityQueryExpectations(List<? super NetworkLabel> 
result) throws Exception {
+        setUpEntityQueryExpectations(
+            VdcQueryType.GetNetworkLabelsByNetworkId,
+            IdQueryParameters.class,
+            new String[] { "Id" },
+            new Object[] { NETWORK_ID },
+            result
+        );
+    }
+
+    private List<NetworkLabel> getEntityList() {
+        List<NetworkLabel> labels = new ArrayList<>();
+        for (int i = 0; i < LABELS.length; i++) {
+            labels.add(getEntity(i));
+        }
+        return labels;
     }
 
     @Override
     protected NetworkLabel getEntity(int index) {
         NetworkLabel entity = control.createMock(NetworkLabel.class);
-        expect(entity.getId()).andReturn(LABEL).anyTimes();
+        expect(entity.getId()).andReturn(LABELS[index]).anyTimes();
         return entity;
     }
+
 }
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelsResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelsResourceTest.java
index 7ad4483..dac7a99 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelsResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendNetworkLabelsResourceTest.java
@@ -12,21 +12,20 @@
 import org.junit.Test;
 import org.ovirt.engine.api.model.Label;
 import org.ovirt.engine.core.common.action.LabelNetworkParameters;
-import org.ovirt.engine.core.common.action.UnlabelNetworkParameters;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import 
org.ovirt.engine.core.common.businessentities.network.pseudo.NetworkLabel;
 import org.ovirt.engine.core.common.queries.IdQueryParameters;
 import org.ovirt.engine.core.common.queries.VdcQueryType;
 import org.ovirt.engine.core.compat.Guid;
 
-public class BackendNetworkLabelsResourceTest extends 
AbstractBackendCollectionResourceTest<Label, NetworkLabel, 
BackendNetworkLabelsResource> {
+public class BackendNetworkLabelsResourceTest
+    extends AbstractBackendCollectionResourceTest<Label, NetworkLabel, 
BackendNetworkLabelsResource> {
 
-    public static Guid networkId = Guid.newGuid();
-    public static final String[] LABELS = { "lbl1", "lbl2", "lbl3" };
-    private static final String NON_EXISTANT_LABEL = "xxx";
+    private static final Guid NETWORK_ID = Guid.newGuid();
+    private static final String[] LABELS = { "lbl1", "lbl2", "lbl3" };
 
     public BackendNetworkLabelsResourceTest() {
-        super(new BackendNetworkLabelsResource(networkId), null, "");
+        super(new BackendNetworkLabelsResource(NETWORK_ID), null, "");
     }
 
     @Test
@@ -35,14 +34,14 @@
         setUpCreationExpectations(VdcActionType.LabelNetwork,
                 LabelNetworkParameters.class,
                 new String[] { "NetworkId", "Label" },
-                new Object[] { networkId, LABELS[0] },
+                new Object[] {NETWORK_ID, LABELS[0] },
                 true,
                 true,
                 LABELS[0],
                 VdcQueryType.GetNetworkLabelsByNetworkId,
                 IdQueryParameters.class,
                 new String[] { "Id" },
-                new Object[] { networkId },
+                new Object[] {NETWORK_ID},
                 asList(getEntity(0)));
         Response response = collection.add(getModel(0));
         assertEquals(201, response.getStatus());
@@ -64,7 +63,7 @@
         setUriInfo(setUpActionExpectations(VdcActionType.LabelNetwork,
                 LabelNetworkParameters.class,
                 new String[] { "NetworkId", "Label" },
-                new Object[] { networkId, LABELS[0] },
+                new Object[] {NETWORK_ID, LABELS[0] },
                 canDo,
                 success));
         try {
@@ -88,65 +87,6 @@
         }
     }
 
-    @Test
-    public void testRemove() throws Exception {
-        setUpGetEntityExpectations();
-        setUriInfo(setUpActionExpectations(VdcActionType.UnlabelNetwork,
-                UnlabelNetworkParameters.class,
-                new String[] { "NetworkId" },
-                new Object[] { networkId },
-                true,
-                true));
-        verifyRemove(collection.remove(LABELS[0]));
-    }
-
-    @Test
-    public void testRemoveNonExistant() throws Exception {
-        setUpGetEntityExpectations();
-        control.replay();
-        try {
-            collection.remove(NON_EXISTANT_LABEL);
-            fail("expected WebApplicationException");
-        } catch (WebApplicationException wae) {
-            assertNotNull(wae.getResponse());
-            assertEquals(404, wae.getResponse().getStatus());
-        }
-    }
-
-    @Test
-    public void testRemoveCantDo() throws Exception {
-        setUpGetEntityExpectations();
-        doTestBadRemove(false, true, CANT_DO);
-    }
-
-    @Test
-    public void testRemoveFailed() throws Exception {
-        setUpGetEntityExpectations();
-        doTestBadRemove(true, false, FAILURE);
-    }
-
-    private void setUpGetEntityExpectations() throws Exception {
-        setUpGetEntityExpectations(VdcQueryType.GetNetworkLabelsByNetworkId,
-                IdQueryParameters.class,
-                new String[] { "Id" },
-                new Object[] { networkId },
-                getEntityList());
-    }
-
-    protected void doTestBadRemove(boolean canDo, boolean success, String 
detail) throws Exception {
-        setUriInfo(setUpActionExpectations(VdcActionType.UnlabelNetwork,
-                UnlabelNetworkParameters.class,
-                new String[] { "NetworkId" },
-                new Object[] { networkId },
-                canDo,
-                success));
-        try {
-            collection.remove(LABELS[0]);
-            fail("expected WebApplicationException");
-        } catch (WebApplicationException wae) {
-            verifyFault(wae, detail);
-        }
-    }
 
     @Override
     protected List<Label> getCollection() {
@@ -167,7 +107,7 @@
         setUpEntityQueryExpectations(VdcQueryType.GetNetworkLabelsByNetworkId,
                 IdQueryParameters.class,
                 new String[] { "Id" },
-                new Object[] { networkId },
+                new Object[] {NETWORK_ID},
                 getEntityList(),
                 failure);
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8d31813da3e6a061d4c70baecbb1801f82382e7e
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

Reply via email to