AppManagerService implements IAppManagerService { @Override @Transactional public void deleteAppManager(String name) { logger.debug("delete app manager " + name); AppManagerEntity entity = appManagerDAO.findByName(name); if (entity == null) { logger.error("Cannot find app manager " + name); throw SoftwareManagerCollectorException.APPMANAGER_NOT_FOUND(name); } List<String> clusterNames = getClusterDao().findClustersByAppManager(name); if (null != clusterNames && !clusterNames.isEmpty()) { logger.error("Cannot delete app manager " + name + " because it is used by the following clusters " + clusterNames + "."); throw SoftwareManagerCollectorException.CAN_NOT_DELETE(name, clusterNames); } appManagerDAO.delete(entity); logger.debug("successfully deleted app manager " + name); }  IAppManagerDAO getAppManagerDAO(); @Autowired void setAppManagerDAO(IAppManagerDAO appManagerDAO); IClusterDAO getClusterDao(); @Autowired void setClusterDao(IClusterDAO clusterDao); @Override @Transactional synchronized void addAppManager(AppManagerAdd appManagerAdd); @Override @Transactional(readOnly = true) AppManagerEntity findAppManagerByName(String name); @Override @Transactional(readOnly = true) AppManagerRead getAppManagerRead(String name); @Override @Transactional(readOnly = true) List<AppManagerRead> getAllAppManagerReads(); @Override @Transactional(readOnly = true) List<AppManagerEntity> findAll(); @Override @Transactional void deleteAppManager(String name); @Override @Transactional void modifyAppManager(AppManagerAdd appManagerAdd);  }
@Test(groups = { "res-mgmt" }) public void testDeleteAppManager() { new NonStrictExpectations() { { appManagerDAO.findByName(anyString); result = appMgrList; List<String> clusters = new ArrayList<String>(); clusterDAO.findClustersByAppManager(anyString); result = clusters; } }; appMgrSvc.setAppManagerDAO(appManagerDAO); appMgrSvc.setClusterDao(clusterDAO); appMgrSvc.deleteAppManager("testAppMgr"); new Verifications() { { appManagerDAO.delete(withAny(appMgrEntity)); } }; }