cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edi...@apache.org
Subject [6/8] starting unit test
Date Wed, 21 Nov 2012 03:01:20 GMT
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDaoImpl.java
index 25aa2aa..59211a8 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDaoImpl.java
@@ -50,7 +50,7 @@ import com.cloud.utils.db.Transaction;
 import com.cloud.utils.db.UpdateBuilder;
 import com.cloud.utils.exception.CloudRuntimeException;
 
-@Local(value=VolumeDao.class)
+@Local(value = VolumeDao.class)
 @Component
 public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements VolumeDao {
     private static final Logger s_logger = Logger.getLogger(VolumeDaoImpl.class);
@@ -61,23 +61,22 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
     protected final SearchBuilder<VolumeVO> InstanceStatesSearch;
     protected final SearchBuilder<VolumeVO> AllFieldsSearch;
     protected GenericSearchBuilder<VolumeVO, Long> CountByAccount;
-    ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class);
-    
+    //ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class);
+    ResourceTagsDaoImpl _tagsDao = null;
     protected static final String SELECT_VM_SQL = "SELECT DISTINCT instance_id from volumes v where v.host_id = ? and v.mirror_state = ?";
     protected static final String SELECT_HYPERTYPE_FROM_VOLUME = "SELECT c.hypervisor_type from volumes v, storage_pool s, cluster c where v.pool_id = s.id and s.cluster_id = c.id and v.id = ?";
 
-    private static final String ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT = "SELECT pool.id, SUM(IF(vol.state='Ready' AND vol.account_id = ?, 1, 0)) FROM `cloud`.`storage_pool` pool LEFT JOIN `cloud`.`volumes` vol ON pool.id = vol.pool_id WHERE pool.data_center_id = ? " +
-                                                                        " AND pool.pod_id = ? AND pool.cluster_id = ? " +
-                                                                        " GROUP BY pool.id ORDER BY 2 ASC ";
-    
+    private static final String ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT = "SELECT pool.id, SUM(IF(vol.state='Ready' AND vol.account_id = ?, 1, 0)) FROM `cloud`.`storage_pool` pool LEFT JOIN `cloud`.`volumes` vol ON pool.id = vol.pool_id WHERE pool.data_center_id = ? "
+            + " AND pool.pod_id = ? AND pool.cluster_id = ? " + " GROUP BY pool.id ORDER BY 2 ASC ";
+
     @Override
     public List<VolumeVO> findDetachedByAccount(long accountId) {
-    	SearchCriteria<VolumeVO> sc = DetachedAccountIdSearch.create();
-    	sc.setParameters("accountId", accountId);
-    	sc.setParameters("destroyed", Volume.State.Destroy);
-    	return listBy(sc);
+        SearchCriteria<VolumeVO> sc = DetachedAccountIdSearch.create();
+        sc.setParameters("accountId", accountId);
+        sc.setParameters("destroyed", Volume.State.Destroy);
+        return listBy(sc);
     }
-    
+
     @Override
     public List<VolumeVO> findByAccount(long accountId) {
         SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
@@ -85,172 +84,172 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
         sc.setParameters("state", Volume.State.Ready);
         return listBy(sc);
     }
-    
+
     @Override
     public List<VolumeVO> findByInstance(long id) {
         SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
         sc.setParameters("instanceId", id);
-	    return listBy(sc);
-	}
-   
+        return listBy(sc);
+    }
+
     @Override
-    public List<VolumeVO> findByInstanceAndDeviceId(long instanceId, long deviceId){
-    	SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
-    	sc.setParameters("instanceId", instanceId);
-    	sc.setParameters("deviceId", deviceId);
-    	return listBy(sc);
+    public List<VolumeVO> findByInstanceAndDeviceId(long instanceId, long deviceId) {
+        SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
+        sc.setParameters("instanceId", instanceId);
+        sc.setParameters("deviceId", deviceId);
+        return listBy(sc);
     }
-    
+
     @Override
     public List<VolumeVO> findByPoolId(long poolId) {
         SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
         sc.setParameters("poolId", poolId);
         sc.setParameters("notDestroyed", Volume.State.Destroy);
         sc.setParameters("vType", new RootDisk().toString());
-	    return listBy(sc);
-	}
-    
-    @Override 
+        return listBy(sc);
+    }
+
+    @Override
     public List<VolumeVO> findCreatedByInstance(long id) {
         SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
         sc.setParameters("instanceId", id);
         sc.setParameters("state", Volume.State.Ready);
         return listBy(sc);
     }
-    
+
     @Override
     public List<VolumeVO> findUsableVolumesForInstance(long instanceId) {
         SearchCriteria<VolumeVO> sc = InstanceStatesSearch.create();
         sc.setParameters("instance", instanceId);
         sc.setParameters("states", Volume.State.Creating, Volume.State.Ready, Volume.State.Allocated);
-        
+
         return listBy(sc);
     }
-    
-	@Override
-	public List<VolumeVO> findByInstanceAndType(long id, VolumeType vType) {
+
+    @Override
+    public List<VolumeVO> findByInstanceAndType(long id, VolumeType vType) {
         SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
         sc.setParameters("instanceId", id);
         sc.setParameters("vType", vType.toString());
-	    return listBy(sc);
-	}
-	
-	@Override
-	public List<VolumeVO> findByInstanceIdDestroyed(long vmId) {
-		SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
-		sc.setParameters("instanceId", vmId);
-		sc.setParameters("destroyed", Volume.State.Destroy);
-		return listBy(sc);
-	}
-	
-	@Override
-	public List<VolumeVO> findReadyRootVolumesByInstance(long instanceId) {
-		SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
-		sc.setParameters("instanceId", instanceId);
-		sc.setParameters("state", Volume.State.Ready);
-		sc.setParameters("vType", new RootDisk().toString());		
-		return listBy(sc);
-	}
-	
-	@Override
-	public List<VolumeVO> findByAccountAndPod(long accountId, long podId) {
-		SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
+        return listBy(sc);
+    }
+
+    @Override
+    public List<VolumeVO> findByInstanceIdDestroyed(long vmId) {
+        SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
+        sc.setParameters("instanceId", vmId);
+        sc.setParameters("destroyed", Volume.State.Destroy);
+        return listBy(sc);
+    }
+
+    @Override
+    public List<VolumeVO> findReadyRootVolumesByInstance(long instanceId) {
+        SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
+        sc.setParameters("instanceId", instanceId);
+        sc.setParameters("state", Volume.State.Ready);
+        sc.setParameters("vType", new RootDisk().toString());
+        return listBy(sc);
+    }
+
+    @Override
+    public List<VolumeVO> findByAccountAndPod(long accountId, long podId) {
+        SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
         sc.setParameters("accountId", accountId);
         sc.setParameters("pod", podId);
         sc.setParameters("state", Volume.State.Ready);
-        
+
+        return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public List<VolumeVO> findByTemplateAndZone(long templateId, long zoneId) {
+        SearchCriteria<VolumeVO> sc = TemplateZoneSearch.create();
+        sc.setParameters("template", templateId);
+        sc.setParameters("zone", zoneId);
+
         return listIncludingRemovedBy(sc);
-	}
-	
-	@Override
-	public List<VolumeVO> findByTemplateAndZone(long templateId, long zoneId) {
-		SearchCriteria<VolumeVO> sc = TemplateZoneSearch.create();
-		sc.setParameters("template", templateId);
-		sc.setParameters("zone", zoneId);
-		
-		return listIncludingRemovedBy(sc);
-	}
-
-	@Override
-	public boolean isAnyVolumeActivelyUsingTemplateOnPool(long templateId, long poolId) {
-	    SearchCriteria<Long> sc = ActiveTemplateSearch.create();
-	    sc.setParameters("template", templateId);
-	    sc.setParameters("pool", poolId);
-	    
-	    List<Long> results = customSearchIncludingRemoved(sc, null);
-	    assert results.size() > 0 : "How can this return a size of " + results.size();
-	    
-	    return results.get(0) > 0;
-	}
-	
+    }
+
+    @Override
+    public boolean isAnyVolumeActivelyUsingTemplateOnPool(long templateId, long poolId) {
+        SearchCriteria<Long> sc = ActiveTemplateSearch.create();
+        sc.setParameters("template", templateId);
+        sc.setParameters("pool", poolId);
+
+        List<Long> results = customSearchIncludingRemoved(sc, null);
+        assert results.size() > 0 : "How can this return a size of " + results.size();
+
+        return results.get(0) > 0;
+    }
+
     @Override
     public void deleteVolumesByInstance(long instanceId) {
         SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
         sc.setParameters("instanceId", instanceId);
         expunge(sc);
     }
-    
+
     @Override
     public void attachVolume(long volumeId, long vmId, long deviceId) {
-    	VolumeVO volume = createForUpdate(volumeId);
-    	volume.setInstanceId(vmId);
-    	volume.setDeviceId(deviceId);
-    	volume.setUpdated(new Date());
-    	volume.setAttached(new Date());
-    	update(volumeId, volume);
+        VolumeVO volume = createForUpdate(volumeId);
+        volume.setInstanceId(vmId);
+        volume.setDeviceId(deviceId);
+        volume.setUpdated(new Date());
+        volume.setAttached(new Date());
+        update(volumeId, volume);
     }
-    
+
     @Override
     public void detachVolume(long volumeId) {
-    	VolumeVO volume = createForUpdate(volumeId);
-    	volume.setInstanceId(null);
+        VolumeVO volume = createForUpdate(volumeId);
+        volume.setInstanceId(null);
         volume.setDeviceId(null);
-    	volume.setUpdated(new Date());
-    	volume.setAttached(null);
-    	update(volumeId, volume);
+        volume.setUpdated(new Date());
+        volume.setAttached(null);
+        update(volumeId, volume);
     }
-    
+
     @Override
     @DB
-	public HypervisorType getHypervisorType(long volumeId) {
-		/*lookup from cluster of pool*/
-    	 Transaction txn = Transaction.currentTxn();
-         PreparedStatement pstmt = null;
-
-         try {
-             String sql = SELECT_HYPERTYPE_FROM_VOLUME;
-             pstmt = txn.prepareAutoCloseStatement(sql);
-             pstmt.setLong(1, volumeId);
-             ResultSet rs = pstmt.executeQuery();
-             if (rs.next()) {
+    public HypervisorType getHypervisorType(long volumeId) {
+        /* lookup from cluster of pool */
+        Transaction txn = Transaction.currentTxn();
+        PreparedStatement pstmt = null;
+
+        try {
+            String sql = SELECT_HYPERTYPE_FROM_VOLUME;
+            pstmt = txn.prepareAutoCloseStatement(sql);
+            pstmt.setLong(1, volumeId);
+            ResultSet rs = pstmt.executeQuery();
+            if (rs.next()) {
                 return HypervisorType.getType(rs.getString(1));
             }
-             return HypervisorType.None;
-         } catch (SQLException e) {
-             throw new CloudRuntimeException("DB Exception on: " + SELECT_HYPERTYPE_FROM_VOLUME, e);
-         } catch (Throwable e) {
-             throw new CloudRuntimeException("Caught: " + SELECT_HYPERTYPE_FROM_VOLUME, e);
-         }
-	}
-    
+            return HypervisorType.None;
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("DB Exception on: " + SELECT_HYPERTYPE_FROM_VOLUME, e);
+        } catch (Throwable e) {
+            throw new CloudRuntimeException("Caught: " + SELECT_HYPERTYPE_FROM_VOLUME, e);
+        }
+    }
+
     @Override
     public ImageFormat getImageFormat(Long volumeId) {
         HypervisorType type = getHypervisorType(volumeId);
-        if ( type.equals(HypervisorType.KVM)) {
+        if (type.equals(HypervisorType.KVM)) {
             return ImageFormat.QCOW2;
-        } else if ( type.equals(HypervisorType.XenServer)) {
+        } else if (type.equals(HypervisorType.XenServer)) {
             return ImageFormat.VHD;
-        } else if ( type.equals(HypervisorType.VMware)) {
+        } else if (type.equals(HypervisorType.VMware)) {
             return ImageFormat.OVA;
         } else {
             s_logger.warn("Do not support hypervisor " + type.toString());
             return null;
         }
     }
-    
-	protected VolumeDaoImpl() {
-	    AllFieldsSearch = createSearchBuilder();
-	    AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ);
+
+    protected VolumeDaoImpl() {
+        AllFieldsSearch = createSearchBuilder();
+        AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ);
         AllFieldsSearch.and("accountId", AllFieldsSearch.entity().getAccountId(), Op.EQ);
         AllFieldsSearch.and("pod", AllFieldsSearch.entity().getPodId(), Op.EQ);
         AllFieldsSearch.and("instanceId", AllFieldsSearch.entity().getInstanceId(), Op.EQ);
@@ -262,33 +261,33 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
         AllFieldsSearch.and("notDestroyed", AllFieldsSearch.entity().getState(), Op.NEQ);
         AllFieldsSearch.and("updatedCount", AllFieldsSearch.entity().getUpdatedCount(), Op.EQ);
         AllFieldsSearch.done();
-        
+
         DetachedAccountIdSearch = createSearchBuilder();
         DetachedAccountIdSearch.and("accountId", DetachedAccountIdSearch.entity().getAccountId(), Op.EQ);
         DetachedAccountIdSearch.and("destroyed", DetachedAccountIdSearch.entity().getState(), Op.NEQ);
         DetachedAccountIdSearch.and("instanceId", DetachedAccountIdSearch.entity().getInstanceId(), Op.NULL);
         DetachedAccountIdSearch.done();
-        
+
         TemplateZoneSearch = createSearchBuilder();
         TemplateZoneSearch.and("template", TemplateZoneSearch.entity().getTemplateId(), Op.EQ);
         TemplateZoneSearch.and("zone", TemplateZoneSearch.entity().getDataCenterId(), Op.EQ);
         TemplateZoneSearch.done();
-        
+
         TotalSizeByPoolSearch = createSearchBuilder(SumCount.class);
         TotalSizeByPoolSearch.select("sum", Func.SUM, TotalSizeByPoolSearch.entity().getSize());
-        TotalSizeByPoolSearch.select("count", Func.COUNT, (Object[])null);
+        TotalSizeByPoolSearch.select("count", Func.COUNT, (Object[]) null);
         TotalSizeByPoolSearch.and("poolId", TotalSizeByPoolSearch.entity().getPoolId(), Op.EQ);
         TotalSizeByPoolSearch.and("removed", TotalSizeByPoolSearch.entity().getRemoved(), Op.NULL);
         TotalSizeByPoolSearch.and("state", TotalSizeByPoolSearch.entity().getState(), Op.NEQ);
         TotalSizeByPoolSearch.done();
-      
+
         ActiveTemplateSearch = createSearchBuilder(Long.class);
         ActiveTemplateSearch.and("pool", ActiveTemplateSearch.entity().getPoolId(), Op.EQ);
         ActiveTemplateSearch.and("template", ActiveTemplateSearch.entity().getTemplateId(), Op.EQ);
         ActiveTemplateSearch.and("removed", ActiveTemplateSearch.entity().getRemoved(), Op.NULL);
         ActiveTemplateSearch.select(null, Func.COUNT, null);
         ActiveTemplateSearch.done();
-        
+
         InstanceStatesSearch = createSearchBuilder();
         InstanceStatesSearch.and("instance", InstanceStatesSearch.entity().getInstanceId(), Op.EQ);
         InstanceStatesSearch.and("states", InstanceStatesSearch.entity().getState(), Op.IN);
@@ -297,75 +296,78 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
         CountByAccount = createSearchBuilder(Long.class);
         CountByAccount.select(null, Func.COUNT, null);
         CountByAccount.and("account", CountByAccount.entity().getAccountId(), SearchCriteria.Op.EQ);
-        CountByAccount.and("state", CountByAccount.entity().getState(), SearchCriteria.Op.NIN);        
+        CountByAccount.and("state", CountByAccount.entity().getState(), SearchCriteria.Op.NIN);
         CountByAccount.done();
-	}
+    }
 
-	@Override @DB(txn=false)
-	public Pair<Long, Long> getCountAndTotalByPool(long poolId) {
+    @Override
+    @DB(txn = false)
+    public Pair<Long, Long> getCountAndTotalByPool(long poolId) {
         SearchCriteria<SumCount> sc = TotalSizeByPoolSearch.create();
         sc.setParameters("poolId", poolId);
         List<SumCount> results = customSearch(sc, null);
         SumCount sumCount = results.get(0);
         return new Pair<Long, Long>(sumCount.count, sumCount.sum);
-	}
+    }
 
     @Override
-	public Long countAllocatedVolumesForAccount(long accountId) {
-	  	SearchCriteria<Long> sc = CountByAccount.create();
+    public Long countAllocatedVolumesForAccount(long accountId) {
+        SearchCriteria<Long> sc = CountByAccount.create();
         sc.setParameters("account", accountId);
-		sc.setParameters("state", Volume.State.Destroy);
-        return customSearch(sc, null).get(0);		
-	}
+        sc.setParameters("state", Volume.State.Destroy);
+        return customSearch(sc, null).get(0);
+    }
+
+    public static class SumCount {
+        public long sum;
+        public long count;
 
-	public static class SumCount {
-	    public long sum;
-	    public long count;
-	    public SumCount() {
-	    }
-	}
+        public SumCount() {
+        }
+    }
 
     @Override
     public List<VolumeVO> listVolumesToBeDestroyed() {
         SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
         sc.setParameters("state", Volume.State.Destroy);
-        
+
         return listBy(sc);
     }
 
-	@Override
-	public boolean updateState(Volume.State currentState,
-			VolumeEvent event, Volume.State nextState, VolumeVO vo,
-			Object data) {
-		
-	        Long oldUpdated = vo.getUpdatedCount();
-	        Date oldUpdatedTime = vo.getUpdated();
-	        
-	        SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
-	        sc.setParameters("id", vo.getId());
-	        sc.setParameters("state", currentState);
-	        sc.setParameters("updatedCount", vo.getUpdatedCount());
-	        
-	        vo.incrUpdatedCount();
-	        
-	        UpdateBuilder builder = getUpdateBuilder(vo);
-	        builder.set(vo, "state", nextState);
-	        builder.set(vo, "updated", new Date());
-	        
-	        int rows = update((VolumeVO)vo, sc);
-	        if (rows == 0 && s_logger.isDebugEnabled()) {
-	            VolumeVO dbVol = findByIdIncludingRemoved(vo.getId()); 
-	            if (dbVol != null) {
-	            	StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
-	            	str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState()).append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=").append(dbVol.getUpdated());
-	            	str.append(": New Data={id=").append(vo.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(vo.getUpdatedCount()).append("; updatedTime=").append(vo.getUpdated());
-	            	str.append(": stale Data={id=").append(vo.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated).append("; updatedTime=").append(oldUpdatedTime);
-	            } else {
-	            	s_logger.debug("Unable to update volume: id=" + vo.getId() + ", as there is no such volume exists in the database anymore");
-	            }
-	        }
-	        return rows > 0;
-	}
+    @Override
+    public boolean updateState(Volume.State currentState, VolumeEvent event, Volume.State nextState, VolumeVO vo, Object data) {
+
+        Long oldUpdated = vo.getUpdatedCount();
+        Date oldUpdatedTime = vo.getUpdated();
+
+        SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
+        sc.setParameters("id", vo.getId());
+        sc.setParameters("state", currentState);
+        sc.setParameters("updatedCount", vo.getUpdatedCount());
+
+        vo.incrUpdatedCount();
+
+        UpdateBuilder builder = getUpdateBuilder(vo);
+        builder.set(vo, "state", nextState);
+        builder.set(vo, "updated", new Date());
+
+        int rows = update((VolumeVO) vo, sc);
+        if (rows == 0 && s_logger.isDebugEnabled()) {
+            VolumeVO dbVol = findByIdIncludingRemoved(vo.getId());
+            if (dbVol != null) {
+                StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
+                str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState()).append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=")
+                        .append(dbVol.getUpdated());
+                str.append(": New Data={id=").append(vo.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(vo.getUpdatedCount())
+                        .append("; updatedTime=").append(vo.getUpdated());
+                str.append(": stale Data={id=").append(vo.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated)
+                        .append("; updatedTime=").append(oldUpdatedTime);
+            } else {
+                s_logger.debug("Unable to update volume: id=" + vo.getId() + ", as there is no such volume exists in the database anymore");
+            }
+        }
+        return rows > 0;
+    }
 
     @Override
     public List<Long> listPoolIdsByVolumeCount(long dcId, Long podId, Long clusterId, long accountId) {
@@ -379,7 +381,7 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
             pstmt.setLong(2, dcId);
             pstmt.setLong(3, podId);
             pstmt.setLong(4, clusterId);
-            
+
             ResultSet rs = pstmt.executeQuery();
             while (rs.next()) {
                 result.add(rs.getLong(1));
@@ -391,8 +393,9 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
             throw new CloudRuntimeException("Caught: " + ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT, e);
         }
     }
-    
-    @Override @DB(txn=false)
+
+    @Override
+    @DB(txn = false)
     public Pair<Long, Long> getNonDestroyedCountAndTotalByPool(long poolId) {
         SearchCriteria<SumCount> sc = TotalSizeByPoolSearch.create();
         sc.setParameters("poolId", poolId);
@@ -401,7 +404,7 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
         SumCount sumCount = results.get(0);
         return new Pair<Long, Long>(sumCount.count, sumCount.sum);
     }
-    
+
     @Override
     @DB
     public boolean remove(Long id) {
@@ -415,12 +418,12 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
         txn.commit();
         return result;
     }
-    
+
     @Override
     @DB
     public VolumeVO allocVolume(long size, VolumeType type, String volName, Long templateId) {
-    	VolumeVO vol = new VolumeVO(size, type.toString(), volName, templateId);
-    	vol = this.persist(vol);
-    	return vol;
+        VolumeVO vol = new VolumeVO(size, type.toString(), volName, templateId);
+        vol = this.persist(vol);
+        return vol;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeVO.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeVO.java b/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeVO.java
index fc9dbc5..04104f6 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeVO.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeVO.java
@@ -16,6 +16,7 @@
 //under the License.
 
 package org.apache.cloudstack.storage.volume.db;
+
 import java.util.Date;
 import java.util.UUID;
 
@@ -33,8 +34,6 @@ import javax.persistence.TemporalType;
 
 import org.apache.cloudstack.engine.subsystem.api.storage.disktype.Unknown;
 
-
-
 import com.cloud.api.Identity;
 import com.cloud.storage.Volume;
 import com.cloud.storage.Storage.StoragePoolType;
@@ -44,383 +43,383 @@ import com.cloud.utils.fsm.StateObject;
 
 @Entity
 @Table(name = "volumes")
-public class VolumeVO implements Identity, StateObject<Volume.State>{
- @Id
- @TableGenerator(name = "volume_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "volume_seq", allocationSize = 1)
- @GeneratedValue(strategy = GenerationType.TABLE)
- @Column(name = "id")
- long id;
-
- @Column(name = "name")
- String name;
-
- @Column(name = "pool_id")
- Long poolId;
- 
- @Column(name = "last_pool_id")
- Long lastPoolId;
- 
- @Column(name = "account_id")
- long accountId;
-
- @Column(name = "domain_id")
- long domainId;
-
- @Column(name = "instance_id")
- Long instanceId = null;
-
- @Column(name = "device_id")
- Long deviceId = null;
-
- @Column(name = "size")
- long size;
-
- @Column(name = "folder")
- String folder;
-
- @Column(name = "path")
- String path;
-
- @Column(name = "pod_id")
- Long podId;
-
- @Column(name = "created")
- Date created;
-
- @Column(name = "attached")
- @Temporal(value = TemporalType.TIMESTAMP)
- Date attached;
-
- @Column(name = "data_center_id")
- long dataCenterId;
-
- @Column(name = "host_ip")
- String hostip;
-
- @Column(name = "disk_offering_id")
- long diskOfferingId;
-
- @Column(name = "template_id")
- Long templateId;
-
- @Column(name = "first_snapshot_backup_uuid")
- String firstSnapshotBackupUuid;
-
- @Column(name = "volume_type")
- String volumeType = "UNKNOWN";
-
- @Column(name = "pool_type")
- @Enumerated(EnumType.STRING)
- StoragePoolType poolType;
- 
- @Column(name = "disk_type")
- String diskType = new Unknown().toString();
- 
- @Column(name = GenericDao.REMOVED_COLUMN)
- Date removed;
-
- @Column(name = "updated")
- @Temporal(value = TemporalType.TIMESTAMP)
- Date updated;
- 
- @Column(name="update_count", updatable = true, nullable=false)
- protected long updatedCount;	// This field should be updated everytime the state is updated.  There's no set method in the vo object because it is done with in the dao code.
-
- @Column(name = "recreatable")
- boolean recreatable;
-
- @Column(name = "state")
- @Enumerated(value = EnumType.STRING)
- private Volume.State state;
-
- @Column(name = "chain_info")
- String chainInfo;
-
- @Column(name = "uuid")
- String uuid;
- 
- @Column(name="reservation")
- String reservationId;
- 
- // Real Constructor
- public VolumeVO(long size, String type, String name, Long templateId) {
-     this.volumeType = type.toString();
-     this.size = size;
-     this.name = name;
-     this.templateId = templateId;
-     this.uuid = UUID.randomUUID().toString();
- }
-
- // Copy Constructor
- public VolumeVO(VolumeVO that) {
-     this(that.getSize(), that.getVolumeType(), that.getName(), that.getTemplateId());
-     this.recreatable = that.isRecreatable();
-     this.state = that.getState();
-     this.size = that.getSize();
-     this.diskOfferingId = that.getDiskOfferingId();
-     this.poolId = that.getPoolId();
-     this.attached = that.getAttached();
-     this.chainInfo = that.getChainInfo();
-     this.templateId = that.getTemplateId();
-     this.deviceId = that.getDeviceId();
-     this.uuid = UUID.randomUUID().toString();
- }
-
- public long getUpdatedCount() {
- 	return this.updatedCount;
- }
- 
- public void incrUpdatedCount() {
- 	this.updatedCount++;
- }
- 
- public void decrUpdatedCount() {
- 	this.updatedCount--;
- }
- 
- public boolean isRecreatable() {
-     return recreatable;
- }
-
- public void setRecreatable(boolean recreatable) {
-     this.recreatable = recreatable;
- }
-
- public long getId() {
-     return id;
- }
-
-
- public Long getPodId() {
-     return podId;
- }
-
-
- public long getDataCenterId() {
-     return dataCenterId;
- }
-
- public String getName() {
-     return name;
- }
-
- public long getAccountId() {
-     return accountId;
- }
-
- public void setPoolType(StoragePoolType poolType) {
-     this.poolType = poolType;
- }
-
- public StoragePoolType getPoolType() {
-     return poolType;
- }
-
- public long getDomainId() {
-     return domainId;
- }
-
- public String getFolder() {
-     return folder;
- }
-
- public String getPath() {
-     return path;
- }
-
- protected VolumeVO() {
- }
-
- public long getSize() {
-     return size;
- }
-
- public void setSize(long size) {
-     this.size = size;
- }
-
- public Long getInstanceId() {
-     return instanceId;
- }
-
- public Long getDeviceId() {
-     return deviceId;
- }
-
- public void setDeviceId(Long deviceId) {
-     this.deviceId = deviceId;
- }
-
- public String getVolumeType() {
-     return volumeType;
- }
-
- public void setName(String name) {
-     this.name = name;
- }
-
- public void setFolder(String folder) {
-     this.folder = folder;
- }
-
- public void setAccountId(long accountId) {
-     this.accountId = accountId;
- }
-
- public void setDomainId(long domainId) {
-     this.domainId = domainId;
- }
-
- public void setInstanceId(Long instanceId) {
-     this.instanceId = instanceId;
- }
-
- public void setPath(String path) {
-     this.path = path;
- }
-
- public String getHostIp() {
-     return hostip;
- }
-
- public void setHostIp(String hostip) {
-     this.hostip = hostip;
- }
-
- public void setPodId(Long podId) {
-     this.podId = podId;
- }
-
- public void setDataCenterId(long dataCenterId) {
-     this.dataCenterId = dataCenterId;
- }
-
- public void setVolumeType(String type) {
-     volumeType = type;
- }
-
- public Date getCreated() {
-     return created;
- }
-
- public Date getRemoved() {
-     return removed;
- }
-
- public void setRemoved(Date removed) {
-     this.removed = removed;
- }
-
- public long getDiskOfferingId() {
-     return diskOfferingId;
- }
-
- public void setDiskOfferingId(long diskOfferingId) {
-     this.diskOfferingId = diskOfferingId;
- }
-
- public Long getTemplateId() {
-     return templateId;
- }
-
- public void setTemplateId(Long templateId) {
-     this.templateId = templateId;
- }
-
- public String getFirstSnapshotBackupUuid() {
-     return firstSnapshotBackupUuid;
- }
-
- public void setFirstSnapshotBackupUuid(String firstSnapshotBackupUuid) {
-     this.firstSnapshotBackupUuid = firstSnapshotBackupUuid;
- }
-
- public Long getPoolId() {
-     return poolId;
- }
-
- public void setPoolId(Long poolId) {
-     this.poolId = poolId;
- }
-
- public Date getUpdated() {
-     return updated;
- }
-
- public Volume.State getState() {
-     return state;
- }
-
- public void setUpdated(Date updated) {
-     this.updated = updated;
- }
-
- @Override
- public String toString() {
-     return new StringBuilder("Vol[").append(id).append("|vm=").append(instanceId).append("|").append(volumeType).append("]").toString();
- }
-
- public Date getAttached() {
-     return this.attached;
- }
-
- public void setAttached(Date attached) {
-     this.attached = attached;
- }
- 
- public String getChainInfo() {
-     return this.chainInfo;
- }
-
- public void setChainInfo(String chainInfo) {
-     this.chainInfo = chainInfo;
- }
- 
- public Long getLastPoolId() {
- 	return this.lastPoolId;
- }
- 
- public void setLastPoolId(Long poolId) {
- 	this.lastPoolId = poolId;
- }
-
- @Override
- public int hashCode() {
-     return NumbersUtil.hash(id);
- }
-
- @Override
- public boolean equals(Object obj) {
-     if (obj instanceof VolumeVO) {
-         return id == ((VolumeVO) obj).id;
-     } else {
-         return false;
-     }
- }
- 
- public String getReservationId() {
- 	return this.reservationId;
- }
-
- public void setReservationId(String reserv) {
- 	this.reservationId = reserv;
- }
- 
- @Override
- public String getUuid() {
- 	return this.uuid;
- }
- 
- public void setUuid(String uuid) {
- 	this.uuid = uuid;
- }
- 
- public String getDiskType() {
-	 return diskType;
- }
- 
- public void setDiskType(String type) {
-	 diskType = type;
- }
-}
+public class VolumeVO implements Identity, StateObject<Volume.State> {
+    @Id
+    @TableGenerator(name = "volume_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "volume_seq", allocationSize = 1)
+    @GeneratedValue(strategy = GenerationType.TABLE)
+    @Column(name = "id")
+    long id;
+
+    @Column(name = "name")
+    String name;
+
+    @Column(name = "pool_id")
+    Long poolId;
+
+    @Column(name = "last_pool_id")
+    Long lastPoolId;
+
+    @Column(name = "account_id")
+    long accountId;
+
+    @Column(name = "domain_id")
+    long domainId;
+
+    @Column(name = "instance_id")
+    Long instanceId = null;
+
+    @Column(name = "device_id")
+    Long deviceId = null;
+
+    @Column(name = "size")
+    long size;
+
+    @Column(name = "folder")
+    String folder;
+
+    @Column(name = "path")
+    String path;
+
+    @Column(name = "pod_id")
+    Long podId;
+
+    @Column(name = "created")
+    Date created;
+
+    @Column(name = "attached")
+    @Temporal(value = TemporalType.TIMESTAMP)
+    Date attached;
+
+    @Column(name = "data_center_id")
+    long dataCenterId;
+
+    @Column(name = "host_ip")
+    String hostip;
+
+    @Column(name = "disk_offering_id")
+    long diskOfferingId;
+
+    @Column(name = "template_id")
+    Long templateId;
+
+    @Column(name = "first_snapshot_backup_uuid")
+    String firstSnapshotBackupUuid;
+
+    @Column(name = "volume_type")
+    String volumeType = "UNKNOWN";
 
+    @Column(name = "pool_type")
+    @Enumerated(EnumType.STRING)
+    StoragePoolType poolType;
+
+    @Column(name = "disk_type")
+    String diskType = new Unknown().toString();
+
+    @Column(name = GenericDao.REMOVED_COLUMN)
+    Date removed;
+
+    @Column(name = "updated")
+    @Temporal(value = TemporalType.TIMESTAMP)
+    Date updated;
+
+    @Column(name = "update_count", updatable = true, nullable = false)
+    protected long updatedCount; // This field should be updated everytime the
+                                 // state is updated. There's no set method in
+                                 // the vo object because it is done with in the
+                                 // dao code.
+
+    @Column(name = "recreatable")
+    boolean recreatable;
+
+    @Column(name = "state")
+    @Enumerated(value = EnumType.STRING)
+    private Volume.State state;
+
+    @Column(name = "chain_info")
+    String chainInfo;
+
+    @Column(name = "uuid")
+    String uuid;
+
+    @Column(name = "reservation")
+    String reservationId;
+
+    // Real Constructor
+    public VolumeVO(long size, String type, String name, Long templateId) {
+        this.volumeType = type.toString();
+        this.size = size;
+        this.name = name;
+        this.templateId = templateId;
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    // Copy Constructor
+    public VolumeVO(VolumeVO that) {
+        this(that.getSize(), that.getVolumeType(), that.getName(), that.getTemplateId());
+        this.recreatable = that.isRecreatable();
+        this.state = that.getState();
+        this.size = that.getSize();
+        this.diskOfferingId = that.getDiskOfferingId();
+        this.poolId = that.getPoolId();
+        this.attached = that.getAttached();
+        this.chainInfo = that.getChainInfo();
+        this.templateId = that.getTemplateId();
+        this.deviceId = that.getDeviceId();
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    public long getUpdatedCount() {
+        return this.updatedCount;
+    }
+
+    public void incrUpdatedCount() {
+        this.updatedCount++;
+    }
+
+    public void decrUpdatedCount() {
+        this.updatedCount--;
+    }
+
+    public boolean isRecreatable() {
+        return recreatable;
+    }
+
+    public void setRecreatable(boolean recreatable) {
+        this.recreatable = recreatable;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public Long getPodId() {
+        return podId;
+    }
+
+    public long getDataCenterId() {
+        return dataCenterId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public long getAccountId() {
+        return accountId;
+    }
+
+    public void setPoolType(StoragePoolType poolType) {
+        this.poolType = poolType;
+    }
+
+    public StoragePoolType getPoolType() {
+        return poolType;
+    }
+
+    public long getDomainId() {
+        return domainId;
+    }
+
+    public String getFolder() {
+        return folder;
+    }
+
+    public String getPath() {
+        return path;
+    }
+
+    protected VolumeVO() {
+    }
+
+    public long getSize() {
+        return size;
+    }
+
+    public void setSize(long size) {
+        this.size = size;
+    }
+
+    public Long getInstanceId() {
+        return instanceId;
+    }
+
+    public Long getDeviceId() {
+        return deviceId;
+    }
+
+    public void setDeviceId(Long deviceId) {
+        this.deviceId = deviceId;
+    }
+
+    public String getVolumeType() {
+        return volumeType;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setFolder(String folder) {
+        this.folder = folder;
+    }
+
+    public void setAccountId(long accountId) {
+        this.accountId = accountId;
+    }
+
+    public void setDomainId(long domainId) {
+        this.domainId = domainId;
+    }
+
+    public void setInstanceId(Long instanceId) {
+        this.instanceId = instanceId;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    public String getHostIp() {
+        return hostip;
+    }
+
+    public void setHostIp(String hostip) {
+        this.hostip = hostip;
+    }
+
+    public void setPodId(Long podId) {
+        this.podId = podId;
+    }
+
+    public void setDataCenterId(long dataCenterId) {
+        this.dataCenterId = dataCenterId;
+    }
+
+    public void setVolumeType(String type) {
+        volumeType = type;
+    }
+
+    public Date getCreated() {
+        return created;
+    }
+
+    public Date getRemoved() {
+        return removed;
+    }
+
+    public void setRemoved(Date removed) {
+        this.removed = removed;
+    }
+
+    public long getDiskOfferingId() {
+        return diskOfferingId;
+    }
+
+    public void setDiskOfferingId(long diskOfferingId) {
+        this.diskOfferingId = diskOfferingId;
+    }
+
+    public Long getTemplateId() {
+        return templateId;
+    }
+
+    public void setTemplateId(Long templateId) {
+        this.templateId = templateId;
+    }
+
+    public String getFirstSnapshotBackupUuid() {
+        return firstSnapshotBackupUuid;
+    }
+
+    public void setFirstSnapshotBackupUuid(String firstSnapshotBackupUuid) {
+        this.firstSnapshotBackupUuid = firstSnapshotBackupUuid;
+    }
+
+    public Long getPoolId() {
+        return poolId;
+    }
+
+    public void setPoolId(Long poolId) {
+        this.poolId = poolId;
+    }
+
+    public Date getUpdated() {
+        return updated;
+    }
+
+    public Volume.State getState() {
+        return state;
+    }
+
+    public void setUpdated(Date updated) {
+        this.updated = updated;
+    }
+
+    @Override
+    public String toString() {
+        return new StringBuilder("Vol[").append(id).append("|vm=").append(instanceId).append("|").append(volumeType).append("]").toString();
+    }
+
+    public Date getAttached() {
+        return this.attached;
+    }
+
+    public void setAttached(Date attached) {
+        this.attached = attached;
+    }
+
+    public String getChainInfo() {
+        return this.chainInfo;
+    }
+
+    public void setChainInfo(String chainInfo) {
+        this.chainInfo = chainInfo;
+    }
+
+    public Long getLastPoolId() {
+        return this.lastPoolId;
+    }
+
+    public void setLastPoolId(Long poolId) {
+        this.lastPoolId = poolId;
+    }
+
+    @Override
+    public int hashCode() {
+        return NumbersUtil.hash(id);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof VolumeVO) {
+            return id == ((VolumeVO) obj).id;
+        } else {
+            return false;
+        }
+    }
+
+    public String getReservationId() {
+        return this.reservationId;
+    }
+
+    public void setReservationId(String reserv) {
+        this.reservationId = reserv;
+    }
+
+    @Override
+    public String getUuid() {
+        return this.uuid;
+    }
+
+    public void setUuid(String uuid) {
+        this.uuid = uuid;
+    }
+
+    public String getDiskType() {
+        return diskType;
+    }
+
+    public void setDiskType(String type) {
+        diskType = type;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/test/org/apache/cloudstack/storage/test/storageContext.xml
----------------------------------------------------------------------
diff --git a/engine/storage/test/org/apache/cloudstack/storage/test/storageContext.xml b/engine/storage/test/org/apache/cloudstack/storage/test/storageContext.xml
deleted file mode 100644
index c32004b..0000000
--- a/engine/storage/test/org/apache/cloudstack/storage/test/storageContext.xml
+++ /dev/null
@@ -1,67 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
-  xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
-  xsi:schemaLocation="http://www.springframework.org/schema/beans
-                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
-                         http://www.springframework.org/schema/tx 
-       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
-       http://www.springframework.org/schema/aop
-       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
-                                 http://www.springframework.org/schema/context
-                                          http://www.springframework.org/schema/context/spring-context-3.0.xsd">
-  <context:annotation-config />
-  <context:component-scan base-package="org.apache.cloudstack.storage" />
-  <context:component-scan base-package="com.cloud.utils.db" />
-  <context:component-scan base-package="com.cloud.utils.component" />
-  <context:component-scan base-package="com.cloud.storage.dao" />
- 
-   <context:component-scan base-package=" com.cloud.upgrade.dao" />
-  <tx:annotation-driven transaction-manager="transactionManager" />
-  <bean id="aopTestBean" class="org.apache.cloudstack.storage.test.AopTestAdvice"/>
-  <aop:config proxy-target-class="true" >
-    <aop:aspect id="AopTestAdvice" ref="aopTestBean">
-    <aop:pointcut id="aoptest"
-      expression="@annotation(com.cloud.utils.db.DB)" />
-      <aop:around pointcut-ref="aoptest" method="AopTestMethod"/> 
-    </aop:aspect>
-    
-
-  </aop:config>
-  <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
-    <property name="entityManagerFactory" ref="entityManagerFactory" />
-  </bean>
-
-  <bean id="dataSource"
-    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
-    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
-    <property name="url" value="jdbc:mysql://localhost:3306/cloud" />
-    <property name="username" value="root" />
-    <property name="password" value="" />
-  </bean>
-
-  <bean id="openJpaVendorAdapter"
-    class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
-    <property name="showSql" value="true" />
-    <property name="databasePlatform"
-      value="org.apache.openjpa.jdbc.sql.MySQLDictionary" />
-  </bean>
-
-  <bean id="entityManagerFactory"
-    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
-    <property name="dataSource" ref="dataSource" />
-    <property name="jpaVendorAdapter" ref="openJpaVendorAdapter" />
-    <property name="packagesToScan" value="org.apache.cloudstack.storage" />
-  </bean>
-
-  <bean id="sharedEntityManager"
-    class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
-    <property name="entityManagerFactory" ref="entityManagerFactory" />
-  </bean>
-
-  <bean id="someDependencyMock" class="org.apache.cloudstack.storage.test.StorageFactoryBean">
-    <constructor-arg name="classToBeMocked"
-      value="org.apache.cloudstack.storage.volume.VolumeMotionService" />
-  </bean>
-
-</beans>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java
----------------------------------------------------------------------
diff --git a/engine/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java b/engine/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java
index ebd41ed..d096cd5 100644
--- a/engine/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java
+++ b/engine/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java
@@ -21,11 +21,13 @@ package org.apache.cloudstack.storage.test;
 import static org.junit.Assert.*;
 
 import java.awt.List;
+import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
 import javax.inject.Inject;
+import javax.naming.ConfigurationException;
 
 import org.apache.cloudstack.engine.subsystem.api.storage.disktype.QCOW2;
 import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VHD;
@@ -35,23 +37,18 @@ import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskTyp
 import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeTypeHelper;
 import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStoreImpl;
 import org.apache.cloudstack.storage.datastore.provider.DefaultPrimaryDatastoreProviderImpl;
-import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProvider;
 import org.apache.cloudstack.storage.image.format.ISO;
 import org.apache.cloudstack.storage.image.format.ImageFormat;
 import org.apache.cloudstack.storage.image.format.ImageFormatHelper;
 import org.apache.cloudstack.storage.image.format.OVA;
 import org.apache.cloudstack.storage.image.format.Unknown;
-import org.apache.cloudstack.storage.volume.VolumeMotionService;
-import org.apache.cloudstack.storage.volume.VolumeService;
-import org.apache.cloudstack.storage.volume.db.VolumeDao;
+import org.apache.cloudstack.storage.image.provider.ImageDataStoreProviderManager;
 
 import org.junit.Before;
 import org.junit.Test;
+
 import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
+
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 import org.mockito.Mockito.*;
@@ -61,37 +58,25 @@ import com.cloud.utils.component.ComponentInject;
 import com.cloud.utils.db.DB;
 
 @RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations="storageContext.xml")
+@ContextConfiguration(locations="classpath:/resource/storageContext.xml")
 public class volumeServiceTest {
-	@Autowired
-	protected VolumeService volService;
-	@Inject
-	protected VolumeDao volumeDao;
-	@Autowired
-	protected VolumeMotionService vmotion;
+    @Inject
+    ImageDataStoreProviderManager imageProviderMgr;
 	@Before
 	public void setUp() {
-		Mockito.when(vmotion.copyVolume(null, null)).thenReturn(false);
+		
 	}
 	
-	@DB
+	@Test
 	public void test() {
-		assertTrue(volService.deleteVolume(1) != false);
-		assertNotNull(volumeDao);
-		//VolumeVO vol = new VolumeVO(Volume.Type.DATADISK, "test", 1, 2, 2, 1, 1);
-		//volumeDao.persist(vol);
-		/*
-		VolumeVO volume = new VolumeVO();
-		String name = "test";
-		long size = 100;
-		volume.setName(name);
-		volume.setSize(size);
-		volumeDao.persist(volume);
-		VolumeVO newVol = volumeDao.getVolumeByName(name);
-		assertTrue(newVol.getSize() == volume.getSize());
-		*/
-
-		fail("Not yet implemented");
+	    try {
+	        
+            imageProviderMgr.configure("image Provider", new HashMap<String, Object>());
+            
+        } catch (ConfigurationException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
 	}
 	
 	//@Test

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/engine/storage/test/resource/storageContext.xml
----------------------------------------------------------------------
diff --git a/engine/storage/test/resource/storageContext.xml b/engine/storage/test/resource/storageContext.xml
new file mode 100644
index 0000000..0dab1f5
--- /dev/null
+++ b/engine/storage/test/resource/storageContext.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
+  xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans
+                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+                         http://www.springframework.org/schema/tx 
+       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
+       http://www.springframework.org/schema/aop
+       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+                                 http://www.springframework.org/schema/context
+                                          http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+  <context:annotation-config />
+  <context:component-scan base-package="org.apache.cloudstack.storage" />
+  <context:component-scan base-package="com.cloud.utils.db" />
+  <context:component-scan base-package="com.cloud.utils.component" />
+  
+ 
+   <context:component-scan base-package=" com.cloud.upgrade.dao" />
+  <tx:annotation-driven transaction-manager="transactionManager" />
+  <bean id="aopTestBean" class="org.apache.cloudstack.storage.test.AopTestAdvice"/>
+  <aop:config proxy-target-class="true" >
+    <aop:aspect id="AopTestAdvice" ref="aopTestBean">
+    <aop:pointcut id="aoptest"
+      expression="@annotation(com.cloud.utils.db.DB)" />
+      <aop:around pointcut-ref="aoptest" method="AopTestMethod"/> 
+    </aop:aspect>
+    
+
+  </aop:config>
+  <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
+    <property name="entityManagerFactory" ref="entityManagerFactory" />
+  </bean>
+
+  <bean id="dataSource"
+    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
+    <property name="url" value="jdbc:mysql://localhost:3306/cloud" />
+    <property name="username" value="root" />
+    <property name="password" value="" />
+  </bean>
+
+  <bean id="openJpaVendorAdapter"
+    class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
+    <property name="showSql" value="true" />
+    <property name="databasePlatform"
+      value="org.apache.openjpa.jdbc.sql.MySQLDictionary" />
+  </bean>
+
+  <bean id="entityManagerFactory"
+    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+    <property name="dataSource" ref="dataSource" />
+    <property name="jpaVendorAdapter" ref="openJpaVendorAdapter" />
+    <property name="packagesToScan" value="org.apache.cloudstack.storage" />
+  </bean>
+
+  <bean id="sharedEntityManager"
+    class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
+    <property name="entityManagerFactory" ref="entityManagerFactory" />
+  </bean>
+
+  <bean id="someDependencyMock" class="org.apache.cloudstack.storage.test.StorageFactoryBean">
+    <constructor-arg name="classToBeMocked"
+      value="org.apache.cloudstack.storage.volume.VolumeMotionService" />
+  </bean>
+
+</beans>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/573d13dd/server/src/com/cloud/storage/dao/VolumeDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/dao/VolumeDaoImpl.java b/server/src/com/cloud/storage/dao/VolumeDaoImpl.java
index 37f8fcf..065f50b 100755
--- a/server/src/com/cloud/storage/dao/VolumeDaoImpl.java
+++ b/server/src/com/cloud/storage/dao/VolumeDaoImpl.java
@@ -50,7 +50,6 @@ import com.cloud.utils.db.Transaction;
 import com.cloud.utils.db.UpdateBuilder;
 import com.cloud.utils.exception.CloudRuntimeException;
 
-@Component
 @Local(value=VolumeDao.class)
 public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements VolumeDao {
     private static final Logger s_logger = Logger.getLogger(VolumeDaoImpl.class);


Mime
View raw message