OpenImmo_1_2_2 extends XmlConverter<OpenImmoDocument, OpenImmoVersion> { protected void downgradeBueroPraxenElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:buero_praxen[@buero_typ]", doc).selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; String value = StringUtils.trimToNull(node.getAttribute("buero_typ")); if ("BUEROZENTRUM".equalsIgnoreCase(value)) node.setAttribute("buero_typ", "BUEROFLAECHE"); else if ("LOFT_ATELIER".equalsIgnoreCase(value)) node.setAttribute("buero_typ", "BUEROFLAECHE"); else if ("PRAXISFLAECHE".equalsIgnoreCase(value)) node.setAttribute("buero_typ", "BUEROFLAECHE"); else if ("PRAXISHAUS".equalsIgnoreCase(value)) node.setAttribute("buero_typ", "BUEROFLAECHE"); } }  @Override OpenImmoVersion getVersion(); @Override void downgradeToPreviousVersion(OpenImmoDocument doc); @Override @SuppressWarnings("Duplicates") void upgradeFromPreviousVersion(OpenImmoDocument doc);  }
@Test public void testDowngradeBueroPraxenElements() { try { Document doc = buildTransferDocumentForDowngrade(); int count; count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:buero_praxen[@buero_typ='BUEROZENTRUM' or @buero_typ='LOFT_ATELIER' or @buero_typ='PRAXISFLAECHE' or @buero_typ='PRAXISHAUS']", doc); Assert.assertEquals( "4 convertable <buero_praxen> elements available before conversion.", 4, count); new OpenImmo_1_2_2().downgradeBueroPraxenElements(doc); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:buero_praxen[@buero_typ='BUEROZENTRUM' or @buero_typ='LOFT_ATELIER' or @buero_typ='PRAXISFLAECHE' or @buero_typ='PRAXISHAUS']", doc); Assert.assertEquals( "0 convertable <buero_praxen> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:buero_praxen[@buero_typ='BUEROFLAECHE']", doc); Assert.assertEquals( "4 converted <buero_praxen> elements available after conversion.", 4, count); } catch (Exception ex) { LOGGER.error("Test of OpenImmo_1_2_2.downgradeBueroPraxenElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmo_1_2_2.downgradeBueroPraxenElements failed!"); } }