OpenImmo_1_2_4 extends XmlConverter<OpenImmoDocument, OpenImmoVersion> { protected void downgradeLandUndForstwirtschaftElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:land_und_forstwirtschaft[@land_typ]", doc).selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; String value = StringUtils.trimToNull(node.getAttribute("land_typ")); if ("JAGDREVIER".equalsIgnoreCase(value)) node.setAttribute("land_typ", "SONSTIGE_LANDWIRTSCHAFTSIMMOBILIEN"); } }  @Override OpenImmoVersion getVersion(); @Override void downgradeToPreviousVersion(OpenImmoDocument doc); @Override void upgradeFromPreviousVersion(OpenImmoDocument doc);  }
@Test public void testDowngradeLandUndForstwirtschaftElements() { try { Document doc = buildTransferDocumentForDowngrade(); int count; count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:land_und_forstwirtschaft", doc); Assert.assertEquals( "2 <land_und_forstwirtschaft> elements available before conversion.", 2, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:land_und_forstwirtschaft[@land_typ='JAGDREVIER']", doc); Assert.assertEquals( "1 convertable <land_und_forstwirtschaft> element available before conversion.", 1, count); new OpenImmo_1_2_4().downgradeLandUndForstwirtschaftElements(doc); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:land_und_forstwirtschaft", doc); Assert.assertEquals( "2 <land_und_forstwirtschaft> elements available after conversion.", 2, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/land_und_forstwirtschaft[@land_typ='JAGDREVIER']", doc); Assert.assertEquals( "0 convertable <land_und_forstwirtschaft> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:land_und_forstwirtschaft[@land_typ='SONSTIGE_LANDWIRTSCHAFTSIMMOBILIEN']", doc); Assert.assertEquals( "1 converted <land_und_forstwirtschaft> element available after conversion.", 1, count); } catch (Exception ex) { LOGGER.error("Test of OpenImmo_1_2_4.downgradeLandUndForstwirtschaftElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmo_1_2_4.downgradeLandUndForstwirtschaftElements failed!"); } }