Kyero_3 extends XmlConverter<KyeroDocument, KyeroVersion> { protected void upgradeNewBuildElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:root/io:property/io:price_freq", doc).selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; Element parentNode = (Element) node.getParentNode(); if (!"new_build".equalsIgnoreCase(node.getTextContent())) continue; node.setTextContent("sale"); Element newBuildNode = doc.createElementNS(KyeroUtils.NAMESPACE, "new_build"); newBuildNode.setTextContent("1"); parentNode.appendChild(newBuildNode); } }  @Override KyeroVersion getVersion(); @Override void downgradeToPreviousVersion(KyeroDocument doc); @Override void upgradeFromPreviousVersion(KyeroDocument doc);  }
@Test public void testUpgradeNewBuildElements() { try { Document doc = buildDocumentForUpgrade(); int count; count = XmlUtils.countNodes( "/io:root/io:property/io:new_build", doc); Assert.assertEquals( "0 <new_build> elements available before conversion.", 0, count); count = XmlUtils.countNodes( "/io:root/io:property/io:price_freq[text()='sale']", doc); Assert.assertEquals( "1 <price_freq>sale</price_freq> elements available before conversion.", 1, count); new Kyero_3().upgradeNewBuildElements(doc); count = XmlUtils.countNodes( "/io:root/io:property/io:new_build", doc); Assert.assertEquals( "1 <new_build> elements available after conversion.", 1, count); count = XmlUtils.countNodes( "/io:root/io:property/io:price_freq[text()='sale']", doc); Assert.assertEquals( "2 <price_freq>sale</price_freq> elements available before conversion.", 2, count); } catch (Exception ex) { LOGGER.error("Test of Kyero_3.upgradeNewBuildElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of Kyero_3.upgradeNewBuildElements failed!"); } }