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