KyeroDocument extends XmlConvertableDocument<Root, KyeroVersion> { @Override public KyeroVersion getDocumentVersion() { String version; try { Document doc = this.getDocument(); version = StringUtils.trimToNull(XmlUtils .newXPath("/io:root/io:kyero/io:feed_version/text()", doc) .stringValueOf(doc)); if (version == null) { LOGGER.warn("Can't find version information in the XML document!"); return null; } } catch (JaxenException ex) { LOGGER.error("Can't evaluate XPath expression!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); return null; } KyeroVersion v = KyeroVersion.detectFromString(version); if (v != null) return v; LOGGER.warn("The provided version (" + version + ") is not supported!"); return null; } KyeroDocument(Document document); @Override KyeroVersion getDocumentVersion(); @Override KyeroVersion getLatestVersion(); static boolean isReadable(Document doc); static KyeroDocument newDocument(); static KyeroDocument newDocument(Root root); @Override void setDocumentVersion(KyeroVersion version); @Override Root toObject();  }
@Test public void testDowngrade() { try { KyeroDocument doc = new KyeroDocument(buildExampleDocument(KyeroUtils.VERSION.toXmlVersion())); doc.downgrade(KyeroVersion.V2_1); Assert.assertEquals("downgrade from " + KyeroUtils.VERSION.toReadableVersion() + " to 2.1", KyeroVersion.V2_1, doc.getDocumentVersion()); } catch (Exception ex) { LOGGER.error("Test of KyeroDocument.downgrade failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of KyeroDocument.downgrade failed!"); } }
@Test public void testGetDocumentVersion() { KyeroDocument doc; try { doc = new KyeroDocument(buildExampleDocument("")); Assert.assertNull("no version", doc.getDocumentVersion()); doc = new KyeroDocument(buildExampleDocument("3")); Assert.assertEquals( "3", KyeroVersion.V3, doc.getDocumentVersion()); doc = new KyeroDocument(buildExampleDocument("3.1")); Assert.assertEquals( "3", KyeroVersion.V3, doc.getDocumentVersion()); } catch (Exception ex) { LOGGER.error("Test of KyeroDocument.getDocumentVersion failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of KyeroDocument.getDocumentVersion failed!"); } }
@Test public void testUpgrade() { try { KyeroDocument doc = new KyeroDocument(buildExampleDocument(KyeroVersion.V2_1.toXmlVersion())); doc.upgrade(KyeroUtils.VERSION); Assert.assertEquals("upgrade from 2.1 to " + KyeroUtils.VERSION.toReadableVersion(), KyeroUtils.VERSION, doc.getDocumentVersion()); } catch (Exception ex) { LOGGER.error("Test of KyeroDocument.upgrade failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of KyeroDocument.upgrade failed!"); } }