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