Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eric Duminil
RegionChooser
Commits
386b7a16
Commit
386b7a16
authored
2 years ago
by
Eric Duminil
Browse files
Options
Download
Email Patches
Plain Diff
Full CLI tests. :D
parent
e43835c8
master
develop
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterfaceTest.java
+51
-13
.../regionchooser/RegionChooserCommandLineInterfaceTest.java
with
51 additions
and
13 deletions
+51
-13
src/test/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterfaceTest.java
+
51
-
13
View file @
386b7a16
package
eu.simstadt.regionchooser
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
java.io.BufferedWriter
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.PrintStream
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
org.junit.jupiter.api.AfterEach
;
// JUnit 5
import
org.junit.jupiter.api.BeforeEach
;
// JUnit 5
import
org.junit.jupiter.api.Test
;
import
picocli.CommandLine
;
class
RegionChooserCommandLineInterfaceTest
{
final
PrintStream
originalOut
=
System
.
out
;
final
PrintStream
originalErr
=
System
.
err
;
final
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
final
ByteArrayOutputStream
err
=
new
ByteArrayOutputStream
();
@Test
void
testCLIWithoutArgument
()
{
RegionChooserCommandLineInterface
app
=
new
RegionChooserCommandLineInterface
();
CommandLine
cmd
=
new
CommandLine
(
app
);
private
static
final
Path
TEST_REPOSITORY
=
Paths
.
get
(
"src/test/resources/testdata/"
);
StringWriter
sw
=
new
StringWriter
();
cmd
.
setOut
(
new
PrintWriter
(
sw
));
@BeforeEach
public
void
setUpStreams
()
{
out
.
reset
();
err
.
reset
();
System
.
setOut
(
new
PrintStream
(
out
));
System
.
setErr
(
new
PrintStream
(
err
));
}
// black box testing
int
exitCode
=
cmd
.
execute
(
"--input=input.gml"
,
"--output=output.gml"
,
"--wkt=input.wkt"
);
assertEquals
(
0
,
exitCode
);
as
se
r
tE
quals
(
"Your output is abc..."
,
sw
.
toString
()
);
@AfterEach
public
void
restoreStreams
()
{
System
.
setOut
(
originalOut
);
System
.
setE
rr
(
originalErr
);
}
@Test
void
testNoInput
()
{
new
CommandLine
(
new
RegionChooserCommandLineInterface
()).
execute
(
""
);
originalOut
.
println
(
err
.
toString
());
String
expectedErr
=
"Missing required options: '--input=input.gml', '--output=output.gml', '--wkt=polygon.wkt'"
;
assertTrue
(
err
.
toString
().
contains
(
expectedErr
),
err
.
toString
()
+
" should contain "
+
expectedErr
);
}
@Test
void
testExtractRegionFromTwoCitygmls
()
throws
IOException
{
String
wktPolygon
=
"POLYGON((3512984.7003764412 5405148.310572891,3513038.6360455155 5405010.072163861,3513142.7277745553 5405004.02571992,3514204.1661769524 5405563.192081669,3514399.2818417274 5405720.905457244,3514291.6158155007 5405896.706492759,3512984.7003764412 5405148.310572891))"
;
Path
citygml1
=
TEST_REPOSITORY
.
resolve
(
"Stuttgart.proj/Stuttgart_LOD0_LOD1_small.gml"
);
Path
citygml2
=
TEST_REPOSITORY
.
resolve
(
"Stuttgart.proj/Stöckach_überarbeitete GML-NoBuildingPart.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="
+
citygml1
+
","
+
citygml2
,
"--output="
+
outGML
,
"--wkt="
+
inWKT
,
"--epsg=31463"
,
"--local"
);
String
expectedErr
=
"Buildings found in selected region 20"
;
assertTrue
(
err
.
toString
().
contains
(
expectedErr
),
err
.
toString
()
+
" should contain "
+
expectedErr
);
originalOut
.
println
(
Files
.
size
(
outGML
));
assertTrue
(
Files
.
size
(
outGML
)
>
600_000
);
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets