OpenImmo_1_2_2 extends XmlConverter<OpenImmoDocument, OpenImmoVersion> { protected void downgradeObjektartElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart", doc).selectNodes(doc); for (Object item : nodes) { Element parentNode = (Element) item; String type = null; List childNodes = XmlUtils.newXPath( "*", doc).selectNodes(parentNode); for (Object childItem : childNodes) { Element node = (Element) childItem; if (type == null) { type = node.getLocalName(); } else if (!type.equalsIgnoreCase(node.getLocalName())) { parentNode.removeChild(node); } } } }  @Override OpenImmoVersion getVersion(); @Override void downgradeToPreviousVersion(OpenImmoDocument doc); @Override @SuppressWarnings("Duplicates") void upgradeFromPreviousVersion(OpenImmoDocument doc);  }
@Test public void testDowngradeObjektartElements() { try { Document doc = buildTransferDocumentForDowngrade(); int count; count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie[@class='multicat']/io:objektkategorie/io:objektart/*", doc); Assert.assertEquals( "5 convertable children of the <objektart> element available before conversion.", 5, count); new OpenImmo_1_2_2().downgradeObjektartElements(doc); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie[@class='multicat']/io:objektkategorie/io:objektart/*", doc); Assert.assertEquals( "3 converted children of the <objektart> element available after conversion.", 3, count); } catch (Exception ex) { LOGGER.error("Test of OpenImmo_1_2_2.downgradeObjektartElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmo_1_2_2.downgradeObjektartElements failed!"); } }