CitygmlParserTests.java 3.45 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
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.nio.file.Path;
import java.nio.file.Paths;
import org.junit.Test;
import com.ximpleware.XPathParseException;


public class CitygmlParserTests
{
Matthias Betz's avatar
Matthias Betz committed
14
	private static final String REGION_CHOOSER_TESTDATA = "src/test/resources/testdata";
15
16
17
18
	private static final String COORDINATES_SHOULD_BE_PLAUSIBLE = "Min/Max Coordinates should be plausible";
	private static final String COORDINATE_SHOULD_BE_A_DOUBLE = "Coordinate should be a double";

	private void testNoNanInCoordinates(Path citygmlPath) throws XPathParseException {
19
20
21
		CityGmlIterator buildingXmlNodes = new CityGmlIterator(citygmlPath);
		for (BuildingXmlNode buildingXmlNode : buildingXmlNodes) {
			assertTrue("Buildings should have coordinates", buildingXmlNode.hasCoordinates());
22
23
24
25
26
27
28
29
30
31
			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_SHOULD_BE_PLAUSIBLE, buildingXmlNode.xMax > buildingXmlNode.x);
			assertTrue(COORDINATES_SHOULD_BE_PLAUSIBLE, buildingXmlNode.yMax > buildingXmlNode.y);
			assertTrue(COORDINATES_SHOULD_BE_PLAUSIBLE, buildingXmlNode.xMin < buildingXmlNode.x);
			assertTrue(COORDINATES_SHOULD_BE_PLAUSIBLE, buildingXmlNode.yMin < buildingXmlNode.y);
32
33
34
35
		}
	}

	@Test
36
37
	public void testExtractCoordsFromStuttgart() throws XPathParseException {
		Path repo = Paths.get(REGION_CHOOSER_TESTDATA, "Stuttgart.proj");
38
		Path citygmlPath = repo.resolve("Stuttgart_LOD0_LOD1_buildings_and_trees.gml");
39
40
41
42
		testNoNanInCoordinates(citygmlPath);
	}

	@Test
43
44
	public void testExtractCoordsFromGruenbuehl() throws XPathParseException {
		Path repo = Paths.get(REGION_CHOOSER_TESTDATA, "Gruenbuehl.proj");
45
		Path citygmlPath = repo.resolve("20140218_Gruenbuehl_LOD2_1building.gml");
46
47
48
49
		testNoNanInCoordinates(citygmlPath);
	}

	@Test
50
51
	public void testExtractCoordsFromMunich() throws XPathParseException {
		Path repo = Paths.get(REGION_CHOOSER_TESTDATA, "Muenchen.proj");
52
		Path citygmlPath = repo.resolve("Munich_v_1_0_0.gml");
53
54
55
56
		testNoNanInCoordinates(citygmlPath);
	}

	@Test
57
58
	public void testExtractCoordsFromNYC() throws XPathParseException {
		Path repo = Paths.get(REGION_CHOOSER_TESTDATA, "NewYork.proj");
59
		Path citygmlPath = repo.resolve("ManhattanSmall.gml");
60
61
62
63
		testNoNanInCoordinates(citygmlPath);
	}

	@Test
64
65
	public void testExtractNoCoordsFromEmptyBuilding() throws XPathParseException {
		Path repo = Paths.get(REGION_CHOOSER_TESTDATA, "Stuttgart.proj");
66
		Path citygmlPath = repo.resolve("Stöckach_empty_buildings.gml");
67
68
69
70
71
72
73
74
75
76
77
		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);
	}
}