Commit 792b9095 authored by Daniel Lehmberg's avatar Daniel Lehmberg
Browse files

closes #262

parent 188ebf8e
Pipeline #146995 failed with stages
in 66 minutes and 3 seconds
...@@ -205,7 +205,7 @@ public class TextView extends JPanel implements IJsonView { ...@@ -205,7 +205,7 @@ public class TextView extends JPanel implements IJsonView {
if (scenarioChecker != null){ if (scenarioChecker != null){
scenarioChecker.checkScenario(currentScenario); scenarioChecker.checkScenario(currentScenario);
} }
} catch (Exception e) { } catch (IOException e) {
ScenarioPanel.setActiveJsonParsingErrorMsg(attributeType.name() + " tab:\n" + e.getMessage()); ScenarioPanel.setActiveJsonParsingErrorMsg(attributeType.name() + " tab:\n" + e.getMessage());
jsonValidIndicator.setInvalid(); jsonValidIndicator.setInvalid();
} }
......
...@@ -24,11 +24,11 @@ public class JsonConverter { ...@@ -24,11 +24,11 @@ public class JsonConverter {
return deserializeScenarioRunManagerFromNode(StateJsonConverter.readTree(json)); return deserializeScenarioRunManagerFromNode(StateJsonConverter.readTree(json));
} }
public static ModelDefinition deserializeModelDefinition(String json) throws Exception { public static ModelDefinition deserializeModelDefinition(String json) throws IOException {
JsonNode node = StateJsonConverter.readTree(json); JsonNode node = StateJsonConverter.readTree(json);
StateJsonConverter.checkForTextOutOfNode(json); StateJsonConverter.checkForTextOutOfNode(json);
if (!node.has(StateJsonConverter.MAIN_MODEL_KEY)) if (!node.has(StateJsonConverter.MAIN_MODEL_KEY))
throw new Exception("No " + StateJsonConverter.MAIN_MODEL_KEY + "-entry was found."); throw new IOException("No " + StateJsonConverter.MAIN_MODEL_KEY + "-entry was found.");
String mainModelString = null; String mainModelString = null;
JsonNode mainModel = node.get(StateJsonConverter.MAIN_MODEL_KEY); JsonNode mainModel = node.get(StateJsonConverter.MAIN_MODEL_KEY);
if (!mainModel.isNull()) { // avoid test-instantiating when mainModel isn't set, otherwise user has invalid json when creating a new scenario if (!mainModel.isNull()) { // avoid test-instantiating when mainModel isn't set, otherwise user has invalid json when creating a new scenario
...@@ -81,8 +81,7 @@ public class JsonConverter { ...@@ -81,8 +81,7 @@ public class JsonConverter {
return StateJsonConverter.writeValueAsString(serializeScenarioRunManagerToNode(scenarioRunManager, commitHashIncluded)); return StateJsonConverter.writeValueAsString(serializeScenarioRunManagerToNode(scenarioRunManager, commitHashIncluded));
} }
public static JsonNode serializeScenarioRunManagerToNode(Scenario scenarioRunManager, public static JsonNode serializeScenarioRunManagerToNode(Scenario scenarioRunManager, boolean commitHashIncluded) {
boolean commitHashIncluded) throws IOException {
ScenarioStore scenarioStore = scenarioRunManager.getScenarioStore(); ScenarioStore scenarioStore = scenarioRunManager.getScenarioStore();
ObjectNode rootNode = StateJsonConverter.createObjectNode(); ObjectNode rootNode = StateJsonConverter.createObjectNode();
serializeMeta(rootNode, commitHashIncluded, scenarioStore); serializeMeta(rootNode, commitHashIncluded, scenarioStore);
......
...@@ -208,7 +208,7 @@ public class TrajectoryReader { ...@@ -208,7 +208,7 @@ public class TrajectoryReader {
} }
} }
private Map<Step, List<Agent>> readStandardTrajectoryFile() throws IOException { private Map<Step, List<Agent>> readStandardTrajectoryFile() throws IOException{
try (BufferedReader in = IOUtils.defaultBufferedReader(this.trajectoryFilePath)) { try (BufferedReader in = IOUtils.defaultBufferedReader(this.trajectoryFilePath)) {
return in.lines() // a stream of lines return in.lines() // a stream of lines
.skip(1) // skip the first line i.e. the header .skip(1) // skip the first line i.e. the header
...@@ -286,7 +286,14 @@ public class TrajectoryReader { ...@@ -286,7 +286,14 @@ public class TrajectoryReader {
} }
if(stridesIndex != NOT_SET_COLUMN_INDEX_IDENTIFIER) { if(stridesIndex != NOT_SET_COLUMN_INDEX_IDENTIFIER) {
FootStep[] footSteps = StateJsonConverter.deserializeObjectFromJson(rowTokens[stridesIndex], FootStep[].class); FootStep[] footSteps;
try{
footSteps = StateJsonConverter.deserializeObjectFromJson(rowTokens[stridesIndex], FootStep[].class);
}catch(IOException e){
e.printStackTrace();
throw new RuntimeException("Could not deserialize foot steps.");
}
for(FootStep footStep : footSteps) { for(FootStep footStep : footSteps) {
ped.addFootStepToTrajectory(footStep); ped.addFootStepToTrajectory(footStep);
} }
......
...@@ -27,6 +27,7 @@ import org.vadere.util.geometry.shapes.VPoint; ...@@ -27,6 +27,7 @@ import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle; import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.geometry.shapes.VShape; import org.vadere.util.geometry.shapes.VShape;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -77,7 +78,12 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -77,7 +78,12 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
public void initialize(SourceTestAttributesBuilder builder) { public void initialize(SourceTestAttributesBuilder builder) {
SourceTestData d = new SourceTestData(); SourceTestData d = new SourceTestData();
d.attributesSource = builder.getResult(); try{
d.attributesSource = builder.getResult();
} catch(IOException e){
throw new RuntimeException(e.getMessage());
}
d.attributesPedestrian = new AttributesAgent(); d.attributesPedestrian = new AttributesAgent();
d.random = new Random(builder.getRandomSeed()); d.random = new Random(builder.getRandomSeed());
...@@ -524,7 +530,7 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -524,7 +530,7 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
@Test @Test
public void testCentroid() { public void testCentroid() throws IOException {
AttributesSource attributesSource = AttributesSource attributesSource =
StateJsonConverter.deserializeObjectFromJson(sourceJson, AttributesSource.class); StateJsonConverter.deserializeObjectFromJson(sourceJson, AttributesSource.class);
Source source = new Source(attributesSource); Source source = new Source(attributesSource);
...@@ -537,7 +543,7 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -537,7 +543,7 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
} }
@Test @Test
public void testSource() { public void testSource() throws IOException {
AttributesSource attributesSource = AttributesSource attributesSource =
StateJsonConverter.deserializeObjectFromJson(sourceJson, AttributesSource.class); StateJsonConverter.deserializeObjectFromJson(sourceJson, AttributesSource.class);
......
...@@ -17,6 +17,7 @@ import org.vadere.util.geometry.shapes.VPoint; ...@@ -17,6 +17,7 @@ import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle; import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.geometry.shapes.VShape; import org.vadere.util.geometry.shapes.VShape;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random; import java.util.Random;
...@@ -45,7 +46,7 @@ public class TestSourceControllerUsingConstantSpawnRate { ...@@ -45,7 +46,7 @@ public class TestSourceControllerUsingConstantSpawnRate {
} }
public void initialize(SourceTestAttributesBuilder builder) { public void initialize(SourceTestAttributesBuilder builder) throws IOException{
SourceTestData d = new SourceTestData(); SourceTestData d = new SourceTestData();
...@@ -97,7 +98,7 @@ public class TestSourceControllerUsingConstantSpawnRate { ...@@ -97,7 +98,7 @@ public class TestSourceControllerUsingConstantSpawnRate {
* Test method for {@link org.vadere.simulator.control.SourceController#update(double)}. * Test method for {@link org.vadere.simulator.control.SourceController#update(double)}.
*/ */
@Test @Test
public void testUpdateEqualStartAndEndTime() { public void testUpdateEqualStartAndEndTime() throws IOException {
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
.setOneTimeSpawn(0); .setOneTimeSpawn(0);
...@@ -114,7 +115,7 @@ public class TestSourceControllerUsingConstantSpawnRate { ...@@ -114,7 +115,7 @@ public class TestSourceControllerUsingConstantSpawnRate {
* Test method for {@link org.vadere.simulator.control.SourceController#update(double)}. * Test method for {@link org.vadere.simulator.control.SourceController#update(double)}.
*/ */
@Test @Test
public void testUpdateEndTimeLarge() { public void testUpdateEndTimeLarge() throws IOException {
double startTime = 0.0; double startTime = 0.0;
double endTime = 10.0; double endTime = 10.0;
...@@ -136,7 +137,7 @@ public class TestSourceControllerUsingConstantSpawnRate { ...@@ -136,7 +137,7 @@ public class TestSourceControllerUsingConstantSpawnRate {
* Test method for {@link org.vadere.simulator.control.SourceController#update(double)}. * Test method for {@link org.vadere.simulator.control.SourceController#update(double)}.
*/ */
@Test @Test
public void testUpdateSpawnDelayThreeTimes() { public void testUpdateSpawnDelayThreeTimes() throws IOException {
double endTime = 10.0; double endTime = 10.0;
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
...@@ -155,7 +156,7 @@ public class TestSourceControllerUsingConstantSpawnRate { ...@@ -155,7 +156,7 @@ public class TestSourceControllerUsingConstantSpawnRate {
* Test method for {@link org.vadere.simulator.control.SourceController#update(double)}. * Test method for {@link org.vadere.simulator.control.SourceController#update(double)}.
*/ */
@Test @Test
public void testUpdateSmallSpawnDelay() { public void testUpdateSmallSpawnDelay() throws IOException {
double endTime = 1.0; double endTime = 1.0;
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
...@@ -174,7 +175,7 @@ public class TestSourceControllerUsingConstantSpawnRate { ...@@ -174,7 +175,7 @@ public class TestSourceControllerUsingConstantSpawnRate {
* Test method for {@link org.vadere.simulator.control.SourceController#update(double)}. * Test method for {@link org.vadere.simulator.control.SourceController#update(double)}.
*/ */
@Test @Test
public void testUpdateUseFreeSpaceOnly() { public void testUpdateUseFreeSpaceOnly() throws IOException {
AttributesAgent attributesAgent = new AttributesAgent(); AttributesAgent attributesAgent = new AttributesAgent();
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
......
...@@ -10,6 +10,7 @@ import org.vadere.state.scenario.Pedestrian; ...@@ -10,6 +10,7 @@ import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.shapes.VRectangle; import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.geometry.shapes.VShape; import org.vadere.util.geometry.shapes.VShape;
import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
...@@ -29,7 +30,12 @@ public class TestSourceControllerUsingDistributions extends TestSourceController ...@@ -29,7 +30,12 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
public void testStartTime() { public void testStartTime() {
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
.setDistributionClass(ConstantTestDistribution.class); .setDistributionClass(ConstantTestDistribution.class);
initialize(builder);
try{
initialize(builder);
}catch (IOException e){
throw new RuntimeException(e.getMessage());
}
first().sourceController.update(0); first().sourceController.update(0);
pedestrianCountEquals(0); pedestrianCountEquals(0);
...@@ -41,7 +47,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController ...@@ -41,7 +47,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
} }
@Test @Test
public void testEndTime() { public void testEndTime() throws IOException {
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder(); SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder();
initialize(builder); initialize(builder);
...@@ -55,7 +61,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController ...@@ -55,7 +61,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
} }
@Test @Test
public void testOneTimeSpawn() { public void testOneTimeSpawn() throws IOException {
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
.setOneTimeSpawn(1); .setOneTimeSpawn(1);
initialize(builder); initialize(builder);
...@@ -69,7 +75,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController ...@@ -69,7 +75,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
} }
@Test @Test
public void testSpawnNumber() { public void testSpawnNumber() throws IOException{
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
.setSpawnNumber(10); .setSpawnNumber(10);
initialize(builder); initialize(builder);
...@@ -81,7 +87,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController ...@@ -81,7 +87,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
} }
@Test @Test
public void testSpawnRateGreaterThanUpdateRate() { public void testSpawnRateGreaterThanUpdateRate() throws IOException {
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
.setStartTime(0).setEndTime(1) .setStartTime(0).setEndTime(1)
.setSpawnIntervalForConstantDistribution(0.3); .setSpawnIntervalForConstantDistribution(0.3);
...@@ -96,7 +102,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController ...@@ -96,7 +102,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
} }
@Test @Test
public void testUseFreeSpaceOnly() { public void testUseFreeSpaceOnly() throws IOException {
// expected: not stop spawning before all pedestrians are created (even after end time) // expected: not stop spawning before all pedestrians are created (even after end time)
double startTime = 0; double startTime = 0;
double endTime = 1; double endTime = 1;
...@@ -121,7 +127,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController ...@@ -121,7 +127,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
} }
@Test @Test
public void testUseFreeSpaceOnlyWithSingleSpawnEvent() { public void testUseFreeSpaceOnlyWithSingleSpawnEvent() throws IOException {
// works also with sources that have startTime == endTime? // works also with sources that have startTime == endTime?
// expected: not stop spawning before all pedestrians are created (even after end time) // expected: not stop spawning before all pedestrians are created (even after end time)
double startTime = 1; double startTime = 1;
...@@ -148,7 +154,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController ...@@ -148,7 +154,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
} }
@Test @Test
public void testMaxSpawnNumberTotalSetTo0() { public void testMaxSpawnNumberTotalSetTo0() throws IOException {
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
.setMaxSpawnNumberTotal(0); // <-- max 0 -> spawn no peds at all .setMaxSpawnNumberTotal(0); // <-- max 0 -> spawn no peds at all
initialize(builder); initialize(builder);
...@@ -161,7 +167,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController ...@@ -161,7 +167,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
} }
@Test @Test
public void testMaxSpawnNumberTotalNotSet() { public void testMaxSpawnNumberTotalNotSet() throws IOException {
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
.setMaxSpawnNumberTotal(AttributesSource.NO_MAX_SPAWN_NUMBER_TOTAL); // <-- maximum not set .setMaxSpawnNumberTotal(AttributesSource.NO_MAX_SPAWN_NUMBER_TOTAL); // <-- maximum not set
initialize(builder); initialize(builder);
...@@ -174,7 +180,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController ...@@ -174,7 +180,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
} }
@Test @Test
public void testMaxSpawnNumberTotalWithSmallEndTime() { public void testMaxSpawnNumberTotalWithSmallEndTime() throws IOException {
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
.setMaxSpawnNumberTotal(4); // <-- not exhausted .setMaxSpawnNumberTotal(4); // <-- not exhausted
initialize(builder); initialize(builder);
...@@ -187,7 +193,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController ...@@ -187,7 +193,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
} }
@Test @Test
public void testMaxSpawnNumberTotalWithLargeEndTime() { public void testMaxSpawnNumberTotalWithLargeEndTime() throws IOException {
double endTime = 100; double endTime = 100;
int maxSpawnNumberTotal = 4; int maxSpawnNumberTotal = 4;
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
...@@ -201,7 +207,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController ...@@ -201,7 +207,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
} }
@Test @Test
public void testMaxSpawnNumberTotalWithLargeEndTimeAndSpawnNumberGreater1() { public void testMaxSpawnNumberTotalWithLargeEndTimeAndSpawnNumberGreater1() throws IOException {
int maxSpawnNumberTotal = 4; // <-- exhausted! int maxSpawnNumberTotal = 4; // <-- exhausted!
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
.setEndTime(100) .setEndTime(100)
...@@ -219,7 +225,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController ...@@ -219,7 +225,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
* source and not within its bound and that no overlap occurs. * source and not within its bound and that no overlap occurs.
*/ */
@Test @Test
public void testPolygonShapedSourceNoRandom() { public void testPolygonShapedSourceNoRandom() throws IOException {
int maxSpawnNumberTotal = 5; int maxSpawnNumberTotal = 5;
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
.setEndTime(100) .setEndTime(100)
...@@ -253,7 +259,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController ...@@ -253,7 +259,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
* source and not within its bound and that no overlap occurs. * source and not within its bound and that no overlap occurs.
*/ */
@Test @Test
public void testPolygonShapedSourceWithRandom() { public void testPolygonShapedSourceWithRandom() throws IOException {
int maxSpawnNumberTotal = 5; int maxSpawnNumberTotal = 5;
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
.setEndTime(100) .setEndTime(100)
......
...@@ -11,7 +11,6 @@ import org.vadere.state.attributes.models.AttributesPotentialCompact; ...@@ -11,7 +11,6 @@ import org.vadere.state.attributes.models.AttributesPotentialCompact;
import org.vadere.state.attributes.scenario.AttributesAgent; import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.Topography; import org.vadere.state.scenario.Topography;
import org.vadere.state.util.StateJsonConverter; import org.vadere.state.util.StateJsonConverter;
import org.vadere.state.util.TextOutOfNodeException;
import org.vadere.util.geometry.shapes.VPoint; import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle; import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.logging.Logger; import org.vadere.util.logging.Logger;
...@@ -146,7 +145,7 @@ public class TestCLOptimalStepsModel { ...@@ -146,7 +145,7 @@ public class TestCLOptimalStepsModel {
*/ */
@Ignore @Ignore
@Before @Before
public void setUp() throws IOException, TextOutOfNodeException { public void setUp() throws IOException {
random = new Random(); random = new Random();
maxStepSize = 0.2f; maxStepSize = 0.2f;
numberOfElements = 256; numberOfElements = 256;
......
...@@ -13,7 +13,6 @@ import org.vadere.state.scenario.Et423Geometry; ...@@ -13,7 +13,6 @@ import org.vadere.state.scenario.Et423Geometry;
import org.vadere.state.scenario.Topography; import org.vadere.state.scenario.Topography;
import org.vadere.state.scenario.TrainGeometry; import org.vadere.state.scenario.TrainGeometry;
import org.vadere.state.util.StateJsonConverter; import org.vadere.state.util.StateJsonConverter;
import org.vadere.state.util.TextOutOfNodeException;
public class TestTopographyAndModelBuilder { public class TestTopographyAndModelBuilder {
...@@ -57,7 +56,7 @@ public class TestTopographyAndModelBuilder { ...@@ -57,7 +56,7 @@ public class TestTopographyAndModelBuilder {
@SuppressWarnings("resource") @SuppressWarnings("resource")
final String json = new Scanner(TestTopographyAndModelBuilder.class.getResourceAsStream(TEST_TRAIN_TOPOGRAPHY_RESOURCE), "UTF-8").useDelimiter("\\A").next(); final String json = new Scanner(TestTopographyAndModelBuilder.class.getResourceAsStream(TEST_TRAIN_TOPOGRAPHY_RESOURCE), "UTF-8").useDelimiter("\\A").next();
return StateJsonConverter.deserializeTopography(json); return StateJsonConverter.deserializeTopography(json);
} catch (IOException | TextOutOfNodeException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException(e); throw new RuntimeException(e);
} }
......
...@@ -8,6 +8,7 @@ import org.vadere.util.geometry.shapes.VRectangle; ...@@ -8,6 +8,7 @@ import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.geometry.shapes.VShape; import org.vadere.util.geometry.shapes.VShape;
import java.awt.geom.Path2D; import java.awt.geom.Path2D;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
public class SourceTestAttributesBuilder { public class SourceTestAttributesBuilder {
...@@ -33,7 +34,7 @@ public class SourceTestAttributesBuilder { ...@@ -33,7 +34,7 @@ public class SourceTestAttributesBuilder {
private double y3 = 5.0; private double y3 = 5.0;
private long randomSeed = 0; private long randomSeed = 0;
public AttributesSource getResult() { public AttributesSource getResult() throws IOException {
String json = generateSourceAttributesJson(); String json = generateSourceAttributesJson();
return StateJsonConverter.deserializeObjectFromJson(json, AttributesSource.class); return StateJsonConverter.deserializeObjectFromJson(json, AttributesSource.class);
} }
......
...@@ -3,6 +3,7 @@ package org.vadere.state.util; ...@@ -3,6 +3,7 @@ package org.vadere.state.util;
import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.ObjectWriter;
...@@ -79,16 +80,10 @@ public abstract class StateJsonConverter { ...@@ -79,16 +80,10 @@ public abstract class StateJsonConverter {
return prettyWriter; return prettyWriter;
} }
// TODO handle exception public static <T> T deserializeObjectFromJson(String json, Class<T> objectClass) throws IOException {
public static <T> T deserializeObjectFromJson(String json, Class<T> objectClass) { final JsonNode node = mapper.readTree(json);
checkForTextOutOfNode(json);
try { return mapper.treeToValue(node, objectClass);
final JsonNode node = mapper.readTree(json);
checkForTextOutOfNode(json);
return mapper.treeToValue(node, objectClass);
} catch (TextOutOfNodeException | IOException e) {
throw new RuntimeException(e);
}
} }
public static <T> T deserializeObjectFromJson(String json, final TypeReference<T> type) { public static <T> T deserializeObjectFromJson(String json, final TypeReference<T> type) {
...@@ -135,7 +130,7 @@ public abstract class StateJsonConverter { ...@@ -135,7 +130,7 @@ public abstract class StateJsonConverter {
AttributesTeleporter teleporter = null; AttributesTeleporter teleporter = null;
} }
public static AttributesSimulation deserializeAttributesSimulation(String json) {