OpenImmo_1_2_6 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 ("COWORKING".equalsIgnoreCase(value)) node.setAttribute("buero_typ", "BUEROFLAECHE"); else if ("SHARED_OFFICE".equalsIgnoreCase(value)) node.setAttribute("buero_typ", "BUEROFLAECHE"); } }  @Override OpenImmoVersion getVersion(); @Override void downgradeToPreviousVersion(OpenImmoDocument doc); @Override 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='BUEROFLAECHE']", doc); Assert.assertEquals( "1 <buero_praxen buero_typ=\"BUEROFLAECHE\"> element available before conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:buero_praxen[@buero_typ='COWORKING']", doc); Assert.assertEquals( "1 convertable <buero_praxen buero_typ=\"COWORKING\"> element available before conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:buero_praxen[@buero_typ='SHARED_OFFICE']", doc); Assert.assertEquals( "1 convertable <buero_praxen buero_typ=\"SHARED_OFFICE\"> element available before conversion.", 1, count); new OpenImmo_1_2_6().downgradeBueroPraxenElements(doc); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:buero_praxen[@buero_typ='BUEROFLAECHE']", doc); Assert.assertEquals( "3 <buero_praxen buero_typ=\"BUEROFLAECHE\"> elements available after conversion.", 3, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:buero_praxen[@buero_typ='COWORKING']", doc); Assert.assertEquals( "0 <buero_praxen buero_typ=\"COWORKING\"> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:buero_praxen[@buero_typ='SHARED_OFFICE']", doc); Assert.assertEquals( "0 <buero_praxen buero_typ=\"SHARED_OFFICE\"> elements available after conversion.", 0, count); } catch (Exception ex) { LOGGER.error("Test of OpenImmo_1_2_6.downgradeBueroPraxenElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmo_1_2_6.downgradeBueroPraxenElements failed!"); } }