Kyero_3 extends XmlConverter<KyeroDocument, KyeroVersion> { protected void downgradeTypeElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:root/io:property/io:type", doc).selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; String value = StringUtils.trimToNull(node.getTextContent()); node.setTextContent(null); Element childNode = doc.createElementNS(KyeroUtils.NAMESPACE, "en"); childNode.setTextContent(value); node.appendChild(childNode); } }  @Override KyeroVersion getVersion(); @Override void downgradeToPreviousVersion(KyeroDocument doc); @Override void upgradeFromPreviousVersion(KyeroDocument doc);  }
@Test public void testDowngradeTypeElements() { try { Document doc = buildDocumentForDowngrade(); int count; count = XmlUtils.countNodes( "/io:root/io:property/io:type", doc); Assert.assertEquals( "3 <type> elements available before conversion.", 3, count); count = XmlUtils.countNodes( "/io:root/io:property/io:type[not(*)]", doc); Assert.assertEquals( "3 <type> elements without children available before conversion.", 3, count); new Kyero_3().downgradeTypeElements(doc); count = XmlUtils.countNodes( "/io:root/io:property/io:type[not(*)]", doc); Assert.assertEquals( "0 <type> elements without children available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:root/io:property/io:type/io:en", doc); Assert.assertEquals( "3 converted <type> elements available after conversion.", 3, count); } catch (Exception ex) { LOGGER.error("Test of Kyero_3.downgradeTypeElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of Kyero_3.downgradeTypeElements failed!"); } }