OpenImmo_1_2_4 extends XmlConverter<OpenImmoDocument, OpenImmoVersion> { protected void upgradeSonstigeElements(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; String value = StringUtils.trimToNull(node.getAttribute("sonstige_typ")); if ("GARAGEN".equalsIgnoreCase(value) || "PARKFLACHE".equalsIgnoreCase(value)) { Element parentNode = (Element) node.getParentNode(); parentNode.removeChild(node); Element newNode = doc.createElementNS(StringUtils.EMPTY, "parken"); newNode.setAttribute("parken_typ", "STELLPLATZ"); parentNode.appendChild(newNode); } } }  @Override OpenImmoVersion getVersion(); @Override void downgradeToPreviousVersion(OpenImmoDocument doc); @Override void upgradeFromPreviousVersion(OpenImmoDocument doc);  }
@Test public void testUpgradeSonstigeElements() { try { Document doc = buildTransferDocumentForUpgrade(); int count; count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:sonstige", doc); Assert.assertEquals( "3 <sonstige> elements available before conversion.", 3, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:sonstige[@sonstige_typ='GARAGEN' or @sonstige_typ='PARKFLACHE']", doc); Assert.assertEquals( "2 convertable <sonstige> elements available before conversion.", 2, count); new OpenImmo_1_2_4().upgradeSonstigeElements(doc); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:sonstige", doc); Assert.assertEquals( "1 <sonstige> element available after conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:sonstige[@sonstige_typ='GARAGEN' or @sonstige_typ='PARKFLACHE']", doc); Assert.assertEquals( "0 convertable <sonstige> elements available before conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:parken[@parken_typ='STELLPLATZ']", doc); Assert.assertEquals( "2 converted <parken> elements available after conversion.", 2, count); } catch (Exception ex) { LOGGER.error("Test of OpenImmo_1_2_4.upgradeSonstigeElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmo_1_2_4.upgradeSonstigeElements failed!"); } }