OpenImmo_1_2_4 extends XmlConverter<OpenImmoDocument, OpenImmoVersion> { protected void upgradeAnhangElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:openimmo/io:anbieter/io:anhang/io:daten/io:pfad | " + "/io:openimmo/io:anbieter/io:immobilie/io:anhaenge/io:anhang/io:daten/io:pfad", doc).selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; Element parentNode = (Element) node.getParentNode().getParentNode(); String value = StringUtils.trimToEmpty(node.getTextContent()).toLowerCase(); if (value.startsWith("http: parentNode.setAttribute("location", "REMOTE"); else if (value.startsWith("https: parentNode.setAttribute("location", "REMOTE"); else if (value.startsWith("ftp: parentNode.setAttribute("location", "REMOTE"); else if (value.startsWith("ftps: parentNode.setAttribute("location", "REMOTE"); } }  @Override OpenImmoVersion getVersion(); @Override void downgradeToPreviousVersion(OpenImmoDocument doc); @Override void upgradeFromPreviousVersion(OpenImmoDocument doc);  }
@Test public void testUpgradeAnhangElements() { try { Document doc = buildTransferDocumentForUpgrade(); int count; count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:anhaenge/io:anhang", doc); Assert.assertEquals( "5 <anhang> elements available before conversion.", 5, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:anhaenge/io:anhang[@location='REMOTE']", doc); Assert.assertEquals( "0 remote <anhang> elements available before conversion.", 0, count); new OpenImmo_1_2_4().upgradeAnhangElements(doc); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:anhaenge/io:anhang", doc); Assert.assertEquals( "5 <anhang> elements available after conversion.", 5, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:anhaenge/io:anhang[@location='REMOTE']", doc); Assert.assertEquals( "4 converted <anhang> elements available after conversion.", 4, count); } catch (Exception ex) { LOGGER.error("Test of OpenImmo_1_2_4.upgradeAnhangElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmo_1_2_4.upgradeAnhangElements failed!"); } }