OpenImmo_1_2_4 extends XmlConverter<OpenImmoDocument, OpenImmoVersion> { protected void upgradeAnzahlBalkonTerrassenElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:openimmo/io:anbieter/io:immobilie/io:flaechen/io:anzahl_balkon_terrassen", doc).selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; Element parentNode = (Element) node.getParentNode(); String value = StringUtils.trimToNull(node.getTextContent()); if (value != null) { Element newNode = (Element) XmlUtils.newXPath( "io:anzahl_balkone", doc).selectSingleNode(parentNode); if (newNode == null) { newNode = doc.createElementNS(StringUtils.EMPTY, "anzahl_balkone"); newNode.setTextContent(value); parentNode.appendChild(newNode); } else if (StringUtils.isBlank(newNode.getTextContent())) { newNode.setTextContent(value); } } parentNode.removeChild(node); } }  @Override OpenImmoVersion getVersion(); @Override void downgradeToPreviousVersion(OpenImmoDocument doc); @Override void upgradeFromPreviousVersion(OpenImmoDocument doc);  }
@Test public void testUpgradeAnzahlBalkonTerrassenElements() { try { Document doc = buildTransferDocumentForUpgrade(); int count; count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:flaechen/io:anzahl_balkon_terrassen", doc); Assert.assertEquals( "2 convertable <anzahl_balkon_terrassen> elements available before conversion.", 2, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:flaechen/io:anzahl_balkone", doc); Assert.assertEquals( "1 <anzahl_balkone> element available before conversion.", 1, count); new OpenImmo_1_2_4().upgradeAnzahlBalkonTerrassenElements(doc); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:flaechen/io:anzahl_balkon_terrassen", doc); Assert.assertEquals( "0 convertable <anzahl_balkon_terrassen> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:flaechen/io:anzahl_balkone", doc); Assert.assertEquals( "2 <anzahl_balkone> elements available after conversion.", 2, count); } catch (Exception ex) { LOGGER.error("Test of OpenImmo_1_2_4.upgradeAnzahlBalkonTerrassenElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmo_1_2_4.upgradeAnzahlBalkonTerrassenElements failed!"); } }