Commit df360506 authored by Riegel's avatar Riegel
Browse files

Test: Add Serialization testcases

parent 2d3ef9cb
Pipeline #11751 failed with stage
in 58 seconds
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.CityDoctorModel;
import de.hft.stuttgart.citydoctor2.datastructure.CityObject;
......@@ -8,8 +7,6 @@ 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.Copy;
import de.hft.stuttgart.citydoctor2.utils.visitors.CityObjectCollector;
import org.h2gis.functions.factory.H2GISDBFactory;
import org.junit.Before;
import org.junit.BeforeClass;
......@@ -17,8 +14,8 @@ import org.junit.Test;
import java.sql.Connection;
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.assertNotNull;
import static org.junit.Assert.fail;
......@@ -26,11 +23,8 @@ import static org.junit.Assert.fail;
public class DataBaseHandlerTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
public static void setUpBeforeClass() {
DatabaseHandler.setupDatabase();
try (Connection con = H2GISDBFactory.openSpatialDataBase("cd_db")) {
assertNotNull(con);
}
}
@Before
......@@ -43,13 +37,45 @@ public class DataBaseHandlerTest {
}
@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")) {
assertNotNull(con);
ParserConfiguration config = new ParserConfiguration(8, false);
CityDoctorModel model = CityGmlParser.parseCityGmlFile("src/test/resources/FZK_haus.gml", config);
Building b = model.getBuildings().get(0);
Copy.copy(b);
assertNotNull(b);
assertEquals(0, DatabaseHandler.getFeatureCount());
DatabaseHandler.marshallCityObject(b);
......@@ -58,19 +84,12 @@ public class DataBaseHandlerTest {
CityObject b2 = DatabaseHandler.unmarshallCityObject(b.getGmlId());
assertNotNull(b2);
assertEquals(1, DatabaseHandler.getFeatureCount());
assertEquals(b.getGmlId(), b2.getGmlId());
assertEquals(b.getFeatureType(), b2.getFeatureType());
CityObjectCollector collector = new CityObjectCollector();
b.accept(collector);
Set<CityObject> coB = collector.getCityObjects();
collector = new CityObjectCollector();
b2.accept(collector);
Set<CityObject> coB2 = collector.getCityObjects();
assertEquals(coB.size(), coB2.size());
assertCityObjectEquality(b, b2);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
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);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment