NeutronSubnetIpAllocationPool implements Serializable { public List<NeutronSubnetIpAllocationPool> splitPool(String ipAddress) { List<NeutronSubnetIpAllocationPool> ans = new ArrayList<>(); long givenIp = NeutronSubnetIpAllocationPool.convert(ipAddress); long startIp = NeutronSubnetIpAllocationPool.convert(poolStart); long endIp = NeutronSubnetIpAllocationPool.convert(poolEnd); long ipaddr; NeutronSubnetIpAllocationPool pool = new NeutronSubnetIpAllocationPool(); boolean poolStarted = false; for (ipaddr = startIp; ipaddr <= endIp; ipaddr++) { if (ipaddr == startIp) { if (ipaddr != givenIp) { pool.setPoolStart(poolStart); poolStarted = true; } else { pool.setPoolStart(NeutronSubnetIpAllocationPool.longToIp(ipaddr + 1)); } } if (ipaddr == endIp) { if (ipaddr != givenIp) { pool.setPoolEnd(poolEnd); } else { pool.setPoolEnd(NeutronSubnetIpAllocationPool.longToIp(ipaddr - 1)); } ans.add(pool); } if (ipaddr != startIp && ipaddr != endIp) { if (ipaddr != givenIp) { if (!poolStarted) { pool.setPoolStart(NeutronSubnetIpAllocationPool.longToIp(ipaddr)); poolStarted = true; } } else { pool.setPoolEnd(NeutronSubnetIpAllocationPool.longToIp(ipaddr - 1)); ans.add(pool); pool = new NeutronSubnetIpAllocationPool(); pool.setPoolStart(NeutronSubnetIpAllocationPool.longToIp(ipaddr + 1)); poolStarted = true; } } } return ans; } NeutronSubnetIpAllocationPool();  NeutronSubnetIpAllocationPool(String lowAddress, String highAddress); String getPoolStart(); void setPoolStart(String poolStart); String getPoolEnd(); void setPoolEnd(String poolEnd); boolean contains(String inputString); boolean containsV6(String inputString); static String join(String[] strings, String separator); List<NeutronSubnetIpAllocationPool> splitPool(String ipAddress); @Override String toString(); List<NeutronSubnetIpAllocationPool> splitPoolV6(String ipAddress);  }
@Test public void splitPoolTest() { NeutronSubnetIpAllocationPool apUT = new NeutronSubnetIpAllocationPool(); apUT.setPoolStart("10.18.0.2"); apUT.setPoolEnd("10.18.0.6"); List<NeutronSubnetIpAllocationPool> result = apUT.splitPool("10.18.0.2"); Assert.assertEquals("splitPool Test 1.1: address == pool start (result size) failed", 1, result.size()); Assert.assertEquals("splitPool Test 1.2: address == pool start (pool start) failed", "10.18.0.3", result.get(0).getPoolStart()); Assert.assertEquals("splitPool Test 1.3: address == pool start (pool end) failed", "10.18.0.6", result.get(0).getPoolEnd()); apUT = new NeutronSubnetIpAllocationPool(); apUT.setPoolStart("10.18.0.2"); apUT.setPoolEnd("10.18.0.6"); result = apUT.splitPool("10.18.0.3"); Assert.assertEquals("splitPool Test 2.1: address one above pool start (result size) failed", 2, result.size()); Assert.assertEquals("splitPool Test 2.2: address one above pool start (pool 1 start) failed", "10.18.0.2", result.get(0).getPoolStart()); Assert.assertEquals("splitPool Test 2.3: address one above pool start (pool 1 end) failed", "10.18.0.2", result.get(0).getPoolEnd()); Assert.assertEquals("splitPool Test 2.4: address one above pool start (pool 2 start) failed", "10.18.0.4", result.get(1).getPoolStart()); Assert.assertEquals("splitPool Test 2.5: address one above pool start (pool 2 end) failed", "10.18.0.6", result.get(1).getPoolEnd()); apUT = new NeutronSubnetIpAllocationPool(); apUT.setPoolStart("10.18.0.2"); apUT.setPoolEnd("10.18.0.6"); result = apUT.splitPool("10.18.0.4"); Assert.assertEquals("splitPool Test 3.1: address one above pool start (result size) failed", 2, result.size()); Assert.assertEquals("splitPool Test 3.2: address one above pool start (pool 1 start) failed", "10.18.0.2", result.get(0).getPoolStart()); Assert.assertEquals("splitPool Test 3.3: address one above pool start (pool 1 end) failed", "10.18.0.3", result.get(0).getPoolEnd()); Assert.assertEquals("splitPool Test 3.4: address one above pool start (pool 2 start) failed", "10.18.0.5", result.get(1).getPoolStart()); Assert.assertEquals("splitPool Test 3.5: address one above pool start (pool 2 end) failed", "10.18.0.6", result.get(1).getPoolEnd()); apUT = new NeutronSubnetIpAllocationPool(); apUT.setPoolStart("10.18.0.2"); apUT.setPoolEnd("10.18.0.6"); result = apUT.splitPool("10.18.0.5"); Assert.assertEquals("splitPool Test 4.1: address one above pool start (result size) failed", 2, result.size()); Assert.assertEquals("splitPool Test 4.2: address one above pool start (pool 1 start) failed", "10.18.0.2", result.get(0).getPoolStart()); Assert.assertEquals("splitPool Test 4.3: address one above pool start (pool 1 end) failed", "10.18.0.4", result.get(0).getPoolEnd()); Assert.assertEquals("splitPool Test 4.4: address one above pool start (pool 2 start) failed", "10.18.0.6", result.get(1).getPoolStart()); Assert.assertEquals("splitPool Test 4.5: address one above pool start (pool 2 end) failed", "10.18.0.6", result.get(1).getPoolEnd()); apUT = new NeutronSubnetIpAllocationPool(); apUT.setPoolStart("10.18.0.2"); apUT.setPoolEnd("10.18.0.6"); result = apUT.splitPool("10.18.0.6"); Assert.assertEquals("splitPool Test 5.1: address == pool start (result size) failed", 1, result.size()); Assert.assertEquals("splitPool Test 5.2: address == pool start (pool start) failed", "10.18.0.2", result.get(0).getPoolStart()); Assert.assertEquals("splitPool Test 5.3: address == pool start (pool end) failed", "10.18.0.5", result.get(0).getPoolEnd()); }