OpenImmoFeedbackDocument extends OpenImmoDocument<OpenimmoFeedback> { @Override public OpenImmoVersion getDocumentVersion() { String version; try { Document doc = this.getDocument(); Element node = (Element) XmlUtils .newXPath("/io:openimmo_feedback/io:version", doc) .selectSingleNode(doc); if (node == null) { Element root = XmlUtils.getRootElement(doc); return (OpenImmoUtils.OLD_NAMESPACE.equalsIgnoreCase(root.getNamespaceURI())) ? OpenImmoVersion.V1_2_0 : OpenImmoVersion.V1_2_3; } version = StringUtils.trimToNull(node.getTextContent()); 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; } OpenImmoFeedbackDocument(Document document); @Override OpenImmoVersion getDocumentVersion(); static boolean isReadable(Document doc); static OpenImmoFeedbackDocument newDocument(); static OpenImmoFeedbackDocument newDocument(OpenimmoFeedback feedback); @Override void setDocumentVersion(OpenImmoVersion version); @Override OpenimmoFeedback toObject();  }
@Test public void testDowngrade() { try { String version = OpenImmoUtils.VERSION.toReadableVersion(); OpenImmoFeedbackDocument doc = new OpenImmoFeedbackDocument(buildExampleDocument(version)); doc.downgrade(OpenImmoVersion.V1_1); Assert.assertEquals( "downgrade from " + version + " to 1.1", OpenImmoVersion.V1_2_0, doc.getDocumentVersion()); } catch (Exception ex) { LOGGER.error("Test of OpenImmoFeedbackDocument.downgrade failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmoFeedbackDocument.downgrade failed!"); } }
@Test public void testGetDocumentVersion() { OpenImmoFeedbackDocument doc; try { doc = new OpenImmoFeedbackDocument(buildExampleDocument("1.2.7")); Assert.assertEquals( "1.2.7", OpenImmoVersion.V1_2_7, doc.getDocumentVersion()); doc = new OpenImmoFeedbackDocument(buildExampleDocument("1.2.6/AT1.0")); Assert.assertEquals( "1.2.6/AT1.0", OpenImmoVersion.V1_2_6, doc.getDocumentVersion()); doc = new OpenImmoFeedbackDocument(buildExampleDocument("1.2.1")); Assert.assertEquals( "1.2.1", OpenImmoVersion.V1_2_3, doc.getDocumentVersion()); doc = new OpenImmoFeedbackDocument(buildExampleDocument("1.2.0")); Assert.assertEquals( "1.2.0", OpenImmoVersion.V1_2_0, doc.getDocumentVersion()); } catch (Exception ex) { LOGGER.error("Test of OpenImmoFeedbackDocument.getDocumentVersion failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmoFeedbackDocument.getDocumentVersion failed!"); } }
@Test public void testUpgrade() { try { String version = OpenImmoUtils.VERSION.toReadableVersion(); OpenImmoFeedbackDocument doc = new OpenImmoFeedbackDocument(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 OpenImmoFeedbackDocument.upgrade failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmoFeedbackDocument.upgrade failed!"); } }