NetworkService implements Serializable, INetworkService { @Override @Transactional public synchronized NetworkEntity addIpPoolNetwork(final String name, final String portGroup, final String netmask, final String gateway, final String dns1, final String dns2, final List<IpBlock> ipBlocks, final NetworkDnsType dnsType) { try { validateNetworkName(name); if (!resService.isNetworkExistInVc(portGroup)) { throw VcProviderException.NETWORK_NOT_FOUND(portGroup); } NetworkEntity network = new NetworkEntity(name, portGroup, AllocType.IP_POOL, netmask, gateway, dns1, dns2, dnsType); networkDao.insert(network); List<IpBlockEntity> blocks = new ArrayList<IpBlockEntity>(ipBlocks.size()); for (IpBlock ib : ipBlocks) { IpBlockEntity blk = new IpBlockEntity(null, IpBlockEntity.FREE_BLOCK_OWNER_ID, BlockType.FREE, IpAddressUtil.getAddressAsLong(ib .getBeginIp()), IpAddressUtil.getAddressAsLong(ib .getEndIp())); blocks.add(blk); } checkIpBlockOverlap(name, blocks, portGroup); networkDao.addIpBlocks(network, blocks); network.validate(); return network; } catch (UniqueConstraintViolationException ex) { logger.error("can not add a network with duplicated name"); throw BddException.ALREADY_EXISTS(ex, "Network", name); } }  INetworkDAO getNetworkDao(); @Autowired void setNetworkDao(INetworkDAO networkDao); @Autowired void setIpBlockDao(IIpBlockDAO ipBlockDao); @Autowired void setClusterDAO(IClusterDAO clusterDAO); @Autowired void setNodeGroupDao(INodeGroupDAO nodeGroupDao); @Autowired void setNodeDao(INodeDAO nodeDao); @Autowired void setResService(IResourceService resSvc); @Override @Transactional synchronized NetworkEntity addDhcpNetwork(final String name,
         final String portGroup, final NetworkDnsType dnsType); @Override @Transactional synchronized NetworkEntity addIpPoolNetwork(final String name,
         final String portGroup, final String netmask, final String gateway,
         final String dns1, final String dns2, final List<IpBlock> ipBlocks,
         final NetworkDnsType dnsType); @Override NetworkEntity getNetworkEntityByName(final String name); @Override @Transactional NetworkRead getNetworkByName(final String name,
         final boolean withDetails); @Override @Transactional List<String> getPortGroupsByNames(final List<String> names); @Override List<NetworkEntity> getAllNetworkEntities(); @Override @Transactional List<NetworkRead> getAllNetworks(final boolean withDetails); @Transactional List<String> getAllNetworkNames(); @Override @Transactional synchronized void updateNetwork(String networkName, NetworkAdd networkAdd); @Override @Transactional synchronized void removeNetwork(NetworkEntity network); @Override @Transactional synchronized void removeNetwork(final String networkName); @Override @Transactional synchronized void addIpBlocks(NetworkEntity network, List<IpBlockEntity> toAdd); @Override @Transactional synchronized void removeIpBlocks(NetworkEntity network,
         List<IpBlockEntity> toRemove); @Override @Transactional synchronized List<IpBlockEntity> alloc(NetworkEntity network, long clusterId,
         long count); @Override @Transactional List<IpBlockEntity> getAllocatedIpBlocks(NetworkEntity network,
         long clusterId); @Override @Transactional synchronized void free(NetworkEntity network, long clusterId,
         List<IpBlockEntity> ipBlocks); @Override @Transactional synchronized void free(NetworkEntity network, long clusterId); @Override @Transactional synchronized void free(NetworkEntity network, long clusterId,
         long ipAddr);  }
@Test(groups = { "res-mgmt" }) public void addIpPoolNetwork() { new Expectations() { { resService.isNetworkExistInVc(anyString); result = true; } }; networkSvc.setResService(resService); networkSvc.setNetworkDao(networkDao); List<IpBlock> ipBlocks = new ArrayList<IpBlock>(); ipBlocks.add(new IpBlock("192.168.1.1", "192.168.1.10")); networkSvc.addIpPoolNetwork("staticNetwork", "network2", "255.255.255.0", "192.168.1.254", "8.8.8.8", "4.4.4.4", ipBlocks, null); new Verifications() { { NetworkEntity networkEntity = new NetworkEntity(); networkDao.insert(withAny(networkEntity)); networkDao.addIpBlocks(withAny(networkEntity), withAny(new ArrayList<IpBlockEntity>())); } }; }