DatastoreService implements IDatastoreService { @Override @Transactional public void deleteDatastore(String name) { logger.debug("delete datastore " + name); final List<VcDatastoreEntity> entities = dsDao.findByName(name); if (entities.isEmpty()) { throw VcProviderException.DATASTORE_NOT_FOUND(name); } List<String> provisioningClusterList = getClusterDao().findClusterByStatus( EnumSet.of(ClusterStatus.PROVISIONING, ClusterStatus.EXPANDING)); if (!provisioningClusterList.isEmpty()) { logger.error("cannot remove datastore, since some clusters are under provisioning."); throw VcProviderException.CLUSTER_UNDER_PROVISIONING(); } final Set<String> patterns = new HashSet<String>(); for (VcDatastoreEntity entity : entities) { if (entity.getRegex() != null && entity.getRegex()) { patterns.add(entity.getVcDatastore()); } else { patterns.add(CommonUtil.getDatastoreJavaPattern(entity.getVcDatastore())); } } List<String> clusterNames = getClusterDao().findClustersByUsedDatastores(patterns); if (!clusterNames.isEmpty()) { logger.error("cannot remove datastore, since following clusters referenced this datastore: " + clusterNames); throw VcProviderException .DATASTORE_IS_REFERENCED_BY_CLUSTER(clusterNames); } for (VcDatastoreEntity entity : entities) { dsDao.delete(entity); } logger.debug("successfully deleted datastore " + name); }  IDatastoreDAO getDsDao(); @Autowired void setDsDao(IDatastoreDAO dsDao); IClusterDAO getClusterDao(); @Autowired void setClusterDao(IClusterDAO clusterDao); IResourceService getResService(); @Autowired void setResService(IResourceService resManager); @Override @Transactional(readOnly = true) Set<String> getAllSharedDatastores(); @Override @Transactional(readOnly = true) Set<String> getSharedDatastoresByNames(List<String> nameList); @Override @Transactional(readOnly = true) Set<String> getLocalDatastoresByNames(List<String> nameList); @Override @Transactional(readOnly = true) Set<String> getAllLocalDatastores(); @Override @Transactional(readOnly = true) Set<String> getDatastoresByName(String name); @Override @Transactional(readOnly = true) Set<String> getDatastoresByNames(List<String> nameList); @Override @Transactional void addDatastores(DatastoreAdd datastore); @Override @Transactional void addDatastores(String name, DatastoreType type, List<String> spec, boolean regex); @Override @Transactional(readOnly = true) Set<String> getAllDatastoreNames(); @Override @Transactional(readOnly = true) DatastoreRead getDatastoreRead(String name); @Override @Transactional(readOnly = true) List<DatastoreRead> getAllDatastoreReads(); @Override @Transactional void deleteDatastore(String name);  }
@Test(groups = { "res-mgmt" }) public void testDeleteDatastore() { new NonStrictExpectations() { { dsDao.findByName(anyString); result = dss; Set<String> names = new HashSet<String>(); names.add("datastore1"); List<String> clusters = new ArrayList<String>(); clusterDao.findClustersByUsedDatastores(names); result = clusters; } }; datastoreSvc.setDsDao(dsDao); datastoreSvc.setClusterDao(clusterDao); datastoreSvc.deleteDatastore("testDS"); new Verifications() { { dsDao.delete(withAny(ds)); } }; }