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
df360506
Commit
df360506
authored
Jul 23, 2025
by
Riegel
Browse files
Test: Add Serialization testcases
parent
2d3ef9cb
Pipeline
#11751
failed with stage
in 58 seconds
Changes
3
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
CityDoctorParent/CityDoctorModel/src/test/java/de/hft/stuttgart/citydoctor2/database/DataBaseHandlerTest.java
View file @
df360506
package
de.hft.stuttgart.citydoctor2.database
;
package
de.hft.stuttgart.citydoctor2.database
;
import
de.hft.stuttgart.citydoctor2.check.CheckableUtilsVisitor
;
import
de.hft.stuttgart.citydoctor2.datastructure.Building
;
import
de.hft.stuttgart.citydoctor2.datastructure.Building
;
import
de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel
;
import
de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel
;
import
de.hft.stuttgart.citydoctor2.datastructure.CityObject
;
import
de.hft.stuttgart.citydoctor2.datastructure.CityObject
;
...
@@ -8,8 +7,6 @@ import de.hft.stuttgart.citydoctor2.parser.CityGmlParseException;
...
@@ -8,8 +7,6 @@ import de.hft.stuttgart.citydoctor2.parser.CityGmlParseException;
import
de.hft.stuttgart.citydoctor2.parser.CityGmlParser
;
import
de.hft.stuttgart.citydoctor2.parser.CityGmlParser
;
import
de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException
;
import
de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException
;
import
de.hft.stuttgart.citydoctor2.parser.ParserConfiguration
;
import
de.hft.stuttgart.citydoctor2.parser.ParserConfiguration
;
import
de.hft.stuttgart.citydoctor2.utils.Copy
;
import
de.hft.stuttgart.citydoctor2.utils.visitors.CityObjectCollector
;
import
org.h2gis.functions.factory.H2GISDBFactory
;
import
org.h2gis.functions.factory.H2GISDBFactory
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.BeforeClass
;
...
@@ -17,8 +14,8 @@ import org.junit.Test;
...
@@ -17,8 +14,8 @@ import org.junit.Test;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.util.Set
;
import
static
de
.
hft
.
stuttgart
.
citydoctor2
.
database
.
SerializationTest
.
assertCityObjectEquality
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
junit
.
Assert
.
fail
;
...
@@ -26,11 +23,8 @@ import static org.junit.Assert.fail;
...
@@ -26,11 +23,8 @@ import static org.junit.Assert.fail;
public
class
DataBaseHandlerTest
{
public
class
DataBaseHandlerTest
{
@BeforeClass
@BeforeClass
public
static
void
setUpBeforeClass
()
throws
Exception
{
public
static
void
setUpBeforeClass
()
{
DatabaseHandler
.
setupDatabase
();
DatabaseHandler
.
setupDatabase
();
try
(
Connection
con
=
H2GISDBFactory
.
openSpatialDataBase
(
"cd_db"
))
{
assertNotNull
(
con
);
}
}
}
@Before
@Before
...
@@ -43,13 +37,45 @@ public class DataBaseHandlerTest {
...
@@ -43,13 +37,45 @@ public class DataBaseHandlerTest {
}
}
@Test
@Test
public
void
cityObjectMarshallingTest
()
throws
InvalidGmlFileException
,
CityGmlParseException
{
public
void
testSetup
()
throws
SQLException
{
try
(
Connection
con
=
H2GISDBFactory
.
openSpatialDataBase
(
"cd_db"
))
{
assertNotNull
(
con
);
}
}
@Test
public
void
testMarshallingRoundTripSimpleSolid
()
throws
InvalidGmlFileException
,
CityGmlParseException
{
try
(
Connection
con
=
H2GISDBFactory
.
openSpatialDataBase
(
"cd_db"
))
{
assertNotNull
(
con
);
ParserConfiguration
config
=
new
ParserConfiguration
(
8
,
false
);
CityDoctorModel
model
=
CityGmlParser
.
parseCityGmlFile
(
"src/test/resources/SimpleSolid_SrefBS.gml"
,
config
);
Building
b
=
model
.
getBuildings
().
get
(
0
);
assertNotNull
(
b
);
assertEquals
(
0
,
DatabaseHandler
.
getFeatureCount
());
DatabaseHandler
.
marshallCityObject
(
b
);
assertEquals
(
1
,
DatabaseHandler
.
getFeatureCount
());
CityObject
b2
=
DatabaseHandler
.
unmarshallCityObject
(
b
.
getGmlId
());
assertNotNull
(
b2
);
assertEquals
(
1
,
DatabaseHandler
.
getFeatureCount
());
assertCityObjectEquality
(
b
,
b2
);
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
@Test
public
void
testMarshallingRoundTripFzk
()
throws
InvalidGmlFileException
,
CityGmlParseException
{
try
(
Connection
con
=
H2GISDBFactory
.
openSpatialDataBase
(
"cd_db"
))
{
try
(
Connection
con
=
H2GISDBFactory
.
openSpatialDataBase
(
"cd_db"
))
{
assertNotNull
(
con
);
assertNotNull
(
con
);
ParserConfiguration
config
=
new
ParserConfiguration
(
8
,
false
);
ParserConfiguration
config
=
new
ParserConfiguration
(
8
,
false
);
CityDoctorModel
model
=
CityGmlParser
.
parseCityGmlFile
(
"src/test/resources/FZK_haus.gml"
,
config
);
CityDoctorModel
model
=
CityGmlParser
.
parseCityGmlFile
(
"src/test/resources/FZK_haus.gml"
,
config
);
Building
b
=
model
.
getBuildings
().
get
(
0
);
Building
b
=
model
.
getBuildings
().
get
(
0
);
Copy
.
copy
(
b
);
assertNotNull
(
b
);
assertNotNull
(
b
);
assertEquals
(
0
,
DatabaseHandler
.
getFeatureCount
());
assertEquals
(
0
,
DatabaseHandler
.
getFeatureCount
());
DatabaseHandler
.
marshallCityObject
(
b
);
DatabaseHandler
.
marshallCityObject
(
b
);
...
@@ -58,19 +84,12 @@ public class DataBaseHandlerTest {
...
@@ -58,19 +84,12 @@ public class DataBaseHandlerTest {
CityObject
b2
=
DatabaseHandler
.
unmarshallCityObject
(
b
.
getGmlId
());
CityObject
b2
=
DatabaseHandler
.
unmarshallCityObject
(
b
.
getGmlId
());
assertNotNull
(
b2
);
assertNotNull
(
b2
);
assertEquals
(
1
,
DatabaseHandler
.
getFeatureCount
());
assertEquals
(
1
,
DatabaseHandler
.
getFeatureCount
());
assertEquals
(
b
.
getGmlId
(),
b2
.
getGmlId
());
assertEquals
(
b
.
getFeatureType
(),
b2
.
getFeatureType
());
CityObjectCollector
collector
=
new
CityObjectCollector
();
assertCityObjectEquality
(
b
,
b2
);
b
.
accept
(
collector
);
Set
<
CityObject
>
coB
=
collector
.
getCityObjects
();
collector
=
new
CityObjectCollector
();
b2
.
accept
(
collector
);
Set
<
CityObject
>
coB2
=
collector
.
getCityObjects
();
assertEquals
(
coB
.
size
(),
coB2
.
size
());
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
}
}
}
}
}
}
CityDoctorParent/CityDoctorModel/src/test/java/de/hft/stuttgart/citydoctor2/database/SerializationTest.java
0 → 100644
View file @
df360506
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.parser.CityGmlParseException
;
import
de.hft.stuttgart.citydoctor2.parser.CityGmlParser
;
import
de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException
;
import
de.hft.stuttgart.citydoctor2.parser.ParserConfiguration
;
import
de.hft.stuttgart.citydoctor2.utils.visitors.CityObjectCollector
;
import
org.apache.commons.lang3.SerializationUtils
;
import
org.junit.Test
;
import
java.util.Set
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
public
class
SerializationTest
{
static
void
assertCityObjectEquality
(
CityObject
c1
,
CityObject
c2
)
{
assertEquals
(
c1
.
getGmlId
(),
c2
.
getGmlId
());
assertEquals
(
c1
.
getFeatureType
(),
c2
.
getFeatureType
());
assertEquals
(
c1
.
getGmlObject
().
getId
(),
c2
.
getGmlObject
().
getId
());
CityObjectCollector
collector
=
new
CityObjectCollector
();
c1
.
accept
(
collector
);
Set
<
CityObject
>
coB
=
collector
.
getCityObjects
();
collector
=
new
CityObjectCollector
();
c2
.
accept
(
collector
);
Set
<
CityObject
>
coB2
=
collector
.
getCityObjects
();
assertEquals
(
coB
.
size
(),
coB2
.
size
());
}
@Test
public
void
testRoundtripSimpleSolid
()
throws
CityGmlParseException
,
InvalidGmlFileException
{
ParserConfiguration
config
=
new
ParserConfiguration
(
8
,
false
);
CityDoctorModel
model
=
CityGmlParser
.
parseCityGmlFile
(
"src/test/resources/SimpleSolid_SrefBS.gml"
,
config
);
Building
b
=
model
.
getBuildings
().
get
(
0
);
assertNotNull
(
b
);
Building
b2
=
SerializationUtils
.
roundtrip
(
b
);
assertNotNull
(
b2
);
assertCityObjectEquality
(
b
,
b2
);
}
@Test
public
void
testRoundtripFzk
()
throws
CityGmlParseException
,
InvalidGmlFileException
{
ParserConfiguration
config
=
new
ParserConfiguration
(
8
,
false
);
CityDoctorModel
model
=
CityGmlParser
.
parseCityGmlFile
(
"src/test/resources/FZK_haus.gml"
,
config
);
Building
b
=
model
.
getBuildings
().
get
(
0
);
assertNotNull
(
b
);
Building
b2
=
SerializationUtils
.
roundtrip
(
b
);
assertCityObjectEquality
(
b
,
b2
);
}
}
CityDoctorParent/CityDoctorModel/src/test/resources/04-FZK-Haus-LoD2-Tex-Storey-CG30-V01-InteriorSurface.gml
0 → 100644
View file @
df360506
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