package eu.simstadt.geo.fast_xml_parser; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import org.junit.Test; import com.ximpleware.NavException; import com.ximpleware.XPathEvalException; import com.ximpleware.XPathParseException; public class CitygmlParserTests { private void testNoNanInCoordinates(Path citygmlPath) throws NumberFormatException, XPathParseException, NavException, XPathEvalException, IOException { CityGmlIterator buildingXmlNodes = new CityGmlIterator(citygmlPath); for (BuildingXmlNode buildingXmlNode : buildingXmlNodes) { assertTrue("Buildings should have coordinates", buildingXmlNode.hasCoordinates()); assertFalse("Coordinate should be a double", Double.isNaN(buildingXmlNode.x)); assertFalse("Coordinate should be a double", Double.isNaN(buildingXmlNode.y)); assertFalse("Coordinate should be a double", Double.isNaN(buildingXmlNode.xMax)); assertFalse("Coordinate should be a double", Double.isNaN(buildingXmlNode.yMax)); assertFalse("Coordinate should be a double", Double.isNaN(buildingXmlNode.xMin)); assertFalse("Coordinate should be a double", Double.isNaN(buildingXmlNode.yMin)); assertTrue("Coordinates Min/Max should be plausible", buildingXmlNode.xMax > buildingXmlNode.x); assertTrue("Coordinates Min/Max should be plausible", buildingXmlNode.yMax > buildingXmlNode.y); assertTrue("Coordinates Min/Max should be plausible", buildingXmlNode.xMin < buildingXmlNode.x); assertTrue("Coordinates Min/Max should be plausible", buildingXmlNode.yMin < buildingXmlNode.y); } } @Test public void testExtractCoordsFromStuttgart() throws NumberFormatException, XPathParseException, NavException, XPathEvalException, IOException { Path repo = Paths.get("../RegionChooser/test/testdata"); Path citygmlPath = repo.resolve("Stuttgart_LOD0_LOD1_buildings_and_trees.gml"); testNoNanInCoordinates(citygmlPath); } @Test public void testExtractCoordsFromGruenbuehl() throws Throwable { Path repo = Paths.get("../RegionChooser/test/testdata"); Path citygmlPath = repo.resolve("20140218_Gruenbuehl_LOD2_1building.gml"); testNoNanInCoordinates(citygmlPath); } @Test public void testExtractCoordsFromMunich() throws Throwable { Path repo = Paths.get("../RegionChooser/test/testdata"); Path citygmlPath = repo.resolve("Munich_v_1_0_0.gml"); testNoNanInCoordinates(citygmlPath); } @Test public void testExtractCoordsFromNYC() throws Throwable { Path repo = Paths.get("../RegionChooser/test/testdata"); Path citygmlPath = repo.resolve("ManhattanSmall.gml"); testNoNanInCoordinates(citygmlPath); } @Test public void testExtractNoCoordsFromEmptyBuilding() throws Throwable { Path repo = Paths.get("../RegionChooser/test/testdata"); Path citygmlPath = repo.resolve("Stöckach_empty_buildings.gml"); CityGmlIterator buildingXmlNodes = new CityGmlIterator(citygmlPath); int counter = 0; for (BuildingXmlNode buildingXmlNode : buildingXmlNodes) { assertFalse("Empty Buildings shouldn't have coordinates", buildingXmlNode.hasCoordinates()); assertTrue("Coordinate should be a Nan", Double.isNaN(buildingXmlNode.x)); assertTrue("Coordinate should be a Nan", Double.isNaN(buildingXmlNode.y)); counter++; } assertEquals("3 buildings should have been analyzed", counter, 3); } }