ImmoXmlDocument extends XmlConvertableDocument<Immoxml, ImmoXmlVersion> { @Override public ImmoXmlVersion getDocumentVersion() { String version; try { Document doc = this.getDocument(); version = StringUtils.trimToNull(XmlUtils .newXPath("/io:immoxml/io:uebertragung/@version", 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; } ImmoXmlVersion v = ImmoXmlVersion.detectFromString(version); if (v != null) return v; LOGGER.warn("The provided version (" + version + ") is not supported!"); return null; } ImmoXmlDocument(Document document); @Override ImmoXmlVersion getDocumentVersion(); @Override ImmoXmlVersion getLatestVersion(); static boolean isReadable(Document doc); static ImmoXmlDocument newDocument(); static ImmoXmlDocument newDocument(Immoxml immoxml); @Override void setDocumentVersion(ImmoXmlVersion version); @Override Immoxml toObject();  }
@Test @SuppressWarnings("Duplicates") public void testDowngrade() { try { String version = ImmoXmlUtils.VERSION.toReadableVersion(); ImmoXmlDocument doc = new ImmoXmlDocument(buildExampleDocument(version)); doc.downgrade(ImmoXmlVersion.V3_0); Assert.assertEquals("downgrade from " + version + " to 3.0", ImmoXmlVersion.V3_0, doc.getDocumentVersion()); } catch (Exception ex) { LOGGER.error("Test of ImmoXmlDocument.downgrade failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of ImmoXmlDocument.downgrade failed!"); } }
@Test @SuppressWarnings("Duplicates") public void testUpgrade() { try { String version = ImmoXmlUtils.VERSION.toReadableVersion(); ImmoXmlDocument doc = new ImmoXmlDocument(buildExampleDocument("1.1")); doc.upgrade(ImmoXmlUtils.VERSION); Assert.assertEquals("upgrade from 1.1 to " + version, ImmoXmlUtils.VERSION, doc.getDocumentVersion()); } catch (Exception ex) { LOGGER.error("Test of ImmoXmlDocument.upgrade failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of ImmoXmlDocument.upgrade failed!"); } }