2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 8521a5be authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Improved class "JsonTransformationV1_3ToV1_4" to rename also elements in "dynamicElements" array

parent 91cae2e9
......@@ -33,6 +33,7 @@ public class JsonTransformationV1_3ToV1_4 extends SimpleJsonTransformation {
private void renameInTopography(JsonNode node, String oldName, String newName) throws MigrationException {
JsonNode attributesPedestrianNode = pathMustExist(node, "scenario/topography/attributesPedestrian");
renameField((ObjectNode)attributesPedestrianNode, oldName, newName);
renameInDynamicElements(node, oldName, newName);
}
private void renameInMainModel(JsonNode node, String oldName, String newName) throws MigrationException {
......@@ -42,4 +43,18 @@ public class JsonTransformationV1_3ToV1_4 extends SimpleJsonTransformation {
renameField((ObjectNode)attributesModelNode, oldName, newName);
}
}
private void renameInDynamicElements(JsonNode node, String oldName, String newName) throws MigrationException {
JsonNode dynamicElementsNode = path(node, "scenario/topography/dynamicElements");
if (dynamicElementsNode.isArray()) {
for (JsonNode jsonNode : dynamicElementsNode) {
JsonNode attributesNode = path(jsonNode, "attributes");
if (!attributesNode.isMissingNode()) {
renameField((ObjectNode)attributesNode, oldName, newName);
}
}
}
}
}
{
"name" : "s002",
"name" : "footStepsToStoreInMainModel",
"description" : "",
"release" : "1.3",
"processWriters" : {
......
{
"name" : "s001",
"name" : "footStepsToStoreInTopography",
"description" : "",
"release" : "1.3",
"processWriters" : {
......
package org.vadere.simulator.projects.migration.jsontranformation.json;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.Test;
import org.vadere.simulator.projects.migration.MigrationException;
import org.vadere.simulator.projects.migration.jsontranformation.JsonTransformationTest;
......@@ -16,7 +17,7 @@ public class JsonTransformationV1_3ToV1_4Test extends JsonTransformationTest {
@Test
public void assertThatJsonTransformationV1_3ToV1_4RenamesFootStepsToStoreInTopography() throws MigrationException {
String scenarioFileAsString = getTestFileAsString("s001.scenario");
String scenarioFileAsString = getTestFileAsString("footStepsToStoreInTopography.scenario");
JsonNode oldScenarioAsJson = getJsonFromString(scenarioFileAsString);
String oldJsonPath = "scenario/topography/attributesPedestrian/footStepsToStore";
......@@ -34,7 +35,7 @@ public class JsonTransformationV1_3ToV1_4Test extends JsonTransformationTest {
@Test
public void assertThatJsonTransformationV1_3ToV1_4RenamesFootStepsToStoreInMainModel() throws MigrationException {
String scenarioFileAsString = getTestFileAsString("s002.scenario");
String scenarioFileAsString = getTestFileAsString("footStepsToStoreInMainModel.scenario");
JsonNode oldScenarioAsJson = getJsonFromString(scenarioFileAsString);
String oldJsonPath = "scenario/attributesModel/org.vadere.state.attributes.scenario.AttributesCar/footStepsToStore";
......@@ -50,4 +51,37 @@ public class JsonTransformationV1_3ToV1_4Test extends JsonTransformationTest {
pathMustExist(newScenarioAsJson, newJsonPath);
}
@Test
public void assertThatJsonTransformationV1_3ToV1_4RenamesFootStepsToStoreInDynamicElements() throws MigrationException {
String scenarioFileAsString = getTestFileAsString("footStepsToStoreInDynamicElements.scenario");
JsonNode oldScenarioAsJson = getJsonFromString(scenarioFileAsString);
JsonNode dynamicElementsNode = path(oldScenarioAsJson, "scenario/topography/dynamicElements");
// Assert that "attributes" node in "dynamicElements" is NOT renamed here.
if (dynamicElementsNode.isArray()) {
for (JsonNode jsonNode : dynamicElementsNode) {
JsonNode attributesNode = path(jsonNode, "attributes");
if (!attributesNode.isMissingNode()) {
pathMustExist(attributesNode, "footStepsToStore");
}
}
}
JsonTransformationV1_3ToV1_4 transform = factory.getJsonTransformationV1_3ToV1_4();
JsonNode newScenarioAsJson = transform.applyAll(oldScenarioAsJson);
// Assert that "attributes" node in "dynamicElements" is renamed here.
if (dynamicElementsNode.isArray()) {
for (JsonNode jsonNode : dynamicElementsNode) {
JsonNode attributesNode = path(jsonNode, "attributes");
if (!attributesNode.isMissingNode()) {
pathMustExist(attributesNode, "footstepHistorySize");
}
}
}
}
}
\ No newline at end of file
Markdown is supported
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