Kyero_3 extends XmlConverter<KyeroDocument, KyeroVersion> { @SuppressWarnings("Duplicates") protected void upgradeTypeElements(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 enTypeValue = null; String fallbackTypeValue = null; List childNodes = XmlUtils.newXPath( "*", doc).selectNodes(node); for (Object childItem : childNodes) { Element langNode = (Element) childItem; if ("en".equalsIgnoreCase(langNode.getLocalName())) enTypeValue = StringUtils.trimToNull(langNode.getTextContent()); else if (fallbackTypeValue == null) fallbackTypeValue = StringUtils.trimToNull(langNode.getTextContent()); node.removeChild(langNode); } node.setTextContent((enTypeValue != null) ? enTypeValue : fallbackTypeValue); } }  @Override KyeroVersion getVersion(); @Override void downgradeToPreviousVersion(KyeroDocument doc); @Override void upgradeFromPreviousVersion(KyeroDocument doc);  }
@Test public void testUpgradeTypeElements() { try { Document doc = buildDocumentForUpgrade(); int count; count = XmlUtils.countNodes( "/io:root/io:property/io:type[not(*)]", doc); Assert.assertEquals( "0 <type> elements without children available before conversion.", 0, count); new Kyero_3().upgradeTypeElements(doc); count = XmlUtils.countNodes( "/io:root/io:property/io:type[not(*)]", doc); Assert.assertEquals( "3 <type> elements without children available after conversion.", 3, count); } catch (Exception ex) { LOGGER.error("Test of Kyero_3.upgradeTypeElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of Kyero_3.upgradeTypeElements failed!"); } }