OpenImmoTransferDocument extends OpenImmoDocument<Openimmo> { @Override public void setDocumentVersion(OpenImmoVersion version) { try { Document doc = this.getDocument(); String currentVersion = StringUtils.trimToEmpty(XmlUtils .newXPath("/io:openimmo/io:uebertragung/@version", doc) .stringValueOf(doc)); String[] ver = StringUtils.split(currentVersion, "/", 2); Element node = (Element) XmlUtils .newXPath("/io:openimmo/io:uebertragung", doc) .selectSingleNode(doc); if (node == null) { Element parentNode = (Element) XmlUtils .newXPath("/io:openimmo", doc) .selectSingleNode(doc); if (parentNode == null) { LOGGER.warn("Can't find an <openimmo> element in the document!"); return; } node = doc.createElement("uebertragung"); parentNode.insertBefore(node, parentNode.getFirstChild()); } String newVersion = version.toReadableVersion(); if (ver.length > 1) newVersion += "/" + ver[1]; node.setAttribute("version", newVersion); } catch (JaxenException ex) { LOGGER.error("Can't evaluate XPath expression!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); } } 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 testSetDocumentVersion() { try { OpenImmoTransferDocument doc = new OpenImmoTransferDocument(buildExampleDocument("1.2.7")); Assert.assertEquals( "1.2.7", OpenImmoVersion.V1_2_7, doc.getDocumentVersion()); doc.setDocumentVersion(OpenImmoVersion.V1_2_6); Assert.assertEquals( "1.2.6/AT1.0", OpenImmoVersion.V1_2_6, doc.getDocumentVersion()); doc.setDocumentVersion(OpenImmoVersion.V1_2_0); Assert.assertEquals( "1.2.0", OpenImmoVersion.V1_2_0, doc.getDocumentVersion()); } catch (Exception ex) { LOGGER.error("Test of OpenImmoTransferDocument.setDocumentVersion failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmoTransferDocument.setDocumentVersion failed!"); } }