Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CityDoctor
CityDoctor2
Commits
e6686903
Commit
e6686903
authored
Jul 24, 2025
by
Luna Riegel
Browse files
Test: Add cases for DatabaseHandler
parent
31b9b2cb
Changes
1
Hide whitespace changes
Inline
Side-by-side
CityDoctorParent/CityDoctorModel/src/test/java/de/hft/stuttgart/citydoctor2/database/DataBaseHandlerTest.java
View file @
e6686903
...
...
@@ -3,17 +3,28 @@ package de.hft.stuttgart.citydoctor2.database;
import
de.hft.stuttgart.citydoctor2.datastructure.Building
;
import
de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel
;
import
de.hft.stuttgart.citydoctor2.datastructure.CityObject
;
import
de.hft.stuttgart.citydoctor2.datastructure.ConcretePolygon
;
import
de.hft.stuttgart.citydoctor2.datastructure.Geometry
;
import
de.hft.stuttgart.citydoctor2.datastructure.GeometryTestUtils
;
import
de.hft.stuttgart.citydoctor2.datastructure.GeometryType
;
import
de.hft.stuttgart.citydoctor2.datastructure.LinearRing
;
import
de.hft.stuttgart.citydoctor2.datastructure.Lod
;
import
de.hft.stuttgart.citydoctor2.datastructure.Vertex
;
import
de.hft.stuttgart.citydoctor2.parser.CityGmlParseException
;
import
de.hft.stuttgart.citydoctor2.parser.CityGmlParser
;
import
de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException
;
import
de.hft.stuttgart.citydoctor2.parser.ParserConfiguration
;
import
org.citygml4j.core.model.building.AbstractBuilding
;
import
org.citygml4j.core.visitor.ObjectVisitor
;
import
org.h2gis.functions.factory.H2GISDBFactory
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
org.mockito.Mockito
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.util.List
;
import
static
de
.
hft
.
stuttgart
.
citydoctor2
.
database
.
SerializationTest
.
assertCityObjectEquality
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
...
...
@@ -43,6 +54,152 @@ public class DataBaseHandlerTest {
}
}
@Test
public
void
testGetAllFeatures
()
{
try
(
Connection
con
=
H2GISDBFactory
.
openSpatialDataBase
(
"cd_db"
))
{
Building
b
=
new
Building
();
b
.
addGeometry
(
GeometryTestUtils
.
createDummyGeometry
(
GeometryType
.
SOLID
,
Lod
.
LOD0
));
Building
b2
=
new
Building
();
b2
.
addGeometry
(
GeometryTestUtils
.
createDummyGeometry
(
GeometryType
.
SOLID
,
Lod
.
LOD2
));
Building
b3
=
new
Building
();
b3
.
addGeometry
(
GeometryTestUtils
.
createDummyGeometry
(
GeometryType
.
SOLID
,
Lod
.
LOD3
));
DatabaseHandler
.
marshallCityObject
(
b
);
DatabaseHandler
.
marshallCityObject
(
b2
);
DatabaseHandler
.
marshallCityObject
(
b3
);
assertEquals
(
3
,
DatabaseHandler
.
getFeatureCount
());
List
<
CityObject
>
objects
=
DatabaseHandler
.
getAllCityObjects
();
assertEquals
(
3
,
objects
.
size
());
assertEquals
(
3
,
DatabaseHandler
.
getFeatureCount
());
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
@Test
public
void
testGetBboxIntersectingObjects
()
{
try
(
Connection
con
=
H2GISDBFactory
.
openSpatialDataBase
(
"cd_db"
))
{
Building
b
=
new
Building
();
Building
b2
=
new
Building
();
b2
.
setGmlObject
(
Mockito
.
mock
(
AbstractBuilding
.
class
));
Building
b3
=
new
Building
();
Geometry
geom
=
new
Geometry
(
GeometryType
.
SOLID
,
Lod
.
LOD0
,
Geometry
.
Orientation
.
OUTWARD
);
ConcretePolygon
polygon
=
new
ConcretePolygon
();
geom
.
getPolygons
().
add
(
polygon
);
polygon
.
setParent
(
geom
);
LinearRing
lr
=
new
LinearRing
(
LinearRing
.
LinearRingType
.
EXTERIOR
);
polygon
.
setExteriorRing
(
lr
);
Vertex
v1
=
new
Vertex
(
10
,
10
,
8
);
lr
.
getVertices
().
add
(
v1
);
Vertex
v2
=
new
Vertex
(
14
,
15
,
7
);
lr
.
getVertices
().
add
(
v2
);
Vertex
v3
=
new
Vertex
(
14
,
15
,
3
);
lr
.
getVertices
().
add
(
v3
);
Vertex
v4
=
new
Vertex
(
10
,
10
,
3
);
lr
.
getVertices
().
add
(
v4
);
lr
.
getVertices
().
add
(
v1
);
geom
.
updateEdgesAndVertices
();
b
.
addGeometry
(
geom
);
Geometry
geom2
=
new
Geometry
(
GeometryType
.
SOLID
,
Lod
.
LOD0
,
Geometry
.
Orientation
.
OUTWARD
);
ConcretePolygon
polygon2
=
new
ConcretePolygon
();
geom2
.
getPolygons
().
add
(
polygon2
);
polygon2
.
setParent
(
geom2
);
LinearRing
lr2
=
new
LinearRing
(
LinearRing
.
LinearRingType
.
EXTERIOR
);
polygon2
.
setExteriorRing
(
lr2
);
Vertex
v1b2
=
new
Vertex
(
6
,
6
,
8
);
lr2
.
getVertices
().
add
(
v1b2
);
Vertex
v2b2
=
new
Vertex
(
11
,
13
,
7
);
lr2
.
getVertices
().
add
(
v2b2
);
Vertex
v3b2
=
new
Vertex
(
11
,
13
,
3
);
lr2
.
getVertices
().
add
(
v3b2
);
Vertex
v4b2
=
new
Vertex
(
6
,
6
,
3
);
lr2
.
getVertices
().
add
(
v4b2
);
lr2
.
getVertices
().
add
(
v1b2
);
geom2
.
updateEdgesAndVertices
();
b2
.
addGeometry
(
geom2
);
Geometry
geom3
=
new
Geometry
(
GeometryType
.
SOLID
,
Lod
.
LOD0
,
Geometry
.
Orientation
.
OUTWARD
);
ConcretePolygon
polygon3
=
new
ConcretePolygon
();
geom3
.
getPolygons
().
add
(
polygon3
);
polygon3
.
setParent
(
geom3
);
LinearRing
lr3
=
new
LinearRing
(
LinearRing
.
LinearRingType
.
EXTERIOR
);
polygon3
.
setExteriorRing
(
lr3
);
Vertex
v1b3
=
new
Vertex
(
6
,
6
,
8
);
lr3
.
getVertices
().
add
(
v1b3
);
Vertex
v2b3
=
new
Vertex
(
8
,
9
,
7
);
lr3
.
getVertices
().
add
(
v2b3
);
Vertex
v3b3
=
new
Vertex
(
8
,
9
,
3
);
lr3
.
getVertices
().
add
(
v3b3
);
Vertex
v4b3
=
new
Vertex
(
6
,
6
,
3
);
lr3
.
getVertices
().
add
(
v4b3
);
lr3
.
getVertices
().
add
(
v1b3
);
geom3
.
updateEdgesAndVertices
();
b3
.
addGeometry
(
geom3
);
DatabaseHandler
.
marshallCityObject
(
b
);
DatabaseHandler
.
marshallCityObject
(
b2
);
DatabaseHandler
.
marshallCityObject
(
b3
);
assertEquals
(
3
,
DatabaseHandler
.
getFeatureCount
());
List
<
CityObject
>
objects
=
DatabaseHandler
.
getBBoxIntersectingObjects
(
b
);
assertEquals
(
1
,
objects
.
size
());
assertEquals
(
3
,
DatabaseHandler
.
getFeatureCount
());
assertCityObjectEquality
(
b2
,
objects
.
get
(
0
));
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
@Test
public
void
testGetBboxBufferIntersectingObjects
()
{
try
(
Connection
con
=
H2GISDBFactory
.
openSpatialDataBase
(
"cd_db"
))
{
Building
b
=
new
Building
();
b
.
addGeometry
(
GeometryTestUtils
.
createDummyGeometry
(
GeometryType
.
SOLID
,
Lod
.
LOD0
));
Building
b2
=
new
Building
();
b2
.
setGmlObject
(
Mockito
.
mock
(
AbstractBuilding
.
class
));
Geometry
geom
=
new
Geometry
(
GeometryType
.
SOLID
,
Lod
.
LOD0
,
Geometry
.
Orientation
.
OUTWARD
);
ConcretePolygon
polygon
=
new
ConcretePolygon
();
geom
.
getPolygons
().
add
(
polygon
);
polygon
.
setParent
(
geom
);
LinearRing
lr
=
new
LinearRing
(
LinearRing
.
LinearRingType
.
EXTERIOR
);
polygon
.
setExteriorRing
(
lr
);
Vertex
v1
=
new
Vertex
(
427583.300
,
6003501.572
,
9.911
);
lr
.
getVertices
().
add
(
v1
);
Vertex
v2
=
new
Vertex
(
427583.296
,
6003502.570
,
9.913
);
lr
.
getVertices
().
add
(
v2
);
Vertex
v3
=
new
Vertex
(
427583.296
,
6003502.570
,
4.297
);
lr
.
getVertices
().
add
(
v3
);
Vertex
v4
=
new
Vertex
(
427583.300
,
6003502.572
,
4.297
);
lr
.
getVertices
().
add
(
v4
);
lr
.
getVertices
().
add
(
v1
);
geom
.
updateEdgesAndVertices
();
b2
.
addGeometry
(
geom
);
DatabaseHandler
.
marshallCityObject
(
b
);
DatabaseHandler
.
marshallCityObject
(
b2
);
assertEquals
(
2
,
DatabaseHandler
.
getFeatureCount
());
List
<
CityObject
>
objects
=
DatabaseHandler
.
getBufferIntersectingObjects
(
b
,
0.005
);
assertEquals
(
1
,
objects
.
size
());
assertEquals
(
2
,
DatabaseHandler
.
getFeatureCount
());
assertCityObjectEquality
(
b2
,
objects
.
get
(
0
));
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
@Test
public
void
testMarshallingRoundTripSimpleSolid
()
throws
InvalidGmlFileException
,
CityGmlParseException
{
try
(
Connection
con
=
H2GISDBFactory
.
openSpatialDataBase
(
"cd_db"
))
{
...
...
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