OpenImmo_1_2_3 extends XmlConverter<OpenImmoDocument, OpenImmoVersion> { protected void downgradeAusrichtBalkonTerrasseElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:ausricht_balkon_terrasse[@NORDOST or @NORDWEST or @SUEDOST or @SUEDWEST]", doc).selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; if (node.hasAttribute("NORDOST")) { String value = StringUtils.trimToEmpty(node.getAttribute("NORDOST")).toLowerCase(); if (value.equals("1") || value.equals("true")) { node.setAttribute("NORD", "true"); node.setAttribute("OST", "true"); } node.removeAttribute("NORDOST"); } if (node.hasAttribute("NORDWEST")) { String value = StringUtils.trimToEmpty(node.getAttribute("NORDWEST")).toLowerCase(); if (value.equals("1") || value.equals("true")) { node.setAttribute("NORD", "true"); node.setAttribute("WEST", "true"); } node.removeAttribute("NORDWEST"); } if (node.hasAttribute("SUEDOST")) { String value = StringUtils.trimToEmpty(node.getAttribute("SUEDOST")).toLowerCase(); if (value.equals("1") || value.equals("true")) { node.setAttribute("SUED", "true"); node.setAttribute("OST", "true"); } node.removeAttribute("SUEDOST"); } if (node.hasAttribute("SUEDWEST")) { String value = StringUtils.trimToEmpty(node.getAttribute("SUEDWEST")).toLowerCase(); if (value.equals("1") || value.equals("true")) { node.setAttribute("SUED", "true"); node.setAttribute("WEST", "true"); } node.removeAttribute("SUEDWEST"); } } }  @Override OpenImmoVersion getVersion(); @Override void downgradeToPreviousVersion(OpenImmoDocument doc); @Override void upgradeFromPreviousVersion(OpenImmoDocument doc);  }
@Test public void testDowngradeAusrichtBalkonTerrasseElements() { try { Document doc = buildTransferDocumentForDowngrade(); int count; count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:ausricht_balkon_terrasse[@NORDOST or @NORDWEST or @SUEDOST or @SUEDWEST]", doc); Assert.assertEquals( "3 convertable <ausricht_balkon_terrasse> elements available before conversion.", 3, count); new OpenImmo_1_2_3().downgradeAusrichtBalkonTerrasseElements(doc); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:ausricht_balkon_terrasse[@NORDOST or @NORDWEST or @SUEDOST or @SUEDWEST]", doc); Assert.assertEquals( "0 convertable <ausricht_balkon_terrasse> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:ausricht_balkon_terrasse[@NORD='true' and @OST='true']", doc); Assert.assertEquals( "1 converted <ausricht_balkon_terrasse> element available after conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:ausricht_balkon_terrasse[@SUED='true' and @WEST='true']", doc); Assert.assertEquals( "1 converted <ausricht_balkon_terrasse> element available after conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:ausricht_balkon_terrasse[@NORD or @OST or @SUED or @WEST]", doc); Assert.assertEquals( "2 converted <ausricht_balkon_terrasse> element available after conversion.", 2, count); } catch (Exception ex) { LOGGER.error("Test of OpenImmo_1_2_3.downgradeAusrichtBalkonTerrasseElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmo_1_2_3.downgradeAusrichtBalkonTerrasseElements failed!"); } }