OpenImmo_1_2_4 extends XmlConverter<OpenImmoDocument, OpenImmoVersion> { @SuppressWarnings("Duplicates") protected void removeFeedbackInteressentChildElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:openimmo_feedback/io:objekt/io:interessent", doc).selectNodes(doc); for (Object item : nodes) { Element parentNode = (Element) item; boolean bevorzugtPassed = false; boolean wunschPassed = false; List childNodes = XmlUtils.newXPath( "io:bevorzugt", doc).selectNodes(parentNode); for (Object childItem : childNodes) { Element node = (Element) childItem; if (!bevorzugtPassed) bevorzugtPassed = true; else parentNode.removeChild(node); } childNodes = XmlUtils.newXPath( "io:wunsch", doc).selectNodes(parentNode); for (Object childItem : childNodes) { Element node = (Element) childItem; if (!wunschPassed) wunschPassed = true; else parentNode.removeChild(node); } } }  @Override OpenImmoVersion getVersion(); @Override void downgradeToPreviousVersion(OpenImmoDocument doc); @Override void upgradeFromPreviousVersion(OpenImmoDocument doc);  }
@Test public void testRemoveFeedbackInteressentChildElements() { try { Document doc = buildFeedbackDocumentForDowngrade(); int count; count = XmlUtils.countNodes( "/io:openimmo_feedback/io:objekt/io:interessent/io:bevorzugt | " + "/io:openimmo_feedback/io:objekt/io:interessent/io:wunsch", doc); Assert.assertEquals( "4 convertable element available before conversion.", 4, count); new OpenImmo_1_2_4().removeFeedbackInteressentChildElements(doc); count = XmlUtils.countNodes( "/io:openimmo_feedback/io:objekt/io:interessent/io:bevorzugt | " + "/io:openimmo_feedback/io:objekt/io:interessent/io:wunsch", doc); Assert.assertEquals( "2 elements available after conversion.", 2, count); } catch (Exception ex) { LOGGER.error("Test of OpenImmo_1_2_4.removeFeedbackInteressentChildElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmo_1_2_4.removeFeedbackInteressentChildElements failed!"); } }