ResourceInitializerService implements IResourceInitializerService { @Override @Transactional @RetryTransaction(2) public void addResourceIntoDB(String clusterName, String vcRPName, String networkName, Map<DatastoreType, List<String>> dsNames) { rpSvc.addResourcePool(DEFAULT_RP, clusterName, vcRPName); logger.info("added resource pool with vc rp:" + vcRPName); if (!dsNames.get(DatastoreType.SHARED).isEmpty()) { dsSvc.addDatastores(DEFAULT_DS_SHARED, DatastoreType.SHARED, dsNames.get(DatastoreType.SHARED), false); } else if (!dsNames.get(DatastoreType.LOCAL).isEmpty()) { dsSvc.addDatastores(DEFAULT_DS_LOCAL, DatastoreType.LOCAL, dsNames.get(DatastoreType.LOCAL), false); } logger.info("added datastore. " + dsNames); if (networkName != null) { networkSvc.addDhcpNetwork(DEFAULT_NETWORK, networkName, NetworkDnsType.NORMAL); logger.info("added network:" + networkName); } }  IServerInfoDAO getServerInfoDao(); @Autowired void setServerInfoDao(IServerInfoDAO serverInfoDao); IResourcePoolService getRpSvc(); @Autowired void setRpSvc(IResourcePoolService rpSvc); IDatastoreService getDsSvc(); @Autowired void setDsSvc(IDatastoreService dsSvc); INetworkService getNetworkSvc(); @Autowired void setNetworkSvc(INetworkService networkSvc); @Override void initResource(); @Override @Transactional @RetryTransaction(2) void addResourceIntoDB(String clusterName, String vcRPName,
         String networkName, Map<DatastoreType, List<String>> dsNames); @Override @Transactional(readOnly = true) boolean isResourceInitialized(); @Override @Transactional @RetryTransaction(2) void updateOrInsertServerInfo(); static final String DEFAULT_NETWORK; static final String DEFAULT_DS_SHARED; static final String DEFAULT_DS_LOCAL; static final String DEFAULT_RP; }
@Test(groups = { "res-mgmt"}) public void addResourceIntoDB() { rpSvc = new MockUp<IResourcePoolService>() { @Mock void addResourcePool(String rpName, String vcClusterName, String vcResourcePool) { logger.info("mock rp service to add rp"); Assert.assertEquals(rpName, "defaultRP"); Assert.assertEquals(vcClusterName, "testCluster"); Assert.assertEquals(vcResourcePool, "serengetiRP"); } }.getMockInstance(); dsSvc = new MockUp<IDatastoreService>() { @Mock void addDatastores(String name, DatastoreType type, List<String> spec, boolean regex) { logger.info("mock datastore service to add ds"); Assert.assertEquals(name, "defaultDSShared"); Assert.assertEquals(type, DatastoreType.SHARED); Assert.assertEquals(spec.size(), 1); Assert.assertEquals(regex, false); } }.getMockInstance(); networkSvc = new MockUp<INetworkService>() { @Mock NetworkEntity addDhcpNetwork(final String name, final String portGroup, NetworkDnsType dnsType) { Assert.assertEquals(dnsType, NetworkDnsType.NORMAL); Assert.assertEquals(name, "defaultNetwork"); Assert.assertEquals(portGroup, "serengetiNet"); return new NetworkEntity(); } }.getMockInstance(); service.setRpSvc(rpSvc); service.setDsSvc(dsSvc); service.setNetworkSvc(networkSvc); Map<DatastoreType, List<String>> dsMaps = new HashMap<DatastoreType, List<String>>(); List<String> dsNames = new ArrayList<String>(); dsNames.add("datastore1"); dsMaps.put(DatastoreType.SHARED, dsNames); service.addResourceIntoDB("testCluster", "serengetiRP", "serengetiNet", dsMaps); }