diff --git a/src/test/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterfaceTest.java b/src/test/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterfaceTest.java index 6ca78b805f95d6105fbb68f183f94bade0de7818..36cf66c086d39b4c6c68a79e05f4c61fe28f76f2 100644 --- a/src/test/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterfaceTest.java +++ b/src/test/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterfaceTest.java @@ -2,9 +2,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.BufferedWriter; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.PrintStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -75,13 +78,44 @@ void testExtractRegionFromTwoCitygmlsInWGS84() throws IOException { } new CommandLine(new RegionChooserCommandLineInterface()).execute("--input=" + citygml1 + "," + citygml2, "--output=" + outGML, "--wkt=" + inWKT); - originalOut.println(err.toString()); String expectedLog = "EPSG:31463"; assertTrue(err.toString().contains(expectedLog), err.toString() + " should contain " + expectedLog); expectedLog = "Buildings found in selected region 22"; assertTrue(err.toString().contains(expectedLog), err.toString() + " should contain " + expectedLog); assertTrue(Files.size(outGML) > 300_000); } - //TODO: Test with stdin + + @Test + void testExtractRegionWithStandardInput() throws IOException { + String wktPolygon = "POLYGON((-73.9959209576448 40.73286384885367, -73.996317924579 40.732359794090684, -73.9947515145143 40.7315061442504, -73.99422580154739 40.73214841515045, -73.9959209576448 40.73286384885367))"; + Path citygml = TEST_REPOSITORY.resolve("NewYork.proj/ManhattanSmall.gml"); + Path outGML = Files.createTempFile("output", ".gml"); + InputStream stdin = new ByteArrayInputStream(wktPolygon.getBytes(StandardCharsets.UTF_8)); + System.setIn(stdin); + new CommandLine(new RegionChooserCommandLineInterface()).execute("--input=" + citygml, "--output=" + outGML, + "--wkt=-"); + String expectedLog = "EPSG:32118"; + originalOut.println(err.toString()); + assertTrue(err.toString().contains(expectedLog), err.toString() + " should contain " + expectedLog); + expectedLog = "Buildings found in selected region 2"; + assertTrue(err.toString().contains(expectedLog), err.toString() + " should contain " + expectedLog); + } + + @Test + void testExtractRegionWithMissingInput() throws IOException { + String wktPolygon = "POLYGON((-73.9959209576448 40.73286384885367, -73.996317924579 40.732359794090684, -73.9947515145143 40.7315061442504, -73.99422580154739 40.73214841515045, -73.9959209576448 40.73286384885367))"; + Path citygml = TEST_REPOSITORY.resolve("NewYork.proj/ManhattanSmall.gml"); + Path outGML = Files.createTempFile("output", ".gml"); + Path inWKT = Files.createTempFile("polygon", ".wkt"); + try (BufferedWriter wkt = Files.newBufferedWriter(inWKT)) { + wkt.write(wktPolygon); + } + new CommandLine(new RegionChooserCommandLineInterface()).execute("--input=" + citygml, "--output=" + outGML, + "--wkt=-"); + String expectedLog = "EPSG:32118"; + assertTrue(err.toString().contains(expectedLog), err.toString() + " should contain " + expectedLog); + expectedLog = "Please provide \"POLYGON((x1 y1, x2 y2, ...))\" to standard input."; + assertTrue(err.toString().contains(expectedLog), err.toString() + " should contain " + expectedLog); + } }