OpenImmoTransferDocument extends OpenImmoDocument<Openimmo> { @Override public OpenImmoVersion getDocumentVersion() { String version; try { Document doc = this.getDocument(); version = StringUtils.trimToNull(XmlUtils .newXPath("/io:openimmo/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; } OpenImmoVersion v = OpenImmoVersion.detectFromString(version); if (v != null) return v; LOGGER.warn("The provided version (" + version + ") is not supported!"); return null; } OpenImmoTransferDocument(Document document); @Override OpenImmoVersion getDocumentVersion(); static boolean isReadable(Document doc); static OpenImmoTransferDocument newDocument(); static OpenImmoTransferDocument newDocument(Openimmo openimmo); @Override void setDocumentVersion(OpenImmoVersion version); @Override Openimmo toObject();  }
@Test public void testDowngrade() { try { String version = OpenImmoUtils.VERSION.toReadableVersion(); OpenImmoTransferDocument doc = new OpenImmoTransferDocument(buildExampleDocument(version)); doc.downgrade(OpenImmoVersion.V1_1); Assert.assertEquals( "downgrade from " + version + " to 1.1", OpenImmoVersion.V1_1, doc.getDocumentVersion()); } catch (Exception ex) { LOGGER.error("Test of OpenImmoTransferDocument.downgrade failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmoTransferDocument.downgrade failed!"); } }
@Test public void testGetDocumentVersion() { OpenImmoTransferDocument doc; try { doc = new OpenImmoTransferDocument(buildExampleDocument("1.2.7")); Assert.assertEquals( "1.2.7", OpenImmoVersion.V1_2_7, doc.getDocumentVersion()); doc = new OpenImmoTransferDocument(buildExampleDocument("1.2.6/AT1.0")); Assert.assertEquals( "1.2.6/AT1.0", OpenImmoVersion.V1_2_6, doc.getDocumentVersion()); doc = new OpenImmoTransferDocument(buildExampleDocument("1.2.0")); Assert.assertEquals( "1.2.0", OpenImmoVersion.V1_2_0, doc.getDocumentVersion()); } catch (Exception ex) { LOGGER.error("Test of OpenImmoTransferDocument.getDocumentVersion failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmoTransferDocument.getDocumentVersion failed!"); } }
@Test public void testUpgrade() { try { String version = OpenImmoUtils.VERSION.toReadableVersion(); OpenImmoTransferDocument doc = new OpenImmoTransferDocument(buildExampleDocument("1.1")); doc.upgrade(OpenImmoUtils.VERSION); Assert.assertEquals( "upgrade from 1.1 to " + version, OpenImmoUtils.VERSION, doc.getDocumentVersion()); } catch (Exception ex) { LOGGER.error("Test of OpenImmoTransferDocument.upgrade failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmoTransferDocument.upgrade failed!"); } }