OpenImmo_1_2_3 extends XmlConverter<OpenImmoDocument, OpenImmoVersion> { protected void downgradeSonstigeElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:sonstige[@sonstige_typ]", doc).selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; Element parent = (Element) node.getParentNode(); String value = StringUtils.trimToNull(node.getAttribute("sonstige_typ")); if ("KRANKENHAUS".equalsIgnoreCase(value)) { parent.removeChild(node); Element newNode = doc.createElementNS(StringUtils.EMPTY, "haus"); newNode.setAttribute("haustyp", "KRANKENHAUS"); parent.appendChild(newNode); } } }  @Override OpenImmoVersion getVersion(); @Override void downgradeToPreviousVersion(OpenImmoDocument doc); @Override void upgradeFromPreviousVersion(OpenImmoDocument doc);  }
@Test public void testDowngradeSonstigeElements() { try { Document doc = buildTransferDocumentForDowngrade(); int count; count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:sonstige[@sonstige_typ='KRANKENHAUS']", doc); Assert.assertEquals( "1 convertable <sonstige> element available before conversion.", 1, count); new OpenImmo_1_2_3().downgradeSonstigeElements(doc); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:sonstige[@sonstige_typ='KRANKENHAUS']", doc); Assert.assertEquals( "0 convertable <sonstige> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:haus[@haustyp='KRANKENHAUS']", doc); Assert.assertEquals( "1 converted <haus> elements available after conversion.", 1, count); } catch (Exception ex) { LOGGER.error("Test of OpenImmo_1_2_3.downgradeSonstigeElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmo_1_2_3.downgradeSonstigeElements failed!"); } }