Source:
public void testRemovalOfIpAddressWithDifferentLocationsInDefinitions() throws IOException { String snmpConfigXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<snmp-config retry=\"3\" timeout=\"800\" read-community=\"public\" write-community=\"private\" xmlns=\"<LINK_0>\">\n" + " <definition version=\"v1\" timeout=\"1200\">\n" + " <range begin=\"192.168.1.15\" end=\"192.168.1.35\"/>\n" + " </definition>\n" + " <definition version=\"v1\" location=\"Minion\">\n" + " <range begin=\"192.168.1.15\" end=\"192.168.1.35\"/>\n" + " </definition>\n" + "</snmp-config>\n" + ""; String expectedConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<snmp-config retry=\"3\" timeout=\"800\" read-community=\"public\" write-community=\"private\" xmlns=\"<LINK_0>\">\n" + " <definition version=\"v1\" timeout=\"1200\" >\n" + " <range begin=\"192.168.1.15\" end=\"192.168.1.35\"/>\n" + " </definition>\n" + " <definition version=\"v1\" location=\"Minion\">\n" + " <range begin=\"192.168.1.15\" end=\"192.168.1.24\"/>\n" + " <range begin=\"192.168.1.26\" end=\"192.168.1.35\"/>\n" + " </definition>\n" + "</snmp-config>\n" + ""; SnmpPeerFactory.setInstance(new SnmpPeerFactory(new StringResource(snmpConfigXml))); assertXmlEquals(snmpConfigXml, SnmpPeerFactory.getInstance().getSnmpConfigAsString()); SnmpPeerFactory.getInstance().removeFromDefinition(InetAddress.getByName("192.168.1.25"), "Minion", "test"); SnmpAgentConfig snmpAgentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName("192.168.1.25")); assertFalse(snmpAgentConfig.isDefault()); String actualConfig = SnmpPeerFactory.getInstance().getSnmpConfigAsString(); assertXmlEquals(expectedConfig, actualConfig); }

Target:
public void testRemovalOfIpAddressWithDifferentLocationsInDefinitions() throws IOException { String snmpConfigXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<snmp-config retry=\"3\" timeout=\"800\" read-community=\"public\" write-community=\"private\" xmlns=\"<LINK_0>\">\n" + " <definition version=\"v1\" timeout=\"1200\">\n" + " <range begin=\"192.168.1.15\" end=\"192.168.1.35\"/>\n" + " </definition>\n" + " <definition version=\"v1\" location=\"Minion\">\n" + " <range begin=\"192.168.1.15\" end=\"192.168.1.35\"/>\n" + " </definition>\n" + "</snmp-config>\n" + ""; String expectedConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<snmp-config retry=\"3\" timeout=\"800\" read-community=\"public\" write-community=\"private\" xmlns=\"<LINK_0>\">\n" + " <definition version=\"v1\" timeout=\"1200\" >\n" + " <range begin=\"192.168.1.15\" end=\"192.168.1.35\"/>\n" + " </definition>\n" + " <definition version=\"v1\" location=\"Minion\">\n" + " <range begin=\"192.168.1.15\" end=\"192.168.1.24\"/>\n" + " <range begin=\"192.168.1.26\" end=\"192.168.1.35\"/>\n" + " </definition>\n" + "</snmp-config>\n" + ""; SnmpPeerFactory.setInstance(new SnmpPeerFactory(new StringResource(snmpConfigXml))); assertXmlEquals(snmpConfigXml, SnmpPeerFactory.getInstance().getSnmpConfigAsString()); SnmpPeerFactory.getInstance().removeFromDefinition(InetAddress.getByName("192.168.1.25"), "Minion", "test"); SnmpAgentConfig snmpAgentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName("192.168.1.25"), "Minion"); assertFalse("Config should be derived from default location", snmpAgentConfig.isDefault()); String actualConfig = SnmpPeerFactory.getInstance().getSnmpConfigAsString(); assertXmlEquals(expectedConfig, actualConfig); }