OpenImmo_1_2_7 extends XmlConverter<OpenImmoDocument, OpenImmoVersion> { protected void removeMultipleEnergiepassElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben", doc).selectNodes(doc); for (Object item : nodes) { Element parentNode = (Element) item; List childNodes = XmlUtils.newXPath("io:energiepass", doc) .selectNodes(parentNode); if (childNodes.size() < 2) continue; for (int j = 1; j < childNodes.size(); j++) { parentNode.removeChild((Node) childNodes.get(j)); } } }  @Override OpenImmoVersion getVersion(); @Override void downgradeToPreviousVersion(OpenImmoDocument doc); @Override void upgradeFromPreviousVersion(OpenImmoDocument doc);  }
@Test public void testRemoveMultipleEnergiepassElements() { try { Document doc = buildTransferDocumentForDowngrade(); int count; List nodes = XmlUtils.newXPath( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben", doc).selectNodes(doc); for (Object item : nodes) { Element parentNode = (Element) item; count = XmlUtils.countNodes("io:energiepass", doc, parentNode); Assert.assertEquals( "2 <energiepass> elements for each <immobilie> before conversion.", 2, count); } new OpenImmo_1_2_7().removeMultipleEnergiepassElements(doc); nodes = XmlUtils.newXPath( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben", doc).selectNodes(doc); for (Object item : nodes) { Element parentNode = (Element) item; count = XmlUtils.countNodes("io:energiepass", doc, parentNode); Assert.assertEquals( "1 <energiepass> element for each <immobilie> after conversion.", 1, count); } } catch (Exception ex) { LOGGER.error("Test of OpenImmo_1_2_7.removeMultipleEnergiepassElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmo_1_2_7.removeMultipleEnergiepassElements failed!"); } }