OpenImmo_1_2_5 extends XmlConverter<OpenImmoDocument, OpenImmoVersion> { protected void downgradeEnergiepassElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass", doc).selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; Element parentNode = (Element) node.getParentNode(); boolean hwbwertPassed = false; boolean hwbklassePassed = false; boolean fgeewertPassed = false; boolean fgeeklassePassed = false; List childNodes; childNodes = XmlUtils.newXPath("io:hwbwert", doc) .selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!hwbwertPassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if (value != null) { parentNode.appendChild(OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_hwbwert", value)); hwbwertPassed = true; } } node.removeChild(childNode); } childNodes = XmlUtils.newXPath("io:hwbklasse", doc) .selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!hwbklassePassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if (value != null) { parentNode.appendChild(OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_hwbklasse", value)); hwbklassePassed = true; } } node.removeChild(childNode); } childNodes = XmlUtils.newXPath("io:fgeewert", doc) .selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!fgeewertPassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if (value != null) { parentNode.appendChild(OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_fgeewert", value)); fgeewertPassed = true; } } node.removeChild(childNode); } childNodes = XmlUtils.newXPath("io:fgeeklasse", doc) .selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!fgeeklassePassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if (value != null) { parentNode.appendChild(OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_fgeeklasse", value)); fgeeklassePassed = true; } } node.removeChild(childNode); } } }  @Override OpenImmoVersion getVersion(); @Override void downgradeToPreviousVersion(OpenImmoDocument doc); @Override @SuppressWarnings("Duplicates") void upgradeFromPreviousVersion(OpenImmoDocument doc);  }
@Test public void testDowngradeEnergiepassElements() { try { Document doc = buildTransferDocumentForDowngrade(); int count; count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:hwbwert", doc); Assert.assertEquals( "1 convertable <hwbwert> element available before conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:hwbklasse", doc); Assert.assertEquals( "1 convertable <hwbklasse> element available before conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:fgeewert", doc); Assert.assertEquals("1 convertable <fgeewert> element available before conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:fgeeklasse", doc); Assert.assertEquals( "1 convertable <fgeeklasse> element available before conversion.", 1, count); new OpenImmo_1_2_5().downgradeEnergiepassElements(doc); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:hwbwert", doc); Assert.assertEquals( "0 convertable <hwbwert> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:hwbklasse", doc); Assert.assertEquals( "0 convertable <hwbklasse> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:fgeewert", doc); Assert.assertEquals( "0 convertable <fgeewert> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:fgeeklasse", doc); Assert.assertEquals( "0 convertable <fgeeklasse> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:user_defined_simplefield[@feldname='epass_hwbwert']", doc); Assert.assertEquals( "1 converted <user_defined_simplefield feldname=\"epass_hwbwert\"> element available after conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:user_defined_simplefield[@feldname='epass_hwbklasse']", doc); Assert.assertEquals( "1 converted <user_defined_simplefield feldname=\"epass_hwbklasse\"> element available after conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:user_defined_simplefield[@feldname='epass_fgeewert']", doc); Assert.assertEquals( "1 converted <user_defined_simplefield feldname=\"epass_fgeewert\"> element available after conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:user_defined_simplefield[@feldname='epass_fgeeklasse']", doc); Assert.assertEquals( "1 converted <user_defined_simplefield feldname=\"epass_fgeeklasse\"> element available after conversion.", 1, count); } catch (Exception ex) { LOGGER.error("Test of OpenImmo_1_2_5.downgradeEnergiepassElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmo_1_2_5.downgradeEnergiepassElements failed!"); } }