Liron Ar has uploaded a new change for review.

Change subject: core: have ovf related logic reside only in ovfhelper
......................................................................

core: have ovf related logic reside only in ovfhelper

Change-Id: I1c65952f43f7a67ba49d3bab148ea318c9b13102
Signed-off-by: Liron Aravot <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmTemplateCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfDataUpdater.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfHelper.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/OvfDataUpdaterTest.java
5 files changed, 171 insertions(+), 186 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/88/24288/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmCommand.java
index 8303a32..7fd8d00 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmCommand.java
@@ -51,6 +51,7 @@
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.KeyValuePairCompat;
 import org.ovirt.engine.core.utils.GuidUtils;
+import org.ovirt.engine.core.utils.linq.Function;
 import org.ovirt.engine.core.utils.linq.LinqUtils;
 import org.ovirt.engine.core.utils.linq.Predicate;
 import org.ovirt.engine.core.utils.ovf.OvfManager;
@@ -493,8 +494,17 @@
     protected boolean updateVmImSpm() {
         Map<Guid, KeyValuePairCompat<String, List<Guid>>> metaDictionary =
                 new HashMap<Guid, KeyValuePairCompat<String, List<Guid>>>();
-        OvfDataUpdater.getInstance().loadVmData(getVm());
-        OvfDataUpdater.getInstance().buildMetadataDictionaryForVm(getVm(), 
metaDictionary);
+        VM vm = getVm();
+        String vmMeta = new OvfHelper().generateOvfConfigurationForVm(vm);
+        metaDictionary.put(
+                vm.getId(),
+                new KeyValuePairCompat<String, List<Guid>>(vmMeta, 
LinqUtils.foreach(vm.getDiskMap().values(),
+                        new Function<Disk, Guid>() {
+                            @Override
+                            public Guid eval(Disk a) {
+                                return a.getId();
+                            }
+                        })));
         return 
OvfDataUpdater.getInstance().executeUpdateVmInSpmCommand(getVm().getStoragePoolId(),
                 metaDictionary, getParameters().getStorageDomainId());
     }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmTemplateCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmTemplateCommand.java
index 05611ac..f7334f2 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmTemplateCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmTemplateCommand.java
@@ -24,6 +24,8 @@
 import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.KeyValuePairCompat;
+import org.ovirt.engine.core.utils.linq.Function;
+import org.ovirt.engine.core.utils.linq.LinqUtils;
 import org.ovirt.engine.core.utils.transaction.TransactionMethod;
 import org.ovirt.engine.core.utils.transaction.TransactionSupport;
 
@@ -176,10 +178,18 @@
         if (getParameters().getTaskGroupSuccess()) {
             Map<Guid, KeyValuePairCompat<String, List<Guid>>> metaDictionary =
                     new HashMap<Guid, KeyValuePairCompat<String, 
List<Guid>>>();
-            OvfDataUpdater.getInstance().loadTemplateData(getVmTemplate());
-            VmTemplateHandler.updateDisksFromDb(getVmTemplate());
+            String templateMeta = new 
OvfHelper().generateOvfConfigurationForTemplate(getVmTemplate());
+
             // update the target (export) domain
-            
OvfDataUpdater.getInstance().buildMetadataDictionaryForTemplate(getVmTemplate(),
 metaDictionary);
+            metaDictionary.put(
+                    getVmTemplate().getId(),
+                    new KeyValuePairCompat<String, List<Guid>>(templateMeta, 
LinqUtils.foreach(getVmTemplate().getDiskList(),
+                            new Function<DiskImage, Guid>() {
+                                @Override
+                                public Guid eval(DiskImage a) {
+                                    return a.getId();
+                                }
+                            })));
             
OvfDataUpdater.getInstance().executeUpdateVmInSpmCommand(getVmTemplate().getStoragePoolId(),
                     metaDictionary,
                     getParameters().getStorageDomainId());
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfDataUpdater.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfDataUpdater.java
index f4b71be..d80b901 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfDataUpdater.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfDataUpdater.java
@@ -1,24 +1,18 @@
 package org.ovirt.engine.core.bll;
 
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.commons.lang.StringUtils;
-import org.ovirt.engine.core.bll.utils.ClusterUtils;
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.businessentities.Disk;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
-import org.ovirt.engine.core.common.businessentities.ImageStatus;
 import org.ovirt.engine.core.common.businessentities.StoragePool;
 import org.ovirt.engine.core.common.businessentities.StoragePoolStatus;
 import org.ovirt.engine.core.common.businessentities.VM;
-import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
-import org.ovirt.engine.core.common.businessentities.VmTemplateStatus;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.vdscommands.RemoveVMVDSCommandParameters;
@@ -34,12 +28,10 @@
 import org.ovirt.engine.core.dao.VmDAO;
 import org.ovirt.engine.core.dao.VmStaticDAO;
 import org.ovirt.engine.core.dao.VmTemplateDAO;
-import org.ovirt.engine.core.dao.network.VmNetworkInterfaceDao;
 import org.ovirt.engine.core.utils.linq.Function;
 import org.ovirt.engine.core.utils.linq.LinqUtils;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
-import org.ovirt.engine.core.utils.ovf.OvfManager;
 import org.ovirt.engine.core.utils.timer.OnTimerMethodAnnotation;
 import org.ovirt.engine.core.utils.timer.SchedulerUtil;
 import org.ovirt.engine.core.utils.timer.SchedulerUtilQuartzImpl;
@@ -53,10 +45,10 @@
     private List<Guid> proccessedIdsInfo;
     private List<Long> proccessedOvfGenerationsInfo;
 
-    private OvfManager ovfManager;
+    protected OvfHelper ovfHelper;
 
     private OvfDataUpdater() {
-        ovfManager = new OvfManager();
+        ovfHelper = new OvfHelper();
     }
 
     public static OvfDataUpdater getInstance() {
@@ -173,42 +165,6 @@
     }
 
     /**
-     * Creates and returns a map containing valid templates metadata
-     */
-    protected Map<Guid, KeyValuePairCompat<String, List<Guid>>> 
populateTemplatesMetadataForOvfUpdate(List<Guid> idsToProcess) {
-        Map<Guid, KeyValuePairCompat<String, List<Guid>>> 
vmsAndTemplateMetadata =
-                new HashMap<Guid, KeyValuePairCompat<String, List<Guid>>>();
-        List<VmTemplate> templates = 
getVmTemplateDao().getVmTemplatesByIds(idsToProcess);
-
-        for (VmTemplate template : templates) {
-            if (VmTemplateStatus.Locked != template.getStatus()) {
-                updateTemplateDisksFromDb(template);
-                boolean verifyDisksNotLocked = 
verifyDisksNotLocked(template.getDiskList());
-                if (verifyDisksNotLocked) {
-                    loadTemplateData(template);
-                    Long currentDbGeneration = 
getVmStaticDao().getDbGeneration(template.getId());
-                    // currentDbGeneration can be null in case that the 
template was deleted during the run of OvfDataUpdater.
-                    if (currentDbGeneration != null && 
template.getDbGeneration() == currentDbGeneration) {
-                        buildMetadataDictionaryForTemplate(template, 
vmsAndTemplateMetadata);
-                        proccessedIdsInfo.add(template.getId());
-                        
proccessedOvfGenerationsInfo.add(template.getDbGeneration());
-                    }
-                }
-            }
-        }
-
-        return vmsAndTemplateMetadata;
-    }
-
-    protected void updateTemplateDisksFromDb(VmTemplate template) {
-        VmTemplateHandler.updateDisksFromDb(template);
-    }
-
-    protected void updateVmDisksFromDb(VM vm) {
-        VmHandler.updateDisksFromDb(vm);
-    }
-
-    /**
      * Update ovfs for updated/added templates since last for the given 
storage pool
      */
     protected void updateOvfForTemplatesOfStoragePool(Guid poolId) {
@@ -236,112 +192,62 @@
                 new HashMap<Guid, KeyValuePairCompat<String, List<Guid>>>();
         List<VM> vms = getVmDao().getVmsByIds(idsToProcess);
         for (VM vm : vms) {
-            if (VMStatus.ImageLocked != vm.getStatus()) {
-                updateVmDisksFromDb(vm);
-                if (verifyDisksNotLocked(vm.getDiskList())) {
-                    loadVmData(vm);
-                    Long currentDbGeneration = 
getVmStaticDao().getDbGeneration(vm.getId());
-                    // currentDbGeneration can be null in case that the vm was 
deleted during the run of OvfDataUpdater.
-                    if (currentDbGeneration != null && 
vm.getStaticData().getDbGeneration() == currentDbGeneration) {
-                        buildMetadataDictionaryForVm(vm, 
vmsAndTemplateMetadata);
-                        proccessedIdsInfo.add(vm.getId());
-                        
proccessedOvfGenerationsInfo.add(vm.getStaticData().getDbGeneration());
-                    }
-                }
+            String vmMeta = generateOvfConfigurationForVm(vm);
+            if (vmMeta == null) {
+                continue;
             }
+            vmsAndTemplateMetadata.put(
+                    vm.getId(),
+                    new KeyValuePairCompat<String, List<Guid>>(vmMeta, 
LinqUtils.foreach(vm.getDiskMap().values(),
+                            new Function<Disk, Guid>() {
+                                @Override
+                                public Guid eval(Disk a) {
+                                    return a.getId();
+                                }
+                            })));
+            proccessedIdsInfo.add(vm.getId());
+            
proccessedOvfGenerationsInfo.add(vm.getStaticData().getDbGeneration());
         }
         return vmsAndTemplateMetadata;
     }
 
     /**
-     * Returns true if none of the given disks is in status 'LOCKED', 
otherwise false.
+     * Creates and returns a map containing valid templates metadata
      */
-    protected boolean verifyDisksNotLocked(List<DiskImage> disks) {
-        for (DiskImage disk : disks) {
-            if (disk.getImageStatus() == ImageStatus.LOCKED) {
-                return false;
+    protected Map<Guid, KeyValuePairCompat<String, List<Guid>>> 
populateTemplatesMetadataForOvfUpdate(List<Guid> idsToProcess) {
+        Map<Guid, KeyValuePairCompat<String, List<Guid>>> 
vmsAndTemplateMetadata =
+                new HashMap<Guid, KeyValuePairCompat<String, List<Guid>>>();
+        List<VmTemplate> templates = 
getVmTemplateDao().getVmTemplatesByIds(idsToProcess);
+
+        for (VmTemplate template : templates) {
+            String templateMeta = 
generateOvfConfigurationForTemplate(template);
+            if (templateMeta == null) {
+                continue;
             }
-        }
-        return true;
-    }
 
-    protected String generateVmTemplateMetadata(VmTemplate template, 
List<DiskImage> allTemplateImages) {
-        return ovfManager.ExportTemplate(template, allTemplateImages, 
ClusterUtils.getCompatibilityVersion(template));
-    }
+            vmsAndTemplateMetadata.put(
+                    template.getId(),
+                    new KeyValuePairCompat<String, List<Guid>>(templateMeta, 
LinqUtils.foreach(template.getDiskList(),
+                            new Function<DiskImage, Guid>() {
+                                @Override
+                                public Guid eval(DiskImage a) {
+                                    return a.getId();
+                                }
+                            })));
 
-    /**
-     * Adds the given template metadata to the given map
-     */
-    protected void buildMetadataDictionaryForTemplate(VmTemplate template,
-            Map<Guid, KeyValuePairCompat<String, List<Guid>>> metaDictionary) {
-        List<DiskImage> allTemplateImages = template.getDiskList();
-        String templateMeta = generateVmTemplateMetadata(template, 
allTemplateImages);
-        metaDictionary.put(template.getId(), new KeyValuePairCompat<String, 
List<Guid>>(
-                templateMeta, LinqUtils.foreach(allTemplateImages, new 
Function<DiskImage, Guid>() {
-                    @Override
-                    public Guid eval(DiskImage diskImage) {
-                        return diskImage.getId();
-                    }
-                })));
-    }
-
-    /**
-     * Loads additional need template data for it's ovf
-     */
-    protected void loadTemplateData(VmTemplate template) {
-        if (template.getInterfaces() == null || 
template.getInterfaces().isEmpty()) {
-            template.setInterfaces(getVmNetworkInterfaceDao()
-                    .getAllForTemplate(template.getId()));
-        }
-    }
-
-    /**
-     * Loads additional need vm data for it's ovf
-     */
-    protected void loadVmData(VM vm) {
-        if (vm.getInterfaces().isEmpty()) {
-            
vm.setInterfaces(getVmNetworkInterfaceDao().getAllForVm(vm.getId()));
-        }
-        if (StringUtils.isEmpty(vm.getVmtName())) {
-            if (!Guid.Empty.equals(vm.getVmtGuid())) {
-                VmTemplate t = getVmTemplateDao().get(vm.getVmtGuid());
-                vm.setVmtName(t.getName());
-            } else {
-                vm.setVmtName(VmTemplateHandler.BLANK_VM_TEMPLATE_NAME);
-            }
-        }
-    }
-
-    protected ArrayList<DiskImage> getAllImageSnapshots(DiskImage diskImage) {
-        return ImagesHandler.getAllImageSnapshots(diskImage.getImageId(),
-                diskImage.getImageTemplateId());
-    }
-
-    protected String generateVmMetadata(VM vm, ArrayList<DiskImage> 
AllVmImages) {
-        return ovfManager.ExportVm(vm, AllVmImages, 
ClusterUtils.getCompatibilityVersion(vm));
-    }
-
-    /**
-     * Adds the given vm metadata to the given map
-     */
-    protected void buildMetadataDictionaryForVm(VM vm, Map<Guid, 
KeyValuePairCompat<String, List<Guid>>> metaDictionary) {
-        ArrayList<DiskImage> AllVmImages = new ArrayList<DiskImage>();
-        List<DiskImage> filteredDisks = 
ImagesHandler.filterImageDisks(vm.getDiskList(), false, true, true);
-
-        for (DiskImage diskImage : filteredDisks) {
-            AllVmImages.addAll(getAllImageSnapshots(diskImage));
+            proccessedIdsInfo.add(template.getId());
+            proccessedOvfGenerationsInfo.add(template.getDbGeneration());
         }
 
-        String vmMeta = generateVmMetadata(vm, AllVmImages);
-        metaDictionary.put(
-                vm.getId(),
-                new KeyValuePairCompat<String, List<Guid>>(vmMeta, 
LinqUtils.foreach(vm.getDiskMap().values(),
-                        new Function<Disk, Guid>() {
-                            @Override
-                            public Guid eval(Disk a) {
-                                return a.getId();
-                            }
-                        })));
+        return vmsAndTemplateMetadata;
+    }
+
+    protected String generateOvfConfigurationForTemplate(VmTemplate template) {
+        return ovfHelper.generateOvfConfigurationForTemplate(template);
+    }
+
+    public String generateOvfConfigurationForVm(VM vm) {
+        return ovfHelper.generateOvfConfigurationForVm(vm);
     }
 
     protected VmDAO getVmDao() {
@@ -350,10 +256,6 @@
 
     protected VmTemplateDAO getVmTemplateDao() {
         return DbFacade.getInstance().getVmTemplateDao();
-    }
-
-    protected VmNetworkInterfaceDao getVmNetworkInterfaceDao() {
-        return DbFacade.getInstance().getVmNetworkInterfaceDao();
     }
 
     protected VmAndTemplatesGenerationsDAO getVmAndTemplatesGenerationsDao() {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfHelper.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfHelper.java
index 0e96c62..c48fdad 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfHelper.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/OvfHelper.java
@@ -11,9 +11,13 @@
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
+import org.ovirt.engine.core.common.businessentities.VmTemplateStatus;
 import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
+import org.ovirt.engine.core.dao.VmStaticDAO;
+import org.ovirt.engine.core.dao.VmTemplateDAO;
+import org.ovirt.engine.core.dao.network.VmNetworkInterfaceDao;
 import org.ovirt.engine.core.utils.ovf.OvfManager;
 import org.ovirt.engine.core.utils.ovf.OvfReaderException;
 
@@ -58,14 +62,14 @@
 
     public String generateOvfConfigurationForVm(VM vm) {
         if (VMStatus.ImageLocked != vm.getStatus()) {
-            VmHandler.updateDisksFromDb(vm);
+            updateVmDisksFromDb(vm);
             DiskImagesValidator validator = new 
DiskImagesValidator(vm.getDiskList());
             if (validator.diskImagesNotLocked().isValid()) {
                 loadVmData(vm);
-                Long currentDbGeneration = 
getDbFacade().getVmStaticDao().getDbGeneration(vm.getId());
+                Long currentDbGeneration = 
getVmStaticDao().getDbGeneration(vm.getId());
                 // currentDbGeneration can be null in case that the vm was 
deleted during the run of OvfDataUpdater.
                 if (currentDbGeneration != null && 
vm.getStaticData().getDbGeneration() == currentDbGeneration) {
-                    return buildMetadataDictionaryForVm(vm);
+                    return getVmOvf(vm);
                 }
             }
         }
@@ -73,29 +77,53 @@
         return null;
     }
 
-    /**
-     * Adds the given vm metadata to the given map
-     */
-    private String buildMetadataDictionaryForVm(VM vm) {
+    public String generateOvfConfigurationForTemplate(VmTemplate template) {
+        if (VmTemplateStatus.Locked != template.getStatus()) {
+            updateTemplateDisksFromDb(template);
+            DiskImagesValidator validator = new 
DiskImagesValidator(template.getDiskList());
+            if (validator.diskImagesNotLocked().isValid()) {
+                loadTemplateData(template);
+                Long currentDbGeneration = 
getVmStaticDao().getDbGeneration(template.getId());
+                // currentDbGeneration can be null in case that the template 
was deleted during the run of OvfDataUpdater.
+                if (currentDbGeneration != null && template.getDbGeneration() 
== currentDbGeneration) {
+                    return getTemplateOvf(template);
+                }
+            }
+        }
+
+        return null;
+    }
+
+
+    protected String getTemplateOvf(VmTemplate template) {
+        List<DiskImage> allTemplateImages = template.getDiskList();
+        return ovfManager.ExportTemplate(template, allTemplateImages, 
ClusterUtils.getCompatibilityVersion(template));
+    }
+
+    protected String getVmOvf(VM vm) {
         ArrayList<DiskImage> AllVmImages = new ArrayList<DiskImage>();
         List<DiskImage> filteredDisks = 
ImagesHandler.filterImageDisks(vm.getDiskList(), false, true, true);
 
         for (DiskImage diskImage : filteredDisks) {
-            List<DiskImage> images = 
ImagesHandler.getAllImageSnapshots(diskImage.getImageId(),
-                    diskImage.getImageTemplateId());
+            List<DiskImage> images = getAllImageSnapshots(diskImage);
             AllVmImages.addAll(images);
         }
 
         return ovfManager.ExportVm(vm, AllVmImages, 
ClusterUtils.getCompatibilityVersion(vm));
     }
 
-    private void loadVmData(VM vm) {
+    protected List<DiskImage> getAllImageSnapshots(DiskImage diskImage) {
+        return ImagesHandler.getAllImageSnapshots(diskImage.getImageId(),
+                diskImage.getImageTemplateId());
+    }
+
+    protected void loadVmData(VM vm) {
         if (vm.getInterfaces().isEmpty()) {
-            
vm.setInterfaces(getDbFacade().getVmNetworkInterfaceDao().getAllForVm(vm.getId()));
+            
vm.setInterfaces(getVmNetworkInterfaceDao().getAllForVm(vm.getId()));
         }
         if (StringUtils.isEmpty(vm.getVmtName())) {
             if (!Guid.Empty.equals(vm.getVmtGuid())) {
-                VmTemplate t = 
getDbFacade().getVmTemplateDao().get(vm.getVmtGuid());
+                VmTemplate t = getVmTemplateDao().get(vm.getVmtGuid());
                 vm.setVmtName(t.getName());
             } else {
                 vm.setVmtName(VmTemplateHandler.BLANK_VM_TEMPLATE_NAME);
@@ -103,10 +131,37 @@
         }
     }
 
+    protected void loadTemplateData(VmTemplate template) {
+        if (template.getInterfaces() == null || 
template.getInterfaces().isEmpty()) {
+            template.setInterfaces(getVmNetworkInterfaceDao()
+                    .getAllForTemplate(template.getId()));
+        }
+    }
+
+    public void updateVmDisksFromDb(VM vm) {
+        VmHandler.updateDisksFromDb(vm);
+    }
+
+    public void updateTemplateDisksFromDb(VmTemplate template) {
+        VmTemplateHandler.updateDisksFromDb(template);
+    }
+
     private DbFacade getDbFacade() {
         return DbFacade.getInstance();
     }
 
+    protected VmStaticDAO getVmStaticDao() {
+        return getDbFacade().getVmStaticDao();
+    }
+
+    protected VmTemplateDAO getVmTemplateDao() {
+        return getDbFacade().getVmTemplateDao();
+    }
+
+    protected VmNetworkInterfaceDao getVmNetworkInterfaceDao() {
+        return getDbFacade().getVmNetworkInterfaceDao();
+    }
+
     public boolean isOvfTemplate(String ovfstring) {
         return ovfManager.IsOvfTemplate(ovfstring);
     }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/OvfDataUpdaterTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/OvfDataUpdaterTest.java
index 062f93a..7abc58b 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/OvfDataUpdaterTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/OvfDataUpdaterTest.java
@@ -36,6 +36,7 @@
 import org.mockito.stubbing.Answer;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.ImageStatus;
+import org.ovirt.engine.core.common.businessentities.StoragePool;
 import org.ovirt.engine.core.common.businessentities.StoragePoolStatus;
 import org.ovirt.engine.core.common.businessentities.StorageType;
 import org.ovirt.engine.core.common.businessentities.VM;
@@ -43,7 +44,6 @@
 import org.ovirt.engine.core.common.businessentities.VmStatic;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import org.ovirt.engine.core.common.businessentities.VmTemplateStatus;
-import org.ovirt.engine.core.common.businessentities.StoragePool;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.KeyValuePairCompat;
 import org.ovirt.engine.core.dao.StoragePoolDAO;
@@ -51,6 +51,7 @@
 import org.ovirt.engine.core.dao.VmDAO;
 import org.ovirt.engine.core.dao.VmStaticDAO;
 import org.ovirt.engine.core.dao.VmTemplateDAO;
+import org.ovirt.engine.core.dao.network.VmNetworkInterfaceDao;
 
 /** A test class for the {@link OvfDataUpdater} class */
 @RunWith(MockitoJUnitRunner.class)
@@ -71,6 +72,9 @@
 
     @Mock
     private VmTemplateDAO vmTemplateDAO;
+
+    @Mock
+    private VmNetworkInterfaceDao vmNetworkInterfaceDao;
 
     private StoragePool pool1;
 
@@ -101,8 +105,9 @@
     @Before
     public void setUp() {
         updater = Mockito.spy(OvfDataUpdater.getInstance());
+        updater.ovfHelper = Mockito.spy(updater.ovfHelper);
+
         doReturn(ITEMS_COUNT_PER_UPDATE).when(updater).reloadConfigValue();
-        doReturn(new 
ArrayList<DiskImage>()).when(updater).getAllImageSnapshots(any(DiskImage.class));
         doCallRealMethod().when(updater).ovfUpdate_timer();
         // init members
         initMembers();
@@ -111,19 +116,24 @@
         doReturn(storagePoolDAO).when(updater).getStoragePoolDao();
         
doReturn(vmAndTemplatesGenerationsDAO).when(updater).getVmAndTemplatesGenerationsDao();
         doReturn(vmDAO).when(updater).getVmDao();
-        doReturn(vmStaticDAO).when(updater).getVmStaticDao();
         doReturn(vmTemplateDAO).when(updater).getVmTemplateDao();
 
         // mock ovf data updater methods
-        doNothing().when(updater).loadTemplateData(any(VmTemplate.class));
-        doNothing().when(updater).loadVmData(any(VM.class));
-        doNothing().when(updater).updateVmDisksFromDb(any(VM.class));
         doNothing().when(updater).addAuditLogError(anyString());
-        
doNothing().when(updater).updateTemplateDisksFromDb(any(VmTemplate.class));
 
         // dao related mocks.
         
doReturn(buildStoragePoolsList()).when(storagePoolDAO).getAllByStatus(any(StoragePoolStatus.class));
         doReturn(1L).when(vmStaticDAO).getDbGeneration(any(Guid.class));
+
+        doReturn(vmStaticDAO).when(updater.ovfHelper).getVmStaticDao();
+        doReturn(vmTemplateDAO).when(updater.ovfHelper).getVmTemplateDao();
+        
doReturn(vmNetworkInterfaceDao).when(updater.ovfHelper).getVmNetworkInterfaceDao();
+
+        doReturn(new 
ArrayList<DiskImage>()).when(updater.ovfHelper).getAllImageSnapshots(any(DiskImage.class));
+        
doNothing().when(updater.ovfHelper).loadTemplateData(any(VmTemplate.class));
+        doNothing().when(updater.ovfHelper).loadVmData(any(VM.class));
+        doNothing().when(updater.ovfHelper).updateVmDisksFromDb(any(VM.class));
+        
doNothing().when(updater.ovfHelper).updateTemplateDisksFromDb(any(VmTemplate.class));
 
         mockAnswers();
     }
@@ -157,24 +167,6 @@
 
 
     private void mockAnswers() {
-        doAnswer(new Answer<String>() {
-            @Override
-            public String answer(InvocationOnMock invocation) throws Throwable 
{
-                VM vm = (VM) invocation.getArguments()[0];
-                return vm.getId().toString();
-            }
-
-        }).when(updater).generateVmMetadata(any(VM.class), 
any(ArrayList.class));
-
-        doAnswer(new Answer<String>() {
-            @Override
-            public String answer(InvocationOnMock invocation) throws Throwable 
{
-                VmTemplate template = (VmTemplate) 
invocation.getArguments()[0];
-                return template.getId().toString();
-            }
-
-        }).when(updater).generateVmTemplateMetadata(any(VmTemplate.class), 
anyList());
-
         doAnswer(new Answer<List<VM>>() {
             @Override
             public List<VM> answer(InvocationOnMock invocation) throws 
Throwable {
@@ -188,6 +180,22 @@
 
         }).when(vmDAO).getVmsByIds(anyList());
 
+        doAnswer(new Answer<String>() {
+            @Override
+            public String answer(InvocationOnMock invocation) throws Throwable 
{
+                VmTemplate template = (VmTemplate) 
invocation.getArguments()[0];
+                return template.getId().toString();
+            }
+        }).when(updater.ovfHelper).getTemplateOvf(any(VmTemplate.class));
+
+        doAnswer(new Answer<String>() {
+            @Override
+            public String answer(InvocationOnMock invocation) throws Throwable 
{
+                VM vm = (VM) invocation.getArguments()[0];
+                return vm.getId().toString();
+            }
+        }).when(updater.ovfHelper).getVmOvf(any(VM.class));
+
         doAnswer(new Answer<List<VmTemplate>>() {
             @Override
             public List<VmTemplate> answer(InvocationOnMock invocation) throws 
Throwable {


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

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

Reply via email to