OpenImmo_1_2_4 extends XmlConverter<OpenImmoDocument, OpenImmoVersion> { protected void downgradeAnhangElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:openimmo/io:anbieter/io:anhang | " + "/io:openimmo/io:anbieter/io:immobilie/io:anhaenge/io:anhang", doc).selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; String value = StringUtils.trimToNull(node.getAttribute("gruppe")); if ("QRCODE".equalsIgnoreCase(value)) node.removeAttribute("gruppe"); else if ("FILM".equalsIgnoreCase(value)) node.removeAttribute("gruppe"); else if ("FILMLINK".equalsIgnoreCase(value)) node.removeAttribute("gruppe"); value = StringUtils.trimToNull(node.getAttribute("location")); if ("REMOTE".equalsIgnoreCase(value)) node.setAttribute("location", "EXTERN"); List childNodes = XmlUtils.newXPath("io:check", doc) .selectNodes(node); for (Object childItem : childNodes) { node.removeChild((Node) childItem); } } }  @Override OpenImmoVersion getVersion(); @Override void downgradeToPreviousVersion(OpenImmoDocument doc); @Override void upgradeFromPreviousVersion(OpenImmoDocument doc);  }
@Test public void testDowngradeAnhangElements() { try { Document doc = buildTransferDocumentForDowngrade(); 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[@gruppe='QRCODE' or @gruppe='FILM' or @gruppe='FILMLINK' or @location='REMOTE'] | " + "/io:openimmo/io:anbieter/io:immobilie/io:anhaenge/io:anhang/io:check/..", doc); Assert.assertEquals( "5 convertable <anhang> elements available before conversion.", 5, count); new OpenImmo_1_2_4().downgradeAnhangElements(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[@gruppe='QRCODE' or @gruppe='FILM' or @gruppe='FILMLINK' or @location='REMOTE'] | " + "/io:openimmo/io:anbieter/io:immobilie/io:anhaenge/io:anhang/io:check/..", doc); Assert.assertEquals( "0 convertable <anhang> elements available before conversion.", 0, count); } catch (Exception ex) { LOGGER.error("Test of OpenImmo_1_2_4.downgradeAnhangElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmo_1_2_4.downgradeAnhangElements failed!"); } }