OpenImmo_1_2_0 extends XmlConverter<OpenImmoDocument, OpenImmoVersion> { protected void downgradeMieteinnahmenElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:mieteinnahmen_ist[@periode] |" + "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:mieteinnahmen_soll[@periode]", doc).selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; String value = StringUtils.trimToNull(node.getTextContent()); Double numericValue = null; try { numericValue = (value != null) ? DatatypeConverter.parseDouble(value) : null; } catch (Exception ex) { String tagName = node.getTagName(); LOGGER.warn("Can't parse <" + tagName + ">" + value + "</" + tagName + "> as number!"); LOGGER.warn("> " + ex.getLocalizedMessage(), ex); } if (numericValue != null && numericValue > 0) { String periode = StringUtils.trimToNull(node.getAttribute("periode")); if ("MONAT".equalsIgnoreCase(periode)) { node.setTextContent(DatatypeConverter.printDouble(numericValue * 12)); } else if ("WOCHE".equalsIgnoreCase(periode)) { node.setTextContent(DatatypeConverter.printDouble(numericValue * 52)); } else if ("TAG".equalsIgnoreCase(periode)) { node.setTextContent(DatatypeConverter.printDouble(numericValue * 365)); } } node.removeAttribute("periode"); } }  @Override OpenImmoVersion getVersion(); @Override void downgradeToPreviousVersion(OpenImmoDocument doc); @Override void upgradeFromPreviousVersion(OpenImmoDocument doc);  }
@Test public void testDowngradeMieteinnahmenElements() { try { Document doc = buildTransferDocumentForDowngrade(); int count; count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:mieteinnahmen_ist[@periode] |" + "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:mieteinnahmen_soll[@periode]", doc); Assert.assertEquals( "2 convertable <mieteinnahmen_ist> and <mieteinnahmen_soll> elements available before conversion.", 2, count); new OpenImmo_1_2_0().downgradeMieteinnahmenElements(doc); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:mieteinnahmen_ist[@periode] |" + "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:mieteinnahmen_soll[@periode]", doc); Assert.assertEquals( "0 convertable <mieteinnahmen_ist> and <mieteinnahmen_soll> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:mieteinnahmen_ist |" + "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:mieteinnahmen_soll", doc); Assert.assertEquals( "2 converted <mieteinnahmen_ist> and <mieteinnahmen_soll> elements available after conversion.", 2, count); } catch (Exception ex) { LOGGER.error("Test of OpenImmo_1_2_0.downgradeMieteinnahmenElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmo_1_2_0.downgradeMieteinnahmenElements failed!"); } }