Kyero_3 extends XmlConverter<KyeroDocument, KyeroVersion> { protected void upgradeCurrencyElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:root/io:property/io:currency", doc).selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; Element parentNode = (Element) node.getParentNode(); String value = StringUtils.trimToNull(node.getTextContent()); if ("EUR".equalsIgnoreCase(value)) node.setTextContent("EUR"); else if ("GBP".equalsIgnoreCase(value)) node.setTextContent("GBP"); else if ("USD".equalsIgnoreCase(value)) node.setTextContent("USD"); else parentNode.removeChild(node); } }  @Override KyeroVersion getVersion(); @Override void downgradeToPreviousVersion(KyeroDocument doc); @Override void upgradeFromPreviousVersion(KyeroDocument doc);  }
@Test public void testUpgradeCurrencyElements() { try { Document doc = buildDocumentForUpgrade(); int count; count = XmlUtils.countNodes( "/io:root/io:property/io:currency", doc); Assert.assertEquals( "3 <currency> elements available before conversion.", 3, count); new Kyero_3().upgradeCurrencyElements(doc); count = XmlUtils.countNodes( "/io:root/io:property/io:currency", doc); Assert.assertEquals( "1 <currency> element available after conversion.", 1, count); } catch (Exception ex) { LOGGER.error("Test of Kyero_3.upgradeCurrencyElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of Kyero_3.upgradeCurrencyElements failed!"); } }