From 563c7c93a1588df29953ac07845cd4536f8ee388 Mon Sep 17 00:00:00 2001 From: Riegel Date: Thu, 23 Jan 2025 14:38:24 +0100 Subject: [PATCH] Test: Add testcase for report writing --- .../citydoctor2/check/CheckerTest.java | 71 ++++ .../src/test/resources/feature_types.gml | 396 ++++++++++++++++++ 2 files changed, 467 insertions(+) create mode 100644 CityDoctorParent/CityDoctorValidation/src/test/resources/feature_types.gml diff --git a/CityDoctorParent/CityDoctorValidation/src/test/java/de/hft/stuttgart/citydoctor2/check/CheckerTest.java b/CityDoctorParent/CityDoctorValidation/src/test/java/de/hft/stuttgart/citydoctor2/check/CheckerTest.java index 33686366..324977e9 100644 --- a/CityDoctorParent/CityDoctorValidation/src/test/java/de/hft/stuttgart/citydoctor2/check/CheckerTest.java +++ b/CityDoctorParent/CityDoctorValidation/src/test/java/de/hft/stuttgart/citydoctor2/check/CheckerTest.java @@ -19,6 +19,11 @@ package de.hft.stuttgart.citydoctor2.check; import de.hft.stuttgart.citydoctor2.CityDoctorValidation; +import de.hft.stuttgart.citydoctor2.checkresult.CheckReport; +import de.hft.stuttgart.citydoctor2.checkresult.GlobalErrorStatistics; +import de.hft.stuttgart.citydoctor2.checkresult.GlobalStatistics; +import de.hft.stuttgart.citydoctor2.checkresult.ModelStatistics; +import de.hft.stuttgart.citydoctor2.checkresult.utility.CheckReportParseException; import de.hft.stuttgart.citydoctor2.checks.util.FeatureCheckedListener; import de.hft.stuttgart.citydoctor2.datastructure.Building; import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel; @@ -29,18 +34,22 @@ import de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException; import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration; import de.hft.stuttgart.citydoctor2.zip.CityGmlZipArchive; import de.hft.stuttgart.citydoctor2.zip.CityGmlZipEntry; +import org.apache.commons.io.FileUtils; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author Matthias Betz @@ -189,4 +198,66 @@ public class CheckerTest { Checker.streamCheck(cgmlArch, null, null, config, l, null); } + @Test + public void testReportCreation() throws IOException, CityGmlParseException, InvalidGmlFileException { + Path tmpDir = null; + try { + tmpDir = Files.createTempDirectory("testTmp"); + tmpDir.toFile().deleteOnExit(); + Path xmlPath = tmpDir.resolve("report.xml"); + Path pdfPath = tmpDir.resolve("report.pdf"); + File features = new File("src/test/resources/feature_types.gml"); + CityDoctorModel model = CityGmlParser.parseCityGmlFileSilently( + features.toString(), new ParserConfiguration(8, false)); + assertNotNull(model); + Checker checker = new Checker(model); + checker.runChecks(); + checker.writeXmlReport(xmlPath.toString()); + checker.writePdfReport(pdfPath.toString()); + assertTrue(Files.exists(xmlPath)); + assertTrue(Files.exists(pdfPath)); + try { + CheckReport report = CheckReport.load(xmlPath.toString()); + assertNotNull(report); + + GlobalStatistics globalStatistics = report.getGlobalStatistics(); + assertNotNull(globalStatistics); + + ModelStatistics modelStats = globalStatistics.getModelStats(); + assertNotNull(modelStats); + assertEquals(1, modelStats.getNumBuildings()); + assertEquals(1, modelStats.getNumVegetation()); + assertEquals(1, modelStats.getNumTransportation()); + assertEquals(1, modelStats.getNumTunnelObjects()); + assertEquals(1, modelStats.getNumBridgeObjects()); + assertEquals(1, modelStats.getNumWaterObjects()); + assertEquals(1, modelStats.getNumLandObjects()); + assertEquals(1, modelStats.getNumCityFurniture()); + assertEquals(1, modelStats.getNumGenericCityObjects()); + + GlobalErrorStatistics globError = globalStatistics.getGlobalErrorStats(); + assertNotNull(globError); + assertEquals(0, globError.getNumErrorBuildings()); + assertEquals(0, globError.getNumErrorVegetation()); + assertEquals(0, globError.getNumErrorTransportation()); + assertEquals(0, globError.getNumErrorTunnelObjects()); + assertEquals(0, globError.getNumErrorBridgeObjects()); + assertEquals(0, globError.getNumErrorWaterObjects()); + assertEquals(0, globError.getNumErrorLandObjects()); + assertEquals(1, globError.getNumErrorCityFurniture()); + assertEquals(1, globError.getNumErrorGenericCityObjects()); + + + } catch (CheckReportParseException e) { + fail("Report should be valid file"); + } + + + } finally { + if (tmpDir != null) { + FileUtils.deleteDirectory(tmpDir.toFile()); + } + } + } + } diff --git a/CityDoctorParent/CityDoctorValidation/src/test/resources/feature_types.gml b/CityDoctorParent/CityDoctorValidation/src/test/resources/feature_types.gml new file mode 100644 index 00000000..a8ffa770 --- /dev/null +++ b/CityDoctorParent/CityDoctorValidation/src/test/resources/feature_types.gml @@ -0,0 +1,396 @@ + + + + + + + + + + + 84816.978 447538.908 1.48 84816.938 447538.659 1.48 84817.016 447538.782 1.48 84816.978 447538.908 1.48 + + + + + + + + + + + + + + + + + 85012.343 447455.577 0.88 85010.804 447448.808 0.88 85013.832 447447.447 0.88 85012.343 447455.577 0.88 + + + + + + + + + + + + + + + + + + + 84967.573 447497.445 0.01 84967.538 447497.33 0.01 84964.343 447494.755 0.01 84962.909 447496.556 0.01 84964.913 447498.161 0.01 84964.969 447498.343 0.01 84967.602 447497.541 0.01 84967.573 447497.445 0.01 + + + + + + + + + 84967.602 447497.541 2.36 84964.969 447498.343 2.36 84964.913 447498.161 2.36 84962.909 447496.556 2.36 84964.343 447494.755 2.36 84967.538 447497.33 2.36 84967.573 447497.445 2.36 84967.602 447497.541 2.36 + + + + + + + + + 84967.538 447497.33 0.01 84967.573 447497.445 0.01 84967.573 447497.445 2.36 84967.538 447497.33 2.36 84967.538 447497.33 0.01 + + + + + + + + + 84964.343 447494.755 0.01 84967.538 447497.33 0.01 84967.538 447497.33 2.36 84964.343 447494.755 2.36 84964.343 447494.755 0.01 + + + + + + + + + 84962.909 447496.556 0.01 84964.343 447494.755 0.01 84964.343 447494.755 2.36 84962.909 447496.556 2.36 84962.909 447496.556 0.01 + + + + + + + + + 84964.913 447498.161 0.01 84962.909 447496.556 0.01 84962.909 447496.556 2.36 84964.913 447498.161 2.36 84964.913 447498.161 0.01 + + + + + + + + + 84964.969 447498.343 0.01 84964.913 447498.161 0.01 84964.913 447498.161 2.36 84964.969 447498.343 2.36 84964.969 447498.343 0.01 + + + + + + + + + 84967.602 447497.541 0.01 84964.969 447498.343 0.01 84964.969 447498.343 2.36 84967.602 447497.541 2.36 84967.602 447497.541 0.01 + + + + + + + + + 84967.573 447497.445 0.01 84967.602 447497.541 0.01 84967.602 447497.541 2.36 84967.573 447497.445 2.36 84967.573 447497.445 0.01 + + + + + + + + + + + + + + + + + + + + + 358506.943 5655399.912 47.06 358507.161 5655401.568 47.06 358506.943 5655403.224 47.06 358506.304 5655404.768 47.06 358505.287 5655406.093 47.06 358503.961 5655407.111 47.06 358502.418 5655407.75 47.06 358500.761 5655407.968 47.06 358499.105 5655407.75 47.06 358497.561 5655407.111 47.06 358496.236 5655406.093 47.06 358495.219 5655404.768 47.06 358494.579 5655403.224 47.06 358494.361 5655401.568 47.06 358494.579 5655399.912 47.06 358495.219 5655398.368 47.06 358496.236 5655397.043 47.06 358497.561 5655396.025 47.06 358499.105 5655395.386 47.06 358500.761 5655395.168 47.06 358502.418 5655395.386 47.06 358503.961 5655396.025 47.06 358505.287 5655397.043 47.06 358506.304 5655398.368 47.06 358506.943 5655399.912 47.06 + + + + + + + + + + + + + + + + + + + 85034.582 447448.556 1.27 85034.916 447449.902 1.36 85030.3 447450.585 1.18 85034.582 447448.556 1.27 + + + + + + + + + + + + + + + + + 84930.097 447481.714 0.04 84930.561 447483.073 -0.07 84929.876 447482.352 0.045 84930.097 447481.714 0.04 + + + + + + + + + + + + + + + + + -0.049000 0.085000 1.162000 -0.098000 0.000000 1.162000 -0.049000 -0.085000 1.162000 0.049000 -0.085000 1.162000 0.098000 0.000000 1.162000 0.049000 0.085000 1.162000 -0.049000 0.085000 1.162000 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 13.0 15.0 0.0 + 13.0 15.0 3.0 + 13.0 10.0 3.0 + 13.0 10.0 0.0 + 13.0 15.0 0.0 + + + + + + + + + + + + + + + + + + + 10.0 15.0 0.0 + 10.0 15.0 3.0 + 11.5 15.0 4.5 + 13.0 15.0 3.0 + 13.0 15.0 0.0 + 10.0 15.0 0.0 + + + + + + + + + + + + + + + + + + + 10.0 10.0 3.0 + 10.0 15.0 3.0 + 10.0 15.0 0.0 + 10.0 10.0 0.0 + 10.0 10.0 3.0 + + + + + + + + + + + + + + + + + + + 13.0 10.0 0.0 + 13.0 10.0 3.0 + 11.5 10.0 4.5 + 10.0 10.0 3.0 + 10.0 10.0 0.0 + 13.0 10.0 0.0 + + + + + + + + + + + + + + + + + + + 10.0 10.0 3.0 + 11.5 10.0 4.5 + 11.5 15.0 4.5 + 10.0 15.0 3.0 + 10.0 10.0 3.0 + + + + + + + + + + + 11.5 10.0 4.5 + 13.0 10.0 3.0 + 13.0 15.0 3.0 + 11.5 15.0 4.5 + 11.5 10.0 4.5 + + + + + + + + + + + + + + + + + + + 10.0 10.0 0.0 + 10.0 15.0 0.0 + 13.0 15.0 0.0 + 13.0 10.0 0.0 + 10.0 10.0 0.0 + + + + + + + + + + + + + + + + + + + + 85042.215 447482.383 0.494 + 85042.439 447481.251 0.490 + 85044.905 447482.952 0.490 + 85042.215 447482.383 0.494 + + + + + + + + + \ No newline at end of file -- GitLab