Vered Volansky has uploaded a new change for review.

Change subject: core: regression added err message check, unitest
......................................................................

core: regression added err message check, unitest

Longer description using lines' length under 72 chars.

With multiple paragraphs if necessary.

Change-Id: Ic91e8718181db7b55b59ca53ddc86e8f76ebd83c
Bug-Url: https://bugzilla.redhat.com/??????
Signed-off-by: Vered Volansky <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommandTest.java
2 files changed, 39 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/94/8694/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
index 020242d..185b044 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java
@@ -100,9 +100,11 @@
     }
 
     protected boolean isImageIsNotLocked() {
-        if (getImage().getimageStatus() == ImageStatus.LOCKED) {
+        DiskImage diskImage = getImage();
+        if (diskImage.getimageStatus() == ImageStatus.LOCKED) {
             if (getParameters().getOperation() == ImageOperation.Move) {
-                
addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_DISKS_ARE_LOCKED);
+                
addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_DISK_IS_LOCKED);
+                addCanDoActionMessage(String.format("$%1$s %2$s", "diskAlias", 
diskImage.getDiskAlias()));
             } else {
                 
addCanDoActionMessage(VdcBllMessages.VM_TEMPLATE_IMAGE_IS_LOCKED);
             }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommandTest.java
index 43e5128..3e92fd9 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommandTest.java
@@ -10,7 +10,9 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -19,6 +21,7 @@
 import org.ovirt.engine.core.common.action.MoveOrCopyImageGroupParameters;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.ImageOperation;
+import org.ovirt.engine.core.common.businessentities.ImageStatus;
 import org.ovirt.engine.core.common.businessentities.StorageDomainStatus;
 import org.ovirt.engine.core.common.businessentities.StorageType;
 import org.ovirt.engine.core.common.businessentities.VM;
@@ -26,6 +29,7 @@
 import org.ovirt.engine.core.common.businessentities.VmDevice;
 import org.ovirt.engine.core.common.businessentities.VmDeviceId;
 import org.ovirt.engine.core.common.businessentities.VmEntityType;
+import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import org.ovirt.engine.core.common.businessentities.storage_domains;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.VdcBllMessages;
@@ -131,6 +135,30 @@
                 
.contains(VdcBllMessages.ACTION_TYPE_FAILED_VM_IS_NOT_DOWN.toString()));
     }
 
+    @Test
+    public void canDoActionDiskIsLocked() throws Exception {
+        initializeCommand(ImageOperation.Move);
+        initVmDiskImage();
+        initVm();
+        command.getImage().setimageStatus(ImageStatus.LOCKED);
+        doReturn(vmDeviceDao).when(command).getVmDeviceDAO();
+        assertFalse(command.canDoAction());
+        assertTrue(command.getReturnValue().getCanDoActionMessages().contains(
+                VdcBllMessages.ACTION_TYPE_FAILED_DISK_IS_LOCKED.toString()));
+    }
+
+    @Test
+    public void canDoActionTemplateImageIsLocked() throws Exception {
+        initializeCommand(ImageOperation.Copy);
+        initTemplateDiskImage();
+        command.getImage().setimageStatus(ImageStatus.LOCKED);
+        doReturn(vmTemplateDao).when(command).getVmTemplateDAO();
+        mockGetAllForImage();
+        assertFalse(command.canDoAction());
+        assertTrue(command.getReturnValue().getCanDoActionMessages().contains(
+                VdcBllMessages.VM_TEMPLATE_IMAGE_IS_LOCKED.toString()));
+    }
+
     protected void initVm() {
         VM vm = new VM();
         vm.setstatus(VMStatus.PoweredDown);
@@ -139,6 +167,13 @@
         mockGetVmsListForDisk();
     }
 
+    private void mockGetAllForImage()
+    {
+        Map<Boolean, VmTemplate> map = new HashMap<Boolean, VmTemplate>();
+        map.put(true, new VmTemplate());
+        doReturn(map).when(vmTemplateDao).getAllForImage(any(Guid.class));
+    }
+
     private void mockGetVmsListForDisk() {
         List<VM> vmList = new ArrayList<VM>();
         VM vm1 = new VM();


--
To view, visit http://gerrit.ovirt.org/8694
To unsubscribe, visit http://gerrit.ovirt.org/settings

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

Reply via email to