Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
vadere
vadere
Commits
792b9095
Commit
792b9095
authored
Aug 22, 2019
by
Daniel Lehmberg
Browse files
closes
#262
parent
188ebf8e
Pipeline
#146995
failed with stages
in 66 minutes and 3 seconds
Changes
15
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
VadereGui/src/org/vadere/gui/projectview/view/TextView.java
View file @
792b9095
...
...
@@ -205,7 +205,7 @@ public class TextView extends JPanel implements IJsonView {
if
(
scenarioChecker
!=
null
){
scenarioChecker
.
checkScenario
(
currentScenario
);
}
}
catch
(
Exception
e
)
{
}
catch
(
IO
Exception
e
)
{
ScenarioPanel
.
setActiveJsonParsingErrorMsg
(
attributeType
.
name
()
+
" tab:\n"
+
e
.
getMessage
());
jsonValidIndicator
.
setInvalid
();
}
...
...
VadereSimulator/src/org/vadere/simulator/projects/io/JsonConverter.java
View file @
792b9095
...
...
@@ -24,11 +24,11 @@ public class JsonConverter {
return
deserializeScenarioRunManagerFromNode
(
StateJsonConverter
.
readTree
(
json
));
}
public
static
ModelDefinition
deserializeModelDefinition
(
String
json
)
throws
Exception
{
public
static
ModelDefinition
deserializeModelDefinition
(
String
json
)
throws
IO
Exception
{
JsonNode
node
=
StateJsonConverter
.
readTree
(
json
);
StateJsonConverter
.
checkForTextOutOfNode
(
json
);
if
(!
node
.
has
(
StateJsonConverter
.
MAIN_MODEL_KEY
))
throw
new
Exception
(
"No "
+
StateJsonConverter
.
MAIN_MODEL_KEY
+
"-entry was found."
);
throw
new
IO
Exception
(
"No "
+
StateJsonConverter
.
MAIN_MODEL_KEY
+
"-entry was found."
);
String
mainModelString
=
null
;
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
...
...
@@ -81,8 +81,7 @@ public class JsonConverter {
return
StateJsonConverter
.
writeValueAsString
(
serializeScenarioRunManagerToNode
(
scenarioRunManager
,
commitHashIncluded
));
}
public
static
JsonNode
serializeScenarioRunManagerToNode
(
Scenario
scenarioRunManager
,
boolean
commitHashIncluded
)
throws
IOException
{
public
static
JsonNode
serializeScenarioRunManagerToNode
(
Scenario
scenarioRunManager
,
boolean
commitHashIncluded
)
{
ScenarioStore
scenarioStore
=
scenarioRunManager
.
getScenarioStore
();
ObjectNode
rootNode
=
StateJsonConverter
.
createObjectNode
();
serializeMeta
(
rootNode
,
commitHashIncluded
,
scenarioStore
);
...
...
VadereSimulator/src/org/vadere/simulator/projects/io/TrajectoryReader.java
View file @
792b9095
...
...
@@ -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
))
{
return
in
.
lines
()
// a stream of lines
.
skip
(
1
)
// skip the first line i.e. the header
...
...
@@ -286,7 +286,14 @@ public class TrajectoryReader {
}
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
)
{
ped
.
addFootStepToTrajectory
(
footStep
);
}
...
...
VadereSimulator/tests/org/vadere/simulator/control/GroupSourceControllerTest.java
View file @
792b9095
...
...
@@ -27,6 +27,7 @@ import org.vadere.util.geometry.shapes.VPoint;
import
org.vadere.util.geometry.shapes.VRectangle
;
import
org.vadere.util.geometry.shapes.VShape
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
...
...
@@ -77,7 +78,12 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
public
void
initialize
(
SourceTestAttributesBuilder
builder
)
{
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
.
random
=
new
Random
(
builder
.
getRandomSeed
());
...
...
@@ -524,7 +530,7 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
@Test
public
void
testCentroid
()
{
public
void
testCentroid
()
throws
IOException
{
AttributesSource
attributesSource
=
StateJsonConverter
.
deserializeObjectFromJson
(
sourceJson
,
AttributesSource
.
class
);
Source
source
=
new
Source
(
attributesSource
);
...
...
@@ -537,7 +543,7 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
}
@Test
public
void
testSource
()
{
public
void
testSource
()
throws
IOException
{
AttributesSource
attributesSource
=
StateJsonConverter
.
deserializeObjectFromJson
(
sourceJson
,
AttributesSource
.
class
);
...
...
VadereSimulator/tests/org/vadere/simulator/control/TestSourceControllerUsingConstantSpawnRate.java
View file @
792b9095
...
...
@@ -17,6 +17,7 @@ import org.vadere.util.geometry.shapes.VPoint;
import
org.vadere.util.geometry.shapes.VRectangle
;
import
org.vadere.util.geometry.shapes.VShape
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Random
;
...
...
@@ -45,7 +46,7 @@ public class TestSourceControllerUsingConstantSpawnRate {
}
public
void
initialize
(
SourceTestAttributesBuilder
builder
)
{
public
void
initialize
(
SourceTestAttributesBuilder
builder
)
throws
IOException
{
SourceTestData
d
=
new
SourceTestData
();
...
...
@@ -97,7 +98,7 @@ public class TestSourceControllerUsingConstantSpawnRate {
* Test method for {@link org.vadere.simulator.control.SourceController#update(double)}.
*/
@Test
public
void
testUpdateEqualStartAndEndTime
()
{
public
void
testUpdateEqualStartAndEndTime
()
throws
IOException
{
SourceTestAttributesBuilder
builder
=
new
SourceTestAttributesBuilder
()
.
setOneTimeSpawn
(
0
);
...
...
@@ -114,7 +115,7 @@ public class TestSourceControllerUsingConstantSpawnRate {
* Test method for {@link org.vadere.simulator.control.SourceController#update(double)}.
*/
@Test
public
void
testUpdateEndTimeLarge
()
{
public
void
testUpdateEndTimeLarge
()
throws
IOException
{
double
startTime
=
0.0
;
double
endTime
=
10.0
;
...
...
@@ -136,7 +137,7 @@ public class TestSourceControllerUsingConstantSpawnRate {
* Test method for {@link org.vadere.simulator.control.SourceController#update(double)}.
*/
@Test
public
void
testUpdateSpawnDelayThreeTimes
()
{
public
void
testUpdateSpawnDelayThreeTimes
()
throws
IOException
{
double
endTime
=
10.0
;
SourceTestAttributesBuilder
builder
=
new
SourceTestAttributesBuilder
()
...
...
@@ -155,7 +156,7 @@ public class TestSourceControllerUsingConstantSpawnRate {
* Test method for {@link org.vadere.simulator.control.SourceController#update(double)}.
*/
@Test
public
void
testUpdateSmallSpawnDelay
()
{
public
void
testUpdateSmallSpawnDelay
()
throws
IOException
{
double
endTime
=
1.0
;
SourceTestAttributesBuilder
builder
=
new
SourceTestAttributesBuilder
()
...
...
@@ -174,7 +175,7 @@ public class TestSourceControllerUsingConstantSpawnRate {
* Test method for {@link org.vadere.simulator.control.SourceController#update(double)}.
*/
@Test
public
void
testUpdateUseFreeSpaceOnly
()
{
public
void
testUpdateUseFreeSpaceOnly
()
throws
IOException
{
AttributesAgent
attributesAgent
=
new
AttributesAgent
();
SourceTestAttributesBuilder
builder
=
new
SourceTestAttributesBuilder
()
...
...
VadereSimulator/tests/org/vadere/simulator/control/TestSourceControllerUsingDistributions.java
View file @
792b9095
...
...
@@ -10,6 +10,7 @@ import org.vadere.state.scenario.Pedestrian;
import
org.vadere.util.geometry.shapes.VRectangle
;
import
org.vadere.util.geometry.shapes.VShape
;
import
java.io.IOException
;
import
java.util.Collection
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
...
...
@@ -29,7 +30,12 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
public
void
testStartTime
()
{
SourceTestAttributesBuilder
builder
=
new
SourceTestAttributesBuilder
()
.
setDistributionClass
(
ConstantTestDistribution
.
class
);
initialize
(
builder
);
try
{
initialize
(
builder
);
}
catch
(
IOException
e
){
throw
new
RuntimeException
(
e
.
getMessage
());
}
first
().
sourceController
.
update
(
0
);
pedestrianCountEquals
(
0
);
...
...
@@ -41,7 +47,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
}
@Test
public
void
testEndTime
()
{
public
void
testEndTime
()
throws
IOException
{
SourceTestAttributesBuilder
builder
=
new
SourceTestAttributesBuilder
();
initialize
(
builder
);
...
...
@@ -55,7 +61,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
}
@Test
public
void
testOneTimeSpawn
()
{
public
void
testOneTimeSpawn
()
throws
IOException
{
SourceTestAttributesBuilder
builder
=
new
SourceTestAttributesBuilder
()
.
setOneTimeSpawn
(
1
);
initialize
(
builder
);
...
...
@@ -69,7 +75,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
}
@Test
public
void
testSpawnNumber
()
{
public
void
testSpawnNumber
()
throws
IOException
{
SourceTestAttributesBuilder
builder
=
new
SourceTestAttributesBuilder
()
.
setSpawnNumber
(
10
);
initialize
(
builder
);
...
...
@@ -81,7 +87,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
}
@Test
public
void
testSpawnRateGreaterThanUpdateRate
()
{
public
void
testSpawnRateGreaterThanUpdateRate
()
throws
IOException
{
SourceTestAttributesBuilder
builder
=
new
SourceTestAttributesBuilder
()
.
setStartTime
(
0
).
setEndTime
(
1
)
.
setSpawnIntervalForConstantDistribution
(
0.3
);
...
...
@@ -96,7 +102,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
}
@Test
public
void
testUseFreeSpaceOnly
()
{
public
void
testUseFreeSpaceOnly
()
throws
IOException
{
// expected: not stop spawning before all pedestrians are created (even after end time)
double
startTime
=
0
;
double
endTime
=
1
;
...
...
@@ -121,7 +127,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
}
@Test
public
void
testUseFreeSpaceOnlyWithSingleSpawnEvent
()
{
public
void
testUseFreeSpaceOnlyWithSingleSpawnEvent
()
throws
IOException
{
// works also with sources that have startTime == endTime?
// expected: not stop spawning before all pedestrians are created (even after end time)
double
startTime
=
1
;
...
...
@@ -148,7 +154,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
}
@Test
public
void
testMaxSpawnNumberTotalSetTo0
()
{
public
void
testMaxSpawnNumberTotalSetTo0
()
throws
IOException
{
SourceTestAttributesBuilder
builder
=
new
SourceTestAttributesBuilder
()
.
setMaxSpawnNumberTotal
(
0
);
// <-- max 0 -> spawn no peds at all
initialize
(
builder
);
...
...
@@ -161,7 +167,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
}
@Test
public
void
testMaxSpawnNumberTotalNotSet
()
{
public
void
testMaxSpawnNumberTotalNotSet
()
throws
IOException
{
SourceTestAttributesBuilder
builder
=
new
SourceTestAttributesBuilder
()
.
setMaxSpawnNumberTotal
(
AttributesSource
.
NO_MAX_SPAWN_NUMBER_TOTAL
);
// <-- maximum not set
initialize
(
builder
);
...
...
@@ -174,7 +180,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
}
@Test
public
void
testMaxSpawnNumberTotalWithSmallEndTime
()
{
public
void
testMaxSpawnNumberTotalWithSmallEndTime
()
throws
IOException
{
SourceTestAttributesBuilder
builder
=
new
SourceTestAttributesBuilder
()
.
setMaxSpawnNumberTotal
(
4
);
// <-- not exhausted
initialize
(
builder
);
...
...
@@ -187,7 +193,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
}
@Test
public
void
testMaxSpawnNumberTotalWithLargeEndTime
()
{
public
void
testMaxSpawnNumberTotalWithLargeEndTime
()
throws
IOException
{
double
endTime
=
100
;
int
maxSpawnNumberTotal
=
4
;
SourceTestAttributesBuilder
builder
=
new
SourceTestAttributesBuilder
()
...
...
@@ -201,7 +207,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
}
@Test
public
void
testMaxSpawnNumberTotalWithLargeEndTimeAndSpawnNumberGreater1
()
{
public
void
testMaxSpawnNumberTotalWithLargeEndTimeAndSpawnNumberGreater1
()
throws
IOException
{
int
maxSpawnNumberTotal
=
4
;
// <-- exhausted!
SourceTestAttributesBuilder
builder
=
new
SourceTestAttributesBuilder
()
.
setEndTime
(
100
)
...
...
@@ -219,7 +225,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
* source and not within its bound and that no overlap occurs.
*/
@Test
public
void
testPolygonShapedSourceNoRandom
()
{
public
void
testPolygonShapedSourceNoRandom
()
throws
IOException
{
int
maxSpawnNumberTotal
=
5
;
SourceTestAttributesBuilder
builder
=
new
SourceTestAttributesBuilder
()
.
setEndTime
(
100
)
...
...
@@ -253,7 +259,7 @@ public class TestSourceControllerUsingDistributions extends TestSourceController
* source and not within its bound and that no overlap occurs.
*/
@Test
public
void
testPolygonShapedSourceWithRandom
()
{
public
void
testPolygonShapedSourceWithRandom
()
throws
IOException
{
int
maxSpawnNumberTotal
=
5
;
SourceTestAttributesBuilder
builder
=
new
SourceTestAttributesBuilder
()
.
setEndTime
(
100
)
...
...
VadereSimulator/tests/org/vadere/simulator/models/osm/opencl/TestCLOptimalStepsModel.java
View file @
792b9095
...
...
@@ -11,7 +11,6 @@ import org.vadere.state.attributes.models.AttributesPotentialCompact;
import
org.vadere.state.attributes.scenario.AttributesAgent
;
import
org.vadere.state.scenario.Topography
;
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.VRectangle
;
import
org.vadere.util.logging.Logger
;
...
...
@@ -146,7 +145,7 @@ public class TestCLOptimalStepsModel {
*/
@Ignore
@Before
public
void
setUp
()
throws
IOException
,
TextOutOfNodeException
{
public
void
setUp
()
throws
IOException
{
random
=
new
Random
();
maxStepSize
=
0.2f
;
numberOfElements
=
256
;
...
...
VadereSimulator/tests/org/vadere/simulator/models/seating/TestTopographyAndModelBuilder.java
View file @
792b9095
...
...
@@ -13,7 +13,6 @@ import org.vadere.state.scenario.Et423Geometry;
import
org.vadere.state.scenario.Topography
;
import
org.vadere.state.scenario.TrainGeometry
;
import
org.vadere.state.util.StateJsonConverter
;
import
org.vadere.state.util.TextOutOfNodeException
;
public
class
TestTopographyAndModelBuilder
{
...
...
@@ -57,7 +56,7 @@ public class TestTopographyAndModelBuilder {
@SuppressWarnings
(
"resource"
)
final
String
json
=
new
Scanner
(
TestTopographyAndModelBuilder
.
class
.
getResourceAsStream
(
TEST_TRAIN_TOPOGRAPHY_RESOURCE
),
"UTF-8"
).
useDelimiter
(
"\\A"
).
next
();
return
StateJsonConverter
.
deserializeTopography
(
json
);
}
catch
(
IOException
|
TextOutOfNodeException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
e
);
}
...
...
VadereState/src/org/vadere/state/attributes/scenario/SourceTestAttributesBuilder.java
View file @
792b9095
...
...
@@ -8,6 +8,7 @@ import org.vadere.util.geometry.shapes.VRectangle;
import
org.vadere.util.geometry.shapes.VShape
;
import
java.awt.geom.Path2D
;
import
java.io.IOException
;
import
java.util.Arrays
;
public
class
SourceTestAttributesBuilder
{
...
...
@@ -33,7 +34,7 @@ public class SourceTestAttributesBuilder {
private
double
y3
=
5.0
;
private
long
randomSeed
=
0
;
public
AttributesSource
getResult
()
{
public
AttributesSource
getResult
()
throws
IOException
{
String
json
=
generateSourceAttributesJson
();
return
StateJsonConverter
.
deserializeObjectFromJson
(
json
,
AttributesSource
.
class
);
}
...
...
VadereState/src/org/vadere/state/util/StateJsonConverter.java
View file @
792b9095
...
...
@@ -3,6 +3,7 @@ package org.vadere.state.util;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectWriter
;
...
...
@@ -79,16 +80,10 @@ public abstract class StateJsonConverter {
return
prettyWriter
;
}
// TODO handle exception
public
static
<
T
>
T
deserializeObjectFromJson
(
String
json
,
Class
<
T
>
objectClass
)
{
try
{
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
,
Class
<
T
>
objectClass
)
throws
IOException
{
final
JsonNode
node
=
mapper
.
readTree
(
json
);
checkForTextOutOfNode
(
json
);
return
mapper
.
treeToValue
(
node
,
objectClass
);
}
public
static
<
T
>
T
deserializeObjectFromJson
(
String
json
,
final
TypeReference
<
T
>
type
)
{
...
...
@@ -135,7 +130,7 @@ public abstract class StateJsonConverter {
AttributesTeleporter
teleporter
=
null
;
}
public
static
AttributesSimulation
deserializeAttributesSimulation
(
String
json
)
{
public
static
AttributesSimulation
deserializeAttributesSimulation
(
String
json
)
throws
IOException
{
return
deserializeObjectFromJson
(
json
,
AttributesSimulation
.
class
);
}
...
...
@@ -158,7 +153,7 @@ public abstract class StateJsonConverter {
return
attributesList
;
}
public
static
Topography
deserializeTopography
(
String
json
)
throws
IOException
,
TextOutOfNodeException
{
public
static
Topography
deserializeTopography
(
String
json
)
throws
IOException
{
checkForTextOutOfNode
(
json
);
return
deserializeTopographyFromNode
(
mapper
.
readTree
(
json
));
}
...
...
@@ -178,7 +173,8 @@ public abstract class StateJsonConverter {
return
topography
;
}
public
static
void
checkForTextOutOfNode
(
String
json
)
throws
TextOutOfNodeException
,
IOException
{
// via stackoverflow.com/a/26026359
public
static
void
checkForTextOutOfNode
(
String
json
)
throws
IOException
{
// via stackoverflow.com/a/26026359
JsonParser
jp
=
mapper
.
getFactory
().
createParser
(
json
);
mapper
.
readValue
(
jp
,
JsonNode
.
class
);
try
{
...
...
VadereState/src/org/vadere/state/util/TextOutOfNodeException.java
View file @
792b9095
package
org.vadere.state.util
;
public
class
TextOutOfNodeException
extends
Exception
{
import
java.io.IO
Exception
;
public
class
TextOutOfNodeException
extends
IOException
{
// is an exception to used this case: stackoverflow.com/a/26026359
public
TextOutOfNodeException
()
{
super
(
"Text outside of the JSON Node can't be parsed."
);
}
...
...
VadereState/tests/org/vadere/state/attributes/TestAttributesInitialization.java
View file @
792b9095
...
...
@@ -7,6 +7,8 @@ import org.junit.Test;
import
org.vadere.state.attributes.scenario.AttributesAgent
;
import
org.vadere.state.util.StateJsonConverter
;
import
java.io.IOException
;
public
class
TestAttributesInitialization
{
private
static
final
double
delta
=
1
e
-
8
;
...
...
@@ -24,14 +26,14 @@ public class TestAttributesInitialization {
/**
* Test method for
* {@link org.vadere.state.attributes.models.AttributesODEIntegrator
#AttributesODEModel
(java.util.Map)}
* {@link org.vadere.state.attributes.models.AttributesODEIntegrator(java.util.Map)}
* . Asserts the attributes are initialized correctly.
*
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
@Test
public
void
testInit
()
throws
IllegalArgumentException
,
I
llegalAccess
Exception
{
public
void
testInit
()
throws
IllegalArgumentException
,
I
O
Exception
{
// correct case
attributesPedestrian
=
StateJsonConverter
.
deserializeObjectFromJson
(
store
,
AttributesAgent
.
class
);
...
...
@@ -41,14 +43,14 @@ public class TestAttributesInitialization {
/**
* Test method for
* {@link org.vadere.state.attributes.models.AttributesODEIntegrator
#AttributesODEModel
(java.util.Map)}
* {@link org.vadere.state.attributes.models.AttributesODEIntegrator(java.util.Map)}
* . Asserts the default attributes are initialized correctly.
*
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
@Test
public
void
testInitDefault
()
throws
IllegalArgumentException
,
I
llegalAccess
Exception
{
public
void
testInitDefault
()
throws
IllegalArgumentException
,
I
O
Exception
{
// correct case
store
=
"{}"
;
attributesPedestrian
=
StateJsonConverter
.
deserializeObjectFromJson
(
store
,
AttributesAgent
.
class
);
...
...
VadereState/tests/org/vadere/state/attributes/TestAttributesODEModel.java
View file @
792b9095
...
...
@@ -9,6 +9,8 @@ import org.vadere.state.attributes.models.AttributesODEIntegrator;
import
org.vadere.state.types.IntegratorType
;
import
org.vadere.state.util.StateJsonConverter
;
import
java.io.IOException
;
public
class
TestAttributesODEModel
{
private
static
final
double
delta
=
1
e
-
8
;
...
...
@@ -21,22 +23,20 @@ public class TestAttributesODEModel {
@Before
public
void
setUp
()
{
store
=
"{"
+
"\"solverType\" : \"CLASSICAL_RK4\","
+
"\"toleranceAbsolute\" : "
+
new
Double
(
1
e
-
5
)
.
toString
()
+
","
+
"\"toleranceRelative\" : "
+
new
Double
(
1
e
-
5
)
.
toString
()
+
","
+
"\"stepSizeMin\" : "
+
new
Double
(
1
e
-
5
)
.
toString
()
+
","
+
"\"stepSizeMax\" : "
+
new
Double
(
1
e
-
5
)
.
toString
()
+
"}"
;
+
"\"toleranceAbsolute\" : "
+
Double
.
toString
(
1
e
-
5
)
+
","
+
"\"toleranceRelative\" : "
+
Double
.
toString
(
1
e
-
5
)
+
","
+
"\"stepSizeMin\" : "
+
Double
.
toString
(
1
e
-
5
)
+
","
+
"\"stepSizeMax\" : "
+
Double
.
toString
(
1
e
-
5
)
+
"}"
;
}
/**
* Test method for
* {@link org.vadere.state.attributes.models.AttributesODEIntegrator
#AttributesODEModel
(java.util.Map)}
* {@link org.vadere.state.attributes.models.AttributesODEIntegrator(java.util.Map)}
* . Asserts that creating an {@link AttributesODEIntegrator} with the given
* store sets the correct instance variables.
*
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
@Test
public
void
testAttributesODEModel
()
throws
IllegalArgumentException
,
I
llegalAccess
Exception
{
public
void
testAttributesODEModel
()
throws
IllegalArgumentException
,
I
O
Exception
{
// correct case
attributesODEModel
=
StateJsonConverter
.
deserializeObjectFromJson
(
store
,
AttributesODEIntegrator
.
class
);
assertArrayEquals
(
new
double
[]
{
1
e
-
5
},
new
double
[]
{
attributesODEModel
.
getToleranceAbsolute
()},
delta
);
...
...
VadereState/tests/org/vadere/state/attributes/TestPojoJsonDeserialization.java
View file @
792b9095
...
...
@@ -5,7 +5,7 @@ import static org.junit.Assert.*;
import
org.junit.Test
;
import
org.vadere.state.util.StateJsonConverter
;
import
com.fasterxml.jackson.databind.JsonMapping
Exception
;
import
java.io.IO
Exception
;
public
class
TestPojoJsonDeserialization
{
...
...
@@ -13,21 +13,21 @@ public class TestPojoJsonDeserialization {
private
static
final
String
completeJson
=
"{\"a\":4,\"b\":5}"
;
@Test
public
void
testEmptyDeserializationWithImplicitDefaultCtor
()
{
public
void
testEmptyDeserializationWithImplicitDefaultCtor
()
throws
IOException
{
// Important: After deserialization with incomplete JSON,
// the init values (for a and b) in POJOs take effect!
assertTestPojoEquals
(
new
TestPojoWithImplicitDefaultConstructor
(),
"{}"
,
TestPojoWithImplicitDefaultConstructor
.
class
);
}
@Test
public
void
testIncompleteDeserialization
()
{
public
void
testIncompleteDeserialization
()
throws
IOException
{
// Important: After deserialization with incomplete JSON,
// the init values (for a and b) in POJOs take effect!
assertTestPojoEquals
(
new
TestPojoWithDefaultConstructor
(
1
,
5
),
incompleteJson
,
TestPojoWithDefaultConstructor
.
class
);
}
@Test
public
void
testCompleteDeserialization
()
{
public
void
testCompleteDeserialization
()
throws
IOException
{
assertTestPojoEquals
(
new
TestPojoWithDefaultConstructor
(
4
,
5
),
completeJson
,
TestPojoWithDefaultConstructor
.
class
);
}
...
...
@@ -35,8 +35,8 @@ public class TestPojoJsonDeserialization {
public
void
testIncompleteDeserializationWithoutDefaultCtor
()
{
try
{
assertTestPojoEquals
(
new
TestPojoWithoutDefaultConstructor
(
0
,
5
),
incompleteJson
,
TestPojoWithoutDefaultConstructor
.
class
);
}
catch
(
Runtime
Exception
e
)
{
assertExceptionCorrect
(
e
);
}
catch
(
IO
Exception
e
)
{
//Test successful
}
}
...
...
@@ -44,16 +44,12 @@ public class TestPojoJsonDeserialization {
public
void
testCompleteDeserializationWithoutDefaultCtor
()
{
try
{
assertTestPojoEquals
(
new
TestPojoWithoutDefaultConstructor
(
0
,
5
),
completeJson
,
TestPojoWithoutDefaultConstructor
.
class
);
}
catch
(
Runtime
Exception
e
)
{
assertExceptionCorrect
(
e
);
}
catch
(
IO
Exception
e
)
{
//Test successful
}
}
private
void
assertExceptionCorrect
(
RuntimeException
e
)
{
assertTrue
(
e
.
getCause
()
instanceof
JsonMappingException
);
}
private
void
assertTestPojoEquals
(
Object
pojo
,
String
json
,
Class
<?>
clazz
)
{
private
void
assertTestPojoEquals
(
Object
pojo
,
String
json
,
Class
<?>
clazz
)
throws
IOException
{
assertEquals
(
pojo
,
StateJsonConverter
.
deserializeObjectFromJson
(
json
,
clazz
));
}
...
...
VadereState/tests/org/vadere/state/attributes/scenario/TestAttributesSource.java
View file @
792b9095
...
...
@@ -2,6 +2,7 @@ package org.vadere.state.attributes.scenario;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -12,18 +13,18 @@ public class TestAttributesSource {
private
AttributesSource
attributes
;
private
void
createAttributes
(
SourceTestAttributesBuilder
builder
)
{
private
void
createAttributes
(
SourceTestAttributesBuilder
builder
)
throws
IOException
{
attributes
=
builder
.
getResult
();
}
@Test
public
void
testGetInterSpawnTimeDistribution
()
{
public
void
testGetInterSpawnTimeDistribution
()
throws
IOException
{