ResourcePoolService implements IResourcePoolService { public synchronized List<String> addAutoResourcePools( List<VcCluster> vcClusters, boolean ignoreDuplicate) { List<String> rpNames = new ArrayList<String>(); for (VcCluster vcCluster : vcClusters) { List<String> vcRps = vcCluster.getVcRps(); if (vcRps == null) { vcRps = new ArrayList<String>(); } if (vcRps.isEmpty()) { vcRps.add(""); } for (String vcRp : vcRps) { if (ignoreDuplicate && rpDao.isRPAdded(vcCluster.getName(), vcRp)) { rpNames.add(rpDao.getNameByClusterAndRp(vcCluster.getName(), vcRp)); continue; } addAutoResourcePool(rpNames, vcCluster, vcRp); } } return rpNames; }  IResourcePoolDAO getRpDao(); @Autowired void setRpDao(IResourcePoolDAO rpDao); IClusterDAO getClusterDao(); @Autowired void setClusterDao(IClusterDAO clusterDao); IResourceService getResService(); @Autowired void setResService(IResourceService resSvc); @Override List<VcCluster> getAllVcResourcePool(); @Override synchronized void addResourcePool(String rpName,
         String vcClusterName, String vcResourcePool); @Override List<VcCluster> getVcResourcePoolByName(String name); @Override List<VcCluster> getVcResourcePoolByNameList(String[] names); @Override Set<String> getAllRPNames(); @Override @Transactional List<ResourcePoolRead> getAllResourcePoolForRest(); @Override @Transactional ResourcePoolRead getResourcePoolForRest(final String rpName); @Override @Transactional synchronized void deleteResourcePool(final String rpName); @Override boolean isDeployedUnderCluster(final String clusterName,
         final String vcRPName); synchronized List<String> addAutoResourcePools(
         List<VcCluster> vcClusters, boolean ignoreDuplicate); @Override synchronized void updateResourcePool(String rpName,
         String vcClusterName, String vcResourcePool);  }
@Test(groups = { "res-mgmt" }, expectedExceptions = VcProviderException.class) public void testAddAutoResourcePools() { new Expectations() { { rpDao.findByName(anyString); result = null; rpDao.isRPAdded(anyString, anyString); result = true; } }; rpSvc.setRpDao(rpDao); rpSvc.setResService(resService); List<String> rps = new ArrayList<String>(); rps.add("rp1"); rps.add("rp2"); VcCluster cluster1 = Mockito.mock(VcCluster.class); Mockito.when(cluster1.getName()).thenReturn("cluster1"); Mockito.when(cluster1.getVcRps()).thenReturn(rps); List<VcCluster> clusters = new ArrayList<VcCluster>(); clusters.add(cluster1); rpSvc.addAutoResourcePools(clusters, false); }